]>
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) | |
171 | tmp = wiphy_to_dev( | |
172 | netdev->ieee80211_ptr->wiphy); | |
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 }, | |
55682965 JB |
387 | }; |
388 | ||
e31b8213 | 389 | /* policy for the key attributes */ |
b54452b0 | 390 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 391 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
392 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
393 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 394 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
395 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
396 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 397 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
398 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
399 | }; | |
400 | ||
401 | /* policy for the key default flags */ | |
402 | static const struct nla_policy | |
403 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
404 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
405 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
406 | }; |
407 | ||
ff1b6e69 JB |
408 | /* policy for WoWLAN attributes */ |
409 | static const struct nla_policy | |
410 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
411 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
412 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
413 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
414 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
415 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
416 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
417 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
418 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
419 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
420 | }; | |
421 | ||
422 | static const struct nla_policy | |
423 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
424 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
425 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
426 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
427 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
428 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
429 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
430 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
431 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
432 | }, | |
433 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
434 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
435 | }, | |
436 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
437 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
438 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
439 | }; |
440 | ||
be29b99a AK |
441 | /* policy for coalesce rule attributes */ |
442 | static const struct nla_policy | |
443 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
444 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
445 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
446 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
447 | }; | |
448 | ||
e5497d76 JB |
449 | /* policy for GTK rekey offload attributes */ |
450 | static const struct nla_policy | |
451 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
452 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
453 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
454 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
455 | }; | |
456 | ||
a1f1c21c LC |
457 | static const struct nla_policy |
458 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 459 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 460 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 461 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
462 | }; |
463 | ||
97990a06 JB |
464 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
465 | struct netlink_callback *cb, | |
466 | struct cfg80211_registered_device **rdev, | |
467 | struct wireless_dev **wdev) | |
a043897a | 468 | { |
97990a06 | 469 | int err; |
a043897a | 470 | |
97990a06 | 471 | rtnl_lock(); |
a043897a | 472 | |
97990a06 JB |
473 | if (!cb->args[0]) { |
474 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
475 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
476 | nl80211_policy); | |
477 | if (err) | |
478 | goto out_unlock; | |
67748893 | 479 | |
97990a06 JB |
480 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
481 | nl80211_fam.attrbuf); | |
482 | if (IS_ERR(*wdev)) { | |
483 | err = PTR_ERR(*wdev); | |
484 | goto out_unlock; | |
485 | } | |
486 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
c319d50b JB |
487 | /* 0 is the first index - add 1 to parse only once */ |
488 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
489 | cb->args[1] = (*wdev)->identifier; |
490 | } else { | |
c319d50b JB |
491 | /* subtract the 1 again here */ |
492 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 493 | struct wireless_dev *tmp; |
67748893 | 494 | |
97990a06 JB |
495 | if (!wiphy) { |
496 | err = -ENODEV; | |
497 | goto out_unlock; | |
498 | } | |
499 | *rdev = wiphy_to_dev(wiphy); | |
500 | *wdev = NULL; | |
67748893 | 501 | |
97990a06 JB |
502 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
503 | if (tmp->identifier == cb->args[1]) { | |
504 | *wdev = tmp; | |
505 | break; | |
506 | } | |
507 | } | |
67748893 | 508 | |
97990a06 JB |
509 | if (!*wdev) { |
510 | err = -ENODEV; | |
511 | goto out_unlock; | |
512 | } | |
67748893 JB |
513 | } |
514 | ||
67748893 | 515 | return 0; |
97990a06 | 516 | out_unlock: |
67748893 JB |
517 | rtnl_unlock(); |
518 | return err; | |
519 | } | |
520 | ||
97990a06 | 521 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 522 | { |
67748893 JB |
523 | rtnl_unlock(); |
524 | } | |
525 | ||
f4a11bb0 JB |
526 | /* IE validation */ |
527 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
528 | { | |
529 | const u8 *pos; | |
530 | int len; | |
531 | ||
532 | if (!attr) | |
533 | return true; | |
534 | ||
535 | pos = nla_data(attr); | |
536 | len = nla_len(attr); | |
537 | ||
538 | while (len) { | |
539 | u8 elemlen; | |
540 | ||
541 | if (len < 2) | |
542 | return false; | |
543 | len -= 2; | |
544 | ||
545 | elemlen = pos[1]; | |
546 | if (elemlen > len) | |
547 | return false; | |
548 | ||
549 | len -= elemlen; | |
550 | pos += 2 + elemlen; | |
551 | } | |
552 | ||
553 | return true; | |
554 | } | |
555 | ||
55682965 | 556 | /* message building helper */ |
15e47304 | 557 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
558 | int flags, u8 cmd) |
559 | { | |
560 | /* since there is no private header just add the generic one */ | |
15e47304 | 561 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
562 | } |
563 | ||
5dab3b8a | 564 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
565 | struct ieee80211_channel *chan, |
566 | bool large) | |
5dab3b8a | 567 | { |
9360ffd1 DM |
568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
569 | chan->center_freq)) | |
570 | goto nla_put_failure; | |
5dab3b8a | 571 | |
9360ffd1 DM |
572 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
573 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
574 | goto nla_put_failure; | |
8fe02e16 LR |
575 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
576 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
577 | goto nla_put_failure; | |
578 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
579 | goto nla_put_failure; | |
580 | } | |
cdc89b97 JB |
581 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
582 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
583 | goto nla_put_failure; | |
584 | if (large) { | |
585 | u32 time; | |
586 | ||
587 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
588 | ||
589 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
590 | chan->dfs_state)) | |
591 | goto nla_put_failure; | |
592 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
593 | time)) | |
594 | goto nla_put_failure; | |
595 | } | |
596 | } | |
5dab3b8a | 597 | |
fe1abafd JB |
598 | if (large) { |
599 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
600 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
601 | goto nla_put_failure; | |
602 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
603 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
604 | goto nla_put_failure; | |
605 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
606 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
607 | goto nla_put_failure; | |
608 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
609 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
610 | goto nla_put_failure; | |
611 | } | |
612 | ||
9360ffd1 DM |
613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
614 | DBM_TO_MBM(chan->max_power))) | |
615 | goto nla_put_failure; | |
5dab3b8a LR |
616 | |
617 | return 0; | |
618 | ||
619 | nla_put_failure: | |
620 | return -ENOBUFS; | |
621 | } | |
622 | ||
55682965 JB |
623 | /* netlink command implementations */ |
624 | ||
b9454e83 JB |
625 | struct key_parse { |
626 | struct key_params p; | |
627 | int idx; | |
e31b8213 | 628 | int type; |
b9454e83 | 629 | bool def, defmgmt; |
dbd2fd65 | 630 | bool def_uni, def_multi; |
b9454e83 JB |
631 | }; |
632 | ||
633 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
634 | { | |
635 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
636 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
637 | nl80211_key_policy); | |
638 | if (err) | |
639 | return err; | |
640 | ||
641 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
642 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
643 | ||
dbd2fd65 JB |
644 | if (k->def) { |
645 | k->def_uni = true; | |
646 | k->def_multi = true; | |
647 | } | |
648 | if (k->defmgmt) | |
649 | k->def_multi = true; | |
650 | ||
b9454e83 JB |
651 | if (tb[NL80211_KEY_IDX]) |
652 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
653 | ||
654 | if (tb[NL80211_KEY_DATA]) { | |
655 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
656 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
657 | } | |
658 | ||
659 | if (tb[NL80211_KEY_SEQ]) { | |
660 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
661 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
662 | } | |
663 | ||
664 | if (tb[NL80211_KEY_CIPHER]) | |
665 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
666 | ||
e31b8213 JB |
667 | if (tb[NL80211_KEY_TYPE]) { |
668 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
669 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
670 | return -EINVAL; | |
671 | } | |
672 | ||
dbd2fd65 JB |
673 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
674 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
675 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
676 | tb[NL80211_KEY_DEFAULT_TYPES], | |
677 | nl80211_key_default_policy); | |
dbd2fd65 JB |
678 | if (err) |
679 | return err; | |
680 | ||
681 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
682 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
683 | } | |
684 | ||
b9454e83 JB |
685 | return 0; |
686 | } | |
687 | ||
688 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
689 | { | |
690 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
691 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
692 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
693 | } | |
694 | ||
695 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
696 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
697 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
698 | } | |
699 | ||
700 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
701 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
702 | ||
703 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
704 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
705 | ||
706 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
707 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
708 | ||
dbd2fd65 JB |
709 | if (k->def) { |
710 | k->def_uni = true; | |
711 | k->def_multi = true; | |
712 | } | |
713 | if (k->defmgmt) | |
714 | k->def_multi = true; | |
715 | ||
e31b8213 JB |
716 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
717 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
718 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
719 | return -EINVAL; | |
720 | } | |
721 | ||
dbd2fd65 JB |
722 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
723 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
724 | int err = nla_parse_nested( | |
725 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
726 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
727 | nl80211_key_default_policy); | |
728 | if (err) | |
729 | return err; | |
730 | ||
731 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
732 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
733 | } | |
734 | ||
b9454e83 JB |
735 | return 0; |
736 | } | |
737 | ||
738 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
739 | { | |
740 | int err; | |
741 | ||
742 | memset(k, 0, sizeof(*k)); | |
743 | k->idx = -1; | |
e31b8213 | 744 | k->type = -1; |
b9454e83 JB |
745 | |
746 | if (info->attrs[NL80211_ATTR_KEY]) | |
747 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
748 | else | |
749 | err = nl80211_parse_key_old(info, k); | |
750 | ||
751 | if (err) | |
752 | return err; | |
753 | ||
754 | if (k->def && k->defmgmt) | |
755 | return -EINVAL; | |
756 | ||
dbd2fd65 JB |
757 | if (k->defmgmt) { |
758 | if (k->def_uni || !k->def_multi) | |
759 | return -EINVAL; | |
760 | } | |
761 | ||
b9454e83 JB |
762 | if (k->idx != -1) { |
763 | if (k->defmgmt) { | |
764 | if (k->idx < 4 || k->idx > 5) | |
765 | return -EINVAL; | |
766 | } else if (k->def) { | |
767 | if (k->idx < 0 || k->idx > 3) | |
768 | return -EINVAL; | |
769 | } else { | |
770 | if (k->idx < 0 || k->idx > 5) | |
771 | return -EINVAL; | |
772 | } | |
773 | } | |
774 | ||
775 | return 0; | |
776 | } | |
777 | ||
fffd0934 JB |
778 | static struct cfg80211_cached_keys * |
779 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 780 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
781 | { |
782 | struct key_parse parse; | |
783 | struct nlattr *key; | |
784 | struct cfg80211_cached_keys *result; | |
785 | int rem, err, def = 0; | |
786 | ||
787 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
788 | if (!result) | |
789 | return ERR_PTR(-ENOMEM); | |
790 | ||
791 | result->def = -1; | |
792 | result->defmgmt = -1; | |
793 | ||
794 | nla_for_each_nested(key, keys, rem) { | |
795 | memset(&parse, 0, sizeof(parse)); | |
796 | parse.idx = -1; | |
797 | ||
798 | err = nl80211_parse_key_new(key, &parse); | |
799 | if (err) | |
800 | goto error; | |
801 | err = -EINVAL; | |
802 | if (!parse.p.key) | |
803 | goto error; | |
804 | if (parse.idx < 0 || parse.idx > 4) | |
805 | goto error; | |
806 | if (parse.def) { | |
807 | if (def) | |
808 | goto error; | |
809 | def = 1; | |
810 | result->def = parse.idx; | |
dbd2fd65 JB |
811 | if (!parse.def_uni || !parse.def_multi) |
812 | goto error; | |
fffd0934 JB |
813 | } else if (parse.defmgmt) |
814 | goto error; | |
815 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 816 | parse.idx, false, NULL); |
fffd0934 JB |
817 | if (err) |
818 | goto error; | |
819 | result->params[parse.idx].cipher = parse.p.cipher; | |
820 | result->params[parse.idx].key_len = parse.p.key_len; | |
821 | result->params[parse.idx].key = result->data[parse.idx]; | |
822 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
823 | |
824 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
825 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
826 | if (no_ht) | |
827 | *no_ht = true; | |
828 | } | |
fffd0934 JB |
829 | } |
830 | ||
831 | return result; | |
832 | error: | |
833 | kfree(result); | |
834 | return ERR_PTR(err); | |
835 | } | |
836 | ||
837 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
838 | { | |
839 | ASSERT_WDEV_LOCK(wdev); | |
840 | ||
fffd0934 JB |
841 | switch (wdev->iftype) { |
842 | case NL80211_IFTYPE_AP: | |
843 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 844 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 845 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
846 | break; |
847 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 848 | case NL80211_IFTYPE_STATION: |
074ac8df | 849 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 850 | if (!wdev->current_bss) |
fffd0934 JB |
851 | return -ENOLINK; |
852 | break; | |
853 | default: | |
854 | return -EINVAL; | |
855 | } | |
856 | ||
857 | return 0; | |
858 | } | |
859 | ||
664834de JM |
860 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
861 | struct nlattr *tb) | |
862 | { | |
863 | struct ieee80211_channel *chan; | |
864 | ||
865 | if (tb == NULL) | |
866 | return NULL; | |
867 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
868 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
869 | return NULL; | |
870 | return chan; | |
871 | } | |
872 | ||
7527a782 JB |
873 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
874 | { | |
875 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
876 | int i; | |
877 | ||
878 | if (!nl_modes) | |
879 | goto nla_put_failure; | |
880 | ||
881 | i = 0; | |
882 | while (ifmodes) { | |
9360ffd1 DM |
883 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
884 | goto nla_put_failure; | |
7527a782 JB |
885 | ifmodes >>= 1; |
886 | i++; | |
887 | } | |
888 | ||
889 | nla_nest_end(msg, nl_modes); | |
890 | return 0; | |
891 | ||
892 | nla_put_failure: | |
893 | return -ENOBUFS; | |
894 | } | |
895 | ||
896 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
897 | struct sk_buff *msg, |
898 | bool large) | |
7527a782 JB |
899 | { |
900 | struct nlattr *nl_combis; | |
901 | int i, j; | |
902 | ||
903 | nl_combis = nla_nest_start(msg, | |
904 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
905 | if (!nl_combis) | |
906 | goto nla_put_failure; | |
907 | ||
908 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
909 | const struct ieee80211_iface_combination *c; | |
910 | struct nlattr *nl_combi, *nl_limits; | |
911 | ||
912 | c = &wiphy->iface_combinations[i]; | |
913 | ||
914 | nl_combi = nla_nest_start(msg, i + 1); | |
915 | if (!nl_combi) | |
916 | goto nla_put_failure; | |
917 | ||
918 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
919 | if (!nl_limits) | |
920 | goto nla_put_failure; | |
921 | ||
922 | for (j = 0; j < c->n_limits; j++) { | |
923 | struct nlattr *nl_limit; | |
924 | ||
925 | nl_limit = nla_nest_start(msg, j + 1); | |
926 | if (!nl_limit) | |
927 | goto nla_put_failure; | |
9360ffd1 DM |
928 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
929 | c->limits[j].max)) | |
930 | goto nla_put_failure; | |
7527a782 JB |
931 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
932 | c->limits[j].types)) | |
933 | goto nla_put_failure; | |
934 | nla_nest_end(msg, nl_limit); | |
935 | } | |
936 | ||
937 | nla_nest_end(msg, nl_limits); | |
938 | ||
9360ffd1 DM |
939 | if (c->beacon_int_infra_match && |
940 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
941 | goto nla_put_failure; | |
942 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
943 | c->num_different_channels) || | |
944 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
945 | c->max_interfaces)) | |
946 | goto nla_put_failure; | |
cdc89b97 JB |
947 | if (large && |
948 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
949 | c->radar_detect_widths)) | |
950 | goto nla_put_failure; | |
7527a782 JB |
951 | |
952 | nla_nest_end(msg, nl_combi); | |
953 | } | |
954 | ||
955 | nla_nest_end(msg, nl_combis); | |
956 | ||
957 | return 0; | |
958 | nla_put_failure: | |
959 | return -ENOBUFS; | |
960 | } | |
961 | ||
3713b4e3 | 962 | #ifdef CONFIG_PM |
b56cf720 JB |
963 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
964 | struct sk_buff *msg) | |
965 | { | |
964dc9e2 | 966 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
967 | struct nlattr *nl_tcp; |
968 | ||
969 | if (!tcp) | |
970 | return 0; | |
971 | ||
972 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
973 | if (!nl_tcp) | |
974 | return -ENOBUFS; | |
975 | ||
976 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
977 | tcp->data_payload_max)) | |
978 | return -ENOBUFS; | |
979 | ||
980 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
981 | tcp->data_payload_max)) | |
982 | return -ENOBUFS; | |
983 | ||
984 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
985 | return -ENOBUFS; | |
986 | ||
987 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
988 | sizeof(*tcp->tok), tcp->tok)) | |
989 | return -ENOBUFS; | |
990 | ||
991 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
992 | tcp->data_interval_max)) | |
993 | return -ENOBUFS; | |
994 | ||
995 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
996 | tcp->wake_payload_max)) | |
997 | return -ENOBUFS; | |
998 | ||
999 | nla_nest_end(msg, nl_tcp); | |
1000 | return 0; | |
1001 | } | |
1002 | ||
3713b4e3 | 1003 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
1004 | struct cfg80211_registered_device *dev, |
1005 | bool large) | |
55682965 | 1006 | { |
3713b4e3 | 1007 | struct nlattr *nl_wowlan; |
55682965 | 1008 | |
964dc9e2 | 1009 | if (!dev->wiphy.wowlan) |
3713b4e3 | 1010 | return 0; |
55682965 | 1011 | |
3713b4e3 JB |
1012 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1013 | if (!nl_wowlan) | |
1014 | return -ENOBUFS; | |
9360ffd1 | 1015 | |
964dc9e2 | 1016 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1017 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
964dc9e2 | 1018 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1019 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
964dc9e2 | 1020 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1021 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
964dc9e2 | 1022 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1023 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
964dc9e2 | 1024 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1025 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
964dc9e2 | 1026 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1027 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
964dc9e2 | 1028 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1029 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
964dc9e2 | 1030 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1031 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1032 | return -ENOBUFS; | |
9360ffd1 | 1033 | |
964dc9e2 | 1034 | if (dev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1035 | struct nl80211_pattern_support pat = { |
964dc9e2 JB |
1036 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
1037 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, | |
1038 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, | |
1039 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1040 | }; |
9360ffd1 | 1041 | |
3713b4e3 JB |
1042 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1043 | sizeof(pat), &pat)) | |
1044 | return -ENOBUFS; | |
1045 | } | |
9360ffd1 | 1046 | |
b56cf720 JB |
1047 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1048 | return -ENOBUFS; | |
1049 | ||
3713b4e3 | 1050 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1051 | |
3713b4e3 JB |
1052 | return 0; |
1053 | } | |
1054 | #endif | |
9360ffd1 | 1055 | |
be29b99a AK |
1056 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1057 | struct cfg80211_registered_device *dev) | |
1058 | { | |
1059 | struct nl80211_coalesce_rule_support rule; | |
1060 | ||
1061 | if (!dev->wiphy.coalesce) | |
1062 | return 0; | |
1063 | ||
1064 | rule.max_rules = dev->wiphy.coalesce->n_rules; | |
1065 | rule.max_delay = dev->wiphy.coalesce->max_delay; | |
1066 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; | |
1067 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; | |
1068 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; | |
1069 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; | |
1070 | ||
1071 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1072 | return -ENOBUFS; | |
1073 | ||
1074 | return 0; | |
1075 | } | |
1076 | ||
3713b4e3 JB |
1077 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1078 | struct ieee80211_supported_band *sband) | |
1079 | { | |
1080 | struct nlattr *nl_rates, *nl_rate; | |
1081 | struct ieee80211_rate *rate; | |
1082 | int i; | |
87bbbe22 | 1083 | |
3713b4e3 JB |
1084 | /* add HT info */ |
1085 | if (sband->ht_cap.ht_supported && | |
1086 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1087 | sizeof(sband->ht_cap.mcs), | |
1088 | &sband->ht_cap.mcs) || | |
1089 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1090 | sband->ht_cap.cap) || | |
1091 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1092 | sband->ht_cap.ampdu_factor) || | |
1093 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1094 | sband->ht_cap.ampdu_density))) | |
1095 | return -ENOBUFS; | |
afe0cbf8 | 1096 | |
3713b4e3 JB |
1097 | /* add VHT info */ |
1098 | if (sband->vht_cap.vht_supported && | |
1099 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1100 | sizeof(sband->vht_cap.vht_mcs), | |
1101 | &sband->vht_cap.vht_mcs) || | |
1102 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1103 | sband->vht_cap.cap))) | |
1104 | return -ENOBUFS; | |
f59ac048 | 1105 | |
3713b4e3 JB |
1106 | /* add bitrates */ |
1107 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1108 | if (!nl_rates) | |
1109 | return -ENOBUFS; | |
ee688b00 | 1110 | |
3713b4e3 JB |
1111 | for (i = 0; i < sband->n_bitrates; i++) { |
1112 | nl_rate = nla_nest_start(msg, i); | |
1113 | if (!nl_rate) | |
1114 | return -ENOBUFS; | |
ee688b00 | 1115 | |
3713b4e3 JB |
1116 | rate = &sband->bitrates[i]; |
1117 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1118 | rate->bitrate)) | |
1119 | return -ENOBUFS; | |
1120 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1121 | nla_put_flag(msg, | |
1122 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1123 | return -ENOBUFS; | |
ee688b00 | 1124 | |
3713b4e3 JB |
1125 | nla_nest_end(msg, nl_rate); |
1126 | } | |
d51626df | 1127 | |
3713b4e3 | 1128 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1129 | |
3713b4e3 JB |
1130 | return 0; |
1131 | } | |
ee688b00 | 1132 | |
3713b4e3 JB |
1133 | static int |
1134 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1135 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1136 | { | |
1137 | u16 stypes; | |
1138 | struct nlattr *nl_ftypes, *nl_ifs; | |
1139 | enum nl80211_iftype ift; | |
1140 | int i; | |
ee688b00 | 1141 | |
3713b4e3 JB |
1142 | if (!mgmt_stypes) |
1143 | return 0; | |
5dab3b8a | 1144 | |
3713b4e3 JB |
1145 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1146 | if (!nl_ifs) | |
1147 | return -ENOBUFS; | |
e2f367f2 | 1148 | |
3713b4e3 JB |
1149 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1150 | nl_ftypes = nla_nest_start(msg, ift); | |
1151 | if (!nl_ftypes) | |
1152 | return -ENOBUFS; | |
1153 | i = 0; | |
1154 | stypes = mgmt_stypes[ift].tx; | |
1155 | while (stypes) { | |
1156 | if ((stypes & 1) && | |
1157 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1158 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1159 | return -ENOBUFS; | |
1160 | stypes >>= 1; | |
1161 | i++; | |
ee688b00 | 1162 | } |
3713b4e3 JB |
1163 | nla_nest_end(msg, nl_ftypes); |
1164 | } | |
ee688b00 | 1165 | |
3713b4e3 | 1166 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1167 | |
3713b4e3 JB |
1168 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1169 | if (!nl_ifs) | |
1170 | return -ENOBUFS; | |
ee688b00 | 1171 | |
3713b4e3 JB |
1172 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1173 | nl_ftypes = nla_nest_start(msg, ift); | |
1174 | if (!nl_ftypes) | |
1175 | return -ENOBUFS; | |
1176 | i = 0; | |
1177 | stypes = mgmt_stypes[ift].rx; | |
1178 | while (stypes) { | |
1179 | if ((stypes & 1) && | |
1180 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1181 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1182 | return -ENOBUFS; | |
1183 | stypes >>= 1; | |
1184 | i++; | |
1185 | } | |
1186 | nla_nest_end(msg, nl_ftypes); | |
1187 | } | |
1188 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1189 | |
3713b4e3 JB |
1190 | return 0; |
1191 | } | |
ee688b00 | 1192 | |
86e8cf98 JB |
1193 | struct nl80211_dump_wiphy_state { |
1194 | s64 filter_wiphy; | |
1195 | long start; | |
1196 | long split_start, band_start, chan_start; | |
1197 | bool split; | |
1198 | }; | |
1199 | ||
3713b4e3 JB |
1200 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1201 | struct sk_buff *msg, u32 portid, u32 seq, | |
86e8cf98 | 1202 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1203 | { |
1204 | void *hdr; | |
1205 | struct nlattr *nl_bands, *nl_band; | |
1206 | struct nlattr *nl_freqs, *nl_freq; | |
1207 | struct nlattr *nl_cmds; | |
1208 | enum ieee80211_band band; | |
1209 | struct ieee80211_channel *chan; | |
1210 | int i; | |
1211 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1212 | dev->wiphy.mgmt_stypes; | |
fe1abafd | 1213 | u32 features; |
ee688b00 | 1214 | |
3713b4e3 JB |
1215 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1216 | if (!hdr) | |
1217 | return -ENOBUFS; | |
ee688b00 | 1218 | |
86e8cf98 JB |
1219 | if (WARN_ON(!state)) |
1220 | return -EINVAL; | |
ee688b00 | 1221 | |
3713b4e3 JB |
1222 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1223 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1224 | wiphy_name(&dev->wiphy)) || | |
1225 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1226 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1227 | goto nla_put_failure; |
1228 | ||
86e8cf98 | 1229 | switch (state->split_start) { |
3713b4e3 JB |
1230 | case 0: |
1231 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1232 | dev->wiphy.retry_short) || | |
1233 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1234 | dev->wiphy.retry_long) || | |
1235 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1236 | dev->wiphy.frag_threshold) || | |
1237 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1238 | dev->wiphy.rts_threshold) || | |
1239 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1240 | dev->wiphy.coverage_class) || | |
1241 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1242 | dev->wiphy.max_scan_ssids) || | |
1243 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1244 | dev->wiphy.max_sched_scan_ssids) || | |
1245 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1246 | dev->wiphy.max_scan_ie_len) || | |
1247 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1248 | dev->wiphy.max_sched_scan_ie_len) || | |
1249 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1250 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1251 | goto nla_put_failure; |
3713b4e3 JB |
1252 | |
1253 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1254 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1255 | goto nla_put_failure; |
3713b4e3 JB |
1256 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1257 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1258 | goto nla_put_failure; | |
1259 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1260 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1261 | goto nla_put_failure; | |
1262 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1263 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1264 | goto nla_put_failure; | |
1265 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1266 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1267 | goto nla_put_failure; | |
1268 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1269 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1270 | goto nla_put_failure; |
86e8cf98 JB |
1271 | state->split_start++; |
1272 | if (state->split) | |
3713b4e3 JB |
1273 | break; |
1274 | case 1: | |
1275 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1276 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1277 | dev->wiphy.cipher_suites)) | |
1278 | goto nla_put_failure; | |
4745fc09 | 1279 | |
3713b4e3 JB |
1280 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1281 | dev->wiphy.max_num_pmkids)) | |
1282 | goto nla_put_failure; | |
b23aa676 | 1283 | |
3713b4e3 JB |
1284 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1285 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1286 | goto nla_put_failure; |
b23aa676 | 1287 | |
3713b4e3 JB |
1288 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1289 | dev->wiphy.available_antennas_tx) || | |
1290 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1291 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1292 | goto nla_put_failure; |
b23aa676 | 1293 | |
3713b4e3 JB |
1294 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1295 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1296 | dev->wiphy.probe_resp_offload)) | |
1297 | goto nla_put_failure; | |
8fdc621d | 1298 | |
3713b4e3 JB |
1299 | if ((dev->wiphy.available_antennas_tx || |
1300 | dev->wiphy.available_antennas_rx) && | |
1301 | dev->ops->get_antenna) { | |
1302 | u32 tx_ant = 0, rx_ant = 0; | |
1303 | int res; | |
1304 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1305 | if (!res) { | |
1306 | if (nla_put_u32(msg, | |
1307 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1308 | tx_ant) || | |
1309 | nla_put_u32(msg, | |
1310 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1311 | rx_ant)) | |
1312 | goto nla_put_failure; | |
1313 | } | |
1314 | } | |
a293911d | 1315 | |
86e8cf98 JB |
1316 | state->split_start++; |
1317 | if (state->split) | |
3713b4e3 JB |
1318 | break; |
1319 | case 2: | |
1320 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1321 | dev->wiphy.interface_modes)) | |
1322 | goto nla_put_failure; | |
86e8cf98 JB |
1323 | state->split_start++; |
1324 | if (state->split) | |
3713b4e3 JB |
1325 | break; |
1326 | case 3: | |
1327 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1328 | if (!nl_bands) | |
1329 | goto nla_put_failure; | |
f7ca38df | 1330 | |
86e8cf98 JB |
1331 | for (band = state->band_start; |
1332 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1333 | struct ieee80211_supported_band *sband; |
2e161f78 | 1334 | |
3713b4e3 | 1335 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1336 | |
3713b4e3 JB |
1337 | if (!sband) |
1338 | continue; | |
1339 | ||
1340 | nl_band = nla_nest_start(msg, band); | |
1341 | if (!nl_band) | |
2e161f78 | 1342 | goto nla_put_failure; |
3713b4e3 | 1343 | |
86e8cf98 | 1344 | switch (state->chan_start) { |
3713b4e3 JB |
1345 | case 0: |
1346 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1347 | goto nla_put_failure; |
86e8cf98 JB |
1348 | state->chan_start++; |
1349 | if (state->split) | |
3713b4e3 JB |
1350 | break; |
1351 | default: | |
1352 | /* add frequencies */ | |
1353 | nl_freqs = nla_nest_start( | |
1354 | msg, NL80211_BAND_ATTR_FREQS); | |
1355 | if (!nl_freqs) | |
1356 | goto nla_put_failure; | |
1357 | ||
86e8cf98 | 1358 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1359 | i < sband->n_channels; |
1360 | i++) { | |
1361 | nl_freq = nla_nest_start(msg, i); | |
1362 | if (!nl_freq) | |
1363 | goto nla_put_failure; | |
1364 | ||
1365 | chan = &sband->channels[i]; | |
1366 | ||
86e8cf98 JB |
1367 | if (nl80211_msg_put_channel( |
1368 | msg, chan, | |
1369 | state->split)) | |
3713b4e3 JB |
1370 | goto nla_put_failure; |
1371 | ||
1372 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1373 | if (state->split) |
3713b4e3 JB |
1374 | break; |
1375 | } | |
1376 | if (i < sband->n_channels) | |
86e8cf98 | 1377 | state->chan_start = i + 2; |
3713b4e3 | 1378 | else |
86e8cf98 | 1379 | state->chan_start = 0; |
3713b4e3 JB |
1380 | nla_nest_end(msg, nl_freqs); |
1381 | } | |
1382 | ||
1383 | nla_nest_end(msg, nl_band); | |
1384 | ||
86e8cf98 | 1385 | if (state->split) { |
3713b4e3 | 1386 | /* start again here */ |
86e8cf98 | 1387 | if (state->chan_start) |
3713b4e3 JB |
1388 | band--; |
1389 | break; | |
2e161f78 | 1390 | } |
2e161f78 | 1391 | } |
3713b4e3 | 1392 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1393 | |
3713b4e3 | 1394 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1395 | state->band_start = band + 1; |
3713b4e3 | 1396 | else |
86e8cf98 | 1397 | state->band_start = 0; |
74b70a4e | 1398 | |
3713b4e3 | 1399 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1400 | if (state->band_start == 0 && state->chan_start == 0) |
1401 | state->split_start++; | |
1402 | if (state->split) | |
3713b4e3 JB |
1403 | break; |
1404 | case 4: | |
1405 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1406 | if (!nl_cmds) | |
2e161f78 JB |
1407 | goto nla_put_failure; |
1408 | ||
3713b4e3 JB |
1409 | i = 0; |
1410 | #define CMD(op, n) \ | |
1411 | do { \ | |
1412 | if (dev->ops->op) { \ | |
1413 | i++; \ | |
1414 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1415 | goto nla_put_failure; \ | |
1416 | } \ | |
1417 | } while (0) | |
1418 | ||
1419 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1420 | CMD(change_virtual_intf, SET_INTERFACE); | |
1421 | CMD(add_key, NEW_KEY); | |
1422 | CMD(start_ap, START_AP); | |
1423 | CMD(add_station, NEW_STATION); | |
1424 | CMD(add_mpath, NEW_MPATH); | |
1425 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1426 | CMD(change_bss, SET_BSS); | |
1427 | CMD(auth, AUTHENTICATE); | |
1428 | CMD(assoc, ASSOCIATE); | |
1429 | CMD(deauth, DEAUTHENTICATE); | |
1430 | CMD(disassoc, DISASSOCIATE); | |
1431 | CMD(join_ibss, JOIN_IBSS); | |
1432 | CMD(join_mesh, JOIN_MESH); | |
1433 | CMD(set_pmksa, SET_PMKSA); | |
1434 | CMD(del_pmksa, DEL_PMKSA); | |
1435 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1436 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1437 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1438 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1439 | CMD(mgmt_tx, FRAME); | |
1440 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1441 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1442 | i++; | |
1443 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1444 | goto nla_put_failure; |
2e161f78 | 1445 | } |
3713b4e3 JB |
1446 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1447 | dev->ops->join_mesh) { | |
1448 | i++; | |
1449 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1450 | goto nla_put_failure; | |
1451 | } | |
1452 | CMD(set_wds_peer, SET_WDS_PEER); | |
1453 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1454 | CMD(tdls_mgmt, TDLS_MGMT); | |
1455 | CMD(tdls_oper, TDLS_OPER); | |
1456 | } | |
1457 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1458 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1459 | CMD(probe_client, PROBE_CLIENT); | |
1460 | CMD(set_noack_map, SET_NOACK_MAP); | |
1461 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1462 | i++; | |
1463 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1464 | goto nla_put_failure; | |
1465 | } | |
1466 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1467 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
86e8cf98 | 1468 | if (state->split) { |
5de17984 AS |
1469 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1470 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
16ef1fe2 SW |
1471 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
1472 | CMD(channel_switch, CHANNEL_SWITCH); | |
5de17984 | 1473 | } |
fa9ffc74 | 1474 | CMD(set_qos_map, SET_QOS_MAP); |
2e161f78 | 1475 | |
3713b4e3 JB |
1476 | #ifdef CONFIG_NL80211_TESTMODE |
1477 | CMD(testmode_cmd, TESTMODE); | |
1478 | #endif | |
ff1b6e69 | 1479 | |
3713b4e3 | 1480 | #undef CMD |
ff1b6e69 | 1481 | |
3713b4e3 JB |
1482 | if (dev->ops->connect || dev->ops->auth) { |
1483 | i++; | |
1484 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1485 | goto nla_put_failure; |
ff1b6e69 JB |
1486 | } |
1487 | ||
3713b4e3 JB |
1488 | if (dev->ops->disconnect || dev->ops->deauth) { |
1489 | i++; | |
1490 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1491 | goto nla_put_failure; | |
1492 | } | |
1493 | ||
1494 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1495 | state->split_start++; |
1496 | if (state->split) | |
3713b4e3 JB |
1497 | break; |
1498 | case 5: | |
1499 | if (dev->ops->remain_on_channel && | |
1500 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1501 | nla_put_u32(msg, | |
1502 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1503 | dev->wiphy.max_remain_on_channel_duration)) | |
1504 | goto nla_put_failure; | |
1505 | ||
1506 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1507 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1508 | goto nla_put_failure; | |
1509 | ||
1510 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1511 | goto nla_put_failure; | |
86e8cf98 JB |
1512 | state->split_start++; |
1513 | if (state->split) | |
3713b4e3 JB |
1514 | break; |
1515 | case 6: | |
1516 | #ifdef CONFIG_PM | |
86e8cf98 | 1517 | if (nl80211_send_wowlan(msg, dev, state->split)) |
3713b4e3 | 1518 | goto nla_put_failure; |
86e8cf98 JB |
1519 | state->split_start++; |
1520 | if (state->split) | |
3713b4e3 JB |
1521 | break; |
1522 | #else | |
86e8cf98 | 1523 | state->split_start++; |
dfb89c56 | 1524 | #endif |
3713b4e3 JB |
1525 | case 7: |
1526 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1527 | dev->wiphy.software_iftypes)) | |
1528 | goto nla_put_failure; | |
ff1b6e69 | 1529 | |
86e8cf98 JB |
1530 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
1531 | state->split)) | |
3713b4e3 | 1532 | goto nla_put_failure; |
7527a782 | 1533 | |
86e8cf98 JB |
1534 | state->split_start++; |
1535 | if (state->split) | |
3713b4e3 JB |
1536 | break; |
1537 | case 8: | |
1538 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1539 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1540 | dev->wiphy.ap_sme_capa)) | |
1541 | goto nla_put_failure; | |
7527a782 | 1542 | |
fe1abafd JB |
1543 | features = dev->wiphy.features; |
1544 | /* | |
1545 | * We can only add the per-channel limit information if the | |
1546 | * dump is split, otherwise it makes it too big. Therefore | |
1547 | * only advertise it in that case. | |
1548 | */ | |
86e8cf98 | 1549 | if (state->split) |
fe1abafd JB |
1550 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1551 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1552 | goto nla_put_failure; |
562a7480 | 1553 | |
3713b4e3 JB |
1554 | if (dev->wiphy.ht_capa_mod_mask && |
1555 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1556 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1557 | dev->wiphy.ht_capa_mod_mask)) | |
1558 | goto nla_put_failure; | |
1f074bd8 | 1559 | |
3713b4e3 JB |
1560 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1561 | dev->wiphy.max_acl_mac_addrs && | |
1562 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1563 | dev->wiphy.max_acl_mac_addrs)) | |
1564 | goto nla_put_failure; | |
7e7c8926 | 1565 | |
3713b4e3 JB |
1566 | /* |
1567 | * Any information below this point is only available to | |
1568 | * applications that can deal with it being split. This | |
1569 | * helps ensure that newly added capabilities don't break | |
1570 | * older tools by overrunning their buffers. | |
1571 | * | |
1572 | * We still increment split_start so that in the split | |
1573 | * case we'll continue with more data in the next round, | |
1574 | * but break unconditionally so unsplit data stops here. | |
1575 | */ | |
86e8cf98 | 1576 | state->split_start++; |
3713b4e3 JB |
1577 | break; |
1578 | case 9: | |
fe1abafd JB |
1579 | if (dev->wiphy.extended_capabilities && |
1580 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1581 | dev->wiphy.extended_capabilities_len, | |
1582 | dev->wiphy.extended_capabilities) || | |
1583 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1584 | dev->wiphy.extended_capabilities_len, | |
1585 | dev->wiphy.extended_capabilities_mask))) | |
1586 | goto nla_put_failure; | |
a50df0c4 | 1587 | |
ee2aca34 JB |
1588 | if (dev->wiphy.vht_capa_mod_mask && |
1589 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1590 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1591 | dev->wiphy.vht_capa_mod_mask)) | |
1592 | goto nla_put_failure; | |
1593 | ||
be29b99a AK |
1594 | state->split_start++; |
1595 | break; | |
1596 | case 10: | |
1597 | if (nl80211_send_coalesce(msg, dev)) | |
1598 | goto nla_put_failure; | |
1599 | ||
01e0daa4 FF |
1600 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
1601 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || | |
1602 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1603 | goto nla_put_failure; | |
b43504cf JM |
1604 | |
1605 | if (dev->wiphy.max_ap_assoc_sta && | |
1606 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, | |
1607 | dev->wiphy.max_ap_assoc_sta)) | |
1608 | goto nla_put_failure; | |
1609 | ||
ad7e718c JB |
1610 | state->split_start++; |
1611 | break; | |
1612 | case 11: | |
567ffc35 JB |
1613 | if (dev->wiphy.n_vendor_commands) { |
1614 | const struct nl80211_vendor_cmd_info *info; | |
1615 | struct nlattr *nested; | |
1616 | ||
1617 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1618 | if (!nested) | |
1619 | goto nla_put_failure; | |
1620 | ||
1621 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) { | |
1622 | info = &dev->wiphy.vendor_commands[i].info; | |
1623 | if (nla_put(msg, i + 1, sizeof(*info), info)) | |
1624 | goto nla_put_failure; | |
1625 | } | |
1626 | nla_nest_end(msg, nested); | |
1627 | } | |
1628 | ||
1629 | if (dev->wiphy.n_vendor_events) { | |
1630 | const struct nl80211_vendor_cmd_info *info; | |
1631 | struct nlattr *nested; | |
ad7e718c | 1632 | |
567ffc35 JB |
1633 | nested = nla_nest_start(msg, |
1634 | NL80211_ATTR_VENDOR_EVENTS); | |
1635 | if (!nested) | |
ad7e718c | 1636 | goto nla_put_failure; |
567ffc35 JB |
1637 | |
1638 | for (i = 0; i < dev->wiphy.n_vendor_events; i++) { | |
1639 | info = &dev->wiphy.vendor_events[i]; | |
1640 | if (nla_put(msg, i + 1, sizeof(*info), info)) | |
1641 | goto nla_put_failure; | |
1642 | } | |
1643 | nla_nest_end(msg, nested); | |
1644 | } | |
01e0daa4 | 1645 | |
3713b4e3 | 1646 | /* done */ |
86e8cf98 | 1647 | state->split_start = 0; |
3713b4e3 JB |
1648 | break; |
1649 | } | |
55682965 JB |
1650 | return genlmsg_end(msg, hdr); |
1651 | ||
1652 | nla_put_failure: | |
bc3ed28c TG |
1653 | genlmsg_cancel(msg, hdr); |
1654 | return -EMSGSIZE; | |
55682965 JB |
1655 | } |
1656 | ||
86e8cf98 JB |
1657 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1658 | struct netlink_callback *cb, | |
1659 | struct nl80211_dump_wiphy_state *state) | |
1660 | { | |
1661 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1662 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1663 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1664 | /* ignore parse errors for backward compatibility */ | |
1665 | if (ret) | |
1666 | return 0; | |
1667 | ||
1668 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1669 | if (tb[NL80211_ATTR_WIPHY]) | |
1670 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1671 | if (tb[NL80211_ATTR_WDEV]) | |
1672 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1673 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1674 | struct net_device *netdev; | |
1675 | struct cfg80211_registered_device *rdev; | |
1676 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1677 | ||
7f2b8562 | 1678 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1679 | if (!netdev) |
1680 | return -ENODEV; | |
1681 | if (netdev->ieee80211_ptr) { | |
1682 | rdev = wiphy_to_dev( | |
1683 | netdev->ieee80211_ptr->wiphy); | |
1684 | state->filter_wiphy = rdev->wiphy_idx; | |
1685 | } | |
86e8cf98 JB |
1686 | } |
1687 | ||
1688 | return 0; | |
1689 | } | |
1690 | ||
55682965 JB |
1691 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1692 | { | |
645e77de | 1693 | int idx = 0, ret; |
86e8cf98 | 1694 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
55682965 | 1695 | struct cfg80211_registered_device *dev; |
3a5a423b | 1696 | |
5fe231e8 | 1697 | rtnl_lock(); |
86e8cf98 JB |
1698 | if (!state) { |
1699 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1700 | if (!state) { |
1701 | rtnl_unlock(); | |
86e8cf98 | 1702 | return -ENOMEM; |
3713b4e3 | 1703 | } |
86e8cf98 JB |
1704 | state->filter_wiphy = -1; |
1705 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1706 | if (ret) { | |
1707 | kfree(state); | |
1708 | rtnl_unlock(); | |
1709 | return ret; | |
3713b4e3 | 1710 | } |
86e8cf98 | 1711 | cb->args[0] = (long)state; |
3713b4e3 JB |
1712 | } |
1713 | ||
79c97e97 | 1714 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1715 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1716 | continue; | |
86e8cf98 | 1717 | if (++idx <= state->start) |
55682965 | 1718 | continue; |
86e8cf98 JB |
1719 | if (state->filter_wiphy != -1 && |
1720 | state->filter_wiphy != dev->wiphy_idx) | |
3713b4e3 JB |
1721 | continue; |
1722 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1723 | do { | |
1724 | ret = nl80211_send_wiphy(dev, skb, | |
1725 | NETLINK_CB(cb->skb).portid, | |
1726 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1727 | NLM_F_MULTI, state); |
3713b4e3 JB |
1728 | if (ret < 0) { |
1729 | /* | |
1730 | * If sending the wiphy data didn't fit (ENOBUFS | |
1731 | * or EMSGSIZE returned), this SKB is still | |
1732 | * empty (so it's not too big because another | |
1733 | * wiphy dataset is already in the skb) and | |
1734 | * we've not tried to adjust the dump allocation | |
1735 | * yet ... then adjust the alloc size to be | |
1736 | * bigger, and return 1 but with the empty skb. | |
1737 | * This results in an empty message being RX'ed | |
1738 | * in userspace, but that is ignored. | |
1739 | * | |
1740 | * We can then retry with the larger buffer. | |
1741 | */ | |
1742 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1743 | !skb->len && !state->split && |
3713b4e3 JB |
1744 | cb->min_dump_alloc < 4096) { |
1745 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1746 | state->split_start = 0; |
d98cae64 | 1747 | rtnl_unlock(); |
3713b4e3 JB |
1748 | return 1; |
1749 | } | |
1750 | idx--; | |
1751 | break; | |
645e77de | 1752 | } |
86e8cf98 | 1753 | } while (state->split_start > 0); |
3713b4e3 | 1754 | break; |
55682965 | 1755 | } |
5fe231e8 | 1756 | rtnl_unlock(); |
55682965 | 1757 | |
86e8cf98 | 1758 | state->start = idx; |
55682965 JB |
1759 | |
1760 | return skb->len; | |
1761 | } | |
1762 | ||
86e8cf98 JB |
1763 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1764 | { | |
1765 | kfree((void *)cb->args[0]); | |
1766 | return 0; | |
1767 | } | |
1768 | ||
55682965 JB |
1769 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1770 | { | |
1771 | struct sk_buff *msg; | |
4c476991 | 1772 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
86e8cf98 | 1773 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1774 | |
645e77de | 1775 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1776 | if (!msg) |
4c476991 | 1777 | return -ENOMEM; |
55682965 | 1778 | |
3713b4e3 | 1779 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
86e8cf98 | 1780 | &state) < 0) { |
4c476991 JB |
1781 | nlmsg_free(msg); |
1782 | return -ENOBUFS; | |
1783 | } | |
55682965 | 1784 | |
134e6375 | 1785 | return genlmsg_reply(msg, info); |
55682965 JB |
1786 | } |
1787 | ||
31888487 JM |
1788 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1789 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1790 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1791 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1792 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1793 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1794 | }; | |
1795 | ||
1796 | static int parse_txq_params(struct nlattr *tb[], | |
1797 | struct ieee80211_txq_params *txq_params) | |
1798 | { | |
a3304b0a | 1799 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1800 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1801 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1802 | return -EINVAL; | |
1803 | ||
a3304b0a | 1804 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1805 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1806 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1807 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1808 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1809 | ||
a3304b0a JB |
1810 | if (txq_params->ac >= NL80211_NUM_ACS) |
1811 | return -EINVAL; | |
1812 | ||
31888487 JM |
1813 | return 0; |
1814 | } | |
1815 | ||
f444de05 JB |
1816 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1817 | { | |
1818 | /* | |
cc1d2806 JB |
1819 | * You can only set the channel explicitly for WDS interfaces, |
1820 | * all others have their channel managed via their respective | |
1821 | * "establish a connection" command (connect, join, ...) | |
1822 | * | |
1823 | * For AP/GO and mesh mode, the channel can be set with the | |
1824 | * channel userspace API, but is only stored and passed to the | |
1825 | * low-level driver when the AP starts or the mesh is joined. | |
1826 | * This is for backward compatibility, userspace can also give | |
1827 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1828 | * |
1829 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1830 | * whatever else is going on, so they have their own special |
1831 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1832 | */ |
1833 | return !wdev || | |
1834 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1835 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1836 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1837 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1838 | } |
1839 | ||
683b6d3b JB |
1840 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1841 | struct genl_info *info, | |
1842 | struct cfg80211_chan_def *chandef) | |
1843 | { | |
dbeca2ea | 1844 | u32 control_freq; |
683b6d3b JB |
1845 | |
1846 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1847 | return -EINVAL; | |
1848 | ||
1849 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1850 | ||
1851 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1852 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1853 | chandef->center_freq1 = control_freq; | |
1854 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1855 | |
1856 | /* Primary channel not allowed */ | |
1857 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1858 | return -EINVAL; | |
1859 | ||
3d9d1d66 JB |
1860 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1861 | enum nl80211_channel_type chantype; | |
1862 | ||
1863 | chantype = nla_get_u32( | |
1864 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1865 | ||
1866 | switch (chantype) { | |
1867 | case NL80211_CHAN_NO_HT: | |
1868 | case NL80211_CHAN_HT20: | |
1869 | case NL80211_CHAN_HT40PLUS: | |
1870 | case NL80211_CHAN_HT40MINUS: | |
1871 | cfg80211_chandef_create(chandef, chandef->chan, | |
1872 | chantype); | |
1873 | break; | |
1874 | default: | |
1875 | return -EINVAL; | |
1876 | } | |
1877 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1878 | chandef->width = | |
1879 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1880 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1881 | chandef->center_freq1 = | |
1882 | nla_get_u32( | |
1883 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1884 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1885 | chandef->center_freq2 = | |
1886 | nla_get_u32( | |
1887 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1888 | } | |
1889 | ||
9f5e8f6e | 1890 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1891 | return -EINVAL; |
1892 | ||
9f5e8f6e JB |
1893 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1894 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1895 | return -EINVAL; |
1896 | ||
2f301ab2 SW |
1897 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1898 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1899 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1900 | return -EINVAL; | |
1901 | ||
683b6d3b JB |
1902 | return 0; |
1903 | } | |
1904 | ||
f444de05 JB |
1905 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1906 | struct wireless_dev *wdev, | |
1907 | struct genl_info *info) | |
1908 | { | |
683b6d3b | 1909 | struct cfg80211_chan_def chandef; |
f444de05 | 1910 | int result; |
e8c9bd5b JB |
1911 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1912 | ||
1913 | if (wdev) | |
1914 | iftype = wdev->iftype; | |
f444de05 | 1915 | |
f444de05 JB |
1916 | if (!nl80211_can_set_dev_channel(wdev)) |
1917 | return -EOPNOTSUPP; | |
1918 | ||
683b6d3b JB |
1919 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1920 | if (result) | |
1921 | return result; | |
f444de05 | 1922 | |
e8c9bd5b | 1923 | switch (iftype) { |
aa430da4 JB |
1924 | case NL80211_IFTYPE_AP: |
1925 | case NL80211_IFTYPE_P2P_GO: | |
1926 | if (wdev->beacon_interval) { | |
1927 | result = -EBUSY; | |
1928 | break; | |
1929 | } | |
683b6d3b | 1930 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1931 | result = -EINVAL; |
1932 | break; | |
1933 | } | |
683b6d3b | 1934 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1935 | result = 0; |
1936 | break; | |
cc1d2806 | 1937 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1938 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1939 | break; |
e8c9bd5b | 1940 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1941 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1942 | break; |
aa430da4 | 1943 | default: |
e8c9bd5b | 1944 | result = -EINVAL; |
f444de05 | 1945 | } |
f444de05 JB |
1946 | |
1947 | return result; | |
1948 | } | |
1949 | ||
1950 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1951 | { | |
4c476991 JB |
1952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1953 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1954 | |
4c476991 | 1955 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1956 | } |
1957 | ||
e8347eba BJ |
1958 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1959 | { | |
43b19952 JB |
1960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1961 | struct net_device *dev = info->user_ptr[1]; | |
1962 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1963 | const u8 *bssid; |
e8347eba BJ |
1964 | |
1965 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1966 | return -EINVAL; | |
1967 | ||
43b19952 JB |
1968 | if (netif_running(dev)) |
1969 | return -EBUSY; | |
e8347eba | 1970 | |
43b19952 JB |
1971 | if (!rdev->ops->set_wds_peer) |
1972 | return -EOPNOTSUPP; | |
e8347eba | 1973 | |
43b19952 JB |
1974 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1975 | return -EOPNOTSUPP; | |
e8347eba BJ |
1976 | |
1977 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1978 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1979 | } |
1980 | ||
1981 | ||
55682965 JB |
1982 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1983 | { | |
1984 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1985 | struct net_device *netdev = NULL; |
1986 | struct wireless_dev *wdev; | |
a1e567c8 | 1987 | int result = 0, rem_txq_params = 0; |
31888487 | 1988 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1989 | u32 changed; |
1990 | u8 retry_short = 0, retry_long = 0; | |
1991 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1992 | u8 coverage_class = 0; |
55682965 | 1993 | |
5fe231e8 JB |
1994 | ASSERT_RTNL(); |
1995 | ||
f444de05 JB |
1996 | /* |
1997 | * Try to find the wiphy and netdev. Normally this | |
1998 | * function shouldn't need the netdev, but this is | |
1999 | * done for backward compatibility -- previously | |
2000 | * setting the channel was done per wiphy, but now | |
2001 | * it is per netdev. Previous userland like hostapd | |
2002 | * also passed a netdev to set_wiphy, so that it is | |
2003 | * possible to let that go to the right netdev! | |
2004 | */ | |
4bbf4d56 | 2005 | |
f444de05 JB |
2006 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2007 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2008 | ||
7f2b8562 | 2009 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2010 | if (netdev && netdev->ieee80211_ptr) |
f444de05 | 2011 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2012 | else |
f444de05 | 2013 | netdev = NULL; |
4bbf4d56 JB |
2014 | } |
2015 | ||
f444de05 | 2016 | if (!netdev) { |
878d9ec7 JB |
2017 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2018 | info->attrs); | |
5fe231e8 | 2019 | if (IS_ERR(rdev)) |
4c476991 | 2020 | return PTR_ERR(rdev); |
f444de05 JB |
2021 | wdev = NULL; |
2022 | netdev = NULL; | |
2023 | result = 0; | |
71fe96bf | 2024 | } else |
f444de05 | 2025 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2026 | |
2027 | /* | |
2028 | * end workaround code, by now the rdev is available | |
2029 | * and locked, and wdev may or may not be NULL. | |
2030 | */ | |
4bbf4d56 JB |
2031 | |
2032 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2033 | result = cfg80211_dev_rename( |
2034 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2035 | |
4bbf4d56 | 2036 | if (result) |
7f2b8562 | 2037 | return result; |
31888487 JM |
2038 | |
2039 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2040 | struct ieee80211_txq_params txq_params; | |
2041 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2042 | ||
7f2b8562 YX |
2043 | if (!rdev->ops->set_txq_params) |
2044 | return -EOPNOTSUPP; | |
31888487 | 2045 | |
7f2b8562 YX |
2046 | if (!netdev) |
2047 | return -EINVAL; | |
f70f01c2 | 2048 | |
133a3ff2 | 2049 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2050 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2051 | return -EINVAL; | |
133a3ff2 | 2052 | |
7f2b8562 YX |
2053 | if (!netif_running(netdev)) |
2054 | return -ENETDOWN; | |
2b5f8b0b | 2055 | |
31888487 JM |
2056 | nla_for_each_nested(nl_txq_params, |
2057 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2058 | rem_txq_params) { | |
ae811e21 JB |
2059 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2060 | nla_data(nl_txq_params), | |
2061 | nla_len(nl_txq_params), | |
2062 | txq_params_policy); | |
2063 | if (result) | |
2064 | return result; | |
31888487 JM |
2065 | result = parse_txq_params(tb, &txq_params); |
2066 | if (result) | |
7f2b8562 | 2067 | return result; |
31888487 | 2068 | |
e35e4d28 HG |
2069 | result = rdev_set_txq_params(rdev, netdev, |
2070 | &txq_params); | |
31888487 | 2071 | if (result) |
7f2b8562 | 2072 | return result; |
31888487 JM |
2073 | } |
2074 | } | |
55682965 | 2075 | |
72bdcf34 | 2076 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
2077 | result = __nl80211_set_channel(rdev, |
2078 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
2079 | info); | |
72bdcf34 | 2080 | if (result) |
7f2b8562 | 2081 | return result; |
72bdcf34 JM |
2082 | } |
2083 | ||
98d2ff8b | 2084 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2085 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2086 | enum nl80211_tx_power_setting type; |
2087 | int idx, mbm = 0; | |
2088 | ||
c8442118 JB |
2089 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2090 | txp_wdev = NULL; | |
2091 | ||
7f2b8562 YX |
2092 | if (!rdev->ops->set_tx_power) |
2093 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2094 | |
2095 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2096 | type = nla_get_u32(info->attrs[idx]); | |
2097 | ||
2098 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2099 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2100 | return -EINVAL; | |
98d2ff8b JO |
2101 | |
2102 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2103 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2104 | mbm = nla_get_u32(info->attrs[idx]); | |
2105 | } | |
2106 | ||
c8442118 | 2107 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2108 | if (result) |
7f2b8562 | 2109 | return result; |
98d2ff8b JO |
2110 | } |
2111 | ||
afe0cbf8 BR |
2112 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2113 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2114 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2115 | if ((!rdev->wiphy.available_antennas_tx && |
2116 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2117 | !rdev->ops->set_antenna) |
2118 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2119 | |
2120 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2121 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2122 | ||
a7ffac95 | 2123 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2124 | * available antenna masks, except for the "all" mask */ |
2125 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2126 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2127 | return -EINVAL; | |
a7ffac95 | 2128 | |
7f531e03 BR |
2129 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2130 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2131 | |
e35e4d28 | 2132 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2133 | if (result) |
7f2b8562 | 2134 | return result; |
afe0cbf8 BR |
2135 | } |
2136 | ||
b9a5f8ca JM |
2137 | changed = 0; |
2138 | ||
2139 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2140 | retry_short = nla_get_u8( | |
2141 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2142 | if (retry_short == 0) |
2143 | return -EINVAL; | |
2144 | ||
b9a5f8ca JM |
2145 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2146 | } | |
2147 | ||
2148 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2149 | retry_long = nla_get_u8( | |
2150 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2151 | if (retry_long == 0) |
2152 | return -EINVAL; | |
2153 | ||
b9a5f8ca JM |
2154 | changed |= WIPHY_PARAM_RETRY_LONG; |
2155 | } | |
2156 | ||
2157 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2158 | frag_threshold = nla_get_u32( | |
2159 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2160 | if (frag_threshold < 256) |
2161 | return -EINVAL; | |
2162 | ||
b9a5f8ca JM |
2163 | if (frag_threshold != (u32) -1) { |
2164 | /* | |
2165 | * Fragments (apart from the last one) are required to | |
2166 | * have even length. Make the fragmentation code | |
2167 | * simpler by stripping LSB should someone try to use | |
2168 | * odd threshold value. | |
2169 | */ | |
2170 | frag_threshold &= ~0x1; | |
2171 | } | |
2172 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2173 | } | |
2174 | ||
2175 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2176 | rts_threshold = nla_get_u32( | |
2177 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2178 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2179 | } | |
2180 | ||
81077e82 LT |
2181 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2182 | coverage_class = nla_get_u8( | |
2183 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2184 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2185 | } | |
2186 | ||
b9a5f8ca JM |
2187 | if (changed) { |
2188 | u8 old_retry_short, old_retry_long; | |
2189 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2190 | u8 old_coverage_class; |
b9a5f8ca | 2191 | |
7f2b8562 YX |
2192 | if (!rdev->ops->set_wiphy_params) |
2193 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2194 | |
2195 | old_retry_short = rdev->wiphy.retry_short; | |
2196 | old_retry_long = rdev->wiphy.retry_long; | |
2197 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2198 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2199 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2200 | |
2201 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2202 | rdev->wiphy.retry_short = retry_short; | |
2203 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2204 | rdev->wiphy.retry_long = retry_long; | |
2205 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2206 | rdev->wiphy.frag_threshold = frag_threshold; | |
2207 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2208 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2209 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2210 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2211 | |
e35e4d28 | 2212 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2213 | if (result) { |
2214 | rdev->wiphy.retry_short = old_retry_short; | |
2215 | rdev->wiphy.retry_long = old_retry_long; | |
2216 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2217 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2218 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2219 | } |
2220 | } | |
7f2b8562 | 2221 | return 0; |
55682965 JB |
2222 | } |
2223 | ||
71bbc994 JB |
2224 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2225 | { | |
2226 | return (u64)wdev->identifier | | |
2227 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2228 | } | |
55682965 | 2229 | |
683b6d3b | 2230 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2231 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2232 | { |
9f5e8f6e | 2233 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2234 | |
683b6d3b JB |
2235 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2236 | chandef->chan->center_freq)) | |
2237 | return -ENOBUFS; | |
3d9d1d66 JB |
2238 | switch (chandef->width) { |
2239 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2240 | case NL80211_CHAN_WIDTH_20: | |
2241 | case NL80211_CHAN_WIDTH_40: | |
2242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2243 | cfg80211_get_chandef_type(chandef))) | |
2244 | return -ENOBUFS; | |
2245 | break; | |
2246 | default: | |
2247 | break; | |
2248 | } | |
2249 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2250 | return -ENOBUFS; | |
2251 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2252 | return -ENOBUFS; | |
2253 | if (chandef->center_freq2 && | |
2254 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2255 | return -ENOBUFS; |
2256 | return 0; | |
2257 | } | |
2258 | ||
15e47304 | 2259 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2260 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2261 | struct wireless_dev *wdev) |
55682965 | 2262 | { |
72fb2abc | 2263 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2264 | void *hdr; |
2265 | ||
15e47304 | 2266 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2267 | if (!hdr) |
2268 | return -1; | |
2269 | ||
72fb2abc JB |
2270 | if (dev && |
2271 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2272 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2273 | goto nla_put_failure; |
2274 | ||
2275 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2276 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2277 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2278 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2279 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2280 | rdev->devlist_generation ^ | |
2281 | (cfg80211_rdev_list_generation << 2))) | |
2282 | goto nla_put_failure; | |
f5ea9120 | 2283 | |
5b7ccaf3 | 2284 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2285 | int ret; |
2286 | struct cfg80211_chan_def chandef; | |
2287 | ||
2288 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2289 | if (ret == 0) { | |
2290 | if (nl80211_send_chandef(msg, &chandef)) | |
2291 | goto nla_put_failure; | |
2292 | } | |
d91df0e3 PF |
2293 | } |
2294 | ||
b84e7a05 AQ |
2295 | if (wdev->ssid_len) { |
2296 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2297 | goto nla_put_failure; | |
2298 | } | |
2299 | ||
55682965 JB |
2300 | return genlmsg_end(msg, hdr); |
2301 | ||
2302 | nla_put_failure: | |
bc3ed28c TG |
2303 | genlmsg_cancel(msg, hdr); |
2304 | return -EMSGSIZE; | |
55682965 JB |
2305 | } |
2306 | ||
2307 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2308 | { | |
2309 | int wp_idx = 0; | |
2310 | int if_idx = 0; | |
2311 | int wp_start = cb->args[0]; | |
2312 | int if_start = cb->args[1]; | |
f5ea9120 | 2313 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2314 | struct wireless_dev *wdev; |
2315 | ||
5fe231e8 | 2316 | rtnl_lock(); |
f5ea9120 JB |
2317 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2318 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2319 | continue; |
bba95fef JB |
2320 | if (wp_idx < wp_start) { |
2321 | wp_idx++; | |
55682965 | 2322 | continue; |
bba95fef | 2323 | } |
55682965 JB |
2324 | if_idx = 0; |
2325 | ||
89a54e48 | 2326 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2327 | if (if_idx < if_start) { |
2328 | if_idx++; | |
55682965 | 2329 | continue; |
bba95fef | 2330 | } |
15e47304 | 2331 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2332 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2333 | rdev, wdev) < 0) { |
bba95fef JB |
2334 | goto out; |
2335 | } | |
2336 | if_idx++; | |
55682965 | 2337 | } |
bba95fef JB |
2338 | |
2339 | wp_idx++; | |
55682965 | 2340 | } |
bba95fef | 2341 | out: |
5fe231e8 | 2342 | rtnl_unlock(); |
55682965 JB |
2343 | |
2344 | cb->args[0] = wp_idx; | |
2345 | cb->args[1] = if_idx; | |
2346 | ||
2347 | return skb->len; | |
2348 | } | |
2349 | ||
2350 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2351 | { | |
2352 | struct sk_buff *msg; | |
4c476991 | 2353 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2354 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2355 | |
fd2120ca | 2356 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2357 | if (!msg) |
4c476991 | 2358 | return -ENOMEM; |
55682965 | 2359 | |
15e47304 | 2360 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2361 | dev, wdev) < 0) { |
4c476991 JB |
2362 | nlmsg_free(msg); |
2363 | return -ENOBUFS; | |
2364 | } | |
55682965 | 2365 | |
134e6375 | 2366 | return genlmsg_reply(msg, info); |
55682965 JB |
2367 | } |
2368 | ||
66f7ac50 MW |
2369 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2370 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2371 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2372 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2373 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2374 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2375 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2376 | }; |
2377 | ||
2378 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2379 | { | |
2380 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2381 | int flag; | |
2382 | ||
2383 | *mntrflags = 0; | |
2384 | ||
2385 | if (!nla) | |
2386 | return -EINVAL; | |
2387 | ||
2388 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2389 | nla, mntr_flags_policy)) | |
2390 | return -EINVAL; | |
2391 | ||
2392 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2393 | if (flags[flag]) | |
2394 | *mntrflags |= (1<<flag); | |
2395 | ||
2396 | return 0; | |
2397 | } | |
2398 | ||
9bc383de | 2399 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2400 | struct net_device *netdev, u8 use_4addr, |
2401 | enum nl80211_iftype iftype) | |
9bc383de | 2402 | { |
ad4bb6f8 | 2403 | if (!use_4addr) { |
f350a0a8 | 2404 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2405 | return -EBUSY; |
9bc383de | 2406 | return 0; |
ad4bb6f8 | 2407 | } |
9bc383de JB |
2408 | |
2409 | switch (iftype) { | |
2410 | case NL80211_IFTYPE_AP_VLAN: | |
2411 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2412 | return 0; | |
2413 | break; | |
2414 | case NL80211_IFTYPE_STATION: | |
2415 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2416 | return 0; | |
2417 | break; | |
2418 | default: | |
2419 | break; | |
2420 | } | |
2421 | ||
2422 | return -EOPNOTSUPP; | |
2423 | } | |
2424 | ||
55682965 JB |
2425 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2426 | { | |
4c476991 | 2427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2428 | struct vif_params params; |
e36d56b6 | 2429 | int err; |
04a773ad | 2430 | enum nl80211_iftype otype, ntype; |
4c476991 | 2431 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2432 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2433 | bool change = false; |
55682965 | 2434 | |
2ec600d6 LCC |
2435 | memset(¶ms, 0, sizeof(params)); |
2436 | ||
04a773ad | 2437 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2438 | |
723b038d | 2439 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2440 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2441 | if (otype != ntype) |
ac7f9cfa | 2442 | change = true; |
4c476991 JB |
2443 | if (ntype > NL80211_IFTYPE_MAX) |
2444 | return -EINVAL; | |
723b038d JB |
2445 | } |
2446 | ||
92ffe055 | 2447 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2448 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2449 | ||
4c476991 JB |
2450 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2451 | return -EINVAL; | |
29cbe68c JB |
2452 | if (netif_running(dev)) |
2453 | return -EBUSY; | |
2454 | ||
2455 | wdev_lock(wdev); | |
2456 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2457 | IEEE80211_MAX_MESH_ID_LEN); | |
2458 | wdev->mesh_id_up_len = | |
2459 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2460 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2461 | wdev->mesh_id_up_len); | |
2462 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2463 | } |
2464 | ||
8b787643 FF |
2465 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2466 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2467 | change = true; | |
ad4bb6f8 | 2468 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2469 | if (err) |
4c476991 | 2470 | return err; |
8b787643 FF |
2471 | } else { |
2472 | params.use_4addr = -1; | |
2473 | } | |
2474 | ||
92ffe055 | 2475 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2476 | if (ntype != NL80211_IFTYPE_MONITOR) |
2477 | return -EINVAL; | |
92ffe055 JB |
2478 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2479 | &_flags); | |
ac7f9cfa | 2480 | if (err) |
4c476991 | 2481 | return err; |
ac7f9cfa JB |
2482 | |
2483 | flags = &_flags; | |
2484 | change = true; | |
92ffe055 | 2485 | } |
3b85875a | 2486 | |
18003297 | 2487 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2488 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2489 | return -EOPNOTSUPP; | |
2490 | ||
ac7f9cfa | 2491 | if (change) |
3d54d255 | 2492 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2493 | else |
2494 | err = 0; | |
60719ffd | 2495 | |
9bc383de JB |
2496 | if (!err && params.use_4addr != -1) |
2497 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2498 | ||
55682965 JB |
2499 | return err; |
2500 | } | |
2501 | ||
2502 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2503 | { | |
4c476991 | 2504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2505 | struct vif_params params; |
84efbb84 | 2506 | struct wireless_dev *wdev; |
1c90f9d4 | 2507 | struct sk_buff *msg; |
55682965 JB |
2508 | int err; |
2509 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2510 | u32 flags; |
55682965 | 2511 | |
2ec600d6 LCC |
2512 | memset(¶ms, 0, sizeof(params)); |
2513 | ||
55682965 JB |
2514 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2515 | return -EINVAL; | |
2516 | ||
2517 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2518 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2519 | if (type > NL80211_IFTYPE_MAX) | |
2520 | return -EINVAL; | |
2521 | } | |
2522 | ||
79c97e97 | 2523 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2524 | !(rdev->wiphy.interface_modes & (1 << type))) |
2525 | return -EOPNOTSUPP; | |
55682965 | 2526 | |
1c18f145 AS |
2527 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2528 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2529 | ETH_ALEN); | |
2530 | if (!is_valid_ether_addr(params.macaddr)) | |
2531 | return -EADDRNOTAVAIL; | |
2532 | } | |
2533 | ||
9bc383de | 2534 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2535 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2536 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2537 | if (err) |
4c476991 | 2538 | return err; |
9bc383de | 2539 | } |
8b787643 | 2540 | |
1c90f9d4 JB |
2541 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2542 | if (!msg) | |
2543 | return -ENOMEM; | |
2544 | ||
66f7ac50 MW |
2545 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2546 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2547 | &flags); | |
e057d3c3 | 2548 | |
18003297 | 2549 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2550 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2551 | return -EOPNOTSUPP; | |
2552 | ||
e35e4d28 HG |
2553 | wdev = rdev_add_virtual_intf(rdev, |
2554 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2555 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2556 | if (IS_ERR(wdev)) { |
2557 | nlmsg_free(msg); | |
84efbb84 | 2558 | return PTR_ERR(wdev); |
1c90f9d4 | 2559 | } |
2ec600d6 | 2560 | |
98104fde JB |
2561 | switch (type) { |
2562 | case NL80211_IFTYPE_MESH_POINT: | |
2563 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2564 | break; | |
29cbe68c JB |
2565 | wdev_lock(wdev); |
2566 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2567 | IEEE80211_MAX_MESH_ID_LEN); | |
2568 | wdev->mesh_id_up_len = | |
2569 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2570 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2571 | wdev->mesh_id_up_len); | |
2572 | wdev_unlock(wdev); | |
98104fde JB |
2573 | break; |
2574 | case NL80211_IFTYPE_P2P_DEVICE: | |
2575 | /* | |
2576 | * P2P Device doesn't have a netdev, so doesn't go | |
2577 | * through the netdev notifier and must be added here | |
2578 | */ | |
2579 | mutex_init(&wdev->mtx); | |
2580 | INIT_LIST_HEAD(&wdev->event_list); | |
2581 | spin_lock_init(&wdev->event_lock); | |
2582 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2583 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2584 | ||
98104fde JB |
2585 | wdev->identifier = ++rdev->wdev_id; |
2586 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2587 | rdev->devlist_generation++; | |
98104fde JB |
2588 | break; |
2589 | default: | |
2590 | break; | |
29cbe68c JB |
2591 | } |
2592 | ||
15e47304 | 2593 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2594 | rdev, wdev) < 0) { |
2595 | nlmsg_free(msg); | |
2596 | return -ENOBUFS; | |
2597 | } | |
2598 | ||
2599 | return genlmsg_reply(msg, info); | |
55682965 JB |
2600 | } |
2601 | ||
2602 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2603 | { | |
4c476991 | 2604 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2605 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2606 | |
4c476991 JB |
2607 | if (!rdev->ops->del_virtual_intf) |
2608 | return -EOPNOTSUPP; | |
55682965 | 2609 | |
84efbb84 JB |
2610 | /* |
2611 | * If we remove a wireless device without a netdev then clear | |
2612 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2613 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2614 | * since the wdev has been freed, unlike with a netdev where | |
2615 | * we need the dev_put() for the netdev to really be freed. | |
2616 | */ | |
2617 | if (!wdev->netdev) | |
2618 | info->user_ptr[1] = NULL; | |
2619 | ||
e35e4d28 | 2620 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2621 | } |
2622 | ||
1d9d9213 SW |
2623 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2624 | { | |
2625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2626 | struct net_device *dev = info->user_ptr[1]; | |
2627 | u16 noack_map; | |
2628 | ||
2629 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2630 | return -EINVAL; | |
2631 | ||
2632 | if (!rdev->ops->set_noack_map) | |
2633 | return -EOPNOTSUPP; | |
2634 | ||
2635 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2636 | ||
e35e4d28 | 2637 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2638 | } |
2639 | ||
41ade00f JB |
2640 | struct get_key_cookie { |
2641 | struct sk_buff *msg; | |
2642 | int error; | |
b9454e83 | 2643 | int idx; |
41ade00f JB |
2644 | }; |
2645 | ||
2646 | static void get_key_callback(void *c, struct key_params *params) | |
2647 | { | |
b9454e83 | 2648 | struct nlattr *key; |
41ade00f JB |
2649 | struct get_key_cookie *cookie = c; |
2650 | ||
9360ffd1 DM |
2651 | if ((params->key && |
2652 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2653 | params->key_len, params->key)) || | |
2654 | (params->seq && | |
2655 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2656 | params->seq_len, params->seq)) || | |
2657 | (params->cipher && | |
2658 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2659 | params->cipher))) | |
2660 | goto nla_put_failure; | |
41ade00f | 2661 | |
b9454e83 JB |
2662 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2663 | if (!key) | |
2664 | goto nla_put_failure; | |
2665 | ||
9360ffd1 DM |
2666 | if ((params->key && |
2667 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2668 | params->key_len, params->key)) || | |
2669 | (params->seq && | |
2670 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2671 | params->seq_len, params->seq)) || | |
2672 | (params->cipher && | |
2673 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2674 | params->cipher))) | |
2675 | goto nla_put_failure; | |
b9454e83 | 2676 | |
9360ffd1 DM |
2677 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2678 | goto nla_put_failure; | |
b9454e83 JB |
2679 | |
2680 | nla_nest_end(cookie->msg, key); | |
2681 | ||
41ade00f JB |
2682 | return; |
2683 | nla_put_failure: | |
2684 | cookie->error = 1; | |
2685 | } | |
2686 | ||
2687 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2688 | { | |
4c476991 | 2689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2690 | int err; |
4c476991 | 2691 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2692 | u8 key_idx = 0; |
e31b8213 JB |
2693 | const u8 *mac_addr = NULL; |
2694 | bool pairwise; | |
41ade00f JB |
2695 | struct get_key_cookie cookie = { |
2696 | .error = 0, | |
2697 | }; | |
2698 | void *hdr; | |
2699 | struct sk_buff *msg; | |
2700 | ||
2701 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2702 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2703 | ||
3cfcf6ac | 2704 | if (key_idx > 5) |
41ade00f JB |
2705 | return -EINVAL; |
2706 | ||
2707 | if (info->attrs[NL80211_ATTR_MAC]) | |
2708 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2709 | ||
e31b8213 JB |
2710 | pairwise = !!mac_addr; |
2711 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2712 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2713 | if (kt >= NUM_NL80211_KEYTYPES) | |
2714 | return -EINVAL; | |
2715 | if (kt != NL80211_KEYTYPE_GROUP && | |
2716 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2717 | return -EINVAL; | |
2718 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2719 | } | |
2720 | ||
4c476991 JB |
2721 | if (!rdev->ops->get_key) |
2722 | return -EOPNOTSUPP; | |
41ade00f | 2723 | |
fd2120ca | 2724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2725 | if (!msg) |
2726 | return -ENOMEM; | |
41ade00f | 2727 | |
15e47304 | 2728 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2729 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2730 | if (!hdr) |
9fe271af | 2731 | goto nla_put_failure; |
41ade00f JB |
2732 | |
2733 | cookie.msg = msg; | |
b9454e83 | 2734 | cookie.idx = key_idx; |
41ade00f | 2735 | |
9360ffd1 DM |
2736 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2737 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2738 | goto nla_put_failure; | |
2739 | if (mac_addr && | |
2740 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2741 | goto nla_put_failure; | |
41ade00f | 2742 | |
e31b8213 JB |
2743 | if (pairwise && mac_addr && |
2744 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2745 | return -ENOENT; | |
2746 | ||
e35e4d28 HG |
2747 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2748 | get_key_callback); | |
41ade00f JB |
2749 | |
2750 | if (err) | |
6c95e2a2 | 2751 | goto free_msg; |
41ade00f JB |
2752 | |
2753 | if (cookie.error) | |
2754 | goto nla_put_failure; | |
2755 | ||
2756 | genlmsg_end(msg, hdr); | |
4c476991 | 2757 | return genlmsg_reply(msg, info); |
41ade00f JB |
2758 | |
2759 | nla_put_failure: | |
2760 | err = -ENOBUFS; | |
6c95e2a2 | 2761 | free_msg: |
41ade00f | 2762 | nlmsg_free(msg); |
41ade00f JB |
2763 | return err; |
2764 | } | |
2765 | ||
2766 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2767 | { | |
4c476991 | 2768 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2769 | struct key_parse key; |
41ade00f | 2770 | int err; |
4c476991 | 2771 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2772 | |
b9454e83 JB |
2773 | err = nl80211_parse_key(info, &key); |
2774 | if (err) | |
2775 | return err; | |
41ade00f | 2776 | |
b9454e83 | 2777 | if (key.idx < 0) |
41ade00f JB |
2778 | return -EINVAL; |
2779 | ||
b9454e83 JB |
2780 | /* only support setting default key */ |
2781 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2782 | return -EINVAL; |
2783 | ||
dbd2fd65 | 2784 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2785 | |
dbd2fd65 JB |
2786 | if (key.def) { |
2787 | if (!rdev->ops->set_default_key) { | |
2788 | err = -EOPNOTSUPP; | |
2789 | goto out; | |
2790 | } | |
41ade00f | 2791 | |
dbd2fd65 JB |
2792 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2793 | if (err) | |
2794 | goto out; | |
2795 | ||
e35e4d28 | 2796 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2797 | key.def_uni, key.def_multi); |
2798 | ||
2799 | if (err) | |
2800 | goto out; | |
fffd0934 | 2801 | |
3d23e349 | 2802 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2803 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2804 | #endif | |
2805 | } else { | |
2806 | if (key.def_uni || !key.def_multi) { | |
2807 | err = -EINVAL; | |
2808 | goto out; | |
2809 | } | |
2810 | ||
2811 | if (!rdev->ops->set_default_mgmt_key) { | |
2812 | err = -EOPNOTSUPP; | |
2813 | goto out; | |
2814 | } | |
2815 | ||
2816 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2817 | if (err) | |
2818 | goto out; | |
2819 | ||
e35e4d28 | 2820 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2821 | if (err) |
2822 | goto out; | |
2823 | ||
2824 | #ifdef CONFIG_CFG80211_WEXT | |
2825 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2826 | #endif |
dbd2fd65 JB |
2827 | } |
2828 | ||
2829 | out: | |
fffd0934 | 2830 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2831 | |
41ade00f JB |
2832 | return err; |
2833 | } | |
2834 | ||
2835 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2836 | { | |
4c476991 | 2837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2838 | int err; |
4c476991 | 2839 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2840 | struct key_parse key; |
e31b8213 | 2841 | const u8 *mac_addr = NULL; |
41ade00f | 2842 | |
b9454e83 JB |
2843 | err = nl80211_parse_key(info, &key); |
2844 | if (err) | |
2845 | return err; | |
41ade00f | 2846 | |
b9454e83 | 2847 | if (!key.p.key) |
41ade00f JB |
2848 | return -EINVAL; |
2849 | ||
41ade00f JB |
2850 | if (info->attrs[NL80211_ATTR_MAC]) |
2851 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2852 | ||
e31b8213 JB |
2853 | if (key.type == -1) { |
2854 | if (mac_addr) | |
2855 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2856 | else | |
2857 | key.type = NL80211_KEYTYPE_GROUP; | |
2858 | } | |
2859 | ||
2860 | /* for now */ | |
2861 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2862 | key.type != NL80211_KEYTYPE_GROUP) | |
2863 | return -EINVAL; | |
2864 | ||
4c476991 JB |
2865 | if (!rdev->ops->add_key) |
2866 | return -EOPNOTSUPP; | |
25e47c18 | 2867 | |
e31b8213 JB |
2868 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2869 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2870 | mac_addr)) | |
4c476991 | 2871 | return -EINVAL; |
41ade00f | 2872 | |
fffd0934 JB |
2873 | wdev_lock(dev->ieee80211_ptr); |
2874 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2875 | if (!err) | |
e35e4d28 HG |
2876 | err = rdev_add_key(rdev, dev, key.idx, |
2877 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2878 | mac_addr, &key.p); | |
fffd0934 | 2879 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2880 | |
41ade00f JB |
2881 | return err; |
2882 | } | |
2883 | ||
2884 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2885 | { | |
4c476991 | 2886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2887 | int err; |
4c476991 | 2888 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2889 | u8 *mac_addr = NULL; |
b9454e83 | 2890 | struct key_parse key; |
41ade00f | 2891 | |
b9454e83 JB |
2892 | err = nl80211_parse_key(info, &key); |
2893 | if (err) | |
2894 | return err; | |
41ade00f JB |
2895 | |
2896 | if (info->attrs[NL80211_ATTR_MAC]) | |
2897 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2898 | ||
e31b8213 JB |
2899 | if (key.type == -1) { |
2900 | if (mac_addr) | |
2901 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2902 | else | |
2903 | key.type = NL80211_KEYTYPE_GROUP; | |
2904 | } | |
2905 | ||
2906 | /* for now */ | |
2907 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2908 | key.type != NL80211_KEYTYPE_GROUP) | |
2909 | return -EINVAL; | |
2910 | ||
4c476991 JB |
2911 | if (!rdev->ops->del_key) |
2912 | return -EOPNOTSUPP; | |
41ade00f | 2913 | |
fffd0934 JB |
2914 | wdev_lock(dev->ieee80211_ptr); |
2915 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2916 | |
2917 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2918 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2919 | err = -ENOENT; | |
2920 | ||
fffd0934 | 2921 | if (!err) |
e35e4d28 HG |
2922 | err = rdev_del_key(rdev, dev, key.idx, |
2923 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2924 | mac_addr); | |
41ade00f | 2925 | |
3d23e349 | 2926 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2927 | if (!err) { |
b9454e83 | 2928 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2929 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2930 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2931 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2932 | } | |
2933 | #endif | |
fffd0934 | 2934 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2935 | |
41ade00f JB |
2936 | return err; |
2937 | } | |
2938 | ||
77765eaf VT |
2939 | /* This function returns an error or the number of nested attributes */ |
2940 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2941 | { | |
2942 | struct nlattr *attr; | |
2943 | int n_entries = 0, tmp; | |
2944 | ||
2945 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2946 | if (nla_len(attr) != ETH_ALEN) | |
2947 | return -EINVAL; | |
2948 | ||
2949 | n_entries++; | |
2950 | } | |
2951 | ||
2952 | return n_entries; | |
2953 | } | |
2954 | ||
2955 | /* | |
2956 | * This function parses ACL information and allocates memory for ACL data. | |
2957 | * On successful return, the calling function is responsible to free the | |
2958 | * ACL buffer returned by this function. | |
2959 | */ | |
2960 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2961 | struct genl_info *info) | |
2962 | { | |
2963 | enum nl80211_acl_policy acl_policy; | |
2964 | struct nlattr *attr; | |
2965 | struct cfg80211_acl_data *acl; | |
2966 | int i = 0, n_entries, tmp; | |
2967 | ||
2968 | if (!wiphy->max_acl_mac_addrs) | |
2969 | return ERR_PTR(-EOPNOTSUPP); | |
2970 | ||
2971 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2972 | return ERR_PTR(-EINVAL); | |
2973 | ||
2974 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2975 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2976 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2977 | return ERR_PTR(-EINVAL); | |
2978 | ||
2979 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2980 | return ERR_PTR(-EINVAL); | |
2981 | ||
2982 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2983 | if (n_entries < 0) | |
2984 | return ERR_PTR(n_entries); | |
2985 | ||
2986 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2987 | return ERR_PTR(-ENOTSUPP); | |
2988 | ||
2989 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2990 | GFP_KERNEL); | |
2991 | if (!acl) | |
2992 | return ERR_PTR(-ENOMEM); | |
2993 | ||
2994 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2995 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2996 | i++; | |
2997 | } | |
2998 | ||
2999 | acl->n_acl_entries = n_entries; | |
3000 | acl->acl_policy = acl_policy; | |
3001 | ||
3002 | return acl; | |
3003 | } | |
3004 | ||
3005 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3006 | { | |
3007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3008 | struct net_device *dev = info->user_ptr[1]; | |
3009 | struct cfg80211_acl_data *acl; | |
3010 | int err; | |
3011 | ||
3012 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3013 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3014 | return -EOPNOTSUPP; | |
3015 | ||
3016 | if (!dev->ieee80211_ptr->beacon_interval) | |
3017 | return -EINVAL; | |
3018 | ||
3019 | acl = parse_acl_data(&rdev->wiphy, info); | |
3020 | if (IS_ERR(acl)) | |
3021 | return PTR_ERR(acl); | |
3022 | ||
3023 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3024 | ||
3025 | kfree(acl); | |
3026 | ||
3027 | return err; | |
3028 | } | |
3029 | ||
a1193be8 | 3030 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3031 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3032 | { |
8860020e | 3033 | bool haveinfo = false; |
ed1b6cc7 | 3034 | |
a1193be8 SW |
3035 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3036 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3037 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3038 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3039 | return -EINVAL; |
3040 | ||
8860020e | 3041 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3042 | |
a1193be8 SW |
3043 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3044 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3045 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3046 | if (!bcn->head_len) |
3047 | return -EINVAL; | |
3048 | haveinfo = true; | |
ed1b6cc7 JB |
3049 | } |
3050 | ||
a1193be8 SW |
3051 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3052 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3053 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3054 | haveinfo = true; |
ed1b6cc7 JB |
3055 | } |
3056 | ||
4c476991 JB |
3057 | if (!haveinfo) |
3058 | return -EINVAL; | |
3b85875a | 3059 | |
a1193be8 SW |
3060 | if (attrs[NL80211_ATTR_IE]) { |
3061 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3062 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3063 | } |
3064 | ||
a1193be8 | 3065 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3066 | bcn->proberesp_ies = |
a1193be8 | 3067 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3068 | bcn->proberesp_ies_len = |
a1193be8 | 3069 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3070 | } |
3071 | ||
a1193be8 | 3072 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3073 | bcn->assocresp_ies = |
a1193be8 | 3074 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3075 | bcn->assocresp_ies_len = |
a1193be8 | 3076 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3077 | } |
3078 | ||
a1193be8 SW |
3079 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3080 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3081 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3082 | } |
3083 | ||
8860020e JB |
3084 | return 0; |
3085 | } | |
3086 | ||
46c1dd0c FF |
3087 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3088 | struct cfg80211_ap_settings *params) | |
3089 | { | |
3090 | struct wireless_dev *wdev; | |
3091 | bool ret = false; | |
3092 | ||
89a54e48 | 3093 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3094 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3095 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3096 | continue; | |
3097 | ||
683b6d3b | 3098 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3099 | continue; |
3100 | ||
683b6d3b | 3101 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3102 | ret = true; |
3103 | break; | |
3104 | } | |
3105 | ||
46c1dd0c FF |
3106 | return ret; |
3107 | } | |
3108 | ||
e39e5b5e JM |
3109 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3110 | enum nl80211_auth_type auth_type, | |
3111 | enum nl80211_commands cmd) | |
3112 | { | |
3113 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3114 | return false; | |
3115 | ||
3116 | switch (cmd) { | |
3117 | case NL80211_CMD_AUTHENTICATE: | |
3118 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3119 | auth_type == NL80211_AUTHTYPE_SAE) | |
3120 | return false; | |
3121 | return true; | |
3122 | case NL80211_CMD_CONNECT: | |
3123 | case NL80211_CMD_START_AP: | |
3124 | /* SAE not supported yet */ | |
3125 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3126 | return false; | |
3127 | return true; | |
3128 | default: | |
3129 | return false; | |
3130 | } | |
3131 | } | |
3132 | ||
8860020e JB |
3133 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3134 | { | |
3135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3136 | struct net_device *dev = info->user_ptr[1]; | |
3137 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3138 | struct cfg80211_ap_settings params; | |
3139 | int err; | |
04f39047 | 3140 | u8 radar_detect_width = 0; |
8860020e JB |
3141 | |
3142 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3143 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3144 | return -EOPNOTSUPP; | |
3145 | ||
3146 | if (!rdev->ops->start_ap) | |
3147 | return -EOPNOTSUPP; | |
3148 | ||
3149 | if (wdev->beacon_interval) | |
3150 | return -EALREADY; | |
3151 | ||
3152 | memset(¶ms, 0, sizeof(params)); | |
3153 | ||
3154 | /* these are required for START_AP */ | |
3155 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3156 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3157 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3158 | return -EINVAL; | |
3159 | ||
a1193be8 | 3160 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3161 | if (err) |
3162 | return err; | |
3163 | ||
3164 | params.beacon_interval = | |
3165 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3166 | params.dtim_period = | |
3167 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3168 | ||
3169 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3170 | if (err) | |
3171 | return err; | |
3172 | ||
3173 | /* | |
3174 | * In theory, some of these attributes should be required here | |
3175 | * but since they were not used when the command was originally | |
3176 | * added, keep them optional for old user space programs to let | |
3177 | * them continue to work with drivers that do not need the | |
3178 | * additional information -- drivers must check! | |
3179 | */ | |
3180 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3181 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3182 | params.ssid_len = | |
3183 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3184 | if (params.ssid_len == 0 || | |
3185 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3186 | return -EINVAL; | |
3187 | } | |
3188 | ||
3189 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3190 | params.hidden_ssid = nla_get_u32( | |
3191 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3192 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3193 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3194 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3195 | return -EINVAL; | |
3196 | } | |
3197 | ||
3198 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3199 | ||
3200 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3201 | params.auth_type = nla_get_u32( | |
3202 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3203 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3204 | NL80211_CMD_START_AP)) | |
8860020e JB |
3205 | return -EINVAL; |
3206 | } else | |
3207 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3208 | ||
3209 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3210 | NL80211_MAX_NR_CIPHER_SUITES); | |
3211 | if (err) | |
3212 | return err; | |
3213 | ||
1b658f11 VT |
3214 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3215 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3216 | return -EOPNOTSUPP; | |
3217 | params.inactivity_timeout = nla_get_u16( | |
3218 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3219 | } | |
3220 | ||
53cabad7 JB |
3221 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3222 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3223 | return -EINVAL; | |
3224 | params.p2p_ctwindow = | |
3225 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3226 | if (params.p2p_ctwindow > 127) | |
3227 | return -EINVAL; | |
3228 | if (params.p2p_ctwindow != 0 && | |
3229 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3230 | return -EINVAL; | |
3231 | } | |
3232 | ||
3233 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3234 | u8 tmp; | |
3235 | ||
3236 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3237 | return -EINVAL; | |
3238 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3239 | if (tmp > 1) | |
3240 | return -EINVAL; | |
3241 | params.p2p_opp_ps = tmp; | |
3242 | if (params.p2p_opp_ps != 0 && | |
3243 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3244 | return -EINVAL; | |
3245 | } | |
3246 | ||
aa430da4 | 3247 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3248 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3249 | if (err) | |
3250 | return err; | |
3251 | } else if (wdev->preset_chandef.chan) { | |
3252 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3253 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3254 | return -EINVAL; |
3255 | ||
683b6d3b | 3256 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3257 | return -EINVAL; |
3258 | ||
04f39047 SW |
3259 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3260 | if (err < 0) | |
3261 | return err; | |
3262 | if (err) { | |
3263 | radar_detect_width = BIT(params.chandef.width); | |
3264 | params.radar_required = true; | |
3265 | } | |
3266 | ||
04f39047 SW |
3267 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3268 | params.chandef.chan, | |
3269 | CHAN_MODE_SHARED, | |
3270 | radar_detect_width); | |
e4e32459 MK |
3271 | if (err) |
3272 | return err; | |
3273 | ||
77765eaf VT |
3274 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3275 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3276 | if (IS_ERR(params.acl)) | |
3277 | return PTR_ERR(params.acl); | |
3278 | } | |
3279 | ||
c56589ed | 3280 | wdev_lock(wdev); |
e35e4d28 | 3281 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3282 | if (!err) { |
683b6d3b | 3283 | wdev->preset_chandef = params.chandef; |
8860020e | 3284 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3285 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3286 | wdev->ssid_len = params.ssid_len; |
3287 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3288 | } |
c56589ed | 3289 | wdev_unlock(wdev); |
77765eaf VT |
3290 | |
3291 | kfree(params.acl); | |
3292 | ||
56d1893d | 3293 | return err; |
ed1b6cc7 JB |
3294 | } |
3295 | ||
8860020e JB |
3296 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3297 | { | |
3298 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3299 | struct net_device *dev = info->user_ptr[1]; | |
3300 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3301 | struct cfg80211_beacon_data params; | |
3302 | int err; | |
3303 | ||
3304 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3305 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3306 | return -EOPNOTSUPP; | |
3307 | ||
3308 | if (!rdev->ops->change_beacon) | |
3309 | return -EOPNOTSUPP; | |
3310 | ||
3311 | if (!wdev->beacon_interval) | |
3312 | return -EINVAL; | |
3313 | ||
a1193be8 | 3314 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3315 | if (err) |
3316 | return err; | |
3317 | ||
c56589ed SW |
3318 | wdev_lock(wdev); |
3319 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3320 | wdev_unlock(wdev); | |
3321 | ||
3322 | return err; | |
8860020e JB |
3323 | } |
3324 | ||
3325 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3326 | { |
4c476991 JB |
3327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3328 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3329 | |
60771780 | 3330 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3331 | } |
3332 | ||
5727ef1b JB |
3333 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3334 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3335 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3336 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3337 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3338 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3339 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3340 | }; |
3341 | ||
eccb8e8f | 3342 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3343 | enum nl80211_iftype iftype, |
eccb8e8f | 3344 | struct station_parameters *params) |
5727ef1b JB |
3345 | { |
3346 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3347 | struct nlattr *nla; |
5727ef1b JB |
3348 | int flag; |
3349 | ||
eccb8e8f JB |
3350 | /* |
3351 | * Try parsing the new attribute first so userspace | |
3352 | * can specify both for older kernels. | |
3353 | */ | |
3354 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3355 | if (nla) { | |
3356 | struct nl80211_sta_flag_update *sta_flags; | |
3357 | ||
3358 | sta_flags = nla_data(nla); | |
3359 | params->sta_flags_mask = sta_flags->mask; | |
3360 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3361 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3362 | if ((params->sta_flags_mask | |
3363 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3364 | return -EINVAL; | |
3365 | return 0; | |
3366 | } | |
3367 | ||
3368 | /* if present, parse the old attribute */ | |
5727ef1b | 3369 | |
eccb8e8f | 3370 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3371 | if (!nla) |
3372 | return 0; | |
3373 | ||
3374 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3375 | nla, sta_flags_policy)) | |
3376 | return -EINVAL; | |
3377 | ||
bdd3ae3d JB |
3378 | /* |
3379 | * Only allow certain flags for interface types so that | |
3380 | * other attributes are silently ignored. Remember that | |
3381 | * this is backward compatibility code with old userspace | |
3382 | * and shouldn't be hit in other cases anyway. | |
3383 | */ | |
3384 | switch (iftype) { | |
3385 | case NL80211_IFTYPE_AP: | |
3386 | case NL80211_IFTYPE_AP_VLAN: | |
3387 | case NL80211_IFTYPE_P2P_GO: | |
3388 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3389 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3390 | BIT(NL80211_STA_FLAG_WME) | | |
3391 | BIT(NL80211_STA_FLAG_MFP); | |
3392 | break; | |
3393 | case NL80211_IFTYPE_P2P_CLIENT: | |
3394 | case NL80211_IFTYPE_STATION: | |
3395 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3396 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3397 | break; | |
3398 | case NL80211_IFTYPE_MESH_POINT: | |
3399 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3400 | BIT(NL80211_STA_FLAG_MFP) | | |
3401 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3402 | default: | |
3403 | return -EINVAL; | |
3404 | } | |
5727ef1b | 3405 | |
3383b5a6 JB |
3406 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3407 | if (flags[flag]) { | |
eccb8e8f | 3408 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3409 | |
3383b5a6 JB |
3410 | /* no longer support new API additions in old API */ |
3411 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3412 | return -EINVAL; | |
3413 | } | |
3414 | } | |
3415 | ||
5727ef1b JB |
3416 | return 0; |
3417 | } | |
3418 | ||
c8dcfd8a FF |
3419 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3420 | int attr) | |
3421 | { | |
3422 | struct nlattr *rate; | |
8eb41c8d VK |
3423 | u32 bitrate; |
3424 | u16 bitrate_compat; | |
c8dcfd8a FF |
3425 | |
3426 | rate = nla_nest_start(msg, attr); | |
3427 | if (!rate) | |
db9c64cf | 3428 | return false; |
c8dcfd8a FF |
3429 | |
3430 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3431 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3432 | /* report 16-bit bitrate only if we can */ |
3433 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3434 | if (bitrate > 0 && |
3435 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3436 | return false; | |
3437 | if (bitrate_compat > 0 && | |
3438 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3439 | return false; | |
3440 | ||
3441 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3442 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3443 | return false; | |
3444 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3445 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3446 | return false; | |
3447 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3448 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3449 | return false; | |
3450 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3451 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3452 | return false; | |
3453 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3454 | return false; | |
3455 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3456 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3457 | return false; | |
3458 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3459 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3460 | return false; | |
3461 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3462 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3463 | return false; | |
3464 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3465 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3466 | return false; | |
3467 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3468 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3469 | return false; | |
3470 | } | |
c8dcfd8a FF |
3471 | |
3472 | nla_nest_end(msg, rate); | |
3473 | return true; | |
c8dcfd8a FF |
3474 | } |
3475 | ||
119363c7 FF |
3476 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3477 | int id) | |
3478 | { | |
3479 | void *attr; | |
3480 | int i = 0; | |
3481 | ||
3482 | if (!mask) | |
3483 | return true; | |
3484 | ||
3485 | attr = nla_nest_start(msg, id); | |
3486 | if (!attr) | |
3487 | return false; | |
3488 | ||
3489 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3490 | if (!(mask & BIT(i))) | |
3491 | continue; | |
3492 | ||
3493 | if (nla_put_u8(msg, i, signal[i])) | |
3494 | return false; | |
3495 | } | |
3496 | ||
3497 | nla_nest_end(msg, attr); | |
3498 | ||
3499 | return true; | |
3500 | } | |
3501 | ||
15e47304 | 3502 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3503 | int flags, |
3504 | struct cfg80211_registered_device *rdev, | |
3505 | struct net_device *dev, | |
98b62183 | 3506 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3507 | { |
3508 | void *hdr; | |
f4263c98 | 3509 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3510 | |
15e47304 | 3511 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3512 | if (!hdr) |
3513 | return -1; | |
3514 | ||
9360ffd1 DM |
3515 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3516 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3517 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3518 | goto nla_put_failure; | |
f5ea9120 | 3519 | |
2ec600d6 LCC |
3520 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3521 | if (!sinfoattr) | |
fd5b74dc | 3522 | goto nla_put_failure; |
9360ffd1 DM |
3523 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3524 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3525 | sinfo->connected_time)) | |
3526 | goto nla_put_failure; | |
3527 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3528 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3529 | sinfo->inactive_time)) | |
3530 | goto nla_put_failure; | |
42745e03 VK |
3531 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3532 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3533 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3534 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3535 | goto nla_put_failure; |
42745e03 | 3536 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3537 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3538 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3539 | (u32)sinfo->tx_bytes)) |
3540 | goto nla_put_failure; | |
3541 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3542 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3543 | sinfo->rx_bytes)) | |
3544 | goto nla_put_failure; | |
3545 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3546 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3547 | sinfo->tx_bytes)) |
3548 | goto nla_put_failure; | |
3549 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3550 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3551 | goto nla_put_failure; | |
3552 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3553 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3554 | goto nla_put_failure; | |
3555 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3556 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3557 | sinfo->plink_state)) | |
3558 | goto nla_put_failure; | |
66266b3a JL |
3559 | switch (rdev->wiphy.signal_type) { |
3560 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3561 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3562 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3563 | sinfo->signal)) | |
3564 | goto nla_put_failure; | |
3565 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3566 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3567 | sinfo->signal_avg)) | |
3568 | goto nla_put_failure; | |
66266b3a JL |
3569 | break; |
3570 | default: | |
3571 | break; | |
3572 | } | |
119363c7 FF |
3573 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3574 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3575 | sinfo->chain_signal, | |
3576 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3577 | goto nla_put_failure; | |
3578 | } | |
3579 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3580 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3581 | sinfo->chain_signal_avg, | |
3582 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3583 | goto nla_put_failure; | |
3584 | } | |
420e7fab | 3585 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3586 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3587 | NL80211_STA_INFO_TX_BITRATE)) | |
3588 | goto nla_put_failure; | |
3589 | } | |
3590 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3591 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3592 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3593 | goto nla_put_failure; |
420e7fab | 3594 | } |
9360ffd1 DM |
3595 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3596 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3597 | sinfo->rx_packets)) | |
3598 | goto nla_put_failure; | |
3599 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3600 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3601 | sinfo->tx_packets)) | |
3602 | goto nla_put_failure; | |
3603 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3604 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3605 | sinfo->tx_retries)) | |
3606 | goto nla_put_failure; | |
3607 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3608 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3609 | sinfo->tx_failed)) | |
3610 | goto nla_put_failure; | |
3611 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3612 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3613 | sinfo->beacon_loss_count)) | |
3614 | goto nla_put_failure; | |
3b1c5a53 MP |
3615 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3616 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3617 | sinfo->local_pm)) | |
3618 | goto nla_put_failure; | |
3619 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3620 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3621 | sinfo->peer_pm)) | |
3622 | goto nla_put_failure; | |
3623 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3624 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3625 | sinfo->nonpeer_pm)) | |
3626 | goto nla_put_failure; | |
f4263c98 PS |
3627 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3628 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3629 | if (!bss_param) | |
3630 | goto nla_put_failure; | |
3631 | ||
9360ffd1 DM |
3632 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3633 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3634 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3635 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3636 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3637 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3638 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3639 | sinfo->bss_param.dtim_period) || | |
3640 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3641 | sinfo->bss_param.beacon_interval)) | |
3642 | goto nla_put_failure; | |
f4263c98 PS |
3643 | |
3644 | nla_nest_end(msg, bss_param); | |
3645 | } | |
9360ffd1 DM |
3646 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3647 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3648 | sizeof(struct nl80211_sta_flag_update), | |
3649 | &sinfo->sta_flags)) | |
3650 | goto nla_put_failure; | |
7eab0f64 JL |
3651 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3652 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3653 | sinfo->t_offset)) | |
3654 | goto nla_put_failure; | |
2ec600d6 | 3655 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3656 | |
9360ffd1 DM |
3657 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3658 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3659 | sinfo->assoc_req_ies)) | |
3660 | goto nla_put_failure; | |
50d3dfb7 | 3661 | |
fd5b74dc JB |
3662 | return genlmsg_end(msg, hdr); |
3663 | ||
3664 | nla_put_failure: | |
bc3ed28c TG |
3665 | genlmsg_cancel(msg, hdr); |
3666 | return -EMSGSIZE; | |
fd5b74dc JB |
3667 | } |
3668 | ||
2ec600d6 | 3669 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3670 | struct netlink_callback *cb) |
2ec600d6 | 3671 | { |
2ec600d6 LCC |
3672 | struct station_info sinfo; |
3673 | struct cfg80211_registered_device *dev; | |
97990a06 | 3674 | struct wireless_dev *wdev; |
2ec600d6 | 3675 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3676 | int sta_idx = cb->args[2]; |
2ec600d6 | 3677 | int err; |
2ec600d6 | 3678 | |
97990a06 | 3679 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3680 | if (err) |
3681 | return err; | |
bba95fef | 3682 | |
97990a06 JB |
3683 | if (!wdev->netdev) { |
3684 | err = -EINVAL; | |
3685 | goto out_err; | |
3686 | } | |
3687 | ||
bba95fef | 3688 | if (!dev->ops->dump_station) { |
eec60b03 | 3689 | err = -EOPNOTSUPP; |
bba95fef JB |
3690 | goto out_err; |
3691 | } | |
3692 | ||
bba95fef | 3693 | while (1) { |
f612cedf | 3694 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3695 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3696 | mac_addr, &sinfo); |
bba95fef JB |
3697 | if (err == -ENOENT) |
3698 | break; | |
3699 | if (err) | |
3b85875a | 3700 | goto out_err; |
bba95fef JB |
3701 | |
3702 | if (nl80211_send_station(skb, | |
15e47304 | 3703 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3704 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3705 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3706 | &sinfo) < 0) |
3707 | goto out; | |
3708 | ||
3709 | sta_idx++; | |
3710 | } | |
3711 | ||
3712 | ||
3713 | out: | |
97990a06 | 3714 | cb->args[2] = sta_idx; |
bba95fef | 3715 | err = skb->len; |
bba95fef | 3716 | out_err: |
97990a06 | 3717 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3718 | |
3719 | return err; | |
2ec600d6 | 3720 | } |
fd5b74dc | 3721 | |
5727ef1b JB |
3722 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3723 | { | |
4c476991 JB |
3724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3725 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3726 | struct station_info sinfo; |
fd5b74dc JB |
3727 | struct sk_buff *msg; |
3728 | u8 *mac_addr = NULL; | |
4c476991 | 3729 | int err; |
fd5b74dc | 3730 | |
2ec600d6 | 3731 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3732 | |
3733 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3734 | return -EINVAL; | |
3735 | ||
3736 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3737 | ||
4c476991 JB |
3738 | if (!rdev->ops->get_station) |
3739 | return -EOPNOTSUPP; | |
3b85875a | 3740 | |
e35e4d28 | 3741 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3742 | if (err) |
4c476991 | 3743 | return err; |
2ec600d6 | 3744 | |
fd2120ca | 3745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3746 | if (!msg) |
4c476991 | 3747 | return -ENOMEM; |
fd5b74dc | 3748 | |
15e47304 | 3749 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3750 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3751 | nlmsg_free(msg); |
3752 | return -ENOBUFS; | |
3753 | } | |
3b85875a | 3754 | |
4c476991 | 3755 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3756 | } |
3757 | ||
77ee7c89 JB |
3758 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3759 | struct station_parameters *params, | |
3760 | enum cfg80211_station_type statype) | |
3761 | { | |
3762 | if (params->listen_interval != -1) | |
3763 | return -EINVAL; | |
3764 | if (params->aid) | |
3765 | return -EINVAL; | |
3766 | ||
3767 | /* When you run into this, adjust the code below for the new flag */ | |
3768 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3769 | ||
3770 | switch (statype) { | |
eef941e6 TP |
3771 | case CFG80211_STA_MESH_PEER_KERNEL: |
3772 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3773 | /* |
3774 | * No ignoring the TDLS flag here -- the userspace mesh | |
3775 | * code doesn't have the bug of including TDLS in the | |
3776 | * mask everywhere. | |
3777 | */ | |
3778 | if (params->sta_flags_mask & | |
3779 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3780 | BIT(NL80211_STA_FLAG_MFP) | | |
3781 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3782 | return -EINVAL; | |
3783 | break; | |
3784 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3785 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3786 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3787 | return -EINVAL; | |
3788 | /* ignore since it can't change */ | |
3789 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3790 | break; | |
3791 | default: | |
3792 | /* disallow mesh-specific things */ | |
3793 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3794 | return -EINVAL; | |
3795 | if (params->local_pm) | |
3796 | return -EINVAL; | |
3797 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3798 | return -EINVAL; | |
3799 | } | |
3800 | ||
3801 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3802 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3803 | /* TDLS can't be set, ... */ | |
3804 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3805 | return -EINVAL; | |
3806 | /* | |
3807 | * ... but don't bother the driver with it. This works around | |
3808 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3809 | * TLDS_PEER flag in the mask even for AP mode. | |
3810 | */ | |
3811 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3812 | } | |
3813 | ||
3814 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3815 | /* reject other things that can't change */ | |
3816 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3817 | return -EINVAL; | |
3818 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3819 | return -EINVAL; | |
3820 | if (params->supported_rates) | |
3821 | return -EINVAL; | |
3822 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3823 | return -EINVAL; | |
3824 | } | |
3825 | ||
3826 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3827 | if (params->vlan) | |
3828 | return -EINVAL; | |
3829 | } | |
3830 | ||
3831 | switch (statype) { | |
3832 | case CFG80211_STA_AP_MLME_CLIENT: | |
3833 | /* Use this only for authorizing/unauthorizing a station */ | |
3834 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3835 | return -EOPNOTSUPP; | |
3836 | break; | |
3837 | case CFG80211_STA_AP_CLIENT: | |
3838 | /* accept only the listed bits */ | |
3839 | if (params->sta_flags_mask & | |
3840 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3841 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3842 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3843 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3844 | BIT(NL80211_STA_FLAG_WME) | | |
3845 | BIT(NL80211_STA_FLAG_MFP))) | |
3846 | return -EINVAL; | |
3847 | ||
3848 | /* but authenticated/associated only if driver handles it */ | |
3849 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3850 | params->sta_flags_mask & | |
3851 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3852 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3853 | return -EINVAL; | |
3854 | break; | |
3855 | case CFG80211_STA_IBSS: | |
3856 | case CFG80211_STA_AP_STA: | |
3857 | /* reject any changes other than AUTHORIZED */ | |
3858 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3859 | return -EINVAL; | |
3860 | break; | |
3861 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3862 | /* reject any changes other than AUTHORIZED or WME */ | |
3863 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3864 | BIT(NL80211_STA_FLAG_WME))) | |
3865 | return -EINVAL; | |
3866 | /* force (at least) rates when authorizing */ | |
3867 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3868 | !params->supported_rates) | |
3869 | return -EINVAL; | |
3870 | break; | |
3871 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3872 | /* reject any changes */ | |
3873 | return -EINVAL; | |
eef941e6 | 3874 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3875 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3876 | return -EINVAL; | |
3877 | break; | |
eef941e6 | 3878 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3879 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3880 | return -EINVAL; | |
3881 | break; | |
3882 | } | |
3883 | ||
3884 | return 0; | |
3885 | } | |
3886 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3887 | ||
5727ef1b | 3888 | /* |
c258d2de | 3889 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3890 | */ |
80b99899 JB |
3891 | static struct net_device *get_vlan(struct genl_info *info, |
3892 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3893 | { |
463d0183 | 3894 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3895 | struct net_device *v; |
3896 | int ret; | |
3897 | ||
3898 | if (!vlanattr) | |
3899 | return NULL; | |
3900 | ||
3901 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3902 | if (!v) | |
3903 | return ERR_PTR(-ENODEV); | |
3904 | ||
3905 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3906 | ret = -EINVAL; | |
3907 | goto error; | |
5727ef1b | 3908 | } |
80b99899 | 3909 | |
77ee7c89 JB |
3910 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3911 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3912 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3913 | ret = -EINVAL; | |
3914 | goto error; | |
3915 | } | |
3916 | ||
80b99899 JB |
3917 | if (!netif_running(v)) { |
3918 | ret = -ENETDOWN; | |
3919 | goto error; | |
3920 | } | |
3921 | ||
3922 | return v; | |
3923 | error: | |
3924 | dev_put(v); | |
3925 | return ERR_PTR(ret); | |
5727ef1b JB |
3926 | } |
3927 | ||
94e860f1 JB |
3928 | static const struct nla_policy |
3929 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
3930 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
3931 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3932 | }; | |
3933 | ||
ff276691 JB |
3934 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3935 | struct station_parameters *params) | |
df881293 | 3936 | { |
df881293 JM |
3937 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3938 | struct nlattr *nla; | |
3939 | int err; | |
3940 | ||
df881293 JM |
3941 | /* parse WME attributes if present */ |
3942 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3943 | return 0; | |
3944 | ||
3945 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3946 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3947 | nl80211_sta_wme_policy); | |
3948 | if (err) | |
3949 | return err; | |
3950 | ||
3951 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3952 | params->uapsd_queues = nla_get_u8( | |
3953 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3954 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3955 | return -EINVAL; | |
3956 | ||
3957 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3958 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3959 | ||
3960 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3961 | return -EINVAL; | |
3962 | ||
3963 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3964 | ||
3965 | return 0; | |
3966 | } | |
3967 | ||
c01fc9ad SD |
3968 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
3969 | struct station_parameters *params) | |
3970 | { | |
3971 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
3972 | params->supported_channels = | |
3973 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
3974 | params->supported_channels_len = | |
3975 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
3976 | /* | |
3977 | * Need to include at least one (first channel, number of | |
3978 | * channels) tuple for each subband, and must have proper | |
3979 | * tuples for the rest of the data as well. | |
3980 | */ | |
3981 | if (params->supported_channels_len < 2) | |
3982 | return -EINVAL; | |
3983 | if (params->supported_channels_len % 2) | |
3984 | return -EINVAL; | |
3985 | } | |
3986 | ||
3987 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
3988 | params->supported_oper_classes = | |
3989 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
3990 | params->supported_oper_classes_len = | |
3991 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
3992 | /* | |
3993 | * The value of the Length field of the Supported Operating | |
3994 | * Classes element is between 2 and 253. | |
3995 | */ | |
3996 | if (params->supported_oper_classes_len < 2 || | |
3997 | params->supported_oper_classes_len > 253) | |
3998 | return -EINVAL; | |
3999 | } | |
4000 | return 0; | |
4001 | } | |
4002 | ||
ff276691 JB |
4003 | static int nl80211_set_station_tdls(struct genl_info *info, |
4004 | struct station_parameters *params) | |
4005 | { | |
c01fc9ad | 4006 | int err; |
ff276691 | 4007 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4008 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4009 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4010 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4011 | params->ht_capa = | |
4012 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4013 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4014 | params->vht_capa = | |
4015 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4016 | ||
c01fc9ad SD |
4017 | err = nl80211_parse_sta_channel_info(info, params); |
4018 | if (err) | |
4019 | return err; | |
4020 | ||
ff276691 JB |
4021 | return nl80211_parse_sta_wme(info, params); |
4022 | } | |
4023 | ||
5727ef1b JB |
4024 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4025 | { | |
4c476991 | 4026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4027 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4028 | struct station_parameters params; |
77ee7c89 JB |
4029 | u8 *mac_addr; |
4030 | int err; | |
5727ef1b JB |
4031 | |
4032 | memset(¶ms, 0, sizeof(params)); | |
4033 | ||
4034 | params.listen_interval = -1; | |
4035 | ||
77ee7c89 JB |
4036 | if (!rdev->ops->change_station) |
4037 | return -EOPNOTSUPP; | |
4038 | ||
5727ef1b JB |
4039 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4040 | return -EINVAL; | |
4041 | ||
4042 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4043 | return -EINVAL; | |
4044 | ||
4045 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4046 | ||
4047 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4048 | params.supported_rates = | |
4049 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4050 | params.supported_rates_len = | |
4051 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4052 | } | |
4053 | ||
9d62a986 JM |
4054 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4055 | params.capability = | |
4056 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4057 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4058 | } | |
4059 | ||
4060 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4061 | params.ext_capab = | |
4062 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4063 | params.ext_capab_len = | |
4064 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4065 | } | |
4066 | ||
df881293 | 4067 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4068 | return -EINVAL; |
36aedc90 | 4069 | |
bdd3ae3d | 4070 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4071 | return -EINVAL; |
4072 | ||
f8bacc21 | 4073 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4074 | params.plink_action = |
f8bacc21 JB |
4075 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4076 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4077 | return -EINVAL; | |
4078 | } | |
2ec600d6 | 4079 | |
f8bacc21 | 4080 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4081 | params.plink_state = |
f8bacc21 JB |
4082 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4083 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4084 | return -EINVAL; | |
4085 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4086 | } | |
9c3990aa | 4087 | |
3b1c5a53 MP |
4088 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4089 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4090 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4091 | ||
4092 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4093 | pm > NL80211_MESH_POWER_MAX) | |
4094 | return -EINVAL; | |
4095 | ||
4096 | params.local_pm = pm; | |
4097 | } | |
4098 | ||
77ee7c89 JB |
4099 | /* Include parameters for TDLS peer (will check later) */ |
4100 | err = nl80211_set_station_tdls(info, ¶ms); | |
4101 | if (err) | |
4102 | return err; | |
4103 | ||
4104 | params.vlan = get_vlan(info, rdev); | |
4105 | if (IS_ERR(params.vlan)) | |
4106 | return PTR_ERR(params.vlan); | |
4107 | ||
a97f4424 JB |
4108 | switch (dev->ieee80211_ptr->iftype) { |
4109 | case NL80211_IFTYPE_AP: | |
4110 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4111 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4112 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4113 | case NL80211_IFTYPE_STATION: |
267335d6 | 4114 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4115 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4116 | break; |
4117 | default: | |
77ee7c89 JB |
4118 | err = -EOPNOTSUPP; |
4119 | goto out_put_vlan; | |
034d655e JB |
4120 | } |
4121 | ||
77ee7c89 | 4122 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4123 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4124 | |
77ee7c89 | 4125 | out_put_vlan: |
5727ef1b JB |
4126 | if (params.vlan) |
4127 | dev_put(params.vlan); | |
3b85875a | 4128 | |
5727ef1b JB |
4129 | return err; |
4130 | } | |
4131 | ||
4132 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4133 | { | |
4c476991 | 4134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4135 | int err; |
4c476991 | 4136 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4137 | struct station_parameters params; |
4138 | u8 *mac_addr = NULL; | |
4139 | ||
4140 | memset(¶ms, 0, sizeof(params)); | |
4141 | ||
984c311b JB |
4142 | if (!rdev->ops->add_station) |
4143 | return -EOPNOTSUPP; | |
4144 | ||
5727ef1b JB |
4145 | if (!info->attrs[NL80211_ATTR_MAC]) |
4146 | return -EINVAL; | |
4147 | ||
5727ef1b JB |
4148 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4149 | return -EINVAL; | |
4150 | ||
4151 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4152 | return -EINVAL; | |
4153 | ||
5e4b6f56 JM |
4154 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4155 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4156 | return -EINVAL; |
4157 | ||
5727ef1b JB |
4158 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4159 | params.supported_rates = | |
4160 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4161 | params.supported_rates_len = | |
4162 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4163 | params.listen_interval = | |
4164 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4165 | |
3d124ea2 | 4166 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4167 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4168 | else |
4169 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4170 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4171 | return -EINVAL; | |
51b50fbe | 4172 | |
9d62a986 JM |
4173 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4174 | params.capability = | |
4175 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4176 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4177 | } | |
4178 | ||
4179 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4180 | params.ext_capab = | |
4181 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4182 | params.ext_capab_len = | |
4183 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4184 | } | |
4185 | ||
36aedc90 JM |
4186 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4187 | params.ht_capa = | |
4188 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4189 | |
f461be3e MP |
4190 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4191 | params.vht_capa = | |
4192 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4193 | ||
60f4a7b1 MK |
4194 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4195 | params.opmode_notif_used = true; | |
4196 | params.opmode_notif = | |
4197 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4198 | } | |
4199 | ||
f8bacc21 | 4200 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4201 | params.plink_action = |
f8bacc21 JB |
4202 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4203 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4204 | return -EINVAL; | |
4205 | } | |
96b78dff | 4206 | |
c01fc9ad SD |
4207 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4208 | if (err) | |
4209 | return err; | |
4210 | ||
ff276691 JB |
4211 | err = nl80211_parse_sta_wme(info, ¶ms); |
4212 | if (err) | |
4213 | return err; | |
bdd90d5e | 4214 | |
bdd3ae3d | 4215 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4216 | return -EINVAL; |
4217 | ||
77ee7c89 JB |
4218 | /* When you run into this, adjust the code below for the new flag */ |
4219 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4220 | ||
bdd90d5e JB |
4221 | switch (dev->ieee80211_ptr->iftype) { |
4222 | case NL80211_IFTYPE_AP: | |
4223 | case NL80211_IFTYPE_AP_VLAN: | |
4224 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4225 | /* ignore WME attributes if iface/sta is not capable */ |
4226 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4227 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4228 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4229 | |
bdd90d5e | 4230 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4231 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4232 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4233 | return -EINVAL; |
bdd90d5e JB |
4234 | /* but don't bother the driver with it */ |
4235 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4236 | |
d582cffb JB |
4237 | /* allow authenticated/associated only if driver handles it */ |
4238 | if (!(rdev->wiphy.features & | |
4239 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4240 | params.sta_flags_mask & | |
4241 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4242 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4243 | return -EINVAL; | |
4244 | ||
bdd90d5e JB |
4245 | /* must be last in here for error handling */ |
4246 | params.vlan = get_vlan(info, rdev); | |
4247 | if (IS_ERR(params.vlan)) | |
4248 | return PTR_ERR(params.vlan); | |
4249 | break; | |
4250 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4251 | /* ignore uAPSD data */ |
4252 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4253 | ||
d582cffb JB |
4254 | /* associated is disallowed */ |
4255 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4256 | return -EINVAL; | |
bdd90d5e | 4257 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4258 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4259 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4260 | return -EINVAL; |
4261 | break; | |
4262 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4263 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4264 | /* ignore uAPSD data */ |
4265 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4266 | ||
77ee7c89 JB |
4267 | /* these are disallowed */ |
4268 | if (params.sta_flags_mask & | |
4269 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4270 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4271 | return -EINVAL; |
bdd90d5e JB |
4272 | /* Only TDLS peers can be added */ |
4273 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4274 | return -EINVAL; | |
4275 | /* Can only add if TDLS ... */ | |
4276 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4277 | return -EOPNOTSUPP; | |
4278 | /* ... with external setup is supported */ | |
4279 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4280 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4281 | /* |
4282 | * Older wpa_supplicant versions always mark the TDLS peer | |
4283 | * as authorized, but it shouldn't yet be. | |
4284 | */ | |
4285 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4286 | break; |
4287 | default: | |
4288 | return -EOPNOTSUPP; | |
c75786c9 EP |
4289 | } |
4290 | ||
bdd90d5e | 4291 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4292 | |
e35e4d28 | 4293 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4294 | |
5727ef1b JB |
4295 | if (params.vlan) |
4296 | dev_put(params.vlan); | |
5727ef1b JB |
4297 | return err; |
4298 | } | |
4299 | ||
4300 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4301 | { | |
4c476991 JB |
4302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4303 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4304 | u8 *mac_addr = NULL; |
4305 | ||
4306 | if (info->attrs[NL80211_ATTR_MAC]) | |
4307 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4308 | ||
e80cf853 | 4309 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4310 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4311 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4312 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4313 | return -EINVAL; | |
5727ef1b | 4314 | |
4c476991 JB |
4315 | if (!rdev->ops->del_station) |
4316 | return -EOPNOTSUPP; | |
3b85875a | 4317 | |
e35e4d28 | 4318 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4319 | } |
4320 | ||
15e47304 | 4321 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4322 | int flags, struct net_device *dev, |
4323 | u8 *dst, u8 *next_hop, | |
4324 | struct mpath_info *pinfo) | |
4325 | { | |
4326 | void *hdr; | |
4327 | struct nlattr *pinfoattr; | |
4328 | ||
15e47304 | 4329 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4330 | if (!hdr) |
4331 | return -1; | |
4332 | ||
9360ffd1 DM |
4333 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4334 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4335 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4336 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4337 | goto nla_put_failure; | |
f5ea9120 | 4338 | |
2ec600d6 LCC |
4339 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4340 | if (!pinfoattr) | |
4341 | goto nla_put_failure; | |
9360ffd1 DM |
4342 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4343 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4344 | pinfo->frame_qlen)) | |
4345 | goto nla_put_failure; | |
4346 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4347 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4348 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4349 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4350 | pinfo->metric)) || | |
4351 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4352 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4353 | pinfo->exptime)) || | |
4354 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4355 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4356 | pinfo->flags)) || | |
4357 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4358 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4359 | pinfo->discovery_timeout)) || | |
4360 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4361 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4362 | pinfo->discovery_retries))) | |
4363 | goto nla_put_failure; | |
2ec600d6 LCC |
4364 | |
4365 | nla_nest_end(msg, pinfoattr); | |
4366 | ||
4367 | return genlmsg_end(msg, hdr); | |
4368 | ||
4369 | nla_put_failure: | |
bc3ed28c TG |
4370 | genlmsg_cancel(msg, hdr); |
4371 | return -EMSGSIZE; | |
2ec600d6 LCC |
4372 | } |
4373 | ||
4374 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4375 | struct netlink_callback *cb) |
2ec600d6 | 4376 | { |
2ec600d6 LCC |
4377 | struct mpath_info pinfo; |
4378 | struct cfg80211_registered_device *dev; | |
97990a06 | 4379 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4380 | u8 dst[ETH_ALEN]; |
4381 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4382 | int path_idx = cb->args[2]; |
2ec600d6 | 4383 | int err; |
2ec600d6 | 4384 | |
97990a06 | 4385 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4386 | if (err) |
4387 | return err; | |
bba95fef JB |
4388 | |
4389 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4390 | err = -EOPNOTSUPP; |
bba95fef JB |
4391 | goto out_err; |
4392 | } | |
4393 | ||
97990a06 | 4394 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4395 | err = -EOPNOTSUPP; |
0448b5fc | 4396 | goto out_err; |
eec60b03 JM |
4397 | } |
4398 | ||
bba95fef | 4399 | while (1) { |
97990a06 JB |
4400 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4401 | next_hop, &pinfo); | |
bba95fef | 4402 | if (err == -ENOENT) |
2ec600d6 | 4403 | break; |
bba95fef | 4404 | if (err) |
3b85875a | 4405 | goto out_err; |
2ec600d6 | 4406 | |
15e47304 | 4407 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4408 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4409 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4410 | &pinfo) < 0) |
4411 | goto out; | |
2ec600d6 | 4412 | |
bba95fef | 4413 | path_idx++; |
2ec600d6 | 4414 | } |
2ec600d6 | 4415 | |
2ec600d6 | 4416 | |
bba95fef | 4417 | out: |
97990a06 | 4418 | cb->args[2] = path_idx; |
bba95fef | 4419 | err = skb->len; |
bba95fef | 4420 | out_err: |
97990a06 | 4421 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4422 | return err; |
2ec600d6 LCC |
4423 | } |
4424 | ||
4425 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4426 | { | |
4c476991 | 4427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4428 | int err; |
4c476991 | 4429 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4430 | struct mpath_info pinfo; |
4431 | struct sk_buff *msg; | |
4432 | u8 *dst = NULL; | |
4433 | u8 next_hop[ETH_ALEN]; | |
4434 | ||
4435 | memset(&pinfo, 0, sizeof(pinfo)); | |
4436 | ||
4437 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4438 | return -EINVAL; | |
4439 | ||
4440 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4441 | ||
4c476991 JB |
4442 | if (!rdev->ops->get_mpath) |
4443 | return -EOPNOTSUPP; | |
2ec600d6 | 4444 | |
4c476991 JB |
4445 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4446 | return -EOPNOTSUPP; | |
eec60b03 | 4447 | |
e35e4d28 | 4448 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4449 | if (err) |
4c476991 | 4450 | return err; |
2ec600d6 | 4451 | |
fd2120ca | 4452 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4453 | if (!msg) |
4c476991 | 4454 | return -ENOMEM; |
2ec600d6 | 4455 | |
15e47304 | 4456 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4457 | dev, dst, next_hop, &pinfo) < 0) { |
4458 | nlmsg_free(msg); | |
4459 | return -ENOBUFS; | |
4460 | } | |
3b85875a | 4461 | |
4c476991 | 4462 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4463 | } |
4464 | ||
4465 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4466 | { | |
4c476991 JB |
4467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4468 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4469 | u8 *dst = NULL; |
4470 | u8 *next_hop = NULL; | |
4471 | ||
4472 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4473 | return -EINVAL; | |
4474 | ||
4475 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4476 | return -EINVAL; | |
4477 | ||
4478 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4479 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4480 | ||
4c476991 JB |
4481 | if (!rdev->ops->change_mpath) |
4482 | return -EOPNOTSUPP; | |
35a8efe1 | 4483 | |
4c476991 JB |
4484 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4485 | return -EOPNOTSUPP; | |
2ec600d6 | 4486 | |
e35e4d28 | 4487 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4488 | } |
4c476991 | 4489 | |
2ec600d6 LCC |
4490 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4491 | { | |
4c476991 JB |
4492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4493 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4494 | u8 *dst = NULL; |
4495 | u8 *next_hop = NULL; | |
4496 | ||
4497 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4498 | return -EINVAL; | |
4499 | ||
4500 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4501 | return -EINVAL; | |
4502 | ||
4503 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4504 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4505 | ||
4c476991 JB |
4506 | if (!rdev->ops->add_mpath) |
4507 | return -EOPNOTSUPP; | |
35a8efe1 | 4508 | |
4c476991 JB |
4509 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4510 | return -EOPNOTSUPP; | |
2ec600d6 | 4511 | |
e35e4d28 | 4512 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4513 | } |
4514 | ||
4515 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4516 | { | |
4c476991 JB |
4517 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4518 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4519 | u8 *dst = NULL; |
4520 | ||
4521 | if (info->attrs[NL80211_ATTR_MAC]) | |
4522 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4523 | ||
4c476991 JB |
4524 | if (!rdev->ops->del_mpath) |
4525 | return -EOPNOTSUPP; | |
3b85875a | 4526 | |
e35e4d28 | 4527 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4528 | } |
4529 | ||
9f1ba906 JM |
4530 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4531 | { | |
4c476991 JB |
4532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4533 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4534 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4535 | struct bss_parameters params; |
c56589ed | 4536 | int err; |
9f1ba906 JM |
4537 | |
4538 | memset(¶ms, 0, sizeof(params)); | |
4539 | /* default to not changing parameters */ | |
4540 | params.use_cts_prot = -1; | |
4541 | params.use_short_preamble = -1; | |
4542 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4543 | params.ap_isolate = -1; |
50b12f59 | 4544 | params.ht_opmode = -1; |
53cabad7 JB |
4545 | params.p2p_ctwindow = -1; |
4546 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4547 | |
4548 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4549 | params.use_cts_prot = | |
4550 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4551 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4552 | params.use_short_preamble = | |
4553 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4554 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4555 | params.use_short_slot_time = | |
4556 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4557 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4558 | params.basic_rates = | |
4559 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4560 | params.basic_rates_len = | |
4561 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4562 | } | |
fd8aaaf3 FF |
4563 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4564 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4565 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4566 | params.ht_opmode = | |
4567 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4568 | |
53cabad7 JB |
4569 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4570 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4571 | return -EINVAL; | |
4572 | params.p2p_ctwindow = | |
4573 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4574 | if (params.p2p_ctwindow < 0) | |
4575 | return -EINVAL; | |
4576 | if (params.p2p_ctwindow != 0 && | |
4577 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4578 | return -EINVAL; | |
4579 | } | |
4580 | ||
4581 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4582 | u8 tmp; | |
4583 | ||
4584 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4585 | return -EINVAL; | |
4586 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4587 | if (tmp > 1) | |
4588 | return -EINVAL; | |
4589 | params.p2p_opp_ps = tmp; | |
4590 | if (params.p2p_opp_ps && | |
4591 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4592 | return -EINVAL; | |
4593 | } | |
4594 | ||
4c476991 JB |
4595 | if (!rdev->ops->change_bss) |
4596 | return -EOPNOTSUPP; | |
9f1ba906 | 4597 | |
074ac8df | 4598 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4599 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4600 | return -EOPNOTSUPP; | |
3b85875a | 4601 | |
c56589ed SW |
4602 | wdev_lock(wdev); |
4603 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4604 | wdev_unlock(wdev); | |
4605 | ||
4606 | return err; | |
9f1ba906 JM |
4607 | } |
4608 | ||
b54452b0 | 4609 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4610 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4611 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4612 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4613 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4614 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4615 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4616 | }; | |
4617 | ||
4618 | static int parse_reg_rule(struct nlattr *tb[], | |
4619 | struct ieee80211_reg_rule *reg_rule) | |
4620 | { | |
4621 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4622 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4623 | ||
4624 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4625 | return -EINVAL; | |
4626 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4627 | return -EINVAL; | |
4628 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4629 | return -EINVAL; | |
b2e1b302 LR |
4630 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4631 | return -EINVAL; | |
4632 | ||
4633 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4634 | ||
4635 | freq_range->start_freq_khz = | |
4636 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4637 | freq_range->end_freq_khz = | |
4638 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
97524820 JD |
4639 | if (tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4640 | freq_range->max_bandwidth_khz = | |
4641 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4642 | |
4643 | power_rule->max_eirp = | |
4644 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4645 | ||
4646 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4647 | power_rule->max_antenna_gain = | |
4648 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4649 | ||
4650 | return 0; | |
4651 | } | |
4652 | ||
4653 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4654 | { | |
4655 | int r; | |
4656 | char *data = NULL; | |
57b5ce07 | 4657 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4658 | |
80778f18 LR |
4659 | /* |
4660 | * You should only get this when cfg80211 hasn't yet initialized | |
4661 | * completely when built-in to the kernel right between the time | |
4662 | * window between nl80211_init() and regulatory_init(), if that is | |
4663 | * even possible. | |
4664 | */ | |
458f4f9e | 4665 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4666 | return -EINPROGRESS; |
80778f18 | 4667 | |
fe33eb39 LR |
4668 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4669 | return -EINVAL; | |
b2e1b302 LR |
4670 | |
4671 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4672 | ||
57b5ce07 LR |
4673 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4674 | user_reg_hint_type = | |
4675 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4676 | else | |
4677 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4678 | ||
4679 | switch (user_reg_hint_type) { | |
4680 | case NL80211_USER_REG_HINT_USER: | |
4681 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4682 | break; | |
4683 | default: | |
4684 | return -EINVAL; | |
4685 | } | |
4686 | ||
4687 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4688 | |
b2e1b302 LR |
4689 | return r; |
4690 | } | |
4691 | ||
24bdd9f4 | 4692 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4693 | struct genl_info *info) |
93da9cc1 | 4694 | { |
4c476991 | 4695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4696 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4697 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4698 | struct mesh_config cur_params; | |
4699 | int err = 0; | |
93da9cc1 | 4700 | void *hdr; |
4701 | struct nlattr *pinfoattr; | |
4702 | struct sk_buff *msg; | |
4703 | ||
29cbe68c JB |
4704 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4705 | return -EOPNOTSUPP; | |
4706 | ||
24bdd9f4 | 4707 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4708 | return -EOPNOTSUPP; |
f3f92586 | 4709 | |
29cbe68c JB |
4710 | wdev_lock(wdev); |
4711 | /* If not connected, get default parameters */ | |
4712 | if (!wdev->mesh_id_len) | |
4713 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4714 | else | |
e35e4d28 | 4715 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4716 | wdev_unlock(wdev); |
4717 | ||
93da9cc1 | 4718 | if (err) |
4c476991 | 4719 | return err; |
93da9cc1 | 4720 | |
4721 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4722 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4723 | if (!msg) |
4724 | return -ENOMEM; | |
15e47304 | 4725 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4726 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4727 | if (!hdr) |
efe1cf0c | 4728 | goto out; |
24bdd9f4 | 4729 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4730 | if (!pinfoattr) |
4731 | goto nla_put_failure; | |
9360ffd1 DM |
4732 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4733 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4734 | cur_params.dot11MeshRetryTimeout) || | |
4735 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4736 | cur_params.dot11MeshConfirmTimeout) || | |
4737 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4738 | cur_params.dot11MeshHoldingTimeout) || | |
4739 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4740 | cur_params.dot11MeshMaxPeerLinks) || | |
4741 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4742 | cur_params.dot11MeshMaxRetries) || | |
4743 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4744 | cur_params.dot11MeshTTL) || | |
4745 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4746 | cur_params.element_ttl) || | |
4747 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4748 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4749 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4750 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4751 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4752 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4753 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4754 | cur_params.path_refresh_time) || | |
4755 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4756 | cur_params.min_discovery_timeout) || | |
4757 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4758 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4759 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4760 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4761 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4762 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4763 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4764 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4765 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4766 | cur_params.dot11MeshHWMPRootMode) || | |
4767 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4768 | cur_params.dot11MeshHWMPRannInterval) || | |
4769 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4770 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4771 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4772 | cur_params.dot11MeshForwarding) || | |
4773 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4774 | cur_params.rssi_threshold) || |
4775 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4776 | cur_params.ht_opmode) || |
4777 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4778 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4779 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4780 | cur_params.dot11MeshHWMProotInterval) || |
4781 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4782 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4783 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4784 | cur_params.power_mode) || | |
4785 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4786 | cur_params.dot11MeshAwakeWindowDuration) || |
4787 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4788 | cur_params.plink_timeout)) | |
9360ffd1 | 4789 | goto nla_put_failure; |
93da9cc1 | 4790 | nla_nest_end(msg, pinfoattr); |
4791 | genlmsg_end(msg, hdr); | |
4c476991 | 4792 | return genlmsg_reply(msg, info); |
93da9cc1 | 4793 | |
3b85875a | 4794 | nla_put_failure: |
93da9cc1 | 4795 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4796 | out: |
d080e275 | 4797 | nlmsg_free(msg); |
4c476991 | 4798 | return -ENOBUFS; |
93da9cc1 | 4799 | } |
4800 | ||
b54452b0 | 4801 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4802 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4803 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4804 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4805 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4806 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4807 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4808 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4809 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4810 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4811 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4812 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4813 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4814 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4815 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4816 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4817 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4818 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4819 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4820 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4821 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4822 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4823 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4824 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4825 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4826 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4827 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4828 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4829 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4830 | }; |
4831 | ||
c80d545d JC |
4832 | static const struct nla_policy |
4833 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4834 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4835 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4836 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4837 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4838 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4839 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4840 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4841 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4842 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4843 | }; |
4844 | ||
24bdd9f4 | 4845 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4846 | struct mesh_config *cfg, |
4847 | u32 *mask_out) | |
93da9cc1 | 4848 | { |
93da9cc1 | 4849 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4850 | u32 mask = 0; |
93da9cc1 | 4851 | |
ea54fba2 MP |
4852 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4853 | do { \ | |
4854 | if (tb[attr]) { \ | |
4855 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4856 | return -EINVAL; \ | |
4857 | cfg->param = fn(tb[attr]); \ | |
4858 | mask |= (1 << (attr - 1)); \ | |
4859 | } \ | |
4860 | } while (0) | |
bd90fdcc JB |
4861 | |
4862 | ||
24bdd9f4 | 4863 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4864 | return -EINVAL; |
4865 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4866 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4867 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4868 | return -EINVAL; |
4869 | ||
93da9cc1 | 4870 | /* This makes sure that there aren't more than 32 mesh config |
4871 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4872 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4873 | ||
4874 | /* Fill in the params struct */ | |
ea54fba2 | 4875 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4876 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4877 | nla_get_u16); | |
ea54fba2 | 4878 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4879 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4880 | nla_get_u16); | |
ea54fba2 | 4881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4882 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4883 | nla_get_u16); | |
ea54fba2 | 4884 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4885 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4886 | nla_get_u16); | |
ea54fba2 | 4887 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4888 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4889 | nla_get_u8); | |
ea54fba2 | 4890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4891 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4892 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4893 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4894 | nla_get_u8); | |
ea54fba2 | 4895 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4896 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4897 | nla_get_u8); | |
ea54fba2 MP |
4898 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4899 | 1, 255, mask, | |
a4f606ea CYY |
4900 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4901 | nla_get_u32); | |
ea54fba2 | 4902 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4903 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4904 | nla_get_u8); | |
ea54fba2 | 4905 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4906 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4907 | nla_get_u32); | |
ea54fba2 | 4908 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4909 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4910 | nla_get_u16); | |
ea54fba2 MP |
4911 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4912 | 1, 65535, mask, | |
a4f606ea CYY |
4913 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4914 | nla_get_u32); | |
93da9cc1 | 4915 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4916 | 1, 65535, mask, |
4917 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4918 | nla_get_u16); |
dca7e943 | 4919 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4920 | 1, 65535, mask, |
4921 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4922 | nla_get_u16); |
93da9cc1 | 4923 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4924 | dot11MeshHWMPnetDiameterTraversalTime, |
4925 | 1, 65535, mask, | |
a4f606ea CYY |
4926 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4927 | nla_get_u16); | |
ea54fba2 MP |
4928 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4929 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4930 | nla_get_u8); | |
4931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4932 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4933 | nla_get_u16); |
63c5723b | 4934 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4935 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4936 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4937 | nla_get_u8); |
ea54fba2 | 4938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4939 | mask, NL80211_MESHCONF_FORWARDING, |
4940 | nla_get_u8); | |
83374fe9 | 4941 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 4942 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 4943 | nla_get_s32); |
ea54fba2 | 4944 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4945 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4946 | nla_get_u16); |
4947 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4948 | 1, 65535, mask, |
ac1073a6 CYY |
4949 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4950 | nla_get_u32); | |
ea54fba2 | 4951 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4952 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4953 | nla_get_u16); |
4954 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4955 | dot11MeshHWMPconfirmationInterval, |
4956 | 1, 65535, mask, | |
728b19e5 | 4957 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4958 | nla_get_u16); |
3b1c5a53 MP |
4959 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4960 | NL80211_MESH_POWER_ACTIVE, | |
4961 | NL80211_MESH_POWER_MAX, | |
4962 | mask, NL80211_MESHCONF_POWER_MODE, | |
4963 | nla_get_u32); | |
4964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4965 | 0, 65535, mask, | |
4966 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
4967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
4968 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4969 | nla_get_u32); | |
bd90fdcc JB |
4970 | if (mask_out) |
4971 | *mask_out = mask; | |
c80d545d | 4972 | |
bd90fdcc JB |
4973 | return 0; |
4974 | ||
4975 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4976 | } | |
4977 | ||
c80d545d JC |
4978 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4979 | struct mesh_setup *setup) | |
4980 | { | |
bb2798d4 | 4981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4982 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4983 | ||
4984 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4985 | return -EINVAL; | |
4986 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4987 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4988 | nl80211_mesh_setup_params_policy)) | |
4989 | return -EINVAL; | |
4990 | ||
d299a1f2 JC |
4991 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4992 | setup->sync_method = | |
4993 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4994 | IEEE80211_SYNC_METHOD_VENDOR : | |
4995 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4996 | ||
c80d545d JC |
4997 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4998 | setup->path_sel_proto = | |
4999 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5000 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5001 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5002 | ||
5003 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5004 | setup->path_metric = | |
5005 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5006 | IEEE80211_PATH_METRIC_VENDOR : | |
5007 | IEEE80211_PATH_METRIC_AIRTIME; | |
5008 | ||
581a8b0f JC |
5009 | |
5010 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5011 | struct nlattr *ieattr = |
581a8b0f | 5012 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5013 | if (!is_valid_ie_attr(ieattr)) |
5014 | return -EINVAL; | |
581a8b0f JC |
5015 | setup->ie = nla_data(ieattr); |
5016 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5017 | } |
bb2798d4 TP |
5018 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5019 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5020 | return -EINVAL; | |
5021 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5022 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5023 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5024 | if (setup->is_secure) |
5025 | setup->user_mpm = true; | |
c80d545d | 5026 | |
6e16d90b CT |
5027 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5028 | if (!setup->user_mpm) | |
5029 | return -EINVAL; | |
5030 | setup->auth_id = | |
5031 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5032 | } | |
5033 | ||
c80d545d JC |
5034 | return 0; |
5035 | } | |
5036 | ||
24bdd9f4 | 5037 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5038 | struct genl_info *info) |
bd90fdcc JB |
5039 | { |
5040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5041 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5042 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5043 | struct mesh_config cfg; |
5044 | u32 mask; | |
5045 | int err; | |
5046 | ||
29cbe68c JB |
5047 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5048 | return -EOPNOTSUPP; | |
5049 | ||
24bdd9f4 | 5050 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5051 | return -EOPNOTSUPP; |
5052 | ||
24bdd9f4 | 5053 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5054 | if (err) |
5055 | return err; | |
5056 | ||
29cbe68c JB |
5057 | wdev_lock(wdev); |
5058 | if (!wdev->mesh_id_len) | |
5059 | err = -ENOLINK; | |
5060 | ||
5061 | if (!err) | |
e35e4d28 | 5062 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5063 | |
5064 | wdev_unlock(wdev); | |
5065 | ||
5066 | return err; | |
93da9cc1 | 5067 | } |
5068 | ||
f130347c LR |
5069 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5070 | { | |
458f4f9e | 5071 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5072 | struct sk_buff *msg; |
5073 | void *hdr = NULL; | |
5074 | struct nlattr *nl_reg_rules; | |
5075 | unsigned int i; | |
f130347c LR |
5076 | |
5077 | if (!cfg80211_regdomain) | |
5fe231e8 | 5078 | return -EINVAL; |
f130347c | 5079 | |
fd2120ca | 5080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5081 | if (!msg) |
5082 | return -ENOBUFS; | |
f130347c | 5083 | |
15e47304 | 5084 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5085 | NL80211_CMD_GET_REG); |
5086 | if (!hdr) | |
efe1cf0c | 5087 | goto put_failure; |
f130347c | 5088 | |
57b5ce07 LR |
5089 | if (reg_last_request_cell_base() && |
5090 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5091 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5092 | goto nla_put_failure; | |
5093 | ||
458f4f9e JB |
5094 | rcu_read_lock(); |
5095 | regdom = rcu_dereference(cfg80211_regdomain); | |
5096 | ||
5097 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5098 | (regdom->dfs_region && | |
5099 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5100 | goto nla_put_failure_rcu; | |
5101 | ||
f130347c LR |
5102 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5103 | if (!nl_reg_rules) | |
458f4f9e | 5104 | goto nla_put_failure_rcu; |
f130347c | 5105 | |
458f4f9e | 5106 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5107 | struct nlattr *nl_reg_rule; |
5108 | const struct ieee80211_reg_rule *reg_rule; | |
5109 | const struct ieee80211_freq_range *freq_range; | |
5110 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5111 | unsigned int max_bandwidth_khz; |
f130347c | 5112 | |
458f4f9e | 5113 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5114 | freq_range = ®_rule->freq_range; |
5115 | power_rule = ®_rule->power_rule; | |
5116 | ||
5117 | nl_reg_rule = nla_nest_start(msg, i); | |
5118 | if (!nl_reg_rule) | |
458f4f9e | 5119 | goto nla_put_failure_rcu; |
f130347c | 5120 | |
97524820 JD |
5121 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5122 | if (!max_bandwidth_khz) | |
5123 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5124 | reg_rule); | |
5125 | ||
9360ffd1 DM |
5126 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5127 | reg_rule->flags) || | |
5128 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5129 | freq_range->start_freq_khz) || | |
5130 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5131 | freq_range->end_freq_khz) || | |
5132 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5133 | max_bandwidth_khz) || |
9360ffd1 DM |
5134 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5135 | power_rule->max_antenna_gain) || | |
5136 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
5137 | power_rule->max_eirp)) | |
458f4f9e | 5138 | goto nla_put_failure_rcu; |
f130347c LR |
5139 | |
5140 | nla_nest_end(msg, nl_reg_rule); | |
5141 | } | |
458f4f9e | 5142 | rcu_read_unlock(); |
f130347c LR |
5143 | |
5144 | nla_nest_end(msg, nl_reg_rules); | |
5145 | ||
5146 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5147 | return genlmsg_reply(msg, info); |
f130347c | 5148 | |
458f4f9e JB |
5149 | nla_put_failure_rcu: |
5150 | rcu_read_unlock(); | |
f130347c LR |
5151 | nla_put_failure: |
5152 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5153 | put_failure: |
d080e275 | 5154 | nlmsg_free(msg); |
5fe231e8 | 5155 | return -EMSGSIZE; |
f130347c LR |
5156 | } |
5157 | ||
b2e1b302 LR |
5158 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5159 | { | |
5160 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5161 | struct nlattr *nl_reg_rule; | |
5162 | char *alpha2 = NULL; | |
5163 | int rem_reg_rules = 0, r = 0; | |
5164 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5165 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5166 | struct ieee80211_regdomain *rd = NULL; |
5167 | ||
5168 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5169 | return -EINVAL; | |
5170 | ||
5171 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5172 | return -EINVAL; | |
5173 | ||
5174 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5175 | ||
8b60b078 LR |
5176 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5177 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5178 | ||
b2e1b302 | 5179 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5180 | rem_reg_rules) { |
b2e1b302 LR |
5181 | num_rules++; |
5182 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5183 | return -EINVAL; |
b2e1b302 LR |
5184 | } |
5185 | ||
e438768f LR |
5186 | if (!reg_is_valid_request(alpha2)) |
5187 | return -EINVAL; | |
5188 | ||
b2e1b302 | 5189 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5190 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5191 | |
5192 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5193 | if (!rd) |
5194 | return -ENOMEM; | |
b2e1b302 LR |
5195 | |
5196 | rd->n_reg_rules = num_rules; | |
5197 | rd->alpha2[0] = alpha2[0]; | |
5198 | rd->alpha2[1] = alpha2[1]; | |
5199 | ||
8b60b078 LR |
5200 | /* |
5201 | * Disable DFS master mode if the DFS region was | |
5202 | * not supported or known on this kernel. | |
5203 | */ | |
5204 | if (reg_supported_dfs_region(dfs_region)) | |
5205 | rd->dfs_region = dfs_region; | |
5206 | ||
b2e1b302 | 5207 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5208 | rem_reg_rules) { |
ae811e21 JB |
5209 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5210 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5211 | reg_rule_policy); | |
5212 | if (r) | |
5213 | goto bad_reg; | |
b2e1b302 LR |
5214 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5215 | if (r) | |
5216 | goto bad_reg; | |
5217 | ||
5218 | rule_idx++; | |
5219 | ||
d0e18f83 LR |
5220 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5221 | r = -EINVAL; | |
b2e1b302 | 5222 | goto bad_reg; |
d0e18f83 | 5223 | } |
b2e1b302 LR |
5224 | } |
5225 | ||
b2e1b302 | 5226 | r = set_regdom(rd); |
6913b49a | 5227 | /* set_regdom took ownership */ |
1a919318 | 5228 | rd = NULL; |
b2e1b302 | 5229 | |
d2372b31 | 5230 | bad_reg: |
b2e1b302 | 5231 | kfree(rd); |
d0e18f83 | 5232 | return r; |
b2e1b302 LR |
5233 | } |
5234 | ||
83f5e2cf JB |
5235 | static int validate_scan_freqs(struct nlattr *freqs) |
5236 | { | |
5237 | struct nlattr *attr1, *attr2; | |
5238 | int n_channels = 0, tmp1, tmp2; | |
5239 | ||
5240 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5241 | n_channels++; | |
5242 | /* | |
5243 | * Some hardware has a limited channel list for | |
5244 | * scanning, and it is pretty much nonsensical | |
5245 | * to scan for a channel twice, so disallow that | |
5246 | * and don't require drivers to check that the | |
5247 | * channel list they get isn't longer than what | |
5248 | * they can scan, as long as they can scan all | |
5249 | * the channels they registered at once. | |
5250 | */ | |
5251 | nla_for_each_nested(attr2, freqs, tmp2) | |
5252 | if (attr1 != attr2 && | |
5253 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5254 | return 0; | |
5255 | } | |
5256 | ||
5257 | return n_channels; | |
5258 | } | |
5259 | ||
2a519311 JB |
5260 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5261 | { | |
4c476991 | 5262 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5263 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5264 | struct cfg80211_scan_request *request; |
2a519311 JB |
5265 | struct nlattr *attr; |
5266 | struct wiphy *wiphy; | |
83f5e2cf | 5267 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5268 | size_t ie_len; |
2a519311 | 5269 | |
f4a11bb0 JB |
5270 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5271 | return -EINVAL; | |
5272 | ||
79c97e97 | 5273 | wiphy = &rdev->wiphy; |
2a519311 | 5274 | |
4c476991 JB |
5275 | if (!rdev->ops->scan) |
5276 | return -EOPNOTSUPP; | |
2a519311 | 5277 | |
f9d15d16 | 5278 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5279 | err = -EBUSY; |
5280 | goto unlock; | |
5281 | } | |
2a519311 JB |
5282 | |
5283 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5284 | n_channels = validate_scan_freqs( |
5285 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5286 | if (!n_channels) { |
5287 | err = -EINVAL; | |
5288 | goto unlock; | |
5289 | } | |
2a519311 | 5290 | } else { |
bdfbec2d | 5291 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5292 | } |
5293 | ||
5294 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5295 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5296 | n_ssids++; | |
5297 | ||
f9f47529 JB |
5298 | if (n_ssids > wiphy->max_scan_ssids) { |
5299 | err = -EINVAL; | |
5300 | goto unlock; | |
5301 | } | |
2a519311 | 5302 | |
70692ad2 JM |
5303 | if (info->attrs[NL80211_ATTR_IE]) |
5304 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5305 | else | |
5306 | ie_len = 0; | |
5307 | ||
f9f47529 JB |
5308 | if (ie_len > wiphy->max_scan_ie_len) { |
5309 | err = -EINVAL; | |
5310 | goto unlock; | |
5311 | } | |
18a83659 | 5312 | |
2a519311 | 5313 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5314 | + sizeof(*request->ssids) * n_ssids |
5315 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5316 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5317 | if (!request) { |
5318 | err = -ENOMEM; | |
5319 | goto unlock; | |
5320 | } | |
2a519311 | 5321 | |
2a519311 | 5322 | if (n_ssids) |
5ba63533 | 5323 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5324 | request->n_ssids = n_ssids; |
70692ad2 JM |
5325 | if (ie_len) { |
5326 | if (request->ssids) | |
5327 | request->ie = (void *)(request->ssids + n_ssids); | |
5328 | else | |
5329 | request->ie = (void *)(request->channels + n_channels); | |
5330 | } | |
2a519311 | 5331 | |
584991dc | 5332 | i = 0; |
2a519311 JB |
5333 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5334 | /* user specified, bail out if channel not found */ | |
2a519311 | 5335 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5336 | struct ieee80211_channel *chan; |
5337 | ||
5338 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5339 | ||
5340 | if (!chan) { | |
2a519311 JB |
5341 | err = -EINVAL; |
5342 | goto out_free; | |
5343 | } | |
584991dc JB |
5344 | |
5345 | /* ignore disabled channels */ | |
5346 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5347 | continue; | |
5348 | ||
5349 | request->channels[i] = chan; | |
2a519311 JB |
5350 | i++; |
5351 | } | |
5352 | } else { | |
34850ab2 JB |
5353 | enum ieee80211_band band; |
5354 | ||
2a519311 | 5355 | /* all channels */ |
2a519311 JB |
5356 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5357 | int j; | |
5358 | if (!wiphy->bands[band]) | |
5359 | continue; | |
5360 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5361 | struct ieee80211_channel *chan; |
5362 | ||
5363 | chan = &wiphy->bands[band]->channels[j]; | |
5364 | ||
5365 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5366 | continue; | |
5367 | ||
5368 | request->channels[i] = chan; | |
2a519311 JB |
5369 | i++; |
5370 | } | |
5371 | } | |
5372 | } | |
5373 | ||
584991dc JB |
5374 | if (!i) { |
5375 | err = -EINVAL; | |
5376 | goto out_free; | |
5377 | } | |
5378 | ||
5379 | request->n_channels = i; | |
5380 | ||
2a519311 JB |
5381 | i = 0; |
5382 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5383 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5384 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5385 | err = -EINVAL; |
5386 | goto out_free; | |
5387 | } | |
57a27e1d | 5388 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5389 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5390 | i++; |
5391 | } | |
5392 | } | |
5393 | ||
70692ad2 JM |
5394 | if (info->attrs[NL80211_ATTR_IE]) { |
5395 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5396 | memcpy((void *)request->ie, |
5397 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5398 | request->ie_len); |
5399 | } | |
5400 | ||
34850ab2 | 5401 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5402 | if (wiphy->bands[i]) |
5403 | request->rates[i] = | |
5404 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5405 | |
5406 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5407 | nla_for_each_nested(attr, | |
5408 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5409 | tmp) { | |
5410 | enum ieee80211_band band = nla_type(attr); | |
5411 | ||
84404623 | 5412 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5413 | err = -EINVAL; |
5414 | goto out_free; | |
5415 | } | |
1b09cd82 FF |
5416 | |
5417 | if (!wiphy->bands[band]) | |
5418 | continue; | |
5419 | ||
34850ab2 JB |
5420 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5421 | nla_data(attr), | |
5422 | nla_len(attr), | |
5423 | &request->rates[band]); | |
5424 | if (err) | |
5425 | goto out_free; | |
5426 | } | |
5427 | } | |
5428 | ||
46856bbf | 5429 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5430 | request->flags = nla_get_u32( |
5431 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5432 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5433 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5434 | err = -EOPNOTSUPP; |
5435 | goto out_free; | |
5436 | } | |
5437 | } | |
ed473771 | 5438 | |
e9f935e3 RM |
5439 | request->no_cck = |
5440 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5441 | ||
fd014284 | 5442 | request->wdev = wdev; |
79c97e97 | 5443 | request->wiphy = &rdev->wiphy; |
15d6030b | 5444 | request->scan_start = jiffies; |
2a519311 | 5445 | |
79c97e97 | 5446 | rdev->scan_req = request; |
e35e4d28 | 5447 | err = rdev_scan(rdev, request); |
2a519311 | 5448 | |
463d0183 | 5449 | if (!err) { |
fd014284 JB |
5450 | nl80211_send_scan_start(rdev, wdev); |
5451 | if (wdev->netdev) | |
5452 | dev_hold(wdev->netdev); | |
4c476991 | 5453 | } else { |
2a519311 | 5454 | out_free: |
79c97e97 | 5455 | rdev->scan_req = NULL; |
2a519311 JB |
5456 | kfree(request); |
5457 | } | |
3b85875a | 5458 | |
f9f47529 | 5459 | unlock: |
2a519311 JB |
5460 | return err; |
5461 | } | |
5462 | ||
807f8a8c LC |
5463 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5464 | struct genl_info *info) | |
5465 | { | |
5466 | struct cfg80211_sched_scan_request *request; | |
5467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5468 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5469 | struct nlattr *attr; |
5470 | struct wiphy *wiphy; | |
a1f1c21c | 5471 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5472 | u32 interval; |
807f8a8c LC |
5473 | enum ieee80211_band band; |
5474 | size_t ie_len; | |
a1f1c21c | 5475 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5476 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c LC |
5477 | |
5478 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5479 | !rdev->ops->sched_scan_start) | |
5480 | return -EOPNOTSUPP; | |
5481 | ||
5482 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5483 | return -EINVAL; | |
5484 | ||
bbe6ad6d LC |
5485 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5486 | return -EINVAL; | |
5487 | ||
5488 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5489 | if (interval == 0) | |
5490 | return -EINVAL; | |
5491 | ||
807f8a8c LC |
5492 | wiphy = &rdev->wiphy; |
5493 | ||
5494 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5495 | n_channels = validate_scan_freqs( | |
5496 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5497 | if (!n_channels) | |
5498 | return -EINVAL; | |
5499 | } else { | |
bdfbec2d | 5500 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5501 | } |
5502 | ||
5503 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5504 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5505 | tmp) | |
5506 | n_ssids++; | |
5507 | ||
93b6aa69 | 5508 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5509 | return -EINVAL; |
5510 | ||
ea73cbce JB |
5511 | /* |
5512 | * First, count the number of 'real' matchsets. Due to an issue with | |
5513 | * the old implementation, matchsets containing only the RSSI attribute | |
5514 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5515 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5516 | * all APs with a strong RSSI. This is needed to be compatible with | |
5517 | * older userspace that treated a matchset with only the RSSI as the | |
5518 | * global RSSI for all other matchsets - if there are other matchsets. | |
5519 | */ | |
5520 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
a1f1c21c LC |
5521 | nla_for_each_nested(attr, |
5522 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
ea73cbce JB |
5523 | tmp) { |
5524 | struct nlattr *rssi; | |
5525 | ||
5526 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5527 | nla_data(attr), nla_len(attr), | |
5528 | nl80211_match_policy); | |
5529 | if (err) | |
5530 | return err; | |
5531 | /* add other standalone attributes here */ | |
5532 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
5533 | n_match_sets++; | |
5534 | continue; | |
5535 | } | |
5536 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5537 | if (rssi) | |
5538 | default_match_rssi = nla_get_s32(rssi); | |
5539 | } | |
5540 | } | |
5541 | ||
5542 | /* However, if there's no other matchset, add the RSSI one */ | |
5543 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
5544 | n_match_sets = 1; | |
a1f1c21c LC |
5545 | |
5546 | if (n_match_sets > wiphy->max_match_sets) | |
5547 | return -EINVAL; | |
5548 | ||
807f8a8c LC |
5549 | if (info->attrs[NL80211_ATTR_IE]) |
5550 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5551 | else | |
5552 | ie_len = 0; | |
5553 | ||
5a865bad | 5554 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5555 | return -EINVAL; |
5556 | ||
c10841ca LC |
5557 | if (rdev->sched_scan_req) { |
5558 | err = -EINPROGRESS; | |
5559 | goto out; | |
5560 | } | |
5561 | ||
807f8a8c | 5562 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5563 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5564 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5565 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5566 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5567 | if (!request) { |
5568 | err = -ENOMEM; | |
5569 | goto out; | |
5570 | } | |
807f8a8c LC |
5571 | |
5572 | if (n_ssids) | |
5573 | request->ssids = (void *)&request->channels[n_channels]; | |
5574 | request->n_ssids = n_ssids; | |
5575 | if (ie_len) { | |
5576 | if (request->ssids) | |
5577 | request->ie = (void *)(request->ssids + n_ssids); | |
5578 | else | |
5579 | request->ie = (void *)(request->channels + n_channels); | |
5580 | } | |
5581 | ||
a1f1c21c LC |
5582 | if (n_match_sets) { |
5583 | if (request->ie) | |
5584 | request->match_sets = (void *)(request->ie + ie_len); | |
5585 | else if (request->ssids) | |
5586 | request->match_sets = | |
5587 | (void *)(request->ssids + n_ssids); | |
5588 | else | |
5589 | request->match_sets = | |
5590 | (void *)(request->channels + n_channels); | |
5591 | } | |
5592 | request->n_match_sets = n_match_sets; | |
5593 | ||
807f8a8c LC |
5594 | i = 0; |
5595 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5596 | /* user specified, bail out if channel not found */ | |
5597 | nla_for_each_nested(attr, | |
5598 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5599 | tmp) { | |
5600 | struct ieee80211_channel *chan; | |
5601 | ||
5602 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5603 | ||
5604 | if (!chan) { | |
5605 | err = -EINVAL; | |
5606 | goto out_free; | |
5607 | } | |
5608 | ||
5609 | /* ignore disabled channels */ | |
5610 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5611 | continue; | |
5612 | ||
5613 | request->channels[i] = chan; | |
5614 | i++; | |
5615 | } | |
5616 | } else { | |
5617 | /* all channels */ | |
5618 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5619 | int j; | |
5620 | if (!wiphy->bands[band]) | |
5621 | continue; | |
5622 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5623 | struct ieee80211_channel *chan; | |
5624 | ||
5625 | chan = &wiphy->bands[band]->channels[j]; | |
5626 | ||
5627 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5628 | continue; | |
5629 | ||
5630 | request->channels[i] = chan; | |
5631 | i++; | |
5632 | } | |
5633 | } | |
5634 | } | |
5635 | ||
5636 | if (!i) { | |
5637 | err = -EINVAL; | |
5638 | goto out_free; | |
5639 | } | |
5640 | ||
5641 | request->n_channels = i; | |
5642 | ||
5643 | i = 0; | |
5644 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5645 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5646 | tmp) { | |
57a27e1d | 5647 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5648 | err = -EINVAL; |
5649 | goto out_free; | |
5650 | } | |
57a27e1d | 5651 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5652 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5653 | nla_len(attr)); | |
807f8a8c LC |
5654 | i++; |
5655 | } | |
5656 | } | |
5657 | ||
a1f1c21c LC |
5658 | i = 0; |
5659 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5660 | nla_for_each_nested(attr, | |
5661 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5662 | tmp) { | |
88e920b4 | 5663 | struct nlattr *ssid, *rssi; |
a1f1c21c | 5664 | |
ae811e21 JB |
5665 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
5666 | nla_data(attr), nla_len(attr), | |
5667 | nl80211_match_policy); | |
5668 | if (err) | |
5669 | goto out_free; | |
4a4ab0d7 | 5670 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 5671 | if (ssid) { |
ea73cbce JB |
5672 | if (WARN_ON(i >= n_match_sets)) { |
5673 | /* this indicates a programming error, | |
5674 | * the loop above should have verified | |
5675 | * things properly | |
5676 | */ | |
5677 | err = -EINVAL; | |
5678 | goto out_free; | |
5679 | } | |
5680 | ||
a1f1c21c LC |
5681 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
5682 | err = -EINVAL; | |
5683 | goto out_free; | |
5684 | } | |
5685 | memcpy(request->match_sets[i].ssid.ssid, | |
5686 | nla_data(ssid), nla_len(ssid)); | |
5687 | request->match_sets[i].ssid.ssid_len = | |
5688 | nla_len(ssid); | |
ea73cbce JB |
5689 | /* special attribute - old implemenation w/a */ |
5690 | request->match_sets[i].rssi_thold = | |
5691 | default_match_rssi; | |
5692 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
5693 | if (rssi) | |
5694 | request->match_sets[i].rssi_thold = | |
5695 | nla_get_s32(rssi); | |
a1f1c21c LC |
5696 | } |
5697 | i++; | |
5698 | } | |
ea73cbce JB |
5699 | |
5700 | /* there was no other matchset, so the RSSI one is alone */ | |
5701 | if (i == 0) | |
5702 | request->match_sets[0].rssi_thold = default_match_rssi; | |
5703 | ||
5704 | request->min_rssi_thold = INT_MAX; | |
5705 | for (i = 0; i < n_match_sets; i++) | |
5706 | request->min_rssi_thold = | |
5707 | min(request->match_sets[i].rssi_thold, | |
5708 | request->min_rssi_thold); | |
5709 | } else { | |
5710 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5711 | } |
5712 | ||
9900e484 JB |
5713 | if (ie_len) { |
5714 | request->ie_len = ie_len; | |
807f8a8c LC |
5715 | memcpy((void *)request->ie, |
5716 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5717 | request->ie_len); | |
5718 | } | |
5719 | ||
46856bbf | 5720 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5721 | request->flags = nla_get_u32( |
5722 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5723 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5724 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5725 | err = -EOPNOTSUPP; |
5726 | goto out_free; | |
5727 | } | |
5728 | } | |
ed473771 | 5729 | |
807f8a8c LC |
5730 | request->dev = dev; |
5731 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5732 | request->interval = interval; |
15d6030b | 5733 | request->scan_start = jiffies; |
807f8a8c | 5734 | |
e35e4d28 | 5735 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5736 | if (!err) { |
5737 | rdev->sched_scan_req = request; | |
5738 | nl80211_send_sched_scan(rdev, dev, | |
5739 | NL80211_CMD_START_SCHED_SCAN); | |
5740 | goto out; | |
5741 | } | |
5742 | ||
5743 | out_free: | |
5744 | kfree(request); | |
5745 | out: | |
5746 | return err; | |
5747 | } | |
5748 | ||
5749 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5750 | struct genl_info *info) | |
5751 | { | |
5752 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5753 | ||
5754 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5755 | !rdev->ops->sched_scan_stop) | |
5756 | return -EOPNOTSUPP; | |
5757 | ||
5fe231e8 | 5758 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5759 | } |
5760 | ||
04f39047 SW |
5761 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5762 | struct genl_info *info) | |
5763 | { | |
5764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5765 | struct net_device *dev = info->user_ptr[1]; | |
5766 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5767 | struct cfg80211_chan_def chandef; | |
55f7435c | 5768 | enum nl80211_dfs_regions dfs_region; |
04f39047 SW |
5769 | int err; |
5770 | ||
55f7435c LR |
5771 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
5772 | if (dfs_region == NL80211_DFS_UNSET) | |
5773 | return -EINVAL; | |
5774 | ||
04f39047 SW |
5775 | err = nl80211_parse_chandef(rdev, info, &chandef); |
5776 | if (err) | |
5777 | return err; | |
5778 | ||
ff311bc1 SW |
5779 | if (netif_carrier_ok(dev)) |
5780 | return -EBUSY; | |
5781 | ||
04f39047 SW |
5782 | if (wdev->cac_started) |
5783 | return -EBUSY; | |
5784 | ||
5785 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5786 | if (err < 0) | |
5787 | return err; | |
5788 | ||
5789 | if (err == 0) | |
5790 | return -EINVAL; | |
5791 | ||
fe7c3a1f | 5792 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
5793 | return -EINVAL; |
5794 | ||
5795 | if (!rdev->ops->start_radar_detection) | |
5796 | return -EOPNOTSUPP; | |
5797 | ||
04f39047 SW |
5798 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5799 | chandef.chan, CHAN_MODE_SHARED, | |
5800 | BIT(chandef.width)); | |
5801 | if (err) | |
5fe231e8 | 5802 | return err; |
04f39047 SW |
5803 | |
5804 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5805 | if (!err) { | |
9e0e2961 | 5806 | wdev->chandef = chandef; |
04f39047 SW |
5807 | wdev->cac_started = true; |
5808 | wdev->cac_start_time = jiffies; | |
5809 | } | |
04f39047 SW |
5810 | return err; |
5811 | } | |
5812 | ||
16ef1fe2 SW |
5813 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
5814 | { | |
5815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5816 | struct net_device *dev = info->user_ptr[1]; | |
5817 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5818 | struct cfg80211_csa_settings params; | |
5819 | /* csa_attrs is defined static to avoid waste of stack size - this | |
5820 | * function is called under RTNL lock, so this should not be a problem. | |
5821 | */ | |
5822 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
5823 | u8 radar_detect_width = 0; | |
5824 | int err; | |
ee4bc9e7 | 5825 | bool need_new_beacon = false; |
16ef1fe2 SW |
5826 | |
5827 | if (!rdev->ops->channel_switch || | |
5828 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
5829 | return -EOPNOTSUPP; | |
5830 | ||
ee4bc9e7 SW |
5831 | switch (dev->ieee80211_ptr->iftype) { |
5832 | case NL80211_IFTYPE_AP: | |
5833 | case NL80211_IFTYPE_P2P_GO: | |
5834 | need_new_beacon = true; | |
5835 | ||
5836 | /* useless if AP is not running */ | |
5837 | if (!wdev->beacon_interval) | |
1ff79dfa | 5838 | return -ENOTCONN; |
ee4bc9e7 SW |
5839 | break; |
5840 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
5841 | if (!wdev->ssid_len) |
5842 | return -ENOTCONN; | |
5843 | break; | |
c6da674a | 5844 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
5845 | if (!wdev->mesh_id_len) |
5846 | return -ENOTCONN; | |
ee4bc9e7 SW |
5847 | break; |
5848 | default: | |
16ef1fe2 | 5849 | return -EOPNOTSUPP; |
ee4bc9e7 | 5850 | } |
16ef1fe2 SW |
5851 | |
5852 | memset(¶ms, 0, sizeof(params)); | |
5853 | ||
5854 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5855 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
5856 | return -EINVAL; | |
5857 | ||
5858 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 5859 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
5860 | return -EINVAL; |
5861 | ||
5862 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
5863 | ||
ee4bc9e7 SW |
5864 | if (!need_new_beacon) |
5865 | goto skip_beacons; | |
5866 | ||
16ef1fe2 SW |
5867 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
5868 | if (err) | |
5869 | return err; | |
5870 | ||
5871 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
5872 | info->attrs[NL80211_ATTR_CSA_IES], | |
5873 | nl80211_policy); | |
5874 | if (err) | |
5875 | return err; | |
5876 | ||
5877 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
5878 | if (err) | |
5879 | return err; | |
5880 | ||
5881 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
5882 | return -EINVAL; | |
5883 | ||
5884 | params.counter_offset_beacon = | |
5885 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
5886 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) | |
5887 | return -EINVAL; | |
5888 | ||
5889 | /* sanity check - counters should be the same */ | |
5890 | if (params.beacon_csa.tail[params.counter_offset_beacon] != | |
5891 | params.count) | |
5892 | return -EINVAL; | |
5893 | ||
5894 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { | |
5895 | params.counter_offset_presp = | |
5896 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
5897 | if (params.counter_offset_presp >= | |
5898 | params.beacon_csa.probe_resp_len) | |
5899 | return -EINVAL; | |
5900 | ||
5901 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != | |
5902 | params.count) | |
5903 | return -EINVAL; | |
5904 | } | |
5905 | ||
ee4bc9e7 | 5906 | skip_beacons: |
16ef1fe2 SW |
5907 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
5908 | if (err) | |
5909 | return err; | |
5910 | ||
5911 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) | |
5912 | return -EINVAL; | |
5913 | ||
ee4bc9e7 | 5914 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
5336fa88 SW |
5915 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
5916 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { | |
ee4bc9e7 SW |
5917 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
5918 | ¶ms.chandef); | |
5919 | if (err < 0) { | |
5920 | return err; | |
5921 | } else if (err) { | |
5922 | radar_detect_width = BIT(params.chandef.width); | |
5923 | params.radar_required = true; | |
5924 | } | |
16ef1fe2 SW |
5925 | } |
5926 | ||
5927 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5928 | params.chandef.chan, | |
5929 | CHAN_MODE_SHARED, | |
5930 | radar_detect_width); | |
5931 | if (err) | |
5932 | return err; | |
5933 | ||
5934 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) | |
5935 | params.block_tx = true; | |
5936 | ||
c56589ed SW |
5937 | wdev_lock(wdev); |
5938 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
5939 | wdev_unlock(wdev); | |
5940 | ||
5941 | return err; | |
16ef1fe2 SW |
5942 | } |
5943 | ||
9720bb3a JB |
5944 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5945 | u32 seq, int flags, | |
2a519311 | 5946 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5947 | struct wireless_dev *wdev, |
5948 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5949 | { |
48ab905d | 5950 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5951 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5952 | void *hdr; |
5953 | struct nlattr *bss; | |
8cef2c9d | 5954 | bool tsf = false; |
48ab905d JB |
5955 | |
5956 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5957 | |
15e47304 | 5958 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5959 | NL80211_CMD_NEW_SCAN_RESULTS); |
5960 | if (!hdr) | |
5961 | return -1; | |
5962 | ||
9720bb3a JB |
5963 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5964 | ||
97990a06 JB |
5965 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5966 | goto nla_put_failure; | |
5967 | if (wdev->netdev && | |
9360ffd1 DM |
5968 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5969 | goto nla_put_failure; | |
97990a06 JB |
5970 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5971 | goto nla_put_failure; | |
2a519311 JB |
5972 | |
5973 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5974 | if (!bss) | |
5975 | goto nla_put_failure; | |
9360ffd1 | 5976 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5977 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5978 | goto nla_put_failure; |
9caf0364 JB |
5979 | |
5980 | rcu_read_lock(); | |
5981 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5982 | if (ies) { |
5983 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5984 | goto fail_unlock_rcu; | |
5985 | tsf = true; | |
5986 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5987 | ies->len, ies->data)) | |
5988 | goto fail_unlock_rcu; | |
9caf0364 JB |
5989 | } |
5990 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5991 | if (ies) { |
5992 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5993 | goto fail_unlock_rcu; | |
5994 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5995 | ies->len, ies->data)) | |
5996 | goto fail_unlock_rcu; | |
9caf0364 JB |
5997 | } |
5998 | rcu_read_unlock(); | |
5999 | ||
9360ffd1 DM |
6000 | if (res->beacon_interval && |
6001 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6002 | goto nla_put_failure; | |
6003 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6004 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6005 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6006 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6007 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6008 | goto nla_put_failure; | |
2a519311 | 6009 | |
77965c97 | 6010 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6011 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6012 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6013 | goto nla_put_failure; | |
2a519311 JB |
6014 | break; |
6015 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6016 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6017 | goto nla_put_failure; | |
2a519311 JB |
6018 | break; |
6019 | default: | |
6020 | break; | |
6021 | } | |
6022 | ||
48ab905d | 6023 | switch (wdev->iftype) { |
074ac8df | 6024 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6025 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6026 | if (intbss == wdev->current_bss && |
6027 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6028 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6029 | goto nla_put_failure; | |
48ab905d JB |
6030 | break; |
6031 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6032 | if (intbss == wdev->current_bss && |
6033 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6034 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6035 | goto nla_put_failure; | |
48ab905d JB |
6036 | break; |
6037 | default: | |
6038 | break; | |
6039 | } | |
6040 | ||
2a519311 JB |
6041 | nla_nest_end(msg, bss); |
6042 | ||
6043 | return genlmsg_end(msg, hdr); | |
6044 | ||
8cef2c9d JB |
6045 | fail_unlock_rcu: |
6046 | rcu_read_unlock(); | |
2a519311 JB |
6047 | nla_put_failure: |
6048 | genlmsg_cancel(msg, hdr); | |
6049 | return -EMSGSIZE; | |
6050 | } | |
6051 | ||
97990a06 | 6052 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6053 | { |
48ab905d | 6054 | struct cfg80211_registered_device *rdev; |
2a519311 | 6055 | struct cfg80211_internal_bss *scan; |
48ab905d | 6056 | struct wireless_dev *wdev; |
97990a06 | 6057 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6058 | int err; |
6059 | ||
97990a06 | 6060 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6061 | if (err) |
6062 | return err; | |
2a519311 | 6063 | |
48ab905d JB |
6064 | wdev_lock(wdev); |
6065 | spin_lock_bh(&rdev->bss_lock); | |
6066 | cfg80211_bss_expire(rdev); | |
6067 | ||
9720bb3a JB |
6068 | cb->seq = rdev->bss_generation; |
6069 | ||
48ab905d | 6070 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6071 | if (++idx <= start) |
6072 | continue; | |
9720bb3a | 6073 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6074 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6075 | rdev, wdev, scan) < 0) { |
2a519311 | 6076 | idx--; |
67748893 | 6077 | break; |
2a519311 JB |
6078 | } |
6079 | } | |
6080 | ||
48ab905d JB |
6081 | spin_unlock_bh(&rdev->bss_lock); |
6082 | wdev_unlock(wdev); | |
2a519311 | 6083 | |
97990a06 JB |
6084 | cb->args[2] = idx; |
6085 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6086 | |
67748893 | 6087 | return skb->len; |
2a519311 JB |
6088 | } |
6089 | ||
15e47304 | 6090 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6091 | int flags, struct net_device *dev, |
6092 | struct survey_info *survey) | |
6093 | { | |
6094 | void *hdr; | |
6095 | struct nlattr *infoattr; | |
6096 | ||
15e47304 | 6097 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6098 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6099 | if (!hdr) | |
6100 | return -ENOMEM; | |
6101 | ||
9360ffd1 DM |
6102 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6103 | goto nla_put_failure; | |
61fa713c HS |
6104 | |
6105 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6106 | if (!infoattr) | |
6107 | goto nla_put_failure; | |
6108 | ||
9360ffd1 DM |
6109 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6110 | survey->channel->center_freq)) | |
6111 | goto nla_put_failure; | |
6112 | ||
6113 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6114 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6115 | goto nla_put_failure; | |
6116 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6117 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6118 | goto nla_put_failure; | |
6119 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6120 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6121 | survey->channel_time)) | |
6122 | goto nla_put_failure; | |
6123 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6124 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6125 | survey->channel_time_busy)) | |
6126 | goto nla_put_failure; | |
6127 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6128 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6129 | survey->channel_time_ext_busy)) | |
6130 | goto nla_put_failure; | |
6131 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6132 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6133 | survey->channel_time_rx)) | |
6134 | goto nla_put_failure; | |
6135 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6136 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6137 | survey->channel_time_tx)) | |
6138 | goto nla_put_failure; | |
61fa713c HS |
6139 | |
6140 | nla_nest_end(msg, infoattr); | |
6141 | ||
6142 | return genlmsg_end(msg, hdr); | |
6143 | ||
6144 | nla_put_failure: | |
6145 | genlmsg_cancel(msg, hdr); | |
6146 | return -EMSGSIZE; | |
6147 | } | |
6148 | ||
6149 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6150 | struct netlink_callback *cb) | |
6151 | { | |
6152 | struct survey_info survey; | |
6153 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
6154 | struct wireless_dev *wdev; |
6155 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6156 | int res; |
6157 | ||
97990a06 | 6158 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
6159 | if (res) |
6160 | return res; | |
61fa713c | 6161 | |
97990a06 JB |
6162 | if (!wdev->netdev) { |
6163 | res = -EINVAL; | |
6164 | goto out_err; | |
6165 | } | |
6166 | ||
61fa713c HS |
6167 | if (!dev->ops->dump_survey) { |
6168 | res = -EOPNOTSUPP; | |
6169 | goto out_err; | |
6170 | } | |
6171 | ||
6172 | while (1) { | |
180cdc79 LR |
6173 | struct ieee80211_channel *chan; |
6174 | ||
97990a06 | 6175 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6176 | if (res == -ENOENT) |
6177 | break; | |
6178 | if (res) | |
6179 | goto out_err; | |
6180 | ||
180cdc79 LR |
6181 | /* Survey without a channel doesn't make sense */ |
6182 | if (!survey.channel) { | |
6183 | res = -EINVAL; | |
6184 | goto out; | |
6185 | } | |
6186 | ||
6187 | chan = ieee80211_get_channel(&dev->wiphy, | |
6188 | survey.channel->center_freq); | |
6189 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6190 | survey_idx++; | |
6191 | continue; | |
6192 | } | |
6193 | ||
61fa713c | 6194 | if (nl80211_send_survey(skb, |
15e47304 | 6195 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6196 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6197 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6198 | goto out; |
6199 | survey_idx++; | |
6200 | } | |
6201 | ||
6202 | out: | |
97990a06 | 6203 | cb->args[2] = survey_idx; |
61fa713c HS |
6204 | res = skb->len; |
6205 | out_err: | |
97990a06 | 6206 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
6207 | return res; |
6208 | } | |
6209 | ||
b23aa676 SO |
6210 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6211 | { | |
6212 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6213 | NL80211_WPA_VERSION_2)); | |
6214 | } | |
6215 | ||
636a5d36 JM |
6216 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6217 | { | |
4c476991 JB |
6218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6219 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6220 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6221 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6222 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6223 | enum nl80211_auth_type auth_type; |
fffd0934 | 6224 | struct key_parse key; |
d5cdfacb | 6225 | bool local_state_change; |
636a5d36 | 6226 | |
f4a11bb0 JB |
6227 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6228 | return -EINVAL; | |
6229 | ||
6230 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6231 | return -EINVAL; | |
6232 | ||
1778092e JM |
6233 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6234 | return -EINVAL; | |
6235 | ||
19957bb3 JB |
6236 | if (!info->attrs[NL80211_ATTR_SSID]) |
6237 | return -EINVAL; | |
6238 | ||
6239 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6240 | return -EINVAL; | |
6241 | ||
fffd0934 JB |
6242 | err = nl80211_parse_key(info, &key); |
6243 | if (err) | |
6244 | return err; | |
6245 | ||
6246 | if (key.idx >= 0) { | |
e31b8213 JB |
6247 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6248 | return -EINVAL; | |
fffd0934 JB |
6249 | if (!key.p.key || !key.p.key_len) |
6250 | return -EINVAL; | |
6251 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6252 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6253 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6254 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6255 | return -EINVAL; | |
6256 | if (key.idx > 4) | |
6257 | return -EINVAL; | |
6258 | } else { | |
6259 | key.p.key_len = 0; | |
6260 | key.p.key = NULL; | |
6261 | } | |
6262 | ||
afea0b7a JB |
6263 | if (key.idx >= 0) { |
6264 | int i; | |
6265 | bool ok = false; | |
6266 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6267 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6268 | ok = true; | |
6269 | break; | |
6270 | } | |
6271 | } | |
4c476991 JB |
6272 | if (!ok) |
6273 | return -EINVAL; | |
afea0b7a JB |
6274 | } |
6275 | ||
4c476991 JB |
6276 | if (!rdev->ops->auth) |
6277 | return -EOPNOTSUPP; | |
636a5d36 | 6278 | |
074ac8df | 6279 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6280 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6281 | return -EOPNOTSUPP; | |
eec60b03 | 6282 | |
19957bb3 | 6283 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6284 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6285 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6286 | if (!chan) | |
4c476991 | 6287 | return -EINVAL; |
636a5d36 | 6288 | |
19957bb3 JB |
6289 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6290 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6291 | |
6292 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6293 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6294 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6295 | } |
6296 | ||
19957bb3 | 6297 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6298 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6299 | return -EINVAL; |
636a5d36 | 6300 | |
e39e5b5e JM |
6301 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6302 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6303 | return -EINVAL; | |
6304 | ||
6305 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6306 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6307 | return -EINVAL; | |
6308 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6309 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6310 | /* need to include at least Auth Transaction and Status Code */ | |
6311 | if (sae_data_len < 4) | |
6312 | return -EINVAL; | |
6313 | } | |
6314 | ||
d5cdfacb JM |
6315 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6316 | ||
95de817b JB |
6317 | /* |
6318 | * Since we no longer track auth state, ignore | |
6319 | * requests to only change local state. | |
6320 | */ | |
6321 | if (local_state_change) | |
6322 | return 0; | |
6323 | ||
91bf9b26 JB |
6324 | wdev_lock(dev->ieee80211_ptr); |
6325 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6326 | ssid, ssid_len, ie, ie_len, | |
6327 | key.p.key, key.p.key_len, key.idx, | |
6328 | sae_data, sae_data_len); | |
6329 | wdev_unlock(dev->ieee80211_ptr); | |
6330 | return err; | |
636a5d36 JM |
6331 | } |
6332 | ||
c0692b8f JB |
6333 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6334 | struct genl_info *info, | |
3dc27d25 JB |
6335 | struct cfg80211_crypto_settings *settings, |
6336 | int cipher_limit) | |
b23aa676 | 6337 | { |
c0b2bbd8 JB |
6338 | memset(settings, 0, sizeof(*settings)); |
6339 | ||
b23aa676 SO |
6340 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6341 | ||
c0692b8f JB |
6342 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6343 | u16 proto; | |
6344 | proto = nla_get_u16( | |
6345 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6346 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6347 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6348 | proto != ETH_P_PAE) | |
6349 | return -EINVAL; | |
6350 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6351 | settings->control_port_no_encrypt = true; | |
6352 | } else | |
6353 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6354 | ||
b23aa676 SO |
6355 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6356 | void *data; | |
6357 | int len, i; | |
6358 | ||
6359 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6360 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6361 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6362 | ||
6363 | if (len % sizeof(u32)) | |
6364 | return -EINVAL; | |
6365 | ||
3dc27d25 | 6366 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6367 | return -EINVAL; |
6368 | ||
6369 | memcpy(settings->ciphers_pairwise, data, len); | |
6370 | ||
6371 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6372 | if (!cfg80211_supported_cipher_suite( |
6373 | &rdev->wiphy, | |
b23aa676 SO |
6374 | settings->ciphers_pairwise[i])) |
6375 | return -EINVAL; | |
6376 | } | |
6377 | ||
6378 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6379 | settings->cipher_group = | |
6380 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6381 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6382 | settings->cipher_group)) | |
b23aa676 SO |
6383 | return -EINVAL; |
6384 | } | |
6385 | ||
6386 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6387 | settings->wpa_versions = | |
6388 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6389 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6390 | return -EINVAL; | |
6391 | } | |
6392 | ||
6393 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6394 | void *data; | |
6d30240e | 6395 | int len; |
b23aa676 SO |
6396 | |
6397 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6398 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6399 | settings->n_akm_suites = len / sizeof(u32); | |
6400 | ||
6401 | if (len % sizeof(u32)) | |
6402 | return -EINVAL; | |
6403 | ||
1b9ca027 JM |
6404 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6405 | return -EINVAL; | |
6406 | ||
b23aa676 | 6407 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6408 | } |
6409 | ||
6410 | return 0; | |
6411 | } | |
6412 | ||
636a5d36 JM |
6413 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6414 | { | |
4c476991 JB |
6415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6416 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6417 | struct ieee80211_channel *chan; |
f62fab73 JB |
6418 | struct cfg80211_assoc_request req = {}; |
6419 | const u8 *bssid, *ssid; | |
6420 | int err, ssid_len = 0; | |
636a5d36 | 6421 | |
f4a11bb0 JB |
6422 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6423 | return -EINVAL; | |
6424 | ||
6425 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6426 | !info->attrs[NL80211_ATTR_SSID] || |
6427 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6428 | return -EINVAL; |
6429 | ||
4c476991 JB |
6430 | if (!rdev->ops->assoc) |
6431 | return -EOPNOTSUPP; | |
636a5d36 | 6432 | |
074ac8df | 6433 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6434 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6435 | return -EOPNOTSUPP; | |
eec60b03 | 6436 | |
19957bb3 | 6437 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6438 | |
664834de JM |
6439 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6440 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6441 | if (!chan) | |
4c476991 | 6442 | return -EINVAL; |
636a5d36 | 6443 | |
19957bb3 JB |
6444 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6445 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6446 | |
6447 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6448 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6449 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6450 | } |
6451 | ||
dc6382ce | 6452 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6453 | enum nl80211_mfp mfp = |
dc6382ce | 6454 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6455 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6456 | req.use_mfp = true; |
4c476991 JB |
6457 | else if (mfp != NL80211_MFP_NO) |
6458 | return -EINVAL; | |
dc6382ce JM |
6459 | } |
6460 | ||
3e5d7649 | 6461 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6462 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6463 | |
7e7c8926 | 6464 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6465 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6466 | |
6467 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6468 | memcpy(&req.ht_capa_mask, |
6469 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6470 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6471 | |
6472 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6473 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6474 | return -EINVAL; |
f62fab73 JB |
6475 | memcpy(&req.ht_capa, |
6476 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6477 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6478 | } |
6479 | ||
ee2aca34 | 6480 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6481 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6482 | |
6483 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6484 | memcpy(&req.vht_capa_mask, |
6485 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6486 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6487 | |
6488 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6489 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6490 | return -EINVAL; |
f62fab73 JB |
6491 | memcpy(&req.vht_capa, |
6492 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6493 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6494 | } |
6495 | ||
f62fab73 | 6496 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6497 | if (!err) { |
6498 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6499 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6500 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6501 | wdev_unlock(dev->ieee80211_ptr); |
6502 | } | |
636a5d36 | 6503 | |
636a5d36 JM |
6504 | return err; |
6505 | } | |
6506 | ||
6507 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6508 | { | |
4c476991 JB |
6509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6510 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6511 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6512 | int ie_len = 0, err; |
19957bb3 | 6513 | u16 reason_code; |
d5cdfacb | 6514 | bool local_state_change; |
636a5d36 | 6515 | |
f4a11bb0 JB |
6516 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6517 | return -EINVAL; | |
6518 | ||
6519 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6520 | return -EINVAL; | |
6521 | ||
6522 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6523 | return -EINVAL; | |
6524 | ||
4c476991 JB |
6525 | if (!rdev->ops->deauth) |
6526 | return -EOPNOTSUPP; | |
636a5d36 | 6527 | |
074ac8df | 6528 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6529 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6530 | return -EOPNOTSUPP; | |
eec60b03 | 6531 | |
19957bb3 | 6532 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6533 | |
19957bb3 JB |
6534 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6535 | if (reason_code == 0) { | |
f4a11bb0 | 6536 | /* Reason Code 0 is reserved */ |
4c476991 | 6537 | return -EINVAL; |
255e737e | 6538 | } |
636a5d36 JM |
6539 | |
6540 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6541 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6542 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6543 | } |
6544 | ||
d5cdfacb JM |
6545 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6546 | ||
91bf9b26 JB |
6547 | wdev_lock(dev->ieee80211_ptr); |
6548 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6549 | local_state_change); | |
6550 | wdev_unlock(dev->ieee80211_ptr); | |
6551 | return err; | |
636a5d36 JM |
6552 | } |
6553 | ||
6554 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6555 | { | |
4c476991 JB |
6556 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6557 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6558 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6559 | int ie_len = 0, err; |
19957bb3 | 6560 | u16 reason_code; |
d5cdfacb | 6561 | bool local_state_change; |
636a5d36 | 6562 | |
f4a11bb0 JB |
6563 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6564 | return -EINVAL; | |
6565 | ||
6566 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6567 | return -EINVAL; | |
6568 | ||
6569 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6570 | return -EINVAL; | |
6571 | ||
4c476991 JB |
6572 | if (!rdev->ops->disassoc) |
6573 | return -EOPNOTSUPP; | |
636a5d36 | 6574 | |
074ac8df | 6575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6576 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6577 | return -EOPNOTSUPP; | |
eec60b03 | 6578 | |
19957bb3 | 6579 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6580 | |
19957bb3 JB |
6581 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6582 | if (reason_code == 0) { | |
f4a11bb0 | 6583 | /* Reason Code 0 is reserved */ |
4c476991 | 6584 | return -EINVAL; |
255e737e | 6585 | } |
636a5d36 JM |
6586 | |
6587 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6588 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6589 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6590 | } |
6591 | ||
d5cdfacb JM |
6592 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6593 | ||
91bf9b26 JB |
6594 | wdev_lock(dev->ieee80211_ptr); |
6595 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6596 | local_state_change); | |
6597 | wdev_unlock(dev->ieee80211_ptr); | |
6598 | return err; | |
636a5d36 JM |
6599 | } |
6600 | ||
dd5b4cc7 FF |
6601 | static bool |
6602 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6603 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6604 | int rateval) | |
6605 | { | |
6606 | struct wiphy *wiphy = &rdev->wiphy; | |
6607 | bool found = false; | |
6608 | int band, i; | |
6609 | ||
6610 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6611 | struct ieee80211_supported_band *sband; | |
6612 | ||
6613 | sband = wiphy->bands[band]; | |
6614 | if (!sband) | |
6615 | continue; | |
6616 | ||
6617 | for (i = 0; i < sband->n_bitrates; i++) { | |
6618 | if (sband->bitrates[i].bitrate == rateval) { | |
6619 | mcast_rate[band] = i + 1; | |
6620 | found = true; | |
6621 | break; | |
6622 | } | |
6623 | } | |
6624 | } | |
6625 | ||
6626 | return found; | |
6627 | } | |
6628 | ||
04a773ad JB |
6629 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6630 | { | |
4c476991 JB |
6631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6632 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6633 | struct cfg80211_ibss_params ibss; |
6634 | struct wiphy *wiphy; | |
fffd0934 | 6635 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6636 | int err; |
6637 | ||
8e30bc55 JB |
6638 | memset(&ibss, 0, sizeof(ibss)); |
6639 | ||
04a773ad JB |
6640 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6641 | return -EINVAL; | |
6642 | ||
683b6d3b | 6643 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6644 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6645 | return -EINVAL; | |
6646 | ||
8e30bc55 JB |
6647 | ibss.beacon_interval = 100; |
6648 | ||
6649 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6650 | ibss.beacon_interval = | |
6651 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6652 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6653 | return -EINVAL; | |
6654 | } | |
6655 | ||
4c476991 JB |
6656 | if (!rdev->ops->join_ibss) |
6657 | return -EOPNOTSUPP; | |
04a773ad | 6658 | |
4c476991 JB |
6659 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6660 | return -EOPNOTSUPP; | |
04a773ad | 6661 | |
79c97e97 | 6662 | wiphy = &rdev->wiphy; |
04a773ad | 6663 | |
39193498 | 6664 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6665 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6666 | |
6667 | if (!is_valid_ether_addr(ibss.bssid)) | |
6668 | return -EINVAL; | |
6669 | } | |
04a773ad JB |
6670 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6671 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6672 | ||
6673 | if (info->attrs[NL80211_ATTR_IE]) { | |
6674 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6675 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6676 | } | |
6677 | ||
683b6d3b JB |
6678 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6679 | if (err) | |
6680 | return err; | |
04a773ad | 6681 | |
683b6d3b | 6682 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6683 | return -EINVAL; |
6684 | ||
2f301ab2 | 6685 | switch (ibss.chandef.width) { |
bf372645 SW |
6686 | case NL80211_CHAN_WIDTH_5: |
6687 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6688 | case NL80211_CHAN_WIDTH_20_NOHT: |
6689 | break; | |
6690 | case NL80211_CHAN_WIDTH_20: | |
6691 | case NL80211_CHAN_WIDTH_40: | |
6692 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6693 | break; | |
6694 | default: | |
c04d6150 | 6695 | return -EINVAL; |
2f301ab2 | 6696 | } |
db9c64cf | 6697 | |
04a773ad | 6698 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6699 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6700 | ||
fbd2c8dc TP |
6701 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6702 | u8 *rates = | |
6703 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6704 | int n_rates = | |
6705 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6706 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6707 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6708 | |
34850ab2 JB |
6709 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6710 | &ibss.basic_rates); | |
6711 | if (err) | |
6712 | return err; | |
fbd2c8dc | 6713 | } |
dd5b4cc7 | 6714 | |
803768f5 SW |
6715 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6716 | memcpy(&ibss.ht_capa_mask, | |
6717 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6718 | sizeof(ibss.ht_capa_mask)); | |
6719 | ||
6720 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6721 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6722 | return -EINVAL; | |
6723 | memcpy(&ibss.ht_capa, | |
6724 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6725 | sizeof(ibss.ht_capa)); | |
6726 | } | |
6727 | ||
dd5b4cc7 FF |
6728 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6729 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6730 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6731 | return -EINVAL; | |
fbd2c8dc | 6732 | |
4c476991 | 6733 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6734 | bool no_ht = false; |
6735 | ||
4c476991 | 6736 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6737 | info->attrs[NL80211_ATTR_KEYS], |
6738 | &no_ht); | |
4c476991 JB |
6739 | if (IS_ERR(connkeys)) |
6740 | return PTR_ERR(connkeys); | |
de7044ee | 6741 | |
3d9d1d66 JB |
6742 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6743 | no_ht) { | |
de7044ee SM |
6744 | kfree(connkeys); |
6745 | return -EINVAL; | |
6746 | } | |
4c476991 | 6747 | } |
04a773ad | 6748 | |
267335d6 AQ |
6749 | ibss.control_port = |
6750 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6751 | ||
5336fa88 SW |
6752 | ibss.userspace_handles_dfs = |
6753 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
6754 | ||
4c476991 | 6755 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6756 | if (err) |
6757 | kfree(connkeys); | |
04a773ad JB |
6758 | return err; |
6759 | } | |
6760 | ||
6761 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6762 | { | |
4c476991 JB |
6763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6764 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6765 | |
4c476991 JB |
6766 | if (!rdev->ops->leave_ibss) |
6767 | return -EOPNOTSUPP; | |
04a773ad | 6768 | |
4c476991 JB |
6769 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6770 | return -EOPNOTSUPP; | |
04a773ad | 6771 | |
4c476991 | 6772 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6773 | } |
6774 | ||
f4e583c8 AQ |
6775 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6776 | { | |
6777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6778 | struct net_device *dev = info->user_ptr[1]; | |
6779 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6780 | u32 nla_rate; | |
6781 | int err; | |
6782 | ||
6783 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6784 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6785 | return -EOPNOTSUPP; | |
6786 | ||
6787 | if (!rdev->ops->set_mcast_rate) | |
6788 | return -EOPNOTSUPP; | |
6789 | ||
6790 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6791 | ||
6792 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6793 | return -EINVAL; | |
6794 | ||
6795 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6796 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6797 | return -EINVAL; | |
6798 | ||
6799 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6800 | ||
6801 | return err; | |
6802 | } | |
6803 | ||
ad7e718c JB |
6804 | static struct sk_buff * |
6805 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6806 | int approxlen, u32 portid, u32 seq, | |
6807 | enum nl80211_commands cmd, | |
567ffc35 JB |
6808 | enum nl80211_attrs attr, |
6809 | const struct nl80211_vendor_cmd_info *info, | |
6810 | gfp_t gfp) | |
ad7e718c JB |
6811 | { |
6812 | struct sk_buff *skb; | |
6813 | void *hdr; | |
6814 | struct nlattr *data; | |
6815 | ||
6816 | skb = nlmsg_new(approxlen + 100, gfp); | |
6817 | if (!skb) | |
6818 | return NULL; | |
6819 | ||
6820 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
6821 | if (!hdr) { | |
6822 | kfree_skb(skb); | |
6823 | return NULL; | |
6824 | } | |
6825 | ||
6826 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
6827 | goto nla_put_failure; | |
567ffc35 JB |
6828 | |
6829 | if (info) { | |
6830 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
6831 | info->vendor_id)) | |
6832 | goto nla_put_failure; | |
6833 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
6834 | info->subcmd)) | |
6835 | goto nla_put_failure; | |
6836 | } | |
6837 | ||
ad7e718c JB |
6838 | data = nla_nest_start(skb, attr); |
6839 | ||
6840 | ((void **)skb->cb)[0] = rdev; | |
6841 | ((void **)skb->cb)[1] = hdr; | |
6842 | ((void **)skb->cb)[2] = data; | |
6843 | ||
6844 | return skb; | |
6845 | ||
6846 | nla_put_failure: | |
6847 | kfree_skb(skb); | |
6848 | return NULL; | |
6849 | } | |
f4e583c8 | 6850 | |
e03ad6ea JB |
6851 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6852 | enum nl80211_commands cmd, | |
6853 | enum nl80211_attrs attr, | |
6854 | int vendor_event_idx, | |
6855 | int approxlen, gfp_t gfp) | |
6856 | { | |
6857 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6858 | const struct nl80211_vendor_cmd_info *info; | |
6859 | ||
6860 | switch (cmd) { | |
6861 | case NL80211_CMD_TESTMODE: | |
6862 | if (WARN_ON(vendor_event_idx != -1)) | |
6863 | return NULL; | |
6864 | info = NULL; | |
6865 | break; | |
6866 | case NL80211_CMD_VENDOR: | |
6867 | if (WARN_ON(vendor_event_idx < 0 || | |
6868 | vendor_event_idx >= wiphy->n_vendor_events)) | |
6869 | return NULL; | |
6870 | info = &wiphy->vendor_events[vendor_event_idx]; | |
6871 | break; | |
6872 | default: | |
6873 | WARN_ON(1); | |
6874 | return NULL; | |
6875 | } | |
6876 | ||
6877 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
6878 | cmd, attr, info, gfp); | |
6879 | } | |
6880 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
6881 | ||
6882 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
6883 | { | |
6884 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6885 | void *hdr = ((void **)skb->cb)[1]; | |
6886 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6887 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
6888 | ||
6889 | nla_nest_end(skb, data); | |
6890 | genlmsg_end(skb, hdr); | |
6891 | ||
6892 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
6893 | mcgrp = NL80211_MCGRP_VENDOR; | |
6894 | ||
6895 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
6896 | mcgrp, gfp); | |
6897 | } | |
6898 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
6899 | ||
aff89a9b | 6900 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
6901 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
6902 | { | |
4c476991 | 6903 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
6904 | struct wireless_dev *wdev = |
6905 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
6906 | int err; |
6907 | ||
fc73f11f DS |
6908 | if (!rdev->ops->testmode_cmd) |
6909 | return -EOPNOTSUPP; | |
6910 | ||
6911 | if (IS_ERR(wdev)) { | |
6912 | err = PTR_ERR(wdev); | |
6913 | if (err != -EINVAL) | |
6914 | return err; | |
6915 | wdev = NULL; | |
6916 | } else if (wdev->wiphy != &rdev->wiphy) { | |
6917 | return -EINVAL; | |
6918 | } | |
6919 | ||
aff89a9b JB |
6920 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
6921 | return -EINVAL; | |
6922 | ||
ad7e718c | 6923 | rdev->cur_cmd_info = info; |
fc73f11f | 6924 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
6925 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6926 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 6927 | rdev->cur_cmd_info = NULL; |
aff89a9b | 6928 | |
aff89a9b JB |
6929 | return err; |
6930 | } | |
6931 | ||
71063f0e WYG |
6932 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6933 | struct netlink_callback *cb) | |
6934 | { | |
00918d33 | 6935 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6936 | int err; |
6937 | long phy_idx; | |
6938 | void *data = NULL; | |
6939 | int data_len = 0; | |
6940 | ||
5fe231e8 JB |
6941 | rtnl_lock(); |
6942 | ||
71063f0e WYG |
6943 | if (cb->args[0]) { |
6944 | /* | |
6945 | * 0 is a valid index, but not valid for args[0], | |
6946 | * so we need to offset by 1. | |
6947 | */ | |
6948 | phy_idx = cb->args[0] - 1; | |
6949 | } else { | |
6950 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6951 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6952 | nl80211_policy); | |
6953 | if (err) | |
5fe231e8 | 6954 | goto out_err; |
00918d33 | 6955 | |
2bd7e35d JB |
6956 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6957 | nl80211_fam.attrbuf); | |
6958 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6959 | err = PTR_ERR(rdev); |
6960 | goto out_err; | |
00918d33 | 6961 | } |
2bd7e35d JB |
6962 | phy_idx = rdev->wiphy_idx; |
6963 | rdev = NULL; | |
2bd7e35d | 6964 | |
71063f0e WYG |
6965 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6966 | cb->args[1] = | |
6967 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6968 | } | |
6969 | ||
6970 | if (cb->args[1]) { | |
6971 | data = nla_data((void *)cb->args[1]); | |
6972 | data_len = nla_len((void *)cb->args[1]); | |
6973 | } | |
6974 | ||
00918d33 JB |
6975 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6976 | if (!rdev) { | |
5fe231e8 JB |
6977 | err = -ENOENT; |
6978 | goto out_err; | |
71063f0e | 6979 | } |
71063f0e | 6980 | |
00918d33 | 6981 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6982 | err = -EOPNOTSUPP; |
6983 | goto out_err; | |
6984 | } | |
6985 | ||
6986 | while (1) { | |
15e47304 | 6987 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6988 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6989 | NL80211_CMD_TESTMODE); | |
6990 | struct nlattr *tmdata; | |
6991 | ||
cb35fba3 DC |
6992 | if (!hdr) |
6993 | break; | |
6994 | ||
9360ffd1 | 6995 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6996 | genlmsg_cancel(skb, hdr); |
6997 | break; | |
6998 | } | |
6999 | ||
7000 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7001 | if (!tmdata) { | |
7002 | genlmsg_cancel(skb, hdr); | |
7003 | break; | |
7004 | } | |
e35e4d28 | 7005 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7006 | nla_nest_end(skb, tmdata); |
7007 | ||
7008 | if (err == -ENOBUFS || err == -ENOENT) { | |
7009 | genlmsg_cancel(skb, hdr); | |
7010 | break; | |
7011 | } else if (err) { | |
7012 | genlmsg_cancel(skb, hdr); | |
7013 | goto out_err; | |
7014 | } | |
7015 | ||
7016 | genlmsg_end(skb, hdr); | |
7017 | } | |
7018 | ||
7019 | err = skb->len; | |
7020 | /* see above */ | |
7021 | cb->args[0] = phy_idx + 1; | |
7022 | out_err: | |
5fe231e8 | 7023 | rtnl_unlock(); |
71063f0e WYG |
7024 | return err; |
7025 | } | |
aff89a9b JB |
7026 | #endif |
7027 | ||
b23aa676 SO |
7028 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7029 | { | |
4c476991 JB |
7030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7031 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7032 | struct cfg80211_connect_params connect; |
7033 | struct wiphy *wiphy; | |
fffd0934 | 7034 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7035 | int err; |
7036 | ||
7037 | memset(&connect, 0, sizeof(connect)); | |
7038 | ||
7039 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7040 | return -EINVAL; | |
7041 | ||
7042 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7043 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7044 | return -EINVAL; | |
7045 | ||
7046 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7047 | connect.auth_type = | |
7048 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7049 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7050 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7051 | return -EINVAL; |
7052 | } else | |
7053 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7054 | ||
7055 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7056 | ||
c0692b8f | 7057 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7058 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7059 | if (err) |
7060 | return err; | |
b23aa676 | 7061 | |
074ac8df | 7062 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7063 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7064 | return -EOPNOTSUPP; | |
b23aa676 | 7065 | |
79c97e97 | 7066 | wiphy = &rdev->wiphy; |
b23aa676 | 7067 | |
4486ea98 BS |
7068 | connect.bg_scan_period = -1; |
7069 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7070 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7071 | connect.bg_scan_period = | |
7072 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7073 | } | |
7074 | ||
b23aa676 SO |
7075 | if (info->attrs[NL80211_ATTR_MAC]) |
7076 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7077 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7078 | connect.bssid_hint = | |
7079 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7080 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7081 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7082 | ||
7083 | if (info->attrs[NL80211_ATTR_IE]) { | |
7084 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7085 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7086 | } | |
7087 | ||
cee00a95 JM |
7088 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7089 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7090 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7091 | connect.mfp != NL80211_MFP_NO) | |
7092 | return -EINVAL; | |
7093 | } else { | |
7094 | connect.mfp = NL80211_MFP_NO; | |
7095 | } | |
7096 | ||
b23aa676 | 7097 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7098 | connect.channel = nl80211_get_valid_chan( |
7099 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7100 | if (!connect.channel) | |
1df4a510 JM |
7101 | return -EINVAL; |
7102 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7103 | connect.channel_hint = nl80211_get_valid_chan( |
7104 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7105 | if (!connect.channel_hint) | |
4c476991 | 7106 | return -EINVAL; |
b23aa676 SO |
7107 | } |
7108 | ||
fffd0934 JB |
7109 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7110 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7111 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7112 | if (IS_ERR(connkeys)) |
7113 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7114 | } |
7115 | ||
7e7c8926 BG |
7116 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7117 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7118 | ||
7119 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7120 | memcpy(&connect.ht_capa_mask, | |
7121 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7122 | sizeof(connect.ht_capa_mask)); | |
7123 | ||
7124 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
7125 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
7126 | kfree(connkeys); | |
7e7c8926 | 7127 | return -EINVAL; |
b4e4f47e | 7128 | } |
7e7c8926 BG |
7129 | memcpy(&connect.ht_capa, |
7130 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7131 | sizeof(connect.ht_capa)); | |
7132 | } | |
7133 | ||
ee2aca34 JB |
7134 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7135 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7136 | ||
7137 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7138 | memcpy(&connect.vht_capa_mask, | |
7139 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7140 | sizeof(connect.vht_capa_mask)); | |
7141 | ||
7142 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7143 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
7144 | kfree(connkeys); | |
7145 | return -EINVAL; | |
7146 | } | |
7147 | memcpy(&connect.vht_capa, | |
7148 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7149 | sizeof(connect.vht_capa)); | |
7150 | } | |
7151 | ||
83739b03 JB |
7152 | wdev_lock(dev->ieee80211_ptr); |
7153 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7154 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
7155 | if (err) |
7156 | kfree(connkeys); | |
b23aa676 SO |
7157 | return err; |
7158 | } | |
7159 | ||
7160 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7161 | { | |
4c476991 JB |
7162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7163 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7164 | u16 reason; |
83739b03 | 7165 | int ret; |
b23aa676 SO |
7166 | |
7167 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7168 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7169 | else | |
7170 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7171 | ||
7172 | if (reason == 0) | |
7173 | return -EINVAL; | |
7174 | ||
074ac8df | 7175 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7176 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7177 | return -EOPNOTSUPP; | |
b23aa676 | 7178 | |
83739b03 JB |
7179 | wdev_lock(dev->ieee80211_ptr); |
7180 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7181 | wdev_unlock(dev->ieee80211_ptr); | |
7182 | return ret; | |
b23aa676 SO |
7183 | } |
7184 | ||
463d0183 JB |
7185 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7186 | { | |
4c476991 | 7187 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7188 | struct net *net; |
7189 | int err; | |
7190 | u32 pid; | |
7191 | ||
7192 | if (!info->attrs[NL80211_ATTR_PID]) | |
7193 | return -EINVAL; | |
7194 | ||
7195 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7196 | ||
463d0183 | 7197 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7198 | if (IS_ERR(net)) |
7199 | return PTR_ERR(net); | |
463d0183 JB |
7200 | |
7201 | err = 0; | |
7202 | ||
7203 | /* check if anything to do */ | |
4c476991 JB |
7204 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7205 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7206 | |
463d0183 | 7207 | put_net(net); |
463d0183 JB |
7208 | return err; |
7209 | } | |
7210 | ||
67fbb16b SO |
7211 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7212 | { | |
4c476991 | 7213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7214 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7215 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7216 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7217 | struct cfg80211_pmksa pmksa; |
7218 | ||
7219 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7220 | ||
7221 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7222 | return -EINVAL; | |
7223 | ||
7224 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7225 | return -EINVAL; | |
7226 | ||
67fbb16b SO |
7227 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7228 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7229 | ||
074ac8df | 7230 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7231 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7232 | return -EOPNOTSUPP; | |
67fbb16b SO |
7233 | |
7234 | switch (info->genlhdr->cmd) { | |
7235 | case NL80211_CMD_SET_PMKSA: | |
7236 | rdev_ops = rdev->ops->set_pmksa; | |
7237 | break; | |
7238 | case NL80211_CMD_DEL_PMKSA: | |
7239 | rdev_ops = rdev->ops->del_pmksa; | |
7240 | break; | |
7241 | default: | |
7242 | WARN_ON(1); | |
7243 | break; | |
7244 | } | |
7245 | ||
4c476991 JB |
7246 | if (!rdev_ops) |
7247 | return -EOPNOTSUPP; | |
67fbb16b | 7248 | |
4c476991 | 7249 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7250 | } |
7251 | ||
7252 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7253 | { | |
4c476991 JB |
7254 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7255 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7256 | |
074ac8df | 7257 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7258 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7259 | return -EOPNOTSUPP; | |
67fbb16b | 7260 | |
4c476991 JB |
7261 | if (!rdev->ops->flush_pmksa) |
7262 | return -EOPNOTSUPP; | |
67fbb16b | 7263 | |
e35e4d28 | 7264 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7265 | } |
7266 | ||
109086ce AN |
7267 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7268 | { | |
7269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7270 | struct net_device *dev = info->user_ptr[1]; | |
7271 | u8 action_code, dialog_token; | |
7272 | u16 status_code; | |
7273 | u8 *peer; | |
7274 | ||
7275 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7276 | !rdev->ops->tdls_mgmt) | |
7277 | return -EOPNOTSUPP; | |
7278 | ||
7279 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7280 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7281 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7282 | !info->attrs[NL80211_ATTR_IE] || | |
7283 | !info->attrs[NL80211_ATTR_MAC]) | |
7284 | return -EINVAL; | |
7285 | ||
7286 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7287 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7288 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7289 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
7290 | ||
e35e4d28 HG |
7291 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
7292 | dialog_token, status_code, | |
7293 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
7294 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7295 | } |
7296 | ||
7297 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7298 | { | |
7299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7300 | struct net_device *dev = info->user_ptr[1]; | |
7301 | enum nl80211_tdls_operation operation; | |
7302 | u8 *peer; | |
7303 | ||
7304 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7305 | !rdev->ops->tdls_oper) | |
7306 | return -EOPNOTSUPP; | |
7307 | ||
7308 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7309 | !info->attrs[NL80211_ATTR_MAC]) | |
7310 | return -EINVAL; | |
7311 | ||
7312 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7313 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7314 | ||
e35e4d28 | 7315 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7316 | } |
7317 | ||
9588bbd5 JM |
7318 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7319 | struct genl_info *info) | |
7320 | { | |
4c476991 | 7321 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7322 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7323 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7324 | struct sk_buff *msg; |
7325 | void *hdr; | |
7326 | u64 cookie; | |
683b6d3b | 7327 | u32 duration; |
9588bbd5 JM |
7328 | int err; |
7329 | ||
7330 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7331 | !info->attrs[NL80211_ATTR_DURATION]) | |
7332 | return -EINVAL; | |
7333 | ||
7334 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7335 | ||
ebf348fc JB |
7336 | if (!rdev->ops->remain_on_channel || |
7337 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7338 | return -EOPNOTSUPP; | |
7339 | ||
9588bbd5 | 7340 | /* |
ebf348fc JB |
7341 | * We should be on that channel for at least a minimum amount of |
7342 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7343 | */ |
ebf348fc | 7344 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7345 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7346 | return -EINVAL; |
7347 | ||
683b6d3b JB |
7348 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7349 | if (err) | |
7350 | return err; | |
9588bbd5 JM |
7351 | |
7352 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7353 | if (!msg) |
7354 | return -ENOMEM; | |
9588bbd5 | 7355 | |
15e47304 | 7356 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7357 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7358 | if (!hdr) { |
7359 | err = -ENOBUFS; | |
9588bbd5 JM |
7360 | goto free_msg; |
7361 | } | |
7362 | ||
683b6d3b JB |
7363 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7364 | duration, &cookie); | |
9588bbd5 JM |
7365 | |
7366 | if (err) | |
7367 | goto free_msg; | |
7368 | ||
9360ffd1 DM |
7369 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7370 | goto nla_put_failure; | |
9588bbd5 JM |
7371 | |
7372 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7373 | |
7374 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7375 | |
7376 | nla_put_failure: | |
7377 | err = -ENOBUFS; | |
7378 | free_msg: | |
7379 | nlmsg_free(msg); | |
9588bbd5 JM |
7380 | return err; |
7381 | } | |
7382 | ||
7383 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7384 | struct genl_info *info) | |
7385 | { | |
4c476991 | 7386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7387 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7388 | u64 cookie; |
9588bbd5 JM |
7389 | |
7390 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7391 | return -EINVAL; | |
7392 | ||
4c476991 JB |
7393 | if (!rdev->ops->cancel_remain_on_channel) |
7394 | return -EOPNOTSUPP; | |
9588bbd5 | 7395 | |
9588bbd5 JM |
7396 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7397 | ||
e35e4d28 | 7398 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7399 | } |
7400 | ||
13ae75b1 JM |
7401 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7402 | u8 *rates, u8 rates_len) | |
7403 | { | |
7404 | u8 i; | |
7405 | u32 mask = 0; | |
7406 | ||
7407 | for (i = 0; i < rates_len; i++) { | |
7408 | int rate = (rates[i] & 0x7f) * 5; | |
7409 | int ridx; | |
7410 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7411 | struct ieee80211_rate *srate = | |
7412 | &sband->bitrates[ridx]; | |
7413 | if (rate == srate->bitrate) { | |
7414 | mask |= 1 << ridx; | |
7415 | break; | |
7416 | } | |
7417 | } | |
7418 | if (ridx == sband->n_bitrates) | |
7419 | return 0; /* rate not found */ | |
7420 | } | |
7421 | ||
7422 | return mask; | |
7423 | } | |
7424 | ||
24db78c0 SW |
7425 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7426 | u8 *rates, u8 rates_len, | |
7427 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7428 | { | |
7429 | u8 i; | |
7430 | ||
7431 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7432 | ||
7433 | for (i = 0; i < rates_len; i++) { | |
7434 | int ridx, rbit; | |
7435 | ||
7436 | ridx = rates[i] / 8; | |
7437 | rbit = BIT(rates[i] % 8); | |
7438 | ||
7439 | /* check validity */ | |
910570b5 | 7440 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7441 | return false; |
7442 | ||
7443 | /* check availability */ | |
7444 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7445 | mcs[ridx] |= rbit; | |
7446 | else | |
7447 | return false; | |
7448 | } | |
7449 | ||
7450 | return true; | |
7451 | } | |
7452 | ||
204e35a9 JD |
7453 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
7454 | { | |
7455 | u16 mcs_mask = 0; | |
7456 | ||
7457 | switch (vht_mcs_map) { | |
7458 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
7459 | break; | |
7460 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
7461 | mcs_mask = 0x00FF; | |
7462 | break; | |
7463 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
7464 | mcs_mask = 0x01FF; | |
7465 | break; | |
7466 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
7467 | mcs_mask = 0x03FF; | |
7468 | break; | |
7469 | default: | |
7470 | break; | |
7471 | } | |
7472 | ||
7473 | return mcs_mask; | |
7474 | } | |
7475 | ||
7476 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
7477 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
7478 | { | |
7479 | u8 nss; | |
7480 | ||
7481 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
7482 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
7483 | vht_mcs_map >>= 2; | |
7484 | } | |
7485 | } | |
7486 | ||
7487 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
7488 | struct nl80211_txrate_vht *txrate, | |
7489 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
7490 | { | |
7491 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7492 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
7493 | u8 i; | |
7494 | ||
7495 | if (!sband->vht_cap.vht_supported) | |
7496 | return false; | |
7497 | ||
7498 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
7499 | ||
7500 | /* Build vht_mcs_mask from VHT capabilities */ | |
7501 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
7502 | ||
7503 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7504 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
7505 | mcs[i] = txrate->mcs[i]; | |
7506 | else | |
7507 | return false; | |
7508 | } | |
7509 | ||
7510 | return true; | |
7511 | } | |
7512 | ||
b54452b0 | 7513 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7514 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7515 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
7516 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
7517 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 7518 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 7519 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
7520 | }; |
7521 | ||
7522 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7523 | struct genl_info *info) | |
7524 | { | |
7525 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7527 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7528 | int rem, i; |
7529 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7530 | struct nlattr *tx_rates; |
7531 | struct ieee80211_supported_band *sband; | |
204e35a9 | 7532 | u16 vht_tx_mcs_map; |
13ae75b1 | 7533 | |
4c476991 JB |
7534 | if (!rdev->ops->set_bitrate_mask) |
7535 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7536 | |
7537 | memset(&mask, 0, sizeof(mask)); | |
7538 | /* Default to all rates enabled */ | |
7539 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7540 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
7541 | |
7542 | if (!sband) | |
7543 | continue; | |
7544 | ||
7545 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 7546 | memcpy(mask.control[i].ht_mcs, |
7869303b | 7547 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 7548 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
7549 | |
7550 | if (!sband->vht_cap.vht_supported) | |
7551 | continue; | |
7552 | ||
7553 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7554 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
7555 | } |
7556 | ||
b9243ab0 JD |
7557 | /* if no rates are given set it back to the defaults */ |
7558 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
7559 | goto out; | |
7560 | ||
13ae75b1 JM |
7561 | /* |
7562 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7563 | * directly to the enum ieee80211_band values used in cfg80211. | |
7564 | */ | |
24db78c0 | 7565 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 7566 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 7567 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
7568 | int err; |
7569 | ||
4c476991 JB |
7570 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7571 | return -EINVAL; | |
13ae75b1 | 7572 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7573 | if (sband == NULL) |
7574 | return -EINVAL; | |
ae811e21 JB |
7575 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7576 | nla_len(tx_rates), nl80211_txattr_policy); | |
7577 | if (err) | |
7578 | return err; | |
13ae75b1 JM |
7579 | if (tb[NL80211_TXRATE_LEGACY]) { |
7580 | mask.control[band].legacy = rateset_to_mask( | |
7581 | sband, | |
7582 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7583 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7584 | if ((mask.control[band].legacy == 0) && |
7585 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7586 | return -EINVAL; | |
24db78c0 | 7587 | } |
d1e33e65 | 7588 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
7589 | if (!ht_rateset_to_mask( |
7590 | sband, | |
d1e33e65 JD |
7591 | nla_data(tb[NL80211_TXRATE_HT]), |
7592 | nla_len(tb[NL80211_TXRATE_HT]), | |
7593 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
7594 | return -EINVAL; |
7595 | } | |
204e35a9 JD |
7596 | if (tb[NL80211_TXRATE_VHT]) { |
7597 | if (!vht_set_mcs_mask( | |
7598 | sband, | |
7599 | nla_data(tb[NL80211_TXRATE_VHT]), | |
7600 | mask.control[band].vht_mcs)) | |
7601 | return -EINVAL; | |
7602 | } | |
0b9323f6 JD |
7603 | if (tb[NL80211_TXRATE_GI]) { |
7604 | mask.control[band].gi = | |
7605 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
7606 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
7607 | return -EINVAL; | |
7608 | } | |
24db78c0 SW |
7609 | |
7610 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
7611 | /* don't allow empty legacy rates if HT or VHT |
7612 | * are not even supported. | |
7613 | */ | |
7614 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
7615 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
7616 | return -EINVAL; |
7617 | ||
7618 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 7619 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
7620 | goto out; |
7621 | ||
7622 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
7623 | if (mask.control[band].vht_mcs[i]) | |
7624 | goto out; | |
24db78c0 SW |
7625 | |
7626 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 7627 | return -EINVAL; |
13ae75b1 JM |
7628 | } |
7629 | } | |
7630 | ||
b9243ab0 | 7631 | out: |
e35e4d28 | 7632 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7633 | } |
7634 | ||
2e161f78 | 7635 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7636 | { |
4c476991 | 7637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7638 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7639 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7640 | |
7641 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7642 | return -EINVAL; | |
7643 | ||
2e161f78 JB |
7644 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7645 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7646 | |
71bbc994 JB |
7647 | switch (wdev->iftype) { |
7648 | case NL80211_IFTYPE_STATION: | |
7649 | case NL80211_IFTYPE_ADHOC: | |
7650 | case NL80211_IFTYPE_P2P_CLIENT: | |
7651 | case NL80211_IFTYPE_AP: | |
7652 | case NL80211_IFTYPE_AP_VLAN: | |
7653 | case NL80211_IFTYPE_MESH_POINT: | |
7654 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7655 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7656 | break; |
7657 | default: | |
4c476991 | 7658 | return -EOPNOTSUPP; |
71bbc994 | 7659 | } |
026331c4 JM |
7660 | |
7661 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7662 | if (!rdev->ops->mgmt_tx) |
7663 | return -EOPNOTSUPP; | |
026331c4 | 7664 | |
15e47304 | 7665 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7666 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7667 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7668 | } |
7669 | ||
2e161f78 | 7670 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7671 | { |
4c476991 | 7672 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7673 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7674 | struct cfg80211_chan_def chandef; |
026331c4 | 7675 | int err; |
d64d373f | 7676 | void *hdr = NULL; |
026331c4 | 7677 | u64 cookie; |
e247bd90 | 7678 | struct sk_buff *msg = NULL; |
b176e629 AO |
7679 | struct cfg80211_mgmt_tx_params params = { |
7680 | .dont_wait_for_ack = | |
7681 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7682 | }; | |
026331c4 | 7683 | |
683b6d3b | 7684 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7685 | return -EINVAL; |
7686 | ||
4c476991 JB |
7687 | if (!rdev->ops->mgmt_tx) |
7688 | return -EOPNOTSUPP; | |
026331c4 | 7689 | |
71bbc994 | 7690 | switch (wdev->iftype) { |
ea141b75 AQ |
7691 | case NL80211_IFTYPE_P2P_DEVICE: |
7692 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7693 | return -EINVAL; | |
71bbc994 JB |
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: | |
7701 | break; | |
7702 | default: | |
4c476991 | 7703 | return -EOPNOTSUPP; |
71bbc994 | 7704 | } |
026331c4 | 7705 | |
f7ca38df | 7706 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7707 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 7708 | return -EINVAL; |
b176e629 | 7709 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
7710 | |
7711 | /* | |
7712 | * We should wait on the channel for at least a minimum amount | |
7713 | * of time (10ms) but no longer than the driver supports. | |
7714 | */ | |
b176e629 AO |
7715 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
7716 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
7717 | return -EINVAL; |
7718 | ||
f7ca38df JB |
7719 | } |
7720 | ||
b176e629 | 7721 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 7722 | |
b176e629 | 7723 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
7724 | return -EINVAL; |
7725 | ||
b176e629 | 7726 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 7727 | |
ea141b75 AQ |
7728 | /* get the channel if any has been specified, otherwise pass NULL to |
7729 | * the driver. The latter will use the current one | |
7730 | */ | |
7731 | chandef.chan = NULL; | |
7732 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7733 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7734 | if (err) | |
7735 | return err; | |
7736 | } | |
7737 | ||
b176e629 | 7738 | if (!chandef.chan && params.offchan) |
ea141b75 | 7739 | return -EINVAL; |
026331c4 | 7740 | |
b176e629 | 7741 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
7742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7743 | if (!msg) | |
7744 | return -ENOMEM; | |
026331c4 | 7745 | |
15e47304 | 7746 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7747 | NL80211_CMD_FRAME); |
cb35fba3 DC |
7748 | if (!hdr) { |
7749 | err = -ENOBUFS; | |
e247bd90 JB |
7750 | goto free_msg; |
7751 | } | |
026331c4 | 7752 | } |
e247bd90 | 7753 | |
b176e629 AO |
7754 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
7755 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
7756 | params.chan = chandef.chan; | |
7757 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
7758 | if (err) |
7759 | goto free_msg; | |
7760 | ||
e247bd90 | 7761 | if (msg) { |
9360ffd1 DM |
7762 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7763 | goto nla_put_failure; | |
026331c4 | 7764 | |
e247bd90 JB |
7765 | genlmsg_end(msg, hdr); |
7766 | return genlmsg_reply(msg, info); | |
7767 | } | |
7768 | ||
7769 | return 0; | |
026331c4 JM |
7770 | |
7771 | nla_put_failure: | |
7772 | err = -ENOBUFS; | |
7773 | free_msg: | |
7774 | nlmsg_free(msg); | |
026331c4 JM |
7775 | return err; |
7776 | } | |
7777 | ||
f7ca38df JB |
7778 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7779 | { | |
7780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7781 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7782 | u64 cookie; |
7783 | ||
7784 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7785 | return -EINVAL; | |
7786 | ||
7787 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7788 | return -EOPNOTSUPP; | |
7789 | ||
71bbc994 JB |
7790 | switch (wdev->iftype) { |
7791 | case NL80211_IFTYPE_STATION: | |
7792 | case NL80211_IFTYPE_ADHOC: | |
7793 | case NL80211_IFTYPE_P2P_CLIENT: | |
7794 | case NL80211_IFTYPE_AP: | |
7795 | case NL80211_IFTYPE_AP_VLAN: | |
7796 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7797 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7798 | break; |
7799 | default: | |
f7ca38df | 7800 | return -EOPNOTSUPP; |
71bbc994 | 7801 | } |
f7ca38df JB |
7802 | |
7803 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7804 | ||
e35e4d28 | 7805 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7806 | } |
7807 | ||
ffb9eb3d KV |
7808 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7809 | { | |
4c476991 | 7810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7811 | struct wireless_dev *wdev; |
4c476991 | 7812 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7813 | u8 ps_state; |
7814 | bool state; | |
7815 | int err; | |
7816 | ||
4c476991 JB |
7817 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7818 | return -EINVAL; | |
ffb9eb3d KV |
7819 | |
7820 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7821 | ||
4c476991 JB |
7822 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7823 | return -EINVAL; | |
ffb9eb3d KV |
7824 | |
7825 | wdev = dev->ieee80211_ptr; | |
7826 | ||
4c476991 JB |
7827 | if (!rdev->ops->set_power_mgmt) |
7828 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7829 | |
7830 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7831 | ||
7832 | if (state == wdev->ps) | |
4c476991 | 7833 | return 0; |
ffb9eb3d | 7834 | |
e35e4d28 | 7835 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7836 | if (!err) |
7837 | wdev->ps = state; | |
ffb9eb3d KV |
7838 | return err; |
7839 | } | |
7840 | ||
7841 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7842 | { | |
4c476991 | 7843 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7844 | enum nl80211_ps_state ps_state; |
7845 | struct wireless_dev *wdev; | |
4c476991 | 7846 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7847 | struct sk_buff *msg; |
7848 | void *hdr; | |
7849 | int err; | |
7850 | ||
ffb9eb3d KV |
7851 | wdev = dev->ieee80211_ptr; |
7852 | ||
4c476991 JB |
7853 | if (!rdev->ops->set_power_mgmt) |
7854 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7855 | |
7856 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7857 | if (!msg) |
7858 | return -ENOMEM; | |
ffb9eb3d | 7859 | |
15e47304 | 7860 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7861 | NL80211_CMD_GET_POWER_SAVE); |
7862 | if (!hdr) { | |
4c476991 | 7863 | err = -ENOBUFS; |
ffb9eb3d KV |
7864 | goto free_msg; |
7865 | } | |
7866 | ||
7867 | if (wdev->ps) | |
7868 | ps_state = NL80211_PS_ENABLED; | |
7869 | else | |
7870 | ps_state = NL80211_PS_DISABLED; | |
7871 | ||
9360ffd1 DM |
7872 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7873 | goto nla_put_failure; | |
ffb9eb3d KV |
7874 | |
7875 | genlmsg_end(msg, hdr); | |
4c476991 | 7876 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7877 | |
4c476991 | 7878 | nla_put_failure: |
ffb9eb3d | 7879 | err = -ENOBUFS; |
4c476991 | 7880 | free_msg: |
ffb9eb3d | 7881 | nlmsg_free(msg); |
ffb9eb3d KV |
7882 | return err; |
7883 | } | |
7884 | ||
94e860f1 JB |
7885 | static const struct nla_policy |
7886 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
7887 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
7888 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7889 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7890 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7891 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7892 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7893 | }; |
7894 | ||
84f10708 | 7895 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7896 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7897 | { |
7898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 7899 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7900 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 7901 | |
d9d8b019 | 7902 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7903 | return -EINVAL; |
7904 | ||
84f10708 TP |
7905 | if (!rdev->ops->set_cqm_txe_config) |
7906 | return -EOPNOTSUPP; | |
7907 | ||
7908 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7909 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7910 | return -EOPNOTSUPP; | |
7911 | ||
e35e4d28 | 7912 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7913 | } |
7914 | ||
d6dc1a38 JO |
7915 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7916 | s32 threshold, u32 hysteresis) | |
7917 | { | |
4c476991 | 7918 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 7919 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7920 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
7921 | |
7922 | if (threshold > 0) | |
7923 | return -EINVAL; | |
7924 | ||
1da5fcc8 JB |
7925 | /* disabling - hysteresis should also be zero then */ |
7926 | if (threshold == 0) | |
7927 | hysteresis = 0; | |
d6dc1a38 | 7928 | |
4c476991 JB |
7929 | if (!rdev->ops->set_cqm_rssi_config) |
7930 | return -EOPNOTSUPP; | |
d6dc1a38 | 7931 | |
074ac8df | 7932 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7933 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7934 | return -EOPNOTSUPP; | |
d6dc1a38 | 7935 | |
e35e4d28 | 7936 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7937 | } |
7938 | ||
7939 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7940 | { | |
7941 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7942 | struct nlattr *cqm; | |
7943 | int err; | |
7944 | ||
7945 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
7946 | if (!cqm) |
7947 | return -EINVAL; | |
d6dc1a38 JO |
7948 | |
7949 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7950 | nl80211_attr_cqm_policy); | |
7951 | if (err) | |
1da5fcc8 | 7952 | return err; |
d6dc1a38 JO |
7953 | |
7954 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7955 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
7956 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
7957 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 7958 | |
1da5fcc8 JB |
7959 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
7960 | } | |
7961 | ||
7962 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
7963 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7964 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7965 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7966 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7967 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7968 | ||
7969 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
7970 | } | |
7971 | ||
7972 | return -EINVAL; | |
d6dc1a38 JO |
7973 | } |
7974 | ||
29cbe68c JB |
7975 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7976 | { | |
7977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7978 | struct net_device *dev = info->user_ptr[1]; | |
7979 | struct mesh_config cfg; | |
c80d545d | 7980 | struct mesh_setup setup; |
29cbe68c JB |
7981 | int err; |
7982 | ||
7983 | /* start with default */ | |
7984 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7985 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7986 | |
24bdd9f4 | 7987 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7988 | /* and parse parameters if given */ |
24bdd9f4 | 7989 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7990 | if (err) |
7991 | return err; | |
7992 | } | |
7993 | ||
7994 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7995 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7996 | return -EINVAL; | |
7997 | ||
c80d545d JC |
7998 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7999 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8000 | ||
4bb62344 CYY |
8001 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8002 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8003 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8004 | return -EINVAL; | |
8005 | ||
9bdbf04d MP |
8006 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8007 | setup.beacon_interval = | |
8008 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8009 | if (setup.beacon_interval < 10 || | |
8010 | setup.beacon_interval > 10000) | |
8011 | return -EINVAL; | |
8012 | } | |
8013 | ||
8014 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8015 | setup.dtim_period = | |
8016 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8017 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8018 | return -EINVAL; | |
8019 | } | |
8020 | ||
c80d545d JC |
8021 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8022 | /* parse additional setup parameters if given */ | |
8023 | err = nl80211_parse_mesh_setup(info, &setup); | |
8024 | if (err) | |
8025 | return err; | |
8026 | } | |
8027 | ||
d37bb18a TP |
8028 | if (setup.user_mpm) |
8029 | cfg.auto_open_plinks = false; | |
8030 | ||
cc1d2806 | 8031 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8032 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8033 | if (err) | |
8034 | return err; | |
cc1d2806 JB |
8035 | } else { |
8036 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8037 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8038 | } |
8039 | ||
ffb3cf30 AN |
8040 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8041 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8042 | int n_rates = | |
8043 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8044 | struct ieee80211_supported_band *sband; | |
8045 | ||
8046 | if (!setup.chandef.chan) | |
8047 | return -EINVAL; | |
8048 | ||
8049 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8050 | ||
8051 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8052 | &setup.basic_rates); | |
8053 | if (err) | |
8054 | return err; | |
8055 | } | |
8056 | ||
c80d545d | 8057 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8058 | } |
8059 | ||
8060 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8061 | { | |
8062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8063 | struct net_device *dev = info->user_ptr[1]; | |
8064 | ||
8065 | return cfg80211_leave_mesh(rdev, dev); | |
8066 | } | |
8067 | ||
dfb89c56 | 8068 | #ifdef CONFIG_PM |
bb92d199 AK |
8069 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8070 | struct cfg80211_registered_device *rdev) | |
8071 | { | |
6abb9cb9 | 8072 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8073 | struct nlattr *nl_pats, *nl_pat; |
8074 | int i, pat_len; | |
8075 | ||
6abb9cb9 | 8076 | if (!wowlan->n_patterns) |
bb92d199 AK |
8077 | return 0; |
8078 | ||
8079 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8080 | if (!nl_pats) | |
8081 | return -ENOBUFS; | |
8082 | ||
6abb9cb9 | 8083 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8084 | nl_pat = nla_nest_start(msg, i + 1); |
8085 | if (!nl_pat) | |
8086 | return -ENOBUFS; | |
6abb9cb9 | 8087 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8088 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8089 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8090 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8091 | wowlan->patterns[i].pattern) || | |
8092 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8093 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8094 | return -ENOBUFS; |
8095 | nla_nest_end(msg, nl_pat); | |
8096 | } | |
8097 | nla_nest_end(msg, nl_pats); | |
8098 | ||
8099 | return 0; | |
8100 | } | |
8101 | ||
2a0e047e JB |
8102 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8103 | struct cfg80211_wowlan_tcp *tcp) | |
8104 | { | |
8105 | struct nlattr *nl_tcp; | |
8106 | ||
8107 | if (!tcp) | |
8108 | return 0; | |
8109 | ||
8110 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8111 | if (!nl_tcp) | |
8112 | return -ENOBUFS; | |
8113 | ||
8114 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8115 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8116 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8117 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8118 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8119 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8120 | tcp->payload_len, tcp->payload) || | |
8121 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8122 | tcp->data_interval) || | |
8123 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8124 | tcp->wake_len, tcp->wake_data) || | |
8125 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8126 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8127 | return -ENOBUFS; | |
8128 | ||
8129 | if (tcp->payload_seq.len && | |
8130 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8131 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8132 | return -ENOBUFS; | |
8133 | ||
8134 | if (tcp->payload_tok.len && | |
8135 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8136 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8137 | &tcp->payload_tok)) | |
8138 | return -ENOBUFS; | |
8139 | ||
e248ad30 JB |
8140 | nla_nest_end(msg, nl_tcp); |
8141 | ||
2a0e047e JB |
8142 | return 0; |
8143 | } | |
8144 | ||
ff1b6e69 JB |
8145 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8146 | { | |
8147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8148 | struct sk_buff *msg; | |
8149 | void *hdr; | |
2a0e047e | 8150 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8151 | |
964dc9e2 | 8152 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8153 | return -EOPNOTSUPP; |
8154 | ||
6abb9cb9 | 8155 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8156 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8157 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8158 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8159 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8160 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8161 | } |
8162 | ||
8163 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8164 | if (!msg) |
8165 | return -ENOMEM; | |
8166 | ||
15e47304 | 8167 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8168 | NL80211_CMD_GET_WOWLAN); |
8169 | if (!hdr) | |
8170 | goto nla_put_failure; | |
8171 | ||
6abb9cb9 | 8172 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8173 | struct nlattr *nl_wowlan; |
8174 | ||
8175 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8176 | if (!nl_wowlan) | |
8177 | goto nla_put_failure; | |
8178 | ||
6abb9cb9 | 8179 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8180 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8181 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8182 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8183 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8184 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8185 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8186 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8187 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8188 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8189 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8190 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8191 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8192 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8193 | goto nla_put_failure; | |
2a0e047e | 8194 | |
bb92d199 AK |
8195 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8196 | goto nla_put_failure; | |
2a0e047e | 8197 | |
6abb9cb9 JB |
8198 | if (nl80211_send_wowlan_tcp(msg, |
8199 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8200 | goto nla_put_failure; |
8201 | ||
ff1b6e69 JB |
8202 | nla_nest_end(msg, nl_wowlan); |
8203 | } | |
8204 | ||
8205 | genlmsg_end(msg, hdr); | |
8206 | return genlmsg_reply(msg, info); | |
8207 | ||
8208 | nla_put_failure: | |
8209 | nlmsg_free(msg); | |
8210 | return -ENOBUFS; | |
8211 | } | |
8212 | ||
2a0e047e JB |
8213 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8214 | struct nlattr *attr, | |
8215 | struct cfg80211_wowlan *trig) | |
8216 | { | |
8217 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8218 | struct cfg80211_wowlan_tcp *cfg; | |
8219 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8220 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8221 | u32 size; | |
8222 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8223 | int err, port; | |
8224 | ||
964dc9e2 | 8225 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8226 | return -EINVAL; |
8227 | ||
8228 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8229 | nla_data(attr), nla_len(attr), | |
8230 | nl80211_wowlan_tcp_policy); | |
8231 | if (err) | |
8232 | return err; | |
8233 | ||
8234 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8235 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8236 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8237 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8238 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8239 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8240 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8241 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8242 | return -EINVAL; | |
8243 | ||
8244 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8245 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8246 | return -EINVAL; |
8247 | ||
8248 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8249 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8250 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8251 | return -EINVAL; |
8252 | ||
8253 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8254 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8255 | return -EINVAL; |
8256 | ||
8257 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8258 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8259 | return -EINVAL; | |
8260 | ||
8261 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8262 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8263 | ||
8264 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8265 | tokens_size = tokln - sizeof(*tok); | |
8266 | ||
8267 | if (!tok->len || tokens_size % tok->len) | |
8268 | return -EINVAL; | |
964dc9e2 | 8269 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8270 | return -EINVAL; |
964dc9e2 | 8271 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8272 | return -EINVAL; |
964dc9e2 | 8273 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8274 | return -EINVAL; |
964dc9e2 | 8275 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8276 | return -EINVAL; |
8277 | if (tok->offset + tok->len > data_size) | |
8278 | return -EINVAL; | |
8279 | } | |
8280 | ||
8281 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8282 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8283 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8284 | return -EINVAL; |
8285 | if (seq->len == 0 || seq->len > 4) | |
8286 | return -EINVAL; | |
8287 | if (seq->len + seq->offset > data_size) | |
8288 | return -EINVAL; | |
8289 | } | |
8290 | ||
8291 | size = sizeof(*cfg); | |
8292 | size += data_size; | |
8293 | size += wake_size + wake_mask_size; | |
8294 | size += tokens_size; | |
8295 | ||
8296 | cfg = kzalloc(size, GFP_KERNEL); | |
8297 | if (!cfg) | |
8298 | return -ENOMEM; | |
8299 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8300 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8301 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8302 | ETH_ALEN); | |
8303 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8304 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8305 | else | |
8306 | port = 0; | |
8307 | #ifdef CONFIG_INET | |
8308 | /* allocate a socket and port for it and use it */ | |
8309 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8310 | IPPROTO_TCP, &cfg->sock, 1); | |
8311 | if (err) { | |
8312 | kfree(cfg); | |
8313 | return err; | |
8314 | } | |
8315 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8316 | sock_release(cfg->sock); | |
8317 | kfree(cfg); | |
8318 | return -EADDRINUSE; | |
8319 | } | |
8320 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8321 | #else | |
8322 | if (!port) { | |
8323 | kfree(cfg); | |
8324 | return -EINVAL; | |
8325 | } | |
8326 | cfg->src_port = port; | |
8327 | #endif | |
8328 | ||
8329 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8330 | cfg->payload_len = data_size; | |
8331 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8332 | memcpy((void *)cfg->payload, | |
8333 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8334 | data_size); | |
8335 | if (seq) | |
8336 | cfg->payload_seq = *seq; | |
8337 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8338 | cfg->wake_len = wake_size; | |
8339 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8340 | memcpy((void *)cfg->wake_data, | |
8341 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8342 | wake_size); | |
8343 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8344 | data_size + wake_size; | |
8345 | memcpy((void *)cfg->wake_mask, | |
8346 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8347 | wake_mask_size); | |
8348 | if (tok) { | |
8349 | cfg->tokens_size = tokens_size; | |
8350 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8351 | } | |
8352 | ||
8353 | trig->tcp = cfg; | |
8354 | ||
8355 | return 0; | |
8356 | } | |
8357 | ||
ff1b6e69 JB |
8358 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8359 | { | |
8360 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8361 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8362 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8363 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8364 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8365 | int err, i; |
6abb9cb9 | 8366 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8367 | |
964dc9e2 | 8368 | if (!wowlan) |
ff1b6e69 JB |
8369 | return -EOPNOTSUPP; |
8370 | ||
ae33bd81 JB |
8371 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8372 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8373 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8374 | goto set_wakeup; |
8375 | } | |
ff1b6e69 JB |
8376 | |
8377 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8378 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8379 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8380 | nl80211_wowlan_policy); | |
8381 | if (err) | |
8382 | return err; | |
8383 | ||
8384 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8385 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8386 | return -EINVAL; | |
8387 | new_triggers.any = true; | |
8388 | } | |
8389 | ||
8390 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8391 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8392 | return -EINVAL; | |
8393 | new_triggers.disconnect = true; | |
8394 | } | |
8395 | ||
8396 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8397 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8398 | return -EINVAL; | |
8399 | new_triggers.magic_pkt = true; | |
8400 | } | |
8401 | ||
77dbbb13 JB |
8402 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8403 | return -EINVAL; | |
8404 | ||
8405 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8406 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8407 | return -EINVAL; | |
8408 | new_triggers.gtk_rekey_failure = true; | |
8409 | } | |
8410 | ||
8411 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8412 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8413 | return -EINVAL; | |
8414 | new_triggers.eap_identity_req = true; | |
8415 | } | |
8416 | ||
8417 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8418 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8419 | return -EINVAL; | |
8420 | new_triggers.four_way_handshake = true; | |
8421 | } | |
8422 | ||
8423 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8424 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8425 | return -EINVAL; | |
8426 | new_triggers.rfkill_release = true; | |
8427 | } | |
8428 | ||
ff1b6e69 JB |
8429 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8430 | struct nlattr *pat; | |
8431 | int n_patterns = 0; | |
bb92d199 | 8432 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8433 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8434 | |
8435 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8436 | rem) | |
8437 | n_patterns++; | |
8438 | if (n_patterns > wowlan->n_patterns) | |
8439 | return -EINVAL; | |
8440 | ||
8441 | new_triggers.patterns = kcalloc(n_patterns, | |
8442 | sizeof(new_triggers.patterns[0]), | |
8443 | GFP_KERNEL); | |
8444 | if (!new_triggers.patterns) | |
8445 | return -ENOMEM; | |
8446 | ||
8447 | new_triggers.n_patterns = n_patterns; | |
8448 | i = 0; | |
8449 | ||
8450 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8451 | rem) { | |
50ac6607 AK |
8452 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8453 | nla_len(pat), NULL); | |
ff1b6e69 | 8454 | err = -EINVAL; |
50ac6607 AK |
8455 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8456 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8457 | goto error; |
50ac6607 | 8458 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8459 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8460 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8461 | goto error; |
8462 | if (pat_len > wowlan->pattern_max_len || | |
8463 | pat_len < wowlan->pattern_min_len) | |
8464 | goto error; | |
8465 | ||
50ac6607 | 8466 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8467 | pkt_offset = 0; |
8468 | else | |
8469 | pkt_offset = nla_get_u32( | |
50ac6607 | 8470 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8471 | if (pkt_offset > wowlan->max_pkt_offset) |
8472 | goto error; | |
8473 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8474 | ||
ff1b6e69 JB |
8475 | new_triggers.patterns[i].mask = |
8476 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8477 | if (!new_triggers.patterns[i].mask) { | |
8478 | err = -ENOMEM; | |
8479 | goto error; | |
8480 | } | |
8481 | new_triggers.patterns[i].pattern = | |
8482 | new_triggers.patterns[i].mask + mask_len; | |
8483 | memcpy(new_triggers.patterns[i].mask, | |
50ac6607 | 8484 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
ff1b6e69 JB |
8485 | mask_len); |
8486 | new_triggers.patterns[i].pattern_len = pat_len; | |
8487 | memcpy(new_triggers.patterns[i].pattern, | |
50ac6607 | 8488 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8489 | pat_len); |
8490 | i++; | |
8491 | } | |
8492 | } | |
8493 | ||
2a0e047e JB |
8494 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8495 | err = nl80211_parse_wowlan_tcp( | |
8496 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8497 | &new_triggers); | |
8498 | if (err) | |
8499 | goto error; | |
8500 | } | |
8501 | ||
ae33bd81 JB |
8502 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8503 | if (!ntrig) { | |
8504 | err = -ENOMEM; | |
8505 | goto error; | |
ff1b6e69 | 8506 | } |
ae33bd81 | 8507 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8508 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8509 | |
ae33bd81 | 8510 | set_wakeup: |
6abb9cb9 JB |
8511 | if (rdev->ops->set_wakeup && |
8512 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8513 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8514 | |
ff1b6e69 JB |
8515 | return 0; |
8516 | error: | |
8517 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8518 | kfree(new_triggers.patterns[i].mask); | |
8519 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8520 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8521 | sock_release(new_triggers.tcp->sock); | |
8522 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8523 | return err; |
8524 | } | |
dfb89c56 | 8525 | #endif |
ff1b6e69 | 8526 | |
be29b99a AK |
8527 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8528 | struct cfg80211_registered_device *rdev) | |
8529 | { | |
8530 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8531 | int i, j, pat_len; | |
8532 | struct cfg80211_coalesce_rules *rule; | |
8533 | ||
8534 | if (!rdev->coalesce->n_rules) | |
8535 | return 0; | |
8536 | ||
8537 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8538 | if (!nl_rules) | |
8539 | return -ENOBUFS; | |
8540 | ||
8541 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8542 | nl_rule = nla_nest_start(msg, i + 1); | |
8543 | if (!nl_rule) | |
8544 | return -ENOBUFS; | |
8545 | ||
8546 | rule = &rdev->coalesce->rules[i]; | |
8547 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8548 | rule->delay)) | |
8549 | return -ENOBUFS; | |
8550 | ||
8551 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8552 | rule->condition)) | |
8553 | return -ENOBUFS; | |
8554 | ||
8555 | nl_pats = nla_nest_start(msg, | |
8556 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8557 | if (!nl_pats) | |
8558 | return -ENOBUFS; | |
8559 | ||
8560 | for (j = 0; j < rule->n_patterns; j++) { | |
8561 | nl_pat = nla_nest_start(msg, j + 1); | |
8562 | if (!nl_pat) | |
8563 | return -ENOBUFS; | |
8564 | pat_len = rule->patterns[j].pattern_len; | |
8565 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8566 | DIV_ROUND_UP(pat_len, 8), | |
8567 | rule->patterns[j].mask) || | |
8568 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8569 | rule->patterns[j].pattern) || | |
8570 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8571 | rule->patterns[j].pkt_offset)) | |
8572 | return -ENOBUFS; | |
8573 | nla_nest_end(msg, nl_pat); | |
8574 | } | |
8575 | nla_nest_end(msg, nl_pats); | |
8576 | nla_nest_end(msg, nl_rule); | |
8577 | } | |
8578 | nla_nest_end(msg, nl_rules); | |
8579 | ||
8580 | return 0; | |
8581 | } | |
8582 | ||
8583 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8584 | { | |
8585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8586 | struct sk_buff *msg; | |
8587 | void *hdr; | |
8588 | ||
8589 | if (!rdev->wiphy.coalesce) | |
8590 | return -EOPNOTSUPP; | |
8591 | ||
8592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8593 | if (!msg) | |
8594 | return -ENOMEM; | |
8595 | ||
8596 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8597 | NL80211_CMD_GET_COALESCE); | |
8598 | if (!hdr) | |
8599 | goto nla_put_failure; | |
8600 | ||
8601 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8602 | goto nla_put_failure; | |
8603 | ||
8604 | genlmsg_end(msg, hdr); | |
8605 | return genlmsg_reply(msg, info); | |
8606 | ||
8607 | nla_put_failure: | |
8608 | nlmsg_free(msg); | |
8609 | return -ENOBUFS; | |
8610 | } | |
8611 | ||
8612 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8613 | { | |
8614 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8615 | int i, j; | |
8616 | struct cfg80211_coalesce_rules *rule; | |
8617 | ||
8618 | if (!coalesce) | |
8619 | return; | |
8620 | ||
8621 | for (i = 0; i < coalesce->n_rules; i++) { | |
8622 | rule = &coalesce->rules[i]; | |
8623 | for (j = 0; j < rule->n_patterns; j++) | |
8624 | kfree(rule->patterns[j].mask); | |
8625 | kfree(rule->patterns); | |
8626 | } | |
8627 | kfree(coalesce->rules); | |
8628 | kfree(coalesce); | |
8629 | rdev->coalesce = NULL; | |
8630 | } | |
8631 | ||
8632 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8633 | struct nlattr *rule, | |
8634 | struct cfg80211_coalesce_rules *new_rule) | |
8635 | { | |
8636 | int err, i; | |
8637 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8638 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8639 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8640 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8641 | ||
8642 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8643 | nla_len(rule), nl80211_coalesce_policy); | |
8644 | if (err) | |
8645 | return err; | |
8646 | ||
8647 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8648 | new_rule->delay = | |
8649 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8650 | if (new_rule->delay > coalesce->max_delay) | |
8651 | return -EINVAL; | |
8652 | ||
8653 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8654 | new_rule->condition = | |
8655 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8656 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8657 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8658 | return -EINVAL; | |
8659 | ||
8660 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8661 | return -EINVAL; | |
8662 | ||
8663 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8664 | rem) | |
8665 | n_patterns++; | |
8666 | if (n_patterns > coalesce->n_patterns) | |
8667 | return -EINVAL; | |
8668 | ||
8669 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8670 | GFP_KERNEL); | |
8671 | if (!new_rule->patterns) | |
8672 | return -ENOMEM; | |
8673 | ||
8674 | new_rule->n_patterns = n_patterns; | |
8675 | i = 0; | |
8676 | ||
8677 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8678 | rem) { | |
8679 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | |
8680 | nla_len(pat), NULL); | |
8681 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8682 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8683 | return -EINVAL; | |
8684 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8685 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8686 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8687 | return -EINVAL; | |
8688 | if (pat_len > coalesce->pattern_max_len || | |
8689 | pat_len < coalesce->pattern_min_len) | |
8690 | return -EINVAL; | |
8691 | ||
8692 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8693 | pkt_offset = 0; | |
8694 | else | |
8695 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8696 | if (pkt_offset > coalesce->max_pkt_offset) | |
8697 | return -EINVAL; | |
8698 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8699 | ||
8700 | new_rule->patterns[i].mask = | |
8701 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8702 | if (!new_rule->patterns[i].mask) | |
8703 | return -ENOMEM; | |
8704 | new_rule->patterns[i].pattern = | |
8705 | new_rule->patterns[i].mask + mask_len; | |
8706 | memcpy(new_rule->patterns[i].mask, | |
8707 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); | |
8708 | new_rule->patterns[i].pattern_len = pat_len; | |
8709 | memcpy(new_rule->patterns[i].pattern, | |
8710 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); | |
8711 | i++; | |
8712 | } | |
8713 | ||
8714 | return 0; | |
8715 | } | |
8716 | ||
8717 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8718 | { | |
8719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8720 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8721 | struct cfg80211_coalesce new_coalesce = {}; | |
8722 | struct cfg80211_coalesce *n_coalesce; | |
8723 | int err, rem_rule, n_rules = 0, i, j; | |
8724 | struct nlattr *rule; | |
8725 | struct cfg80211_coalesce_rules *tmp_rule; | |
8726 | ||
8727 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8728 | return -EOPNOTSUPP; | |
8729 | ||
8730 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8731 | cfg80211_rdev_free_coalesce(rdev); | |
8732 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8733 | return 0; | |
8734 | } | |
8735 | ||
8736 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8737 | rem_rule) | |
8738 | n_rules++; | |
8739 | if (n_rules > coalesce->n_rules) | |
8740 | return -EINVAL; | |
8741 | ||
8742 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8743 | GFP_KERNEL); | |
8744 | if (!new_coalesce.rules) | |
8745 | return -ENOMEM; | |
8746 | ||
8747 | new_coalesce.n_rules = n_rules; | |
8748 | i = 0; | |
8749 | ||
8750 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8751 | rem_rule) { | |
8752 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8753 | &new_coalesce.rules[i]); | |
8754 | if (err) | |
8755 | goto error; | |
8756 | ||
8757 | i++; | |
8758 | } | |
8759 | ||
8760 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8761 | if (err) | |
8762 | goto error; | |
8763 | ||
8764 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8765 | if (!n_coalesce) { | |
8766 | err = -ENOMEM; | |
8767 | goto error; | |
8768 | } | |
8769 | cfg80211_rdev_free_coalesce(rdev); | |
8770 | rdev->coalesce = n_coalesce; | |
8771 | ||
8772 | return 0; | |
8773 | error: | |
8774 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8775 | tmp_rule = &new_coalesce.rules[i]; | |
8776 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8777 | kfree(tmp_rule->patterns[j].mask); | |
8778 | kfree(tmp_rule->patterns); | |
8779 | } | |
8780 | kfree(new_coalesce.rules); | |
8781 | ||
8782 | return err; | |
8783 | } | |
8784 | ||
e5497d76 JB |
8785 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8786 | { | |
8787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8788 | struct net_device *dev = info->user_ptr[1]; | |
8789 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8790 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8791 | struct cfg80211_gtk_rekey_data rekey_data; | |
8792 | int err; | |
8793 | ||
8794 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8795 | return -EINVAL; | |
8796 | ||
8797 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8798 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8799 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8800 | nl80211_rekey_policy); | |
8801 | if (err) | |
8802 | return err; | |
8803 | ||
8804 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8805 | return -ERANGE; | |
8806 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8807 | return -ERANGE; | |
8808 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8809 | return -ERANGE; | |
8810 | ||
8811 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8812 | NL80211_KEK_LEN); | |
8813 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8814 | NL80211_KCK_LEN); | |
8815 | memcpy(rekey_data.replay_ctr, | |
8816 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8817 | NL80211_REPLAY_CTR_LEN); | |
8818 | ||
8819 | wdev_lock(wdev); | |
8820 | if (!wdev->current_bss) { | |
8821 | err = -ENOTCONN; | |
8822 | goto out; | |
8823 | } | |
8824 | ||
8825 | if (!rdev->ops->set_rekey_data) { | |
8826 | err = -EOPNOTSUPP; | |
8827 | goto out; | |
8828 | } | |
8829 | ||
e35e4d28 | 8830 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8831 | out: |
8832 | wdev_unlock(wdev); | |
8833 | return err; | |
8834 | } | |
8835 | ||
28946da7 JB |
8836 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8837 | struct genl_info *info) | |
8838 | { | |
8839 | struct net_device *dev = info->user_ptr[1]; | |
8840 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8841 | ||
8842 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8843 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8844 | return -EINVAL; | |
8845 | ||
15e47304 | 8846 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8847 | return -EBUSY; |
8848 | ||
15e47304 | 8849 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8850 | return 0; |
8851 | } | |
8852 | ||
7f6cf311 JB |
8853 | static int nl80211_probe_client(struct sk_buff *skb, |
8854 | struct genl_info *info) | |
8855 | { | |
8856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8857 | struct net_device *dev = info->user_ptr[1]; | |
8858 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8859 | struct sk_buff *msg; | |
8860 | void *hdr; | |
8861 | const u8 *addr; | |
8862 | u64 cookie; | |
8863 | int err; | |
8864 | ||
8865 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8866 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8867 | return -EOPNOTSUPP; | |
8868 | ||
8869 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8870 | return -EINVAL; | |
8871 | ||
8872 | if (!rdev->ops->probe_client) | |
8873 | return -EOPNOTSUPP; | |
8874 | ||
8875 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8876 | if (!msg) | |
8877 | return -ENOMEM; | |
8878 | ||
15e47304 | 8879 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 8880 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
8881 | if (!hdr) { |
8882 | err = -ENOBUFS; | |
7f6cf311 JB |
8883 | goto free_msg; |
8884 | } | |
8885 | ||
8886 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8887 | ||
e35e4d28 | 8888 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8889 | if (err) |
8890 | goto free_msg; | |
8891 | ||
9360ffd1 DM |
8892 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8893 | goto nla_put_failure; | |
7f6cf311 JB |
8894 | |
8895 | genlmsg_end(msg, hdr); | |
8896 | ||
8897 | return genlmsg_reply(msg, info); | |
8898 | ||
8899 | nla_put_failure: | |
8900 | err = -ENOBUFS; | |
8901 | free_msg: | |
8902 | nlmsg_free(msg); | |
8903 | return err; | |
8904 | } | |
8905 | ||
5e760230 JB |
8906 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8907 | { | |
8908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8909 | struct cfg80211_beacon_registration *reg, *nreg; |
8910 | int rv; | |
5e760230 JB |
8911 | |
8912 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8913 | return -EOPNOTSUPP; | |
8914 | ||
37c73b5f BG |
8915 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8916 | if (!nreg) | |
8917 | return -ENOMEM; | |
8918 | ||
8919 | /* First, check if already registered. */ | |
8920 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8921 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8922 | if (reg->nlportid == info->snd_portid) { | |
8923 | rv = -EALREADY; | |
8924 | goto out_err; | |
8925 | } | |
8926 | } | |
8927 | /* Add it to the list */ | |
8928 | nreg->nlportid = info->snd_portid; | |
8929 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8930 | |
37c73b5f | 8931 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8932 | |
8933 | return 0; | |
37c73b5f BG |
8934 | out_err: |
8935 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8936 | kfree(nreg); | |
8937 | return rv; | |
5e760230 JB |
8938 | } |
8939 | ||
98104fde JB |
8940 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8941 | { | |
8942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8943 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8944 | int err; | |
8945 | ||
8946 | if (!rdev->ops->start_p2p_device) | |
8947 | return -EOPNOTSUPP; | |
8948 | ||
8949 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8950 | return -EOPNOTSUPP; | |
8951 | ||
8952 | if (wdev->p2p_started) | |
8953 | return 0; | |
8954 | ||
98104fde | 8955 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8956 | if (err) |
8957 | return err; | |
8958 | ||
eeb126e9 | 8959 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8960 | if (err) |
8961 | return err; | |
8962 | ||
8963 | wdev->p2p_started = true; | |
98104fde | 8964 | rdev->opencount++; |
98104fde JB |
8965 | |
8966 | return 0; | |
8967 | } | |
8968 | ||
8969 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8970 | { | |
8971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8972 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8973 | ||
8974 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8975 | return -EOPNOTSUPP; | |
8976 | ||
8977 | if (!rdev->ops->stop_p2p_device) | |
8978 | return -EOPNOTSUPP; | |
8979 | ||
f9f47529 | 8980 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8981 | |
8982 | return 0; | |
8983 | } | |
8984 | ||
3713b4e3 JB |
8985 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8986 | struct genl_info *info) | |
8987 | { | |
8988 | void *hdr; | |
8989 | struct sk_buff *msg; | |
8990 | ||
8991 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8992 | if (!msg) | |
8993 | return -ENOMEM; | |
8994 | ||
8995 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8996 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8997 | if (!hdr) | |
8998 | goto nla_put_failure; | |
8999 | ||
9000 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9001 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9002 | goto nla_put_failure; | |
9003 | ||
9004 | genlmsg_end(msg, hdr); | |
9005 | return genlmsg_reply(msg, info); | |
9006 | ||
9007 | nla_put_failure: | |
9008 | kfree_skb(msg); | |
9009 | return -ENOBUFS; | |
9010 | } | |
9011 | ||
355199e0 JM |
9012 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9013 | { | |
9014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9015 | struct cfg80211_update_ft_ies_params ft_params; | |
9016 | struct net_device *dev = info->user_ptr[1]; | |
9017 | ||
9018 | if (!rdev->ops->update_ft_ies) | |
9019 | return -EOPNOTSUPP; | |
9020 | ||
9021 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9022 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9023 | return -EINVAL; | |
9024 | ||
9025 | memset(&ft_params, 0, sizeof(ft_params)); | |
9026 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9027 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9028 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9029 | ||
9030 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9031 | } | |
9032 | ||
5de17984 AS |
9033 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9034 | struct genl_info *info) | |
9035 | { | |
9036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9037 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9038 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9039 | u16 duration; | |
9040 | int ret; | |
9041 | ||
9042 | if (!rdev->ops->crit_proto_start) | |
9043 | return -EOPNOTSUPP; | |
9044 | ||
9045 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9046 | return -EINVAL; | |
9047 | ||
9048 | if (rdev->crit_proto_nlportid) | |
9049 | return -EBUSY; | |
9050 | ||
9051 | /* determine protocol if provided */ | |
9052 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9053 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9054 | ||
9055 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9056 | return -EINVAL; | |
9057 | ||
9058 | /* timeout must be provided */ | |
9059 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9060 | return -EINVAL; | |
9061 | ||
9062 | duration = | |
9063 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9064 | ||
9065 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9066 | return -ERANGE; | |
9067 | ||
9068 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9069 | if (!ret) | |
9070 | rdev->crit_proto_nlportid = info->snd_portid; | |
9071 | ||
9072 | return ret; | |
9073 | } | |
9074 | ||
9075 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9076 | struct genl_info *info) | |
9077 | { | |
9078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9079 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9080 | ||
9081 | if (!rdev->ops->crit_proto_stop) | |
9082 | return -EOPNOTSUPP; | |
9083 | ||
9084 | if (rdev->crit_proto_nlportid) { | |
9085 | rdev->crit_proto_nlportid = 0; | |
9086 | rdev_crit_proto_stop(rdev, wdev); | |
9087 | } | |
9088 | return 0; | |
9089 | } | |
9090 | ||
ad7e718c JB |
9091 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9092 | { | |
9093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9094 | struct wireless_dev *wdev = | |
9095 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9096 | int i, err; | |
9097 | u32 vid, subcmd; | |
9098 | ||
9099 | if (!rdev->wiphy.vendor_commands) | |
9100 | return -EOPNOTSUPP; | |
9101 | ||
9102 | if (IS_ERR(wdev)) { | |
9103 | err = PTR_ERR(wdev); | |
9104 | if (err != -EINVAL) | |
9105 | return err; | |
9106 | wdev = NULL; | |
9107 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9108 | return -EINVAL; | |
9109 | } | |
9110 | ||
9111 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9112 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9113 | return -EINVAL; | |
9114 | ||
9115 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9116 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9117 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9118 | const struct wiphy_vendor_command *vcmd; | |
9119 | void *data = NULL; | |
9120 | int len = 0; | |
9121 | ||
9122 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9123 | ||
9124 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9125 | continue; | |
9126 | ||
9127 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9128 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9129 | if (!wdev) | |
9130 | return -EINVAL; | |
9131 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9132 | !wdev->netdev) | |
9133 | return -EINVAL; | |
9134 | ||
9135 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9136 | if (wdev->netdev && | |
9137 | !netif_running(wdev->netdev)) | |
9138 | return -ENETDOWN; | |
9139 | if (!wdev->netdev && !wdev->p2p_started) | |
9140 | return -ENETDOWN; | |
9141 | } | |
9142 | } else { | |
9143 | wdev = NULL; | |
9144 | } | |
9145 | ||
9146 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9147 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9148 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9149 | } | |
9150 | ||
9151 | rdev->cur_cmd_info = info; | |
9152 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9153 | data, len); | |
9154 | rdev->cur_cmd_info = NULL; | |
9155 | return err; | |
9156 | } | |
9157 | ||
9158 | return -EOPNOTSUPP; | |
9159 | } | |
9160 | ||
9161 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9162 | enum nl80211_commands cmd, | |
9163 | enum nl80211_attrs attr, | |
9164 | int approxlen) | |
9165 | { | |
9166 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9167 | ||
9168 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9169 | return NULL; | |
9170 | ||
9171 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9172 | rdev->cur_cmd_info->snd_portid, | |
9173 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9174 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9175 | } |
9176 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9177 | ||
9178 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9179 | { | |
9180 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9181 | void *hdr = ((void **)skb->cb)[1]; | |
9182 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9183 | ||
9184 | if (WARN_ON(!rdev->cur_cmd_info)) { | |
9185 | kfree_skb(skb); | |
9186 | return -EINVAL; | |
9187 | } | |
9188 | ||
9189 | nla_nest_end(skb, data); | |
9190 | genlmsg_end(skb, hdr); | |
9191 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9192 | } | |
9193 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9194 | ||
9195 | ||
fa9ffc74 KP |
9196 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9197 | struct genl_info *info) | |
9198 | { | |
9199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9200 | struct cfg80211_qos_map *qos_map = NULL; | |
9201 | struct net_device *dev = info->user_ptr[1]; | |
9202 | u8 *pos, len, num_des, des_len, des; | |
9203 | int ret; | |
9204 | ||
9205 | if (!rdev->ops->set_qos_map) | |
9206 | return -EOPNOTSUPP; | |
9207 | ||
9208 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9209 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9210 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9211 | ||
9212 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9213 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9214 | return -EINVAL; | |
9215 | ||
9216 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9217 | if (!qos_map) | |
9218 | return -ENOMEM; | |
9219 | ||
9220 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9221 | if (num_des) { | |
9222 | des_len = num_des * | |
9223 | sizeof(struct cfg80211_dscp_exception); | |
9224 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9225 | qos_map->num_des = num_des; | |
9226 | for (des = 0; des < num_des; des++) { | |
9227 | if (qos_map->dscp_exception[des].up > 7) { | |
9228 | kfree(qos_map); | |
9229 | return -EINVAL; | |
9230 | } | |
9231 | } | |
9232 | pos += des_len; | |
9233 | } | |
9234 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9235 | } | |
9236 | ||
9237 | wdev_lock(dev->ieee80211_ptr); | |
9238 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9239 | if (!ret) | |
9240 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9241 | wdev_unlock(dev->ieee80211_ptr); | |
9242 | ||
9243 | kfree(qos_map); | |
9244 | return ret; | |
9245 | } | |
9246 | ||
4c476991 JB |
9247 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
9248 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
9249 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
9250 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
9251 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
9252 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 9253 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 9254 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
9255 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
9256 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 | 9257 | |
f84f771d | 9258 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9259 | struct genl_info *info) |
9260 | { | |
9261 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 9262 | struct wireless_dev *wdev; |
4c476991 | 9263 | struct net_device *dev; |
4c476991 JB |
9264 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
9265 | ||
9266 | if (rtnl) | |
9267 | rtnl_lock(); | |
9268 | ||
9269 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 9270 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
9271 | if (IS_ERR(rdev)) { |
9272 | if (rtnl) | |
9273 | rtnl_unlock(); | |
9274 | return PTR_ERR(rdev); | |
9275 | } | |
9276 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
9277 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
9278 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
9279 | ASSERT_RTNL(); |
9280 | ||
89a54e48 JB |
9281 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
9282 | info->attrs); | |
9283 | if (IS_ERR(wdev)) { | |
4c476991 JB |
9284 | if (rtnl) |
9285 | rtnl_unlock(); | |
89a54e48 | 9286 | return PTR_ERR(wdev); |
4c476991 | 9287 | } |
89a54e48 | 9288 | |
89a54e48 JB |
9289 | dev = wdev->netdev; |
9290 | rdev = wiphy_to_dev(wdev->wiphy); | |
9291 | ||
1bf614ef JB |
9292 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
9293 | if (!dev) { | |
1bf614ef JB |
9294 | if (rtnl) |
9295 | rtnl_unlock(); | |
9296 | return -EINVAL; | |
9297 | } | |
9298 | ||
9299 | info->user_ptr[1] = dev; | |
9300 | } else { | |
9301 | info->user_ptr[1] = wdev; | |
41265714 | 9302 | } |
1bf614ef JB |
9303 | |
9304 | if (dev) { | |
9305 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
9306 | !netif_running(dev)) { | |
1bf614ef JB |
9307 | if (rtnl) |
9308 | rtnl_unlock(); | |
9309 | return -ENETDOWN; | |
9310 | } | |
9311 | ||
9312 | dev_hold(dev); | |
98104fde JB |
9313 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
9314 | if (!wdev->p2p_started) { | |
98104fde JB |
9315 | if (rtnl) |
9316 | rtnl_unlock(); | |
9317 | return -ENETDOWN; | |
9318 | } | |
41265714 | 9319 | } |
89a54e48 | 9320 | |
4c476991 | 9321 | info->user_ptr[0] = rdev; |
4c476991 JB |
9322 | } |
9323 | ||
9324 | return 0; | |
9325 | } | |
9326 | ||
f84f771d | 9327 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9328 | struct genl_info *info) |
9329 | { | |
1bf614ef JB |
9330 | if (info->user_ptr[1]) { |
9331 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
9332 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9333 | ||
9334 | if (wdev->netdev) | |
9335 | dev_put(wdev->netdev); | |
9336 | } else { | |
9337 | dev_put(info->user_ptr[1]); | |
9338 | } | |
9339 | } | |
4c476991 JB |
9340 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
9341 | rtnl_unlock(); | |
9342 | } | |
9343 | ||
4534de83 | 9344 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
9345 | { |
9346 | .cmd = NL80211_CMD_GET_WIPHY, | |
9347 | .doit = nl80211_get_wiphy, | |
9348 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 9349 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
9350 | .policy = nl80211_policy, |
9351 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9352 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9353 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9354 | }, |
9355 | { | |
9356 | .cmd = NL80211_CMD_SET_WIPHY, | |
9357 | .doit = nl80211_set_wiphy, | |
9358 | .policy = nl80211_policy, | |
9359 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 9360 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
9361 | }, |
9362 | { | |
9363 | .cmd = NL80211_CMD_GET_INTERFACE, | |
9364 | .doit = nl80211_get_interface, | |
9365 | .dumpit = nl80211_dump_interface, | |
9366 | .policy = nl80211_policy, | |
9367 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9368 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
9369 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9370 | }, |
9371 | { | |
9372 | .cmd = NL80211_CMD_SET_INTERFACE, | |
9373 | .doit = nl80211_set_interface, | |
9374 | .policy = nl80211_policy, | |
9375 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9376 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9377 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9378 | }, |
9379 | { | |
9380 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9381 | .doit = nl80211_new_interface, | |
9382 | .policy = nl80211_policy, | |
9383 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9384 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9385 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9386 | }, |
9387 | { | |
9388 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9389 | .doit = nl80211_del_interface, | |
9390 | .policy = nl80211_policy, | |
41ade00f | 9391 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9392 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9393 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9394 | }, |
9395 | { | |
9396 | .cmd = NL80211_CMD_GET_KEY, | |
9397 | .doit = nl80211_get_key, | |
9398 | .policy = nl80211_policy, | |
9399 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9401 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9402 | }, |
9403 | { | |
9404 | .cmd = NL80211_CMD_SET_KEY, | |
9405 | .doit = nl80211_set_key, | |
9406 | .policy = nl80211_policy, | |
9407 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9409 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9410 | }, |
9411 | { | |
9412 | .cmd = NL80211_CMD_NEW_KEY, | |
9413 | .doit = nl80211_new_key, | |
9414 | .policy = nl80211_policy, | |
9415 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9417 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9418 | }, |
9419 | { | |
9420 | .cmd = NL80211_CMD_DEL_KEY, | |
9421 | .doit = nl80211_del_key, | |
9422 | .policy = nl80211_policy, | |
55682965 | 9423 | .flags = GENL_ADMIN_PERM, |
41265714 | 9424 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9425 | NL80211_FLAG_NEED_RTNL, |
55682965 | 9426 | }, |
ed1b6cc7 JB |
9427 | { |
9428 | .cmd = NL80211_CMD_SET_BEACON, | |
9429 | .policy = nl80211_policy, | |
9430 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9431 | .doit = nl80211_set_beacon, |
2b5f8b0b | 9432 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9433 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9434 | }, |
9435 | { | |
8860020e | 9436 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
9437 | .policy = nl80211_policy, |
9438 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9439 | .doit = nl80211_start_ap, |
2b5f8b0b | 9440 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9441 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9442 | }, |
9443 | { | |
8860020e | 9444 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
9445 | .policy = nl80211_policy, |
9446 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9447 | .doit = nl80211_stop_ap, |
2b5f8b0b | 9448 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9449 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 9450 | }, |
5727ef1b JB |
9451 | { |
9452 | .cmd = NL80211_CMD_GET_STATION, | |
9453 | .doit = nl80211_get_station, | |
2ec600d6 | 9454 | .dumpit = nl80211_dump_station, |
5727ef1b | 9455 | .policy = nl80211_policy, |
4c476991 JB |
9456 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9457 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
9458 | }, |
9459 | { | |
9460 | .cmd = NL80211_CMD_SET_STATION, | |
9461 | .doit = nl80211_set_station, | |
9462 | .policy = nl80211_policy, | |
9463 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9464 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9465 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9466 | }, |
9467 | { | |
9468 | .cmd = NL80211_CMD_NEW_STATION, | |
9469 | .doit = nl80211_new_station, | |
9470 | .policy = nl80211_policy, | |
9471 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9472 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9473 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9474 | }, |
9475 | { | |
9476 | .cmd = NL80211_CMD_DEL_STATION, | |
9477 | .doit = nl80211_del_station, | |
9478 | .policy = nl80211_policy, | |
2ec600d6 | 9479 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9481 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9482 | }, |
9483 | { | |
9484 | .cmd = NL80211_CMD_GET_MPATH, | |
9485 | .doit = nl80211_get_mpath, | |
9486 | .dumpit = nl80211_dump_mpath, | |
9487 | .policy = nl80211_policy, | |
9488 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9489 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9490 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9491 | }, |
9492 | { | |
9493 | .cmd = NL80211_CMD_SET_MPATH, | |
9494 | .doit = nl80211_set_mpath, | |
9495 | .policy = nl80211_policy, | |
9496 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9498 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9499 | }, |
9500 | { | |
9501 | .cmd = NL80211_CMD_NEW_MPATH, | |
9502 | .doit = nl80211_new_mpath, | |
9503 | .policy = nl80211_policy, | |
9504 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9506 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9507 | }, |
9508 | { | |
9509 | .cmd = NL80211_CMD_DEL_MPATH, | |
9510 | .doit = nl80211_del_mpath, | |
9511 | .policy = nl80211_policy, | |
9f1ba906 | 9512 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9514 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9515 | }, |
9516 | { | |
9517 | .cmd = NL80211_CMD_SET_BSS, | |
9518 | .doit = nl80211_set_bss, | |
9519 | .policy = nl80211_policy, | |
b2e1b302 | 9520 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9522 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9523 | }, |
f130347c LR |
9524 | { |
9525 | .cmd = NL80211_CMD_GET_REG, | |
9526 | .doit = nl80211_get_reg, | |
9527 | .policy = nl80211_policy, | |
5fe231e8 | 9528 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9529 | /* can be retrieved by unprivileged users */ |
9530 | }, | |
b2e1b302 LR |
9531 | { |
9532 | .cmd = NL80211_CMD_SET_REG, | |
9533 | .doit = nl80211_set_reg, | |
9534 | .policy = nl80211_policy, | |
9535 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9536 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9537 | }, |
9538 | { | |
9539 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9540 | .doit = nl80211_req_set_reg, | |
9541 | .policy = nl80211_policy, | |
93da9cc1 | 9542 | .flags = GENL_ADMIN_PERM, |
9543 | }, | |
9544 | { | |
24bdd9f4 JC |
9545 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9546 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9547 | .policy = nl80211_policy, |
9548 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9549 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9550 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9551 | }, |
9552 | { | |
24bdd9f4 JC |
9553 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9554 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9555 | .policy = nl80211_policy, |
9aed3cc1 | 9556 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9558 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9559 | }, |
2a519311 JB |
9560 | { |
9561 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9562 | .doit = nl80211_trigger_scan, | |
9563 | .policy = nl80211_policy, | |
9564 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9565 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9566 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9567 | }, |
9568 | { | |
9569 | .cmd = NL80211_CMD_GET_SCAN, | |
9570 | .policy = nl80211_policy, | |
9571 | .dumpit = nl80211_dump_scan, | |
9572 | }, | |
807f8a8c LC |
9573 | { |
9574 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9575 | .doit = nl80211_start_sched_scan, | |
9576 | .policy = nl80211_policy, | |
9577 | .flags = GENL_ADMIN_PERM, | |
9578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9579 | NL80211_FLAG_NEED_RTNL, | |
9580 | }, | |
9581 | { | |
9582 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9583 | .doit = nl80211_stop_sched_scan, | |
9584 | .policy = nl80211_policy, | |
9585 | .flags = GENL_ADMIN_PERM, | |
9586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9587 | NL80211_FLAG_NEED_RTNL, | |
9588 | }, | |
636a5d36 JM |
9589 | { |
9590 | .cmd = NL80211_CMD_AUTHENTICATE, | |
9591 | .doit = nl80211_authenticate, | |
9592 | .policy = nl80211_policy, | |
9593 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9595 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9596 | }, |
9597 | { | |
9598 | .cmd = NL80211_CMD_ASSOCIATE, | |
9599 | .doit = nl80211_associate, | |
9600 | .policy = nl80211_policy, | |
9601 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9603 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9604 | }, |
9605 | { | |
9606 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9607 | .doit = nl80211_deauthenticate, | |
9608 | .policy = nl80211_policy, | |
9609 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9611 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9612 | }, |
9613 | { | |
9614 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9615 | .doit = nl80211_disassociate, | |
9616 | .policy = nl80211_policy, | |
9617 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9618 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9619 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9620 | }, |
04a773ad JB |
9621 | { |
9622 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9623 | .doit = nl80211_join_ibss, | |
9624 | .policy = nl80211_policy, | |
9625 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9626 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9627 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9628 | }, |
9629 | { | |
9630 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9631 | .doit = nl80211_leave_ibss, | |
9632 | .policy = nl80211_policy, | |
9633 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9634 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9635 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9636 | }, |
aff89a9b JB |
9637 | #ifdef CONFIG_NL80211_TESTMODE |
9638 | { | |
9639 | .cmd = NL80211_CMD_TESTMODE, | |
9640 | .doit = nl80211_testmode_do, | |
71063f0e | 9641 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9642 | .policy = nl80211_policy, |
9643 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9644 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9645 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9646 | }, |
9647 | #endif | |
b23aa676 SO |
9648 | { |
9649 | .cmd = NL80211_CMD_CONNECT, | |
9650 | .doit = nl80211_connect, | |
9651 | .policy = nl80211_policy, | |
9652 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9653 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9654 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9655 | }, |
9656 | { | |
9657 | .cmd = NL80211_CMD_DISCONNECT, | |
9658 | .doit = nl80211_disconnect, | |
9659 | .policy = nl80211_policy, | |
9660 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9661 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9662 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9663 | }, |
463d0183 JB |
9664 | { |
9665 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9666 | .doit = nl80211_wiphy_netns, | |
9667 | .policy = nl80211_policy, | |
9668 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9669 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9670 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9671 | }, |
61fa713c HS |
9672 | { |
9673 | .cmd = NL80211_CMD_GET_SURVEY, | |
9674 | .policy = nl80211_policy, | |
9675 | .dumpit = nl80211_dump_survey, | |
9676 | }, | |
67fbb16b SO |
9677 | { |
9678 | .cmd = NL80211_CMD_SET_PMKSA, | |
9679 | .doit = nl80211_setdel_pmksa, | |
9680 | .policy = nl80211_policy, | |
9681 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9682 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9683 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9684 | }, |
9685 | { | |
9686 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9687 | .doit = nl80211_setdel_pmksa, | |
9688 | .policy = nl80211_policy, | |
9689 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9690 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9691 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9692 | }, |
9693 | { | |
9694 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9695 | .doit = nl80211_flush_pmksa, | |
9696 | .policy = nl80211_policy, | |
9697 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9698 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9699 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9700 | }, |
9588bbd5 JM |
9701 | { |
9702 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9703 | .doit = nl80211_remain_on_channel, | |
9704 | .policy = nl80211_policy, | |
9705 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9706 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9707 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9708 | }, |
9709 | { | |
9710 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9711 | .doit = nl80211_cancel_remain_on_channel, | |
9712 | .policy = nl80211_policy, | |
9713 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9714 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9715 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9716 | }, |
13ae75b1 JM |
9717 | { |
9718 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9719 | .doit = nl80211_set_tx_bitrate_mask, | |
9720 | .policy = nl80211_policy, | |
9721 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9722 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9723 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9724 | }, |
026331c4 | 9725 | { |
2e161f78 JB |
9726 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9727 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9728 | .policy = nl80211_policy, |
9729 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9730 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9731 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9732 | }, |
9733 | { | |
2e161f78 JB |
9734 | .cmd = NL80211_CMD_FRAME, |
9735 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9736 | .policy = nl80211_policy, |
f7ca38df | 9737 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9738 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9739 | NL80211_FLAG_NEED_RTNL, |
9740 | }, | |
9741 | { | |
9742 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9743 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9744 | .policy = nl80211_policy, | |
026331c4 | 9745 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9746 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9747 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9748 | }, |
ffb9eb3d KV |
9749 | { |
9750 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9751 | .doit = nl80211_set_power_save, | |
9752 | .policy = nl80211_policy, | |
9753 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9754 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9755 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9756 | }, |
9757 | { | |
9758 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9759 | .doit = nl80211_get_power_save, | |
9760 | .policy = nl80211_policy, | |
9761 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9762 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9763 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9764 | }, |
d6dc1a38 JO |
9765 | { |
9766 | .cmd = NL80211_CMD_SET_CQM, | |
9767 | .doit = nl80211_set_cqm, | |
9768 | .policy = nl80211_policy, | |
9769 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9770 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9771 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9772 | }, |
f444de05 JB |
9773 | { |
9774 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9775 | .doit = nl80211_set_channel, | |
9776 | .policy = nl80211_policy, | |
9777 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9778 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9779 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9780 | }, |
e8347eba BJ |
9781 | { |
9782 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9783 | .doit = nl80211_set_wds_peer, | |
9784 | .policy = nl80211_policy, | |
9785 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9786 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9787 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9788 | }, |
29cbe68c JB |
9789 | { |
9790 | .cmd = NL80211_CMD_JOIN_MESH, | |
9791 | .doit = nl80211_join_mesh, | |
9792 | .policy = nl80211_policy, | |
9793 | .flags = GENL_ADMIN_PERM, | |
9794 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9795 | NL80211_FLAG_NEED_RTNL, | |
9796 | }, | |
9797 | { | |
9798 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9799 | .doit = nl80211_leave_mesh, | |
9800 | .policy = nl80211_policy, | |
9801 | .flags = GENL_ADMIN_PERM, | |
9802 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9803 | NL80211_FLAG_NEED_RTNL, | |
9804 | }, | |
dfb89c56 | 9805 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9806 | { |
9807 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9808 | .doit = nl80211_get_wowlan, | |
9809 | .policy = nl80211_policy, | |
9810 | /* can be retrieved by unprivileged users */ | |
9811 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9812 | NL80211_FLAG_NEED_RTNL, | |
9813 | }, | |
9814 | { | |
9815 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9816 | .doit = nl80211_set_wowlan, | |
9817 | .policy = nl80211_policy, | |
9818 | .flags = GENL_ADMIN_PERM, | |
9819 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9820 | NL80211_FLAG_NEED_RTNL, | |
9821 | }, | |
dfb89c56 | 9822 | #endif |
e5497d76 JB |
9823 | { |
9824 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9825 | .doit = nl80211_set_rekey_data, | |
9826 | .policy = nl80211_policy, | |
9827 | .flags = GENL_ADMIN_PERM, | |
9828 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9829 | NL80211_FLAG_NEED_RTNL, | |
9830 | }, | |
109086ce AN |
9831 | { |
9832 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9833 | .doit = nl80211_tdls_mgmt, | |
9834 | .policy = nl80211_policy, | |
9835 | .flags = GENL_ADMIN_PERM, | |
9836 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9837 | NL80211_FLAG_NEED_RTNL, | |
9838 | }, | |
9839 | { | |
9840 | .cmd = NL80211_CMD_TDLS_OPER, | |
9841 | .doit = nl80211_tdls_oper, | |
9842 | .policy = nl80211_policy, | |
9843 | .flags = GENL_ADMIN_PERM, | |
9844 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9845 | NL80211_FLAG_NEED_RTNL, | |
9846 | }, | |
28946da7 JB |
9847 | { |
9848 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9849 | .doit = nl80211_register_unexpected_frame, | |
9850 | .policy = nl80211_policy, | |
9851 | .flags = GENL_ADMIN_PERM, | |
9852 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9853 | NL80211_FLAG_NEED_RTNL, | |
9854 | }, | |
7f6cf311 JB |
9855 | { |
9856 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9857 | .doit = nl80211_probe_client, | |
9858 | .policy = nl80211_policy, | |
9859 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9860 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9861 | NL80211_FLAG_NEED_RTNL, |
9862 | }, | |
5e760230 JB |
9863 | { |
9864 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9865 | .doit = nl80211_register_beacons, | |
9866 | .policy = nl80211_policy, | |
9867 | .flags = GENL_ADMIN_PERM, | |
9868 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9869 | NL80211_FLAG_NEED_RTNL, | |
9870 | }, | |
1d9d9213 SW |
9871 | { |
9872 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9873 | .doit = nl80211_set_noack_map, | |
9874 | .policy = nl80211_policy, | |
9875 | .flags = GENL_ADMIN_PERM, | |
9876 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9877 | NL80211_FLAG_NEED_RTNL, | |
9878 | }, | |
98104fde JB |
9879 | { |
9880 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9881 | .doit = nl80211_start_p2p_device, | |
9882 | .policy = nl80211_policy, | |
9883 | .flags = GENL_ADMIN_PERM, | |
9884 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9885 | NL80211_FLAG_NEED_RTNL, | |
9886 | }, | |
9887 | { | |
9888 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9889 | .doit = nl80211_stop_p2p_device, | |
9890 | .policy = nl80211_policy, | |
9891 | .flags = GENL_ADMIN_PERM, | |
9892 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9893 | NL80211_FLAG_NEED_RTNL, | |
9894 | }, | |
f4e583c8 AQ |
9895 | { |
9896 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9897 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9898 | .policy = nl80211_policy, |
9899 | .flags = GENL_ADMIN_PERM, | |
9900 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9901 | NL80211_FLAG_NEED_RTNL, | |
9902 | }, | |
9903 | { | |
9904 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9905 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9906 | .policy = nl80211_policy, |
9907 | .flags = GENL_ADMIN_PERM, | |
9908 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9909 | NL80211_FLAG_NEED_RTNL, | |
9910 | }, | |
04f39047 SW |
9911 | { |
9912 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9913 | .doit = nl80211_start_radar_detection, | |
9914 | .policy = nl80211_policy, | |
9915 | .flags = GENL_ADMIN_PERM, | |
9916 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9917 | NL80211_FLAG_NEED_RTNL, | |
9918 | }, | |
3713b4e3 JB |
9919 | { |
9920 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9921 | .doit = nl80211_get_protocol_features, | |
9922 | .policy = nl80211_policy, | |
9923 | }, | |
355199e0 JM |
9924 | { |
9925 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9926 | .doit = nl80211_update_ft_ies, | |
9927 | .policy = nl80211_policy, | |
9928 | .flags = GENL_ADMIN_PERM, | |
9929 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9930 | NL80211_FLAG_NEED_RTNL, | |
9931 | }, | |
5de17984 AS |
9932 | { |
9933 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9934 | .doit = nl80211_crit_protocol_start, | |
9935 | .policy = nl80211_policy, | |
9936 | .flags = GENL_ADMIN_PERM, | |
9937 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9938 | NL80211_FLAG_NEED_RTNL, | |
9939 | }, | |
9940 | { | |
9941 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9942 | .doit = nl80211_crit_protocol_stop, | |
9943 | .policy = nl80211_policy, | |
9944 | .flags = GENL_ADMIN_PERM, | |
9945 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9946 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
9947 | }, |
9948 | { | |
9949 | .cmd = NL80211_CMD_GET_COALESCE, | |
9950 | .doit = nl80211_get_coalesce, | |
9951 | .policy = nl80211_policy, | |
9952 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9953 | NL80211_FLAG_NEED_RTNL, | |
9954 | }, | |
9955 | { | |
9956 | .cmd = NL80211_CMD_SET_COALESCE, | |
9957 | .doit = nl80211_set_coalesce, | |
9958 | .policy = nl80211_policy, | |
9959 | .flags = GENL_ADMIN_PERM, | |
9960 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9961 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
9962 | }, |
9963 | { | |
9964 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
9965 | .doit = nl80211_channel_switch, | |
9966 | .policy = nl80211_policy, | |
9967 | .flags = GENL_ADMIN_PERM, | |
9968 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9969 | NL80211_FLAG_NEED_RTNL, | |
9970 | }, | |
ad7e718c JB |
9971 | { |
9972 | .cmd = NL80211_CMD_VENDOR, | |
9973 | .doit = nl80211_vendor_cmd, | |
9974 | .policy = nl80211_policy, | |
9975 | .flags = GENL_ADMIN_PERM, | |
9976 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9977 | NL80211_FLAG_NEED_RTNL, | |
9978 | }, | |
fa9ffc74 KP |
9979 | { |
9980 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
9981 | .doit = nl80211_set_qos_map, | |
9982 | .policy = nl80211_policy, | |
9983 | .flags = GENL_ADMIN_PERM, | |
9984 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9985 | NL80211_FLAG_NEED_RTNL, | |
9986 | }, | |
55682965 | 9987 | }; |
9588bbd5 | 9988 | |
55682965 JB |
9989 | /* notification functions */ |
9990 | ||
9991 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9992 | { | |
9993 | struct sk_buff *msg; | |
86e8cf98 | 9994 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 9995 | |
fd2120ca | 9996 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9997 | if (!msg) |
9998 | return; | |
9999 | ||
86e8cf98 | 10000 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
10001 | nlmsg_free(msg); |
10002 | return; | |
10003 | } | |
10004 | ||
68eb5503 | 10005 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10006 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
10007 | } |
10008 | ||
362a415d JB |
10009 | static int nl80211_add_scan_req(struct sk_buff *msg, |
10010 | struct cfg80211_registered_device *rdev) | |
10011 | { | |
10012 | struct cfg80211_scan_request *req = rdev->scan_req; | |
10013 | struct nlattr *nest; | |
10014 | int i; | |
10015 | ||
10016 | if (WARN_ON(!req)) | |
10017 | return 0; | |
10018 | ||
10019 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
10020 | if (!nest) | |
10021 | goto nla_put_failure; | |
9360ffd1 DM |
10022 | for (i = 0; i < req->n_ssids; i++) { |
10023 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
10024 | goto nla_put_failure; | |
10025 | } | |
362a415d JB |
10026 | nla_nest_end(msg, nest); |
10027 | ||
10028 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
10029 | if (!nest) | |
10030 | goto nla_put_failure; | |
9360ffd1 DM |
10031 | for (i = 0; i < req->n_channels; i++) { |
10032 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10033 | goto nla_put_failure; | |
10034 | } | |
362a415d JB |
10035 | nla_nest_end(msg, nest); |
10036 | ||
9360ffd1 DM |
10037 | if (req->ie && |
10038 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
10039 | goto nla_put_failure; | |
362a415d | 10040 | |
ae917c9f JB |
10041 | if (req->flags && |
10042 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
10043 | goto nla_put_failure; | |
ed473771 | 10044 | |
362a415d JB |
10045 | return 0; |
10046 | nla_put_failure: | |
10047 | return -ENOBUFS; | |
10048 | } | |
10049 | ||
a538e2d5 JB |
10050 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
10051 | struct cfg80211_registered_device *rdev, | |
fd014284 | 10052 | struct wireless_dev *wdev, |
15e47304 | 10053 | u32 portid, u32 seq, int flags, |
a538e2d5 | 10054 | u32 cmd) |
2a519311 JB |
10055 | { |
10056 | void *hdr; | |
10057 | ||
15e47304 | 10058 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
10059 | if (!hdr) |
10060 | return -1; | |
10061 | ||
9360ffd1 | 10062 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
10063 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10064 | wdev->netdev->ifindex)) || | |
10065 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 10066 | goto nla_put_failure; |
2a519311 | 10067 | |
362a415d JB |
10068 | /* ignore errors and send incomplete event anyway */ |
10069 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
10070 | |
10071 | return genlmsg_end(msg, hdr); | |
10072 | ||
10073 | nla_put_failure: | |
10074 | genlmsg_cancel(msg, hdr); | |
10075 | return -EMSGSIZE; | |
10076 | } | |
10077 | ||
807f8a8c LC |
10078 | static int |
10079 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
10080 | struct cfg80211_registered_device *rdev, | |
10081 | struct net_device *netdev, | |
15e47304 | 10082 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
10083 | { |
10084 | void *hdr; | |
10085 | ||
15e47304 | 10086 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
10087 | if (!hdr) |
10088 | return -1; | |
10089 | ||
9360ffd1 DM |
10090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10091 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
10092 | goto nla_put_failure; | |
807f8a8c LC |
10093 | |
10094 | return genlmsg_end(msg, hdr); | |
10095 | ||
10096 | nla_put_failure: | |
10097 | genlmsg_cancel(msg, hdr); | |
10098 | return -EMSGSIZE; | |
10099 | } | |
10100 | ||
a538e2d5 | 10101 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 10102 | struct wireless_dev *wdev) |
a538e2d5 JB |
10103 | { |
10104 | struct sk_buff *msg; | |
10105 | ||
58050fce | 10106 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10107 | if (!msg) |
10108 | return; | |
10109 | ||
fd014284 | 10110 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
10111 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
10112 | nlmsg_free(msg); | |
10113 | return; | |
10114 | } | |
10115 | ||
68eb5503 | 10116 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10117 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
10118 | } |
10119 | ||
f9d15d16 JB |
10120 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
10121 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
10122 | { |
10123 | struct sk_buff *msg; | |
10124 | ||
fd2120ca | 10125 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 10126 | if (!msg) |
f9d15d16 | 10127 | return NULL; |
2a519311 | 10128 | |
fd014284 | 10129 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
10130 | aborted ? NL80211_CMD_SCAN_ABORTED : |
10131 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 10132 | nlmsg_free(msg); |
f9d15d16 | 10133 | return NULL; |
2a519311 JB |
10134 | } |
10135 | ||
f9d15d16 | 10136 | return msg; |
2a519311 JB |
10137 | } |
10138 | ||
f9d15d16 JB |
10139 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
10140 | struct sk_buff *msg) | |
2a519311 | 10141 | { |
2a519311 JB |
10142 | if (!msg) |
10143 | return; | |
10144 | ||
68eb5503 | 10145 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10146 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10147 | } |
10148 | ||
807f8a8c LC |
10149 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
10150 | struct net_device *netdev) | |
10151 | { | |
10152 | struct sk_buff *msg; | |
10153 | ||
10154 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10155 | if (!msg) | |
10156 | return; | |
10157 | ||
10158 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
10159 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
10160 | nlmsg_free(msg); | |
10161 | return; | |
10162 | } | |
10163 | ||
68eb5503 | 10164 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10165 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10166 | } |
10167 | ||
10168 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
10169 | struct net_device *netdev, u32 cmd) | |
10170 | { | |
10171 | struct sk_buff *msg; | |
10172 | ||
58050fce | 10173 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
10174 | if (!msg) |
10175 | return; | |
10176 | ||
10177 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
10178 | nlmsg_free(msg); | |
10179 | return; | |
10180 | } | |
10181 | ||
68eb5503 | 10182 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10183 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10184 | } |
10185 | ||
73d54c9e LR |
10186 | /* |
10187 | * This can happen on global regulatory changes or device specific settings | |
10188 | * based on custom world regulatory domains. | |
10189 | */ | |
10190 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
10191 | { | |
10192 | struct sk_buff *msg; | |
10193 | void *hdr; | |
10194 | ||
fd2120ca | 10195 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
10196 | if (!msg) |
10197 | return; | |
10198 | ||
10199 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
10200 | if (!hdr) { | |
10201 | nlmsg_free(msg); | |
10202 | return; | |
10203 | } | |
10204 | ||
10205 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
10206 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
10207 | goto nla_put_failure; | |
10208 | ||
10209 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
10210 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10211 | NL80211_REGDOM_TYPE_WORLD)) | |
10212 | goto nla_put_failure; | |
10213 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
10214 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10215 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
10216 | goto nla_put_failure; | |
10217 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
10218 | request->intersect) { | |
10219 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10220 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
10221 | goto nla_put_failure; | |
10222 | } else { | |
10223 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10224 | NL80211_REGDOM_TYPE_COUNTRY) || | |
10225 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
10226 | request->alpha2)) | |
10227 | goto nla_put_failure; | |
10228 | } | |
10229 | ||
f4173766 | 10230 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
10231 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
10232 | goto nla_put_failure; | |
73d54c9e | 10233 | |
3b7b72ee | 10234 | genlmsg_end(msg, hdr); |
73d54c9e | 10235 | |
bc43b28c | 10236 | rcu_read_lock(); |
68eb5503 | 10237 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10238 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 10239 | rcu_read_unlock(); |
73d54c9e LR |
10240 | |
10241 | return; | |
10242 | ||
10243 | nla_put_failure: | |
10244 | genlmsg_cancel(msg, hdr); | |
10245 | nlmsg_free(msg); | |
10246 | } | |
10247 | ||
6039f6d2 JM |
10248 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
10249 | struct net_device *netdev, | |
10250 | const u8 *buf, size_t len, | |
e6d6e342 | 10251 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
10252 | { |
10253 | struct sk_buff *msg; | |
10254 | void *hdr; | |
10255 | ||
e6d6e342 | 10256 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
10257 | if (!msg) |
10258 | return; | |
10259 | ||
10260 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10261 | if (!hdr) { | |
10262 | nlmsg_free(msg); | |
10263 | return; | |
10264 | } | |
10265 | ||
9360ffd1 DM |
10266 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10267 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10268 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10269 | goto nla_put_failure; | |
6039f6d2 | 10270 | |
3b7b72ee | 10271 | genlmsg_end(msg, hdr); |
6039f6d2 | 10272 | |
68eb5503 | 10273 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10274 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
10275 | return; |
10276 | ||
10277 | nla_put_failure: | |
10278 | genlmsg_cancel(msg, hdr); | |
10279 | nlmsg_free(msg); | |
10280 | } | |
10281 | ||
10282 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10283 | struct net_device *netdev, const u8 *buf, |
10284 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10285 | { |
10286 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10287 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
10288 | } |
10289 | ||
10290 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
10291 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10292 | size_t len, gfp_t gfp) |
6039f6d2 | 10293 | { |
e6d6e342 JB |
10294 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
10295 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
10296 | } |
10297 | ||
53b46b84 | 10298 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
10299 | struct net_device *netdev, const u8 *buf, |
10300 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10301 | { |
10302 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10303 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
10304 | } |
10305 | ||
53b46b84 JM |
10306 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
10307 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10308 | size_t len, gfp_t gfp) |
6039f6d2 JM |
10309 | { |
10310 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10311 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
10312 | } |
10313 | ||
6ff57cf8 JB |
10314 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
10315 | size_t len) | |
cf4e594e | 10316 | { |
947add36 JB |
10317 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10318 | struct wiphy *wiphy = wdev->wiphy; | |
10319 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6ff57cf8 JB |
10320 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
10321 | u32 cmd; | |
947add36 | 10322 | |
6ff57cf8 JB |
10323 | if (WARN_ON(len < 2)) |
10324 | return; | |
cf4e594e | 10325 | |
6ff57cf8 JB |
10326 | if (ieee80211_is_deauth(mgmt->frame_control)) |
10327 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
10328 | else | |
10329 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 10330 | |
6ff57cf8 JB |
10331 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
10332 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 10333 | } |
6ff57cf8 | 10334 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 10335 | |
1b06bb40 LR |
10336 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
10337 | struct net_device *netdev, int cmd, | |
e6d6e342 | 10338 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
10339 | { |
10340 | struct sk_buff *msg; | |
10341 | void *hdr; | |
10342 | ||
e6d6e342 | 10343 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
10344 | if (!msg) |
10345 | return; | |
10346 | ||
10347 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10348 | if (!hdr) { | |
10349 | nlmsg_free(msg); | |
10350 | return; | |
10351 | } | |
10352 | ||
9360ffd1 DM |
10353 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10354 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10355 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
10356 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10357 | goto nla_put_failure; | |
1965c853 | 10358 | |
3b7b72ee | 10359 | genlmsg_end(msg, hdr); |
1965c853 | 10360 | |
68eb5503 | 10361 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10362 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
10363 | return; |
10364 | ||
10365 | nla_put_failure: | |
10366 | genlmsg_cancel(msg, hdr); | |
10367 | nlmsg_free(msg); | |
10368 | } | |
10369 | ||
10370 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10371 | struct net_device *netdev, const u8 *addr, |
10372 | gfp_t gfp) | |
1965c853 JM |
10373 | { |
10374 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 10375 | addr, gfp); |
1965c853 JM |
10376 | } |
10377 | ||
10378 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10379 | struct net_device *netdev, const u8 *addr, |
10380 | gfp_t gfp) | |
1965c853 | 10381 | { |
e6d6e342 JB |
10382 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
10383 | addr, gfp); | |
1965c853 JM |
10384 | } |
10385 | ||
b23aa676 SO |
10386 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
10387 | struct net_device *netdev, const u8 *bssid, | |
10388 | const u8 *req_ie, size_t req_ie_len, | |
10389 | const u8 *resp_ie, size_t resp_ie_len, | |
10390 | u16 status, gfp_t gfp) | |
10391 | { | |
10392 | struct sk_buff *msg; | |
10393 | void *hdr; | |
10394 | ||
58050fce | 10395 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10396 | if (!msg) |
10397 | return; | |
10398 | ||
10399 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
10400 | if (!hdr) { | |
10401 | nlmsg_free(msg); | |
10402 | return; | |
10403 | } | |
10404 | ||
9360ffd1 DM |
10405 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10406 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10407 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
10408 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
10409 | (req_ie && | |
10410 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10411 | (resp_ie && | |
10412 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10413 | goto nla_put_failure; | |
b23aa676 | 10414 | |
3b7b72ee | 10415 | genlmsg_end(msg, hdr); |
b23aa676 | 10416 | |
68eb5503 | 10417 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10418 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10419 | return; |
10420 | ||
10421 | nla_put_failure: | |
10422 | genlmsg_cancel(msg, hdr); | |
10423 | nlmsg_free(msg); | |
10424 | ||
10425 | } | |
10426 | ||
10427 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
10428 | struct net_device *netdev, const u8 *bssid, | |
10429 | const u8 *req_ie, size_t req_ie_len, | |
10430 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
10431 | { | |
10432 | struct sk_buff *msg; | |
10433 | void *hdr; | |
10434 | ||
58050fce | 10435 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10436 | if (!msg) |
10437 | return; | |
10438 | ||
10439 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
10440 | if (!hdr) { | |
10441 | nlmsg_free(msg); | |
10442 | return; | |
10443 | } | |
10444 | ||
9360ffd1 DM |
10445 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10446 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10447 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
10448 | (req_ie && | |
10449 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10450 | (resp_ie && | |
10451 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10452 | goto nla_put_failure; | |
b23aa676 | 10453 | |
3b7b72ee | 10454 | genlmsg_end(msg, hdr); |
b23aa676 | 10455 | |
68eb5503 | 10456 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10457 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10458 | return; |
10459 | ||
10460 | nla_put_failure: | |
10461 | genlmsg_cancel(msg, hdr); | |
10462 | nlmsg_free(msg); | |
10463 | ||
10464 | } | |
10465 | ||
10466 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
10467 | struct net_device *netdev, u16 reason, | |
667503dd | 10468 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
10469 | { |
10470 | struct sk_buff *msg; | |
10471 | void *hdr; | |
10472 | ||
58050fce | 10473 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
10474 | if (!msg) |
10475 | return; | |
10476 | ||
10477 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
10478 | if (!hdr) { | |
10479 | nlmsg_free(msg); | |
10480 | return; | |
10481 | } | |
10482 | ||
9360ffd1 DM |
10483 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10484 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10485 | (from_ap && reason && | |
10486 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10487 | (from_ap && | |
10488 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10489 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10490 | goto nla_put_failure; | |
b23aa676 | 10491 | |
3b7b72ee | 10492 | genlmsg_end(msg, hdr); |
b23aa676 | 10493 | |
68eb5503 | 10494 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10495 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
10496 | return; |
10497 | ||
10498 | nla_put_failure: | |
10499 | genlmsg_cancel(msg, hdr); | |
10500 | nlmsg_free(msg); | |
10501 | ||
10502 | } | |
10503 | ||
04a773ad JB |
10504 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10505 | struct net_device *netdev, const u8 *bssid, | |
10506 | gfp_t gfp) | |
10507 | { | |
10508 | struct sk_buff *msg; | |
10509 | void *hdr; | |
10510 | ||
fd2120ca | 10511 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10512 | if (!msg) |
10513 | return; | |
10514 | ||
10515 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10516 | if (!hdr) { | |
10517 | nlmsg_free(msg); | |
10518 | return; | |
10519 | } | |
10520 | ||
9360ffd1 DM |
10521 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10522 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10523 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10524 | goto nla_put_failure; | |
04a773ad | 10525 | |
3b7b72ee | 10526 | genlmsg_end(msg, hdr); |
04a773ad | 10527 | |
68eb5503 | 10528 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10529 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
10530 | return; |
10531 | ||
10532 | nla_put_failure: | |
10533 | genlmsg_cancel(msg, hdr); | |
10534 | nlmsg_free(msg); | |
10535 | } | |
10536 | ||
947add36 JB |
10537 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10538 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10539 | { |
947add36 JB |
10540 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10541 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
10542 | struct sk_buff *msg; |
10543 | void *hdr; | |
10544 | ||
947add36 JB |
10545 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10546 | return; | |
10547 | ||
10548 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10549 | ||
c93b5e71 JC |
10550 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10551 | if (!msg) | |
10552 | return; | |
10553 | ||
10554 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
10555 | if (!hdr) { | |
10556 | nlmsg_free(msg); | |
10557 | return; | |
10558 | } | |
10559 | ||
9360ffd1 | 10560 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
10561 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10562 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
10563 | (ie_len && ie && |
10564 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
10565 | goto nla_put_failure; | |
c93b5e71 | 10566 | |
3b7b72ee | 10567 | genlmsg_end(msg, hdr); |
c93b5e71 | 10568 | |
68eb5503 | 10569 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10570 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
10571 | return; |
10572 | ||
10573 | nla_put_failure: | |
10574 | genlmsg_cancel(msg, hdr); | |
10575 | nlmsg_free(msg); | |
10576 | } | |
947add36 | 10577 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 10578 | |
a3b8b056 JM |
10579 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
10580 | struct net_device *netdev, const u8 *addr, | |
10581 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 10582 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
10583 | { |
10584 | struct sk_buff *msg; | |
10585 | void *hdr; | |
10586 | ||
e6d6e342 | 10587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
10588 | if (!msg) |
10589 | return; | |
10590 | ||
10591 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
10592 | if (!hdr) { | |
10593 | nlmsg_free(msg); | |
10594 | return; | |
10595 | } | |
10596 | ||
9360ffd1 DM |
10597 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10598 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10599 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
10600 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10601 | (key_id != -1 && | |
10602 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10603 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10604 | goto nla_put_failure; | |
a3b8b056 | 10605 | |
3b7b72ee | 10606 | genlmsg_end(msg, hdr); |
a3b8b056 | 10607 | |
68eb5503 | 10608 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10609 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
10610 | return; |
10611 | ||
10612 | nla_put_failure: | |
10613 | genlmsg_cancel(msg, hdr); | |
10614 | nlmsg_free(msg); | |
10615 | } | |
10616 | ||
6bad8766 LR |
10617 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10618 | struct ieee80211_channel *channel_before, | |
10619 | struct ieee80211_channel *channel_after) | |
10620 | { | |
10621 | struct sk_buff *msg; | |
10622 | void *hdr; | |
10623 | struct nlattr *nl_freq; | |
10624 | ||
fd2120ca | 10625 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10626 | if (!msg) |
10627 | return; | |
10628 | ||
10629 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10630 | if (!hdr) { | |
10631 | nlmsg_free(msg); | |
10632 | return; | |
10633 | } | |
10634 | ||
10635 | /* | |
10636 | * Since we are applying the beacon hint to a wiphy we know its | |
10637 | * wiphy_idx is valid | |
10638 | */ | |
9360ffd1 DM |
10639 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10640 | goto nla_put_failure; | |
6bad8766 LR |
10641 | |
10642 | /* Before */ | |
10643 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10644 | if (!nl_freq) | |
10645 | goto nla_put_failure; | |
cdc89b97 | 10646 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10647 | goto nla_put_failure; |
10648 | nla_nest_end(msg, nl_freq); | |
10649 | ||
10650 | /* After */ | |
10651 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10652 | if (!nl_freq) | |
10653 | goto nla_put_failure; | |
cdc89b97 | 10654 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10655 | goto nla_put_failure; |
10656 | nla_nest_end(msg, nl_freq); | |
10657 | ||
3b7b72ee | 10658 | genlmsg_end(msg, hdr); |
6bad8766 | 10659 | |
463d0183 | 10660 | rcu_read_lock(); |
68eb5503 | 10661 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10662 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 10663 | rcu_read_unlock(); |
6bad8766 LR |
10664 | |
10665 | return; | |
10666 | ||
10667 | nla_put_failure: | |
10668 | genlmsg_cancel(msg, hdr); | |
10669 | nlmsg_free(msg); | |
10670 | } | |
10671 | ||
9588bbd5 JM |
10672 | static void nl80211_send_remain_on_chan_event( |
10673 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10674 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10675 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10676 | unsigned int duration, gfp_t gfp) |
10677 | { | |
10678 | struct sk_buff *msg; | |
10679 | void *hdr; | |
10680 | ||
10681 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10682 | if (!msg) | |
10683 | return; | |
10684 | ||
10685 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10686 | if (!hdr) { | |
10687 | nlmsg_free(msg); | |
10688 | return; | |
10689 | } | |
10690 | ||
9360ffd1 | 10691 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10692 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10693 | wdev->netdev->ifindex)) || | |
00f53350 | 10694 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10695 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10696 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10697 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10698 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10699 | goto nla_put_failure; | |
9588bbd5 | 10700 | |
9360ffd1 DM |
10701 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10702 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10703 | goto nla_put_failure; | |
9588bbd5 | 10704 | |
3b7b72ee | 10705 | genlmsg_end(msg, hdr); |
9588bbd5 | 10706 | |
68eb5503 | 10707 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10708 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
10709 | return; |
10710 | ||
10711 | nla_put_failure: | |
10712 | genlmsg_cancel(msg, hdr); | |
10713 | nlmsg_free(msg); | |
10714 | } | |
10715 | ||
947add36 JB |
10716 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10717 | struct ieee80211_channel *chan, | |
10718 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10719 | { |
947add36 JB |
10720 | struct wiphy *wiphy = wdev->wiphy; |
10721 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10722 | ||
10723 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10724 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10725 | rdev, wdev, cookie, chan, |
42d97a59 | 10726 | duration, gfp); |
9588bbd5 | 10727 | } |
947add36 | 10728 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10729 | |
947add36 JB |
10730 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10731 | struct ieee80211_channel *chan, | |
10732 | gfp_t gfp) | |
9588bbd5 | 10733 | { |
947add36 JB |
10734 | struct wiphy *wiphy = wdev->wiphy; |
10735 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10736 | ||
10737 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10738 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10739 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10740 | } |
947add36 | 10741 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10742 | |
947add36 JB |
10743 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10744 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10745 | { |
947add36 JB |
10746 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10747 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
10748 | struct sk_buff *msg; |
10749 | ||
947add36 JB |
10750 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10751 | ||
58050fce | 10752 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10753 | if (!msg) |
10754 | return; | |
10755 | ||
66266b3a JL |
10756 | if (nl80211_send_station(msg, 0, 0, 0, |
10757 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10758 | nlmsg_free(msg); |
10759 | return; | |
10760 | } | |
10761 | ||
68eb5503 | 10762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10763 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 10764 | } |
947add36 | 10765 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10766 | |
947add36 | 10767 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10768 | { |
947add36 JB |
10769 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10770 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
10771 | struct sk_buff *msg; |
10772 | void *hdr; | |
10773 | ||
947add36 JB |
10774 | trace_cfg80211_del_sta(dev, mac_addr); |
10775 | ||
58050fce | 10776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10777 | if (!msg) |
10778 | return; | |
10779 | ||
10780 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10781 | if (!hdr) { | |
10782 | nlmsg_free(msg); | |
10783 | return; | |
10784 | } | |
10785 | ||
9360ffd1 DM |
10786 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10787 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10788 | goto nla_put_failure; | |
ec15e68b | 10789 | |
3b7b72ee | 10790 | genlmsg_end(msg, hdr); |
ec15e68b | 10791 | |
68eb5503 | 10792 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10793 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
10794 | return; |
10795 | ||
10796 | nla_put_failure: | |
10797 | genlmsg_cancel(msg, hdr); | |
10798 | nlmsg_free(msg); | |
10799 | } | |
947add36 | 10800 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10801 | |
947add36 JB |
10802 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10803 | enum nl80211_connect_failed_reason reason, | |
10804 | gfp_t gfp) | |
ed44a951 | 10805 | { |
947add36 JB |
10806 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10807 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
10808 | struct sk_buff *msg; |
10809 | void *hdr; | |
10810 | ||
10811 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10812 | if (!msg) | |
10813 | return; | |
10814 | ||
10815 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10816 | if (!hdr) { | |
10817 | nlmsg_free(msg); | |
10818 | return; | |
10819 | } | |
10820 | ||
10821 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10822 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10823 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10824 | goto nla_put_failure; | |
10825 | ||
10826 | genlmsg_end(msg, hdr); | |
10827 | ||
68eb5503 | 10828 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10829 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
10830 | return; |
10831 | ||
10832 | nla_put_failure: | |
10833 | genlmsg_cancel(msg, hdr); | |
10834 | nlmsg_free(msg); | |
10835 | } | |
947add36 | 10836 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10837 | |
b92ab5d8 JB |
10838 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10839 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10840 | { |
10841 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10842 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10843 | struct sk_buff *msg; | |
10844 | void *hdr; | |
15e47304 | 10845 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10846 | |
15e47304 | 10847 | if (!nlportid) |
28946da7 JB |
10848 | return false; |
10849 | ||
10850 | msg = nlmsg_new(100, gfp); | |
10851 | if (!msg) | |
10852 | return true; | |
10853 | ||
b92ab5d8 | 10854 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10855 | if (!hdr) { |
10856 | nlmsg_free(msg); | |
10857 | return true; | |
10858 | } | |
10859 | ||
9360ffd1 DM |
10860 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10861 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10862 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10863 | goto nla_put_failure; | |
28946da7 | 10864 | |
9c90a9f6 | 10865 | genlmsg_end(msg, hdr); |
15e47304 | 10866 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10867 | return true; |
10868 | ||
10869 | nla_put_failure: | |
10870 | genlmsg_cancel(msg, hdr); | |
10871 | nlmsg_free(msg); | |
10872 | return true; | |
10873 | } | |
10874 | ||
947add36 JB |
10875 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10876 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10877 | { |
947add36 JB |
10878 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10879 | bool ret; | |
10880 | ||
10881 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10882 | ||
10883 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10884 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10885 | trace_cfg80211_return_bool(false); | |
10886 | return false; | |
10887 | } | |
10888 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10889 | addr, gfp); | |
10890 | trace_cfg80211_return_bool(ret); | |
10891 | return ret; | |
b92ab5d8 | 10892 | } |
947add36 | 10893 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10894 | |
947add36 JB |
10895 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10896 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10897 | { |
947add36 JB |
10898 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10899 | bool ret; | |
10900 | ||
10901 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10902 | ||
10903 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10904 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10905 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10906 | trace_cfg80211_return_bool(false); | |
10907 | return false; | |
10908 | } | |
10909 | ret = __nl80211_unexpected_frame(dev, | |
10910 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10911 | addr, gfp); | |
10912 | trace_cfg80211_return_bool(ret); | |
10913 | return ret; | |
b92ab5d8 | 10914 | } |
947add36 | 10915 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10916 | |
2e161f78 | 10917 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10918 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 10919 | int freq, int sig_dbm, |
19504cf5 | 10920 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 10921 | { |
71bbc994 | 10922 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10923 | struct sk_buff *msg; |
10924 | void *hdr; | |
026331c4 JM |
10925 | |
10926 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10927 | if (!msg) | |
10928 | return -ENOMEM; | |
10929 | ||
2e161f78 | 10930 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10931 | if (!hdr) { |
10932 | nlmsg_free(msg); | |
10933 | return -ENOMEM; | |
10934 | } | |
10935 | ||
9360ffd1 | 10936 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10937 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10938 | netdev->ifindex)) || | |
a838490b | 10939 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10940 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10941 | (sig_dbm && | |
10942 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
10943 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10944 | (flags && | |
10945 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 10946 | goto nla_put_failure; |
026331c4 | 10947 | |
3b7b72ee | 10948 | genlmsg_end(msg, hdr); |
026331c4 | 10949 | |
15e47304 | 10950 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10951 | |
10952 | nla_put_failure: | |
10953 | genlmsg_cancel(msg, hdr); | |
10954 | nlmsg_free(msg); | |
10955 | return -ENOBUFS; | |
10956 | } | |
10957 | ||
947add36 JB |
10958 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10959 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10960 | { |
947add36 JB |
10961 | struct wiphy *wiphy = wdev->wiphy; |
10962 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10963 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10964 | struct sk_buff *msg; |
10965 | void *hdr; | |
10966 | ||
947add36 JB |
10967 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10968 | ||
026331c4 JM |
10969 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10970 | if (!msg) | |
10971 | return; | |
10972 | ||
2e161f78 | 10973 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10974 | if (!hdr) { |
10975 | nlmsg_free(msg); | |
10976 | return; | |
10977 | } | |
10978 | ||
9360ffd1 | 10979 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10980 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10981 | netdev->ifindex)) || | |
a838490b | 10982 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10983 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10984 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10985 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10986 | goto nla_put_failure; | |
026331c4 | 10987 | |
3b7b72ee | 10988 | genlmsg_end(msg, hdr); |
026331c4 | 10989 | |
68eb5503 | 10990 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10991 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
10992 | return; |
10993 | ||
10994 | nla_put_failure: | |
10995 | genlmsg_cancel(msg, hdr); | |
10996 | nlmsg_free(msg); | |
10997 | } | |
947add36 | 10998 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10999 | |
947add36 JB |
11000 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
11001 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
11002 | gfp_t gfp) | |
d6dc1a38 | 11003 | { |
947add36 JB |
11004 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11005 | struct wiphy *wiphy = wdev->wiphy; | |
11006 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
11007 | struct sk_buff *msg; |
11008 | struct nlattr *pinfoattr; | |
11009 | void *hdr; | |
11010 | ||
947add36 JB |
11011 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
11012 | ||
58050fce | 11013 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
11014 | if (!msg) |
11015 | return; | |
11016 | ||
11017 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11018 | if (!hdr) { | |
11019 | nlmsg_free(msg); | |
11020 | return; | |
11021 | } | |
11022 | ||
9360ffd1 | 11023 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11024 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 11025 | goto nla_put_failure; |
d6dc1a38 JO |
11026 | |
11027 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11028 | if (!pinfoattr) | |
11029 | goto nla_put_failure; | |
11030 | ||
9360ffd1 DM |
11031 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
11032 | rssi_event)) | |
11033 | goto nla_put_failure; | |
d6dc1a38 JO |
11034 | |
11035 | nla_nest_end(msg, pinfoattr); | |
11036 | ||
3b7b72ee | 11037 | genlmsg_end(msg, hdr); |
d6dc1a38 | 11038 | |
68eb5503 | 11039 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11040 | NL80211_MCGRP_MLME, gfp); |
d6dc1a38 JO |
11041 | return; |
11042 | ||
11043 | nla_put_failure: | |
11044 | genlmsg_cancel(msg, hdr); | |
11045 | nlmsg_free(msg); | |
11046 | } | |
947add36 | 11047 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 11048 | |
947add36 JB |
11049 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
11050 | struct net_device *netdev, const u8 *bssid, | |
11051 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
11052 | { |
11053 | struct sk_buff *msg; | |
11054 | struct nlattr *rekey_attr; | |
11055 | void *hdr; | |
11056 | ||
58050fce | 11057 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
11058 | if (!msg) |
11059 | return; | |
11060 | ||
11061 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
11062 | if (!hdr) { | |
11063 | nlmsg_free(msg); | |
11064 | return; | |
11065 | } | |
11066 | ||
9360ffd1 DM |
11067 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11068 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11069 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11070 | goto nla_put_failure; | |
e5497d76 JB |
11071 | |
11072 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
11073 | if (!rekey_attr) | |
11074 | goto nla_put_failure; | |
11075 | ||
9360ffd1 DM |
11076 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
11077 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
11078 | goto nla_put_failure; | |
e5497d76 JB |
11079 | |
11080 | nla_nest_end(msg, rekey_attr); | |
11081 | ||
3b7b72ee | 11082 | genlmsg_end(msg, hdr); |
e5497d76 | 11083 | |
68eb5503 | 11084 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11085 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
11086 | return; |
11087 | ||
11088 | nla_put_failure: | |
11089 | genlmsg_cancel(msg, hdr); | |
11090 | nlmsg_free(msg); | |
11091 | } | |
11092 | ||
947add36 JB |
11093 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
11094 | const u8 *replay_ctr, gfp_t gfp) | |
11095 | { | |
11096 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11097 | struct wiphy *wiphy = wdev->wiphy; | |
11098 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11099 | ||
11100 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
11101 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
11102 | } | |
11103 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
11104 | ||
11105 | static void | |
11106 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
11107 | struct net_device *netdev, int index, | |
11108 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
11109 | { |
11110 | struct sk_buff *msg; | |
11111 | struct nlattr *attr; | |
11112 | void *hdr; | |
11113 | ||
58050fce | 11114 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
11115 | if (!msg) |
11116 | return; | |
11117 | ||
11118 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
11119 | if (!hdr) { | |
11120 | nlmsg_free(msg); | |
11121 | return; | |
11122 | } | |
11123 | ||
9360ffd1 DM |
11124 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11125 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11126 | goto nla_put_failure; | |
c9df56b4 JM |
11127 | |
11128 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
11129 | if (!attr) | |
11130 | goto nla_put_failure; | |
11131 | ||
9360ffd1 DM |
11132 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
11133 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
11134 | (preauth && | |
11135 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
11136 | goto nla_put_failure; | |
c9df56b4 JM |
11137 | |
11138 | nla_nest_end(msg, attr); | |
11139 | ||
3b7b72ee | 11140 | genlmsg_end(msg, hdr); |
c9df56b4 | 11141 | |
68eb5503 | 11142 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11143 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
11144 | return; |
11145 | ||
11146 | nla_put_failure: | |
11147 | genlmsg_cancel(msg, hdr); | |
11148 | nlmsg_free(msg); | |
11149 | } | |
11150 | ||
947add36 JB |
11151 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
11152 | const u8 *bssid, bool preauth, gfp_t gfp) | |
11153 | { | |
11154 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11155 | struct wiphy *wiphy = wdev->wiphy; | |
11156 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11157 | ||
11158 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
11159 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
11160 | } | |
11161 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
11162 | ||
11163 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
11164 | struct net_device *netdev, | |
11165 | struct cfg80211_chan_def *chandef, | |
11166 | gfp_t gfp) | |
5314526b TP |
11167 | { |
11168 | struct sk_buff *msg; | |
11169 | void *hdr; | |
11170 | ||
58050fce | 11171 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
11172 | if (!msg) |
11173 | return; | |
11174 | ||
11175 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
11176 | if (!hdr) { | |
11177 | nlmsg_free(msg); | |
11178 | return; | |
11179 | } | |
11180 | ||
683b6d3b JB |
11181 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
11182 | goto nla_put_failure; | |
11183 | ||
11184 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 11185 | goto nla_put_failure; |
5314526b TP |
11186 | |
11187 | genlmsg_end(msg, hdr); | |
11188 | ||
68eb5503 | 11189 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11190 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
11191 | return; |
11192 | ||
11193 | nla_put_failure: | |
11194 | genlmsg_cancel(msg, hdr); | |
11195 | nlmsg_free(msg); | |
11196 | } | |
11197 | ||
947add36 JB |
11198 | void cfg80211_ch_switch_notify(struct net_device *dev, |
11199 | struct cfg80211_chan_def *chandef) | |
84f10708 | 11200 | { |
947add36 JB |
11201 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11202 | struct wiphy *wiphy = wdev->wiphy; | |
11203 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11204 | ||
e487eaeb | 11205 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 11206 | |
e487eaeb | 11207 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 JB |
11208 | |
11209 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
ee4bc9e7 | 11210 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
b8456a14 CYY |
11211 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
11212 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | |
e487eaeb | 11213 | return; |
947add36 | 11214 | |
9e0e2961 | 11215 | wdev->chandef = *chandef; |
96f55f12 | 11216 | wdev->preset_chandef = *chandef; |
947add36 | 11217 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
947add36 JB |
11218 | } |
11219 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
11220 | ||
11221 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
11222 | const u8 *peer, u32 num_packets, | |
11223 | u32 rate, u32 intvl, gfp_t gfp) | |
11224 | { | |
11225 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11226 | struct wiphy *wiphy = wdev->wiphy; | |
11227 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
11228 | struct sk_buff *msg; |
11229 | struct nlattr *pinfoattr; | |
11230 | void *hdr; | |
11231 | ||
11232 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11233 | if (!msg) | |
11234 | return; | |
11235 | ||
11236 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11237 | if (!hdr) { | |
11238 | nlmsg_free(msg); | |
11239 | return; | |
11240 | } | |
11241 | ||
11242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 11243 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
11244 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11245 | goto nla_put_failure; | |
11246 | ||
11247 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11248 | if (!pinfoattr) | |
11249 | goto nla_put_failure; | |
11250 | ||
11251 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
11252 | goto nla_put_failure; | |
11253 | ||
11254 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
11255 | goto nla_put_failure; | |
11256 | ||
11257 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
11258 | goto nla_put_failure; | |
11259 | ||
11260 | nla_nest_end(msg, pinfoattr); | |
11261 | ||
11262 | genlmsg_end(msg, hdr); | |
11263 | ||
68eb5503 | 11264 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11265 | NL80211_MCGRP_MLME, gfp); |
84f10708 TP |
11266 | return; |
11267 | ||
11268 | nla_put_failure: | |
11269 | genlmsg_cancel(msg, hdr); | |
11270 | nlmsg_free(msg); | |
11271 | } | |
947add36 | 11272 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 11273 | |
04f39047 SW |
11274 | void |
11275 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 11276 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
11277 | enum nl80211_radar_event event, |
11278 | struct net_device *netdev, gfp_t gfp) | |
11279 | { | |
11280 | struct sk_buff *msg; | |
11281 | void *hdr; | |
11282 | ||
11283 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11284 | if (!msg) | |
11285 | return; | |
11286 | ||
11287 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
11288 | if (!hdr) { | |
11289 | nlmsg_free(msg); | |
11290 | return; | |
11291 | } | |
11292 | ||
11293 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11294 | goto nla_put_failure; | |
11295 | ||
11296 | /* NOP and radar events don't need a netdev parameter */ | |
11297 | if (netdev) { | |
11298 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
11299 | ||
11300 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11301 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11302 | goto nla_put_failure; | |
11303 | } | |
11304 | ||
11305 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
11306 | goto nla_put_failure; | |
11307 | ||
11308 | if (nl80211_send_chandef(msg, chandef)) | |
11309 | goto nla_put_failure; | |
11310 | ||
9c90a9f6 | 11311 | genlmsg_end(msg, hdr); |
04f39047 | 11312 | |
68eb5503 | 11313 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11314 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
11315 | return; |
11316 | ||
11317 | nla_put_failure: | |
11318 | genlmsg_cancel(msg, hdr); | |
11319 | nlmsg_free(msg); | |
11320 | } | |
11321 | ||
947add36 JB |
11322 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
11323 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 11324 | { |
947add36 JB |
11325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11326 | struct wiphy *wiphy = wdev->wiphy; | |
11327 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
11328 | struct sk_buff *msg; |
11329 | struct nlattr *pinfoattr; | |
11330 | void *hdr; | |
11331 | ||
947add36 JB |
11332 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
11333 | ||
58050fce | 11334 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
11335 | if (!msg) |
11336 | return; | |
11337 | ||
11338 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11339 | if (!hdr) { | |
11340 | nlmsg_free(msg); | |
11341 | return; | |
11342 | } | |
11343 | ||
9360ffd1 | 11344 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11345 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
11346 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11347 | goto nla_put_failure; | |
c063dbf5 JB |
11348 | |
11349 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11350 | if (!pinfoattr) | |
11351 | goto nla_put_failure; | |
11352 | ||
9360ffd1 DM |
11353 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
11354 | goto nla_put_failure; | |
c063dbf5 JB |
11355 | |
11356 | nla_nest_end(msg, pinfoattr); | |
11357 | ||
3b7b72ee | 11358 | genlmsg_end(msg, hdr); |
c063dbf5 | 11359 | |
68eb5503 | 11360 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11361 | NL80211_MCGRP_MLME, gfp); |
c063dbf5 JB |
11362 | return; |
11363 | ||
11364 | nla_put_failure: | |
11365 | genlmsg_cancel(msg, hdr); | |
11366 | nlmsg_free(msg); | |
11367 | } | |
947add36 | 11368 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 11369 | |
7f6cf311 JB |
11370 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
11371 | u64 cookie, bool acked, gfp_t gfp) | |
11372 | { | |
11373 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11374 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11375 | struct sk_buff *msg; | |
11376 | void *hdr; | |
7f6cf311 | 11377 | |
4ee3e063 BL |
11378 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
11379 | ||
58050fce | 11380 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 11381 | |
7f6cf311 JB |
11382 | if (!msg) |
11383 | return; | |
11384 | ||
11385 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
11386 | if (!hdr) { | |
11387 | nlmsg_free(msg); | |
11388 | return; | |
11389 | } | |
11390 | ||
9360ffd1 DM |
11391 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11392 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11393 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
11394 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11395 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11396 | goto nla_put_failure; | |
7f6cf311 | 11397 | |
9c90a9f6 | 11398 | genlmsg_end(msg, hdr); |
7f6cf311 | 11399 | |
68eb5503 | 11400 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11401 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
11402 | return; |
11403 | ||
11404 | nla_put_failure: | |
11405 | genlmsg_cancel(msg, hdr); | |
11406 | nlmsg_free(msg); | |
11407 | } | |
11408 | EXPORT_SYMBOL(cfg80211_probe_status); | |
11409 | ||
5e760230 JB |
11410 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
11411 | const u8 *frame, size_t len, | |
37c73b5f | 11412 | int freq, int sig_dbm) |
5e760230 JB |
11413 | { |
11414 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11415 | struct sk_buff *msg; | |
11416 | void *hdr; | |
37c73b5f | 11417 | struct cfg80211_beacon_registration *reg; |
5e760230 | 11418 | |
4ee3e063 BL |
11419 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
11420 | ||
37c73b5f BG |
11421 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11422 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11423 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
11424 | if (!msg) { | |
11425 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11426 | return; | |
11427 | } | |
5e760230 | 11428 | |
37c73b5f BG |
11429 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
11430 | if (!hdr) | |
11431 | goto nla_put_failure; | |
5e760230 | 11432 | |
37c73b5f BG |
11433 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11434 | (freq && | |
11435 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
11436 | (sig_dbm && | |
11437 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
11438 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
11439 | goto nla_put_failure; | |
5e760230 | 11440 | |
37c73b5f | 11441 | genlmsg_end(msg, hdr); |
5e760230 | 11442 | |
37c73b5f BG |
11443 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
11444 | } | |
11445 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
11446 | return; |
11447 | ||
11448 | nla_put_failure: | |
37c73b5f BG |
11449 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
11450 | if (hdr) | |
11451 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
11452 | nlmsg_free(msg); |
11453 | } | |
11454 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
11455 | ||
cd8f7cb4 JB |
11456 | #ifdef CONFIG_PM |
11457 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
11458 | struct cfg80211_wowlan_wakeup *wakeup, | |
11459 | gfp_t gfp) | |
11460 | { | |
11461 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11462 | struct sk_buff *msg; | |
11463 | void *hdr; | |
9c90a9f6 | 11464 | int size = 200; |
cd8f7cb4 JB |
11465 | |
11466 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
11467 | ||
11468 | if (wakeup) | |
11469 | size += wakeup->packet_present_len; | |
11470 | ||
11471 | msg = nlmsg_new(size, gfp); | |
11472 | if (!msg) | |
11473 | return; | |
11474 | ||
11475 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
11476 | if (!hdr) | |
11477 | goto free_msg; | |
11478 | ||
11479 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11480 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11481 | goto free_msg; | |
11482 | ||
11483 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11484 | wdev->netdev->ifindex)) | |
11485 | goto free_msg; | |
11486 | ||
11487 | if (wakeup) { | |
11488 | struct nlattr *reasons; | |
11489 | ||
11490 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
11491 | if (!reasons) |
11492 | goto free_msg; | |
cd8f7cb4 JB |
11493 | |
11494 | if (wakeup->disconnect && | |
11495 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11496 | goto free_msg; | |
11497 | if (wakeup->magic_pkt && | |
11498 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11499 | goto free_msg; | |
11500 | if (wakeup->gtk_rekey_failure && | |
11501 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11502 | goto free_msg; | |
11503 | if (wakeup->eap_identity_req && | |
11504 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11505 | goto free_msg; | |
11506 | if (wakeup->four_way_handshake && | |
11507 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11508 | goto free_msg; | |
11509 | if (wakeup->rfkill_release && | |
11510 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11511 | goto free_msg; | |
11512 | ||
11513 | if (wakeup->pattern_idx >= 0 && | |
11514 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11515 | wakeup->pattern_idx)) | |
11516 | goto free_msg; | |
11517 | ||
ae917c9f JB |
11518 | if (wakeup->tcp_match && |
11519 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
11520 | goto free_msg; | |
2a0e047e | 11521 | |
ae917c9f JB |
11522 | if (wakeup->tcp_connlost && |
11523 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
11524 | goto free_msg; | |
2a0e047e | 11525 | |
ae917c9f JB |
11526 | if (wakeup->tcp_nomoretokens && |
11527 | nla_put_flag(msg, | |
11528 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
11529 | goto free_msg; | |
2a0e047e | 11530 | |
cd8f7cb4 JB |
11531 | if (wakeup->packet) { |
11532 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11533 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11534 | ||
11535 | if (!wakeup->packet_80211) { | |
11536 | pkt_attr = | |
11537 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11538 | len_attr = | |
11539 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11540 | } | |
11541 | ||
11542 | if (wakeup->packet_len && | |
11543 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11544 | goto free_msg; | |
11545 | ||
11546 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11547 | wakeup->packet)) | |
11548 | goto free_msg; | |
11549 | } | |
11550 | ||
11551 | nla_nest_end(msg, reasons); | |
11552 | } | |
11553 | ||
9c90a9f6 | 11554 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 11555 | |
68eb5503 | 11556 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11557 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
11558 | return; |
11559 | ||
11560 | free_msg: | |
11561 | nlmsg_free(msg); | |
11562 | } | |
11563 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
11564 | #endif | |
11565 | ||
3475b094 JM |
11566 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
11567 | enum nl80211_tdls_operation oper, | |
11568 | u16 reason_code, gfp_t gfp) | |
11569 | { | |
11570 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11571 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11572 | struct sk_buff *msg; | |
11573 | void *hdr; | |
3475b094 JM |
11574 | |
11575 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
11576 | reason_code); | |
11577 | ||
11578 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11579 | if (!msg) | |
11580 | return; | |
11581 | ||
11582 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
11583 | if (!hdr) { | |
11584 | nlmsg_free(msg); | |
11585 | return; | |
11586 | } | |
11587 | ||
11588 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11589 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11590 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
11591 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
11592 | (reason_code > 0 && | |
11593 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
11594 | goto nla_put_failure; | |
11595 | ||
9c90a9f6 | 11596 | genlmsg_end(msg, hdr); |
3475b094 | 11597 | |
68eb5503 | 11598 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11599 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
11600 | return; |
11601 | ||
11602 | nla_put_failure: | |
11603 | genlmsg_cancel(msg, hdr); | |
11604 | nlmsg_free(msg); | |
11605 | } | |
11606 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
11607 | ||
026331c4 JM |
11608 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11609 | unsigned long state, | |
11610 | void *_notify) | |
11611 | { | |
11612 | struct netlink_notify *notify = _notify; | |
11613 | struct cfg80211_registered_device *rdev; | |
11614 | struct wireless_dev *wdev; | |
37c73b5f | 11615 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11616 | |
11617 | if (state != NETLINK_URELEASE) | |
11618 | return NOTIFY_DONE; | |
11619 | ||
11620 | rcu_read_lock(); | |
11621 | ||
5e760230 | 11622 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 11623 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 11624 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
11625 | |
11626 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11627 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11628 | list) { | |
11629 | if (reg->nlportid == notify->portid) { | |
11630 | list_del(®->list); | |
11631 | kfree(reg); | |
11632 | break; | |
11633 | } | |
11634 | } | |
11635 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 11636 | } |
026331c4 JM |
11637 | |
11638 | rcu_read_unlock(); | |
11639 | ||
11640 | return NOTIFY_DONE; | |
11641 | } | |
11642 | ||
11643 | static struct notifier_block nl80211_netlink_notifier = { | |
11644 | .notifier_call = nl80211_netlink_notify, | |
11645 | }; | |
11646 | ||
355199e0 JM |
11647 | void cfg80211_ft_event(struct net_device *netdev, |
11648 | struct cfg80211_ft_event_params *ft_event) | |
11649 | { | |
11650 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
11651 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11652 | struct sk_buff *msg; | |
11653 | void *hdr; | |
355199e0 JM |
11654 | |
11655 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11656 | ||
11657 | if (!ft_event->target_ap) | |
11658 | return; | |
11659 | ||
11660 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11661 | if (!msg) | |
11662 | return; | |
11663 | ||
11664 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
11665 | if (!hdr) |
11666 | goto out; | |
355199e0 | 11667 | |
ae917c9f JB |
11668 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11669 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11670 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
11671 | goto out; | |
355199e0 | 11672 | |
ae917c9f JB |
11673 | if (ft_event->ies && |
11674 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
11675 | goto out; | |
11676 | if (ft_event->ric_ies && | |
11677 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11678 | ft_event->ric_ies)) | |
11679 | goto out; | |
355199e0 | 11680 | |
9c90a9f6 | 11681 | genlmsg_end(msg, hdr); |
355199e0 | 11682 | |
68eb5503 | 11683 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11684 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
11685 | return; |
11686 | out: | |
11687 | nlmsg_free(msg); | |
355199e0 JM |
11688 | } |
11689 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11690 | ||
5de17984 AS |
11691 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11692 | { | |
11693 | struct cfg80211_registered_device *rdev; | |
11694 | struct sk_buff *msg; | |
11695 | void *hdr; | |
11696 | u32 nlportid; | |
11697 | ||
11698 | rdev = wiphy_to_dev(wdev->wiphy); | |
11699 | if (!rdev->crit_proto_nlportid) | |
11700 | return; | |
11701 | ||
11702 | nlportid = rdev->crit_proto_nlportid; | |
11703 | rdev->crit_proto_nlportid = 0; | |
11704 | ||
11705 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11706 | if (!msg) | |
11707 | return; | |
11708 | ||
11709 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11710 | if (!hdr) | |
11711 | goto nla_put_failure; | |
11712 | ||
11713 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11714 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11715 | goto nla_put_failure; | |
11716 | ||
11717 | genlmsg_end(msg, hdr); | |
11718 | ||
11719 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11720 | return; | |
11721 | ||
11722 | nla_put_failure: | |
11723 | if (hdr) | |
11724 | genlmsg_cancel(msg, hdr); | |
11725 | nlmsg_free(msg); | |
11726 | ||
11727 | } | |
11728 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11729 | ||
348baf0e JB |
11730 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
11731 | { | |
11732 | struct wiphy *wiphy = wdev->wiphy; | |
11733 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11734 | struct sk_buff *msg; | |
11735 | void *hdr; | |
11736 | ||
11737 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11738 | if (!msg) | |
11739 | return; | |
11740 | ||
11741 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
11742 | if (!hdr) | |
11743 | goto out; | |
11744 | ||
11745 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11746 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
11747 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11748 | goto out; | |
11749 | ||
11750 | genlmsg_end(msg, hdr); | |
11751 | ||
11752 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
11753 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
11754 | return; | |
11755 | out: | |
11756 | nlmsg_free(msg); | |
11757 | } | |
11758 | ||
55682965 JB |
11759 | /* initialisation/exit functions */ |
11760 | ||
11761 | int nl80211_init(void) | |
11762 | { | |
0d63cbb5 | 11763 | int err; |
55682965 | 11764 | |
2a94fe48 JB |
11765 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
11766 | nl80211_mcgrps); | |
55682965 JB |
11767 | if (err) |
11768 | return err; | |
11769 | ||
026331c4 JM |
11770 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11771 | if (err) | |
11772 | goto err_out; | |
11773 | ||
55682965 JB |
11774 | return 0; |
11775 | err_out: | |
11776 | genl_unregister_family(&nl80211_fam); | |
11777 | return err; | |
11778 | } | |
11779 | ||
11780 | void nl80211_exit(void) | |
11781 | { | |
026331c4 | 11782 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11783 | genl_unregister_family(&nl80211_fam); |
11784 | } |