]>
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> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
55682965 JB |
11 | #include <linux/list.h> |
12 | #include <linux/if_ether.h> | |
13 | #include <linux/ieee80211.h> | |
14 | #include <linux/nl80211.h> | |
15 | #include <linux/rtnetlink.h> | |
16 | #include <linux/netlink.h> | |
2a519311 | 17 | #include <linux/etherdevice.h> |
463d0183 | 18 | #include <net/net_namespace.h> |
55682965 JB |
19 | #include <net/genetlink.h> |
20 | #include <net/cfg80211.h> | |
463d0183 | 21 | #include <net/sock.h> |
2a0e047e | 22 | #include <net/inet_connection_sock.h> |
55682965 JB |
23 | #include "core.h" |
24 | #include "nl80211.h" | |
b2e1b302 | 25 | #include "reg.h" |
e35e4d28 | 26 | #include "rdev-ops.h" |
55682965 | 27 | |
5fb628e9 JM |
28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
29 | struct genl_info *info, | |
30 | struct cfg80211_crypto_settings *settings, | |
31 | int cipher_limit); | |
32 | ||
f84f771d | 33 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 34 | struct genl_info *info); |
f84f771d | 35 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
36 | struct genl_info *info); |
37 | ||
55682965 JB |
38 | /* the netlink family */ |
39 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
42 | .hdrsize = 0, /* no private header */ | |
43 | .version = 1, /* no particular meaning now */ | |
55682965 | 44 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 45 | .netnsok = true, |
4c476991 JB |
46 | .pre_doit = nl80211_pre_doit, |
47 | .post_doit = nl80211_post_doit, | |
55682965 JB |
48 | }; |
49 | ||
2a94fe48 JB |
50 | /* multicast groups */ |
51 | enum nl80211_multicast_groups { | |
52 | NL80211_MCGRP_CONFIG, | |
53 | NL80211_MCGRP_SCAN, | |
54 | NL80211_MCGRP_REGULATORY, | |
55 | NL80211_MCGRP_MLME, | |
567ffc35 | 56 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
57 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
58 | }; | |
59 | ||
60 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
61 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, | |
62 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, | |
63 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, | |
64 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, | |
567ffc35 | 65 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
2a94fe48 JB |
66 | #ifdef CONFIG_NL80211_TESTMODE |
67 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } | |
68 | #endif | |
69 | }; | |
70 | ||
89a54e48 JB |
71 | /* returns ERR_PTR values */ |
72 | static struct wireless_dev * | |
73 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 74 | { |
89a54e48 JB |
75 | struct cfg80211_registered_device *rdev; |
76 | struct wireless_dev *result = NULL; | |
77 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
78 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
79 | u64 wdev_id; | |
80 | int wiphy_idx = -1; | |
81 | int ifidx = -1; | |
55682965 | 82 | |
5fe231e8 | 83 | ASSERT_RTNL(); |
55682965 | 84 | |
89a54e48 JB |
85 | if (!have_ifidx && !have_wdev_id) |
86 | return ERR_PTR(-EINVAL); | |
55682965 | 87 | |
89a54e48 JB |
88 | if (have_ifidx) |
89 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
90 | if (have_wdev_id) { | |
91 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
92 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
93 | } |
94 | ||
89a54e48 JB |
95 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
96 | struct wireless_dev *wdev; | |
97 | ||
98 | if (wiphy_net(&rdev->wiphy) != netns) | |
99 | continue; | |
100 | ||
101 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
102 | continue; | |
103 | ||
89a54e48 JB |
104 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
105 | if (have_ifidx && wdev->netdev && | |
106 | wdev->netdev->ifindex == ifidx) { | |
107 | result = wdev; | |
108 | break; | |
109 | } | |
110 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
111 | result = wdev; | |
112 | break; | |
113 | } | |
114 | } | |
89a54e48 JB |
115 | |
116 | if (result) | |
117 | break; | |
118 | } | |
119 | ||
120 | if (result) | |
121 | return result; | |
122 | return ERR_PTR(-ENODEV); | |
55682965 JB |
123 | } |
124 | ||
a9455408 | 125 | static struct cfg80211_registered_device * |
878d9ec7 | 126 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 127 | { |
7fee4778 JB |
128 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
129 | struct net_device *netdev; | |
a9455408 | 130 | |
5fe231e8 | 131 | ASSERT_RTNL(); |
a9455408 | 132 | |
878d9ec7 | 133 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
134 | !attrs[NL80211_ATTR_IFINDEX] && |
135 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
136 | return ERR_PTR(-EINVAL); |
137 | ||
878d9ec7 | 138 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 139 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 140 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 141 | |
89a54e48 JB |
142 | if (attrs[NL80211_ATTR_WDEV]) { |
143 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
144 | struct wireless_dev *wdev; | |
145 | bool found = false; | |
146 | ||
147 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
148 | if (tmp) { | |
149 | /* make sure wdev exists */ | |
89a54e48 JB |
150 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
151 | if (wdev->identifier != (u32)wdev_id) | |
152 | continue; | |
153 | found = true; | |
154 | break; | |
155 | } | |
89a54e48 JB |
156 | |
157 | if (!found) | |
158 | tmp = NULL; | |
159 | ||
160 | if (rdev && tmp != rdev) | |
161 | return ERR_PTR(-EINVAL); | |
162 | rdev = tmp; | |
163 | } | |
164 | } | |
165 | ||
878d9ec7 JB |
166 | if (attrs[NL80211_ATTR_IFINDEX]) { |
167 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 168 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
169 | if (netdev) { |
170 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
171 | tmp = wiphy_to_rdev( |
172 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
173 | else |
174 | tmp = NULL; | |
175 | ||
7fee4778 JB |
176 | /* not wireless device -- return error */ |
177 | if (!tmp) | |
178 | return ERR_PTR(-EINVAL); | |
179 | ||
180 | /* mismatch -- return error */ | |
181 | if (rdev && tmp != rdev) | |
182 | return ERR_PTR(-EINVAL); | |
183 | ||
184 | rdev = tmp; | |
a9455408 | 185 | } |
a9455408 | 186 | } |
a9455408 | 187 | |
4f7eff10 JB |
188 | if (!rdev) |
189 | return ERR_PTR(-ENODEV); | |
a9455408 | 190 | |
4f7eff10 JB |
191 | if (netns != wiphy_net(&rdev->wiphy)) |
192 | return ERR_PTR(-ENODEV); | |
193 | ||
194 | return rdev; | |
a9455408 JB |
195 | } |
196 | ||
197 | /* | |
198 | * This function returns a pointer to the driver | |
199 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
200 | * |
201 | * The result of this can be a PTR_ERR and hence must | |
202 | * be checked with IS_ERR() for errors. | |
203 | */ | |
204 | static struct cfg80211_registered_device * | |
4f7eff10 | 205 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 206 | { |
5fe231e8 | 207 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
208 | } |
209 | ||
55682965 | 210 | /* policy for the attributes */ |
b54452b0 | 211 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
212 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
213 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 214 | .len = 20-1 }, |
31888487 | 215 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 216 | |
72bdcf34 | 217 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 218 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
219 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
220 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
221 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
222 | ||
b9a5f8ca JM |
223 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
224 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
225 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
226 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 227 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
228 | |
229 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
230 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
231 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 232 | |
e007b857 EP |
233 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
234 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 235 | |
b9454e83 | 236 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
237 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
238 | .len = WLAN_MAX_KEY_LEN }, | |
239 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
240 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
241 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 242 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 243 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
244 | |
245 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
246 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
247 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
248 | .len = IEEE80211_MAX_DATA_LEN }, | |
249 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
251 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
252 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
253 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
254 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
255 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 256 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 257 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 258 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 259 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 260 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 261 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 262 | |
b2e1b302 LR |
263 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
264 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
265 | ||
9f1ba906 JM |
266 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
267 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
268 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
269 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
270 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 271 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 272 | |
24bdd9f4 | 273 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 274 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 275 | |
6c739419 | 276 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
277 | |
278 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
279 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
280 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
281 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
282 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
283 | |
284 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
285 | .len = IEEE80211_MAX_SSID_LEN }, | |
286 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
287 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 288 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 289 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 290 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
291 | [NL80211_ATTR_STA_FLAGS2] = { |
292 | .len = sizeof(struct nl80211_sta_flag_update), | |
293 | }, | |
3f77316c | 294 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
295 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
296 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
297 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
298 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
299 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 300 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 301 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
302 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
303 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
304 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
305 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 306 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
307 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
308 | .len = IEEE80211_MAX_DATA_LEN }, | |
309 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 310 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 311 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 312 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 313 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
314 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
315 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 316 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
317 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
318 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 319 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 320 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 321 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 322 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 323 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 324 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 325 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 326 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 327 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
328 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
329 | .len = IEEE80211_MAX_DATA_LEN }, | |
330 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 332 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 333 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 334 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
335 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
336 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
337 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
338 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
339 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 340 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
341 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
342 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 343 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
344 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
345 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
346 | .len = NL80211_HT_CAPABILITY_LEN | |
347 | }, | |
1d9d9213 | 348 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 349 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 350 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 351 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 352 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 353 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 354 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 355 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
356 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
357 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
358 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
359 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
360 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
361 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 362 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
363 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
364 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
365 | .len = NL80211_VHT_CAPABILITY_LEN, | |
366 | }, | |
355199e0 JM |
367 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
368 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
369 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 370 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
371 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
372 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
373 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
374 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, | |
375 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, | |
c01fc9ad SD |
376 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
377 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 378 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 379 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
380 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
381 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
382 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
383 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
384 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
385 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
386 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 387 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
78f22b6a | 388 | [NL80211_ATTR_IFACE_SOCKET_OWNER] = { .type = NLA_FLAG }, |
55682965 JB |
389 | }; |
390 | ||
e31b8213 | 391 | /* policy for the key attributes */ |
b54452b0 | 392 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 393 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
394 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
395 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 396 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
397 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
398 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 399 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
400 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
401 | }; | |
402 | ||
403 | /* policy for the key default flags */ | |
404 | static const struct nla_policy | |
405 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
406 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
407 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
408 | }; |
409 | ||
ff1b6e69 JB |
410 | /* policy for WoWLAN attributes */ |
411 | static const struct nla_policy | |
412 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
413 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
414 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
415 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
416 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
417 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
418 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
419 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
420 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
421 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
422 | }; | |
423 | ||
424 | static const struct nla_policy | |
425 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
426 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
427 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
428 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
429 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
430 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
431 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
432 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
433 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
434 | }, | |
435 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
436 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
437 | }, | |
438 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
439 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
440 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
441 | }; |
442 | ||
be29b99a AK |
443 | /* policy for coalesce rule attributes */ |
444 | static const struct nla_policy | |
445 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
446 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
447 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
448 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
449 | }; | |
450 | ||
e5497d76 JB |
451 | /* policy for GTK rekey offload attributes */ |
452 | static const struct nla_policy | |
453 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
454 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
455 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
456 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
457 | }; | |
458 | ||
a1f1c21c LC |
459 | static const struct nla_policy |
460 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 461 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 462 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 463 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
464 | }; |
465 | ||
97990a06 JB |
466 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
467 | struct netlink_callback *cb, | |
468 | struct cfg80211_registered_device **rdev, | |
469 | struct wireless_dev **wdev) | |
a043897a | 470 | { |
97990a06 | 471 | int err; |
a043897a | 472 | |
97990a06 | 473 | rtnl_lock(); |
a043897a | 474 | |
97990a06 JB |
475 | if (!cb->args[0]) { |
476 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
477 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
478 | nl80211_policy); | |
479 | if (err) | |
480 | goto out_unlock; | |
67748893 | 481 | |
97990a06 JB |
482 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
483 | nl80211_fam.attrbuf); | |
484 | if (IS_ERR(*wdev)) { | |
485 | err = PTR_ERR(*wdev); | |
486 | goto out_unlock; | |
487 | } | |
f26cbf40 | 488 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
489 | /* 0 is the first index - add 1 to parse only once */ |
490 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
491 | cb->args[1] = (*wdev)->identifier; |
492 | } else { | |
c319d50b JB |
493 | /* subtract the 1 again here */ |
494 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 495 | struct wireless_dev *tmp; |
67748893 | 496 | |
97990a06 JB |
497 | if (!wiphy) { |
498 | err = -ENODEV; | |
499 | goto out_unlock; | |
500 | } | |
f26cbf40 | 501 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 502 | *wdev = NULL; |
67748893 | 503 | |
97990a06 JB |
504 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
505 | if (tmp->identifier == cb->args[1]) { | |
506 | *wdev = tmp; | |
507 | break; | |
508 | } | |
509 | } | |
67748893 | 510 | |
97990a06 JB |
511 | if (!*wdev) { |
512 | err = -ENODEV; | |
513 | goto out_unlock; | |
514 | } | |
67748893 JB |
515 | } |
516 | ||
67748893 | 517 | return 0; |
97990a06 | 518 | out_unlock: |
67748893 JB |
519 | rtnl_unlock(); |
520 | return err; | |
521 | } | |
522 | ||
97990a06 | 523 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 524 | { |
67748893 JB |
525 | rtnl_unlock(); |
526 | } | |
527 | ||
f4a11bb0 JB |
528 | /* IE validation */ |
529 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
530 | { | |
531 | const u8 *pos; | |
532 | int len; | |
533 | ||
534 | if (!attr) | |
535 | return true; | |
536 | ||
537 | pos = nla_data(attr); | |
538 | len = nla_len(attr); | |
539 | ||
540 | while (len) { | |
541 | u8 elemlen; | |
542 | ||
543 | if (len < 2) | |
544 | return false; | |
545 | len -= 2; | |
546 | ||
547 | elemlen = pos[1]; | |
548 | if (elemlen > len) | |
549 | return false; | |
550 | ||
551 | len -= elemlen; | |
552 | pos += 2 + elemlen; | |
553 | } | |
554 | ||
555 | return true; | |
556 | } | |
557 | ||
55682965 | 558 | /* message building helper */ |
15e47304 | 559 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
560 | int flags, u8 cmd) |
561 | { | |
562 | /* since there is no private header just add the generic one */ | |
15e47304 | 563 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
564 | } |
565 | ||
5dab3b8a | 566 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
567 | struct ieee80211_channel *chan, |
568 | bool large) | |
5dab3b8a | 569 | { |
ea077c1c RL |
570 | /* Some channels must be completely excluded from the |
571 | * list to protect old user-space tools from breaking | |
572 | */ | |
573 | if (!large && chan->flags & | |
574 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
575 | return 0; | |
576 | ||
9360ffd1 DM |
577 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
578 | chan->center_freq)) | |
579 | goto nla_put_failure; | |
5dab3b8a | 580 | |
9360ffd1 DM |
581 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
582 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
583 | goto nla_put_failure; | |
8fe02e16 LR |
584 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
585 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
586 | goto nla_put_failure; | |
587 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
588 | goto nla_put_failure; | |
589 | } | |
cdc89b97 JB |
590 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
591 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
592 | goto nla_put_failure; | |
593 | if (large) { | |
594 | u32 time; | |
595 | ||
596 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
597 | ||
598 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
599 | chan->dfs_state)) | |
600 | goto nla_put_failure; | |
601 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
602 | time)) | |
603 | goto nla_put_failure; | |
089027e5 JD |
604 | if (nla_put_u32(msg, |
605 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
606 | chan->dfs_cac_ms)) | |
607 | goto nla_put_failure; | |
cdc89b97 JB |
608 | } |
609 | } | |
5dab3b8a | 610 | |
fe1abafd JB |
611 | if (large) { |
612 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
613 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
614 | goto nla_put_failure; | |
615 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
616 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
617 | goto nla_put_failure; | |
618 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
619 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
620 | goto nla_put_failure; | |
621 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
622 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
623 | goto nla_put_failure; | |
570dbde1 DS |
624 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
626 | goto nla_put_failure; | |
627 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
629 | goto nla_put_failure; | |
ea077c1c RL |
630 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
632 | goto nla_put_failure; | |
633 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
635 | goto nla_put_failure; | |
fe1abafd JB |
636 | } |
637 | ||
9360ffd1 DM |
638 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
639 | DBM_TO_MBM(chan->max_power))) | |
640 | goto nla_put_failure; | |
5dab3b8a LR |
641 | |
642 | return 0; | |
643 | ||
644 | nla_put_failure: | |
645 | return -ENOBUFS; | |
646 | } | |
647 | ||
55682965 JB |
648 | /* netlink command implementations */ |
649 | ||
b9454e83 JB |
650 | struct key_parse { |
651 | struct key_params p; | |
652 | int idx; | |
e31b8213 | 653 | int type; |
b9454e83 | 654 | bool def, defmgmt; |
dbd2fd65 | 655 | bool def_uni, def_multi; |
b9454e83 JB |
656 | }; |
657 | ||
658 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
659 | { | |
660 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
661 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
662 | nl80211_key_policy); | |
663 | if (err) | |
664 | return err; | |
665 | ||
666 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
667 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
668 | ||
dbd2fd65 JB |
669 | if (k->def) { |
670 | k->def_uni = true; | |
671 | k->def_multi = true; | |
672 | } | |
673 | if (k->defmgmt) | |
674 | k->def_multi = true; | |
675 | ||
b9454e83 JB |
676 | if (tb[NL80211_KEY_IDX]) |
677 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
678 | ||
679 | if (tb[NL80211_KEY_DATA]) { | |
680 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
681 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
682 | } | |
683 | ||
684 | if (tb[NL80211_KEY_SEQ]) { | |
685 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
686 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
687 | } | |
688 | ||
689 | if (tb[NL80211_KEY_CIPHER]) | |
690 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
691 | ||
e31b8213 JB |
692 | if (tb[NL80211_KEY_TYPE]) { |
693 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
694 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
695 | return -EINVAL; | |
696 | } | |
697 | ||
dbd2fd65 JB |
698 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
699 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
700 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
701 | tb[NL80211_KEY_DEFAULT_TYPES], | |
702 | nl80211_key_default_policy); | |
dbd2fd65 JB |
703 | if (err) |
704 | return err; | |
705 | ||
706 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
707 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
708 | } | |
709 | ||
b9454e83 JB |
710 | return 0; |
711 | } | |
712 | ||
713 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
714 | { | |
715 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
716 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
717 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
718 | } | |
719 | ||
720 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
721 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
722 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
723 | } | |
724 | ||
725 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
726 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
727 | ||
728 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
729 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
730 | ||
731 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
732 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
733 | ||
dbd2fd65 JB |
734 | if (k->def) { |
735 | k->def_uni = true; | |
736 | k->def_multi = true; | |
737 | } | |
738 | if (k->defmgmt) | |
739 | k->def_multi = true; | |
740 | ||
e31b8213 JB |
741 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
742 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
743 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
744 | return -EINVAL; | |
745 | } | |
746 | ||
dbd2fd65 JB |
747 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
748 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
749 | int err = nla_parse_nested( | |
750 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
751 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
752 | nl80211_key_default_policy); | |
753 | if (err) | |
754 | return err; | |
755 | ||
756 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
757 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
758 | } | |
759 | ||
b9454e83 JB |
760 | return 0; |
761 | } | |
762 | ||
763 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
764 | { | |
765 | int err; | |
766 | ||
767 | memset(k, 0, sizeof(*k)); | |
768 | k->idx = -1; | |
e31b8213 | 769 | k->type = -1; |
b9454e83 JB |
770 | |
771 | if (info->attrs[NL80211_ATTR_KEY]) | |
772 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
773 | else | |
774 | err = nl80211_parse_key_old(info, k); | |
775 | ||
776 | if (err) | |
777 | return err; | |
778 | ||
779 | if (k->def && k->defmgmt) | |
780 | return -EINVAL; | |
781 | ||
dbd2fd65 JB |
782 | if (k->defmgmt) { |
783 | if (k->def_uni || !k->def_multi) | |
784 | return -EINVAL; | |
785 | } | |
786 | ||
b9454e83 JB |
787 | if (k->idx != -1) { |
788 | if (k->defmgmt) { | |
789 | if (k->idx < 4 || k->idx > 5) | |
790 | return -EINVAL; | |
791 | } else if (k->def) { | |
792 | if (k->idx < 0 || k->idx > 3) | |
793 | return -EINVAL; | |
794 | } else { | |
795 | if (k->idx < 0 || k->idx > 5) | |
796 | return -EINVAL; | |
797 | } | |
798 | } | |
799 | ||
800 | return 0; | |
801 | } | |
802 | ||
fffd0934 JB |
803 | static struct cfg80211_cached_keys * |
804 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 805 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
806 | { |
807 | struct key_parse parse; | |
808 | struct nlattr *key; | |
809 | struct cfg80211_cached_keys *result; | |
810 | int rem, err, def = 0; | |
811 | ||
812 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
813 | if (!result) | |
814 | return ERR_PTR(-ENOMEM); | |
815 | ||
816 | result->def = -1; | |
817 | result->defmgmt = -1; | |
818 | ||
819 | nla_for_each_nested(key, keys, rem) { | |
820 | memset(&parse, 0, sizeof(parse)); | |
821 | parse.idx = -1; | |
822 | ||
823 | err = nl80211_parse_key_new(key, &parse); | |
824 | if (err) | |
825 | goto error; | |
826 | err = -EINVAL; | |
827 | if (!parse.p.key) | |
828 | goto error; | |
829 | if (parse.idx < 0 || parse.idx > 4) | |
830 | goto error; | |
831 | if (parse.def) { | |
832 | if (def) | |
833 | goto error; | |
834 | def = 1; | |
835 | result->def = parse.idx; | |
dbd2fd65 JB |
836 | if (!parse.def_uni || !parse.def_multi) |
837 | goto error; | |
fffd0934 JB |
838 | } else if (parse.defmgmt) |
839 | goto error; | |
840 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 841 | parse.idx, false, NULL); |
fffd0934 JB |
842 | if (err) |
843 | goto error; | |
844 | result->params[parse.idx].cipher = parse.p.cipher; | |
845 | result->params[parse.idx].key_len = parse.p.key_len; | |
846 | result->params[parse.idx].key = result->data[parse.idx]; | |
847 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
848 | |
849 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
850 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
851 | if (no_ht) | |
852 | *no_ht = true; | |
853 | } | |
fffd0934 JB |
854 | } |
855 | ||
856 | return result; | |
857 | error: | |
858 | kfree(result); | |
859 | return ERR_PTR(err); | |
860 | } | |
861 | ||
862 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
863 | { | |
864 | ASSERT_WDEV_LOCK(wdev); | |
865 | ||
fffd0934 JB |
866 | switch (wdev->iftype) { |
867 | case NL80211_IFTYPE_AP: | |
868 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 869 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 870 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
871 | break; |
872 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 873 | case NL80211_IFTYPE_STATION: |
074ac8df | 874 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 875 | if (!wdev->current_bss) |
fffd0934 JB |
876 | return -ENOLINK; |
877 | break; | |
878 | default: | |
879 | return -EINVAL; | |
880 | } | |
881 | ||
882 | return 0; | |
883 | } | |
884 | ||
664834de JM |
885 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
886 | struct nlattr *tb) | |
887 | { | |
888 | struct ieee80211_channel *chan; | |
889 | ||
890 | if (tb == NULL) | |
891 | return NULL; | |
892 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
893 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
894 | return NULL; | |
895 | return chan; | |
896 | } | |
897 | ||
7527a782 JB |
898 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
899 | { | |
900 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
901 | int i; | |
902 | ||
903 | if (!nl_modes) | |
904 | goto nla_put_failure; | |
905 | ||
906 | i = 0; | |
907 | while (ifmodes) { | |
9360ffd1 DM |
908 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
909 | goto nla_put_failure; | |
7527a782 JB |
910 | ifmodes >>= 1; |
911 | i++; | |
912 | } | |
913 | ||
914 | nla_nest_end(msg, nl_modes); | |
915 | return 0; | |
916 | ||
917 | nla_put_failure: | |
918 | return -ENOBUFS; | |
919 | } | |
920 | ||
921 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
922 | struct sk_buff *msg, |
923 | bool large) | |
7527a782 JB |
924 | { |
925 | struct nlattr *nl_combis; | |
926 | int i, j; | |
927 | ||
928 | nl_combis = nla_nest_start(msg, | |
929 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
930 | if (!nl_combis) | |
931 | goto nla_put_failure; | |
932 | ||
933 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
934 | const struct ieee80211_iface_combination *c; | |
935 | struct nlattr *nl_combi, *nl_limits; | |
936 | ||
937 | c = &wiphy->iface_combinations[i]; | |
938 | ||
939 | nl_combi = nla_nest_start(msg, i + 1); | |
940 | if (!nl_combi) | |
941 | goto nla_put_failure; | |
942 | ||
943 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
944 | if (!nl_limits) | |
945 | goto nla_put_failure; | |
946 | ||
947 | for (j = 0; j < c->n_limits; j++) { | |
948 | struct nlattr *nl_limit; | |
949 | ||
950 | nl_limit = nla_nest_start(msg, j + 1); | |
951 | if (!nl_limit) | |
952 | goto nla_put_failure; | |
9360ffd1 DM |
953 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
954 | c->limits[j].max)) | |
955 | goto nla_put_failure; | |
7527a782 JB |
956 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
957 | c->limits[j].types)) | |
958 | goto nla_put_failure; | |
959 | nla_nest_end(msg, nl_limit); | |
960 | } | |
961 | ||
962 | nla_nest_end(msg, nl_limits); | |
963 | ||
9360ffd1 DM |
964 | if (c->beacon_int_infra_match && |
965 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
966 | goto nla_put_failure; | |
967 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
968 | c->num_different_channels) || | |
969 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
970 | c->max_interfaces)) | |
971 | goto nla_put_failure; | |
cdc89b97 JB |
972 | if (large && |
973 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
974 | c->radar_detect_widths)) | |
975 | goto nla_put_failure; | |
7527a782 JB |
976 | |
977 | nla_nest_end(msg, nl_combi); | |
978 | } | |
979 | ||
980 | nla_nest_end(msg, nl_combis); | |
981 | ||
982 | return 0; | |
983 | nla_put_failure: | |
984 | return -ENOBUFS; | |
985 | } | |
986 | ||
3713b4e3 | 987 | #ifdef CONFIG_PM |
b56cf720 JB |
988 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
989 | struct sk_buff *msg) | |
990 | { | |
964dc9e2 | 991 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
992 | struct nlattr *nl_tcp; |
993 | ||
994 | if (!tcp) | |
995 | return 0; | |
996 | ||
997 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
998 | if (!nl_tcp) | |
999 | return -ENOBUFS; | |
1000 | ||
1001 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1002 | tcp->data_payload_max)) | |
1003 | return -ENOBUFS; | |
1004 | ||
1005 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1006 | tcp->data_payload_max)) | |
1007 | return -ENOBUFS; | |
1008 | ||
1009 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1010 | return -ENOBUFS; | |
1011 | ||
1012 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1013 | sizeof(*tcp->tok), tcp->tok)) | |
1014 | return -ENOBUFS; | |
1015 | ||
1016 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1017 | tcp->data_interval_max)) | |
1018 | return -ENOBUFS; | |
1019 | ||
1020 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1021 | tcp->wake_payload_max)) | |
1022 | return -ENOBUFS; | |
1023 | ||
1024 | nla_nest_end(msg, nl_tcp); | |
1025 | return 0; | |
1026 | } | |
1027 | ||
3713b4e3 | 1028 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1029 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1030 | bool large) |
55682965 | 1031 | { |
3713b4e3 | 1032 | struct nlattr *nl_wowlan; |
55682965 | 1033 | |
1b8ec87a | 1034 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1035 | return 0; |
55682965 | 1036 | |
3713b4e3 JB |
1037 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1038 | if (!nl_wowlan) | |
1039 | return -ENOBUFS; | |
9360ffd1 | 1040 | |
1b8ec87a | 1041 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1042 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1043 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1044 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1045 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1046 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1047 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1048 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1049 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1050 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1051 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1052 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1053 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1054 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1055 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1056 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1057 | return -ENOBUFS; | |
9360ffd1 | 1058 | |
1b8ec87a | 1059 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1060 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1061 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1062 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1063 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1064 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1065 | }; |
9360ffd1 | 1066 | |
3713b4e3 JB |
1067 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1068 | sizeof(pat), &pat)) | |
1069 | return -ENOBUFS; | |
1070 | } | |
9360ffd1 | 1071 | |
1b8ec87a | 1072 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1073 | return -ENOBUFS; |
1074 | ||
3713b4e3 | 1075 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1076 | |
3713b4e3 JB |
1077 | return 0; |
1078 | } | |
1079 | #endif | |
9360ffd1 | 1080 | |
be29b99a | 1081 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1082 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1083 | { |
1084 | struct nl80211_coalesce_rule_support rule; | |
1085 | ||
1b8ec87a | 1086 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1087 | return 0; |
1088 | ||
1b8ec87a ZG |
1089 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1090 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1091 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1092 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1093 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1094 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1095 | |
1096 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1097 | return -ENOBUFS; | |
1098 | ||
1099 | return 0; | |
1100 | } | |
1101 | ||
3713b4e3 JB |
1102 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1103 | struct ieee80211_supported_band *sband) | |
1104 | { | |
1105 | struct nlattr *nl_rates, *nl_rate; | |
1106 | struct ieee80211_rate *rate; | |
1107 | int i; | |
87bbbe22 | 1108 | |
3713b4e3 JB |
1109 | /* add HT info */ |
1110 | if (sband->ht_cap.ht_supported && | |
1111 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1112 | sizeof(sband->ht_cap.mcs), | |
1113 | &sband->ht_cap.mcs) || | |
1114 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1115 | sband->ht_cap.cap) || | |
1116 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1117 | sband->ht_cap.ampdu_factor) || | |
1118 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1119 | sband->ht_cap.ampdu_density))) | |
1120 | return -ENOBUFS; | |
afe0cbf8 | 1121 | |
3713b4e3 JB |
1122 | /* add VHT info */ |
1123 | if (sband->vht_cap.vht_supported && | |
1124 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1125 | sizeof(sband->vht_cap.vht_mcs), | |
1126 | &sband->vht_cap.vht_mcs) || | |
1127 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1128 | sband->vht_cap.cap))) | |
1129 | return -ENOBUFS; | |
f59ac048 | 1130 | |
3713b4e3 JB |
1131 | /* add bitrates */ |
1132 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1133 | if (!nl_rates) | |
1134 | return -ENOBUFS; | |
ee688b00 | 1135 | |
3713b4e3 JB |
1136 | for (i = 0; i < sband->n_bitrates; i++) { |
1137 | nl_rate = nla_nest_start(msg, i); | |
1138 | if (!nl_rate) | |
1139 | return -ENOBUFS; | |
ee688b00 | 1140 | |
3713b4e3 JB |
1141 | rate = &sband->bitrates[i]; |
1142 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1143 | rate->bitrate)) | |
1144 | return -ENOBUFS; | |
1145 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1146 | nla_put_flag(msg, | |
1147 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1148 | return -ENOBUFS; | |
ee688b00 | 1149 | |
3713b4e3 JB |
1150 | nla_nest_end(msg, nl_rate); |
1151 | } | |
d51626df | 1152 | |
3713b4e3 | 1153 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1154 | |
3713b4e3 JB |
1155 | return 0; |
1156 | } | |
ee688b00 | 1157 | |
3713b4e3 JB |
1158 | static int |
1159 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1160 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1161 | { | |
1162 | u16 stypes; | |
1163 | struct nlattr *nl_ftypes, *nl_ifs; | |
1164 | enum nl80211_iftype ift; | |
1165 | int i; | |
ee688b00 | 1166 | |
3713b4e3 JB |
1167 | if (!mgmt_stypes) |
1168 | return 0; | |
5dab3b8a | 1169 | |
3713b4e3 JB |
1170 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1171 | if (!nl_ifs) | |
1172 | return -ENOBUFS; | |
e2f367f2 | 1173 | |
3713b4e3 JB |
1174 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1175 | nl_ftypes = nla_nest_start(msg, ift); | |
1176 | if (!nl_ftypes) | |
1177 | return -ENOBUFS; | |
1178 | i = 0; | |
1179 | stypes = mgmt_stypes[ift].tx; | |
1180 | while (stypes) { | |
1181 | if ((stypes & 1) && | |
1182 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1183 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1184 | return -ENOBUFS; | |
1185 | stypes >>= 1; | |
1186 | i++; | |
ee688b00 | 1187 | } |
3713b4e3 JB |
1188 | nla_nest_end(msg, nl_ftypes); |
1189 | } | |
ee688b00 | 1190 | |
3713b4e3 | 1191 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1192 | |
3713b4e3 JB |
1193 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1194 | if (!nl_ifs) | |
1195 | return -ENOBUFS; | |
ee688b00 | 1196 | |
3713b4e3 JB |
1197 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1198 | nl_ftypes = nla_nest_start(msg, ift); | |
1199 | if (!nl_ftypes) | |
1200 | return -ENOBUFS; | |
1201 | i = 0; | |
1202 | stypes = mgmt_stypes[ift].rx; | |
1203 | while (stypes) { | |
1204 | if ((stypes & 1) && | |
1205 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1206 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1207 | return -ENOBUFS; | |
1208 | stypes >>= 1; | |
1209 | i++; | |
1210 | } | |
1211 | nla_nest_end(msg, nl_ftypes); | |
1212 | } | |
1213 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1214 | |
3713b4e3 JB |
1215 | return 0; |
1216 | } | |
ee688b00 | 1217 | |
86e8cf98 JB |
1218 | struct nl80211_dump_wiphy_state { |
1219 | s64 filter_wiphy; | |
1220 | long start; | |
1221 | long split_start, band_start, chan_start; | |
1222 | bool split; | |
1223 | }; | |
1224 | ||
1b8ec87a | 1225 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3713b4e3 | 1226 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1227 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1228 | { |
1229 | void *hdr; | |
1230 | struct nlattr *nl_bands, *nl_band; | |
1231 | struct nlattr *nl_freqs, *nl_freq; | |
1232 | struct nlattr *nl_cmds; | |
1233 | enum ieee80211_band band; | |
1234 | struct ieee80211_channel *chan; | |
1235 | int i; | |
1236 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1237 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1238 | u32 features; |
ee688b00 | 1239 | |
3713b4e3 JB |
1240 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1241 | if (!hdr) | |
1242 | return -ENOBUFS; | |
ee688b00 | 1243 | |
86e8cf98 JB |
1244 | if (WARN_ON(!state)) |
1245 | return -EINVAL; | |
ee688b00 | 1246 | |
1b8ec87a | 1247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1248 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1249 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1250 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1251 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1252 | goto nla_put_failure; |
1253 | ||
86e8cf98 | 1254 | switch (state->split_start) { |
3713b4e3 JB |
1255 | case 0: |
1256 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1257 | rdev->wiphy.retry_short) || |
3713b4e3 | 1258 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1259 | rdev->wiphy.retry_long) || |
3713b4e3 | 1260 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1261 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1262 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1263 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1264 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1265 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1266 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1267 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1268 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1269 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1270 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1271 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1272 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1273 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1274 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1275 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1276 | goto nla_put_failure; |
3713b4e3 | 1277 | |
1b8ec87a | 1278 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1279 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1280 | goto nla_put_failure; |
1b8ec87a | 1281 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1282 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1283 | goto nla_put_failure; | |
1b8ec87a | 1284 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1285 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1286 | goto nla_put_failure; | |
1b8ec87a | 1287 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1288 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1289 | goto nla_put_failure; | |
1b8ec87a | 1290 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1291 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1292 | goto nla_put_failure; | |
1b8ec87a | 1293 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1294 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1295 | goto nla_put_failure; |
86e8cf98 JB |
1296 | state->split_start++; |
1297 | if (state->split) | |
3713b4e3 JB |
1298 | break; |
1299 | case 1: | |
1300 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1301 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1302 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1303 | goto nla_put_failure; |
4745fc09 | 1304 | |
3713b4e3 | 1305 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1306 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1307 | goto nla_put_failure; |
b23aa676 | 1308 | |
1b8ec87a | 1309 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1310 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1311 | goto nla_put_failure; |
b23aa676 | 1312 | |
3713b4e3 | 1313 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1314 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1315 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1316 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1317 | goto nla_put_failure; |
b23aa676 | 1318 | |
1b8ec87a | 1319 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1320 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1321 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1322 | goto nla_put_failure; |
8fdc621d | 1323 | |
1b8ec87a ZG |
1324 | if ((rdev->wiphy.available_antennas_tx || |
1325 | rdev->wiphy.available_antennas_rx) && | |
1326 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1327 | u32 tx_ant = 0, rx_ant = 0; |
1328 | int res; | |
1b8ec87a | 1329 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1330 | if (!res) { |
1331 | if (nla_put_u32(msg, | |
1332 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1333 | tx_ant) || | |
1334 | nla_put_u32(msg, | |
1335 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1336 | rx_ant)) | |
1337 | goto nla_put_failure; | |
1338 | } | |
1339 | } | |
a293911d | 1340 | |
86e8cf98 JB |
1341 | state->split_start++; |
1342 | if (state->split) | |
3713b4e3 JB |
1343 | break; |
1344 | case 2: | |
1345 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1346 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1347 | goto nla_put_failure; |
86e8cf98 JB |
1348 | state->split_start++; |
1349 | if (state->split) | |
3713b4e3 JB |
1350 | break; |
1351 | case 3: | |
1352 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1353 | if (!nl_bands) | |
1354 | goto nla_put_failure; | |
f7ca38df | 1355 | |
86e8cf98 JB |
1356 | for (band = state->band_start; |
1357 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1358 | struct ieee80211_supported_band *sband; |
2e161f78 | 1359 | |
1b8ec87a | 1360 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1361 | |
3713b4e3 JB |
1362 | if (!sband) |
1363 | continue; | |
1364 | ||
1365 | nl_band = nla_nest_start(msg, band); | |
1366 | if (!nl_band) | |
2e161f78 | 1367 | goto nla_put_failure; |
3713b4e3 | 1368 | |
86e8cf98 | 1369 | switch (state->chan_start) { |
3713b4e3 JB |
1370 | case 0: |
1371 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1372 | goto nla_put_failure; |
86e8cf98 JB |
1373 | state->chan_start++; |
1374 | if (state->split) | |
3713b4e3 JB |
1375 | break; |
1376 | default: | |
1377 | /* add frequencies */ | |
1378 | nl_freqs = nla_nest_start( | |
1379 | msg, NL80211_BAND_ATTR_FREQS); | |
1380 | if (!nl_freqs) | |
1381 | goto nla_put_failure; | |
1382 | ||
86e8cf98 | 1383 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1384 | i < sband->n_channels; |
1385 | i++) { | |
1386 | nl_freq = nla_nest_start(msg, i); | |
1387 | if (!nl_freq) | |
1388 | goto nla_put_failure; | |
1389 | ||
1390 | chan = &sband->channels[i]; | |
1391 | ||
86e8cf98 JB |
1392 | if (nl80211_msg_put_channel( |
1393 | msg, chan, | |
1394 | state->split)) | |
3713b4e3 JB |
1395 | goto nla_put_failure; |
1396 | ||
1397 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1398 | if (state->split) |
3713b4e3 JB |
1399 | break; |
1400 | } | |
1401 | if (i < sband->n_channels) | |
86e8cf98 | 1402 | state->chan_start = i + 2; |
3713b4e3 | 1403 | else |
86e8cf98 | 1404 | state->chan_start = 0; |
3713b4e3 JB |
1405 | nla_nest_end(msg, nl_freqs); |
1406 | } | |
1407 | ||
1408 | nla_nest_end(msg, nl_band); | |
1409 | ||
86e8cf98 | 1410 | if (state->split) { |
3713b4e3 | 1411 | /* start again here */ |
86e8cf98 | 1412 | if (state->chan_start) |
3713b4e3 JB |
1413 | band--; |
1414 | break; | |
2e161f78 | 1415 | } |
2e161f78 | 1416 | } |
3713b4e3 | 1417 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1418 | |
3713b4e3 | 1419 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1420 | state->band_start = band + 1; |
3713b4e3 | 1421 | else |
86e8cf98 | 1422 | state->band_start = 0; |
74b70a4e | 1423 | |
3713b4e3 | 1424 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1425 | if (state->band_start == 0 && state->chan_start == 0) |
1426 | state->split_start++; | |
1427 | if (state->split) | |
3713b4e3 JB |
1428 | break; |
1429 | case 4: | |
1430 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1431 | if (!nl_cmds) | |
2e161f78 JB |
1432 | goto nla_put_failure; |
1433 | ||
3713b4e3 JB |
1434 | i = 0; |
1435 | #define CMD(op, n) \ | |
1436 | do { \ | |
1b8ec87a | 1437 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1438 | i++; \ |
1439 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1440 | goto nla_put_failure; \ | |
1441 | } \ | |
1442 | } while (0) | |
1443 | ||
1444 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1445 | CMD(change_virtual_intf, SET_INTERFACE); | |
1446 | CMD(add_key, NEW_KEY); | |
1447 | CMD(start_ap, START_AP); | |
1448 | CMD(add_station, NEW_STATION); | |
1449 | CMD(add_mpath, NEW_MPATH); | |
1450 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1451 | CMD(change_bss, SET_BSS); | |
1452 | CMD(auth, AUTHENTICATE); | |
1453 | CMD(assoc, ASSOCIATE); | |
1454 | CMD(deauth, DEAUTHENTICATE); | |
1455 | CMD(disassoc, DISASSOCIATE); | |
1456 | CMD(join_ibss, JOIN_IBSS); | |
1457 | CMD(join_mesh, JOIN_MESH); | |
1458 | CMD(set_pmksa, SET_PMKSA); | |
1459 | CMD(del_pmksa, DEL_PMKSA); | |
1460 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1461 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1462 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1463 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1464 | CMD(mgmt_tx, FRAME); | |
1465 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1466 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1467 | i++; |
1468 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1469 | goto nla_put_failure; |
2e161f78 | 1470 | } |
1b8ec87a ZG |
1471 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1472 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1473 | i++; |
1474 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1475 | goto nla_put_failure; | |
1476 | } | |
1477 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1478 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1479 | CMD(tdls_mgmt, TDLS_MGMT); |
1480 | CMD(tdls_oper, TDLS_OPER); | |
1481 | } | |
1b8ec87a | 1482 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1483 | CMD(sched_scan_start, START_SCHED_SCAN); |
1484 | CMD(probe_client, PROBE_CLIENT); | |
1485 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1486 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1487 | i++; |
1488 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1489 | goto nla_put_failure; | |
1490 | } | |
1491 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1492 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
86e8cf98 | 1493 | if (state->split) { |
5de17984 AS |
1494 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1495 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1496 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1497 | CMD(channel_switch, CHANNEL_SWITCH); |
5de17984 | 1498 | } |
fa9ffc74 | 1499 | CMD(set_qos_map, SET_QOS_MAP); |
2e161f78 | 1500 | |
3713b4e3 JB |
1501 | #ifdef CONFIG_NL80211_TESTMODE |
1502 | CMD(testmode_cmd, TESTMODE); | |
1503 | #endif | |
ff1b6e69 | 1504 | |
3713b4e3 | 1505 | #undef CMD |
ff1b6e69 | 1506 | |
1b8ec87a | 1507 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1508 | i++; |
1509 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1510 | goto nla_put_failure; |
ff1b6e69 JB |
1511 | } |
1512 | ||
1b8ec87a | 1513 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1514 | i++; |
1515 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1516 | goto nla_put_failure; | |
1517 | } | |
1518 | ||
1519 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1520 | state->split_start++; |
1521 | if (state->split) | |
3713b4e3 JB |
1522 | break; |
1523 | case 5: | |
1b8ec87a ZG |
1524 | if (rdev->ops->remain_on_channel && |
1525 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1526 | nla_put_u32(msg, |
1527 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1528 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1529 | goto nla_put_failure; |
1530 | ||
1b8ec87a | 1531 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1532 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1533 | goto nla_put_failure; | |
1534 | ||
1535 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1536 | goto nla_put_failure; | |
86e8cf98 JB |
1537 | state->split_start++; |
1538 | if (state->split) | |
3713b4e3 JB |
1539 | break; |
1540 | case 6: | |
1541 | #ifdef CONFIG_PM | |
1b8ec87a | 1542 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1543 | goto nla_put_failure; |
86e8cf98 JB |
1544 | state->split_start++; |
1545 | if (state->split) | |
3713b4e3 JB |
1546 | break; |
1547 | #else | |
86e8cf98 | 1548 | state->split_start++; |
dfb89c56 | 1549 | #endif |
3713b4e3 JB |
1550 | case 7: |
1551 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1552 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1553 | goto nla_put_failure; |
ff1b6e69 | 1554 | |
1b8ec87a | 1555 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1556 | state->split)) |
3713b4e3 | 1557 | goto nla_put_failure; |
7527a782 | 1558 | |
86e8cf98 JB |
1559 | state->split_start++; |
1560 | if (state->split) | |
3713b4e3 JB |
1561 | break; |
1562 | case 8: | |
1b8ec87a | 1563 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1564 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1565 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1566 | goto nla_put_failure; |
7527a782 | 1567 | |
1b8ec87a | 1568 | features = rdev->wiphy.features; |
fe1abafd JB |
1569 | /* |
1570 | * We can only add the per-channel limit information if the | |
1571 | * dump is split, otherwise it makes it too big. Therefore | |
1572 | * only advertise it in that case. | |
1573 | */ | |
86e8cf98 | 1574 | if (state->split) |
fe1abafd JB |
1575 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1576 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1577 | goto nla_put_failure; |
562a7480 | 1578 | |
1b8ec87a | 1579 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1580 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1581 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1582 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1583 | goto nla_put_failure; |
1f074bd8 | 1584 | |
1b8ec87a ZG |
1585 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1586 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1587 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1588 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1589 | goto nla_put_failure; |
7e7c8926 | 1590 | |
3713b4e3 JB |
1591 | /* |
1592 | * Any information below this point is only available to | |
1593 | * applications that can deal with it being split. This | |
1594 | * helps ensure that newly added capabilities don't break | |
1595 | * older tools by overrunning their buffers. | |
1596 | * | |
1597 | * We still increment split_start so that in the split | |
1598 | * case we'll continue with more data in the next round, | |
1599 | * but break unconditionally so unsplit data stops here. | |
1600 | */ | |
86e8cf98 | 1601 | state->split_start++; |
3713b4e3 JB |
1602 | break; |
1603 | case 9: | |
1b8ec87a | 1604 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1605 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1606 | rdev->wiphy.extended_capabilities_len, |
1607 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1608 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1609 | rdev->wiphy.extended_capabilities_len, |
1610 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1611 | goto nla_put_failure; |
a50df0c4 | 1612 | |
1b8ec87a | 1613 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1614 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1615 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1616 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1617 | goto nla_put_failure; |
1618 | ||
be29b99a AK |
1619 | state->split_start++; |
1620 | break; | |
1621 | case 10: | |
1b8ec87a | 1622 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1623 | goto nla_put_failure; |
1624 | ||
1b8ec87a | 1625 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1626 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1627 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1628 | goto nla_put_failure; | |
b43504cf | 1629 | |
1b8ec87a | 1630 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1631 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1632 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1633 | goto nla_put_failure; |
1634 | ||
ad7e718c JB |
1635 | state->split_start++; |
1636 | break; | |
1637 | case 11: | |
1b8ec87a | 1638 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1639 | const struct nl80211_vendor_cmd_info *info; |
1640 | struct nlattr *nested; | |
1641 | ||
1642 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1643 | if (!nested) | |
1644 | goto nla_put_failure; | |
1645 | ||
1b8ec87a ZG |
1646 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1647 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1648 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1649 | goto nla_put_failure; | |
1650 | } | |
1651 | nla_nest_end(msg, nested); | |
1652 | } | |
1653 | ||
1b8ec87a | 1654 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1655 | const struct nl80211_vendor_cmd_info *info; |
1656 | struct nlattr *nested; | |
ad7e718c | 1657 | |
567ffc35 JB |
1658 | nested = nla_nest_start(msg, |
1659 | NL80211_ATTR_VENDOR_EVENTS); | |
1660 | if (!nested) | |
ad7e718c | 1661 | goto nla_put_failure; |
567ffc35 | 1662 | |
1b8ec87a ZG |
1663 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1664 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1665 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1666 | goto nla_put_failure; | |
1667 | } | |
1668 | nla_nest_end(msg, nested); | |
1669 | } | |
01e0daa4 | 1670 | |
3713b4e3 | 1671 | /* done */ |
86e8cf98 | 1672 | state->split_start = 0; |
3713b4e3 JB |
1673 | break; |
1674 | } | |
55682965 JB |
1675 | return genlmsg_end(msg, hdr); |
1676 | ||
1677 | nla_put_failure: | |
bc3ed28c TG |
1678 | genlmsg_cancel(msg, hdr); |
1679 | return -EMSGSIZE; | |
55682965 JB |
1680 | } |
1681 | ||
86e8cf98 JB |
1682 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1683 | struct netlink_callback *cb, | |
1684 | struct nl80211_dump_wiphy_state *state) | |
1685 | { | |
1686 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1687 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1688 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1689 | /* ignore parse errors for backward compatibility */ | |
1690 | if (ret) | |
1691 | return 0; | |
1692 | ||
1693 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1694 | if (tb[NL80211_ATTR_WIPHY]) | |
1695 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1696 | if (tb[NL80211_ATTR_WDEV]) | |
1697 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1698 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1699 | struct net_device *netdev; | |
1700 | struct cfg80211_registered_device *rdev; | |
1701 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1702 | ||
7f2b8562 | 1703 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1704 | if (!netdev) |
1705 | return -ENODEV; | |
1706 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1707 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1708 | netdev->ieee80211_ptr->wiphy); |
1709 | state->filter_wiphy = rdev->wiphy_idx; | |
1710 | } | |
86e8cf98 JB |
1711 | } |
1712 | ||
1713 | return 0; | |
1714 | } | |
1715 | ||
55682965 JB |
1716 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1717 | { | |
645e77de | 1718 | int idx = 0, ret; |
86e8cf98 | 1719 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1720 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1721 | |
5fe231e8 | 1722 | rtnl_lock(); |
86e8cf98 JB |
1723 | if (!state) { |
1724 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1725 | if (!state) { |
1726 | rtnl_unlock(); | |
86e8cf98 | 1727 | return -ENOMEM; |
3713b4e3 | 1728 | } |
86e8cf98 JB |
1729 | state->filter_wiphy = -1; |
1730 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1731 | if (ret) { | |
1732 | kfree(state); | |
1733 | rtnl_unlock(); | |
1734 | return ret; | |
3713b4e3 | 1735 | } |
86e8cf98 | 1736 | cb->args[0] = (long)state; |
3713b4e3 JB |
1737 | } |
1738 | ||
1b8ec87a ZG |
1739 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1740 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1741 | continue; |
86e8cf98 | 1742 | if (++idx <= state->start) |
55682965 | 1743 | continue; |
86e8cf98 | 1744 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1745 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1746 | continue; |
1747 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1748 | do { | |
1b8ec87a | 1749 | ret = nl80211_send_wiphy(rdev, skb, |
3713b4e3 JB |
1750 | NETLINK_CB(cb->skb).portid, |
1751 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1752 | NLM_F_MULTI, state); |
3713b4e3 JB |
1753 | if (ret < 0) { |
1754 | /* | |
1755 | * If sending the wiphy data didn't fit (ENOBUFS | |
1756 | * or EMSGSIZE returned), this SKB is still | |
1757 | * empty (so it's not too big because another | |
1758 | * wiphy dataset is already in the skb) and | |
1759 | * we've not tried to adjust the dump allocation | |
1760 | * yet ... then adjust the alloc size to be | |
1761 | * bigger, and return 1 but with the empty skb. | |
1762 | * This results in an empty message being RX'ed | |
1763 | * in userspace, but that is ignored. | |
1764 | * | |
1765 | * We can then retry with the larger buffer. | |
1766 | */ | |
1767 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1768 | !skb->len && !state->split && |
3713b4e3 JB |
1769 | cb->min_dump_alloc < 4096) { |
1770 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1771 | state->split_start = 0; |
d98cae64 | 1772 | rtnl_unlock(); |
3713b4e3 JB |
1773 | return 1; |
1774 | } | |
1775 | idx--; | |
1776 | break; | |
645e77de | 1777 | } |
86e8cf98 | 1778 | } while (state->split_start > 0); |
3713b4e3 | 1779 | break; |
55682965 | 1780 | } |
5fe231e8 | 1781 | rtnl_unlock(); |
55682965 | 1782 | |
86e8cf98 | 1783 | state->start = idx; |
55682965 JB |
1784 | |
1785 | return skb->len; | |
1786 | } | |
1787 | ||
86e8cf98 JB |
1788 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1789 | { | |
1790 | kfree((void *)cb->args[0]); | |
1791 | return 0; | |
1792 | } | |
1793 | ||
55682965 JB |
1794 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1795 | { | |
1796 | struct sk_buff *msg; | |
1b8ec87a | 1797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1798 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1799 | |
645e77de | 1800 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1801 | if (!msg) |
4c476991 | 1802 | return -ENOMEM; |
55682965 | 1803 | |
1b8ec87a | 1804 | if (nl80211_send_wiphy(rdev, msg, info->snd_portid, info->snd_seq, 0, |
86e8cf98 | 1805 | &state) < 0) { |
4c476991 JB |
1806 | nlmsg_free(msg); |
1807 | return -ENOBUFS; | |
1808 | } | |
55682965 | 1809 | |
134e6375 | 1810 | return genlmsg_reply(msg, info); |
55682965 JB |
1811 | } |
1812 | ||
31888487 JM |
1813 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1814 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1815 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1816 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1817 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1818 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1819 | }; | |
1820 | ||
1821 | static int parse_txq_params(struct nlattr *tb[], | |
1822 | struct ieee80211_txq_params *txq_params) | |
1823 | { | |
a3304b0a | 1824 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1825 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1826 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1827 | return -EINVAL; | |
1828 | ||
a3304b0a | 1829 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1830 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1831 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1832 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1833 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1834 | ||
a3304b0a JB |
1835 | if (txq_params->ac >= NL80211_NUM_ACS) |
1836 | return -EINVAL; | |
1837 | ||
31888487 JM |
1838 | return 0; |
1839 | } | |
1840 | ||
f444de05 JB |
1841 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1842 | { | |
1843 | /* | |
cc1d2806 JB |
1844 | * You can only set the channel explicitly for WDS interfaces, |
1845 | * all others have their channel managed via their respective | |
1846 | * "establish a connection" command (connect, join, ...) | |
1847 | * | |
1848 | * For AP/GO and mesh mode, the channel can be set with the | |
1849 | * channel userspace API, but is only stored and passed to the | |
1850 | * low-level driver when the AP starts or the mesh is joined. | |
1851 | * This is for backward compatibility, userspace can also give | |
1852 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1853 | * |
1854 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1855 | * whatever else is going on, so they have their own special |
1856 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1857 | */ |
1858 | return !wdev || | |
1859 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1860 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1861 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1862 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1863 | } |
1864 | ||
683b6d3b JB |
1865 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1866 | struct genl_info *info, | |
1867 | struct cfg80211_chan_def *chandef) | |
1868 | { | |
dbeca2ea | 1869 | u32 control_freq; |
683b6d3b JB |
1870 | |
1871 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1872 | return -EINVAL; | |
1873 | ||
1874 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1875 | ||
1876 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1877 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1878 | chandef->center_freq1 = control_freq; | |
1879 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1880 | |
1881 | /* Primary channel not allowed */ | |
1882 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1883 | return -EINVAL; | |
1884 | ||
3d9d1d66 JB |
1885 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1886 | enum nl80211_channel_type chantype; | |
1887 | ||
1888 | chantype = nla_get_u32( | |
1889 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1890 | ||
1891 | switch (chantype) { | |
1892 | case NL80211_CHAN_NO_HT: | |
1893 | case NL80211_CHAN_HT20: | |
1894 | case NL80211_CHAN_HT40PLUS: | |
1895 | case NL80211_CHAN_HT40MINUS: | |
1896 | cfg80211_chandef_create(chandef, chandef->chan, | |
1897 | chantype); | |
1898 | break; | |
1899 | default: | |
1900 | return -EINVAL; | |
1901 | } | |
1902 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1903 | chandef->width = | |
1904 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1905 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1906 | chandef->center_freq1 = | |
1907 | nla_get_u32( | |
1908 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1909 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1910 | chandef->center_freq2 = | |
1911 | nla_get_u32( | |
1912 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1913 | } | |
1914 | ||
9f5e8f6e | 1915 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1916 | return -EINVAL; |
1917 | ||
9f5e8f6e JB |
1918 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1919 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1920 | return -EINVAL; |
1921 | ||
2f301ab2 SW |
1922 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1923 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1924 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1925 | return -EINVAL; | |
1926 | ||
683b6d3b JB |
1927 | return 0; |
1928 | } | |
1929 | ||
f444de05 | 1930 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1931 | struct net_device *dev, |
f444de05 JB |
1932 | struct genl_info *info) |
1933 | { | |
683b6d3b | 1934 | struct cfg80211_chan_def chandef; |
f444de05 | 1935 | int result; |
e8c9bd5b | 1936 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1937 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1938 | |
e16821bc JM |
1939 | if (dev) |
1940 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1941 | if (!nl80211_can_set_dev_channel(wdev)) |
1942 | return -EOPNOTSUPP; | |
e16821bc JM |
1943 | if (wdev) |
1944 | iftype = wdev->iftype; | |
f444de05 | 1945 | |
683b6d3b JB |
1946 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1947 | if (result) | |
1948 | return result; | |
f444de05 | 1949 | |
e8c9bd5b | 1950 | switch (iftype) { |
aa430da4 JB |
1951 | case NL80211_IFTYPE_AP: |
1952 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 1953 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
1954 | result = -EINVAL; |
1955 | break; | |
1956 | } | |
e16821bc JM |
1957 | if (wdev->beacon_interval) { |
1958 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
1959 | !(rdev->wiphy.features & | |
1960 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
1961 | result = -EBUSY; | |
1962 | break; | |
1963 | } | |
1964 | ||
1965 | /* Only allow dynamic channel width changes */ | |
1966 | if (chandef.chan != wdev->preset_chandef.chan) { | |
1967 | result = -EBUSY; | |
1968 | break; | |
1969 | } | |
1970 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
1971 | if (result) | |
1972 | break; | |
1973 | } | |
683b6d3b | 1974 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1975 | result = 0; |
1976 | break; | |
cc1d2806 | 1977 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1978 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1979 | break; |
e8c9bd5b | 1980 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1981 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1982 | break; |
aa430da4 | 1983 | default: |
e8c9bd5b | 1984 | result = -EINVAL; |
f444de05 | 1985 | } |
f444de05 JB |
1986 | |
1987 | return result; | |
1988 | } | |
1989 | ||
1990 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1991 | { | |
4c476991 JB |
1992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1993 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1994 | |
e16821bc | 1995 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
1996 | } |
1997 | ||
e8347eba BJ |
1998 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1999 | { | |
43b19952 JB |
2000 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2001 | struct net_device *dev = info->user_ptr[1]; | |
2002 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2003 | const u8 *bssid; |
e8347eba BJ |
2004 | |
2005 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2006 | return -EINVAL; | |
2007 | ||
43b19952 JB |
2008 | if (netif_running(dev)) |
2009 | return -EBUSY; | |
e8347eba | 2010 | |
43b19952 JB |
2011 | if (!rdev->ops->set_wds_peer) |
2012 | return -EOPNOTSUPP; | |
e8347eba | 2013 | |
43b19952 JB |
2014 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2015 | return -EOPNOTSUPP; | |
e8347eba BJ |
2016 | |
2017 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2018 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2019 | } |
2020 | ||
2021 | ||
55682965 JB |
2022 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2023 | { | |
2024 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2025 | struct net_device *netdev = NULL; |
2026 | struct wireless_dev *wdev; | |
a1e567c8 | 2027 | int result = 0, rem_txq_params = 0; |
31888487 | 2028 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2029 | u32 changed; |
2030 | u8 retry_short = 0, retry_long = 0; | |
2031 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2032 | u8 coverage_class = 0; |
55682965 | 2033 | |
5fe231e8 JB |
2034 | ASSERT_RTNL(); |
2035 | ||
f444de05 JB |
2036 | /* |
2037 | * Try to find the wiphy and netdev. Normally this | |
2038 | * function shouldn't need the netdev, but this is | |
2039 | * done for backward compatibility -- previously | |
2040 | * setting the channel was done per wiphy, but now | |
2041 | * it is per netdev. Previous userland like hostapd | |
2042 | * also passed a netdev to set_wiphy, so that it is | |
2043 | * possible to let that go to the right netdev! | |
2044 | */ | |
4bbf4d56 | 2045 | |
f444de05 JB |
2046 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2047 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2048 | ||
7f2b8562 | 2049 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2050 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2051 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2052 | else |
f444de05 | 2053 | netdev = NULL; |
4bbf4d56 JB |
2054 | } |
2055 | ||
f444de05 | 2056 | if (!netdev) { |
878d9ec7 JB |
2057 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2058 | info->attrs); | |
5fe231e8 | 2059 | if (IS_ERR(rdev)) |
4c476991 | 2060 | return PTR_ERR(rdev); |
f444de05 JB |
2061 | wdev = NULL; |
2062 | netdev = NULL; | |
2063 | result = 0; | |
71fe96bf | 2064 | } else |
f444de05 | 2065 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2066 | |
2067 | /* | |
2068 | * end workaround code, by now the rdev is available | |
2069 | * and locked, and wdev may or may not be NULL. | |
2070 | */ | |
4bbf4d56 JB |
2071 | |
2072 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2073 | result = cfg80211_dev_rename( |
2074 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2075 | |
4bbf4d56 | 2076 | if (result) |
7f2b8562 | 2077 | return result; |
31888487 JM |
2078 | |
2079 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2080 | struct ieee80211_txq_params txq_params; | |
2081 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2082 | ||
7f2b8562 YX |
2083 | if (!rdev->ops->set_txq_params) |
2084 | return -EOPNOTSUPP; | |
31888487 | 2085 | |
7f2b8562 YX |
2086 | if (!netdev) |
2087 | return -EINVAL; | |
f70f01c2 | 2088 | |
133a3ff2 | 2089 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2090 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2091 | return -EINVAL; | |
133a3ff2 | 2092 | |
7f2b8562 YX |
2093 | if (!netif_running(netdev)) |
2094 | return -ENETDOWN; | |
2b5f8b0b | 2095 | |
31888487 JM |
2096 | nla_for_each_nested(nl_txq_params, |
2097 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2098 | rem_txq_params) { | |
ae811e21 JB |
2099 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2100 | nla_data(nl_txq_params), | |
2101 | nla_len(nl_txq_params), | |
2102 | txq_params_policy); | |
2103 | if (result) | |
2104 | return result; | |
31888487 JM |
2105 | result = parse_txq_params(tb, &txq_params); |
2106 | if (result) | |
7f2b8562 | 2107 | return result; |
31888487 | 2108 | |
e35e4d28 HG |
2109 | result = rdev_set_txq_params(rdev, netdev, |
2110 | &txq_params); | |
31888487 | 2111 | if (result) |
7f2b8562 | 2112 | return result; |
31888487 JM |
2113 | } |
2114 | } | |
55682965 | 2115 | |
72bdcf34 | 2116 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2117 | result = __nl80211_set_channel( |
2118 | rdev, | |
2119 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2120 | info); | |
72bdcf34 | 2121 | if (result) |
7f2b8562 | 2122 | return result; |
72bdcf34 JM |
2123 | } |
2124 | ||
98d2ff8b | 2125 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2126 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2127 | enum nl80211_tx_power_setting type; |
2128 | int idx, mbm = 0; | |
2129 | ||
c8442118 JB |
2130 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2131 | txp_wdev = NULL; | |
2132 | ||
7f2b8562 YX |
2133 | if (!rdev->ops->set_tx_power) |
2134 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2135 | |
2136 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2137 | type = nla_get_u32(info->attrs[idx]); | |
2138 | ||
2139 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2140 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2141 | return -EINVAL; | |
98d2ff8b JO |
2142 | |
2143 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2144 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2145 | mbm = nla_get_u32(info->attrs[idx]); | |
2146 | } | |
2147 | ||
c8442118 | 2148 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2149 | if (result) |
7f2b8562 | 2150 | return result; |
98d2ff8b JO |
2151 | } |
2152 | ||
afe0cbf8 BR |
2153 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2154 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2155 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2156 | if ((!rdev->wiphy.available_antennas_tx && |
2157 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2158 | !rdev->ops->set_antenna) |
2159 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2160 | |
2161 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2162 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2163 | ||
a7ffac95 | 2164 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2165 | * available antenna masks, except for the "all" mask */ |
2166 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2167 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2168 | return -EINVAL; | |
a7ffac95 | 2169 | |
7f531e03 BR |
2170 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2171 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2172 | |
e35e4d28 | 2173 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2174 | if (result) |
7f2b8562 | 2175 | return result; |
afe0cbf8 BR |
2176 | } |
2177 | ||
b9a5f8ca JM |
2178 | changed = 0; |
2179 | ||
2180 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2181 | retry_short = nla_get_u8( | |
2182 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2183 | if (retry_short == 0) |
2184 | return -EINVAL; | |
2185 | ||
b9a5f8ca JM |
2186 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2187 | } | |
2188 | ||
2189 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2190 | retry_long = nla_get_u8( | |
2191 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2192 | if (retry_long == 0) |
2193 | return -EINVAL; | |
2194 | ||
b9a5f8ca JM |
2195 | changed |= WIPHY_PARAM_RETRY_LONG; |
2196 | } | |
2197 | ||
2198 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2199 | frag_threshold = nla_get_u32( | |
2200 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2201 | if (frag_threshold < 256) |
2202 | return -EINVAL; | |
2203 | ||
b9a5f8ca JM |
2204 | if (frag_threshold != (u32) -1) { |
2205 | /* | |
2206 | * Fragments (apart from the last one) are required to | |
2207 | * have even length. Make the fragmentation code | |
2208 | * simpler by stripping LSB should someone try to use | |
2209 | * odd threshold value. | |
2210 | */ | |
2211 | frag_threshold &= ~0x1; | |
2212 | } | |
2213 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2214 | } | |
2215 | ||
2216 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2217 | rts_threshold = nla_get_u32( | |
2218 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2219 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2220 | } | |
2221 | ||
81077e82 LT |
2222 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2223 | coverage_class = nla_get_u8( | |
2224 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2225 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2226 | } | |
2227 | ||
b9a5f8ca JM |
2228 | if (changed) { |
2229 | u8 old_retry_short, old_retry_long; | |
2230 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2231 | u8 old_coverage_class; |
b9a5f8ca | 2232 | |
7f2b8562 YX |
2233 | if (!rdev->ops->set_wiphy_params) |
2234 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2235 | |
2236 | old_retry_short = rdev->wiphy.retry_short; | |
2237 | old_retry_long = rdev->wiphy.retry_long; | |
2238 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2239 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2240 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2241 | |
2242 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2243 | rdev->wiphy.retry_short = retry_short; | |
2244 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2245 | rdev->wiphy.retry_long = retry_long; | |
2246 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2247 | rdev->wiphy.frag_threshold = frag_threshold; | |
2248 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2249 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2250 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2251 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2252 | |
e35e4d28 | 2253 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2254 | if (result) { |
2255 | rdev->wiphy.retry_short = old_retry_short; | |
2256 | rdev->wiphy.retry_long = old_retry_long; | |
2257 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2258 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2259 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2260 | } |
2261 | } | |
7f2b8562 | 2262 | return 0; |
55682965 JB |
2263 | } |
2264 | ||
71bbc994 JB |
2265 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2266 | { | |
2267 | return (u64)wdev->identifier | | |
f26cbf40 | 2268 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2269 | } |
55682965 | 2270 | |
683b6d3b | 2271 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2272 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2273 | { |
9f5e8f6e | 2274 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2275 | |
683b6d3b JB |
2276 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2277 | chandef->chan->center_freq)) | |
2278 | return -ENOBUFS; | |
3d9d1d66 JB |
2279 | switch (chandef->width) { |
2280 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2281 | case NL80211_CHAN_WIDTH_20: | |
2282 | case NL80211_CHAN_WIDTH_40: | |
2283 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2284 | cfg80211_get_chandef_type(chandef))) | |
2285 | return -ENOBUFS; | |
2286 | break; | |
2287 | default: | |
2288 | break; | |
2289 | } | |
2290 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2291 | return -ENOBUFS; | |
2292 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2293 | return -ENOBUFS; | |
2294 | if (chandef->center_freq2 && | |
2295 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2296 | return -ENOBUFS; |
2297 | return 0; | |
2298 | } | |
2299 | ||
15e47304 | 2300 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2301 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2302 | struct wireless_dev *wdev) |
55682965 | 2303 | { |
72fb2abc | 2304 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2305 | void *hdr; |
2306 | ||
15e47304 | 2307 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2308 | if (!hdr) |
2309 | return -1; | |
2310 | ||
72fb2abc JB |
2311 | if (dev && |
2312 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2313 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2314 | goto nla_put_failure; |
2315 | ||
2316 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2317 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2318 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2319 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2320 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2321 | rdev->devlist_generation ^ | |
2322 | (cfg80211_rdev_list_generation << 2))) | |
2323 | goto nla_put_failure; | |
f5ea9120 | 2324 | |
5b7ccaf3 | 2325 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2326 | int ret; |
2327 | struct cfg80211_chan_def chandef; | |
2328 | ||
2329 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2330 | if (ret == 0) { | |
2331 | if (nl80211_send_chandef(msg, &chandef)) | |
2332 | goto nla_put_failure; | |
2333 | } | |
d91df0e3 PF |
2334 | } |
2335 | ||
b84e7a05 AQ |
2336 | if (wdev->ssid_len) { |
2337 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2338 | goto nla_put_failure; | |
2339 | } | |
2340 | ||
55682965 JB |
2341 | return genlmsg_end(msg, hdr); |
2342 | ||
2343 | nla_put_failure: | |
bc3ed28c TG |
2344 | genlmsg_cancel(msg, hdr); |
2345 | return -EMSGSIZE; | |
55682965 JB |
2346 | } |
2347 | ||
2348 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2349 | { | |
2350 | int wp_idx = 0; | |
2351 | int if_idx = 0; | |
2352 | int wp_start = cb->args[0]; | |
2353 | int if_start = cb->args[1]; | |
f5ea9120 | 2354 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2355 | struct wireless_dev *wdev; |
2356 | ||
5fe231e8 | 2357 | rtnl_lock(); |
f5ea9120 JB |
2358 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2359 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2360 | continue; |
bba95fef JB |
2361 | if (wp_idx < wp_start) { |
2362 | wp_idx++; | |
55682965 | 2363 | continue; |
bba95fef | 2364 | } |
55682965 JB |
2365 | if_idx = 0; |
2366 | ||
89a54e48 | 2367 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2368 | if (if_idx < if_start) { |
2369 | if_idx++; | |
55682965 | 2370 | continue; |
bba95fef | 2371 | } |
15e47304 | 2372 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2373 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2374 | rdev, wdev) < 0) { |
bba95fef JB |
2375 | goto out; |
2376 | } | |
2377 | if_idx++; | |
55682965 | 2378 | } |
bba95fef JB |
2379 | |
2380 | wp_idx++; | |
55682965 | 2381 | } |
bba95fef | 2382 | out: |
5fe231e8 | 2383 | rtnl_unlock(); |
55682965 JB |
2384 | |
2385 | cb->args[0] = wp_idx; | |
2386 | cb->args[1] = if_idx; | |
2387 | ||
2388 | return skb->len; | |
2389 | } | |
2390 | ||
2391 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2392 | { | |
2393 | struct sk_buff *msg; | |
1b8ec87a | 2394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2395 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2396 | |
fd2120ca | 2397 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2398 | if (!msg) |
4c476991 | 2399 | return -ENOMEM; |
55682965 | 2400 | |
15e47304 | 2401 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1b8ec87a | 2402 | rdev, wdev) < 0) { |
4c476991 JB |
2403 | nlmsg_free(msg); |
2404 | return -ENOBUFS; | |
2405 | } | |
55682965 | 2406 | |
134e6375 | 2407 | return genlmsg_reply(msg, info); |
55682965 JB |
2408 | } |
2409 | ||
66f7ac50 MW |
2410 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2411 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2412 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2413 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2414 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2415 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2416 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2417 | }; |
2418 | ||
2419 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2420 | { | |
2421 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2422 | int flag; | |
2423 | ||
2424 | *mntrflags = 0; | |
2425 | ||
2426 | if (!nla) | |
2427 | return -EINVAL; | |
2428 | ||
2429 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2430 | nla, mntr_flags_policy)) | |
2431 | return -EINVAL; | |
2432 | ||
2433 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2434 | if (flags[flag]) | |
2435 | *mntrflags |= (1<<flag); | |
2436 | ||
2437 | return 0; | |
2438 | } | |
2439 | ||
9bc383de | 2440 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2441 | struct net_device *netdev, u8 use_4addr, |
2442 | enum nl80211_iftype iftype) | |
9bc383de | 2443 | { |
ad4bb6f8 | 2444 | if (!use_4addr) { |
f350a0a8 | 2445 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2446 | return -EBUSY; |
9bc383de | 2447 | return 0; |
ad4bb6f8 | 2448 | } |
9bc383de JB |
2449 | |
2450 | switch (iftype) { | |
2451 | case NL80211_IFTYPE_AP_VLAN: | |
2452 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2453 | return 0; | |
2454 | break; | |
2455 | case NL80211_IFTYPE_STATION: | |
2456 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2457 | return 0; | |
2458 | break; | |
2459 | default: | |
2460 | break; | |
2461 | } | |
2462 | ||
2463 | return -EOPNOTSUPP; | |
2464 | } | |
2465 | ||
55682965 JB |
2466 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2467 | { | |
4c476991 | 2468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2469 | struct vif_params params; |
e36d56b6 | 2470 | int err; |
04a773ad | 2471 | enum nl80211_iftype otype, ntype; |
4c476991 | 2472 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2473 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2474 | bool change = false; |
55682965 | 2475 | |
2ec600d6 LCC |
2476 | memset(¶ms, 0, sizeof(params)); |
2477 | ||
04a773ad | 2478 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2479 | |
723b038d | 2480 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2481 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2482 | if (otype != ntype) |
ac7f9cfa | 2483 | change = true; |
4c476991 JB |
2484 | if (ntype > NL80211_IFTYPE_MAX) |
2485 | return -EINVAL; | |
723b038d JB |
2486 | } |
2487 | ||
92ffe055 | 2488 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2490 | ||
4c476991 JB |
2491 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2492 | return -EINVAL; | |
29cbe68c JB |
2493 | if (netif_running(dev)) |
2494 | return -EBUSY; | |
2495 | ||
2496 | wdev_lock(wdev); | |
2497 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2498 | IEEE80211_MAX_MESH_ID_LEN); | |
2499 | wdev->mesh_id_up_len = | |
2500 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2501 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2502 | wdev->mesh_id_up_len); | |
2503 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2504 | } |
2505 | ||
8b787643 FF |
2506 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2507 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2508 | change = true; | |
ad4bb6f8 | 2509 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2510 | if (err) |
4c476991 | 2511 | return err; |
8b787643 FF |
2512 | } else { |
2513 | params.use_4addr = -1; | |
2514 | } | |
2515 | ||
92ffe055 | 2516 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2517 | if (ntype != NL80211_IFTYPE_MONITOR) |
2518 | return -EINVAL; | |
92ffe055 JB |
2519 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2520 | &_flags); | |
ac7f9cfa | 2521 | if (err) |
4c476991 | 2522 | return err; |
ac7f9cfa JB |
2523 | |
2524 | flags = &_flags; | |
2525 | change = true; | |
92ffe055 | 2526 | } |
3b85875a | 2527 | |
18003297 | 2528 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2529 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2530 | return -EOPNOTSUPP; | |
2531 | ||
ac7f9cfa | 2532 | if (change) |
3d54d255 | 2533 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2534 | else |
2535 | err = 0; | |
60719ffd | 2536 | |
9bc383de JB |
2537 | if (!err && params.use_4addr != -1) |
2538 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2539 | ||
55682965 JB |
2540 | return err; |
2541 | } | |
2542 | ||
2543 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2544 | { | |
4c476991 | 2545 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2546 | struct vif_params params; |
84efbb84 | 2547 | struct wireless_dev *wdev; |
1c90f9d4 | 2548 | struct sk_buff *msg; |
55682965 JB |
2549 | int err; |
2550 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2551 | u32 flags; |
55682965 | 2552 | |
78f22b6a JB |
2553 | /* to avoid failing a new interface creation due to pending removal */ |
2554 | cfg80211_destroy_ifaces(rdev); | |
2555 | ||
2ec600d6 LCC |
2556 | memset(¶ms, 0, sizeof(params)); |
2557 | ||
55682965 JB |
2558 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2559 | return -EINVAL; | |
2560 | ||
2561 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2562 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2563 | if (type > NL80211_IFTYPE_MAX) | |
2564 | return -EINVAL; | |
2565 | } | |
2566 | ||
79c97e97 | 2567 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2568 | !(rdev->wiphy.interface_modes & (1 << type))) |
2569 | return -EOPNOTSUPP; | |
55682965 | 2570 | |
1c18f145 AS |
2571 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2572 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2573 | ETH_ALEN); | |
2574 | if (!is_valid_ether_addr(params.macaddr)) | |
2575 | return -EADDRNOTAVAIL; | |
2576 | } | |
2577 | ||
9bc383de | 2578 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2579 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2580 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2581 | if (err) |
4c476991 | 2582 | return err; |
9bc383de | 2583 | } |
8b787643 | 2584 | |
1c90f9d4 JB |
2585 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2586 | if (!msg) | |
2587 | return -ENOMEM; | |
2588 | ||
66f7ac50 MW |
2589 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2590 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2591 | &flags); | |
e057d3c3 | 2592 | |
18003297 | 2593 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2594 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2595 | return -EOPNOTSUPP; | |
2596 | ||
e35e4d28 HG |
2597 | wdev = rdev_add_virtual_intf(rdev, |
2598 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2599 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2600 | if (IS_ERR(wdev)) { |
2601 | nlmsg_free(msg); | |
84efbb84 | 2602 | return PTR_ERR(wdev); |
1c90f9d4 | 2603 | } |
2ec600d6 | 2604 | |
78f22b6a JB |
2605 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
2606 | wdev->owner_nlportid = info->snd_portid; | |
2607 | ||
98104fde JB |
2608 | switch (type) { |
2609 | case NL80211_IFTYPE_MESH_POINT: | |
2610 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2611 | break; | |
29cbe68c JB |
2612 | wdev_lock(wdev); |
2613 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2614 | IEEE80211_MAX_MESH_ID_LEN); | |
2615 | wdev->mesh_id_up_len = | |
2616 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2617 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2618 | wdev->mesh_id_up_len); | |
2619 | wdev_unlock(wdev); | |
98104fde JB |
2620 | break; |
2621 | case NL80211_IFTYPE_P2P_DEVICE: | |
2622 | /* | |
2623 | * P2P Device doesn't have a netdev, so doesn't go | |
2624 | * through the netdev notifier and must be added here | |
2625 | */ | |
2626 | mutex_init(&wdev->mtx); | |
2627 | INIT_LIST_HEAD(&wdev->event_list); | |
2628 | spin_lock_init(&wdev->event_lock); | |
2629 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2630 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2631 | ||
98104fde JB |
2632 | wdev->identifier = ++rdev->wdev_id; |
2633 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2634 | rdev->devlist_generation++; | |
98104fde JB |
2635 | break; |
2636 | default: | |
2637 | break; | |
29cbe68c JB |
2638 | } |
2639 | ||
15e47304 | 2640 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2641 | rdev, wdev) < 0) { |
2642 | nlmsg_free(msg); | |
2643 | return -ENOBUFS; | |
2644 | } | |
2645 | ||
2646 | return genlmsg_reply(msg, info); | |
55682965 JB |
2647 | } |
2648 | ||
2649 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2650 | { | |
4c476991 | 2651 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2652 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2653 | |
4c476991 JB |
2654 | if (!rdev->ops->del_virtual_intf) |
2655 | return -EOPNOTSUPP; | |
55682965 | 2656 | |
84efbb84 JB |
2657 | /* |
2658 | * If we remove a wireless device without a netdev then clear | |
2659 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2660 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2661 | * since the wdev has been freed, unlike with a netdev where | |
2662 | * we need the dev_put() for the netdev to really be freed. | |
2663 | */ | |
2664 | if (!wdev->netdev) | |
2665 | info->user_ptr[1] = NULL; | |
2666 | ||
e35e4d28 | 2667 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2668 | } |
2669 | ||
1d9d9213 SW |
2670 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2671 | { | |
2672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2673 | struct net_device *dev = info->user_ptr[1]; | |
2674 | u16 noack_map; | |
2675 | ||
2676 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2677 | return -EINVAL; | |
2678 | ||
2679 | if (!rdev->ops->set_noack_map) | |
2680 | return -EOPNOTSUPP; | |
2681 | ||
2682 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2683 | ||
e35e4d28 | 2684 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2685 | } |
2686 | ||
41ade00f JB |
2687 | struct get_key_cookie { |
2688 | struct sk_buff *msg; | |
2689 | int error; | |
b9454e83 | 2690 | int idx; |
41ade00f JB |
2691 | }; |
2692 | ||
2693 | static void get_key_callback(void *c, struct key_params *params) | |
2694 | { | |
b9454e83 | 2695 | struct nlattr *key; |
41ade00f JB |
2696 | struct get_key_cookie *cookie = c; |
2697 | ||
9360ffd1 DM |
2698 | if ((params->key && |
2699 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2700 | params->key_len, params->key)) || | |
2701 | (params->seq && | |
2702 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2703 | params->seq_len, params->seq)) || | |
2704 | (params->cipher && | |
2705 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2706 | params->cipher))) | |
2707 | goto nla_put_failure; | |
41ade00f | 2708 | |
b9454e83 JB |
2709 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2710 | if (!key) | |
2711 | goto nla_put_failure; | |
2712 | ||
9360ffd1 DM |
2713 | if ((params->key && |
2714 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2715 | params->key_len, params->key)) || | |
2716 | (params->seq && | |
2717 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2718 | params->seq_len, params->seq)) || | |
2719 | (params->cipher && | |
2720 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2721 | params->cipher))) | |
2722 | goto nla_put_failure; | |
b9454e83 | 2723 | |
9360ffd1 DM |
2724 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2725 | goto nla_put_failure; | |
b9454e83 JB |
2726 | |
2727 | nla_nest_end(cookie->msg, key); | |
2728 | ||
41ade00f JB |
2729 | return; |
2730 | nla_put_failure: | |
2731 | cookie->error = 1; | |
2732 | } | |
2733 | ||
2734 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2735 | { | |
4c476991 | 2736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2737 | int err; |
4c476991 | 2738 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2739 | u8 key_idx = 0; |
e31b8213 JB |
2740 | const u8 *mac_addr = NULL; |
2741 | bool pairwise; | |
41ade00f JB |
2742 | struct get_key_cookie cookie = { |
2743 | .error = 0, | |
2744 | }; | |
2745 | void *hdr; | |
2746 | struct sk_buff *msg; | |
2747 | ||
2748 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2749 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2750 | ||
3cfcf6ac | 2751 | if (key_idx > 5) |
41ade00f JB |
2752 | return -EINVAL; |
2753 | ||
2754 | if (info->attrs[NL80211_ATTR_MAC]) | |
2755 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2756 | ||
e31b8213 JB |
2757 | pairwise = !!mac_addr; |
2758 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2759 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2760 | if (kt >= NUM_NL80211_KEYTYPES) | |
2761 | return -EINVAL; | |
2762 | if (kt != NL80211_KEYTYPE_GROUP && | |
2763 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2764 | return -EINVAL; | |
2765 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2766 | } | |
2767 | ||
4c476991 JB |
2768 | if (!rdev->ops->get_key) |
2769 | return -EOPNOTSUPP; | |
41ade00f | 2770 | |
fd2120ca | 2771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2772 | if (!msg) |
2773 | return -ENOMEM; | |
41ade00f | 2774 | |
15e47304 | 2775 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2776 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2777 | if (!hdr) |
9fe271af | 2778 | goto nla_put_failure; |
41ade00f JB |
2779 | |
2780 | cookie.msg = msg; | |
b9454e83 | 2781 | cookie.idx = key_idx; |
41ade00f | 2782 | |
9360ffd1 DM |
2783 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2784 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2785 | goto nla_put_failure; | |
2786 | if (mac_addr && | |
2787 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2788 | goto nla_put_failure; | |
41ade00f | 2789 | |
e31b8213 JB |
2790 | if (pairwise && mac_addr && |
2791 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2792 | return -ENOENT; | |
2793 | ||
e35e4d28 HG |
2794 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2795 | get_key_callback); | |
41ade00f JB |
2796 | |
2797 | if (err) | |
6c95e2a2 | 2798 | goto free_msg; |
41ade00f JB |
2799 | |
2800 | if (cookie.error) | |
2801 | goto nla_put_failure; | |
2802 | ||
2803 | genlmsg_end(msg, hdr); | |
4c476991 | 2804 | return genlmsg_reply(msg, info); |
41ade00f JB |
2805 | |
2806 | nla_put_failure: | |
2807 | err = -ENOBUFS; | |
6c95e2a2 | 2808 | free_msg: |
41ade00f | 2809 | nlmsg_free(msg); |
41ade00f JB |
2810 | return err; |
2811 | } | |
2812 | ||
2813 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2814 | { | |
4c476991 | 2815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2816 | struct key_parse key; |
41ade00f | 2817 | int err; |
4c476991 | 2818 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2819 | |
b9454e83 JB |
2820 | err = nl80211_parse_key(info, &key); |
2821 | if (err) | |
2822 | return err; | |
41ade00f | 2823 | |
b9454e83 | 2824 | if (key.idx < 0) |
41ade00f JB |
2825 | return -EINVAL; |
2826 | ||
b9454e83 JB |
2827 | /* only support setting default key */ |
2828 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2829 | return -EINVAL; |
2830 | ||
dbd2fd65 | 2831 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2832 | |
dbd2fd65 JB |
2833 | if (key.def) { |
2834 | if (!rdev->ops->set_default_key) { | |
2835 | err = -EOPNOTSUPP; | |
2836 | goto out; | |
2837 | } | |
41ade00f | 2838 | |
dbd2fd65 JB |
2839 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2840 | if (err) | |
2841 | goto out; | |
2842 | ||
e35e4d28 | 2843 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2844 | key.def_uni, key.def_multi); |
2845 | ||
2846 | if (err) | |
2847 | goto out; | |
fffd0934 | 2848 | |
3d23e349 | 2849 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2850 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2851 | #endif | |
2852 | } else { | |
2853 | if (key.def_uni || !key.def_multi) { | |
2854 | err = -EINVAL; | |
2855 | goto out; | |
2856 | } | |
2857 | ||
2858 | if (!rdev->ops->set_default_mgmt_key) { | |
2859 | err = -EOPNOTSUPP; | |
2860 | goto out; | |
2861 | } | |
2862 | ||
2863 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2864 | if (err) | |
2865 | goto out; | |
2866 | ||
e35e4d28 | 2867 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2868 | if (err) |
2869 | goto out; | |
2870 | ||
2871 | #ifdef CONFIG_CFG80211_WEXT | |
2872 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2873 | #endif |
dbd2fd65 JB |
2874 | } |
2875 | ||
2876 | out: | |
fffd0934 | 2877 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2878 | |
41ade00f JB |
2879 | return err; |
2880 | } | |
2881 | ||
2882 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2883 | { | |
4c476991 | 2884 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2885 | int err; |
4c476991 | 2886 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2887 | struct key_parse key; |
e31b8213 | 2888 | const u8 *mac_addr = NULL; |
41ade00f | 2889 | |
b9454e83 JB |
2890 | err = nl80211_parse_key(info, &key); |
2891 | if (err) | |
2892 | return err; | |
41ade00f | 2893 | |
b9454e83 | 2894 | if (!key.p.key) |
41ade00f JB |
2895 | return -EINVAL; |
2896 | ||
41ade00f JB |
2897 | if (info->attrs[NL80211_ATTR_MAC]) |
2898 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2899 | ||
e31b8213 JB |
2900 | if (key.type == -1) { |
2901 | if (mac_addr) | |
2902 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2903 | else | |
2904 | key.type = NL80211_KEYTYPE_GROUP; | |
2905 | } | |
2906 | ||
2907 | /* for now */ | |
2908 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2909 | key.type != NL80211_KEYTYPE_GROUP) | |
2910 | return -EINVAL; | |
2911 | ||
4c476991 JB |
2912 | if (!rdev->ops->add_key) |
2913 | return -EOPNOTSUPP; | |
25e47c18 | 2914 | |
e31b8213 JB |
2915 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2916 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2917 | mac_addr)) | |
4c476991 | 2918 | return -EINVAL; |
41ade00f | 2919 | |
fffd0934 JB |
2920 | wdev_lock(dev->ieee80211_ptr); |
2921 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2922 | if (!err) | |
e35e4d28 HG |
2923 | err = rdev_add_key(rdev, dev, key.idx, |
2924 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2925 | mac_addr, &key.p); | |
fffd0934 | 2926 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2927 | |
41ade00f JB |
2928 | return err; |
2929 | } | |
2930 | ||
2931 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2932 | { | |
4c476991 | 2933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2934 | int err; |
4c476991 | 2935 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2936 | u8 *mac_addr = NULL; |
b9454e83 | 2937 | struct key_parse key; |
41ade00f | 2938 | |
b9454e83 JB |
2939 | err = nl80211_parse_key(info, &key); |
2940 | if (err) | |
2941 | return err; | |
41ade00f JB |
2942 | |
2943 | if (info->attrs[NL80211_ATTR_MAC]) | |
2944 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2945 | ||
e31b8213 JB |
2946 | if (key.type == -1) { |
2947 | if (mac_addr) | |
2948 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2949 | else | |
2950 | key.type = NL80211_KEYTYPE_GROUP; | |
2951 | } | |
2952 | ||
2953 | /* for now */ | |
2954 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2955 | key.type != NL80211_KEYTYPE_GROUP) | |
2956 | return -EINVAL; | |
2957 | ||
4c476991 JB |
2958 | if (!rdev->ops->del_key) |
2959 | return -EOPNOTSUPP; | |
41ade00f | 2960 | |
fffd0934 JB |
2961 | wdev_lock(dev->ieee80211_ptr); |
2962 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2963 | |
2964 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2965 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2966 | err = -ENOENT; | |
2967 | ||
fffd0934 | 2968 | if (!err) |
e35e4d28 HG |
2969 | err = rdev_del_key(rdev, dev, key.idx, |
2970 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2971 | mac_addr); | |
41ade00f | 2972 | |
3d23e349 | 2973 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2974 | if (!err) { |
b9454e83 | 2975 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2976 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2977 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2978 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2979 | } | |
2980 | #endif | |
fffd0934 | 2981 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2982 | |
41ade00f JB |
2983 | return err; |
2984 | } | |
2985 | ||
77765eaf VT |
2986 | /* This function returns an error or the number of nested attributes */ |
2987 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2988 | { | |
2989 | struct nlattr *attr; | |
2990 | int n_entries = 0, tmp; | |
2991 | ||
2992 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2993 | if (nla_len(attr) != ETH_ALEN) | |
2994 | return -EINVAL; | |
2995 | ||
2996 | n_entries++; | |
2997 | } | |
2998 | ||
2999 | return n_entries; | |
3000 | } | |
3001 | ||
3002 | /* | |
3003 | * This function parses ACL information and allocates memory for ACL data. | |
3004 | * On successful return, the calling function is responsible to free the | |
3005 | * ACL buffer returned by this function. | |
3006 | */ | |
3007 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3008 | struct genl_info *info) | |
3009 | { | |
3010 | enum nl80211_acl_policy acl_policy; | |
3011 | struct nlattr *attr; | |
3012 | struct cfg80211_acl_data *acl; | |
3013 | int i = 0, n_entries, tmp; | |
3014 | ||
3015 | if (!wiphy->max_acl_mac_addrs) | |
3016 | return ERR_PTR(-EOPNOTSUPP); | |
3017 | ||
3018 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3019 | return ERR_PTR(-EINVAL); | |
3020 | ||
3021 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3022 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3023 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3024 | return ERR_PTR(-EINVAL); | |
3025 | ||
3026 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3027 | return ERR_PTR(-EINVAL); | |
3028 | ||
3029 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3030 | if (n_entries < 0) | |
3031 | return ERR_PTR(n_entries); | |
3032 | ||
3033 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3034 | return ERR_PTR(-ENOTSUPP); | |
3035 | ||
3036 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3037 | GFP_KERNEL); | |
3038 | if (!acl) | |
3039 | return ERR_PTR(-ENOMEM); | |
3040 | ||
3041 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3042 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3043 | i++; | |
3044 | } | |
3045 | ||
3046 | acl->n_acl_entries = n_entries; | |
3047 | acl->acl_policy = acl_policy; | |
3048 | ||
3049 | return acl; | |
3050 | } | |
3051 | ||
3052 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3053 | { | |
3054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3055 | struct net_device *dev = info->user_ptr[1]; | |
3056 | struct cfg80211_acl_data *acl; | |
3057 | int err; | |
3058 | ||
3059 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3060 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3061 | return -EOPNOTSUPP; | |
3062 | ||
3063 | if (!dev->ieee80211_ptr->beacon_interval) | |
3064 | return -EINVAL; | |
3065 | ||
3066 | acl = parse_acl_data(&rdev->wiphy, info); | |
3067 | if (IS_ERR(acl)) | |
3068 | return PTR_ERR(acl); | |
3069 | ||
3070 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3071 | ||
3072 | kfree(acl); | |
3073 | ||
3074 | return err; | |
3075 | } | |
3076 | ||
a1193be8 | 3077 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3078 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3079 | { |
8860020e | 3080 | bool haveinfo = false; |
ed1b6cc7 | 3081 | |
a1193be8 SW |
3082 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3083 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3084 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3085 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3086 | return -EINVAL; |
3087 | ||
8860020e | 3088 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3089 | |
a1193be8 SW |
3090 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3091 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3092 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3093 | if (!bcn->head_len) |
3094 | return -EINVAL; | |
3095 | haveinfo = true; | |
ed1b6cc7 JB |
3096 | } |
3097 | ||
a1193be8 SW |
3098 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3099 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3100 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3101 | haveinfo = true; |
ed1b6cc7 JB |
3102 | } |
3103 | ||
4c476991 JB |
3104 | if (!haveinfo) |
3105 | return -EINVAL; | |
3b85875a | 3106 | |
a1193be8 SW |
3107 | if (attrs[NL80211_ATTR_IE]) { |
3108 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3109 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3110 | } |
3111 | ||
a1193be8 | 3112 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3113 | bcn->proberesp_ies = |
a1193be8 | 3114 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3115 | bcn->proberesp_ies_len = |
a1193be8 | 3116 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3117 | } |
3118 | ||
a1193be8 | 3119 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3120 | bcn->assocresp_ies = |
a1193be8 | 3121 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3122 | bcn->assocresp_ies_len = |
a1193be8 | 3123 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3124 | } |
3125 | ||
a1193be8 SW |
3126 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3127 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3128 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3129 | } |
3130 | ||
8860020e JB |
3131 | return 0; |
3132 | } | |
3133 | ||
46c1dd0c FF |
3134 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3135 | struct cfg80211_ap_settings *params) | |
3136 | { | |
3137 | struct wireless_dev *wdev; | |
3138 | bool ret = false; | |
3139 | ||
89a54e48 | 3140 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3141 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3142 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3143 | continue; | |
3144 | ||
683b6d3b | 3145 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3146 | continue; |
3147 | ||
683b6d3b | 3148 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3149 | ret = true; |
3150 | break; | |
3151 | } | |
3152 | ||
46c1dd0c FF |
3153 | return ret; |
3154 | } | |
3155 | ||
e39e5b5e JM |
3156 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3157 | enum nl80211_auth_type auth_type, | |
3158 | enum nl80211_commands cmd) | |
3159 | { | |
3160 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3161 | return false; | |
3162 | ||
3163 | switch (cmd) { | |
3164 | case NL80211_CMD_AUTHENTICATE: | |
3165 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3166 | auth_type == NL80211_AUTHTYPE_SAE) | |
3167 | return false; | |
3168 | return true; | |
3169 | case NL80211_CMD_CONNECT: | |
3170 | case NL80211_CMD_START_AP: | |
3171 | /* SAE not supported yet */ | |
3172 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3173 | return false; | |
3174 | return true; | |
3175 | default: | |
3176 | return false; | |
3177 | } | |
3178 | } | |
3179 | ||
8860020e JB |
3180 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3181 | { | |
3182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3183 | struct net_device *dev = info->user_ptr[1]; | |
3184 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3185 | struct cfg80211_ap_settings params; | |
3186 | int err; | |
3187 | ||
3188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3189 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3190 | return -EOPNOTSUPP; | |
3191 | ||
3192 | if (!rdev->ops->start_ap) | |
3193 | return -EOPNOTSUPP; | |
3194 | ||
3195 | if (wdev->beacon_interval) | |
3196 | return -EALREADY; | |
3197 | ||
3198 | memset(¶ms, 0, sizeof(params)); | |
3199 | ||
3200 | /* these are required for START_AP */ | |
3201 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3202 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3203 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3204 | return -EINVAL; | |
3205 | ||
a1193be8 | 3206 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3207 | if (err) |
3208 | return err; | |
3209 | ||
3210 | params.beacon_interval = | |
3211 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3212 | params.dtim_period = | |
3213 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3214 | ||
3215 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3216 | if (err) | |
3217 | return err; | |
3218 | ||
3219 | /* | |
3220 | * In theory, some of these attributes should be required here | |
3221 | * but since they were not used when the command was originally | |
3222 | * added, keep them optional for old user space programs to let | |
3223 | * them continue to work with drivers that do not need the | |
3224 | * additional information -- drivers must check! | |
3225 | */ | |
3226 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3227 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3228 | params.ssid_len = | |
3229 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3230 | if (params.ssid_len == 0 || | |
3231 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3232 | return -EINVAL; | |
3233 | } | |
3234 | ||
3235 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3236 | params.hidden_ssid = nla_get_u32( | |
3237 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3238 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3239 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3240 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3241 | return -EINVAL; | |
3242 | } | |
3243 | ||
3244 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3245 | ||
3246 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3247 | params.auth_type = nla_get_u32( | |
3248 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3249 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3250 | NL80211_CMD_START_AP)) | |
8860020e JB |
3251 | return -EINVAL; |
3252 | } else | |
3253 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3254 | ||
3255 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3256 | NL80211_MAX_NR_CIPHER_SUITES); | |
3257 | if (err) | |
3258 | return err; | |
3259 | ||
1b658f11 VT |
3260 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3261 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3262 | return -EOPNOTSUPP; | |
3263 | params.inactivity_timeout = nla_get_u16( | |
3264 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3265 | } | |
3266 | ||
53cabad7 JB |
3267 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3269 | return -EINVAL; | |
3270 | params.p2p_ctwindow = | |
3271 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3272 | if (params.p2p_ctwindow > 127) | |
3273 | return -EINVAL; | |
3274 | if (params.p2p_ctwindow != 0 && | |
3275 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3276 | return -EINVAL; | |
3277 | } | |
3278 | ||
3279 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3280 | u8 tmp; | |
3281 | ||
3282 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3283 | return -EINVAL; | |
3284 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3285 | if (tmp > 1) | |
3286 | return -EINVAL; | |
3287 | params.p2p_opp_ps = tmp; | |
3288 | if (params.p2p_opp_ps != 0 && | |
3289 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3290 | return -EINVAL; | |
3291 | } | |
3292 | ||
aa430da4 | 3293 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3294 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3295 | if (err) | |
3296 | return err; | |
3297 | } else if (wdev->preset_chandef.chan) { | |
3298 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3299 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3300 | return -EINVAL; |
3301 | ||
174e0cd2 IP |
3302 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3303 | wdev->iftype)) | |
aa430da4 JB |
3304 | return -EINVAL; |
3305 | ||
77765eaf VT |
3306 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3307 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3308 | if (IS_ERR(params.acl)) | |
3309 | return PTR_ERR(params.acl); | |
3310 | } | |
3311 | ||
c56589ed | 3312 | wdev_lock(wdev); |
e35e4d28 | 3313 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3314 | if (!err) { |
683b6d3b | 3315 | wdev->preset_chandef = params.chandef; |
8860020e | 3316 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3317 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3318 | wdev->ssid_len = params.ssid_len; |
3319 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3320 | } |
c56589ed | 3321 | wdev_unlock(wdev); |
77765eaf VT |
3322 | |
3323 | kfree(params.acl); | |
3324 | ||
56d1893d | 3325 | return err; |
ed1b6cc7 JB |
3326 | } |
3327 | ||
8860020e JB |
3328 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3329 | { | |
3330 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3331 | struct net_device *dev = info->user_ptr[1]; | |
3332 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3333 | struct cfg80211_beacon_data params; | |
3334 | int err; | |
3335 | ||
3336 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3337 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3338 | return -EOPNOTSUPP; | |
3339 | ||
3340 | if (!rdev->ops->change_beacon) | |
3341 | return -EOPNOTSUPP; | |
3342 | ||
3343 | if (!wdev->beacon_interval) | |
3344 | return -EINVAL; | |
3345 | ||
a1193be8 | 3346 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3347 | if (err) |
3348 | return err; | |
3349 | ||
c56589ed SW |
3350 | wdev_lock(wdev); |
3351 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3352 | wdev_unlock(wdev); | |
3353 | ||
3354 | return err; | |
8860020e JB |
3355 | } |
3356 | ||
3357 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3358 | { |
4c476991 JB |
3359 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3360 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3361 | |
7c8d5e03 | 3362 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3363 | } |
3364 | ||
5727ef1b JB |
3365 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3366 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3367 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3368 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3369 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3370 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3371 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3372 | }; |
3373 | ||
eccb8e8f | 3374 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3375 | enum nl80211_iftype iftype, |
eccb8e8f | 3376 | struct station_parameters *params) |
5727ef1b JB |
3377 | { |
3378 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3379 | struct nlattr *nla; |
5727ef1b JB |
3380 | int flag; |
3381 | ||
eccb8e8f JB |
3382 | /* |
3383 | * Try parsing the new attribute first so userspace | |
3384 | * can specify both for older kernels. | |
3385 | */ | |
3386 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3387 | if (nla) { | |
3388 | struct nl80211_sta_flag_update *sta_flags; | |
3389 | ||
3390 | sta_flags = nla_data(nla); | |
3391 | params->sta_flags_mask = sta_flags->mask; | |
3392 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3393 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3394 | if ((params->sta_flags_mask | |
3395 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3396 | return -EINVAL; | |
3397 | return 0; | |
3398 | } | |
3399 | ||
3400 | /* if present, parse the old attribute */ | |
5727ef1b | 3401 | |
eccb8e8f | 3402 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3403 | if (!nla) |
3404 | return 0; | |
3405 | ||
3406 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3407 | nla, sta_flags_policy)) | |
3408 | return -EINVAL; | |
3409 | ||
bdd3ae3d JB |
3410 | /* |
3411 | * Only allow certain flags for interface types so that | |
3412 | * other attributes are silently ignored. Remember that | |
3413 | * this is backward compatibility code with old userspace | |
3414 | * and shouldn't be hit in other cases anyway. | |
3415 | */ | |
3416 | switch (iftype) { | |
3417 | case NL80211_IFTYPE_AP: | |
3418 | case NL80211_IFTYPE_AP_VLAN: | |
3419 | case NL80211_IFTYPE_P2P_GO: | |
3420 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3421 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3422 | BIT(NL80211_STA_FLAG_WME) | | |
3423 | BIT(NL80211_STA_FLAG_MFP); | |
3424 | break; | |
3425 | case NL80211_IFTYPE_P2P_CLIENT: | |
3426 | case NL80211_IFTYPE_STATION: | |
3427 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3428 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3429 | break; | |
3430 | case NL80211_IFTYPE_MESH_POINT: | |
3431 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3432 | BIT(NL80211_STA_FLAG_MFP) | | |
3433 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3434 | default: | |
3435 | return -EINVAL; | |
3436 | } | |
5727ef1b | 3437 | |
3383b5a6 JB |
3438 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3439 | if (flags[flag]) { | |
eccb8e8f | 3440 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3441 | |
3383b5a6 JB |
3442 | /* no longer support new API additions in old API */ |
3443 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3444 | return -EINVAL; | |
3445 | } | |
3446 | } | |
3447 | ||
5727ef1b JB |
3448 | return 0; |
3449 | } | |
3450 | ||
c8dcfd8a FF |
3451 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3452 | int attr) | |
3453 | { | |
3454 | struct nlattr *rate; | |
8eb41c8d VK |
3455 | u32 bitrate; |
3456 | u16 bitrate_compat; | |
c8dcfd8a FF |
3457 | |
3458 | rate = nla_nest_start(msg, attr); | |
3459 | if (!rate) | |
db9c64cf | 3460 | return false; |
c8dcfd8a FF |
3461 | |
3462 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3463 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3464 | /* report 16-bit bitrate only if we can */ |
3465 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3466 | if (bitrate > 0 && |
3467 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3468 | return false; | |
3469 | if (bitrate_compat > 0 && | |
3470 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3471 | return false; | |
3472 | ||
3473 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3474 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3475 | return false; | |
3476 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3477 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3478 | return false; | |
3479 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3480 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3481 | return false; | |
3482 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3483 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3484 | return false; | |
3485 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3486 | return false; | |
3487 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3488 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3489 | return false; | |
3490 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3491 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3492 | return false; | |
3493 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3494 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3495 | return false; | |
3496 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3497 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3498 | return false; | |
3499 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3500 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3501 | return false; | |
3502 | } | |
c8dcfd8a FF |
3503 | |
3504 | nla_nest_end(msg, rate); | |
3505 | return true; | |
c8dcfd8a FF |
3506 | } |
3507 | ||
119363c7 FF |
3508 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3509 | int id) | |
3510 | { | |
3511 | void *attr; | |
3512 | int i = 0; | |
3513 | ||
3514 | if (!mask) | |
3515 | return true; | |
3516 | ||
3517 | attr = nla_nest_start(msg, id); | |
3518 | if (!attr) | |
3519 | return false; | |
3520 | ||
3521 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3522 | if (!(mask & BIT(i))) | |
3523 | continue; | |
3524 | ||
3525 | if (nla_put_u8(msg, i, signal[i])) | |
3526 | return false; | |
3527 | } | |
3528 | ||
3529 | nla_nest_end(msg, attr); | |
3530 | ||
3531 | return true; | |
3532 | } | |
3533 | ||
15e47304 | 3534 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3535 | int flags, |
3536 | struct cfg80211_registered_device *rdev, | |
3537 | struct net_device *dev, | |
98b62183 | 3538 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3539 | { |
3540 | void *hdr; | |
f4263c98 | 3541 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3542 | |
15e47304 | 3543 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3544 | if (!hdr) |
3545 | return -1; | |
3546 | ||
9360ffd1 DM |
3547 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3548 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3549 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3550 | goto nla_put_failure; | |
f5ea9120 | 3551 | |
2ec600d6 LCC |
3552 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3553 | if (!sinfoattr) | |
fd5b74dc | 3554 | goto nla_put_failure; |
9360ffd1 DM |
3555 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3556 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3557 | sinfo->connected_time)) | |
3558 | goto nla_put_failure; | |
3559 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3560 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3561 | sinfo->inactive_time)) | |
3562 | goto nla_put_failure; | |
42745e03 VK |
3563 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3564 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3565 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3566 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3567 | goto nla_put_failure; |
42745e03 | 3568 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3569 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3570 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3571 | (u32)sinfo->tx_bytes)) |
3572 | goto nla_put_failure; | |
3573 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3574 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3575 | sinfo->rx_bytes)) | |
3576 | goto nla_put_failure; | |
3577 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3578 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3579 | sinfo->tx_bytes)) |
3580 | goto nla_put_failure; | |
3581 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3582 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3583 | goto nla_put_failure; | |
3584 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3585 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3586 | goto nla_put_failure; | |
3587 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3588 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3589 | sinfo->plink_state)) | |
3590 | goto nla_put_failure; | |
66266b3a JL |
3591 | switch (rdev->wiphy.signal_type) { |
3592 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3593 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3594 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3595 | sinfo->signal)) | |
3596 | goto nla_put_failure; | |
3597 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3598 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3599 | sinfo->signal_avg)) | |
3600 | goto nla_put_failure; | |
66266b3a JL |
3601 | break; |
3602 | default: | |
3603 | break; | |
3604 | } | |
119363c7 FF |
3605 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3606 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3607 | sinfo->chain_signal, | |
3608 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3609 | goto nla_put_failure; | |
3610 | } | |
3611 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3612 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3613 | sinfo->chain_signal_avg, | |
3614 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3615 | goto nla_put_failure; | |
3616 | } | |
420e7fab | 3617 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3618 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3619 | NL80211_STA_INFO_TX_BITRATE)) | |
3620 | goto nla_put_failure; | |
3621 | } | |
3622 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3623 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3624 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3625 | goto nla_put_failure; |
420e7fab | 3626 | } |
9360ffd1 DM |
3627 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3628 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3629 | sinfo->rx_packets)) | |
3630 | goto nla_put_failure; | |
3631 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3632 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3633 | sinfo->tx_packets)) | |
3634 | goto nla_put_failure; | |
3635 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3636 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3637 | sinfo->tx_retries)) | |
3638 | goto nla_put_failure; | |
3639 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3640 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3641 | sinfo->tx_failed)) | |
3642 | goto nla_put_failure; | |
3643 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3644 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3645 | sinfo->beacon_loss_count)) | |
3646 | goto nla_put_failure; | |
3b1c5a53 MP |
3647 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3648 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3649 | sinfo->local_pm)) | |
3650 | goto nla_put_failure; | |
3651 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3652 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3653 | sinfo->peer_pm)) | |
3654 | goto nla_put_failure; | |
3655 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3656 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3657 | sinfo->nonpeer_pm)) | |
3658 | goto nla_put_failure; | |
f4263c98 PS |
3659 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3660 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3661 | if (!bss_param) | |
3662 | goto nla_put_failure; | |
3663 | ||
9360ffd1 DM |
3664 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3665 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3666 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3667 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3668 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3669 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3670 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3671 | sinfo->bss_param.dtim_period) || | |
3672 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3673 | sinfo->bss_param.beacon_interval)) | |
3674 | goto nla_put_failure; | |
f4263c98 PS |
3675 | |
3676 | nla_nest_end(msg, bss_param); | |
3677 | } | |
9360ffd1 DM |
3678 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3679 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3680 | sizeof(struct nl80211_sta_flag_update), | |
3681 | &sinfo->sta_flags)) | |
3682 | goto nla_put_failure; | |
7eab0f64 JL |
3683 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3684 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3685 | sinfo->t_offset)) | |
3686 | goto nla_put_failure; | |
2ec600d6 | 3687 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3688 | |
9360ffd1 DM |
3689 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3690 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3691 | sinfo->assoc_req_ies)) | |
3692 | goto nla_put_failure; | |
50d3dfb7 | 3693 | |
fd5b74dc JB |
3694 | return genlmsg_end(msg, hdr); |
3695 | ||
3696 | nla_put_failure: | |
bc3ed28c TG |
3697 | genlmsg_cancel(msg, hdr); |
3698 | return -EMSGSIZE; | |
fd5b74dc JB |
3699 | } |
3700 | ||
2ec600d6 | 3701 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3702 | struct netlink_callback *cb) |
2ec600d6 | 3703 | { |
2ec600d6 | 3704 | struct station_info sinfo; |
1b8ec87a | 3705 | struct cfg80211_registered_device *rdev; |
97990a06 | 3706 | struct wireless_dev *wdev; |
2ec600d6 | 3707 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3708 | int sta_idx = cb->args[2]; |
2ec600d6 | 3709 | int err; |
2ec600d6 | 3710 | |
1b8ec87a | 3711 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3712 | if (err) |
3713 | return err; | |
bba95fef | 3714 | |
97990a06 JB |
3715 | if (!wdev->netdev) { |
3716 | err = -EINVAL; | |
3717 | goto out_err; | |
3718 | } | |
3719 | ||
1b8ec87a | 3720 | if (!rdev->ops->dump_station) { |
eec60b03 | 3721 | err = -EOPNOTSUPP; |
bba95fef JB |
3722 | goto out_err; |
3723 | } | |
3724 | ||
bba95fef | 3725 | while (1) { |
f612cedf | 3726 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3727 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3728 | mac_addr, &sinfo); |
bba95fef JB |
3729 | if (err == -ENOENT) |
3730 | break; | |
3731 | if (err) | |
3b85875a | 3732 | goto out_err; |
bba95fef JB |
3733 | |
3734 | if (nl80211_send_station(skb, | |
15e47304 | 3735 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3736 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3737 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3738 | &sinfo) < 0) |
3739 | goto out; | |
3740 | ||
3741 | sta_idx++; | |
3742 | } | |
3743 | ||
3744 | ||
3745 | out: | |
97990a06 | 3746 | cb->args[2] = sta_idx; |
bba95fef | 3747 | err = skb->len; |
bba95fef | 3748 | out_err: |
1b8ec87a | 3749 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3750 | |
3751 | return err; | |
2ec600d6 | 3752 | } |
fd5b74dc | 3753 | |
5727ef1b JB |
3754 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3755 | { | |
4c476991 JB |
3756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3757 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3758 | struct station_info sinfo; |
fd5b74dc JB |
3759 | struct sk_buff *msg; |
3760 | u8 *mac_addr = NULL; | |
4c476991 | 3761 | int err; |
fd5b74dc | 3762 | |
2ec600d6 | 3763 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3764 | |
3765 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3766 | return -EINVAL; | |
3767 | ||
3768 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3769 | ||
4c476991 JB |
3770 | if (!rdev->ops->get_station) |
3771 | return -EOPNOTSUPP; | |
3b85875a | 3772 | |
e35e4d28 | 3773 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3774 | if (err) |
4c476991 | 3775 | return err; |
2ec600d6 | 3776 | |
fd2120ca | 3777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3778 | if (!msg) |
4c476991 | 3779 | return -ENOMEM; |
fd5b74dc | 3780 | |
15e47304 | 3781 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3782 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3783 | nlmsg_free(msg); |
3784 | return -ENOBUFS; | |
3785 | } | |
3b85875a | 3786 | |
4c476991 | 3787 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3788 | } |
3789 | ||
77ee7c89 JB |
3790 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3791 | struct station_parameters *params, | |
3792 | enum cfg80211_station_type statype) | |
3793 | { | |
3794 | if (params->listen_interval != -1) | |
3795 | return -EINVAL; | |
3796 | if (params->aid) | |
3797 | return -EINVAL; | |
3798 | ||
3799 | /* When you run into this, adjust the code below for the new flag */ | |
3800 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3801 | ||
3802 | switch (statype) { | |
eef941e6 TP |
3803 | case CFG80211_STA_MESH_PEER_KERNEL: |
3804 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3805 | /* |
3806 | * No ignoring the TDLS flag here -- the userspace mesh | |
3807 | * code doesn't have the bug of including TDLS in the | |
3808 | * mask everywhere. | |
3809 | */ | |
3810 | if (params->sta_flags_mask & | |
3811 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3812 | BIT(NL80211_STA_FLAG_MFP) | | |
3813 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3814 | return -EINVAL; | |
3815 | break; | |
3816 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3817 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3818 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3819 | return -EINVAL; | |
3820 | /* ignore since it can't change */ | |
3821 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3822 | break; | |
3823 | default: | |
3824 | /* disallow mesh-specific things */ | |
3825 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3826 | return -EINVAL; | |
3827 | if (params->local_pm) | |
3828 | return -EINVAL; | |
3829 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3830 | return -EINVAL; | |
3831 | } | |
3832 | ||
3833 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3834 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3835 | /* TDLS can't be set, ... */ | |
3836 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3837 | return -EINVAL; | |
3838 | /* | |
3839 | * ... but don't bother the driver with it. This works around | |
3840 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3841 | * TLDS_PEER flag in the mask even for AP mode. | |
3842 | */ | |
3843 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3844 | } | |
3845 | ||
3846 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3847 | /* reject other things that can't change */ | |
3848 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3849 | return -EINVAL; | |
3850 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3851 | return -EINVAL; | |
3852 | if (params->supported_rates) | |
3853 | return -EINVAL; | |
3854 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3855 | return -EINVAL; | |
3856 | } | |
3857 | ||
3858 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3859 | if (params->vlan) | |
3860 | return -EINVAL; | |
3861 | } | |
3862 | ||
3863 | switch (statype) { | |
3864 | case CFG80211_STA_AP_MLME_CLIENT: | |
3865 | /* Use this only for authorizing/unauthorizing a station */ | |
3866 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3867 | return -EOPNOTSUPP; | |
3868 | break; | |
3869 | case CFG80211_STA_AP_CLIENT: | |
3870 | /* accept only the listed bits */ | |
3871 | if (params->sta_flags_mask & | |
3872 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3873 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3874 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3875 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3876 | BIT(NL80211_STA_FLAG_WME) | | |
3877 | BIT(NL80211_STA_FLAG_MFP))) | |
3878 | return -EINVAL; | |
3879 | ||
3880 | /* but authenticated/associated only if driver handles it */ | |
3881 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3882 | params->sta_flags_mask & | |
3883 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3884 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3885 | return -EINVAL; | |
3886 | break; | |
3887 | case CFG80211_STA_IBSS: | |
3888 | case CFG80211_STA_AP_STA: | |
3889 | /* reject any changes other than AUTHORIZED */ | |
3890 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3891 | return -EINVAL; | |
3892 | break; | |
3893 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3894 | /* reject any changes other than AUTHORIZED or WME */ | |
3895 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3896 | BIT(NL80211_STA_FLAG_WME))) | |
3897 | return -EINVAL; | |
3898 | /* force (at least) rates when authorizing */ | |
3899 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3900 | !params->supported_rates) | |
3901 | return -EINVAL; | |
3902 | break; | |
3903 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3904 | /* reject any changes */ | |
3905 | return -EINVAL; | |
eef941e6 | 3906 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3907 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3908 | return -EINVAL; | |
3909 | break; | |
eef941e6 | 3910 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3911 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3912 | return -EINVAL; | |
3913 | break; | |
3914 | } | |
3915 | ||
3916 | return 0; | |
3917 | } | |
3918 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3919 | ||
5727ef1b | 3920 | /* |
c258d2de | 3921 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3922 | */ |
80b99899 JB |
3923 | static struct net_device *get_vlan(struct genl_info *info, |
3924 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3925 | { |
463d0183 | 3926 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3927 | struct net_device *v; |
3928 | int ret; | |
3929 | ||
3930 | if (!vlanattr) | |
3931 | return NULL; | |
3932 | ||
3933 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3934 | if (!v) | |
3935 | return ERR_PTR(-ENODEV); | |
3936 | ||
3937 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3938 | ret = -EINVAL; | |
3939 | goto error; | |
5727ef1b | 3940 | } |
80b99899 | 3941 | |
77ee7c89 JB |
3942 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3943 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3944 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3945 | ret = -EINVAL; | |
3946 | goto error; | |
3947 | } | |
3948 | ||
80b99899 JB |
3949 | if (!netif_running(v)) { |
3950 | ret = -ENETDOWN; | |
3951 | goto error; | |
3952 | } | |
3953 | ||
3954 | return v; | |
3955 | error: | |
3956 | dev_put(v); | |
3957 | return ERR_PTR(ret); | |
5727ef1b JB |
3958 | } |
3959 | ||
94e860f1 JB |
3960 | static const struct nla_policy |
3961 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
3962 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
3963 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3964 | }; | |
3965 | ||
ff276691 JB |
3966 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3967 | struct station_parameters *params) | |
df881293 | 3968 | { |
df881293 JM |
3969 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3970 | struct nlattr *nla; | |
3971 | int err; | |
3972 | ||
df881293 JM |
3973 | /* parse WME attributes if present */ |
3974 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3975 | return 0; | |
3976 | ||
3977 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3978 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3979 | nl80211_sta_wme_policy); | |
3980 | if (err) | |
3981 | return err; | |
3982 | ||
3983 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3984 | params->uapsd_queues = nla_get_u8( | |
3985 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3986 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3987 | return -EINVAL; | |
3988 | ||
3989 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3990 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3991 | ||
3992 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3993 | return -EINVAL; | |
3994 | ||
3995 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3996 | ||
3997 | return 0; | |
3998 | } | |
3999 | ||
c01fc9ad SD |
4000 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4001 | struct station_parameters *params) | |
4002 | { | |
4003 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4004 | params->supported_channels = | |
4005 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4006 | params->supported_channels_len = | |
4007 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4008 | /* | |
4009 | * Need to include at least one (first channel, number of | |
4010 | * channels) tuple for each subband, and must have proper | |
4011 | * tuples for the rest of the data as well. | |
4012 | */ | |
4013 | if (params->supported_channels_len < 2) | |
4014 | return -EINVAL; | |
4015 | if (params->supported_channels_len % 2) | |
4016 | return -EINVAL; | |
4017 | } | |
4018 | ||
4019 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4020 | params->supported_oper_classes = | |
4021 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4022 | params->supported_oper_classes_len = | |
4023 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4024 | /* | |
4025 | * The value of the Length field of the Supported Operating | |
4026 | * Classes element is between 2 and 253. | |
4027 | */ | |
4028 | if (params->supported_oper_classes_len < 2 || | |
4029 | params->supported_oper_classes_len > 253) | |
4030 | return -EINVAL; | |
4031 | } | |
4032 | return 0; | |
4033 | } | |
4034 | ||
ff276691 JB |
4035 | static int nl80211_set_station_tdls(struct genl_info *info, |
4036 | struct station_parameters *params) | |
4037 | { | |
c01fc9ad | 4038 | int err; |
ff276691 | 4039 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4040 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4041 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4042 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4043 | params->ht_capa = | |
4044 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4045 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4046 | params->vht_capa = | |
4047 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4048 | ||
c01fc9ad SD |
4049 | err = nl80211_parse_sta_channel_info(info, params); |
4050 | if (err) | |
4051 | return err; | |
4052 | ||
ff276691 JB |
4053 | return nl80211_parse_sta_wme(info, params); |
4054 | } | |
4055 | ||
5727ef1b JB |
4056 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4057 | { | |
4c476991 | 4058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4059 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4060 | struct station_parameters params; |
77ee7c89 JB |
4061 | u8 *mac_addr; |
4062 | int err; | |
5727ef1b JB |
4063 | |
4064 | memset(¶ms, 0, sizeof(params)); | |
4065 | ||
4066 | params.listen_interval = -1; | |
4067 | ||
77ee7c89 JB |
4068 | if (!rdev->ops->change_station) |
4069 | return -EOPNOTSUPP; | |
4070 | ||
5727ef1b JB |
4071 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4072 | return -EINVAL; | |
4073 | ||
4074 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4075 | return -EINVAL; | |
4076 | ||
4077 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4078 | ||
4079 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4080 | params.supported_rates = | |
4081 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4082 | params.supported_rates_len = | |
4083 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4084 | } | |
4085 | ||
9d62a986 JM |
4086 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4087 | params.capability = | |
4088 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4089 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4090 | } | |
4091 | ||
4092 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4093 | params.ext_capab = | |
4094 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4095 | params.ext_capab_len = | |
4096 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4097 | } | |
4098 | ||
df881293 | 4099 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4100 | return -EINVAL; |
36aedc90 | 4101 | |
bdd3ae3d | 4102 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4103 | return -EINVAL; |
4104 | ||
f8bacc21 | 4105 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4106 | params.plink_action = |
f8bacc21 JB |
4107 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4108 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4109 | return -EINVAL; | |
4110 | } | |
2ec600d6 | 4111 | |
f8bacc21 | 4112 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4113 | params.plink_state = |
f8bacc21 JB |
4114 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4115 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4116 | return -EINVAL; | |
4117 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4118 | } | |
9c3990aa | 4119 | |
3b1c5a53 MP |
4120 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4121 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4122 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4123 | ||
4124 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4125 | pm > NL80211_MESH_POWER_MAX) | |
4126 | return -EINVAL; | |
4127 | ||
4128 | params.local_pm = pm; | |
4129 | } | |
4130 | ||
77ee7c89 JB |
4131 | /* Include parameters for TDLS peer (will check later) */ |
4132 | err = nl80211_set_station_tdls(info, ¶ms); | |
4133 | if (err) | |
4134 | return err; | |
4135 | ||
4136 | params.vlan = get_vlan(info, rdev); | |
4137 | if (IS_ERR(params.vlan)) | |
4138 | return PTR_ERR(params.vlan); | |
4139 | ||
a97f4424 JB |
4140 | switch (dev->ieee80211_ptr->iftype) { |
4141 | case NL80211_IFTYPE_AP: | |
4142 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4143 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4144 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4145 | case NL80211_IFTYPE_STATION: |
267335d6 | 4146 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4147 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4148 | break; |
4149 | default: | |
77ee7c89 JB |
4150 | err = -EOPNOTSUPP; |
4151 | goto out_put_vlan; | |
034d655e JB |
4152 | } |
4153 | ||
77ee7c89 | 4154 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4155 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4156 | |
77ee7c89 | 4157 | out_put_vlan: |
5727ef1b JB |
4158 | if (params.vlan) |
4159 | dev_put(params.vlan); | |
3b85875a | 4160 | |
5727ef1b JB |
4161 | return err; |
4162 | } | |
4163 | ||
4164 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4165 | { | |
4c476991 | 4166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4167 | int err; |
4c476991 | 4168 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4169 | struct station_parameters params; |
4170 | u8 *mac_addr = NULL; | |
4171 | ||
4172 | memset(¶ms, 0, sizeof(params)); | |
4173 | ||
984c311b JB |
4174 | if (!rdev->ops->add_station) |
4175 | return -EOPNOTSUPP; | |
4176 | ||
5727ef1b JB |
4177 | if (!info->attrs[NL80211_ATTR_MAC]) |
4178 | return -EINVAL; | |
4179 | ||
5727ef1b JB |
4180 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4181 | return -EINVAL; | |
4182 | ||
4183 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4184 | return -EINVAL; | |
4185 | ||
5e4b6f56 JM |
4186 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4187 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4188 | return -EINVAL; |
4189 | ||
5727ef1b JB |
4190 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4191 | params.supported_rates = | |
4192 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4193 | params.supported_rates_len = | |
4194 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4195 | params.listen_interval = | |
4196 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4197 | |
3d124ea2 | 4198 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4199 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4200 | else |
4201 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4202 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4203 | return -EINVAL; | |
51b50fbe | 4204 | |
9d62a986 JM |
4205 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4206 | params.capability = | |
4207 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4208 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4209 | } | |
4210 | ||
4211 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4212 | params.ext_capab = | |
4213 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4214 | params.ext_capab_len = | |
4215 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4216 | } | |
4217 | ||
36aedc90 JM |
4218 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4219 | params.ht_capa = | |
4220 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4221 | |
f461be3e MP |
4222 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4223 | params.vht_capa = | |
4224 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4225 | ||
60f4a7b1 MK |
4226 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4227 | params.opmode_notif_used = true; | |
4228 | params.opmode_notif = | |
4229 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4230 | } | |
4231 | ||
f8bacc21 | 4232 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4233 | params.plink_action = |
f8bacc21 JB |
4234 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4235 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4236 | return -EINVAL; | |
4237 | } | |
96b78dff | 4238 | |
c01fc9ad SD |
4239 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4240 | if (err) | |
4241 | return err; | |
4242 | ||
ff276691 JB |
4243 | err = nl80211_parse_sta_wme(info, ¶ms); |
4244 | if (err) | |
4245 | return err; | |
bdd90d5e | 4246 | |
bdd3ae3d | 4247 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4248 | return -EINVAL; |
4249 | ||
77ee7c89 JB |
4250 | /* When you run into this, adjust the code below for the new flag */ |
4251 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4252 | ||
bdd90d5e JB |
4253 | switch (dev->ieee80211_ptr->iftype) { |
4254 | case NL80211_IFTYPE_AP: | |
4255 | case NL80211_IFTYPE_AP_VLAN: | |
4256 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4257 | /* ignore WME attributes if iface/sta is not capable */ |
4258 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4259 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4260 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4261 | |
bdd90d5e | 4262 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4263 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4264 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4265 | return -EINVAL; |
bdd90d5e JB |
4266 | /* but don't bother the driver with it */ |
4267 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4268 | |
d582cffb JB |
4269 | /* allow authenticated/associated only if driver handles it */ |
4270 | if (!(rdev->wiphy.features & | |
4271 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4272 | params.sta_flags_mask & | |
4273 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4274 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4275 | return -EINVAL; | |
4276 | ||
bdd90d5e JB |
4277 | /* must be last in here for error handling */ |
4278 | params.vlan = get_vlan(info, rdev); | |
4279 | if (IS_ERR(params.vlan)) | |
4280 | return PTR_ERR(params.vlan); | |
4281 | break; | |
4282 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4283 | /* ignore uAPSD data */ |
4284 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4285 | ||
d582cffb JB |
4286 | /* associated is disallowed */ |
4287 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4288 | return -EINVAL; | |
bdd90d5e | 4289 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4290 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4291 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4292 | return -EINVAL; |
4293 | break; | |
4294 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4295 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4296 | /* ignore uAPSD data */ |
4297 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4298 | ||
77ee7c89 JB |
4299 | /* these are disallowed */ |
4300 | if (params.sta_flags_mask & | |
4301 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4302 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4303 | return -EINVAL; |
bdd90d5e JB |
4304 | /* Only TDLS peers can be added */ |
4305 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4306 | return -EINVAL; | |
4307 | /* Can only add if TDLS ... */ | |
4308 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4309 | return -EOPNOTSUPP; | |
4310 | /* ... with external setup is supported */ | |
4311 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4312 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4313 | /* |
4314 | * Older wpa_supplicant versions always mark the TDLS peer | |
4315 | * as authorized, but it shouldn't yet be. | |
4316 | */ | |
4317 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4318 | break; |
4319 | default: | |
4320 | return -EOPNOTSUPP; | |
c75786c9 EP |
4321 | } |
4322 | ||
bdd90d5e | 4323 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4324 | |
e35e4d28 | 4325 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4326 | |
5727ef1b JB |
4327 | if (params.vlan) |
4328 | dev_put(params.vlan); | |
5727ef1b JB |
4329 | return err; |
4330 | } | |
4331 | ||
4332 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4333 | { | |
4c476991 JB |
4334 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4335 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4336 | u8 *mac_addr = NULL; |
4337 | ||
4338 | if (info->attrs[NL80211_ATTR_MAC]) | |
4339 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4340 | ||
e80cf853 | 4341 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4342 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4343 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4344 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4345 | return -EINVAL; | |
5727ef1b | 4346 | |
4c476991 JB |
4347 | if (!rdev->ops->del_station) |
4348 | return -EOPNOTSUPP; | |
3b85875a | 4349 | |
e35e4d28 | 4350 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4351 | } |
4352 | ||
15e47304 | 4353 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4354 | int flags, struct net_device *dev, |
4355 | u8 *dst, u8 *next_hop, | |
4356 | struct mpath_info *pinfo) | |
4357 | { | |
4358 | void *hdr; | |
4359 | struct nlattr *pinfoattr; | |
4360 | ||
15e47304 | 4361 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4362 | if (!hdr) |
4363 | return -1; | |
4364 | ||
9360ffd1 DM |
4365 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4366 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4367 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4368 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4369 | goto nla_put_failure; | |
f5ea9120 | 4370 | |
2ec600d6 LCC |
4371 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4372 | if (!pinfoattr) | |
4373 | goto nla_put_failure; | |
9360ffd1 DM |
4374 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4375 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4376 | pinfo->frame_qlen)) | |
4377 | goto nla_put_failure; | |
4378 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4379 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4380 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4381 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4382 | pinfo->metric)) || | |
4383 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4384 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4385 | pinfo->exptime)) || | |
4386 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4387 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4388 | pinfo->flags)) || | |
4389 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4390 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4391 | pinfo->discovery_timeout)) || | |
4392 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4393 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4394 | pinfo->discovery_retries))) | |
4395 | goto nla_put_failure; | |
2ec600d6 LCC |
4396 | |
4397 | nla_nest_end(msg, pinfoattr); | |
4398 | ||
4399 | return genlmsg_end(msg, hdr); | |
4400 | ||
4401 | nla_put_failure: | |
bc3ed28c TG |
4402 | genlmsg_cancel(msg, hdr); |
4403 | return -EMSGSIZE; | |
2ec600d6 LCC |
4404 | } |
4405 | ||
4406 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4407 | struct netlink_callback *cb) |
2ec600d6 | 4408 | { |
2ec600d6 | 4409 | struct mpath_info pinfo; |
1b8ec87a | 4410 | struct cfg80211_registered_device *rdev; |
97990a06 | 4411 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4412 | u8 dst[ETH_ALEN]; |
4413 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4414 | int path_idx = cb->args[2]; |
2ec600d6 | 4415 | int err; |
2ec600d6 | 4416 | |
1b8ec87a | 4417 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4418 | if (err) |
4419 | return err; | |
bba95fef | 4420 | |
1b8ec87a | 4421 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4422 | err = -EOPNOTSUPP; |
bba95fef JB |
4423 | goto out_err; |
4424 | } | |
4425 | ||
97990a06 | 4426 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4427 | err = -EOPNOTSUPP; |
0448b5fc | 4428 | goto out_err; |
eec60b03 JM |
4429 | } |
4430 | ||
bba95fef | 4431 | while (1) { |
1b8ec87a | 4432 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4433 | next_hop, &pinfo); |
bba95fef | 4434 | if (err == -ENOENT) |
2ec600d6 | 4435 | break; |
bba95fef | 4436 | if (err) |
3b85875a | 4437 | goto out_err; |
2ec600d6 | 4438 | |
15e47304 | 4439 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4440 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4441 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4442 | &pinfo) < 0) |
4443 | goto out; | |
2ec600d6 | 4444 | |
bba95fef | 4445 | path_idx++; |
2ec600d6 | 4446 | } |
2ec600d6 | 4447 | |
2ec600d6 | 4448 | |
bba95fef | 4449 | out: |
97990a06 | 4450 | cb->args[2] = path_idx; |
bba95fef | 4451 | err = skb->len; |
bba95fef | 4452 | out_err: |
1b8ec87a | 4453 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4454 | return err; |
2ec600d6 LCC |
4455 | } |
4456 | ||
4457 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4458 | { | |
4c476991 | 4459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4460 | int err; |
4c476991 | 4461 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4462 | struct mpath_info pinfo; |
4463 | struct sk_buff *msg; | |
4464 | u8 *dst = NULL; | |
4465 | u8 next_hop[ETH_ALEN]; | |
4466 | ||
4467 | memset(&pinfo, 0, sizeof(pinfo)); | |
4468 | ||
4469 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4470 | return -EINVAL; | |
4471 | ||
4472 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4473 | ||
4c476991 JB |
4474 | if (!rdev->ops->get_mpath) |
4475 | return -EOPNOTSUPP; | |
2ec600d6 | 4476 | |
4c476991 JB |
4477 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4478 | return -EOPNOTSUPP; | |
eec60b03 | 4479 | |
e35e4d28 | 4480 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4481 | if (err) |
4c476991 | 4482 | return err; |
2ec600d6 | 4483 | |
fd2120ca | 4484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4485 | if (!msg) |
4c476991 | 4486 | return -ENOMEM; |
2ec600d6 | 4487 | |
15e47304 | 4488 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4489 | dev, dst, next_hop, &pinfo) < 0) { |
4490 | nlmsg_free(msg); | |
4491 | return -ENOBUFS; | |
4492 | } | |
3b85875a | 4493 | |
4c476991 | 4494 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4495 | } |
4496 | ||
4497 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4498 | { | |
4c476991 JB |
4499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4500 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4501 | u8 *dst = NULL; |
4502 | u8 *next_hop = NULL; | |
4503 | ||
4504 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4505 | return -EINVAL; | |
4506 | ||
4507 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4508 | return -EINVAL; | |
4509 | ||
4510 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4511 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4512 | ||
4c476991 JB |
4513 | if (!rdev->ops->change_mpath) |
4514 | return -EOPNOTSUPP; | |
35a8efe1 | 4515 | |
4c476991 JB |
4516 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4517 | return -EOPNOTSUPP; | |
2ec600d6 | 4518 | |
e35e4d28 | 4519 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4520 | } |
4c476991 | 4521 | |
2ec600d6 LCC |
4522 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4523 | { | |
4c476991 JB |
4524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4525 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4526 | u8 *dst = NULL; |
4527 | u8 *next_hop = NULL; | |
4528 | ||
4529 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4530 | return -EINVAL; | |
4531 | ||
4532 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4533 | return -EINVAL; | |
4534 | ||
4535 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4536 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4537 | ||
4c476991 JB |
4538 | if (!rdev->ops->add_mpath) |
4539 | return -EOPNOTSUPP; | |
35a8efe1 | 4540 | |
4c476991 JB |
4541 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4542 | return -EOPNOTSUPP; | |
2ec600d6 | 4543 | |
e35e4d28 | 4544 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4545 | } |
4546 | ||
4547 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4548 | { | |
4c476991 JB |
4549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4550 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4551 | u8 *dst = NULL; |
4552 | ||
4553 | if (info->attrs[NL80211_ATTR_MAC]) | |
4554 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4555 | ||
4c476991 JB |
4556 | if (!rdev->ops->del_mpath) |
4557 | return -EOPNOTSUPP; | |
3b85875a | 4558 | |
e35e4d28 | 4559 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4560 | } |
4561 | ||
9f1ba906 JM |
4562 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4563 | { | |
4c476991 JB |
4564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4565 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4566 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4567 | struct bss_parameters params; |
c56589ed | 4568 | int err; |
9f1ba906 JM |
4569 | |
4570 | memset(¶ms, 0, sizeof(params)); | |
4571 | /* default to not changing parameters */ | |
4572 | params.use_cts_prot = -1; | |
4573 | params.use_short_preamble = -1; | |
4574 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4575 | params.ap_isolate = -1; |
50b12f59 | 4576 | params.ht_opmode = -1; |
53cabad7 JB |
4577 | params.p2p_ctwindow = -1; |
4578 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4579 | |
4580 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4581 | params.use_cts_prot = | |
4582 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4583 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4584 | params.use_short_preamble = | |
4585 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4586 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4587 | params.use_short_slot_time = | |
4588 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4589 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4590 | params.basic_rates = | |
4591 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4592 | params.basic_rates_len = | |
4593 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4594 | } | |
fd8aaaf3 FF |
4595 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4596 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4597 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4598 | params.ht_opmode = | |
4599 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4600 | |
53cabad7 JB |
4601 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4602 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4603 | return -EINVAL; | |
4604 | params.p2p_ctwindow = | |
4605 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4606 | if (params.p2p_ctwindow < 0) | |
4607 | return -EINVAL; | |
4608 | if (params.p2p_ctwindow != 0 && | |
4609 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4610 | return -EINVAL; | |
4611 | } | |
4612 | ||
4613 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4614 | u8 tmp; | |
4615 | ||
4616 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4617 | return -EINVAL; | |
4618 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4619 | if (tmp > 1) | |
4620 | return -EINVAL; | |
4621 | params.p2p_opp_ps = tmp; | |
4622 | if (params.p2p_opp_ps && | |
4623 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4624 | return -EINVAL; | |
4625 | } | |
4626 | ||
4c476991 JB |
4627 | if (!rdev->ops->change_bss) |
4628 | return -EOPNOTSUPP; | |
9f1ba906 | 4629 | |
074ac8df | 4630 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4631 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4632 | return -EOPNOTSUPP; | |
3b85875a | 4633 | |
c56589ed SW |
4634 | wdev_lock(wdev); |
4635 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4636 | wdev_unlock(wdev); | |
4637 | ||
4638 | return err; | |
9f1ba906 JM |
4639 | } |
4640 | ||
b54452b0 | 4641 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4642 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4643 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4644 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4645 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4646 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4647 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4648 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4649 | }; |
4650 | ||
4651 | static int parse_reg_rule(struct nlattr *tb[], | |
4652 | struct ieee80211_reg_rule *reg_rule) | |
4653 | { | |
4654 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4655 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4656 | ||
4657 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4658 | return -EINVAL; | |
4659 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4660 | return -EINVAL; | |
4661 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4662 | return -EINVAL; | |
b0dfd2ea JD |
4663 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4664 | return -EINVAL; | |
b2e1b302 LR |
4665 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4666 | return -EINVAL; | |
4667 | ||
4668 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4669 | ||
4670 | freq_range->start_freq_khz = | |
4671 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4672 | freq_range->end_freq_khz = | |
4673 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4674 | freq_range->max_bandwidth_khz = |
4675 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4676 | |
4677 | power_rule->max_eirp = | |
4678 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4679 | ||
4680 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4681 | power_rule->max_antenna_gain = | |
4682 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4683 | ||
089027e5 JD |
4684 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4685 | reg_rule->dfs_cac_ms = | |
4686 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4687 | ||
b2e1b302 LR |
4688 | return 0; |
4689 | } | |
4690 | ||
4691 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4692 | { | |
b2e1b302 | 4693 | char *data = NULL; |
57b5ce07 | 4694 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4695 | |
80778f18 LR |
4696 | /* |
4697 | * You should only get this when cfg80211 hasn't yet initialized | |
4698 | * completely when built-in to the kernel right between the time | |
4699 | * window between nl80211_init() and regulatory_init(), if that is | |
4700 | * even possible. | |
4701 | */ | |
458f4f9e | 4702 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4703 | return -EINPROGRESS; |
80778f18 | 4704 | |
57b5ce07 LR |
4705 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4706 | user_reg_hint_type = | |
4707 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4708 | else | |
4709 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4710 | ||
4711 | switch (user_reg_hint_type) { | |
4712 | case NL80211_USER_REG_HINT_USER: | |
4713 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4714 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4715 | return -EINVAL; | |
4716 | ||
4717 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4718 | return regulatory_hint_user(data, user_reg_hint_type); | |
4719 | case NL80211_USER_REG_HINT_INDOOR: | |
4720 | return regulatory_hint_indoor_user(); | |
57b5ce07 LR |
4721 | default: |
4722 | return -EINVAL; | |
4723 | } | |
b2e1b302 LR |
4724 | } |
4725 | ||
24bdd9f4 | 4726 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4727 | struct genl_info *info) |
93da9cc1 | 4728 | { |
4c476991 | 4729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4730 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4731 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4732 | struct mesh_config cur_params; | |
4733 | int err = 0; | |
93da9cc1 | 4734 | void *hdr; |
4735 | struct nlattr *pinfoattr; | |
4736 | struct sk_buff *msg; | |
4737 | ||
29cbe68c JB |
4738 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4739 | return -EOPNOTSUPP; | |
4740 | ||
24bdd9f4 | 4741 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4742 | return -EOPNOTSUPP; |
f3f92586 | 4743 | |
29cbe68c JB |
4744 | wdev_lock(wdev); |
4745 | /* If not connected, get default parameters */ | |
4746 | if (!wdev->mesh_id_len) | |
4747 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4748 | else | |
e35e4d28 | 4749 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4750 | wdev_unlock(wdev); |
4751 | ||
93da9cc1 | 4752 | if (err) |
4c476991 | 4753 | return err; |
93da9cc1 | 4754 | |
4755 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4756 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4757 | if (!msg) |
4758 | return -ENOMEM; | |
15e47304 | 4759 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4760 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4761 | if (!hdr) |
efe1cf0c | 4762 | goto out; |
24bdd9f4 | 4763 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4764 | if (!pinfoattr) |
4765 | goto nla_put_failure; | |
9360ffd1 DM |
4766 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4767 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4768 | cur_params.dot11MeshRetryTimeout) || | |
4769 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4770 | cur_params.dot11MeshConfirmTimeout) || | |
4771 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4772 | cur_params.dot11MeshHoldingTimeout) || | |
4773 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4774 | cur_params.dot11MeshMaxPeerLinks) || | |
4775 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4776 | cur_params.dot11MeshMaxRetries) || | |
4777 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4778 | cur_params.dot11MeshTTL) || | |
4779 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4780 | cur_params.element_ttl) || | |
4781 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4782 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4783 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4784 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4785 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4786 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4787 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4788 | cur_params.path_refresh_time) || | |
4789 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4790 | cur_params.min_discovery_timeout) || | |
4791 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4792 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4793 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4794 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4795 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4796 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4797 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4798 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4799 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4800 | cur_params.dot11MeshHWMPRootMode) || | |
4801 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4802 | cur_params.dot11MeshHWMPRannInterval) || | |
4803 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4804 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4805 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4806 | cur_params.dot11MeshForwarding) || | |
4807 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4808 | cur_params.rssi_threshold) || |
4809 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4810 | cur_params.ht_opmode) || |
4811 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4812 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4813 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4814 | cur_params.dot11MeshHWMProotInterval) || |
4815 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4816 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4817 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4818 | cur_params.power_mode) || | |
4819 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4820 | cur_params.dot11MeshAwakeWindowDuration) || |
4821 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4822 | cur_params.plink_timeout)) | |
9360ffd1 | 4823 | goto nla_put_failure; |
93da9cc1 | 4824 | nla_nest_end(msg, pinfoattr); |
4825 | genlmsg_end(msg, hdr); | |
4c476991 | 4826 | return genlmsg_reply(msg, info); |
93da9cc1 | 4827 | |
3b85875a | 4828 | nla_put_failure: |
93da9cc1 | 4829 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4830 | out: |
d080e275 | 4831 | nlmsg_free(msg); |
4c476991 | 4832 | return -ENOBUFS; |
93da9cc1 | 4833 | } |
4834 | ||
b54452b0 | 4835 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4836 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4837 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4838 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4839 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4840 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4841 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4842 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4843 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4844 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4845 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4846 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4847 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4848 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4849 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4850 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4851 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4852 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4853 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4854 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4855 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4856 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4857 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4858 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4859 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4860 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4861 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4862 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4863 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4864 | }; |
4865 | ||
c80d545d JC |
4866 | static const struct nla_policy |
4867 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4868 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4869 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4870 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4871 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4872 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4873 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4874 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4875 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4876 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4877 | }; |
4878 | ||
24bdd9f4 | 4879 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4880 | struct mesh_config *cfg, |
4881 | u32 *mask_out) | |
93da9cc1 | 4882 | { |
93da9cc1 | 4883 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4884 | u32 mask = 0; |
93da9cc1 | 4885 | |
ea54fba2 MP |
4886 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4887 | do { \ | |
4888 | if (tb[attr]) { \ | |
4889 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4890 | return -EINVAL; \ | |
4891 | cfg->param = fn(tb[attr]); \ | |
4892 | mask |= (1 << (attr - 1)); \ | |
4893 | } \ | |
4894 | } while (0) | |
bd90fdcc JB |
4895 | |
4896 | ||
24bdd9f4 | 4897 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4898 | return -EINVAL; |
4899 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4900 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4901 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4902 | return -EINVAL; |
4903 | ||
93da9cc1 | 4904 | /* This makes sure that there aren't more than 32 mesh config |
4905 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4906 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4907 | ||
4908 | /* Fill in the params struct */ | |
ea54fba2 | 4909 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4910 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4911 | nla_get_u16); | |
ea54fba2 | 4912 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4913 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4914 | nla_get_u16); | |
ea54fba2 | 4915 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4916 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4917 | nla_get_u16); | |
ea54fba2 | 4918 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4919 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4920 | nla_get_u16); | |
ea54fba2 | 4921 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4922 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4923 | nla_get_u8); | |
ea54fba2 | 4924 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4925 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4926 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4927 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4928 | nla_get_u8); | |
ea54fba2 | 4929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4930 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4931 | nla_get_u8); | |
ea54fba2 MP |
4932 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4933 | 1, 255, mask, | |
a4f606ea CYY |
4934 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4935 | nla_get_u32); | |
ea54fba2 | 4936 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4937 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4938 | nla_get_u8); | |
ea54fba2 | 4939 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4940 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4941 | nla_get_u32); | |
ea54fba2 | 4942 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4943 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4944 | nla_get_u16); | |
ea54fba2 MP |
4945 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4946 | 1, 65535, mask, | |
a4f606ea CYY |
4947 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4948 | nla_get_u32); | |
93da9cc1 | 4949 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4950 | 1, 65535, mask, |
4951 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4952 | nla_get_u16); |
dca7e943 | 4953 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4954 | 1, 65535, mask, |
4955 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4956 | nla_get_u16); |
93da9cc1 | 4957 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4958 | dot11MeshHWMPnetDiameterTraversalTime, |
4959 | 1, 65535, mask, | |
a4f606ea CYY |
4960 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4961 | nla_get_u16); | |
ea54fba2 MP |
4962 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4963 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4964 | nla_get_u8); | |
4965 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4966 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4967 | nla_get_u16); |
63c5723b | 4968 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4969 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4970 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4971 | nla_get_u8); |
ea54fba2 | 4972 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4973 | mask, NL80211_MESHCONF_FORWARDING, |
4974 | nla_get_u8); | |
83374fe9 | 4975 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 4976 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 4977 | nla_get_s32); |
ea54fba2 | 4978 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4979 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4980 | nla_get_u16); |
4981 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4982 | 1, 65535, mask, |
ac1073a6 CYY |
4983 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4984 | nla_get_u32); | |
ea54fba2 | 4985 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4986 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4987 | nla_get_u16); |
4988 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4989 | dot11MeshHWMPconfirmationInterval, |
4990 | 1, 65535, mask, | |
728b19e5 | 4991 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4992 | nla_get_u16); |
3b1c5a53 MP |
4993 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4994 | NL80211_MESH_POWER_ACTIVE, | |
4995 | NL80211_MESH_POWER_MAX, | |
4996 | mask, NL80211_MESHCONF_POWER_MODE, | |
4997 | nla_get_u32); | |
4998 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4999 | 0, 65535, mask, | |
5000 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
5001 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
5002 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5003 | nla_get_u32); | |
bd90fdcc JB |
5004 | if (mask_out) |
5005 | *mask_out = mask; | |
c80d545d | 5006 | |
bd90fdcc JB |
5007 | return 0; |
5008 | ||
5009 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5010 | } | |
5011 | ||
c80d545d JC |
5012 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5013 | struct mesh_setup *setup) | |
5014 | { | |
bb2798d4 | 5015 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5016 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5017 | ||
5018 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5019 | return -EINVAL; | |
5020 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5021 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5022 | nl80211_mesh_setup_params_policy)) | |
5023 | return -EINVAL; | |
5024 | ||
d299a1f2 JC |
5025 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5026 | setup->sync_method = | |
5027 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5028 | IEEE80211_SYNC_METHOD_VENDOR : | |
5029 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5030 | ||
c80d545d JC |
5031 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5032 | setup->path_sel_proto = | |
5033 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5034 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5035 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5036 | ||
5037 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5038 | setup->path_metric = | |
5039 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5040 | IEEE80211_PATH_METRIC_VENDOR : | |
5041 | IEEE80211_PATH_METRIC_AIRTIME; | |
5042 | ||
581a8b0f JC |
5043 | |
5044 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5045 | struct nlattr *ieattr = |
581a8b0f | 5046 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5047 | if (!is_valid_ie_attr(ieattr)) |
5048 | return -EINVAL; | |
581a8b0f JC |
5049 | setup->ie = nla_data(ieattr); |
5050 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5051 | } |
bb2798d4 TP |
5052 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5053 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5054 | return -EINVAL; | |
5055 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5056 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5057 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5058 | if (setup->is_secure) |
5059 | setup->user_mpm = true; | |
c80d545d | 5060 | |
6e16d90b CT |
5061 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5062 | if (!setup->user_mpm) | |
5063 | return -EINVAL; | |
5064 | setup->auth_id = | |
5065 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5066 | } | |
5067 | ||
c80d545d JC |
5068 | return 0; |
5069 | } | |
5070 | ||
24bdd9f4 | 5071 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5072 | struct genl_info *info) |
bd90fdcc JB |
5073 | { |
5074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5075 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5076 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5077 | struct mesh_config cfg; |
5078 | u32 mask; | |
5079 | int err; | |
5080 | ||
29cbe68c JB |
5081 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5082 | return -EOPNOTSUPP; | |
5083 | ||
24bdd9f4 | 5084 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5085 | return -EOPNOTSUPP; |
5086 | ||
24bdd9f4 | 5087 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5088 | if (err) |
5089 | return err; | |
5090 | ||
29cbe68c JB |
5091 | wdev_lock(wdev); |
5092 | if (!wdev->mesh_id_len) | |
5093 | err = -ENOLINK; | |
5094 | ||
5095 | if (!err) | |
e35e4d28 | 5096 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5097 | |
5098 | wdev_unlock(wdev); | |
5099 | ||
5100 | return err; | |
93da9cc1 | 5101 | } |
5102 | ||
f130347c LR |
5103 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5104 | { | |
458f4f9e | 5105 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5106 | struct sk_buff *msg; |
5107 | void *hdr = NULL; | |
5108 | struct nlattr *nl_reg_rules; | |
5109 | unsigned int i; | |
f130347c LR |
5110 | |
5111 | if (!cfg80211_regdomain) | |
5fe231e8 | 5112 | return -EINVAL; |
f130347c | 5113 | |
fd2120ca | 5114 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5115 | if (!msg) |
5116 | return -ENOBUFS; | |
f130347c | 5117 | |
15e47304 | 5118 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5119 | NL80211_CMD_GET_REG); |
5120 | if (!hdr) | |
efe1cf0c | 5121 | goto put_failure; |
f130347c | 5122 | |
57b5ce07 LR |
5123 | if (reg_last_request_cell_base() && |
5124 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5125 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5126 | goto nla_put_failure; | |
5127 | ||
458f4f9e JB |
5128 | rcu_read_lock(); |
5129 | regdom = rcu_dereference(cfg80211_regdomain); | |
5130 | ||
5131 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5132 | (regdom->dfs_region && | |
5133 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5134 | goto nla_put_failure_rcu; | |
5135 | ||
f130347c LR |
5136 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5137 | if (!nl_reg_rules) | |
458f4f9e | 5138 | goto nla_put_failure_rcu; |
f130347c | 5139 | |
458f4f9e | 5140 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5141 | struct nlattr *nl_reg_rule; |
5142 | const struct ieee80211_reg_rule *reg_rule; | |
5143 | const struct ieee80211_freq_range *freq_range; | |
5144 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5145 | unsigned int max_bandwidth_khz; |
f130347c | 5146 | |
458f4f9e | 5147 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5148 | freq_range = ®_rule->freq_range; |
5149 | power_rule = ®_rule->power_rule; | |
5150 | ||
5151 | nl_reg_rule = nla_nest_start(msg, i); | |
5152 | if (!nl_reg_rule) | |
458f4f9e | 5153 | goto nla_put_failure_rcu; |
f130347c | 5154 | |
97524820 JD |
5155 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5156 | if (!max_bandwidth_khz) | |
5157 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5158 | reg_rule); | |
5159 | ||
9360ffd1 DM |
5160 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5161 | reg_rule->flags) || | |
5162 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5163 | freq_range->start_freq_khz) || | |
5164 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5165 | freq_range->end_freq_khz) || | |
5166 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5167 | max_bandwidth_khz) || |
9360ffd1 DM |
5168 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5169 | power_rule->max_antenna_gain) || | |
5170 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5171 | power_rule->max_eirp) || |
5172 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5173 | reg_rule->dfs_cac_ms)) | |
458f4f9e | 5174 | goto nla_put_failure_rcu; |
f130347c LR |
5175 | |
5176 | nla_nest_end(msg, nl_reg_rule); | |
5177 | } | |
458f4f9e | 5178 | rcu_read_unlock(); |
f130347c LR |
5179 | |
5180 | nla_nest_end(msg, nl_reg_rules); | |
5181 | ||
5182 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5183 | return genlmsg_reply(msg, info); |
f130347c | 5184 | |
458f4f9e JB |
5185 | nla_put_failure_rcu: |
5186 | rcu_read_unlock(); | |
f130347c LR |
5187 | nla_put_failure: |
5188 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5189 | put_failure: |
d080e275 | 5190 | nlmsg_free(msg); |
5fe231e8 | 5191 | return -EMSGSIZE; |
f130347c LR |
5192 | } |
5193 | ||
b2e1b302 LR |
5194 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5195 | { | |
5196 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5197 | struct nlattr *nl_reg_rule; | |
5198 | char *alpha2 = NULL; | |
5199 | int rem_reg_rules = 0, r = 0; | |
5200 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5201 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5202 | struct ieee80211_regdomain *rd = NULL; |
5203 | ||
5204 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5205 | return -EINVAL; | |
5206 | ||
5207 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5208 | return -EINVAL; | |
5209 | ||
5210 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5211 | ||
8b60b078 LR |
5212 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5213 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5214 | ||
b2e1b302 | 5215 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5216 | rem_reg_rules) { |
b2e1b302 LR |
5217 | num_rules++; |
5218 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5219 | return -EINVAL; |
b2e1b302 LR |
5220 | } |
5221 | ||
e438768f LR |
5222 | if (!reg_is_valid_request(alpha2)) |
5223 | return -EINVAL; | |
5224 | ||
b2e1b302 | 5225 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5226 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5227 | |
5228 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5229 | if (!rd) |
5230 | return -ENOMEM; | |
b2e1b302 LR |
5231 | |
5232 | rd->n_reg_rules = num_rules; | |
5233 | rd->alpha2[0] = alpha2[0]; | |
5234 | rd->alpha2[1] = alpha2[1]; | |
5235 | ||
8b60b078 LR |
5236 | /* |
5237 | * Disable DFS master mode if the DFS region was | |
5238 | * not supported or known on this kernel. | |
5239 | */ | |
5240 | if (reg_supported_dfs_region(dfs_region)) | |
5241 | rd->dfs_region = dfs_region; | |
5242 | ||
b2e1b302 | 5243 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5244 | rem_reg_rules) { |
ae811e21 JB |
5245 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5246 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5247 | reg_rule_policy); | |
5248 | if (r) | |
5249 | goto bad_reg; | |
b2e1b302 LR |
5250 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5251 | if (r) | |
5252 | goto bad_reg; | |
5253 | ||
5254 | rule_idx++; | |
5255 | ||
d0e18f83 LR |
5256 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5257 | r = -EINVAL; | |
b2e1b302 | 5258 | goto bad_reg; |
d0e18f83 | 5259 | } |
b2e1b302 LR |
5260 | } |
5261 | ||
b2e1b302 | 5262 | r = set_regdom(rd); |
6913b49a | 5263 | /* set_regdom took ownership */ |
1a919318 | 5264 | rd = NULL; |
b2e1b302 | 5265 | |
d2372b31 | 5266 | bad_reg: |
b2e1b302 | 5267 | kfree(rd); |
d0e18f83 | 5268 | return r; |
b2e1b302 LR |
5269 | } |
5270 | ||
83f5e2cf JB |
5271 | static int validate_scan_freqs(struct nlattr *freqs) |
5272 | { | |
5273 | struct nlattr *attr1, *attr2; | |
5274 | int n_channels = 0, tmp1, tmp2; | |
5275 | ||
5276 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5277 | n_channels++; | |
5278 | /* | |
5279 | * Some hardware has a limited channel list for | |
5280 | * scanning, and it is pretty much nonsensical | |
5281 | * to scan for a channel twice, so disallow that | |
5282 | * and don't require drivers to check that the | |
5283 | * channel list they get isn't longer than what | |
5284 | * they can scan, as long as they can scan all | |
5285 | * the channels they registered at once. | |
5286 | */ | |
5287 | nla_for_each_nested(attr2, freqs, tmp2) | |
5288 | if (attr1 != attr2 && | |
5289 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5290 | return 0; | |
5291 | } | |
5292 | ||
5293 | return n_channels; | |
5294 | } | |
5295 | ||
2a519311 JB |
5296 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5297 | { | |
4c476991 | 5298 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5299 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5300 | struct cfg80211_scan_request *request; |
2a519311 JB |
5301 | struct nlattr *attr; |
5302 | struct wiphy *wiphy; | |
83f5e2cf | 5303 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5304 | size_t ie_len; |
2a519311 | 5305 | |
f4a11bb0 JB |
5306 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5307 | return -EINVAL; | |
5308 | ||
79c97e97 | 5309 | wiphy = &rdev->wiphy; |
2a519311 | 5310 | |
4c476991 JB |
5311 | if (!rdev->ops->scan) |
5312 | return -EOPNOTSUPP; | |
2a519311 | 5313 | |
f9d15d16 | 5314 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5315 | err = -EBUSY; |
5316 | goto unlock; | |
5317 | } | |
2a519311 JB |
5318 | |
5319 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5320 | n_channels = validate_scan_freqs( |
5321 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5322 | if (!n_channels) { |
5323 | err = -EINVAL; | |
5324 | goto unlock; | |
5325 | } | |
2a519311 | 5326 | } else { |
bdfbec2d | 5327 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5328 | } |
5329 | ||
5330 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5331 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5332 | n_ssids++; | |
5333 | ||
f9f47529 JB |
5334 | if (n_ssids > wiphy->max_scan_ssids) { |
5335 | err = -EINVAL; | |
5336 | goto unlock; | |
5337 | } | |
2a519311 | 5338 | |
70692ad2 JM |
5339 | if (info->attrs[NL80211_ATTR_IE]) |
5340 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5341 | else | |
5342 | ie_len = 0; | |
5343 | ||
f9f47529 JB |
5344 | if (ie_len > wiphy->max_scan_ie_len) { |
5345 | err = -EINVAL; | |
5346 | goto unlock; | |
5347 | } | |
18a83659 | 5348 | |
2a519311 | 5349 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5350 | + sizeof(*request->ssids) * n_ssids |
5351 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5352 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5353 | if (!request) { |
5354 | err = -ENOMEM; | |
5355 | goto unlock; | |
5356 | } | |
2a519311 | 5357 | |
2a519311 | 5358 | if (n_ssids) |
5ba63533 | 5359 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5360 | request->n_ssids = n_ssids; |
70692ad2 JM |
5361 | if (ie_len) { |
5362 | if (request->ssids) | |
5363 | request->ie = (void *)(request->ssids + n_ssids); | |
5364 | else | |
5365 | request->ie = (void *)(request->channels + n_channels); | |
5366 | } | |
2a519311 | 5367 | |
584991dc | 5368 | i = 0; |
2a519311 JB |
5369 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5370 | /* user specified, bail out if channel not found */ | |
2a519311 | 5371 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5372 | struct ieee80211_channel *chan; |
5373 | ||
5374 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5375 | ||
5376 | if (!chan) { | |
2a519311 JB |
5377 | err = -EINVAL; |
5378 | goto out_free; | |
5379 | } | |
584991dc JB |
5380 | |
5381 | /* ignore disabled channels */ | |
5382 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5383 | continue; | |
5384 | ||
5385 | request->channels[i] = chan; | |
2a519311 JB |
5386 | i++; |
5387 | } | |
5388 | } else { | |
34850ab2 JB |
5389 | enum ieee80211_band band; |
5390 | ||
2a519311 | 5391 | /* all channels */ |
2a519311 JB |
5392 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5393 | int j; | |
5394 | if (!wiphy->bands[band]) | |
5395 | continue; | |
5396 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5397 | struct ieee80211_channel *chan; |
5398 | ||
5399 | chan = &wiphy->bands[band]->channels[j]; | |
5400 | ||
5401 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5402 | continue; | |
5403 | ||
5404 | request->channels[i] = chan; | |
2a519311 JB |
5405 | i++; |
5406 | } | |
5407 | } | |
5408 | } | |
5409 | ||
584991dc JB |
5410 | if (!i) { |
5411 | err = -EINVAL; | |
5412 | goto out_free; | |
5413 | } | |
5414 | ||
5415 | request->n_channels = i; | |
5416 | ||
2a519311 JB |
5417 | i = 0; |
5418 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5419 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5420 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5421 | err = -EINVAL; |
5422 | goto out_free; | |
5423 | } | |
57a27e1d | 5424 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5425 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5426 | i++; |
5427 | } | |
5428 | } | |
5429 | ||
70692ad2 JM |
5430 | if (info->attrs[NL80211_ATTR_IE]) { |
5431 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5432 | memcpy((void *)request->ie, |
5433 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5434 | request->ie_len); |
5435 | } | |
5436 | ||
34850ab2 | 5437 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5438 | if (wiphy->bands[i]) |
5439 | request->rates[i] = | |
5440 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5441 | |
5442 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5443 | nla_for_each_nested(attr, | |
5444 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5445 | tmp) { | |
5446 | enum ieee80211_band band = nla_type(attr); | |
5447 | ||
84404623 | 5448 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5449 | err = -EINVAL; |
5450 | goto out_free; | |
5451 | } | |
1b09cd82 FF |
5452 | |
5453 | if (!wiphy->bands[band]) | |
5454 | continue; | |
5455 | ||
34850ab2 JB |
5456 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5457 | nla_data(attr), | |
5458 | nla_len(attr), | |
5459 | &request->rates[band]); | |
5460 | if (err) | |
5461 | goto out_free; | |
5462 | } | |
5463 | } | |
5464 | ||
46856bbf | 5465 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5466 | request->flags = nla_get_u32( |
5467 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5468 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5469 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5470 | err = -EOPNOTSUPP; |
5471 | goto out_free; | |
5472 | } | |
5473 | } | |
ed473771 | 5474 | |
e9f935e3 RM |
5475 | request->no_cck = |
5476 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5477 | ||
fd014284 | 5478 | request->wdev = wdev; |
79c97e97 | 5479 | request->wiphy = &rdev->wiphy; |
15d6030b | 5480 | request->scan_start = jiffies; |
2a519311 | 5481 | |
79c97e97 | 5482 | rdev->scan_req = request; |
e35e4d28 | 5483 | err = rdev_scan(rdev, request); |
2a519311 | 5484 | |
463d0183 | 5485 | if (!err) { |
fd014284 JB |
5486 | nl80211_send_scan_start(rdev, wdev); |
5487 | if (wdev->netdev) | |
5488 | dev_hold(wdev->netdev); | |
4c476991 | 5489 | } else { |
2a519311 | 5490 | out_free: |
79c97e97 | 5491 | rdev->scan_req = NULL; |
2a519311 JB |
5492 | kfree(request); |
5493 | } | |
3b85875a | 5494 | |
f9f47529 | 5495 | unlock: |
2a519311 JB |
5496 | return err; |
5497 | } | |
5498 | ||
807f8a8c LC |
5499 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5500 | struct genl_info *info) | |
5501 | { | |
5502 | struct cfg80211_sched_scan_request *request; | |
5503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5504 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5505 | struct nlattr *attr; |
5506 | struct wiphy *wiphy; | |
a1f1c21c | 5507 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5508 | u32 interval; |
807f8a8c LC |
5509 | enum ieee80211_band band; |
5510 | size_t ie_len; | |
a1f1c21c | 5511 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5512 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c LC |
5513 | |
5514 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5515 | !rdev->ops->sched_scan_start) | |
5516 | return -EOPNOTSUPP; | |
5517 | ||
5518 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5519 | return -EINVAL; | |
5520 | ||
bbe6ad6d LC |
5521 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5522 | return -EINVAL; | |
5523 | ||
5524 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5525 | if (interval == 0) | |
5526 | return -EINVAL; | |
5527 | ||
807f8a8c LC |
5528 | wiphy = &rdev->wiphy; |
5529 | ||
5530 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5531 | n_channels = validate_scan_freqs( | |
5532 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5533 | if (!n_channels) | |
5534 | return -EINVAL; | |
5535 | } else { | |
bdfbec2d | 5536 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5537 | } |
5538 | ||
5539 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5540 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5541 | tmp) | |
5542 | n_ssids++; | |
5543 | ||
93b6aa69 | 5544 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5545 | return -EINVAL; |
5546 | ||
ea73cbce JB |
5547 | /* |
5548 | * First, count the number of 'real' matchsets. Due to an issue with | |
5549 | * the old implementation, matchsets containing only the RSSI attribute | |
5550 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5551 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5552 | * all APs with a strong RSSI. This is needed to be compatible with | |
5553 | * older userspace that treated a matchset with only the RSSI as the | |
5554 | * global RSSI for all other matchsets - if there are other matchsets. | |
5555 | */ | |
5556 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
a1f1c21c LC |
5557 | nla_for_each_nested(attr, |
5558 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
ea73cbce JB |
5559 | tmp) { |
5560 | struct nlattr *rssi; | |
5561 | ||
5562 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5563 | nla_data(attr), nla_len(attr), | |
5564 | nl80211_match_policy); | |
5565 | if (err) | |
5566 | return err; | |
5567 | /* add other standalone attributes here */ | |
5568 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5569 | n_match_sets++; | |
5570 | continue; | |
5571 | } | |
5572 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5573 | if (rssi) | |
5574 | default_match_rssi = nla_get_s32(rssi); | |
5575 | } | |
5576 | } | |
5577 | ||
5578 | /* However, if there's no other matchset, add the RSSI one */ | |
5579 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
5580 | n_match_sets = 1; | |
a1f1c21c LC |
5581 | |
5582 | if (n_match_sets > wiphy->max_match_sets) | |
5583 | return -EINVAL; | |
5584 | ||
807f8a8c LC |
5585 | if (info->attrs[NL80211_ATTR_IE]) |
5586 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5587 | else | |
5588 | ie_len = 0; | |
5589 | ||
5a865bad | 5590 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5591 | return -EINVAL; |
5592 | ||
c10841ca LC |
5593 | if (rdev->sched_scan_req) { |
5594 | err = -EINPROGRESS; | |
5595 | goto out; | |
5596 | } | |
5597 | ||
807f8a8c | 5598 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5599 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5600 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5601 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5602 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5603 | if (!request) { |
5604 | err = -ENOMEM; | |
5605 | goto out; | |
5606 | } | |
807f8a8c LC |
5607 | |
5608 | if (n_ssids) | |
5609 | request->ssids = (void *)&request->channels[n_channels]; | |
5610 | request->n_ssids = n_ssids; | |
5611 | if (ie_len) { | |
5612 | if (request->ssids) | |
5613 | request->ie = (void *)(request->ssids + n_ssids); | |
5614 | else | |
5615 | request->ie = (void *)(request->channels + n_channels); | |
5616 | } | |
5617 | ||
a1f1c21c LC |
5618 | if (n_match_sets) { |
5619 | if (request->ie) | |
5620 | request->match_sets = (void *)(request->ie + ie_len); | |
5621 | else if (request->ssids) | |
5622 | request->match_sets = | |
5623 | (void *)(request->ssids + n_ssids); | |
5624 | else | |
5625 | request->match_sets = | |
5626 | (void *)(request->channels + n_channels); | |
5627 | } | |
5628 | request->n_match_sets = n_match_sets; | |
5629 | ||
807f8a8c LC |
5630 | i = 0; |
5631 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5632 | /* user specified, bail out if channel not found */ | |
5633 | nla_for_each_nested(attr, | |
5634 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5635 | tmp) { | |
5636 | struct ieee80211_channel *chan; | |
5637 | ||
5638 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5639 | ||
5640 | if (!chan) { | |
5641 | err = -EINVAL; | |
5642 | goto out_free; | |
5643 | } | |
5644 | ||
5645 | /* ignore disabled channels */ | |
5646 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5647 | continue; | |
5648 | ||
5649 | request->channels[i] = chan; | |
5650 | i++; | |
5651 | } | |
5652 | } else { | |
5653 | /* all channels */ | |
5654 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5655 | int j; | |
5656 | if (!wiphy->bands[band]) | |
5657 | continue; | |
5658 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5659 | struct ieee80211_channel *chan; | |
5660 | ||
5661 | chan = &wiphy->bands[band]->channels[j]; | |
5662 | ||
5663 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5664 | continue; | |
5665 | ||
5666 | request->channels[i] = chan; | |
5667 | i++; | |
5668 | } | |
5669 | } | |
5670 | } | |
5671 | ||
5672 | if (!i) { | |
5673 | err = -EINVAL; | |
5674 | goto out_free; | |
5675 | } | |
5676 | ||
5677 | request->n_channels = i; | |
5678 | ||
5679 | i = 0; | |
5680 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5681 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5682 | tmp) { | |
57a27e1d | 5683 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5684 | err = -EINVAL; |
5685 | goto out_free; | |
5686 | } | |
57a27e1d | 5687 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5688 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5689 | nla_len(attr)); | |
807f8a8c LC |
5690 | i++; |
5691 | } | |
5692 | } | |
5693 | ||
a1f1c21c LC |
5694 | i = 0; |
5695 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5696 | nla_for_each_nested(attr, | |
5697 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5698 | tmp) { | |
88e920b4 | 5699 | struct nlattr *ssid, *rssi; |
a1f1c21c | 5700 | |
ae811e21 JB |
5701 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
5702 | nla_data(attr), nla_len(attr), | |
5703 | nl80211_match_policy); | |
5704 | if (err) | |
5705 | goto out_free; | |
4a4ab0d7 | 5706 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 5707 | if (ssid) { |
ea73cbce JB |
5708 | if (WARN_ON(i >= n_match_sets)) { |
5709 | /* this indicates a programming error, | |
5710 | * the loop above should have verified | |
5711 | * things properly | |
5712 | */ | |
5713 | err = -EINVAL; | |
5714 | goto out_free; | |
5715 | } | |
5716 | ||
a1f1c21c LC |
5717 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
5718 | err = -EINVAL; | |
5719 | goto out_free; | |
5720 | } | |
5721 | memcpy(request->match_sets[i].ssid.ssid, | |
5722 | nla_data(ssid), nla_len(ssid)); | |
5723 | request->match_sets[i].ssid.ssid_len = | |
5724 | nla_len(ssid); | |
ea73cbce JB |
5725 | /* special attribute - old implemenation w/a */ |
5726 | request->match_sets[i].rssi_thold = | |
5727 | default_match_rssi; | |
5728 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5729 | if (rssi) | |
5730 | request->match_sets[i].rssi_thold = | |
5731 | nla_get_s32(rssi); | |
a1f1c21c LC |
5732 | } |
5733 | i++; | |
5734 | } | |
ea73cbce JB |
5735 | |
5736 | /* there was no other matchset, so the RSSI one is alone */ | |
5737 | if (i == 0) | |
5738 | request->match_sets[0].rssi_thold = default_match_rssi; | |
5739 | ||
5740 | request->min_rssi_thold = INT_MAX; | |
5741 | for (i = 0; i < n_match_sets; i++) | |
5742 | request->min_rssi_thold = | |
5743 | min(request->match_sets[i].rssi_thold, | |
5744 | request->min_rssi_thold); | |
5745 | } else { | |
5746 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5747 | } |
5748 | ||
9900e484 JB |
5749 | if (ie_len) { |
5750 | request->ie_len = ie_len; | |
807f8a8c LC |
5751 | memcpy((void *)request->ie, |
5752 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5753 | request->ie_len); | |
5754 | } | |
5755 | ||
46856bbf | 5756 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5757 | request->flags = nla_get_u32( |
5758 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5759 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5760 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5761 | err = -EOPNOTSUPP; |
5762 | goto out_free; | |
5763 | } | |
5764 | } | |
ed473771 | 5765 | |
807f8a8c LC |
5766 | request->dev = dev; |
5767 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5768 | request->interval = interval; |
15d6030b | 5769 | request->scan_start = jiffies; |
807f8a8c | 5770 | |
e35e4d28 | 5771 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5772 | if (!err) { |
5773 | rdev->sched_scan_req = request; | |
5774 | nl80211_send_sched_scan(rdev, dev, | |
5775 | NL80211_CMD_START_SCHED_SCAN); | |
5776 | goto out; | |
5777 | } | |
5778 | ||
5779 | out_free: | |
5780 | kfree(request); | |
5781 | out: | |
5782 | return err; | |
5783 | } | |
5784 | ||
5785 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5786 | struct genl_info *info) | |
5787 | { | |
5788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5789 | ||
5790 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5791 | !rdev->ops->sched_scan_stop) | |
5792 | return -EOPNOTSUPP; | |
5793 | ||
5fe231e8 | 5794 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5795 | } |
5796 | ||
04f39047 SW |
5797 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5798 | struct genl_info *info) | |
5799 | { | |
5800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5801 | struct net_device *dev = info->user_ptr[1]; | |
5802 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5803 | struct cfg80211_chan_def chandef; | |
55f7435c | 5804 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 5805 | unsigned int cac_time_ms; |
04f39047 SW |
5806 | int err; |
5807 | ||
55f7435c LR |
5808 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
5809 | if (dfs_region == NL80211_DFS_UNSET) | |
5810 | return -EINVAL; | |
5811 | ||
04f39047 SW |
5812 | err = nl80211_parse_chandef(rdev, info, &chandef); |
5813 | if (err) | |
5814 | return err; | |
5815 | ||
ff311bc1 SW |
5816 | if (netif_carrier_ok(dev)) |
5817 | return -EBUSY; | |
5818 | ||
04f39047 SW |
5819 | if (wdev->cac_started) |
5820 | return -EBUSY; | |
5821 | ||
2beb6dab LC |
5822 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
5823 | NL80211_IFTYPE_UNSPECIFIED); | |
04f39047 SW |
5824 | if (err < 0) |
5825 | return err; | |
5826 | ||
5827 | if (err == 0) | |
5828 | return -EINVAL; | |
5829 | ||
fe7c3a1f | 5830 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
5831 | return -EINVAL; |
5832 | ||
5833 | if (!rdev->ops->start_radar_detection) | |
5834 | return -EOPNOTSUPP; | |
5835 | ||
31559f35 JD |
5836 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
5837 | if (WARN_ON(!cac_time_ms)) | |
5838 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
5839 | ||
5840 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
5841 | cac_time_ms); | |
04f39047 | 5842 | if (!err) { |
9e0e2961 | 5843 | wdev->chandef = chandef; |
04f39047 SW |
5844 | wdev->cac_started = true; |
5845 | wdev->cac_start_time = jiffies; | |
31559f35 | 5846 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 5847 | } |
04f39047 SW |
5848 | return err; |
5849 | } | |
5850 | ||
16ef1fe2 SW |
5851 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
5852 | { | |
5853 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5854 | struct net_device *dev = info->user_ptr[1]; | |
5855 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5856 | struct cfg80211_csa_settings params; | |
5857 | /* csa_attrs is defined static to avoid waste of stack size - this | |
5858 | * function is called under RTNL lock, so this should not be a problem. | |
5859 | */ | |
5860 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
5861 | u8 radar_detect_width = 0; | |
5862 | int err; | |
ee4bc9e7 | 5863 | bool need_new_beacon = false; |
16ef1fe2 SW |
5864 | |
5865 | if (!rdev->ops->channel_switch || | |
5866 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
5867 | return -EOPNOTSUPP; | |
5868 | ||
ee4bc9e7 SW |
5869 | switch (dev->ieee80211_ptr->iftype) { |
5870 | case NL80211_IFTYPE_AP: | |
5871 | case NL80211_IFTYPE_P2P_GO: | |
5872 | need_new_beacon = true; | |
5873 | ||
5874 | /* useless if AP is not running */ | |
5875 | if (!wdev->beacon_interval) | |
1ff79dfa | 5876 | return -ENOTCONN; |
ee4bc9e7 SW |
5877 | break; |
5878 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
5879 | if (!wdev->ssid_len) |
5880 | return -ENOTCONN; | |
5881 | break; | |
c6da674a | 5882 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
5883 | if (!wdev->mesh_id_len) |
5884 | return -ENOTCONN; | |
ee4bc9e7 SW |
5885 | break; |
5886 | default: | |
16ef1fe2 | 5887 | return -EOPNOTSUPP; |
ee4bc9e7 | 5888 | } |
16ef1fe2 SW |
5889 | |
5890 | memset(¶ms, 0, sizeof(params)); | |
5891 | ||
5892 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5893 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
5894 | return -EINVAL; | |
5895 | ||
5896 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 5897 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
5898 | return -EINVAL; |
5899 | ||
5900 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
5901 | ||
ee4bc9e7 SW |
5902 | if (!need_new_beacon) |
5903 | goto skip_beacons; | |
5904 | ||
16ef1fe2 SW |
5905 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
5906 | if (err) | |
5907 | return err; | |
5908 | ||
5909 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
5910 | info->attrs[NL80211_ATTR_CSA_IES], | |
5911 | nl80211_policy); | |
5912 | if (err) | |
5913 | return err; | |
5914 | ||
5915 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
5916 | if (err) | |
5917 | return err; | |
5918 | ||
5919 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
5920 | return -EINVAL; | |
5921 | ||
5922 | params.counter_offset_beacon = | |
5923 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
5924 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) | |
5925 | return -EINVAL; | |
5926 | ||
5927 | /* sanity check - counters should be the same */ | |
5928 | if (params.beacon_csa.tail[params.counter_offset_beacon] != | |
5929 | params.count) | |
5930 | return -EINVAL; | |
5931 | ||
5932 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { | |
5933 | params.counter_offset_presp = | |
5934 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
5935 | if (params.counter_offset_presp >= | |
5936 | params.beacon_csa.probe_resp_len) | |
5937 | return -EINVAL; | |
5938 | ||
5939 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != | |
5940 | params.count) | |
5941 | return -EINVAL; | |
5942 | } | |
5943 | ||
ee4bc9e7 | 5944 | skip_beacons: |
16ef1fe2 SW |
5945 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
5946 | if (err) | |
5947 | return err; | |
5948 | ||
174e0cd2 IP |
5949 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
5950 | wdev->iftype)) | |
16ef1fe2 SW |
5951 | return -EINVAL; |
5952 | ||
2beb6dab LC |
5953 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
5954 | ¶ms.chandef, | |
5955 | wdev->iftype); | |
5956 | if (err < 0) | |
5957 | return err; | |
5958 | ||
5959 | if (err > 0) { | |
5960 | radar_detect_width = BIT(params.chandef.width); | |
5961 | params.radar_required = true; | |
16ef1fe2 SW |
5962 | } |
5963 | ||
73de86a3 LC |
5964 | /* TODO: I left this here for now. With channel switch, the |
5965 | * verification is a bit more complicated, because we only do | |
5966 | * it later when the channel switch really happens. | |
5967 | */ | |
16ef1fe2 SW |
5968 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5969 | params.chandef.chan, | |
5970 | CHAN_MODE_SHARED, | |
5971 | radar_detect_width); | |
5972 | if (err) | |
5973 | return err; | |
5974 | ||
5975 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) | |
5976 | params.block_tx = true; | |
5977 | ||
c56589ed SW |
5978 | wdev_lock(wdev); |
5979 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
5980 | wdev_unlock(wdev); | |
5981 | ||
5982 | return err; | |
16ef1fe2 SW |
5983 | } |
5984 | ||
9720bb3a JB |
5985 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5986 | u32 seq, int flags, | |
2a519311 | 5987 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5988 | struct wireless_dev *wdev, |
5989 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5990 | { |
48ab905d | 5991 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5992 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5993 | void *hdr; |
5994 | struct nlattr *bss; | |
8cef2c9d | 5995 | bool tsf = false; |
48ab905d JB |
5996 | |
5997 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5998 | |
15e47304 | 5999 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6000 | NL80211_CMD_NEW_SCAN_RESULTS); |
6001 | if (!hdr) | |
6002 | return -1; | |
6003 | ||
9720bb3a JB |
6004 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6005 | ||
97990a06 JB |
6006 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6007 | goto nla_put_failure; | |
6008 | if (wdev->netdev && | |
9360ffd1 DM |
6009 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6010 | goto nla_put_failure; | |
97990a06 JB |
6011 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6012 | goto nla_put_failure; | |
2a519311 JB |
6013 | |
6014 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6015 | if (!bss) | |
6016 | goto nla_put_failure; | |
9360ffd1 | 6017 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6018 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6019 | goto nla_put_failure; |
9caf0364 JB |
6020 | |
6021 | rcu_read_lock(); | |
6022 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
6023 | if (ies) { |
6024 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6025 | goto fail_unlock_rcu; | |
6026 | tsf = true; | |
6027 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
6028 | ies->len, ies->data)) | |
6029 | goto fail_unlock_rcu; | |
9caf0364 JB |
6030 | } |
6031 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
6032 | if (ies) { |
6033 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6034 | goto fail_unlock_rcu; | |
6035 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6036 | ies->len, ies->data)) | |
6037 | goto fail_unlock_rcu; | |
9caf0364 JB |
6038 | } |
6039 | rcu_read_unlock(); | |
6040 | ||
9360ffd1 DM |
6041 | if (res->beacon_interval && |
6042 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6043 | goto nla_put_failure; | |
6044 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6045 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6046 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6047 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6048 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6049 | goto nla_put_failure; | |
2a519311 | 6050 | |
77965c97 | 6051 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6052 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6053 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6054 | goto nla_put_failure; | |
2a519311 JB |
6055 | break; |
6056 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6057 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6058 | goto nla_put_failure; | |
2a519311 JB |
6059 | break; |
6060 | default: | |
6061 | break; | |
6062 | } | |
6063 | ||
48ab905d | 6064 | switch (wdev->iftype) { |
074ac8df | 6065 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6066 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6067 | if (intbss == wdev->current_bss && |
6068 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6069 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6070 | goto nla_put_failure; | |
48ab905d JB |
6071 | break; |
6072 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6073 | if (intbss == wdev->current_bss && |
6074 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6075 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6076 | goto nla_put_failure; | |
48ab905d JB |
6077 | break; |
6078 | default: | |
6079 | break; | |
6080 | } | |
6081 | ||
2a519311 JB |
6082 | nla_nest_end(msg, bss); |
6083 | ||
6084 | return genlmsg_end(msg, hdr); | |
6085 | ||
8cef2c9d JB |
6086 | fail_unlock_rcu: |
6087 | rcu_read_unlock(); | |
2a519311 JB |
6088 | nla_put_failure: |
6089 | genlmsg_cancel(msg, hdr); | |
6090 | return -EMSGSIZE; | |
6091 | } | |
6092 | ||
97990a06 | 6093 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6094 | { |
48ab905d | 6095 | struct cfg80211_registered_device *rdev; |
2a519311 | 6096 | struct cfg80211_internal_bss *scan; |
48ab905d | 6097 | struct wireless_dev *wdev; |
97990a06 | 6098 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6099 | int err; |
6100 | ||
97990a06 | 6101 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6102 | if (err) |
6103 | return err; | |
2a519311 | 6104 | |
48ab905d JB |
6105 | wdev_lock(wdev); |
6106 | spin_lock_bh(&rdev->bss_lock); | |
6107 | cfg80211_bss_expire(rdev); | |
6108 | ||
9720bb3a JB |
6109 | cb->seq = rdev->bss_generation; |
6110 | ||
48ab905d | 6111 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6112 | if (++idx <= start) |
6113 | continue; | |
9720bb3a | 6114 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6115 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6116 | rdev, wdev, scan) < 0) { |
2a519311 | 6117 | idx--; |
67748893 | 6118 | break; |
2a519311 JB |
6119 | } |
6120 | } | |
6121 | ||
48ab905d JB |
6122 | spin_unlock_bh(&rdev->bss_lock); |
6123 | wdev_unlock(wdev); | |
2a519311 | 6124 | |
97990a06 JB |
6125 | cb->args[2] = idx; |
6126 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6127 | |
67748893 | 6128 | return skb->len; |
2a519311 JB |
6129 | } |
6130 | ||
15e47304 | 6131 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6132 | int flags, struct net_device *dev, |
6133 | struct survey_info *survey) | |
6134 | { | |
6135 | void *hdr; | |
6136 | struct nlattr *infoattr; | |
6137 | ||
15e47304 | 6138 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6139 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6140 | if (!hdr) | |
6141 | return -ENOMEM; | |
6142 | ||
9360ffd1 DM |
6143 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6144 | goto nla_put_failure; | |
61fa713c HS |
6145 | |
6146 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6147 | if (!infoattr) | |
6148 | goto nla_put_failure; | |
6149 | ||
9360ffd1 DM |
6150 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6151 | survey->channel->center_freq)) | |
6152 | goto nla_put_failure; | |
6153 | ||
6154 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6155 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6156 | goto nla_put_failure; | |
6157 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6158 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6159 | goto nla_put_failure; | |
6160 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6161 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6162 | survey->channel_time)) | |
6163 | goto nla_put_failure; | |
6164 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6165 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6166 | survey->channel_time_busy)) | |
6167 | goto nla_put_failure; | |
6168 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6169 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6170 | survey->channel_time_ext_busy)) | |
6171 | goto nla_put_failure; | |
6172 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6173 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6174 | survey->channel_time_rx)) | |
6175 | goto nla_put_failure; | |
6176 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6177 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6178 | survey->channel_time_tx)) | |
6179 | goto nla_put_failure; | |
61fa713c HS |
6180 | |
6181 | nla_nest_end(msg, infoattr); | |
6182 | ||
6183 | return genlmsg_end(msg, hdr); | |
6184 | ||
6185 | nla_put_failure: | |
6186 | genlmsg_cancel(msg, hdr); | |
6187 | return -EMSGSIZE; | |
6188 | } | |
6189 | ||
6190 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6191 | struct netlink_callback *cb) | |
6192 | { | |
6193 | struct survey_info survey; | |
1b8ec87a | 6194 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6195 | struct wireless_dev *wdev; |
6196 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6197 | int res; |
6198 | ||
1b8ec87a | 6199 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6200 | if (res) |
6201 | return res; | |
61fa713c | 6202 | |
97990a06 JB |
6203 | if (!wdev->netdev) { |
6204 | res = -EINVAL; | |
6205 | goto out_err; | |
6206 | } | |
6207 | ||
1b8ec87a | 6208 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6209 | res = -EOPNOTSUPP; |
6210 | goto out_err; | |
6211 | } | |
6212 | ||
6213 | while (1) { | |
180cdc79 LR |
6214 | struct ieee80211_channel *chan; |
6215 | ||
1b8ec87a | 6216 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6217 | if (res == -ENOENT) |
6218 | break; | |
6219 | if (res) | |
6220 | goto out_err; | |
6221 | ||
180cdc79 LR |
6222 | /* Survey without a channel doesn't make sense */ |
6223 | if (!survey.channel) { | |
6224 | res = -EINVAL; | |
6225 | goto out; | |
6226 | } | |
6227 | ||
1b8ec87a | 6228 | chan = ieee80211_get_channel(&rdev->wiphy, |
180cdc79 LR |
6229 | survey.channel->center_freq); |
6230 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6231 | survey_idx++; | |
6232 | continue; | |
6233 | } | |
6234 | ||
61fa713c | 6235 | if (nl80211_send_survey(skb, |
15e47304 | 6236 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6237 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6238 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6239 | goto out; |
6240 | survey_idx++; | |
6241 | } | |
6242 | ||
6243 | out: | |
97990a06 | 6244 | cb->args[2] = survey_idx; |
61fa713c HS |
6245 | res = skb->len; |
6246 | out_err: | |
1b8ec87a | 6247 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6248 | return res; |
6249 | } | |
6250 | ||
b23aa676 SO |
6251 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6252 | { | |
6253 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6254 | NL80211_WPA_VERSION_2)); | |
6255 | } | |
6256 | ||
636a5d36 JM |
6257 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6258 | { | |
4c476991 JB |
6259 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6260 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6261 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6262 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6263 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6264 | enum nl80211_auth_type auth_type; |
fffd0934 | 6265 | struct key_parse key; |
d5cdfacb | 6266 | bool local_state_change; |
636a5d36 | 6267 | |
f4a11bb0 JB |
6268 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6269 | return -EINVAL; | |
6270 | ||
6271 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6272 | return -EINVAL; | |
6273 | ||
1778092e JM |
6274 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6275 | return -EINVAL; | |
6276 | ||
19957bb3 JB |
6277 | if (!info->attrs[NL80211_ATTR_SSID]) |
6278 | return -EINVAL; | |
6279 | ||
6280 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6281 | return -EINVAL; | |
6282 | ||
fffd0934 JB |
6283 | err = nl80211_parse_key(info, &key); |
6284 | if (err) | |
6285 | return err; | |
6286 | ||
6287 | if (key.idx >= 0) { | |
e31b8213 JB |
6288 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6289 | return -EINVAL; | |
fffd0934 JB |
6290 | if (!key.p.key || !key.p.key_len) |
6291 | return -EINVAL; | |
6292 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6293 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6294 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6295 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6296 | return -EINVAL; | |
6297 | if (key.idx > 4) | |
6298 | return -EINVAL; | |
6299 | } else { | |
6300 | key.p.key_len = 0; | |
6301 | key.p.key = NULL; | |
6302 | } | |
6303 | ||
afea0b7a JB |
6304 | if (key.idx >= 0) { |
6305 | int i; | |
6306 | bool ok = false; | |
6307 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6308 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6309 | ok = true; | |
6310 | break; | |
6311 | } | |
6312 | } | |
4c476991 JB |
6313 | if (!ok) |
6314 | return -EINVAL; | |
afea0b7a JB |
6315 | } |
6316 | ||
4c476991 JB |
6317 | if (!rdev->ops->auth) |
6318 | return -EOPNOTSUPP; | |
636a5d36 | 6319 | |
074ac8df | 6320 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6321 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6322 | return -EOPNOTSUPP; | |
eec60b03 | 6323 | |
19957bb3 | 6324 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6325 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6326 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6327 | if (!chan) | |
4c476991 | 6328 | return -EINVAL; |
636a5d36 | 6329 | |
19957bb3 JB |
6330 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6331 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6332 | |
6333 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6334 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6335 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6336 | } |
6337 | ||
19957bb3 | 6338 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6339 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6340 | return -EINVAL; |
636a5d36 | 6341 | |
e39e5b5e JM |
6342 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6343 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6344 | return -EINVAL; | |
6345 | ||
6346 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6347 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6348 | return -EINVAL; | |
6349 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6350 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6351 | /* need to include at least Auth Transaction and Status Code */ | |
6352 | if (sae_data_len < 4) | |
6353 | return -EINVAL; | |
6354 | } | |
6355 | ||
d5cdfacb JM |
6356 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6357 | ||
95de817b JB |
6358 | /* |
6359 | * Since we no longer track auth state, ignore | |
6360 | * requests to only change local state. | |
6361 | */ | |
6362 | if (local_state_change) | |
6363 | return 0; | |
6364 | ||
91bf9b26 JB |
6365 | wdev_lock(dev->ieee80211_ptr); |
6366 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6367 | ssid, ssid_len, ie, ie_len, | |
6368 | key.p.key, key.p.key_len, key.idx, | |
6369 | sae_data, sae_data_len); | |
6370 | wdev_unlock(dev->ieee80211_ptr); | |
6371 | return err; | |
636a5d36 JM |
6372 | } |
6373 | ||
c0692b8f JB |
6374 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6375 | struct genl_info *info, | |
3dc27d25 JB |
6376 | struct cfg80211_crypto_settings *settings, |
6377 | int cipher_limit) | |
b23aa676 | 6378 | { |
c0b2bbd8 JB |
6379 | memset(settings, 0, sizeof(*settings)); |
6380 | ||
b23aa676 SO |
6381 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6382 | ||
c0692b8f JB |
6383 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6384 | u16 proto; | |
6385 | proto = nla_get_u16( | |
6386 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6387 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6388 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6389 | proto != ETH_P_PAE) | |
6390 | return -EINVAL; | |
6391 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6392 | settings->control_port_no_encrypt = true; | |
6393 | } else | |
6394 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6395 | ||
b23aa676 SO |
6396 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6397 | void *data; | |
6398 | int len, i; | |
6399 | ||
6400 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6401 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6402 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6403 | ||
6404 | if (len % sizeof(u32)) | |
6405 | return -EINVAL; | |
6406 | ||
3dc27d25 | 6407 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6408 | return -EINVAL; |
6409 | ||
6410 | memcpy(settings->ciphers_pairwise, data, len); | |
6411 | ||
6412 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6413 | if (!cfg80211_supported_cipher_suite( |
6414 | &rdev->wiphy, | |
b23aa676 SO |
6415 | settings->ciphers_pairwise[i])) |
6416 | return -EINVAL; | |
6417 | } | |
6418 | ||
6419 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6420 | settings->cipher_group = | |
6421 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6422 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6423 | settings->cipher_group)) | |
b23aa676 SO |
6424 | return -EINVAL; |
6425 | } | |
6426 | ||
6427 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6428 | settings->wpa_versions = | |
6429 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6430 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6431 | return -EINVAL; | |
6432 | } | |
6433 | ||
6434 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6435 | void *data; | |
6d30240e | 6436 | int len; |
b23aa676 SO |
6437 | |
6438 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6439 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6440 | settings->n_akm_suites = len / sizeof(u32); | |
6441 | ||
6442 | if (len % sizeof(u32)) | |
6443 | return -EINVAL; | |
6444 | ||
1b9ca027 JM |
6445 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6446 | return -EINVAL; | |
6447 | ||
b23aa676 | 6448 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6449 | } |
6450 | ||
6451 | return 0; | |
6452 | } | |
6453 | ||
636a5d36 JM |
6454 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6455 | { | |
4c476991 JB |
6456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6457 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6458 | struct ieee80211_channel *chan; |
f62fab73 JB |
6459 | struct cfg80211_assoc_request req = {}; |
6460 | const u8 *bssid, *ssid; | |
6461 | int err, ssid_len = 0; | |
636a5d36 | 6462 | |
f4a11bb0 JB |
6463 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6464 | return -EINVAL; | |
6465 | ||
6466 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6467 | !info->attrs[NL80211_ATTR_SSID] || |
6468 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6469 | return -EINVAL; |
6470 | ||
4c476991 JB |
6471 | if (!rdev->ops->assoc) |
6472 | return -EOPNOTSUPP; | |
636a5d36 | 6473 | |
074ac8df | 6474 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6475 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6476 | return -EOPNOTSUPP; | |
eec60b03 | 6477 | |
19957bb3 | 6478 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6479 | |
664834de JM |
6480 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6481 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6482 | if (!chan) | |
4c476991 | 6483 | return -EINVAL; |
636a5d36 | 6484 | |
19957bb3 JB |
6485 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6486 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6487 | |
6488 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6489 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6490 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6491 | } |
6492 | ||
dc6382ce | 6493 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6494 | enum nl80211_mfp mfp = |
dc6382ce | 6495 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6496 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6497 | req.use_mfp = true; |
4c476991 JB |
6498 | else if (mfp != NL80211_MFP_NO) |
6499 | return -EINVAL; | |
dc6382ce JM |
6500 | } |
6501 | ||
3e5d7649 | 6502 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6503 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6504 | |
7e7c8926 | 6505 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6506 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6507 | |
6508 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6509 | memcpy(&req.ht_capa_mask, |
6510 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6511 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6512 | |
6513 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6514 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6515 | return -EINVAL; |
f62fab73 JB |
6516 | memcpy(&req.ht_capa, |
6517 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6518 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6519 | } |
6520 | ||
ee2aca34 | 6521 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6522 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6523 | |
6524 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6525 | memcpy(&req.vht_capa_mask, |
6526 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6527 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6528 | |
6529 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6530 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6531 | return -EINVAL; |
f62fab73 JB |
6532 | memcpy(&req.vht_capa, |
6533 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6534 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6535 | } |
6536 | ||
f62fab73 | 6537 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6538 | if (!err) { |
6539 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6540 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6541 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6542 | wdev_unlock(dev->ieee80211_ptr); |
6543 | } | |
636a5d36 | 6544 | |
636a5d36 JM |
6545 | return err; |
6546 | } | |
6547 | ||
6548 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6549 | { | |
4c476991 JB |
6550 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6551 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6552 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6553 | int ie_len = 0, err; |
19957bb3 | 6554 | u16 reason_code; |
d5cdfacb | 6555 | bool local_state_change; |
636a5d36 | 6556 | |
f4a11bb0 JB |
6557 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6558 | return -EINVAL; | |
6559 | ||
6560 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6561 | return -EINVAL; | |
6562 | ||
6563 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6564 | return -EINVAL; | |
6565 | ||
4c476991 JB |
6566 | if (!rdev->ops->deauth) |
6567 | return -EOPNOTSUPP; | |
636a5d36 | 6568 | |
074ac8df | 6569 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6570 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6571 | return -EOPNOTSUPP; | |
eec60b03 | 6572 | |
19957bb3 | 6573 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6574 | |
19957bb3 JB |
6575 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6576 | if (reason_code == 0) { | |
f4a11bb0 | 6577 | /* Reason Code 0 is reserved */ |
4c476991 | 6578 | return -EINVAL; |
255e737e | 6579 | } |
636a5d36 JM |
6580 | |
6581 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6582 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6583 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6584 | } |
6585 | ||
d5cdfacb JM |
6586 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6587 | ||
91bf9b26 JB |
6588 | wdev_lock(dev->ieee80211_ptr); |
6589 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6590 | local_state_change); | |
6591 | wdev_unlock(dev->ieee80211_ptr); | |
6592 | return err; | |
636a5d36 JM |
6593 | } |
6594 | ||
6595 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6596 | { | |
4c476991 JB |
6597 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6598 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6599 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6600 | int ie_len = 0, err; |
19957bb3 | 6601 | u16 reason_code; |
d5cdfacb | 6602 | bool local_state_change; |
636a5d36 | 6603 | |
f4a11bb0 JB |
6604 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6605 | return -EINVAL; | |
6606 | ||
6607 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6608 | return -EINVAL; | |
6609 | ||
6610 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6611 | return -EINVAL; | |
6612 | ||
4c476991 JB |
6613 | if (!rdev->ops->disassoc) |
6614 | return -EOPNOTSUPP; | |
636a5d36 | 6615 | |
074ac8df | 6616 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6618 | return -EOPNOTSUPP; | |
eec60b03 | 6619 | |
19957bb3 | 6620 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6621 | |
19957bb3 JB |
6622 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6623 | if (reason_code == 0) { | |
f4a11bb0 | 6624 | /* Reason Code 0 is reserved */ |
4c476991 | 6625 | return -EINVAL; |
255e737e | 6626 | } |
636a5d36 JM |
6627 | |
6628 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6629 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6630 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6631 | } |
6632 | ||
d5cdfacb JM |
6633 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6634 | ||
91bf9b26 JB |
6635 | wdev_lock(dev->ieee80211_ptr); |
6636 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6637 | local_state_change); | |
6638 | wdev_unlock(dev->ieee80211_ptr); | |
6639 | return err; | |
636a5d36 JM |
6640 | } |
6641 | ||
dd5b4cc7 FF |
6642 | static bool |
6643 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6644 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6645 | int rateval) | |
6646 | { | |
6647 | struct wiphy *wiphy = &rdev->wiphy; | |
6648 | bool found = false; | |
6649 | int band, i; | |
6650 | ||
6651 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6652 | struct ieee80211_supported_band *sband; | |
6653 | ||
6654 | sband = wiphy->bands[band]; | |
6655 | if (!sband) | |
6656 | continue; | |
6657 | ||
6658 | for (i = 0; i < sband->n_bitrates; i++) { | |
6659 | if (sband->bitrates[i].bitrate == rateval) { | |
6660 | mcast_rate[band] = i + 1; | |
6661 | found = true; | |
6662 | break; | |
6663 | } | |
6664 | } | |
6665 | } | |
6666 | ||
6667 | return found; | |
6668 | } | |
6669 | ||
04a773ad JB |
6670 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6671 | { | |
4c476991 JB |
6672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6673 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6674 | struct cfg80211_ibss_params ibss; |
6675 | struct wiphy *wiphy; | |
fffd0934 | 6676 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6677 | int err; |
6678 | ||
8e30bc55 JB |
6679 | memset(&ibss, 0, sizeof(ibss)); |
6680 | ||
04a773ad JB |
6681 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6682 | return -EINVAL; | |
6683 | ||
683b6d3b | 6684 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6685 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6686 | return -EINVAL; | |
6687 | ||
8e30bc55 JB |
6688 | ibss.beacon_interval = 100; |
6689 | ||
6690 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6691 | ibss.beacon_interval = | |
6692 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6693 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6694 | return -EINVAL; | |
6695 | } | |
6696 | ||
4c476991 JB |
6697 | if (!rdev->ops->join_ibss) |
6698 | return -EOPNOTSUPP; | |
04a773ad | 6699 | |
4c476991 JB |
6700 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6701 | return -EOPNOTSUPP; | |
04a773ad | 6702 | |
79c97e97 | 6703 | wiphy = &rdev->wiphy; |
04a773ad | 6704 | |
39193498 | 6705 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6706 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6707 | |
6708 | if (!is_valid_ether_addr(ibss.bssid)) | |
6709 | return -EINVAL; | |
6710 | } | |
04a773ad JB |
6711 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6712 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6713 | ||
6714 | if (info->attrs[NL80211_ATTR_IE]) { | |
6715 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6716 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6717 | } | |
6718 | ||
683b6d3b JB |
6719 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6720 | if (err) | |
6721 | return err; | |
04a773ad | 6722 | |
174e0cd2 IP |
6723 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
6724 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
6725 | return -EINVAL; |
6726 | ||
2f301ab2 | 6727 | switch (ibss.chandef.width) { |
bf372645 SW |
6728 | case NL80211_CHAN_WIDTH_5: |
6729 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6730 | case NL80211_CHAN_WIDTH_20_NOHT: |
6731 | break; | |
6732 | case NL80211_CHAN_WIDTH_20: | |
6733 | case NL80211_CHAN_WIDTH_40: | |
6734 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6735 | break; | |
6736 | default: | |
c04d6150 | 6737 | return -EINVAL; |
2f301ab2 | 6738 | } |
db9c64cf | 6739 | |
04a773ad | 6740 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6741 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6742 | ||
fbd2c8dc TP |
6743 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6744 | u8 *rates = | |
6745 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6746 | int n_rates = | |
6747 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6748 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6749 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6750 | |
34850ab2 JB |
6751 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6752 | &ibss.basic_rates); | |
6753 | if (err) | |
6754 | return err; | |
fbd2c8dc | 6755 | } |
dd5b4cc7 | 6756 | |
803768f5 SW |
6757 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6758 | memcpy(&ibss.ht_capa_mask, | |
6759 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6760 | sizeof(ibss.ht_capa_mask)); | |
6761 | ||
6762 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6763 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6764 | return -EINVAL; | |
6765 | memcpy(&ibss.ht_capa, | |
6766 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6767 | sizeof(ibss.ht_capa)); | |
6768 | } | |
6769 | ||
dd5b4cc7 FF |
6770 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6771 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6772 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6773 | return -EINVAL; | |
fbd2c8dc | 6774 | |
4c476991 | 6775 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6776 | bool no_ht = false; |
6777 | ||
4c476991 | 6778 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6779 | info->attrs[NL80211_ATTR_KEYS], |
6780 | &no_ht); | |
4c476991 JB |
6781 | if (IS_ERR(connkeys)) |
6782 | return PTR_ERR(connkeys); | |
de7044ee | 6783 | |
3d9d1d66 JB |
6784 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6785 | no_ht) { | |
de7044ee SM |
6786 | kfree(connkeys); |
6787 | return -EINVAL; | |
6788 | } | |
4c476991 | 6789 | } |
04a773ad | 6790 | |
267335d6 AQ |
6791 | ibss.control_port = |
6792 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6793 | ||
5336fa88 SW |
6794 | ibss.userspace_handles_dfs = |
6795 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
6796 | ||
4c476991 | 6797 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6798 | if (err) |
6799 | kfree(connkeys); | |
04a773ad JB |
6800 | return err; |
6801 | } | |
6802 | ||
6803 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6804 | { | |
4c476991 JB |
6805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6806 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6807 | |
4c476991 JB |
6808 | if (!rdev->ops->leave_ibss) |
6809 | return -EOPNOTSUPP; | |
04a773ad | 6810 | |
4c476991 JB |
6811 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6812 | return -EOPNOTSUPP; | |
04a773ad | 6813 | |
4c476991 | 6814 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6815 | } |
6816 | ||
f4e583c8 AQ |
6817 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6818 | { | |
6819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6820 | struct net_device *dev = info->user_ptr[1]; | |
6821 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6822 | u32 nla_rate; | |
6823 | int err; | |
6824 | ||
6825 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6826 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6827 | return -EOPNOTSUPP; | |
6828 | ||
6829 | if (!rdev->ops->set_mcast_rate) | |
6830 | return -EOPNOTSUPP; | |
6831 | ||
6832 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6833 | ||
6834 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6835 | return -EINVAL; | |
6836 | ||
6837 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6838 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6839 | return -EINVAL; | |
6840 | ||
6841 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6842 | ||
6843 | return err; | |
6844 | } | |
6845 | ||
ad7e718c JB |
6846 | static struct sk_buff * |
6847 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6848 | int approxlen, u32 portid, u32 seq, | |
6849 | enum nl80211_commands cmd, | |
567ffc35 JB |
6850 | enum nl80211_attrs attr, |
6851 | const struct nl80211_vendor_cmd_info *info, | |
6852 | gfp_t gfp) | |
ad7e718c JB |
6853 | { |
6854 | struct sk_buff *skb; | |
6855 | void *hdr; | |
6856 | struct nlattr *data; | |
6857 | ||
6858 | skb = nlmsg_new(approxlen + 100, gfp); | |
6859 | if (!skb) | |
6860 | return NULL; | |
6861 | ||
6862 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
6863 | if (!hdr) { | |
6864 | kfree_skb(skb); | |
6865 | return NULL; | |
6866 | } | |
6867 | ||
6868 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
6869 | goto nla_put_failure; | |
567ffc35 JB |
6870 | |
6871 | if (info) { | |
6872 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
6873 | info->vendor_id)) | |
6874 | goto nla_put_failure; | |
6875 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
6876 | info->subcmd)) | |
6877 | goto nla_put_failure; | |
6878 | } | |
6879 | ||
ad7e718c JB |
6880 | data = nla_nest_start(skb, attr); |
6881 | ||
6882 | ((void **)skb->cb)[0] = rdev; | |
6883 | ((void **)skb->cb)[1] = hdr; | |
6884 | ((void **)skb->cb)[2] = data; | |
6885 | ||
6886 | return skb; | |
6887 | ||
6888 | nla_put_failure: | |
6889 | kfree_skb(skb); | |
6890 | return NULL; | |
6891 | } | |
f4e583c8 | 6892 | |
e03ad6ea JB |
6893 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6894 | enum nl80211_commands cmd, | |
6895 | enum nl80211_attrs attr, | |
6896 | int vendor_event_idx, | |
6897 | int approxlen, gfp_t gfp) | |
6898 | { | |
f26cbf40 | 6899 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
6900 | const struct nl80211_vendor_cmd_info *info; |
6901 | ||
6902 | switch (cmd) { | |
6903 | case NL80211_CMD_TESTMODE: | |
6904 | if (WARN_ON(vendor_event_idx != -1)) | |
6905 | return NULL; | |
6906 | info = NULL; | |
6907 | break; | |
6908 | case NL80211_CMD_VENDOR: | |
6909 | if (WARN_ON(vendor_event_idx < 0 || | |
6910 | vendor_event_idx >= wiphy->n_vendor_events)) | |
6911 | return NULL; | |
6912 | info = &wiphy->vendor_events[vendor_event_idx]; | |
6913 | break; | |
6914 | default: | |
6915 | WARN_ON(1); | |
6916 | return NULL; | |
6917 | } | |
6918 | ||
6919 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
6920 | cmd, attr, info, gfp); | |
6921 | } | |
6922 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
6923 | ||
6924 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
6925 | { | |
6926 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6927 | void *hdr = ((void **)skb->cb)[1]; | |
6928 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6929 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
6930 | ||
6931 | nla_nest_end(skb, data); | |
6932 | genlmsg_end(skb, hdr); | |
6933 | ||
6934 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
6935 | mcgrp = NL80211_MCGRP_VENDOR; | |
6936 | ||
6937 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
6938 | mcgrp, gfp); | |
6939 | } | |
6940 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
6941 | ||
aff89a9b | 6942 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
6943 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
6944 | { | |
4c476991 | 6945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
6946 | struct wireless_dev *wdev = |
6947 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
6948 | int err; |
6949 | ||
fc73f11f DS |
6950 | if (!rdev->ops->testmode_cmd) |
6951 | return -EOPNOTSUPP; | |
6952 | ||
6953 | if (IS_ERR(wdev)) { | |
6954 | err = PTR_ERR(wdev); | |
6955 | if (err != -EINVAL) | |
6956 | return err; | |
6957 | wdev = NULL; | |
6958 | } else if (wdev->wiphy != &rdev->wiphy) { | |
6959 | return -EINVAL; | |
6960 | } | |
6961 | ||
aff89a9b JB |
6962 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
6963 | return -EINVAL; | |
6964 | ||
ad7e718c | 6965 | rdev->cur_cmd_info = info; |
fc73f11f | 6966 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
6967 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6968 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 6969 | rdev->cur_cmd_info = NULL; |
aff89a9b | 6970 | |
aff89a9b JB |
6971 | return err; |
6972 | } | |
6973 | ||
71063f0e WYG |
6974 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6975 | struct netlink_callback *cb) | |
6976 | { | |
00918d33 | 6977 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6978 | int err; |
6979 | long phy_idx; | |
6980 | void *data = NULL; | |
6981 | int data_len = 0; | |
6982 | ||
5fe231e8 JB |
6983 | rtnl_lock(); |
6984 | ||
71063f0e WYG |
6985 | if (cb->args[0]) { |
6986 | /* | |
6987 | * 0 is a valid index, but not valid for args[0], | |
6988 | * so we need to offset by 1. | |
6989 | */ | |
6990 | phy_idx = cb->args[0] - 1; | |
6991 | } else { | |
6992 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6993 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6994 | nl80211_policy); | |
6995 | if (err) | |
5fe231e8 | 6996 | goto out_err; |
00918d33 | 6997 | |
2bd7e35d JB |
6998 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6999 | nl80211_fam.attrbuf); | |
7000 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7001 | err = PTR_ERR(rdev); |
7002 | goto out_err; | |
00918d33 | 7003 | } |
2bd7e35d JB |
7004 | phy_idx = rdev->wiphy_idx; |
7005 | rdev = NULL; | |
2bd7e35d | 7006 | |
71063f0e WYG |
7007 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7008 | cb->args[1] = | |
7009 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7010 | } | |
7011 | ||
7012 | if (cb->args[1]) { | |
7013 | data = nla_data((void *)cb->args[1]); | |
7014 | data_len = nla_len((void *)cb->args[1]); | |
7015 | } | |
7016 | ||
00918d33 JB |
7017 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7018 | if (!rdev) { | |
5fe231e8 JB |
7019 | err = -ENOENT; |
7020 | goto out_err; | |
71063f0e | 7021 | } |
71063f0e | 7022 | |
00918d33 | 7023 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7024 | err = -EOPNOTSUPP; |
7025 | goto out_err; | |
7026 | } | |
7027 | ||
7028 | while (1) { | |
15e47304 | 7029 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7030 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7031 | NL80211_CMD_TESTMODE); | |
7032 | struct nlattr *tmdata; | |
7033 | ||
cb35fba3 DC |
7034 | if (!hdr) |
7035 | break; | |
7036 | ||
9360ffd1 | 7037 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7038 | genlmsg_cancel(skb, hdr); |
7039 | break; | |
7040 | } | |
7041 | ||
7042 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7043 | if (!tmdata) { | |
7044 | genlmsg_cancel(skb, hdr); | |
7045 | break; | |
7046 | } | |
e35e4d28 | 7047 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7048 | nla_nest_end(skb, tmdata); |
7049 | ||
7050 | if (err == -ENOBUFS || err == -ENOENT) { | |
7051 | genlmsg_cancel(skb, hdr); | |
7052 | break; | |
7053 | } else if (err) { | |
7054 | genlmsg_cancel(skb, hdr); | |
7055 | goto out_err; | |
7056 | } | |
7057 | ||
7058 | genlmsg_end(skb, hdr); | |
7059 | } | |
7060 | ||
7061 | err = skb->len; | |
7062 | /* see above */ | |
7063 | cb->args[0] = phy_idx + 1; | |
7064 | out_err: | |
5fe231e8 | 7065 | rtnl_unlock(); |
71063f0e WYG |
7066 | return err; |
7067 | } | |
aff89a9b JB |
7068 | #endif |
7069 | ||
b23aa676 SO |
7070 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7071 | { | |
4c476991 JB |
7072 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7073 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7074 | struct cfg80211_connect_params connect; |
7075 | struct wiphy *wiphy; | |
fffd0934 | 7076 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7077 | int err; |
7078 | ||
7079 | memset(&connect, 0, sizeof(connect)); | |
7080 | ||
7081 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7082 | return -EINVAL; | |
7083 | ||
7084 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7085 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7086 | return -EINVAL; | |
7087 | ||
7088 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7089 | connect.auth_type = | |
7090 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7091 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7092 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7093 | return -EINVAL; |
7094 | } else | |
7095 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7096 | ||
7097 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7098 | ||
c0692b8f | 7099 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7100 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7101 | if (err) |
7102 | return err; | |
b23aa676 | 7103 | |
074ac8df | 7104 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7105 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7106 | return -EOPNOTSUPP; | |
b23aa676 | 7107 | |
79c97e97 | 7108 | wiphy = &rdev->wiphy; |
b23aa676 | 7109 | |
4486ea98 BS |
7110 | connect.bg_scan_period = -1; |
7111 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7112 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7113 | connect.bg_scan_period = | |
7114 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7115 | } | |
7116 | ||
b23aa676 SO |
7117 | if (info->attrs[NL80211_ATTR_MAC]) |
7118 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7119 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7120 | connect.bssid_hint = | |
7121 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7122 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7123 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7124 | ||
7125 | if (info->attrs[NL80211_ATTR_IE]) { | |
7126 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7127 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7128 | } | |
7129 | ||
cee00a95 JM |
7130 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7131 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7132 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7133 | connect.mfp != NL80211_MFP_NO) | |
7134 | return -EINVAL; | |
7135 | } else { | |
7136 | connect.mfp = NL80211_MFP_NO; | |
7137 | } | |
7138 | ||
b23aa676 | 7139 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7140 | connect.channel = nl80211_get_valid_chan( |
7141 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7142 | if (!connect.channel) | |
1df4a510 JM |
7143 | return -EINVAL; |
7144 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7145 | connect.channel_hint = nl80211_get_valid_chan( |
7146 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7147 | if (!connect.channel_hint) | |
4c476991 | 7148 | return -EINVAL; |
b23aa676 SO |
7149 | } |
7150 | ||
fffd0934 JB |
7151 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7152 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7153 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7154 | if (IS_ERR(connkeys)) |
7155 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7156 | } |
7157 | ||
7e7c8926 BG |
7158 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7159 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7160 | ||
7161 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7162 | memcpy(&connect.ht_capa_mask, | |
7163 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7164 | sizeof(connect.ht_capa_mask)); | |
7165 | ||
7166 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
7167 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
7168 | kfree(connkeys); | |
7e7c8926 | 7169 | return -EINVAL; |
b4e4f47e | 7170 | } |
7e7c8926 BG |
7171 | memcpy(&connect.ht_capa, |
7172 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7173 | sizeof(connect.ht_capa)); | |
7174 | } | |
7175 | ||
ee2aca34 JB |
7176 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7177 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7178 | ||
7179 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7180 | memcpy(&connect.vht_capa_mask, | |
7181 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7182 | sizeof(connect.vht_capa_mask)); | |
7183 | ||
7184 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7185 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
7186 | kfree(connkeys); | |
7187 | return -EINVAL; | |
7188 | } | |
7189 | memcpy(&connect.vht_capa, | |
7190 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7191 | sizeof(connect.vht_capa)); | |
7192 | } | |
7193 | ||
83739b03 JB |
7194 | wdev_lock(dev->ieee80211_ptr); |
7195 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7196 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
7197 | if (err) |
7198 | kfree(connkeys); | |
b23aa676 SO |
7199 | return err; |
7200 | } | |
7201 | ||
7202 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7203 | { | |
4c476991 JB |
7204 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7205 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7206 | u16 reason; |
83739b03 | 7207 | int ret; |
b23aa676 SO |
7208 | |
7209 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7210 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7211 | else | |
7212 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7213 | ||
7214 | if (reason == 0) | |
7215 | return -EINVAL; | |
7216 | ||
074ac8df | 7217 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7218 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7219 | return -EOPNOTSUPP; | |
b23aa676 | 7220 | |
83739b03 JB |
7221 | wdev_lock(dev->ieee80211_ptr); |
7222 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7223 | wdev_unlock(dev->ieee80211_ptr); | |
7224 | return ret; | |
b23aa676 SO |
7225 | } |
7226 | ||
463d0183 JB |
7227 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7228 | { | |
4c476991 | 7229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7230 | struct net *net; |
7231 | int err; | |
7232 | u32 pid; | |
7233 | ||
7234 | if (!info->attrs[NL80211_ATTR_PID]) | |
7235 | return -EINVAL; | |
7236 | ||
7237 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7238 | ||
463d0183 | 7239 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7240 | if (IS_ERR(net)) |
7241 | return PTR_ERR(net); | |
463d0183 JB |
7242 | |
7243 | err = 0; | |
7244 | ||
7245 | /* check if anything to do */ | |
4c476991 JB |
7246 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7247 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7248 | |
463d0183 | 7249 | put_net(net); |
463d0183 JB |
7250 | return err; |
7251 | } | |
7252 | ||
67fbb16b SO |
7253 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7254 | { | |
4c476991 | 7255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7256 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7257 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7258 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7259 | struct cfg80211_pmksa pmksa; |
7260 | ||
7261 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7262 | ||
7263 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7264 | return -EINVAL; | |
7265 | ||
7266 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7267 | return -EINVAL; | |
7268 | ||
67fbb16b SO |
7269 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7270 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7271 | ||
074ac8df | 7272 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7273 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7274 | return -EOPNOTSUPP; | |
67fbb16b SO |
7275 | |
7276 | switch (info->genlhdr->cmd) { | |
7277 | case NL80211_CMD_SET_PMKSA: | |
7278 | rdev_ops = rdev->ops->set_pmksa; | |
7279 | break; | |
7280 | case NL80211_CMD_DEL_PMKSA: | |
7281 | rdev_ops = rdev->ops->del_pmksa; | |
7282 | break; | |
7283 | default: | |
7284 | WARN_ON(1); | |
7285 | break; | |
7286 | } | |
7287 | ||
4c476991 JB |
7288 | if (!rdev_ops) |
7289 | return -EOPNOTSUPP; | |
67fbb16b | 7290 | |
4c476991 | 7291 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7292 | } |
7293 | ||
7294 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7295 | { | |
4c476991 JB |
7296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7297 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7298 | |
074ac8df | 7299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7300 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7301 | return -EOPNOTSUPP; | |
67fbb16b | 7302 | |
4c476991 JB |
7303 | if (!rdev->ops->flush_pmksa) |
7304 | return -EOPNOTSUPP; | |
67fbb16b | 7305 | |
e35e4d28 | 7306 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7307 | } |
7308 | ||
109086ce AN |
7309 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7310 | { | |
7311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7312 | struct net_device *dev = info->user_ptr[1]; | |
7313 | u8 action_code, dialog_token; | |
df942e7b | 7314 | u32 peer_capability = 0; |
109086ce AN |
7315 | u16 status_code; |
7316 | u8 *peer; | |
7317 | ||
7318 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7319 | !rdev->ops->tdls_mgmt) | |
7320 | return -EOPNOTSUPP; | |
7321 | ||
7322 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7323 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7324 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7325 | !info->attrs[NL80211_ATTR_IE] || | |
7326 | !info->attrs[NL80211_ATTR_MAC]) | |
7327 | return -EINVAL; | |
7328 | ||
7329 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7330 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7331 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7332 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
df942e7b SDU |
7333 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7334 | peer_capability = | |
7335 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7336 | |
e35e4d28 | 7337 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7338 | dialog_token, status_code, peer_capability, |
e35e4d28 HG |
7339 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7340 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7341 | } |
7342 | ||
7343 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7344 | { | |
7345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7346 | struct net_device *dev = info->user_ptr[1]; | |
7347 | enum nl80211_tdls_operation operation; | |
7348 | u8 *peer; | |
7349 | ||
7350 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7351 | !rdev->ops->tdls_oper) | |
7352 | return -EOPNOTSUPP; | |
7353 | ||
7354 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7355 | !info->attrs[NL80211_ATTR_MAC]) | |
7356 | return -EINVAL; | |
7357 | ||
7358 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7359 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7360 | ||
e35e4d28 | 7361 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7362 | } |
7363 | ||
9588bbd5 JM |
7364 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7365 | struct genl_info *info) | |
7366 | { | |
4c476991 | 7367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7368 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7369 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7370 | struct sk_buff *msg; |
7371 | void *hdr; | |
7372 | u64 cookie; | |
683b6d3b | 7373 | u32 duration; |
9588bbd5 JM |
7374 | int err; |
7375 | ||
7376 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7377 | !info->attrs[NL80211_ATTR_DURATION]) | |
7378 | return -EINVAL; | |
7379 | ||
7380 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7381 | ||
ebf348fc JB |
7382 | if (!rdev->ops->remain_on_channel || |
7383 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7384 | return -EOPNOTSUPP; | |
7385 | ||
9588bbd5 | 7386 | /* |
ebf348fc JB |
7387 | * We should be on that channel for at least a minimum amount of |
7388 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7389 | */ |
ebf348fc | 7390 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7391 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7392 | return -EINVAL; |
7393 | ||
683b6d3b JB |
7394 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7395 | if (err) | |
7396 | return err; | |
9588bbd5 JM |
7397 | |
7398 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7399 | if (!msg) |
7400 | return -ENOMEM; | |
9588bbd5 | 7401 | |
15e47304 | 7402 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7403 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7404 | if (!hdr) { |
7405 | err = -ENOBUFS; | |
9588bbd5 JM |
7406 | goto free_msg; |
7407 | } | |
7408 | ||
683b6d3b JB |
7409 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7410 | duration, &cookie); | |
9588bbd5 JM |
7411 | |
7412 | if (err) | |
7413 | goto free_msg; | |
7414 | ||
9360ffd1 DM |
7415 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7416 | goto nla_put_failure; | |
9588bbd5 JM |
7417 | |
7418 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7419 | |
7420 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7421 | |
7422 | nla_put_failure: | |
7423 | err = -ENOBUFS; | |
7424 | free_msg: | |
7425 | nlmsg_free(msg); | |
9588bbd5 JM |
7426 | return err; |
7427 | } | |
7428 | ||
7429 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7430 | struct genl_info *info) | |
7431 | { | |
4c476991 | 7432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7433 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7434 | u64 cookie; |
9588bbd5 JM |
7435 | |
7436 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7437 | return -EINVAL; | |
7438 | ||
4c476991 JB |
7439 | if (!rdev->ops->cancel_remain_on_channel) |
7440 | return -EOPNOTSUPP; | |
9588bbd5 | 7441 | |
9588bbd5 JM |
7442 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7443 | ||
e35e4d28 | 7444 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7445 | } |
7446 | ||
13ae75b1 JM |
7447 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7448 | u8 *rates, u8 rates_len) | |
7449 | { | |
7450 | u8 i; | |
7451 | u32 mask = 0; | |
7452 | ||
7453 | for (i = 0; i < rates_len; i++) { | |
7454 | int rate = (rates[i] & 0x7f) * 5; | |
7455 | int ridx; | |
7456 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7457 | struct ieee80211_rate *srate = | |
7458 | &sband->bitrates[ridx]; | |
7459 | if (rate == srate->bitrate) { | |
7460 | mask |= 1 << ridx; | |
7461 | break; | |
7462 | } | |
7463 | } | |
7464 | if (ridx == sband->n_bitrates) | |
7465 | return 0; /* rate not found */ | |
7466 | } | |
7467 | ||
7468 | return mask; | |
7469 | } | |
7470 | ||
24db78c0 SW |
7471 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7472 | u8 *rates, u8 rates_len, | |
7473 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7474 | { | |
7475 | u8 i; | |
7476 | ||
7477 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7478 | ||
7479 | for (i = 0; i < rates_len; i++) { | |
7480 | int ridx, rbit; | |
7481 | ||
7482 | ridx = rates[i] / 8; | |
7483 | rbit = BIT(rates[i] % 8); | |
7484 | ||
7485 | /* check validity */ | |
910570b5 | 7486 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7487 | return false; |
7488 | ||
7489 | /* check availability */ | |
7490 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7491 | mcs[ridx] |= rbit; | |
7492 | else | |
7493 | return false; | |
7494 | } | |
7495 | ||
7496 | return true; | |
7497 | } | |
7498 | ||
204e35a9 JD |
7499 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
7500 | { | |
7501 | u16 mcs_mask = 0; | |
7502 | ||
7503 | switch (vht_mcs_map) { | |
7504 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
7505 | break; | |
7506 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
7507 | mcs_mask = 0x00FF; | |
7508 | break; | |
7509 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
7510 | mcs_mask = 0x01FF; | |
7511 | break; | |
7512 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
7513 | mcs_mask = 0x03FF; | |
7514 | break; | |
7515 | default: | |
7516 | break; | |
7517 | } | |
7518 | ||
7519 | return mcs_mask; | |
7520 | } | |
7521 | ||
7522 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
7523 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
7524 | { | |
7525 | u8 nss; | |
7526 | ||
7527 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
7528 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
7529 | vht_mcs_map >>= 2; | |
7530 | } | |
7531 | } | |
7532 | ||
7533 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
7534 | struct nl80211_txrate_vht *txrate, | |
7535 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
7536 | { | |
7537 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7538 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
7539 | u8 i; | |
7540 | ||
7541 | if (!sband->vht_cap.vht_supported) | |
7542 | return false; | |
7543 | ||
7544 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
7545 | ||
7546 | /* Build vht_mcs_mask from VHT capabilities */ | |
7547 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
7548 | ||
7549 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7550 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
7551 | mcs[i] = txrate->mcs[i]; | |
7552 | else | |
7553 | return false; | |
7554 | } | |
7555 | ||
7556 | return true; | |
7557 | } | |
7558 | ||
b54452b0 | 7559 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7560 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7561 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
7562 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
7563 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 7564 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 7565 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
7566 | }; |
7567 | ||
7568 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7569 | struct genl_info *info) | |
7570 | { | |
7571 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7573 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7574 | int rem, i; |
7575 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7576 | struct nlattr *tx_rates; |
7577 | struct ieee80211_supported_band *sband; | |
204e35a9 | 7578 | u16 vht_tx_mcs_map; |
13ae75b1 | 7579 | |
4c476991 JB |
7580 | if (!rdev->ops->set_bitrate_mask) |
7581 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7582 | |
7583 | memset(&mask, 0, sizeof(mask)); | |
7584 | /* Default to all rates enabled */ | |
7585 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7586 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
7587 | |
7588 | if (!sband) | |
7589 | continue; | |
7590 | ||
7591 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 7592 | memcpy(mask.control[i].ht_mcs, |
7869303b | 7593 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 7594 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
7595 | |
7596 | if (!sband->vht_cap.vht_supported) | |
7597 | continue; | |
7598 | ||
7599 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7600 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
7601 | } |
7602 | ||
b9243ab0 JD |
7603 | /* if no rates are given set it back to the defaults */ |
7604 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
7605 | goto out; | |
7606 | ||
13ae75b1 JM |
7607 | /* |
7608 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7609 | * directly to the enum ieee80211_band values used in cfg80211. | |
7610 | */ | |
24db78c0 | 7611 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 7612 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 7613 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
7614 | int err; |
7615 | ||
4c476991 JB |
7616 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7617 | return -EINVAL; | |
13ae75b1 | 7618 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7619 | if (sband == NULL) |
7620 | return -EINVAL; | |
ae811e21 JB |
7621 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7622 | nla_len(tx_rates), nl80211_txattr_policy); | |
7623 | if (err) | |
7624 | return err; | |
13ae75b1 JM |
7625 | if (tb[NL80211_TXRATE_LEGACY]) { |
7626 | mask.control[band].legacy = rateset_to_mask( | |
7627 | sband, | |
7628 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7629 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7630 | if ((mask.control[band].legacy == 0) && |
7631 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7632 | return -EINVAL; | |
24db78c0 | 7633 | } |
d1e33e65 | 7634 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
7635 | if (!ht_rateset_to_mask( |
7636 | sband, | |
d1e33e65 JD |
7637 | nla_data(tb[NL80211_TXRATE_HT]), |
7638 | nla_len(tb[NL80211_TXRATE_HT]), | |
7639 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
7640 | return -EINVAL; |
7641 | } | |
204e35a9 JD |
7642 | if (tb[NL80211_TXRATE_VHT]) { |
7643 | if (!vht_set_mcs_mask( | |
7644 | sband, | |
7645 | nla_data(tb[NL80211_TXRATE_VHT]), | |
7646 | mask.control[band].vht_mcs)) | |
7647 | return -EINVAL; | |
7648 | } | |
0b9323f6 JD |
7649 | if (tb[NL80211_TXRATE_GI]) { |
7650 | mask.control[band].gi = | |
7651 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
7652 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
7653 | return -EINVAL; | |
7654 | } | |
24db78c0 SW |
7655 | |
7656 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
7657 | /* don't allow empty legacy rates if HT or VHT |
7658 | * are not even supported. | |
7659 | */ | |
7660 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
7661 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
7662 | return -EINVAL; |
7663 | ||
7664 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 7665 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
7666 | goto out; |
7667 | ||
7668 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
7669 | if (mask.control[band].vht_mcs[i]) | |
7670 | goto out; | |
24db78c0 SW |
7671 | |
7672 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 7673 | return -EINVAL; |
13ae75b1 JM |
7674 | } |
7675 | } | |
7676 | ||
b9243ab0 | 7677 | out: |
e35e4d28 | 7678 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7679 | } |
7680 | ||
2e161f78 | 7681 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7682 | { |
4c476991 | 7683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7684 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7685 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7686 | |
7687 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7688 | return -EINVAL; | |
7689 | ||
2e161f78 JB |
7690 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7691 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7692 | |
71bbc994 JB |
7693 | switch (wdev->iftype) { |
7694 | case NL80211_IFTYPE_STATION: | |
7695 | case NL80211_IFTYPE_ADHOC: | |
7696 | case NL80211_IFTYPE_P2P_CLIENT: | |
7697 | case NL80211_IFTYPE_AP: | |
7698 | case NL80211_IFTYPE_AP_VLAN: | |
7699 | case NL80211_IFTYPE_MESH_POINT: | |
7700 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7701 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7702 | break; |
7703 | default: | |
4c476991 | 7704 | return -EOPNOTSUPP; |
71bbc994 | 7705 | } |
026331c4 JM |
7706 | |
7707 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7708 | if (!rdev->ops->mgmt_tx) |
7709 | return -EOPNOTSUPP; | |
026331c4 | 7710 | |
15e47304 | 7711 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7712 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7713 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7714 | } |
7715 | ||
2e161f78 | 7716 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7717 | { |
4c476991 | 7718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7719 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7720 | struct cfg80211_chan_def chandef; |
026331c4 | 7721 | int err; |
d64d373f | 7722 | void *hdr = NULL; |
026331c4 | 7723 | u64 cookie; |
e247bd90 | 7724 | struct sk_buff *msg = NULL; |
b176e629 AO |
7725 | struct cfg80211_mgmt_tx_params params = { |
7726 | .dont_wait_for_ack = | |
7727 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7728 | }; | |
026331c4 | 7729 | |
683b6d3b | 7730 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7731 | return -EINVAL; |
7732 | ||
4c476991 JB |
7733 | if (!rdev->ops->mgmt_tx) |
7734 | return -EOPNOTSUPP; | |
026331c4 | 7735 | |
71bbc994 | 7736 | switch (wdev->iftype) { |
ea141b75 AQ |
7737 | case NL80211_IFTYPE_P2P_DEVICE: |
7738 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7739 | return -EINVAL; | |
71bbc994 JB |
7740 | case NL80211_IFTYPE_STATION: |
7741 | case NL80211_IFTYPE_ADHOC: | |
7742 | case NL80211_IFTYPE_P2P_CLIENT: | |
7743 | case NL80211_IFTYPE_AP: | |
7744 | case NL80211_IFTYPE_AP_VLAN: | |
7745 | case NL80211_IFTYPE_MESH_POINT: | |
7746 | case NL80211_IFTYPE_P2P_GO: | |
7747 | break; | |
7748 | default: | |
4c476991 | 7749 | return -EOPNOTSUPP; |
71bbc994 | 7750 | } |
026331c4 | 7751 | |
f7ca38df | 7752 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7753 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 7754 | return -EINVAL; |
b176e629 | 7755 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
7756 | |
7757 | /* | |
7758 | * We should wait on the channel for at least a minimum amount | |
7759 | * of time (10ms) but no longer than the driver supports. | |
7760 | */ | |
b176e629 AO |
7761 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
7762 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
7763 | return -EINVAL; |
7764 | ||
f7ca38df JB |
7765 | } |
7766 | ||
b176e629 | 7767 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 7768 | |
b176e629 | 7769 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
7770 | return -EINVAL; |
7771 | ||
b176e629 | 7772 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 7773 | |
ea141b75 AQ |
7774 | /* get the channel if any has been specified, otherwise pass NULL to |
7775 | * the driver. The latter will use the current one | |
7776 | */ | |
7777 | chandef.chan = NULL; | |
7778 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7779 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7780 | if (err) | |
7781 | return err; | |
7782 | } | |
7783 | ||
b176e629 | 7784 | if (!chandef.chan && params.offchan) |
ea141b75 | 7785 | return -EINVAL; |
026331c4 | 7786 | |
b176e629 | 7787 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
7788 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7789 | if (!msg) | |
7790 | return -ENOMEM; | |
026331c4 | 7791 | |
15e47304 | 7792 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7793 | NL80211_CMD_FRAME); |
cb35fba3 DC |
7794 | if (!hdr) { |
7795 | err = -ENOBUFS; | |
e247bd90 JB |
7796 | goto free_msg; |
7797 | } | |
026331c4 | 7798 | } |
e247bd90 | 7799 | |
b176e629 AO |
7800 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
7801 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
7802 | params.chan = chandef.chan; | |
7803 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
7804 | if (err) |
7805 | goto free_msg; | |
7806 | ||
e247bd90 | 7807 | if (msg) { |
9360ffd1 DM |
7808 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7809 | goto nla_put_failure; | |
026331c4 | 7810 | |
e247bd90 JB |
7811 | genlmsg_end(msg, hdr); |
7812 | return genlmsg_reply(msg, info); | |
7813 | } | |
7814 | ||
7815 | return 0; | |
026331c4 JM |
7816 | |
7817 | nla_put_failure: | |
7818 | err = -ENOBUFS; | |
7819 | free_msg: | |
7820 | nlmsg_free(msg); | |
026331c4 JM |
7821 | return err; |
7822 | } | |
7823 | ||
f7ca38df JB |
7824 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7825 | { | |
7826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7827 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7828 | u64 cookie; |
7829 | ||
7830 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7831 | return -EINVAL; | |
7832 | ||
7833 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7834 | return -EOPNOTSUPP; | |
7835 | ||
71bbc994 JB |
7836 | switch (wdev->iftype) { |
7837 | case NL80211_IFTYPE_STATION: | |
7838 | case NL80211_IFTYPE_ADHOC: | |
7839 | case NL80211_IFTYPE_P2P_CLIENT: | |
7840 | case NL80211_IFTYPE_AP: | |
7841 | case NL80211_IFTYPE_AP_VLAN: | |
7842 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7843 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7844 | break; |
7845 | default: | |
f7ca38df | 7846 | return -EOPNOTSUPP; |
71bbc994 | 7847 | } |
f7ca38df JB |
7848 | |
7849 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7850 | ||
e35e4d28 | 7851 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7852 | } |
7853 | ||
ffb9eb3d KV |
7854 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7855 | { | |
4c476991 | 7856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7857 | struct wireless_dev *wdev; |
4c476991 | 7858 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7859 | u8 ps_state; |
7860 | bool state; | |
7861 | int err; | |
7862 | ||
4c476991 JB |
7863 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7864 | return -EINVAL; | |
ffb9eb3d KV |
7865 | |
7866 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7867 | ||
4c476991 JB |
7868 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7869 | return -EINVAL; | |
ffb9eb3d KV |
7870 | |
7871 | wdev = dev->ieee80211_ptr; | |
7872 | ||
4c476991 JB |
7873 | if (!rdev->ops->set_power_mgmt) |
7874 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7875 | |
7876 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7877 | ||
7878 | if (state == wdev->ps) | |
4c476991 | 7879 | return 0; |
ffb9eb3d | 7880 | |
e35e4d28 | 7881 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7882 | if (!err) |
7883 | wdev->ps = state; | |
ffb9eb3d KV |
7884 | return err; |
7885 | } | |
7886 | ||
7887 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7888 | { | |
4c476991 | 7889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7890 | enum nl80211_ps_state ps_state; |
7891 | struct wireless_dev *wdev; | |
4c476991 | 7892 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7893 | struct sk_buff *msg; |
7894 | void *hdr; | |
7895 | int err; | |
7896 | ||
ffb9eb3d KV |
7897 | wdev = dev->ieee80211_ptr; |
7898 | ||
4c476991 JB |
7899 | if (!rdev->ops->set_power_mgmt) |
7900 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7901 | |
7902 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7903 | if (!msg) |
7904 | return -ENOMEM; | |
ffb9eb3d | 7905 | |
15e47304 | 7906 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7907 | NL80211_CMD_GET_POWER_SAVE); |
7908 | if (!hdr) { | |
4c476991 | 7909 | err = -ENOBUFS; |
ffb9eb3d KV |
7910 | goto free_msg; |
7911 | } | |
7912 | ||
7913 | if (wdev->ps) | |
7914 | ps_state = NL80211_PS_ENABLED; | |
7915 | else | |
7916 | ps_state = NL80211_PS_DISABLED; | |
7917 | ||
9360ffd1 DM |
7918 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7919 | goto nla_put_failure; | |
ffb9eb3d KV |
7920 | |
7921 | genlmsg_end(msg, hdr); | |
4c476991 | 7922 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7923 | |
4c476991 | 7924 | nla_put_failure: |
ffb9eb3d | 7925 | err = -ENOBUFS; |
4c476991 | 7926 | free_msg: |
ffb9eb3d | 7927 | nlmsg_free(msg); |
ffb9eb3d KV |
7928 | return err; |
7929 | } | |
7930 | ||
94e860f1 JB |
7931 | static const struct nla_policy |
7932 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
7933 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
7934 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7935 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7936 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7937 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7938 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7939 | }; |
7940 | ||
84f10708 | 7941 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7942 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7943 | { |
7944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 7945 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7946 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 7947 | |
d9d8b019 | 7948 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7949 | return -EINVAL; |
7950 | ||
84f10708 TP |
7951 | if (!rdev->ops->set_cqm_txe_config) |
7952 | return -EOPNOTSUPP; | |
7953 | ||
7954 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7955 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7956 | return -EOPNOTSUPP; | |
7957 | ||
e35e4d28 | 7958 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7959 | } |
7960 | ||
d6dc1a38 JO |
7961 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7962 | s32 threshold, u32 hysteresis) | |
7963 | { | |
4c476991 | 7964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 7965 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7966 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
7967 | |
7968 | if (threshold > 0) | |
7969 | return -EINVAL; | |
7970 | ||
1da5fcc8 JB |
7971 | /* disabling - hysteresis should also be zero then */ |
7972 | if (threshold == 0) | |
7973 | hysteresis = 0; | |
d6dc1a38 | 7974 | |
4c476991 JB |
7975 | if (!rdev->ops->set_cqm_rssi_config) |
7976 | return -EOPNOTSUPP; | |
d6dc1a38 | 7977 | |
074ac8df | 7978 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7979 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7980 | return -EOPNOTSUPP; | |
d6dc1a38 | 7981 | |
e35e4d28 | 7982 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7983 | } |
7984 | ||
7985 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7986 | { | |
7987 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7988 | struct nlattr *cqm; | |
7989 | int err; | |
7990 | ||
7991 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
7992 | if (!cqm) |
7993 | return -EINVAL; | |
d6dc1a38 JO |
7994 | |
7995 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7996 | nl80211_attr_cqm_policy); | |
7997 | if (err) | |
1da5fcc8 | 7998 | return err; |
d6dc1a38 JO |
7999 | |
8000 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8001 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8002 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8003 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8004 | |
1da5fcc8 JB |
8005 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8006 | } | |
8007 | ||
8008 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8009 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8010 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8011 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8012 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8013 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8014 | ||
8015 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8016 | } | |
8017 | ||
8018 | return -EINVAL; | |
d6dc1a38 JO |
8019 | } |
8020 | ||
29cbe68c JB |
8021 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8022 | { | |
8023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8024 | struct net_device *dev = info->user_ptr[1]; | |
8025 | struct mesh_config cfg; | |
c80d545d | 8026 | struct mesh_setup setup; |
29cbe68c JB |
8027 | int err; |
8028 | ||
8029 | /* start with default */ | |
8030 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8031 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8032 | |
24bdd9f4 | 8033 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8034 | /* and parse parameters if given */ |
24bdd9f4 | 8035 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8036 | if (err) |
8037 | return err; | |
8038 | } | |
8039 | ||
8040 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8041 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8042 | return -EINVAL; | |
8043 | ||
c80d545d JC |
8044 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8045 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8046 | ||
4bb62344 CYY |
8047 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8048 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8049 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8050 | return -EINVAL; | |
8051 | ||
9bdbf04d MP |
8052 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8053 | setup.beacon_interval = | |
8054 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8055 | if (setup.beacon_interval < 10 || | |
8056 | setup.beacon_interval > 10000) | |
8057 | return -EINVAL; | |
8058 | } | |
8059 | ||
8060 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8061 | setup.dtim_period = | |
8062 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8063 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8064 | return -EINVAL; | |
8065 | } | |
8066 | ||
c80d545d JC |
8067 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8068 | /* parse additional setup parameters if given */ | |
8069 | err = nl80211_parse_mesh_setup(info, &setup); | |
8070 | if (err) | |
8071 | return err; | |
8072 | } | |
8073 | ||
d37bb18a TP |
8074 | if (setup.user_mpm) |
8075 | cfg.auto_open_plinks = false; | |
8076 | ||
cc1d2806 | 8077 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8078 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8079 | if (err) | |
8080 | return err; | |
cc1d2806 JB |
8081 | } else { |
8082 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8083 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8084 | } |
8085 | ||
ffb3cf30 AN |
8086 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8087 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8088 | int n_rates = | |
8089 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8090 | struct ieee80211_supported_band *sband; | |
8091 | ||
8092 | if (!setup.chandef.chan) | |
8093 | return -EINVAL; | |
8094 | ||
8095 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8096 | ||
8097 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8098 | &setup.basic_rates); | |
8099 | if (err) | |
8100 | return err; | |
8101 | } | |
8102 | ||
c80d545d | 8103 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8104 | } |
8105 | ||
8106 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8107 | { | |
8108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8109 | struct net_device *dev = info->user_ptr[1]; | |
8110 | ||
8111 | return cfg80211_leave_mesh(rdev, dev); | |
8112 | } | |
8113 | ||
dfb89c56 | 8114 | #ifdef CONFIG_PM |
bb92d199 AK |
8115 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8116 | struct cfg80211_registered_device *rdev) | |
8117 | { | |
6abb9cb9 | 8118 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8119 | struct nlattr *nl_pats, *nl_pat; |
8120 | int i, pat_len; | |
8121 | ||
6abb9cb9 | 8122 | if (!wowlan->n_patterns) |
bb92d199 AK |
8123 | return 0; |
8124 | ||
8125 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8126 | if (!nl_pats) | |
8127 | return -ENOBUFS; | |
8128 | ||
6abb9cb9 | 8129 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8130 | nl_pat = nla_nest_start(msg, i + 1); |
8131 | if (!nl_pat) | |
8132 | return -ENOBUFS; | |
6abb9cb9 | 8133 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8134 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8135 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8136 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8137 | wowlan->patterns[i].pattern) || | |
8138 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8139 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8140 | return -ENOBUFS; |
8141 | nla_nest_end(msg, nl_pat); | |
8142 | } | |
8143 | nla_nest_end(msg, nl_pats); | |
8144 | ||
8145 | return 0; | |
8146 | } | |
8147 | ||
2a0e047e JB |
8148 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8149 | struct cfg80211_wowlan_tcp *tcp) | |
8150 | { | |
8151 | struct nlattr *nl_tcp; | |
8152 | ||
8153 | if (!tcp) | |
8154 | return 0; | |
8155 | ||
8156 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8157 | if (!nl_tcp) | |
8158 | return -ENOBUFS; | |
8159 | ||
8160 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8161 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8162 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8163 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8164 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8165 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8166 | tcp->payload_len, tcp->payload) || | |
8167 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8168 | tcp->data_interval) || | |
8169 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8170 | tcp->wake_len, tcp->wake_data) || | |
8171 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8172 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8173 | return -ENOBUFS; | |
8174 | ||
8175 | if (tcp->payload_seq.len && | |
8176 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8177 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8178 | return -ENOBUFS; | |
8179 | ||
8180 | if (tcp->payload_tok.len && | |
8181 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8182 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8183 | &tcp->payload_tok)) | |
8184 | return -ENOBUFS; | |
8185 | ||
e248ad30 JB |
8186 | nla_nest_end(msg, nl_tcp); |
8187 | ||
2a0e047e JB |
8188 | return 0; |
8189 | } | |
8190 | ||
ff1b6e69 JB |
8191 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8192 | { | |
8193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8194 | struct sk_buff *msg; | |
8195 | void *hdr; | |
2a0e047e | 8196 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8197 | |
964dc9e2 | 8198 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8199 | return -EOPNOTSUPP; |
8200 | ||
6abb9cb9 | 8201 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8202 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8203 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8204 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8205 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8206 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8207 | } |
8208 | ||
8209 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8210 | if (!msg) |
8211 | return -ENOMEM; | |
8212 | ||
15e47304 | 8213 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8214 | NL80211_CMD_GET_WOWLAN); |
8215 | if (!hdr) | |
8216 | goto nla_put_failure; | |
8217 | ||
6abb9cb9 | 8218 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8219 | struct nlattr *nl_wowlan; |
8220 | ||
8221 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8222 | if (!nl_wowlan) | |
8223 | goto nla_put_failure; | |
8224 | ||
6abb9cb9 | 8225 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8226 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8227 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8228 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8229 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8230 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8231 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8232 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8233 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8234 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8235 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8236 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8237 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8238 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8239 | goto nla_put_failure; | |
2a0e047e | 8240 | |
bb92d199 AK |
8241 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8242 | goto nla_put_failure; | |
2a0e047e | 8243 | |
6abb9cb9 JB |
8244 | if (nl80211_send_wowlan_tcp(msg, |
8245 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8246 | goto nla_put_failure; |
8247 | ||
ff1b6e69 JB |
8248 | nla_nest_end(msg, nl_wowlan); |
8249 | } | |
8250 | ||
8251 | genlmsg_end(msg, hdr); | |
8252 | return genlmsg_reply(msg, info); | |
8253 | ||
8254 | nla_put_failure: | |
8255 | nlmsg_free(msg); | |
8256 | return -ENOBUFS; | |
8257 | } | |
8258 | ||
2a0e047e JB |
8259 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8260 | struct nlattr *attr, | |
8261 | struct cfg80211_wowlan *trig) | |
8262 | { | |
8263 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8264 | struct cfg80211_wowlan_tcp *cfg; | |
8265 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8266 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8267 | u32 size; | |
8268 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8269 | int err, port; | |
8270 | ||
964dc9e2 | 8271 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8272 | return -EINVAL; |
8273 | ||
8274 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8275 | nla_data(attr), nla_len(attr), | |
8276 | nl80211_wowlan_tcp_policy); | |
8277 | if (err) | |
8278 | return err; | |
8279 | ||
8280 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8281 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8282 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8283 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8284 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8285 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8286 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8287 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8288 | return -EINVAL; | |
8289 | ||
8290 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8291 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8292 | return -EINVAL; |
8293 | ||
8294 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8295 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8296 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8297 | return -EINVAL; |
8298 | ||
8299 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8300 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8301 | return -EINVAL; |
8302 | ||
8303 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8304 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8305 | return -EINVAL; | |
8306 | ||
8307 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8308 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8309 | ||
8310 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8311 | tokens_size = tokln - sizeof(*tok); | |
8312 | ||
8313 | if (!tok->len || tokens_size % tok->len) | |
8314 | return -EINVAL; | |
964dc9e2 | 8315 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8316 | return -EINVAL; |
964dc9e2 | 8317 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8318 | return -EINVAL; |
964dc9e2 | 8319 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8320 | return -EINVAL; |
964dc9e2 | 8321 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8322 | return -EINVAL; |
8323 | if (tok->offset + tok->len > data_size) | |
8324 | return -EINVAL; | |
8325 | } | |
8326 | ||
8327 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8328 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8329 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8330 | return -EINVAL; |
8331 | if (seq->len == 0 || seq->len > 4) | |
8332 | return -EINVAL; | |
8333 | if (seq->len + seq->offset > data_size) | |
8334 | return -EINVAL; | |
8335 | } | |
8336 | ||
8337 | size = sizeof(*cfg); | |
8338 | size += data_size; | |
8339 | size += wake_size + wake_mask_size; | |
8340 | size += tokens_size; | |
8341 | ||
8342 | cfg = kzalloc(size, GFP_KERNEL); | |
8343 | if (!cfg) | |
8344 | return -ENOMEM; | |
8345 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8346 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8347 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8348 | ETH_ALEN); | |
8349 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8350 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8351 | else | |
8352 | port = 0; | |
8353 | #ifdef CONFIG_INET | |
8354 | /* allocate a socket and port for it and use it */ | |
8355 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8356 | IPPROTO_TCP, &cfg->sock, 1); | |
8357 | if (err) { | |
8358 | kfree(cfg); | |
8359 | return err; | |
8360 | } | |
8361 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8362 | sock_release(cfg->sock); | |
8363 | kfree(cfg); | |
8364 | return -EADDRINUSE; | |
8365 | } | |
8366 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8367 | #else | |
8368 | if (!port) { | |
8369 | kfree(cfg); | |
8370 | return -EINVAL; | |
8371 | } | |
8372 | cfg->src_port = port; | |
8373 | #endif | |
8374 | ||
8375 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8376 | cfg->payload_len = data_size; | |
8377 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8378 | memcpy((void *)cfg->payload, | |
8379 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8380 | data_size); | |
8381 | if (seq) | |
8382 | cfg->payload_seq = *seq; | |
8383 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8384 | cfg->wake_len = wake_size; | |
8385 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8386 | memcpy((void *)cfg->wake_data, | |
8387 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8388 | wake_size); | |
8389 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8390 | data_size + wake_size; | |
8391 | memcpy((void *)cfg->wake_mask, | |
8392 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8393 | wake_mask_size); | |
8394 | if (tok) { | |
8395 | cfg->tokens_size = tokens_size; | |
8396 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8397 | } | |
8398 | ||
8399 | trig->tcp = cfg; | |
8400 | ||
8401 | return 0; | |
8402 | } | |
8403 | ||
ff1b6e69 JB |
8404 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8405 | { | |
8406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8407 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8408 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8409 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8410 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8411 | int err, i; |
6abb9cb9 | 8412 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8413 | |
964dc9e2 | 8414 | if (!wowlan) |
ff1b6e69 JB |
8415 | return -EOPNOTSUPP; |
8416 | ||
ae33bd81 JB |
8417 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8418 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8419 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8420 | goto set_wakeup; |
8421 | } | |
ff1b6e69 JB |
8422 | |
8423 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8424 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8425 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8426 | nl80211_wowlan_policy); | |
8427 | if (err) | |
8428 | return err; | |
8429 | ||
8430 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8431 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8432 | return -EINVAL; | |
8433 | new_triggers.any = true; | |
8434 | } | |
8435 | ||
8436 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8437 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8438 | return -EINVAL; | |
8439 | new_triggers.disconnect = true; | |
8440 | } | |
8441 | ||
8442 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8443 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8444 | return -EINVAL; | |
8445 | new_triggers.magic_pkt = true; | |
8446 | } | |
8447 | ||
77dbbb13 JB |
8448 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8449 | return -EINVAL; | |
8450 | ||
8451 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8452 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8453 | return -EINVAL; | |
8454 | new_triggers.gtk_rekey_failure = true; | |
8455 | } | |
8456 | ||
8457 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8458 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8459 | return -EINVAL; | |
8460 | new_triggers.eap_identity_req = true; | |
8461 | } | |
8462 | ||
8463 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8464 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8465 | return -EINVAL; | |
8466 | new_triggers.four_way_handshake = true; | |
8467 | } | |
8468 | ||
8469 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8470 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8471 | return -EINVAL; | |
8472 | new_triggers.rfkill_release = true; | |
8473 | } | |
8474 | ||
ff1b6e69 JB |
8475 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8476 | struct nlattr *pat; | |
8477 | int n_patterns = 0; | |
bb92d199 | 8478 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8479 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8480 | |
8481 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8482 | rem) | |
8483 | n_patterns++; | |
8484 | if (n_patterns > wowlan->n_patterns) | |
8485 | return -EINVAL; | |
8486 | ||
8487 | new_triggers.patterns = kcalloc(n_patterns, | |
8488 | sizeof(new_triggers.patterns[0]), | |
8489 | GFP_KERNEL); | |
8490 | if (!new_triggers.patterns) | |
8491 | return -ENOMEM; | |
8492 | ||
8493 | new_triggers.n_patterns = n_patterns; | |
8494 | i = 0; | |
8495 | ||
8496 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8497 | rem) { | |
50ac6607 AK |
8498 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8499 | nla_len(pat), NULL); | |
ff1b6e69 | 8500 | err = -EINVAL; |
50ac6607 AK |
8501 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8502 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8503 | goto error; |
50ac6607 | 8504 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8505 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8506 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8507 | goto error; |
8508 | if (pat_len > wowlan->pattern_max_len || | |
8509 | pat_len < wowlan->pattern_min_len) | |
8510 | goto error; | |
8511 | ||
50ac6607 | 8512 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8513 | pkt_offset = 0; |
8514 | else | |
8515 | pkt_offset = nla_get_u32( | |
50ac6607 | 8516 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8517 | if (pkt_offset > wowlan->max_pkt_offset) |
8518 | goto error; | |
8519 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8520 | ||
ff1b6e69 JB |
8521 | new_triggers.patterns[i].mask = |
8522 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8523 | if (!new_triggers.patterns[i].mask) { | |
8524 | err = -ENOMEM; | |
8525 | goto error; | |
8526 | } | |
8527 | new_triggers.patterns[i].pattern = | |
8528 | new_triggers.patterns[i].mask + mask_len; | |
8529 | memcpy(new_triggers.patterns[i].mask, | |
50ac6607 | 8530 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
ff1b6e69 JB |
8531 | mask_len); |
8532 | new_triggers.patterns[i].pattern_len = pat_len; | |
8533 | memcpy(new_triggers.patterns[i].pattern, | |
50ac6607 | 8534 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8535 | pat_len); |
8536 | i++; | |
8537 | } | |
8538 | } | |
8539 | ||
2a0e047e JB |
8540 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8541 | err = nl80211_parse_wowlan_tcp( | |
8542 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8543 | &new_triggers); | |
8544 | if (err) | |
8545 | goto error; | |
8546 | } | |
8547 | ||
ae33bd81 JB |
8548 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8549 | if (!ntrig) { | |
8550 | err = -ENOMEM; | |
8551 | goto error; | |
ff1b6e69 | 8552 | } |
ae33bd81 | 8553 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8554 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8555 | |
ae33bd81 | 8556 | set_wakeup: |
6abb9cb9 JB |
8557 | if (rdev->ops->set_wakeup && |
8558 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8559 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8560 | |
ff1b6e69 JB |
8561 | return 0; |
8562 | error: | |
8563 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8564 | kfree(new_triggers.patterns[i].mask); | |
8565 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8566 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8567 | sock_release(new_triggers.tcp->sock); | |
8568 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8569 | return err; |
8570 | } | |
dfb89c56 | 8571 | #endif |
ff1b6e69 | 8572 | |
be29b99a AK |
8573 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8574 | struct cfg80211_registered_device *rdev) | |
8575 | { | |
8576 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8577 | int i, j, pat_len; | |
8578 | struct cfg80211_coalesce_rules *rule; | |
8579 | ||
8580 | if (!rdev->coalesce->n_rules) | |
8581 | return 0; | |
8582 | ||
8583 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8584 | if (!nl_rules) | |
8585 | return -ENOBUFS; | |
8586 | ||
8587 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8588 | nl_rule = nla_nest_start(msg, i + 1); | |
8589 | if (!nl_rule) | |
8590 | return -ENOBUFS; | |
8591 | ||
8592 | rule = &rdev->coalesce->rules[i]; | |
8593 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8594 | rule->delay)) | |
8595 | return -ENOBUFS; | |
8596 | ||
8597 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8598 | rule->condition)) | |
8599 | return -ENOBUFS; | |
8600 | ||
8601 | nl_pats = nla_nest_start(msg, | |
8602 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8603 | if (!nl_pats) | |
8604 | return -ENOBUFS; | |
8605 | ||
8606 | for (j = 0; j < rule->n_patterns; j++) { | |
8607 | nl_pat = nla_nest_start(msg, j + 1); | |
8608 | if (!nl_pat) | |
8609 | return -ENOBUFS; | |
8610 | pat_len = rule->patterns[j].pattern_len; | |
8611 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8612 | DIV_ROUND_UP(pat_len, 8), | |
8613 | rule->patterns[j].mask) || | |
8614 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8615 | rule->patterns[j].pattern) || | |
8616 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8617 | rule->patterns[j].pkt_offset)) | |
8618 | return -ENOBUFS; | |
8619 | nla_nest_end(msg, nl_pat); | |
8620 | } | |
8621 | nla_nest_end(msg, nl_pats); | |
8622 | nla_nest_end(msg, nl_rule); | |
8623 | } | |
8624 | nla_nest_end(msg, nl_rules); | |
8625 | ||
8626 | return 0; | |
8627 | } | |
8628 | ||
8629 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8630 | { | |
8631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8632 | struct sk_buff *msg; | |
8633 | void *hdr; | |
8634 | ||
8635 | if (!rdev->wiphy.coalesce) | |
8636 | return -EOPNOTSUPP; | |
8637 | ||
8638 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8639 | if (!msg) | |
8640 | return -ENOMEM; | |
8641 | ||
8642 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8643 | NL80211_CMD_GET_COALESCE); | |
8644 | if (!hdr) | |
8645 | goto nla_put_failure; | |
8646 | ||
8647 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8648 | goto nla_put_failure; | |
8649 | ||
8650 | genlmsg_end(msg, hdr); | |
8651 | return genlmsg_reply(msg, info); | |
8652 | ||
8653 | nla_put_failure: | |
8654 | nlmsg_free(msg); | |
8655 | return -ENOBUFS; | |
8656 | } | |
8657 | ||
8658 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8659 | { | |
8660 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8661 | int i, j; | |
8662 | struct cfg80211_coalesce_rules *rule; | |
8663 | ||
8664 | if (!coalesce) | |
8665 | return; | |
8666 | ||
8667 | for (i = 0; i < coalesce->n_rules; i++) { | |
8668 | rule = &coalesce->rules[i]; | |
8669 | for (j = 0; j < rule->n_patterns; j++) | |
8670 | kfree(rule->patterns[j].mask); | |
8671 | kfree(rule->patterns); | |
8672 | } | |
8673 | kfree(coalesce->rules); | |
8674 | kfree(coalesce); | |
8675 | rdev->coalesce = NULL; | |
8676 | } | |
8677 | ||
8678 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8679 | struct nlattr *rule, | |
8680 | struct cfg80211_coalesce_rules *new_rule) | |
8681 | { | |
8682 | int err, i; | |
8683 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8684 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8685 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8686 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8687 | ||
8688 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8689 | nla_len(rule), nl80211_coalesce_policy); | |
8690 | if (err) | |
8691 | return err; | |
8692 | ||
8693 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8694 | new_rule->delay = | |
8695 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8696 | if (new_rule->delay > coalesce->max_delay) | |
8697 | return -EINVAL; | |
8698 | ||
8699 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8700 | new_rule->condition = | |
8701 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8702 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8703 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8704 | return -EINVAL; | |
8705 | ||
8706 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8707 | return -EINVAL; | |
8708 | ||
8709 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8710 | rem) | |
8711 | n_patterns++; | |
8712 | if (n_patterns > coalesce->n_patterns) | |
8713 | return -EINVAL; | |
8714 | ||
8715 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8716 | GFP_KERNEL); | |
8717 | if (!new_rule->patterns) | |
8718 | return -ENOMEM; | |
8719 | ||
8720 | new_rule->n_patterns = n_patterns; | |
8721 | i = 0; | |
8722 | ||
8723 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8724 | rem) { | |
8725 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | |
8726 | nla_len(pat), NULL); | |
8727 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8728 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8729 | return -EINVAL; | |
8730 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8731 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8732 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8733 | return -EINVAL; | |
8734 | if (pat_len > coalesce->pattern_max_len || | |
8735 | pat_len < coalesce->pattern_min_len) | |
8736 | return -EINVAL; | |
8737 | ||
8738 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8739 | pkt_offset = 0; | |
8740 | else | |
8741 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8742 | if (pkt_offset > coalesce->max_pkt_offset) | |
8743 | return -EINVAL; | |
8744 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8745 | ||
8746 | new_rule->patterns[i].mask = | |
8747 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8748 | if (!new_rule->patterns[i].mask) | |
8749 | return -ENOMEM; | |
8750 | new_rule->patterns[i].pattern = | |
8751 | new_rule->patterns[i].mask + mask_len; | |
8752 | memcpy(new_rule->patterns[i].mask, | |
8753 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); | |
8754 | new_rule->patterns[i].pattern_len = pat_len; | |
8755 | memcpy(new_rule->patterns[i].pattern, | |
8756 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); | |
8757 | i++; | |
8758 | } | |
8759 | ||
8760 | return 0; | |
8761 | } | |
8762 | ||
8763 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8764 | { | |
8765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8766 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8767 | struct cfg80211_coalesce new_coalesce = {}; | |
8768 | struct cfg80211_coalesce *n_coalesce; | |
8769 | int err, rem_rule, n_rules = 0, i, j; | |
8770 | struct nlattr *rule; | |
8771 | struct cfg80211_coalesce_rules *tmp_rule; | |
8772 | ||
8773 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8774 | return -EOPNOTSUPP; | |
8775 | ||
8776 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8777 | cfg80211_rdev_free_coalesce(rdev); | |
8778 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8779 | return 0; | |
8780 | } | |
8781 | ||
8782 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8783 | rem_rule) | |
8784 | n_rules++; | |
8785 | if (n_rules > coalesce->n_rules) | |
8786 | return -EINVAL; | |
8787 | ||
8788 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8789 | GFP_KERNEL); | |
8790 | if (!new_coalesce.rules) | |
8791 | return -ENOMEM; | |
8792 | ||
8793 | new_coalesce.n_rules = n_rules; | |
8794 | i = 0; | |
8795 | ||
8796 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8797 | rem_rule) { | |
8798 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8799 | &new_coalesce.rules[i]); | |
8800 | if (err) | |
8801 | goto error; | |
8802 | ||
8803 | i++; | |
8804 | } | |
8805 | ||
8806 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8807 | if (err) | |
8808 | goto error; | |
8809 | ||
8810 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8811 | if (!n_coalesce) { | |
8812 | err = -ENOMEM; | |
8813 | goto error; | |
8814 | } | |
8815 | cfg80211_rdev_free_coalesce(rdev); | |
8816 | rdev->coalesce = n_coalesce; | |
8817 | ||
8818 | return 0; | |
8819 | error: | |
8820 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8821 | tmp_rule = &new_coalesce.rules[i]; | |
8822 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8823 | kfree(tmp_rule->patterns[j].mask); | |
8824 | kfree(tmp_rule->patterns); | |
8825 | } | |
8826 | kfree(new_coalesce.rules); | |
8827 | ||
8828 | return err; | |
8829 | } | |
8830 | ||
e5497d76 JB |
8831 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8832 | { | |
8833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8834 | struct net_device *dev = info->user_ptr[1]; | |
8835 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8836 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8837 | struct cfg80211_gtk_rekey_data rekey_data; | |
8838 | int err; | |
8839 | ||
8840 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8841 | return -EINVAL; | |
8842 | ||
8843 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8844 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8845 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8846 | nl80211_rekey_policy); | |
8847 | if (err) | |
8848 | return err; | |
8849 | ||
8850 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8851 | return -ERANGE; | |
8852 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8853 | return -ERANGE; | |
8854 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8855 | return -ERANGE; | |
8856 | ||
8857 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8858 | NL80211_KEK_LEN); | |
8859 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8860 | NL80211_KCK_LEN); | |
8861 | memcpy(rekey_data.replay_ctr, | |
8862 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8863 | NL80211_REPLAY_CTR_LEN); | |
8864 | ||
8865 | wdev_lock(wdev); | |
8866 | if (!wdev->current_bss) { | |
8867 | err = -ENOTCONN; | |
8868 | goto out; | |
8869 | } | |
8870 | ||
8871 | if (!rdev->ops->set_rekey_data) { | |
8872 | err = -EOPNOTSUPP; | |
8873 | goto out; | |
8874 | } | |
8875 | ||
e35e4d28 | 8876 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8877 | out: |
8878 | wdev_unlock(wdev); | |
8879 | return err; | |
8880 | } | |
8881 | ||
28946da7 JB |
8882 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8883 | struct genl_info *info) | |
8884 | { | |
8885 | struct net_device *dev = info->user_ptr[1]; | |
8886 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8887 | ||
8888 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8889 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8890 | return -EINVAL; | |
8891 | ||
15e47304 | 8892 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8893 | return -EBUSY; |
8894 | ||
15e47304 | 8895 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8896 | return 0; |
8897 | } | |
8898 | ||
7f6cf311 JB |
8899 | static int nl80211_probe_client(struct sk_buff *skb, |
8900 | struct genl_info *info) | |
8901 | { | |
8902 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8903 | struct net_device *dev = info->user_ptr[1]; | |
8904 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8905 | struct sk_buff *msg; | |
8906 | void *hdr; | |
8907 | const u8 *addr; | |
8908 | u64 cookie; | |
8909 | int err; | |
8910 | ||
8911 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8912 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8913 | return -EOPNOTSUPP; | |
8914 | ||
8915 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8916 | return -EINVAL; | |
8917 | ||
8918 | if (!rdev->ops->probe_client) | |
8919 | return -EOPNOTSUPP; | |
8920 | ||
8921 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8922 | if (!msg) | |
8923 | return -ENOMEM; | |
8924 | ||
15e47304 | 8925 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 8926 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
8927 | if (!hdr) { |
8928 | err = -ENOBUFS; | |
7f6cf311 JB |
8929 | goto free_msg; |
8930 | } | |
8931 | ||
8932 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8933 | ||
e35e4d28 | 8934 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8935 | if (err) |
8936 | goto free_msg; | |
8937 | ||
9360ffd1 DM |
8938 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8939 | goto nla_put_failure; | |
7f6cf311 JB |
8940 | |
8941 | genlmsg_end(msg, hdr); | |
8942 | ||
8943 | return genlmsg_reply(msg, info); | |
8944 | ||
8945 | nla_put_failure: | |
8946 | err = -ENOBUFS; | |
8947 | free_msg: | |
8948 | nlmsg_free(msg); | |
8949 | return err; | |
8950 | } | |
8951 | ||
5e760230 JB |
8952 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8953 | { | |
8954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8955 | struct cfg80211_beacon_registration *reg, *nreg; |
8956 | int rv; | |
5e760230 JB |
8957 | |
8958 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8959 | return -EOPNOTSUPP; | |
8960 | ||
37c73b5f BG |
8961 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8962 | if (!nreg) | |
8963 | return -ENOMEM; | |
8964 | ||
8965 | /* First, check if already registered. */ | |
8966 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8967 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8968 | if (reg->nlportid == info->snd_portid) { | |
8969 | rv = -EALREADY; | |
8970 | goto out_err; | |
8971 | } | |
8972 | } | |
8973 | /* Add it to the list */ | |
8974 | nreg->nlportid = info->snd_portid; | |
8975 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8976 | |
37c73b5f | 8977 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8978 | |
8979 | return 0; | |
37c73b5f BG |
8980 | out_err: |
8981 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8982 | kfree(nreg); | |
8983 | return rv; | |
5e760230 JB |
8984 | } |
8985 | ||
98104fde JB |
8986 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8987 | { | |
8988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8989 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8990 | int err; | |
8991 | ||
8992 | if (!rdev->ops->start_p2p_device) | |
8993 | return -EOPNOTSUPP; | |
8994 | ||
8995 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8996 | return -EOPNOTSUPP; | |
8997 | ||
8998 | if (wdev->p2p_started) | |
8999 | return 0; | |
9000 | ||
b6a55015 LC |
9001 | if (rfkill_blocked(rdev->rfkill)) |
9002 | return -ERFKILL; | |
98104fde | 9003 | |
eeb126e9 | 9004 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9005 | if (err) |
9006 | return err; | |
9007 | ||
9008 | wdev->p2p_started = true; | |
98104fde | 9009 | rdev->opencount++; |
98104fde JB |
9010 | |
9011 | return 0; | |
9012 | } | |
9013 | ||
9014 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9015 | { | |
9016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9017 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9018 | ||
9019 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9020 | return -EOPNOTSUPP; | |
9021 | ||
9022 | if (!rdev->ops->stop_p2p_device) | |
9023 | return -EOPNOTSUPP; | |
9024 | ||
f9f47529 | 9025 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9026 | |
9027 | return 0; | |
9028 | } | |
9029 | ||
3713b4e3 JB |
9030 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9031 | struct genl_info *info) | |
9032 | { | |
9033 | void *hdr; | |
9034 | struct sk_buff *msg; | |
9035 | ||
9036 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9037 | if (!msg) | |
9038 | return -ENOMEM; | |
9039 | ||
9040 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9041 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9042 | if (!hdr) | |
9043 | goto nla_put_failure; | |
9044 | ||
9045 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9046 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9047 | goto nla_put_failure; | |
9048 | ||
9049 | genlmsg_end(msg, hdr); | |
9050 | return genlmsg_reply(msg, info); | |
9051 | ||
9052 | nla_put_failure: | |
9053 | kfree_skb(msg); | |
9054 | return -ENOBUFS; | |
9055 | } | |
9056 | ||
355199e0 JM |
9057 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9058 | { | |
9059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9060 | struct cfg80211_update_ft_ies_params ft_params; | |
9061 | struct net_device *dev = info->user_ptr[1]; | |
9062 | ||
9063 | if (!rdev->ops->update_ft_ies) | |
9064 | return -EOPNOTSUPP; | |
9065 | ||
9066 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9067 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9068 | return -EINVAL; | |
9069 | ||
9070 | memset(&ft_params, 0, sizeof(ft_params)); | |
9071 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9072 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9073 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9074 | ||
9075 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9076 | } | |
9077 | ||
5de17984 AS |
9078 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9079 | struct genl_info *info) | |
9080 | { | |
9081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9082 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9083 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9084 | u16 duration; | |
9085 | int ret; | |
9086 | ||
9087 | if (!rdev->ops->crit_proto_start) | |
9088 | return -EOPNOTSUPP; | |
9089 | ||
9090 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9091 | return -EINVAL; | |
9092 | ||
9093 | if (rdev->crit_proto_nlportid) | |
9094 | return -EBUSY; | |
9095 | ||
9096 | /* determine protocol if provided */ | |
9097 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9098 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9099 | ||
9100 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9101 | return -EINVAL; | |
9102 | ||
9103 | /* timeout must be provided */ | |
9104 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9105 | return -EINVAL; | |
9106 | ||
9107 | duration = | |
9108 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9109 | ||
9110 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9111 | return -ERANGE; | |
9112 | ||
9113 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9114 | if (!ret) | |
9115 | rdev->crit_proto_nlportid = info->snd_portid; | |
9116 | ||
9117 | return ret; | |
9118 | } | |
9119 | ||
9120 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9121 | struct genl_info *info) | |
9122 | { | |
9123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9124 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9125 | ||
9126 | if (!rdev->ops->crit_proto_stop) | |
9127 | return -EOPNOTSUPP; | |
9128 | ||
9129 | if (rdev->crit_proto_nlportid) { | |
9130 | rdev->crit_proto_nlportid = 0; | |
9131 | rdev_crit_proto_stop(rdev, wdev); | |
9132 | } | |
9133 | return 0; | |
9134 | } | |
9135 | ||
ad7e718c JB |
9136 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9137 | { | |
9138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9139 | struct wireless_dev *wdev = | |
9140 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9141 | int i, err; | |
9142 | u32 vid, subcmd; | |
9143 | ||
9144 | if (!rdev->wiphy.vendor_commands) | |
9145 | return -EOPNOTSUPP; | |
9146 | ||
9147 | if (IS_ERR(wdev)) { | |
9148 | err = PTR_ERR(wdev); | |
9149 | if (err != -EINVAL) | |
9150 | return err; | |
9151 | wdev = NULL; | |
9152 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9153 | return -EINVAL; | |
9154 | } | |
9155 | ||
9156 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9157 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9158 | return -EINVAL; | |
9159 | ||
9160 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9161 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9162 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9163 | const struct wiphy_vendor_command *vcmd; | |
9164 | void *data = NULL; | |
9165 | int len = 0; | |
9166 | ||
9167 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9168 | ||
9169 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9170 | continue; | |
9171 | ||
9172 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9173 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9174 | if (!wdev) | |
9175 | return -EINVAL; | |
9176 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9177 | !wdev->netdev) | |
9178 | return -EINVAL; | |
9179 | ||
9180 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9181 | if (wdev->netdev && | |
9182 | !netif_running(wdev->netdev)) | |
9183 | return -ENETDOWN; | |
9184 | if (!wdev->netdev && !wdev->p2p_started) | |
9185 | return -ENETDOWN; | |
9186 | } | |
9187 | } else { | |
9188 | wdev = NULL; | |
9189 | } | |
9190 | ||
9191 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9192 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9193 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9194 | } | |
9195 | ||
9196 | rdev->cur_cmd_info = info; | |
9197 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9198 | data, len); | |
9199 | rdev->cur_cmd_info = NULL; | |
9200 | return err; | |
9201 | } | |
9202 | ||
9203 | return -EOPNOTSUPP; | |
9204 | } | |
9205 | ||
9206 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9207 | enum nl80211_commands cmd, | |
9208 | enum nl80211_attrs attr, | |
9209 | int approxlen) | |
9210 | { | |
f26cbf40 | 9211 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9212 | |
9213 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9214 | return NULL; | |
9215 | ||
9216 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9217 | rdev->cur_cmd_info->snd_portid, | |
9218 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9219 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9220 | } |
9221 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9222 | ||
9223 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9224 | { | |
9225 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9226 | void *hdr = ((void **)skb->cb)[1]; | |
9227 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9228 | ||
9229 | if (WARN_ON(!rdev->cur_cmd_info)) { | |
9230 | kfree_skb(skb); | |
9231 | return -EINVAL; | |
9232 | } | |
9233 | ||
9234 | nla_nest_end(skb, data); | |
9235 | genlmsg_end(skb, hdr); | |
9236 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9237 | } | |
9238 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9239 | ||
9240 | ||
fa9ffc74 KP |
9241 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9242 | struct genl_info *info) | |
9243 | { | |
9244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9245 | struct cfg80211_qos_map *qos_map = NULL; | |
9246 | struct net_device *dev = info->user_ptr[1]; | |
9247 | u8 *pos, len, num_des, des_len, des; | |
9248 | int ret; | |
9249 | ||
9250 | if (!rdev->ops->set_qos_map) | |
9251 | return -EOPNOTSUPP; | |
9252 | ||
9253 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9254 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9255 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9256 | ||
9257 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9258 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9259 | return -EINVAL; | |
9260 | ||
9261 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9262 | if (!qos_map) | |
9263 | return -ENOMEM; | |
9264 | ||
9265 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9266 | if (num_des) { | |
9267 | des_len = num_des * | |
9268 | sizeof(struct cfg80211_dscp_exception); | |
9269 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9270 | qos_map->num_des = num_des; | |
9271 | for (des = 0; des < num_des; des++) { | |
9272 | if (qos_map->dscp_exception[des].up > 7) { | |
9273 | kfree(qos_map); | |
9274 | return -EINVAL; | |
9275 | } | |
9276 | } | |
9277 | pos += des_len; | |
9278 | } | |
9279 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9280 | } | |
9281 | ||
9282 | wdev_lock(dev->ieee80211_ptr); | |
9283 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9284 | if (!ret) | |
9285 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9286 | wdev_unlock(dev->ieee80211_ptr); | |
9287 | ||
9288 | kfree(qos_map); | |
9289 | return ret; | |
9290 | } | |
9291 | ||
4c476991 JB |
9292 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
9293 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
9294 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
9295 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
9296 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
9297 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 9298 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 9299 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
9300 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
9301 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 | 9302 | |
f84f771d | 9303 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9304 | struct genl_info *info) |
9305 | { | |
9306 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 9307 | struct wireless_dev *wdev; |
4c476991 | 9308 | struct net_device *dev; |
4c476991 JB |
9309 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
9310 | ||
9311 | if (rtnl) | |
9312 | rtnl_lock(); | |
9313 | ||
9314 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 9315 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
9316 | if (IS_ERR(rdev)) { |
9317 | if (rtnl) | |
9318 | rtnl_unlock(); | |
9319 | return PTR_ERR(rdev); | |
9320 | } | |
9321 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
9322 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
9323 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
9324 | ASSERT_RTNL(); |
9325 | ||
89a54e48 JB |
9326 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
9327 | info->attrs); | |
9328 | if (IS_ERR(wdev)) { | |
4c476991 JB |
9329 | if (rtnl) |
9330 | rtnl_unlock(); | |
89a54e48 | 9331 | return PTR_ERR(wdev); |
4c476991 | 9332 | } |
89a54e48 | 9333 | |
89a54e48 | 9334 | dev = wdev->netdev; |
f26cbf40 | 9335 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 9336 | |
1bf614ef JB |
9337 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
9338 | if (!dev) { | |
1bf614ef JB |
9339 | if (rtnl) |
9340 | rtnl_unlock(); | |
9341 | return -EINVAL; | |
9342 | } | |
9343 | ||
9344 | info->user_ptr[1] = dev; | |
9345 | } else { | |
9346 | info->user_ptr[1] = wdev; | |
41265714 | 9347 | } |
1bf614ef JB |
9348 | |
9349 | if (dev) { | |
9350 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
9351 | !netif_running(dev)) { | |
1bf614ef JB |
9352 | if (rtnl) |
9353 | rtnl_unlock(); | |
9354 | return -ENETDOWN; | |
9355 | } | |
9356 | ||
9357 | dev_hold(dev); | |
98104fde JB |
9358 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
9359 | if (!wdev->p2p_started) { | |
98104fde JB |
9360 | if (rtnl) |
9361 | rtnl_unlock(); | |
9362 | return -ENETDOWN; | |
9363 | } | |
41265714 | 9364 | } |
89a54e48 | 9365 | |
4c476991 | 9366 | info->user_ptr[0] = rdev; |
4c476991 JB |
9367 | } |
9368 | ||
9369 | return 0; | |
9370 | } | |
9371 | ||
f84f771d | 9372 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9373 | struct genl_info *info) |
9374 | { | |
1bf614ef JB |
9375 | if (info->user_ptr[1]) { |
9376 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
9377 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9378 | ||
9379 | if (wdev->netdev) | |
9380 | dev_put(wdev->netdev); | |
9381 | } else { | |
9382 | dev_put(info->user_ptr[1]); | |
9383 | } | |
9384 | } | |
4c476991 JB |
9385 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
9386 | rtnl_unlock(); | |
9387 | } | |
9388 | ||
4534de83 | 9389 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
9390 | { |
9391 | .cmd = NL80211_CMD_GET_WIPHY, | |
9392 | .doit = nl80211_get_wiphy, | |
9393 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 9394 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
9395 | .policy = nl80211_policy, |
9396 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9397 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9398 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9399 | }, |
9400 | { | |
9401 | .cmd = NL80211_CMD_SET_WIPHY, | |
9402 | .doit = nl80211_set_wiphy, | |
9403 | .policy = nl80211_policy, | |
9404 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 9405 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
9406 | }, |
9407 | { | |
9408 | .cmd = NL80211_CMD_GET_INTERFACE, | |
9409 | .doit = nl80211_get_interface, | |
9410 | .dumpit = nl80211_dump_interface, | |
9411 | .policy = nl80211_policy, | |
9412 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9413 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
9414 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9415 | }, |
9416 | { | |
9417 | .cmd = NL80211_CMD_SET_INTERFACE, | |
9418 | .doit = nl80211_set_interface, | |
9419 | .policy = nl80211_policy, | |
9420 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9421 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9422 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9423 | }, |
9424 | { | |
9425 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9426 | .doit = nl80211_new_interface, | |
9427 | .policy = nl80211_policy, | |
9428 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9429 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9430 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9431 | }, |
9432 | { | |
9433 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9434 | .doit = nl80211_del_interface, | |
9435 | .policy = nl80211_policy, | |
41ade00f | 9436 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9437 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9438 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9439 | }, |
9440 | { | |
9441 | .cmd = NL80211_CMD_GET_KEY, | |
9442 | .doit = nl80211_get_key, | |
9443 | .policy = nl80211_policy, | |
9444 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9445 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9446 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9447 | }, |
9448 | { | |
9449 | .cmd = NL80211_CMD_SET_KEY, | |
9450 | .doit = nl80211_set_key, | |
9451 | .policy = nl80211_policy, | |
9452 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9453 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9454 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9455 | }, |
9456 | { | |
9457 | .cmd = NL80211_CMD_NEW_KEY, | |
9458 | .doit = nl80211_new_key, | |
9459 | .policy = nl80211_policy, | |
9460 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9461 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9462 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9463 | }, |
9464 | { | |
9465 | .cmd = NL80211_CMD_DEL_KEY, | |
9466 | .doit = nl80211_del_key, | |
9467 | .policy = nl80211_policy, | |
55682965 | 9468 | .flags = GENL_ADMIN_PERM, |
41265714 | 9469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9470 | NL80211_FLAG_NEED_RTNL, |
55682965 | 9471 | }, |
ed1b6cc7 JB |
9472 | { |
9473 | .cmd = NL80211_CMD_SET_BEACON, | |
9474 | .policy = nl80211_policy, | |
9475 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9476 | .doit = nl80211_set_beacon, |
2b5f8b0b | 9477 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9478 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9479 | }, |
9480 | { | |
8860020e | 9481 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
9482 | .policy = nl80211_policy, |
9483 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9484 | .doit = nl80211_start_ap, |
2b5f8b0b | 9485 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9486 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9487 | }, |
9488 | { | |
8860020e | 9489 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
9490 | .policy = nl80211_policy, |
9491 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9492 | .doit = nl80211_stop_ap, |
2b5f8b0b | 9493 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9494 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 9495 | }, |
5727ef1b JB |
9496 | { |
9497 | .cmd = NL80211_CMD_GET_STATION, | |
9498 | .doit = nl80211_get_station, | |
2ec600d6 | 9499 | .dumpit = nl80211_dump_station, |
5727ef1b | 9500 | .policy = nl80211_policy, |
4c476991 JB |
9501 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9502 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
9503 | }, |
9504 | { | |
9505 | .cmd = NL80211_CMD_SET_STATION, | |
9506 | .doit = nl80211_set_station, | |
9507 | .policy = nl80211_policy, | |
9508 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9510 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9511 | }, |
9512 | { | |
9513 | .cmd = NL80211_CMD_NEW_STATION, | |
9514 | .doit = nl80211_new_station, | |
9515 | .policy = nl80211_policy, | |
9516 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9517 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9518 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9519 | }, |
9520 | { | |
9521 | .cmd = NL80211_CMD_DEL_STATION, | |
9522 | .doit = nl80211_del_station, | |
9523 | .policy = nl80211_policy, | |
2ec600d6 | 9524 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9526 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9527 | }, |
9528 | { | |
9529 | .cmd = NL80211_CMD_GET_MPATH, | |
9530 | .doit = nl80211_get_mpath, | |
9531 | .dumpit = nl80211_dump_mpath, | |
9532 | .policy = nl80211_policy, | |
9533 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9535 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9536 | }, |
9537 | { | |
9538 | .cmd = NL80211_CMD_SET_MPATH, | |
9539 | .doit = nl80211_set_mpath, | |
9540 | .policy = nl80211_policy, | |
9541 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9542 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9543 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9544 | }, |
9545 | { | |
9546 | .cmd = NL80211_CMD_NEW_MPATH, | |
9547 | .doit = nl80211_new_mpath, | |
9548 | .policy = nl80211_policy, | |
9549 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9550 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9551 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9552 | }, |
9553 | { | |
9554 | .cmd = NL80211_CMD_DEL_MPATH, | |
9555 | .doit = nl80211_del_mpath, | |
9556 | .policy = nl80211_policy, | |
9f1ba906 | 9557 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9558 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9559 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9560 | }, |
9561 | { | |
9562 | .cmd = NL80211_CMD_SET_BSS, | |
9563 | .doit = nl80211_set_bss, | |
9564 | .policy = nl80211_policy, | |
b2e1b302 | 9565 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9566 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9567 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9568 | }, |
f130347c LR |
9569 | { |
9570 | .cmd = NL80211_CMD_GET_REG, | |
9571 | .doit = nl80211_get_reg, | |
9572 | .policy = nl80211_policy, | |
5fe231e8 | 9573 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9574 | /* can be retrieved by unprivileged users */ |
9575 | }, | |
b2e1b302 LR |
9576 | { |
9577 | .cmd = NL80211_CMD_SET_REG, | |
9578 | .doit = nl80211_set_reg, | |
9579 | .policy = nl80211_policy, | |
9580 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9581 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9582 | }, |
9583 | { | |
9584 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9585 | .doit = nl80211_req_set_reg, | |
9586 | .policy = nl80211_policy, | |
93da9cc1 | 9587 | .flags = GENL_ADMIN_PERM, |
9588 | }, | |
9589 | { | |
24bdd9f4 JC |
9590 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9591 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9592 | .policy = nl80211_policy, |
9593 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9595 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9596 | }, |
9597 | { | |
24bdd9f4 JC |
9598 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9599 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9600 | .policy = nl80211_policy, |
9aed3cc1 | 9601 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9603 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9604 | }, |
2a519311 JB |
9605 | { |
9606 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9607 | .doit = nl80211_trigger_scan, | |
9608 | .policy = nl80211_policy, | |
9609 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9610 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9611 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9612 | }, |
9613 | { | |
9614 | .cmd = NL80211_CMD_GET_SCAN, | |
9615 | .policy = nl80211_policy, | |
9616 | .dumpit = nl80211_dump_scan, | |
9617 | }, | |
807f8a8c LC |
9618 | { |
9619 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9620 | .doit = nl80211_start_sched_scan, | |
9621 | .policy = nl80211_policy, | |
9622 | .flags = GENL_ADMIN_PERM, | |
9623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9624 | NL80211_FLAG_NEED_RTNL, | |
9625 | }, | |
9626 | { | |
9627 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9628 | .doit = nl80211_stop_sched_scan, | |
9629 | .policy = nl80211_policy, | |
9630 | .flags = GENL_ADMIN_PERM, | |
9631 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9632 | NL80211_FLAG_NEED_RTNL, | |
9633 | }, | |
636a5d36 JM |
9634 | { |
9635 | .cmd = NL80211_CMD_AUTHENTICATE, | |
9636 | .doit = nl80211_authenticate, | |
9637 | .policy = nl80211_policy, | |
9638 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9640 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9641 | }, |
9642 | { | |
9643 | .cmd = NL80211_CMD_ASSOCIATE, | |
9644 | .doit = nl80211_associate, | |
9645 | .policy = nl80211_policy, | |
9646 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9648 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9649 | }, |
9650 | { | |
9651 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9652 | .doit = nl80211_deauthenticate, | |
9653 | .policy = nl80211_policy, | |
9654 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9656 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9657 | }, |
9658 | { | |
9659 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9660 | .doit = nl80211_disassociate, | |
9661 | .policy = nl80211_policy, | |
9662 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9664 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9665 | }, |
04a773ad JB |
9666 | { |
9667 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9668 | .doit = nl80211_join_ibss, | |
9669 | .policy = nl80211_policy, | |
9670 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9672 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9673 | }, |
9674 | { | |
9675 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9676 | .doit = nl80211_leave_ibss, | |
9677 | .policy = nl80211_policy, | |
9678 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9680 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9681 | }, |
aff89a9b JB |
9682 | #ifdef CONFIG_NL80211_TESTMODE |
9683 | { | |
9684 | .cmd = NL80211_CMD_TESTMODE, | |
9685 | .doit = nl80211_testmode_do, | |
71063f0e | 9686 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9687 | .policy = nl80211_policy, |
9688 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9689 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9690 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9691 | }, |
9692 | #endif | |
b23aa676 SO |
9693 | { |
9694 | .cmd = NL80211_CMD_CONNECT, | |
9695 | .doit = nl80211_connect, | |
9696 | .policy = nl80211_policy, | |
9697 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9698 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9699 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9700 | }, |
9701 | { | |
9702 | .cmd = NL80211_CMD_DISCONNECT, | |
9703 | .doit = nl80211_disconnect, | |
9704 | .policy = nl80211_policy, | |
9705 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9706 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9707 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9708 | }, |
463d0183 JB |
9709 | { |
9710 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9711 | .doit = nl80211_wiphy_netns, | |
9712 | .policy = nl80211_policy, | |
9713 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9714 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9715 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9716 | }, |
61fa713c HS |
9717 | { |
9718 | .cmd = NL80211_CMD_GET_SURVEY, | |
9719 | .policy = nl80211_policy, | |
9720 | .dumpit = nl80211_dump_survey, | |
9721 | }, | |
67fbb16b SO |
9722 | { |
9723 | .cmd = NL80211_CMD_SET_PMKSA, | |
9724 | .doit = nl80211_setdel_pmksa, | |
9725 | .policy = nl80211_policy, | |
9726 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9727 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9728 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9729 | }, |
9730 | { | |
9731 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9732 | .doit = nl80211_setdel_pmksa, | |
9733 | .policy = nl80211_policy, | |
9734 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9735 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9736 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9737 | }, |
9738 | { | |
9739 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9740 | .doit = nl80211_flush_pmksa, | |
9741 | .policy = nl80211_policy, | |
9742 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9743 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9744 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9745 | }, |
9588bbd5 JM |
9746 | { |
9747 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9748 | .doit = nl80211_remain_on_channel, | |
9749 | .policy = nl80211_policy, | |
9750 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9751 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9752 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9753 | }, |
9754 | { | |
9755 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9756 | .doit = nl80211_cancel_remain_on_channel, | |
9757 | .policy = nl80211_policy, | |
9758 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9759 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9760 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9761 | }, |
13ae75b1 JM |
9762 | { |
9763 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9764 | .doit = nl80211_set_tx_bitrate_mask, | |
9765 | .policy = nl80211_policy, | |
9766 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9767 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9768 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9769 | }, |
026331c4 | 9770 | { |
2e161f78 JB |
9771 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9772 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9773 | .policy = nl80211_policy, |
9774 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9775 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9776 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9777 | }, |
9778 | { | |
2e161f78 JB |
9779 | .cmd = NL80211_CMD_FRAME, |
9780 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9781 | .policy = nl80211_policy, |
f7ca38df | 9782 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9783 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9784 | NL80211_FLAG_NEED_RTNL, |
9785 | }, | |
9786 | { | |
9787 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9788 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9789 | .policy = nl80211_policy, | |
026331c4 | 9790 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9791 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9792 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9793 | }, |
ffb9eb3d KV |
9794 | { |
9795 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9796 | .doit = nl80211_set_power_save, | |
9797 | .policy = nl80211_policy, | |
9798 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9799 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9800 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9801 | }, |
9802 | { | |
9803 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9804 | .doit = nl80211_get_power_save, | |
9805 | .policy = nl80211_policy, | |
9806 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9807 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9808 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9809 | }, |
d6dc1a38 JO |
9810 | { |
9811 | .cmd = NL80211_CMD_SET_CQM, | |
9812 | .doit = nl80211_set_cqm, | |
9813 | .policy = nl80211_policy, | |
9814 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9815 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9816 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9817 | }, |
f444de05 JB |
9818 | { |
9819 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9820 | .doit = nl80211_set_channel, | |
9821 | .policy = nl80211_policy, | |
9822 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9823 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9824 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9825 | }, |
e8347eba BJ |
9826 | { |
9827 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9828 | .doit = nl80211_set_wds_peer, | |
9829 | .policy = nl80211_policy, | |
9830 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9831 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9832 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9833 | }, |
29cbe68c JB |
9834 | { |
9835 | .cmd = NL80211_CMD_JOIN_MESH, | |
9836 | .doit = nl80211_join_mesh, | |
9837 | .policy = nl80211_policy, | |
9838 | .flags = GENL_ADMIN_PERM, | |
9839 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9840 | NL80211_FLAG_NEED_RTNL, | |
9841 | }, | |
9842 | { | |
9843 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9844 | .doit = nl80211_leave_mesh, | |
9845 | .policy = nl80211_policy, | |
9846 | .flags = GENL_ADMIN_PERM, | |
9847 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9848 | NL80211_FLAG_NEED_RTNL, | |
9849 | }, | |
dfb89c56 | 9850 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9851 | { |
9852 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9853 | .doit = nl80211_get_wowlan, | |
9854 | .policy = nl80211_policy, | |
9855 | /* can be retrieved by unprivileged users */ | |
9856 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9857 | NL80211_FLAG_NEED_RTNL, | |
9858 | }, | |
9859 | { | |
9860 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9861 | .doit = nl80211_set_wowlan, | |
9862 | .policy = nl80211_policy, | |
9863 | .flags = GENL_ADMIN_PERM, | |
9864 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9865 | NL80211_FLAG_NEED_RTNL, | |
9866 | }, | |
dfb89c56 | 9867 | #endif |
e5497d76 JB |
9868 | { |
9869 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9870 | .doit = nl80211_set_rekey_data, | |
9871 | .policy = nl80211_policy, | |
9872 | .flags = GENL_ADMIN_PERM, | |
9873 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9874 | NL80211_FLAG_NEED_RTNL, | |
9875 | }, | |
109086ce AN |
9876 | { |
9877 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9878 | .doit = nl80211_tdls_mgmt, | |
9879 | .policy = nl80211_policy, | |
9880 | .flags = GENL_ADMIN_PERM, | |
9881 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9882 | NL80211_FLAG_NEED_RTNL, | |
9883 | }, | |
9884 | { | |
9885 | .cmd = NL80211_CMD_TDLS_OPER, | |
9886 | .doit = nl80211_tdls_oper, | |
9887 | .policy = nl80211_policy, | |
9888 | .flags = GENL_ADMIN_PERM, | |
9889 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9890 | NL80211_FLAG_NEED_RTNL, | |
9891 | }, | |
28946da7 JB |
9892 | { |
9893 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9894 | .doit = nl80211_register_unexpected_frame, | |
9895 | .policy = nl80211_policy, | |
9896 | .flags = GENL_ADMIN_PERM, | |
9897 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9898 | NL80211_FLAG_NEED_RTNL, | |
9899 | }, | |
7f6cf311 JB |
9900 | { |
9901 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9902 | .doit = nl80211_probe_client, | |
9903 | .policy = nl80211_policy, | |
9904 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9905 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9906 | NL80211_FLAG_NEED_RTNL, |
9907 | }, | |
5e760230 JB |
9908 | { |
9909 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9910 | .doit = nl80211_register_beacons, | |
9911 | .policy = nl80211_policy, | |
9912 | .flags = GENL_ADMIN_PERM, | |
9913 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9914 | NL80211_FLAG_NEED_RTNL, | |
9915 | }, | |
1d9d9213 SW |
9916 | { |
9917 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9918 | .doit = nl80211_set_noack_map, | |
9919 | .policy = nl80211_policy, | |
9920 | .flags = GENL_ADMIN_PERM, | |
9921 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9922 | NL80211_FLAG_NEED_RTNL, | |
9923 | }, | |
98104fde JB |
9924 | { |
9925 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9926 | .doit = nl80211_start_p2p_device, | |
9927 | .policy = nl80211_policy, | |
9928 | .flags = GENL_ADMIN_PERM, | |
9929 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9930 | NL80211_FLAG_NEED_RTNL, | |
9931 | }, | |
9932 | { | |
9933 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9934 | .doit = nl80211_stop_p2p_device, | |
9935 | .policy = nl80211_policy, | |
9936 | .flags = GENL_ADMIN_PERM, | |
9937 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9938 | NL80211_FLAG_NEED_RTNL, | |
9939 | }, | |
f4e583c8 AQ |
9940 | { |
9941 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9942 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9943 | .policy = nl80211_policy, |
9944 | .flags = GENL_ADMIN_PERM, | |
9945 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9946 | NL80211_FLAG_NEED_RTNL, | |
9947 | }, | |
9948 | { | |
9949 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9950 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9951 | .policy = nl80211_policy, |
9952 | .flags = GENL_ADMIN_PERM, | |
9953 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9954 | NL80211_FLAG_NEED_RTNL, | |
9955 | }, | |
04f39047 SW |
9956 | { |
9957 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9958 | .doit = nl80211_start_radar_detection, | |
9959 | .policy = nl80211_policy, | |
9960 | .flags = GENL_ADMIN_PERM, | |
9961 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9962 | NL80211_FLAG_NEED_RTNL, | |
9963 | }, | |
3713b4e3 JB |
9964 | { |
9965 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9966 | .doit = nl80211_get_protocol_features, | |
9967 | .policy = nl80211_policy, | |
9968 | }, | |
355199e0 JM |
9969 | { |
9970 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9971 | .doit = nl80211_update_ft_ies, | |
9972 | .policy = nl80211_policy, | |
9973 | .flags = GENL_ADMIN_PERM, | |
9974 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9975 | NL80211_FLAG_NEED_RTNL, | |
9976 | }, | |
5de17984 AS |
9977 | { |
9978 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9979 | .doit = nl80211_crit_protocol_start, | |
9980 | .policy = nl80211_policy, | |
9981 | .flags = GENL_ADMIN_PERM, | |
9982 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9983 | NL80211_FLAG_NEED_RTNL, | |
9984 | }, | |
9985 | { | |
9986 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9987 | .doit = nl80211_crit_protocol_stop, | |
9988 | .policy = nl80211_policy, | |
9989 | .flags = GENL_ADMIN_PERM, | |
9990 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9991 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
9992 | }, |
9993 | { | |
9994 | .cmd = NL80211_CMD_GET_COALESCE, | |
9995 | .doit = nl80211_get_coalesce, | |
9996 | .policy = nl80211_policy, | |
9997 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9998 | NL80211_FLAG_NEED_RTNL, | |
9999 | }, | |
10000 | { | |
10001 | .cmd = NL80211_CMD_SET_COALESCE, | |
10002 | .doit = nl80211_set_coalesce, | |
10003 | .policy = nl80211_policy, | |
10004 | .flags = GENL_ADMIN_PERM, | |
10005 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10006 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10007 | }, |
10008 | { | |
10009 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10010 | .doit = nl80211_channel_switch, | |
10011 | .policy = nl80211_policy, | |
10012 | .flags = GENL_ADMIN_PERM, | |
10013 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10014 | NL80211_FLAG_NEED_RTNL, | |
10015 | }, | |
ad7e718c JB |
10016 | { |
10017 | .cmd = NL80211_CMD_VENDOR, | |
10018 | .doit = nl80211_vendor_cmd, | |
10019 | .policy = nl80211_policy, | |
10020 | .flags = GENL_ADMIN_PERM, | |
10021 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10022 | NL80211_FLAG_NEED_RTNL, | |
10023 | }, | |
fa9ffc74 KP |
10024 | { |
10025 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10026 | .doit = nl80211_set_qos_map, | |
10027 | .policy = nl80211_policy, | |
10028 | .flags = GENL_ADMIN_PERM, | |
10029 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10030 | NL80211_FLAG_NEED_RTNL, | |
10031 | }, | |
55682965 | 10032 | }; |
9588bbd5 | 10033 | |
55682965 JB |
10034 | /* notification functions */ |
10035 | ||
10036 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
10037 | { | |
10038 | struct sk_buff *msg; | |
86e8cf98 | 10039 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 10040 | |
fd2120ca | 10041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
10042 | if (!msg) |
10043 | return; | |
10044 | ||
86e8cf98 | 10045 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10046 | nlmsg_free(msg); |
10047 | return; | |
10048 | } | |
10049 | ||
68eb5503 | 10050 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10051 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10052 | } |
10053 | ||
362a415d JB |
10054 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10055 | struct cfg80211_registered_device *rdev) | |
10056 | { | |
10057 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10058 | struct nlattr *nest; | |
10059 | int i; | |
10060 | ||
10061 | if (WARN_ON(!req)) | |
10062 | return 0; | |
10063 | ||
10064 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10065 | if (!nest) | |
10066 | goto nla_put_failure; | |
9360ffd1 DM |
10067 | for (i = 0; i < req->n_ssids; i++) { |
10068 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10069 | goto nla_put_failure; | |
10070 | } | |
362a415d JB |
10071 | nla_nest_end(msg, nest); |
10072 | ||
10073 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10074 | if (!nest) | |
10075 | goto nla_put_failure; | |
9360ffd1 DM |
10076 | for (i = 0; i < req->n_channels; i++) { |
10077 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10078 | goto nla_put_failure; | |
10079 | } | |
362a415d JB |
10080 | nla_nest_end(msg, nest); |
10081 | ||
9360ffd1 DM |
10082 | if (req->ie && |
10083 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10084 | goto nla_put_failure; | |
362a415d | 10085 | |
ae917c9f JB |
10086 | if (req->flags && |
10087 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
10088 | goto nla_put_failure; | |
ed473771 | 10089 | |
362a415d JB |
10090 | return 0; |
10091 | nla_put_failure: | |
10092 | return -ENOBUFS; | |
10093 | } | |
10094 | ||
a538e2d5 JB |
10095 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
10096 | struct cfg80211_registered_device *rdev, | |
fd014284 | 10097 | struct wireless_dev *wdev, |
15e47304 | 10098 | u32 portid, u32 seq, int flags, |
a538e2d5 | 10099 | u32 cmd) |
2a519311 JB |
10100 | { |
10101 | void *hdr; | |
10102 | ||
15e47304 | 10103 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
10104 | if (!hdr) |
10105 | return -1; | |
10106 | ||
9360ffd1 | 10107 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
10108 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10109 | wdev->netdev->ifindex)) || | |
10110 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 10111 | goto nla_put_failure; |
2a519311 | 10112 | |
362a415d JB |
10113 | /* ignore errors and send incomplete event anyway */ |
10114 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
10115 | |
10116 | return genlmsg_end(msg, hdr); | |
10117 | ||
10118 | nla_put_failure: | |
10119 | genlmsg_cancel(msg, hdr); | |
10120 | return -EMSGSIZE; | |
10121 | } | |
10122 | ||
807f8a8c LC |
10123 | static int |
10124 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
10125 | struct cfg80211_registered_device *rdev, | |
10126 | struct net_device *netdev, | |
15e47304 | 10127 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
10128 | { |
10129 | void *hdr; | |
10130 | ||
15e47304 | 10131 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
10132 | if (!hdr) |
10133 | return -1; | |
10134 | ||
9360ffd1 DM |
10135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10136 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10137 | goto nla_put_failure; | |
807f8a8c LC |
10138 | |
10139 | return genlmsg_end(msg, hdr); | |
10140 | ||
10141 | nla_put_failure: | |
10142 | genlmsg_cancel(msg, hdr); | |
10143 | return -EMSGSIZE; | |
10144 | } | |
10145 | ||
a538e2d5 | 10146 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 10147 | struct wireless_dev *wdev) |
a538e2d5 JB |
10148 | { |
10149 | struct sk_buff *msg; | |
10150 | ||
58050fce | 10151 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10152 | if (!msg) |
10153 | return; | |
10154 | ||
fd014284 | 10155 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
10156 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
10157 | nlmsg_free(msg); | |
10158 | return; | |
10159 | } | |
10160 | ||
68eb5503 | 10161 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10162 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
10163 | } |
10164 | ||
f9d15d16 JB |
10165 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
10166 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
10167 | { |
10168 | struct sk_buff *msg; | |
10169 | ||
fd2120ca | 10170 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 10171 | if (!msg) |
f9d15d16 | 10172 | return NULL; |
2a519311 | 10173 | |
fd014284 | 10174 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
10175 | aborted ? NL80211_CMD_SCAN_ABORTED : |
10176 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 10177 | nlmsg_free(msg); |
f9d15d16 | 10178 | return NULL; |
2a519311 JB |
10179 | } |
10180 | ||
f9d15d16 | 10181 | return msg; |
2a519311 JB |
10182 | } |
10183 | ||
f9d15d16 JB |
10184 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
10185 | struct sk_buff *msg) | |
2a519311 | 10186 | { |
2a519311 JB |
10187 | if (!msg) |
10188 | return; | |
10189 | ||
68eb5503 | 10190 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10191 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10192 | } |
10193 | ||
807f8a8c LC |
10194 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
10195 | struct net_device *netdev) | |
10196 | { | |
10197 | struct sk_buff *msg; | |
10198 | ||
10199 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10200 | if (!msg) | |
10201 | return; | |
10202 | ||
10203 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
10204 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
10205 | nlmsg_free(msg); | |
10206 | return; | |
10207 | } | |
10208 | ||
68eb5503 | 10209 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10210 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10211 | } |
10212 | ||
10213 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
10214 | struct net_device *netdev, u32 cmd) | |
10215 | { | |
10216 | struct sk_buff *msg; | |
10217 | ||
58050fce | 10218 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
10219 | if (!msg) |
10220 | return; | |
10221 | ||
10222 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
10223 | nlmsg_free(msg); | |
10224 | return; | |
10225 | } | |
10226 | ||
68eb5503 | 10227 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10228 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10229 | } |
10230 | ||
73d54c9e LR |
10231 | /* |
10232 | * This can happen on global regulatory changes or device specific settings | |
10233 | * based on custom world regulatory domains. | |
10234 | */ | |
10235 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
10236 | { | |
10237 | struct sk_buff *msg; | |
10238 | void *hdr; | |
10239 | ||
fd2120ca | 10240 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
10241 | if (!msg) |
10242 | return; | |
10243 | ||
10244 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
10245 | if (!hdr) { | |
10246 | nlmsg_free(msg); | |
10247 | return; | |
10248 | } | |
10249 | ||
10250 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
10251 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
10252 | goto nla_put_failure; | |
10253 | ||
10254 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
10255 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10256 | NL80211_REGDOM_TYPE_WORLD)) | |
10257 | goto nla_put_failure; | |
10258 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
10259 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10260 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
10261 | goto nla_put_failure; | |
10262 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
10263 | request->intersect) { | |
10264 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10265 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
10266 | goto nla_put_failure; | |
10267 | } else { | |
10268 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10269 | NL80211_REGDOM_TYPE_COUNTRY) || | |
10270 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
10271 | request->alpha2)) | |
10272 | goto nla_put_failure; | |
10273 | } | |
10274 | ||
f4173766 | 10275 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
10276 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
10277 | goto nla_put_failure; | |
73d54c9e | 10278 | |
3b7b72ee | 10279 | genlmsg_end(msg, hdr); |
73d54c9e | 10280 | |
bc43b28c | 10281 | rcu_read_lock(); |
68eb5503 | 10282 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10283 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 10284 | rcu_read_unlock(); |
73d54c9e LR |
10285 | |
10286 | return; | |
10287 | ||
10288 | nla_put_failure: | |
10289 | genlmsg_cancel(msg, hdr); | |
10290 | nlmsg_free(msg); | |
10291 | } | |
10292 | ||
6039f6d2 JM |
10293 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
10294 | struct net_device *netdev, | |
10295 | const u8 *buf, size_t len, | |
e6d6e342 | 10296 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
10297 | { |
10298 | struct sk_buff *msg; | |
10299 | void *hdr; | |
10300 | ||
e6d6e342 | 10301 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
10302 | if (!msg) |
10303 | return; | |
10304 | ||
10305 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10306 | if (!hdr) { | |
10307 | nlmsg_free(msg); | |
10308 | return; | |
10309 | } | |
10310 | ||
9360ffd1 DM |
10311 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10312 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10313 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10314 | goto nla_put_failure; | |
6039f6d2 | 10315 | |
3b7b72ee | 10316 | genlmsg_end(msg, hdr); |
6039f6d2 | 10317 | |
68eb5503 | 10318 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10319 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
10320 | return; |
10321 | ||
10322 | nla_put_failure: | |
10323 | genlmsg_cancel(msg, hdr); | |
10324 | nlmsg_free(msg); | |
10325 | } | |
10326 | ||
10327 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10328 | struct net_device *netdev, const u8 *buf, |
10329 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10330 | { |
10331 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10332 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
10333 | } |
10334 | ||
10335 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
10336 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10337 | size_t len, gfp_t gfp) |
6039f6d2 | 10338 | { |
e6d6e342 JB |
10339 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
10340 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
10341 | } |
10342 | ||
53b46b84 | 10343 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
10344 | struct net_device *netdev, const u8 *buf, |
10345 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10346 | { |
10347 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10348 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
10349 | } |
10350 | ||
53b46b84 JM |
10351 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
10352 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10353 | size_t len, gfp_t gfp) |
6039f6d2 JM |
10354 | { |
10355 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10356 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
10357 | } |
10358 | ||
6ff57cf8 JB |
10359 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
10360 | size_t len) | |
cf4e594e | 10361 | { |
947add36 JB |
10362 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10363 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 10364 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
10365 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
10366 | u32 cmd; | |
947add36 | 10367 | |
6ff57cf8 JB |
10368 | if (WARN_ON(len < 2)) |
10369 | return; | |
cf4e594e | 10370 | |
6ff57cf8 JB |
10371 | if (ieee80211_is_deauth(mgmt->frame_control)) |
10372 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
10373 | else | |
10374 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 10375 | |
6ff57cf8 JB |
10376 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
10377 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 10378 | } |
6ff57cf8 | 10379 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 10380 | |
1b06bb40 LR |
10381 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
10382 | struct net_device *netdev, int cmd, | |
e6d6e342 | 10383 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
10384 | { |
10385 | struct sk_buff *msg; | |
10386 | void *hdr; | |
10387 | ||
e6d6e342 | 10388 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
10389 | if (!msg) |
10390 | return; | |
10391 | ||
10392 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10393 | if (!hdr) { | |
10394 | nlmsg_free(msg); | |
10395 | return; | |
10396 | } | |
10397 | ||
9360ffd1 DM |
10398 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10399 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10400 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
10401 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10402 | goto nla_put_failure; | |
1965c853 | 10403 | |
3b7b72ee | 10404 | genlmsg_end(msg, hdr); |
1965c853 | 10405 | |
68eb5503 | 10406 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10407 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
10408 | return; |
10409 | ||
10410 | nla_put_failure: | |
10411 | genlmsg_cancel(msg, hdr); | |
10412 | nlmsg_free(msg); | |
10413 | } | |
10414 | ||
10415 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10416 | struct net_device *netdev, const u8 *addr, |
10417 | gfp_t gfp) | |
1965c853 JM |
10418 | { |
10419 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 10420 | addr, gfp); |
1965c853 JM |
10421 | } |
10422 | ||
10423 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10424 | struct net_device *netdev, const u8 *addr, |
10425 | gfp_t gfp) | |
1965c853 | 10426 | { |
e6d6e342 JB |
10427 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
10428 | addr, gfp); | |
1965c853 JM |
10429 | } |
10430 | ||
b23aa676 SO |
10431 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
10432 | struct net_device *netdev, const u8 *bssid, | |
10433 | const u8 *req_ie, size_t req_ie_len, | |
10434 | const u8 *resp_ie, size_t resp_ie_len, | |
10435 | u16 status, gfp_t gfp) | |
10436 | { | |
10437 | struct sk_buff *msg; | |
10438 | void *hdr; | |
10439 | ||
58050fce | 10440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10441 | if (!msg) |
10442 | return; | |
10443 | ||
10444 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
10445 | if (!hdr) { | |
10446 | nlmsg_free(msg); | |
10447 | return; | |
10448 | } | |
10449 | ||
9360ffd1 DM |
10450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10451 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10452 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
10453 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
10454 | (req_ie && | |
10455 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10456 | (resp_ie && | |
10457 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10458 | goto nla_put_failure; | |
b23aa676 | 10459 | |
3b7b72ee | 10460 | genlmsg_end(msg, hdr); |
b23aa676 | 10461 | |
68eb5503 | 10462 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10463 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10464 | return; |
10465 | ||
10466 | nla_put_failure: | |
10467 | genlmsg_cancel(msg, hdr); | |
10468 | nlmsg_free(msg); | |
10469 | ||
10470 | } | |
10471 | ||
10472 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
10473 | struct net_device *netdev, const u8 *bssid, | |
10474 | const u8 *req_ie, size_t req_ie_len, | |
10475 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
10476 | { | |
10477 | struct sk_buff *msg; | |
10478 | void *hdr; | |
10479 | ||
58050fce | 10480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10481 | if (!msg) |
10482 | return; | |
10483 | ||
10484 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
10485 | if (!hdr) { | |
10486 | nlmsg_free(msg); | |
10487 | return; | |
10488 | } | |
10489 | ||
9360ffd1 DM |
10490 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10491 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10492 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
10493 | (req_ie && | |
10494 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10495 | (resp_ie && | |
10496 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10497 | goto nla_put_failure; | |
b23aa676 | 10498 | |
3b7b72ee | 10499 | genlmsg_end(msg, hdr); |
b23aa676 | 10500 | |
68eb5503 | 10501 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10502 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10503 | return; |
10504 | ||
10505 | nla_put_failure: | |
10506 | genlmsg_cancel(msg, hdr); | |
10507 | nlmsg_free(msg); | |
10508 | ||
10509 | } | |
10510 | ||
10511 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
10512 | struct net_device *netdev, u16 reason, | |
667503dd | 10513 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
10514 | { |
10515 | struct sk_buff *msg; | |
10516 | void *hdr; | |
10517 | ||
58050fce | 10518 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
10519 | if (!msg) |
10520 | return; | |
10521 | ||
10522 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
10523 | if (!hdr) { | |
10524 | nlmsg_free(msg); | |
10525 | return; | |
10526 | } | |
10527 | ||
9360ffd1 DM |
10528 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10529 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10530 | (from_ap && reason && | |
10531 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10532 | (from_ap && | |
10533 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10534 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10535 | goto nla_put_failure; | |
b23aa676 | 10536 | |
3b7b72ee | 10537 | genlmsg_end(msg, hdr); |
b23aa676 | 10538 | |
68eb5503 | 10539 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10540 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
10541 | return; |
10542 | ||
10543 | nla_put_failure: | |
10544 | genlmsg_cancel(msg, hdr); | |
10545 | nlmsg_free(msg); | |
10546 | ||
10547 | } | |
10548 | ||
04a773ad JB |
10549 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10550 | struct net_device *netdev, const u8 *bssid, | |
10551 | gfp_t gfp) | |
10552 | { | |
10553 | struct sk_buff *msg; | |
10554 | void *hdr; | |
10555 | ||
fd2120ca | 10556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10557 | if (!msg) |
10558 | return; | |
10559 | ||
10560 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10561 | if (!hdr) { | |
10562 | nlmsg_free(msg); | |
10563 | return; | |
10564 | } | |
10565 | ||
9360ffd1 DM |
10566 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10567 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10568 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10569 | goto nla_put_failure; | |
04a773ad | 10570 | |
3b7b72ee | 10571 | genlmsg_end(msg, hdr); |
04a773ad | 10572 | |
68eb5503 | 10573 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10574 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
10575 | return; |
10576 | ||
10577 | nla_put_failure: | |
10578 | genlmsg_cancel(msg, hdr); | |
10579 | nlmsg_free(msg); | |
10580 | } | |
10581 | ||
947add36 JB |
10582 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10583 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10584 | { |
947add36 | 10585 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 10586 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
10587 | struct sk_buff *msg; |
10588 | void *hdr; | |
10589 | ||
947add36 JB |
10590 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10591 | return; | |
10592 | ||
10593 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10594 | ||
c93b5e71 JC |
10595 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10596 | if (!msg) | |
10597 | return; | |
10598 | ||
10599 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
10600 | if (!hdr) { | |
10601 | nlmsg_free(msg); | |
10602 | return; | |
10603 | } | |
10604 | ||
9360ffd1 | 10605 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
10606 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10607 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
10608 | (ie_len && ie && |
10609 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
10610 | goto nla_put_failure; | |
c93b5e71 | 10611 | |
3b7b72ee | 10612 | genlmsg_end(msg, hdr); |
c93b5e71 | 10613 | |
68eb5503 | 10614 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10615 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
10616 | return; |
10617 | ||
10618 | nla_put_failure: | |
10619 | genlmsg_cancel(msg, hdr); | |
10620 | nlmsg_free(msg); | |
10621 | } | |
947add36 | 10622 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 10623 | |
a3b8b056 JM |
10624 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
10625 | struct net_device *netdev, const u8 *addr, | |
10626 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 10627 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
10628 | { |
10629 | struct sk_buff *msg; | |
10630 | void *hdr; | |
10631 | ||
e6d6e342 | 10632 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
10633 | if (!msg) |
10634 | return; | |
10635 | ||
10636 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
10637 | if (!hdr) { | |
10638 | nlmsg_free(msg); | |
10639 | return; | |
10640 | } | |
10641 | ||
9360ffd1 DM |
10642 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10643 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10644 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
10645 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10646 | (key_id != -1 && | |
10647 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10648 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10649 | goto nla_put_failure; | |
a3b8b056 | 10650 | |
3b7b72ee | 10651 | genlmsg_end(msg, hdr); |
a3b8b056 | 10652 | |
68eb5503 | 10653 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10654 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
10655 | return; |
10656 | ||
10657 | nla_put_failure: | |
10658 | genlmsg_cancel(msg, hdr); | |
10659 | nlmsg_free(msg); | |
10660 | } | |
10661 | ||
6bad8766 LR |
10662 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10663 | struct ieee80211_channel *channel_before, | |
10664 | struct ieee80211_channel *channel_after) | |
10665 | { | |
10666 | struct sk_buff *msg; | |
10667 | void *hdr; | |
10668 | struct nlattr *nl_freq; | |
10669 | ||
fd2120ca | 10670 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10671 | if (!msg) |
10672 | return; | |
10673 | ||
10674 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10675 | if (!hdr) { | |
10676 | nlmsg_free(msg); | |
10677 | return; | |
10678 | } | |
10679 | ||
10680 | /* | |
10681 | * Since we are applying the beacon hint to a wiphy we know its | |
10682 | * wiphy_idx is valid | |
10683 | */ | |
9360ffd1 DM |
10684 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10685 | goto nla_put_failure; | |
6bad8766 LR |
10686 | |
10687 | /* Before */ | |
10688 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10689 | if (!nl_freq) | |
10690 | goto nla_put_failure; | |
cdc89b97 | 10691 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10692 | goto nla_put_failure; |
10693 | nla_nest_end(msg, nl_freq); | |
10694 | ||
10695 | /* After */ | |
10696 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10697 | if (!nl_freq) | |
10698 | goto nla_put_failure; | |
cdc89b97 | 10699 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10700 | goto nla_put_failure; |
10701 | nla_nest_end(msg, nl_freq); | |
10702 | ||
3b7b72ee | 10703 | genlmsg_end(msg, hdr); |
6bad8766 | 10704 | |
463d0183 | 10705 | rcu_read_lock(); |
68eb5503 | 10706 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10707 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 10708 | rcu_read_unlock(); |
6bad8766 LR |
10709 | |
10710 | return; | |
10711 | ||
10712 | nla_put_failure: | |
10713 | genlmsg_cancel(msg, hdr); | |
10714 | nlmsg_free(msg); | |
10715 | } | |
10716 | ||
9588bbd5 JM |
10717 | static void nl80211_send_remain_on_chan_event( |
10718 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10719 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10720 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10721 | unsigned int duration, gfp_t gfp) |
10722 | { | |
10723 | struct sk_buff *msg; | |
10724 | void *hdr; | |
10725 | ||
10726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10727 | if (!msg) | |
10728 | return; | |
10729 | ||
10730 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10731 | if (!hdr) { | |
10732 | nlmsg_free(msg); | |
10733 | return; | |
10734 | } | |
10735 | ||
9360ffd1 | 10736 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10737 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10738 | wdev->netdev->ifindex)) || | |
00f53350 | 10739 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10740 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10741 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10742 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10743 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10744 | goto nla_put_failure; | |
9588bbd5 | 10745 | |
9360ffd1 DM |
10746 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10747 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10748 | goto nla_put_failure; | |
9588bbd5 | 10749 | |
3b7b72ee | 10750 | genlmsg_end(msg, hdr); |
9588bbd5 | 10751 | |
68eb5503 | 10752 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10753 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
10754 | return; |
10755 | ||
10756 | nla_put_failure: | |
10757 | genlmsg_cancel(msg, hdr); | |
10758 | nlmsg_free(msg); | |
10759 | } | |
10760 | ||
947add36 JB |
10761 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10762 | struct ieee80211_channel *chan, | |
10763 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10764 | { |
947add36 | 10765 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 10766 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
10767 | |
10768 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10769 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10770 | rdev, wdev, cookie, chan, |
42d97a59 | 10771 | duration, gfp); |
9588bbd5 | 10772 | } |
947add36 | 10773 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10774 | |
947add36 JB |
10775 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10776 | struct ieee80211_channel *chan, | |
10777 | gfp_t gfp) | |
9588bbd5 | 10778 | { |
947add36 | 10779 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 10780 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
10781 | |
10782 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10783 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10784 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10785 | } |
947add36 | 10786 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10787 | |
947add36 JB |
10788 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10789 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10790 | { |
947add36 | 10791 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10792 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
10793 | struct sk_buff *msg; |
10794 | ||
947add36 JB |
10795 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10796 | ||
58050fce | 10797 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10798 | if (!msg) |
10799 | return; | |
10800 | ||
66266b3a JL |
10801 | if (nl80211_send_station(msg, 0, 0, 0, |
10802 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10803 | nlmsg_free(msg); |
10804 | return; | |
10805 | } | |
10806 | ||
68eb5503 | 10807 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10808 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 10809 | } |
947add36 | 10810 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10811 | |
947add36 | 10812 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10813 | { |
947add36 | 10814 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10815 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b JM |
10816 | struct sk_buff *msg; |
10817 | void *hdr; | |
10818 | ||
947add36 JB |
10819 | trace_cfg80211_del_sta(dev, mac_addr); |
10820 | ||
58050fce | 10821 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10822 | if (!msg) |
10823 | return; | |
10824 | ||
10825 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10826 | if (!hdr) { | |
10827 | nlmsg_free(msg); | |
10828 | return; | |
10829 | } | |
10830 | ||
9360ffd1 DM |
10831 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10832 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10833 | goto nla_put_failure; | |
ec15e68b | 10834 | |
3b7b72ee | 10835 | genlmsg_end(msg, hdr); |
ec15e68b | 10836 | |
68eb5503 | 10837 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10838 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
10839 | return; |
10840 | ||
10841 | nla_put_failure: | |
10842 | genlmsg_cancel(msg, hdr); | |
10843 | nlmsg_free(msg); | |
10844 | } | |
947add36 | 10845 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10846 | |
947add36 JB |
10847 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10848 | enum nl80211_connect_failed_reason reason, | |
10849 | gfp_t gfp) | |
ed44a951 | 10850 | { |
947add36 | 10851 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 10852 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
10853 | struct sk_buff *msg; |
10854 | void *hdr; | |
10855 | ||
10856 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10857 | if (!msg) | |
10858 | return; | |
10859 | ||
10860 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10861 | if (!hdr) { | |
10862 | nlmsg_free(msg); | |
10863 | return; | |
10864 | } | |
10865 | ||
10866 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10867 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10868 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10869 | goto nla_put_failure; | |
10870 | ||
10871 | genlmsg_end(msg, hdr); | |
10872 | ||
68eb5503 | 10873 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10874 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
10875 | return; |
10876 | ||
10877 | nla_put_failure: | |
10878 | genlmsg_cancel(msg, hdr); | |
10879 | nlmsg_free(msg); | |
10880 | } | |
947add36 | 10881 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10882 | |
b92ab5d8 JB |
10883 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10884 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10885 | { |
10886 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 10887 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
10888 | struct sk_buff *msg; |
10889 | void *hdr; | |
15e47304 | 10890 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10891 | |
15e47304 | 10892 | if (!nlportid) |
28946da7 JB |
10893 | return false; |
10894 | ||
10895 | msg = nlmsg_new(100, gfp); | |
10896 | if (!msg) | |
10897 | return true; | |
10898 | ||
b92ab5d8 | 10899 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10900 | if (!hdr) { |
10901 | nlmsg_free(msg); | |
10902 | return true; | |
10903 | } | |
10904 | ||
9360ffd1 DM |
10905 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10906 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10907 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10908 | goto nla_put_failure; | |
28946da7 | 10909 | |
9c90a9f6 | 10910 | genlmsg_end(msg, hdr); |
15e47304 | 10911 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10912 | return true; |
10913 | ||
10914 | nla_put_failure: | |
10915 | genlmsg_cancel(msg, hdr); | |
10916 | nlmsg_free(msg); | |
10917 | return true; | |
10918 | } | |
10919 | ||
947add36 JB |
10920 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10921 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10922 | { |
947add36 JB |
10923 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10924 | bool ret; | |
10925 | ||
10926 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10927 | ||
10928 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10929 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10930 | trace_cfg80211_return_bool(false); | |
10931 | return false; | |
10932 | } | |
10933 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10934 | addr, gfp); | |
10935 | trace_cfg80211_return_bool(ret); | |
10936 | return ret; | |
b92ab5d8 | 10937 | } |
947add36 | 10938 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10939 | |
947add36 JB |
10940 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10941 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10942 | { |
947add36 JB |
10943 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10944 | bool ret; | |
10945 | ||
10946 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10947 | ||
10948 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10949 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10950 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10951 | trace_cfg80211_return_bool(false); | |
10952 | return false; | |
10953 | } | |
10954 | ret = __nl80211_unexpected_frame(dev, | |
10955 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10956 | addr, gfp); | |
10957 | trace_cfg80211_return_bool(ret); | |
10958 | return ret; | |
b92ab5d8 | 10959 | } |
947add36 | 10960 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10961 | |
2e161f78 | 10962 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10963 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 10964 | int freq, int sig_dbm, |
19504cf5 | 10965 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 10966 | { |
71bbc994 | 10967 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10968 | struct sk_buff *msg; |
10969 | void *hdr; | |
026331c4 JM |
10970 | |
10971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10972 | if (!msg) | |
10973 | return -ENOMEM; | |
10974 | ||
2e161f78 | 10975 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10976 | if (!hdr) { |
10977 | nlmsg_free(msg); | |
10978 | return -ENOMEM; | |
10979 | } | |
10980 | ||
9360ffd1 | 10981 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10982 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10983 | netdev->ifindex)) || | |
a838490b | 10984 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10985 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10986 | (sig_dbm && | |
10987 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
10988 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10989 | (flags && | |
10990 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 10991 | goto nla_put_failure; |
026331c4 | 10992 | |
3b7b72ee | 10993 | genlmsg_end(msg, hdr); |
026331c4 | 10994 | |
15e47304 | 10995 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10996 | |
10997 | nla_put_failure: | |
10998 | genlmsg_cancel(msg, hdr); | |
10999 | nlmsg_free(msg); | |
11000 | return -ENOBUFS; | |
11001 | } | |
11002 | ||
947add36 JB |
11003 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
11004 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 11005 | { |
947add36 | 11006 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11007 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 11008 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11009 | struct sk_buff *msg; |
11010 | void *hdr; | |
11011 | ||
947add36 JB |
11012 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
11013 | ||
026331c4 JM |
11014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11015 | if (!msg) | |
11016 | return; | |
11017 | ||
2e161f78 | 11018 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
11019 | if (!hdr) { |
11020 | nlmsg_free(msg); | |
11021 | return; | |
11022 | } | |
11023 | ||
9360ffd1 | 11024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11025 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11026 | netdev->ifindex)) || | |
a838490b | 11027 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
11028 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
11029 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11030 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11031 | goto nla_put_failure; | |
026331c4 | 11032 | |
3b7b72ee | 11033 | genlmsg_end(msg, hdr); |
026331c4 | 11034 | |
68eb5503 | 11035 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11036 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
11037 | return; |
11038 | ||
11039 | nla_put_failure: | |
11040 | genlmsg_cancel(msg, hdr); | |
11041 | nlmsg_free(msg); | |
11042 | } | |
947add36 | 11043 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 11044 | |
947add36 JB |
11045 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
11046 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
11047 | gfp_t gfp) | |
d6dc1a38 | 11048 | { |
947add36 JB |
11049 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11050 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11051 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
d6dc1a38 JO |
11052 | struct sk_buff *msg; |
11053 | struct nlattr *pinfoattr; | |
11054 | void *hdr; | |
11055 | ||
947add36 JB |
11056 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
11057 | ||
58050fce | 11058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
11059 | if (!msg) |
11060 | return; | |
11061 | ||
11062 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11063 | if (!hdr) { | |
11064 | nlmsg_free(msg); | |
11065 | return; | |
11066 | } | |
11067 | ||
9360ffd1 | 11068 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11069 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 11070 | goto nla_put_failure; |
d6dc1a38 JO |
11071 | |
11072 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11073 | if (!pinfoattr) | |
11074 | goto nla_put_failure; | |
11075 | ||
9360ffd1 DM |
11076 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
11077 | rssi_event)) | |
11078 | goto nla_put_failure; | |
d6dc1a38 JO |
11079 | |
11080 | nla_nest_end(msg, pinfoattr); | |
11081 | ||
3b7b72ee | 11082 | genlmsg_end(msg, hdr); |
d6dc1a38 | 11083 | |
68eb5503 | 11084 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11085 | NL80211_MCGRP_MLME, gfp); |
d6dc1a38 JO |
11086 | return; |
11087 | ||
11088 | nla_put_failure: | |
11089 | genlmsg_cancel(msg, hdr); | |
11090 | nlmsg_free(msg); | |
11091 | } | |
947add36 | 11092 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 11093 | |
947add36 JB |
11094 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
11095 | struct net_device *netdev, const u8 *bssid, | |
11096 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
11097 | { |
11098 | struct sk_buff *msg; | |
11099 | struct nlattr *rekey_attr; | |
11100 | void *hdr; | |
11101 | ||
58050fce | 11102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
11103 | if (!msg) |
11104 | return; | |
11105 | ||
11106 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
11107 | if (!hdr) { | |
11108 | nlmsg_free(msg); | |
11109 | return; | |
11110 | } | |
11111 | ||
9360ffd1 DM |
11112 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11113 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11114 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11115 | goto nla_put_failure; | |
e5497d76 JB |
11116 | |
11117 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
11118 | if (!rekey_attr) | |
11119 | goto nla_put_failure; | |
11120 | ||
9360ffd1 DM |
11121 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
11122 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
11123 | goto nla_put_failure; | |
e5497d76 JB |
11124 | |
11125 | nla_nest_end(msg, rekey_attr); | |
11126 | ||
3b7b72ee | 11127 | genlmsg_end(msg, hdr); |
e5497d76 | 11128 | |
68eb5503 | 11129 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11130 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
11131 | return; |
11132 | ||
11133 | nla_put_failure: | |
11134 | genlmsg_cancel(msg, hdr); | |
11135 | nlmsg_free(msg); | |
11136 | } | |
11137 | ||
947add36 JB |
11138 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
11139 | const u8 *replay_ctr, gfp_t gfp) | |
11140 | { | |
11141 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11142 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11143 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11144 | |
11145 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
11146 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
11147 | } | |
11148 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
11149 | ||
11150 | static void | |
11151 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
11152 | struct net_device *netdev, int index, | |
11153 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
11154 | { |
11155 | struct sk_buff *msg; | |
11156 | struct nlattr *attr; | |
11157 | void *hdr; | |
11158 | ||
58050fce | 11159 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
11160 | if (!msg) |
11161 | return; | |
11162 | ||
11163 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
11164 | if (!hdr) { | |
11165 | nlmsg_free(msg); | |
11166 | return; | |
11167 | } | |
11168 | ||
9360ffd1 DM |
11169 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11170 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11171 | goto nla_put_failure; | |
c9df56b4 JM |
11172 | |
11173 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
11174 | if (!attr) | |
11175 | goto nla_put_failure; | |
11176 | ||
9360ffd1 DM |
11177 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
11178 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
11179 | (preauth && | |
11180 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
11181 | goto nla_put_failure; | |
c9df56b4 JM |
11182 | |
11183 | nla_nest_end(msg, attr); | |
11184 | ||
3b7b72ee | 11185 | genlmsg_end(msg, hdr); |
c9df56b4 | 11186 | |
68eb5503 | 11187 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11188 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
11189 | return; |
11190 | ||
11191 | nla_put_failure: | |
11192 | genlmsg_cancel(msg, hdr); | |
11193 | nlmsg_free(msg); | |
11194 | } | |
11195 | ||
947add36 JB |
11196 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
11197 | const u8 *bssid, bool preauth, gfp_t gfp) | |
11198 | { | |
11199 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11200 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11201 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11202 | |
11203 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
11204 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
11205 | } | |
11206 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
11207 | ||
11208 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
11209 | struct net_device *netdev, | |
11210 | struct cfg80211_chan_def *chandef, | |
11211 | gfp_t gfp) | |
5314526b TP |
11212 | { |
11213 | struct sk_buff *msg; | |
11214 | void *hdr; | |
11215 | ||
58050fce | 11216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
11217 | if (!msg) |
11218 | return; | |
11219 | ||
11220 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
11221 | if (!hdr) { | |
11222 | nlmsg_free(msg); | |
11223 | return; | |
11224 | } | |
11225 | ||
683b6d3b JB |
11226 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
11227 | goto nla_put_failure; | |
11228 | ||
11229 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 11230 | goto nla_put_failure; |
5314526b TP |
11231 | |
11232 | genlmsg_end(msg, hdr); | |
11233 | ||
68eb5503 | 11234 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11235 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
11236 | return; |
11237 | ||
11238 | nla_put_failure: | |
11239 | genlmsg_cancel(msg, hdr); | |
11240 | nlmsg_free(msg); | |
11241 | } | |
11242 | ||
947add36 JB |
11243 | void cfg80211_ch_switch_notify(struct net_device *dev, |
11244 | struct cfg80211_chan_def *chandef) | |
84f10708 | 11245 | { |
947add36 JB |
11246 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11247 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11248 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 11249 | |
e487eaeb | 11250 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 11251 | |
e487eaeb | 11252 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 JB |
11253 | |
11254 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
ee4bc9e7 | 11255 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
b8456a14 CYY |
11256 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
11257 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | |
e487eaeb | 11258 | return; |
947add36 | 11259 | |
9e0e2961 | 11260 | wdev->chandef = *chandef; |
96f55f12 | 11261 | wdev->preset_chandef = *chandef; |
947add36 | 11262 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
947add36 JB |
11263 | } |
11264 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
11265 | ||
11266 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
11267 | const u8 *peer, u32 num_packets, | |
11268 | u32 rate, u32 intvl, gfp_t gfp) | |
11269 | { | |
11270 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11271 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11272 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
84f10708 TP |
11273 | struct sk_buff *msg; |
11274 | struct nlattr *pinfoattr; | |
11275 | void *hdr; | |
11276 | ||
11277 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11278 | if (!msg) | |
11279 | return; | |
11280 | ||
11281 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11282 | if (!hdr) { | |
11283 | nlmsg_free(msg); | |
11284 | return; | |
11285 | } | |
11286 | ||
11287 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 11288 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
11289 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11290 | goto nla_put_failure; | |
11291 | ||
11292 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11293 | if (!pinfoattr) | |
11294 | goto nla_put_failure; | |
11295 | ||
11296 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
11297 | goto nla_put_failure; | |
11298 | ||
11299 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
11300 | goto nla_put_failure; | |
11301 | ||
11302 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
11303 | goto nla_put_failure; | |
11304 | ||
11305 | nla_nest_end(msg, pinfoattr); | |
11306 | ||
11307 | genlmsg_end(msg, hdr); | |
11308 | ||
68eb5503 | 11309 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11310 | NL80211_MCGRP_MLME, gfp); |
84f10708 TP |
11311 | return; |
11312 | ||
11313 | nla_put_failure: | |
11314 | genlmsg_cancel(msg, hdr); | |
11315 | nlmsg_free(msg); | |
11316 | } | |
947add36 | 11317 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 11318 | |
04f39047 SW |
11319 | void |
11320 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 11321 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
11322 | enum nl80211_radar_event event, |
11323 | struct net_device *netdev, gfp_t gfp) | |
11324 | { | |
11325 | struct sk_buff *msg; | |
11326 | void *hdr; | |
11327 | ||
11328 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11329 | if (!msg) | |
11330 | return; | |
11331 | ||
11332 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
11333 | if (!hdr) { | |
11334 | nlmsg_free(msg); | |
11335 | return; | |
11336 | } | |
11337 | ||
11338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11339 | goto nla_put_failure; | |
11340 | ||
11341 | /* NOP and radar events don't need a netdev parameter */ | |
11342 | if (netdev) { | |
11343 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
11344 | ||
11345 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11346 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11347 | goto nla_put_failure; | |
11348 | } | |
11349 | ||
11350 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
11351 | goto nla_put_failure; | |
11352 | ||
11353 | if (nl80211_send_chandef(msg, chandef)) | |
11354 | goto nla_put_failure; | |
11355 | ||
9c90a9f6 | 11356 | genlmsg_end(msg, hdr); |
04f39047 | 11357 | |
68eb5503 | 11358 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11359 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
11360 | return; |
11361 | ||
11362 | nla_put_failure: | |
11363 | genlmsg_cancel(msg, hdr); | |
11364 | nlmsg_free(msg); | |
11365 | } | |
11366 | ||
947add36 JB |
11367 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
11368 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 11369 | { |
947add36 JB |
11370 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11371 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11372 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
c063dbf5 JB |
11373 | struct sk_buff *msg; |
11374 | struct nlattr *pinfoattr; | |
11375 | void *hdr; | |
11376 | ||
947add36 JB |
11377 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
11378 | ||
58050fce | 11379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
11380 | if (!msg) |
11381 | return; | |
11382 | ||
11383 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11384 | if (!hdr) { | |
11385 | nlmsg_free(msg); | |
11386 | return; | |
11387 | } | |
11388 | ||
9360ffd1 | 11389 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11390 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
11391 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11392 | goto nla_put_failure; | |
c063dbf5 JB |
11393 | |
11394 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11395 | if (!pinfoattr) | |
11396 | goto nla_put_failure; | |
11397 | ||
9360ffd1 DM |
11398 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
11399 | goto nla_put_failure; | |
c063dbf5 JB |
11400 | |
11401 | nla_nest_end(msg, pinfoattr); | |
11402 | ||
3b7b72ee | 11403 | genlmsg_end(msg, hdr); |
c063dbf5 | 11404 | |
68eb5503 | 11405 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11406 | NL80211_MCGRP_MLME, gfp); |
c063dbf5 JB |
11407 | return; |
11408 | ||
11409 | nla_put_failure: | |
11410 | genlmsg_cancel(msg, hdr); | |
11411 | nlmsg_free(msg); | |
11412 | } | |
947add36 | 11413 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 11414 | |
7f6cf311 JB |
11415 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
11416 | u64 cookie, bool acked, gfp_t gfp) | |
11417 | { | |
11418 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11419 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
11420 | struct sk_buff *msg; |
11421 | void *hdr; | |
7f6cf311 | 11422 | |
4ee3e063 BL |
11423 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
11424 | ||
58050fce | 11425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 11426 | |
7f6cf311 JB |
11427 | if (!msg) |
11428 | return; | |
11429 | ||
11430 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
11431 | if (!hdr) { | |
11432 | nlmsg_free(msg); | |
11433 | return; | |
11434 | } | |
11435 | ||
9360ffd1 DM |
11436 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11437 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11438 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
11439 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11440 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11441 | goto nla_put_failure; | |
7f6cf311 | 11442 | |
9c90a9f6 | 11443 | genlmsg_end(msg, hdr); |
7f6cf311 | 11444 | |
68eb5503 | 11445 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11446 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
11447 | return; |
11448 | ||
11449 | nla_put_failure: | |
11450 | genlmsg_cancel(msg, hdr); | |
11451 | nlmsg_free(msg); | |
11452 | } | |
11453 | EXPORT_SYMBOL(cfg80211_probe_status); | |
11454 | ||
5e760230 JB |
11455 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
11456 | const u8 *frame, size_t len, | |
37c73b5f | 11457 | int freq, int sig_dbm) |
5e760230 | 11458 | { |
f26cbf40 | 11459 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
11460 | struct sk_buff *msg; |
11461 | void *hdr; | |
37c73b5f | 11462 | struct cfg80211_beacon_registration *reg; |
5e760230 | 11463 | |
4ee3e063 BL |
11464 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
11465 | ||
37c73b5f BG |
11466 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11467 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11468 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
11469 | if (!msg) { | |
11470 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11471 | return; | |
11472 | } | |
5e760230 | 11473 | |
37c73b5f BG |
11474 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
11475 | if (!hdr) | |
11476 | goto nla_put_failure; | |
5e760230 | 11477 | |
37c73b5f BG |
11478 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11479 | (freq && | |
11480 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
11481 | (sig_dbm && | |
11482 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
11483 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
11484 | goto nla_put_failure; | |
5e760230 | 11485 | |
37c73b5f | 11486 | genlmsg_end(msg, hdr); |
5e760230 | 11487 | |
37c73b5f BG |
11488 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
11489 | } | |
11490 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
11491 | return; |
11492 | ||
11493 | nla_put_failure: | |
37c73b5f BG |
11494 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
11495 | if (hdr) | |
11496 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
11497 | nlmsg_free(msg); |
11498 | } | |
11499 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
11500 | ||
cd8f7cb4 JB |
11501 | #ifdef CONFIG_PM |
11502 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
11503 | struct cfg80211_wowlan_wakeup *wakeup, | |
11504 | gfp_t gfp) | |
11505 | { | |
f26cbf40 | 11506 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
11507 | struct sk_buff *msg; |
11508 | void *hdr; | |
9c90a9f6 | 11509 | int size = 200; |
cd8f7cb4 JB |
11510 | |
11511 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
11512 | ||
11513 | if (wakeup) | |
11514 | size += wakeup->packet_present_len; | |
11515 | ||
11516 | msg = nlmsg_new(size, gfp); | |
11517 | if (!msg) | |
11518 | return; | |
11519 | ||
11520 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
11521 | if (!hdr) | |
11522 | goto free_msg; | |
11523 | ||
11524 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11525 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11526 | goto free_msg; | |
11527 | ||
11528 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11529 | wdev->netdev->ifindex)) | |
11530 | goto free_msg; | |
11531 | ||
11532 | if (wakeup) { | |
11533 | struct nlattr *reasons; | |
11534 | ||
11535 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
11536 | if (!reasons) |
11537 | goto free_msg; | |
cd8f7cb4 JB |
11538 | |
11539 | if (wakeup->disconnect && | |
11540 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11541 | goto free_msg; | |
11542 | if (wakeup->magic_pkt && | |
11543 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11544 | goto free_msg; | |
11545 | if (wakeup->gtk_rekey_failure && | |
11546 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11547 | goto free_msg; | |
11548 | if (wakeup->eap_identity_req && | |
11549 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11550 | goto free_msg; | |
11551 | if (wakeup->four_way_handshake && | |
11552 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11553 | goto free_msg; | |
11554 | if (wakeup->rfkill_release && | |
11555 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11556 | goto free_msg; | |
11557 | ||
11558 | if (wakeup->pattern_idx >= 0 && | |
11559 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11560 | wakeup->pattern_idx)) | |
11561 | goto free_msg; | |
11562 | ||
ae917c9f JB |
11563 | if (wakeup->tcp_match && |
11564 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
11565 | goto free_msg; | |
2a0e047e | 11566 | |
ae917c9f JB |
11567 | if (wakeup->tcp_connlost && |
11568 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
11569 | goto free_msg; | |
2a0e047e | 11570 | |
ae917c9f JB |
11571 | if (wakeup->tcp_nomoretokens && |
11572 | nla_put_flag(msg, | |
11573 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
11574 | goto free_msg; | |
2a0e047e | 11575 | |
cd8f7cb4 JB |
11576 | if (wakeup->packet) { |
11577 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11578 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11579 | ||
11580 | if (!wakeup->packet_80211) { | |
11581 | pkt_attr = | |
11582 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11583 | len_attr = | |
11584 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11585 | } | |
11586 | ||
11587 | if (wakeup->packet_len && | |
11588 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11589 | goto free_msg; | |
11590 | ||
11591 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11592 | wakeup->packet)) | |
11593 | goto free_msg; | |
11594 | } | |
11595 | ||
11596 | nla_nest_end(msg, reasons); | |
11597 | } | |
11598 | ||
9c90a9f6 | 11599 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 11600 | |
68eb5503 | 11601 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11602 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
11603 | return; |
11604 | ||
11605 | free_msg: | |
11606 | nlmsg_free(msg); | |
11607 | } | |
11608 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
11609 | #endif | |
11610 | ||
3475b094 JM |
11611 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
11612 | enum nl80211_tdls_operation oper, | |
11613 | u16 reason_code, gfp_t gfp) | |
11614 | { | |
11615 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11616 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
11617 | struct sk_buff *msg; |
11618 | void *hdr; | |
3475b094 JM |
11619 | |
11620 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
11621 | reason_code); | |
11622 | ||
11623 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11624 | if (!msg) | |
11625 | return; | |
11626 | ||
11627 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
11628 | if (!hdr) { | |
11629 | nlmsg_free(msg); | |
11630 | return; | |
11631 | } | |
11632 | ||
11633 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11634 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11635 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
11636 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
11637 | (reason_code > 0 && | |
11638 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
11639 | goto nla_put_failure; | |
11640 | ||
9c90a9f6 | 11641 | genlmsg_end(msg, hdr); |
3475b094 | 11642 | |
68eb5503 | 11643 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11644 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
11645 | return; |
11646 | ||
11647 | nla_put_failure: | |
11648 | genlmsg_cancel(msg, hdr); | |
11649 | nlmsg_free(msg); | |
11650 | } | |
11651 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
11652 | ||
026331c4 JM |
11653 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11654 | unsigned long state, | |
11655 | void *_notify) | |
11656 | { | |
11657 | struct netlink_notify *notify = _notify; | |
11658 | struct cfg80211_registered_device *rdev; | |
11659 | struct wireless_dev *wdev; | |
37c73b5f | 11660 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11661 | |
11662 | if (state != NETLINK_URELEASE) | |
11663 | return NOTIFY_DONE; | |
11664 | ||
11665 | rcu_read_lock(); | |
11666 | ||
5e760230 | 11667 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a JB |
11668 | bool schedule_destroy_work = false; |
11669 | ||
11670 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 11671 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 11672 | |
78f22b6a JB |
11673 | if (wdev->owner_nlportid == notify->portid) |
11674 | schedule_destroy_work = true; | |
11675 | } | |
11676 | ||
37c73b5f BG |
11677 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11678 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11679 | list) { | |
11680 | if (reg->nlportid == notify->portid) { | |
11681 | list_del(®->list); | |
11682 | kfree(reg); | |
11683 | break; | |
11684 | } | |
11685 | } | |
11686 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
11687 | |
11688 | if (schedule_destroy_work) { | |
11689 | struct cfg80211_iface_destroy *destroy; | |
11690 | ||
11691 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
11692 | if (destroy) { | |
11693 | destroy->nlportid = notify->portid; | |
11694 | spin_lock(&rdev->destroy_list_lock); | |
11695 | list_add(&destroy->list, &rdev->destroy_list); | |
11696 | spin_unlock(&rdev->destroy_list_lock); | |
11697 | schedule_work(&rdev->destroy_work); | |
11698 | } | |
11699 | } | |
5e760230 | 11700 | } |
026331c4 JM |
11701 | |
11702 | rcu_read_unlock(); | |
11703 | ||
6784c7db | 11704 | return NOTIFY_OK; |
026331c4 JM |
11705 | } |
11706 | ||
11707 | static struct notifier_block nl80211_netlink_notifier = { | |
11708 | .notifier_call = nl80211_netlink_notify, | |
11709 | }; | |
11710 | ||
355199e0 JM |
11711 | void cfg80211_ft_event(struct net_device *netdev, |
11712 | struct cfg80211_ft_event_params *ft_event) | |
11713 | { | |
11714 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 11715 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
11716 | struct sk_buff *msg; |
11717 | void *hdr; | |
355199e0 JM |
11718 | |
11719 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11720 | ||
11721 | if (!ft_event->target_ap) | |
11722 | return; | |
11723 | ||
11724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11725 | if (!msg) | |
11726 | return; | |
11727 | ||
11728 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
11729 | if (!hdr) |
11730 | goto out; | |
355199e0 | 11731 | |
ae917c9f JB |
11732 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11733 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11734 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
11735 | goto out; | |
355199e0 | 11736 | |
ae917c9f JB |
11737 | if (ft_event->ies && |
11738 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
11739 | goto out; | |
11740 | if (ft_event->ric_ies && | |
11741 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11742 | ft_event->ric_ies)) | |
11743 | goto out; | |
355199e0 | 11744 | |
9c90a9f6 | 11745 | genlmsg_end(msg, hdr); |
355199e0 | 11746 | |
68eb5503 | 11747 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11748 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
11749 | return; |
11750 | out: | |
11751 | nlmsg_free(msg); | |
355199e0 JM |
11752 | } |
11753 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11754 | ||
5de17984 AS |
11755 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11756 | { | |
11757 | struct cfg80211_registered_device *rdev; | |
11758 | struct sk_buff *msg; | |
11759 | void *hdr; | |
11760 | u32 nlportid; | |
11761 | ||
f26cbf40 | 11762 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
11763 | if (!rdev->crit_proto_nlportid) |
11764 | return; | |
11765 | ||
11766 | nlportid = rdev->crit_proto_nlportid; | |
11767 | rdev->crit_proto_nlportid = 0; | |
11768 | ||
11769 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11770 | if (!msg) | |
11771 | return; | |
11772 | ||
11773 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11774 | if (!hdr) | |
11775 | goto nla_put_failure; | |
11776 | ||
11777 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11778 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11779 | goto nla_put_failure; | |
11780 | ||
11781 | genlmsg_end(msg, hdr); | |
11782 | ||
11783 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11784 | return; | |
11785 | ||
11786 | nla_put_failure: | |
11787 | if (hdr) | |
11788 | genlmsg_cancel(msg, hdr); | |
11789 | nlmsg_free(msg); | |
11790 | ||
11791 | } | |
11792 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11793 | ||
348baf0e JB |
11794 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
11795 | { | |
11796 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11797 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
11798 | struct sk_buff *msg; |
11799 | void *hdr; | |
11800 | ||
11801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11802 | if (!msg) | |
11803 | return; | |
11804 | ||
11805 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
11806 | if (!hdr) | |
11807 | goto out; | |
11808 | ||
11809 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11810 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
11811 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11812 | goto out; | |
11813 | ||
11814 | genlmsg_end(msg, hdr); | |
11815 | ||
11816 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
11817 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
11818 | return; | |
11819 | out: | |
11820 | nlmsg_free(msg); | |
11821 | } | |
11822 | ||
55682965 JB |
11823 | /* initialisation/exit functions */ |
11824 | ||
11825 | int nl80211_init(void) | |
11826 | { | |
0d63cbb5 | 11827 | int err; |
55682965 | 11828 | |
2a94fe48 JB |
11829 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
11830 | nl80211_mcgrps); | |
55682965 JB |
11831 | if (err) |
11832 | return err; | |
11833 | ||
026331c4 JM |
11834 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11835 | if (err) | |
11836 | goto err_out; | |
11837 | ||
55682965 JB |
11838 | return 0; |
11839 | err_out: | |
11840 | genl_unregister_family(&nl80211_fam); | |
11841 | return err; | |
11842 | } | |
11843 | ||
11844 | void nl80211_exit(void) | |
11845 | { | |
026331c4 | 11846 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11847 | genl_unregister_family(&nl80211_fam); |
11848 | } |