]>
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 }, | |
55682965 JB |
385 | }; |
386 | ||
e31b8213 | 387 | /* policy for the key attributes */ |
b54452b0 | 388 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 389 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
390 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
391 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 392 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
393 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
394 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 395 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
396 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
397 | }; | |
398 | ||
399 | /* policy for the key default flags */ | |
400 | static const struct nla_policy | |
401 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
402 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
403 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
404 | }; |
405 | ||
ff1b6e69 JB |
406 | /* policy for WoWLAN attributes */ |
407 | static const struct nla_policy | |
408 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
409 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
410 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
411 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
412 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
413 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
414 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
415 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
416 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e JB |
417 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
418 | }; | |
419 | ||
420 | static const struct nla_policy | |
421 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
422 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
423 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
424 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
425 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
426 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
427 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
428 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
429 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
430 | }, | |
431 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
432 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
433 | }, | |
434 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
435 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
436 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
437 | }; |
438 | ||
be29b99a AK |
439 | /* policy for coalesce rule attributes */ |
440 | static const struct nla_policy | |
441 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
442 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
443 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
444 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
445 | }; | |
446 | ||
e5497d76 JB |
447 | /* policy for GTK rekey offload attributes */ |
448 | static const struct nla_policy | |
449 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
450 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
451 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
452 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
453 | }; | |
454 | ||
a1f1c21c LC |
455 | static const struct nla_policy |
456 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 457 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 458 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 459 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
460 | }; |
461 | ||
97990a06 JB |
462 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
463 | struct netlink_callback *cb, | |
464 | struct cfg80211_registered_device **rdev, | |
465 | struct wireless_dev **wdev) | |
a043897a | 466 | { |
97990a06 | 467 | int err; |
a043897a | 468 | |
97990a06 | 469 | rtnl_lock(); |
a043897a | 470 | |
97990a06 JB |
471 | if (!cb->args[0]) { |
472 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
473 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
474 | nl80211_policy); | |
475 | if (err) | |
476 | goto out_unlock; | |
67748893 | 477 | |
97990a06 JB |
478 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
479 | nl80211_fam.attrbuf); | |
480 | if (IS_ERR(*wdev)) { | |
481 | err = PTR_ERR(*wdev); | |
482 | goto out_unlock; | |
483 | } | |
484 | *rdev = wiphy_to_dev((*wdev)->wiphy); | |
c319d50b JB |
485 | /* 0 is the first index - add 1 to parse only once */ |
486 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
487 | cb->args[1] = (*wdev)->identifier; |
488 | } else { | |
c319d50b JB |
489 | /* subtract the 1 again here */ |
490 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 491 | struct wireless_dev *tmp; |
67748893 | 492 | |
97990a06 JB |
493 | if (!wiphy) { |
494 | err = -ENODEV; | |
495 | goto out_unlock; | |
496 | } | |
497 | *rdev = wiphy_to_dev(wiphy); | |
498 | *wdev = NULL; | |
67748893 | 499 | |
97990a06 JB |
500 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
501 | if (tmp->identifier == cb->args[1]) { | |
502 | *wdev = tmp; | |
503 | break; | |
504 | } | |
505 | } | |
67748893 | 506 | |
97990a06 JB |
507 | if (!*wdev) { |
508 | err = -ENODEV; | |
509 | goto out_unlock; | |
510 | } | |
67748893 JB |
511 | } |
512 | ||
67748893 | 513 | return 0; |
97990a06 | 514 | out_unlock: |
67748893 JB |
515 | rtnl_unlock(); |
516 | return err; | |
517 | } | |
518 | ||
97990a06 | 519 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 520 | { |
67748893 JB |
521 | rtnl_unlock(); |
522 | } | |
523 | ||
f4a11bb0 JB |
524 | /* IE validation */ |
525 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
526 | { | |
527 | const u8 *pos; | |
528 | int len; | |
529 | ||
530 | if (!attr) | |
531 | return true; | |
532 | ||
533 | pos = nla_data(attr); | |
534 | len = nla_len(attr); | |
535 | ||
536 | while (len) { | |
537 | u8 elemlen; | |
538 | ||
539 | if (len < 2) | |
540 | return false; | |
541 | len -= 2; | |
542 | ||
543 | elemlen = pos[1]; | |
544 | if (elemlen > len) | |
545 | return false; | |
546 | ||
547 | len -= elemlen; | |
548 | pos += 2 + elemlen; | |
549 | } | |
550 | ||
551 | return true; | |
552 | } | |
553 | ||
55682965 | 554 | /* message building helper */ |
15e47304 | 555 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
556 | int flags, u8 cmd) |
557 | { | |
558 | /* since there is no private header just add the generic one */ | |
15e47304 | 559 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
560 | } |
561 | ||
5dab3b8a | 562 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
563 | struct ieee80211_channel *chan, |
564 | bool large) | |
5dab3b8a | 565 | { |
9360ffd1 DM |
566 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
567 | chan->center_freq)) | |
568 | goto nla_put_failure; | |
5dab3b8a | 569 | |
9360ffd1 DM |
570 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
572 | goto nla_put_failure; | |
8fe02e16 LR |
573 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
574 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
575 | goto nla_put_failure; | |
576 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
577 | goto nla_put_failure; | |
578 | } | |
cdc89b97 JB |
579 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
580 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
581 | goto nla_put_failure; | |
582 | if (large) { | |
583 | u32 time; | |
584 | ||
585 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
586 | ||
587 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
588 | chan->dfs_state)) | |
589 | goto nla_put_failure; | |
590 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
591 | time)) | |
592 | goto nla_put_failure; | |
593 | } | |
594 | } | |
5dab3b8a | 595 | |
fe1abafd JB |
596 | if (large) { |
597 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
598 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
599 | goto nla_put_failure; | |
600 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
601 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
602 | goto nla_put_failure; | |
603 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
604 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
605 | goto nla_put_failure; | |
606 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
607 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
608 | goto nla_put_failure; | |
609 | } | |
610 | ||
9360ffd1 DM |
611 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
612 | DBM_TO_MBM(chan->max_power))) | |
613 | goto nla_put_failure; | |
5dab3b8a LR |
614 | |
615 | return 0; | |
616 | ||
617 | nla_put_failure: | |
618 | return -ENOBUFS; | |
619 | } | |
620 | ||
55682965 JB |
621 | /* netlink command implementations */ |
622 | ||
b9454e83 JB |
623 | struct key_parse { |
624 | struct key_params p; | |
625 | int idx; | |
e31b8213 | 626 | int type; |
b9454e83 | 627 | bool def, defmgmt; |
dbd2fd65 | 628 | bool def_uni, def_multi; |
b9454e83 JB |
629 | }; |
630 | ||
631 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
632 | { | |
633 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
634 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
635 | nl80211_key_policy); | |
636 | if (err) | |
637 | return err; | |
638 | ||
639 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
640 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
641 | ||
dbd2fd65 JB |
642 | if (k->def) { |
643 | k->def_uni = true; | |
644 | k->def_multi = true; | |
645 | } | |
646 | if (k->defmgmt) | |
647 | k->def_multi = true; | |
648 | ||
b9454e83 JB |
649 | if (tb[NL80211_KEY_IDX]) |
650 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
651 | ||
652 | if (tb[NL80211_KEY_DATA]) { | |
653 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
654 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
655 | } | |
656 | ||
657 | if (tb[NL80211_KEY_SEQ]) { | |
658 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
659 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
660 | } | |
661 | ||
662 | if (tb[NL80211_KEY_CIPHER]) | |
663 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
664 | ||
e31b8213 JB |
665 | if (tb[NL80211_KEY_TYPE]) { |
666 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
667 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
668 | return -EINVAL; | |
669 | } | |
670 | ||
dbd2fd65 JB |
671 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
672 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
673 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
674 | tb[NL80211_KEY_DEFAULT_TYPES], | |
675 | nl80211_key_default_policy); | |
dbd2fd65 JB |
676 | if (err) |
677 | return err; | |
678 | ||
679 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
680 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
681 | } | |
682 | ||
b9454e83 JB |
683 | return 0; |
684 | } | |
685 | ||
686 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
687 | { | |
688 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
689 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
690 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
691 | } | |
692 | ||
693 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
694 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
695 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
696 | } | |
697 | ||
698 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
699 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
700 | ||
701 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
702 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
703 | ||
704 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
705 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
706 | ||
dbd2fd65 JB |
707 | if (k->def) { |
708 | k->def_uni = true; | |
709 | k->def_multi = true; | |
710 | } | |
711 | if (k->defmgmt) | |
712 | k->def_multi = true; | |
713 | ||
e31b8213 JB |
714 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
715 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
716 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
717 | return -EINVAL; | |
718 | } | |
719 | ||
dbd2fd65 JB |
720 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
721 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
722 | int err = nla_parse_nested( | |
723 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
724 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
725 | nl80211_key_default_policy); | |
726 | if (err) | |
727 | return err; | |
728 | ||
729 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
730 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
731 | } | |
732 | ||
b9454e83 JB |
733 | return 0; |
734 | } | |
735 | ||
736 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
737 | { | |
738 | int err; | |
739 | ||
740 | memset(k, 0, sizeof(*k)); | |
741 | k->idx = -1; | |
e31b8213 | 742 | k->type = -1; |
b9454e83 JB |
743 | |
744 | if (info->attrs[NL80211_ATTR_KEY]) | |
745 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
746 | else | |
747 | err = nl80211_parse_key_old(info, k); | |
748 | ||
749 | if (err) | |
750 | return err; | |
751 | ||
752 | if (k->def && k->defmgmt) | |
753 | return -EINVAL; | |
754 | ||
dbd2fd65 JB |
755 | if (k->defmgmt) { |
756 | if (k->def_uni || !k->def_multi) | |
757 | return -EINVAL; | |
758 | } | |
759 | ||
b9454e83 JB |
760 | if (k->idx != -1) { |
761 | if (k->defmgmt) { | |
762 | if (k->idx < 4 || k->idx > 5) | |
763 | return -EINVAL; | |
764 | } else if (k->def) { | |
765 | if (k->idx < 0 || k->idx > 3) | |
766 | return -EINVAL; | |
767 | } else { | |
768 | if (k->idx < 0 || k->idx > 5) | |
769 | return -EINVAL; | |
770 | } | |
771 | } | |
772 | ||
773 | return 0; | |
774 | } | |
775 | ||
fffd0934 JB |
776 | static struct cfg80211_cached_keys * |
777 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 778 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
779 | { |
780 | struct key_parse parse; | |
781 | struct nlattr *key; | |
782 | struct cfg80211_cached_keys *result; | |
783 | int rem, err, def = 0; | |
784 | ||
785 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
786 | if (!result) | |
787 | return ERR_PTR(-ENOMEM); | |
788 | ||
789 | result->def = -1; | |
790 | result->defmgmt = -1; | |
791 | ||
792 | nla_for_each_nested(key, keys, rem) { | |
793 | memset(&parse, 0, sizeof(parse)); | |
794 | parse.idx = -1; | |
795 | ||
796 | err = nl80211_parse_key_new(key, &parse); | |
797 | if (err) | |
798 | goto error; | |
799 | err = -EINVAL; | |
800 | if (!parse.p.key) | |
801 | goto error; | |
802 | if (parse.idx < 0 || parse.idx > 4) | |
803 | goto error; | |
804 | if (parse.def) { | |
805 | if (def) | |
806 | goto error; | |
807 | def = 1; | |
808 | result->def = parse.idx; | |
dbd2fd65 JB |
809 | if (!parse.def_uni || !parse.def_multi) |
810 | goto error; | |
fffd0934 JB |
811 | } else if (parse.defmgmt) |
812 | goto error; | |
813 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 814 | parse.idx, false, NULL); |
fffd0934 JB |
815 | if (err) |
816 | goto error; | |
817 | result->params[parse.idx].cipher = parse.p.cipher; | |
818 | result->params[parse.idx].key_len = parse.p.key_len; | |
819 | result->params[parse.idx].key = result->data[parse.idx]; | |
820 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
821 | |
822 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
823 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
824 | if (no_ht) | |
825 | *no_ht = true; | |
826 | } | |
fffd0934 JB |
827 | } |
828 | ||
829 | return result; | |
830 | error: | |
831 | kfree(result); | |
832 | return ERR_PTR(err); | |
833 | } | |
834 | ||
835 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
836 | { | |
837 | ASSERT_WDEV_LOCK(wdev); | |
838 | ||
fffd0934 JB |
839 | switch (wdev->iftype) { |
840 | case NL80211_IFTYPE_AP: | |
841 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 842 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 843 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
844 | break; |
845 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 846 | case NL80211_IFTYPE_STATION: |
074ac8df | 847 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 848 | if (!wdev->current_bss) |
fffd0934 JB |
849 | return -ENOLINK; |
850 | break; | |
851 | default: | |
852 | return -EINVAL; | |
853 | } | |
854 | ||
855 | return 0; | |
856 | } | |
857 | ||
7527a782 JB |
858 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
859 | { | |
860 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
861 | int i; | |
862 | ||
863 | if (!nl_modes) | |
864 | goto nla_put_failure; | |
865 | ||
866 | i = 0; | |
867 | while (ifmodes) { | |
9360ffd1 DM |
868 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
869 | goto nla_put_failure; | |
7527a782 JB |
870 | ifmodes >>= 1; |
871 | i++; | |
872 | } | |
873 | ||
874 | nla_nest_end(msg, nl_modes); | |
875 | return 0; | |
876 | ||
877 | nla_put_failure: | |
878 | return -ENOBUFS; | |
879 | } | |
880 | ||
881 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
882 | struct sk_buff *msg, |
883 | bool large) | |
7527a782 JB |
884 | { |
885 | struct nlattr *nl_combis; | |
886 | int i, j; | |
887 | ||
888 | nl_combis = nla_nest_start(msg, | |
889 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
890 | if (!nl_combis) | |
891 | goto nla_put_failure; | |
892 | ||
893 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
894 | const struct ieee80211_iface_combination *c; | |
895 | struct nlattr *nl_combi, *nl_limits; | |
896 | ||
897 | c = &wiphy->iface_combinations[i]; | |
898 | ||
899 | nl_combi = nla_nest_start(msg, i + 1); | |
900 | if (!nl_combi) | |
901 | goto nla_put_failure; | |
902 | ||
903 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
904 | if (!nl_limits) | |
905 | goto nla_put_failure; | |
906 | ||
907 | for (j = 0; j < c->n_limits; j++) { | |
908 | struct nlattr *nl_limit; | |
909 | ||
910 | nl_limit = nla_nest_start(msg, j + 1); | |
911 | if (!nl_limit) | |
912 | goto nla_put_failure; | |
9360ffd1 DM |
913 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
914 | c->limits[j].max)) | |
915 | goto nla_put_failure; | |
7527a782 JB |
916 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
917 | c->limits[j].types)) | |
918 | goto nla_put_failure; | |
919 | nla_nest_end(msg, nl_limit); | |
920 | } | |
921 | ||
922 | nla_nest_end(msg, nl_limits); | |
923 | ||
9360ffd1 DM |
924 | if (c->beacon_int_infra_match && |
925 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
926 | goto nla_put_failure; | |
927 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
928 | c->num_different_channels) || | |
929 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
930 | c->max_interfaces)) | |
931 | goto nla_put_failure; | |
cdc89b97 JB |
932 | if (large && |
933 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, | |
934 | c->radar_detect_widths)) | |
935 | goto nla_put_failure; | |
7527a782 JB |
936 | |
937 | nla_nest_end(msg, nl_combi); | |
938 | } | |
939 | ||
940 | nla_nest_end(msg, nl_combis); | |
941 | ||
942 | return 0; | |
943 | nla_put_failure: | |
944 | return -ENOBUFS; | |
945 | } | |
946 | ||
3713b4e3 | 947 | #ifdef CONFIG_PM |
b56cf720 JB |
948 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
949 | struct sk_buff *msg) | |
950 | { | |
964dc9e2 | 951 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
952 | struct nlattr *nl_tcp; |
953 | ||
954 | if (!tcp) | |
955 | return 0; | |
956 | ||
957 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
958 | if (!nl_tcp) | |
959 | return -ENOBUFS; | |
960 | ||
961 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
962 | tcp->data_payload_max)) | |
963 | return -ENOBUFS; | |
964 | ||
965 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
966 | tcp->data_payload_max)) | |
967 | return -ENOBUFS; | |
968 | ||
969 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
970 | return -ENOBUFS; | |
971 | ||
972 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
973 | sizeof(*tcp->tok), tcp->tok)) | |
974 | return -ENOBUFS; | |
975 | ||
976 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
977 | tcp->data_interval_max)) | |
978 | return -ENOBUFS; | |
979 | ||
980 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
981 | tcp->wake_payload_max)) | |
982 | return -ENOBUFS; | |
983 | ||
984 | nla_nest_end(msg, nl_tcp); | |
985 | return 0; | |
986 | } | |
987 | ||
3713b4e3 | 988 | static int nl80211_send_wowlan(struct sk_buff *msg, |
b56cf720 JB |
989 | struct cfg80211_registered_device *dev, |
990 | bool large) | |
55682965 | 991 | { |
3713b4e3 | 992 | struct nlattr *nl_wowlan; |
55682965 | 993 | |
964dc9e2 | 994 | if (!dev->wiphy.wowlan) |
3713b4e3 | 995 | return 0; |
55682965 | 996 | |
3713b4e3 JB |
997 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
998 | if (!nl_wowlan) | |
999 | return -ENOBUFS; | |
9360ffd1 | 1000 | |
964dc9e2 | 1001 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1002 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
964dc9e2 | 1003 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1004 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
964dc9e2 | 1005 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
964dc9e2 | 1007 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1008 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
964dc9e2 | 1009 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
964dc9e2 | 1011 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1012 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
964dc9e2 | 1013 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1014 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
964dc9e2 | 1015 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1016 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1017 | return -ENOBUFS; | |
9360ffd1 | 1018 | |
964dc9e2 | 1019 | if (dev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1020 | struct nl80211_pattern_support pat = { |
964dc9e2 JB |
1021 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
1022 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, | |
1023 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, | |
1024 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1025 | }; |
9360ffd1 | 1026 | |
3713b4e3 JB |
1027 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1028 | sizeof(pat), &pat)) | |
1029 | return -ENOBUFS; | |
1030 | } | |
9360ffd1 | 1031 | |
b56cf720 JB |
1032 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
1033 | return -ENOBUFS; | |
1034 | ||
3713b4e3 | 1035 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1036 | |
3713b4e3 JB |
1037 | return 0; |
1038 | } | |
1039 | #endif | |
9360ffd1 | 1040 | |
be29b99a AK |
1041 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1042 | struct cfg80211_registered_device *dev) | |
1043 | { | |
1044 | struct nl80211_coalesce_rule_support rule; | |
1045 | ||
1046 | if (!dev->wiphy.coalesce) | |
1047 | return 0; | |
1048 | ||
1049 | rule.max_rules = dev->wiphy.coalesce->n_rules; | |
1050 | rule.max_delay = dev->wiphy.coalesce->max_delay; | |
1051 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; | |
1052 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; | |
1053 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; | |
1054 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; | |
1055 | ||
1056 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1057 | return -ENOBUFS; | |
1058 | ||
1059 | return 0; | |
1060 | } | |
1061 | ||
3713b4e3 JB |
1062 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1063 | struct ieee80211_supported_band *sband) | |
1064 | { | |
1065 | struct nlattr *nl_rates, *nl_rate; | |
1066 | struct ieee80211_rate *rate; | |
1067 | int i; | |
87bbbe22 | 1068 | |
3713b4e3 JB |
1069 | /* add HT info */ |
1070 | if (sband->ht_cap.ht_supported && | |
1071 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1072 | sizeof(sband->ht_cap.mcs), | |
1073 | &sband->ht_cap.mcs) || | |
1074 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1075 | sband->ht_cap.cap) || | |
1076 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1077 | sband->ht_cap.ampdu_factor) || | |
1078 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1079 | sband->ht_cap.ampdu_density))) | |
1080 | return -ENOBUFS; | |
afe0cbf8 | 1081 | |
3713b4e3 JB |
1082 | /* add VHT info */ |
1083 | if (sband->vht_cap.vht_supported && | |
1084 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1085 | sizeof(sband->vht_cap.vht_mcs), | |
1086 | &sband->vht_cap.vht_mcs) || | |
1087 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1088 | sband->vht_cap.cap))) | |
1089 | return -ENOBUFS; | |
f59ac048 | 1090 | |
3713b4e3 JB |
1091 | /* add bitrates */ |
1092 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1093 | if (!nl_rates) | |
1094 | return -ENOBUFS; | |
ee688b00 | 1095 | |
3713b4e3 JB |
1096 | for (i = 0; i < sband->n_bitrates; i++) { |
1097 | nl_rate = nla_nest_start(msg, i); | |
1098 | if (!nl_rate) | |
1099 | return -ENOBUFS; | |
ee688b00 | 1100 | |
3713b4e3 JB |
1101 | rate = &sband->bitrates[i]; |
1102 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1103 | rate->bitrate)) | |
1104 | return -ENOBUFS; | |
1105 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1106 | nla_put_flag(msg, | |
1107 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1108 | return -ENOBUFS; | |
ee688b00 | 1109 | |
3713b4e3 JB |
1110 | nla_nest_end(msg, nl_rate); |
1111 | } | |
d51626df | 1112 | |
3713b4e3 | 1113 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1114 | |
3713b4e3 JB |
1115 | return 0; |
1116 | } | |
ee688b00 | 1117 | |
3713b4e3 JB |
1118 | static int |
1119 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1120 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1121 | { | |
1122 | u16 stypes; | |
1123 | struct nlattr *nl_ftypes, *nl_ifs; | |
1124 | enum nl80211_iftype ift; | |
1125 | int i; | |
ee688b00 | 1126 | |
3713b4e3 JB |
1127 | if (!mgmt_stypes) |
1128 | return 0; | |
5dab3b8a | 1129 | |
3713b4e3 JB |
1130 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1131 | if (!nl_ifs) | |
1132 | return -ENOBUFS; | |
e2f367f2 | 1133 | |
3713b4e3 JB |
1134 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1135 | nl_ftypes = nla_nest_start(msg, ift); | |
1136 | if (!nl_ftypes) | |
1137 | return -ENOBUFS; | |
1138 | i = 0; | |
1139 | stypes = mgmt_stypes[ift].tx; | |
1140 | while (stypes) { | |
1141 | if ((stypes & 1) && | |
1142 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1143 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1144 | return -ENOBUFS; | |
1145 | stypes >>= 1; | |
1146 | i++; | |
ee688b00 | 1147 | } |
3713b4e3 JB |
1148 | nla_nest_end(msg, nl_ftypes); |
1149 | } | |
ee688b00 | 1150 | |
3713b4e3 | 1151 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1152 | |
3713b4e3 JB |
1153 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1154 | if (!nl_ifs) | |
1155 | return -ENOBUFS; | |
ee688b00 | 1156 | |
3713b4e3 JB |
1157 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1158 | nl_ftypes = nla_nest_start(msg, ift); | |
1159 | if (!nl_ftypes) | |
1160 | return -ENOBUFS; | |
1161 | i = 0; | |
1162 | stypes = mgmt_stypes[ift].rx; | |
1163 | while (stypes) { | |
1164 | if ((stypes & 1) && | |
1165 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1166 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1167 | return -ENOBUFS; | |
1168 | stypes >>= 1; | |
1169 | i++; | |
1170 | } | |
1171 | nla_nest_end(msg, nl_ftypes); | |
1172 | } | |
1173 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1174 | |
3713b4e3 JB |
1175 | return 0; |
1176 | } | |
ee688b00 | 1177 | |
86e8cf98 JB |
1178 | struct nl80211_dump_wiphy_state { |
1179 | s64 filter_wiphy; | |
1180 | long start; | |
1181 | long split_start, band_start, chan_start; | |
1182 | bool split; | |
1183 | }; | |
1184 | ||
3713b4e3 JB |
1185 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
1186 | struct sk_buff *msg, u32 portid, u32 seq, | |
86e8cf98 | 1187 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1188 | { |
1189 | void *hdr; | |
1190 | struct nlattr *nl_bands, *nl_band; | |
1191 | struct nlattr *nl_freqs, *nl_freq; | |
1192 | struct nlattr *nl_cmds; | |
1193 | enum ieee80211_band band; | |
1194 | struct ieee80211_channel *chan; | |
1195 | int i; | |
1196 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1197 | dev->wiphy.mgmt_stypes; | |
fe1abafd | 1198 | u32 features; |
ee688b00 | 1199 | |
3713b4e3 JB |
1200 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
1201 | if (!hdr) | |
1202 | return -ENOBUFS; | |
ee688b00 | 1203 | |
86e8cf98 JB |
1204 | if (WARN_ON(!state)) |
1205 | return -EINVAL; | |
ee688b00 | 1206 | |
3713b4e3 JB |
1207 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
1208 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, | |
1209 | wiphy_name(&dev->wiphy)) || | |
1210 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1211 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1212 | goto nla_put_failure; |
1213 | ||
86e8cf98 | 1214 | switch (state->split_start) { |
3713b4e3 JB |
1215 | case 0: |
1216 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1217 | dev->wiphy.retry_short) || | |
1218 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
1219 | dev->wiphy.retry_long) || | |
1220 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
1221 | dev->wiphy.frag_threshold) || | |
1222 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
1223 | dev->wiphy.rts_threshold) || | |
1224 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
1225 | dev->wiphy.coverage_class) || | |
1226 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
1227 | dev->wiphy.max_scan_ssids) || | |
1228 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
1229 | dev->wiphy.max_sched_scan_ssids) || | |
1230 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
1231 | dev->wiphy.max_scan_ie_len) || | |
1232 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
1233 | dev->wiphy.max_sched_scan_ie_len) || | |
1234 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
1235 | dev->wiphy.max_match_sets)) | |
9360ffd1 | 1236 | goto nla_put_failure; |
3713b4e3 JB |
1237 | |
1238 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
1239 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
aa430da4 | 1240 | goto nla_put_failure; |
3713b4e3 JB |
1241 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
1242 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
1243 | goto nla_put_failure; | |
1244 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
1245 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
1246 | goto nla_put_failure; | |
1247 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
1248 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
1249 | goto nla_put_failure; | |
1250 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
1251 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
1252 | goto nla_put_failure; | |
1253 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
1254 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
9360ffd1 | 1255 | goto nla_put_failure; |
86e8cf98 JB |
1256 | state->split_start++; |
1257 | if (state->split) | |
3713b4e3 JB |
1258 | break; |
1259 | case 1: | |
1260 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1261 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
1262 | dev->wiphy.cipher_suites)) | |
1263 | goto nla_put_failure; | |
4745fc09 | 1264 | |
3713b4e3 JB |
1265 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1266 | dev->wiphy.max_num_pmkids)) | |
1267 | goto nla_put_failure; | |
b23aa676 | 1268 | |
3713b4e3 JB |
1269 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
1270 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
9360ffd1 | 1271 | goto nla_put_failure; |
b23aa676 | 1272 | |
3713b4e3 JB |
1273 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1274 | dev->wiphy.available_antennas_tx) || | |
1275 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
1276 | dev->wiphy.available_antennas_rx)) | |
9360ffd1 | 1277 | goto nla_put_failure; |
b23aa676 | 1278 | |
3713b4e3 JB |
1279 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
1280 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
1281 | dev->wiphy.probe_resp_offload)) | |
1282 | goto nla_put_failure; | |
8fdc621d | 1283 | |
3713b4e3 JB |
1284 | if ((dev->wiphy.available_antennas_tx || |
1285 | dev->wiphy.available_antennas_rx) && | |
1286 | dev->ops->get_antenna) { | |
1287 | u32 tx_ant = 0, rx_ant = 0; | |
1288 | int res; | |
1289 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); | |
1290 | if (!res) { | |
1291 | if (nla_put_u32(msg, | |
1292 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1293 | tx_ant) || | |
1294 | nla_put_u32(msg, | |
1295 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1296 | rx_ant)) | |
1297 | goto nla_put_failure; | |
1298 | } | |
1299 | } | |
a293911d | 1300 | |
86e8cf98 JB |
1301 | state->split_start++; |
1302 | if (state->split) | |
3713b4e3 JB |
1303 | break; |
1304 | case 2: | |
1305 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1306 | dev->wiphy.interface_modes)) | |
1307 | goto nla_put_failure; | |
86e8cf98 JB |
1308 | state->split_start++; |
1309 | if (state->split) | |
3713b4e3 JB |
1310 | break; |
1311 | case 3: | |
1312 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1313 | if (!nl_bands) | |
1314 | goto nla_put_failure; | |
f7ca38df | 1315 | |
86e8cf98 JB |
1316 | for (band = state->band_start; |
1317 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1318 | struct ieee80211_supported_band *sband; |
2e161f78 | 1319 | |
3713b4e3 | 1320 | sband = dev->wiphy.bands[band]; |
2e161f78 | 1321 | |
3713b4e3 JB |
1322 | if (!sband) |
1323 | continue; | |
1324 | ||
1325 | nl_band = nla_nest_start(msg, band); | |
1326 | if (!nl_band) | |
2e161f78 | 1327 | goto nla_put_failure; |
3713b4e3 | 1328 | |
86e8cf98 | 1329 | switch (state->chan_start) { |
3713b4e3 JB |
1330 | case 0: |
1331 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1332 | goto nla_put_failure; |
86e8cf98 JB |
1333 | state->chan_start++; |
1334 | if (state->split) | |
3713b4e3 JB |
1335 | break; |
1336 | default: | |
1337 | /* add frequencies */ | |
1338 | nl_freqs = nla_nest_start( | |
1339 | msg, NL80211_BAND_ATTR_FREQS); | |
1340 | if (!nl_freqs) | |
1341 | goto nla_put_failure; | |
1342 | ||
86e8cf98 | 1343 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1344 | i < sband->n_channels; |
1345 | i++) { | |
1346 | nl_freq = nla_nest_start(msg, i); | |
1347 | if (!nl_freq) | |
1348 | goto nla_put_failure; | |
1349 | ||
1350 | chan = &sband->channels[i]; | |
1351 | ||
86e8cf98 JB |
1352 | if (nl80211_msg_put_channel( |
1353 | msg, chan, | |
1354 | state->split)) | |
3713b4e3 JB |
1355 | goto nla_put_failure; |
1356 | ||
1357 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1358 | if (state->split) |
3713b4e3 JB |
1359 | break; |
1360 | } | |
1361 | if (i < sband->n_channels) | |
86e8cf98 | 1362 | state->chan_start = i + 2; |
3713b4e3 | 1363 | else |
86e8cf98 | 1364 | state->chan_start = 0; |
3713b4e3 JB |
1365 | nla_nest_end(msg, nl_freqs); |
1366 | } | |
1367 | ||
1368 | nla_nest_end(msg, nl_band); | |
1369 | ||
86e8cf98 | 1370 | if (state->split) { |
3713b4e3 | 1371 | /* start again here */ |
86e8cf98 | 1372 | if (state->chan_start) |
3713b4e3 JB |
1373 | band--; |
1374 | break; | |
2e161f78 | 1375 | } |
2e161f78 | 1376 | } |
3713b4e3 | 1377 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1378 | |
3713b4e3 | 1379 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1380 | state->band_start = band + 1; |
3713b4e3 | 1381 | else |
86e8cf98 | 1382 | state->band_start = 0; |
74b70a4e | 1383 | |
3713b4e3 | 1384 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1385 | if (state->band_start == 0 && state->chan_start == 0) |
1386 | state->split_start++; | |
1387 | if (state->split) | |
3713b4e3 JB |
1388 | break; |
1389 | case 4: | |
1390 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1391 | if (!nl_cmds) | |
2e161f78 JB |
1392 | goto nla_put_failure; |
1393 | ||
3713b4e3 JB |
1394 | i = 0; |
1395 | #define CMD(op, n) \ | |
1396 | do { \ | |
1397 | if (dev->ops->op) { \ | |
1398 | i++; \ | |
1399 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1400 | goto nla_put_failure; \ | |
1401 | } \ | |
1402 | } while (0) | |
1403 | ||
1404 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1405 | CMD(change_virtual_intf, SET_INTERFACE); | |
1406 | CMD(add_key, NEW_KEY); | |
1407 | CMD(start_ap, START_AP); | |
1408 | CMD(add_station, NEW_STATION); | |
1409 | CMD(add_mpath, NEW_MPATH); | |
1410 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1411 | CMD(change_bss, SET_BSS); | |
1412 | CMD(auth, AUTHENTICATE); | |
1413 | CMD(assoc, ASSOCIATE); | |
1414 | CMD(deauth, DEAUTHENTICATE); | |
1415 | CMD(disassoc, DISASSOCIATE); | |
1416 | CMD(join_ibss, JOIN_IBSS); | |
1417 | CMD(join_mesh, JOIN_MESH); | |
1418 | CMD(set_pmksa, SET_PMKSA); | |
1419 | CMD(del_pmksa, DEL_PMKSA); | |
1420 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1421 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1422 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1423 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1424 | CMD(mgmt_tx, FRAME); | |
1425 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1426 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1427 | i++; | |
1428 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1429 | goto nla_put_failure; |
2e161f78 | 1430 | } |
3713b4e3 JB |
1431 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
1432 | dev->ops->join_mesh) { | |
1433 | i++; | |
1434 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1435 | goto nla_put_failure; | |
1436 | } | |
1437 | CMD(set_wds_peer, SET_WDS_PEER); | |
1438 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1439 | CMD(tdls_mgmt, TDLS_MGMT); | |
1440 | CMD(tdls_oper, TDLS_OPER); | |
1441 | } | |
1442 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
1443 | CMD(sched_scan_start, START_SCHED_SCAN); | |
1444 | CMD(probe_client, PROBE_CLIENT); | |
1445 | CMD(set_noack_map, SET_NOACK_MAP); | |
1446 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1447 | i++; | |
1448 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1449 | goto nla_put_failure; | |
1450 | } | |
1451 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1452 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
86e8cf98 | 1453 | if (state->split) { |
5de17984 AS |
1454 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1455 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
16ef1fe2 SW |
1456 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
1457 | CMD(channel_switch, CHANNEL_SWITCH); | |
5de17984 | 1458 | } |
fa9ffc74 | 1459 | CMD(set_qos_map, SET_QOS_MAP); |
2e161f78 | 1460 | |
3713b4e3 JB |
1461 | #ifdef CONFIG_NL80211_TESTMODE |
1462 | CMD(testmode_cmd, TESTMODE); | |
1463 | #endif | |
ff1b6e69 | 1464 | |
3713b4e3 | 1465 | #undef CMD |
ff1b6e69 | 1466 | |
3713b4e3 JB |
1467 | if (dev->ops->connect || dev->ops->auth) { |
1468 | i++; | |
1469 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1470 | goto nla_put_failure; |
ff1b6e69 JB |
1471 | } |
1472 | ||
3713b4e3 JB |
1473 | if (dev->ops->disconnect || dev->ops->deauth) { |
1474 | i++; | |
1475 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1476 | goto nla_put_failure; | |
1477 | } | |
1478 | ||
1479 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1480 | state->split_start++; |
1481 | if (state->split) | |
3713b4e3 JB |
1482 | break; |
1483 | case 5: | |
1484 | if (dev->ops->remain_on_channel && | |
1485 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
1486 | nla_put_u32(msg, | |
1487 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1488 | dev->wiphy.max_remain_on_channel_duration)) | |
1489 | goto nla_put_failure; | |
1490 | ||
1491 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && | |
1492 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1493 | goto nla_put_failure; | |
1494 | ||
1495 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1496 | goto nla_put_failure; | |
86e8cf98 JB |
1497 | state->split_start++; |
1498 | if (state->split) | |
3713b4e3 JB |
1499 | break; |
1500 | case 6: | |
1501 | #ifdef CONFIG_PM | |
86e8cf98 | 1502 | if (nl80211_send_wowlan(msg, dev, state->split)) |
3713b4e3 | 1503 | goto nla_put_failure; |
86e8cf98 JB |
1504 | state->split_start++; |
1505 | if (state->split) | |
3713b4e3 JB |
1506 | break; |
1507 | #else | |
86e8cf98 | 1508 | state->split_start++; |
dfb89c56 | 1509 | #endif |
3713b4e3 JB |
1510 | case 7: |
1511 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1512 | dev->wiphy.software_iftypes)) | |
1513 | goto nla_put_failure; | |
ff1b6e69 | 1514 | |
86e8cf98 JB |
1515 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
1516 | state->split)) | |
3713b4e3 | 1517 | goto nla_put_failure; |
7527a782 | 1518 | |
86e8cf98 JB |
1519 | state->split_start++; |
1520 | if (state->split) | |
3713b4e3 JB |
1521 | break; |
1522 | case 8: | |
1523 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && | |
1524 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1525 | dev->wiphy.ap_sme_capa)) | |
1526 | goto nla_put_failure; | |
7527a782 | 1527 | |
fe1abafd JB |
1528 | features = dev->wiphy.features; |
1529 | /* | |
1530 | * We can only add the per-channel limit information if the | |
1531 | * dump is split, otherwise it makes it too big. Therefore | |
1532 | * only advertise it in that case. | |
1533 | */ | |
86e8cf98 | 1534 | if (state->split) |
fe1abafd JB |
1535 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1536 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1537 | goto nla_put_failure; |
562a7480 | 1538 | |
3713b4e3 JB |
1539 | if (dev->wiphy.ht_capa_mod_mask && |
1540 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1541 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1542 | dev->wiphy.ht_capa_mod_mask)) | |
1543 | goto nla_put_failure; | |
1f074bd8 | 1544 | |
3713b4e3 JB |
1545 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1546 | dev->wiphy.max_acl_mac_addrs && | |
1547 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, | |
1548 | dev->wiphy.max_acl_mac_addrs)) | |
1549 | goto nla_put_failure; | |
7e7c8926 | 1550 | |
3713b4e3 JB |
1551 | /* |
1552 | * Any information below this point is only available to | |
1553 | * applications that can deal with it being split. This | |
1554 | * helps ensure that newly added capabilities don't break | |
1555 | * older tools by overrunning their buffers. | |
1556 | * | |
1557 | * We still increment split_start so that in the split | |
1558 | * case we'll continue with more data in the next round, | |
1559 | * but break unconditionally so unsplit data stops here. | |
1560 | */ | |
86e8cf98 | 1561 | state->split_start++; |
3713b4e3 JB |
1562 | break; |
1563 | case 9: | |
fe1abafd JB |
1564 | if (dev->wiphy.extended_capabilities && |
1565 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1566 | dev->wiphy.extended_capabilities_len, | |
1567 | dev->wiphy.extended_capabilities) || | |
1568 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1569 | dev->wiphy.extended_capabilities_len, | |
1570 | dev->wiphy.extended_capabilities_mask))) | |
1571 | goto nla_put_failure; | |
a50df0c4 | 1572 | |
ee2aca34 JB |
1573 | if (dev->wiphy.vht_capa_mod_mask && |
1574 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, | |
1575 | sizeof(*dev->wiphy.vht_capa_mod_mask), | |
1576 | dev->wiphy.vht_capa_mod_mask)) | |
1577 | goto nla_put_failure; | |
1578 | ||
be29b99a AK |
1579 | state->split_start++; |
1580 | break; | |
1581 | case 10: | |
1582 | if (nl80211_send_coalesce(msg, dev)) | |
1583 | goto nla_put_failure; | |
1584 | ||
01e0daa4 FF |
1585 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
1586 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || | |
1587 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1588 | goto nla_put_failure; | |
ad7e718c JB |
1589 | state->split_start++; |
1590 | break; | |
1591 | case 11: | |
567ffc35 JB |
1592 | if (dev->wiphy.n_vendor_commands) { |
1593 | const struct nl80211_vendor_cmd_info *info; | |
1594 | struct nlattr *nested; | |
1595 | ||
1596 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1597 | if (!nested) | |
1598 | goto nla_put_failure; | |
1599 | ||
1600 | for (i = 0; i < dev->wiphy.n_vendor_commands; i++) { | |
1601 | info = &dev->wiphy.vendor_commands[i].info; | |
1602 | if (nla_put(msg, i + 1, sizeof(*info), info)) | |
1603 | goto nla_put_failure; | |
1604 | } | |
1605 | nla_nest_end(msg, nested); | |
1606 | } | |
1607 | ||
1608 | if (dev->wiphy.n_vendor_events) { | |
1609 | const struct nl80211_vendor_cmd_info *info; | |
1610 | struct nlattr *nested; | |
ad7e718c | 1611 | |
567ffc35 JB |
1612 | nested = nla_nest_start(msg, |
1613 | NL80211_ATTR_VENDOR_EVENTS); | |
1614 | if (!nested) | |
ad7e718c | 1615 | goto nla_put_failure; |
567ffc35 JB |
1616 | |
1617 | for (i = 0; i < dev->wiphy.n_vendor_events; i++) { | |
1618 | info = &dev->wiphy.vendor_events[i]; | |
1619 | if (nla_put(msg, i + 1, sizeof(*info), info)) | |
1620 | goto nla_put_failure; | |
1621 | } | |
1622 | nla_nest_end(msg, nested); | |
1623 | } | |
01e0daa4 | 1624 | |
3713b4e3 | 1625 | /* done */ |
86e8cf98 | 1626 | state->split_start = 0; |
3713b4e3 JB |
1627 | break; |
1628 | } | |
55682965 JB |
1629 | return genlmsg_end(msg, hdr); |
1630 | ||
1631 | nla_put_failure: | |
bc3ed28c TG |
1632 | genlmsg_cancel(msg, hdr); |
1633 | return -EMSGSIZE; | |
55682965 JB |
1634 | } |
1635 | ||
86e8cf98 JB |
1636 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1637 | struct netlink_callback *cb, | |
1638 | struct nl80211_dump_wiphy_state *state) | |
1639 | { | |
1640 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1641 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1642 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1643 | /* ignore parse errors for backward compatibility */ | |
1644 | if (ret) | |
1645 | return 0; | |
1646 | ||
1647 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1648 | if (tb[NL80211_ATTR_WIPHY]) | |
1649 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1650 | if (tb[NL80211_ATTR_WDEV]) | |
1651 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1652 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1653 | struct net_device *netdev; | |
1654 | struct cfg80211_registered_device *rdev; | |
1655 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1656 | ||
7f2b8562 | 1657 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1658 | if (!netdev) |
1659 | return -ENODEV; | |
1660 | if (netdev->ieee80211_ptr) { | |
1661 | rdev = wiphy_to_dev( | |
1662 | netdev->ieee80211_ptr->wiphy); | |
1663 | state->filter_wiphy = rdev->wiphy_idx; | |
1664 | } | |
86e8cf98 JB |
1665 | } |
1666 | ||
1667 | return 0; | |
1668 | } | |
1669 | ||
55682965 JB |
1670 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1671 | { | |
645e77de | 1672 | int idx = 0, ret; |
86e8cf98 | 1673 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
55682965 | 1674 | struct cfg80211_registered_device *dev; |
3a5a423b | 1675 | |
5fe231e8 | 1676 | rtnl_lock(); |
86e8cf98 JB |
1677 | if (!state) { |
1678 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1679 | if (!state) { |
1680 | rtnl_unlock(); | |
86e8cf98 | 1681 | return -ENOMEM; |
3713b4e3 | 1682 | } |
86e8cf98 JB |
1683 | state->filter_wiphy = -1; |
1684 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1685 | if (ret) { | |
1686 | kfree(state); | |
1687 | rtnl_unlock(); | |
1688 | return ret; | |
3713b4e3 | 1689 | } |
86e8cf98 | 1690 | cb->args[0] = (long)state; |
3713b4e3 JB |
1691 | } |
1692 | ||
79c97e97 | 1693 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1694 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1695 | continue; | |
86e8cf98 | 1696 | if (++idx <= state->start) |
55682965 | 1697 | continue; |
86e8cf98 JB |
1698 | if (state->filter_wiphy != -1 && |
1699 | state->filter_wiphy != dev->wiphy_idx) | |
3713b4e3 JB |
1700 | continue; |
1701 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1702 | do { | |
1703 | ret = nl80211_send_wiphy(dev, skb, | |
1704 | NETLINK_CB(cb->skb).portid, | |
1705 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1706 | NLM_F_MULTI, state); |
3713b4e3 JB |
1707 | if (ret < 0) { |
1708 | /* | |
1709 | * If sending the wiphy data didn't fit (ENOBUFS | |
1710 | * or EMSGSIZE returned), this SKB is still | |
1711 | * empty (so it's not too big because another | |
1712 | * wiphy dataset is already in the skb) and | |
1713 | * we've not tried to adjust the dump allocation | |
1714 | * yet ... then adjust the alloc size to be | |
1715 | * bigger, and return 1 but with the empty skb. | |
1716 | * This results in an empty message being RX'ed | |
1717 | * in userspace, but that is ignored. | |
1718 | * | |
1719 | * We can then retry with the larger buffer. | |
1720 | */ | |
1721 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1722 | !skb->len && !state->split && |
3713b4e3 JB |
1723 | cb->min_dump_alloc < 4096) { |
1724 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1725 | state->split_start = 0; |
d98cae64 | 1726 | rtnl_unlock(); |
3713b4e3 JB |
1727 | return 1; |
1728 | } | |
1729 | idx--; | |
1730 | break; | |
645e77de | 1731 | } |
86e8cf98 | 1732 | } while (state->split_start > 0); |
3713b4e3 | 1733 | break; |
55682965 | 1734 | } |
5fe231e8 | 1735 | rtnl_unlock(); |
55682965 | 1736 | |
86e8cf98 | 1737 | state->start = idx; |
55682965 JB |
1738 | |
1739 | return skb->len; | |
1740 | } | |
1741 | ||
86e8cf98 JB |
1742 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1743 | { | |
1744 | kfree((void *)cb->args[0]); | |
1745 | return 0; | |
1746 | } | |
1747 | ||
55682965 JB |
1748 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1749 | { | |
1750 | struct sk_buff *msg; | |
4c476991 | 1751 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
86e8cf98 | 1752 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1753 | |
645e77de | 1754 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1755 | if (!msg) |
4c476991 | 1756 | return -ENOMEM; |
55682965 | 1757 | |
3713b4e3 | 1758 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
86e8cf98 | 1759 | &state) < 0) { |
4c476991 JB |
1760 | nlmsg_free(msg); |
1761 | return -ENOBUFS; | |
1762 | } | |
55682965 | 1763 | |
134e6375 | 1764 | return genlmsg_reply(msg, info); |
55682965 JB |
1765 | } |
1766 | ||
31888487 JM |
1767 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1768 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1769 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1770 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1771 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1772 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1773 | }; | |
1774 | ||
1775 | static int parse_txq_params(struct nlattr *tb[], | |
1776 | struct ieee80211_txq_params *txq_params) | |
1777 | { | |
a3304b0a | 1778 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1779 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1780 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1781 | return -EINVAL; | |
1782 | ||
a3304b0a | 1783 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1784 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1785 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1786 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1787 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1788 | ||
a3304b0a JB |
1789 | if (txq_params->ac >= NL80211_NUM_ACS) |
1790 | return -EINVAL; | |
1791 | ||
31888487 JM |
1792 | return 0; |
1793 | } | |
1794 | ||
f444de05 JB |
1795 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1796 | { | |
1797 | /* | |
cc1d2806 JB |
1798 | * You can only set the channel explicitly for WDS interfaces, |
1799 | * all others have their channel managed via their respective | |
1800 | * "establish a connection" command (connect, join, ...) | |
1801 | * | |
1802 | * For AP/GO and mesh mode, the channel can be set with the | |
1803 | * channel userspace API, but is only stored and passed to the | |
1804 | * low-level driver when the AP starts or the mesh is joined. | |
1805 | * This is for backward compatibility, userspace can also give | |
1806 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1807 | * |
1808 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1809 | * whatever else is going on, so they have their own special |
1810 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1811 | */ |
1812 | return !wdev || | |
1813 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1814 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1815 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1816 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1817 | } |
1818 | ||
683b6d3b JB |
1819 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1820 | struct genl_info *info, | |
1821 | struct cfg80211_chan_def *chandef) | |
1822 | { | |
dbeca2ea | 1823 | u32 control_freq; |
683b6d3b JB |
1824 | |
1825 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1826 | return -EINVAL; | |
1827 | ||
1828 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1829 | ||
1830 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1831 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1832 | chandef->center_freq1 = control_freq; | |
1833 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1834 | |
1835 | /* Primary channel not allowed */ | |
1836 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1837 | return -EINVAL; | |
1838 | ||
3d9d1d66 JB |
1839 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1840 | enum nl80211_channel_type chantype; | |
1841 | ||
1842 | chantype = nla_get_u32( | |
1843 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1844 | ||
1845 | switch (chantype) { | |
1846 | case NL80211_CHAN_NO_HT: | |
1847 | case NL80211_CHAN_HT20: | |
1848 | case NL80211_CHAN_HT40PLUS: | |
1849 | case NL80211_CHAN_HT40MINUS: | |
1850 | cfg80211_chandef_create(chandef, chandef->chan, | |
1851 | chantype); | |
1852 | break; | |
1853 | default: | |
1854 | return -EINVAL; | |
1855 | } | |
1856 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1857 | chandef->width = | |
1858 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1859 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1860 | chandef->center_freq1 = | |
1861 | nla_get_u32( | |
1862 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1863 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1864 | chandef->center_freq2 = | |
1865 | nla_get_u32( | |
1866 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1867 | } | |
1868 | ||
9f5e8f6e | 1869 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1870 | return -EINVAL; |
1871 | ||
9f5e8f6e JB |
1872 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1873 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1874 | return -EINVAL; |
1875 | ||
2f301ab2 SW |
1876 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1877 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1878 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1879 | return -EINVAL; | |
1880 | ||
683b6d3b JB |
1881 | return 0; |
1882 | } | |
1883 | ||
f444de05 JB |
1884 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1885 | struct wireless_dev *wdev, | |
1886 | struct genl_info *info) | |
1887 | { | |
683b6d3b | 1888 | struct cfg80211_chan_def chandef; |
f444de05 | 1889 | int result; |
e8c9bd5b JB |
1890 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1891 | ||
1892 | if (wdev) | |
1893 | iftype = wdev->iftype; | |
f444de05 | 1894 | |
f444de05 JB |
1895 | if (!nl80211_can_set_dev_channel(wdev)) |
1896 | return -EOPNOTSUPP; | |
1897 | ||
683b6d3b JB |
1898 | result = nl80211_parse_chandef(rdev, info, &chandef); |
1899 | if (result) | |
1900 | return result; | |
f444de05 | 1901 | |
e8c9bd5b | 1902 | switch (iftype) { |
aa430da4 JB |
1903 | case NL80211_IFTYPE_AP: |
1904 | case NL80211_IFTYPE_P2P_GO: | |
1905 | if (wdev->beacon_interval) { | |
1906 | result = -EBUSY; | |
1907 | break; | |
1908 | } | |
683b6d3b | 1909 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
aa430da4 JB |
1910 | result = -EINVAL; |
1911 | break; | |
1912 | } | |
683b6d3b | 1913 | wdev->preset_chandef = chandef; |
aa430da4 JB |
1914 | result = 0; |
1915 | break; | |
cc1d2806 | 1916 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 1917 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 1918 | break; |
e8c9bd5b | 1919 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 1920 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 1921 | break; |
aa430da4 | 1922 | default: |
e8c9bd5b | 1923 | result = -EINVAL; |
f444de05 | 1924 | } |
f444de05 JB |
1925 | |
1926 | return result; | |
1927 | } | |
1928 | ||
1929 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1930 | { | |
4c476991 JB |
1931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1932 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1933 | |
4c476991 | 1934 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1935 | } |
1936 | ||
e8347eba BJ |
1937 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1938 | { | |
43b19952 JB |
1939 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1940 | struct net_device *dev = info->user_ptr[1]; | |
1941 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1942 | const u8 *bssid; |
e8347eba BJ |
1943 | |
1944 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1945 | return -EINVAL; | |
1946 | ||
43b19952 JB |
1947 | if (netif_running(dev)) |
1948 | return -EBUSY; | |
e8347eba | 1949 | |
43b19952 JB |
1950 | if (!rdev->ops->set_wds_peer) |
1951 | return -EOPNOTSUPP; | |
e8347eba | 1952 | |
43b19952 JB |
1953 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1954 | return -EOPNOTSUPP; | |
e8347eba BJ |
1955 | |
1956 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 1957 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
1958 | } |
1959 | ||
1960 | ||
55682965 JB |
1961 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1962 | { | |
1963 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1964 | struct net_device *netdev = NULL; |
1965 | struct wireless_dev *wdev; | |
a1e567c8 | 1966 | int result = 0, rem_txq_params = 0; |
31888487 | 1967 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1968 | u32 changed; |
1969 | u8 retry_short = 0, retry_long = 0; | |
1970 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1971 | u8 coverage_class = 0; |
55682965 | 1972 | |
5fe231e8 JB |
1973 | ASSERT_RTNL(); |
1974 | ||
f444de05 JB |
1975 | /* |
1976 | * Try to find the wiphy and netdev. Normally this | |
1977 | * function shouldn't need the netdev, but this is | |
1978 | * done for backward compatibility -- previously | |
1979 | * setting the channel was done per wiphy, but now | |
1980 | * it is per netdev. Previous userland like hostapd | |
1981 | * also passed a netdev to set_wiphy, so that it is | |
1982 | * possible to let that go to the right netdev! | |
1983 | */ | |
4bbf4d56 | 1984 | |
f444de05 JB |
1985 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1986 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1987 | ||
7f2b8562 | 1988 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 1989 | if (netdev && netdev->ieee80211_ptr) |
f444de05 | 1990 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 1991 | else |
f444de05 | 1992 | netdev = NULL; |
4bbf4d56 JB |
1993 | } |
1994 | ||
f444de05 | 1995 | if (!netdev) { |
878d9ec7 JB |
1996 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1997 | info->attrs); | |
5fe231e8 | 1998 | if (IS_ERR(rdev)) |
4c476991 | 1999 | return PTR_ERR(rdev); |
f444de05 JB |
2000 | wdev = NULL; |
2001 | netdev = NULL; | |
2002 | result = 0; | |
71fe96bf | 2003 | } else |
f444de05 | 2004 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2005 | |
2006 | /* | |
2007 | * end workaround code, by now the rdev is available | |
2008 | * and locked, and wdev may or may not be NULL. | |
2009 | */ | |
4bbf4d56 JB |
2010 | |
2011 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2012 | result = cfg80211_dev_rename( |
2013 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2014 | |
4bbf4d56 | 2015 | if (result) |
7f2b8562 | 2016 | return result; |
31888487 JM |
2017 | |
2018 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2019 | struct ieee80211_txq_params txq_params; | |
2020 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2021 | ||
7f2b8562 YX |
2022 | if (!rdev->ops->set_txq_params) |
2023 | return -EOPNOTSUPP; | |
31888487 | 2024 | |
7f2b8562 YX |
2025 | if (!netdev) |
2026 | return -EINVAL; | |
f70f01c2 | 2027 | |
133a3ff2 | 2028 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2029 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2030 | return -EINVAL; | |
133a3ff2 | 2031 | |
7f2b8562 YX |
2032 | if (!netif_running(netdev)) |
2033 | return -ENETDOWN; | |
2b5f8b0b | 2034 | |
31888487 JM |
2035 | nla_for_each_nested(nl_txq_params, |
2036 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2037 | rem_txq_params) { | |
2038 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
2039 | nla_data(nl_txq_params), | |
2040 | nla_len(nl_txq_params), | |
2041 | txq_params_policy); | |
2042 | result = parse_txq_params(tb, &txq_params); | |
2043 | if (result) | |
7f2b8562 | 2044 | return result; |
31888487 | 2045 | |
e35e4d28 HG |
2046 | result = rdev_set_txq_params(rdev, netdev, |
2047 | &txq_params); | |
31888487 | 2048 | if (result) |
7f2b8562 | 2049 | return result; |
31888487 JM |
2050 | } |
2051 | } | |
55682965 | 2052 | |
72bdcf34 | 2053 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
71fe96bf JB |
2054 | result = __nl80211_set_channel(rdev, |
2055 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, | |
2056 | info); | |
72bdcf34 | 2057 | if (result) |
7f2b8562 | 2058 | return result; |
72bdcf34 JM |
2059 | } |
2060 | ||
98d2ff8b | 2061 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2062 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2063 | enum nl80211_tx_power_setting type; |
2064 | int idx, mbm = 0; | |
2065 | ||
c8442118 JB |
2066 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2067 | txp_wdev = NULL; | |
2068 | ||
7f2b8562 YX |
2069 | if (!rdev->ops->set_tx_power) |
2070 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2071 | |
2072 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2073 | type = nla_get_u32(info->attrs[idx]); | |
2074 | ||
2075 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2076 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2077 | return -EINVAL; | |
98d2ff8b JO |
2078 | |
2079 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2080 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2081 | mbm = nla_get_u32(info->attrs[idx]); | |
2082 | } | |
2083 | ||
c8442118 | 2084 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2085 | if (result) |
7f2b8562 | 2086 | return result; |
98d2ff8b JO |
2087 | } |
2088 | ||
afe0cbf8 BR |
2089 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2090 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2091 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2092 | if ((!rdev->wiphy.available_antennas_tx && |
2093 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2094 | !rdev->ops->set_antenna) |
2095 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2096 | |
2097 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2098 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2099 | ||
a7ffac95 | 2100 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2101 | * available antenna masks, except for the "all" mask */ |
2102 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2103 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2104 | return -EINVAL; | |
a7ffac95 | 2105 | |
7f531e03 BR |
2106 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2107 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2108 | |
e35e4d28 | 2109 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2110 | if (result) |
7f2b8562 | 2111 | return result; |
afe0cbf8 BR |
2112 | } |
2113 | ||
b9a5f8ca JM |
2114 | changed = 0; |
2115 | ||
2116 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2117 | retry_short = nla_get_u8( | |
2118 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2119 | if (retry_short == 0) |
2120 | return -EINVAL; | |
2121 | ||
b9a5f8ca JM |
2122 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2123 | } | |
2124 | ||
2125 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2126 | retry_long = nla_get_u8( | |
2127 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2128 | if (retry_long == 0) |
2129 | return -EINVAL; | |
2130 | ||
b9a5f8ca JM |
2131 | changed |= WIPHY_PARAM_RETRY_LONG; |
2132 | } | |
2133 | ||
2134 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2135 | frag_threshold = nla_get_u32( | |
2136 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2137 | if (frag_threshold < 256) |
2138 | return -EINVAL; | |
2139 | ||
b9a5f8ca JM |
2140 | if (frag_threshold != (u32) -1) { |
2141 | /* | |
2142 | * Fragments (apart from the last one) are required to | |
2143 | * have even length. Make the fragmentation code | |
2144 | * simpler by stripping LSB should someone try to use | |
2145 | * odd threshold value. | |
2146 | */ | |
2147 | frag_threshold &= ~0x1; | |
2148 | } | |
2149 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2150 | } | |
2151 | ||
2152 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2153 | rts_threshold = nla_get_u32( | |
2154 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2155 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2156 | } | |
2157 | ||
81077e82 LT |
2158 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
2159 | coverage_class = nla_get_u8( | |
2160 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2161 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2162 | } | |
2163 | ||
b9a5f8ca JM |
2164 | if (changed) { |
2165 | u8 old_retry_short, old_retry_long; | |
2166 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2167 | u8 old_coverage_class; |
b9a5f8ca | 2168 | |
7f2b8562 YX |
2169 | if (!rdev->ops->set_wiphy_params) |
2170 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2171 | |
2172 | old_retry_short = rdev->wiphy.retry_short; | |
2173 | old_retry_long = rdev->wiphy.retry_long; | |
2174 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2175 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2176 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2177 | |
2178 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2179 | rdev->wiphy.retry_short = retry_short; | |
2180 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2181 | rdev->wiphy.retry_long = retry_long; | |
2182 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2183 | rdev->wiphy.frag_threshold = frag_threshold; | |
2184 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2185 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2186 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2187 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2188 | |
e35e4d28 | 2189 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2190 | if (result) { |
2191 | rdev->wiphy.retry_short = old_retry_short; | |
2192 | rdev->wiphy.retry_long = old_retry_long; | |
2193 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2194 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2195 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2196 | } |
2197 | } | |
7f2b8562 | 2198 | return 0; |
55682965 JB |
2199 | } |
2200 | ||
71bbc994 JB |
2201 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2202 | { | |
2203 | return (u64)wdev->identifier | | |
2204 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); | |
2205 | } | |
55682965 | 2206 | |
683b6d3b | 2207 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2208 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2209 | { |
9f5e8f6e | 2210 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
3d9d1d66 | 2211 | |
683b6d3b JB |
2212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2213 | chandef->chan->center_freq)) | |
2214 | return -ENOBUFS; | |
3d9d1d66 JB |
2215 | switch (chandef->width) { |
2216 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2217 | case NL80211_CHAN_WIDTH_20: | |
2218 | case NL80211_CHAN_WIDTH_40: | |
2219 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2220 | cfg80211_get_chandef_type(chandef))) | |
2221 | return -ENOBUFS; | |
2222 | break; | |
2223 | default: | |
2224 | break; | |
2225 | } | |
2226 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2227 | return -ENOBUFS; | |
2228 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2229 | return -ENOBUFS; | |
2230 | if (chandef->center_freq2 && | |
2231 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2232 | return -ENOBUFS; |
2233 | return 0; | |
2234 | } | |
2235 | ||
15e47304 | 2236 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2237 | struct cfg80211_registered_device *rdev, |
72fb2abc | 2238 | struct wireless_dev *wdev) |
55682965 | 2239 | { |
72fb2abc | 2240 | struct net_device *dev = wdev->netdev; |
55682965 JB |
2241 | void *hdr; |
2242 | ||
15e47304 | 2243 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
55682965 JB |
2244 | if (!hdr) |
2245 | return -1; | |
2246 | ||
72fb2abc JB |
2247 | if (dev && |
2248 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2249 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2250 | goto nla_put_failure; |
2251 | ||
2252 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2253 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2254 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2255 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2256 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2257 | rdev->devlist_generation ^ | |
2258 | (cfg80211_rdev_list_generation << 2))) | |
2259 | goto nla_put_failure; | |
f5ea9120 | 2260 | |
5b7ccaf3 | 2261 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2262 | int ret; |
2263 | struct cfg80211_chan_def chandef; | |
2264 | ||
2265 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2266 | if (ret == 0) { | |
2267 | if (nl80211_send_chandef(msg, &chandef)) | |
2268 | goto nla_put_failure; | |
2269 | } | |
d91df0e3 PF |
2270 | } |
2271 | ||
b84e7a05 AQ |
2272 | if (wdev->ssid_len) { |
2273 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2274 | goto nla_put_failure; | |
2275 | } | |
2276 | ||
55682965 JB |
2277 | return genlmsg_end(msg, hdr); |
2278 | ||
2279 | nla_put_failure: | |
bc3ed28c TG |
2280 | genlmsg_cancel(msg, hdr); |
2281 | return -EMSGSIZE; | |
55682965 JB |
2282 | } |
2283 | ||
2284 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2285 | { | |
2286 | int wp_idx = 0; | |
2287 | int if_idx = 0; | |
2288 | int wp_start = cb->args[0]; | |
2289 | int if_start = cb->args[1]; | |
f5ea9120 | 2290 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2291 | struct wireless_dev *wdev; |
2292 | ||
5fe231e8 | 2293 | rtnl_lock(); |
f5ea9120 JB |
2294 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2295 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2296 | continue; |
bba95fef JB |
2297 | if (wp_idx < wp_start) { |
2298 | wp_idx++; | |
55682965 | 2299 | continue; |
bba95fef | 2300 | } |
55682965 JB |
2301 | if_idx = 0; |
2302 | ||
89a54e48 | 2303 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2304 | if (if_idx < if_start) { |
2305 | if_idx++; | |
55682965 | 2306 | continue; |
bba95fef | 2307 | } |
15e47304 | 2308 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2309 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
72fb2abc | 2310 | rdev, wdev) < 0) { |
bba95fef JB |
2311 | goto out; |
2312 | } | |
2313 | if_idx++; | |
55682965 | 2314 | } |
bba95fef JB |
2315 | |
2316 | wp_idx++; | |
55682965 | 2317 | } |
bba95fef | 2318 | out: |
5fe231e8 | 2319 | rtnl_unlock(); |
55682965 JB |
2320 | |
2321 | cb->args[0] = wp_idx; | |
2322 | cb->args[1] = if_idx; | |
2323 | ||
2324 | return skb->len; | |
2325 | } | |
2326 | ||
2327 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2328 | { | |
2329 | struct sk_buff *msg; | |
4c476991 | 2330 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
72fb2abc | 2331 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2332 | |
fd2120ca | 2333 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2334 | if (!msg) |
4c476991 | 2335 | return -ENOMEM; |
55682965 | 2336 | |
15e47304 | 2337 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
72fb2abc | 2338 | dev, wdev) < 0) { |
4c476991 JB |
2339 | nlmsg_free(msg); |
2340 | return -ENOBUFS; | |
2341 | } | |
55682965 | 2342 | |
134e6375 | 2343 | return genlmsg_reply(msg, info); |
55682965 JB |
2344 | } |
2345 | ||
66f7ac50 MW |
2346 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2347 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2348 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2349 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2350 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2351 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2352 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2353 | }; |
2354 | ||
2355 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2356 | { | |
2357 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2358 | int flag; | |
2359 | ||
2360 | *mntrflags = 0; | |
2361 | ||
2362 | if (!nla) | |
2363 | return -EINVAL; | |
2364 | ||
2365 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2366 | nla, mntr_flags_policy)) | |
2367 | return -EINVAL; | |
2368 | ||
2369 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2370 | if (flags[flag]) | |
2371 | *mntrflags |= (1<<flag); | |
2372 | ||
2373 | return 0; | |
2374 | } | |
2375 | ||
9bc383de | 2376 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2377 | struct net_device *netdev, u8 use_4addr, |
2378 | enum nl80211_iftype iftype) | |
9bc383de | 2379 | { |
ad4bb6f8 | 2380 | if (!use_4addr) { |
f350a0a8 | 2381 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2382 | return -EBUSY; |
9bc383de | 2383 | return 0; |
ad4bb6f8 | 2384 | } |
9bc383de JB |
2385 | |
2386 | switch (iftype) { | |
2387 | case NL80211_IFTYPE_AP_VLAN: | |
2388 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2389 | return 0; | |
2390 | break; | |
2391 | case NL80211_IFTYPE_STATION: | |
2392 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2393 | return 0; | |
2394 | break; | |
2395 | default: | |
2396 | break; | |
2397 | } | |
2398 | ||
2399 | return -EOPNOTSUPP; | |
2400 | } | |
2401 | ||
55682965 JB |
2402 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2403 | { | |
4c476991 | 2404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2405 | struct vif_params params; |
e36d56b6 | 2406 | int err; |
04a773ad | 2407 | enum nl80211_iftype otype, ntype; |
4c476991 | 2408 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2409 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2410 | bool change = false; |
55682965 | 2411 | |
2ec600d6 LCC |
2412 | memset(¶ms, 0, sizeof(params)); |
2413 | ||
04a773ad | 2414 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2415 | |
723b038d | 2416 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2417 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2418 | if (otype != ntype) |
ac7f9cfa | 2419 | change = true; |
4c476991 JB |
2420 | if (ntype > NL80211_IFTYPE_MAX) |
2421 | return -EINVAL; | |
723b038d JB |
2422 | } |
2423 | ||
92ffe055 | 2424 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2425 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2426 | ||
4c476991 JB |
2427 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2428 | return -EINVAL; | |
29cbe68c JB |
2429 | if (netif_running(dev)) |
2430 | return -EBUSY; | |
2431 | ||
2432 | wdev_lock(wdev); | |
2433 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2434 | IEEE80211_MAX_MESH_ID_LEN); | |
2435 | wdev->mesh_id_up_len = | |
2436 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2437 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2438 | wdev->mesh_id_up_len); | |
2439 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2440 | } |
2441 | ||
8b787643 FF |
2442 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2443 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2444 | change = true; | |
ad4bb6f8 | 2445 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2446 | if (err) |
4c476991 | 2447 | return err; |
8b787643 FF |
2448 | } else { |
2449 | params.use_4addr = -1; | |
2450 | } | |
2451 | ||
92ffe055 | 2452 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2453 | if (ntype != NL80211_IFTYPE_MONITOR) |
2454 | return -EINVAL; | |
92ffe055 JB |
2455 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2456 | &_flags); | |
ac7f9cfa | 2457 | if (err) |
4c476991 | 2458 | return err; |
ac7f9cfa JB |
2459 | |
2460 | flags = &_flags; | |
2461 | change = true; | |
92ffe055 | 2462 | } |
3b85875a | 2463 | |
18003297 | 2464 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2465 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2466 | return -EOPNOTSUPP; | |
2467 | ||
ac7f9cfa | 2468 | if (change) |
3d54d255 | 2469 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2470 | else |
2471 | err = 0; | |
60719ffd | 2472 | |
9bc383de JB |
2473 | if (!err && params.use_4addr != -1) |
2474 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2475 | ||
55682965 JB |
2476 | return err; |
2477 | } | |
2478 | ||
2479 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2480 | { | |
4c476991 | 2481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2482 | struct vif_params params; |
84efbb84 | 2483 | struct wireless_dev *wdev; |
1c90f9d4 | 2484 | struct sk_buff *msg; |
55682965 JB |
2485 | int err; |
2486 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2487 | u32 flags; |
55682965 | 2488 | |
2ec600d6 LCC |
2489 | memset(¶ms, 0, sizeof(params)); |
2490 | ||
55682965 JB |
2491 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2492 | return -EINVAL; | |
2493 | ||
2494 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2495 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2496 | if (type > NL80211_IFTYPE_MAX) | |
2497 | return -EINVAL; | |
2498 | } | |
2499 | ||
79c97e97 | 2500 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2501 | !(rdev->wiphy.interface_modes & (1 << type))) |
2502 | return -EOPNOTSUPP; | |
55682965 | 2503 | |
1c18f145 AS |
2504 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
2505 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], | |
2506 | ETH_ALEN); | |
2507 | if (!is_valid_ether_addr(params.macaddr)) | |
2508 | return -EADDRNOTAVAIL; | |
2509 | } | |
2510 | ||
9bc383de | 2511 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2512 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2513 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2514 | if (err) |
4c476991 | 2515 | return err; |
9bc383de | 2516 | } |
8b787643 | 2517 | |
1c90f9d4 JB |
2518 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2519 | if (!msg) | |
2520 | return -ENOMEM; | |
2521 | ||
66f7ac50 MW |
2522 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2523 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2524 | &flags); | |
e057d3c3 | 2525 | |
18003297 | 2526 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2527 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2528 | return -EOPNOTSUPP; | |
2529 | ||
e35e4d28 HG |
2530 | wdev = rdev_add_virtual_intf(rdev, |
2531 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2532 | type, err ? NULL : &flags, ¶ms); | |
1c90f9d4 JB |
2533 | if (IS_ERR(wdev)) { |
2534 | nlmsg_free(msg); | |
84efbb84 | 2535 | return PTR_ERR(wdev); |
1c90f9d4 | 2536 | } |
2ec600d6 | 2537 | |
98104fde JB |
2538 | switch (type) { |
2539 | case NL80211_IFTYPE_MESH_POINT: | |
2540 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2541 | break; | |
29cbe68c JB |
2542 | wdev_lock(wdev); |
2543 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2544 | IEEE80211_MAX_MESH_ID_LEN); | |
2545 | wdev->mesh_id_up_len = | |
2546 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2547 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2548 | wdev->mesh_id_up_len); | |
2549 | wdev_unlock(wdev); | |
98104fde JB |
2550 | break; |
2551 | case NL80211_IFTYPE_P2P_DEVICE: | |
2552 | /* | |
2553 | * P2P Device doesn't have a netdev, so doesn't go | |
2554 | * through the netdev notifier and must be added here | |
2555 | */ | |
2556 | mutex_init(&wdev->mtx); | |
2557 | INIT_LIST_HEAD(&wdev->event_list); | |
2558 | spin_lock_init(&wdev->event_lock); | |
2559 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2560 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2561 | ||
98104fde JB |
2562 | wdev->identifier = ++rdev->wdev_id; |
2563 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2564 | rdev->devlist_generation++; | |
98104fde JB |
2565 | break; |
2566 | default: | |
2567 | break; | |
29cbe68c JB |
2568 | } |
2569 | ||
15e47304 | 2570 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
1c90f9d4 JB |
2571 | rdev, wdev) < 0) { |
2572 | nlmsg_free(msg); | |
2573 | return -ENOBUFS; | |
2574 | } | |
2575 | ||
2576 | return genlmsg_reply(msg, info); | |
55682965 JB |
2577 | } |
2578 | ||
2579 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2580 | { | |
4c476991 | 2581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2582 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2583 | |
4c476991 JB |
2584 | if (!rdev->ops->del_virtual_intf) |
2585 | return -EOPNOTSUPP; | |
55682965 | 2586 | |
84efbb84 JB |
2587 | /* |
2588 | * If we remove a wireless device without a netdev then clear | |
2589 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2590 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2591 | * since the wdev has been freed, unlike with a netdev where | |
2592 | * we need the dev_put() for the netdev to really be freed. | |
2593 | */ | |
2594 | if (!wdev->netdev) | |
2595 | info->user_ptr[1] = NULL; | |
2596 | ||
e35e4d28 | 2597 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2598 | } |
2599 | ||
1d9d9213 SW |
2600 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2601 | { | |
2602 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2603 | struct net_device *dev = info->user_ptr[1]; | |
2604 | u16 noack_map; | |
2605 | ||
2606 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2607 | return -EINVAL; | |
2608 | ||
2609 | if (!rdev->ops->set_noack_map) | |
2610 | return -EOPNOTSUPP; | |
2611 | ||
2612 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2613 | ||
e35e4d28 | 2614 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2615 | } |
2616 | ||
41ade00f JB |
2617 | struct get_key_cookie { |
2618 | struct sk_buff *msg; | |
2619 | int error; | |
b9454e83 | 2620 | int idx; |
41ade00f JB |
2621 | }; |
2622 | ||
2623 | static void get_key_callback(void *c, struct key_params *params) | |
2624 | { | |
b9454e83 | 2625 | struct nlattr *key; |
41ade00f JB |
2626 | struct get_key_cookie *cookie = c; |
2627 | ||
9360ffd1 DM |
2628 | if ((params->key && |
2629 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2630 | params->key_len, params->key)) || | |
2631 | (params->seq && | |
2632 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2633 | params->seq_len, params->seq)) || | |
2634 | (params->cipher && | |
2635 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2636 | params->cipher))) | |
2637 | goto nla_put_failure; | |
41ade00f | 2638 | |
b9454e83 JB |
2639 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2640 | if (!key) | |
2641 | goto nla_put_failure; | |
2642 | ||
9360ffd1 DM |
2643 | if ((params->key && |
2644 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2645 | params->key_len, params->key)) || | |
2646 | (params->seq && | |
2647 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2648 | params->seq_len, params->seq)) || | |
2649 | (params->cipher && | |
2650 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2651 | params->cipher))) | |
2652 | goto nla_put_failure; | |
b9454e83 | 2653 | |
9360ffd1 DM |
2654 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2655 | goto nla_put_failure; | |
b9454e83 JB |
2656 | |
2657 | nla_nest_end(cookie->msg, key); | |
2658 | ||
41ade00f JB |
2659 | return; |
2660 | nla_put_failure: | |
2661 | cookie->error = 1; | |
2662 | } | |
2663 | ||
2664 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2665 | { | |
4c476991 | 2666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2667 | int err; |
4c476991 | 2668 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2669 | u8 key_idx = 0; |
e31b8213 JB |
2670 | const u8 *mac_addr = NULL; |
2671 | bool pairwise; | |
41ade00f JB |
2672 | struct get_key_cookie cookie = { |
2673 | .error = 0, | |
2674 | }; | |
2675 | void *hdr; | |
2676 | struct sk_buff *msg; | |
2677 | ||
2678 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2679 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2680 | ||
3cfcf6ac | 2681 | if (key_idx > 5) |
41ade00f JB |
2682 | return -EINVAL; |
2683 | ||
2684 | if (info->attrs[NL80211_ATTR_MAC]) | |
2685 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2686 | ||
e31b8213 JB |
2687 | pairwise = !!mac_addr; |
2688 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2689 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2690 | if (kt >= NUM_NL80211_KEYTYPES) | |
2691 | return -EINVAL; | |
2692 | if (kt != NL80211_KEYTYPE_GROUP && | |
2693 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2694 | return -EINVAL; | |
2695 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2696 | } | |
2697 | ||
4c476991 JB |
2698 | if (!rdev->ops->get_key) |
2699 | return -EOPNOTSUPP; | |
41ade00f | 2700 | |
fd2120ca | 2701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2702 | if (!msg) |
2703 | return -ENOMEM; | |
41ade00f | 2704 | |
15e47304 | 2705 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2706 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2707 | if (!hdr) |
9fe271af | 2708 | goto nla_put_failure; |
41ade00f JB |
2709 | |
2710 | cookie.msg = msg; | |
b9454e83 | 2711 | cookie.idx = key_idx; |
41ade00f | 2712 | |
9360ffd1 DM |
2713 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2714 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2715 | goto nla_put_failure; | |
2716 | if (mac_addr && | |
2717 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2718 | goto nla_put_failure; | |
41ade00f | 2719 | |
e31b8213 JB |
2720 | if (pairwise && mac_addr && |
2721 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2722 | return -ENOENT; | |
2723 | ||
e35e4d28 HG |
2724 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2725 | get_key_callback); | |
41ade00f JB |
2726 | |
2727 | if (err) | |
6c95e2a2 | 2728 | goto free_msg; |
41ade00f JB |
2729 | |
2730 | if (cookie.error) | |
2731 | goto nla_put_failure; | |
2732 | ||
2733 | genlmsg_end(msg, hdr); | |
4c476991 | 2734 | return genlmsg_reply(msg, info); |
41ade00f JB |
2735 | |
2736 | nla_put_failure: | |
2737 | err = -ENOBUFS; | |
6c95e2a2 | 2738 | free_msg: |
41ade00f | 2739 | nlmsg_free(msg); |
41ade00f JB |
2740 | return err; |
2741 | } | |
2742 | ||
2743 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2744 | { | |
4c476991 | 2745 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2746 | struct key_parse key; |
41ade00f | 2747 | int err; |
4c476991 | 2748 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2749 | |
b9454e83 JB |
2750 | err = nl80211_parse_key(info, &key); |
2751 | if (err) | |
2752 | return err; | |
41ade00f | 2753 | |
b9454e83 | 2754 | if (key.idx < 0) |
41ade00f JB |
2755 | return -EINVAL; |
2756 | ||
b9454e83 JB |
2757 | /* only support setting default key */ |
2758 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2759 | return -EINVAL; |
2760 | ||
dbd2fd65 | 2761 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2762 | |
dbd2fd65 JB |
2763 | if (key.def) { |
2764 | if (!rdev->ops->set_default_key) { | |
2765 | err = -EOPNOTSUPP; | |
2766 | goto out; | |
2767 | } | |
41ade00f | 2768 | |
dbd2fd65 JB |
2769 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2770 | if (err) | |
2771 | goto out; | |
2772 | ||
e35e4d28 | 2773 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2774 | key.def_uni, key.def_multi); |
2775 | ||
2776 | if (err) | |
2777 | goto out; | |
fffd0934 | 2778 | |
3d23e349 | 2779 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2780 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2781 | #endif | |
2782 | } else { | |
2783 | if (key.def_uni || !key.def_multi) { | |
2784 | err = -EINVAL; | |
2785 | goto out; | |
2786 | } | |
2787 | ||
2788 | if (!rdev->ops->set_default_mgmt_key) { | |
2789 | err = -EOPNOTSUPP; | |
2790 | goto out; | |
2791 | } | |
2792 | ||
2793 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2794 | if (err) | |
2795 | goto out; | |
2796 | ||
e35e4d28 | 2797 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2798 | if (err) |
2799 | goto out; | |
2800 | ||
2801 | #ifdef CONFIG_CFG80211_WEXT | |
2802 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2803 | #endif |
dbd2fd65 JB |
2804 | } |
2805 | ||
2806 | out: | |
fffd0934 | 2807 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2808 | |
41ade00f JB |
2809 | return err; |
2810 | } | |
2811 | ||
2812 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2813 | { | |
4c476991 | 2814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2815 | int err; |
4c476991 | 2816 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2817 | struct key_parse key; |
e31b8213 | 2818 | const u8 *mac_addr = NULL; |
41ade00f | 2819 | |
b9454e83 JB |
2820 | err = nl80211_parse_key(info, &key); |
2821 | if (err) | |
2822 | return err; | |
41ade00f | 2823 | |
b9454e83 | 2824 | if (!key.p.key) |
41ade00f JB |
2825 | return -EINVAL; |
2826 | ||
41ade00f JB |
2827 | if (info->attrs[NL80211_ATTR_MAC]) |
2828 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2829 | ||
e31b8213 JB |
2830 | if (key.type == -1) { |
2831 | if (mac_addr) | |
2832 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2833 | else | |
2834 | key.type = NL80211_KEYTYPE_GROUP; | |
2835 | } | |
2836 | ||
2837 | /* for now */ | |
2838 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2839 | key.type != NL80211_KEYTYPE_GROUP) | |
2840 | return -EINVAL; | |
2841 | ||
4c476991 JB |
2842 | if (!rdev->ops->add_key) |
2843 | return -EOPNOTSUPP; | |
25e47c18 | 2844 | |
e31b8213 JB |
2845 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2846 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2847 | mac_addr)) | |
4c476991 | 2848 | return -EINVAL; |
41ade00f | 2849 | |
fffd0934 JB |
2850 | wdev_lock(dev->ieee80211_ptr); |
2851 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2852 | if (!err) | |
e35e4d28 HG |
2853 | err = rdev_add_key(rdev, dev, key.idx, |
2854 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2855 | mac_addr, &key.p); | |
fffd0934 | 2856 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2857 | |
41ade00f JB |
2858 | return err; |
2859 | } | |
2860 | ||
2861 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2862 | { | |
4c476991 | 2863 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2864 | int err; |
4c476991 | 2865 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2866 | u8 *mac_addr = NULL; |
b9454e83 | 2867 | struct key_parse key; |
41ade00f | 2868 | |
b9454e83 JB |
2869 | err = nl80211_parse_key(info, &key); |
2870 | if (err) | |
2871 | return err; | |
41ade00f JB |
2872 | |
2873 | if (info->attrs[NL80211_ATTR_MAC]) | |
2874 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2875 | ||
e31b8213 JB |
2876 | if (key.type == -1) { |
2877 | if (mac_addr) | |
2878 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2879 | else | |
2880 | key.type = NL80211_KEYTYPE_GROUP; | |
2881 | } | |
2882 | ||
2883 | /* for now */ | |
2884 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2885 | key.type != NL80211_KEYTYPE_GROUP) | |
2886 | return -EINVAL; | |
2887 | ||
4c476991 JB |
2888 | if (!rdev->ops->del_key) |
2889 | return -EOPNOTSUPP; | |
41ade00f | 2890 | |
fffd0934 JB |
2891 | wdev_lock(dev->ieee80211_ptr); |
2892 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2893 | |
2894 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2895 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2896 | err = -ENOENT; | |
2897 | ||
fffd0934 | 2898 | if (!err) |
e35e4d28 HG |
2899 | err = rdev_del_key(rdev, dev, key.idx, |
2900 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2901 | mac_addr); | |
41ade00f | 2902 | |
3d23e349 | 2903 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2904 | if (!err) { |
b9454e83 | 2905 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2906 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2907 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2908 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2909 | } | |
2910 | #endif | |
fffd0934 | 2911 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2912 | |
41ade00f JB |
2913 | return err; |
2914 | } | |
2915 | ||
77765eaf VT |
2916 | /* This function returns an error or the number of nested attributes */ |
2917 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
2918 | { | |
2919 | struct nlattr *attr; | |
2920 | int n_entries = 0, tmp; | |
2921 | ||
2922 | nla_for_each_nested(attr, nl_attr, tmp) { | |
2923 | if (nla_len(attr) != ETH_ALEN) | |
2924 | return -EINVAL; | |
2925 | ||
2926 | n_entries++; | |
2927 | } | |
2928 | ||
2929 | return n_entries; | |
2930 | } | |
2931 | ||
2932 | /* | |
2933 | * This function parses ACL information and allocates memory for ACL data. | |
2934 | * On successful return, the calling function is responsible to free the | |
2935 | * ACL buffer returned by this function. | |
2936 | */ | |
2937 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
2938 | struct genl_info *info) | |
2939 | { | |
2940 | enum nl80211_acl_policy acl_policy; | |
2941 | struct nlattr *attr; | |
2942 | struct cfg80211_acl_data *acl; | |
2943 | int i = 0, n_entries, tmp; | |
2944 | ||
2945 | if (!wiphy->max_acl_mac_addrs) | |
2946 | return ERR_PTR(-EOPNOTSUPP); | |
2947 | ||
2948 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
2949 | return ERR_PTR(-EINVAL); | |
2950 | ||
2951 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
2952 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
2953 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
2954 | return ERR_PTR(-EINVAL); | |
2955 | ||
2956 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
2957 | return ERR_PTR(-EINVAL); | |
2958 | ||
2959 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
2960 | if (n_entries < 0) | |
2961 | return ERR_PTR(n_entries); | |
2962 | ||
2963 | if (n_entries > wiphy->max_acl_mac_addrs) | |
2964 | return ERR_PTR(-ENOTSUPP); | |
2965 | ||
2966 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
2967 | GFP_KERNEL); | |
2968 | if (!acl) | |
2969 | return ERR_PTR(-ENOMEM); | |
2970 | ||
2971 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
2972 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
2973 | i++; | |
2974 | } | |
2975 | ||
2976 | acl->n_acl_entries = n_entries; | |
2977 | acl->acl_policy = acl_policy; | |
2978 | ||
2979 | return acl; | |
2980 | } | |
2981 | ||
2982 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
2983 | { | |
2984 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2985 | struct net_device *dev = info->user_ptr[1]; | |
2986 | struct cfg80211_acl_data *acl; | |
2987 | int err; | |
2988 | ||
2989 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2990 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2991 | return -EOPNOTSUPP; | |
2992 | ||
2993 | if (!dev->ieee80211_ptr->beacon_interval) | |
2994 | return -EINVAL; | |
2995 | ||
2996 | acl = parse_acl_data(&rdev->wiphy, info); | |
2997 | if (IS_ERR(acl)) | |
2998 | return PTR_ERR(acl); | |
2999 | ||
3000 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3001 | ||
3002 | kfree(acl); | |
3003 | ||
3004 | return err; | |
3005 | } | |
3006 | ||
a1193be8 | 3007 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3008 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3009 | { |
8860020e | 3010 | bool haveinfo = false; |
ed1b6cc7 | 3011 | |
a1193be8 SW |
3012 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3013 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3014 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3015 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3016 | return -EINVAL; |
3017 | ||
8860020e | 3018 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3019 | |
a1193be8 SW |
3020 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3021 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3022 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3023 | if (!bcn->head_len) |
3024 | return -EINVAL; | |
3025 | haveinfo = true; | |
ed1b6cc7 JB |
3026 | } |
3027 | ||
a1193be8 SW |
3028 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3029 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3030 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3031 | haveinfo = true; |
ed1b6cc7 JB |
3032 | } |
3033 | ||
4c476991 JB |
3034 | if (!haveinfo) |
3035 | return -EINVAL; | |
3b85875a | 3036 | |
a1193be8 SW |
3037 | if (attrs[NL80211_ATTR_IE]) { |
3038 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3039 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3040 | } |
3041 | ||
a1193be8 | 3042 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3043 | bcn->proberesp_ies = |
a1193be8 | 3044 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3045 | bcn->proberesp_ies_len = |
a1193be8 | 3046 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3047 | } |
3048 | ||
a1193be8 | 3049 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3050 | bcn->assocresp_ies = |
a1193be8 | 3051 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3052 | bcn->assocresp_ies_len = |
a1193be8 | 3053 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3054 | } |
3055 | ||
a1193be8 SW |
3056 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3057 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3058 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3059 | } |
3060 | ||
8860020e JB |
3061 | return 0; |
3062 | } | |
3063 | ||
46c1dd0c FF |
3064 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3065 | struct cfg80211_ap_settings *params) | |
3066 | { | |
3067 | struct wireless_dev *wdev; | |
3068 | bool ret = false; | |
3069 | ||
89a54e48 | 3070 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3071 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3072 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3073 | continue; | |
3074 | ||
683b6d3b | 3075 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3076 | continue; |
3077 | ||
683b6d3b | 3078 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3079 | ret = true; |
3080 | break; | |
3081 | } | |
3082 | ||
46c1dd0c FF |
3083 | return ret; |
3084 | } | |
3085 | ||
e39e5b5e JM |
3086 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3087 | enum nl80211_auth_type auth_type, | |
3088 | enum nl80211_commands cmd) | |
3089 | { | |
3090 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3091 | return false; | |
3092 | ||
3093 | switch (cmd) { | |
3094 | case NL80211_CMD_AUTHENTICATE: | |
3095 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3096 | auth_type == NL80211_AUTHTYPE_SAE) | |
3097 | return false; | |
3098 | return true; | |
3099 | case NL80211_CMD_CONNECT: | |
3100 | case NL80211_CMD_START_AP: | |
3101 | /* SAE not supported yet */ | |
3102 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3103 | return false; | |
3104 | return true; | |
3105 | default: | |
3106 | return false; | |
3107 | } | |
3108 | } | |
3109 | ||
8860020e JB |
3110 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3111 | { | |
3112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3113 | struct net_device *dev = info->user_ptr[1]; | |
3114 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3115 | struct cfg80211_ap_settings params; | |
3116 | int err; | |
04f39047 | 3117 | u8 radar_detect_width = 0; |
8860020e JB |
3118 | |
3119 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3120 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3121 | return -EOPNOTSUPP; | |
3122 | ||
3123 | if (!rdev->ops->start_ap) | |
3124 | return -EOPNOTSUPP; | |
3125 | ||
3126 | if (wdev->beacon_interval) | |
3127 | return -EALREADY; | |
3128 | ||
3129 | memset(¶ms, 0, sizeof(params)); | |
3130 | ||
3131 | /* these are required for START_AP */ | |
3132 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3133 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3134 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3135 | return -EINVAL; | |
3136 | ||
a1193be8 | 3137 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3138 | if (err) |
3139 | return err; | |
3140 | ||
3141 | params.beacon_interval = | |
3142 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3143 | params.dtim_period = | |
3144 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3145 | ||
3146 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3147 | if (err) | |
3148 | return err; | |
3149 | ||
3150 | /* | |
3151 | * In theory, some of these attributes should be required here | |
3152 | * but since they were not used when the command was originally | |
3153 | * added, keep them optional for old user space programs to let | |
3154 | * them continue to work with drivers that do not need the | |
3155 | * additional information -- drivers must check! | |
3156 | */ | |
3157 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3158 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3159 | params.ssid_len = | |
3160 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3161 | if (params.ssid_len == 0 || | |
3162 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3163 | return -EINVAL; | |
3164 | } | |
3165 | ||
3166 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3167 | params.hidden_ssid = nla_get_u32( | |
3168 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3169 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3170 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3171 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3172 | return -EINVAL; | |
3173 | } | |
3174 | ||
3175 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3176 | ||
3177 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3178 | params.auth_type = nla_get_u32( | |
3179 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3180 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3181 | NL80211_CMD_START_AP)) | |
8860020e JB |
3182 | return -EINVAL; |
3183 | } else | |
3184 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3185 | ||
3186 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3187 | NL80211_MAX_NR_CIPHER_SUITES); | |
3188 | if (err) | |
3189 | return err; | |
3190 | ||
1b658f11 VT |
3191 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3192 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3193 | return -EOPNOTSUPP; | |
3194 | params.inactivity_timeout = nla_get_u16( | |
3195 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3196 | } | |
3197 | ||
53cabad7 JB |
3198 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3199 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3200 | return -EINVAL; | |
3201 | params.p2p_ctwindow = | |
3202 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3203 | if (params.p2p_ctwindow > 127) | |
3204 | return -EINVAL; | |
3205 | if (params.p2p_ctwindow != 0 && | |
3206 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3207 | return -EINVAL; | |
3208 | } | |
3209 | ||
3210 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3211 | u8 tmp; | |
3212 | ||
3213 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3214 | return -EINVAL; | |
3215 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3216 | if (tmp > 1) | |
3217 | return -EINVAL; | |
3218 | params.p2p_opp_ps = tmp; | |
3219 | if (params.p2p_opp_ps != 0 && | |
3220 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3221 | return -EINVAL; | |
3222 | } | |
3223 | ||
aa430da4 | 3224 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3225 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3226 | if (err) | |
3227 | return err; | |
3228 | } else if (wdev->preset_chandef.chan) { | |
3229 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3230 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3231 | return -EINVAL; |
3232 | ||
683b6d3b | 3233 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
aa430da4 JB |
3234 | return -EINVAL; |
3235 | ||
04f39047 SW |
3236 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
3237 | if (err < 0) | |
3238 | return err; | |
3239 | if (err) { | |
3240 | radar_detect_width = BIT(params.chandef.width); | |
3241 | params.radar_required = true; | |
3242 | } | |
3243 | ||
04f39047 SW |
3244 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
3245 | params.chandef.chan, | |
3246 | CHAN_MODE_SHARED, | |
3247 | radar_detect_width); | |
e4e32459 MK |
3248 | if (err) |
3249 | return err; | |
3250 | ||
77765eaf VT |
3251 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3252 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3253 | if (IS_ERR(params.acl)) | |
3254 | return PTR_ERR(params.acl); | |
3255 | } | |
3256 | ||
c56589ed | 3257 | wdev_lock(wdev); |
e35e4d28 | 3258 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3259 | if (!err) { |
683b6d3b | 3260 | wdev->preset_chandef = params.chandef; |
8860020e | 3261 | wdev->beacon_interval = params.beacon_interval; |
683b6d3b | 3262 | wdev->channel = params.chandef.chan; |
06e191e2 AQ |
3263 | wdev->ssid_len = params.ssid_len; |
3264 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3265 | } |
c56589ed | 3266 | wdev_unlock(wdev); |
77765eaf VT |
3267 | |
3268 | kfree(params.acl); | |
3269 | ||
56d1893d | 3270 | return err; |
ed1b6cc7 JB |
3271 | } |
3272 | ||
8860020e JB |
3273 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3274 | { | |
3275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3276 | struct net_device *dev = info->user_ptr[1]; | |
3277 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3278 | struct cfg80211_beacon_data params; | |
3279 | int err; | |
3280 | ||
3281 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3282 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3283 | return -EOPNOTSUPP; | |
3284 | ||
3285 | if (!rdev->ops->change_beacon) | |
3286 | return -EOPNOTSUPP; | |
3287 | ||
3288 | if (!wdev->beacon_interval) | |
3289 | return -EINVAL; | |
3290 | ||
a1193be8 | 3291 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3292 | if (err) |
3293 | return err; | |
3294 | ||
c56589ed SW |
3295 | wdev_lock(wdev); |
3296 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3297 | wdev_unlock(wdev); | |
3298 | ||
3299 | return err; | |
8860020e JB |
3300 | } |
3301 | ||
3302 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3303 | { |
4c476991 JB |
3304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3305 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3306 | |
60771780 | 3307 | return cfg80211_stop_ap(rdev, dev); |
ed1b6cc7 JB |
3308 | } |
3309 | ||
5727ef1b JB |
3310 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3311 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3312 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3313 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3314 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3315 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3316 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3317 | }; |
3318 | ||
eccb8e8f | 3319 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3320 | enum nl80211_iftype iftype, |
eccb8e8f | 3321 | struct station_parameters *params) |
5727ef1b JB |
3322 | { |
3323 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3324 | struct nlattr *nla; |
5727ef1b JB |
3325 | int flag; |
3326 | ||
eccb8e8f JB |
3327 | /* |
3328 | * Try parsing the new attribute first so userspace | |
3329 | * can specify both for older kernels. | |
3330 | */ | |
3331 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3332 | if (nla) { | |
3333 | struct nl80211_sta_flag_update *sta_flags; | |
3334 | ||
3335 | sta_flags = nla_data(nla); | |
3336 | params->sta_flags_mask = sta_flags->mask; | |
3337 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3338 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3339 | if ((params->sta_flags_mask | |
3340 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3341 | return -EINVAL; | |
3342 | return 0; | |
3343 | } | |
3344 | ||
3345 | /* if present, parse the old attribute */ | |
5727ef1b | 3346 | |
eccb8e8f | 3347 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3348 | if (!nla) |
3349 | return 0; | |
3350 | ||
3351 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3352 | nla, sta_flags_policy)) | |
3353 | return -EINVAL; | |
3354 | ||
bdd3ae3d JB |
3355 | /* |
3356 | * Only allow certain flags for interface types so that | |
3357 | * other attributes are silently ignored. Remember that | |
3358 | * this is backward compatibility code with old userspace | |
3359 | * and shouldn't be hit in other cases anyway. | |
3360 | */ | |
3361 | switch (iftype) { | |
3362 | case NL80211_IFTYPE_AP: | |
3363 | case NL80211_IFTYPE_AP_VLAN: | |
3364 | case NL80211_IFTYPE_P2P_GO: | |
3365 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3366 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3367 | BIT(NL80211_STA_FLAG_WME) | | |
3368 | BIT(NL80211_STA_FLAG_MFP); | |
3369 | break; | |
3370 | case NL80211_IFTYPE_P2P_CLIENT: | |
3371 | case NL80211_IFTYPE_STATION: | |
3372 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3373 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3374 | break; | |
3375 | case NL80211_IFTYPE_MESH_POINT: | |
3376 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3377 | BIT(NL80211_STA_FLAG_MFP) | | |
3378 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3379 | default: | |
3380 | return -EINVAL; | |
3381 | } | |
5727ef1b | 3382 | |
3383b5a6 JB |
3383 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3384 | if (flags[flag]) { | |
eccb8e8f | 3385 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3386 | |
3383b5a6 JB |
3387 | /* no longer support new API additions in old API */ |
3388 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3389 | return -EINVAL; | |
3390 | } | |
3391 | } | |
3392 | ||
5727ef1b JB |
3393 | return 0; |
3394 | } | |
3395 | ||
c8dcfd8a FF |
3396 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3397 | int attr) | |
3398 | { | |
3399 | struct nlattr *rate; | |
8eb41c8d VK |
3400 | u32 bitrate; |
3401 | u16 bitrate_compat; | |
c8dcfd8a FF |
3402 | |
3403 | rate = nla_nest_start(msg, attr); | |
3404 | if (!rate) | |
db9c64cf | 3405 | return false; |
c8dcfd8a FF |
3406 | |
3407 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3408 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3409 | /* report 16-bit bitrate only if we can */ |
3410 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3411 | if (bitrate > 0 && |
3412 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3413 | return false; | |
3414 | if (bitrate_compat > 0 && | |
3415 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3416 | return false; | |
3417 | ||
3418 | if (info->flags & RATE_INFO_FLAGS_MCS) { | |
3419 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3420 | return false; | |
3421 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3422 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3423 | return false; | |
3424 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3425 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3426 | return false; | |
3427 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3428 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3429 | return false; | |
3430 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3431 | return false; | |
3432 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && | |
3433 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) | |
3434 | return false; | |
3435 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && | |
3436 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) | |
3437 | return false; | |
3438 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && | |
3439 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) | |
3440 | return false; | |
3441 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && | |
3442 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) | |
3443 | return false; | |
3444 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && | |
3445 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3446 | return false; | |
3447 | } | |
c8dcfd8a FF |
3448 | |
3449 | nla_nest_end(msg, rate); | |
3450 | return true; | |
c8dcfd8a FF |
3451 | } |
3452 | ||
119363c7 FF |
3453 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3454 | int id) | |
3455 | { | |
3456 | void *attr; | |
3457 | int i = 0; | |
3458 | ||
3459 | if (!mask) | |
3460 | return true; | |
3461 | ||
3462 | attr = nla_nest_start(msg, id); | |
3463 | if (!attr) | |
3464 | return false; | |
3465 | ||
3466 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3467 | if (!(mask & BIT(i))) | |
3468 | continue; | |
3469 | ||
3470 | if (nla_put_u8(msg, i, signal[i])) | |
3471 | return false; | |
3472 | } | |
3473 | ||
3474 | nla_nest_end(msg, attr); | |
3475 | ||
3476 | return true; | |
3477 | } | |
3478 | ||
15e47304 | 3479 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
66266b3a JL |
3480 | int flags, |
3481 | struct cfg80211_registered_device *rdev, | |
3482 | struct net_device *dev, | |
98b62183 | 3483 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3484 | { |
3485 | void *hdr; | |
f4263c98 | 3486 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3487 | |
15e47304 | 3488 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
fd5b74dc JB |
3489 | if (!hdr) |
3490 | return -1; | |
3491 | ||
9360ffd1 DM |
3492 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3494 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3495 | goto nla_put_failure; | |
f5ea9120 | 3496 | |
2ec600d6 LCC |
3497 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3498 | if (!sinfoattr) | |
fd5b74dc | 3499 | goto nla_put_failure; |
9360ffd1 DM |
3500 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
3501 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
3502 | sinfo->connected_time)) | |
3503 | goto nla_put_failure; | |
3504 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
3505 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
3506 | sinfo->inactive_time)) | |
3507 | goto nla_put_failure; | |
42745e03 VK |
3508 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
3509 | STATION_INFO_RX_BYTES64)) && | |
9360ffd1 | 3510 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3511 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3512 | goto nla_put_failure; |
42745e03 | 3513 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
4325d724 | 3514 | STATION_INFO_TX_BYTES64)) && |
9360ffd1 | 3515 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3516 | (u32)sinfo->tx_bytes)) |
3517 | goto nla_put_failure; | |
3518 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && | |
3519 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, | |
3520 | sinfo->rx_bytes)) | |
3521 | goto nla_put_failure; | |
3522 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && | |
3523 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, | |
9360ffd1 DM |
3524 | sinfo->tx_bytes)) |
3525 | goto nla_put_failure; | |
3526 | if ((sinfo->filled & STATION_INFO_LLID) && | |
3527 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
3528 | goto nla_put_failure; | |
3529 | if ((sinfo->filled & STATION_INFO_PLID) && | |
3530 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
3531 | goto nla_put_failure; | |
3532 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
3533 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
3534 | sinfo->plink_state)) | |
3535 | goto nla_put_failure; | |
66266b3a JL |
3536 | switch (rdev->wiphy.signal_type) { |
3537 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
3538 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
3539 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
3540 | sinfo->signal)) | |
3541 | goto nla_put_failure; | |
3542 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
3543 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
3544 | sinfo->signal_avg)) | |
3545 | goto nla_put_failure; | |
66266b3a JL |
3546 | break; |
3547 | default: | |
3548 | break; | |
3549 | } | |
119363c7 FF |
3550 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
3551 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3552 | sinfo->chain_signal, | |
3553 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3554 | goto nla_put_failure; | |
3555 | } | |
3556 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { | |
3557 | if (!nl80211_put_signal(msg, sinfo->chains, | |
3558 | sinfo->chain_signal_avg, | |
3559 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3560 | goto nla_put_failure; | |
3561 | } | |
420e7fab | 3562 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
3563 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3564 | NL80211_STA_INFO_TX_BITRATE)) | |
3565 | goto nla_put_failure; | |
3566 | } | |
3567 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
3568 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
3569 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3570 | goto nla_put_failure; |
420e7fab | 3571 | } |
9360ffd1 DM |
3572 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
3573 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
3574 | sinfo->rx_packets)) | |
3575 | goto nla_put_failure; | |
3576 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
3577 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
3578 | sinfo->tx_packets)) | |
3579 | goto nla_put_failure; | |
3580 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
3581 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
3582 | sinfo->tx_retries)) | |
3583 | goto nla_put_failure; | |
3584 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
3585 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
3586 | sinfo->tx_failed)) | |
3587 | goto nla_put_failure; | |
3588 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
3589 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
3590 | sinfo->beacon_loss_count)) | |
3591 | goto nla_put_failure; | |
3b1c5a53 MP |
3592 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
3593 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, | |
3594 | sinfo->local_pm)) | |
3595 | goto nla_put_failure; | |
3596 | if ((sinfo->filled & STATION_INFO_PEER_PM) && | |
3597 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, | |
3598 | sinfo->peer_pm)) | |
3599 | goto nla_put_failure; | |
3600 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && | |
3601 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, | |
3602 | sinfo->nonpeer_pm)) | |
3603 | goto nla_put_failure; | |
f4263c98 PS |
3604 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
3605 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
3606 | if (!bss_param) | |
3607 | goto nla_put_failure; | |
3608 | ||
9360ffd1 DM |
3609 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3610 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3611 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3612 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3613 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3614 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3615 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3616 | sinfo->bss_param.dtim_period) || | |
3617 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3618 | sinfo->bss_param.beacon_interval)) | |
3619 | goto nla_put_failure; | |
f4263c98 PS |
3620 | |
3621 | nla_nest_end(msg, bss_param); | |
3622 | } | |
9360ffd1 DM |
3623 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
3624 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
3625 | sizeof(struct nl80211_sta_flag_update), | |
3626 | &sinfo->sta_flags)) | |
3627 | goto nla_put_failure; | |
7eab0f64 JL |
3628 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
3629 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
3630 | sinfo->t_offset)) | |
3631 | goto nla_put_failure; | |
2ec600d6 | 3632 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3633 | |
9360ffd1 DM |
3634 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
3635 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
3636 | sinfo->assoc_req_ies)) | |
3637 | goto nla_put_failure; | |
50d3dfb7 | 3638 | |
fd5b74dc JB |
3639 | return genlmsg_end(msg, hdr); |
3640 | ||
3641 | nla_put_failure: | |
bc3ed28c TG |
3642 | genlmsg_cancel(msg, hdr); |
3643 | return -EMSGSIZE; | |
fd5b74dc JB |
3644 | } |
3645 | ||
2ec600d6 | 3646 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3647 | struct netlink_callback *cb) |
2ec600d6 | 3648 | { |
2ec600d6 LCC |
3649 | struct station_info sinfo; |
3650 | struct cfg80211_registered_device *dev; | |
97990a06 | 3651 | struct wireless_dev *wdev; |
2ec600d6 | 3652 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3653 | int sta_idx = cb->args[2]; |
2ec600d6 | 3654 | int err; |
2ec600d6 | 3655 | |
97990a06 | 3656 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
3657 | if (err) |
3658 | return err; | |
bba95fef | 3659 | |
97990a06 JB |
3660 | if (!wdev->netdev) { |
3661 | err = -EINVAL; | |
3662 | goto out_err; | |
3663 | } | |
3664 | ||
bba95fef | 3665 | if (!dev->ops->dump_station) { |
eec60b03 | 3666 | err = -EOPNOTSUPP; |
bba95fef JB |
3667 | goto out_err; |
3668 | } | |
3669 | ||
bba95fef | 3670 | while (1) { |
f612cedf | 3671 | memset(&sinfo, 0, sizeof(sinfo)); |
97990a06 | 3672 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
e35e4d28 | 3673 | mac_addr, &sinfo); |
bba95fef JB |
3674 | if (err == -ENOENT) |
3675 | break; | |
3676 | if (err) | |
3b85875a | 3677 | goto out_err; |
bba95fef JB |
3678 | |
3679 | if (nl80211_send_station(skb, | |
15e47304 | 3680 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3681 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 3682 | dev, wdev->netdev, mac_addr, |
bba95fef JB |
3683 | &sinfo) < 0) |
3684 | goto out; | |
3685 | ||
3686 | sta_idx++; | |
3687 | } | |
3688 | ||
3689 | ||
3690 | out: | |
97990a06 | 3691 | cb->args[2] = sta_idx; |
bba95fef | 3692 | err = skb->len; |
bba95fef | 3693 | out_err: |
97990a06 | 3694 | nl80211_finish_wdev_dump(dev); |
bba95fef JB |
3695 | |
3696 | return err; | |
2ec600d6 | 3697 | } |
fd5b74dc | 3698 | |
5727ef1b JB |
3699 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3700 | { | |
4c476991 JB |
3701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3702 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3703 | struct station_info sinfo; |
fd5b74dc JB |
3704 | struct sk_buff *msg; |
3705 | u8 *mac_addr = NULL; | |
4c476991 | 3706 | int err; |
fd5b74dc | 3707 | |
2ec600d6 | 3708 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3709 | |
3710 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3711 | return -EINVAL; | |
3712 | ||
3713 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3714 | ||
4c476991 JB |
3715 | if (!rdev->ops->get_station) |
3716 | return -EOPNOTSUPP; | |
3b85875a | 3717 | |
e35e4d28 | 3718 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3719 | if (err) |
4c476991 | 3720 | return err; |
2ec600d6 | 3721 | |
fd2120ca | 3722 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3723 | if (!msg) |
4c476991 | 3724 | return -ENOMEM; |
fd5b74dc | 3725 | |
15e47304 | 3726 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
66266b3a | 3727 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3728 | nlmsg_free(msg); |
3729 | return -ENOBUFS; | |
3730 | } | |
3b85875a | 3731 | |
4c476991 | 3732 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3733 | } |
3734 | ||
77ee7c89 JB |
3735 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3736 | struct station_parameters *params, | |
3737 | enum cfg80211_station_type statype) | |
3738 | { | |
3739 | if (params->listen_interval != -1) | |
3740 | return -EINVAL; | |
3741 | if (params->aid) | |
3742 | return -EINVAL; | |
3743 | ||
3744 | /* When you run into this, adjust the code below for the new flag */ | |
3745 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3746 | ||
3747 | switch (statype) { | |
eef941e6 TP |
3748 | case CFG80211_STA_MESH_PEER_KERNEL: |
3749 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3750 | /* |
3751 | * No ignoring the TDLS flag here -- the userspace mesh | |
3752 | * code doesn't have the bug of including TDLS in the | |
3753 | * mask everywhere. | |
3754 | */ | |
3755 | if (params->sta_flags_mask & | |
3756 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3757 | BIT(NL80211_STA_FLAG_MFP) | | |
3758 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3759 | return -EINVAL; | |
3760 | break; | |
3761 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3762 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3763 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3764 | return -EINVAL; | |
3765 | /* ignore since it can't change */ | |
3766 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3767 | break; | |
3768 | default: | |
3769 | /* disallow mesh-specific things */ | |
3770 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3771 | return -EINVAL; | |
3772 | if (params->local_pm) | |
3773 | return -EINVAL; | |
3774 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3775 | return -EINVAL; | |
3776 | } | |
3777 | ||
3778 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3779 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3780 | /* TDLS can't be set, ... */ | |
3781 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3782 | return -EINVAL; | |
3783 | /* | |
3784 | * ... but don't bother the driver with it. This works around | |
3785 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3786 | * TLDS_PEER flag in the mask even for AP mode. | |
3787 | */ | |
3788 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3789 | } | |
3790 | ||
3791 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
3792 | /* reject other things that can't change */ | |
3793 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
3794 | return -EINVAL; | |
3795 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
3796 | return -EINVAL; | |
3797 | if (params->supported_rates) | |
3798 | return -EINVAL; | |
3799 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
3800 | return -EINVAL; | |
3801 | } | |
3802 | ||
3803 | if (statype != CFG80211_STA_AP_CLIENT) { | |
3804 | if (params->vlan) | |
3805 | return -EINVAL; | |
3806 | } | |
3807 | ||
3808 | switch (statype) { | |
3809 | case CFG80211_STA_AP_MLME_CLIENT: | |
3810 | /* Use this only for authorizing/unauthorizing a station */ | |
3811 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3812 | return -EOPNOTSUPP; | |
3813 | break; | |
3814 | case CFG80211_STA_AP_CLIENT: | |
3815 | /* accept only the listed bits */ | |
3816 | if (params->sta_flags_mask & | |
3817 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3818 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3819 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
3820 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3821 | BIT(NL80211_STA_FLAG_WME) | | |
3822 | BIT(NL80211_STA_FLAG_MFP))) | |
3823 | return -EINVAL; | |
3824 | ||
3825 | /* but authenticated/associated only if driver handles it */ | |
3826 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
3827 | params->sta_flags_mask & | |
3828 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3829 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
3830 | return -EINVAL; | |
3831 | break; | |
3832 | case CFG80211_STA_IBSS: | |
3833 | case CFG80211_STA_AP_STA: | |
3834 | /* reject any changes other than AUTHORIZED */ | |
3835 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3836 | return -EINVAL; | |
3837 | break; | |
3838 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3839 | /* reject any changes other than AUTHORIZED or WME */ | |
3840 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3841 | BIT(NL80211_STA_FLAG_WME))) | |
3842 | return -EINVAL; | |
3843 | /* force (at least) rates when authorizing */ | |
3844 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
3845 | !params->supported_rates) | |
3846 | return -EINVAL; | |
3847 | break; | |
3848 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3849 | /* reject any changes */ | |
3850 | return -EINVAL; | |
eef941e6 | 3851 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
3852 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
3853 | return -EINVAL; | |
3854 | break; | |
eef941e6 | 3855 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
3856 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
3857 | return -EINVAL; | |
3858 | break; | |
3859 | } | |
3860 | ||
3861 | return 0; | |
3862 | } | |
3863 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
3864 | ||
5727ef1b | 3865 | /* |
c258d2de | 3866 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 3867 | */ |
80b99899 JB |
3868 | static struct net_device *get_vlan(struct genl_info *info, |
3869 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 3870 | { |
463d0183 | 3871 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
3872 | struct net_device *v; |
3873 | int ret; | |
3874 | ||
3875 | if (!vlanattr) | |
3876 | return NULL; | |
3877 | ||
3878 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
3879 | if (!v) | |
3880 | return ERR_PTR(-ENODEV); | |
3881 | ||
3882 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
3883 | ret = -EINVAL; | |
3884 | goto error; | |
5727ef1b | 3885 | } |
80b99899 | 3886 | |
77ee7c89 JB |
3887 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
3888 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3889 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
3890 | ret = -EINVAL; | |
3891 | goto error; | |
3892 | } | |
3893 | ||
80b99899 JB |
3894 | if (!netif_running(v)) { |
3895 | ret = -ENETDOWN; | |
3896 | goto error; | |
3897 | } | |
3898 | ||
3899 | return v; | |
3900 | error: | |
3901 | dev_put(v); | |
3902 | return ERR_PTR(ret); | |
5727ef1b JB |
3903 | } |
3904 | ||
df881293 JM |
3905 | static struct nla_policy |
3906 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3907 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3908 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3909 | }; | |
3910 | ||
ff276691 JB |
3911 | static int nl80211_parse_sta_wme(struct genl_info *info, |
3912 | struct station_parameters *params) | |
df881293 | 3913 | { |
df881293 JM |
3914 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
3915 | struct nlattr *nla; | |
3916 | int err; | |
3917 | ||
df881293 JM |
3918 | /* parse WME attributes if present */ |
3919 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
3920 | return 0; | |
3921 | ||
3922 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3923 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3924 | nl80211_sta_wme_policy); | |
3925 | if (err) | |
3926 | return err; | |
3927 | ||
3928 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3929 | params->uapsd_queues = nla_get_u8( | |
3930 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3931 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3932 | return -EINVAL; | |
3933 | ||
3934 | if (tb[NL80211_STA_WME_MAX_SP]) | |
3935 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
3936 | ||
3937 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3938 | return -EINVAL; | |
3939 | ||
3940 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
3941 | ||
3942 | return 0; | |
3943 | } | |
3944 | ||
c01fc9ad SD |
3945 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
3946 | struct station_parameters *params) | |
3947 | { | |
3948 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
3949 | params->supported_channels = | |
3950 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
3951 | params->supported_channels_len = | |
3952 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
3953 | /* | |
3954 | * Need to include at least one (first channel, number of | |
3955 | * channels) tuple for each subband, and must have proper | |
3956 | * tuples for the rest of the data as well. | |
3957 | */ | |
3958 | if (params->supported_channels_len < 2) | |
3959 | return -EINVAL; | |
3960 | if (params->supported_channels_len % 2) | |
3961 | return -EINVAL; | |
3962 | } | |
3963 | ||
3964 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
3965 | params->supported_oper_classes = | |
3966 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
3967 | params->supported_oper_classes_len = | |
3968 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
3969 | /* | |
3970 | * The value of the Length field of the Supported Operating | |
3971 | * Classes element is between 2 and 253. | |
3972 | */ | |
3973 | if (params->supported_oper_classes_len < 2 || | |
3974 | params->supported_oper_classes_len > 253) | |
3975 | return -EINVAL; | |
3976 | } | |
3977 | return 0; | |
3978 | } | |
3979 | ||
ff276691 JB |
3980 | static int nl80211_set_station_tdls(struct genl_info *info, |
3981 | struct station_parameters *params) | |
3982 | { | |
c01fc9ad | 3983 | int err; |
ff276691 | 3984 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
3985 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
3986 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
3987 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3988 | params->ht_capa = | |
3989 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
3990 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
3991 | params->vht_capa = | |
3992 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
3993 | ||
c01fc9ad SD |
3994 | err = nl80211_parse_sta_channel_info(info, params); |
3995 | if (err) | |
3996 | return err; | |
3997 | ||
ff276691 JB |
3998 | return nl80211_parse_sta_wme(info, params); |
3999 | } | |
4000 | ||
5727ef1b JB |
4001 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4002 | { | |
4c476991 | 4003 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4004 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4005 | struct station_parameters params; |
77ee7c89 JB |
4006 | u8 *mac_addr; |
4007 | int err; | |
5727ef1b JB |
4008 | |
4009 | memset(¶ms, 0, sizeof(params)); | |
4010 | ||
4011 | params.listen_interval = -1; | |
4012 | ||
77ee7c89 JB |
4013 | if (!rdev->ops->change_station) |
4014 | return -EOPNOTSUPP; | |
4015 | ||
5727ef1b JB |
4016 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4017 | return -EINVAL; | |
4018 | ||
4019 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4020 | return -EINVAL; | |
4021 | ||
4022 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4023 | ||
4024 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4025 | params.supported_rates = | |
4026 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4027 | params.supported_rates_len = | |
4028 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4029 | } | |
4030 | ||
9d62a986 JM |
4031 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4032 | params.capability = | |
4033 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4034 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4035 | } | |
4036 | ||
4037 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4038 | params.ext_capab = | |
4039 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4040 | params.ext_capab_len = | |
4041 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4042 | } | |
4043 | ||
df881293 | 4044 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4045 | return -EINVAL; |
36aedc90 | 4046 | |
bdd3ae3d | 4047 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4048 | return -EINVAL; |
4049 | ||
f8bacc21 | 4050 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4051 | params.plink_action = |
f8bacc21 JB |
4052 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4053 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4054 | return -EINVAL; | |
4055 | } | |
2ec600d6 | 4056 | |
f8bacc21 | 4057 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4058 | params.plink_state = |
f8bacc21 JB |
4059 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4060 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4061 | return -EINVAL; | |
4062 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4063 | } | |
9c3990aa | 4064 | |
3b1c5a53 MP |
4065 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4066 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4067 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4068 | ||
4069 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4070 | pm > NL80211_MESH_POWER_MAX) | |
4071 | return -EINVAL; | |
4072 | ||
4073 | params.local_pm = pm; | |
4074 | } | |
4075 | ||
77ee7c89 JB |
4076 | /* Include parameters for TDLS peer (will check later) */ |
4077 | err = nl80211_set_station_tdls(info, ¶ms); | |
4078 | if (err) | |
4079 | return err; | |
4080 | ||
4081 | params.vlan = get_vlan(info, rdev); | |
4082 | if (IS_ERR(params.vlan)) | |
4083 | return PTR_ERR(params.vlan); | |
4084 | ||
a97f4424 JB |
4085 | switch (dev->ieee80211_ptr->iftype) { |
4086 | case NL80211_IFTYPE_AP: | |
4087 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4088 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4089 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4090 | case NL80211_IFTYPE_STATION: |
267335d6 | 4091 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4092 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4093 | break; |
4094 | default: | |
77ee7c89 JB |
4095 | err = -EOPNOTSUPP; |
4096 | goto out_put_vlan; | |
034d655e JB |
4097 | } |
4098 | ||
77ee7c89 | 4099 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4100 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4101 | |
77ee7c89 | 4102 | out_put_vlan: |
5727ef1b JB |
4103 | if (params.vlan) |
4104 | dev_put(params.vlan); | |
3b85875a | 4105 | |
5727ef1b JB |
4106 | return err; |
4107 | } | |
4108 | ||
4109 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4110 | { | |
4c476991 | 4111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4112 | int err; |
4c476991 | 4113 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4114 | struct station_parameters params; |
4115 | u8 *mac_addr = NULL; | |
4116 | ||
4117 | memset(¶ms, 0, sizeof(params)); | |
4118 | ||
984c311b JB |
4119 | if (!rdev->ops->add_station) |
4120 | return -EOPNOTSUPP; | |
4121 | ||
5727ef1b JB |
4122 | if (!info->attrs[NL80211_ATTR_MAC]) |
4123 | return -EINVAL; | |
4124 | ||
5727ef1b JB |
4125 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4126 | return -EINVAL; | |
4127 | ||
4128 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4129 | return -EINVAL; | |
4130 | ||
5e4b6f56 JM |
4131 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4132 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4133 | return -EINVAL; |
4134 | ||
5727ef1b JB |
4135 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4136 | params.supported_rates = | |
4137 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4138 | params.supported_rates_len = | |
4139 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4140 | params.listen_interval = | |
4141 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4142 | |
3d124ea2 | 4143 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4144 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4145 | else |
4146 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4147 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4148 | return -EINVAL; | |
51b50fbe | 4149 | |
9d62a986 JM |
4150 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4151 | params.capability = | |
4152 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4153 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4154 | } | |
4155 | ||
4156 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4157 | params.ext_capab = | |
4158 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4159 | params.ext_capab_len = | |
4160 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4161 | } | |
4162 | ||
36aedc90 JM |
4163 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4164 | params.ht_capa = | |
4165 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4166 | |
f461be3e MP |
4167 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4168 | params.vht_capa = | |
4169 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4170 | ||
60f4a7b1 MK |
4171 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4172 | params.opmode_notif_used = true; | |
4173 | params.opmode_notif = | |
4174 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4175 | } | |
4176 | ||
f8bacc21 | 4177 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4178 | params.plink_action = |
f8bacc21 JB |
4179 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4180 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4181 | return -EINVAL; | |
4182 | } | |
96b78dff | 4183 | |
c01fc9ad SD |
4184 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4185 | if (err) | |
4186 | return err; | |
4187 | ||
ff276691 JB |
4188 | err = nl80211_parse_sta_wme(info, ¶ms); |
4189 | if (err) | |
4190 | return err; | |
bdd90d5e | 4191 | |
bdd3ae3d | 4192 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4193 | return -EINVAL; |
4194 | ||
77ee7c89 JB |
4195 | /* When you run into this, adjust the code below for the new flag */ |
4196 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4197 | ||
bdd90d5e JB |
4198 | switch (dev->ieee80211_ptr->iftype) { |
4199 | case NL80211_IFTYPE_AP: | |
4200 | case NL80211_IFTYPE_AP_VLAN: | |
4201 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4202 | /* ignore WME attributes if iface/sta is not capable */ |
4203 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4204 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4205 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4206 | |
bdd90d5e | 4207 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4208 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4209 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4210 | return -EINVAL; |
bdd90d5e JB |
4211 | /* but don't bother the driver with it */ |
4212 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4213 | |
d582cffb JB |
4214 | /* allow authenticated/associated only if driver handles it */ |
4215 | if (!(rdev->wiphy.features & | |
4216 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4217 | params.sta_flags_mask & | |
4218 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4219 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4220 | return -EINVAL; | |
4221 | ||
bdd90d5e JB |
4222 | /* must be last in here for error handling */ |
4223 | params.vlan = get_vlan(info, rdev); | |
4224 | if (IS_ERR(params.vlan)) | |
4225 | return PTR_ERR(params.vlan); | |
4226 | break; | |
4227 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4228 | /* ignore uAPSD data */ |
4229 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4230 | ||
d582cffb JB |
4231 | /* associated is disallowed */ |
4232 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4233 | return -EINVAL; | |
bdd90d5e | 4234 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4235 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4236 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4237 | return -EINVAL; |
4238 | break; | |
4239 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4240 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4241 | /* ignore uAPSD data */ |
4242 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4243 | ||
77ee7c89 JB |
4244 | /* these are disallowed */ |
4245 | if (params.sta_flags_mask & | |
4246 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4247 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4248 | return -EINVAL; |
bdd90d5e JB |
4249 | /* Only TDLS peers can be added */ |
4250 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4251 | return -EINVAL; | |
4252 | /* Can only add if TDLS ... */ | |
4253 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4254 | return -EOPNOTSUPP; | |
4255 | /* ... with external setup is supported */ | |
4256 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4257 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4258 | /* |
4259 | * Older wpa_supplicant versions always mark the TDLS peer | |
4260 | * as authorized, but it shouldn't yet be. | |
4261 | */ | |
4262 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4263 | break; |
4264 | default: | |
4265 | return -EOPNOTSUPP; | |
c75786c9 EP |
4266 | } |
4267 | ||
bdd90d5e | 4268 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4269 | |
e35e4d28 | 4270 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4271 | |
5727ef1b JB |
4272 | if (params.vlan) |
4273 | dev_put(params.vlan); | |
5727ef1b JB |
4274 | return err; |
4275 | } | |
4276 | ||
4277 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4278 | { | |
4c476991 JB |
4279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4280 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
4281 | u8 *mac_addr = NULL; |
4282 | ||
4283 | if (info->attrs[NL80211_ATTR_MAC]) | |
4284 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4285 | ||
e80cf853 | 4286 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4287 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4288 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4289 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4290 | return -EINVAL; | |
5727ef1b | 4291 | |
4c476991 JB |
4292 | if (!rdev->ops->del_station) |
4293 | return -EOPNOTSUPP; | |
3b85875a | 4294 | |
e35e4d28 | 4295 | return rdev_del_station(rdev, dev, mac_addr); |
5727ef1b JB |
4296 | } |
4297 | ||
15e47304 | 4298 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4299 | int flags, struct net_device *dev, |
4300 | u8 *dst, u8 *next_hop, | |
4301 | struct mpath_info *pinfo) | |
4302 | { | |
4303 | void *hdr; | |
4304 | struct nlattr *pinfoattr; | |
4305 | ||
15e47304 | 4306 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
2ec600d6 LCC |
4307 | if (!hdr) |
4308 | return -1; | |
4309 | ||
9360ffd1 DM |
4310 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4311 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4312 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4313 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4314 | goto nla_put_failure; | |
f5ea9120 | 4315 | |
2ec600d6 LCC |
4316 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4317 | if (!pinfoattr) | |
4318 | goto nla_put_failure; | |
9360ffd1 DM |
4319 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4320 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4321 | pinfo->frame_qlen)) | |
4322 | goto nla_put_failure; | |
4323 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4324 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4325 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4326 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4327 | pinfo->metric)) || | |
4328 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4329 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4330 | pinfo->exptime)) || | |
4331 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4332 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4333 | pinfo->flags)) || | |
4334 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4335 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4336 | pinfo->discovery_timeout)) || | |
4337 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4338 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4339 | pinfo->discovery_retries))) | |
4340 | goto nla_put_failure; | |
2ec600d6 LCC |
4341 | |
4342 | nla_nest_end(msg, pinfoattr); | |
4343 | ||
4344 | return genlmsg_end(msg, hdr); | |
4345 | ||
4346 | nla_put_failure: | |
bc3ed28c TG |
4347 | genlmsg_cancel(msg, hdr); |
4348 | return -EMSGSIZE; | |
2ec600d6 LCC |
4349 | } |
4350 | ||
4351 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4352 | struct netlink_callback *cb) |
2ec600d6 | 4353 | { |
2ec600d6 LCC |
4354 | struct mpath_info pinfo; |
4355 | struct cfg80211_registered_device *dev; | |
97990a06 | 4356 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4357 | u8 dst[ETH_ALEN]; |
4358 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4359 | int path_idx = cb->args[2]; |
2ec600d6 | 4360 | int err; |
2ec600d6 | 4361 | |
97990a06 | 4362 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
4363 | if (err) |
4364 | return err; | |
bba95fef JB |
4365 | |
4366 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 4367 | err = -EOPNOTSUPP; |
bba95fef JB |
4368 | goto out_err; |
4369 | } | |
4370 | ||
97990a06 | 4371 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4372 | err = -EOPNOTSUPP; |
0448b5fc | 4373 | goto out_err; |
eec60b03 JM |
4374 | } |
4375 | ||
bba95fef | 4376 | while (1) { |
97990a06 JB |
4377 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
4378 | next_hop, &pinfo); | |
bba95fef | 4379 | if (err == -ENOENT) |
2ec600d6 | 4380 | break; |
bba95fef | 4381 | if (err) |
3b85875a | 4382 | goto out_err; |
2ec600d6 | 4383 | |
15e47304 | 4384 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4385 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4386 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4387 | &pinfo) < 0) |
4388 | goto out; | |
2ec600d6 | 4389 | |
bba95fef | 4390 | path_idx++; |
2ec600d6 | 4391 | } |
2ec600d6 | 4392 | |
2ec600d6 | 4393 | |
bba95fef | 4394 | out: |
97990a06 | 4395 | cb->args[2] = path_idx; |
bba95fef | 4396 | err = skb->len; |
bba95fef | 4397 | out_err: |
97990a06 | 4398 | nl80211_finish_wdev_dump(dev); |
bba95fef | 4399 | return err; |
2ec600d6 LCC |
4400 | } |
4401 | ||
4402 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4403 | { | |
4c476991 | 4404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4405 | int err; |
4c476991 | 4406 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4407 | struct mpath_info pinfo; |
4408 | struct sk_buff *msg; | |
4409 | u8 *dst = NULL; | |
4410 | u8 next_hop[ETH_ALEN]; | |
4411 | ||
4412 | memset(&pinfo, 0, sizeof(pinfo)); | |
4413 | ||
4414 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4415 | return -EINVAL; | |
4416 | ||
4417 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4418 | ||
4c476991 JB |
4419 | if (!rdev->ops->get_mpath) |
4420 | return -EOPNOTSUPP; | |
2ec600d6 | 4421 | |
4c476991 JB |
4422 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4423 | return -EOPNOTSUPP; | |
eec60b03 | 4424 | |
e35e4d28 | 4425 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4426 | if (err) |
4c476991 | 4427 | return err; |
2ec600d6 | 4428 | |
fd2120ca | 4429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4430 | if (!msg) |
4c476991 | 4431 | return -ENOMEM; |
2ec600d6 | 4432 | |
15e47304 | 4433 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4434 | dev, dst, next_hop, &pinfo) < 0) { |
4435 | nlmsg_free(msg); | |
4436 | return -ENOBUFS; | |
4437 | } | |
3b85875a | 4438 | |
4c476991 | 4439 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4440 | } |
4441 | ||
4442 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4443 | { | |
4c476991 JB |
4444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4445 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4446 | u8 *dst = NULL; |
4447 | u8 *next_hop = NULL; | |
4448 | ||
4449 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4450 | return -EINVAL; | |
4451 | ||
4452 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4453 | return -EINVAL; | |
4454 | ||
4455 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4456 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4457 | ||
4c476991 JB |
4458 | if (!rdev->ops->change_mpath) |
4459 | return -EOPNOTSUPP; | |
35a8efe1 | 4460 | |
4c476991 JB |
4461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4462 | return -EOPNOTSUPP; | |
2ec600d6 | 4463 | |
e35e4d28 | 4464 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4465 | } |
4c476991 | 4466 | |
2ec600d6 LCC |
4467 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4468 | { | |
4c476991 JB |
4469 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4470 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4471 | u8 *dst = NULL; |
4472 | u8 *next_hop = NULL; | |
4473 | ||
4474 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4475 | return -EINVAL; | |
4476 | ||
4477 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4478 | return -EINVAL; | |
4479 | ||
4480 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4481 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4482 | ||
4c476991 JB |
4483 | if (!rdev->ops->add_mpath) |
4484 | return -EOPNOTSUPP; | |
35a8efe1 | 4485 | |
4c476991 JB |
4486 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4487 | return -EOPNOTSUPP; | |
2ec600d6 | 4488 | |
e35e4d28 | 4489 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4490 | } |
4491 | ||
4492 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4493 | { | |
4c476991 JB |
4494 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4495 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4496 | u8 *dst = NULL; |
4497 | ||
4498 | if (info->attrs[NL80211_ATTR_MAC]) | |
4499 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4500 | ||
4c476991 JB |
4501 | if (!rdev->ops->del_mpath) |
4502 | return -EOPNOTSUPP; | |
3b85875a | 4503 | |
e35e4d28 | 4504 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4505 | } |
4506 | ||
9f1ba906 JM |
4507 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4508 | { | |
4c476991 JB |
4509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4510 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4511 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4512 | struct bss_parameters params; |
c56589ed | 4513 | int err; |
9f1ba906 JM |
4514 | |
4515 | memset(¶ms, 0, sizeof(params)); | |
4516 | /* default to not changing parameters */ | |
4517 | params.use_cts_prot = -1; | |
4518 | params.use_short_preamble = -1; | |
4519 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4520 | params.ap_isolate = -1; |
50b12f59 | 4521 | params.ht_opmode = -1; |
53cabad7 JB |
4522 | params.p2p_ctwindow = -1; |
4523 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4524 | |
4525 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4526 | params.use_cts_prot = | |
4527 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4528 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4529 | params.use_short_preamble = | |
4530 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4531 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4532 | params.use_short_slot_time = | |
4533 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4534 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4535 | params.basic_rates = | |
4536 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4537 | params.basic_rates_len = | |
4538 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4539 | } | |
fd8aaaf3 FF |
4540 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4541 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4542 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4543 | params.ht_opmode = | |
4544 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4545 | |
53cabad7 JB |
4546 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4547 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4548 | return -EINVAL; | |
4549 | params.p2p_ctwindow = | |
4550 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4551 | if (params.p2p_ctwindow < 0) | |
4552 | return -EINVAL; | |
4553 | if (params.p2p_ctwindow != 0 && | |
4554 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4555 | return -EINVAL; | |
4556 | } | |
4557 | ||
4558 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4559 | u8 tmp; | |
4560 | ||
4561 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4562 | return -EINVAL; | |
4563 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4564 | if (tmp > 1) | |
4565 | return -EINVAL; | |
4566 | params.p2p_opp_ps = tmp; | |
4567 | if (params.p2p_opp_ps && | |
4568 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4569 | return -EINVAL; | |
4570 | } | |
4571 | ||
4c476991 JB |
4572 | if (!rdev->ops->change_bss) |
4573 | return -EOPNOTSUPP; | |
9f1ba906 | 4574 | |
074ac8df | 4575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4576 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4577 | return -EOPNOTSUPP; | |
3b85875a | 4578 | |
c56589ed SW |
4579 | wdev_lock(wdev); |
4580 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4581 | wdev_unlock(wdev); | |
4582 | ||
4583 | return err; | |
9f1ba906 JM |
4584 | } |
4585 | ||
b54452b0 | 4586 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4587 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4588 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4589 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4590 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4591 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4592 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
4593 | }; | |
4594 | ||
4595 | static int parse_reg_rule(struct nlattr *tb[], | |
4596 | struct ieee80211_reg_rule *reg_rule) | |
4597 | { | |
4598 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4599 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4600 | ||
4601 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4602 | return -EINVAL; | |
4603 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4604 | return -EINVAL; | |
4605 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4606 | return -EINVAL; | |
4607 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
4608 | return -EINVAL; | |
4609 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
4610 | return -EINVAL; | |
4611 | ||
4612 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4613 | ||
4614 | freq_range->start_freq_khz = | |
4615 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4616 | freq_range->end_freq_khz = | |
4617 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
4618 | freq_range->max_bandwidth_khz = | |
4619 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
4620 | ||
4621 | power_rule->max_eirp = | |
4622 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4623 | ||
4624 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4625 | power_rule->max_antenna_gain = | |
4626 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4627 | ||
4628 | return 0; | |
4629 | } | |
4630 | ||
4631 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4632 | { | |
4633 | int r; | |
4634 | char *data = NULL; | |
57b5ce07 | 4635 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
b2e1b302 | 4636 | |
80778f18 LR |
4637 | /* |
4638 | * You should only get this when cfg80211 hasn't yet initialized | |
4639 | * completely when built-in to the kernel right between the time | |
4640 | * window between nl80211_init() and regulatory_init(), if that is | |
4641 | * even possible. | |
4642 | */ | |
458f4f9e | 4643 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4644 | return -EINPROGRESS; |
80778f18 | 4645 | |
fe33eb39 LR |
4646 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4647 | return -EINVAL; | |
b2e1b302 LR |
4648 | |
4649 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4650 | ||
57b5ce07 LR |
4651 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4652 | user_reg_hint_type = | |
4653 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4654 | else | |
4655 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4656 | ||
4657 | switch (user_reg_hint_type) { | |
4658 | case NL80211_USER_REG_HINT_USER: | |
4659 | case NL80211_USER_REG_HINT_CELL_BASE: | |
4660 | break; | |
4661 | default: | |
4662 | return -EINVAL; | |
4663 | } | |
4664 | ||
4665 | r = regulatory_hint_user(data, user_reg_hint_type); | |
fe33eb39 | 4666 | |
b2e1b302 LR |
4667 | return r; |
4668 | } | |
4669 | ||
24bdd9f4 | 4670 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 4671 | struct genl_info *info) |
93da9cc1 | 4672 | { |
4c476991 | 4673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4674 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
4675 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4676 | struct mesh_config cur_params; | |
4677 | int err = 0; | |
93da9cc1 | 4678 | void *hdr; |
4679 | struct nlattr *pinfoattr; | |
4680 | struct sk_buff *msg; | |
4681 | ||
29cbe68c JB |
4682 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
4683 | return -EOPNOTSUPP; | |
4684 | ||
24bdd9f4 | 4685 | if (!rdev->ops->get_mesh_config) |
4c476991 | 4686 | return -EOPNOTSUPP; |
f3f92586 | 4687 | |
29cbe68c JB |
4688 | wdev_lock(wdev); |
4689 | /* If not connected, get default parameters */ | |
4690 | if (!wdev->mesh_id_len) | |
4691 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
4692 | else | |
e35e4d28 | 4693 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
4694 | wdev_unlock(wdev); |
4695 | ||
93da9cc1 | 4696 | if (err) |
4c476991 | 4697 | return err; |
93da9cc1 | 4698 | |
4699 | /* Draw up a netlink message to send back */ | |
fd2120ca | 4700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
4701 | if (!msg) |
4702 | return -ENOMEM; | |
15e47304 | 4703 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 4704 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 4705 | if (!hdr) |
efe1cf0c | 4706 | goto out; |
24bdd9f4 | 4707 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 4708 | if (!pinfoattr) |
4709 | goto nla_put_failure; | |
9360ffd1 DM |
4710 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4711 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
4712 | cur_params.dot11MeshRetryTimeout) || | |
4713 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
4714 | cur_params.dot11MeshConfirmTimeout) || | |
4715 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
4716 | cur_params.dot11MeshHoldingTimeout) || | |
4717 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
4718 | cur_params.dot11MeshMaxPeerLinks) || | |
4719 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
4720 | cur_params.dot11MeshMaxRetries) || | |
4721 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
4722 | cur_params.dot11MeshTTL) || | |
4723 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
4724 | cur_params.element_ttl) || | |
4725 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
4726 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
4727 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4728 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
4729 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4730 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
4731 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
4732 | cur_params.path_refresh_time) || | |
4733 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
4734 | cur_params.min_discovery_timeout) || | |
4735 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
4736 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
4737 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
4738 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
4739 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
4740 | cur_params.dot11MeshHWMPperrMinInterval) || | |
4741 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
4742 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
4743 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4744 | cur_params.dot11MeshHWMPRootMode) || | |
4745 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
4746 | cur_params.dot11MeshHWMPRannInterval) || | |
4747 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
4748 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
4749 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
4750 | cur_params.dot11MeshForwarding) || | |
4751 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
4752 | cur_params.rssi_threshold) || |
4753 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
4754 | cur_params.ht_opmode) || |
4755 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
4756 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
4757 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
4758 | cur_params.dot11MeshHWMProotInterval) || |
4759 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
4760 | cur_params.dot11MeshHWMPconfirmationInterval) || |
4761 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
4762 | cur_params.power_mode) || | |
4763 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
4764 | cur_params.dot11MeshAwakeWindowDuration) || |
4765 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4766 | cur_params.plink_timeout)) | |
9360ffd1 | 4767 | goto nla_put_failure; |
93da9cc1 | 4768 | nla_nest_end(msg, pinfoattr); |
4769 | genlmsg_end(msg, hdr); | |
4c476991 | 4770 | return genlmsg_reply(msg, info); |
93da9cc1 | 4771 | |
3b85875a | 4772 | nla_put_failure: |
93da9cc1 | 4773 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 4774 | out: |
d080e275 | 4775 | nlmsg_free(msg); |
4c476991 | 4776 | return -ENOBUFS; |
93da9cc1 | 4777 | } |
4778 | ||
b54452b0 | 4779 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 4780 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
4781 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
4782 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
4783 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
4784 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
4785 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 4786 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 4787 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 4788 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 4789 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
4790 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
4791 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
4792 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
4793 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 4794 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 4795 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 4796 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 4797 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 4798 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 4799 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
4800 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
4801 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
4802 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
4803 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 4804 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
4805 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
4806 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 4807 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 4808 | }; |
4809 | ||
c80d545d JC |
4810 | static const struct nla_policy |
4811 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 4812 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
4813 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
4814 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 4815 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 4816 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 4817 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 4818 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 4819 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 4820 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
4821 | }; |
4822 | ||
24bdd9f4 | 4823 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
4824 | struct mesh_config *cfg, |
4825 | u32 *mask_out) | |
93da9cc1 | 4826 | { |
93da9cc1 | 4827 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 4828 | u32 mask = 0; |
93da9cc1 | 4829 | |
ea54fba2 MP |
4830 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
4831 | do { \ | |
4832 | if (tb[attr]) { \ | |
4833 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
4834 | return -EINVAL; \ | |
4835 | cfg->param = fn(tb[attr]); \ | |
4836 | mask |= (1 << (attr - 1)); \ | |
4837 | } \ | |
4838 | } while (0) | |
bd90fdcc JB |
4839 | |
4840 | ||
24bdd9f4 | 4841 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 4842 | return -EINVAL; |
4843 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 4844 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 4845 | nl80211_meshconf_params_policy)) |
93da9cc1 | 4846 | return -EINVAL; |
4847 | ||
93da9cc1 | 4848 | /* This makes sure that there aren't more than 32 mesh config |
4849 | * parameters (otherwise our bitfield scheme would not work.) */ | |
4850 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
4851 | ||
4852 | /* Fill in the params struct */ | |
ea54fba2 | 4853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
4854 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
4855 | nla_get_u16); | |
ea54fba2 | 4856 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
4857 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
4858 | nla_get_u16); | |
ea54fba2 | 4859 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
4860 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
4861 | nla_get_u16); | |
ea54fba2 | 4862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
4863 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
4864 | nla_get_u16); | |
ea54fba2 | 4865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
4866 | mask, NL80211_MESHCONF_MAX_RETRIES, |
4867 | nla_get_u8); | |
ea54fba2 | 4868 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 4869 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 4870 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
4871 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
4872 | nla_get_u8); | |
ea54fba2 | 4873 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
4874 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
4875 | nla_get_u8); | |
ea54fba2 MP |
4876 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
4877 | 1, 255, mask, | |
a4f606ea CYY |
4878 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
4879 | nla_get_u32); | |
ea54fba2 | 4880 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
4881 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
4882 | nla_get_u8); | |
ea54fba2 | 4883 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
4884 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
4885 | nla_get_u32); | |
ea54fba2 | 4886 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
4887 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
4888 | nla_get_u16); | |
ea54fba2 MP |
4889 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
4890 | 1, 65535, mask, | |
a4f606ea CYY |
4891 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
4892 | nla_get_u32); | |
93da9cc1 | 4893 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
4894 | 1, 65535, mask, |
4895 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 4896 | nla_get_u16); |
dca7e943 | 4897 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
4898 | 1, 65535, mask, |
4899 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 4900 | nla_get_u16); |
93da9cc1 | 4901 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4902 | dot11MeshHWMPnetDiameterTraversalTime, |
4903 | 1, 65535, mask, | |
a4f606ea CYY |
4904 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
4905 | nla_get_u16); | |
ea54fba2 MP |
4906 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
4907 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
4908 | nla_get_u8); | |
4909 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
4910 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 4911 | nla_get_u16); |
63c5723b | 4912 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
4913 | dot11MeshGateAnnouncementProtocol, 0, 1, |
4914 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 4915 | nla_get_u8); |
ea54fba2 | 4916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
4917 | mask, NL80211_MESHCONF_FORWARDING, |
4918 | nla_get_u8); | |
83374fe9 | 4919 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 4920 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 4921 | nla_get_s32); |
ea54fba2 | 4922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 4923 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
4924 | nla_get_u16); |
4925 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 4926 | 1, 65535, mask, |
ac1073a6 CYY |
4927 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
4928 | nla_get_u32); | |
ea54fba2 | 4929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 4930 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
4931 | nla_get_u16); |
4932 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
4933 | dot11MeshHWMPconfirmationInterval, |
4934 | 1, 65535, mask, | |
728b19e5 | 4935 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 4936 | nla_get_u16); |
3b1c5a53 MP |
4937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
4938 | NL80211_MESH_POWER_ACTIVE, | |
4939 | NL80211_MESH_POWER_MAX, | |
4940 | mask, NL80211_MESHCONF_POWER_MODE, | |
4941 | nla_get_u32); | |
4942 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
4943 | 0, 65535, mask, | |
4944 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
8e7c0538 CT |
4945 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
4946 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4947 | nla_get_u32); | |
bd90fdcc JB |
4948 | if (mask_out) |
4949 | *mask_out = mask; | |
c80d545d | 4950 | |
bd90fdcc JB |
4951 | return 0; |
4952 | ||
4953 | #undef FILL_IN_MESH_PARAM_IF_SET | |
4954 | } | |
4955 | ||
c80d545d JC |
4956 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
4957 | struct mesh_setup *setup) | |
4958 | { | |
bb2798d4 | 4959 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
4960 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
4961 | ||
4962 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
4963 | return -EINVAL; | |
4964 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
4965 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
4966 | nl80211_mesh_setup_params_policy)) | |
4967 | return -EINVAL; | |
4968 | ||
d299a1f2 JC |
4969 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
4970 | setup->sync_method = | |
4971 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
4972 | IEEE80211_SYNC_METHOD_VENDOR : | |
4973 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
4974 | ||
c80d545d JC |
4975 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
4976 | setup->path_sel_proto = | |
4977 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
4978 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
4979 | IEEE80211_PATH_PROTOCOL_HWMP; | |
4980 | ||
4981 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
4982 | setup->path_metric = | |
4983 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
4984 | IEEE80211_PATH_METRIC_VENDOR : | |
4985 | IEEE80211_PATH_METRIC_AIRTIME; | |
4986 | ||
581a8b0f JC |
4987 | |
4988 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 4989 | struct nlattr *ieattr = |
581a8b0f | 4990 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
4991 | if (!is_valid_ie_attr(ieattr)) |
4992 | return -EINVAL; | |
581a8b0f JC |
4993 | setup->ie = nla_data(ieattr); |
4994 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 4995 | } |
bb2798d4 TP |
4996 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
4997 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
4998 | return -EINVAL; | |
4999 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5000 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5001 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5002 | if (setup->is_secure) |
5003 | setup->user_mpm = true; | |
c80d545d | 5004 | |
6e16d90b CT |
5005 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5006 | if (!setup->user_mpm) | |
5007 | return -EINVAL; | |
5008 | setup->auth_id = | |
5009 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5010 | } | |
5011 | ||
c80d545d JC |
5012 | return 0; |
5013 | } | |
5014 | ||
24bdd9f4 | 5015 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5016 | struct genl_info *info) |
bd90fdcc JB |
5017 | { |
5018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5019 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5020 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5021 | struct mesh_config cfg; |
5022 | u32 mask; | |
5023 | int err; | |
5024 | ||
29cbe68c JB |
5025 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5026 | return -EOPNOTSUPP; | |
5027 | ||
24bdd9f4 | 5028 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5029 | return -EOPNOTSUPP; |
5030 | ||
24bdd9f4 | 5031 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5032 | if (err) |
5033 | return err; | |
5034 | ||
29cbe68c JB |
5035 | wdev_lock(wdev); |
5036 | if (!wdev->mesh_id_len) | |
5037 | err = -ENOLINK; | |
5038 | ||
5039 | if (!err) | |
e35e4d28 | 5040 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5041 | |
5042 | wdev_unlock(wdev); | |
5043 | ||
5044 | return err; | |
93da9cc1 | 5045 | } |
5046 | ||
f130347c LR |
5047 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
5048 | { | |
458f4f9e | 5049 | const struct ieee80211_regdomain *regdom; |
f130347c LR |
5050 | struct sk_buff *msg; |
5051 | void *hdr = NULL; | |
5052 | struct nlattr *nl_reg_rules; | |
5053 | unsigned int i; | |
f130347c LR |
5054 | |
5055 | if (!cfg80211_regdomain) | |
5fe231e8 | 5056 | return -EINVAL; |
f130347c | 5057 | |
fd2120ca | 5058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
5fe231e8 JB |
5059 | if (!msg) |
5060 | return -ENOBUFS; | |
f130347c | 5061 | |
15e47304 | 5062 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
f130347c LR |
5063 | NL80211_CMD_GET_REG); |
5064 | if (!hdr) | |
efe1cf0c | 5065 | goto put_failure; |
f130347c | 5066 | |
57b5ce07 LR |
5067 | if (reg_last_request_cell_base() && |
5068 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5069 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5070 | goto nla_put_failure; | |
5071 | ||
458f4f9e JB |
5072 | rcu_read_lock(); |
5073 | regdom = rcu_dereference(cfg80211_regdomain); | |
5074 | ||
5075 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || | |
5076 | (regdom->dfs_region && | |
5077 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
5078 | goto nla_put_failure_rcu; | |
5079 | ||
f130347c LR |
5080 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5081 | if (!nl_reg_rules) | |
458f4f9e | 5082 | goto nla_put_failure_rcu; |
f130347c | 5083 | |
458f4f9e | 5084 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5085 | struct nlattr *nl_reg_rule; |
5086 | const struct ieee80211_reg_rule *reg_rule; | |
5087 | const struct ieee80211_freq_range *freq_range; | |
5088 | const struct ieee80211_power_rule *power_rule; | |
5089 | ||
458f4f9e | 5090 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5091 | freq_range = ®_rule->freq_range; |
5092 | power_rule = ®_rule->power_rule; | |
5093 | ||
5094 | nl_reg_rule = nla_nest_start(msg, i); | |
5095 | if (!nl_reg_rule) | |
458f4f9e | 5096 | goto nla_put_failure_rcu; |
f130347c | 5097 | |
9360ffd1 DM |
5098 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5099 | reg_rule->flags) || | |
5100 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5101 | freq_range->start_freq_khz) || | |
5102 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5103 | freq_range->end_freq_khz) || | |
5104 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
5105 | freq_range->max_bandwidth_khz) || | |
5106 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
5107 | power_rule->max_antenna_gain) || | |
5108 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
5109 | power_rule->max_eirp)) | |
458f4f9e | 5110 | goto nla_put_failure_rcu; |
f130347c LR |
5111 | |
5112 | nla_nest_end(msg, nl_reg_rule); | |
5113 | } | |
458f4f9e | 5114 | rcu_read_unlock(); |
f130347c LR |
5115 | |
5116 | nla_nest_end(msg, nl_reg_rules); | |
5117 | ||
5118 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5119 | return genlmsg_reply(msg, info); |
f130347c | 5120 | |
458f4f9e JB |
5121 | nla_put_failure_rcu: |
5122 | rcu_read_unlock(); | |
f130347c LR |
5123 | nla_put_failure: |
5124 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5125 | put_failure: |
d080e275 | 5126 | nlmsg_free(msg); |
5fe231e8 | 5127 | return -EMSGSIZE; |
f130347c LR |
5128 | } |
5129 | ||
b2e1b302 LR |
5130 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5131 | { | |
5132 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5133 | struct nlattr *nl_reg_rule; | |
5134 | char *alpha2 = NULL; | |
5135 | int rem_reg_rules = 0, r = 0; | |
5136 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
4c7d3982 | 5137 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
b2e1b302 LR |
5138 | struct ieee80211_regdomain *rd = NULL; |
5139 | ||
5140 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5141 | return -EINVAL; | |
5142 | ||
5143 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5144 | return -EINVAL; | |
5145 | ||
5146 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5147 | ||
8b60b078 LR |
5148 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5149 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5150 | ||
b2e1b302 | 5151 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5152 | rem_reg_rules) { |
b2e1b302 LR |
5153 | num_rules++; |
5154 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5155 | return -EINVAL; |
b2e1b302 LR |
5156 | } |
5157 | ||
e438768f LR |
5158 | if (!reg_is_valid_request(alpha2)) |
5159 | return -EINVAL; | |
5160 | ||
b2e1b302 | 5161 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5162 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5163 | |
5164 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5165 | if (!rd) |
5166 | return -ENOMEM; | |
b2e1b302 LR |
5167 | |
5168 | rd->n_reg_rules = num_rules; | |
5169 | rd->alpha2[0] = alpha2[0]; | |
5170 | rd->alpha2[1] = alpha2[1]; | |
5171 | ||
8b60b078 LR |
5172 | /* |
5173 | * Disable DFS master mode if the DFS region was | |
5174 | * not supported or known on this kernel. | |
5175 | */ | |
5176 | if (reg_supported_dfs_region(dfs_region)) | |
5177 | rd->dfs_region = dfs_region; | |
5178 | ||
b2e1b302 | 5179 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5180 | rem_reg_rules) { |
b2e1b302 | 5181 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
1a919318 JB |
5182 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
5183 | reg_rule_policy); | |
b2e1b302 LR |
5184 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5185 | if (r) | |
5186 | goto bad_reg; | |
5187 | ||
5188 | rule_idx++; | |
5189 | ||
d0e18f83 LR |
5190 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5191 | r = -EINVAL; | |
b2e1b302 | 5192 | goto bad_reg; |
d0e18f83 | 5193 | } |
b2e1b302 LR |
5194 | } |
5195 | ||
b2e1b302 | 5196 | r = set_regdom(rd); |
6913b49a | 5197 | /* set_regdom took ownership */ |
1a919318 | 5198 | rd = NULL; |
b2e1b302 | 5199 | |
d2372b31 | 5200 | bad_reg: |
b2e1b302 | 5201 | kfree(rd); |
d0e18f83 | 5202 | return r; |
b2e1b302 LR |
5203 | } |
5204 | ||
83f5e2cf JB |
5205 | static int validate_scan_freqs(struct nlattr *freqs) |
5206 | { | |
5207 | struct nlattr *attr1, *attr2; | |
5208 | int n_channels = 0, tmp1, tmp2; | |
5209 | ||
5210 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5211 | n_channels++; | |
5212 | /* | |
5213 | * Some hardware has a limited channel list for | |
5214 | * scanning, and it is pretty much nonsensical | |
5215 | * to scan for a channel twice, so disallow that | |
5216 | * and don't require drivers to check that the | |
5217 | * channel list they get isn't longer than what | |
5218 | * they can scan, as long as they can scan all | |
5219 | * the channels they registered at once. | |
5220 | */ | |
5221 | nla_for_each_nested(attr2, freqs, tmp2) | |
5222 | if (attr1 != attr2 && | |
5223 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5224 | return 0; | |
5225 | } | |
5226 | ||
5227 | return n_channels; | |
5228 | } | |
5229 | ||
2a519311 JB |
5230 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5231 | { | |
4c476991 | 5232 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5233 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5234 | struct cfg80211_scan_request *request; |
2a519311 JB |
5235 | struct nlattr *attr; |
5236 | struct wiphy *wiphy; | |
83f5e2cf | 5237 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5238 | size_t ie_len; |
2a519311 | 5239 | |
f4a11bb0 JB |
5240 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5241 | return -EINVAL; | |
5242 | ||
79c97e97 | 5243 | wiphy = &rdev->wiphy; |
2a519311 | 5244 | |
4c476991 JB |
5245 | if (!rdev->ops->scan) |
5246 | return -EOPNOTSUPP; | |
2a519311 | 5247 | |
f9f47529 JB |
5248 | if (rdev->scan_req) { |
5249 | err = -EBUSY; | |
5250 | goto unlock; | |
5251 | } | |
2a519311 JB |
5252 | |
5253 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5254 | n_channels = validate_scan_freqs( |
5255 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5256 | if (!n_channels) { |
5257 | err = -EINVAL; | |
5258 | goto unlock; | |
5259 | } | |
2a519311 | 5260 | } else { |
bdfbec2d | 5261 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5262 | } |
5263 | ||
5264 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5265 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5266 | n_ssids++; | |
5267 | ||
f9f47529 JB |
5268 | if (n_ssids > wiphy->max_scan_ssids) { |
5269 | err = -EINVAL; | |
5270 | goto unlock; | |
5271 | } | |
2a519311 | 5272 | |
70692ad2 JM |
5273 | if (info->attrs[NL80211_ATTR_IE]) |
5274 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5275 | else | |
5276 | ie_len = 0; | |
5277 | ||
f9f47529 JB |
5278 | if (ie_len > wiphy->max_scan_ie_len) { |
5279 | err = -EINVAL; | |
5280 | goto unlock; | |
5281 | } | |
18a83659 | 5282 | |
2a519311 | 5283 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5284 | + sizeof(*request->ssids) * n_ssids |
5285 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5286 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5287 | if (!request) { |
5288 | err = -ENOMEM; | |
5289 | goto unlock; | |
5290 | } | |
2a519311 | 5291 | |
2a519311 | 5292 | if (n_ssids) |
5ba63533 | 5293 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5294 | request->n_ssids = n_ssids; |
70692ad2 JM |
5295 | if (ie_len) { |
5296 | if (request->ssids) | |
5297 | request->ie = (void *)(request->ssids + n_ssids); | |
5298 | else | |
5299 | request->ie = (void *)(request->channels + n_channels); | |
5300 | } | |
2a519311 | 5301 | |
584991dc | 5302 | i = 0; |
2a519311 JB |
5303 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5304 | /* user specified, bail out if channel not found */ | |
2a519311 | 5305 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5306 | struct ieee80211_channel *chan; |
5307 | ||
5308 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5309 | ||
5310 | if (!chan) { | |
2a519311 JB |
5311 | err = -EINVAL; |
5312 | goto out_free; | |
5313 | } | |
584991dc JB |
5314 | |
5315 | /* ignore disabled channels */ | |
5316 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5317 | continue; | |
5318 | ||
5319 | request->channels[i] = chan; | |
2a519311 JB |
5320 | i++; |
5321 | } | |
5322 | } else { | |
34850ab2 JB |
5323 | enum ieee80211_band band; |
5324 | ||
2a519311 | 5325 | /* all channels */ |
2a519311 JB |
5326 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5327 | int j; | |
5328 | if (!wiphy->bands[band]) | |
5329 | continue; | |
5330 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5331 | struct ieee80211_channel *chan; |
5332 | ||
5333 | chan = &wiphy->bands[band]->channels[j]; | |
5334 | ||
5335 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5336 | continue; | |
5337 | ||
5338 | request->channels[i] = chan; | |
2a519311 JB |
5339 | i++; |
5340 | } | |
5341 | } | |
5342 | } | |
5343 | ||
584991dc JB |
5344 | if (!i) { |
5345 | err = -EINVAL; | |
5346 | goto out_free; | |
5347 | } | |
5348 | ||
5349 | request->n_channels = i; | |
5350 | ||
2a519311 JB |
5351 | i = 0; |
5352 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5353 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 5354 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5355 | err = -EINVAL; |
5356 | goto out_free; | |
5357 | } | |
57a27e1d | 5358 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5359 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5360 | i++; |
5361 | } | |
5362 | } | |
5363 | ||
70692ad2 JM |
5364 | if (info->attrs[NL80211_ATTR_IE]) { |
5365 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5366 | memcpy((void *)request->ie, |
5367 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5368 | request->ie_len); |
5369 | } | |
5370 | ||
34850ab2 | 5371 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5372 | if (wiphy->bands[i]) |
5373 | request->rates[i] = | |
5374 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5375 | |
5376 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5377 | nla_for_each_nested(attr, | |
5378 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5379 | tmp) { | |
5380 | enum ieee80211_band band = nla_type(attr); | |
5381 | ||
84404623 | 5382 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5383 | err = -EINVAL; |
5384 | goto out_free; | |
5385 | } | |
1b09cd82 FF |
5386 | |
5387 | if (!wiphy->bands[band]) | |
5388 | continue; | |
5389 | ||
34850ab2 JB |
5390 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5391 | nla_data(attr), | |
5392 | nla_len(attr), | |
5393 | &request->rates[band]); | |
5394 | if (err) | |
5395 | goto out_free; | |
5396 | } | |
5397 | } | |
5398 | ||
46856bbf | 5399 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5400 | request->flags = nla_get_u32( |
5401 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5402 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5403 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5404 | err = -EOPNOTSUPP; |
5405 | goto out_free; | |
5406 | } | |
5407 | } | |
ed473771 | 5408 | |
e9f935e3 RM |
5409 | request->no_cck = |
5410 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5411 | ||
fd014284 | 5412 | request->wdev = wdev; |
79c97e97 | 5413 | request->wiphy = &rdev->wiphy; |
15d6030b | 5414 | request->scan_start = jiffies; |
2a519311 | 5415 | |
79c97e97 | 5416 | rdev->scan_req = request; |
e35e4d28 | 5417 | err = rdev_scan(rdev, request); |
2a519311 | 5418 | |
463d0183 | 5419 | if (!err) { |
fd014284 JB |
5420 | nl80211_send_scan_start(rdev, wdev); |
5421 | if (wdev->netdev) | |
5422 | dev_hold(wdev->netdev); | |
4c476991 | 5423 | } else { |
2a519311 | 5424 | out_free: |
79c97e97 | 5425 | rdev->scan_req = NULL; |
2a519311 JB |
5426 | kfree(request); |
5427 | } | |
3b85875a | 5428 | |
f9f47529 | 5429 | unlock: |
2a519311 JB |
5430 | return err; |
5431 | } | |
5432 | ||
807f8a8c LC |
5433 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
5434 | struct genl_info *info) | |
5435 | { | |
5436 | struct cfg80211_sched_scan_request *request; | |
5437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5438 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
5439 | struct nlattr *attr; |
5440 | struct wiphy *wiphy; | |
a1f1c21c | 5441 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5442 | u32 interval; |
807f8a8c LC |
5443 | enum ieee80211_band band; |
5444 | size_t ie_len; | |
a1f1c21c | 5445 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
5446 | |
5447 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5448 | !rdev->ops->sched_scan_start) | |
5449 | return -EOPNOTSUPP; | |
5450 | ||
5451 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5452 | return -EINVAL; | |
5453 | ||
bbe6ad6d LC |
5454 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5455 | return -EINVAL; | |
5456 | ||
5457 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
5458 | if (interval == 0) | |
5459 | return -EINVAL; | |
5460 | ||
807f8a8c LC |
5461 | wiphy = &rdev->wiphy; |
5462 | ||
5463 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5464 | n_channels = validate_scan_freqs( | |
5465 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
5466 | if (!n_channels) | |
5467 | return -EINVAL; | |
5468 | } else { | |
bdfbec2d | 5469 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5470 | } |
5471 | ||
5472 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5473 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5474 | tmp) | |
5475 | n_ssids++; | |
5476 | ||
93b6aa69 | 5477 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
5478 | return -EINVAL; |
5479 | ||
a1f1c21c LC |
5480 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
5481 | nla_for_each_nested(attr, | |
5482 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5483 | tmp) | |
5484 | n_match_sets++; | |
5485 | ||
5486 | if (n_match_sets > wiphy->max_match_sets) | |
5487 | return -EINVAL; | |
5488 | ||
807f8a8c LC |
5489 | if (info->attrs[NL80211_ATTR_IE]) |
5490 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5491 | else | |
5492 | ie_len = 0; | |
5493 | ||
5a865bad | 5494 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
5495 | return -EINVAL; |
5496 | ||
c10841ca LC |
5497 | if (rdev->sched_scan_req) { |
5498 | err = -EINPROGRESS; | |
5499 | goto out; | |
5500 | } | |
5501 | ||
807f8a8c | 5502 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 5503 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 5504 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 5505 | + sizeof(*request->channels) * n_channels |
807f8a8c | 5506 | + ie_len, GFP_KERNEL); |
c10841ca LC |
5507 | if (!request) { |
5508 | err = -ENOMEM; | |
5509 | goto out; | |
5510 | } | |
807f8a8c LC |
5511 | |
5512 | if (n_ssids) | |
5513 | request->ssids = (void *)&request->channels[n_channels]; | |
5514 | request->n_ssids = n_ssids; | |
5515 | if (ie_len) { | |
5516 | if (request->ssids) | |
5517 | request->ie = (void *)(request->ssids + n_ssids); | |
5518 | else | |
5519 | request->ie = (void *)(request->channels + n_channels); | |
5520 | } | |
5521 | ||
a1f1c21c LC |
5522 | if (n_match_sets) { |
5523 | if (request->ie) | |
5524 | request->match_sets = (void *)(request->ie + ie_len); | |
5525 | else if (request->ssids) | |
5526 | request->match_sets = | |
5527 | (void *)(request->ssids + n_ssids); | |
5528 | else | |
5529 | request->match_sets = | |
5530 | (void *)(request->channels + n_channels); | |
5531 | } | |
5532 | request->n_match_sets = n_match_sets; | |
5533 | ||
807f8a8c LC |
5534 | i = 0; |
5535 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
5536 | /* user specified, bail out if channel not found */ | |
5537 | nla_for_each_nested(attr, | |
5538 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
5539 | tmp) { | |
5540 | struct ieee80211_channel *chan; | |
5541 | ||
5542 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5543 | ||
5544 | if (!chan) { | |
5545 | err = -EINVAL; | |
5546 | goto out_free; | |
5547 | } | |
5548 | ||
5549 | /* ignore disabled channels */ | |
5550 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5551 | continue; | |
5552 | ||
5553 | request->channels[i] = chan; | |
5554 | i++; | |
5555 | } | |
5556 | } else { | |
5557 | /* all channels */ | |
5558 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5559 | int j; | |
5560 | if (!wiphy->bands[band]) | |
5561 | continue; | |
5562 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
5563 | struct ieee80211_channel *chan; | |
5564 | ||
5565 | chan = &wiphy->bands[band]->channels[j]; | |
5566 | ||
5567 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5568 | continue; | |
5569 | ||
5570 | request->channels[i] = chan; | |
5571 | i++; | |
5572 | } | |
5573 | } | |
5574 | } | |
5575 | ||
5576 | if (!i) { | |
5577 | err = -EINVAL; | |
5578 | goto out_free; | |
5579 | } | |
5580 | ||
5581 | request->n_channels = i; | |
5582 | ||
5583 | i = 0; | |
5584 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
5585 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
5586 | tmp) { | |
57a27e1d | 5587 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
5588 | err = -EINVAL; |
5589 | goto out_free; | |
5590 | } | |
57a27e1d | 5591 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
5592 | memcpy(request->ssids[i].ssid, nla_data(attr), |
5593 | nla_len(attr)); | |
807f8a8c LC |
5594 | i++; |
5595 | } | |
5596 | } | |
5597 | ||
a1f1c21c LC |
5598 | i = 0; |
5599 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
5600 | nla_for_each_nested(attr, | |
5601 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
5602 | tmp) { | |
88e920b4 | 5603 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
5604 | |
5605 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
5606 | nla_data(attr), nla_len(attr), | |
5607 | nl80211_match_policy); | |
4a4ab0d7 | 5608 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
5609 | if (ssid) { |
5610 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
5611 | err = -EINVAL; | |
5612 | goto out_free; | |
5613 | } | |
5614 | memcpy(request->match_sets[i].ssid.ssid, | |
5615 | nla_data(ssid), nla_len(ssid)); | |
5616 | request->match_sets[i].ssid.ssid_len = | |
5617 | nla_len(ssid); | |
5618 | } | |
88e920b4 TP |
5619 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
5620 | if (rssi) | |
5621 | request->rssi_thold = nla_get_u32(rssi); | |
5622 | else | |
5623 | request->rssi_thold = | |
5624 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
5625 | i++; |
5626 | } | |
5627 | } | |
5628 | ||
807f8a8c LC |
5629 | if (info->attrs[NL80211_ATTR_IE]) { |
5630 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5631 | memcpy((void *)request->ie, | |
5632 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5633 | request->ie_len); | |
5634 | } | |
5635 | ||
46856bbf | 5636 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5637 | request->flags = nla_get_u32( |
5638 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5639 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5640 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5641 | err = -EOPNOTSUPP; |
5642 | goto out_free; | |
5643 | } | |
5644 | } | |
ed473771 | 5645 | |
807f8a8c LC |
5646 | request->dev = dev; |
5647 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 5648 | request->interval = interval; |
15d6030b | 5649 | request->scan_start = jiffies; |
807f8a8c | 5650 | |
e35e4d28 | 5651 | err = rdev_sched_scan_start(rdev, dev, request); |
807f8a8c LC |
5652 | if (!err) { |
5653 | rdev->sched_scan_req = request; | |
5654 | nl80211_send_sched_scan(rdev, dev, | |
5655 | NL80211_CMD_START_SCHED_SCAN); | |
5656 | goto out; | |
5657 | } | |
5658 | ||
5659 | out_free: | |
5660 | kfree(request); | |
5661 | out: | |
5662 | return err; | |
5663 | } | |
5664 | ||
5665 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
5666 | struct genl_info *info) | |
5667 | { | |
5668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5669 | ||
5670 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
5671 | !rdev->ops->sched_scan_stop) | |
5672 | return -EOPNOTSUPP; | |
5673 | ||
5fe231e8 | 5674 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
5675 | } |
5676 | ||
04f39047 SW |
5677 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
5678 | struct genl_info *info) | |
5679 | { | |
5680 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5681 | struct net_device *dev = info->user_ptr[1]; | |
5682 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5683 | struct cfg80211_chan_def chandef; | |
55f7435c | 5684 | enum nl80211_dfs_regions dfs_region; |
04f39047 SW |
5685 | int err; |
5686 | ||
55f7435c LR |
5687 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
5688 | if (dfs_region == NL80211_DFS_UNSET) | |
5689 | return -EINVAL; | |
5690 | ||
04f39047 SW |
5691 | err = nl80211_parse_chandef(rdev, info, &chandef); |
5692 | if (err) | |
5693 | return err; | |
5694 | ||
ff311bc1 SW |
5695 | if (netif_carrier_ok(dev)) |
5696 | return -EBUSY; | |
5697 | ||
04f39047 SW |
5698 | if (wdev->cac_started) |
5699 | return -EBUSY; | |
5700 | ||
5701 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); | |
5702 | if (err < 0) | |
5703 | return err; | |
5704 | ||
5705 | if (err == 0) | |
5706 | return -EINVAL; | |
5707 | ||
fe7c3a1f | 5708 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
5709 | return -EINVAL; |
5710 | ||
5711 | if (!rdev->ops->start_radar_detection) | |
5712 | return -EOPNOTSUPP; | |
5713 | ||
04f39047 SW |
5714 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
5715 | chandef.chan, CHAN_MODE_SHARED, | |
5716 | BIT(chandef.width)); | |
5717 | if (err) | |
5fe231e8 | 5718 | return err; |
04f39047 SW |
5719 | |
5720 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); | |
5721 | if (!err) { | |
5722 | wdev->channel = chandef.chan; | |
5723 | wdev->cac_started = true; | |
5724 | wdev->cac_start_time = jiffies; | |
5725 | } | |
04f39047 SW |
5726 | return err; |
5727 | } | |
5728 | ||
16ef1fe2 SW |
5729 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
5730 | { | |
5731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5732 | struct net_device *dev = info->user_ptr[1]; | |
5733 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
5734 | struct cfg80211_csa_settings params; | |
5735 | /* csa_attrs is defined static to avoid waste of stack size - this | |
5736 | * function is called under RTNL lock, so this should not be a problem. | |
5737 | */ | |
5738 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
5739 | u8 radar_detect_width = 0; | |
5740 | int err; | |
ee4bc9e7 | 5741 | bool need_new_beacon = false; |
16ef1fe2 SW |
5742 | |
5743 | if (!rdev->ops->channel_switch || | |
5744 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
5745 | return -EOPNOTSUPP; | |
5746 | ||
ee4bc9e7 SW |
5747 | switch (dev->ieee80211_ptr->iftype) { |
5748 | case NL80211_IFTYPE_AP: | |
5749 | case NL80211_IFTYPE_P2P_GO: | |
5750 | need_new_beacon = true; | |
5751 | ||
5752 | /* useless if AP is not running */ | |
5753 | if (!wdev->beacon_interval) | |
5754 | return -EINVAL; | |
5755 | break; | |
5756 | case NL80211_IFTYPE_ADHOC: | |
c6da674a | 5757 | case NL80211_IFTYPE_MESH_POINT: |
ee4bc9e7 SW |
5758 | break; |
5759 | default: | |
16ef1fe2 | 5760 | return -EOPNOTSUPP; |
ee4bc9e7 | 5761 | } |
16ef1fe2 SW |
5762 | |
5763 | memset(¶ms, 0, sizeof(params)); | |
5764 | ||
5765 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5766 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
5767 | return -EINVAL; | |
5768 | ||
5769 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 5770 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
5771 | return -EINVAL; |
5772 | ||
5773 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
5774 | ||
ee4bc9e7 SW |
5775 | if (!need_new_beacon) |
5776 | goto skip_beacons; | |
5777 | ||
16ef1fe2 SW |
5778 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
5779 | if (err) | |
5780 | return err; | |
5781 | ||
5782 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
5783 | info->attrs[NL80211_ATTR_CSA_IES], | |
5784 | nl80211_policy); | |
5785 | if (err) | |
5786 | return err; | |
5787 | ||
5788 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
5789 | if (err) | |
5790 | return err; | |
5791 | ||
5792 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
5793 | return -EINVAL; | |
5794 | ||
5795 | params.counter_offset_beacon = | |
5796 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
5797 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) | |
5798 | return -EINVAL; | |
5799 | ||
5800 | /* sanity check - counters should be the same */ | |
5801 | if (params.beacon_csa.tail[params.counter_offset_beacon] != | |
5802 | params.count) | |
5803 | return -EINVAL; | |
5804 | ||
5805 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { | |
5806 | params.counter_offset_presp = | |
5807 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
5808 | if (params.counter_offset_presp >= | |
5809 | params.beacon_csa.probe_resp_len) | |
5810 | return -EINVAL; | |
5811 | ||
5812 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != | |
5813 | params.count) | |
5814 | return -EINVAL; | |
5815 | } | |
5816 | ||
ee4bc9e7 | 5817 | skip_beacons: |
16ef1fe2 SW |
5818 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
5819 | if (err) | |
5820 | return err; | |
5821 | ||
5822 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) | |
5823 | return -EINVAL; | |
5824 | ||
ee4bc9e7 | 5825 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
5336fa88 SW |
5826 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
5827 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { | |
ee4bc9e7 SW |
5828 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
5829 | ¶ms.chandef); | |
5830 | if (err < 0) { | |
5831 | return err; | |
5832 | } else if (err) { | |
5833 | radar_detect_width = BIT(params.chandef.width); | |
5834 | params.radar_required = true; | |
5835 | } | |
16ef1fe2 SW |
5836 | } |
5837 | ||
5838 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, | |
5839 | params.chandef.chan, | |
5840 | CHAN_MODE_SHARED, | |
5841 | radar_detect_width); | |
5842 | if (err) | |
5843 | return err; | |
5844 | ||
5845 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) | |
5846 | params.block_tx = true; | |
5847 | ||
c56589ed SW |
5848 | wdev_lock(wdev); |
5849 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
5850 | wdev_unlock(wdev); | |
5851 | ||
5852 | return err; | |
16ef1fe2 SW |
5853 | } |
5854 | ||
9720bb3a JB |
5855 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
5856 | u32 seq, int flags, | |
2a519311 | 5857 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
5858 | struct wireless_dev *wdev, |
5859 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 5860 | { |
48ab905d | 5861 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 5862 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
5863 | void *hdr; |
5864 | struct nlattr *bss; | |
8cef2c9d | 5865 | bool tsf = false; |
48ab905d JB |
5866 | |
5867 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 5868 | |
15e47304 | 5869 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
5870 | NL80211_CMD_NEW_SCAN_RESULTS); |
5871 | if (!hdr) | |
5872 | return -1; | |
5873 | ||
9720bb3a JB |
5874 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
5875 | ||
97990a06 JB |
5876 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
5877 | goto nla_put_failure; | |
5878 | if (wdev->netdev && | |
9360ffd1 DM |
5879 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
5880 | goto nla_put_failure; | |
97990a06 JB |
5881 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
5882 | goto nla_put_failure; | |
2a519311 JB |
5883 | |
5884 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
5885 | if (!bss) | |
5886 | goto nla_put_failure; | |
9360ffd1 | 5887 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 5888 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 5889 | goto nla_put_failure; |
9caf0364 JB |
5890 | |
5891 | rcu_read_lock(); | |
5892 | ies = rcu_dereference(res->ies); | |
8cef2c9d JB |
5893 | if (ies) { |
5894 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5895 | goto fail_unlock_rcu; | |
5896 | tsf = true; | |
5897 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
5898 | ies->len, ies->data)) | |
5899 | goto fail_unlock_rcu; | |
9caf0364 JB |
5900 | } |
5901 | ies = rcu_dereference(res->beacon_ies); | |
8cef2c9d JB |
5902 | if (ies) { |
5903 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
5904 | goto fail_unlock_rcu; | |
5905 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
5906 | ies->len, ies->data)) | |
5907 | goto fail_unlock_rcu; | |
9caf0364 JB |
5908 | } |
5909 | rcu_read_unlock(); | |
5910 | ||
9360ffd1 DM |
5911 | if (res->beacon_interval && |
5912 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
5913 | goto nla_put_failure; | |
5914 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
5915 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 5916 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
5917 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
5918 | jiffies_to_msecs(jiffies - intbss->ts))) | |
5919 | goto nla_put_failure; | |
2a519311 | 5920 | |
77965c97 | 5921 | switch (rdev->wiphy.signal_type) { |
2a519311 | 5922 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
5923 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
5924 | goto nla_put_failure; | |
2a519311 JB |
5925 | break; |
5926 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
5927 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
5928 | goto nla_put_failure; | |
2a519311 JB |
5929 | break; |
5930 | default: | |
5931 | break; | |
5932 | } | |
5933 | ||
48ab905d | 5934 | switch (wdev->iftype) { |
074ac8df | 5935 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 5936 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
5937 | if (intbss == wdev->current_bss && |
5938 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5939 | NL80211_BSS_STATUS_ASSOCIATED)) | |
5940 | goto nla_put_failure; | |
48ab905d JB |
5941 | break; |
5942 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
5943 | if (intbss == wdev->current_bss && |
5944 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
5945 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
5946 | goto nla_put_failure; | |
48ab905d JB |
5947 | break; |
5948 | default: | |
5949 | break; | |
5950 | } | |
5951 | ||
2a519311 JB |
5952 | nla_nest_end(msg, bss); |
5953 | ||
5954 | return genlmsg_end(msg, hdr); | |
5955 | ||
8cef2c9d JB |
5956 | fail_unlock_rcu: |
5957 | rcu_read_unlock(); | |
2a519311 JB |
5958 | nla_put_failure: |
5959 | genlmsg_cancel(msg, hdr); | |
5960 | return -EMSGSIZE; | |
5961 | } | |
5962 | ||
97990a06 | 5963 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 5964 | { |
48ab905d | 5965 | struct cfg80211_registered_device *rdev; |
2a519311 | 5966 | struct cfg80211_internal_bss *scan; |
48ab905d | 5967 | struct wireless_dev *wdev; |
97990a06 | 5968 | int start = cb->args[2], idx = 0; |
2a519311 JB |
5969 | int err; |
5970 | ||
97990a06 | 5971 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5972 | if (err) |
5973 | return err; | |
2a519311 | 5974 | |
48ab905d JB |
5975 | wdev_lock(wdev); |
5976 | spin_lock_bh(&rdev->bss_lock); | |
5977 | cfg80211_bss_expire(rdev); | |
5978 | ||
9720bb3a JB |
5979 | cb->seq = rdev->bss_generation; |
5980 | ||
48ab905d | 5981 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
5982 | if (++idx <= start) |
5983 | continue; | |
9720bb3a | 5984 | if (nl80211_send_bss(skb, cb, |
2a519311 | 5985 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 5986 | rdev, wdev, scan) < 0) { |
2a519311 | 5987 | idx--; |
67748893 | 5988 | break; |
2a519311 JB |
5989 | } |
5990 | } | |
5991 | ||
48ab905d JB |
5992 | spin_unlock_bh(&rdev->bss_lock); |
5993 | wdev_unlock(wdev); | |
2a519311 | 5994 | |
97990a06 JB |
5995 | cb->args[2] = idx; |
5996 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 5997 | |
67748893 | 5998 | return skb->len; |
2a519311 JB |
5999 | } |
6000 | ||
15e47304 | 6001 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
61fa713c HS |
6002 | int flags, struct net_device *dev, |
6003 | struct survey_info *survey) | |
6004 | { | |
6005 | void *hdr; | |
6006 | struct nlattr *infoattr; | |
6007 | ||
15e47304 | 6008 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6009 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6010 | if (!hdr) | |
6011 | return -ENOMEM; | |
6012 | ||
9360ffd1 DM |
6013 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6014 | goto nla_put_failure; | |
61fa713c HS |
6015 | |
6016 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6017 | if (!infoattr) | |
6018 | goto nla_put_failure; | |
6019 | ||
9360ffd1 DM |
6020 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
6021 | survey->channel->center_freq)) | |
6022 | goto nla_put_failure; | |
6023 | ||
6024 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6025 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6026 | goto nla_put_failure; | |
6027 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6028 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6029 | goto nla_put_failure; | |
6030 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
6031 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
6032 | survey->channel_time)) | |
6033 | goto nla_put_failure; | |
6034 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
6035 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
6036 | survey->channel_time_busy)) | |
6037 | goto nla_put_failure; | |
6038 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
6039 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
6040 | survey->channel_time_ext_busy)) | |
6041 | goto nla_put_failure; | |
6042 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
6043 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
6044 | survey->channel_time_rx)) | |
6045 | goto nla_put_failure; | |
6046 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
6047 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
6048 | survey->channel_time_tx)) | |
6049 | goto nla_put_failure; | |
61fa713c HS |
6050 | |
6051 | nla_nest_end(msg, infoattr); | |
6052 | ||
6053 | return genlmsg_end(msg, hdr); | |
6054 | ||
6055 | nla_put_failure: | |
6056 | genlmsg_cancel(msg, hdr); | |
6057 | return -EMSGSIZE; | |
6058 | } | |
6059 | ||
6060 | static int nl80211_dump_survey(struct sk_buff *skb, | |
6061 | struct netlink_callback *cb) | |
6062 | { | |
6063 | struct survey_info survey; | |
6064 | struct cfg80211_registered_device *dev; | |
97990a06 JB |
6065 | struct wireless_dev *wdev; |
6066 | int survey_idx = cb->args[2]; | |
61fa713c HS |
6067 | int res; |
6068 | ||
97990a06 | 6069 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
67748893 JB |
6070 | if (res) |
6071 | return res; | |
61fa713c | 6072 | |
97990a06 JB |
6073 | if (!wdev->netdev) { |
6074 | res = -EINVAL; | |
6075 | goto out_err; | |
6076 | } | |
6077 | ||
61fa713c HS |
6078 | if (!dev->ops->dump_survey) { |
6079 | res = -EOPNOTSUPP; | |
6080 | goto out_err; | |
6081 | } | |
6082 | ||
6083 | while (1) { | |
180cdc79 LR |
6084 | struct ieee80211_channel *chan; |
6085 | ||
97990a06 | 6086 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6087 | if (res == -ENOENT) |
6088 | break; | |
6089 | if (res) | |
6090 | goto out_err; | |
6091 | ||
180cdc79 LR |
6092 | /* Survey without a channel doesn't make sense */ |
6093 | if (!survey.channel) { | |
6094 | res = -EINVAL; | |
6095 | goto out; | |
6096 | } | |
6097 | ||
6098 | chan = ieee80211_get_channel(&dev->wiphy, | |
6099 | survey.channel->center_freq); | |
6100 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
6101 | survey_idx++; | |
6102 | continue; | |
6103 | } | |
6104 | ||
61fa713c | 6105 | if (nl80211_send_survey(skb, |
15e47304 | 6106 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6107 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 6108 | wdev->netdev, &survey) < 0) |
61fa713c HS |
6109 | goto out; |
6110 | survey_idx++; | |
6111 | } | |
6112 | ||
6113 | out: | |
97990a06 | 6114 | cb->args[2] = survey_idx; |
61fa713c HS |
6115 | res = skb->len; |
6116 | out_err: | |
97990a06 | 6117 | nl80211_finish_wdev_dump(dev); |
61fa713c HS |
6118 | return res; |
6119 | } | |
6120 | ||
b23aa676 SO |
6121 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6122 | { | |
6123 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6124 | NL80211_WPA_VERSION_2)); | |
6125 | } | |
6126 | ||
636a5d36 JM |
6127 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6128 | { | |
4c476991 JB |
6129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6130 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6131 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6132 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6133 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6134 | enum nl80211_auth_type auth_type; |
fffd0934 | 6135 | struct key_parse key; |
d5cdfacb | 6136 | bool local_state_change; |
636a5d36 | 6137 | |
f4a11bb0 JB |
6138 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6139 | return -EINVAL; | |
6140 | ||
6141 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6142 | return -EINVAL; | |
6143 | ||
1778092e JM |
6144 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6145 | return -EINVAL; | |
6146 | ||
19957bb3 JB |
6147 | if (!info->attrs[NL80211_ATTR_SSID]) |
6148 | return -EINVAL; | |
6149 | ||
6150 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6151 | return -EINVAL; | |
6152 | ||
fffd0934 JB |
6153 | err = nl80211_parse_key(info, &key); |
6154 | if (err) | |
6155 | return err; | |
6156 | ||
6157 | if (key.idx >= 0) { | |
e31b8213 JB |
6158 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6159 | return -EINVAL; | |
fffd0934 JB |
6160 | if (!key.p.key || !key.p.key_len) |
6161 | return -EINVAL; | |
6162 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6163 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6164 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6165 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6166 | return -EINVAL; | |
6167 | if (key.idx > 4) | |
6168 | return -EINVAL; | |
6169 | } else { | |
6170 | key.p.key_len = 0; | |
6171 | key.p.key = NULL; | |
6172 | } | |
6173 | ||
afea0b7a JB |
6174 | if (key.idx >= 0) { |
6175 | int i; | |
6176 | bool ok = false; | |
6177 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6178 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6179 | ok = true; | |
6180 | break; | |
6181 | } | |
6182 | } | |
4c476991 JB |
6183 | if (!ok) |
6184 | return -EINVAL; | |
afea0b7a JB |
6185 | } |
6186 | ||
4c476991 JB |
6187 | if (!rdev->ops->auth) |
6188 | return -EOPNOTSUPP; | |
636a5d36 | 6189 | |
074ac8df | 6190 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6191 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6192 | return -EOPNOTSUPP; | |
eec60b03 | 6193 | |
19957bb3 | 6194 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 6195 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 6196 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
6197 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6198 | return -EINVAL; | |
636a5d36 | 6199 | |
19957bb3 JB |
6200 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6201 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6202 | |
6203 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6204 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6205 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6206 | } |
6207 | ||
19957bb3 | 6208 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6209 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6210 | return -EINVAL; |
636a5d36 | 6211 | |
e39e5b5e JM |
6212 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6213 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6214 | return -EINVAL; | |
6215 | ||
6216 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6217 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6218 | return -EINVAL; | |
6219 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6220 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6221 | /* need to include at least Auth Transaction and Status Code */ | |
6222 | if (sae_data_len < 4) | |
6223 | return -EINVAL; | |
6224 | } | |
6225 | ||
d5cdfacb JM |
6226 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6227 | ||
95de817b JB |
6228 | /* |
6229 | * Since we no longer track auth state, ignore | |
6230 | * requests to only change local state. | |
6231 | */ | |
6232 | if (local_state_change) | |
6233 | return 0; | |
6234 | ||
91bf9b26 JB |
6235 | wdev_lock(dev->ieee80211_ptr); |
6236 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6237 | ssid, ssid_len, ie, ie_len, | |
6238 | key.p.key, key.p.key_len, key.idx, | |
6239 | sae_data, sae_data_len); | |
6240 | wdev_unlock(dev->ieee80211_ptr); | |
6241 | return err; | |
636a5d36 JM |
6242 | } |
6243 | ||
c0692b8f JB |
6244 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6245 | struct genl_info *info, | |
3dc27d25 JB |
6246 | struct cfg80211_crypto_settings *settings, |
6247 | int cipher_limit) | |
b23aa676 | 6248 | { |
c0b2bbd8 JB |
6249 | memset(settings, 0, sizeof(*settings)); |
6250 | ||
b23aa676 SO |
6251 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6252 | ||
c0692b8f JB |
6253 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6254 | u16 proto; | |
6255 | proto = nla_get_u16( | |
6256 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6257 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6258 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6259 | proto != ETH_P_PAE) | |
6260 | return -EINVAL; | |
6261 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6262 | settings->control_port_no_encrypt = true; | |
6263 | } else | |
6264 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6265 | ||
b23aa676 SO |
6266 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6267 | void *data; | |
6268 | int len, i; | |
6269 | ||
6270 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6271 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6272 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6273 | ||
6274 | if (len % sizeof(u32)) | |
6275 | return -EINVAL; | |
6276 | ||
3dc27d25 | 6277 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6278 | return -EINVAL; |
6279 | ||
6280 | memcpy(settings->ciphers_pairwise, data, len); | |
6281 | ||
6282 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6283 | if (!cfg80211_supported_cipher_suite( |
6284 | &rdev->wiphy, | |
b23aa676 SO |
6285 | settings->ciphers_pairwise[i])) |
6286 | return -EINVAL; | |
6287 | } | |
6288 | ||
6289 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6290 | settings->cipher_group = | |
6291 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6292 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6293 | settings->cipher_group)) | |
b23aa676 SO |
6294 | return -EINVAL; |
6295 | } | |
6296 | ||
6297 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6298 | settings->wpa_versions = | |
6299 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6300 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6301 | return -EINVAL; | |
6302 | } | |
6303 | ||
6304 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6305 | void *data; | |
6d30240e | 6306 | int len; |
b23aa676 SO |
6307 | |
6308 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6309 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6310 | settings->n_akm_suites = len / sizeof(u32); | |
6311 | ||
6312 | if (len % sizeof(u32)) | |
6313 | return -EINVAL; | |
6314 | ||
1b9ca027 JM |
6315 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6316 | return -EINVAL; | |
6317 | ||
b23aa676 | 6318 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6319 | } |
6320 | ||
6321 | return 0; | |
6322 | } | |
6323 | ||
636a5d36 JM |
6324 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6325 | { | |
4c476991 JB |
6326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6327 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6328 | struct ieee80211_channel *chan; |
f62fab73 JB |
6329 | struct cfg80211_assoc_request req = {}; |
6330 | const u8 *bssid, *ssid; | |
6331 | int err, ssid_len = 0; | |
636a5d36 | 6332 | |
f4a11bb0 JB |
6333 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6334 | return -EINVAL; | |
6335 | ||
6336 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
6337 | !info->attrs[NL80211_ATTR_SSID] || |
6338 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
6339 | return -EINVAL; |
6340 | ||
4c476991 JB |
6341 | if (!rdev->ops->assoc) |
6342 | return -EOPNOTSUPP; | |
636a5d36 | 6343 | |
074ac8df | 6344 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6345 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6346 | return -EOPNOTSUPP; | |
eec60b03 | 6347 | |
19957bb3 | 6348 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6349 | |
19957bb3 JB |
6350 | chan = ieee80211_get_channel(&rdev->wiphy, |
6351 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
6352 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
6353 | return -EINVAL; | |
636a5d36 | 6354 | |
19957bb3 JB |
6355 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6356 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6357 | |
6358 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
6359 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6360 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6361 | } |
6362 | ||
dc6382ce | 6363 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 6364 | enum nl80211_mfp mfp = |
dc6382ce | 6365 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 6366 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 6367 | req.use_mfp = true; |
4c476991 JB |
6368 | else if (mfp != NL80211_MFP_NO) |
6369 | return -EINVAL; | |
dc6382ce JM |
6370 | } |
6371 | ||
3e5d7649 | 6372 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 6373 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 6374 | |
7e7c8926 | 6375 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 6376 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
6377 | |
6378 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
6379 | memcpy(&req.ht_capa_mask, |
6380 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6381 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
6382 | |
6383 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 6384 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 6385 | return -EINVAL; |
f62fab73 JB |
6386 | memcpy(&req.ht_capa, |
6387 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6388 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
6389 | } |
6390 | ||
ee2aca34 | 6391 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 6392 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
6393 | |
6394 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
6395 | memcpy(&req.vht_capa_mask, |
6396 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
6397 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
6398 | |
6399 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 6400 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 6401 | return -EINVAL; |
f62fab73 JB |
6402 | memcpy(&req.vht_capa, |
6403 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
6404 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
6405 | } |
6406 | ||
f62fab73 | 6407 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
6408 | if (!err) { |
6409 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
6410 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
6411 | ssid, ssid_len, &req); | |
91bf9b26 JB |
6412 | wdev_unlock(dev->ieee80211_ptr); |
6413 | } | |
636a5d36 | 6414 | |
636a5d36 JM |
6415 | return err; |
6416 | } | |
6417 | ||
6418 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
6419 | { | |
4c476991 JB |
6420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6421 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6422 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6423 | int ie_len = 0, err; |
19957bb3 | 6424 | u16 reason_code; |
d5cdfacb | 6425 | bool local_state_change; |
636a5d36 | 6426 | |
f4a11bb0 JB |
6427 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6428 | return -EINVAL; | |
6429 | ||
6430 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6431 | return -EINVAL; | |
6432 | ||
6433 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6434 | return -EINVAL; | |
6435 | ||
4c476991 JB |
6436 | if (!rdev->ops->deauth) |
6437 | return -EOPNOTSUPP; | |
636a5d36 | 6438 | |
074ac8df | 6439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6440 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6441 | return -EOPNOTSUPP; | |
eec60b03 | 6442 | |
19957bb3 | 6443 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6444 | |
19957bb3 JB |
6445 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6446 | if (reason_code == 0) { | |
f4a11bb0 | 6447 | /* Reason Code 0 is reserved */ |
4c476991 | 6448 | return -EINVAL; |
255e737e | 6449 | } |
636a5d36 JM |
6450 | |
6451 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6452 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6453 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6454 | } |
6455 | ||
d5cdfacb JM |
6456 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6457 | ||
91bf9b26 JB |
6458 | wdev_lock(dev->ieee80211_ptr); |
6459 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
6460 | local_state_change); | |
6461 | wdev_unlock(dev->ieee80211_ptr); | |
6462 | return err; | |
636a5d36 JM |
6463 | } |
6464 | ||
6465 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
6466 | { | |
4c476991 JB |
6467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6468 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6469 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 6470 | int ie_len = 0, err; |
19957bb3 | 6471 | u16 reason_code; |
d5cdfacb | 6472 | bool local_state_change; |
636a5d36 | 6473 | |
f4a11bb0 JB |
6474 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6475 | return -EINVAL; | |
6476 | ||
6477 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6478 | return -EINVAL; | |
6479 | ||
6480 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
6481 | return -EINVAL; | |
6482 | ||
4c476991 JB |
6483 | if (!rdev->ops->disassoc) |
6484 | return -EOPNOTSUPP; | |
636a5d36 | 6485 | |
074ac8df | 6486 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6487 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6488 | return -EOPNOTSUPP; | |
eec60b03 | 6489 | |
19957bb3 | 6490 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 6491 | |
19957bb3 JB |
6492 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
6493 | if (reason_code == 0) { | |
f4a11bb0 | 6494 | /* Reason Code 0 is reserved */ |
4c476991 | 6495 | return -EINVAL; |
255e737e | 6496 | } |
636a5d36 JM |
6497 | |
6498 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6499 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6500 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6501 | } |
6502 | ||
d5cdfacb JM |
6503 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6504 | ||
91bf9b26 JB |
6505 | wdev_lock(dev->ieee80211_ptr); |
6506 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
6507 | local_state_change); | |
6508 | wdev_unlock(dev->ieee80211_ptr); | |
6509 | return err; | |
636a5d36 JM |
6510 | } |
6511 | ||
dd5b4cc7 FF |
6512 | static bool |
6513 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
6514 | int mcast_rate[IEEE80211_NUM_BANDS], | |
6515 | int rateval) | |
6516 | { | |
6517 | struct wiphy *wiphy = &rdev->wiphy; | |
6518 | bool found = false; | |
6519 | int band, i; | |
6520 | ||
6521 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6522 | struct ieee80211_supported_band *sband; | |
6523 | ||
6524 | sband = wiphy->bands[band]; | |
6525 | if (!sband) | |
6526 | continue; | |
6527 | ||
6528 | for (i = 0; i < sband->n_bitrates; i++) { | |
6529 | if (sband->bitrates[i].bitrate == rateval) { | |
6530 | mcast_rate[band] = i + 1; | |
6531 | found = true; | |
6532 | break; | |
6533 | } | |
6534 | } | |
6535 | } | |
6536 | ||
6537 | return found; | |
6538 | } | |
6539 | ||
04a773ad JB |
6540 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
6541 | { | |
4c476991 JB |
6542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6543 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
6544 | struct cfg80211_ibss_params ibss; |
6545 | struct wiphy *wiphy; | |
fffd0934 | 6546 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
6547 | int err; |
6548 | ||
8e30bc55 JB |
6549 | memset(&ibss, 0, sizeof(ibss)); |
6550 | ||
04a773ad JB |
6551 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6552 | return -EINVAL; | |
6553 | ||
683b6d3b | 6554 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
6555 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
6556 | return -EINVAL; | |
6557 | ||
8e30bc55 JB |
6558 | ibss.beacon_interval = 100; |
6559 | ||
6560 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
6561 | ibss.beacon_interval = | |
6562 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
6563 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
6564 | return -EINVAL; | |
6565 | } | |
6566 | ||
4c476991 JB |
6567 | if (!rdev->ops->join_ibss) |
6568 | return -EOPNOTSUPP; | |
04a773ad | 6569 | |
4c476991 JB |
6570 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6571 | return -EOPNOTSUPP; | |
04a773ad | 6572 | |
79c97e97 | 6573 | wiphy = &rdev->wiphy; |
04a773ad | 6574 | |
39193498 | 6575 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 6576 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
6577 | |
6578 | if (!is_valid_ether_addr(ibss.bssid)) | |
6579 | return -EINVAL; | |
6580 | } | |
04a773ad JB |
6581 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6582 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6583 | ||
6584 | if (info->attrs[NL80211_ATTR_IE]) { | |
6585 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6586 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6587 | } | |
6588 | ||
683b6d3b JB |
6589 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
6590 | if (err) | |
6591 | return err; | |
04a773ad | 6592 | |
683b6d3b | 6593 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
54858ee5 AS |
6594 | return -EINVAL; |
6595 | ||
2f301ab2 | 6596 | switch (ibss.chandef.width) { |
bf372645 SW |
6597 | case NL80211_CHAN_WIDTH_5: |
6598 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
6599 | case NL80211_CHAN_WIDTH_20_NOHT: |
6600 | break; | |
6601 | case NL80211_CHAN_WIDTH_20: | |
6602 | case NL80211_CHAN_WIDTH_40: | |
6603 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) | |
6604 | break; | |
6605 | default: | |
c04d6150 | 6606 | return -EINVAL; |
2f301ab2 | 6607 | } |
db9c64cf | 6608 | |
04a773ad | 6609 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
6610 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
6611 | ||
fbd2c8dc TP |
6612 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
6613 | u8 *rates = | |
6614 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6615 | int n_rates = | |
6616 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
6617 | struct ieee80211_supported_band *sband = | |
683b6d3b | 6618 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 6619 | |
34850ab2 JB |
6620 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
6621 | &ibss.basic_rates); | |
6622 | if (err) | |
6623 | return err; | |
fbd2c8dc | 6624 | } |
dd5b4cc7 | 6625 | |
803768f5 SW |
6626 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
6627 | memcpy(&ibss.ht_capa_mask, | |
6628 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
6629 | sizeof(ibss.ht_capa_mask)); | |
6630 | ||
6631 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
6632 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
6633 | return -EINVAL; | |
6634 | memcpy(&ibss.ht_capa, | |
6635 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
6636 | sizeof(ibss.ht_capa)); | |
6637 | } | |
6638 | ||
dd5b4cc7 FF |
6639 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6640 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
6641 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6642 | return -EINVAL; | |
fbd2c8dc | 6643 | |
4c476991 | 6644 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
6645 | bool no_ht = false; |
6646 | ||
4c476991 | 6647 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
6648 | info->attrs[NL80211_ATTR_KEYS], |
6649 | &no_ht); | |
4c476991 JB |
6650 | if (IS_ERR(connkeys)) |
6651 | return PTR_ERR(connkeys); | |
de7044ee | 6652 | |
3d9d1d66 JB |
6653 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
6654 | no_ht) { | |
de7044ee SM |
6655 | kfree(connkeys); |
6656 | return -EINVAL; | |
6657 | } | |
4c476991 | 6658 | } |
04a773ad | 6659 | |
267335d6 AQ |
6660 | ibss.control_port = |
6661 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
6662 | ||
5336fa88 SW |
6663 | ibss.userspace_handles_dfs = |
6664 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
6665 | ||
4c476991 | 6666 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
6667 | if (err) |
6668 | kfree(connkeys); | |
04a773ad JB |
6669 | return err; |
6670 | } | |
6671 | ||
6672 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
6673 | { | |
4c476991 JB |
6674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6675 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 6676 | |
4c476991 JB |
6677 | if (!rdev->ops->leave_ibss) |
6678 | return -EOPNOTSUPP; | |
04a773ad | 6679 | |
4c476991 JB |
6680 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
6681 | return -EOPNOTSUPP; | |
04a773ad | 6682 | |
4c476991 | 6683 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
6684 | } |
6685 | ||
f4e583c8 AQ |
6686 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
6687 | { | |
6688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6689 | struct net_device *dev = info->user_ptr[1]; | |
6690 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
6691 | u32 nla_rate; | |
6692 | int err; | |
6693 | ||
6694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6695 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
6696 | return -EOPNOTSUPP; | |
6697 | ||
6698 | if (!rdev->ops->set_mcast_rate) | |
6699 | return -EOPNOTSUPP; | |
6700 | ||
6701 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
6702 | ||
6703 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
6704 | return -EINVAL; | |
6705 | ||
6706 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
6707 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
6708 | return -EINVAL; | |
6709 | ||
6710 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
6711 | ||
6712 | return err; | |
6713 | } | |
6714 | ||
ad7e718c JB |
6715 | static struct sk_buff * |
6716 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6717 | int approxlen, u32 portid, u32 seq, | |
6718 | enum nl80211_commands cmd, | |
567ffc35 JB |
6719 | enum nl80211_attrs attr, |
6720 | const struct nl80211_vendor_cmd_info *info, | |
6721 | gfp_t gfp) | |
ad7e718c JB |
6722 | { |
6723 | struct sk_buff *skb; | |
6724 | void *hdr; | |
6725 | struct nlattr *data; | |
6726 | ||
6727 | skb = nlmsg_new(approxlen + 100, gfp); | |
6728 | if (!skb) | |
6729 | return NULL; | |
6730 | ||
6731 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
6732 | if (!hdr) { | |
6733 | kfree_skb(skb); | |
6734 | return NULL; | |
6735 | } | |
6736 | ||
6737 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
6738 | goto nla_put_failure; | |
567ffc35 JB |
6739 | |
6740 | if (info) { | |
6741 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
6742 | info->vendor_id)) | |
6743 | goto nla_put_failure; | |
6744 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
6745 | info->subcmd)) | |
6746 | goto nla_put_failure; | |
6747 | } | |
6748 | ||
ad7e718c JB |
6749 | data = nla_nest_start(skb, attr); |
6750 | ||
6751 | ((void **)skb->cb)[0] = rdev; | |
6752 | ((void **)skb->cb)[1] = hdr; | |
6753 | ((void **)skb->cb)[2] = data; | |
6754 | ||
6755 | return skb; | |
6756 | ||
6757 | nla_put_failure: | |
6758 | kfree_skb(skb); | |
6759 | return NULL; | |
6760 | } | |
f4e583c8 | 6761 | |
e03ad6ea JB |
6762 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6763 | enum nl80211_commands cmd, | |
6764 | enum nl80211_attrs attr, | |
6765 | int vendor_event_idx, | |
6766 | int approxlen, gfp_t gfp) | |
6767 | { | |
6768 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6769 | const struct nl80211_vendor_cmd_info *info; | |
6770 | ||
6771 | switch (cmd) { | |
6772 | case NL80211_CMD_TESTMODE: | |
6773 | if (WARN_ON(vendor_event_idx != -1)) | |
6774 | return NULL; | |
6775 | info = NULL; | |
6776 | break; | |
6777 | case NL80211_CMD_VENDOR: | |
6778 | if (WARN_ON(vendor_event_idx < 0 || | |
6779 | vendor_event_idx >= wiphy->n_vendor_events)) | |
6780 | return NULL; | |
6781 | info = &wiphy->vendor_events[vendor_event_idx]; | |
6782 | break; | |
6783 | default: | |
6784 | WARN_ON(1); | |
6785 | return NULL; | |
6786 | } | |
6787 | ||
6788 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, | |
6789 | cmd, attr, info, gfp); | |
6790 | } | |
6791 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
6792 | ||
6793 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
6794 | { | |
6795 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
6796 | void *hdr = ((void **)skb->cb)[1]; | |
6797 | struct nlattr *data = ((void **)skb->cb)[2]; | |
6798 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
6799 | ||
6800 | nla_nest_end(skb, data); | |
6801 | genlmsg_end(skb, hdr); | |
6802 | ||
6803 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
6804 | mcgrp = NL80211_MCGRP_VENDOR; | |
6805 | ||
6806 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
6807 | mcgrp, gfp); | |
6808 | } | |
6809 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
6810 | ||
aff89a9b | 6811 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
6812 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
6813 | { | |
4c476991 | 6814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
6815 | struct wireless_dev *wdev = |
6816 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
6817 | int err; |
6818 | ||
fc73f11f DS |
6819 | if (!rdev->ops->testmode_cmd) |
6820 | return -EOPNOTSUPP; | |
6821 | ||
6822 | if (IS_ERR(wdev)) { | |
6823 | err = PTR_ERR(wdev); | |
6824 | if (err != -EINVAL) | |
6825 | return err; | |
6826 | wdev = NULL; | |
6827 | } else if (wdev->wiphy != &rdev->wiphy) { | |
6828 | return -EINVAL; | |
6829 | } | |
6830 | ||
aff89a9b JB |
6831 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
6832 | return -EINVAL; | |
6833 | ||
ad7e718c | 6834 | rdev->cur_cmd_info = info; |
fc73f11f | 6835 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
6836 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
6837 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 6838 | rdev->cur_cmd_info = NULL; |
aff89a9b | 6839 | |
aff89a9b JB |
6840 | return err; |
6841 | } | |
6842 | ||
71063f0e WYG |
6843 | static int nl80211_testmode_dump(struct sk_buff *skb, |
6844 | struct netlink_callback *cb) | |
6845 | { | |
00918d33 | 6846 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
6847 | int err; |
6848 | long phy_idx; | |
6849 | void *data = NULL; | |
6850 | int data_len = 0; | |
6851 | ||
5fe231e8 JB |
6852 | rtnl_lock(); |
6853 | ||
71063f0e WYG |
6854 | if (cb->args[0]) { |
6855 | /* | |
6856 | * 0 is a valid index, but not valid for args[0], | |
6857 | * so we need to offset by 1. | |
6858 | */ | |
6859 | phy_idx = cb->args[0] - 1; | |
6860 | } else { | |
6861 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
6862 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
6863 | nl80211_policy); | |
6864 | if (err) | |
5fe231e8 | 6865 | goto out_err; |
00918d33 | 6866 | |
2bd7e35d JB |
6867 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
6868 | nl80211_fam.attrbuf); | |
6869 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
6870 | err = PTR_ERR(rdev); |
6871 | goto out_err; | |
00918d33 | 6872 | } |
2bd7e35d JB |
6873 | phy_idx = rdev->wiphy_idx; |
6874 | rdev = NULL; | |
2bd7e35d | 6875 | |
71063f0e WYG |
6876 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
6877 | cb->args[1] = | |
6878 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
6879 | } | |
6880 | ||
6881 | if (cb->args[1]) { | |
6882 | data = nla_data((void *)cb->args[1]); | |
6883 | data_len = nla_len((void *)cb->args[1]); | |
6884 | } | |
6885 | ||
00918d33 JB |
6886 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
6887 | if (!rdev) { | |
5fe231e8 JB |
6888 | err = -ENOENT; |
6889 | goto out_err; | |
71063f0e | 6890 | } |
71063f0e | 6891 | |
00918d33 | 6892 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
6893 | err = -EOPNOTSUPP; |
6894 | goto out_err; | |
6895 | } | |
6896 | ||
6897 | while (1) { | |
15e47304 | 6898 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
6899 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
6900 | NL80211_CMD_TESTMODE); | |
6901 | struct nlattr *tmdata; | |
6902 | ||
cb35fba3 DC |
6903 | if (!hdr) |
6904 | break; | |
6905 | ||
9360ffd1 | 6906 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
6907 | genlmsg_cancel(skb, hdr); |
6908 | break; | |
6909 | } | |
6910 | ||
6911 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
6912 | if (!tmdata) { | |
6913 | genlmsg_cancel(skb, hdr); | |
6914 | break; | |
6915 | } | |
e35e4d28 | 6916 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
6917 | nla_nest_end(skb, tmdata); |
6918 | ||
6919 | if (err == -ENOBUFS || err == -ENOENT) { | |
6920 | genlmsg_cancel(skb, hdr); | |
6921 | break; | |
6922 | } else if (err) { | |
6923 | genlmsg_cancel(skb, hdr); | |
6924 | goto out_err; | |
6925 | } | |
6926 | ||
6927 | genlmsg_end(skb, hdr); | |
6928 | } | |
6929 | ||
6930 | err = skb->len; | |
6931 | /* see above */ | |
6932 | cb->args[0] = phy_idx + 1; | |
6933 | out_err: | |
5fe231e8 | 6934 | rtnl_unlock(); |
71063f0e WYG |
6935 | return err; |
6936 | } | |
aff89a9b JB |
6937 | #endif |
6938 | ||
b23aa676 SO |
6939 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
6940 | { | |
4c476991 JB |
6941 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6942 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
6943 | struct cfg80211_connect_params connect; |
6944 | struct wiphy *wiphy; | |
fffd0934 | 6945 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
6946 | int err; |
6947 | ||
6948 | memset(&connect, 0, sizeof(connect)); | |
6949 | ||
6950 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
6951 | return -EINVAL; | |
6952 | ||
6953 | if (!info->attrs[NL80211_ATTR_SSID] || | |
6954 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
6955 | return -EINVAL; | |
6956 | ||
6957 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
6958 | connect.auth_type = | |
6959 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
6960 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
6961 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
6962 | return -EINVAL; |
6963 | } else | |
6964 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
6965 | ||
6966 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
6967 | ||
c0692b8f | 6968 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 6969 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
6970 | if (err) |
6971 | return err; | |
b23aa676 | 6972 | |
074ac8df | 6973 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6974 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6975 | return -EOPNOTSUPP; | |
b23aa676 | 6976 | |
79c97e97 | 6977 | wiphy = &rdev->wiphy; |
b23aa676 | 6978 | |
4486ea98 BS |
6979 | connect.bg_scan_period = -1; |
6980 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
6981 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
6982 | connect.bg_scan_period = | |
6983 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
6984 | } | |
6985 | ||
b23aa676 SO |
6986 | if (info->attrs[NL80211_ATTR_MAC]) |
6987 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6988 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
6989 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
6990 | ||
6991 | if (info->attrs[NL80211_ATTR_IE]) { | |
6992 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
6993 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6994 | } | |
6995 | ||
cee00a95 JM |
6996 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
6997 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
6998 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
6999 | connect.mfp != NL80211_MFP_NO) | |
7000 | return -EINVAL; | |
7001 | } else { | |
7002 | connect.mfp = NL80211_MFP_NO; | |
7003 | } | |
7004 | ||
b23aa676 SO |
7005 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
7006 | connect.channel = | |
7007 | ieee80211_get_channel(wiphy, | |
7008 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
7009 | if (!connect.channel || | |
4c476991 JB |
7010 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
7011 | return -EINVAL; | |
b23aa676 SO |
7012 | } |
7013 | ||
fffd0934 JB |
7014 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7015 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7016 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7017 | if (IS_ERR(connkeys)) |
7018 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7019 | } |
7020 | ||
7e7c8926 BG |
7021 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7022 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7023 | ||
7024 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7025 | memcpy(&connect.ht_capa_mask, | |
7026 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7027 | sizeof(connect.ht_capa_mask)); | |
7028 | ||
7029 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e WY |
7030 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
7031 | kfree(connkeys); | |
7e7c8926 | 7032 | return -EINVAL; |
b4e4f47e | 7033 | } |
7e7c8926 BG |
7034 | memcpy(&connect.ht_capa, |
7035 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7036 | sizeof(connect.ht_capa)); | |
7037 | } | |
7038 | ||
ee2aca34 JB |
7039 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7040 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7041 | ||
7042 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7043 | memcpy(&connect.vht_capa_mask, | |
7044 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7045 | sizeof(connect.vht_capa_mask)); | |
7046 | ||
7047 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7048 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
7049 | kfree(connkeys); | |
7050 | return -EINVAL; | |
7051 | } | |
7052 | memcpy(&connect.vht_capa, | |
7053 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7054 | sizeof(connect.vht_capa)); | |
7055 | } | |
7056 | ||
83739b03 JB |
7057 | wdev_lock(dev->ieee80211_ptr); |
7058 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7059 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 JB |
7060 | if (err) |
7061 | kfree(connkeys); | |
b23aa676 SO |
7062 | return err; |
7063 | } | |
7064 | ||
7065 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7066 | { | |
4c476991 JB |
7067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7068 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7069 | u16 reason; |
83739b03 | 7070 | int ret; |
b23aa676 SO |
7071 | |
7072 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7073 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7074 | else | |
7075 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7076 | ||
7077 | if (reason == 0) | |
7078 | return -EINVAL; | |
7079 | ||
074ac8df | 7080 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7081 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7082 | return -EOPNOTSUPP; | |
b23aa676 | 7083 | |
83739b03 JB |
7084 | wdev_lock(dev->ieee80211_ptr); |
7085 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7086 | wdev_unlock(dev->ieee80211_ptr); | |
7087 | return ret; | |
b23aa676 SO |
7088 | } |
7089 | ||
463d0183 JB |
7090 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7091 | { | |
4c476991 | 7092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7093 | struct net *net; |
7094 | int err; | |
7095 | u32 pid; | |
7096 | ||
7097 | if (!info->attrs[NL80211_ATTR_PID]) | |
7098 | return -EINVAL; | |
7099 | ||
7100 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7101 | ||
463d0183 | 7102 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
7103 | if (IS_ERR(net)) |
7104 | return PTR_ERR(net); | |
463d0183 JB |
7105 | |
7106 | err = 0; | |
7107 | ||
7108 | /* check if anything to do */ | |
4c476991 JB |
7109 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7110 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7111 | |
463d0183 | 7112 | put_net(net); |
463d0183 JB |
7113 | return err; |
7114 | } | |
7115 | ||
67fbb16b SO |
7116 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7117 | { | |
4c476991 | 7118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7119 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7120 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7121 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7122 | struct cfg80211_pmksa pmksa; |
7123 | ||
7124 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7125 | ||
7126 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7127 | return -EINVAL; | |
7128 | ||
7129 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7130 | return -EINVAL; | |
7131 | ||
67fbb16b SO |
7132 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7133 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7134 | ||
074ac8df | 7135 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7136 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7137 | return -EOPNOTSUPP; | |
67fbb16b SO |
7138 | |
7139 | switch (info->genlhdr->cmd) { | |
7140 | case NL80211_CMD_SET_PMKSA: | |
7141 | rdev_ops = rdev->ops->set_pmksa; | |
7142 | break; | |
7143 | case NL80211_CMD_DEL_PMKSA: | |
7144 | rdev_ops = rdev->ops->del_pmksa; | |
7145 | break; | |
7146 | default: | |
7147 | WARN_ON(1); | |
7148 | break; | |
7149 | } | |
7150 | ||
4c476991 JB |
7151 | if (!rdev_ops) |
7152 | return -EOPNOTSUPP; | |
67fbb16b | 7153 | |
4c476991 | 7154 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7155 | } |
7156 | ||
7157 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7158 | { | |
4c476991 JB |
7159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7160 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7161 | |
074ac8df | 7162 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7163 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7164 | return -EOPNOTSUPP; | |
67fbb16b | 7165 | |
4c476991 JB |
7166 | if (!rdev->ops->flush_pmksa) |
7167 | return -EOPNOTSUPP; | |
67fbb16b | 7168 | |
e35e4d28 | 7169 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7170 | } |
7171 | ||
109086ce AN |
7172 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7173 | { | |
7174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7175 | struct net_device *dev = info->user_ptr[1]; | |
7176 | u8 action_code, dialog_token; | |
7177 | u16 status_code; | |
7178 | u8 *peer; | |
7179 | ||
7180 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7181 | !rdev->ops->tdls_mgmt) | |
7182 | return -EOPNOTSUPP; | |
7183 | ||
7184 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7185 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7186 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7187 | !info->attrs[NL80211_ATTR_IE] || | |
7188 | !info->attrs[NL80211_ATTR_MAC]) | |
7189 | return -EINVAL; | |
7190 | ||
7191 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7192 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7193 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7194 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
7195 | ||
e35e4d28 HG |
7196 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
7197 | dialog_token, status_code, | |
7198 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
7199 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7200 | } |
7201 | ||
7202 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7203 | { | |
7204 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7205 | struct net_device *dev = info->user_ptr[1]; | |
7206 | enum nl80211_tdls_operation operation; | |
7207 | u8 *peer; | |
7208 | ||
7209 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7210 | !rdev->ops->tdls_oper) | |
7211 | return -EOPNOTSUPP; | |
7212 | ||
7213 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7214 | !info->attrs[NL80211_ATTR_MAC]) | |
7215 | return -EINVAL; | |
7216 | ||
7217 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7218 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7219 | ||
e35e4d28 | 7220 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7221 | } |
7222 | ||
9588bbd5 JM |
7223 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7224 | struct genl_info *info) | |
7225 | { | |
4c476991 | 7226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7227 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7228 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7229 | struct sk_buff *msg; |
7230 | void *hdr; | |
7231 | u64 cookie; | |
683b6d3b | 7232 | u32 duration; |
9588bbd5 JM |
7233 | int err; |
7234 | ||
7235 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7236 | !info->attrs[NL80211_ATTR_DURATION]) | |
7237 | return -EINVAL; | |
7238 | ||
7239 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7240 | ||
ebf348fc JB |
7241 | if (!rdev->ops->remain_on_channel || |
7242 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7243 | return -EOPNOTSUPP; | |
7244 | ||
9588bbd5 | 7245 | /* |
ebf348fc JB |
7246 | * We should be on that channel for at least a minimum amount of |
7247 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7248 | */ |
ebf348fc | 7249 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7250 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7251 | return -EINVAL; |
7252 | ||
683b6d3b JB |
7253 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7254 | if (err) | |
7255 | return err; | |
9588bbd5 JM |
7256 | |
7257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7258 | if (!msg) |
7259 | return -ENOMEM; | |
9588bbd5 | 7260 | |
15e47304 | 7261 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7262 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7263 | if (!hdr) { |
7264 | err = -ENOBUFS; | |
9588bbd5 JM |
7265 | goto free_msg; |
7266 | } | |
7267 | ||
683b6d3b JB |
7268 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7269 | duration, &cookie); | |
9588bbd5 JM |
7270 | |
7271 | if (err) | |
7272 | goto free_msg; | |
7273 | ||
9360ffd1 DM |
7274 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7275 | goto nla_put_failure; | |
9588bbd5 JM |
7276 | |
7277 | genlmsg_end(msg, hdr); | |
4c476991 JB |
7278 | |
7279 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
7280 | |
7281 | nla_put_failure: | |
7282 | err = -ENOBUFS; | |
7283 | free_msg: | |
7284 | nlmsg_free(msg); | |
9588bbd5 JM |
7285 | return err; |
7286 | } | |
7287 | ||
7288 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
7289 | struct genl_info *info) | |
7290 | { | |
4c476991 | 7291 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7292 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 7293 | u64 cookie; |
9588bbd5 JM |
7294 | |
7295 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7296 | return -EINVAL; | |
7297 | ||
4c476991 JB |
7298 | if (!rdev->ops->cancel_remain_on_channel) |
7299 | return -EOPNOTSUPP; | |
9588bbd5 | 7300 | |
9588bbd5 JM |
7301 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
7302 | ||
e35e4d28 | 7303 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
7304 | } |
7305 | ||
13ae75b1 JM |
7306 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
7307 | u8 *rates, u8 rates_len) | |
7308 | { | |
7309 | u8 i; | |
7310 | u32 mask = 0; | |
7311 | ||
7312 | for (i = 0; i < rates_len; i++) { | |
7313 | int rate = (rates[i] & 0x7f) * 5; | |
7314 | int ridx; | |
7315 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
7316 | struct ieee80211_rate *srate = | |
7317 | &sband->bitrates[ridx]; | |
7318 | if (rate == srate->bitrate) { | |
7319 | mask |= 1 << ridx; | |
7320 | break; | |
7321 | } | |
7322 | } | |
7323 | if (ridx == sband->n_bitrates) | |
7324 | return 0; /* rate not found */ | |
7325 | } | |
7326 | ||
7327 | return mask; | |
7328 | } | |
7329 | ||
24db78c0 SW |
7330 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
7331 | u8 *rates, u8 rates_len, | |
7332 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
7333 | { | |
7334 | u8 i; | |
7335 | ||
7336 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
7337 | ||
7338 | for (i = 0; i < rates_len; i++) { | |
7339 | int ridx, rbit; | |
7340 | ||
7341 | ridx = rates[i] / 8; | |
7342 | rbit = BIT(rates[i] % 8); | |
7343 | ||
7344 | /* check validity */ | |
910570b5 | 7345 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
7346 | return false; |
7347 | ||
7348 | /* check availability */ | |
7349 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
7350 | mcs[ridx] |= rbit; | |
7351 | else | |
7352 | return false; | |
7353 | } | |
7354 | ||
7355 | return true; | |
7356 | } | |
7357 | ||
204e35a9 JD |
7358 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
7359 | { | |
7360 | u16 mcs_mask = 0; | |
7361 | ||
7362 | switch (vht_mcs_map) { | |
7363 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
7364 | break; | |
7365 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
7366 | mcs_mask = 0x00FF; | |
7367 | break; | |
7368 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
7369 | mcs_mask = 0x01FF; | |
7370 | break; | |
7371 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
7372 | mcs_mask = 0x03FF; | |
7373 | break; | |
7374 | default: | |
7375 | break; | |
7376 | } | |
7377 | ||
7378 | return mcs_mask; | |
7379 | } | |
7380 | ||
7381 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
7382 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
7383 | { | |
7384 | u8 nss; | |
7385 | ||
7386 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
7387 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
7388 | vht_mcs_map >>= 2; | |
7389 | } | |
7390 | } | |
7391 | ||
7392 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
7393 | struct nl80211_txrate_vht *txrate, | |
7394 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
7395 | { | |
7396 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7397 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
7398 | u8 i; | |
7399 | ||
7400 | if (!sband->vht_cap.vht_supported) | |
7401 | return false; | |
7402 | ||
7403 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
7404 | ||
7405 | /* Build vht_mcs_mask from VHT capabilities */ | |
7406 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
7407 | ||
7408 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
7409 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
7410 | mcs[i] = txrate->mcs[i]; | |
7411 | else | |
7412 | return false; | |
7413 | } | |
7414 | ||
7415 | return true; | |
7416 | } | |
7417 | ||
b54452b0 | 7418 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
7419 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
7420 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
7421 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
7422 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 7423 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
13ae75b1 JM |
7424 | }; |
7425 | ||
7426 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
7427 | struct genl_info *info) | |
7428 | { | |
7429 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 7430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 7431 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
7432 | int rem, i; |
7433 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
7434 | struct nlattr *tx_rates; |
7435 | struct ieee80211_supported_band *sband; | |
204e35a9 | 7436 | u16 vht_tx_mcs_map; |
13ae75b1 | 7437 | |
4c476991 JB |
7438 | if (!rdev->ops->set_bitrate_mask) |
7439 | return -EOPNOTSUPP; | |
13ae75b1 JM |
7440 | |
7441 | memset(&mask, 0, sizeof(mask)); | |
7442 | /* Default to all rates enabled */ | |
7443 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
7444 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
7445 | |
7446 | if (!sband) | |
7447 | continue; | |
7448 | ||
7449 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 7450 | memcpy(mask.control[i].ht_mcs, |
7869303b | 7451 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 7452 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
7453 | |
7454 | if (!sband->vht_cap.vht_supported) | |
7455 | continue; | |
7456 | ||
7457 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
7458 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
7459 | } |
7460 | ||
b9243ab0 JD |
7461 | /* if no rates are given set it back to the defaults */ |
7462 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
7463 | goto out; | |
7464 | ||
13ae75b1 JM |
7465 | /* |
7466 | * The nested attribute uses enum nl80211_band as the index. This maps | |
7467 | * directly to the enum ieee80211_band values used in cfg80211. | |
7468 | */ | |
24db78c0 | 7469 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
7470 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
7471 | { | |
7472 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
7473 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
7474 | return -EINVAL; | |
13ae75b1 | 7475 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
7476 | if (sband == NULL) |
7477 | return -EINVAL; | |
13ae75b1 JM |
7478 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
7479 | nla_len(tx_rates), nl80211_txattr_policy); | |
7480 | if (tb[NL80211_TXRATE_LEGACY]) { | |
7481 | mask.control[band].legacy = rateset_to_mask( | |
7482 | sband, | |
7483 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
7484 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
7485 | if ((mask.control[band].legacy == 0) && |
7486 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
7487 | return -EINVAL; | |
24db78c0 | 7488 | } |
d1e33e65 | 7489 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
7490 | if (!ht_rateset_to_mask( |
7491 | sband, | |
d1e33e65 JD |
7492 | nla_data(tb[NL80211_TXRATE_HT]), |
7493 | nla_len(tb[NL80211_TXRATE_HT]), | |
7494 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
7495 | return -EINVAL; |
7496 | } | |
204e35a9 JD |
7497 | if (tb[NL80211_TXRATE_VHT]) { |
7498 | if (!vht_set_mcs_mask( | |
7499 | sband, | |
7500 | nla_data(tb[NL80211_TXRATE_VHT]), | |
7501 | mask.control[band].vht_mcs)) | |
7502 | return -EINVAL; | |
7503 | } | |
24db78c0 SW |
7504 | |
7505 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
7506 | /* don't allow empty legacy rates if HT or VHT |
7507 | * are not even supported. | |
7508 | */ | |
7509 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
7510 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
7511 | return -EINVAL; |
7512 | ||
7513 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 7514 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
7515 | goto out; |
7516 | ||
7517 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
7518 | if (mask.control[band].vht_mcs[i]) | |
7519 | goto out; | |
24db78c0 SW |
7520 | |
7521 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 7522 | return -EINVAL; |
13ae75b1 JM |
7523 | } |
7524 | } | |
7525 | ||
b9243ab0 | 7526 | out: |
e35e4d28 | 7527 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
7528 | } |
7529 | ||
2e161f78 | 7530 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7531 | { |
4c476991 | 7532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7533 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 7534 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
7535 | |
7536 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
7537 | return -EINVAL; | |
7538 | ||
2e161f78 JB |
7539 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
7540 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 7541 | |
71bbc994 JB |
7542 | switch (wdev->iftype) { |
7543 | case NL80211_IFTYPE_STATION: | |
7544 | case NL80211_IFTYPE_ADHOC: | |
7545 | case NL80211_IFTYPE_P2P_CLIENT: | |
7546 | case NL80211_IFTYPE_AP: | |
7547 | case NL80211_IFTYPE_AP_VLAN: | |
7548 | case NL80211_IFTYPE_MESH_POINT: | |
7549 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7550 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7551 | break; |
7552 | default: | |
4c476991 | 7553 | return -EOPNOTSUPP; |
71bbc994 | 7554 | } |
026331c4 JM |
7555 | |
7556 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
7557 | if (!rdev->ops->mgmt_tx) |
7558 | return -EOPNOTSUPP; | |
026331c4 | 7559 | |
15e47304 | 7560 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
7561 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
7562 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
7563 | } |
7564 | ||
2e161f78 | 7565 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 7566 | { |
4c476991 | 7567 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7568 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7569 | struct cfg80211_chan_def chandef; |
026331c4 | 7570 | int err; |
d64d373f | 7571 | void *hdr = NULL; |
026331c4 | 7572 | u64 cookie; |
e247bd90 | 7573 | struct sk_buff *msg = NULL; |
b176e629 AO |
7574 | struct cfg80211_mgmt_tx_params params = { |
7575 | .dont_wait_for_ack = | |
7576 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
7577 | }; | |
026331c4 | 7578 | |
683b6d3b | 7579 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
7580 | return -EINVAL; |
7581 | ||
4c476991 JB |
7582 | if (!rdev->ops->mgmt_tx) |
7583 | return -EOPNOTSUPP; | |
026331c4 | 7584 | |
71bbc994 | 7585 | switch (wdev->iftype) { |
ea141b75 AQ |
7586 | case NL80211_IFTYPE_P2P_DEVICE: |
7587 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7588 | return -EINVAL; | |
71bbc994 JB |
7589 | case NL80211_IFTYPE_STATION: |
7590 | case NL80211_IFTYPE_ADHOC: | |
7591 | case NL80211_IFTYPE_P2P_CLIENT: | |
7592 | case NL80211_IFTYPE_AP: | |
7593 | case NL80211_IFTYPE_AP_VLAN: | |
7594 | case NL80211_IFTYPE_MESH_POINT: | |
7595 | case NL80211_IFTYPE_P2P_GO: | |
7596 | break; | |
7597 | default: | |
4c476991 | 7598 | return -EOPNOTSUPP; |
71bbc994 | 7599 | } |
026331c4 | 7600 | |
f7ca38df | 7601 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 7602 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 7603 | return -EINVAL; |
b176e629 | 7604 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
7605 | |
7606 | /* | |
7607 | * We should wait on the channel for at least a minimum amount | |
7608 | * of time (10ms) but no longer than the driver supports. | |
7609 | */ | |
b176e629 AO |
7610 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
7611 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
7612 | return -EINVAL; |
7613 | ||
f7ca38df JB |
7614 | } |
7615 | ||
b176e629 | 7616 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 7617 | |
b176e629 | 7618 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
7619 | return -EINVAL; |
7620 | ||
b176e629 | 7621 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 7622 | |
ea141b75 AQ |
7623 | /* get the channel if any has been specified, otherwise pass NULL to |
7624 | * the driver. The latter will use the current one | |
7625 | */ | |
7626 | chandef.chan = NULL; | |
7627 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
7628 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
7629 | if (err) | |
7630 | return err; | |
7631 | } | |
7632 | ||
b176e629 | 7633 | if (!chandef.chan && params.offchan) |
ea141b75 | 7634 | return -EINVAL; |
026331c4 | 7635 | |
b176e629 | 7636 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
7637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
7638 | if (!msg) | |
7639 | return -ENOMEM; | |
026331c4 | 7640 | |
15e47304 | 7641 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 7642 | NL80211_CMD_FRAME); |
cb35fba3 DC |
7643 | if (!hdr) { |
7644 | err = -ENOBUFS; | |
e247bd90 JB |
7645 | goto free_msg; |
7646 | } | |
026331c4 | 7647 | } |
e247bd90 | 7648 | |
b176e629 AO |
7649 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
7650 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
7651 | params.chan = chandef.chan; | |
7652 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
7653 | if (err) |
7654 | goto free_msg; | |
7655 | ||
e247bd90 | 7656 | if (msg) { |
9360ffd1 DM |
7657 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
7658 | goto nla_put_failure; | |
026331c4 | 7659 | |
e247bd90 JB |
7660 | genlmsg_end(msg, hdr); |
7661 | return genlmsg_reply(msg, info); | |
7662 | } | |
7663 | ||
7664 | return 0; | |
026331c4 JM |
7665 | |
7666 | nla_put_failure: | |
7667 | err = -ENOBUFS; | |
7668 | free_msg: | |
7669 | nlmsg_free(msg); | |
026331c4 JM |
7670 | return err; |
7671 | } | |
7672 | ||
f7ca38df JB |
7673 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
7674 | { | |
7675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 7676 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
7677 | u64 cookie; |
7678 | ||
7679 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
7680 | return -EINVAL; | |
7681 | ||
7682 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
7683 | return -EOPNOTSUPP; | |
7684 | ||
71bbc994 JB |
7685 | switch (wdev->iftype) { |
7686 | case NL80211_IFTYPE_STATION: | |
7687 | case NL80211_IFTYPE_ADHOC: | |
7688 | case NL80211_IFTYPE_P2P_CLIENT: | |
7689 | case NL80211_IFTYPE_AP: | |
7690 | case NL80211_IFTYPE_AP_VLAN: | |
7691 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 7692 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
7693 | break; |
7694 | default: | |
f7ca38df | 7695 | return -EOPNOTSUPP; |
71bbc994 | 7696 | } |
f7ca38df JB |
7697 | |
7698 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7699 | ||
e35e4d28 | 7700 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
7701 | } |
7702 | ||
ffb9eb3d KV |
7703 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
7704 | { | |
4c476991 | 7705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 7706 | struct wireless_dev *wdev; |
4c476991 | 7707 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7708 | u8 ps_state; |
7709 | bool state; | |
7710 | int err; | |
7711 | ||
4c476991 JB |
7712 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
7713 | return -EINVAL; | |
ffb9eb3d KV |
7714 | |
7715 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
7716 | ||
4c476991 JB |
7717 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
7718 | return -EINVAL; | |
ffb9eb3d KV |
7719 | |
7720 | wdev = dev->ieee80211_ptr; | |
7721 | ||
4c476991 JB |
7722 | if (!rdev->ops->set_power_mgmt) |
7723 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7724 | |
7725 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
7726 | ||
7727 | if (state == wdev->ps) | |
4c476991 | 7728 | return 0; |
ffb9eb3d | 7729 | |
e35e4d28 | 7730 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
7731 | if (!err) |
7732 | wdev->ps = state; | |
ffb9eb3d KV |
7733 | return err; |
7734 | } | |
7735 | ||
7736 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
7737 | { | |
4c476991 | 7738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
7739 | enum nl80211_ps_state ps_state; |
7740 | struct wireless_dev *wdev; | |
4c476991 | 7741 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
7742 | struct sk_buff *msg; |
7743 | void *hdr; | |
7744 | int err; | |
7745 | ||
ffb9eb3d KV |
7746 | wdev = dev->ieee80211_ptr; |
7747 | ||
4c476991 JB |
7748 | if (!rdev->ops->set_power_mgmt) |
7749 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
7750 | |
7751 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7752 | if (!msg) |
7753 | return -ENOMEM; | |
ffb9eb3d | 7754 | |
15e47304 | 7755 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
7756 | NL80211_CMD_GET_POWER_SAVE); |
7757 | if (!hdr) { | |
4c476991 | 7758 | err = -ENOBUFS; |
ffb9eb3d KV |
7759 | goto free_msg; |
7760 | } | |
7761 | ||
7762 | if (wdev->ps) | |
7763 | ps_state = NL80211_PS_ENABLED; | |
7764 | else | |
7765 | ps_state = NL80211_PS_DISABLED; | |
7766 | ||
9360ffd1 DM |
7767 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
7768 | goto nla_put_failure; | |
ffb9eb3d KV |
7769 | |
7770 | genlmsg_end(msg, hdr); | |
4c476991 | 7771 | return genlmsg_reply(msg, info); |
ffb9eb3d | 7772 | |
4c476991 | 7773 | nla_put_failure: |
ffb9eb3d | 7774 | err = -ENOBUFS; |
4c476991 | 7775 | free_msg: |
ffb9eb3d | 7776 | nlmsg_free(msg); |
ffb9eb3d KV |
7777 | return err; |
7778 | } | |
7779 | ||
d6dc1a38 JO |
7780 | static struct nla_policy |
7781 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
7782 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
7783 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
7784 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
7785 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
7786 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
7787 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
7788 | }; |
7789 | ||
84f10708 | 7790 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 7791 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
7792 | { |
7793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 7794 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7795 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 7796 | |
d9d8b019 | 7797 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
7798 | return -EINVAL; |
7799 | ||
84f10708 TP |
7800 | if (!rdev->ops->set_cqm_txe_config) |
7801 | return -EOPNOTSUPP; | |
7802 | ||
7803 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
7804 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
7805 | return -EOPNOTSUPP; | |
7806 | ||
e35e4d28 | 7807 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
7808 | } |
7809 | ||
d6dc1a38 JO |
7810 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
7811 | s32 threshold, u32 hysteresis) | |
7812 | { | |
4c476991 | 7813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 7814 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 7815 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
7816 | |
7817 | if (threshold > 0) | |
7818 | return -EINVAL; | |
7819 | ||
1da5fcc8 JB |
7820 | /* disabling - hysteresis should also be zero then */ |
7821 | if (threshold == 0) | |
7822 | hysteresis = 0; | |
d6dc1a38 | 7823 | |
4c476991 JB |
7824 | if (!rdev->ops->set_cqm_rssi_config) |
7825 | return -EOPNOTSUPP; | |
d6dc1a38 | 7826 | |
074ac8df | 7827 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7828 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7829 | return -EOPNOTSUPP; | |
d6dc1a38 | 7830 | |
e35e4d28 | 7831 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
7832 | } |
7833 | ||
7834 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
7835 | { | |
7836 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
7837 | struct nlattr *cqm; | |
7838 | int err; | |
7839 | ||
7840 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
7841 | if (!cqm) |
7842 | return -EINVAL; | |
d6dc1a38 JO |
7843 | |
7844 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
7845 | nl80211_attr_cqm_policy); | |
7846 | if (err) | |
1da5fcc8 | 7847 | return err; |
d6dc1a38 JO |
7848 | |
7849 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
7850 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
7851 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
7852 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 7853 | |
1da5fcc8 JB |
7854 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
7855 | } | |
7856 | ||
7857 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
7858 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
7859 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
7860 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
7861 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
7862 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
7863 | ||
7864 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
7865 | } | |
7866 | ||
7867 | return -EINVAL; | |
d6dc1a38 JO |
7868 | } |
7869 | ||
29cbe68c JB |
7870 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
7871 | { | |
7872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7873 | struct net_device *dev = info->user_ptr[1]; | |
7874 | struct mesh_config cfg; | |
c80d545d | 7875 | struct mesh_setup setup; |
29cbe68c JB |
7876 | int err; |
7877 | ||
7878 | /* start with default */ | |
7879 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 7880 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 7881 | |
24bdd9f4 | 7882 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 7883 | /* and parse parameters if given */ |
24bdd9f4 | 7884 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
7885 | if (err) |
7886 | return err; | |
7887 | } | |
7888 | ||
7889 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
7890 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
7891 | return -EINVAL; | |
7892 | ||
c80d545d JC |
7893 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
7894 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
7895 | ||
4bb62344 CYY |
7896 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7897 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
7898 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7899 | return -EINVAL; | |
7900 | ||
9bdbf04d MP |
7901 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
7902 | setup.beacon_interval = | |
7903 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7904 | if (setup.beacon_interval < 10 || | |
7905 | setup.beacon_interval > 10000) | |
7906 | return -EINVAL; | |
7907 | } | |
7908 | ||
7909 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
7910 | setup.dtim_period = | |
7911 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
7912 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
7913 | return -EINVAL; | |
7914 | } | |
7915 | ||
c80d545d JC |
7916 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
7917 | /* parse additional setup parameters if given */ | |
7918 | err = nl80211_parse_mesh_setup(info, &setup); | |
7919 | if (err) | |
7920 | return err; | |
7921 | } | |
7922 | ||
d37bb18a TP |
7923 | if (setup.user_mpm) |
7924 | cfg.auto_open_plinks = false; | |
7925 | ||
cc1d2806 | 7926 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
7927 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
7928 | if (err) | |
7929 | return err; | |
cc1d2806 JB |
7930 | } else { |
7931 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 7932 | setup.chandef.chan = NULL; |
cc1d2806 JB |
7933 | } |
7934 | ||
ffb3cf30 AN |
7935 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7936 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7937 | int n_rates = | |
7938 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7939 | struct ieee80211_supported_band *sband; | |
7940 | ||
7941 | if (!setup.chandef.chan) | |
7942 | return -EINVAL; | |
7943 | ||
7944 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
7945 | ||
7946 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
7947 | &setup.basic_rates); | |
7948 | if (err) | |
7949 | return err; | |
7950 | } | |
7951 | ||
c80d545d | 7952 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
7953 | } |
7954 | ||
7955 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
7956 | { | |
7957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7958 | struct net_device *dev = info->user_ptr[1]; | |
7959 | ||
7960 | return cfg80211_leave_mesh(rdev, dev); | |
7961 | } | |
7962 | ||
dfb89c56 | 7963 | #ifdef CONFIG_PM |
bb92d199 AK |
7964 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
7965 | struct cfg80211_registered_device *rdev) | |
7966 | { | |
6abb9cb9 | 7967 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
7968 | struct nlattr *nl_pats, *nl_pat; |
7969 | int i, pat_len; | |
7970 | ||
6abb9cb9 | 7971 | if (!wowlan->n_patterns) |
bb92d199 AK |
7972 | return 0; |
7973 | ||
7974 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
7975 | if (!nl_pats) | |
7976 | return -ENOBUFS; | |
7977 | ||
6abb9cb9 | 7978 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
7979 | nl_pat = nla_nest_start(msg, i + 1); |
7980 | if (!nl_pat) | |
7981 | return -ENOBUFS; | |
6abb9cb9 | 7982 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 7983 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 7984 | wowlan->patterns[i].mask) || |
50ac6607 AK |
7985 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
7986 | wowlan->patterns[i].pattern) || | |
7987 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 7988 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
7989 | return -ENOBUFS; |
7990 | nla_nest_end(msg, nl_pat); | |
7991 | } | |
7992 | nla_nest_end(msg, nl_pats); | |
7993 | ||
7994 | return 0; | |
7995 | } | |
7996 | ||
2a0e047e JB |
7997 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
7998 | struct cfg80211_wowlan_tcp *tcp) | |
7999 | { | |
8000 | struct nlattr *nl_tcp; | |
8001 | ||
8002 | if (!tcp) | |
8003 | return 0; | |
8004 | ||
8005 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8006 | if (!nl_tcp) | |
8007 | return -ENOBUFS; | |
8008 | ||
8009 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8010 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8011 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8012 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8013 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8014 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8015 | tcp->payload_len, tcp->payload) || | |
8016 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8017 | tcp->data_interval) || | |
8018 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8019 | tcp->wake_len, tcp->wake_data) || | |
8020 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8021 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8022 | return -ENOBUFS; | |
8023 | ||
8024 | if (tcp->payload_seq.len && | |
8025 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8026 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8027 | return -ENOBUFS; | |
8028 | ||
8029 | if (tcp->payload_tok.len && | |
8030 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8031 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8032 | &tcp->payload_tok)) | |
8033 | return -ENOBUFS; | |
8034 | ||
e248ad30 JB |
8035 | nla_nest_end(msg, nl_tcp); |
8036 | ||
2a0e047e JB |
8037 | return 0; |
8038 | } | |
8039 | ||
ff1b6e69 JB |
8040 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8041 | { | |
8042 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8043 | struct sk_buff *msg; | |
8044 | void *hdr; | |
2a0e047e | 8045 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8046 | |
964dc9e2 | 8047 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8048 | return -EOPNOTSUPP; |
8049 | ||
6abb9cb9 | 8050 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8051 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8052 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8053 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8054 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8055 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8056 | } |
8057 | ||
8058 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8059 | if (!msg) |
8060 | return -ENOMEM; | |
8061 | ||
15e47304 | 8062 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8063 | NL80211_CMD_GET_WOWLAN); |
8064 | if (!hdr) | |
8065 | goto nla_put_failure; | |
8066 | ||
6abb9cb9 | 8067 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8068 | struct nlattr *nl_wowlan; |
8069 | ||
8070 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8071 | if (!nl_wowlan) | |
8072 | goto nla_put_failure; | |
8073 | ||
6abb9cb9 | 8074 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8076 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8077 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8078 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8079 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8080 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8081 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8082 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8083 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8084 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8085 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8086 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8087 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8088 | goto nla_put_failure; | |
2a0e047e | 8089 | |
bb92d199 AK |
8090 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8091 | goto nla_put_failure; | |
2a0e047e | 8092 | |
6abb9cb9 JB |
8093 | if (nl80211_send_wowlan_tcp(msg, |
8094 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e JB |
8095 | goto nla_put_failure; |
8096 | ||
ff1b6e69 JB |
8097 | nla_nest_end(msg, nl_wowlan); |
8098 | } | |
8099 | ||
8100 | genlmsg_end(msg, hdr); | |
8101 | return genlmsg_reply(msg, info); | |
8102 | ||
8103 | nla_put_failure: | |
8104 | nlmsg_free(msg); | |
8105 | return -ENOBUFS; | |
8106 | } | |
8107 | ||
2a0e047e JB |
8108 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8109 | struct nlattr *attr, | |
8110 | struct cfg80211_wowlan *trig) | |
8111 | { | |
8112 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8113 | struct cfg80211_wowlan_tcp *cfg; | |
8114 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8115 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8116 | u32 size; | |
8117 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8118 | int err, port; | |
8119 | ||
964dc9e2 | 8120 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8121 | return -EINVAL; |
8122 | ||
8123 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8124 | nla_data(attr), nla_len(attr), | |
8125 | nl80211_wowlan_tcp_policy); | |
8126 | if (err) | |
8127 | return err; | |
8128 | ||
8129 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8130 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8131 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8132 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8133 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8134 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8135 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8136 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8137 | return -EINVAL; | |
8138 | ||
8139 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8140 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8141 | return -EINVAL; |
8142 | ||
8143 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8144 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8145 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8146 | return -EINVAL; |
8147 | ||
8148 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8149 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8150 | return -EINVAL; |
8151 | ||
8152 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8153 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8154 | return -EINVAL; | |
8155 | ||
8156 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8157 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8158 | ||
8159 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8160 | tokens_size = tokln - sizeof(*tok); | |
8161 | ||
8162 | if (!tok->len || tokens_size % tok->len) | |
8163 | return -EINVAL; | |
964dc9e2 | 8164 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8165 | return -EINVAL; |
964dc9e2 | 8166 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8167 | return -EINVAL; |
964dc9e2 | 8168 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8169 | return -EINVAL; |
964dc9e2 | 8170 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8171 | return -EINVAL; |
8172 | if (tok->offset + tok->len > data_size) | |
8173 | return -EINVAL; | |
8174 | } | |
8175 | ||
8176 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
8177 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 8178 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
8179 | return -EINVAL; |
8180 | if (seq->len == 0 || seq->len > 4) | |
8181 | return -EINVAL; | |
8182 | if (seq->len + seq->offset > data_size) | |
8183 | return -EINVAL; | |
8184 | } | |
8185 | ||
8186 | size = sizeof(*cfg); | |
8187 | size += data_size; | |
8188 | size += wake_size + wake_mask_size; | |
8189 | size += tokens_size; | |
8190 | ||
8191 | cfg = kzalloc(size, GFP_KERNEL); | |
8192 | if (!cfg) | |
8193 | return -ENOMEM; | |
8194 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
8195 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
8196 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
8197 | ETH_ALEN); | |
8198 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
8199 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
8200 | else | |
8201 | port = 0; | |
8202 | #ifdef CONFIG_INET | |
8203 | /* allocate a socket and port for it and use it */ | |
8204 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
8205 | IPPROTO_TCP, &cfg->sock, 1); | |
8206 | if (err) { | |
8207 | kfree(cfg); | |
8208 | return err; | |
8209 | } | |
8210 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
8211 | sock_release(cfg->sock); | |
8212 | kfree(cfg); | |
8213 | return -EADDRINUSE; | |
8214 | } | |
8215 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
8216 | #else | |
8217 | if (!port) { | |
8218 | kfree(cfg); | |
8219 | return -EINVAL; | |
8220 | } | |
8221 | cfg->src_port = port; | |
8222 | #endif | |
8223 | ||
8224 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
8225 | cfg->payload_len = data_size; | |
8226 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
8227 | memcpy((void *)cfg->payload, | |
8228 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
8229 | data_size); | |
8230 | if (seq) | |
8231 | cfg->payload_seq = *seq; | |
8232 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
8233 | cfg->wake_len = wake_size; | |
8234 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
8235 | memcpy((void *)cfg->wake_data, | |
8236 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
8237 | wake_size); | |
8238 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
8239 | data_size + wake_size; | |
8240 | memcpy((void *)cfg->wake_mask, | |
8241 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
8242 | wake_mask_size); | |
8243 | if (tok) { | |
8244 | cfg->tokens_size = tokens_size; | |
8245 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
8246 | } | |
8247 | ||
8248 | trig->tcp = cfg; | |
8249 | ||
8250 | return 0; | |
8251 | } | |
8252 | ||
ff1b6e69 JB |
8253 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
8254 | { | |
8255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8256 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 8257 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 8258 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 8259 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 8260 | int err, i; |
6abb9cb9 | 8261 | bool prev_enabled = rdev->wiphy.wowlan_config; |
ff1b6e69 | 8262 | |
964dc9e2 | 8263 | if (!wowlan) |
ff1b6e69 JB |
8264 | return -EOPNOTSUPP; |
8265 | ||
ae33bd81 JB |
8266 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
8267 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 8268 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
8269 | goto set_wakeup; |
8270 | } | |
ff1b6e69 JB |
8271 | |
8272 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
8273 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8274 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
8275 | nl80211_wowlan_policy); | |
8276 | if (err) | |
8277 | return err; | |
8278 | ||
8279 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
8280 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
8281 | return -EINVAL; | |
8282 | new_triggers.any = true; | |
8283 | } | |
8284 | ||
8285 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
8286 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
8287 | return -EINVAL; | |
8288 | new_triggers.disconnect = true; | |
8289 | } | |
8290 | ||
8291 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
8292 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
8293 | return -EINVAL; | |
8294 | new_triggers.magic_pkt = true; | |
8295 | } | |
8296 | ||
77dbbb13 JB |
8297 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
8298 | return -EINVAL; | |
8299 | ||
8300 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
8301 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
8302 | return -EINVAL; | |
8303 | new_triggers.gtk_rekey_failure = true; | |
8304 | } | |
8305 | ||
8306 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
8307 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
8308 | return -EINVAL; | |
8309 | new_triggers.eap_identity_req = true; | |
8310 | } | |
8311 | ||
8312 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
8313 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
8314 | return -EINVAL; | |
8315 | new_triggers.four_way_handshake = true; | |
8316 | } | |
8317 | ||
8318 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
8319 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
8320 | return -EINVAL; | |
8321 | new_triggers.rfkill_release = true; | |
8322 | } | |
8323 | ||
ff1b6e69 JB |
8324 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
8325 | struct nlattr *pat; | |
8326 | int n_patterns = 0; | |
bb92d199 | 8327 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 8328 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 JB |
8329 | |
8330 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8331 | rem) | |
8332 | n_patterns++; | |
8333 | if (n_patterns > wowlan->n_patterns) | |
8334 | return -EINVAL; | |
8335 | ||
8336 | new_triggers.patterns = kcalloc(n_patterns, | |
8337 | sizeof(new_triggers.patterns[0]), | |
8338 | GFP_KERNEL); | |
8339 | if (!new_triggers.patterns) | |
8340 | return -ENOMEM; | |
8341 | ||
8342 | new_triggers.n_patterns = n_patterns; | |
8343 | i = 0; | |
8344 | ||
8345 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
8346 | rem) { | |
50ac6607 AK |
8347 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
8348 | nla_len(pat), NULL); | |
ff1b6e69 | 8349 | err = -EINVAL; |
50ac6607 AK |
8350 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
8351 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 8352 | goto error; |
50ac6607 | 8353 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 8354 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 8355 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
8356 | goto error; |
8357 | if (pat_len > wowlan->pattern_max_len || | |
8358 | pat_len < wowlan->pattern_min_len) | |
8359 | goto error; | |
8360 | ||
50ac6607 | 8361 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
8362 | pkt_offset = 0; |
8363 | else | |
8364 | pkt_offset = nla_get_u32( | |
50ac6607 | 8365 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
8366 | if (pkt_offset > wowlan->max_pkt_offset) |
8367 | goto error; | |
8368 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
8369 | ||
ff1b6e69 JB |
8370 | new_triggers.patterns[i].mask = |
8371 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8372 | if (!new_triggers.patterns[i].mask) { | |
8373 | err = -ENOMEM; | |
8374 | goto error; | |
8375 | } | |
8376 | new_triggers.patterns[i].pattern = | |
8377 | new_triggers.patterns[i].mask + mask_len; | |
8378 | memcpy(new_triggers.patterns[i].mask, | |
50ac6607 | 8379 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
ff1b6e69 JB |
8380 | mask_len); |
8381 | new_triggers.patterns[i].pattern_len = pat_len; | |
8382 | memcpy(new_triggers.patterns[i].pattern, | |
50ac6607 | 8383 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
8384 | pat_len); |
8385 | i++; | |
8386 | } | |
8387 | } | |
8388 | ||
2a0e047e JB |
8389 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
8390 | err = nl80211_parse_wowlan_tcp( | |
8391 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
8392 | &new_triggers); | |
8393 | if (err) | |
8394 | goto error; | |
8395 | } | |
8396 | ||
ae33bd81 JB |
8397 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
8398 | if (!ntrig) { | |
8399 | err = -ENOMEM; | |
8400 | goto error; | |
ff1b6e69 | 8401 | } |
ae33bd81 | 8402 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 8403 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 8404 | |
ae33bd81 | 8405 | set_wakeup: |
6abb9cb9 JB |
8406 | if (rdev->ops->set_wakeup && |
8407 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
8408 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 8409 | |
ff1b6e69 JB |
8410 | return 0; |
8411 | error: | |
8412 | for (i = 0; i < new_triggers.n_patterns; i++) | |
8413 | kfree(new_triggers.patterns[i].mask); | |
8414 | kfree(new_triggers.patterns); | |
2a0e047e JB |
8415 | if (new_triggers.tcp && new_triggers.tcp->sock) |
8416 | sock_release(new_triggers.tcp->sock); | |
8417 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
8418 | return err; |
8419 | } | |
dfb89c56 | 8420 | #endif |
ff1b6e69 | 8421 | |
be29b99a AK |
8422 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
8423 | struct cfg80211_registered_device *rdev) | |
8424 | { | |
8425 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
8426 | int i, j, pat_len; | |
8427 | struct cfg80211_coalesce_rules *rule; | |
8428 | ||
8429 | if (!rdev->coalesce->n_rules) | |
8430 | return 0; | |
8431 | ||
8432 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
8433 | if (!nl_rules) | |
8434 | return -ENOBUFS; | |
8435 | ||
8436 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
8437 | nl_rule = nla_nest_start(msg, i + 1); | |
8438 | if (!nl_rule) | |
8439 | return -ENOBUFS; | |
8440 | ||
8441 | rule = &rdev->coalesce->rules[i]; | |
8442 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
8443 | rule->delay)) | |
8444 | return -ENOBUFS; | |
8445 | ||
8446 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
8447 | rule->condition)) | |
8448 | return -ENOBUFS; | |
8449 | ||
8450 | nl_pats = nla_nest_start(msg, | |
8451 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
8452 | if (!nl_pats) | |
8453 | return -ENOBUFS; | |
8454 | ||
8455 | for (j = 0; j < rule->n_patterns; j++) { | |
8456 | nl_pat = nla_nest_start(msg, j + 1); | |
8457 | if (!nl_pat) | |
8458 | return -ENOBUFS; | |
8459 | pat_len = rule->patterns[j].pattern_len; | |
8460 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
8461 | DIV_ROUND_UP(pat_len, 8), | |
8462 | rule->patterns[j].mask) || | |
8463 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
8464 | rule->patterns[j].pattern) || | |
8465 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
8466 | rule->patterns[j].pkt_offset)) | |
8467 | return -ENOBUFS; | |
8468 | nla_nest_end(msg, nl_pat); | |
8469 | } | |
8470 | nla_nest_end(msg, nl_pats); | |
8471 | nla_nest_end(msg, nl_rule); | |
8472 | } | |
8473 | nla_nest_end(msg, nl_rules); | |
8474 | ||
8475 | return 0; | |
8476 | } | |
8477 | ||
8478 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8479 | { | |
8480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8481 | struct sk_buff *msg; | |
8482 | void *hdr; | |
8483 | ||
8484 | if (!rdev->wiphy.coalesce) | |
8485 | return -EOPNOTSUPP; | |
8486 | ||
8487 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8488 | if (!msg) | |
8489 | return -ENOMEM; | |
8490 | ||
8491 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8492 | NL80211_CMD_GET_COALESCE); | |
8493 | if (!hdr) | |
8494 | goto nla_put_failure; | |
8495 | ||
8496 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
8497 | goto nla_put_failure; | |
8498 | ||
8499 | genlmsg_end(msg, hdr); | |
8500 | return genlmsg_reply(msg, info); | |
8501 | ||
8502 | nla_put_failure: | |
8503 | nlmsg_free(msg); | |
8504 | return -ENOBUFS; | |
8505 | } | |
8506 | ||
8507 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
8508 | { | |
8509 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
8510 | int i, j; | |
8511 | struct cfg80211_coalesce_rules *rule; | |
8512 | ||
8513 | if (!coalesce) | |
8514 | return; | |
8515 | ||
8516 | for (i = 0; i < coalesce->n_rules; i++) { | |
8517 | rule = &coalesce->rules[i]; | |
8518 | for (j = 0; j < rule->n_patterns; j++) | |
8519 | kfree(rule->patterns[j].mask); | |
8520 | kfree(rule->patterns); | |
8521 | } | |
8522 | kfree(coalesce->rules); | |
8523 | kfree(coalesce); | |
8524 | rdev->coalesce = NULL; | |
8525 | } | |
8526 | ||
8527 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
8528 | struct nlattr *rule, | |
8529 | struct cfg80211_coalesce_rules *new_rule) | |
8530 | { | |
8531 | int err, i; | |
8532 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8533 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
8534 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
8535 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
8536 | ||
8537 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
8538 | nla_len(rule), nl80211_coalesce_policy); | |
8539 | if (err) | |
8540 | return err; | |
8541 | ||
8542 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
8543 | new_rule->delay = | |
8544 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
8545 | if (new_rule->delay > coalesce->max_delay) | |
8546 | return -EINVAL; | |
8547 | ||
8548 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
8549 | new_rule->condition = | |
8550 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
8551 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
8552 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
8553 | return -EINVAL; | |
8554 | ||
8555 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
8556 | return -EINVAL; | |
8557 | ||
8558 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8559 | rem) | |
8560 | n_patterns++; | |
8561 | if (n_patterns > coalesce->n_patterns) | |
8562 | return -EINVAL; | |
8563 | ||
8564 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
8565 | GFP_KERNEL); | |
8566 | if (!new_rule->patterns) | |
8567 | return -ENOMEM; | |
8568 | ||
8569 | new_rule->n_patterns = n_patterns; | |
8570 | i = 0; | |
8571 | ||
8572 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
8573 | rem) { | |
8574 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), | |
8575 | nla_len(pat), NULL); | |
8576 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
8577 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
8578 | return -EINVAL; | |
8579 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
8580 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
8581 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
8582 | return -EINVAL; | |
8583 | if (pat_len > coalesce->pattern_max_len || | |
8584 | pat_len < coalesce->pattern_min_len) | |
8585 | return -EINVAL; | |
8586 | ||
8587 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
8588 | pkt_offset = 0; | |
8589 | else | |
8590 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
8591 | if (pkt_offset > coalesce->max_pkt_offset) | |
8592 | return -EINVAL; | |
8593 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
8594 | ||
8595 | new_rule->patterns[i].mask = | |
8596 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
8597 | if (!new_rule->patterns[i].mask) | |
8598 | return -ENOMEM; | |
8599 | new_rule->patterns[i].pattern = | |
8600 | new_rule->patterns[i].mask + mask_len; | |
8601 | memcpy(new_rule->patterns[i].mask, | |
8602 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); | |
8603 | new_rule->patterns[i].pattern_len = pat_len; | |
8604 | memcpy(new_rule->patterns[i].pattern, | |
8605 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); | |
8606 | i++; | |
8607 | } | |
8608 | ||
8609 | return 0; | |
8610 | } | |
8611 | ||
8612 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
8613 | { | |
8614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8615 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
8616 | struct cfg80211_coalesce new_coalesce = {}; | |
8617 | struct cfg80211_coalesce *n_coalesce; | |
8618 | int err, rem_rule, n_rules = 0, i, j; | |
8619 | struct nlattr *rule; | |
8620 | struct cfg80211_coalesce_rules *tmp_rule; | |
8621 | ||
8622 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
8623 | return -EOPNOTSUPP; | |
8624 | ||
8625 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
8626 | cfg80211_rdev_free_coalesce(rdev); | |
8627 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
8628 | return 0; | |
8629 | } | |
8630 | ||
8631 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8632 | rem_rule) | |
8633 | n_rules++; | |
8634 | if (n_rules > coalesce->n_rules) | |
8635 | return -EINVAL; | |
8636 | ||
8637 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
8638 | GFP_KERNEL); | |
8639 | if (!new_coalesce.rules) | |
8640 | return -ENOMEM; | |
8641 | ||
8642 | new_coalesce.n_rules = n_rules; | |
8643 | i = 0; | |
8644 | ||
8645 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
8646 | rem_rule) { | |
8647 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
8648 | &new_coalesce.rules[i]); | |
8649 | if (err) | |
8650 | goto error; | |
8651 | ||
8652 | i++; | |
8653 | } | |
8654 | ||
8655 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
8656 | if (err) | |
8657 | goto error; | |
8658 | ||
8659 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
8660 | if (!n_coalesce) { | |
8661 | err = -ENOMEM; | |
8662 | goto error; | |
8663 | } | |
8664 | cfg80211_rdev_free_coalesce(rdev); | |
8665 | rdev->coalesce = n_coalesce; | |
8666 | ||
8667 | return 0; | |
8668 | error: | |
8669 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
8670 | tmp_rule = &new_coalesce.rules[i]; | |
8671 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
8672 | kfree(tmp_rule->patterns[j].mask); | |
8673 | kfree(tmp_rule->patterns); | |
8674 | } | |
8675 | kfree(new_coalesce.rules); | |
8676 | ||
8677 | return err; | |
8678 | } | |
8679 | ||
e5497d76 JB |
8680 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
8681 | { | |
8682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8683 | struct net_device *dev = info->user_ptr[1]; | |
8684 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8685 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
8686 | struct cfg80211_gtk_rekey_data rekey_data; | |
8687 | int err; | |
8688 | ||
8689 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
8690 | return -EINVAL; | |
8691 | ||
8692 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
8693 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8694 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
8695 | nl80211_rekey_policy); | |
8696 | if (err) | |
8697 | return err; | |
8698 | ||
8699 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
8700 | return -ERANGE; | |
8701 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
8702 | return -ERANGE; | |
8703 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
8704 | return -ERANGE; | |
8705 | ||
8706 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
8707 | NL80211_KEK_LEN); | |
8708 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
8709 | NL80211_KCK_LEN); | |
8710 | memcpy(rekey_data.replay_ctr, | |
8711 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
8712 | NL80211_REPLAY_CTR_LEN); | |
8713 | ||
8714 | wdev_lock(wdev); | |
8715 | if (!wdev->current_bss) { | |
8716 | err = -ENOTCONN; | |
8717 | goto out; | |
8718 | } | |
8719 | ||
8720 | if (!rdev->ops->set_rekey_data) { | |
8721 | err = -EOPNOTSUPP; | |
8722 | goto out; | |
8723 | } | |
8724 | ||
e35e4d28 | 8725 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
8726 | out: |
8727 | wdev_unlock(wdev); | |
8728 | return err; | |
8729 | } | |
8730 | ||
28946da7 JB |
8731 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
8732 | struct genl_info *info) | |
8733 | { | |
8734 | struct net_device *dev = info->user_ptr[1]; | |
8735 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8736 | ||
8737 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8738 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8739 | return -EINVAL; | |
8740 | ||
15e47304 | 8741 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
8742 | return -EBUSY; |
8743 | ||
15e47304 | 8744 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
8745 | return 0; |
8746 | } | |
8747 | ||
7f6cf311 JB |
8748 | static int nl80211_probe_client(struct sk_buff *skb, |
8749 | struct genl_info *info) | |
8750 | { | |
8751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8752 | struct net_device *dev = info->user_ptr[1]; | |
8753 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8754 | struct sk_buff *msg; | |
8755 | void *hdr; | |
8756 | const u8 *addr; | |
8757 | u64 cookie; | |
8758 | int err; | |
8759 | ||
8760 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
8761 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
8762 | return -EOPNOTSUPP; | |
8763 | ||
8764 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8765 | return -EINVAL; | |
8766 | ||
8767 | if (!rdev->ops->probe_client) | |
8768 | return -EOPNOTSUPP; | |
8769 | ||
8770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8771 | if (!msg) | |
8772 | return -ENOMEM; | |
8773 | ||
15e47304 | 8774 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 8775 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
8776 | if (!hdr) { |
8777 | err = -ENOBUFS; | |
7f6cf311 JB |
8778 | goto free_msg; |
8779 | } | |
8780 | ||
8781 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8782 | ||
e35e4d28 | 8783 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
8784 | if (err) |
8785 | goto free_msg; | |
8786 | ||
9360ffd1 DM |
8787 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8788 | goto nla_put_failure; | |
7f6cf311 JB |
8789 | |
8790 | genlmsg_end(msg, hdr); | |
8791 | ||
8792 | return genlmsg_reply(msg, info); | |
8793 | ||
8794 | nla_put_failure: | |
8795 | err = -ENOBUFS; | |
8796 | free_msg: | |
8797 | nlmsg_free(msg); | |
8798 | return err; | |
8799 | } | |
8800 | ||
5e760230 JB |
8801 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
8802 | { | |
8803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
8804 | struct cfg80211_beacon_registration *reg, *nreg; |
8805 | int rv; | |
5e760230 JB |
8806 | |
8807 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
8808 | return -EOPNOTSUPP; | |
8809 | ||
37c73b5f BG |
8810 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
8811 | if (!nreg) | |
8812 | return -ENOMEM; | |
8813 | ||
8814 | /* First, check if already registered. */ | |
8815 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
8816 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
8817 | if (reg->nlportid == info->snd_portid) { | |
8818 | rv = -EALREADY; | |
8819 | goto out_err; | |
8820 | } | |
8821 | } | |
8822 | /* Add it to the list */ | |
8823 | nreg->nlportid = info->snd_portid; | |
8824 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 8825 | |
37c73b5f | 8826 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
8827 | |
8828 | return 0; | |
37c73b5f BG |
8829 | out_err: |
8830 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
8831 | kfree(nreg); | |
8832 | return rv; | |
5e760230 JB |
8833 | } |
8834 | ||
98104fde JB |
8835 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
8836 | { | |
8837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8838 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8839 | int err; | |
8840 | ||
8841 | if (!rdev->ops->start_p2p_device) | |
8842 | return -EOPNOTSUPP; | |
8843 | ||
8844 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8845 | return -EOPNOTSUPP; | |
8846 | ||
8847 | if (wdev->p2p_started) | |
8848 | return 0; | |
8849 | ||
98104fde | 8850 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
98104fde JB |
8851 | if (err) |
8852 | return err; | |
8853 | ||
eeb126e9 | 8854 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
8855 | if (err) |
8856 | return err; | |
8857 | ||
8858 | wdev->p2p_started = true; | |
98104fde | 8859 | rdev->opencount++; |
98104fde JB |
8860 | |
8861 | return 0; | |
8862 | } | |
8863 | ||
8864 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
8865 | { | |
8866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8867 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8868 | ||
8869 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
8870 | return -EOPNOTSUPP; | |
8871 | ||
8872 | if (!rdev->ops->stop_p2p_device) | |
8873 | return -EOPNOTSUPP; | |
8874 | ||
f9f47529 | 8875 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
8876 | |
8877 | return 0; | |
8878 | } | |
8879 | ||
3713b4e3 JB |
8880 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
8881 | struct genl_info *info) | |
8882 | { | |
8883 | void *hdr; | |
8884 | struct sk_buff *msg; | |
8885 | ||
8886 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
8887 | if (!msg) | |
8888 | return -ENOMEM; | |
8889 | ||
8890 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
8891 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
8892 | if (!hdr) | |
8893 | goto nla_put_failure; | |
8894 | ||
8895 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
8896 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
8897 | goto nla_put_failure; | |
8898 | ||
8899 | genlmsg_end(msg, hdr); | |
8900 | return genlmsg_reply(msg, info); | |
8901 | ||
8902 | nla_put_failure: | |
8903 | kfree_skb(msg); | |
8904 | return -ENOBUFS; | |
8905 | } | |
8906 | ||
355199e0 JM |
8907 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
8908 | { | |
8909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8910 | struct cfg80211_update_ft_ies_params ft_params; | |
8911 | struct net_device *dev = info->user_ptr[1]; | |
8912 | ||
8913 | if (!rdev->ops->update_ft_ies) | |
8914 | return -EOPNOTSUPP; | |
8915 | ||
8916 | if (!info->attrs[NL80211_ATTR_MDID] || | |
8917 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8918 | return -EINVAL; | |
8919 | ||
8920 | memset(&ft_params, 0, sizeof(ft_params)); | |
8921 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
8922 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8923 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8924 | ||
8925 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
8926 | } | |
8927 | ||
5de17984 AS |
8928 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
8929 | struct genl_info *info) | |
8930 | { | |
8931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8932 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8933 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
8934 | u16 duration; | |
8935 | int ret; | |
8936 | ||
8937 | if (!rdev->ops->crit_proto_start) | |
8938 | return -EOPNOTSUPP; | |
8939 | ||
8940 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
8941 | return -EINVAL; | |
8942 | ||
8943 | if (rdev->crit_proto_nlportid) | |
8944 | return -EBUSY; | |
8945 | ||
8946 | /* determine protocol if provided */ | |
8947 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
8948 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
8949 | ||
8950 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
8951 | return -EINVAL; | |
8952 | ||
8953 | /* timeout must be provided */ | |
8954 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
8955 | return -EINVAL; | |
8956 | ||
8957 | duration = | |
8958 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
8959 | ||
8960 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
8961 | return -ERANGE; | |
8962 | ||
8963 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
8964 | if (!ret) | |
8965 | rdev->crit_proto_nlportid = info->snd_portid; | |
8966 | ||
8967 | return ret; | |
8968 | } | |
8969 | ||
8970 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
8971 | struct genl_info *info) | |
8972 | { | |
8973 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8974 | struct wireless_dev *wdev = info->user_ptr[1]; | |
8975 | ||
8976 | if (!rdev->ops->crit_proto_stop) | |
8977 | return -EOPNOTSUPP; | |
8978 | ||
8979 | if (rdev->crit_proto_nlportid) { | |
8980 | rdev->crit_proto_nlportid = 0; | |
8981 | rdev_crit_proto_stop(rdev, wdev); | |
8982 | } | |
8983 | return 0; | |
8984 | } | |
8985 | ||
ad7e718c JB |
8986 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
8987 | { | |
8988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8989 | struct wireless_dev *wdev = | |
8990 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
8991 | int i, err; | |
8992 | u32 vid, subcmd; | |
8993 | ||
8994 | if (!rdev->wiphy.vendor_commands) | |
8995 | return -EOPNOTSUPP; | |
8996 | ||
8997 | if (IS_ERR(wdev)) { | |
8998 | err = PTR_ERR(wdev); | |
8999 | if (err != -EINVAL) | |
9000 | return err; | |
9001 | wdev = NULL; | |
9002 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9003 | return -EINVAL; | |
9004 | } | |
9005 | ||
9006 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9007 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9008 | return -EINVAL; | |
9009 | ||
9010 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9011 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9012 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9013 | const struct wiphy_vendor_command *vcmd; | |
9014 | void *data = NULL; | |
9015 | int len = 0; | |
9016 | ||
9017 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9018 | ||
9019 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9020 | continue; | |
9021 | ||
9022 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9023 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9024 | if (!wdev) | |
9025 | return -EINVAL; | |
9026 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9027 | !wdev->netdev) | |
9028 | return -EINVAL; | |
9029 | ||
9030 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9031 | if (wdev->netdev && | |
9032 | !netif_running(wdev->netdev)) | |
9033 | return -ENETDOWN; | |
9034 | if (!wdev->netdev && !wdev->p2p_started) | |
9035 | return -ENETDOWN; | |
9036 | } | |
9037 | } else { | |
9038 | wdev = NULL; | |
9039 | } | |
9040 | ||
9041 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9042 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9043 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9044 | } | |
9045 | ||
9046 | rdev->cur_cmd_info = info; | |
9047 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9048 | data, len); | |
9049 | rdev->cur_cmd_info = NULL; | |
9050 | return err; | |
9051 | } | |
9052 | ||
9053 | return -EOPNOTSUPP; | |
9054 | } | |
9055 | ||
9056 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9057 | enum nl80211_commands cmd, | |
9058 | enum nl80211_attrs attr, | |
9059 | int approxlen) | |
9060 | { | |
9061 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
9062 | ||
9063 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9064 | return NULL; | |
9065 | ||
9066 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, | |
9067 | rdev->cur_cmd_info->snd_portid, | |
9068 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9069 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9070 | } |
9071 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9072 | ||
9073 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9074 | { | |
9075 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9076 | void *hdr = ((void **)skb->cb)[1]; | |
9077 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9078 | ||
9079 | if (WARN_ON(!rdev->cur_cmd_info)) { | |
9080 | kfree_skb(skb); | |
9081 | return -EINVAL; | |
9082 | } | |
9083 | ||
9084 | nla_nest_end(skb, data); | |
9085 | genlmsg_end(skb, hdr); | |
9086 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9087 | } | |
9088 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9089 | ||
9090 | ||
fa9ffc74 KP |
9091 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9092 | struct genl_info *info) | |
9093 | { | |
9094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9095 | struct cfg80211_qos_map *qos_map = NULL; | |
9096 | struct net_device *dev = info->user_ptr[1]; | |
9097 | u8 *pos, len, num_des, des_len, des; | |
9098 | int ret; | |
9099 | ||
9100 | if (!rdev->ops->set_qos_map) | |
9101 | return -EOPNOTSUPP; | |
9102 | ||
9103 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9104 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9105 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9106 | ||
9107 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9108 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
9109 | return -EINVAL; | |
9110 | ||
9111 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
9112 | if (!qos_map) | |
9113 | return -ENOMEM; | |
9114 | ||
9115 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
9116 | if (num_des) { | |
9117 | des_len = num_des * | |
9118 | sizeof(struct cfg80211_dscp_exception); | |
9119 | memcpy(qos_map->dscp_exception, pos, des_len); | |
9120 | qos_map->num_des = num_des; | |
9121 | for (des = 0; des < num_des; des++) { | |
9122 | if (qos_map->dscp_exception[des].up > 7) { | |
9123 | kfree(qos_map); | |
9124 | return -EINVAL; | |
9125 | } | |
9126 | } | |
9127 | pos += des_len; | |
9128 | } | |
9129 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
9130 | } | |
9131 | ||
9132 | wdev_lock(dev->ieee80211_ptr); | |
9133 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
9134 | if (!ret) | |
9135 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
9136 | wdev_unlock(dev->ieee80211_ptr); | |
9137 | ||
9138 | kfree(qos_map); | |
9139 | return ret; | |
9140 | } | |
9141 | ||
4c476991 JB |
9142 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
9143 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
9144 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
9145 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
9146 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
9147 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 9148 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 9149 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
9150 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
9151 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 | 9152 | |
f84f771d | 9153 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9154 | struct genl_info *info) |
9155 | { | |
9156 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 9157 | struct wireless_dev *wdev; |
4c476991 | 9158 | struct net_device *dev; |
4c476991 JB |
9159 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
9160 | ||
9161 | if (rtnl) | |
9162 | rtnl_lock(); | |
9163 | ||
9164 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 9165 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
9166 | if (IS_ERR(rdev)) { |
9167 | if (rtnl) | |
9168 | rtnl_unlock(); | |
9169 | return PTR_ERR(rdev); | |
9170 | } | |
9171 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
9172 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
9173 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
9174 | ASSERT_RTNL(); |
9175 | ||
89a54e48 JB |
9176 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
9177 | info->attrs); | |
9178 | if (IS_ERR(wdev)) { | |
4c476991 JB |
9179 | if (rtnl) |
9180 | rtnl_unlock(); | |
89a54e48 | 9181 | return PTR_ERR(wdev); |
4c476991 | 9182 | } |
89a54e48 | 9183 | |
89a54e48 JB |
9184 | dev = wdev->netdev; |
9185 | rdev = wiphy_to_dev(wdev->wiphy); | |
9186 | ||
1bf614ef JB |
9187 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
9188 | if (!dev) { | |
1bf614ef JB |
9189 | if (rtnl) |
9190 | rtnl_unlock(); | |
9191 | return -EINVAL; | |
9192 | } | |
9193 | ||
9194 | info->user_ptr[1] = dev; | |
9195 | } else { | |
9196 | info->user_ptr[1] = wdev; | |
41265714 | 9197 | } |
1bf614ef JB |
9198 | |
9199 | if (dev) { | |
9200 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
9201 | !netif_running(dev)) { | |
1bf614ef JB |
9202 | if (rtnl) |
9203 | rtnl_unlock(); | |
9204 | return -ENETDOWN; | |
9205 | } | |
9206 | ||
9207 | dev_hold(dev); | |
98104fde JB |
9208 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
9209 | if (!wdev->p2p_started) { | |
98104fde JB |
9210 | if (rtnl) |
9211 | rtnl_unlock(); | |
9212 | return -ENETDOWN; | |
9213 | } | |
41265714 | 9214 | } |
89a54e48 | 9215 | |
4c476991 | 9216 | info->user_ptr[0] = rdev; |
4c476991 JB |
9217 | } |
9218 | ||
9219 | return 0; | |
9220 | } | |
9221 | ||
f84f771d | 9222 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
9223 | struct genl_info *info) |
9224 | { | |
1bf614ef JB |
9225 | if (info->user_ptr[1]) { |
9226 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
9227 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9228 | ||
9229 | if (wdev->netdev) | |
9230 | dev_put(wdev->netdev); | |
9231 | } else { | |
9232 | dev_put(info->user_ptr[1]); | |
9233 | } | |
9234 | } | |
4c476991 JB |
9235 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
9236 | rtnl_unlock(); | |
9237 | } | |
9238 | ||
4534de83 | 9239 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
9240 | { |
9241 | .cmd = NL80211_CMD_GET_WIPHY, | |
9242 | .doit = nl80211_get_wiphy, | |
9243 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 9244 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
9245 | .policy = nl80211_policy, |
9246 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9247 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9248 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9249 | }, |
9250 | { | |
9251 | .cmd = NL80211_CMD_SET_WIPHY, | |
9252 | .doit = nl80211_set_wiphy, | |
9253 | .policy = nl80211_policy, | |
9254 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 9255 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
9256 | }, |
9257 | { | |
9258 | .cmd = NL80211_CMD_GET_INTERFACE, | |
9259 | .doit = nl80211_get_interface, | |
9260 | .dumpit = nl80211_dump_interface, | |
9261 | .policy = nl80211_policy, | |
9262 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
9263 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
9264 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9265 | }, |
9266 | { | |
9267 | .cmd = NL80211_CMD_SET_INTERFACE, | |
9268 | .doit = nl80211_set_interface, | |
9269 | .policy = nl80211_policy, | |
9270 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9271 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9272 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9273 | }, |
9274 | { | |
9275 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
9276 | .doit = nl80211_new_interface, | |
9277 | .policy = nl80211_policy, | |
9278 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9279 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9280 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
9281 | }, |
9282 | { | |
9283 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
9284 | .doit = nl80211_del_interface, | |
9285 | .policy = nl80211_policy, | |
41ade00f | 9286 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 9287 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9288 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9289 | }, |
9290 | { | |
9291 | .cmd = NL80211_CMD_GET_KEY, | |
9292 | .doit = nl80211_get_key, | |
9293 | .policy = nl80211_policy, | |
9294 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9295 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9296 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9297 | }, |
9298 | { | |
9299 | .cmd = NL80211_CMD_SET_KEY, | |
9300 | .doit = nl80211_set_key, | |
9301 | .policy = nl80211_policy, | |
9302 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9304 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9305 | }, |
9306 | { | |
9307 | .cmd = NL80211_CMD_NEW_KEY, | |
9308 | .doit = nl80211_new_key, | |
9309 | .policy = nl80211_policy, | |
9310 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9311 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9312 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
9313 | }, |
9314 | { | |
9315 | .cmd = NL80211_CMD_DEL_KEY, | |
9316 | .doit = nl80211_del_key, | |
9317 | .policy = nl80211_policy, | |
55682965 | 9318 | .flags = GENL_ADMIN_PERM, |
41265714 | 9319 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9320 | NL80211_FLAG_NEED_RTNL, |
55682965 | 9321 | }, |
ed1b6cc7 JB |
9322 | { |
9323 | .cmd = NL80211_CMD_SET_BEACON, | |
9324 | .policy = nl80211_policy, | |
9325 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9326 | .doit = nl80211_set_beacon, |
2b5f8b0b | 9327 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9328 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9329 | }, |
9330 | { | |
8860020e | 9331 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
9332 | .policy = nl80211_policy, |
9333 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9334 | .doit = nl80211_start_ap, |
2b5f8b0b | 9335 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9336 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
9337 | }, |
9338 | { | |
8860020e | 9339 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
9340 | .policy = nl80211_policy, |
9341 | .flags = GENL_ADMIN_PERM, | |
8860020e | 9342 | .doit = nl80211_stop_ap, |
2b5f8b0b | 9343 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9344 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 9345 | }, |
5727ef1b JB |
9346 | { |
9347 | .cmd = NL80211_CMD_GET_STATION, | |
9348 | .doit = nl80211_get_station, | |
2ec600d6 | 9349 | .dumpit = nl80211_dump_station, |
5727ef1b | 9350 | .policy = nl80211_policy, |
4c476991 JB |
9351 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9352 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
9353 | }, |
9354 | { | |
9355 | .cmd = NL80211_CMD_SET_STATION, | |
9356 | .doit = nl80211_set_station, | |
9357 | .policy = nl80211_policy, | |
9358 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9359 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9360 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9361 | }, |
9362 | { | |
9363 | .cmd = NL80211_CMD_NEW_STATION, | |
9364 | .doit = nl80211_new_station, | |
9365 | .policy = nl80211_policy, | |
9366 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9367 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9368 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
9369 | }, |
9370 | { | |
9371 | .cmd = NL80211_CMD_DEL_STATION, | |
9372 | .doit = nl80211_del_station, | |
9373 | .policy = nl80211_policy, | |
2ec600d6 | 9374 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9375 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9376 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9377 | }, |
9378 | { | |
9379 | .cmd = NL80211_CMD_GET_MPATH, | |
9380 | .doit = nl80211_get_mpath, | |
9381 | .dumpit = nl80211_dump_mpath, | |
9382 | .policy = nl80211_policy, | |
9383 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9385 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9386 | }, |
9387 | { | |
9388 | .cmd = NL80211_CMD_SET_MPATH, | |
9389 | .doit = nl80211_set_mpath, | |
9390 | .policy = nl80211_policy, | |
9391 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9392 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9393 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9394 | }, |
9395 | { | |
9396 | .cmd = NL80211_CMD_NEW_MPATH, | |
9397 | .doit = nl80211_new_mpath, | |
9398 | .policy = nl80211_policy, | |
9399 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9400 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9401 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
9402 | }, |
9403 | { | |
9404 | .cmd = NL80211_CMD_DEL_MPATH, | |
9405 | .doit = nl80211_del_mpath, | |
9406 | .policy = nl80211_policy, | |
9f1ba906 | 9407 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9409 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
9410 | }, |
9411 | { | |
9412 | .cmd = NL80211_CMD_SET_BSS, | |
9413 | .doit = nl80211_set_bss, | |
9414 | .policy = nl80211_policy, | |
b2e1b302 | 9415 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 9416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9417 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 9418 | }, |
f130347c LR |
9419 | { |
9420 | .cmd = NL80211_CMD_GET_REG, | |
9421 | .doit = nl80211_get_reg, | |
9422 | .policy = nl80211_policy, | |
5fe231e8 | 9423 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
9424 | /* can be retrieved by unprivileged users */ |
9425 | }, | |
b2e1b302 LR |
9426 | { |
9427 | .cmd = NL80211_CMD_SET_REG, | |
9428 | .doit = nl80211_set_reg, | |
9429 | .policy = nl80211_policy, | |
9430 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 9431 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
9432 | }, |
9433 | { | |
9434 | .cmd = NL80211_CMD_REQ_SET_REG, | |
9435 | .doit = nl80211_req_set_reg, | |
9436 | .policy = nl80211_policy, | |
93da9cc1 | 9437 | .flags = GENL_ADMIN_PERM, |
9438 | }, | |
9439 | { | |
24bdd9f4 JC |
9440 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
9441 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 9442 | .policy = nl80211_policy, |
9443 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 9444 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9445 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 9446 | }, |
9447 | { | |
24bdd9f4 JC |
9448 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
9449 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 9450 | .policy = nl80211_policy, |
9aed3cc1 | 9451 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 9452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9453 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 9454 | }, |
2a519311 JB |
9455 | { |
9456 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
9457 | .doit = nl80211_trigger_scan, | |
9458 | .policy = nl80211_policy, | |
9459 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 9460 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9461 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
9462 | }, |
9463 | { | |
9464 | .cmd = NL80211_CMD_GET_SCAN, | |
9465 | .policy = nl80211_policy, | |
9466 | .dumpit = nl80211_dump_scan, | |
9467 | }, | |
807f8a8c LC |
9468 | { |
9469 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
9470 | .doit = nl80211_start_sched_scan, | |
9471 | .policy = nl80211_policy, | |
9472 | .flags = GENL_ADMIN_PERM, | |
9473 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9474 | NL80211_FLAG_NEED_RTNL, | |
9475 | }, | |
9476 | { | |
9477 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
9478 | .doit = nl80211_stop_sched_scan, | |
9479 | .policy = nl80211_policy, | |
9480 | .flags = GENL_ADMIN_PERM, | |
9481 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9482 | NL80211_FLAG_NEED_RTNL, | |
9483 | }, | |
636a5d36 JM |
9484 | { |
9485 | .cmd = NL80211_CMD_AUTHENTICATE, | |
9486 | .doit = nl80211_authenticate, | |
9487 | .policy = nl80211_policy, | |
9488 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9489 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9490 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9491 | }, |
9492 | { | |
9493 | .cmd = NL80211_CMD_ASSOCIATE, | |
9494 | .doit = nl80211_associate, | |
9495 | .policy = nl80211_policy, | |
9496 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9498 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9499 | }, |
9500 | { | |
9501 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
9502 | .doit = nl80211_deauthenticate, | |
9503 | .policy = nl80211_policy, | |
9504 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9506 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
9507 | }, |
9508 | { | |
9509 | .cmd = NL80211_CMD_DISASSOCIATE, | |
9510 | .doit = nl80211_disassociate, | |
9511 | .policy = nl80211_policy, | |
9512 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9514 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 9515 | }, |
04a773ad JB |
9516 | { |
9517 | .cmd = NL80211_CMD_JOIN_IBSS, | |
9518 | .doit = nl80211_join_ibss, | |
9519 | .policy = nl80211_policy, | |
9520 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9521 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9522 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
9523 | }, |
9524 | { | |
9525 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
9526 | .doit = nl80211_leave_ibss, | |
9527 | .policy = nl80211_policy, | |
9528 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9529 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9530 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 9531 | }, |
aff89a9b JB |
9532 | #ifdef CONFIG_NL80211_TESTMODE |
9533 | { | |
9534 | .cmd = NL80211_CMD_TESTMODE, | |
9535 | .doit = nl80211_testmode_do, | |
71063f0e | 9536 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
9537 | .policy = nl80211_policy, |
9538 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9539 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9540 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
9541 | }, |
9542 | #endif | |
b23aa676 SO |
9543 | { |
9544 | .cmd = NL80211_CMD_CONNECT, | |
9545 | .doit = nl80211_connect, | |
9546 | .policy = nl80211_policy, | |
9547 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9548 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9549 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
9550 | }, |
9551 | { | |
9552 | .cmd = NL80211_CMD_DISCONNECT, | |
9553 | .doit = nl80211_disconnect, | |
9554 | .policy = nl80211_policy, | |
9555 | .flags = GENL_ADMIN_PERM, | |
41265714 | 9556 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9557 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 9558 | }, |
463d0183 JB |
9559 | { |
9560 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
9561 | .doit = nl80211_wiphy_netns, | |
9562 | .policy = nl80211_policy, | |
9563 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9564 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
9565 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 9566 | }, |
61fa713c HS |
9567 | { |
9568 | .cmd = NL80211_CMD_GET_SURVEY, | |
9569 | .policy = nl80211_policy, | |
9570 | .dumpit = nl80211_dump_survey, | |
9571 | }, | |
67fbb16b SO |
9572 | { |
9573 | .cmd = NL80211_CMD_SET_PMKSA, | |
9574 | .doit = nl80211_setdel_pmksa, | |
9575 | .policy = nl80211_policy, | |
9576 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9578 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9579 | }, |
9580 | { | |
9581 | .cmd = NL80211_CMD_DEL_PMKSA, | |
9582 | .doit = nl80211_setdel_pmksa, | |
9583 | .policy = nl80211_policy, | |
9584 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9585 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9586 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
9587 | }, |
9588 | { | |
9589 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
9590 | .doit = nl80211_flush_pmksa, | |
9591 | .policy = nl80211_policy, | |
9592 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9593 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 9594 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 9595 | }, |
9588bbd5 JM |
9596 | { |
9597 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
9598 | .doit = nl80211_remain_on_channel, | |
9599 | .policy = nl80211_policy, | |
9600 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9601 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9602 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
9603 | }, |
9604 | { | |
9605 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
9606 | .doit = nl80211_cancel_remain_on_channel, | |
9607 | .policy = nl80211_policy, | |
9608 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9609 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9610 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 9611 | }, |
13ae75b1 JM |
9612 | { |
9613 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
9614 | .doit = nl80211_set_tx_bitrate_mask, | |
9615 | .policy = nl80211_policy, | |
9616 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9617 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9618 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 9619 | }, |
026331c4 | 9620 | { |
2e161f78 JB |
9621 | .cmd = NL80211_CMD_REGISTER_FRAME, |
9622 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
9623 | .policy = nl80211_policy, |
9624 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 9625 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 9626 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
9627 | }, |
9628 | { | |
2e161f78 JB |
9629 | .cmd = NL80211_CMD_FRAME, |
9630 | .doit = nl80211_tx_mgmt, | |
026331c4 | 9631 | .policy = nl80211_policy, |
f7ca38df | 9632 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9633 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
9634 | NL80211_FLAG_NEED_RTNL, |
9635 | }, | |
9636 | { | |
9637 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
9638 | .doit = nl80211_tx_mgmt_cancel_wait, | |
9639 | .policy = nl80211_policy, | |
026331c4 | 9640 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 9641 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 9642 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 9643 | }, |
ffb9eb3d KV |
9644 | { |
9645 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
9646 | .doit = nl80211_set_power_save, | |
9647 | .policy = nl80211_policy, | |
9648 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9649 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9650 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
9651 | }, |
9652 | { | |
9653 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
9654 | .doit = nl80211_get_power_save, | |
9655 | .policy = nl80211_policy, | |
9656 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
9657 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9658 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 9659 | }, |
d6dc1a38 JO |
9660 | { |
9661 | .cmd = NL80211_CMD_SET_CQM, | |
9662 | .doit = nl80211_set_cqm, | |
9663 | .policy = nl80211_policy, | |
9664 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9665 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9666 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 9667 | }, |
f444de05 JB |
9668 | { |
9669 | .cmd = NL80211_CMD_SET_CHANNEL, | |
9670 | .doit = nl80211_set_channel, | |
9671 | .policy = nl80211_policy, | |
9672 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
9673 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9674 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 9675 | }, |
e8347eba BJ |
9676 | { |
9677 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
9678 | .doit = nl80211_set_wds_peer, | |
9679 | .policy = nl80211_policy, | |
9680 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
9681 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
9682 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 9683 | }, |
29cbe68c JB |
9684 | { |
9685 | .cmd = NL80211_CMD_JOIN_MESH, | |
9686 | .doit = nl80211_join_mesh, | |
9687 | .policy = nl80211_policy, | |
9688 | .flags = GENL_ADMIN_PERM, | |
9689 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9690 | NL80211_FLAG_NEED_RTNL, | |
9691 | }, | |
9692 | { | |
9693 | .cmd = NL80211_CMD_LEAVE_MESH, | |
9694 | .doit = nl80211_leave_mesh, | |
9695 | .policy = nl80211_policy, | |
9696 | .flags = GENL_ADMIN_PERM, | |
9697 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9698 | NL80211_FLAG_NEED_RTNL, | |
9699 | }, | |
dfb89c56 | 9700 | #ifdef CONFIG_PM |
ff1b6e69 JB |
9701 | { |
9702 | .cmd = NL80211_CMD_GET_WOWLAN, | |
9703 | .doit = nl80211_get_wowlan, | |
9704 | .policy = nl80211_policy, | |
9705 | /* can be retrieved by unprivileged users */ | |
9706 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9707 | NL80211_FLAG_NEED_RTNL, | |
9708 | }, | |
9709 | { | |
9710 | .cmd = NL80211_CMD_SET_WOWLAN, | |
9711 | .doit = nl80211_set_wowlan, | |
9712 | .policy = nl80211_policy, | |
9713 | .flags = GENL_ADMIN_PERM, | |
9714 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9715 | NL80211_FLAG_NEED_RTNL, | |
9716 | }, | |
dfb89c56 | 9717 | #endif |
e5497d76 JB |
9718 | { |
9719 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
9720 | .doit = nl80211_set_rekey_data, | |
9721 | .policy = nl80211_policy, | |
9722 | .flags = GENL_ADMIN_PERM, | |
9723 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9724 | NL80211_FLAG_NEED_RTNL, | |
9725 | }, | |
109086ce AN |
9726 | { |
9727 | .cmd = NL80211_CMD_TDLS_MGMT, | |
9728 | .doit = nl80211_tdls_mgmt, | |
9729 | .policy = nl80211_policy, | |
9730 | .flags = GENL_ADMIN_PERM, | |
9731 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9732 | NL80211_FLAG_NEED_RTNL, | |
9733 | }, | |
9734 | { | |
9735 | .cmd = NL80211_CMD_TDLS_OPER, | |
9736 | .doit = nl80211_tdls_oper, | |
9737 | .policy = nl80211_policy, | |
9738 | .flags = GENL_ADMIN_PERM, | |
9739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9740 | NL80211_FLAG_NEED_RTNL, | |
9741 | }, | |
28946da7 JB |
9742 | { |
9743 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
9744 | .doit = nl80211_register_unexpected_frame, | |
9745 | .policy = nl80211_policy, | |
9746 | .flags = GENL_ADMIN_PERM, | |
9747 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9748 | NL80211_FLAG_NEED_RTNL, | |
9749 | }, | |
7f6cf311 JB |
9750 | { |
9751 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
9752 | .doit = nl80211_probe_client, | |
9753 | .policy = nl80211_policy, | |
9754 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 9755 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
9756 | NL80211_FLAG_NEED_RTNL, |
9757 | }, | |
5e760230 JB |
9758 | { |
9759 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
9760 | .doit = nl80211_register_beacons, | |
9761 | .policy = nl80211_policy, | |
9762 | .flags = GENL_ADMIN_PERM, | |
9763 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9764 | NL80211_FLAG_NEED_RTNL, | |
9765 | }, | |
1d9d9213 SW |
9766 | { |
9767 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
9768 | .doit = nl80211_set_noack_map, | |
9769 | .policy = nl80211_policy, | |
9770 | .flags = GENL_ADMIN_PERM, | |
9771 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9772 | NL80211_FLAG_NEED_RTNL, | |
9773 | }, | |
98104fde JB |
9774 | { |
9775 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
9776 | .doit = nl80211_start_p2p_device, | |
9777 | .policy = nl80211_policy, | |
9778 | .flags = GENL_ADMIN_PERM, | |
9779 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
9780 | NL80211_FLAG_NEED_RTNL, | |
9781 | }, | |
9782 | { | |
9783 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
9784 | .doit = nl80211_stop_p2p_device, | |
9785 | .policy = nl80211_policy, | |
9786 | .flags = GENL_ADMIN_PERM, | |
9787 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9788 | NL80211_FLAG_NEED_RTNL, | |
9789 | }, | |
f4e583c8 AQ |
9790 | { |
9791 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
9792 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
9793 | .policy = nl80211_policy, |
9794 | .flags = GENL_ADMIN_PERM, | |
9795 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9796 | NL80211_FLAG_NEED_RTNL, | |
9797 | }, | |
9798 | { | |
9799 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
9800 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
9801 | .policy = nl80211_policy, |
9802 | .flags = GENL_ADMIN_PERM, | |
9803 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
9804 | NL80211_FLAG_NEED_RTNL, | |
9805 | }, | |
04f39047 SW |
9806 | { |
9807 | .cmd = NL80211_CMD_RADAR_DETECT, | |
9808 | .doit = nl80211_start_radar_detection, | |
9809 | .policy = nl80211_policy, | |
9810 | .flags = GENL_ADMIN_PERM, | |
9811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9812 | NL80211_FLAG_NEED_RTNL, | |
9813 | }, | |
3713b4e3 JB |
9814 | { |
9815 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
9816 | .doit = nl80211_get_protocol_features, | |
9817 | .policy = nl80211_policy, | |
9818 | }, | |
355199e0 JM |
9819 | { |
9820 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
9821 | .doit = nl80211_update_ft_ies, | |
9822 | .policy = nl80211_policy, | |
9823 | .flags = GENL_ADMIN_PERM, | |
9824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9825 | NL80211_FLAG_NEED_RTNL, | |
9826 | }, | |
5de17984 AS |
9827 | { |
9828 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
9829 | .doit = nl80211_crit_protocol_start, | |
9830 | .policy = nl80211_policy, | |
9831 | .flags = GENL_ADMIN_PERM, | |
9832 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9833 | NL80211_FLAG_NEED_RTNL, | |
9834 | }, | |
9835 | { | |
9836 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
9837 | .doit = nl80211_crit_protocol_stop, | |
9838 | .policy = nl80211_policy, | |
9839 | .flags = GENL_ADMIN_PERM, | |
9840 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
9841 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
9842 | }, |
9843 | { | |
9844 | .cmd = NL80211_CMD_GET_COALESCE, | |
9845 | .doit = nl80211_get_coalesce, | |
9846 | .policy = nl80211_policy, | |
9847 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9848 | NL80211_FLAG_NEED_RTNL, | |
9849 | }, | |
9850 | { | |
9851 | .cmd = NL80211_CMD_SET_COALESCE, | |
9852 | .doit = nl80211_set_coalesce, | |
9853 | .policy = nl80211_policy, | |
9854 | .flags = GENL_ADMIN_PERM, | |
9855 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9856 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
9857 | }, |
9858 | { | |
9859 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
9860 | .doit = nl80211_channel_switch, | |
9861 | .policy = nl80211_policy, | |
9862 | .flags = GENL_ADMIN_PERM, | |
9863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9864 | NL80211_FLAG_NEED_RTNL, | |
9865 | }, | |
ad7e718c JB |
9866 | { |
9867 | .cmd = NL80211_CMD_VENDOR, | |
9868 | .doit = nl80211_vendor_cmd, | |
9869 | .policy = nl80211_policy, | |
9870 | .flags = GENL_ADMIN_PERM, | |
9871 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
9872 | NL80211_FLAG_NEED_RTNL, | |
9873 | }, | |
fa9ffc74 KP |
9874 | { |
9875 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
9876 | .doit = nl80211_set_qos_map, | |
9877 | .policy = nl80211_policy, | |
9878 | .flags = GENL_ADMIN_PERM, | |
9879 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
9880 | NL80211_FLAG_NEED_RTNL, | |
9881 | }, | |
55682965 | 9882 | }; |
9588bbd5 | 9883 | |
55682965 JB |
9884 | /* notification functions */ |
9885 | ||
9886 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
9887 | { | |
9888 | struct sk_buff *msg; | |
86e8cf98 | 9889 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 9890 | |
fd2120ca | 9891 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
9892 | if (!msg) |
9893 | return; | |
9894 | ||
86e8cf98 | 9895 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
9896 | nlmsg_free(msg); |
9897 | return; | |
9898 | } | |
9899 | ||
68eb5503 | 9900 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 9901 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
9902 | } |
9903 | ||
362a415d JB |
9904 | static int nl80211_add_scan_req(struct sk_buff *msg, |
9905 | struct cfg80211_registered_device *rdev) | |
9906 | { | |
9907 | struct cfg80211_scan_request *req = rdev->scan_req; | |
9908 | struct nlattr *nest; | |
9909 | int i; | |
9910 | ||
9911 | if (WARN_ON(!req)) | |
9912 | return 0; | |
9913 | ||
9914 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
9915 | if (!nest) | |
9916 | goto nla_put_failure; | |
9360ffd1 DM |
9917 | for (i = 0; i < req->n_ssids; i++) { |
9918 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
9919 | goto nla_put_failure; | |
9920 | } | |
362a415d JB |
9921 | nla_nest_end(msg, nest); |
9922 | ||
9923 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
9924 | if (!nest) | |
9925 | goto nla_put_failure; | |
9360ffd1 DM |
9926 | for (i = 0; i < req->n_channels; i++) { |
9927 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9928 | goto nla_put_failure; | |
9929 | } | |
362a415d JB |
9930 | nla_nest_end(msg, nest); |
9931 | ||
9360ffd1 DM |
9932 | if (req->ie && |
9933 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
9934 | goto nla_put_failure; | |
362a415d | 9935 | |
ae917c9f JB |
9936 | if (req->flags && |
9937 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
9938 | goto nla_put_failure; | |
ed473771 | 9939 | |
362a415d JB |
9940 | return 0; |
9941 | nla_put_failure: | |
9942 | return -ENOBUFS; | |
9943 | } | |
9944 | ||
a538e2d5 JB |
9945 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
9946 | struct cfg80211_registered_device *rdev, | |
fd014284 | 9947 | struct wireless_dev *wdev, |
15e47304 | 9948 | u32 portid, u32 seq, int flags, |
a538e2d5 | 9949 | u32 cmd) |
2a519311 JB |
9950 | { |
9951 | void *hdr; | |
9952 | ||
15e47304 | 9953 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
9954 | if (!hdr) |
9955 | return -1; | |
9956 | ||
9360ffd1 | 9957 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
9958 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
9959 | wdev->netdev->ifindex)) || | |
9960 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 9961 | goto nla_put_failure; |
2a519311 | 9962 | |
362a415d JB |
9963 | /* ignore errors and send incomplete event anyway */ |
9964 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
9965 | |
9966 | return genlmsg_end(msg, hdr); | |
9967 | ||
9968 | nla_put_failure: | |
9969 | genlmsg_cancel(msg, hdr); | |
9970 | return -EMSGSIZE; | |
9971 | } | |
9972 | ||
807f8a8c LC |
9973 | static int |
9974 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
9975 | struct cfg80211_registered_device *rdev, | |
9976 | struct net_device *netdev, | |
15e47304 | 9977 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
9978 | { |
9979 | void *hdr; | |
9980 | ||
15e47304 | 9981 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
9982 | if (!hdr) |
9983 | return -1; | |
9984 | ||
9360ffd1 DM |
9985 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
9986 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
9987 | goto nla_put_failure; | |
807f8a8c LC |
9988 | |
9989 | return genlmsg_end(msg, hdr); | |
9990 | ||
9991 | nla_put_failure: | |
9992 | genlmsg_cancel(msg, hdr); | |
9993 | return -EMSGSIZE; | |
9994 | } | |
9995 | ||
a538e2d5 | 9996 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 9997 | struct wireless_dev *wdev) |
a538e2d5 JB |
9998 | { |
9999 | struct sk_buff *msg; | |
10000 | ||
58050fce | 10001 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
10002 | if (!msg) |
10003 | return; | |
10004 | ||
fd014284 | 10005 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
10006 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
10007 | nlmsg_free(msg); | |
10008 | return; | |
10009 | } | |
10010 | ||
68eb5503 | 10011 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10012 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
10013 | } |
10014 | ||
2a519311 | 10015 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
fd014284 | 10016 | struct wireless_dev *wdev) |
2a519311 JB |
10017 | { |
10018 | struct sk_buff *msg; | |
10019 | ||
fd2120ca | 10020 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
10021 | if (!msg) |
10022 | return; | |
10023 | ||
fd014284 | 10024 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 10025 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
2a519311 JB |
10026 | nlmsg_free(msg); |
10027 | return; | |
10028 | } | |
10029 | ||
68eb5503 | 10030 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10031 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10032 | } |
10033 | ||
10034 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
fd014284 | 10035 | struct wireless_dev *wdev) |
2a519311 JB |
10036 | { |
10037 | struct sk_buff *msg; | |
10038 | ||
fd2120ca | 10039 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
10040 | if (!msg) |
10041 | return; | |
10042 | ||
fd014284 | 10043 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 | 10044 | NL80211_CMD_SCAN_ABORTED) < 0) { |
2a519311 JB |
10045 | nlmsg_free(msg); |
10046 | return; | |
10047 | } | |
10048 | ||
68eb5503 | 10049 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10050 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
10051 | } |
10052 | ||
807f8a8c LC |
10053 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
10054 | struct net_device *netdev) | |
10055 | { | |
10056 | struct sk_buff *msg; | |
10057 | ||
10058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10059 | if (!msg) | |
10060 | return; | |
10061 | ||
10062 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
10063 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
10064 | nlmsg_free(msg); | |
10065 | return; | |
10066 | } | |
10067 | ||
68eb5503 | 10068 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10069 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10070 | } |
10071 | ||
10072 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
10073 | struct net_device *netdev, u32 cmd) | |
10074 | { | |
10075 | struct sk_buff *msg; | |
10076 | ||
58050fce | 10077 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
10078 | if (!msg) |
10079 | return; | |
10080 | ||
10081 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
10082 | nlmsg_free(msg); | |
10083 | return; | |
10084 | } | |
10085 | ||
68eb5503 | 10086 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10087 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
10088 | } |
10089 | ||
73d54c9e LR |
10090 | /* |
10091 | * This can happen on global regulatory changes or device specific settings | |
10092 | * based on custom world regulatory domains. | |
10093 | */ | |
10094 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
10095 | { | |
10096 | struct sk_buff *msg; | |
10097 | void *hdr; | |
10098 | ||
fd2120ca | 10099 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
10100 | if (!msg) |
10101 | return; | |
10102 | ||
10103 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
10104 | if (!hdr) { | |
10105 | nlmsg_free(msg); | |
10106 | return; | |
10107 | } | |
10108 | ||
10109 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
10110 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
10111 | goto nla_put_failure; | |
10112 | ||
10113 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
10114 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10115 | NL80211_REGDOM_TYPE_WORLD)) | |
10116 | goto nla_put_failure; | |
10117 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
10118 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10119 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
10120 | goto nla_put_failure; | |
10121 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
10122 | request->intersect) { | |
10123 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10124 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
10125 | goto nla_put_failure; | |
10126 | } else { | |
10127 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
10128 | NL80211_REGDOM_TYPE_COUNTRY) || | |
10129 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
10130 | request->alpha2)) | |
10131 | goto nla_put_failure; | |
10132 | } | |
10133 | ||
f4173766 | 10134 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
9360ffd1 DM |
10135 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
10136 | goto nla_put_failure; | |
73d54c9e | 10137 | |
3b7b72ee | 10138 | genlmsg_end(msg, hdr); |
73d54c9e | 10139 | |
bc43b28c | 10140 | rcu_read_lock(); |
68eb5503 | 10141 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10142 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 10143 | rcu_read_unlock(); |
73d54c9e LR |
10144 | |
10145 | return; | |
10146 | ||
10147 | nla_put_failure: | |
10148 | genlmsg_cancel(msg, hdr); | |
10149 | nlmsg_free(msg); | |
10150 | } | |
10151 | ||
6039f6d2 JM |
10152 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
10153 | struct net_device *netdev, | |
10154 | const u8 *buf, size_t len, | |
e6d6e342 | 10155 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
10156 | { |
10157 | struct sk_buff *msg; | |
10158 | void *hdr; | |
10159 | ||
e6d6e342 | 10160 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
10161 | if (!msg) |
10162 | return; | |
10163 | ||
10164 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10165 | if (!hdr) { | |
10166 | nlmsg_free(msg); | |
10167 | return; | |
10168 | } | |
10169 | ||
9360ffd1 DM |
10170 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10171 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10172 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
10173 | goto nla_put_failure; | |
6039f6d2 | 10174 | |
3b7b72ee | 10175 | genlmsg_end(msg, hdr); |
6039f6d2 | 10176 | |
68eb5503 | 10177 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10178 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
10179 | return; |
10180 | ||
10181 | nla_put_failure: | |
10182 | genlmsg_cancel(msg, hdr); | |
10183 | nlmsg_free(msg); | |
10184 | } | |
10185 | ||
10186 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10187 | struct net_device *netdev, const u8 *buf, |
10188 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10189 | { |
10190 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10191 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
10192 | } |
10193 | ||
10194 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
10195 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10196 | size_t len, gfp_t gfp) |
6039f6d2 | 10197 | { |
e6d6e342 JB |
10198 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
10199 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
10200 | } |
10201 | ||
53b46b84 | 10202 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
10203 | struct net_device *netdev, const u8 *buf, |
10204 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
10205 | { |
10206 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10207 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
10208 | } |
10209 | ||
53b46b84 JM |
10210 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
10211 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 10212 | size_t len, gfp_t gfp) |
6039f6d2 JM |
10213 | { |
10214 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 10215 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
10216 | } |
10217 | ||
6ff57cf8 JB |
10218 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
10219 | size_t len) | |
cf4e594e | 10220 | { |
947add36 JB |
10221 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10222 | struct wiphy *wiphy = wdev->wiphy; | |
10223 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
6ff57cf8 JB |
10224 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
10225 | u32 cmd; | |
947add36 | 10226 | |
6ff57cf8 JB |
10227 | if (WARN_ON(len < 2)) |
10228 | return; | |
cf4e594e | 10229 | |
6ff57cf8 JB |
10230 | if (ieee80211_is_deauth(mgmt->frame_control)) |
10231 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
10232 | else | |
10233 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 10234 | |
6ff57cf8 JB |
10235 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
10236 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); | |
cf4e594e | 10237 | } |
6ff57cf8 | 10238 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 10239 | |
1b06bb40 LR |
10240 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
10241 | struct net_device *netdev, int cmd, | |
e6d6e342 | 10242 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
10243 | { |
10244 | struct sk_buff *msg; | |
10245 | void *hdr; | |
10246 | ||
e6d6e342 | 10247 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
10248 | if (!msg) |
10249 | return; | |
10250 | ||
10251 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10252 | if (!hdr) { | |
10253 | nlmsg_free(msg); | |
10254 | return; | |
10255 | } | |
10256 | ||
9360ffd1 DM |
10257 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10258 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10259 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
10260 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10261 | goto nla_put_failure; | |
1965c853 | 10262 | |
3b7b72ee | 10263 | genlmsg_end(msg, hdr); |
1965c853 | 10264 | |
68eb5503 | 10265 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10266 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
10267 | return; |
10268 | ||
10269 | nla_put_failure: | |
10270 | genlmsg_cancel(msg, hdr); | |
10271 | nlmsg_free(msg); | |
10272 | } | |
10273 | ||
10274 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10275 | struct net_device *netdev, const u8 *addr, |
10276 | gfp_t gfp) | |
1965c853 JM |
10277 | { |
10278 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 10279 | addr, gfp); |
1965c853 JM |
10280 | } |
10281 | ||
10282 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
10283 | struct net_device *netdev, const u8 *addr, |
10284 | gfp_t gfp) | |
1965c853 | 10285 | { |
e6d6e342 JB |
10286 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
10287 | addr, gfp); | |
1965c853 JM |
10288 | } |
10289 | ||
b23aa676 SO |
10290 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
10291 | struct net_device *netdev, const u8 *bssid, | |
10292 | const u8 *req_ie, size_t req_ie_len, | |
10293 | const u8 *resp_ie, size_t resp_ie_len, | |
10294 | u16 status, gfp_t gfp) | |
10295 | { | |
10296 | struct sk_buff *msg; | |
10297 | void *hdr; | |
10298 | ||
58050fce | 10299 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10300 | if (!msg) |
10301 | return; | |
10302 | ||
10303 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
10304 | if (!hdr) { | |
10305 | nlmsg_free(msg); | |
10306 | return; | |
10307 | } | |
10308 | ||
9360ffd1 DM |
10309 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10310 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10311 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
10312 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
10313 | (req_ie && | |
10314 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10315 | (resp_ie && | |
10316 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10317 | goto nla_put_failure; | |
b23aa676 | 10318 | |
3b7b72ee | 10319 | genlmsg_end(msg, hdr); |
b23aa676 | 10320 | |
68eb5503 | 10321 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10322 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10323 | return; |
10324 | ||
10325 | nla_put_failure: | |
10326 | genlmsg_cancel(msg, hdr); | |
10327 | nlmsg_free(msg); | |
10328 | ||
10329 | } | |
10330 | ||
10331 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
10332 | struct net_device *netdev, const u8 *bssid, | |
10333 | const u8 *req_ie, size_t req_ie_len, | |
10334 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
10335 | { | |
10336 | struct sk_buff *msg; | |
10337 | void *hdr; | |
10338 | ||
58050fce | 10339 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
10340 | if (!msg) |
10341 | return; | |
10342 | ||
10343 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
10344 | if (!hdr) { | |
10345 | nlmsg_free(msg); | |
10346 | return; | |
10347 | } | |
10348 | ||
9360ffd1 DM |
10349 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10350 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10351 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
10352 | (req_ie && | |
10353 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
10354 | (resp_ie && | |
10355 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
10356 | goto nla_put_failure; | |
b23aa676 | 10357 | |
3b7b72ee | 10358 | genlmsg_end(msg, hdr); |
b23aa676 | 10359 | |
68eb5503 | 10360 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10361 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
10362 | return; |
10363 | ||
10364 | nla_put_failure: | |
10365 | genlmsg_cancel(msg, hdr); | |
10366 | nlmsg_free(msg); | |
10367 | ||
10368 | } | |
10369 | ||
10370 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
10371 | struct net_device *netdev, u16 reason, | |
667503dd | 10372 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
10373 | { |
10374 | struct sk_buff *msg; | |
10375 | void *hdr; | |
10376 | ||
58050fce | 10377 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
10378 | if (!msg) |
10379 | return; | |
10380 | ||
10381 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
10382 | if (!hdr) { | |
10383 | nlmsg_free(msg); | |
10384 | return; | |
10385 | } | |
10386 | ||
9360ffd1 DM |
10387 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10388 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10389 | (from_ap && reason && | |
10390 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
10391 | (from_ap && | |
10392 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
10393 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
10394 | goto nla_put_failure; | |
b23aa676 | 10395 | |
3b7b72ee | 10396 | genlmsg_end(msg, hdr); |
b23aa676 | 10397 | |
68eb5503 | 10398 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10399 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
10400 | return; |
10401 | ||
10402 | nla_put_failure: | |
10403 | genlmsg_cancel(msg, hdr); | |
10404 | nlmsg_free(msg); | |
10405 | ||
10406 | } | |
10407 | ||
04a773ad JB |
10408 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
10409 | struct net_device *netdev, const u8 *bssid, | |
10410 | gfp_t gfp) | |
10411 | { | |
10412 | struct sk_buff *msg; | |
10413 | void *hdr; | |
10414 | ||
fd2120ca | 10415 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
10416 | if (!msg) |
10417 | return; | |
10418 | ||
10419 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
10420 | if (!hdr) { | |
10421 | nlmsg_free(msg); | |
10422 | return; | |
10423 | } | |
10424 | ||
9360ffd1 DM |
10425 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10426 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10427 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10428 | goto nla_put_failure; | |
04a773ad | 10429 | |
3b7b72ee | 10430 | genlmsg_end(msg, hdr); |
04a773ad | 10431 | |
68eb5503 | 10432 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10433 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
10434 | return; |
10435 | ||
10436 | nla_put_failure: | |
10437 | genlmsg_cancel(msg, hdr); | |
10438 | nlmsg_free(msg); | |
10439 | } | |
10440 | ||
947add36 JB |
10441 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
10442 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 10443 | { |
947add36 JB |
10444 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10445 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
c93b5e71 JC |
10446 | struct sk_buff *msg; |
10447 | void *hdr; | |
10448 | ||
947add36 JB |
10449 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
10450 | return; | |
10451 | ||
10452 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
10453 | ||
c93b5e71 JC |
10454 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10455 | if (!msg) | |
10456 | return; | |
10457 | ||
10458 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
10459 | if (!hdr) { | |
10460 | nlmsg_free(msg); | |
10461 | return; | |
10462 | } | |
10463 | ||
9360ffd1 | 10464 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
10465 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10466 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
10467 | (ie_len && ie && |
10468 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
10469 | goto nla_put_failure; | |
c93b5e71 | 10470 | |
3b7b72ee | 10471 | genlmsg_end(msg, hdr); |
c93b5e71 | 10472 | |
68eb5503 | 10473 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10474 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
10475 | return; |
10476 | ||
10477 | nla_put_failure: | |
10478 | genlmsg_cancel(msg, hdr); | |
10479 | nlmsg_free(msg); | |
10480 | } | |
947add36 | 10481 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 10482 | |
a3b8b056 JM |
10483 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
10484 | struct net_device *netdev, const u8 *addr, | |
10485 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 10486 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
10487 | { |
10488 | struct sk_buff *msg; | |
10489 | void *hdr; | |
10490 | ||
e6d6e342 | 10491 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
10492 | if (!msg) |
10493 | return; | |
10494 | ||
10495 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
10496 | if (!hdr) { | |
10497 | nlmsg_free(msg); | |
10498 | return; | |
10499 | } | |
10500 | ||
9360ffd1 DM |
10501 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10502 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10503 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
10504 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
10505 | (key_id != -1 && | |
10506 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
10507 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
10508 | goto nla_put_failure; | |
a3b8b056 | 10509 | |
3b7b72ee | 10510 | genlmsg_end(msg, hdr); |
a3b8b056 | 10511 | |
68eb5503 | 10512 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10513 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
10514 | return; |
10515 | ||
10516 | nla_put_failure: | |
10517 | genlmsg_cancel(msg, hdr); | |
10518 | nlmsg_free(msg); | |
10519 | } | |
10520 | ||
6bad8766 LR |
10521 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
10522 | struct ieee80211_channel *channel_before, | |
10523 | struct ieee80211_channel *channel_after) | |
10524 | { | |
10525 | struct sk_buff *msg; | |
10526 | void *hdr; | |
10527 | struct nlattr *nl_freq; | |
10528 | ||
fd2120ca | 10529 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
10530 | if (!msg) |
10531 | return; | |
10532 | ||
10533 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
10534 | if (!hdr) { | |
10535 | nlmsg_free(msg); | |
10536 | return; | |
10537 | } | |
10538 | ||
10539 | /* | |
10540 | * Since we are applying the beacon hint to a wiphy we know its | |
10541 | * wiphy_idx is valid | |
10542 | */ | |
9360ffd1 DM |
10543 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
10544 | goto nla_put_failure; | |
6bad8766 LR |
10545 | |
10546 | /* Before */ | |
10547 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
10548 | if (!nl_freq) | |
10549 | goto nla_put_failure; | |
cdc89b97 | 10550 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
10551 | goto nla_put_failure; |
10552 | nla_nest_end(msg, nl_freq); | |
10553 | ||
10554 | /* After */ | |
10555 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
10556 | if (!nl_freq) | |
10557 | goto nla_put_failure; | |
cdc89b97 | 10558 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
10559 | goto nla_put_failure; |
10560 | nla_nest_end(msg, nl_freq); | |
10561 | ||
3b7b72ee | 10562 | genlmsg_end(msg, hdr); |
6bad8766 | 10563 | |
463d0183 | 10564 | rcu_read_lock(); |
68eb5503 | 10565 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 10566 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 10567 | rcu_read_unlock(); |
6bad8766 LR |
10568 | |
10569 | return; | |
10570 | ||
10571 | nla_put_failure: | |
10572 | genlmsg_cancel(msg, hdr); | |
10573 | nlmsg_free(msg); | |
10574 | } | |
10575 | ||
9588bbd5 JM |
10576 | static void nl80211_send_remain_on_chan_event( |
10577 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 10578 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 10579 | struct ieee80211_channel *chan, |
9588bbd5 JM |
10580 | unsigned int duration, gfp_t gfp) |
10581 | { | |
10582 | struct sk_buff *msg; | |
10583 | void *hdr; | |
10584 | ||
10585 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10586 | if (!msg) | |
10587 | return; | |
10588 | ||
10589 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
10590 | if (!hdr) { | |
10591 | nlmsg_free(msg); | |
10592 | return; | |
10593 | } | |
10594 | ||
9360ffd1 | 10595 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10596 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10597 | wdev->netdev->ifindex)) || | |
00f53350 | 10598 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 10599 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
10600 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
10601 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
10602 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
10603 | goto nla_put_failure; | |
9588bbd5 | 10604 | |
9360ffd1 DM |
10605 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
10606 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
10607 | goto nla_put_failure; | |
9588bbd5 | 10608 | |
3b7b72ee | 10609 | genlmsg_end(msg, hdr); |
9588bbd5 | 10610 | |
68eb5503 | 10611 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10612 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
10613 | return; |
10614 | ||
10615 | nla_put_failure: | |
10616 | genlmsg_cancel(msg, hdr); | |
10617 | nlmsg_free(msg); | |
10618 | } | |
10619 | ||
947add36 JB |
10620 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
10621 | struct ieee80211_channel *chan, | |
10622 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 10623 | { |
947add36 JB |
10624 | struct wiphy *wiphy = wdev->wiphy; |
10625 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10626 | ||
10627 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 10628 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 10629 | rdev, wdev, cookie, chan, |
42d97a59 | 10630 | duration, gfp); |
9588bbd5 | 10631 | } |
947add36 | 10632 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 10633 | |
947add36 JB |
10634 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
10635 | struct ieee80211_channel *chan, | |
10636 | gfp_t gfp) | |
9588bbd5 | 10637 | { |
947add36 JB |
10638 | struct wiphy *wiphy = wdev->wiphy; |
10639 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
10640 | ||
10641 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 10642 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 10643 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 10644 | } |
947add36 | 10645 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 10646 | |
947add36 JB |
10647 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
10648 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 10649 | { |
947add36 JB |
10650 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10651 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
98b62183 JB |
10652 | struct sk_buff *msg; |
10653 | ||
947add36 JB |
10654 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
10655 | ||
58050fce | 10656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
10657 | if (!msg) |
10658 | return; | |
10659 | ||
66266b3a JL |
10660 | if (nl80211_send_station(msg, 0, 0, 0, |
10661 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
10662 | nlmsg_free(msg); |
10663 | return; | |
10664 | } | |
10665 | ||
68eb5503 | 10666 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10667 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 10668 | } |
947add36 | 10669 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 10670 | |
947add36 | 10671 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
ec15e68b | 10672 | { |
947add36 JB |
10673 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10674 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ec15e68b JM |
10675 | struct sk_buff *msg; |
10676 | void *hdr; | |
10677 | ||
947add36 JB |
10678 | trace_cfg80211_del_sta(dev, mac_addr); |
10679 | ||
58050fce | 10680 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
10681 | if (!msg) |
10682 | return; | |
10683 | ||
10684 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
10685 | if (!hdr) { | |
10686 | nlmsg_free(msg); | |
10687 | return; | |
10688 | } | |
10689 | ||
9360ffd1 DM |
10690 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
10691 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
10692 | goto nla_put_failure; | |
ec15e68b | 10693 | |
3b7b72ee | 10694 | genlmsg_end(msg, hdr); |
ec15e68b | 10695 | |
68eb5503 | 10696 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10697 | NL80211_MCGRP_MLME, gfp); |
ec15e68b JM |
10698 | return; |
10699 | ||
10700 | nla_put_failure: | |
10701 | genlmsg_cancel(msg, hdr); | |
10702 | nlmsg_free(msg); | |
10703 | } | |
947add36 | 10704 | EXPORT_SYMBOL(cfg80211_del_sta); |
ec15e68b | 10705 | |
947add36 JB |
10706 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
10707 | enum nl80211_connect_failed_reason reason, | |
10708 | gfp_t gfp) | |
ed44a951 | 10709 | { |
947add36 JB |
10710 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
10711 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
ed44a951 PP |
10712 | struct sk_buff *msg; |
10713 | void *hdr; | |
10714 | ||
10715 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
10716 | if (!msg) | |
10717 | return; | |
10718 | ||
10719 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
10720 | if (!hdr) { | |
10721 | nlmsg_free(msg); | |
10722 | return; | |
10723 | } | |
10724 | ||
10725 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10726 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
10727 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
10728 | goto nla_put_failure; | |
10729 | ||
10730 | genlmsg_end(msg, hdr); | |
10731 | ||
68eb5503 | 10732 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10733 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
10734 | return; |
10735 | ||
10736 | nla_put_failure: | |
10737 | genlmsg_cancel(msg, hdr); | |
10738 | nlmsg_free(msg); | |
10739 | } | |
947add36 | 10740 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 10741 | |
b92ab5d8 JB |
10742 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
10743 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
10744 | { |
10745 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10746 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
10747 | struct sk_buff *msg; | |
10748 | void *hdr; | |
15e47304 | 10749 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 10750 | |
15e47304 | 10751 | if (!nlportid) |
28946da7 JB |
10752 | return false; |
10753 | ||
10754 | msg = nlmsg_new(100, gfp); | |
10755 | if (!msg) | |
10756 | return true; | |
10757 | ||
b92ab5d8 | 10758 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
10759 | if (!hdr) { |
10760 | nlmsg_free(msg); | |
10761 | return true; | |
10762 | } | |
10763 | ||
9360ffd1 DM |
10764 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10765 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
10766 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
10767 | goto nla_put_failure; | |
28946da7 | 10768 | |
9c90a9f6 | 10769 | genlmsg_end(msg, hdr); |
15e47304 | 10770 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
10771 | return true; |
10772 | ||
10773 | nla_put_failure: | |
10774 | genlmsg_cancel(msg, hdr); | |
10775 | nlmsg_free(msg); | |
10776 | return true; | |
10777 | } | |
10778 | ||
947add36 JB |
10779 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
10780 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10781 | { |
947add36 JB |
10782 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10783 | bool ret; | |
10784 | ||
10785 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
10786 | ||
10787 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10788 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
10789 | trace_cfg80211_return_bool(false); | |
10790 | return false; | |
10791 | } | |
10792 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
10793 | addr, gfp); | |
10794 | trace_cfg80211_return_bool(ret); | |
10795 | return ret; | |
b92ab5d8 | 10796 | } |
947add36 | 10797 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 10798 | |
947add36 JB |
10799 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
10800 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 10801 | { |
947add36 JB |
10802 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10803 | bool ret; | |
10804 | ||
10805 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
10806 | ||
10807 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
10808 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
10809 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
10810 | trace_cfg80211_return_bool(false); | |
10811 | return false; | |
10812 | } | |
10813 | ret = __nl80211_unexpected_frame(dev, | |
10814 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
10815 | addr, gfp); | |
10816 | trace_cfg80211_return_bool(ret); | |
10817 | return ret; | |
b92ab5d8 | 10818 | } |
947add36 | 10819 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 10820 | |
2e161f78 | 10821 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 10822 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 10823 | int freq, int sig_dbm, |
19504cf5 | 10824 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 10825 | { |
71bbc994 | 10826 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10827 | struct sk_buff *msg; |
10828 | void *hdr; | |
026331c4 JM |
10829 | |
10830 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10831 | if (!msg) | |
10832 | return -ENOMEM; | |
10833 | ||
2e161f78 | 10834 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
10835 | if (!hdr) { |
10836 | nlmsg_free(msg); | |
10837 | return -ENOMEM; | |
10838 | } | |
10839 | ||
9360ffd1 | 10840 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10841 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10842 | netdev->ifindex)) || | |
a838490b | 10843 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10844 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
10845 | (sig_dbm && | |
10846 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
10847 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10848 | (flags && | |
10849 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 10850 | goto nla_put_failure; |
026331c4 | 10851 | |
3b7b72ee | 10852 | genlmsg_end(msg, hdr); |
026331c4 | 10853 | |
15e47304 | 10854 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
10855 | |
10856 | nla_put_failure: | |
10857 | genlmsg_cancel(msg, hdr); | |
10858 | nlmsg_free(msg); | |
10859 | return -ENOBUFS; | |
10860 | } | |
10861 | ||
947add36 JB |
10862 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
10863 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 10864 | { |
947add36 JB |
10865 | struct wiphy *wiphy = wdev->wiphy; |
10866 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
71bbc994 | 10867 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
10868 | struct sk_buff *msg; |
10869 | void *hdr; | |
10870 | ||
947add36 JB |
10871 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
10872 | ||
026331c4 JM |
10873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
10874 | if (!msg) | |
10875 | return; | |
10876 | ||
2e161f78 | 10877 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
10878 | if (!hdr) { |
10879 | nlmsg_free(msg); | |
10880 | return; | |
10881 | } | |
10882 | ||
9360ffd1 | 10883 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
10884 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
10885 | netdev->ifindex)) || | |
a838490b | 10886 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
10887 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
10888 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
10889 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
10890 | goto nla_put_failure; | |
026331c4 | 10891 | |
3b7b72ee | 10892 | genlmsg_end(msg, hdr); |
026331c4 | 10893 | |
68eb5503 | 10894 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10895 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
10896 | return; |
10897 | ||
10898 | nla_put_failure: | |
10899 | genlmsg_cancel(msg, hdr); | |
10900 | nlmsg_free(msg); | |
10901 | } | |
947add36 | 10902 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 10903 | |
947add36 JB |
10904 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
10905 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
10906 | gfp_t gfp) | |
d6dc1a38 | 10907 | { |
947add36 JB |
10908 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
10909 | struct wiphy *wiphy = wdev->wiphy; | |
10910 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
d6dc1a38 JO |
10911 | struct sk_buff *msg; |
10912 | struct nlattr *pinfoattr; | |
10913 | void *hdr; | |
10914 | ||
947add36 JB |
10915 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
10916 | ||
58050fce | 10917 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
d6dc1a38 JO |
10918 | if (!msg) |
10919 | return; | |
10920 | ||
10921 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
10922 | if (!hdr) { | |
10923 | nlmsg_free(msg); | |
10924 | return; | |
10925 | } | |
10926 | ||
9360ffd1 | 10927 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 10928 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 10929 | goto nla_put_failure; |
d6dc1a38 JO |
10930 | |
10931 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
10932 | if (!pinfoattr) | |
10933 | goto nla_put_failure; | |
10934 | ||
9360ffd1 DM |
10935 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
10936 | rssi_event)) | |
10937 | goto nla_put_failure; | |
d6dc1a38 JO |
10938 | |
10939 | nla_nest_end(msg, pinfoattr); | |
10940 | ||
3b7b72ee | 10941 | genlmsg_end(msg, hdr); |
d6dc1a38 | 10942 | |
68eb5503 | 10943 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10944 | NL80211_MCGRP_MLME, gfp); |
d6dc1a38 JO |
10945 | return; |
10946 | ||
10947 | nla_put_failure: | |
10948 | genlmsg_cancel(msg, hdr); | |
10949 | nlmsg_free(msg); | |
10950 | } | |
947add36 | 10951 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 10952 | |
947add36 JB |
10953 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
10954 | struct net_device *netdev, const u8 *bssid, | |
10955 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
10956 | { |
10957 | struct sk_buff *msg; | |
10958 | struct nlattr *rekey_attr; | |
10959 | void *hdr; | |
10960 | ||
58050fce | 10961 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
10962 | if (!msg) |
10963 | return; | |
10964 | ||
10965 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
10966 | if (!hdr) { | |
10967 | nlmsg_free(msg); | |
10968 | return; | |
10969 | } | |
10970 | ||
9360ffd1 DM |
10971 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
10972 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
10973 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
10974 | goto nla_put_failure; | |
e5497d76 JB |
10975 | |
10976 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10977 | if (!rekey_attr) | |
10978 | goto nla_put_failure; | |
10979 | ||
9360ffd1 DM |
10980 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
10981 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
10982 | goto nla_put_failure; | |
e5497d76 JB |
10983 | |
10984 | nla_nest_end(msg, rekey_attr); | |
10985 | ||
3b7b72ee | 10986 | genlmsg_end(msg, hdr); |
e5497d76 | 10987 | |
68eb5503 | 10988 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 10989 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
10990 | return; |
10991 | ||
10992 | nla_put_failure: | |
10993 | genlmsg_cancel(msg, hdr); | |
10994 | nlmsg_free(msg); | |
10995 | } | |
10996 | ||
947add36 JB |
10997 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
10998 | const u8 *replay_ctr, gfp_t gfp) | |
10999 | { | |
11000 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11001 | struct wiphy *wiphy = wdev->wiphy; | |
11002 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11003 | ||
11004 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
11005 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
11006 | } | |
11007 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
11008 | ||
11009 | static void | |
11010 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
11011 | struct net_device *netdev, int index, | |
11012 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
11013 | { |
11014 | struct sk_buff *msg; | |
11015 | struct nlattr *attr; | |
11016 | void *hdr; | |
11017 | ||
58050fce | 11018 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
11019 | if (!msg) |
11020 | return; | |
11021 | ||
11022 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
11023 | if (!hdr) { | |
11024 | nlmsg_free(msg); | |
11025 | return; | |
11026 | } | |
11027 | ||
9360ffd1 DM |
11028 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11029 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11030 | goto nla_put_failure; | |
c9df56b4 JM |
11031 | |
11032 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
11033 | if (!attr) | |
11034 | goto nla_put_failure; | |
11035 | ||
9360ffd1 DM |
11036 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
11037 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
11038 | (preauth && | |
11039 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
11040 | goto nla_put_failure; | |
c9df56b4 JM |
11041 | |
11042 | nla_nest_end(msg, attr); | |
11043 | ||
3b7b72ee | 11044 | genlmsg_end(msg, hdr); |
c9df56b4 | 11045 | |
68eb5503 | 11046 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11047 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
11048 | return; |
11049 | ||
11050 | nla_put_failure: | |
11051 | genlmsg_cancel(msg, hdr); | |
11052 | nlmsg_free(msg); | |
11053 | } | |
11054 | ||
947add36 JB |
11055 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
11056 | const u8 *bssid, bool preauth, gfp_t gfp) | |
11057 | { | |
11058 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11059 | struct wiphy *wiphy = wdev->wiphy; | |
11060 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11061 | ||
11062 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
11063 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
11064 | } | |
11065 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
11066 | ||
11067 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
11068 | struct net_device *netdev, | |
11069 | struct cfg80211_chan_def *chandef, | |
11070 | gfp_t gfp) | |
5314526b TP |
11071 | { |
11072 | struct sk_buff *msg; | |
11073 | void *hdr; | |
11074 | ||
58050fce | 11075 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
11076 | if (!msg) |
11077 | return; | |
11078 | ||
11079 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
11080 | if (!hdr) { | |
11081 | nlmsg_free(msg); | |
11082 | return; | |
11083 | } | |
11084 | ||
683b6d3b JB |
11085 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
11086 | goto nla_put_failure; | |
11087 | ||
11088 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 11089 | goto nla_put_failure; |
5314526b TP |
11090 | |
11091 | genlmsg_end(msg, hdr); | |
11092 | ||
68eb5503 | 11093 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11094 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
11095 | return; |
11096 | ||
11097 | nla_put_failure: | |
11098 | genlmsg_cancel(msg, hdr); | |
11099 | nlmsg_free(msg); | |
11100 | } | |
11101 | ||
947add36 JB |
11102 | void cfg80211_ch_switch_notify(struct net_device *dev, |
11103 | struct cfg80211_chan_def *chandef) | |
84f10708 | 11104 | { |
947add36 JB |
11105 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11106 | struct wiphy *wiphy = wdev->wiphy; | |
11107 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11108 | ||
e487eaeb | 11109 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 11110 | |
e487eaeb | 11111 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 JB |
11112 | |
11113 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
ee4bc9e7 | 11114 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
b8456a14 CYY |
11115 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
11116 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) | |
e487eaeb | 11117 | return; |
947add36 JB |
11118 | |
11119 | wdev->channel = chandef->chan; | |
11120 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); | |
947add36 JB |
11121 | } |
11122 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
11123 | ||
11124 | void cfg80211_cqm_txe_notify(struct net_device *dev, | |
11125 | const u8 *peer, u32 num_packets, | |
11126 | u32 rate, u32 intvl, gfp_t gfp) | |
11127 | { | |
11128 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11129 | struct wiphy *wiphy = wdev->wiphy; | |
11130 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
84f10708 TP |
11131 | struct sk_buff *msg; |
11132 | struct nlattr *pinfoattr; | |
11133 | void *hdr; | |
11134 | ||
11135 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11136 | if (!msg) | |
11137 | return; | |
11138 | ||
11139 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11140 | if (!hdr) { | |
11141 | nlmsg_free(msg); | |
11142 | return; | |
11143 | } | |
11144 | ||
11145 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
947add36 | 11146 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
84f10708 TP |
11147 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11148 | goto nla_put_failure; | |
11149 | ||
11150 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11151 | if (!pinfoattr) | |
11152 | goto nla_put_failure; | |
11153 | ||
11154 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
11155 | goto nla_put_failure; | |
11156 | ||
11157 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
11158 | goto nla_put_failure; | |
11159 | ||
11160 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
11161 | goto nla_put_failure; | |
11162 | ||
11163 | nla_nest_end(msg, pinfoattr); | |
11164 | ||
11165 | genlmsg_end(msg, hdr); | |
11166 | ||
68eb5503 | 11167 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11168 | NL80211_MCGRP_MLME, gfp); |
84f10708 TP |
11169 | return; |
11170 | ||
11171 | nla_put_failure: | |
11172 | genlmsg_cancel(msg, hdr); | |
11173 | nlmsg_free(msg); | |
11174 | } | |
947add36 | 11175 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
84f10708 | 11176 | |
04f39047 SW |
11177 | void |
11178 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 11179 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
11180 | enum nl80211_radar_event event, |
11181 | struct net_device *netdev, gfp_t gfp) | |
11182 | { | |
11183 | struct sk_buff *msg; | |
11184 | void *hdr; | |
11185 | ||
11186 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11187 | if (!msg) | |
11188 | return; | |
11189 | ||
11190 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
11191 | if (!hdr) { | |
11192 | nlmsg_free(msg); | |
11193 | return; | |
11194 | } | |
11195 | ||
11196 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
11197 | goto nla_put_failure; | |
11198 | ||
11199 | /* NOP and radar events don't need a netdev parameter */ | |
11200 | if (netdev) { | |
11201 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
11202 | ||
11203 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11204 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11205 | goto nla_put_failure; | |
11206 | } | |
11207 | ||
11208 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
11209 | goto nla_put_failure; | |
11210 | ||
11211 | if (nl80211_send_chandef(msg, chandef)) | |
11212 | goto nla_put_failure; | |
11213 | ||
9c90a9f6 | 11214 | genlmsg_end(msg, hdr); |
04f39047 | 11215 | |
68eb5503 | 11216 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11217 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
11218 | return; |
11219 | ||
11220 | nla_put_failure: | |
11221 | genlmsg_cancel(msg, hdr); | |
11222 | nlmsg_free(msg); | |
11223 | } | |
11224 | ||
947add36 JB |
11225 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
11226 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
c063dbf5 | 11227 | { |
947add36 JB |
11228 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11229 | struct wiphy *wiphy = wdev->wiphy; | |
11230 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
c063dbf5 JB |
11231 | struct sk_buff *msg; |
11232 | struct nlattr *pinfoattr; | |
11233 | void *hdr; | |
11234 | ||
947add36 JB |
11235 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
11236 | ||
58050fce | 11237 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c063dbf5 JB |
11238 | if (!msg) |
11239 | return; | |
11240 | ||
11241 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
11242 | if (!hdr) { | |
11243 | nlmsg_free(msg); | |
11244 | return; | |
11245 | } | |
11246 | ||
9360ffd1 | 11247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 11248 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
9360ffd1 DM |
11249 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
11250 | goto nla_put_failure; | |
c063dbf5 JB |
11251 | |
11252 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
11253 | if (!pinfoattr) | |
11254 | goto nla_put_failure; | |
11255 | ||
9360ffd1 DM |
11256 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
11257 | goto nla_put_failure; | |
c063dbf5 JB |
11258 | |
11259 | nla_nest_end(msg, pinfoattr); | |
11260 | ||
3b7b72ee | 11261 | genlmsg_end(msg, hdr); |
c063dbf5 | 11262 | |
68eb5503 | 11263 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11264 | NL80211_MCGRP_MLME, gfp); |
c063dbf5 JB |
11265 | return; |
11266 | ||
11267 | nla_put_failure: | |
11268 | genlmsg_cancel(msg, hdr); | |
11269 | nlmsg_free(msg); | |
11270 | } | |
947add36 | 11271 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
c063dbf5 | 11272 | |
7f6cf311 JB |
11273 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
11274 | u64 cookie, bool acked, gfp_t gfp) | |
11275 | { | |
11276 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11277 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11278 | struct sk_buff *msg; | |
11279 | void *hdr; | |
7f6cf311 | 11280 | |
4ee3e063 BL |
11281 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
11282 | ||
58050fce | 11283 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 11284 | |
7f6cf311 JB |
11285 | if (!msg) |
11286 | return; | |
11287 | ||
11288 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
11289 | if (!hdr) { | |
11290 | nlmsg_free(msg); | |
11291 | return; | |
11292 | } | |
11293 | ||
9360ffd1 DM |
11294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11295 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11296 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
11297 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
11298 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
11299 | goto nla_put_failure; | |
7f6cf311 | 11300 | |
9c90a9f6 | 11301 | genlmsg_end(msg, hdr); |
7f6cf311 | 11302 | |
68eb5503 | 11303 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11304 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
11305 | return; |
11306 | ||
11307 | nla_put_failure: | |
11308 | genlmsg_cancel(msg, hdr); | |
11309 | nlmsg_free(msg); | |
11310 | } | |
11311 | EXPORT_SYMBOL(cfg80211_probe_status); | |
11312 | ||
5e760230 JB |
11313 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
11314 | const u8 *frame, size_t len, | |
37c73b5f | 11315 | int freq, int sig_dbm) |
5e760230 JB |
11316 | { |
11317 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11318 | struct sk_buff *msg; | |
11319 | void *hdr; | |
37c73b5f | 11320 | struct cfg80211_beacon_registration *reg; |
5e760230 | 11321 | |
4ee3e063 BL |
11322 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
11323 | ||
37c73b5f BG |
11324 | spin_lock_bh(&rdev->beacon_registrations_lock); |
11325 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11326 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
11327 | if (!msg) { | |
11328 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11329 | return; | |
11330 | } | |
5e760230 | 11331 | |
37c73b5f BG |
11332 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
11333 | if (!hdr) | |
11334 | goto nla_put_failure; | |
5e760230 | 11335 | |
37c73b5f BG |
11336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11337 | (freq && | |
11338 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
11339 | (sig_dbm && | |
11340 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
11341 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
11342 | goto nla_put_failure; | |
5e760230 | 11343 | |
37c73b5f | 11344 | genlmsg_end(msg, hdr); |
5e760230 | 11345 | |
37c73b5f BG |
11346 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
11347 | } | |
11348 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
11349 | return; |
11350 | ||
11351 | nla_put_failure: | |
37c73b5f BG |
11352 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
11353 | if (hdr) | |
11354 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
11355 | nlmsg_free(msg); |
11356 | } | |
11357 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
11358 | ||
cd8f7cb4 JB |
11359 | #ifdef CONFIG_PM |
11360 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, | |
11361 | struct cfg80211_wowlan_wakeup *wakeup, | |
11362 | gfp_t gfp) | |
11363 | { | |
11364 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11365 | struct sk_buff *msg; | |
11366 | void *hdr; | |
9c90a9f6 | 11367 | int size = 200; |
cd8f7cb4 JB |
11368 | |
11369 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
11370 | ||
11371 | if (wakeup) | |
11372 | size += wakeup->packet_present_len; | |
11373 | ||
11374 | msg = nlmsg_new(size, gfp); | |
11375 | if (!msg) | |
11376 | return; | |
11377 | ||
11378 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
11379 | if (!hdr) | |
11380 | goto free_msg; | |
11381 | ||
11382 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11383 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11384 | goto free_msg; | |
11385 | ||
11386 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11387 | wdev->netdev->ifindex)) | |
11388 | goto free_msg; | |
11389 | ||
11390 | if (wakeup) { | |
11391 | struct nlattr *reasons; | |
11392 | ||
11393 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
11394 | if (!reasons) |
11395 | goto free_msg; | |
cd8f7cb4 JB |
11396 | |
11397 | if (wakeup->disconnect && | |
11398 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
11399 | goto free_msg; | |
11400 | if (wakeup->magic_pkt && | |
11401 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
11402 | goto free_msg; | |
11403 | if (wakeup->gtk_rekey_failure && | |
11404 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
11405 | goto free_msg; | |
11406 | if (wakeup->eap_identity_req && | |
11407 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
11408 | goto free_msg; | |
11409 | if (wakeup->four_way_handshake && | |
11410 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
11411 | goto free_msg; | |
11412 | if (wakeup->rfkill_release && | |
11413 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
11414 | goto free_msg; | |
11415 | ||
11416 | if (wakeup->pattern_idx >= 0 && | |
11417 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
11418 | wakeup->pattern_idx)) | |
11419 | goto free_msg; | |
11420 | ||
ae917c9f JB |
11421 | if (wakeup->tcp_match && |
11422 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
11423 | goto free_msg; | |
2a0e047e | 11424 | |
ae917c9f JB |
11425 | if (wakeup->tcp_connlost && |
11426 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
11427 | goto free_msg; | |
2a0e047e | 11428 | |
ae917c9f JB |
11429 | if (wakeup->tcp_nomoretokens && |
11430 | nla_put_flag(msg, | |
11431 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
11432 | goto free_msg; | |
2a0e047e | 11433 | |
cd8f7cb4 JB |
11434 | if (wakeup->packet) { |
11435 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
11436 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
11437 | ||
11438 | if (!wakeup->packet_80211) { | |
11439 | pkt_attr = | |
11440 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
11441 | len_attr = | |
11442 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
11443 | } | |
11444 | ||
11445 | if (wakeup->packet_len && | |
11446 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
11447 | goto free_msg; | |
11448 | ||
11449 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
11450 | wakeup->packet)) | |
11451 | goto free_msg; | |
11452 | } | |
11453 | ||
11454 | nla_nest_end(msg, reasons); | |
11455 | } | |
11456 | ||
9c90a9f6 | 11457 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 11458 | |
68eb5503 | 11459 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11460 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
11461 | return; |
11462 | ||
11463 | free_msg: | |
11464 | nlmsg_free(msg); | |
11465 | } | |
11466 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
11467 | #endif | |
11468 | ||
3475b094 JM |
11469 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
11470 | enum nl80211_tdls_operation oper, | |
11471 | u16 reason_code, gfp_t gfp) | |
11472 | { | |
11473 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11474 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
11475 | struct sk_buff *msg; | |
11476 | void *hdr; | |
3475b094 JM |
11477 | |
11478 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
11479 | reason_code); | |
11480 | ||
11481 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11482 | if (!msg) | |
11483 | return; | |
11484 | ||
11485 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
11486 | if (!hdr) { | |
11487 | nlmsg_free(msg); | |
11488 | return; | |
11489 | } | |
11490 | ||
11491 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11492 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11493 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
11494 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
11495 | (reason_code > 0 && | |
11496 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
11497 | goto nla_put_failure; | |
11498 | ||
9c90a9f6 | 11499 | genlmsg_end(msg, hdr); |
3475b094 | 11500 | |
68eb5503 | 11501 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11502 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
11503 | return; |
11504 | ||
11505 | nla_put_failure: | |
11506 | genlmsg_cancel(msg, hdr); | |
11507 | nlmsg_free(msg); | |
11508 | } | |
11509 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
11510 | ||
026331c4 JM |
11511 | static int nl80211_netlink_notify(struct notifier_block * nb, |
11512 | unsigned long state, | |
11513 | void *_notify) | |
11514 | { | |
11515 | struct netlink_notify *notify = _notify; | |
11516 | struct cfg80211_registered_device *rdev; | |
11517 | struct wireless_dev *wdev; | |
37c73b5f | 11518 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
11519 | |
11520 | if (state != NETLINK_URELEASE) | |
11521 | return NOTIFY_DONE; | |
11522 | ||
11523 | rcu_read_lock(); | |
11524 | ||
5e760230 | 11525 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
89a54e48 | 11526 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
15e47304 | 11527 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f BG |
11528 | |
11529 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11530 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
11531 | list) { | |
11532 | if (reg->nlportid == notify->portid) { | |
11533 | list_del(®->list); | |
11534 | kfree(reg); | |
11535 | break; | |
11536 | } | |
11537 | } | |
11538 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 11539 | } |
026331c4 JM |
11540 | |
11541 | rcu_read_unlock(); | |
11542 | ||
11543 | return NOTIFY_DONE; | |
11544 | } | |
11545 | ||
11546 | static struct notifier_block nl80211_netlink_notifier = { | |
11547 | .notifier_call = nl80211_netlink_notify, | |
11548 | }; | |
11549 | ||
355199e0 JM |
11550 | void cfg80211_ft_event(struct net_device *netdev, |
11551 | struct cfg80211_ft_event_params *ft_event) | |
11552 | { | |
11553 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
11554 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
11555 | struct sk_buff *msg; | |
11556 | void *hdr; | |
355199e0 JM |
11557 | |
11558 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
11559 | ||
11560 | if (!ft_event->target_ap) | |
11561 | return; | |
11562 | ||
11563 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11564 | if (!msg) | |
11565 | return; | |
11566 | ||
11567 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
11568 | if (!hdr) |
11569 | goto out; | |
355199e0 | 11570 | |
ae917c9f JB |
11571 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11572 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11573 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
11574 | goto out; | |
355199e0 | 11575 | |
ae917c9f JB |
11576 | if (ft_event->ies && |
11577 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
11578 | goto out; | |
11579 | if (ft_event->ric_ies && | |
11580 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
11581 | ft_event->ric_ies)) | |
11582 | goto out; | |
355199e0 | 11583 | |
9c90a9f6 | 11584 | genlmsg_end(msg, hdr); |
355199e0 | 11585 | |
68eb5503 | 11586 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11587 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
11588 | return; |
11589 | out: | |
11590 | nlmsg_free(msg); | |
355199e0 JM |
11591 | } |
11592 | EXPORT_SYMBOL(cfg80211_ft_event); | |
11593 | ||
5de17984 AS |
11594 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
11595 | { | |
11596 | struct cfg80211_registered_device *rdev; | |
11597 | struct sk_buff *msg; | |
11598 | void *hdr; | |
11599 | u32 nlportid; | |
11600 | ||
11601 | rdev = wiphy_to_dev(wdev->wiphy); | |
11602 | if (!rdev->crit_proto_nlportid) | |
11603 | return; | |
11604 | ||
11605 | nlportid = rdev->crit_proto_nlportid; | |
11606 | rdev->crit_proto_nlportid = 0; | |
11607 | ||
11608 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11609 | if (!msg) | |
11610 | return; | |
11611 | ||
11612 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
11613 | if (!hdr) | |
11614 | goto nla_put_failure; | |
11615 | ||
11616 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11617 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
11618 | goto nla_put_failure; | |
11619 | ||
11620 | genlmsg_end(msg, hdr); | |
11621 | ||
11622 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
11623 | return; | |
11624 | ||
11625 | nla_put_failure: | |
11626 | if (hdr) | |
11627 | genlmsg_cancel(msg, hdr); | |
11628 | nlmsg_free(msg); | |
11629 | ||
11630 | } | |
11631 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
11632 | ||
55682965 JB |
11633 | /* initialisation/exit functions */ |
11634 | ||
11635 | int nl80211_init(void) | |
11636 | { | |
0d63cbb5 | 11637 | int err; |
55682965 | 11638 | |
2a94fe48 JB |
11639 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
11640 | nl80211_mcgrps); | |
55682965 JB |
11641 | if (err) |
11642 | return err; | |
11643 | ||
026331c4 JM |
11644 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
11645 | if (err) | |
11646 | goto err_out; | |
11647 | ||
55682965 JB |
11648 | return 0; |
11649 | err_out: | |
11650 | genl_unregister_family(&nl80211_fam); | |
11651 | return err; | |
11652 | } | |
11653 | ||
11654 | void nl80211_exit(void) | |
11655 | { | |
026331c4 | 11656 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
11657 | genl_unregister_family(&nl80211_fam); |
11658 | } |