2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright 2015-2017 Intel Deutschland GmbH
7 * Copyright (C) 2018 Intel Corporation
11 #include <linux/module.h>
12 #include <linux/err.h>
13 #include <linux/slab.h>
14 #include <linux/list.h>
15 #include <linux/if_ether.h>
16 #include <linux/ieee80211.h>
17 #include <linux/nl80211.h>
18 #include <linux/rtnetlink.h>
19 #include <linux/netlink.h>
20 #include <linux/nospec.h>
21 #include <linux/etherdevice.h>
22 #include <net/net_namespace.h>
23 #include <net/genetlink.h>
24 #include <net/cfg80211.h>
26 #include <net/inet_connection_sock.h>
32 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
33 struct genl_info
*info
,
34 struct cfg80211_crypto_settings
*settings
,
37 /* the netlink family */
38 static struct genl_family nl80211_fam
;
40 /* multicast groups */
41 enum nl80211_multicast_groups
{
44 NL80211_MCGRP_REGULATORY
,
48 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
51 static const struct genl_multicast_group nl80211_mcgrps
[] = {
52 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
53 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
54 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
55 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
56 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
57 [NL80211_MCGRP_NAN
] = { .name
= NL80211_MULTICAST_GROUP_NAN
},
58 #ifdef CONFIG_NL80211_TESTMODE
59 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
63 /* returns ERR_PTR values */
64 static struct wireless_dev
*
65 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
67 struct cfg80211_registered_device
*rdev
;
68 struct wireless_dev
*result
= NULL
;
69 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
70 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
77 if (!have_ifidx
&& !have_wdev_id
)
78 return ERR_PTR(-EINVAL
);
81 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
83 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
84 wiphy_idx
= wdev_id
>> 32;
87 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
88 struct wireless_dev
*wdev
;
90 if (wiphy_net(&rdev
->wiphy
) != netns
)
93 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
96 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
97 if (have_ifidx
&& wdev
->netdev
&&
98 wdev
->netdev
->ifindex
== ifidx
) {
102 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
114 return ERR_PTR(-ENODEV
);
117 static struct cfg80211_registered_device
*
118 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
120 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
121 struct net_device
*netdev
;
125 if (!attrs
[NL80211_ATTR_WIPHY
] &&
126 !attrs
[NL80211_ATTR_IFINDEX
] &&
127 !attrs
[NL80211_ATTR_WDEV
])
128 return ERR_PTR(-EINVAL
);
130 if (attrs
[NL80211_ATTR_WIPHY
])
131 rdev
= cfg80211_rdev_by_wiphy_idx(
132 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
134 if (attrs
[NL80211_ATTR_WDEV
]) {
135 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
136 struct wireless_dev
*wdev
;
139 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
141 /* make sure wdev exists */
142 list_for_each_entry(wdev
, &tmp
->wiphy
.wdev_list
, list
) {
143 if (wdev
->identifier
!= (u32
)wdev_id
)
152 if (rdev
&& tmp
!= rdev
)
153 return ERR_PTR(-EINVAL
);
158 if (attrs
[NL80211_ATTR_IFINDEX
]) {
159 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
161 netdev
= __dev_get_by_index(netns
, ifindex
);
163 if (netdev
->ieee80211_ptr
)
165 netdev
->ieee80211_ptr
->wiphy
);
169 /* not wireless device -- return error */
171 return ERR_PTR(-EINVAL
);
173 /* mismatch -- return error */
174 if (rdev
&& tmp
!= rdev
)
175 return ERR_PTR(-EINVAL
);
182 return ERR_PTR(-ENODEV
);
184 if (netns
!= wiphy_net(&rdev
->wiphy
))
185 return ERR_PTR(-ENODEV
);
191 * This function returns a pointer to the driver
192 * that the genl_info item that is passed refers to.
194 * The result of this can be a PTR_ERR and hence must
195 * be checked with IS_ERR() for errors.
197 static struct cfg80211_registered_device
*
198 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
200 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
203 /* policy for the attributes */
204 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
205 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
206 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
208 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
210 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
211 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
212 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
213 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
214 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
216 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
217 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
218 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
219 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
220 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
221 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
223 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
225 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
227 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
228 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
230 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
231 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
232 .len
= WLAN_MAX_KEY_LEN
},
233 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
234 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
235 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
236 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
237 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
239 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
240 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
241 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
242 .len
= IEEE80211_MAX_DATA_LEN
},
243 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
244 .len
= IEEE80211_MAX_DATA_LEN
},
245 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
246 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
247 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
248 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
249 .len
= NL80211_MAX_SUPP_RATES
},
250 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
251 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
253 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
254 .len
= IEEE80211_MAX_MESH_ID_LEN
},
255 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
258 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
260 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
261 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
262 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
263 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
264 .len
= NL80211_MAX_SUPP_RATES
},
265 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
267 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
268 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
270 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
272 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
274 .len
= IEEE80211_MAX_DATA_LEN
},
275 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
276 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
278 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
279 .len
= IEEE80211_MAX_SSID_LEN
},
280 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
281 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
282 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
283 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
284 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
285 [NL80211_ATTR_STA_FLAGS2
] = {
286 .len
= sizeof(struct nl80211_sta_flag_update
),
288 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
289 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
290 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
291 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211
] = { .type
= NLA_FLAG
},
292 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
293 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
294 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
295 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
296 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
297 [NL80211_ATTR_PMKID
] = { .len
= WLAN_PMKID_LEN
},
298 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
299 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
300 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
301 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
302 .len
= IEEE80211_MAX_DATA_LEN
},
303 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
304 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
306 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
307 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
308 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
309 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
311 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
312 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
313 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
314 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
315 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
316 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
317 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
318 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
319 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
320 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
321 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
323 .len
= IEEE80211_MAX_DATA_LEN
},
324 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
325 .len
= IEEE80211_MAX_DATA_LEN
},
326 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
327 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
328 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
329 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
330 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
331 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
332 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
333 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
334 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
335 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
336 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
337 .len
= IEEE80211_MAX_DATA_LEN
},
338 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
339 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
340 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
341 .len
= NL80211_HT_CAPABILITY_LEN
343 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
344 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
345 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
346 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
347 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
348 [NL80211_ATTR_AUTH_DATA
] = { .type
= NLA_BINARY
, },
349 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
350 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
351 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
352 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
353 [NL80211_ATTR_LOCAL_MESH_POWER_MODE
] = {. type
= NLA_U32
},
354 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
355 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
356 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
357 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
358 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
359 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
360 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
361 .len
= NL80211_VHT_CAPABILITY_LEN
,
363 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
364 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
365 .len
= IEEE80211_MAX_DATA_LEN
},
366 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
367 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
368 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
369 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
370 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
371 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
372 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
373 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
374 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
375 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
376 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
377 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
378 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
379 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
380 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
381 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
382 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
383 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
384 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
385 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
386 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
387 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
388 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
389 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
390 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
391 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
392 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
393 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
394 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
395 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
396 [NL80211_ATTR_PBSS
] = { .type
= NLA_FLAG
},
397 [NL80211_ATTR_BSS_SELECT
] = { .type
= NLA_NESTED
},
398 [NL80211_ATTR_STA_SUPPORT_P2P_PS
] = { .type
= NLA_U8
},
399 [NL80211_ATTR_MU_MIMO_GROUP_DATA
] = {
400 .len
= VHT_MUMIMO_GROUPS_DATA_LEN
402 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
] = { .len
= ETH_ALEN
},
403 [NL80211_ATTR_NAN_MASTER_PREF
] = { .type
= NLA_U8
},
404 [NL80211_ATTR_BANDS
] = { .type
= NLA_U32
},
405 [NL80211_ATTR_NAN_FUNC
] = { .type
= NLA_NESTED
},
406 [NL80211_ATTR_FILS_KEK
] = { .type
= NLA_BINARY
,
407 .len
= FILS_MAX_KEK_LEN
},
408 [NL80211_ATTR_FILS_NONCES
] = { .len
= 2 * FILS_NONCE_LEN
},
409 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
] = { .type
= NLA_FLAG
, },
410 [NL80211_ATTR_BSSID
] = { .len
= ETH_ALEN
},
411 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] = { .type
= NLA_S8
},
412 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
] = {
413 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
415 [NL80211_ATTR_TIMEOUT_REASON
] = { .type
= NLA_U32
},
416 [NL80211_ATTR_FILS_ERP_USERNAME
] = { .type
= NLA_BINARY
,
417 .len
= FILS_ERP_MAX_USERNAME_LEN
},
418 [NL80211_ATTR_FILS_ERP_REALM
] = { .type
= NLA_BINARY
,
419 .len
= FILS_ERP_MAX_REALM_LEN
},
420 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] = { .type
= NLA_U16
},
421 [NL80211_ATTR_FILS_ERP_RRK
] = { .type
= NLA_BINARY
,
422 .len
= FILS_ERP_MAX_RRK_LEN
},
423 [NL80211_ATTR_FILS_CACHE_ID
] = { .len
= 2 },
424 [NL80211_ATTR_PMK
] = { .type
= NLA_BINARY
, .len
= PMK_MAX_LEN
},
425 [NL80211_ATTR_SCHED_SCAN_MULTI
] = { .type
= NLA_FLAG
},
426 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
] = { .type
= NLA_FLAG
},
428 [NL80211_ATTR_TXQ_LIMIT
] = { .type
= NLA_U32
},
429 [NL80211_ATTR_TXQ_MEMORY_LIMIT
] = { .type
= NLA_U32
},
430 [NL80211_ATTR_TXQ_QUANTUM
] = { .type
= NLA_U32
},
433 /* policy for the key attributes */
434 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
435 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
436 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
437 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
438 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
439 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
440 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
441 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
442 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
445 /* policy for the key default flags */
446 static const struct nla_policy
447 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
448 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
449 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
453 /* policy for WoWLAN attributes */
454 static const struct nla_policy
455 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
456 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
457 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
458 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
459 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
460 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
461 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
462 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
463 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
464 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
465 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
468 static const struct nla_policy
469 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
470 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
471 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
472 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
473 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
474 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
475 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
476 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
477 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
479 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
480 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
482 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
483 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
484 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
486 #endif /* CONFIG_PM */
488 /* policy for coalesce rule attributes */
489 static const struct nla_policy
490 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
491 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
492 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
493 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
496 /* policy for GTK rekey offload attributes */
497 static const struct nla_policy
498 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
499 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
500 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
501 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
504 static const struct nla_policy
505 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
506 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
507 .len
= IEEE80211_MAX_SSID_LEN
},
508 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
] = { .len
= ETH_ALEN
},
509 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
512 static const struct nla_policy
513 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
514 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
515 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
518 static const struct nla_policy
519 nl80211_bss_select_policy
[NL80211_BSS_SELECT_ATTR_MAX
+ 1] = {
520 [NL80211_BSS_SELECT_ATTR_RSSI
] = { .type
= NLA_FLAG
},
521 [NL80211_BSS_SELECT_ATTR_BAND_PREF
] = { .type
= NLA_U32
},
522 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
] = {
523 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
527 /* policy for NAN function attributes */
528 static const struct nla_policy
529 nl80211_nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
530 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
531 [NL80211_NAN_FUNC_SERVICE_ID
] = {
532 .len
= NL80211_NAN_FUNC_SERVICE_ID_LEN
},
533 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
534 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
535 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
536 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
537 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
538 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { .len
= ETH_ALEN
},
539 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
540 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
541 [NL80211_NAN_FUNC_SERVICE_INFO
] = { .type
= NLA_BINARY
,
542 .len
= NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN
},
543 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
544 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
545 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
546 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
547 [NL80211_NAN_FUNC_TERM_REASON
] = { .type
= NLA_U8
},
550 /* policy for Service Response Filter attributes */
551 static const struct nla_policy
552 nl80211_nan_srf_policy
[NL80211_NAN_SRF_ATTR_MAX
+ 1] = {
553 [NL80211_NAN_SRF_INCLUDE
] = { .type
= NLA_FLAG
},
554 [NL80211_NAN_SRF_BF
] = { .type
= NLA_BINARY
,
555 .len
= NL80211_NAN_FUNC_SRF_MAX_LEN
},
556 [NL80211_NAN_SRF_BF_IDX
] = { .type
= NLA_U8
},
557 [NL80211_NAN_SRF_MAC_ADDRS
] = { .type
= NLA_NESTED
},
560 /* policy for packet pattern attributes */
561 static const struct nla_policy
562 nl80211_packet_pattern_policy
[MAX_NL80211_PKTPAT
+ 1] = {
563 [NL80211_PKTPAT_MASK
] = { .type
= NLA_BINARY
, },
564 [NL80211_PKTPAT_PATTERN
] = { .type
= NLA_BINARY
, },
565 [NL80211_PKTPAT_OFFSET
] = { .type
= NLA_U32
},
568 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
569 struct netlink_callback
*cb
,
570 struct cfg80211_registered_device
**rdev
,
571 struct wireless_dev
**wdev
)
576 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
577 genl_family_attrbuf(&nl80211_fam
),
578 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
582 *wdev
= __cfg80211_wdev_from_attrs(
584 genl_family_attrbuf(&nl80211_fam
));
586 return PTR_ERR(*wdev
);
587 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
588 /* 0 is the first index - add 1 to parse only once */
589 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
590 cb
->args
[1] = (*wdev
)->identifier
;
592 /* subtract the 1 again here */
593 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
594 struct wireless_dev
*tmp
;
598 *rdev
= wiphy_to_rdev(wiphy
);
601 list_for_each_entry(tmp
, &(*rdev
)->wiphy
.wdev_list
, list
) {
602 if (tmp
->identifier
== cb
->args
[1]) {
616 static bool is_valid_ie_attr(const struct nlattr
*attr
)
624 pos
= nla_data(attr
);
645 /* message building helper */
646 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
649 /* since there is no private header just add the generic one */
650 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
653 static int nl80211_msg_put_wmm_rules(struct sk_buff
*msg
,
654 const struct ieee80211_reg_rule
*rule
)
657 struct nlattr
*nl_wmm_rules
=
658 nla_nest_start(msg
, NL80211_FREQUENCY_ATTR_WMM
);
661 goto nla_put_failure
;
663 for (j
= 0; j
< IEEE80211_NUM_ACS
; j
++) {
664 struct nlattr
*nl_wmm_rule
= nla_nest_start(msg
, j
);
667 goto nla_put_failure
;
669 if (nla_put_u16(msg
, NL80211_WMMR_CW_MIN
,
670 rule
->wmm_rule
->client
[j
].cw_min
) ||
671 nla_put_u16(msg
, NL80211_WMMR_CW_MAX
,
672 rule
->wmm_rule
->client
[j
].cw_max
) ||
673 nla_put_u8(msg
, NL80211_WMMR_AIFSN
,
674 rule
->wmm_rule
->client
[j
].aifsn
) ||
675 nla_put_u8(msg
, NL80211_WMMR_TXOP
,
676 rule
->wmm_rule
->client
[j
].cot
))
677 goto nla_put_failure
;
679 nla_nest_end(msg
, nl_wmm_rule
);
681 nla_nest_end(msg
, nl_wmm_rules
);
689 static int nl80211_msg_put_channel(struct sk_buff
*msg
, struct wiphy
*wiphy
,
690 struct ieee80211_channel
*chan
,
693 /* Some channels must be completely excluded from the
694 * list to protect old user-space tools from breaking
696 if (!large
&& chan
->flags
&
697 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
700 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
702 goto nla_put_failure
;
704 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
705 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
706 goto nla_put_failure
;
707 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
708 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
709 goto nla_put_failure
;
710 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
711 goto nla_put_failure
;
713 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
714 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
715 goto nla_put_failure
;
719 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
721 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
723 goto nla_put_failure
;
724 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
726 goto nla_put_failure
;
728 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
730 goto nla_put_failure
;
735 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
736 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
737 goto nla_put_failure
;
738 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
739 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
740 goto nla_put_failure
;
741 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
742 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
743 goto nla_put_failure
;
744 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
745 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
746 goto nla_put_failure
;
747 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
748 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
749 goto nla_put_failure
;
750 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
751 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
752 goto nla_put_failure
;
753 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
754 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
755 goto nla_put_failure
;
756 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
757 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
758 goto nla_put_failure
;
761 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
762 DBM_TO_MBM(chan
->max_power
)))
763 goto nla_put_failure
;
766 const struct ieee80211_reg_rule
*rule
=
767 freq_reg_info(wiphy
, chan
->center_freq
);
769 if (!IS_ERR(rule
) && rule
->wmm_rule
) {
770 if (nl80211_msg_put_wmm_rules(msg
, rule
))
771 goto nla_put_failure
;
781 static bool nl80211_put_txq_stats(struct sk_buff
*msg
,
782 struct cfg80211_txq_stats
*txqstats
,
785 struct nlattr
*txqattr
;
787 #define PUT_TXQVAL_U32(attr, memb) do { \
788 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
789 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
793 txqattr
= nla_nest_start(msg
, attrtype
);
797 PUT_TXQVAL_U32(BACKLOG_BYTES
, backlog_bytes
);
798 PUT_TXQVAL_U32(BACKLOG_PACKETS
, backlog_packets
);
799 PUT_TXQVAL_U32(FLOWS
, flows
);
800 PUT_TXQVAL_U32(DROPS
, drops
);
801 PUT_TXQVAL_U32(ECN_MARKS
, ecn_marks
);
802 PUT_TXQVAL_U32(OVERLIMIT
, overlimit
);
803 PUT_TXQVAL_U32(OVERMEMORY
, overmemory
);
804 PUT_TXQVAL_U32(COLLISIONS
, collisions
);
805 PUT_TXQVAL_U32(TX_BYTES
, tx_bytes
);
806 PUT_TXQVAL_U32(TX_PACKETS
, tx_packets
);
807 PUT_TXQVAL_U32(MAX_FLOWS
, max_flows
);
808 nla_nest_end(msg
, txqattr
);
810 #undef PUT_TXQVAL_U32
814 /* netlink command implementations */
821 bool def_uni
, def_multi
;
824 static int nl80211_parse_key_new(struct genl_info
*info
, struct nlattr
*key
,
827 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
828 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
829 nl80211_key_policy
, info
->extack
);
833 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
834 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
843 if (tb
[NL80211_KEY_IDX
])
844 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
846 if (tb
[NL80211_KEY_DATA
]) {
847 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
848 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
851 if (tb
[NL80211_KEY_SEQ
]) {
852 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
853 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
856 if (tb
[NL80211_KEY_CIPHER
])
857 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
859 if (tb
[NL80211_KEY_TYPE
]) {
860 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
861 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
862 return genl_err_attr(info
, -EINVAL
,
863 tb
[NL80211_KEY_TYPE
]);
866 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
867 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
869 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
870 tb
[NL80211_KEY_DEFAULT_TYPES
],
871 nl80211_key_default_policy
,
876 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
877 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
883 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
885 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
886 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
887 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
890 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
891 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
892 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
895 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
896 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
898 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
899 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
901 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
902 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
911 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
912 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
913 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
) {
914 GENL_SET_ERR_MSG(info
, "key type out of range");
919 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
920 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
921 int err
= nla_parse_nested(kdt
,
922 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
923 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
924 nl80211_key_default_policy
,
929 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
930 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
936 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
940 memset(k
, 0, sizeof(*k
));
944 if (info
->attrs
[NL80211_ATTR_KEY
])
945 err
= nl80211_parse_key_new(info
, info
->attrs
[NL80211_ATTR_KEY
], k
);
947 err
= nl80211_parse_key_old(info
, k
);
952 if (k
->def
&& k
->defmgmt
) {
953 GENL_SET_ERR_MSG(info
, "key with def && defmgmt is invalid");
958 if (k
->def_uni
|| !k
->def_multi
) {
959 GENL_SET_ERR_MSG(info
, "defmgmt key must be mcast");
966 if (k
->idx
< 4 || k
->idx
> 5) {
967 GENL_SET_ERR_MSG(info
,
968 "defmgmt key idx not 4 or 5");
972 if (k
->idx
< 0 || k
->idx
> 3) {
973 GENL_SET_ERR_MSG(info
, "def key idx not 0-3");
977 if (k
->idx
< 0 || k
->idx
> 5) {
978 GENL_SET_ERR_MSG(info
, "key idx not 0-5");
987 static struct cfg80211_cached_keys
*
988 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
989 struct genl_info
*info
, bool *no_ht
)
991 struct nlattr
*keys
= info
->attrs
[NL80211_ATTR_KEYS
];
992 struct key_parse parse
;
994 struct cfg80211_cached_keys
*result
;
995 int rem
, err
, def
= 0;
996 bool have_key
= false;
998 nla_for_each_nested(key
, keys
, rem
) {
1006 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
1008 return ERR_PTR(-ENOMEM
);
1012 nla_for_each_nested(key
, keys
, rem
) {
1013 memset(&parse
, 0, sizeof(parse
));
1016 err
= nl80211_parse_key_new(info
, key
, &parse
);
1022 if (parse
.idx
< 0 || parse
.idx
> 3) {
1023 GENL_SET_ERR_MSG(info
, "key index out of range [0-3]");
1028 GENL_SET_ERR_MSG(info
,
1029 "only one key can be default");
1033 result
->def
= parse
.idx
;
1034 if (!parse
.def_uni
|| !parse
.def_multi
)
1036 } else if (parse
.defmgmt
)
1038 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
1039 parse
.idx
, false, NULL
);
1042 if (parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1043 parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
) {
1044 GENL_SET_ERR_MSG(info
, "connect key must be WEP");
1048 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
1049 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
1050 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
1051 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
1053 /* must be WEP key if we got here */
1058 if (result
->def
< 0) {
1060 GENL_SET_ERR_MSG(info
, "need a default/TX key");
1067 return ERR_PTR(err
);
1070 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
1072 ASSERT_WDEV_LOCK(wdev
);
1074 switch (wdev
->iftype
) {
1075 case NL80211_IFTYPE_AP
:
1076 case NL80211_IFTYPE_AP_VLAN
:
1077 case NL80211_IFTYPE_P2P_GO
:
1078 case NL80211_IFTYPE_MESH_POINT
:
1080 case NL80211_IFTYPE_ADHOC
:
1081 case NL80211_IFTYPE_STATION
:
1082 case NL80211_IFTYPE_P2P_CLIENT
:
1083 if (!wdev
->current_bss
)
1086 case NL80211_IFTYPE_UNSPECIFIED
:
1087 case NL80211_IFTYPE_OCB
:
1088 case NL80211_IFTYPE_MONITOR
:
1089 case NL80211_IFTYPE_NAN
:
1090 case NL80211_IFTYPE_P2P_DEVICE
:
1091 case NL80211_IFTYPE_WDS
:
1092 case NUM_NL80211_IFTYPES
:
1099 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
1102 struct ieee80211_channel
*chan
;
1106 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
1107 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
1112 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
1114 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
1118 goto nla_put_failure
;
1122 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
1123 goto nla_put_failure
;
1128 nla_nest_end(msg
, nl_modes
);
1135 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
1136 struct sk_buff
*msg
,
1139 struct nlattr
*nl_combis
;
1142 nl_combis
= nla_nest_start(msg
,
1143 NL80211_ATTR_INTERFACE_COMBINATIONS
);
1145 goto nla_put_failure
;
1147 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
1148 const struct ieee80211_iface_combination
*c
;
1149 struct nlattr
*nl_combi
, *nl_limits
;
1151 c
= &wiphy
->iface_combinations
[i
];
1153 nl_combi
= nla_nest_start(msg
, i
+ 1);
1155 goto nla_put_failure
;
1157 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
1159 goto nla_put_failure
;
1161 for (j
= 0; j
< c
->n_limits
; j
++) {
1162 struct nlattr
*nl_limit
;
1164 nl_limit
= nla_nest_start(msg
, j
+ 1);
1166 goto nla_put_failure
;
1167 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
1169 goto nla_put_failure
;
1170 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
1171 c
->limits
[j
].types
))
1172 goto nla_put_failure
;
1173 nla_nest_end(msg
, nl_limit
);
1176 nla_nest_end(msg
, nl_limits
);
1178 if (c
->beacon_int_infra_match
&&
1179 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
1180 goto nla_put_failure
;
1181 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
1182 c
->num_different_channels
) ||
1183 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
1185 goto nla_put_failure
;
1187 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1188 c
->radar_detect_widths
) ||
1189 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1190 c
->radar_detect_regions
)))
1191 goto nla_put_failure
;
1192 if (c
->beacon_int_min_gcd
&&
1193 nla_put_u32(msg
, NL80211_IFACE_COMB_BI_MIN_GCD
,
1194 c
->beacon_int_min_gcd
))
1195 goto nla_put_failure
;
1197 nla_nest_end(msg
, nl_combi
);
1200 nla_nest_end(msg
, nl_combis
);
1208 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1209 struct sk_buff
*msg
)
1211 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1212 struct nlattr
*nl_tcp
;
1217 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1221 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1222 tcp
->data_payload_max
))
1225 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1226 tcp
->data_payload_max
))
1229 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1232 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1233 sizeof(*tcp
->tok
), tcp
->tok
))
1236 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1237 tcp
->data_interval_max
))
1240 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1241 tcp
->wake_payload_max
))
1244 nla_nest_end(msg
, nl_tcp
);
1248 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1249 struct cfg80211_registered_device
*rdev
,
1252 struct nlattr
*nl_wowlan
;
1254 if (!rdev
->wiphy
.wowlan
)
1257 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1261 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1262 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1263 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1264 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1265 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1266 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1267 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1268 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1269 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1270 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1271 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1272 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1273 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1274 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1275 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1276 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1279 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1280 struct nl80211_pattern_support pat
= {
1281 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1282 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1283 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1284 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1287 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1292 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1293 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1294 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1297 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1300 nla_nest_end(msg
, nl_wowlan
);
1306 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1307 struct cfg80211_registered_device
*rdev
)
1309 struct nl80211_coalesce_rule_support rule
;
1311 if (!rdev
->wiphy
.coalesce
)
1314 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1315 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1316 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1317 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1318 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1319 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1321 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1327 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1328 struct ieee80211_supported_band
*sband
)
1330 struct nlattr
*nl_rates
, *nl_rate
;
1331 struct ieee80211_rate
*rate
;
1335 if (sband
->ht_cap
.ht_supported
&&
1336 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1337 sizeof(sband
->ht_cap
.mcs
),
1338 &sband
->ht_cap
.mcs
) ||
1339 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1340 sband
->ht_cap
.cap
) ||
1341 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1342 sband
->ht_cap
.ampdu_factor
) ||
1343 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1344 sband
->ht_cap
.ampdu_density
)))
1348 if (sband
->vht_cap
.vht_supported
&&
1349 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1350 sizeof(sband
->vht_cap
.vht_mcs
),
1351 &sband
->vht_cap
.vht_mcs
) ||
1352 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1353 sband
->vht_cap
.cap
)))
1357 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1361 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1362 nl_rate
= nla_nest_start(msg
, i
);
1366 rate
= &sband
->bitrates
[i
];
1367 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1370 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1372 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1375 nla_nest_end(msg
, nl_rate
);
1378 nla_nest_end(msg
, nl_rates
);
1384 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1385 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1388 struct nlattr
*nl_ftypes
, *nl_ifs
;
1389 enum nl80211_iftype ift
;
1395 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1399 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1400 nl_ftypes
= nla_nest_start(msg
, ift
);
1404 stypes
= mgmt_stypes
[ift
].tx
;
1407 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1408 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1413 nla_nest_end(msg
, nl_ftypes
);
1416 nla_nest_end(msg
, nl_ifs
);
1418 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1422 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1423 nl_ftypes
= nla_nest_start(msg
, ift
);
1427 stypes
= mgmt_stypes
[ift
].rx
;
1430 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1431 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1436 nla_nest_end(msg
, nl_ftypes
);
1438 nla_nest_end(msg
, nl_ifs
);
1443 #define CMD(op, n) \
1445 if (rdev->ops->op) { \
1447 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1448 goto nla_put_failure; \
1452 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device
*rdev
,
1453 struct sk_buff
*msg
)
1458 * do *NOT* add anything into this function, new things need to be
1459 * advertised only to new versions of userspace that can deal with
1460 * the split (and they can't possibly care about new features...
1462 CMD(add_virtual_intf
, NEW_INTERFACE
);
1463 CMD(change_virtual_intf
, SET_INTERFACE
);
1464 CMD(add_key
, NEW_KEY
);
1465 CMD(start_ap
, START_AP
);
1466 CMD(add_station
, NEW_STATION
);
1467 CMD(add_mpath
, NEW_MPATH
);
1468 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1469 CMD(change_bss
, SET_BSS
);
1470 CMD(auth
, AUTHENTICATE
);
1471 CMD(assoc
, ASSOCIATE
);
1472 CMD(deauth
, DEAUTHENTICATE
);
1473 CMD(disassoc
, DISASSOCIATE
);
1474 CMD(join_ibss
, JOIN_IBSS
);
1475 CMD(join_mesh
, JOIN_MESH
);
1476 CMD(set_pmksa
, SET_PMKSA
);
1477 CMD(del_pmksa
, DEL_PMKSA
);
1478 CMD(flush_pmksa
, FLUSH_PMKSA
);
1479 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1480 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1481 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1482 CMD(mgmt_tx
, FRAME
);
1483 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1484 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1486 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1487 goto nla_put_failure
;
1489 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1490 rdev
->ops
->join_mesh
) {
1492 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1493 goto nla_put_failure
;
1495 CMD(set_wds_peer
, SET_WDS_PEER
);
1496 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1497 CMD(tdls_mgmt
, TDLS_MGMT
);
1498 CMD(tdls_oper
, TDLS_OPER
);
1500 if (rdev
->wiphy
.max_sched_scan_reqs
)
1501 CMD(sched_scan_start
, START_SCHED_SCAN
);
1502 CMD(probe_client
, PROBE_CLIENT
);
1503 CMD(set_noack_map
, SET_NOACK_MAP
);
1504 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1506 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1507 goto nla_put_failure
;
1509 CMD(start_p2p_device
, START_P2P_DEVICE
);
1510 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1511 #ifdef CONFIG_NL80211_TESTMODE
1512 CMD(testmode_cmd
, TESTMODE
);
1515 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1517 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1518 goto nla_put_failure
;
1521 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1523 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1524 goto nla_put_failure
;
1532 struct nl80211_dump_wiphy_state
{
1535 long split_start
, band_start
, chan_start
, capa_start
;
1539 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1540 enum nl80211_commands cmd
,
1541 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1542 int flags
, struct nl80211_dump_wiphy_state
*state
)
1545 struct nlattr
*nl_bands
, *nl_band
;
1546 struct nlattr
*nl_freqs
, *nl_freq
;
1547 struct nlattr
*nl_cmds
;
1548 enum nl80211_band band
;
1549 struct ieee80211_channel
*chan
;
1551 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1552 rdev
->wiphy
.mgmt_stypes
;
1555 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1559 if (WARN_ON(!state
))
1562 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1563 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1564 wiphy_name(&rdev
->wiphy
)) ||
1565 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1566 cfg80211_rdev_list_generation
))
1567 goto nla_put_failure
;
1569 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1572 switch (state
->split_start
) {
1574 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1575 rdev
->wiphy
.retry_short
) ||
1576 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1577 rdev
->wiphy
.retry_long
) ||
1578 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1579 rdev
->wiphy
.frag_threshold
) ||
1580 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1581 rdev
->wiphy
.rts_threshold
) ||
1582 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1583 rdev
->wiphy
.coverage_class
) ||
1584 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1585 rdev
->wiphy
.max_scan_ssids
) ||
1586 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1587 rdev
->wiphy
.max_sched_scan_ssids
) ||
1588 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1589 rdev
->wiphy
.max_scan_ie_len
) ||
1590 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1591 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1592 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1593 rdev
->wiphy
.max_match_sets
) ||
1594 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1595 rdev
->wiphy
.max_sched_scan_plans
) ||
1596 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1597 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1598 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1599 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1600 goto nla_put_failure
;
1602 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1603 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1604 goto nla_put_failure
;
1605 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1606 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1607 goto nla_put_failure
;
1608 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1609 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1610 goto nla_put_failure
;
1611 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1612 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1613 goto nla_put_failure
;
1614 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1615 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1616 goto nla_put_failure
;
1617 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1618 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1619 goto nla_put_failure
;
1620 state
->split_start
++;
1624 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1625 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1626 rdev
->wiphy
.cipher_suites
))
1627 goto nla_put_failure
;
1629 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1630 rdev
->wiphy
.max_num_pmkids
))
1631 goto nla_put_failure
;
1633 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1634 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1635 goto nla_put_failure
;
1637 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1638 rdev
->wiphy
.available_antennas_tx
) ||
1639 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1640 rdev
->wiphy
.available_antennas_rx
))
1641 goto nla_put_failure
;
1643 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1644 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1645 rdev
->wiphy
.probe_resp_offload
))
1646 goto nla_put_failure
;
1648 if ((rdev
->wiphy
.available_antennas_tx
||
1649 rdev
->wiphy
.available_antennas_rx
) &&
1650 rdev
->ops
->get_antenna
) {
1651 u32 tx_ant
= 0, rx_ant
= 0;
1654 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1656 if (nla_put_u32(msg
,
1657 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1660 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1662 goto nla_put_failure
;
1666 state
->split_start
++;
1670 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1671 rdev
->wiphy
.interface_modes
))
1672 goto nla_put_failure
;
1673 state
->split_start
++;
1677 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1679 goto nla_put_failure
;
1681 for (band
= state
->band_start
;
1682 band
< NUM_NL80211_BANDS
; band
++) {
1683 struct ieee80211_supported_band
*sband
;
1685 sband
= rdev
->wiphy
.bands
[band
];
1690 nl_band
= nla_nest_start(msg
, band
);
1692 goto nla_put_failure
;
1694 switch (state
->chan_start
) {
1696 if (nl80211_send_band_rateinfo(msg
, sband
))
1697 goto nla_put_failure
;
1698 state
->chan_start
++;
1702 /* add frequencies */
1703 nl_freqs
= nla_nest_start(
1704 msg
, NL80211_BAND_ATTR_FREQS
);
1706 goto nla_put_failure
;
1708 for (i
= state
->chan_start
- 1;
1709 i
< sband
->n_channels
;
1711 nl_freq
= nla_nest_start(msg
, i
);
1713 goto nla_put_failure
;
1715 chan
= &sband
->channels
[i
];
1717 if (nl80211_msg_put_channel(
1718 msg
, &rdev
->wiphy
, chan
,
1720 goto nla_put_failure
;
1722 nla_nest_end(msg
, nl_freq
);
1726 if (i
< sband
->n_channels
)
1727 state
->chan_start
= i
+ 2;
1729 state
->chan_start
= 0;
1730 nla_nest_end(msg
, nl_freqs
);
1733 nla_nest_end(msg
, nl_band
);
1736 /* start again here */
1737 if (state
->chan_start
)
1742 nla_nest_end(msg
, nl_bands
);
1744 if (band
< NUM_NL80211_BANDS
)
1745 state
->band_start
= band
+ 1;
1747 state
->band_start
= 0;
1749 /* if bands & channels are done, continue outside */
1750 if (state
->band_start
== 0 && state
->chan_start
== 0)
1751 state
->split_start
++;
1755 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1757 goto nla_put_failure
;
1759 i
= nl80211_add_commands_unsplit(rdev
, msg
);
1761 goto nla_put_failure
;
1763 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1764 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1765 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1766 CMD(channel_switch
, CHANNEL_SWITCH
);
1767 CMD(set_qos_map
, SET_QOS_MAP
);
1768 if (rdev
->wiphy
.features
&
1769 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1770 CMD(add_tx_ts
, ADD_TX_TS
);
1771 CMD(set_multicast_to_unicast
, SET_MULTICAST_TO_UNICAST
);
1772 CMD(update_connect_params
, UPDATE_CONNECT_PARAMS
);
1776 nla_nest_end(msg
, nl_cmds
);
1777 state
->split_start
++;
1781 if (rdev
->ops
->remain_on_channel
&&
1782 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1784 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1785 rdev
->wiphy
.max_remain_on_channel_duration
))
1786 goto nla_put_failure
;
1788 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1789 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1790 goto nla_put_failure
;
1792 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1793 goto nla_put_failure
;
1794 state
->split_start
++;
1799 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1800 goto nla_put_failure
;
1801 state
->split_start
++;
1805 state
->split_start
++;
1808 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1809 rdev
->wiphy
.software_iftypes
))
1810 goto nla_put_failure
;
1812 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1814 goto nla_put_failure
;
1816 state
->split_start
++;
1820 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1821 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1822 rdev
->wiphy
.ap_sme_capa
))
1823 goto nla_put_failure
;
1825 features
= rdev
->wiphy
.features
;
1827 * We can only add the per-channel limit information if the
1828 * dump is split, otherwise it makes it too big. Therefore
1829 * only advertise it in that case.
1832 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1833 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1834 goto nla_put_failure
;
1836 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1837 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1838 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1839 rdev
->wiphy
.ht_capa_mod_mask
))
1840 goto nla_put_failure
;
1842 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1843 rdev
->wiphy
.max_acl_mac_addrs
&&
1844 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1845 rdev
->wiphy
.max_acl_mac_addrs
))
1846 goto nla_put_failure
;
1849 * Any information below this point is only available to
1850 * applications that can deal with it being split. This
1851 * helps ensure that newly added capabilities don't break
1852 * older tools by overrunning their buffers.
1854 * We still increment split_start so that in the split
1855 * case we'll continue with more data in the next round,
1856 * but break unconditionally so unsplit data stops here.
1858 state
->split_start
++;
1861 if (rdev
->wiphy
.extended_capabilities
&&
1862 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1863 rdev
->wiphy
.extended_capabilities_len
,
1864 rdev
->wiphy
.extended_capabilities
) ||
1865 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1866 rdev
->wiphy
.extended_capabilities_len
,
1867 rdev
->wiphy
.extended_capabilities_mask
)))
1868 goto nla_put_failure
;
1870 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1871 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1872 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1873 rdev
->wiphy
.vht_capa_mod_mask
))
1874 goto nla_put_failure
;
1876 state
->split_start
++;
1879 if (nl80211_send_coalesce(msg
, rdev
))
1880 goto nla_put_failure
;
1882 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1883 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1884 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1885 goto nla_put_failure
;
1887 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1888 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1889 rdev
->wiphy
.max_ap_assoc_sta
))
1890 goto nla_put_failure
;
1892 state
->split_start
++;
1895 if (rdev
->wiphy
.n_vendor_commands
) {
1896 const struct nl80211_vendor_cmd_info
*info
;
1897 struct nlattr
*nested
;
1899 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1901 goto nla_put_failure
;
1903 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1904 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1905 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1906 goto nla_put_failure
;
1908 nla_nest_end(msg
, nested
);
1911 if (rdev
->wiphy
.n_vendor_events
) {
1912 const struct nl80211_vendor_cmd_info
*info
;
1913 struct nlattr
*nested
;
1915 nested
= nla_nest_start(msg
,
1916 NL80211_ATTR_VENDOR_EVENTS
);
1918 goto nla_put_failure
;
1920 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1921 info
= &rdev
->wiphy
.vendor_events
[i
];
1922 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1923 goto nla_put_failure
;
1925 nla_nest_end(msg
, nested
);
1927 state
->split_start
++;
1930 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1931 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1932 rdev
->wiphy
.max_num_csa_counters
))
1933 goto nla_put_failure
;
1935 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1936 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1937 goto nla_put_failure
;
1939 if (rdev
->wiphy
.max_sched_scan_reqs
&&
1940 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_MAX_REQS
,
1941 rdev
->wiphy
.max_sched_scan_reqs
))
1942 goto nla_put_failure
;
1944 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1945 sizeof(rdev
->wiphy
.ext_features
),
1946 rdev
->wiphy
.ext_features
))
1947 goto nla_put_failure
;
1949 if (rdev
->wiphy
.bss_select_support
) {
1950 struct nlattr
*nested
;
1951 u32 bss_select_support
= rdev
->wiphy
.bss_select_support
;
1953 nested
= nla_nest_start(msg
, NL80211_ATTR_BSS_SELECT
);
1955 goto nla_put_failure
;
1958 while (bss_select_support
) {
1959 if ((bss_select_support
& 1) &&
1960 nla_put_flag(msg
, i
))
1961 goto nla_put_failure
;
1963 bss_select_support
>>= 1;
1965 nla_nest_end(msg
, nested
);
1968 state
->split_start
++;
1971 if (rdev
->wiphy
.num_iftype_ext_capab
&&
1972 rdev
->wiphy
.iftype_ext_capab
) {
1973 struct nlattr
*nested_ext_capab
, *nested
;
1975 nested
= nla_nest_start(msg
,
1976 NL80211_ATTR_IFTYPE_EXT_CAPA
);
1978 goto nla_put_failure
;
1980 for (i
= state
->capa_start
;
1981 i
< rdev
->wiphy
.num_iftype_ext_capab
; i
++) {
1982 const struct wiphy_iftype_ext_capab
*capab
;
1984 capab
= &rdev
->wiphy
.iftype_ext_capab
[i
];
1986 nested_ext_capab
= nla_nest_start(msg
, i
);
1987 if (!nested_ext_capab
||
1988 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
1990 nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1991 capab
->extended_capabilities_len
,
1992 capab
->extended_capabilities
) ||
1993 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1994 capab
->extended_capabilities_len
,
1995 capab
->extended_capabilities_mask
))
1996 goto nla_put_failure
;
1998 nla_nest_end(msg
, nested_ext_capab
);
2002 nla_nest_end(msg
, nested
);
2003 if (i
< rdev
->wiphy
.num_iftype_ext_capab
) {
2004 state
->capa_start
= i
+ 1;
2009 if (nla_put_u32(msg
, NL80211_ATTR_BANDS
,
2010 rdev
->wiphy
.nan_supported_bands
))
2011 goto nla_put_failure
;
2013 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
2014 NL80211_EXT_FEATURE_TXQS
)) {
2015 struct cfg80211_txq_stats txqstats
= {};
2018 res
= rdev_get_txq_stats(rdev
, NULL
, &txqstats
);
2020 !nl80211_put_txq_stats(msg
, &txqstats
,
2021 NL80211_ATTR_TXQ_STATS
))
2022 goto nla_put_failure
;
2024 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_LIMIT
,
2025 rdev
->wiphy
.txq_limit
))
2026 goto nla_put_failure
;
2027 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_MEMORY_LIMIT
,
2028 rdev
->wiphy
.txq_memory_limit
))
2029 goto nla_put_failure
;
2030 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_QUANTUM
,
2031 rdev
->wiphy
.txq_quantum
))
2032 goto nla_put_failure
;
2036 state
->split_start
= 0;
2040 genlmsg_end(msg
, hdr
);
2044 genlmsg_cancel(msg
, hdr
);
2048 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
2049 struct netlink_callback
*cb
,
2050 struct nl80211_dump_wiphy_state
*state
)
2052 struct nlattr
**tb
= genl_family_attrbuf(&nl80211_fam
);
2053 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, tb
,
2054 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
2055 /* ignore parse errors for backward compatibility */
2059 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
2060 if (tb
[NL80211_ATTR_WIPHY
])
2061 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
2062 if (tb
[NL80211_ATTR_WDEV
])
2063 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
2064 if (tb
[NL80211_ATTR_IFINDEX
]) {
2065 struct net_device
*netdev
;
2066 struct cfg80211_registered_device
*rdev
;
2067 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2069 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2072 if (netdev
->ieee80211_ptr
) {
2073 rdev
= wiphy_to_rdev(
2074 netdev
->ieee80211_ptr
->wiphy
);
2075 state
->filter_wiphy
= rdev
->wiphy_idx
;
2082 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2085 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
2086 struct cfg80211_registered_device
*rdev
;
2090 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
2095 state
->filter_wiphy
= -1;
2096 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
2102 cb
->args
[0] = (long)state
;
2105 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2106 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2108 if (++idx
<= state
->start
)
2110 if (state
->filter_wiphy
!= -1 &&
2111 state
->filter_wiphy
!= rdev
->wiphy_idx
)
2113 /* attempt to fit multiple wiphy data chunks into the skb */
2115 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
2117 NETLINK_CB(cb
->skb
).portid
,
2119 NLM_F_MULTI
, state
);
2122 * If sending the wiphy data didn't fit (ENOBUFS
2123 * or EMSGSIZE returned), this SKB is still
2124 * empty (so it's not too big because another
2125 * wiphy dataset is already in the skb) and
2126 * we've not tried to adjust the dump allocation
2127 * yet ... then adjust the alloc size to be
2128 * bigger, and return 1 but with the empty skb.
2129 * This results in an empty message being RX'ed
2130 * in userspace, but that is ignored.
2132 * We can then retry with the larger buffer.
2134 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
2135 !skb
->len
&& !state
->split
&&
2136 cb
->min_dump_alloc
< 4096) {
2137 cb
->min_dump_alloc
= 4096;
2138 state
->split_start
= 0;
2145 } while (state
->split_start
> 0);
2155 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
2157 kfree((void *)cb
->args
[0]);
2161 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2163 struct sk_buff
*msg
;
2164 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2165 struct nl80211_dump_wiphy_state state
= {};
2167 msg
= nlmsg_new(4096, GFP_KERNEL
);
2171 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
2172 info
->snd_portid
, info
->snd_seq
, 0,
2178 return genlmsg_reply(msg
, info
);
2181 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
2182 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
2183 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
2184 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
2185 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
2186 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
2189 static int parse_txq_params(struct nlattr
*tb
[],
2190 struct ieee80211_txq_params
*txq_params
)
2194 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
2195 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
2196 !tb
[NL80211_TXQ_ATTR_AIFS
])
2199 ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
2200 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
2201 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
2202 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
2203 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
2205 if (ac
>= NL80211_NUM_ACS
)
2207 txq_params
->ac
= array_index_nospec(ac
, NL80211_NUM_ACS
);
2211 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
2214 * You can only set the channel explicitly for WDS interfaces,
2215 * all others have their channel managed via their respective
2216 * "establish a connection" command (connect, join, ...)
2218 * For AP/GO and mesh mode, the channel can be set with the
2219 * channel userspace API, but is only stored and passed to the
2220 * low-level driver when the AP starts or the mesh is joined.
2221 * This is for backward compatibility, userspace can also give
2222 * the channel in the start-ap or join-mesh commands instead.
2224 * Monitors are special as they are normally slaved to
2225 * whatever else is going on, so they have their own special
2226 * operation to set the monitor channel if possible.
2229 wdev
->iftype
== NL80211_IFTYPE_AP
||
2230 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
2231 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
2232 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
2235 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
2236 struct genl_info
*info
,
2237 struct cfg80211_chan_def
*chandef
)
2241 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
2244 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
2246 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
2247 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
2248 chandef
->center_freq1
= control_freq
;
2249 chandef
->center_freq2
= 0;
2251 /* Primary channel not allowed */
2252 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
2255 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2256 enum nl80211_channel_type chantype
;
2258 chantype
= nla_get_u32(
2259 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2262 case NL80211_CHAN_NO_HT
:
2263 case NL80211_CHAN_HT20
:
2264 case NL80211_CHAN_HT40PLUS
:
2265 case NL80211_CHAN_HT40MINUS
:
2266 cfg80211_chandef_create(chandef
, chandef
->chan
,
2268 /* user input for center_freq is incorrect */
2269 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
] &&
2270 chandef
->center_freq1
!= nla_get_u32(
2271 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]))
2273 /* center_freq2 must be zero */
2274 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
] &&
2275 nla_get_u32(info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]))
2281 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
2283 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
2284 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
2285 chandef
->center_freq1
=
2287 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
2288 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
2289 chandef
->center_freq2
=
2291 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
2294 if (!cfg80211_chandef_valid(chandef
))
2297 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
2298 IEEE80211_CHAN_DISABLED
))
2301 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
2302 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
2303 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
2309 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
2310 struct net_device
*dev
,
2311 struct genl_info
*info
)
2313 struct cfg80211_chan_def chandef
;
2315 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
2316 struct wireless_dev
*wdev
= NULL
;
2319 wdev
= dev
->ieee80211_ptr
;
2320 if (!nl80211_can_set_dev_channel(wdev
))
2323 iftype
= wdev
->iftype
;
2325 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2330 case NL80211_IFTYPE_AP
:
2331 case NL80211_IFTYPE_P2P_GO
:
2332 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2337 if (wdev
->beacon_interval
) {
2338 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2339 !(rdev
->wiphy
.features
&
2340 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2345 /* Only allow dynamic channel width changes */
2346 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2350 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2354 wdev
->preset_chandef
= chandef
;
2357 case NL80211_IFTYPE_MESH_POINT
:
2358 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2360 case NL80211_IFTYPE_MONITOR
:
2361 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2370 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2372 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2373 struct net_device
*netdev
= info
->user_ptr
[1];
2375 return __nl80211_set_channel(rdev
, netdev
, info
);
2378 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2380 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2381 struct net_device
*dev
= info
->user_ptr
[1];
2382 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2385 if (!info
->attrs
[NL80211_ATTR_MAC
])
2388 if (netif_running(dev
))
2391 if (!rdev
->ops
->set_wds_peer
)
2394 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2397 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2398 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2401 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2403 struct cfg80211_registered_device
*rdev
;
2404 struct net_device
*netdev
= NULL
;
2405 struct wireless_dev
*wdev
;
2406 int result
= 0, rem_txq_params
= 0;
2407 struct nlattr
*nl_txq_params
;
2409 u8 retry_short
= 0, retry_long
= 0;
2410 u32 frag_threshold
= 0, rts_threshold
= 0;
2411 u8 coverage_class
= 0;
2412 u32 txq_limit
= 0, txq_memory_limit
= 0, txq_quantum
= 0;
2417 * Try to find the wiphy and netdev. Normally this
2418 * function shouldn't need the netdev, but this is
2419 * done for backward compatibility -- previously
2420 * setting the channel was done per wiphy, but now
2421 * it is per netdev. Previous userland like hostapd
2422 * also passed a netdev to set_wiphy, so that it is
2423 * possible to let that go to the right netdev!
2426 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2427 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2429 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2430 if (netdev
&& netdev
->ieee80211_ptr
)
2431 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2437 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2440 return PTR_ERR(rdev
);
2445 wdev
= netdev
->ieee80211_ptr
;
2448 * end workaround code, by now the rdev is available
2449 * and locked, and wdev may or may not be NULL.
2452 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2453 result
= cfg80211_dev_rename(
2454 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2459 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2460 struct ieee80211_txq_params txq_params
;
2461 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2463 if (!rdev
->ops
->set_txq_params
)
2469 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2470 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2473 if (!netif_running(netdev
))
2476 nla_for_each_nested(nl_txq_params
,
2477 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2479 result
= nla_parse_nested(tb
, NL80211_TXQ_ATTR_MAX
,
2485 result
= parse_txq_params(tb
, &txq_params
);
2489 result
= rdev_set_txq_params(rdev
, netdev
,
2496 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2497 result
= __nl80211_set_channel(
2499 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2505 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2506 struct wireless_dev
*txp_wdev
= wdev
;
2507 enum nl80211_tx_power_setting type
;
2510 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2513 if (!rdev
->ops
->set_tx_power
)
2516 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2517 type
= nla_get_u32(info
->attrs
[idx
]);
2519 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2520 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2523 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2524 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2525 mbm
= nla_get_u32(info
->attrs
[idx
]);
2528 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2533 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2534 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2537 if ((!rdev
->wiphy
.available_antennas_tx
&&
2538 !rdev
->wiphy
.available_antennas_rx
) ||
2539 !rdev
->ops
->set_antenna
)
2542 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2543 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2545 /* reject antenna configurations which don't match the
2546 * available antenna masks, except for the "all" mask */
2547 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2548 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2551 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2552 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2554 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2561 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2562 retry_short
= nla_get_u8(
2563 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2564 if (retry_short
== 0)
2567 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2570 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2571 retry_long
= nla_get_u8(
2572 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2573 if (retry_long
== 0)
2576 changed
|= WIPHY_PARAM_RETRY_LONG
;
2579 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2580 frag_threshold
= nla_get_u32(
2581 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2582 if (frag_threshold
< 256)
2585 if (frag_threshold
!= (u32
) -1) {
2587 * Fragments (apart from the last one) are required to
2588 * have even length. Make the fragmentation code
2589 * simpler by stripping LSB should someone try to use
2590 * odd threshold value.
2592 frag_threshold
&= ~0x1;
2594 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2597 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2598 rts_threshold
= nla_get_u32(
2599 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2600 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2603 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2604 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2607 coverage_class
= nla_get_u8(
2608 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2609 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2612 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2613 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2616 changed
|= WIPHY_PARAM_DYN_ACK
;
2619 if (info
->attrs
[NL80211_ATTR_TXQ_LIMIT
]) {
2620 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
2621 NL80211_EXT_FEATURE_TXQS
))
2623 txq_limit
= nla_get_u32(
2624 info
->attrs
[NL80211_ATTR_TXQ_LIMIT
]);
2625 changed
|= WIPHY_PARAM_TXQ_LIMIT
;
2628 if (info
->attrs
[NL80211_ATTR_TXQ_MEMORY_LIMIT
]) {
2629 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
2630 NL80211_EXT_FEATURE_TXQS
))
2632 txq_memory_limit
= nla_get_u32(
2633 info
->attrs
[NL80211_ATTR_TXQ_MEMORY_LIMIT
]);
2634 changed
|= WIPHY_PARAM_TXQ_MEMORY_LIMIT
;
2637 if (info
->attrs
[NL80211_ATTR_TXQ_QUANTUM
]) {
2638 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
2639 NL80211_EXT_FEATURE_TXQS
))
2641 txq_quantum
= nla_get_u32(
2642 info
->attrs
[NL80211_ATTR_TXQ_QUANTUM
]);
2643 changed
|= WIPHY_PARAM_TXQ_QUANTUM
;
2647 u8 old_retry_short
, old_retry_long
;
2648 u32 old_frag_threshold
, old_rts_threshold
;
2649 u8 old_coverage_class
;
2650 u32 old_txq_limit
, old_txq_memory_limit
, old_txq_quantum
;
2652 if (!rdev
->ops
->set_wiphy_params
)
2655 old_retry_short
= rdev
->wiphy
.retry_short
;
2656 old_retry_long
= rdev
->wiphy
.retry_long
;
2657 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2658 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2659 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2660 old_txq_limit
= rdev
->wiphy
.txq_limit
;
2661 old_txq_memory_limit
= rdev
->wiphy
.txq_memory_limit
;
2662 old_txq_quantum
= rdev
->wiphy
.txq_quantum
;
2664 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2665 rdev
->wiphy
.retry_short
= retry_short
;
2666 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2667 rdev
->wiphy
.retry_long
= retry_long
;
2668 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2669 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2670 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2671 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2672 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2673 rdev
->wiphy
.coverage_class
= coverage_class
;
2674 if (changed
& WIPHY_PARAM_TXQ_LIMIT
)
2675 rdev
->wiphy
.txq_limit
= txq_limit
;
2676 if (changed
& WIPHY_PARAM_TXQ_MEMORY_LIMIT
)
2677 rdev
->wiphy
.txq_memory_limit
= txq_memory_limit
;
2678 if (changed
& WIPHY_PARAM_TXQ_QUANTUM
)
2679 rdev
->wiphy
.txq_quantum
= txq_quantum
;
2681 result
= rdev_set_wiphy_params(rdev
, changed
);
2683 rdev
->wiphy
.retry_short
= old_retry_short
;
2684 rdev
->wiphy
.retry_long
= old_retry_long
;
2685 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2686 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2687 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2688 rdev
->wiphy
.txq_limit
= old_txq_limit
;
2689 rdev
->wiphy
.txq_memory_limit
= old_txq_memory_limit
;
2690 rdev
->wiphy
.txq_quantum
= old_txq_quantum
;
2697 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2699 return (u64
)wdev
->identifier
|
2700 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2703 static int nl80211_send_chandef(struct sk_buff
*msg
,
2704 const struct cfg80211_chan_def
*chandef
)
2706 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2709 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2710 chandef
->chan
->center_freq
))
2712 switch (chandef
->width
) {
2713 case NL80211_CHAN_WIDTH_20_NOHT
:
2714 case NL80211_CHAN_WIDTH_20
:
2715 case NL80211_CHAN_WIDTH_40
:
2716 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2717 cfg80211_get_chandef_type(chandef
)))
2723 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2725 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2727 if (chandef
->center_freq2
&&
2728 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2733 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2734 struct cfg80211_registered_device
*rdev
,
2735 struct wireless_dev
*wdev
, bool removal
)
2737 struct net_device
*dev
= wdev
->netdev
;
2738 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2742 cmd
= NL80211_CMD_DEL_INTERFACE
;
2744 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2749 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2750 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2751 goto nla_put_failure
;
2753 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2754 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2755 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
2756 NL80211_ATTR_PAD
) ||
2757 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2758 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2759 rdev
->devlist_generation
^
2760 (cfg80211_rdev_list_generation
<< 2)))
2761 goto nla_put_failure
;
2763 if (rdev
->ops
->get_channel
) {
2765 struct cfg80211_chan_def chandef
;
2767 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2769 if (nl80211_send_chandef(msg
, &chandef
))
2770 goto nla_put_failure
;
2774 if (rdev
->ops
->get_tx_power
) {
2777 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2779 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2781 goto nla_put_failure
;
2785 switch (wdev
->iftype
) {
2786 case NL80211_IFTYPE_AP
:
2787 if (wdev
->ssid_len
&&
2788 nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2789 goto nla_put_failure_locked
;
2791 case NL80211_IFTYPE_STATION
:
2792 case NL80211_IFTYPE_P2P_CLIENT
:
2793 case NL80211_IFTYPE_ADHOC
: {
2795 if (!wdev
->current_bss
)
2798 ssid_ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
2801 nla_put(msg
, NL80211_ATTR_SSID
, ssid_ie
[1], ssid_ie
+ 2))
2802 goto nla_put_failure_rcu_locked
;
2812 if (rdev
->ops
->get_txq_stats
) {
2813 struct cfg80211_txq_stats txqstats
= {};
2814 int ret
= rdev_get_txq_stats(rdev
, wdev
, &txqstats
);
2817 !nl80211_put_txq_stats(msg
, &txqstats
,
2818 NL80211_ATTR_TXQ_STATS
))
2819 goto nla_put_failure
;
2822 genlmsg_end(msg
, hdr
);
2825 nla_put_failure_rcu_locked
:
2827 nla_put_failure_locked
:
2830 genlmsg_cancel(msg
, hdr
);
2834 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2838 int wp_start
= cb
->args
[0];
2839 int if_start
= cb
->args
[1];
2840 int filter_wiphy
= -1;
2841 struct cfg80211_registered_device
*rdev
;
2842 struct wireless_dev
*wdev
;
2847 struct nl80211_dump_wiphy_state state
= {
2851 ret
= nl80211_dump_wiphy_parse(skb
, cb
, &state
);
2855 filter_wiphy
= state
.filter_wiphy
;
2858 * if filtering, set cb->args[2] to +1 since 0 is the default
2859 * value needed to determine that parsing is necessary.
2861 if (filter_wiphy
>= 0)
2862 cb
->args
[2] = filter_wiphy
+ 1;
2865 } else if (cb
->args
[2] > 0) {
2866 filter_wiphy
= cb
->args
[2] - 1;
2869 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2870 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2872 if (wp_idx
< wp_start
) {
2877 if (filter_wiphy
>= 0 && filter_wiphy
!= rdev
->wiphy_idx
)
2882 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
2883 if (if_idx
< if_start
) {
2887 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2888 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2889 rdev
, wdev
, false) < 0) {
2898 cb
->args
[0] = wp_idx
;
2899 cb
->args
[1] = if_idx
;
2908 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2910 struct sk_buff
*msg
;
2911 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2912 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2914 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2918 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2919 rdev
, wdev
, false) < 0) {
2924 return genlmsg_reply(msg
, info
);
2927 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2928 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2929 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2930 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2931 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2932 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2933 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2936 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2938 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2946 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
, nla
,
2947 mntr_flags_policy
, NULL
))
2950 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2952 *mntrflags
|= (1<<flag
);
2954 *mntrflags
|= MONITOR_FLAG_CHANGED
;
2959 static int nl80211_parse_mon_options(struct cfg80211_registered_device
*rdev
,
2960 enum nl80211_iftype type
,
2961 struct genl_info
*info
,
2962 struct vif_params
*params
)
2964 bool change
= false;
2967 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2968 if (type
!= NL80211_IFTYPE_MONITOR
)
2971 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2979 if (params
->flags
& MONITOR_FLAG_ACTIVE
&&
2980 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2983 if (info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]) {
2984 const u8
*mumimo_groups
;
2985 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2987 if (type
!= NL80211_IFTYPE_MONITOR
)
2990 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2994 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]);
2996 /* bits 0 and 63 are reserved and must be zero */
2997 if ((mumimo_groups
[0] & BIT(0)) ||
2998 (mumimo_groups
[VHT_MUMIMO_GROUPS_DATA_LEN
- 1] & BIT(7)))
3001 params
->vht_mumimo_groups
= mumimo_groups
;
3005 if (info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]) {
3006 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
3008 if (type
!= NL80211_IFTYPE_MONITOR
)
3011 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
3014 params
->vht_mumimo_follow_addr
=
3015 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]);
3019 return change
? 1 : 0;
3022 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
3023 struct net_device
*netdev
, u8 use_4addr
,
3024 enum nl80211_iftype iftype
)
3027 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
3033 case NL80211_IFTYPE_AP_VLAN
:
3034 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
3037 case NL80211_IFTYPE_STATION
:
3038 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
3048 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3050 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3051 struct vif_params params
;
3053 enum nl80211_iftype otype
, ntype
;
3054 struct net_device
*dev
= info
->user_ptr
[1];
3055 bool change
= false;
3057 memset(¶ms
, 0, sizeof(params
));
3059 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
3061 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
3062 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
3065 if (ntype
> NL80211_IFTYPE_MAX
)
3069 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
3070 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3072 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
3074 if (netif_running(dev
))
3078 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
3079 IEEE80211_MAX_MESH_ID_LEN
);
3080 wdev
->mesh_id_up_len
=
3081 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
3082 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
3083 wdev
->mesh_id_up_len
);
3087 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
3088 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
3090 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
3094 params
.use_4addr
= -1;
3097 err
= nl80211_parse_mon_options(rdev
, ntype
, info
, ¶ms
);
3104 err
= cfg80211_change_iface(rdev
, dev
, ntype
, ¶ms
);
3108 if (!err
&& params
.use_4addr
!= -1)
3109 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
3114 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3116 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3117 struct vif_params params
;
3118 struct wireless_dev
*wdev
;
3119 struct sk_buff
*msg
;
3121 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
3123 /* to avoid failing a new interface creation due to pending removal */
3124 cfg80211_destroy_ifaces(rdev
);
3126 memset(¶ms
, 0, sizeof(params
));
3128 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
3131 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
3132 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
3133 if (type
> NL80211_IFTYPE_MAX
)
3137 if (!rdev
->ops
->add_virtual_intf
||
3138 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
3141 if ((type
== NL80211_IFTYPE_P2P_DEVICE
|| type
== NL80211_IFTYPE_NAN
||
3142 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
3143 info
->attrs
[NL80211_ATTR_MAC
]) {
3144 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
3146 if (!is_valid_ether_addr(params
.macaddr
))
3147 return -EADDRNOTAVAIL
;
3150 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
3151 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
3152 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
3157 err
= nl80211_parse_mon_options(rdev
, type
, info
, ¶ms
);
3161 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3165 wdev
= rdev_add_virtual_intf(rdev
,
3166 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
3167 NET_NAME_USER
, type
, ¶ms
);
3168 if (WARN_ON(!wdev
)) {
3171 } else if (IS_ERR(wdev
)) {
3173 return PTR_ERR(wdev
);
3176 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
3177 wdev
->owner_nlportid
= info
->snd_portid
;
3180 case NL80211_IFTYPE_MESH_POINT
:
3181 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
3184 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
3185 IEEE80211_MAX_MESH_ID_LEN
);
3186 wdev
->mesh_id_up_len
=
3187 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
3188 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
3189 wdev
->mesh_id_up_len
);
3192 case NL80211_IFTYPE_NAN
:
3193 case NL80211_IFTYPE_P2P_DEVICE
:
3195 * P2P Device and NAN do not have a netdev, so don't go
3196 * through the netdev notifier and must be added here
3198 mutex_init(&wdev
->mtx
);
3199 INIT_LIST_HEAD(&wdev
->event_list
);
3200 spin_lock_init(&wdev
->event_lock
);
3201 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
3202 spin_lock_init(&wdev
->mgmt_registrations_lock
);
3204 wdev
->identifier
= ++rdev
->wdev_id
;
3205 list_add_rcu(&wdev
->list
, &rdev
->wiphy
.wdev_list
);
3206 rdev
->devlist_generation
++;
3212 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3213 rdev
, wdev
, false) < 0) {
3219 * For wdevs which have no associated netdev object (e.g. of type
3220 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3221 * For all other types, the event will be generated from the
3225 nl80211_notify_iface(rdev
, wdev
, NL80211_CMD_NEW_INTERFACE
);
3227 return genlmsg_reply(msg
, info
);
3230 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3232 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3233 struct wireless_dev
*wdev
= info
->user_ptr
[1];
3235 if (!rdev
->ops
->del_virtual_intf
)
3239 * If we remove a wireless device without a netdev then clear
3240 * user_ptr[1] so that nl80211_post_doit won't dereference it
3241 * to check if it needs to do dev_put(). Otherwise it crashes
3242 * since the wdev has been freed, unlike with a netdev where
3243 * we need the dev_put() for the netdev to really be freed.
3246 info
->user_ptr
[1] = NULL
;
3248 return rdev_del_virtual_intf(rdev
, wdev
);
3251 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
3253 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3254 struct net_device
*dev
= info
->user_ptr
[1];
3257 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
3260 if (!rdev
->ops
->set_noack_map
)
3263 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
3265 return rdev_set_noack_map(rdev
, dev
, noack_map
);
3268 struct get_key_cookie
{
3269 struct sk_buff
*msg
;
3274 static void get_key_callback(void *c
, struct key_params
*params
)
3277 struct get_key_cookie
*cookie
= c
;
3280 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
3281 params
->key_len
, params
->key
)) ||
3283 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
3284 params
->seq_len
, params
->seq
)) ||
3286 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
3288 goto nla_put_failure
;
3290 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
3292 goto nla_put_failure
;
3295 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
3296 params
->key_len
, params
->key
)) ||
3298 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
3299 params
->seq_len
, params
->seq
)) ||
3301 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
3303 goto nla_put_failure
;
3305 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
3306 goto nla_put_failure
;
3308 nla_nest_end(cookie
->msg
, key
);
3315 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
3317 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3319 struct net_device
*dev
= info
->user_ptr
[1];
3321 const u8
*mac_addr
= NULL
;
3323 struct get_key_cookie cookie
= {
3327 struct sk_buff
*msg
;
3329 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
3330 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
3335 if (info
->attrs
[NL80211_ATTR_MAC
])
3336 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3338 pairwise
= !!mac_addr
;
3339 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
3340 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
3342 if (kt
>= NUM_NL80211_KEYTYPES
)
3344 if (kt
!= NL80211_KEYTYPE_GROUP
&&
3345 kt
!= NL80211_KEYTYPE_PAIRWISE
)
3347 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
3350 if (!rdev
->ops
->get_key
)
3353 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3356 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3360 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3361 NL80211_CMD_NEW_KEY
);
3363 goto nla_put_failure
;
3366 cookie
.idx
= key_idx
;
3368 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3369 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
3370 goto nla_put_failure
;
3372 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
3373 goto nla_put_failure
;
3375 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
3382 goto nla_put_failure
;
3384 genlmsg_end(msg
, hdr
);
3385 return genlmsg_reply(msg
, info
);
3394 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
3396 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3397 struct key_parse key
;
3399 struct net_device
*dev
= info
->user_ptr
[1];
3401 err
= nl80211_parse_key(info
, &key
);
3408 /* only support setting default key */
3409 if (!key
.def
&& !key
.defmgmt
)
3412 wdev_lock(dev
->ieee80211_ptr
);
3415 if (!rdev
->ops
->set_default_key
) {
3420 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3424 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
3425 key
.def_uni
, key
.def_multi
);
3430 #ifdef CONFIG_CFG80211_WEXT
3431 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
3434 if (key
.def_uni
|| !key
.def_multi
) {
3439 if (!rdev
->ops
->set_default_mgmt_key
) {
3444 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3448 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
3452 #ifdef CONFIG_CFG80211_WEXT
3453 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3458 wdev_unlock(dev
->ieee80211_ptr
);
3463 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3465 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3467 struct net_device
*dev
= info
->user_ptr
[1];
3468 struct key_parse key
;
3469 const u8
*mac_addr
= NULL
;
3471 err
= nl80211_parse_key(info
, &key
);
3478 if (info
->attrs
[NL80211_ATTR_MAC
])
3479 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3481 if (key
.type
== -1) {
3483 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3485 key
.type
= NL80211_KEYTYPE_GROUP
;
3489 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3490 key
.type
!= NL80211_KEYTYPE_GROUP
)
3493 if (!rdev
->ops
->add_key
)
3496 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3497 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3501 wdev_lock(dev
->ieee80211_ptr
);
3502 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3504 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3505 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3507 wdev_unlock(dev
->ieee80211_ptr
);
3512 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3514 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3516 struct net_device
*dev
= info
->user_ptr
[1];
3517 u8
*mac_addr
= NULL
;
3518 struct key_parse key
;
3520 err
= nl80211_parse_key(info
, &key
);
3524 if (info
->attrs
[NL80211_ATTR_MAC
])
3525 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3527 if (key
.type
== -1) {
3529 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3531 key
.type
= NL80211_KEYTYPE_GROUP
;
3535 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3536 key
.type
!= NL80211_KEYTYPE_GROUP
)
3539 if (!rdev
->ops
->del_key
)
3542 wdev_lock(dev
->ieee80211_ptr
);
3543 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3545 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3546 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3550 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3551 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3554 #ifdef CONFIG_CFG80211_WEXT
3556 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3557 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3558 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3559 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3562 wdev_unlock(dev
->ieee80211_ptr
);
3567 /* This function returns an error or the number of nested attributes */
3568 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3570 struct nlattr
*attr
;
3571 int n_entries
= 0, tmp
;
3573 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3574 if (nla_len(attr
) != ETH_ALEN
)
3584 * This function parses ACL information and allocates memory for ACL data.
3585 * On successful return, the calling function is responsible to free the
3586 * ACL buffer returned by this function.
3588 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3589 struct genl_info
*info
)
3591 enum nl80211_acl_policy acl_policy
;
3592 struct nlattr
*attr
;
3593 struct cfg80211_acl_data
*acl
;
3594 int i
= 0, n_entries
, tmp
;
3596 if (!wiphy
->max_acl_mac_addrs
)
3597 return ERR_PTR(-EOPNOTSUPP
);
3599 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3600 return ERR_PTR(-EINVAL
);
3602 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3603 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3604 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3605 return ERR_PTR(-EINVAL
);
3607 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3608 return ERR_PTR(-EINVAL
);
3610 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3612 return ERR_PTR(n_entries
);
3614 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3615 return ERR_PTR(-ENOTSUPP
);
3617 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3620 return ERR_PTR(-ENOMEM
);
3622 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3623 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3627 acl
->n_acl_entries
= n_entries
;
3628 acl
->acl_policy
= acl_policy
;
3633 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3635 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3636 struct net_device
*dev
= info
->user_ptr
[1];
3637 struct cfg80211_acl_data
*acl
;
3640 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3641 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3644 if (!dev
->ieee80211_ptr
->beacon_interval
)
3647 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3649 return PTR_ERR(acl
);
3651 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3658 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
3659 u8
*rates
, u8 rates_len
)
3664 for (i
= 0; i
< rates_len
; i
++) {
3665 int rate
= (rates
[i
] & 0x7f) * 5;
3668 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
3669 struct ieee80211_rate
*srate
=
3670 &sband
->bitrates
[ridx
];
3671 if (rate
== srate
->bitrate
) {
3676 if (ridx
== sband
->n_bitrates
)
3677 return 0; /* rate not found */
3683 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
3684 u8
*rates
, u8 rates_len
,
3685 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
3689 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
3691 for (i
= 0; i
< rates_len
; i
++) {
3694 ridx
= rates
[i
] / 8;
3695 rbit
= BIT(rates
[i
] % 8);
3697 /* check validity */
3698 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
3701 /* check availability */
3702 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
3711 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
3715 switch (vht_mcs_map
) {
3716 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
3718 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
3721 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
3724 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
3734 static void vht_build_mcs_mask(u16 vht_mcs_map
,
3735 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
3739 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
3740 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
3745 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
3746 struct nl80211_txrate_vht
*txrate
,
3747 u16 mcs
[NL80211_VHT_NSS_MAX
])
3749 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3750 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
3753 if (!sband
->vht_cap
.vht_supported
)
3756 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
3758 /* Build vht_mcs_mask from VHT capabilities */
3759 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
3761 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3762 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
3763 mcs
[i
] = txrate
->mcs
[i
];
3771 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
3772 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
3773 .len
= NL80211_MAX_SUPP_RATES
},
3774 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
3775 .len
= NL80211_MAX_SUPP_HT_RATES
},
3776 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
3777 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
3780 static int nl80211_parse_tx_bitrate_mask(struct genl_info
*info
,
3781 struct cfg80211_bitrate_mask
*mask
)
3783 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
3784 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3786 struct nlattr
*tx_rates
;
3787 struct ieee80211_supported_band
*sband
;
3790 memset(mask
, 0, sizeof(*mask
));
3791 /* Default to all rates enabled */
3792 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
3793 sband
= rdev
->wiphy
.bands
[i
];
3798 mask
->control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
3799 memcpy(mask
->control
[i
].ht_mcs
,
3800 sband
->ht_cap
.mcs
.rx_mask
,
3801 sizeof(mask
->control
[i
].ht_mcs
));
3803 if (!sband
->vht_cap
.vht_supported
)
3806 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3807 vht_build_mcs_mask(vht_tx_mcs_map
, mask
->control
[i
].vht_mcs
);
3810 /* if no rates are given set it back to the defaults */
3811 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
3814 /* The nested attribute uses enum nl80211_band as the index. This maps
3815 * directly to the enum nl80211_band values used in cfg80211.
3817 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
3818 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
3819 enum nl80211_band band
= nla_type(tx_rates
);
3822 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
3824 sband
= rdev
->wiphy
.bands
[band
];
3827 err
= nla_parse_nested(tb
, NL80211_TXRATE_MAX
, tx_rates
,
3828 nl80211_txattr_policy
, info
->extack
);
3831 if (tb
[NL80211_TXRATE_LEGACY
]) {
3832 mask
->control
[band
].legacy
= rateset_to_mask(
3834 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
3835 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
3836 if ((mask
->control
[band
].legacy
== 0) &&
3837 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
3840 if (tb
[NL80211_TXRATE_HT
]) {
3841 if (!ht_rateset_to_mask(
3843 nla_data(tb
[NL80211_TXRATE_HT
]),
3844 nla_len(tb
[NL80211_TXRATE_HT
]),
3845 mask
->control
[band
].ht_mcs
))
3848 if (tb
[NL80211_TXRATE_VHT
]) {
3849 if (!vht_set_mcs_mask(
3851 nla_data(tb
[NL80211_TXRATE_VHT
]),
3852 mask
->control
[band
].vht_mcs
))
3855 if (tb
[NL80211_TXRATE_GI
]) {
3856 mask
->control
[band
].gi
=
3857 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
3858 if (mask
->control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
3862 if (mask
->control
[band
].legacy
== 0) {
3863 /* don't allow empty legacy rates if HT or VHT
3864 * are not even supported.
3866 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
3867 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
3870 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3871 if (mask
->control
[band
].ht_mcs
[i
])
3874 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3875 if (mask
->control
[band
].vht_mcs
[i
])
3878 /* legacy and mcs rates may not be both empty */
3887 static int validate_beacon_tx_rate(struct cfg80211_registered_device
*rdev
,
3888 enum nl80211_band band
,
3889 struct cfg80211_bitrate_mask
*beacon_rate
)
3891 u32 count_ht
, count_vht
, i
;
3892 u32 rate
= beacon_rate
->control
[band
].legacy
;
3894 /* Allow only one rate */
3895 if (hweight32(rate
) > 1)
3899 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
3900 if (hweight8(beacon_rate
->control
[band
].ht_mcs
[i
]) > 1) {
3902 } else if (beacon_rate
->control
[band
].ht_mcs
[i
]) {
3907 if (count_ht
&& rate
)
3912 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3913 if (hweight16(beacon_rate
->control
[band
].vht_mcs
[i
]) > 1) {
3915 } else if (beacon_rate
->control
[band
].vht_mcs
[i
]) {
3920 if (count_vht
&& rate
)
3924 if ((count_ht
&& count_vht
) || (!rate
&& !count_ht
&& !count_vht
))
3928 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3929 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
))
3932 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3933 NL80211_EXT_FEATURE_BEACON_RATE_HT
))
3936 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3937 NL80211_EXT_FEATURE_BEACON_RATE_VHT
))
3943 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3944 struct cfg80211_beacon_data
*bcn
)
3946 bool haveinfo
= false;
3948 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3949 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3950 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3951 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3954 memset(bcn
, 0, sizeof(*bcn
));
3956 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3957 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3958 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3964 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3965 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3966 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3973 if (attrs
[NL80211_ATTR_IE
]) {
3974 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3975 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3978 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3979 bcn
->proberesp_ies
=
3980 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3981 bcn
->proberesp_ies_len
=
3982 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3985 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3986 bcn
->assocresp_ies
=
3987 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3988 bcn
->assocresp_ies_len
=
3989 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3992 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3993 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3994 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
4000 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings
*params
,
4008 for (i
= 0; i
< rates
[1]; i
++) {
4009 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HT_PHY
)
4010 params
->ht_required
= true;
4011 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)
4012 params
->vht_required
= true;
4017 * Since the nl80211 API didn't include, from the beginning, attributes about
4018 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4019 * benefit of drivers that rebuild IEs in the firmware.
4021 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings
*params
)
4023 const struct cfg80211_beacon_data
*bcn
= ¶ms
->beacon
;
4024 size_t ies_len
= bcn
->tail_len
;
4025 const u8
*ies
= bcn
->tail
;
4029 rates
= cfg80211_find_ie(WLAN_EID_SUPP_RATES
, ies
, ies_len
);
4030 nl80211_check_ap_rate_selectors(params
, rates
);
4032 rates
= cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES
, ies
, ies_len
);
4033 nl80211_check_ap_rate_selectors(params
, rates
);
4035 cap
= cfg80211_find_ie(WLAN_EID_HT_CAPABILITY
, ies
, ies_len
);
4036 if (cap
&& cap
[1] >= sizeof(*params
->ht_cap
))
4037 params
->ht_cap
= (void *)(cap
+ 2);
4038 cap
= cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY
, ies
, ies_len
);
4039 if (cap
&& cap
[1] >= sizeof(*params
->vht_cap
))
4040 params
->vht_cap
= (void *)(cap
+ 2);
4043 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
4044 struct cfg80211_ap_settings
*params
)
4046 struct wireless_dev
*wdev
;
4049 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
4050 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
4051 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4054 if (!wdev
->preset_chandef
.chan
)
4057 params
->chandef
= wdev
->preset_chandef
;
4065 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
4066 enum nl80211_auth_type auth_type
,
4067 enum nl80211_commands cmd
)
4069 if (auth_type
> NL80211_AUTHTYPE_MAX
)
4073 case NL80211_CMD_AUTHENTICATE
:
4074 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
4075 auth_type
== NL80211_AUTHTYPE_SAE
)
4077 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
4078 NL80211_EXT_FEATURE_FILS_STA
) &&
4079 (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
4080 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4081 auth_type
== NL80211_AUTHTYPE_FILS_PK
))
4084 case NL80211_CMD_CONNECT
:
4085 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
4086 auth_type
== NL80211_AUTHTYPE_SAE
)
4089 /* FILS with SK PFS or PK not supported yet */
4090 if (auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4091 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
4093 if (!wiphy_ext_feature_isset(
4095 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
4096 auth_type
== NL80211_AUTHTYPE_FILS_SK
)
4099 case NL80211_CMD_START_AP
:
4100 /* SAE not supported yet */
4101 if (auth_type
== NL80211_AUTHTYPE_SAE
)
4103 /* FILS not supported yet */
4104 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
4105 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4106 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
4114 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
4116 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4117 struct net_device
*dev
= info
->user_ptr
[1];
4118 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4119 struct cfg80211_ap_settings params
;
4122 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4123 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4126 if (!rdev
->ops
->start_ap
)
4129 if (wdev
->beacon_interval
)
4132 memset(¶ms
, 0, sizeof(params
));
4134 /* these are required for START_AP */
4135 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
4136 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
4137 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
4140 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
4144 params
.beacon_interval
=
4145 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4146 params
.dtim_period
=
4147 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
4149 err
= cfg80211_validate_beacon_int(rdev
, dev
->ieee80211_ptr
->iftype
,
4150 params
.beacon_interval
);
4155 * In theory, some of these attributes should be required here
4156 * but since they were not used when the command was originally
4157 * added, keep them optional for old user space programs to let
4158 * them continue to work with drivers that do not need the
4159 * additional information -- drivers must check!
4161 if (info
->attrs
[NL80211_ATTR_SSID
]) {
4162 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4164 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4165 if (params
.ssid_len
== 0 ||
4166 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
4170 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
4171 params
.hidden_ssid
= nla_get_u32(
4172 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
4173 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
4174 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
4175 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
4179 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4181 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4182 params
.auth_type
= nla_get_u32(
4183 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4184 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
4185 NL80211_CMD_START_AP
))
4188 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4190 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
4191 NL80211_MAX_NR_CIPHER_SUITES
);
4195 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
4196 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
4198 params
.inactivity_timeout
= nla_get_u16(
4199 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
4202 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4203 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4205 params
.p2p_ctwindow
=
4206 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4207 if (params
.p2p_ctwindow
> 127)
4209 if (params
.p2p_ctwindow
!= 0 &&
4210 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4214 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4217 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4219 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4222 params
.p2p_opp_ps
= tmp
;
4223 if (params
.p2p_opp_ps
!= 0 &&
4224 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4228 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4229 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
4232 } else if (wdev
->preset_chandef
.chan
) {
4233 params
.chandef
= wdev
->preset_chandef
;
4234 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
4237 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
4241 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
4242 err
= nl80211_parse_tx_bitrate_mask(info
, ¶ms
.beacon_rate
);
4246 err
= validate_beacon_tx_rate(rdev
, params
.chandef
.chan
->band
,
4247 ¶ms
.beacon_rate
);
4252 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
4254 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
4255 switch (params
.smps_mode
) {
4256 case NL80211_SMPS_OFF
:
4258 case NL80211_SMPS_STATIC
:
4259 if (!(rdev
->wiphy
.features
&
4260 NL80211_FEATURE_STATIC_SMPS
))
4263 case NL80211_SMPS_DYNAMIC
:
4264 if (!(rdev
->wiphy
.features
&
4265 NL80211_FEATURE_DYNAMIC_SMPS
))
4272 params
.smps_mode
= NL80211_SMPS_OFF
;
4275 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
4276 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
4279 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
4280 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
4281 if (IS_ERR(params
.acl
))
4282 return PTR_ERR(params
.acl
);
4285 nl80211_calculate_ap_params(¶ms
);
4288 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
4290 wdev
->preset_chandef
= params
.chandef
;
4291 wdev
->beacon_interval
= params
.beacon_interval
;
4292 wdev
->chandef
= params
.chandef
;
4293 wdev
->ssid_len
= params
.ssid_len
;
4294 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
4296 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
4297 wdev
->conn_owner_nlportid
= info
->snd_portid
;
4306 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
4308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4309 struct net_device
*dev
= info
->user_ptr
[1];
4310 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4311 struct cfg80211_beacon_data params
;
4314 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4315 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4318 if (!rdev
->ops
->change_beacon
)
4321 if (!wdev
->beacon_interval
)
4324 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
4329 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
4335 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
4337 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4338 struct net_device
*dev
= info
->user_ptr
[1];
4340 return cfg80211_stop_ap(rdev
, dev
, false);
4343 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
4344 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
4345 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
4346 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
4347 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
4348 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
4349 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
4352 static int parse_station_flags(struct genl_info
*info
,
4353 enum nl80211_iftype iftype
,
4354 struct station_parameters
*params
)
4356 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
4361 * Try parsing the new attribute first so userspace
4362 * can specify both for older kernels.
4364 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
4366 struct nl80211_sta_flag_update
*sta_flags
;
4368 sta_flags
= nla_data(nla
);
4369 params
->sta_flags_mask
= sta_flags
->mask
;
4370 params
->sta_flags_set
= sta_flags
->set
;
4371 params
->sta_flags_set
&= params
->sta_flags_mask
;
4372 if ((params
->sta_flags_mask
|
4373 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
4378 /* if present, parse the old attribute */
4380 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
4384 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
, nla
,
4385 sta_flags_policy
, info
->extack
))
4389 * Only allow certain flags for interface types so that
4390 * other attributes are silently ignored. Remember that
4391 * this is backward compatibility code with old userspace
4392 * and shouldn't be hit in other cases anyway.
4395 case NL80211_IFTYPE_AP
:
4396 case NL80211_IFTYPE_AP_VLAN
:
4397 case NL80211_IFTYPE_P2P_GO
:
4398 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4399 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4400 BIT(NL80211_STA_FLAG_WME
) |
4401 BIT(NL80211_STA_FLAG_MFP
);
4403 case NL80211_IFTYPE_P2P_CLIENT
:
4404 case NL80211_IFTYPE_STATION
:
4405 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4406 BIT(NL80211_STA_FLAG_TDLS_PEER
);
4408 case NL80211_IFTYPE_MESH_POINT
:
4409 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4410 BIT(NL80211_STA_FLAG_MFP
) |
4411 BIT(NL80211_STA_FLAG_AUTHORIZED
);
4416 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
4418 params
->sta_flags_set
|= (1<<flag
);
4420 /* no longer support new API additions in old API */
4421 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
4429 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
4432 struct nlattr
*rate
;
4435 enum nl80211_rate_info rate_flg
;
4437 rate
= nla_nest_start(msg
, attr
);
4441 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4442 bitrate
= cfg80211_calculate_bitrate(info
);
4443 /* report 16-bit bitrate only if we can */
4444 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
4446 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
4448 if (bitrate_compat
> 0 &&
4449 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
4453 case RATE_INFO_BW_5
:
4454 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
4456 case RATE_INFO_BW_10
:
4457 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
4462 case RATE_INFO_BW_20
:
4465 case RATE_INFO_BW_40
:
4466 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
4468 case RATE_INFO_BW_80
:
4469 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
4471 case RATE_INFO_BW_160
:
4472 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
4476 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
4479 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
4480 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
4482 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4483 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4485 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
4486 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
4488 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
4490 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4491 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4495 nla_nest_end(msg
, rate
);
4499 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
4508 attr
= nla_nest_start(msg
, id
);
4512 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
4513 if (!(mask
& BIT(i
)))
4516 if (nla_put_u8(msg
, i
, signal
[i
]))
4520 nla_nest_end(msg
, attr
);
4525 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
4527 struct cfg80211_registered_device
*rdev
,
4528 struct net_device
*dev
,
4529 const u8
*mac_addr
, struct station_info
*sinfo
)
4532 struct nlattr
*sinfoattr
, *bss_param
;
4534 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
4538 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4539 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
4540 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
4541 goto nla_put_failure
;
4543 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
4545 goto nla_put_failure
;
4547 #define PUT_SINFO(attr, memb, type) do { \
4548 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
4549 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4550 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4552 goto nla_put_failure; \
4554 #define PUT_SINFO_U64(attr, memb) do { \
4555 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4556 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4557 sinfo->memb, NL80211_STA_INFO_PAD)) \
4558 goto nla_put_failure; \
4561 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
4562 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
4564 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
4565 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
4566 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
4567 (u32
)sinfo
->rx_bytes
))
4568 goto nla_put_failure
;
4570 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
4571 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
4572 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
4573 (u32
)sinfo
->tx_bytes
))
4574 goto nla_put_failure
;
4576 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
4577 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
4578 PUT_SINFO(LLID
, llid
, u16
);
4579 PUT_SINFO(PLID
, plid
, u16
);
4580 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
4581 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
4583 switch (rdev
->wiphy
.signal_type
) {
4584 case CFG80211_SIGNAL_TYPE_MBM
:
4585 PUT_SINFO(SIGNAL
, signal
, u8
);
4586 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
4591 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
4592 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4593 sinfo
->chain_signal
,
4594 NL80211_STA_INFO_CHAIN_SIGNAL
))
4595 goto nla_put_failure
;
4597 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
4598 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4599 sinfo
->chain_signal_avg
,
4600 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
4601 goto nla_put_failure
;
4603 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
4604 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
4605 NL80211_STA_INFO_TX_BITRATE
))
4606 goto nla_put_failure
;
4608 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
4609 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
4610 NL80211_STA_INFO_RX_BITRATE
))
4611 goto nla_put_failure
;
4614 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
4615 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
4616 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
4617 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
4618 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
4619 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
4620 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
4621 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
4622 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
4624 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
4625 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
4627 goto nla_put_failure
;
4629 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
4630 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
4631 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
4632 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
4633 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
4634 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
4635 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
4636 sinfo
->bss_param
.dtim_period
) ||
4637 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
4638 sinfo
->bss_param
.beacon_interval
))
4639 goto nla_put_failure
;
4641 nla_nest_end(msg
, bss_param
);
4643 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
4644 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
4645 sizeof(struct nl80211_sta_flag_update
),
4647 goto nla_put_failure
;
4649 PUT_SINFO_U64(T_OFFSET
, t_offset
);
4650 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
4651 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
4652 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
4653 PUT_SINFO(ACK_SIGNAL
, ack_signal
, u8
);
4654 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
4655 NL80211_EXT_FEATURE_DATA_ACK_SIGNAL_SUPPORT
))
4656 PUT_SINFO(DATA_ACK_SIGNAL_AVG
, avg_ack_signal
, s8
);
4659 #undef PUT_SINFO_U64
4661 if (sinfo
->pertid
) {
4662 struct nlattr
*tidsattr
;
4665 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
4667 goto nla_put_failure
;
4669 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
4670 struct cfg80211_tid_stats
*tidstats
;
4671 struct nlattr
*tidattr
;
4673 tidstats
= &sinfo
->pertid
[tid
];
4675 if (!tidstats
->filled
)
4678 tidattr
= nla_nest_start(msg
, tid
+ 1);
4680 goto nla_put_failure
;
4682 #define PUT_TIDVAL_U64(attr, memb) do { \
4683 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
4684 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4685 tidstats->memb, NL80211_TID_STATS_PAD)) \
4686 goto nla_put_failure; \
4689 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
4690 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
4691 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
4692 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
4694 #undef PUT_TIDVAL_U64
4695 if ((tidstats
->filled
&
4696 BIT(NL80211_TID_STATS_TXQ_STATS
)) &&
4697 !nl80211_put_txq_stats(msg
, &tidstats
->txq_stats
,
4698 NL80211_TID_STATS_TXQ_STATS
))
4699 goto nla_put_failure
;
4701 nla_nest_end(msg
, tidattr
);
4704 nla_nest_end(msg
, tidsattr
);
4707 nla_nest_end(msg
, sinfoattr
);
4709 if (sinfo
->assoc_req_ies_len
&&
4710 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
4711 sinfo
->assoc_req_ies
))
4712 goto nla_put_failure
;
4714 cfg80211_sinfo_release_content(sinfo
);
4715 genlmsg_end(msg
, hdr
);
4719 cfg80211_sinfo_release_content(sinfo
);
4720 genlmsg_cancel(msg
, hdr
);
4724 static int nl80211_dump_station(struct sk_buff
*skb
,
4725 struct netlink_callback
*cb
)
4727 struct station_info sinfo
;
4728 struct cfg80211_registered_device
*rdev
;
4729 struct wireless_dev
*wdev
;
4730 u8 mac_addr
[ETH_ALEN
];
4731 int sta_idx
= cb
->args
[2];
4735 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4739 if (!wdev
->netdev
) {
4744 if (!rdev
->ops
->dump_station
) {
4750 memset(&sinfo
, 0, sizeof(sinfo
));
4751 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
4758 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
4759 NETLINK_CB(cb
->skb
).portid
,
4760 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4761 rdev
, wdev
->netdev
, mac_addr
,
4769 cb
->args
[2] = sta_idx
;
4777 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
4779 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4780 struct net_device
*dev
= info
->user_ptr
[1];
4781 struct station_info sinfo
;
4782 struct sk_buff
*msg
;
4783 u8
*mac_addr
= NULL
;
4786 memset(&sinfo
, 0, sizeof(sinfo
));
4788 if (!info
->attrs
[NL80211_ATTR_MAC
])
4791 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4793 if (!rdev
->ops
->get_station
)
4796 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
4800 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4802 cfg80211_sinfo_release_content(&sinfo
);
4806 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
4807 info
->snd_portid
, info
->snd_seq
, 0,
4808 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
4813 return genlmsg_reply(msg
, info
);
4816 int cfg80211_check_station_change(struct wiphy
*wiphy
,
4817 struct station_parameters
*params
,
4818 enum cfg80211_station_type statype
)
4820 if (params
->listen_interval
!= -1 &&
4821 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4824 if (params
->support_p2p_ps
!= -1 &&
4825 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4829 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
4830 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4833 /* When you run into this, adjust the code below for the new flag */
4834 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4837 case CFG80211_STA_MESH_PEER_KERNEL
:
4838 case CFG80211_STA_MESH_PEER_USER
:
4840 * No ignoring the TDLS flag here -- the userspace mesh
4841 * code doesn't have the bug of including TDLS in the
4844 if (params
->sta_flags_mask
&
4845 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4846 BIT(NL80211_STA_FLAG_MFP
) |
4847 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4850 case CFG80211_STA_TDLS_PEER_SETUP
:
4851 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4852 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4854 /* ignore since it can't change */
4855 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4858 /* disallow mesh-specific things */
4859 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4861 if (params
->local_pm
)
4863 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4867 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4868 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4869 /* TDLS can't be set, ... */
4870 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4873 * ... but don't bother the driver with it. This works around
4874 * a hostapd/wpa_supplicant issue -- it always includes the
4875 * TLDS_PEER flag in the mask even for AP mode.
4877 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4880 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4881 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4882 /* reject other things that can't change */
4883 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4885 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4887 if (params
->supported_rates
)
4889 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4893 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4894 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4900 case CFG80211_STA_AP_MLME_CLIENT
:
4901 /* Use this only for authorizing/unauthorizing a station */
4902 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4905 case CFG80211_STA_AP_CLIENT
:
4906 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4907 /* accept only the listed bits */
4908 if (params
->sta_flags_mask
&
4909 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4910 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4911 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4912 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4913 BIT(NL80211_STA_FLAG_WME
) |
4914 BIT(NL80211_STA_FLAG_MFP
)))
4917 /* but authenticated/associated only if driver handles it */
4918 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4919 params
->sta_flags_mask
&
4920 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4921 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4924 case CFG80211_STA_IBSS
:
4925 case CFG80211_STA_AP_STA
:
4926 /* reject any changes other than AUTHORIZED */
4927 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4930 case CFG80211_STA_TDLS_PEER_SETUP
:
4931 /* reject any changes other than AUTHORIZED or WME */
4932 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4933 BIT(NL80211_STA_FLAG_WME
)))
4935 /* force (at least) rates when authorizing */
4936 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4937 !params
->supported_rates
)
4940 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4941 /* reject any changes */
4943 case CFG80211_STA_MESH_PEER_KERNEL
:
4944 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4947 case CFG80211_STA_MESH_PEER_USER
:
4948 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4949 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4955 * Older kernel versions ignored this attribute entirely, so don't
4956 * reject attempts to update it but mark it as unused instead so the
4957 * driver won't look at the data.
4959 if (statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
&&
4960 statype
!= CFG80211_STA_TDLS_PEER_SETUP
)
4961 params
->opmode_notif_used
= false;
4965 EXPORT_SYMBOL(cfg80211_check_station_change
);
4968 * Get vlan interface making sure it is running and on the right wiphy.
4970 static struct net_device
*get_vlan(struct genl_info
*info
,
4971 struct cfg80211_registered_device
*rdev
)
4973 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4974 struct net_device
*v
;
4980 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4982 return ERR_PTR(-ENODEV
);
4984 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4989 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4990 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4991 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4996 if (!netif_running(v
)) {
5004 return ERR_PTR(ret
);
5007 static const struct nla_policy
5008 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
5009 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
5010 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
5013 static int nl80211_parse_sta_wme(struct genl_info
*info
,
5014 struct station_parameters
*params
)
5016 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
5020 /* parse WME attributes if present */
5021 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
5024 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
5025 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
5026 nl80211_sta_wme_policy
, info
->extack
);
5030 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
5031 params
->uapsd_queues
= nla_get_u8(
5032 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
5033 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
5036 if (tb
[NL80211_STA_WME_MAX_SP
])
5037 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
5039 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
5042 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
5047 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
5048 struct station_parameters
*params
)
5050 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
5051 params
->supported_channels
=
5052 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
5053 params
->supported_channels_len
=
5054 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
5056 * Need to include at least one (first channel, number of
5057 * channels) tuple for each subband, and must have proper
5058 * tuples for the rest of the data as well.
5060 if (params
->supported_channels_len
< 2)
5062 if (params
->supported_channels_len
% 2)
5066 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
5067 params
->supported_oper_classes
=
5068 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
5069 params
->supported_oper_classes_len
=
5070 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
5072 * The value of the Length field of the Supported Operating
5073 * Classes element is between 2 and 253.
5075 if (params
->supported_oper_classes_len
< 2 ||
5076 params
->supported_oper_classes_len
> 253)
5082 static int nl80211_set_station_tdls(struct genl_info
*info
,
5083 struct station_parameters
*params
)
5086 /* Dummy STA entry gets updated once the peer capabilities are known */
5087 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
5088 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
5089 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
5091 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5092 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
5094 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
5096 err
= nl80211_parse_sta_channel_info(info
, params
);
5100 return nl80211_parse_sta_wme(info
, params
);
5103 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
5105 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5106 struct net_device
*dev
= info
->user_ptr
[1];
5107 struct station_parameters params
;
5111 memset(¶ms
, 0, sizeof(params
));
5113 if (!rdev
->ops
->change_station
)
5117 * AID and listen_interval properties can be set only for unassociated
5118 * station. Include these parameters here and will check them in
5119 * cfg80211_check_station_change().
5121 if (info
->attrs
[NL80211_ATTR_STA_AID
])
5122 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
5124 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
5125 params
.listen_interval
=
5126 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
5128 params
.listen_interval
= -1;
5130 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
5133 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
5134 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
5137 params
.support_p2p_ps
= tmp
;
5139 params
.support_p2p_ps
= -1;
5142 if (!info
->attrs
[NL80211_ATTR_MAC
])
5145 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5147 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
5148 params
.supported_rates
=
5149 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5150 params
.supported_rates_len
=
5151 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5154 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
5156 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
5157 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
5160 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
5162 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5163 params
.ext_capab_len
=
5164 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5167 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
5170 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
5171 params
.plink_action
=
5172 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
5173 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
5177 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
5178 params
.plink_state
=
5179 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
5180 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
5182 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]) {
5183 params
.peer_aid
= nla_get_u16(
5184 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
5185 if (params
.peer_aid
> IEEE80211_MAX_AID
)
5188 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
5191 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
5192 enum nl80211_mesh_power_mode pm
= nla_get_u32(
5193 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
5195 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
5196 pm
> NL80211_MESH_POWER_MAX
)
5199 params
.local_pm
= pm
;
5202 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
5203 params
.opmode_notif_used
= true;
5204 params
.opmode_notif
=
5205 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
5208 /* Include parameters for TDLS peer (will check later) */
5209 err
= nl80211_set_station_tdls(info
, ¶ms
);
5213 params
.vlan
= get_vlan(info
, rdev
);
5214 if (IS_ERR(params
.vlan
))
5215 return PTR_ERR(params
.vlan
);
5217 switch (dev
->ieee80211_ptr
->iftype
) {
5218 case NL80211_IFTYPE_AP
:
5219 case NL80211_IFTYPE_AP_VLAN
:
5220 case NL80211_IFTYPE_P2P_GO
:
5221 case NL80211_IFTYPE_P2P_CLIENT
:
5222 case NL80211_IFTYPE_STATION
:
5223 case NL80211_IFTYPE_ADHOC
:
5224 case NL80211_IFTYPE_MESH_POINT
:
5231 /* driver will call cfg80211_check_station_change() */
5232 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
5236 dev_put(params
.vlan
);
5241 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
5243 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5245 struct net_device
*dev
= info
->user_ptr
[1];
5246 struct station_parameters params
;
5247 u8
*mac_addr
= NULL
;
5248 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5249 BIT(NL80211_STA_FLAG_ASSOCIATED
);
5251 memset(¶ms
, 0, sizeof(params
));
5253 if (!rdev
->ops
->add_station
)
5256 if (!info
->attrs
[NL80211_ATTR_MAC
])
5259 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
5262 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
5265 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
5266 !info
->attrs
[NL80211_ATTR_PEER_AID
])
5269 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5270 params
.supported_rates
=
5271 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5272 params
.supported_rates_len
=
5273 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5274 params
.listen_interval
=
5275 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
5277 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
5280 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
5281 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
5284 params
.support_p2p_ps
= tmp
;
5287 * if not specified, assume it's supported for P2P GO interface,
5288 * and is NOT supported for AP interface
5290 params
.support_p2p_ps
=
5291 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
5294 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
5295 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
5297 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
5298 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
5301 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
5303 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
5304 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
5307 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
5309 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5310 params
.ext_capab_len
=
5311 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5314 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
5316 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5318 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
5320 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
5322 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
5323 params
.opmode_notif_used
= true;
5324 params
.opmode_notif
=
5325 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
5328 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
5329 params
.plink_action
=
5330 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
5331 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
5335 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
5339 err
= nl80211_parse_sta_wme(info
, ¶ms
);
5343 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
5346 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5347 * as userspace might just pass through the capabilities from the IEs
5348 * directly, rather than enforcing this restriction and returning an
5349 * error in this case.
5351 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
5352 params
.ht_capa
= NULL
;
5353 params
.vht_capa
= NULL
;
5356 /* When you run into this, adjust the code below for the new flag */
5357 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
5359 switch (dev
->ieee80211_ptr
->iftype
) {
5360 case NL80211_IFTYPE_AP
:
5361 case NL80211_IFTYPE_AP_VLAN
:
5362 case NL80211_IFTYPE_P2P_GO
:
5363 /* ignore WME attributes if iface/sta is not capable */
5364 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
5365 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
5366 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5368 /* TDLS peers cannot be added */
5369 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5370 info
->attrs
[NL80211_ATTR_PEER_AID
])
5372 /* but don't bother the driver with it */
5373 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
5375 /* allow authenticated/associated only if driver handles it */
5376 if (!(rdev
->wiphy
.features
&
5377 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
5378 params
.sta_flags_mask
& auth_assoc
)
5381 /* Older userspace, or userspace wanting to be compatible with
5382 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5383 * and assoc flags in the mask, but assumes the station will be
5384 * added as associated anyway since this was the required driver
5385 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5387 * In order to not bother drivers with this quirk in the API
5388 * set the flags in both the mask and set for new stations in
5391 if (!(params
.sta_flags_mask
& auth_assoc
)) {
5392 params
.sta_flags_mask
|= auth_assoc
;
5393 params
.sta_flags_set
|= auth_assoc
;
5396 /* must be last in here for error handling */
5397 params
.vlan
= get_vlan(info
, rdev
);
5398 if (IS_ERR(params
.vlan
))
5399 return PTR_ERR(params
.vlan
);
5401 case NL80211_IFTYPE_MESH_POINT
:
5402 /* ignore uAPSD data */
5403 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5405 /* associated is disallowed */
5406 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
5408 /* TDLS peers cannot be added */
5409 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5410 info
->attrs
[NL80211_ATTR_PEER_AID
])
5413 case NL80211_IFTYPE_STATION
:
5414 case NL80211_IFTYPE_P2P_CLIENT
:
5415 /* ignore uAPSD data */
5416 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5418 /* these are disallowed */
5419 if (params
.sta_flags_mask
&
5420 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
5421 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
5423 /* Only TDLS peers can be added */
5424 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
5426 /* Can only add if TDLS ... */
5427 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
5429 /* ... with external setup is supported */
5430 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
5433 * Older wpa_supplicant versions always mark the TDLS peer
5434 * as authorized, but it shouldn't yet be.
5436 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
5442 /* be aware of params.vlan when changing code here */
5444 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
5447 dev_put(params
.vlan
);
5451 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
5453 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5454 struct net_device
*dev
= info
->user_ptr
[1];
5455 struct station_del_parameters params
;
5457 memset(¶ms
, 0, sizeof(params
));
5459 if (info
->attrs
[NL80211_ATTR_MAC
])
5460 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5462 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5463 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5464 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5465 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5468 if (!rdev
->ops
->del_station
)
5471 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
5473 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
5474 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
5475 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
5478 /* Default to Deauthentication frame */
5479 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
5482 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
5483 params
.reason_code
=
5484 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5485 if (params
.reason_code
== 0)
5486 return -EINVAL
; /* 0 is reserved */
5488 /* Default to reason code 2 */
5489 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
5492 return rdev_del_station(rdev
, dev
, ¶ms
);
5495 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5496 int flags
, struct net_device
*dev
,
5497 u8
*dst
, u8
*next_hop
,
5498 struct mpath_info
*pinfo
)
5501 struct nlattr
*pinfoattr
;
5503 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
5507 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5508 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
5509 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
5510 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
5511 goto nla_put_failure
;
5513 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
5515 goto nla_put_failure
;
5516 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
5517 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
5519 goto nla_put_failure
;
5520 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
5521 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
5522 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
5523 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
5525 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
5526 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
5528 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
5529 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
5531 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
5532 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
5533 pinfo
->discovery_timeout
)) ||
5534 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
5535 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
5536 pinfo
->discovery_retries
)))
5537 goto nla_put_failure
;
5539 nla_nest_end(msg
, pinfoattr
);
5541 genlmsg_end(msg
, hdr
);
5545 genlmsg_cancel(msg
, hdr
);
5549 static int nl80211_dump_mpath(struct sk_buff
*skb
,
5550 struct netlink_callback
*cb
)
5552 struct mpath_info pinfo
;
5553 struct cfg80211_registered_device
*rdev
;
5554 struct wireless_dev
*wdev
;
5556 u8 next_hop
[ETH_ALEN
];
5557 int path_idx
= cb
->args
[2];
5561 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5565 if (!rdev
->ops
->dump_mpath
) {
5570 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5576 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
5583 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5584 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5585 wdev
->netdev
, dst
, next_hop
,
5593 cb
->args
[2] = path_idx
;
5600 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5602 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5604 struct net_device
*dev
= info
->user_ptr
[1];
5605 struct mpath_info pinfo
;
5606 struct sk_buff
*msg
;
5608 u8 next_hop
[ETH_ALEN
];
5610 memset(&pinfo
, 0, sizeof(pinfo
));
5612 if (!info
->attrs
[NL80211_ATTR_MAC
])
5615 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5617 if (!rdev
->ops
->get_mpath
)
5620 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5623 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
5627 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5631 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5632 dev
, dst
, next_hop
, &pinfo
) < 0) {
5637 return genlmsg_reply(msg
, info
);
5640 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5642 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5643 struct net_device
*dev
= info
->user_ptr
[1];
5645 u8
*next_hop
= NULL
;
5647 if (!info
->attrs
[NL80211_ATTR_MAC
])
5650 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5653 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5654 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5656 if (!rdev
->ops
->change_mpath
)
5659 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5662 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
5665 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5667 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5668 struct net_device
*dev
= info
->user_ptr
[1];
5670 u8
*next_hop
= NULL
;
5672 if (!info
->attrs
[NL80211_ATTR_MAC
])
5675 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5678 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5679 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5681 if (!rdev
->ops
->add_mpath
)
5684 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5687 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
5690 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5692 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5693 struct net_device
*dev
= info
->user_ptr
[1];
5696 if (info
->attrs
[NL80211_ATTR_MAC
])
5697 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5699 if (!rdev
->ops
->del_mpath
)
5702 return rdev_del_mpath(rdev
, dev
, dst
);
5705 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
5707 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5709 struct net_device
*dev
= info
->user_ptr
[1];
5710 struct mpath_info pinfo
;
5711 struct sk_buff
*msg
;
5715 memset(&pinfo
, 0, sizeof(pinfo
));
5717 if (!info
->attrs
[NL80211_ATTR_MAC
])
5720 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5722 if (!rdev
->ops
->get_mpp
)
5725 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5728 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
5732 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5736 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5737 dev
, dst
, mpp
, &pinfo
) < 0) {
5742 return genlmsg_reply(msg
, info
);
5745 static int nl80211_dump_mpp(struct sk_buff
*skb
,
5746 struct netlink_callback
*cb
)
5748 struct mpath_info pinfo
;
5749 struct cfg80211_registered_device
*rdev
;
5750 struct wireless_dev
*wdev
;
5753 int path_idx
= cb
->args
[2];
5757 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5761 if (!rdev
->ops
->dump_mpp
) {
5766 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5772 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
5779 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5780 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5781 wdev
->netdev
, dst
, mpp
,
5789 cb
->args
[2] = path_idx
;
5796 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
5798 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5799 struct net_device
*dev
= info
->user_ptr
[1];
5800 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5801 struct bss_parameters params
;
5804 memset(¶ms
, 0, sizeof(params
));
5805 /* default to not changing parameters */
5806 params
.use_cts_prot
= -1;
5807 params
.use_short_preamble
= -1;
5808 params
.use_short_slot_time
= -1;
5809 params
.ap_isolate
= -1;
5810 params
.ht_opmode
= -1;
5811 params
.p2p_ctwindow
= -1;
5812 params
.p2p_opp_ps
= -1;
5814 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
5815 params
.use_cts_prot
=
5816 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
5817 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
5818 params
.use_short_preamble
=
5819 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
5820 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
5821 params
.use_short_slot_time
=
5822 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
5823 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5824 params
.basic_rates
=
5825 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5826 params
.basic_rates_len
=
5827 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5829 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
5830 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
5831 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
5833 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
5835 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
5836 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5838 params
.p2p_ctwindow
=
5839 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
5840 if (params
.p2p_ctwindow
< 0)
5842 if (params
.p2p_ctwindow
!= 0 &&
5843 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
5847 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
5850 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5852 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
5855 params
.p2p_opp_ps
= tmp
;
5856 if (params
.p2p_opp_ps
&&
5857 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
5861 if (!rdev
->ops
->change_bss
)
5864 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5865 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5869 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
5875 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5879 enum nl80211_user_reg_hint_type user_reg_hint_type
;
5883 * You should only get this when cfg80211 hasn't yet initialized
5884 * completely when built-in to the kernel right between the time
5885 * window between nl80211_init() and regulatory_init(), if that is
5888 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
5889 return -EINPROGRESS
;
5891 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
5892 user_reg_hint_type
=
5893 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
5895 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
5897 switch (user_reg_hint_type
) {
5898 case NL80211_USER_REG_HINT_USER
:
5899 case NL80211_USER_REG_HINT_CELL_BASE
:
5900 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5903 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5904 return regulatory_hint_user(data
, user_reg_hint_type
);
5905 case NL80211_USER_REG_HINT_INDOOR
:
5906 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
5907 owner_nlportid
= info
->snd_portid
;
5908 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
5914 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
5920 static int nl80211_reload_regdb(struct sk_buff
*skb
, struct genl_info
*info
)
5922 return reg_reload_regdb();
5925 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
5926 struct genl_info
*info
)
5928 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5929 struct net_device
*dev
= info
->user_ptr
[1];
5930 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5931 struct mesh_config cur_params
;
5934 struct nlattr
*pinfoattr
;
5935 struct sk_buff
*msg
;
5937 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5940 if (!rdev
->ops
->get_mesh_config
)
5944 /* If not connected, get default parameters */
5945 if (!wdev
->mesh_id_len
)
5946 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5948 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5954 /* Draw up a netlink message to send back */
5955 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5958 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5959 NL80211_CMD_GET_MESH_CONFIG
);
5962 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5964 goto nla_put_failure
;
5965 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5966 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5967 cur_params
.dot11MeshRetryTimeout
) ||
5968 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5969 cur_params
.dot11MeshConfirmTimeout
) ||
5970 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5971 cur_params
.dot11MeshHoldingTimeout
) ||
5972 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5973 cur_params
.dot11MeshMaxPeerLinks
) ||
5974 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5975 cur_params
.dot11MeshMaxRetries
) ||
5976 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5977 cur_params
.dot11MeshTTL
) ||
5978 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5979 cur_params
.element_ttl
) ||
5980 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5981 cur_params
.auto_open_plinks
) ||
5982 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5983 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5984 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5985 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5986 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5987 cur_params
.path_refresh_time
) ||
5988 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5989 cur_params
.min_discovery_timeout
) ||
5990 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5991 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5992 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5993 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5994 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5995 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5996 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5997 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5998 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5999 cur_params
.dot11MeshHWMPRootMode
) ||
6000 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
6001 cur_params
.dot11MeshHWMPRannInterval
) ||
6002 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
6003 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
6004 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
6005 cur_params
.dot11MeshForwarding
) ||
6006 nla_put_s32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
6007 cur_params
.rssi_threshold
) ||
6008 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
6009 cur_params
.ht_opmode
) ||
6010 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
6011 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
6012 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
6013 cur_params
.dot11MeshHWMProotInterval
) ||
6014 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
6015 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
6016 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
6017 cur_params
.power_mode
) ||
6018 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
6019 cur_params
.dot11MeshAwakeWindowDuration
) ||
6020 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
6021 cur_params
.plink_timeout
))
6022 goto nla_put_failure
;
6023 nla_nest_end(msg
, pinfoattr
);
6024 genlmsg_end(msg
, hdr
);
6025 return genlmsg_reply(msg
, info
);
6033 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
6034 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
6035 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
6036 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
6037 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
6038 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
6039 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
6040 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
6041 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
6042 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
6043 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
6044 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
6045 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
6046 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
6047 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
6048 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
6049 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
6050 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
6051 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
6052 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
6053 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
6054 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
6055 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
6056 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
6057 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
6058 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
6059 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
6060 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
6061 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
6064 static const struct nla_policy
6065 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
6066 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
6067 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
6068 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
6069 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
6070 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
6071 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
6072 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
6073 .len
= IEEE80211_MAX_DATA_LEN
},
6074 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
6077 static int nl80211_check_bool(const struct nlattr
*nla
, u8 min
, u8 max
, bool *out
)
6079 u8 val
= nla_get_u8(nla
);
6080 if (val
< min
|| val
> max
)
6086 static int nl80211_check_u8(const struct nlattr
*nla
, u8 min
, u8 max
, u8
*out
)
6088 u8 val
= nla_get_u8(nla
);
6089 if (val
< min
|| val
> max
)
6095 static int nl80211_check_u16(const struct nlattr
*nla
, u16 min
, u16 max
, u16
*out
)
6097 u16 val
= nla_get_u16(nla
);
6098 if (val
< min
|| val
> max
)
6104 static int nl80211_check_u32(const struct nlattr
*nla
, u32 min
, u32 max
, u32
*out
)
6106 u32 val
= nla_get_u32(nla
);
6107 if (val
< min
|| val
> max
)
6113 static int nl80211_check_s32(const struct nlattr
*nla
, s32 min
, s32 max
, s32
*out
)
6115 s32 val
= nla_get_s32(nla
);
6116 if (val
< min
|| val
> max
)
6122 static int nl80211_check_power_mode(const struct nlattr
*nla
,
6123 enum nl80211_mesh_power_mode min
,
6124 enum nl80211_mesh_power_mode max
,
6125 enum nl80211_mesh_power_mode
*out
)
6127 u32 val
= nla_get_u32(nla
);
6128 if (val
< min
|| val
> max
)
6134 static int nl80211_parse_mesh_config(struct genl_info
*info
,
6135 struct mesh_config
*cfg
,
6138 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
6142 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
6145 if (fn(tb[attr], min, max, &cfg->param)) \
6147 mask |= (1 << (attr - 1)); \
6151 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
6153 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
6154 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
6155 nl80211_meshconf_params_policy
, info
->extack
))
6158 /* This makes sure that there aren't more than 32 mesh config
6159 * parameters (otherwise our bitfield scheme would not work.) */
6160 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
6162 /* Fill in the params struct */
6163 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
6164 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
6166 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
6167 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
6169 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
6170 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
6172 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
6173 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
6175 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
6176 mask
, NL80211_MESHCONF_MAX_RETRIES
,
6178 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
6179 mask
, NL80211_MESHCONF_TTL
, nl80211_check_u8
);
6180 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
6181 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
6183 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
6184 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
6185 nl80211_check_bool
);
6186 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
6188 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
6190 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
6191 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
6193 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
6194 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
6196 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
6197 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
6199 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
6201 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
6203 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
6205 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
6207 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
6209 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
6211 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6212 dot11MeshHWMPnetDiameterTraversalTime
,
6214 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
6216 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
6217 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
6219 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
6220 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
6222 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6223 dot11MeshGateAnnouncementProtocol
, 0, 1,
6224 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
6225 nl80211_check_bool
);
6226 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
6227 mask
, NL80211_MESHCONF_FORWARDING
,
6228 nl80211_check_bool
);
6229 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
6230 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
6233 * Check HT operation mode based on
6234 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
6236 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
6237 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
6239 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
6240 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
6241 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6244 if ((ht_opmode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
) &&
6245 (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6248 switch (ht_opmode
& IEEE80211_HT_OP_MODE_PROTECTION
) {
6249 case IEEE80211_HT_OP_MODE_PROTECTION_NONE
:
6250 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
6251 if (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
)
6254 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER
:
6255 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
6256 if (!(ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6260 cfg
->ht_opmode
= ht_opmode
;
6261 mask
|= (1 << (NL80211_MESHCONF_HT_OPMODE
- 1));
6263 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
6265 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
6267 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
6268 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
6270 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6271 dot11MeshHWMPconfirmationInterval
,
6273 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
6275 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
6276 NL80211_MESH_POWER_ACTIVE
,
6277 NL80211_MESH_POWER_MAX
,
6278 mask
, NL80211_MESHCONF_POWER_MODE
,
6279 nl80211_check_power_mode
);
6280 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
6282 NL80211_MESHCONF_AWAKE_WINDOW
, nl80211_check_u16
);
6283 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
6284 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
6291 #undef FILL_IN_MESH_PARAM_IF_SET
6294 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
6295 struct mesh_setup
*setup
)
6297 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6298 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
6300 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
6302 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
6303 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
6304 nl80211_mesh_setup_params_policy
, info
->extack
))
6307 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
6308 setup
->sync_method
=
6309 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
6310 IEEE80211_SYNC_METHOD_VENDOR
:
6311 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
6313 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
6314 setup
->path_sel_proto
=
6315 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
6316 IEEE80211_PATH_PROTOCOL_VENDOR
:
6317 IEEE80211_PATH_PROTOCOL_HWMP
;
6319 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
6320 setup
->path_metric
=
6321 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
6322 IEEE80211_PATH_METRIC_VENDOR
:
6323 IEEE80211_PATH_METRIC_AIRTIME
;
6325 if (tb
[NL80211_MESH_SETUP_IE
]) {
6326 struct nlattr
*ieattr
=
6327 tb
[NL80211_MESH_SETUP_IE
];
6328 if (!is_valid_ie_attr(ieattr
))
6330 setup
->ie
= nla_data(ieattr
);
6331 setup
->ie_len
= nla_len(ieattr
);
6333 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
6334 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
6336 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
6337 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
6338 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
6339 if (setup
->is_secure
)
6340 setup
->user_mpm
= true;
6342 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
6343 if (!setup
->user_mpm
)
6346 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
6352 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
6353 struct genl_info
*info
)
6355 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6356 struct net_device
*dev
= info
->user_ptr
[1];
6357 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6358 struct mesh_config cfg
;
6362 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6365 if (!rdev
->ops
->update_mesh_config
)
6368 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
6373 if (!wdev
->mesh_id_len
)
6377 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
6384 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
6385 struct sk_buff
*msg
)
6387 struct nlattr
*nl_reg_rules
;
6390 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
6391 (regdom
->dfs_region
&&
6392 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
6393 goto nla_put_failure
;
6395 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
6397 goto nla_put_failure
;
6399 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
6400 struct nlattr
*nl_reg_rule
;
6401 const struct ieee80211_reg_rule
*reg_rule
;
6402 const struct ieee80211_freq_range
*freq_range
;
6403 const struct ieee80211_power_rule
*power_rule
;
6404 unsigned int max_bandwidth_khz
;
6406 reg_rule
= ®dom
->reg_rules
[i
];
6407 freq_range
= ®_rule
->freq_range
;
6408 power_rule
= ®_rule
->power_rule
;
6410 nl_reg_rule
= nla_nest_start(msg
, i
);
6412 goto nla_put_failure
;
6414 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
6415 if (!max_bandwidth_khz
)
6416 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
6419 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
6421 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
6422 freq_range
->start_freq_khz
) ||
6423 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
6424 freq_range
->end_freq_khz
) ||
6425 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
6426 max_bandwidth_khz
) ||
6427 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
6428 power_rule
->max_antenna_gain
) ||
6429 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
6430 power_rule
->max_eirp
) ||
6431 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
6432 reg_rule
->dfs_cac_ms
))
6433 goto nla_put_failure
;
6435 nla_nest_end(msg
, nl_reg_rule
);
6438 nla_nest_end(msg
, nl_reg_rules
);
6445 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
6447 const struct ieee80211_regdomain
*regdom
= NULL
;
6448 struct cfg80211_registered_device
*rdev
;
6449 struct wiphy
*wiphy
= NULL
;
6450 struct sk_buff
*msg
;
6453 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6457 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6458 NL80211_CMD_GET_REG
);
6462 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
6465 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6468 return PTR_ERR(rdev
);
6471 wiphy
= &rdev
->wiphy
;
6472 self_managed
= wiphy
->regulatory_flags
&
6473 REGULATORY_WIPHY_SELF_MANAGED
;
6474 regdom
= get_wiphy_regdom(wiphy
);
6476 /* a self-managed-reg device must have a private regdom */
6477 if (WARN_ON(!regdom
&& self_managed
)) {
6483 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6484 goto nla_put_failure
;
6487 if (!wiphy
&& reg_last_request_cell_base() &&
6488 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6489 NL80211_USER_REG_HINT_CELL_BASE
))
6490 goto nla_put_failure
;
6495 regdom
= rcu_dereference(cfg80211_regdomain
);
6497 if (nl80211_put_regdom(regdom
, msg
))
6498 goto nla_put_failure_rcu
;
6502 genlmsg_end(msg
, hdr
);
6503 return genlmsg_reply(msg
, info
);
6505 nla_put_failure_rcu
:
6513 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6514 u32 seq
, int flags
, struct wiphy
*wiphy
,
6515 const struct ieee80211_regdomain
*regdom
)
6517 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6518 NL80211_CMD_GET_REG
);
6523 genl_dump_check_consistent(cb
, hdr
);
6525 if (nl80211_put_regdom(regdom
, msg
))
6526 goto nla_put_failure
;
6528 if (!wiphy
&& reg_last_request_cell_base() &&
6529 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6530 NL80211_USER_REG_HINT_CELL_BASE
))
6531 goto nla_put_failure
;
6534 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6535 goto nla_put_failure
;
6537 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
6538 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
6539 goto nla_put_failure
;
6541 genlmsg_end(msg
, hdr
);
6545 genlmsg_cancel(msg
, hdr
);
6549 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
6550 struct netlink_callback
*cb
)
6552 const struct ieee80211_regdomain
*regdom
= NULL
;
6553 struct cfg80211_registered_device
*rdev
;
6554 int err
, reg_idx
, start
= cb
->args
[2];
6558 if (cfg80211_regdomain
&& start
== 0) {
6559 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6561 rtnl_dereference(cfg80211_regdomain
));
6566 /* the global regdom is idx 0 */
6568 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
6569 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
6573 if (++reg_idx
<= start
)
6576 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6577 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
6584 cb
->args
[2] = reg_idx
;
6591 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
6592 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
6593 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
6594 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
6595 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
6596 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
6597 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
6598 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
6599 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
6602 static int parse_reg_rule(struct nlattr
*tb
[],
6603 struct ieee80211_reg_rule
*reg_rule
)
6605 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
6606 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
6608 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
6610 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
6612 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
6614 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
6616 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
6619 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
6621 freq_range
->start_freq_khz
=
6622 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
6623 freq_range
->end_freq_khz
=
6624 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
6625 freq_range
->max_bandwidth_khz
=
6626 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
6628 power_rule
->max_eirp
=
6629 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
6631 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
6632 power_rule
->max_antenna_gain
=
6633 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
6635 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
6636 reg_rule
->dfs_cac_ms
=
6637 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
6642 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
6644 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
6645 struct nlattr
*nl_reg_rule
;
6647 int rem_reg_rules
, r
;
6648 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
6649 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
6650 struct ieee80211_regdomain
*rd
;
6652 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
6655 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
6658 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
6660 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
6661 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
6663 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6666 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
6670 if (!reg_is_valid_request(alpha2
))
6673 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
6674 num_rules
* sizeof(struct ieee80211_reg_rule
);
6676 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
6680 rd
->n_reg_rules
= num_rules
;
6681 rd
->alpha2
[0] = alpha2
[0];
6682 rd
->alpha2
[1] = alpha2
[1];
6685 * Disable DFS master mode if the DFS region was
6686 * not supported or known on this kernel.
6688 if (reg_supported_dfs_region(dfs_region
))
6689 rd
->dfs_region
= dfs_region
;
6691 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6693 r
= nla_parse_nested(tb
, NL80211_REG_RULE_ATTR_MAX
,
6694 nl_reg_rule
, reg_rule_policy
,
6698 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
6704 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
6710 /* set_regdom takes ownership of rd */
6711 return set_regdom(rd
, REGD_SOURCE_CRDA
);
6716 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
6718 static int validate_scan_freqs(struct nlattr
*freqs
)
6720 struct nlattr
*attr1
, *attr2
;
6721 int n_channels
= 0, tmp1
, tmp2
;
6723 nla_for_each_nested(attr1
, freqs
, tmp1
)
6724 if (nla_len(attr1
) != sizeof(u32
))
6727 nla_for_each_nested(attr1
, freqs
, tmp1
) {
6730 * Some hardware has a limited channel list for
6731 * scanning, and it is pretty much nonsensical
6732 * to scan for a channel twice, so disallow that
6733 * and don't require drivers to check that the
6734 * channel list they get isn't longer than what
6735 * they can scan, as long as they can scan all
6736 * the channels they registered at once.
6738 nla_for_each_nested(attr2
, freqs
, tmp2
)
6739 if (attr1
!= attr2
&&
6740 nla_get_u32(attr1
) == nla_get_u32(attr2
))
6747 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
6749 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
6752 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
6753 struct cfg80211_bss_selection
*bss_select
)
6755 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
6756 struct nlattr
*nest
;
6761 /* only process one nested attribute */
6762 nest
= nla_data(nla
);
6763 if (!nla_ok(nest
, nla_len(nest
)))
6766 err
= nla_parse_nested(attr
, NL80211_BSS_SELECT_ATTR_MAX
, nest
,
6767 nl80211_bss_select_policy
, NULL
);
6771 /* only one attribute may be given */
6772 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
6780 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
6782 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
6783 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
6785 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
6786 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
6787 bss_select
->param
.band_pref
=
6788 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
6789 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
6793 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
6794 struct nl80211_bss_select_rssi_adjust
*adj_param
;
6796 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
6797 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
6798 bss_select
->param
.adjust
.band
= adj_param
->band
;
6799 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
6800 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
6804 /* user-space did not provide behaviour attribute */
6805 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
6808 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
6814 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
6815 u8
*mac_addr
, u8
*mac_addr_mask
)
6819 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
6820 eth_zero_addr(mac_addr
);
6821 eth_zero_addr(mac_addr_mask
);
6823 mac_addr_mask
[0] = 0x3;
6828 /* need both or none */
6829 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
6832 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
6833 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
6835 /* don't allow or configure an mcast address */
6836 if (!is_multicast_ether_addr(mac_addr_mask
) ||
6837 is_multicast_ether_addr(mac_addr
))
6841 * allow users to pass a MAC address that has bits set outside
6842 * of the mask, but don't bother drivers with having to deal
6845 for (i
= 0; i
< ETH_ALEN
; i
++)
6846 mac_addr
[i
] &= mac_addr_mask
[i
];
6851 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev
*wdev
)
6853 ASSERT_WDEV_LOCK(wdev
);
6855 if (!cfg80211_beaconing_iface_active(wdev
))
6858 if (!(wdev
->chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
))
6861 return regulatory_pre_cac_allowed(wdev
->wiphy
);
6865 nl80211_check_scan_flags(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6866 void *request
, struct nlattr
**attrs
,
6869 u8
*mac_addr
, *mac_addr_mask
;
6871 enum nl80211_feature_flags randomness_flag
;
6873 if (!attrs
[NL80211_ATTR_SCAN_FLAGS
])
6876 if (is_sched_scan
) {
6877 struct cfg80211_sched_scan_request
*req
= request
;
6879 randomness_flag
= wdev
?
6880 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
:
6881 NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
6882 flags
= &req
->flags
;
6883 mac_addr
= req
->mac_addr
;
6884 mac_addr_mask
= req
->mac_addr_mask
;
6886 struct cfg80211_scan_request
*req
= request
;
6888 randomness_flag
= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
6889 flags
= &req
->flags
;
6890 mac_addr
= req
->mac_addr
;
6891 mac_addr_mask
= req
->mac_addr_mask
;
6894 *flags
= nla_get_u32(attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6896 if (((*flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6897 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
6898 ((*flags
& NL80211_SCAN_FLAG_LOW_SPAN
) &&
6899 !wiphy_ext_feature_isset(wiphy
,
6900 NL80211_EXT_FEATURE_LOW_SPAN_SCAN
)) ||
6901 ((*flags
& NL80211_SCAN_FLAG_LOW_POWER
) &&
6902 !wiphy_ext_feature_isset(wiphy
,
6903 NL80211_EXT_FEATURE_LOW_POWER_SCAN
)) ||
6904 ((*flags
& NL80211_SCAN_FLAG_HIGH_ACCURACY
) &&
6905 !wiphy_ext_feature_isset(wiphy
,
6906 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN
)))
6909 if (*flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6912 if (!(wiphy
->features
& randomness_flag
) ||
6913 (wdev
&& wdev
->current_bss
))
6916 err
= nl80211_parse_random_mac(attrs
, mac_addr
, mac_addr_mask
);
6921 if ((*flags
& NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME
) &&
6922 !wiphy_ext_feature_isset(wiphy
,
6923 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME
))
6926 if ((*flags
& NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP
) &&
6927 !wiphy_ext_feature_isset(wiphy
,
6928 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP
))
6931 if ((*flags
& NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
) &&
6932 !wiphy_ext_feature_isset(wiphy
,
6933 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
))
6936 if ((*flags
& NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE
) &&
6937 !wiphy_ext_feature_isset(wiphy
,
6938 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE
))
6944 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6946 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6947 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6948 struct cfg80211_scan_request
*request
;
6949 struct nlattr
*attr
;
6950 struct wiphy
*wiphy
;
6951 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
6954 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6957 wiphy
= &rdev
->wiphy
;
6959 if (wdev
->iftype
== NL80211_IFTYPE_NAN
)
6962 if (!rdev
->ops
->scan
)
6965 if (rdev
->scan_req
|| rdev
->scan_msg
) {
6970 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6971 n_channels
= validate_scan_freqs(
6972 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6978 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6981 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
6982 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
6985 if (n_ssids
> wiphy
->max_scan_ssids
) {
6990 if (info
->attrs
[NL80211_ATTR_IE
])
6991 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6995 if (ie_len
> wiphy
->max_scan_ie_len
) {
7000 request
= kzalloc(sizeof(*request
)
7001 + sizeof(*request
->ssids
) * n_ssids
7002 + sizeof(*request
->channels
) * n_channels
7003 + ie_len
, GFP_KERNEL
);
7010 request
->ssids
= (void *)&request
->channels
[n_channels
];
7011 request
->n_ssids
= n_ssids
;
7014 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
7016 request
->ie
= (void *)(request
->channels
+ n_channels
);
7020 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7021 /* user specified, bail out if channel not found */
7022 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
7023 struct ieee80211_channel
*chan
;
7025 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
7032 /* ignore disabled channels */
7033 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7036 request
->channels
[i
] = chan
;
7040 enum nl80211_band band
;
7043 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7046 if (!wiphy
->bands
[band
])
7048 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
7049 struct ieee80211_channel
*chan
;
7051 chan
= &wiphy
->bands
[band
]->channels
[j
];
7053 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7056 request
->channels
[i
] = chan
;
7067 request
->n_channels
= i
;
7070 if (!cfg80211_off_channel_oper_allowed(wdev
)) {
7071 struct ieee80211_channel
*chan
;
7073 if (request
->n_channels
!= 1) {
7079 chan
= request
->channels
[0];
7080 if (chan
->center_freq
!= wdev
->chandef
.chan
->center_freq
) {
7090 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
7091 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7095 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7096 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
7101 if (info
->attrs
[NL80211_ATTR_IE
]) {
7102 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7103 memcpy((void *)request
->ie
,
7104 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
7108 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
7109 if (wiphy
->bands
[i
])
7111 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
7113 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
7114 nla_for_each_nested(attr
,
7115 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
7117 enum nl80211_band band
= nla_type(attr
);
7119 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
7124 if (!wiphy
->bands
[band
])
7127 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
7130 &request
->rates
[band
]);
7136 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
7137 if (!wiphy_ext_feature_isset(wiphy
,
7138 NL80211_EXT_FEATURE_SET_SCAN_DWELL
)) {
7144 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
7145 request
->duration_mandatory
=
7146 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
7149 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, info
->attrs
,
7155 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7157 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7158 * BSSID to scan for. This was problematic because that same attribute
7159 * was already used for another purpose (local random MAC address). The
7160 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7161 * compatibility with older userspace components, also use the
7162 * NL80211_ATTR_MAC value here if it can be determined to be used for
7163 * the specific BSSID use case instead of the random MAC address
7164 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7166 if (info
->attrs
[NL80211_ATTR_BSSID
])
7167 memcpy(request
->bssid
,
7168 nla_data(info
->attrs
[NL80211_ATTR_BSSID
]), ETH_ALEN
);
7169 else if (!(request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) &&
7170 info
->attrs
[NL80211_ATTR_MAC
])
7171 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
7174 eth_broadcast_addr(request
->bssid
);
7176 request
->wdev
= wdev
;
7177 request
->wiphy
= &rdev
->wiphy
;
7178 request
->scan_start
= jiffies
;
7180 rdev
->scan_req
= request
;
7181 err
= rdev_scan(rdev
, request
);
7184 nl80211_send_scan_start(rdev
, wdev
);
7186 dev_hold(wdev
->netdev
);
7189 rdev
->scan_req
= NULL
;
7197 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
7199 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7200 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7202 if (!rdev
->ops
->abort_scan
)
7208 if (!rdev
->scan_req
)
7211 rdev_abort_scan(rdev
, wdev
);
7216 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
7217 struct cfg80211_sched_scan_request
*request
,
7218 struct nlattr
**attrs
)
7220 int tmp
, err
, i
= 0;
7221 struct nlattr
*attr
;
7223 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
7227 * If scan plans are not specified,
7228 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
7229 * case one scan plan will be set with the specified scan
7230 * interval and infinite number of iterations.
7232 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
7236 request
->scan_plans
[0].interval
=
7237 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
7238 if (!request
->scan_plans
[0].interval
)
7241 if (request
->scan_plans
[0].interval
>
7242 wiphy
->max_sched_scan_plan_interval
)
7243 request
->scan_plans
[0].interval
=
7244 wiphy
->max_sched_scan_plan_interval
;
7249 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
7250 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
7252 if (WARN_ON(i
>= n_plans
))
7255 err
= nla_parse_nested(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
7256 attr
, nl80211_plan_policy
, NULL
);
7260 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
7263 request
->scan_plans
[i
].interval
=
7264 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
7265 if (!request
->scan_plans
[i
].interval
||
7266 request
->scan_plans
[i
].interval
>
7267 wiphy
->max_sched_scan_plan_interval
)
7270 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
7271 request
->scan_plans
[i
].iterations
=
7272 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
7273 if (!request
->scan_plans
[i
].iterations
||
7274 (request
->scan_plans
[i
].iterations
>
7275 wiphy
->max_sched_scan_plan_iterations
))
7277 } else if (i
< n_plans
- 1) {
7279 * All scan plans but the last one must specify
7280 * a finite number of iterations
7289 * The last scan plan must not specify the number of
7290 * iterations, it is supposed to run infinitely
7292 if (request
->scan_plans
[n_plans
- 1].iterations
)
7298 static struct cfg80211_sched_scan_request
*
7299 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
7300 struct nlattr
**attrs
, int max_match_sets
)
7302 struct cfg80211_sched_scan_request
*request
;
7303 struct nlattr
*attr
;
7304 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
7305 enum nl80211_band band
;
7307 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
7308 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
7310 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
7311 return ERR_PTR(-EINVAL
);
7313 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7314 n_channels
= validate_scan_freqs(
7315 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
7317 return ERR_PTR(-EINVAL
);
7319 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
7322 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
7323 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7327 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
7328 return ERR_PTR(-EINVAL
);
7331 * First, count the number of 'real' matchsets. Due to an issue with
7332 * the old implementation, matchsets containing only the RSSI attribute
7333 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7334 * RSSI for all matchsets, rather than their own matchset for reporting
7335 * all APs with a strong RSSI. This is needed to be compatible with
7336 * older userspace that treated a matchset with only the RSSI as the
7337 * global RSSI for all other matchsets - if there are other matchsets.
7339 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7340 nla_for_each_nested(attr
,
7341 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7343 struct nlattr
*rssi
;
7345 err
= nla_parse_nested(tb
,
7346 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7347 attr
, nl80211_match_policy
,
7350 return ERR_PTR(err
);
7352 /* SSID and BSSID are mutually exclusive */
7353 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] &&
7354 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
])
7355 return ERR_PTR(-EINVAL
);
7357 /* add other standalone attributes here */
7358 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] ||
7359 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
]) {
7363 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7365 default_match_rssi
= nla_get_s32(rssi
);
7369 /* However, if there's no other matchset, add the RSSI one */
7370 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
7373 if (n_match_sets
> max_match_sets
)
7374 return ERR_PTR(-EINVAL
);
7376 if (attrs
[NL80211_ATTR_IE
])
7377 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
7381 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
7382 return ERR_PTR(-EINVAL
);
7384 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
7386 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7387 * each scan plan already specifies its own interval
7389 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7390 return ERR_PTR(-EINVAL
);
7392 nla_for_each_nested(attr
,
7393 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
7397 * The scan interval attribute is kept for backward
7398 * compatibility. If no scan plans are specified and sched scan
7399 * interval is specified, one scan plan will be set with this
7400 * scan interval and infinite number of iterations.
7402 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7403 return ERR_PTR(-EINVAL
);
7408 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
7409 return ERR_PTR(-EINVAL
);
7411 if (!wiphy_ext_feature_isset(
7412 wiphy
, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI
) &&
7413 (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] ||
7414 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]))
7415 return ERR_PTR(-EINVAL
);
7417 request
= kzalloc(sizeof(*request
)
7418 + sizeof(*request
->ssids
) * n_ssids
7419 + sizeof(*request
->match_sets
) * n_match_sets
7420 + sizeof(*request
->scan_plans
) * n_plans
7421 + sizeof(*request
->channels
) * n_channels
7422 + ie_len
, GFP_KERNEL
);
7424 return ERR_PTR(-ENOMEM
);
7427 request
->ssids
= (void *)&request
->channels
[n_channels
];
7428 request
->n_ssids
= n_ssids
;
7431 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
7433 request
->ie
= (void *)(request
->channels
+ n_channels
);
7438 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
7440 request
->match_sets
=
7441 (void *)(request
->ssids
+ n_ssids
);
7443 request
->match_sets
=
7444 (void *)(request
->channels
+ n_channels
);
7446 request
->n_match_sets
= n_match_sets
;
7449 request
->scan_plans
= (void *)(request
->match_sets
+
7451 else if (request
->ie
)
7452 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
7454 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
7456 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
7458 request
->n_scan_plans
= n_plans
;
7461 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7462 /* user specified, bail out if channel not found */
7463 nla_for_each_nested(attr
,
7464 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
7466 struct ieee80211_channel
*chan
;
7468 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
7475 /* ignore disabled channels */
7476 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7479 request
->channels
[i
] = chan
;
7484 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7487 if (!wiphy
->bands
[band
])
7489 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
7490 struct ieee80211_channel
*chan
;
7492 chan
= &wiphy
->bands
[band
]->channels
[j
];
7494 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7497 request
->channels
[i
] = chan
;
7508 request
->n_channels
= i
;
7512 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7514 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7518 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7519 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
7526 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7527 nla_for_each_nested(attr
,
7528 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7530 struct nlattr
*ssid
, *bssid
, *rssi
;
7532 err
= nla_parse_nested(tb
,
7533 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7534 attr
, nl80211_match_policy
,
7538 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
7539 bssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
];
7540 if (ssid
|| bssid
) {
7541 if (WARN_ON(i
>= n_match_sets
)) {
7542 /* this indicates a programming error,
7543 * the loop above should have verified
7551 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
7555 memcpy(request
->match_sets
[i
].ssid
.ssid
,
7556 nla_data(ssid
), nla_len(ssid
));
7557 request
->match_sets
[i
].ssid
.ssid_len
=
7561 if (nla_len(bssid
) != ETH_ALEN
) {
7565 memcpy(request
->match_sets
[i
].bssid
,
7566 nla_data(bssid
), ETH_ALEN
);
7569 /* special attribute - old implementation w/a */
7570 request
->match_sets
[i
].rssi_thold
=
7572 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7574 request
->match_sets
[i
].rssi_thold
=
7580 /* there was no other matchset, so the RSSI one is alone */
7581 if (i
== 0 && n_match_sets
)
7582 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
7584 request
->min_rssi_thold
= INT_MAX
;
7585 for (i
= 0; i
< n_match_sets
; i
++)
7586 request
->min_rssi_thold
=
7587 min(request
->match_sets
[i
].rssi_thold
,
7588 request
->min_rssi_thold
);
7590 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
7594 request
->ie_len
= ie_len
;
7595 memcpy((void *)request
->ie
,
7596 nla_data(attrs
[NL80211_ATTR_IE
]),
7600 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, attrs
, true);
7604 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
7606 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
7608 if (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]) {
7609 request
->relative_rssi
= nla_get_s8(
7610 attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]);
7611 request
->relative_rssi_set
= true;
7614 if (request
->relative_rssi_set
&&
7615 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]) {
7616 struct nl80211_bss_select_rssi_adjust
*rssi_adjust
;
7618 rssi_adjust
= nla_data(
7619 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]);
7620 request
->rssi_adjust
.band
= rssi_adjust
->band
;
7621 request
->rssi_adjust
.delta
= rssi_adjust
->delta
;
7622 if (!is_band_valid(wiphy
, request
->rssi_adjust
.band
)) {
7628 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
7632 request
->scan_start
= jiffies
;
7638 return ERR_PTR(err
);
7641 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
7642 struct genl_info
*info
)
7644 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7645 struct net_device
*dev
= info
->user_ptr
[1];
7646 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7647 struct cfg80211_sched_scan_request
*sched_scan_req
;
7651 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_start
)
7654 want_multi
= info
->attrs
[NL80211_ATTR_SCHED_SCAN_MULTI
];
7655 err
= cfg80211_sched_scan_req_possible(rdev
, want_multi
);
7659 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
7661 rdev
->wiphy
.max_match_sets
);
7663 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
7667 /* leave request id zero for legacy request
7668 * or if driver does not support multi-scheduled scan
7670 if (want_multi
&& rdev
->wiphy
.max_sched_scan_reqs
> 1) {
7671 while (!sched_scan_req
->reqid
)
7672 sched_scan_req
->reqid
= rdev
->wiphy
.cookie_counter
++;
7675 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
7679 sched_scan_req
->dev
= dev
;
7680 sched_scan_req
->wiphy
= &rdev
->wiphy
;
7682 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
7683 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
7685 cfg80211_add_sched_scan_req(rdev
, sched_scan_req
);
7687 nl80211_send_sched_scan(sched_scan_req
, NL80211_CMD_START_SCHED_SCAN
);
7691 kfree(sched_scan_req
);
7696 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
7697 struct genl_info
*info
)
7699 struct cfg80211_sched_scan_request
*req
;
7700 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7703 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_stop
)
7706 if (info
->attrs
[NL80211_ATTR_COOKIE
]) {
7707 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7708 return __cfg80211_stop_sched_scan(rdev
, cookie
, false);
7711 req
= list_first_or_null_rcu(&rdev
->sched_scan_req_list
,
7712 struct cfg80211_sched_scan_request
,
7714 if (!req
|| req
->reqid
||
7715 (req
->owner_nlportid
&&
7716 req
->owner_nlportid
!= info
->snd_portid
))
7719 return cfg80211_stop_sched_scan_req(rdev
, req
, false);
7722 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
7723 struct genl_info
*info
)
7725 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7726 struct net_device
*dev
= info
->user_ptr
[1];
7727 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7728 struct wiphy
*wiphy
= wdev
->wiphy
;
7729 struct cfg80211_chan_def chandef
;
7730 enum nl80211_dfs_regions dfs_region
;
7731 unsigned int cac_time_ms
;
7734 dfs_region
= reg_get_dfs_region(wiphy
);
7735 if (dfs_region
== NL80211_DFS_UNSET
)
7738 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7742 if (netif_carrier_ok(dev
))
7745 if (wdev
->cac_started
)
7748 err
= cfg80211_chandef_dfs_required(wiphy
, &chandef
, wdev
->iftype
);
7755 if (!cfg80211_chandef_dfs_usable(wiphy
, &chandef
))
7758 /* CAC start is offloaded to HW and can't be started manually */
7759 if (wiphy_ext_feature_isset(wiphy
, NL80211_EXT_FEATURE_DFS_OFFLOAD
))
7762 if (!rdev
->ops
->start_radar_detection
)
7765 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
7766 if (WARN_ON(!cac_time_ms
))
7767 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
7769 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
7771 wdev
->chandef
= chandef
;
7772 wdev
->cac_started
= true;
7773 wdev
->cac_start_time
= jiffies
;
7774 wdev
->cac_time_ms
= cac_time_ms
;
7779 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
7781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7782 struct net_device
*dev
= info
->user_ptr
[1];
7783 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7784 struct cfg80211_csa_settings params
;
7785 /* csa_attrs is defined static to avoid waste of stack size - this
7786 * function is called under RTNL lock, so this should not be a problem.
7788 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
7790 bool need_new_beacon
= false;
7791 bool need_handle_dfs_flag
= true;
7795 if (!rdev
->ops
->channel_switch
||
7796 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
7799 switch (dev
->ieee80211_ptr
->iftype
) {
7800 case NL80211_IFTYPE_AP
:
7801 case NL80211_IFTYPE_P2P_GO
:
7802 need_new_beacon
= true;
7803 /* For all modes except AP the handle_dfs flag needs to be
7804 * supplied to tell the kernel that userspace will handle radar
7805 * events when they happen. Otherwise a switch to a channel
7806 * requiring DFS will be rejected.
7808 need_handle_dfs_flag
= false;
7810 /* useless if AP is not running */
7811 if (!wdev
->beacon_interval
)
7814 case NL80211_IFTYPE_ADHOC
:
7815 if (!wdev
->ssid_len
)
7818 case NL80211_IFTYPE_MESH_POINT
:
7819 if (!wdev
->mesh_id_len
)
7826 memset(¶ms
, 0, sizeof(params
));
7828 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7829 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
7832 /* only important for AP, IBSS and mesh create IEs internally */
7833 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
7836 /* Even though the attribute is u32, the specification says
7837 * u8, so let's make sure we don't overflow.
7839 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
7843 params
.count
= cs_count
;
7845 if (!need_new_beacon
)
7848 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
7852 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
7853 info
->attrs
[NL80211_ATTR_CSA_IES
],
7854 nl80211_policy
, info
->extack
);
7858 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
7862 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
7865 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7866 if (!len
|| (len
% sizeof(u16
)))
7869 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
7870 if (rdev
->wiphy
.max_num_csa_counters
&&
7871 (params
.n_counter_offsets_beacon
>
7872 rdev
->wiphy
.max_num_csa_counters
))
7875 params
.counter_offsets_beacon
=
7876 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7878 /* sanity checks - counters should fit and be the same */
7879 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
7880 u16 offset
= params
.counter_offsets_beacon
[i
];
7882 if (offset
>= params
.beacon_csa
.tail_len
)
7885 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
7889 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
7890 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7891 if (!len
|| (len
% sizeof(u16
)))
7894 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
7895 if (rdev
->wiphy
.max_num_csa_counters
&&
7896 (params
.n_counter_offsets_presp
>
7897 rdev
->wiphy
.max_num_csa_counters
))
7900 params
.counter_offsets_presp
=
7901 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7903 /* sanity checks - counters should fit and be the same */
7904 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
7905 u16 offset
= params
.counter_offsets_presp
[i
];
7907 if (offset
>= params
.beacon_csa
.probe_resp_len
)
7910 if (params
.beacon_csa
.probe_resp
[offset
] !=
7917 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
7921 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
7925 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
7932 params
.radar_required
= true;
7933 if (need_handle_dfs_flag
&&
7934 !nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
])) {
7939 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
7940 params
.block_tx
= true;
7943 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
7949 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
7951 struct cfg80211_registered_device
*rdev
,
7952 struct wireless_dev
*wdev
,
7953 struct cfg80211_internal_bss
*intbss
)
7955 struct cfg80211_bss
*res
= &intbss
->pub
;
7956 const struct cfg80211_bss_ies
*ies
;
7960 ASSERT_WDEV_LOCK(wdev
);
7962 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
7963 NL80211_CMD_NEW_SCAN_RESULTS
);
7967 genl_dump_check_consistent(cb
, hdr
);
7969 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
7970 goto nla_put_failure
;
7972 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
7973 goto nla_put_failure
;
7974 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
7976 goto nla_put_failure
;
7978 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
7980 goto nla_put_failure
;
7981 if ((!is_zero_ether_addr(res
->bssid
) &&
7982 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
7983 goto nla_put_failure
;
7986 /* indicate whether we have probe response data or not */
7987 if (rcu_access_pointer(res
->proberesp_ies
) &&
7988 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
7989 goto fail_unlock_rcu
;
7991 /* this pointer prefers to be pointed to probe response data
7992 * but is always valid
7994 ies
= rcu_dereference(res
->ies
);
7996 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
7998 goto fail_unlock_rcu
;
7999 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
8000 ies
->len
, ies
->data
))
8001 goto fail_unlock_rcu
;
8004 /* and this pointer is always (unless driver didn't know) beacon data */
8005 ies
= rcu_dereference(res
->beacon_ies
);
8006 if (ies
&& ies
->from_beacon
) {
8007 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
8009 goto fail_unlock_rcu
;
8010 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
8011 ies
->len
, ies
->data
))
8012 goto fail_unlock_rcu
;
8016 if (res
->beacon_interval
&&
8017 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
8018 goto nla_put_failure
;
8019 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
8020 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
8021 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
8022 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
8023 jiffies_to_msecs(jiffies
- intbss
->ts
)))
8024 goto nla_put_failure
;
8026 if (intbss
->parent_tsf
&&
8027 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
8028 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
8029 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
8030 intbss
->parent_bssid
)))
8031 goto nla_put_failure
;
8033 if (intbss
->ts_boottime
&&
8034 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
8035 intbss
->ts_boottime
, NL80211_BSS_PAD
))
8036 goto nla_put_failure
;
8038 if (!nl80211_put_signal(msg
, intbss
->pub
.chains
,
8039 intbss
->pub
.chain_signal
,
8040 NL80211_BSS_CHAIN_SIGNAL
))
8041 goto nla_put_failure
;
8043 switch (rdev
->wiphy
.signal_type
) {
8044 case CFG80211_SIGNAL_TYPE_MBM
:
8045 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
8046 goto nla_put_failure
;
8048 case CFG80211_SIGNAL_TYPE_UNSPEC
:
8049 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
8050 goto nla_put_failure
;
8056 switch (wdev
->iftype
) {
8057 case NL80211_IFTYPE_P2P_CLIENT
:
8058 case NL80211_IFTYPE_STATION
:
8059 if (intbss
== wdev
->current_bss
&&
8060 nla_put_u32(msg
, NL80211_BSS_STATUS
,
8061 NL80211_BSS_STATUS_ASSOCIATED
))
8062 goto nla_put_failure
;
8064 case NL80211_IFTYPE_ADHOC
:
8065 if (intbss
== wdev
->current_bss
&&
8066 nla_put_u32(msg
, NL80211_BSS_STATUS
,
8067 NL80211_BSS_STATUS_IBSS_JOINED
))
8068 goto nla_put_failure
;
8074 nla_nest_end(msg
, bss
);
8076 genlmsg_end(msg
, hdr
);
8082 genlmsg_cancel(msg
, hdr
);
8086 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
8088 struct cfg80211_registered_device
*rdev
;
8089 struct cfg80211_internal_bss
*scan
;
8090 struct wireless_dev
*wdev
;
8091 int start
= cb
->args
[2], idx
= 0;
8095 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
8102 spin_lock_bh(&rdev
->bss_lock
);
8105 * dump_scan will be called multiple times to break up the scan results
8106 * into multiple messages. It is unlikely that any more bss-es will be
8107 * expired after the first call, so only call only call this on the
8108 * first dump_scan invocation.
8111 cfg80211_bss_expire(rdev
);
8113 cb
->seq
= rdev
->bss_generation
;
8115 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
8118 if (nl80211_send_bss(skb
, cb
,
8119 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8120 rdev
, wdev
, scan
) < 0) {
8126 spin_unlock_bh(&rdev
->bss_lock
);
8135 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
8136 int flags
, struct net_device
*dev
,
8137 bool allow_radio_stats
,
8138 struct survey_info
*survey
)
8141 struct nlattr
*infoattr
;
8143 /* skip radio stats if userspace didn't request them */
8144 if (!survey
->channel
&& !allow_radio_stats
)
8147 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
8148 NL80211_CMD_NEW_SURVEY_RESULTS
);
8152 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
8153 goto nla_put_failure
;
8155 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
8157 goto nla_put_failure
;
8159 if (survey
->channel
&&
8160 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
8161 survey
->channel
->center_freq
))
8162 goto nla_put_failure
;
8164 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
8165 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
8166 goto nla_put_failure
;
8167 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
8168 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
8169 goto nla_put_failure
;
8170 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
8171 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
8172 survey
->time
, NL80211_SURVEY_INFO_PAD
))
8173 goto nla_put_failure
;
8174 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
8175 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
8176 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
8177 goto nla_put_failure
;
8178 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
8179 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
8180 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
8181 goto nla_put_failure
;
8182 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
8183 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
8184 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
8185 goto nla_put_failure
;
8186 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
8187 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
8188 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
8189 goto nla_put_failure
;
8190 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
8191 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
8192 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
8193 goto nla_put_failure
;
8195 nla_nest_end(msg
, infoattr
);
8197 genlmsg_end(msg
, hdr
);
8201 genlmsg_cancel(msg
, hdr
);
8205 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
8207 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
8208 struct survey_info survey
;
8209 struct cfg80211_registered_device
*rdev
;
8210 struct wireless_dev
*wdev
;
8211 int survey_idx
= cb
->args
[2];
8216 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
8220 /* prepare_wdev_dump parsed the attributes */
8221 radio_stats
= attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
8223 if (!wdev
->netdev
) {
8228 if (!rdev
->ops
->dump_survey
) {
8234 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
8240 /* don't send disabled channels, but do send non-channel data */
8241 if (survey
.channel
&&
8242 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
8247 if (nl80211_send_survey(skb
,
8248 NETLINK_CB(cb
->skb
).portid
,
8249 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8250 wdev
->netdev
, radio_stats
, &survey
) < 0)
8256 cb
->args
[2] = survey_idx
;
8263 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
8265 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
8266 NL80211_WPA_VERSION_2
));
8269 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8271 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8272 struct net_device
*dev
= info
->user_ptr
[1];
8273 struct ieee80211_channel
*chan
;
8274 const u8
*bssid
, *ssid
, *ie
= NULL
, *auth_data
= NULL
;
8275 int err
, ssid_len
, ie_len
= 0, auth_data_len
= 0;
8276 enum nl80211_auth_type auth_type
;
8277 struct key_parse key
;
8278 bool local_state_change
;
8280 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8283 if (!info
->attrs
[NL80211_ATTR_MAC
])
8286 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
8289 if (!info
->attrs
[NL80211_ATTR_SSID
])
8292 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8295 err
= nl80211_parse_key(info
, &key
);
8300 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
8302 if (!key
.p
.key
|| !key
.p
.key_len
)
8304 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
8305 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
8306 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
8307 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
8320 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
8321 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
8330 if (!rdev
->ops
->auth
)
8333 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8334 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8337 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8338 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8339 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8343 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8344 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8346 if (info
->attrs
[NL80211_ATTR_IE
]) {
8347 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8348 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8351 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8352 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
8355 if ((auth_type
== NL80211_AUTHTYPE_SAE
||
8356 auth_type
== NL80211_AUTHTYPE_FILS_SK
||
8357 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
8358 auth_type
== NL80211_AUTHTYPE_FILS_PK
) &&
8359 !info
->attrs
[NL80211_ATTR_AUTH_DATA
])
8362 if (info
->attrs
[NL80211_ATTR_AUTH_DATA
]) {
8363 if (auth_type
!= NL80211_AUTHTYPE_SAE
&&
8364 auth_type
!= NL80211_AUTHTYPE_FILS_SK
&&
8365 auth_type
!= NL80211_AUTHTYPE_FILS_SK_PFS
&&
8366 auth_type
!= NL80211_AUTHTYPE_FILS_PK
)
8368 auth_data
= nla_data(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8369 auth_data_len
= nla_len(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8370 /* need to include at least Auth Transaction and Status Code */
8371 if (auth_data_len
< 4)
8375 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8378 * Since we no longer track auth state, ignore
8379 * requests to only change local state.
8381 if (local_state_change
)
8384 wdev_lock(dev
->ieee80211_ptr
);
8385 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
8386 ssid
, ssid_len
, ie
, ie_len
,
8387 key
.p
.key
, key
.p
.key_len
, key
.idx
,
8388 auth_data
, auth_data_len
);
8389 wdev_unlock(dev
->ieee80211_ptr
);
8393 static int validate_pae_over_nl80211(struct cfg80211_registered_device
*rdev
,
8394 struct genl_info
*info
)
8396 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
8397 GENL_SET_ERR_MSG(info
, "SOCKET_OWNER not set");
8401 if (!rdev
->ops
->tx_control_port
||
8402 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8403 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
8409 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
8410 struct genl_info
*info
,
8411 struct cfg80211_crypto_settings
*settings
,
8414 memset(settings
, 0, sizeof(*settings
));
8416 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
8418 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
8421 proto
= nla_get_u16(
8422 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
8423 settings
->control_port_ethertype
= cpu_to_be16(proto
);
8424 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
8427 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
8428 settings
->control_port_no_encrypt
= true;
8430 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
8432 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
8433 int r
= validate_pae_over_nl80211(rdev
, info
);
8438 settings
->control_port_over_nl80211
= true;
8441 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
8445 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8446 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8447 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
8449 if (len
% sizeof(u32
))
8452 if (settings
->n_ciphers_pairwise
> cipher_limit
)
8455 memcpy(settings
->ciphers_pairwise
, data
, len
);
8457 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
8458 if (!cfg80211_supported_cipher_suite(
8460 settings
->ciphers_pairwise
[i
]))
8464 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
8465 settings
->cipher_group
=
8466 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
8467 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
8468 settings
->cipher_group
))
8472 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
8473 settings
->wpa_versions
=
8474 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
8475 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
8479 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
8483 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8484 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8485 settings
->n_akm_suites
= len
/ sizeof(u32
);
8487 if (len
% sizeof(u32
))
8490 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
8493 memcpy(settings
->akm_suites
, data
, len
);
8496 if (info
->attrs
[NL80211_ATTR_PMK
]) {
8497 if (nla_len(info
->attrs
[NL80211_ATTR_PMK
]) != WLAN_PMK_LEN
)
8499 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8500 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK
))
8502 settings
->psk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
8508 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
8510 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8511 struct net_device
*dev
= info
->user_ptr
[1];
8512 struct ieee80211_channel
*chan
;
8513 struct cfg80211_assoc_request req
= {};
8514 const u8
*bssid
, *ssid
;
8515 int err
, ssid_len
= 0;
8517 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
8518 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
8521 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8524 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
8525 !info
->attrs
[NL80211_ATTR_SSID
] ||
8526 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8529 if (!rdev
->ops
->assoc
)
8532 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8533 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8536 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8538 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8539 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8543 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8544 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8546 if (info
->attrs
[NL80211_ATTR_IE
]) {
8547 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8548 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8551 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
8552 enum nl80211_mfp mfp
=
8553 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
8554 if (mfp
== NL80211_MFP_REQUIRED
)
8556 else if (mfp
!= NL80211_MFP_NO
)
8560 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
8561 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
8563 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
8564 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
8566 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8567 memcpy(&req
.ht_capa_mask
,
8568 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8569 sizeof(req
.ht_capa_mask
));
8571 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8572 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8574 memcpy(&req
.ht_capa
,
8575 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8576 sizeof(req
.ht_capa
));
8579 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
8580 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
8582 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8583 memcpy(&req
.vht_capa_mask
,
8584 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
8585 sizeof(req
.vht_capa_mask
));
8587 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
8588 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8590 memcpy(&req
.vht_capa
,
8591 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
8592 sizeof(req
.vht_capa
));
8595 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
8596 if (!((rdev
->wiphy
.features
&
8597 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
8598 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
8599 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8600 NL80211_EXT_FEATURE_RRM
))
8602 req
.flags
|= ASSOC_REQ_USE_RRM
;
8605 if (info
->attrs
[NL80211_ATTR_FILS_KEK
]) {
8606 req
.fils_kek
= nla_data(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8607 req
.fils_kek_len
= nla_len(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8608 if (!info
->attrs
[NL80211_ATTR_FILS_NONCES
])
8611 nla_data(info
->attrs
[NL80211_ATTR_FILS_NONCES
]);
8614 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
8616 wdev_lock(dev
->ieee80211_ptr
);
8618 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
8619 ssid
, ssid_len
, &req
);
8621 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
8622 dev
->ieee80211_ptr
->conn_owner_nlportid
=
8624 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
8628 wdev_unlock(dev
->ieee80211_ptr
);
8634 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8637 struct net_device
*dev
= info
->user_ptr
[1];
8638 const u8
*ie
= NULL
, *bssid
;
8639 int ie_len
= 0, err
;
8641 bool local_state_change
;
8643 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
8644 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
8647 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8650 if (!info
->attrs
[NL80211_ATTR_MAC
])
8653 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8656 if (!rdev
->ops
->deauth
)
8659 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8660 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8663 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8665 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8666 if (reason_code
== 0) {
8667 /* Reason Code 0 is reserved */
8671 if (info
->attrs
[NL80211_ATTR_IE
]) {
8672 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8673 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8676 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8678 wdev_lock(dev
->ieee80211_ptr
);
8679 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8680 local_state_change
);
8681 wdev_unlock(dev
->ieee80211_ptr
);
8685 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
8687 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8688 struct net_device
*dev
= info
->user_ptr
[1];
8689 const u8
*ie
= NULL
, *bssid
;
8690 int ie_len
= 0, err
;
8692 bool local_state_change
;
8694 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
8695 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
8698 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8701 if (!info
->attrs
[NL80211_ATTR_MAC
])
8704 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8707 if (!rdev
->ops
->disassoc
)
8710 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8711 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8714 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8716 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8717 if (reason_code
== 0) {
8718 /* Reason Code 0 is reserved */
8722 if (info
->attrs
[NL80211_ATTR_IE
]) {
8723 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8724 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8727 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8729 wdev_lock(dev
->ieee80211_ptr
);
8730 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8731 local_state_change
);
8732 wdev_unlock(dev
->ieee80211_ptr
);
8737 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
8738 int mcast_rate
[NUM_NL80211_BANDS
],
8741 struct wiphy
*wiphy
= &rdev
->wiphy
;
8745 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8746 struct ieee80211_supported_band
*sband
;
8748 sband
= wiphy
->bands
[band
];
8752 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
8753 if (sband
->bitrates
[i
].bitrate
== rateval
) {
8754 mcast_rate
[band
] = i
+ 1;
8764 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8766 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8767 struct net_device
*dev
= info
->user_ptr
[1];
8768 struct cfg80211_ibss_params ibss
;
8769 struct wiphy
*wiphy
;
8770 struct cfg80211_cached_keys
*connkeys
= NULL
;
8773 memset(&ibss
, 0, sizeof(ibss
));
8775 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8778 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8779 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8782 ibss
.beacon_interval
= 100;
8784 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
])
8785 ibss
.beacon_interval
=
8786 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8788 err
= cfg80211_validate_beacon_int(rdev
, NL80211_IFTYPE_ADHOC
,
8789 ibss
.beacon_interval
);
8793 if (!rdev
->ops
->join_ibss
)
8796 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8799 wiphy
= &rdev
->wiphy
;
8801 if (info
->attrs
[NL80211_ATTR_MAC
]) {
8802 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8804 if (!is_valid_ether_addr(ibss
.bssid
))
8807 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8808 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8810 if (info
->attrs
[NL80211_ATTR_IE
]) {
8811 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8812 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8815 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
8819 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
8820 NL80211_IFTYPE_ADHOC
))
8823 switch (ibss
.chandef
.width
) {
8824 case NL80211_CHAN_WIDTH_5
:
8825 case NL80211_CHAN_WIDTH_10
:
8826 case NL80211_CHAN_WIDTH_20_NOHT
:
8828 case NL80211_CHAN_WIDTH_20
:
8829 case NL80211_CHAN_WIDTH_40
:
8830 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8833 case NL80211_CHAN_WIDTH_80
:
8834 case NL80211_CHAN_WIDTH_80P80
:
8835 case NL80211_CHAN_WIDTH_160
:
8836 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8838 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8839 NL80211_EXT_FEATURE_VHT_IBSS
))
8846 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
8847 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
8849 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8851 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8853 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8854 struct ieee80211_supported_band
*sband
=
8855 wiphy
->bands
[ibss
.chandef
.chan
->band
];
8857 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8863 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8864 memcpy(&ibss
.ht_capa_mask
,
8865 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8866 sizeof(ibss
.ht_capa_mask
));
8868 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8869 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8871 memcpy(&ibss
.ht_capa
,
8872 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8873 sizeof(ibss
.ht_capa
));
8876 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8877 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
8878 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8881 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
8884 connkeys
= nl80211_parse_connkeys(rdev
, info
, &no_ht
);
8885 if (IS_ERR(connkeys
))
8886 return PTR_ERR(connkeys
);
8888 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
8896 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
8898 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
8899 int r
= validate_pae_over_nl80211(rdev
, info
);
8904 ibss
.control_port_over_nl80211
= true;
8907 ibss
.userspace_handles_dfs
=
8908 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
8910 wdev_lock(dev
->ieee80211_ptr
);
8911 err
= __cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
8914 else if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
8915 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
8916 wdev_unlock(dev
->ieee80211_ptr
);
8921 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8923 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8924 struct net_device
*dev
= info
->user_ptr
[1];
8926 if (!rdev
->ops
->leave_ibss
)
8929 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8932 return cfg80211_leave_ibss(rdev
, dev
, false);
8935 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
8937 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8938 struct net_device
*dev
= info
->user_ptr
[1];
8939 int mcast_rate
[NUM_NL80211_BANDS
];
8943 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
8944 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
8945 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
8948 if (!rdev
->ops
->set_mcast_rate
)
8951 memset(mcast_rate
, 0, sizeof(mcast_rate
));
8953 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
8956 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
8957 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
8960 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
8965 static struct sk_buff
*
8966 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
8967 struct wireless_dev
*wdev
, int approxlen
,
8968 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
8969 enum nl80211_attrs attr
,
8970 const struct nl80211_vendor_cmd_info
*info
,
8973 struct sk_buff
*skb
;
8975 struct nlattr
*data
;
8977 skb
= nlmsg_new(approxlen
+ 100, gfp
);
8981 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
8987 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
8988 goto nla_put_failure
;
8991 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
8993 goto nla_put_failure
;
8994 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
8996 goto nla_put_failure
;
9000 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
9001 wdev_id(wdev
), NL80211_ATTR_PAD
))
9002 goto nla_put_failure
;
9004 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
9005 wdev
->netdev
->ifindex
))
9006 goto nla_put_failure
;
9009 data
= nla_nest_start(skb
, attr
);
9011 goto nla_put_failure
;
9013 ((void **)skb
->cb
)[0] = rdev
;
9014 ((void **)skb
->cb
)[1] = hdr
;
9015 ((void **)skb
->cb
)[2] = data
;
9024 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
9025 struct wireless_dev
*wdev
,
9026 enum nl80211_commands cmd
,
9027 enum nl80211_attrs attr
,
9028 int vendor_event_idx
,
9029 int approxlen
, gfp_t gfp
)
9031 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
9032 const struct nl80211_vendor_cmd_info
*info
;
9035 case NL80211_CMD_TESTMODE
:
9036 if (WARN_ON(vendor_event_idx
!= -1))
9040 case NL80211_CMD_VENDOR
:
9041 if (WARN_ON(vendor_event_idx
< 0 ||
9042 vendor_event_idx
>= wiphy
->n_vendor_events
))
9044 info
= &wiphy
->vendor_events
[vendor_event_idx
];
9051 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
9052 cmd
, attr
, info
, gfp
);
9054 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
9056 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
9058 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
9059 void *hdr
= ((void **)skb
->cb
)[1];
9060 struct nlattr
*data
= ((void **)skb
->cb
)[2];
9061 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
9063 /* clear CB data for netlink core to own from now on */
9064 memset(skb
->cb
, 0, sizeof(skb
->cb
));
9066 nla_nest_end(skb
, data
);
9067 genlmsg_end(skb
, hdr
);
9069 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
9070 mcgrp
= NL80211_MCGRP_VENDOR
;
9072 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
9075 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
9077 #ifdef CONFIG_NL80211_TESTMODE
9078 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
9080 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9081 struct wireless_dev
*wdev
=
9082 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
9085 if (!rdev
->ops
->testmode_cmd
)
9089 err
= PTR_ERR(wdev
);
9093 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
9097 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
9100 rdev
->cur_cmd_info
= info
;
9101 err
= rdev_testmode_cmd(rdev
, wdev
,
9102 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
9103 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
9104 rdev
->cur_cmd_info
= NULL
;
9109 static int nl80211_testmode_dump(struct sk_buff
*skb
,
9110 struct netlink_callback
*cb
)
9112 struct cfg80211_registered_device
*rdev
;
9122 * 0 is a valid index, but not valid for args[0],
9123 * so we need to offset by 1.
9125 phy_idx
= cb
->args
[0] - 1;
9127 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
9133 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
9135 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
9136 attrbuf
, nl80211_fam
.maxattr
,
9137 nl80211_policy
, NULL
);
9141 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
9143 err
= PTR_ERR(rdev
);
9146 phy_idx
= rdev
->wiphy_idx
;
9148 if (attrbuf
[NL80211_ATTR_TESTDATA
])
9149 cb
->args
[1] = (long)attrbuf
[NL80211_ATTR_TESTDATA
];
9153 data
= nla_data((void *)cb
->args
[1]);
9154 data_len
= nla_len((void *)cb
->args
[1]);
9157 if (!rdev
->ops
->testmode_dump
) {
9163 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
9164 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
9165 NL80211_CMD_TESTMODE
);
9166 struct nlattr
*tmdata
;
9171 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
9172 genlmsg_cancel(skb
, hdr
);
9176 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
9178 genlmsg_cancel(skb
, hdr
);
9181 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
9182 nla_nest_end(skb
, tmdata
);
9184 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
9185 genlmsg_cancel(skb
, hdr
);
9188 genlmsg_cancel(skb
, hdr
);
9192 genlmsg_end(skb
, hdr
);
9197 cb
->args
[0] = phy_idx
+ 1;
9204 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
9206 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9207 struct net_device
*dev
= info
->user_ptr
[1];
9208 struct cfg80211_connect_params connect
;
9209 struct wiphy
*wiphy
;
9210 struct cfg80211_cached_keys
*connkeys
= NULL
;
9213 memset(&connect
, 0, sizeof(connect
));
9215 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9218 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
9219 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
9222 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
9224 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
9225 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
9226 NL80211_CMD_CONNECT
))
9229 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
9231 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
9233 if (info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
] &&
9234 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9235 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
9237 connect
.want_1x
= info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
];
9239 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
9240 NL80211_MAX_NR_CIPHER_SUITES
);
9244 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9245 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9248 wiphy
= &rdev
->wiphy
;
9250 connect
.bg_scan_period
= -1;
9251 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
9252 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
9253 connect
.bg_scan_period
=
9254 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
9257 if (info
->attrs
[NL80211_ATTR_MAC
])
9258 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9259 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
9260 connect
.bssid_hint
=
9261 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
9262 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9263 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9265 if (info
->attrs
[NL80211_ATTR_IE
]) {
9266 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9267 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9270 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
9271 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
9272 if (connect
.mfp
== NL80211_MFP_OPTIONAL
&&
9273 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9274 NL80211_EXT_FEATURE_MFP_OPTIONAL
))
9277 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
9278 connect
.mfp
!= NL80211_MFP_NO
&&
9279 connect
.mfp
!= NL80211_MFP_OPTIONAL
)
9282 connect
.mfp
= NL80211_MFP_NO
;
9285 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
9286 connect
.prev_bssid
=
9287 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
9289 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9290 connect
.channel
= nl80211_get_valid_chan(
9291 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
9292 if (!connect
.channel
)
9294 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
9295 connect
.channel_hint
= nl80211_get_valid_chan(
9296 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
9297 if (!connect
.channel_hint
)
9301 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
9302 connkeys
= nl80211_parse_connkeys(rdev
, info
, NULL
);
9303 if (IS_ERR(connkeys
))
9304 return PTR_ERR(connkeys
);
9307 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
9308 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
9310 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9311 memcpy(&connect
.ht_capa_mask
,
9312 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
9313 sizeof(connect
.ht_capa_mask
));
9315 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
9316 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
9320 memcpy(&connect
.ht_capa
,
9321 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
9322 sizeof(connect
.ht_capa
));
9325 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
9326 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
9328 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
9329 memcpy(&connect
.vht_capa_mask
,
9330 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
9331 sizeof(connect
.vht_capa_mask
));
9333 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
9334 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
9338 memcpy(&connect
.vht_capa
,
9339 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
9340 sizeof(connect
.vht_capa
));
9343 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
9344 if (!((rdev
->wiphy
.features
&
9345 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
9346 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
9347 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9348 NL80211_EXT_FEATURE_RRM
)) {
9352 connect
.flags
|= ASSOC_REQ_USE_RRM
;
9355 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
9356 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
9361 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
9362 /* bss selection makes no sense if bssid is set */
9363 if (connect
.bssid
) {
9368 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
9369 wiphy
, &connect
.bss_select
);
9376 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
9377 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
9378 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
9379 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
9380 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
9381 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9382 connect
.fils_erp_username
=
9383 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9384 connect
.fils_erp_username_len
=
9385 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9386 connect
.fils_erp_realm
=
9387 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9388 connect
.fils_erp_realm_len
=
9389 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9390 connect
.fils_erp_next_seq_num
=
9392 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
9393 connect
.fils_erp_rrk
=
9394 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9395 connect
.fils_erp_rrk_len
=
9396 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9397 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
9398 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
9399 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
9400 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9405 if (nla_get_flag(info
->attrs
[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
])) {
9406 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9408 GENL_SET_ERR_MSG(info
,
9409 "external auth requires connection ownership");
9412 connect
.flags
|= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT
;
9415 wdev_lock(dev
->ieee80211_ptr
);
9417 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
9418 connect
.prev_bssid
);
9422 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9423 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
9425 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
9426 connect
.bssid
, ETH_ALEN
);
9428 memset(dev
->ieee80211_ptr
->disconnect_bssid
,
9432 wdev_unlock(dev
->ieee80211_ptr
);
9437 static int nl80211_update_connect_params(struct sk_buff
*skb
,
9438 struct genl_info
*info
)
9440 struct cfg80211_connect_params connect
= {};
9441 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9442 struct net_device
*dev
= info
->user_ptr
[1];
9443 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9444 bool fils_sk_offload
;
9449 if (!rdev
->ops
->update_connect_params
)
9452 if (info
->attrs
[NL80211_ATTR_IE
]) {
9453 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9455 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9456 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9457 changed
|= UPDATE_ASSOC_IES
;
9460 fils_sk_offload
= wiphy_ext_feature_isset(&rdev
->wiphy
,
9461 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
);
9464 * when driver supports fils-sk offload all attributes must be
9465 * provided. So the else covers "fils-sk-not-all" and
9468 if (fils_sk_offload
&&
9469 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
9470 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
9471 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
9472 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9473 connect
.fils_erp_username
=
9474 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9475 connect
.fils_erp_username_len
=
9476 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9477 connect
.fils_erp_realm
=
9478 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9479 connect
.fils_erp_realm_len
=
9480 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9481 connect
.fils_erp_next_seq_num
=
9483 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
9484 connect
.fils_erp_rrk
=
9485 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9486 connect
.fils_erp_rrk_len
=
9487 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9488 changed
|= UPDATE_FILS_ERP_INFO
;
9489 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
9490 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
9491 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
9492 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9496 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
9497 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
9498 if (!nl80211_valid_auth_type(rdev
, auth_type
,
9499 NL80211_CMD_CONNECT
))
9502 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
&&
9503 fils_sk_offload
&& !(changed
& UPDATE_FILS_ERP_INFO
))
9506 connect
.auth_type
= auth_type
;
9507 changed
|= UPDATE_AUTH_TYPE
;
9510 wdev_lock(dev
->ieee80211_ptr
);
9511 if (!wdev
->current_bss
)
9514 ret
= rdev_update_connect_params(rdev
, dev
, &connect
, changed
);
9515 wdev_unlock(dev
->ieee80211_ptr
);
9520 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
9522 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9523 struct net_device
*dev
= info
->user_ptr
[1];
9527 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
9528 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
9531 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
9532 reason
= WLAN_REASON_DEAUTH_LEAVING
;
9534 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
9539 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9540 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9543 wdev_lock(dev
->ieee80211_ptr
);
9544 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
9545 wdev_unlock(dev
->ieee80211_ptr
);
9549 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
9551 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9555 if (info
->attrs
[NL80211_ATTR_PID
]) {
9556 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
9558 net
= get_net_ns_by_pid(pid
);
9559 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
9560 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
9562 net
= get_net_ns_by_fd(fd
);
9568 return PTR_ERR(net
);
9572 /* check if anything to do */
9573 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
9574 err
= cfg80211_switch_netns(rdev
, net
);
9580 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9582 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9583 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
9584 struct cfg80211_pmksa
*pmksa
) = NULL
;
9585 struct net_device
*dev
= info
->user_ptr
[1];
9586 struct cfg80211_pmksa pmksa
;
9588 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
9590 if (!info
->attrs
[NL80211_ATTR_PMKID
])
9593 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
9595 if (info
->attrs
[NL80211_ATTR_MAC
]) {
9596 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9597 } else if (info
->attrs
[NL80211_ATTR_SSID
] &&
9598 info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
] &&
9599 (info
->genlhdr
->cmd
== NL80211_CMD_DEL_PMKSA
||
9600 info
->attrs
[NL80211_ATTR_PMK
])) {
9601 pmksa
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9602 pmksa
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9604 nla_data(info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
]);
9608 if (info
->attrs
[NL80211_ATTR_PMK
]) {
9609 pmksa
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
9610 pmksa
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
9613 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9614 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9617 switch (info
->genlhdr
->cmd
) {
9618 case NL80211_CMD_SET_PMKSA
:
9619 rdev_ops
= rdev
->ops
->set_pmksa
;
9621 case NL80211_CMD_DEL_PMKSA
:
9622 rdev_ops
= rdev
->ops
->del_pmksa
;
9632 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
9635 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9637 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9638 struct net_device
*dev
= info
->user_ptr
[1];
9640 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9641 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9644 if (!rdev
->ops
->flush_pmksa
)
9647 return rdev_flush_pmksa(rdev
, dev
);
9650 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9652 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9653 struct net_device
*dev
= info
->user_ptr
[1];
9654 u8 action_code
, dialog_token
;
9655 u32 peer_capability
= 0;
9660 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9661 !rdev
->ops
->tdls_mgmt
)
9664 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
9665 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
9666 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
9667 !info
->attrs
[NL80211_ATTR_IE
] ||
9668 !info
->attrs
[NL80211_ATTR_MAC
])
9671 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9672 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
9673 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
9674 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
9675 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
9676 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
9678 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
9680 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
9681 dialog_token
, status_code
, peer_capability
,
9683 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
9684 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
9687 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
9689 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9690 struct net_device
*dev
= info
->user_ptr
[1];
9691 enum nl80211_tdls_operation operation
;
9694 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9695 !rdev
->ops
->tdls_oper
)
9698 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
9699 !info
->attrs
[NL80211_ATTR_MAC
])
9702 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
9703 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9705 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
9708 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
9709 struct genl_info
*info
)
9711 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9712 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9713 struct cfg80211_chan_def chandef
;
9714 const struct cfg80211_chan_def
*compat_chandef
;
9715 struct sk_buff
*msg
;
9721 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
9722 !info
->attrs
[NL80211_ATTR_DURATION
])
9725 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9727 if (!rdev
->ops
->remain_on_channel
||
9728 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
9732 * We should be on that channel for at least a minimum amount of
9733 * time (10ms) but no longer than the driver supports.
9735 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9736 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
9739 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9744 if (!cfg80211_off_channel_oper_allowed(wdev
) &&
9745 !cfg80211_chandef_identical(&wdev
->chandef
, &chandef
)) {
9746 compat_chandef
= cfg80211_chandef_compatible(&wdev
->chandef
,
9748 if (compat_chandef
!= &chandef
) {
9755 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9759 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9760 NL80211_CMD_REMAIN_ON_CHANNEL
);
9766 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
9772 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9774 goto nla_put_failure
;
9776 genlmsg_end(msg
, hdr
);
9778 return genlmsg_reply(msg
, info
);
9787 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
9788 struct genl_info
*info
)
9790 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9791 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9794 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9797 if (!rdev
->ops
->cancel_remain_on_channel
)
9800 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9802 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
9805 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
9806 struct genl_info
*info
)
9808 struct cfg80211_bitrate_mask mask
;
9809 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9810 struct net_device
*dev
= info
->user_ptr
[1];
9813 if (!rdev
->ops
->set_bitrate_mask
)
9816 err
= nl80211_parse_tx_bitrate_mask(info
, &mask
);
9820 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
9823 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9825 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9826 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9827 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
9829 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
9832 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
9833 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
9835 switch (wdev
->iftype
) {
9836 case NL80211_IFTYPE_STATION
:
9837 case NL80211_IFTYPE_ADHOC
:
9838 case NL80211_IFTYPE_P2P_CLIENT
:
9839 case NL80211_IFTYPE_AP
:
9840 case NL80211_IFTYPE_AP_VLAN
:
9841 case NL80211_IFTYPE_MESH_POINT
:
9842 case NL80211_IFTYPE_P2P_GO
:
9843 case NL80211_IFTYPE_P2P_DEVICE
:
9845 case NL80211_IFTYPE_NAN
:
9850 /* not much point in registering if we can't reply */
9851 if (!rdev
->ops
->mgmt_tx
)
9854 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
9855 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
9856 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
9859 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9862 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9863 struct cfg80211_chan_def chandef
;
9867 struct sk_buff
*msg
= NULL
;
9868 struct cfg80211_mgmt_tx_params params
= {
9869 .dont_wait_for_ack
=
9870 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
9873 if (!info
->attrs
[NL80211_ATTR_FRAME
])
9876 if (!rdev
->ops
->mgmt_tx
)
9879 switch (wdev
->iftype
) {
9880 case NL80211_IFTYPE_P2P_DEVICE
:
9881 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9883 case NL80211_IFTYPE_STATION
:
9884 case NL80211_IFTYPE_ADHOC
:
9885 case NL80211_IFTYPE_P2P_CLIENT
:
9886 case NL80211_IFTYPE_AP
:
9887 case NL80211_IFTYPE_AP_VLAN
:
9888 case NL80211_IFTYPE_MESH_POINT
:
9889 case NL80211_IFTYPE_P2P_GO
:
9891 case NL80211_IFTYPE_NAN
:
9896 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
9897 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9899 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9902 * We should wait on the channel for at least a minimum amount
9903 * of time (10ms) but no longer than the driver supports.
9905 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9906 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
9910 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
9912 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9915 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
9917 /* get the channel if any has been specified, otherwise pass NULL to
9918 * the driver. The latter will use the current one
9920 chandef
.chan
= NULL
;
9921 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9922 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9927 if (!chandef
.chan
&& params
.offchan
)
9931 if (params
.offchan
&& !cfg80211_off_channel_oper_allowed(wdev
)) {
9937 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
9938 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
9940 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
9941 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9944 if (len
% sizeof(u16
))
9947 params
.n_csa_offsets
= len
/ sizeof(u16
);
9948 params
.csa_offsets
=
9949 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9951 /* check that all the offsets fit the frame */
9952 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
9953 if (params
.csa_offsets
[i
] >= params
.len
)
9958 if (!params
.dont_wait_for_ack
) {
9959 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9963 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9971 params
.chan
= chandef
.chan
;
9972 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
9977 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9979 goto nla_put_failure
;
9981 genlmsg_end(msg
, hdr
);
9982 return genlmsg_reply(msg
, info
);
9994 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
9996 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9997 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10000 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
10003 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
10004 return -EOPNOTSUPP
;
10006 switch (wdev
->iftype
) {
10007 case NL80211_IFTYPE_STATION
:
10008 case NL80211_IFTYPE_ADHOC
:
10009 case NL80211_IFTYPE_P2P_CLIENT
:
10010 case NL80211_IFTYPE_AP
:
10011 case NL80211_IFTYPE_AP_VLAN
:
10012 case NL80211_IFTYPE_P2P_GO
:
10013 case NL80211_IFTYPE_P2P_DEVICE
:
10015 case NL80211_IFTYPE_NAN
:
10017 return -EOPNOTSUPP
;
10020 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
10022 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
10025 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
10027 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10028 struct wireless_dev
*wdev
;
10029 struct net_device
*dev
= info
->user_ptr
[1];
10034 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
10037 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
10039 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
10042 wdev
= dev
->ieee80211_ptr
;
10044 if (!rdev
->ops
->set_power_mgmt
)
10045 return -EOPNOTSUPP
;
10047 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
10049 if (state
== wdev
->ps
)
10052 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
10058 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
10060 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10061 enum nl80211_ps_state ps_state
;
10062 struct wireless_dev
*wdev
;
10063 struct net_device
*dev
= info
->user_ptr
[1];
10064 struct sk_buff
*msg
;
10068 wdev
= dev
->ieee80211_ptr
;
10070 if (!rdev
->ops
->set_power_mgmt
)
10071 return -EOPNOTSUPP
;
10073 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10077 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10078 NL80211_CMD_GET_POWER_SAVE
);
10085 ps_state
= NL80211_PS_ENABLED
;
10087 ps_state
= NL80211_PS_DISABLED
;
10089 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
10090 goto nla_put_failure
;
10092 genlmsg_end(msg
, hdr
);
10093 return genlmsg_reply(msg
, info
);
10102 static const struct nla_policy
10103 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
10104 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_BINARY
},
10105 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
10106 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
10107 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
10108 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
10109 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
10110 [NL80211_ATTR_CQM_RSSI_LEVEL
] = { .type
= NLA_S32
},
10113 static int nl80211_set_cqm_txe(struct genl_info
*info
,
10114 u32 rate
, u32 pkts
, u32 intvl
)
10116 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10117 struct net_device
*dev
= info
->user_ptr
[1];
10118 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10120 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
10123 if (!rdev
->ops
->set_cqm_txe_config
)
10124 return -EOPNOTSUPP
;
10126 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
10127 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10128 return -EOPNOTSUPP
;
10130 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
10133 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device
*rdev
,
10134 struct net_device
*dev
)
10136 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10137 s32 last
, low
, high
;
10142 /* RSSI reporting disabled? */
10143 if (!wdev
->cqm_config
)
10144 return rdev_set_cqm_rssi_range_config(rdev
, dev
, 0, 0);
10147 * Obtain current RSSI value if possible, if not and no RSSI threshold
10148 * event has been received yet, we should receive an event after a
10149 * connection is established and enough beacons received to calculate
10152 if (!wdev
->cqm_config
->last_rssi_event_value
&& wdev
->current_bss
&&
10153 rdev
->ops
->get_station
) {
10154 struct station_info sinfo
= {};
10157 mac_addr
= wdev
->current_bss
->pub
.bssid
;
10159 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
10163 if (sinfo
.filled
& BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG
))
10164 wdev
->cqm_config
->last_rssi_event_value
=
10165 (s8
) sinfo
.rx_beacon_signal_avg
;
10168 last
= wdev
->cqm_config
->last_rssi_event_value
;
10169 hyst
= wdev
->cqm_config
->rssi_hyst
;
10170 n
= wdev
->cqm_config
->n_rssi_thresholds
;
10172 for (i
= 0; i
< n
; i
++)
10173 if (last
< wdev
->cqm_config
->rssi_thresholds
[i
])
10177 (wdev
->cqm_config
->rssi_thresholds
[i
- 1] - hyst
) : S32_MIN
;
10179 (wdev
->cqm_config
->rssi_thresholds
[i
] + hyst
- 1) : S32_MAX
;
10181 return rdev_set_cqm_rssi_range_config(rdev
, dev
, low
, high
);
10184 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
10185 const s32
*thresholds
, int n_thresholds
,
10188 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10189 struct net_device
*dev
= info
->user_ptr
[1];
10190 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10192 s32 prev
= S32_MIN
;
10194 /* Check all values negative and sorted */
10195 for (i
= 0; i
< n_thresholds
; i
++) {
10196 if (thresholds
[i
] > 0 || thresholds
[i
] <= prev
)
10199 prev
= thresholds
[i
];
10202 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
10203 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10204 return -EOPNOTSUPP
;
10207 cfg80211_cqm_config_free(wdev
);
10210 if (n_thresholds
<= 1 && rdev
->ops
->set_cqm_rssi_config
) {
10211 if (n_thresholds
== 0 || thresholds
[0] == 0) /* Disabling */
10212 return rdev_set_cqm_rssi_config(rdev
, dev
, 0, 0);
10214 return rdev_set_cqm_rssi_config(rdev
, dev
,
10215 thresholds
[0], hysteresis
);
10218 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
10219 NL80211_EXT_FEATURE_CQM_RSSI_LIST
))
10220 return -EOPNOTSUPP
;
10222 if (n_thresholds
== 1 && thresholds
[0] == 0) /* Disabling */
10226 if (n_thresholds
) {
10227 struct cfg80211_cqm_config
*cqm_config
;
10229 cqm_config
= kzalloc(sizeof(struct cfg80211_cqm_config
) +
10230 n_thresholds
* sizeof(s32
), GFP_KERNEL
);
10236 cqm_config
->rssi_hyst
= hysteresis
;
10237 cqm_config
->n_rssi_thresholds
= n_thresholds
;
10238 memcpy(cqm_config
->rssi_thresholds
, thresholds
,
10239 n_thresholds
* sizeof(s32
));
10241 wdev
->cqm_config
= cqm_config
;
10244 err
= cfg80211_cqm_rssi_update(rdev
, dev
);
10252 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
10254 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
10255 struct nlattr
*cqm
;
10258 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
10262 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
10263 nl80211_attr_cqm_policy
, info
->extack
);
10267 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
10268 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
10269 const s32
*thresholds
=
10270 nla_data(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
10271 int len
= nla_len(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
10272 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
10277 return nl80211_set_cqm_rssi(info
, thresholds
, len
/ 4,
10281 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
10282 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
10283 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
10284 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
10285 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
10286 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
10288 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
10294 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
10296 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10297 struct net_device
*dev
= info
->user_ptr
[1];
10298 struct ocb_setup setup
= {};
10301 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
10305 return cfg80211_join_ocb(rdev
, dev
, &setup
);
10308 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
10310 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10311 struct net_device
*dev
= info
->user_ptr
[1];
10313 return cfg80211_leave_ocb(rdev
, dev
);
10316 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
10318 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10319 struct net_device
*dev
= info
->user_ptr
[1];
10320 struct mesh_config cfg
;
10321 struct mesh_setup setup
;
10324 /* start with default */
10325 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
10326 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
10328 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
10329 /* and parse parameters if given */
10330 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
10335 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
10336 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
10339 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
10340 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
10342 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
10343 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
10344 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
10347 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
10348 setup
.beacon_interval
=
10349 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
10351 err
= cfg80211_validate_beacon_int(rdev
,
10352 NL80211_IFTYPE_MESH_POINT
,
10353 setup
.beacon_interval
);
10358 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
10359 setup
.dtim_period
=
10360 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
10361 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
10365 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
10366 /* parse additional setup parameters if given */
10367 err
= nl80211_parse_mesh_setup(info
, &setup
);
10372 if (setup
.user_mpm
)
10373 cfg
.auto_open_plinks
= false;
10375 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
10376 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
10380 /* __cfg80211_join_mesh() will sort it out */
10381 setup
.chandef
.chan
= NULL
;
10384 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
10385 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10387 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10388 struct ieee80211_supported_band
*sband
;
10390 if (!setup
.chandef
.chan
)
10393 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
10395 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
10396 &setup
.basic_rates
);
10401 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
10402 err
= nl80211_parse_tx_bitrate_mask(info
, &setup
.beacon_rate
);
10406 if (!setup
.chandef
.chan
)
10409 err
= validate_beacon_tx_rate(rdev
, setup
.chandef
.chan
->band
,
10410 &setup
.beacon_rate
);
10415 setup
.userspace_handles_dfs
=
10416 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
10418 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
10419 int r
= validate_pae_over_nl80211(rdev
, info
);
10424 setup
.control_port_over_nl80211
= true;
10427 wdev_lock(dev
->ieee80211_ptr
);
10428 err
= __cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
10429 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
10430 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
10431 wdev_unlock(dev
->ieee80211_ptr
);
10436 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
10438 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10439 struct net_device
*dev
= info
->user_ptr
[1];
10441 return cfg80211_leave_mesh(rdev
, dev
);
10445 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
10446 struct cfg80211_registered_device
*rdev
)
10448 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
10449 struct nlattr
*nl_pats
, *nl_pat
;
10452 if (!wowlan
->n_patterns
)
10455 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
10459 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
10460 nl_pat
= nla_nest_start(msg
, i
+ 1);
10463 pat_len
= wowlan
->patterns
[i
].pattern_len
;
10464 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
10465 wowlan
->patterns
[i
].mask
) ||
10466 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
10467 wowlan
->patterns
[i
].pattern
) ||
10468 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
10469 wowlan
->patterns
[i
].pkt_offset
))
10471 nla_nest_end(msg
, nl_pat
);
10473 nla_nest_end(msg
, nl_pats
);
10478 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
10479 struct cfg80211_wowlan_tcp
*tcp
)
10481 struct nlattr
*nl_tcp
;
10486 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
10490 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
10491 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
10492 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
10493 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
10494 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
10495 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
10496 tcp
->payload_len
, tcp
->payload
) ||
10497 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
10498 tcp
->data_interval
) ||
10499 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
10500 tcp
->wake_len
, tcp
->wake_data
) ||
10501 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
10502 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
10505 if (tcp
->payload_seq
.len
&&
10506 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
10507 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
10510 if (tcp
->payload_tok
.len
&&
10511 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
10512 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
10513 &tcp
->payload_tok
))
10516 nla_nest_end(msg
, nl_tcp
);
10521 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
10522 struct cfg80211_sched_scan_request
*req
)
10524 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
10530 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
10534 if (req
->n_scan_plans
== 1 &&
10535 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
10536 req
->scan_plans
[0].interval
* 1000))
10539 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
10542 if (req
->relative_rssi_set
) {
10543 struct nl80211_bss_select_rssi_adjust rssi_adjust
;
10545 if (nla_put_s8(msg
, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
,
10546 req
->relative_rssi
))
10549 rssi_adjust
.band
= req
->rssi_adjust
.band
;
10550 rssi_adjust
.delta
= req
->rssi_adjust
.delta
;
10551 if (nla_put(msg
, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
,
10552 sizeof(rssi_adjust
), &rssi_adjust
))
10556 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
10560 for (i
= 0; i
< req
->n_channels
; i
++) {
10561 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
10565 nla_nest_end(msg
, freqs
);
10567 if (req
->n_match_sets
) {
10568 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
10572 for (i
= 0; i
< req
->n_match_sets
; i
++) {
10573 match
= nla_nest_start(msg
, i
);
10577 if (nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
10578 req
->match_sets
[i
].ssid
.ssid_len
,
10579 req
->match_sets
[i
].ssid
.ssid
))
10581 nla_nest_end(msg
, match
);
10583 nla_nest_end(msg
, matches
);
10586 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
10590 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
10591 scan_plan
= nla_nest_start(msg
, i
+ 1);
10596 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
10597 req
->scan_plans
[i
].interval
) ||
10598 (req
->scan_plans
[i
].iterations
&&
10599 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
10600 req
->scan_plans
[i
].iterations
)))
10602 nla_nest_end(msg
, scan_plan
);
10604 nla_nest_end(msg
, scan_plans
);
10606 nla_nest_end(msg
, nd
);
10611 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
10613 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10614 struct sk_buff
*msg
;
10616 u32 size
= NLMSG_DEFAULT_SIZE
;
10618 if (!rdev
->wiphy
.wowlan
)
10619 return -EOPNOTSUPP
;
10621 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
10622 /* adjust size to have room for all the data */
10623 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
10624 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
10625 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
10626 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
10629 msg
= nlmsg_new(size
, GFP_KERNEL
);
10633 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10634 NL80211_CMD_GET_WOWLAN
);
10636 goto nla_put_failure
;
10638 if (rdev
->wiphy
.wowlan_config
) {
10639 struct nlattr
*nl_wowlan
;
10641 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10643 goto nla_put_failure
;
10645 if ((rdev
->wiphy
.wowlan_config
->any
&&
10646 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
10647 (rdev
->wiphy
.wowlan_config
->disconnect
&&
10648 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
10649 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
10650 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
10651 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
10652 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
10653 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
10654 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
10655 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
10656 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
10657 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
10658 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
10659 goto nla_put_failure
;
10661 if (nl80211_send_wowlan_patterns(msg
, rdev
))
10662 goto nla_put_failure
;
10664 if (nl80211_send_wowlan_tcp(msg
,
10665 rdev
->wiphy
.wowlan_config
->tcp
))
10666 goto nla_put_failure
;
10668 if (nl80211_send_wowlan_nd(
10670 rdev
->wiphy
.wowlan_config
->nd_config
))
10671 goto nla_put_failure
;
10673 nla_nest_end(msg
, nl_wowlan
);
10676 genlmsg_end(msg
, hdr
);
10677 return genlmsg_reply(msg
, info
);
10684 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
10685 struct nlattr
*attr
,
10686 struct cfg80211_wowlan
*trig
)
10688 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
10689 struct cfg80211_wowlan_tcp
*cfg
;
10690 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
10691 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
10693 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
10696 if (!rdev
->wiphy
.wowlan
->tcp
)
10699 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TCP
, attr
,
10700 nl80211_wowlan_tcp_policy
, NULL
);
10704 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
10705 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
10706 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
10707 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
10708 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
10709 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
10710 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
10711 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
10714 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
10715 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
10718 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
10719 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
10720 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
10723 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
10724 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
10727 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
10728 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
10731 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
10732 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10734 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10735 tokens_size
= tokln
- sizeof(*tok
);
10737 if (!tok
->len
|| tokens_size
% tok
->len
)
10739 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
10741 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
10743 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
10745 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
10747 if (tok
->offset
+ tok
->len
> data_size
)
10751 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
10752 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
10753 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
10755 if (seq
->len
== 0 || seq
->len
> 4)
10757 if (seq
->len
+ seq
->offset
> data_size
)
10761 size
= sizeof(*cfg
);
10763 size
+= wake_size
+ wake_mask_size
;
10764 size
+= tokens_size
;
10766 cfg
= kzalloc(size
, GFP_KERNEL
);
10769 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
10770 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
10771 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
10773 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
10774 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
10778 /* allocate a socket and port for it and use it */
10779 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
10780 IPPROTO_TCP
, &cfg
->sock
, 1);
10785 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
10786 sock_release(cfg
->sock
);
10788 return -EADDRINUSE
;
10790 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
10796 cfg
->src_port
= port
;
10799 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
10800 cfg
->payload_len
= data_size
;
10801 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
10802 memcpy((void *)cfg
->payload
,
10803 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
10806 cfg
->payload_seq
= *seq
;
10807 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
10808 cfg
->wake_len
= wake_size
;
10809 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
10810 memcpy((void *)cfg
->wake_data
,
10811 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
10813 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
10814 data_size
+ wake_size
;
10815 memcpy((void *)cfg
->wake_mask
,
10816 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
10819 cfg
->tokens_size
= tokens_size
;
10820 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
10828 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
10829 const struct wiphy_wowlan_support
*wowlan
,
10830 struct nlattr
*attr
,
10831 struct cfg80211_wowlan
*trig
)
10833 struct nlattr
**tb
;
10836 tb
= kcalloc(NUM_NL80211_ATTR
, sizeof(*tb
), GFP_KERNEL
);
10840 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
10845 err
= nla_parse_nested(tb
, NL80211_ATTR_MAX
, attr
, nl80211_policy
,
10850 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
,
10851 wowlan
->max_nd_match_sets
);
10852 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
10854 trig
->nd_config
= NULL
;
10861 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
10863 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10864 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
10865 struct cfg80211_wowlan new_triggers
= {};
10866 struct cfg80211_wowlan
*ntrig
;
10867 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
10869 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
10870 bool regular
= false;
10873 return -EOPNOTSUPP
;
10875 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
10876 cfg80211_rdev_free_wowlan(rdev
);
10877 rdev
->wiphy
.wowlan_config
= NULL
;
10881 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TRIG
,
10882 info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
],
10883 nl80211_wowlan_policy
, info
->extack
);
10887 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
10888 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
10890 new_triggers
.any
= true;
10893 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
10894 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
10896 new_triggers
.disconnect
= true;
10900 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
10901 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
10903 new_triggers
.magic_pkt
= true;
10907 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
10910 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
10911 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
10913 new_triggers
.gtk_rekey_failure
= true;
10917 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
10918 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
10920 new_triggers
.eap_identity_req
= true;
10924 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
10925 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
10927 new_triggers
.four_way_handshake
= true;
10931 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
10932 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
10934 new_triggers
.rfkill_release
= true;
10938 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
10939 struct nlattr
*pat
;
10940 int n_patterns
= 0;
10941 int rem
, pat_len
, mask_len
, pkt_offset
;
10942 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
10946 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
10949 if (n_patterns
> wowlan
->n_patterns
)
10952 new_triggers
.patterns
= kcalloc(n_patterns
,
10953 sizeof(new_triggers
.patterns
[0]),
10955 if (!new_triggers
.patterns
)
10958 new_triggers
.n_patterns
= n_patterns
;
10961 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
10965 nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
10966 nl80211_packet_pattern_policy
,
10969 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10970 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10972 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10973 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10974 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10976 if (pat_len
> wowlan
->pattern_max_len
||
10977 pat_len
< wowlan
->pattern_min_len
)
10980 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10983 pkt_offset
= nla_get_u32(
10984 pat_tb
[NL80211_PKTPAT_OFFSET
]);
10985 if (pkt_offset
> wowlan
->max_pkt_offset
)
10987 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
10989 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10994 new_triggers
.patterns
[i
].mask
= mask_pat
;
10995 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10997 mask_pat
+= mask_len
;
10998 new_triggers
.patterns
[i
].pattern
= mask_pat
;
10999 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
11001 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
11007 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
11009 err
= nl80211_parse_wowlan_tcp(
11010 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
11016 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
11018 err
= nl80211_parse_wowlan_nd(
11019 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
11025 /* The 'any' trigger means the device continues operating more or less
11026 * as in its normal operation mode and wakes up the host on most of the
11027 * normal interrupts (like packet RX, ...)
11028 * It therefore makes little sense to combine with the more constrained
11029 * wakeup trigger modes.
11031 if (new_triggers
.any
&& regular
) {
11036 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
11041 cfg80211_rdev_free_wowlan(rdev
);
11042 rdev
->wiphy
.wowlan_config
= ntrig
;
11045 if (rdev
->ops
->set_wakeup
&&
11046 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
11047 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
11051 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
11052 kfree(new_triggers
.patterns
[i
].mask
);
11053 kfree(new_triggers
.patterns
);
11054 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
11055 sock_release(new_triggers
.tcp
->sock
);
11056 kfree(new_triggers
.tcp
);
11057 kfree(new_triggers
.nd_config
);
11062 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
11063 struct cfg80211_registered_device
*rdev
)
11065 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
11067 struct cfg80211_coalesce_rules
*rule
;
11069 if (!rdev
->coalesce
->n_rules
)
11072 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
11076 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
11077 nl_rule
= nla_nest_start(msg
, i
+ 1);
11081 rule
= &rdev
->coalesce
->rules
[i
];
11082 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
11086 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
11090 nl_pats
= nla_nest_start(msg
,
11091 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
11095 for (j
= 0; j
< rule
->n_patterns
; j
++) {
11096 nl_pat
= nla_nest_start(msg
, j
+ 1);
11099 pat_len
= rule
->patterns
[j
].pattern_len
;
11100 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
11101 DIV_ROUND_UP(pat_len
, 8),
11102 rule
->patterns
[j
].mask
) ||
11103 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
11104 rule
->patterns
[j
].pattern
) ||
11105 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
11106 rule
->patterns
[j
].pkt_offset
))
11108 nla_nest_end(msg
, nl_pat
);
11110 nla_nest_end(msg
, nl_pats
);
11111 nla_nest_end(msg
, nl_rule
);
11113 nla_nest_end(msg
, nl_rules
);
11118 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
11120 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11121 struct sk_buff
*msg
;
11124 if (!rdev
->wiphy
.coalesce
)
11125 return -EOPNOTSUPP
;
11127 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11131 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11132 NL80211_CMD_GET_COALESCE
);
11134 goto nla_put_failure
;
11136 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
11137 goto nla_put_failure
;
11139 genlmsg_end(msg
, hdr
);
11140 return genlmsg_reply(msg
, info
);
11147 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
11149 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
11151 struct cfg80211_coalesce_rules
*rule
;
11156 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
11157 rule
= &coalesce
->rules
[i
];
11158 for (j
= 0; j
< rule
->n_patterns
; j
++)
11159 kfree(rule
->patterns
[j
].mask
);
11160 kfree(rule
->patterns
);
11162 kfree(coalesce
->rules
);
11164 rdev
->coalesce
= NULL
;
11167 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
11168 struct nlattr
*rule
,
11169 struct cfg80211_coalesce_rules
*new_rule
)
11172 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
11173 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
11174 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
11175 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
11177 err
= nla_parse_nested(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, rule
,
11178 nl80211_coalesce_policy
, NULL
);
11182 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
11184 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
11185 if (new_rule
->delay
> coalesce
->max_delay
)
11188 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
11189 new_rule
->condition
=
11190 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
11191 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
11192 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
11195 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
11198 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
11201 if (n_patterns
> coalesce
->n_patterns
)
11204 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
11206 if (!new_rule
->patterns
)
11209 new_rule
->n_patterns
= n_patterns
;
11212 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
11216 nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
11217 nl80211_packet_pattern_policy
, NULL
);
11218 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
11219 !pat_tb
[NL80211_PKTPAT_PATTERN
])
11221 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
11222 mask_len
= DIV_ROUND_UP(pat_len
, 8);
11223 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
11225 if (pat_len
> coalesce
->pattern_max_len
||
11226 pat_len
< coalesce
->pattern_min_len
)
11229 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
11232 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
11233 if (pkt_offset
> coalesce
->max_pkt_offset
)
11235 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
11237 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
11241 new_rule
->patterns
[i
].mask
= mask_pat
;
11242 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
11245 mask_pat
+= mask_len
;
11246 new_rule
->patterns
[i
].pattern
= mask_pat
;
11247 new_rule
->patterns
[i
].pattern_len
= pat_len
;
11248 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
11256 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
11258 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11259 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
11260 struct cfg80211_coalesce new_coalesce
= {};
11261 struct cfg80211_coalesce
*n_coalesce
;
11262 int err
, rem_rule
, n_rules
= 0, i
, j
;
11263 struct nlattr
*rule
;
11264 struct cfg80211_coalesce_rules
*tmp_rule
;
11266 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
11267 return -EOPNOTSUPP
;
11269 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
11270 cfg80211_rdev_free_coalesce(rdev
);
11271 rdev_set_coalesce(rdev
, NULL
);
11275 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
11278 if (n_rules
> coalesce
->n_rules
)
11281 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
11283 if (!new_coalesce
.rules
)
11286 new_coalesce
.n_rules
= n_rules
;
11289 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
11291 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
11292 &new_coalesce
.rules
[i
]);
11299 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
11303 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
11308 cfg80211_rdev_free_coalesce(rdev
);
11309 rdev
->coalesce
= n_coalesce
;
11313 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
11314 tmp_rule
= &new_coalesce
.rules
[i
];
11315 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
11316 kfree(tmp_rule
->patterns
[j
].mask
);
11317 kfree(tmp_rule
->patterns
);
11319 kfree(new_coalesce
.rules
);
11324 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
11326 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11327 struct net_device
*dev
= info
->user_ptr
[1];
11328 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11329 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
11330 struct cfg80211_gtk_rekey_data rekey_data
;
11333 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
11336 err
= nla_parse_nested(tb
, MAX_NL80211_REKEY_DATA
,
11337 info
->attrs
[NL80211_ATTR_REKEY_DATA
],
11338 nl80211_rekey_policy
, info
->extack
);
11342 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
11343 !tb
[NL80211_REKEY_DATA_KCK
])
11345 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
11347 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
11349 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
11352 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
11353 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
11354 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
11357 if (!wdev
->current_bss
) {
11362 if (!rdev
->ops
->set_rekey_data
) {
11367 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
11373 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
11374 struct genl_info
*info
)
11376 struct net_device
*dev
= info
->user_ptr
[1];
11377 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11379 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11380 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
11383 if (wdev
->ap_unexpected_nlportid
)
11386 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
11390 static int nl80211_probe_client(struct sk_buff
*skb
,
11391 struct genl_info
*info
)
11393 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11394 struct net_device
*dev
= info
->user_ptr
[1];
11395 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11396 struct sk_buff
*msg
;
11402 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11403 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
11404 return -EOPNOTSUPP
;
11406 if (!info
->attrs
[NL80211_ATTR_MAC
])
11409 if (!rdev
->ops
->probe_client
)
11410 return -EOPNOTSUPP
;
11412 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11416 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11417 NL80211_CMD_PROBE_CLIENT
);
11423 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11425 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
11429 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11431 goto nla_put_failure
;
11433 genlmsg_end(msg
, hdr
);
11435 return genlmsg_reply(msg
, info
);
11444 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
11446 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11447 struct cfg80211_beacon_registration
*reg
, *nreg
;
11450 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
11451 return -EOPNOTSUPP
;
11453 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
11457 /* First, check if already registered. */
11458 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11459 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
11460 if (reg
->nlportid
== info
->snd_portid
) {
11465 /* Add it to the list */
11466 nreg
->nlportid
= info
->snd_portid
;
11467 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
11469 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11473 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11478 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11480 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11481 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11484 if (!rdev
->ops
->start_p2p_device
)
11485 return -EOPNOTSUPP
;
11487 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11488 return -EOPNOTSUPP
;
11490 if (wdev_running(wdev
))
11493 if (rfkill_blocked(rdev
->rfkill
))
11496 err
= rdev_start_p2p_device(rdev
, wdev
);
11500 wdev
->is_running
= true;
11506 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11508 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11509 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11511 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11512 return -EOPNOTSUPP
;
11514 if (!rdev
->ops
->stop_p2p_device
)
11515 return -EOPNOTSUPP
;
11517 cfg80211_stop_p2p_device(rdev
, wdev
);
11522 static int nl80211_start_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11524 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11525 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11526 struct cfg80211_nan_conf conf
= {};
11529 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11530 return -EOPNOTSUPP
;
11532 if (wdev_running(wdev
))
11535 if (rfkill_blocked(rdev
->rfkill
))
11538 if (!info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
])
11542 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
11543 if (!conf
.master_pref
)
11546 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
11547 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
11549 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
11550 return -EOPNOTSUPP
;
11552 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
11555 conf
.bands
= bands
;
11558 err
= rdev_start_nan(rdev
, wdev
, &conf
);
11562 wdev
->is_running
= true;
11568 static int nl80211_stop_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11570 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11571 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11573 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11574 return -EOPNOTSUPP
;
11576 cfg80211_stop_nan(rdev
, wdev
);
11581 static int validate_nan_filter(struct nlattr
*filter_attr
)
11583 struct nlattr
*attr
;
11584 int len
= 0, n_entries
= 0, rem
;
11586 nla_for_each_nested(attr
, filter_attr
, rem
) {
11587 len
+= nla_len(attr
);
11597 static int handle_nan_filter(struct nlattr
*attr_filter
,
11598 struct cfg80211_nan_func
*func
,
11601 struct nlattr
*attr
;
11602 int n_entries
, rem
, i
;
11603 struct cfg80211_nan_func_filter
*filter
;
11605 n_entries
= validate_nan_filter(attr_filter
);
11609 BUILD_BUG_ON(sizeof(*func
->rx_filters
) != sizeof(*func
->tx_filters
));
11611 filter
= kcalloc(n_entries
, sizeof(*func
->rx_filters
), GFP_KERNEL
);
11616 nla_for_each_nested(attr
, attr_filter
, rem
) {
11617 filter
[i
].filter
= nla_memdup(attr
, GFP_KERNEL
);
11618 filter
[i
].len
= nla_len(attr
);
11622 func
->num_tx_filters
= n_entries
;
11623 func
->tx_filters
= filter
;
11625 func
->num_rx_filters
= n_entries
;
11626 func
->rx_filters
= filter
;
11632 static int nl80211_nan_add_func(struct sk_buff
*skb
,
11633 struct genl_info
*info
)
11635 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11636 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11637 struct nlattr
*tb
[NUM_NL80211_NAN_FUNC_ATTR
], *func_attr
;
11638 struct cfg80211_nan_func
*func
;
11639 struct sk_buff
*msg
= NULL
;
11643 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11644 return -EOPNOTSUPP
;
11646 if (!wdev_running(wdev
))
11649 if (!info
->attrs
[NL80211_ATTR_NAN_FUNC
])
11652 err
= nla_parse_nested(tb
, NL80211_NAN_FUNC_ATTR_MAX
,
11653 info
->attrs
[NL80211_ATTR_NAN_FUNC
],
11654 nl80211_nan_func_policy
, info
->extack
);
11658 func
= kzalloc(sizeof(*func
), GFP_KERNEL
);
11662 func
->cookie
= wdev
->wiphy
->cookie_counter
++;
11664 if (!tb
[NL80211_NAN_FUNC_TYPE
] ||
11665 nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]) > NL80211_NAN_FUNC_MAX_TYPE
) {
11671 func
->type
= nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]);
11673 if (!tb
[NL80211_NAN_FUNC_SERVICE_ID
]) {
11678 memcpy(func
->service_id
, nla_data(tb
[NL80211_NAN_FUNC_SERVICE_ID
]),
11679 sizeof(func
->service_id
));
11681 func
->close_range
=
11682 nla_get_flag(tb
[NL80211_NAN_FUNC_CLOSE_RANGE
]);
11684 if (tb
[NL80211_NAN_FUNC_SERVICE_INFO
]) {
11685 func
->serv_spec_info_len
=
11686 nla_len(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]);
11687 func
->serv_spec_info
=
11688 kmemdup(nla_data(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]),
11689 func
->serv_spec_info_len
,
11691 if (!func
->serv_spec_info
) {
11697 if (tb
[NL80211_NAN_FUNC_TTL
])
11698 func
->ttl
= nla_get_u32(tb
[NL80211_NAN_FUNC_TTL
]);
11700 switch (func
->type
) {
11701 case NL80211_NAN_FUNC_PUBLISH
:
11702 if (!tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]) {
11707 func
->publish_type
=
11708 nla_get_u8(tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]);
11709 func
->publish_bcast
=
11710 nla_get_flag(tb
[NL80211_NAN_FUNC_PUBLISH_BCAST
]);
11712 if ((!(func
->publish_type
& NL80211_NAN_SOLICITED_PUBLISH
)) &&
11713 func
->publish_bcast
) {
11718 case NL80211_NAN_FUNC_SUBSCRIBE
:
11719 func
->subscribe_active
=
11720 nla_get_flag(tb
[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
]);
11722 case NL80211_NAN_FUNC_FOLLOW_UP
:
11723 if (!tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
] ||
11724 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] ||
11725 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]) {
11730 func
->followup_id
=
11731 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
]);
11732 func
->followup_reqid
=
11733 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]);
11734 memcpy(func
->followup_dest
.addr
,
11735 nla_data(tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]),
11736 sizeof(func
->followup_dest
.addr
));
11747 if (tb
[NL80211_NAN_FUNC_SRF
]) {
11748 struct nlattr
*srf_tb
[NUM_NL80211_NAN_SRF_ATTR
];
11750 err
= nla_parse_nested(srf_tb
, NL80211_NAN_SRF_ATTR_MAX
,
11751 tb
[NL80211_NAN_FUNC_SRF
],
11752 nl80211_nan_srf_policy
, info
->extack
);
11756 func
->srf_include
=
11757 nla_get_flag(srf_tb
[NL80211_NAN_SRF_INCLUDE
]);
11759 if (srf_tb
[NL80211_NAN_SRF_BF
]) {
11760 if (srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
] ||
11761 !srf_tb
[NL80211_NAN_SRF_BF_IDX
]) {
11767 nla_len(srf_tb
[NL80211_NAN_SRF_BF
]);
11769 kmemdup(nla_data(srf_tb
[NL80211_NAN_SRF_BF
]),
11770 func
->srf_bf_len
, GFP_KERNEL
);
11771 if (!func
->srf_bf
) {
11777 nla_get_u8(srf_tb
[NL80211_NAN_SRF_BF_IDX
]);
11779 struct nlattr
*attr
, *mac_attr
=
11780 srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
];
11781 int n_entries
, rem
, i
= 0;
11788 n_entries
= validate_acl_mac_addrs(mac_attr
);
11789 if (n_entries
<= 0) {
11794 func
->srf_num_macs
= n_entries
;
11796 kcalloc(n_entries
, sizeof(*func
->srf_macs
),
11798 if (!func
->srf_macs
) {
11803 nla_for_each_nested(attr
, mac_attr
, rem
)
11804 memcpy(func
->srf_macs
[i
++].addr
, nla_data(attr
),
11805 sizeof(*func
->srf_macs
));
11809 if (tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
]) {
11810 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
],
11816 if (tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
]) {
11817 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
],
11823 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11829 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11830 NL80211_CMD_ADD_NAN_FUNCTION
);
11831 /* This can't really happen - we just allocated 4KB */
11832 if (WARN_ON(!hdr
)) {
11837 err
= rdev_add_nan_func(rdev
, wdev
, func
);
11840 cfg80211_free_nan_func(func
);
11845 /* propagate the instance id and cookie to userspace */
11846 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, func
->cookie
,
11848 goto nla_put_failure
;
11850 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
11852 goto nla_put_failure
;
11854 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
,
11855 func
->instance_id
))
11856 goto nla_put_failure
;
11858 nla_nest_end(msg
, func_attr
);
11860 genlmsg_end(msg
, hdr
);
11861 return genlmsg_reply(msg
, info
);
11868 static int nl80211_nan_del_func(struct sk_buff
*skb
,
11869 struct genl_info
*info
)
11871 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11872 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11875 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11876 return -EOPNOTSUPP
;
11878 if (!wdev_running(wdev
))
11881 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
11884 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
11886 rdev_del_nan_func(rdev
, wdev
, cookie
);
11891 static int nl80211_nan_change_config(struct sk_buff
*skb
,
11892 struct genl_info
*info
)
11894 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11895 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11896 struct cfg80211_nan_conf conf
= {};
11899 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11900 return -EOPNOTSUPP
;
11902 if (!wdev_running(wdev
))
11905 if (info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]) {
11907 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
11908 if (conf
.master_pref
<= 1 || conf
.master_pref
== 255)
11911 changed
|= CFG80211_NAN_CONF_CHANGED_PREF
;
11914 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
11915 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
11917 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
11918 return -EOPNOTSUPP
;
11920 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
11923 conf
.bands
= bands
;
11924 changed
|= CFG80211_NAN_CONF_CHANGED_BANDS
;
11930 return rdev_nan_change_conf(rdev
, wdev
, &conf
, changed
);
11933 void cfg80211_nan_match(struct wireless_dev
*wdev
,
11934 struct cfg80211_nan_match_params
*match
, gfp_t gfp
)
11936 struct wiphy
*wiphy
= wdev
->wiphy
;
11937 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11938 struct nlattr
*match_attr
, *local_func_attr
, *peer_func_attr
;
11939 struct sk_buff
*msg
;
11942 if (WARN_ON(!match
->inst_id
|| !match
->peer_inst_id
|| !match
->addr
))
11945 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11949 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NAN_MATCH
);
11955 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11956 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11957 wdev
->netdev
->ifindex
)) ||
11958 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
11960 goto nla_put_failure
;
11962 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, match
->cookie
,
11963 NL80211_ATTR_PAD
) ||
11964 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, match
->addr
))
11965 goto nla_put_failure
;
11967 match_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_MATCH
);
11969 goto nla_put_failure
;
11971 local_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_LOCAL
);
11972 if (!local_func_attr
)
11973 goto nla_put_failure
;
11975 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->inst_id
))
11976 goto nla_put_failure
;
11978 nla_nest_end(msg
, local_func_attr
);
11980 peer_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_PEER
);
11981 if (!peer_func_attr
)
11982 goto nla_put_failure
;
11984 if (nla_put_u8(msg
, NL80211_NAN_FUNC_TYPE
, match
->type
) ||
11985 nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->peer_inst_id
))
11986 goto nla_put_failure
;
11988 if (match
->info
&& match
->info_len
&&
11989 nla_put(msg
, NL80211_NAN_FUNC_SERVICE_INFO
, match
->info_len
,
11991 goto nla_put_failure
;
11993 nla_nest_end(msg
, peer_func_attr
);
11994 nla_nest_end(msg
, match_attr
);
11995 genlmsg_end(msg
, hdr
);
11997 if (!wdev
->owner_nlportid
)
11998 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
11999 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
12001 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
12002 wdev
->owner_nlportid
);
12009 EXPORT_SYMBOL(cfg80211_nan_match
);
12011 void cfg80211_nan_func_terminated(struct wireless_dev
*wdev
,
12013 enum nl80211_nan_func_term_reason reason
,
12014 u64 cookie
, gfp_t gfp
)
12016 struct wiphy
*wiphy
= wdev
->wiphy
;
12017 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12018 struct sk_buff
*msg
;
12019 struct nlattr
*func_attr
;
12022 if (WARN_ON(!inst_id
))
12025 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12029 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION
);
12035 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12036 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12037 wdev
->netdev
->ifindex
)) ||
12038 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12040 goto nla_put_failure
;
12042 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
12044 goto nla_put_failure
;
12046 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
12048 goto nla_put_failure
;
12050 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, inst_id
) ||
12051 nla_put_u8(msg
, NL80211_NAN_FUNC_TERM_REASON
, reason
))
12052 goto nla_put_failure
;
12054 nla_nest_end(msg
, func_attr
);
12055 genlmsg_end(msg
, hdr
);
12057 if (!wdev
->owner_nlportid
)
12058 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
12059 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
12061 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
12062 wdev
->owner_nlportid
);
12069 EXPORT_SYMBOL(cfg80211_nan_func_terminated
);
12071 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
12072 struct genl_info
*info
)
12075 struct sk_buff
*msg
;
12077 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12081 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12082 NL80211_CMD_GET_PROTOCOL_FEATURES
);
12084 goto nla_put_failure
;
12086 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
12087 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
12088 goto nla_put_failure
;
12090 genlmsg_end(msg
, hdr
);
12091 return genlmsg_reply(msg
, info
);
12098 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
12100 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12101 struct cfg80211_update_ft_ies_params ft_params
;
12102 struct net_device
*dev
= info
->user_ptr
[1];
12104 if (!rdev
->ops
->update_ft_ies
)
12105 return -EOPNOTSUPP
;
12107 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
12108 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
12111 memset(&ft_params
, 0, sizeof(ft_params
));
12112 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
12113 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
12114 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
12116 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
12119 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
12120 struct genl_info
*info
)
12122 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12123 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12124 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
12128 if (!rdev
->ops
->crit_proto_start
)
12129 return -EOPNOTSUPP
;
12131 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
12134 if (rdev
->crit_proto_nlportid
)
12137 /* determine protocol if provided */
12138 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
12139 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
12141 if (proto
>= NUM_NL80211_CRIT_PROTO
)
12144 /* timeout must be provided */
12145 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
12149 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
12151 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
12154 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
12156 rdev
->crit_proto_nlportid
= info
->snd_portid
;
12161 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
12162 struct genl_info
*info
)
12164 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12165 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12167 if (!rdev
->ops
->crit_proto_stop
)
12168 return -EOPNOTSUPP
;
12170 if (rdev
->crit_proto_nlportid
) {
12171 rdev
->crit_proto_nlportid
= 0;
12172 rdev_crit_proto_stop(rdev
, wdev
);
12177 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
12179 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12180 struct wireless_dev
*wdev
=
12181 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
12185 if (!rdev
->wiphy
.vendor_commands
)
12186 return -EOPNOTSUPP
;
12188 if (IS_ERR(wdev
)) {
12189 err
= PTR_ERR(wdev
);
12190 if (err
!= -EINVAL
)
12193 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
12197 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
12198 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
12201 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
12202 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
12203 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
12204 const struct wiphy_vendor_command
*vcmd
;
12208 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
12210 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
12213 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
12214 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
12217 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
12221 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
12222 if (!wdev_running(wdev
))
12227 return -EOPNOTSUPP
;
12232 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
12233 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
12234 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
12237 rdev
->cur_cmd_info
= info
;
12238 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
12240 rdev
->cur_cmd_info
= NULL
;
12244 return -EOPNOTSUPP
;
12247 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
12248 struct netlink_callback
*cb
,
12249 struct cfg80211_registered_device
**rdev
,
12250 struct wireless_dev
**wdev
)
12252 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
12258 unsigned int data_len
= 0;
12261 /* subtract the 1 again here */
12262 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
12263 struct wireless_dev
*tmp
;
12267 *rdev
= wiphy_to_rdev(wiphy
);
12271 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
12272 if (tmp
->identifier
== cb
->args
[1] - 1) {
12279 /* keep rtnl locked in successful case */
12283 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, attrbuf
,
12284 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
12288 if (!attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
12289 !attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
])
12292 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
12296 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
12298 return PTR_ERR(*rdev
);
12300 vid
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_ID
]);
12301 subcmd
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
12303 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
12304 const struct wiphy_vendor_command
*vcmd
;
12306 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
12308 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
12312 return -EOPNOTSUPP
;
12319 return -EOPNOTSUPP
;
12321 if (attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
12322 data
= nla_data(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
12323 data_len
= nla_len(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
12326 /* 0 is the first index - add 1 to parse only once */
12327 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
12328 /* add 1 to know if it was NULL */
12329 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
12330 cb
->args
[2] = vcmd_idx
;
12331 cb
->args
[3] = (unsigned long)data
;
12332 cb
->args
[4] = data_len
;
12334 /* keep rtnl locked in successful case */
12338 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
12339 struct netlink_callback
*cb
)
12341 struct cfg80211_registered_device
*rdev
;
12342 struct wireless_dev
*wdev
;
12343 unsigned int vcmd_idx
;
12344 const struct wiphy_vendor_command
*vcmd
;
12348 struct nlattr
*vendor_data
;
12351 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
12355 vcmd_idx
= cb
->args
[2];
12356 data
= (void *)cb
->args
[3];
12357 data_len
= cb
->args
[4];
12358 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
12360 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
12361 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
12366 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
12372 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
12373 if (!wdev_running(wdev
)) {
12381 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
12382 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
12383 NL80211_CMD_VENDOR
);
12387 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12388 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
12390 NL80211_ATTR_PAD
))) {
12391 genlmsg_cancel(skb
, hdr
);
12395 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
12396 if (!vendor_data
) {
12397 genlmsg_cancel(skb
, hdr
);
12401 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
12402 (unsigned long *)&cb
->args
[5]);
12403 nla_nest_end(skb
, vendor_data
);
12405 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
12406 genlmsg_cancel(skb
, hdr
);
12409 genlmsg_cancel(skb
, hdr
);
12413 genlmsg_end(skb
, hdr
);
12422 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
12423 enum nl80211_commands cmd
,
12424 enum nl80211_attrs attr
,
12427 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12429 if (WARN_ON(!rdev
->cur_cmd_info
))
12432 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
12433 rdev
->cur_cmd_info
->snd_portid
,
12434 rdev
->cur_cmd_info
->snd_seq
,
12435 cmd
, attr
, NULL
, GFP_KERNEL
);
12437 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
12439 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
12441 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
12442 void *hdr
= ((void **)skb
->cb
)[1];
12443 struct nlattr
*data
= ((void **)skb
->cb
)[2];
12445 /* clear CB data for netlink core to own from now on */
12446 memset(skb
->cb
, 0, sizeof(skb
->cb
));
12448 if (WARN_ON(!rdev
->cur_cmd_info
)) {
12453 nla_nest_end(skb
, data
);
12454 genlmsg_end(skb
, hdr
);
12455 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
12457 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
12459 static int nl80211_set_qos_map(struct sk_buff
*skb
,
12460 struct genl_info
*info
)
12462 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12463 struct cfg80211_qos_map
*qos_map
= NULL
;
12464 struct net_device
*dev
= info
->user_ptr
[1];
12465 u8
*pos
, len
, num_des
, des_len
, des
;
12468 if (!rdev
->ops
->set_qos_map
)
12469 return -EOPNOTSUPP
;
12471 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
12472 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12473 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12475 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
12476 len
> IEEE80211_QOS_MAP_LEN_MAX
)
12479 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
12483 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
12485 des_len
= num_des
*
12486 sizeof(struct cfg80211_dscp_exception
);
12487 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
12488 qos_map
->num_des
= num_des
;
12489 for (des
= 0; des
< num_des
; des
++) {
12490 if (qos_map
->dscp_exception
[des
].up
> 7) {
12497 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
12500 wdev_lock(dev
->ieee80211_ptr
);
12501 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
12503 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
12504 wdev_unlock(dev
->ieee80211_ptr
);
12510 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12512 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12513 struct net_device
*dev
= info
->user_ptr
[1];
12514 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12517 u16 admitted_time
= 0;
12520 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
12521 return -EOPNOTSUPP
;
12523 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
12524 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
12527 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12528 if (tsid
>= IEEE80211_NUM_TIDS
)
12531 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
12532 if (up
>= IEEE80211_NUM_UPS
)
12535 /* WMM uses TIDs 0-7 even for TSPEC */
12536 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
12537 /* TODO: handle 802.11 TSPEC/admission control
12538 * need more attributes for that (e.g. BA session requirement);
12539 * change the WMM adminssion test above to allow both then
12544 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12546 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
12548 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
12549 if (!admitted_time
)
12554 switch (wdev
->iftype
) {
12555 case NL80211_IFTYPE_STATION
:
12556 case NL80211_IFTYPE_P2P_CLIENT
:
12557 if (wdev
->current_bss
)
12566 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
12573 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12575 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12576 struct net_device
*dev
= info
->user_ptr
[1];
12577 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12582 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
12585 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12586 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12589 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
12595 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
12596 struct genl_info
*info
)
12598 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12599 struct net_device
*dev
= info
->user_ptr
[1];
12600 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12601 struct cfg80211_chan_def chandef
= {};
12606 if (!rdev
->ops
->tdls_channel_switch
||
12607 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12608 return -EOPNOTSUPP
;
12610 switch (dev
->ieee80211_ptr
->iftype
) {
12611 case NL80211_IFTYPE_STATION
:
12612 case NL80211_IFTYPE_P2P_CLIENT
:
12615 return -EOPNOTSUPP
;
12618 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
12619 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
12622 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
12627 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12628 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12629 * specification is not defined for them.
12631 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
12632 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
12633 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
12636 /* we will be active on the TDLS link */
12637 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
12641 /* don't allow switching to DFS channels */
12642 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
12645 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12646 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
12649 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
12655 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
12656 struct genl_info
*info
)
12658 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12659 struct net_device
*dev
= info
->user_ptr
[1];
12660 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12663 if (!rdev
->ops
->tdls_channel_switch
||
12664 !rdev
->ops
->tdls_cancel_channel_switch
||
12665 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12666 return -EOPNOTSUPP
;
12668 switch (dev
->ieee80211_ptr
->iftype
) {
12669 case NL80211_IFTYPE_STATION
:
12670 case NL80211_IFTYPE_P2P_CLIENT
:
12673 return -EOPNOTSUPP
;
12676 if (!info
->attrs
[NL80211_ATTR_MAC
])
12679 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12682 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
12688 static int nl80211_set_multicast_to_unicast(struct sk_buff
*skb
,
12689 struct genl_info
*info
)
12691 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12692 struct net_device
*dev
= info
->user_ptr
[1];
12693 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12694 const struct nlattr
*nla
;
12697 if (!rdev
->ops
->set_multicast_to_unicast
)
12698 return -EOPNOTSUPP
;
12700 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12701 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12702 return -EOPNOTSUPP
;
12704 nla
= info
->attrs
[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
];
12705 enabled
= nla_get_flag(nla
);
12707 return rdev_set_multicast_to_unicast(rdev
, dev
, enabled
);
12710 static int nl80211_set_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12712 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12713 struct net_device
*dev
= info
->user_ptr
[1];
12714 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12715 struct cfg80211_pmk_conf pmk_conf
= {};
12718 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12719 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12720 return -EOPNOTSUPP
;
12722 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12723 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12724 return -EOPNOTSUPP
;
12726 if (!info
->attrs
[NL80211_ATTR_MAC
] || !info
->attrs
[NL80211_ATTR_PMK
])
12730 if (!wdev
->current_bss
) {
12735 pmk_conf
.aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12736 if (memcmp(pmk_conf
.aa
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
)) {
12741 pmk_conf
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
12742 pmk_conf
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
12743 if (pmk_conf
.pmk_len
!= WLAN_PMK_LEN
&&
12744 pmk_conf
.pmk_len
!= WLAN_PMK_LEN_SUITE_B_192
) {
12749 if (info
->attrs
[NL80211_ATTR_PMKR0_NAME
]) {
12750 int r0_name_len
= nla_len(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12752 if (r0_name_len
!= WLAN_PMK_NAME_LEN
) {
12757 pmk_conf
.pmk_r0_name
=
12758 nla_data(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12761 ret
= rdev_set_pmk(rdev
, dev
, &pmk_conf
);
12767 static int nl80211_del_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12769 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12770 struct net_device
*dev
= info
->user_ptr
[1];
12771 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12775 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12776 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12777 return -EOPNOTSUPP
;
12779 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12780 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12781 return -EOPNOTSUPP
;
12783 if (!info
->attrs
[NL80211_ATTR_MAC
])
12787 aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12788 ret
= rdev_del_pmk(rdev
, dev
, aa
);
12794 static int nl80211_external_auth(struct sk_buff
*skb
, struct genl_info
*info
)
12796 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12797 struct net_device
*dev
= info
->user_ptr
[1];
12798 struct cfg80211_external_auth_params params
;
12800 if (!rdev
->ops
->external_auth
)
12801 return -EOPNOTSUPP
;
12803 if (!info
->attrs
[NL80211_ATTR_SSID
])
12806 if (!info
->attrs
[NL80211_ATTR_BSSID
])
12809 if (!info
->attrs
[NL80211_ATTR_STATUS_CODE
])
12812 memset(¶ms
, 0, sizeof(params
));
12814 params
.ssid
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
12815 if (params
.ssid
.ssid_len
== 0 ||
12816 params
.ssid
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
12818 memcpy(params
.ssid
.ssid
, nla_data(info
->attrs
[NL80211_ATTR_SSID
]),
12819 params
.ssid
.ssid_len
);
12821 memcpy(params
.bssid
, nla_data(info
->attrs
[NL80211_ATTR_BSSID
]),
12824 params
.status
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
12826 return rdev_external_auth(rdev
, dev
, ¶ms
);
12829 static int nl80211_tx_control_port(struct sk_buff
*skb
, struct genl_info
*info
)
12831 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12832 struct net_device
*dev
= info
->user_ptr
[1];
12833 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12841 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12842 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
12843 return -EOPNOTSUPP
;
12845 if (!rdev
->ops
->tx_control_port
)
12846 return -EOPNOTSUPP
;
12848 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
12849 !info
->attrs
[NL80211_ATTR_MAC
] ||
12850 !info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
12851 GENL_SET_ERR_MSG(info
, "Frame, MAC or ethertype missing");
12857 switch (wdev
->iftype
) {
12858 case NL80211_IFTYPE_AP
:
12859 case NL80211_IFTYPE_P2P_GO
:
12860 case NL80211_IFTYPE_MESH_POINT
:
12862 case NL80211_IFTYPE_ADHOC
:
12863 case NL80211_IFTYPE_STATION
:
12864 case NL80211_IFTYPE_P2P_CLIENT
:
12865 if (wdev
->current_bss
)
12876 buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
12877 len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
12878 dest
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12879 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
12881 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
]);
12883 return rdev_tx_control_port(rdev
, dev
, buf
, len
,
12884 dest
, cpu_to_be16(proto
), noencrypt
);
12891 #define NL80211_FLAG_NEED_WIPHY 0x01
12892 #define NL80211_FLAG_NEED_NETDEV 0x02
12893 #define NL80211_FLAG_NEED_RTNL 0x04
12894 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12895 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12896 NL80211_FLAG_CHECK_NETDEV_UP)
12897 #define NL80211_FLAG_NEED_WDEV 0x10
12898 /* If a netdev is associated, it must be UP, P2P must be started */
12899 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12900 NL80211_FLAG_CHECK_NETDEV_UP)
12901 #define NL80211_FLAG_CLEAR_SKB 0x20
12903 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
12904 struct genl_info
*info
)
12906 struct cfg80211_registered_device
*rdev
;
12907 struct wireless_dev
*wdev
;
12908 struct net_device
*dev
;
12909 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
12914 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
12915 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
12916 if (IS_ERR(rdev
)) {
12919 return PTR_ERR(rdev
);
12921 info
->user_ptr
[0] = rdev
;
12922 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
12923 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
12926 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
12928 if (IS_ERR(wdev
)) {
12931 return PTR_ERR(wdev
);
12934 dev
= wdev
->netdev
;
12935 rdev
= wiphy_to_rdev(wdev
->wiphy
);
12937 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
12944 info
->user_ptr
[1] = dev
;
12946 info
->user_ptr
[1] = wdev
;
12949 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
12950 !wdev_running(wdev
)) {
12959 info
->user_ptr
[0] = rdev
;
12965 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
12966 struct genl_info
*info
)
12968 if (info
->user_ptr
[1]) {
12969 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
12970 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12973 dev_put(wdev
->netdev
);
12975 dev_put(info
->user_ptr
[1]);
12979 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
12982 /* If needed, clear the netlink message payload from the SKB
12983 * as it might contain key data that shouldn't stick around on
12984 * the heap after the SKB is freed. The netlink message header
12985 * is still needed for further processing, so leave it intact.
12987 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
12988 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
12990 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
12994 static const struct genl_ops nl80211_ops
[] = {
12996 .cmd
= NL80211_CMD_GET_WIPHY
,
12997 .doit
= nl80211_get_wiphy
,
12998 .dumpit
= nl80211_dump_wiphy
,
12999 .done
= nl80211_dump_wiphy_done
,
13000 .policy
= nl80211_policy
,
13001 /* can be retrieved by unprivileged users */
13002 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13003 NL80211_FLAG_NEED_RTNL
,
13006 .cmd
= NL80211_CMD_SET_WIPHY
,
13007 .doit
= nl80211_set_wiphy
,
13008 .policy
= nl80211_policy
,
13009 .flags
= GENL_UNS_ADMIN_PERM
,
13010 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
13013 .cmd
= NL80211_CMD_GET_INTERFACE
,
13014 .doit
= nl80211_get_interface
,
13015 .dumpit
= nl80211_dump_interface
,
13016 .policy
= nl80211_policy
,
13017 /* can be retrieved by unprivileged users */
13018 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13019 NL80211_FLAG_NEED_RTNL
,
13022 .cmd
= NL80211_CMD_SET_INTERFACE
,
13023 .doit
= nl80211_set_interface
,
13024 .policy
= nl80211_policy
,
13025 .flags
= GENL_UNS_ADMIN_PERM
,
13026 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13027 NL80211_FLAG_NEED_RTNL
,
13030 .cmd
= NL80211_CMD_NEW_INTERFACE
,
13031 .doit
= nl80211_new_interface
,
13032 .policy
= nl80211_policy
,
13033 .flags
= GENL_UNS_ADMIN_PERM
,
13034 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13035 NL80211_FLAG_NEED_RTNL
,
13038 .cmd
= NL80211_CMD_DEL_INTERFACE
,
13039 .doit
= nl80211_del_interface
,
13040 .policy
= nl80211_policy
,
13041 .flags
= GENL_UNS_ADMIN_PERM
,
13042 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13043 NL80211_FLAG_NEED_RTNL
,
13046 .cmd
= NL80211_CMD_GET_KEY
,
13047 .doit
= nl80211_get_key
,
13048 .policy
= nl80211_policy
,
13049 .flags
= GENL_UNS_ADMIN_PERM
,
13050 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13051 NL80211_FLAG_NEED_RTNL
,
13054 .cmd
= NL80211_CMD_SET_KEY
,
13055 .doit
= nl80211_set_key
,
13056 .policy
= nl80211_policy
,
13057 .flags
= GENL_UNS_ADMIN_PERM
,
13058 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13059 NL80211_FLAG_NEED_RTNL
|
13060 NL80211_FLAG_CLEAR_SKB
,
13063 .cmd
= NL80211_CMD_NEW_KEY
,
13064 .doit
= nl80211_new_key
,
13065 .policy
= nl80211_policy
,
13066 .flags
= GENL_UNS_ADMIN_PERM
,
13067 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13068 NL80211_FLAG_NEED_RTNL
|
13069 NL80211_FLAG_CLEAR_SKB
,
13072 .cmd
= NL80211_CMD_DEL_KEY
,
13073 .doit
= nl80211_del_key
,
13074 .policy
= nl80211_policy
,
13075 .flags
= GENL_UNS_ADMIN_PERM
,
13076 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13077 NL80211_FLAG_NEED_RTNL
,
13080 .cmd
= NL80211_CMD_SET_BEACON
,
13081 .policy
= nl80211_policy
,
13082 .flags
= GENL_UNS_ADMIN_PERM
,
13083 .doit
= nl80211_set_beacon
,
13084 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13085 NL80211_FLAG_NEED_RTNL
,
13088 .cmd
= NL80211_CMD_START_AP
,
13089 .policy
= nl80211_policy
,
13090 .flags
= GENL_UNS_ADMIN_PERM
,
13091 .doit
= nl80211_start_ap
,
13092 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13093 NL80211_FLAG_NEED_RTNL
,
13096 .cmd
= NL80211_CMD_STOP_AP
,
13097 .policy
= nl80211_policy
,
13098 .flags
= GENL_UNS_ADMIN_PERM
,
13099 .doit
= nl80211_stop_ap
,
13100 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13101 NL80211_FLAG_NEED_RTNL
,
13104 .cmd
= NL80211_CMD_GET_STATION
,
13105 .doit
= nl80211_get_station
,
13106 .dumpit
= nl80211_dump_station
,
13107 .policy
= nl80211_policy
,
13108 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13109 NL80211_FLAG_NEED_RTNL
,
13112 .cmd
= NL80211_CMD_SET_STATION
,
13113 .doit
= nl80211_set_station
,
13114 .policy
= nl80211_policy
,
13115 .flags
= GENL_UNS_ADMIN_PERM
,
13116 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13117 NL80211_FLAG_NEED_RTNL
,
13120 .cmd
= NL80211_CMD_NEW_STATION
,
13121 .doit
= nl80211_new_station
,
13122 .policy
= nl80211_policy
,
13123 .flags
= GENL_UNS_ADMIN_PERM
,
13124 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13125 NL80211_FLAG_NEED_RTNL
,
13128 .cmd
= NL80211_CMD_DEL_STATION
,
13129 .doit
= nl80211_del_station
,
13130 .policy
= nl80211_policy
,
13131 .flags
= GENL_UNS_ADMIN_PERM
,
13132 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13133 NL80211_FLAG_NEED_RTNL
,
13136 .cmd
= NL80211_CMD_GET_MPATH
,
13137 .doit
= nl80211_get_mpath
,
13138 .dumpit
= nl80211_dump_mpath
,
13139 .policy
= nl80211_policy
,
13140 .flags
= GENL_UNS_ADMIN_PERM
,
13141 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13142 NL80211_FLAG_NEED_RTNL
,
13145 .cmd
= NL80211_CMD_GET_MPP
,
13146 .doit
= nl80211_get_mpp
,
13147 .dumpit
= nl80211_dump_mpp
,
13148 .policy
= nl80211_policy
,
13149 .flags
= GENL_UNS_ADMIN_PERM
,
13150 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13151 NL80211_FLAG_NEED_RTNL
,
13154 .cmd
= NL80211_CMD_SET_MPATH
,
13155 .doit
= nl80211_set_mpath
,
13156 .policy
= nl80211_policy
,
13157 .flags
= GENL_UNS_ADMIN_PERM
,
13158 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13159 NL80211_FLAG_NEED_RTNL
,
13162 .cmd
= NL80211_CMD_NEW_MPATH
,
13163 .doit
= nl80211_new_mpath
,
13164 .policy
= nl80211_policy
,
13165 .flags
= GENL_UNS_ADMIN_PERM
,
13166 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13167 NL80211_FLAG_NEED_RTNL
,
13170 .cmd
= NL80211_CMD_DEL_MPATH
,
13171 .doit
= nl80211_del_mpath
,
13172 .policy
= nl80211_policy
,
13173 .flags
= GENL_UNS_ADMIN_PERM
,
13174 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13175 NL80211_FLAG_NEED_RTNL
,
13178 .cmd
= NL80211_CMD_SET_BSS
,
13179 .doit
= nl80211_set_bss
,
13180 .policy
= nl80211_policy
,
13181 .flags
= GENL_UNS_ADMIN_PERM
,
13182 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13183 NL80211_FLAG_NEED_RTNL
,
13186 .cmd
= NL80211_CMD_GET_REG
,
13187 .doit
= nl80211_get_reg_do
,
13188 .dumpit
= nl80211_get_reg_dump
,
13189 .policy
= nl80211_policy
,
13190 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
13191 /* can be retrieved by unprivileged users */
13193 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
13195 .cmd
= NL80211_CMD_SET_REG
,
13196 .doit
= nl80211_set_reg
,
13197 .policy
= nl80211_policy
,
13198 .flags
= GENL_ADMIN_PERM
,
13199 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
13203 .cmd
= NL80211_CMD_REQ_SET_REG
,
13204 .doit
= nl80211_req_set_reg
,
13205 .policy
= nl80211_policy
,
13206 .flags
= GENL_ADMIN_PERM
,
13209 .cmd
= NL80211_CMD_RELOAD_REGDB
,
13210 .doit
= nl80211_reload_regdb
,
13211 .policy
= nl80211_policy
,
13212 .flags
= GENL_ADMIN_PERM
,
13215 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
13216 .doit
= nl80211_get_mesh_config
,
13217 .policy
= nl80211_policy
,
13218 /* can be retrieved by unprivileged users */
13219 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13220 NL80211_FLAG_NEED_RTNL
,
13223 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
13224 .doit
= nl80211_update_mesh_config
,
13225 .policy
= nl80211_policy
,
13226 .flags
= GENL_UNS_ADMIN_PERM
,
13227 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13228 NL80211_FLAG_NEED_RTNL
,
13231 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
13232 .doit
= nl80211_trigger_scan
,
13233 .policy
= nl80211_policy
,
13234 .flags
= GENL_UNS_ADMIN_PERM
,
13235 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13236 NL80211_FLAG_NEED_RTNL
,
13239 .cmd
= NL80211_CMD_ABORT_SCAN
,
13240 .doit
= nl80211_abort_scan
,
13241 .policy
= nl80211_policy
,
13242 .flags
= GENL_UNS_ADMIN_PERM
,
13243 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13244 NL80211_FLAG_NEED_RTNL
,
13247 .cmd
= NL80211_CMD_GET_SCAN
,
13248 .policy
= nl80211_policy
,
13249 .dumpit
= nl80211_dump_scan
,
13252 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
13253 .doit
= nl80211_start_sched_scan
,
13254 .policy
= nl80211_policy
,
13255 .flags
= GENL_UNS_ADMIN_PERM
,
13256 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13257 NL80211_FLAG_NEED_RTNL
,
13260 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
13261 .doit
= nl80211_stop_sched_scan
,
13262 .policy
= nl80211_policy
,
13263 .flags
= GENL_UNS_ADMIN_PERM
,
13264 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13265 NL80211_FLAG_NEED_RTNL
,
13268 .cmd
= NL80211_CMD_AUTHENTICATE
,
13269 .doit
= nl80211_authenticate
,
13270 .policy
= nl80211_policy
,
13271 .flags
= GENL_UNS_ADMIN_PERM
,
13272 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13273 NL80211_FLAG_NEED_RTNL
|
13274 NL80211_FLAG_CLEAR_SKB
,
13277 .cmd
= NL80211_CMD_ASSOCIATE
,
13278 .doit
= nl80211_associate
,
13279 .policy
= nl80211_policy
,
13280 .flags
= GENL_UNS_ADMIN_PERM
,
13281 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13282 NL80211_FLAG_NEED_RTNL
,
13285 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
13286 .doit
= nl80211_deauthenticate
,
13287 .policy
= nl80211_policy
,
13288 .flags
= GENL_UNS_ADMIN_PERM
,
13289 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13290 NL80211_FLAG_NEED_RTNL
,
13293 .cmd
= NL80211_CMD_DISASSOCIATE
,
13294 .doit
= nl80211_disassociate
,
13295 .policy
= nl80211_policy
,
13296 .flags
= GENL_UNS_ADMIN_PERM
,
13297 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13298 NL80211_FLAG_NEED_RTNL
,
13301 .cmd
= NL80211_CMD_JOIN_IBSS
,
13302 .doit
= nl80211_join_ibss
,
13303 .policy
= nl80211_policy
,
13304 .flags
= GENL_UNS_ADMIN_PERM
,
13305 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13306 NL80211_FLAG_NEED_RTNL
,
13309 .cmd
= NL80211_CMD_LEAVE_IBSS
,
13310 .doit
= nl80211_leave_ibss
,
13311 .policy
= nl80211_policy
,
13312 .flags
= GENL_UNS_ADMIN_PERM
,
13313 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13314 NL80211_FLAG_NEED_RTNL
,
13316 #ifdef CONFIG_NL80211_TESTMODE
13318 .cmd
= NL80211_CMD_TESTMODE
,
13319 .doit
= nl80211_testmode_do
,
13320 .dumpit
= nl80211_testmode_dump
,
13321 .policy
= nl80211_policy
,
13322 .flags
= GENL_UNS_ADMIN_PERM
,
13323 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13324 NL80211_FLAG_NEED_RTNL
,
13328 .cmd
= NL80211_CMD_CONNECT
,
13329 .doit
= nl80211_connect
,
13330 .policy
= nl80211_policy
,
13331 .flags
= GENL_UNS_ADMIN_PERM
,
13332 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13333 NL80211_FLAG_NEED_RTNL
,
13336 .cmd
= NL80211_CMD_UPDATE_CONNECT_PARAMS
,
13337 .doit
= nl80211_update_connect_params
,
13338 .policy
= nl80211_policy
,
13339 .flags
= GENL_ADMIN_PERM
,
13340 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13341 NL80211_FLAG_NEED_RTNL
,
13344 .cmd
= NL80211_CMD_DISCONNECT
,
13345 .doit
= nl80211_disconnect
,
13346 .policy
= nl80211_policy
,
13347 .flags
= GENL_UNS_ADMIN_PERM
,
13348 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13349 NL80211_FLAG_NEED_RTNL
,
13352 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
13353 .doit
= nl80211_wiphy_netns
,
13354 .policy
= nl80211_policy
,
13355 .flags
= GENL_UNS_ADMIN_PERM
,
13356 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13357 NL80211_FLAG_NEED_RTNL
,
13360 .cmd
= NL80211_CMD_GET_SURVEY
,
13361 .policy
= nl80211_policy
,
13362 .dumpit
= nl80211_dump_survey
,
13365 .cmd
= NL80211_CMD_SET_PMKSA
,
13366 .doit
= nl80211_setdel_pmksa
,
13367 .policy
= nl80211_policy
,
13368 .flags
= GENL_UNS_ADMIN_PERM
,
13369 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13370 NL80211_FLAG_NEED_RTNL
,
13373 .cmd
= NL80211_CMD_DEL_PMKSA
,
13374 .doit
= nl80211_setdel_pmksa
,
13375 .policy
= nl80211_policy
,
13376 .flags
= GENL_UNS_ADMIN_PERM
,
13377 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13378 NL80211_FLAG_NEED_RTNL
,
13381 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
13382 .doit
= nl80211_flush_pmksa
,
13383 .policy
= nl80211_policy
,
13384 .flags
= GENL_UNS_ADMIN_PERM
,
13385 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13386 NL80211_FLAG_NEED_RTNL
,
13389 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
13390 .doit
= nl80211_remain_on_channel
,
13391 .policy
= nl80211_policy
,
13392 .flags
= GENL_UNS_ADMIN_PERM
,
13393 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13394 NL80211_FLAG_NEED_RTNL
,
13397 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
13398 .doit
= nl80211_cancel_remain_on_channel
,
13399 .policy
= nl80211_policy
,
13400 .flags
= GENL_UNS_ADMIN_PERM
,
13401 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13402 NL80211_FLAG_NEED_RTNL
,
13405 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
13406 .doit
= nl80211_set_tx_bitrate_mask
,
13407 .policy
= nl80211_policy
,
13408 .flags
= GENL_UNS_ADMIN_PERM
,
13409 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13410 NL80211_FLAG_NEED_RTNL
,
13413 .cmd
= NL80211_CMD_REGISTER_FRAME
,
13414 .doit
= nl80211_register_mgmt
,
13415 .policy
= nl80211_policy
,
13416 .flags
= GENL_UNS_ADMIN_PERM
,
13417 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13418 NL80211_FLAG_NEED_RTNL
,
13421 .cmd
= NL80211_CMD_FRAME
,
13422 .doit
= nl80211_tx_mgmt
,
13423 .policy
= nl80211_policy
,
13424 .flags
= GENL_UNS_ADMIN_PERM
,
13425 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13426 NL80211_FLAG_NEED_RTNL
,
13429 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
13430 .doit
= nl80211_tx_mgmt_cancel_wait
,
13431 .policy
= nl80211_policy
,
13432 .flags
= GENL_UNS_ADMIN_PERM
,
13433 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13434 NL80211_FLAG_NEED_RTNL
,
13437 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
13438 .doit
= nl80211_set_power_save
,
13439 .policy
= nl80211_policy
,
13440 .flags
= GENL_UNS_ADMIN_PERM
,
13441 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13442 NL80211_FLAG_NEED_RTNL
,
13445 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
13446 .doit
= nl80211_get_power_save
,
13447 .policy
= nl80211_policy
,
13448 /* can be retrieved by unprivileged users */
13449 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13450 NL80211_FLAG_NEED_RTNL
,
13453 .cmd
= NL80211_CMD_SET_CQM
,
13454 .doit
= nl80211_set_cqm
,
13455 .policy
= nl80211_policy
,
13456 .flags
= GENL_UNS_ADMIN_PERM
,
13457 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13458 NL80211_FLAG_NEED_RTNL
,
13461 .cmd
= NL80211_CMD_SET_CHANNEL
,
13462 .doit
= nl80211_set_channel
,
13463 .policy
= nl80211_policy
,
13464 .flags
= GENL_UNS_ADMIN_PERM
,
13465 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13466 NL80211_FLAG_NEED_RTNL
,
13469 .cmd
= NL80211_CMD_SET_WDS_PEER
,
13470 .doit
= nl80211_set_wds_peer
,
13471 .policy
= nl80211_policy
,
13472 .flags
= GENL_UNS_ADMIN_PERM
,
13473 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13474 NL80211_FLAG_NEED_RTNL
,
13477 .cmd
= NL80211_CMD_JOIN_MESH
,
13478 .doit
= nl80211_join_mesh
,
13479 .policy
= nl80211_policy
,
13480 .flags
= GENL_UNS_ADMIN_PERM
,
13481 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13482 NL80211_FLAG_NEED_RTNL
,
13485 .cmd
= NL80211_CMD_LEAVE_MESH
,
13486 .doit
= nl80211_leave_mesh
,
13487 .policy
= nl80211_policy
,
13488 .flags
= GENL_UNS_ADMIN_PERM
,
13489 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13490 NL80211_FLAG_NEED_RTNL
,
13493 .cmd
= NL80211_CMD_JOIN_OCB
,
13494 .doit
= nl80211_join_ocb
,
13495 .policy
= nl80211_policy
,
13496 .flags
= GENL_UNS_ADMIN_PERM
,
13497 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13498 NL80211_FLAG_NEED_RTNL
,
13501 .cmd
= NL80211_CMD_LEAVE_OCB
,
13502 .doit
= nl80211_leave_ocb
,
13503 .policy
= nl80211_policy
,
13504 .flags
= GENL_UNS_ADMIN_PERM
,
13505 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13506 NL80211_FLAG_NEED_RTNL
,
13510 .cmd
= NL80211_CMD_GET_WOWLAN
,
13511 .doit
= nl80211_get_wowlan
,
13512 .policy
= nl80211_policy
,
13513 /* can be retrieved by unprivileged users */
13514 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13515 NL80211_FLAG_NEED_RTNL
,
13518 .cmd
= NL80211_CMD_SET_WOWLAN
,
13519 .doit
= nl80211_set_wowlan
,
13520 .policy
= nl80211_policy
,
13521 .flags
= GENL_UNS_ADMIN_PERM
,
13522 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13523 NL80211_FLAG_NEED_RTNL
,
13527 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
13528 .doit
= nl80211_set_rekey_data
,
13529 .policy
= nl80211_policy
,
13530 .flags
= GENL_UNS_ADMIN_PERM
,
13531 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13532 NL80211_FLAG_NEED_RTNL
|
13533 NL80211_FLAG_CLEAR_SKB
,
13536 .cmd
= NL80211_CMD_TDLS_MGMT
,
13537 .doit
= nl80211_tdls_mgmt
,
13538 .policy
= nl80211_policy
,
13539 .flags
= GENL_UNS_ADMIN_PERM
,
13540 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13541 NL80211_FLAG_NEED_RTNL
,
13544 .cmd
= NL80211_CMD_TDLS_OPER
,
13545 .doit
= nl80211_tdls_oper
,
13546 .policy
= nl80211_policy
,
13547 .flags
= GENL_UNS_ADMIN_PERM
,
13548 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13549 NL80211_FLAG_NEED_RTNL
,
13552 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
13553 .doit
= nl80211_register_unexpected_frame
,
13554 .policy
= nl80211_policy
,
13555 .flags
= GENL_UNS_ADMIN_PERM
,
13556 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13557 NL80211_FLAG_NEED_RTNL
,
13560 .cmd
= NL80211_CMD_PROBE_CLIENT
,
13561 .doit
= nl80211_probe_client
,
13562 .policy
= nl80211_policy
,
13563 .flags
= GENL_UNS_ADMIN_PERM
,
13564 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13565 NL80211_FLAG_NEED_RTNL
,
13568 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
13569 .doit
= nl80211_register_beacons
,
13570 .policy
= nl80211_policy
,
13571 .flags
= GENL_UNS_ADMIN_PERM
,
13572 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13573 NL80211_FLAG_NEED_RTNL
,
13576 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
13577 .doit
= nl80211_set_noack_map
,
13578 .policy
= nl80211_policy
,
13579 .flags
= GENL_UNS_ADMIN_PERM
,
13580 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13581 NL80211_FLAG_NEED_RTNL
,
13584 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
13585 .doit
= nl80211_start_p2p_device
,
13586 .policy
= nl80211_policy
,
13587 .flags
= GENL_UNS_ADMIN_PERM
,
13588 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13589 NL80211_FLAG_NEED_RTNL
,
13592 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
13593 .doit
= nl80211_stop_p2p_device
,
13594 .policy
= nl80211_policy
,
13595 .flags
= GENL_UNS_ADMIN_PERM
,
13596 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13597 NL80211_FLAG_NEED_RTNL
,
13600 .cmd
= NL80211_CMD_START_NAN
,
13601 .doit
= nl80211_start_nan
,
13602 .policy
= nl80211_policy
,
13603 .flags
= GENL_ADMIN_PERM
,
13604 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13605 NL80211_FLAG_NEED_RTNL
,
13608 .cmd
= NL80211_CMD_STOP_NAN
,
13609 .doit
= nl80211_stop_nan
,
13610 .policy
= nl80211_policy
,
13611 .flags
= GENL_ADMIN_PERM
,
13612 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13613 NL80211_FLAG_NEED_RTNL
,
13616 .cmd
= NL80211_CMD_ADD_NAN_FUNCTION
,
13617 .doit
= nl80211_nan_add_func
,
13618 .policy
= nl80211_policy
,
13619 .flags
= GENL_ADMIN_PERM
,
13620 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13621 NL80211_FLAG_NEED_RTNL
,
13624 .cmd
= NL80211_CMD_DEL_NAN_FUNCTION
,
13625 .doit
= nl80211_nan_del_func
,
13626 .policy
= nl80211_policy
,
13627 .flags
= GENL_ADMIN_PERM
,
13628 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13629 NL80211_FLAG_NEED_RTNL
,
13632 .cmd
= NL80211_CMD_CHANGE_NAN_CONFIG
,
13633 .doit
= nl80211_nan_change_config
,
13634 .policy
= nl80211_policy
,
13635 .flags
= GENL_ADMIN_PERM
,
13636 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13637 NL80211_FLAG_NEED_RTNL
,
13640 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
13641 .doit
= nl80211_set_mcast_rate
,
13642 .policy
= nl80211_policy
,
13643 .flags
= GENL_UNS_ADMIN_PERM
,
13644 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13645 NL80211_FLAG_NEED_RTNL
,
13648 .cmd
= NL80211_CMD_SET_MAC_ACL
,
13649 .doit
= nl80211_set_mac_acl
,
13650 .policy
= nl80211_policy
,
13651 .flags
= GENL_UNS_ADMIN_PERM
,
13652 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13653 NL80211_FLAG_NEED_RTNL
,
13656 .cmd
= NL80211_CMD_RADAR_DETECT
,
13657 .doit
= nl80211_start_radar_detection
,
13658 .policy
= nl80211_policy
,
13659 .flags
= GENL_UNS_ADMIN_PERM
,
13660 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13661 NL80211_FLAG_NEED_RTNL
,
13664 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
13665 .doit
= nl80211_get_protocol_features
,
13666 .policy
= nl80211_policy
,
13669 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
13670 .doit
= nl80211_update_ft_ies
,
13671 .policy
= nl80211_policy
,
13672 .flags
= GENL_UNS_ADMIN_PERM
,
13673 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13674 NL80211_FLAG_NEED_RTNL
,
13677 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
13678 .doit
= nl80211_crit_protocol_start
,
13679 .policy
= nl80211_policy
,
13680 .flags
= GENL_UNS_ADMIN_PERM
,
13681 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13682 NL80211_FLAG_NEED_RTNL
,
13685 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
13686 .doit
= nl80211_crit_protocol_stop
,
13687 .policy
= nl80211_policy
,
13688 .flags
= GENL_UNS_ADMIN_PERM
,
13689 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13690 NL80211_FLAG_NEED_RTNL
,
13693 .cmd
= NL80211_CMD_GET_COALESCE
,
13694 .doit
= nl80211_get_coalesce
,
13695 .policy
= nl80211_policy
,
13696 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13697 NL80211_FLAG_NEED_RTNL
,
13700 .cmd
= NL80211_CMD_SET_COALESCE
,
13701 .doit
= nl80211_set_coalesce
,
13702 .policy
= nl80211_policy
,
13703 .flags
= GENL_UNS_ADMIN_PERM
,
13704 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13705 NL80211_FLAG_NEED_RTNL
,
13708 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
13709 .doit
= nl80211_channel_switch
,
13710 .policy
= nl80211_policy
,
13711 .flags
= GENL_UNS_ADMIN_PERM
,
13712 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13713 NL80211_FLAG_NEED_RTNL
,
13716 .cmd
= NL80211_CMD_VENDOR
,
13717 .doit
= nl80211_vendor_cmd
,
13718 .dumpit
= nl80211_vendor_cmd_dump
,
13719 .policy
= nl80211_policy
,
13720 .flags
= GENL_UNS_ADMIN_PERM
,
13721 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13722 NL80211_FLAG_NEED_RTNL
,
13725 .cmd
= NL80211_CMD_SET_QOS_MAP
,
13726 .doit
= nl80211_set_qos_map
,
13727 .policy
= nl80211_policy
,
13728 .flags
= GENL_UNS_ADMIN_PERM
,
13729 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13730 NL80211_FLAG_NEED_RTNL
,
13733 .cmd
= NL80211_CMD_ADD_TX_TS
,
13734 .doit
= nl80211_add_tx_ts
,
13735 .policy
= nl80211_policy
,
13736 .flags
= GENL_UNS_ADMIN_PERM
,
13737 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13738 NL80211_FLAG_NEED_RTNL
,
13741 .cmd
= NL80211_CMD_DEL_TX_TS
,
13742 .doit
= nl80211_del_tx_ts
,
13743 .policy
= nl80211_policy
,
13744 .flags
= GENL_UNS_ADMIN_PERM
,
13745 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13746 NL80211_FLAG_NEED_RTNL
,
13749 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
13750 .doit
= nl80211_tdls_channel_switch
,
13751 .policy
= nl80211_policy
,
13752 .flags
= GENL_UNS_ADMIN_PERM
,
13753 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13754 NL80211_FLAG_NEED_RTNL
,
13757 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
13758 .doit
= nl80211_tdls_cancel_channel_switch
,
13759 .policy
= nl80211_policy
,
13760 .flags
= GENL_UNS_ADMIN_PERM
,
13761 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13762 NL80211_FLAG_NEED_RTNL
,
13765 .cmd
= NL80211_CMD_SET_MULTICAST_TO_UNICAST
,
13766 .doit
= nl80211_set_multicast_to_unicast
,
13767 .policy
= nl80211_policy
,
13768 .flags
= GENL_UNS_ADMIN_PERM
,
13769 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13770 NL80211_FLAG_NEED_RTNL
,
13773 .cmd
= NL80211_CMD_SET_PMK
,
13774 .doit
= nl80211_set_pmk
,
13775 .policy
= nl80211_policy
,
13776 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13777 NL80211_FLAG_NEED_RTNL
,
13780 .cmd
= NL80211_CMD_DEL_PMK
,
13781 .doit
= nl80211_del_pmk
,
13782 .policy
= nl80211_policy
,
13783 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13784 NL80211_FLAG_NEED_RTNL
,
13787 .cmd
= NL80211_CMD_EXTERNAL_AUTH
,
13788 .doit
= nl80211_external_auth
,
13789 .policy
= nl80211_policy
,
13790 .flags
= GENL_ADMIN_PERM
,
13791 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13792 NL80211_FLAG_NEED_RTNL
,
13795 .cmd
= NL80211_CMD_CONTROL_PORT_FRAME
,
13796 .doit
= nl80211_tx_control_port
,
13797 .policy
= nl80211_policy
,
13798 .flags
= GENL_UNS_ADMIN_PERM
,
13799 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13800 NL80211_FLAG_NEED_RTNL
,
13804 static struct genl_family nl80211_fam __ro_after_init
= {
13805 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
13806 .hdrsize
= 0, /* no private header */
13807 .version
= 1, /* no particular meaning now */
13808 .maxattr
= NL80211_ATTR_MAX
,
13810 .pre_doit
= nl80211_pre_doit
,
13811 .post_doit
= nl80211_post_doit
,
13812 .module
= THIS_MODULE
,
13813 .ops
= nl80211_ops
,
13814 .n_ops
= ARRAY_SIZE(nl80211_ops
),
13815 .mcgrps
= nl80211_mcgrps
,
13816 .n_mcgrps
= ARRAY_SIZE(nl80211_mcgrps
),
13819 /* notification functions */
13821 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
13822 enum nl80211_commands cmd
)
13824 struct sk_buff
*msg
;
13825 struct nl80211_dump_wiphy_state state
= {};
13827 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
13828 cmd
!= NL80211_CMD_DEL_WIPHY
);
13830 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13834 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
13839 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13840 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
13843 void nl80211_notify_iface(struct cfg80211_registered_device
*rdev
,
13844 struct wireless_dev
*wdev
,
13845 enum nl80211_commands cmd
)
13847 struct sk_buff
*msg
;
13849 WARN_ON(cmd
!= NL80211_CMD_NEW_INTERFACE
&&
13850 cmd
!= NL80211_CMD_DEL_INTERFACE
);
13852 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13856 if (nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
,
13857 cmd
== NL80211_CMD_DEL_INTERFACE
) < 0) {
13862 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13863 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
13866 static int nl80211_add_scan_req(struct sk_buff
*msg
,
13867 struct cfg80211_registered_device
*rdev
)
13869 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
13870 struct nlattr
*nest
;
13876 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
13878 goto nla_put_failure
;
13879 for (i
= 0; i
< req
->n_ssids
; i
++) {
13880 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
13881 goto nla_put_failure
;
13883 nla_nest_end(msg
, nest
);
13885 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
13887 goto nla_put_failure
;
13888 for (i
= 0; i
< req
->n_channels
; i
++) {
13889 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
13890 goto nla_put_failure
;
13892 nla_nest_end(msg
, nest
);
13895 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
13896 goto nla_put_failure
;
13899 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
13900 goto nla_put_failure
;
13902 if (req
->info
.scan_start_tsf
&&
13903 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
13904 req
->info
.scan_start_tsf
, NL80211_BSS_PAD
) ||
13905 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
13906 req
->info
.tsf_bssid
)))
13907 goto nla_put_failure
;
13914 static int nl80211_prep_scan_msg(struct sk_buff
*msg
,
13915 struct cfg80211_registered_device
*rdev
,
13916 struct wireless_dev
*wdev
,
13917 u32 portid
, u32 seq
, int flags
,
13922 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
13926 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13927 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13928 wdev
->netdev
->ifindex
)) ||
13929 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13931 goto nla_put_failure
;
13933 /* ignore errors and send incomplete event anyway */
13934 nl80211_add_scan_req(msg
, rdev
);
13936 genlmsg_end(msg
, hdr
);
13940 genlmsg_cancel(msg
, hdr
);
13945 nl80211_prep_sched_scan_msg(struct sk_buff
*msg
,
13946 struct cfg80211_sched_scan_request
*req
, u32 cmd
)
13950 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13954 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
,
13955 wiphy_to_rdev(req
->wiphy
)->wiphy_idx
) ||
13956 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, req
->dev
->ifindex
) ||
13957 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, req
->reqid
,
13959 goto nla_put_failure
;
13961 genlmsg_end(msg
, hdr
);
13965 genlmsg_cancel(msg
, hdr
);
13969 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
13970 struct wireless_dev
*wdev
)
13972 struct sk_buff
*msg
;
13974 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13978 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
13979 NL80211_CMD_TRIGGER_SCAN
) < 0) {
13984 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13985 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
13988 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
13989 struct wireless_dev
*wdev
, bool aborted
)
13991 struct sk_buff
*msg
;
13993 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13997 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
13998 aborted
? NL80211_CMD_SCAN_ABORTED
:
13999 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
14007 /* send message created by nl80211_build_scan_msg() */
14008 void nl80211_send_scan_msg(struct cfg80211_registered_device
*rdev
,
14009 struct sk_buff
*msg
)
14014 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14015 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
14018 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request
*req
, u32 cmd
)
14020 struct sk_buff
*msg
;
14022 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14026 if (nl80211_prep_sched_scan_msg(msg
, req
, cmd
) < 0) {
14031 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(req
->wiphy
), msg
, 0,
14032 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
14035 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
14036 struct regulatory_request
*request
)
14038 /* Userspace can always count this one always being set */
14039 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
14040 goto nla_put_failure
;
14042 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
14043 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14044 NL80211_REGDOM_TYPE_WORLD
))
14045 goto nla_put_failure
;
14046 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
14047 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14048 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
14049 goto nla_put_failure
;
14050 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
14051 request
->intersect
) {
14052 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14053 NL80211_REGDOM_TYPE_INTERSECTION
))
14054 goto nla_put_failure
;
14056 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14057 NL80211_REGDOM_TYPE_COUNTRY
) ||
14058 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
14060 goto nla_put_failure
;
14063 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
14064 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
14067 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
14068 goto nla_put_failure
;
14071 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
14072 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
14073 goto nla_put_failure
;
14083 * This can happen on global regulatory changes or device specific settings
14084 * based on custom regulatory domains.
14086 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
14087 struct regulatory_request
*request
)
14089 struct sk_buff
*msg
;
14092 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14096 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
14102 if (nl80211_reg_change_event_fill(msg
, request
) == false)
14103 goto nla_put_failure
;
14105 genlmsg_end(msg
, hdr
);
14108 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
14109 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
14118 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
14119 struct net_device
*netdev
,
14120 const u8
*buf
, size_t len
,
14121 enum nl80211_commands cmd
, gfp_t gfp
,
14124 struct sk_buff
*msg
;
14127 msg
= nlmsg_new(100 + len
, gfp
);
14131 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14137 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14138 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14139 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
14140 goto nla_put_failure
;
14142 if (uapsd_queues
>= 0) {
14143 struct nlattr
*nla_wmm
=
14144 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
14146 goto nla_put_failure
;
14148 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
14150 goto nla_put_failure
;
14152 nla_nest_end(msg
, nla_wmm
);
14155 genlmsg_end(msg
, hdr
);
14157 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14158 NL80211_MCGRP_MLME
, gfp
);
14165 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
14166 struct net_device
*netdev
, const u8
*buf
,
14167 size_t len
, gfp_t gfp
)
14169 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14170 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
14173 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
14174 struct net_device
*netdev
, const u8
*buf
,
14175 size_t len
, gfp_t gfp
, int uapsd_queues
)
14177 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14178 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
14181 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
14182 struct net_device
*netdev
, const u8
*buf
,
14183 size_t len
, gfp_t gfp
)
14185 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14186 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
14189 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
14190 struct net_device
*netdev
, const u8
*buf
,
14191 size_t len
, gfp_t gfp
)
14193 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14194 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
14197 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
14200 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14201 struct wiphy
*wiphy
= wdev
->wiphy
;
14202 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14203 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
14206 if (WARN_ON(len
< 2))
14209 if (ieee80211_is_deauth(mgmt
->frame_control
))
14210 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
14212 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
14214 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
14215 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
14217 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
14219 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
14220 struct net_device
*netdev
, int cmd
,
14221 const u8
*addr
, gfp_t gfp
)
14223 struct sk_buff
*msg
;
14226 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14230 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14236 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14237 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14238 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
14239 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
14240 goto nla_put_failure
;
14242 genlmsg_end(msg
, hdr
);
14244 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14245 NL80211_MCGRP_MLME
, gfp
);
14252 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
14253 struct net_device
*netdev
, const u8
*addr
,
14256 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
14260 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
14261 struct net_device
*netdev
, const u8
*addr
,
14264 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
14268 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
14269 struct net_device
*netdev
,
14270 struct cfg80211_connect_resp_params
*cr
,
14273 struct sk_buff
*msg
;
14276 msg
= nlmsg_new(100 + cr
->req_ie_len
+ cr
->resp_ie_len
+
14277 cr
->fils
.kek_len
+ cr
->fils
.pmk_len
+
14278 (cr
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
14282 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
14288 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14289 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14291 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, cr
->bssid
)) ||
14292 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
14293 cr
->status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
14296 (nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
14297 nla_put_u32(msg
, NL80211_ATTR_TIMEOUT_REASON
,
14298 cr
->timeout_reason
))) ||
14300 nla_put(msg
, NL80211_ATTR_REQ_IE
, cr
->req_ie_len
, cr
->req_ie
)) ||
14302 nla_put(msg
, NL80211_ATTR_RESP_IE
, cr
->resp_ie_len
,
14304 (cr
->fils
.update_erp_next_seq_num
&&
14305 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
14306 cr
->fils
.erp_next_seq_num
)) ||
14307 (cr
->status
== WLAN_STATUS_SUCCESS
&&
14309 nla_put(msg
, NL80211_ATTR_FILS_KEK
, cr
->fils
.kek_len
,
14312 nla_put(msg
, NL80211_ATTR_PMK
, cr
->fils
.pmk_len
, cr
->fils
.pmk
)) ||
14314 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, cr
->fils
.pmkid
)))))
14315 goto nla_put_failure
;
14317 genlmsg_end(msg
, hdr
);
14319 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14320 NL80211_MCGRP_MLME
, gfp
);
14327 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
14328 struct net_device
*netdev
,
14329 struct cfg80211_roam_info
*info
, gfp_t gfp
)
14331 struct sk_buff
*msg
;
14333 const u8
*bssid
= info
->bss
? info
->bss
->bssid
: info
->bssid
;
14335 msg
= nlmsg_new(100 + info
->req_ie_len
+ info
->resp_ie_len
+
14336 info
->fils
.kek_len
+ info
->fils
.pmk_len
+
14337 (info
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
14341 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
14347 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14348 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14349 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
14351 nla_put(msg
, NL80211_ATTR_REQ_IE
, info
->req_ie_len
,
14354 nla_put(msg
, NL80211_ATTR_RESP_IE
, info
->resp_ie_len
,
14356 (info
->fils
.update_erp_next_seq_num
&&
14357 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
14358 info
->fils
.erp_next_seq_num
)) ||
14360 nla_put(msg
, NL80211_ATTR_FILS_KEK
, info
->fils
.kek_len
,
14361 info
->fils
.kek
)) ||
14363 nla_put(msg
, NL80211_ATTR_PMK
, info
->fils
.pmk_len
, info
->fils
.pmk
)) ||
14364 (info
->fils
.pmkid
&&
14365 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, info
->fils
.pmkid
)))
14366 goto nla_put_failure
;
14368 genlmsg_end(msg
, hdr
);
14370 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14371 NL80211_MCGRP_MLME
, gfp
);
14378 void nl80211_send_port_authorized(struct cfg80211_registered_device
*rdev
,
14379 struct net_device
*netdev
, const u8
*bssid
)
14381 struct sk_buff
*msg
;
14384 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14388 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED
);
14394 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
14395 goto nla_put_failure
;
14397 genlmsg_end(msg
, hdr
);
14399 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14400 NL80211_MCGRP_MLME
, GFP_KERNEL
);
14407 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
14408 struct net_device
*netdev
, u16 reason
,
14409 const u8
*ie
, size_t ie_len
, bool from_ap
)
14411 struct sk_buff
*msg
;
14414 msg
= nlmsg_new(100 + ie_len
, GFP_KERNEL
);
14418 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
14424 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14425 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14427 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
14429 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
14430 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
14431 goto nla_put_failure
;
14433 genlmsg_end(msg
, hdr
);
14435 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14436 NL80211_MCGRP_MLME
, GFP_KERNEL
);
14443 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
14444 struct net_device
*netdev
, const u8
*bssid
,
14447 struct sk_buff
*msg
;
14450 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14454 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
14460 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14461 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14462 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
14463 goto nla_put_failure
;
14465 genlmsg_end(msg
, hdr
);
14467 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14468 NL80211_MCGRP_MLME
, gfp
);
14475 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
14476 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
14478 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14479 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14480 struct sk_buff
*msg
;
14483 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
14486 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
14488 msg
= nlmsg_new(100 + ie_len
, gfp
);
14492 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
14498 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14499 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14500 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
14502 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
14503 goto nla_put_failure
;
14505 genlmsg_end(msg
, hdr
);
14507 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14508 NL80211_MCGRP_MLME
, gfp
);
14514 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
14516 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
14517 struct net_device
*netdev
, const u8
*addr
,
14518 enum nl80211_key_type key_type
, int key_id
,
14519 const u8
*tsc
, gfp_t gfp
)
14521 struct sk_buff
*msg
;
14524 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14528 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
14534 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14535 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14536 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
14537 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
14539 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
14540 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
14541 goto nla_put_failure
;
14543 genlmsg_end(msg
, hdr
);
14545 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14546 NL80211_MCGRP_MLME
, gfp
);
14553 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
14554 struct ieee80211_channel
*channel_before
,
14555 struct ieee80211_channel
*channel_after
)
14557 struct sk_buff
*msg
;
14559 struct nlattr
*nl_freq
;
14561 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
14565 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
14572 * Since we are applying the beacon hint to a wiphy we know its
14573 * wiphy_idx is valid
14575 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
14576 goto nla_put_failure
;
14579 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
14581 goto nla_put_failure
;
14583 if (nl80211_msg_put_channel(msg
, wiphy
, channel_before
, false))
14584 goto nla_put_failure
;
14585 nla_nest_end(msg
, nl_freq
);
14588 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
14590 goto nla_put_failure
;
14592 if (nl80211_msg_put_channel(msg
, wiphy
, channel_after
, false))
14593 goto nla_put_failure
;
14594 nla_nest_end(msg
, nl_freq
);
14596 genlmsg_end(msg
, hdr
);
14599 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
14600 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
14609 static void nl80211_send_remain_on_chan_event(
14610 int cmd
, struct cfg80211_registered_device
*rdev
,
14611 struct wireless_dev
*wdev
, u64 cookie
,
14612 struct ieee80211_channel
*chan
,
14613 unsigned int duration
, gfp_t gfp
)
14615 struct sk_buff
*msg
;
14618 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14622 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14628 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14629 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14630 wdev
->netdev
->ifindex
)) ||
14631 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14632 NL80211_ATTR_PAD
) ||
14633 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
14634 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
14635 NL80211_CHAN_NO_HT
) ||
14636 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14638 goto nla_put_failure
;
14640 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
14641 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
14642 goto nla_put_failure
;
14644 genlmsg_end(msg
, hdr
);
14646 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14647 NL80211_MCGRP_MLME
, gfp
);
14654 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
14655 struct ieee80211_channel
*chan
,
14656 unsigned int duration
, gfp_t gfp
)
14658 struct wiphy
*wiphy
= wdev
->wiphy
;
14659 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14661 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
14662 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
14663 rdev
, wdev
, cookie
, chan
,
14666 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
14668 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
14669 struct ieee80211_channel
*chan
,
14672 struct wiphy
*wiphy
= wdev
->wiphy
;
14673 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14675 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
14676 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
14677 rdev
, wdev
, cookie
, chan
, 0, gfp
);
14679 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
14681 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
14682 struct station_info
*sinfo
, gfp_t gfp
)
14684 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14685 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14686 struct sk_buff
*msg
;
14688 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
14690 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14694 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
14695 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14700 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14701 NL80211_MCGRP_MLME
, gfp
);
14703 EXPORT_SYMBOL(cfg80211_new_sta
);
14705 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
14706 struct station_info
*sinfo
, gfp_t gfp
)
14708 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14709 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14710 struct sk_buff
*msg
;
14711 struct station_info empty_sinfo
= {};
14714 sinfo
= &empty_sinfo
;
14716 trace_cfg80211_del_sta(dev
, mac_addr
);
14718 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14720 cfg80211_sinfo_release_content(sinfo
);
14724 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
14725 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14730 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14731 NL80211_MCGRP_MLME
, gfp
);
14733 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
14735 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
14736 enum nl80211_connect_failed_reason reason
,
14739 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14740 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14741 struct sk_buff
*msg
;
14744 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
14748 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
14754 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14755 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
14756 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
14757 goto nla_put_failure
;
14759 genlmsg_end(msg
, hdr
);
14761 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14762 NL80211_MCGRP_MLME
, gfp
);
14768 EXPORT_SYMBOL(cfg80211_conn_failed
);
14770 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
14771 const u8
*addr
, gfp_t gfp
)
14773 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14774 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14775 struct sk_buff
*msg
;
14777 u32 nlportid
= READ_ONCE(wdev
->ap_unexpected_nlportid
);
14782 msg
= nlmsg_new(100, gfp
);
14786 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14792 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14793 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14794 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
14795 goto nla_put_failure
;
14797 genlmsg_end(msg
, hdr
);
14798 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14806 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
14807 const u8
*addr
, gfp_t gfp
)
14809 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14812 trace_cfg80211_rx_spurious_frame(dev
, addr
);
14814 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14815 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
14816 trace_cfg80211_return_bool(false);
14819 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
14821 trace_cfg80211_return_bool(ret
);
14824 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
14826 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
14827 const u8
*addr
, gfp_t gfp
)
14829 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14832 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
14834 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14835 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
14836 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
14837 trace_cfg80211_return_bool(false);
14840 ret
= __nl80211_unexpected_frame(dev
,
14841 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
14843 trace_cfg80211_return_bool(ret
);
14846 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
14848 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
14849 struct wireless_dev
*wdev
, u32 nlportid
,
14850 int freq
, int sig_dbm
,
14851 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
14853 struct net_device
*netdev
= wdev
->netdev
;
14854 struct sk_buff
*msg
;
14857 msg
= nlmsg_new(100 + len
, gfp
);
14861 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
14867 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14868 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14869 netdev
->ifindex
)) ||
14870 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14871 NL80211_ATTR_PAD
) ||
14872 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
14874 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
14875 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
14877 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
14878 goto nla_put_failure
;
14880 genlmsg_end(msg
, hdr
);
14882 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14889 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
14890 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
14892 struct wiphy
*wiphy
= wdev
->wiphy
;
14893 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14894 struct net_device
*netdev
= wdev
->netdev
;
14895 struct sk_buff
*msg
;
14898 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
14900 msg
= nlmsg_new(100 + len
, gfp
);
14904 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
14910 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14911 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14912 netdev
->ifindex
)) ||
14913 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14914 NL80211_ATTR_PAD
) ||
14915 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
14916 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14917 NL80211_ATTR_PAD
) ||
14918 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
14919 goto nla_put_failure
;
14921 genlmsg_end(msg
, hdr
);
14923 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14924 NL80211_MCGRP_MLME
, gfp
);
14930 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
14932 static int __nl80211_rx_control_port(struct net_device
*dev
,
14933 const u8
*buf
, size_t len
,
14934 const u8
*addr
, u16 proto
,
14935 bool unencrypted
, gfp_t gfp
)
14937 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14938 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14939 struct sk_buff
*msg
;
14941 u32 nlportid
= READ_ONCE(wdev
->conn_owner_nlportid
);
14946 msg
= nlmsg_new(100 + len
, gfp
);
14950 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME
);
14956 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14957 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14958 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14959 NL80211_ATTR_PAD
) ||
14960 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
14961 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
14962 nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, proto
) ||
14963 (unencrypted
&& nla_put_flag(msg
,
14964 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
14965 goto nla_put_failure
;
14967 genlmsg_end(msg
, hdr
);
14969 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14976 bool cfg80211_rx_control_port(struct net_device
*dev
,
14977 const u8
*buf
, size_t len
,
14978 const u8
*addr
, u16 proto
, bool unencrypted
)
14982 trace_cfg80211_rx_control_port(dev
, buf
, len
, addr
, proto
, unencrypted
);
14983 ret
= __nl80211_rx_control_port(dev
, buf
, len
, addr
, proto
,
14984 unencrypted
, GFP_ATOMIC
);
14985 trace_cfg80211_return_bool(ret
== 0);
14988 EXPORT_SYMBOL(cfg80211_rx_control_port
);
14990 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
14991 const char *mac
, gfp_t gfp
)
14993 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14994 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14995 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15001 cb
= (void **)msg
->cb
;
15003 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
15009 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15010 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
15011 goto nla_put_failure
;
15013 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
15014 goto nla_put_failure
;
15016 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
15018 goto nla_put_failure
;
15028 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
15030 void **cb
= (void **)msg
->cb
;
15031 struct cfg80211_registered_device
*rdev
= cb
[2];
15033 nla_nest_end(msg
, cb
[1]);
15034 genlmsg_end(msg
, cb
[0]);
15036 memset(msg
->cb
, 0, sizeof(msg
->cb
));
15038 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15039 NL80211_MCGRP_MLME
, gfp
);
15042 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
15043 enum nl80211_cqm_rssi_threshold_event rssi_event
,
15044 s32 rssi_level
, gfp_t gfp
)
15046 struct sk_buff
*msg
;
15047 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15048 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15050 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
, rssi_level
);
15052 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
15053 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
15056 if (wdev
->cqm_config
) {
15057 wdev
->cqm_config
->last_rssi_event_value
= rssi_level
;
15059 cfg80211_cqm_rssi_update(rdev
, dev
);
15061 if (rssi_level
== 0)
15062 rssi_level
= wdev
->cqm_config
->last_rssi_event_value
;
15065 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
15069 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
15071 goto nla_put_failure
;
15073 if (rssi_level
&& nla_put_s32(msg
, NL80211_ATTR_CQM_RSSI_LEVEL
,
15075 goto nla_put_failure
;
15077 cfg80211_send_cqm(msg
, gfp
);
15084 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
15086 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
15087 const u8
*peer
, u32 num_packets
,
15088 u32 rate
, u32 intvl
, gfp_t gfp
)
15090 struct sk_buff
*msg
;
15092 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
15096 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
15097 goto nla_put_failure
;
15099 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
15100 goto nla_put_failure
;
15102 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
15103 goto nla_put_failure
;
15105 cfg80211_send_cqm(msg
, gfp
);
15111 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
15113 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
15114 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
15116 struct sk_buff
*msg
;
15118 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
15120 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
15124 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
15125 goto nla_put_failure
;
15127 cfg80211_send_cqm(msg
, gfp
);
15133 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
15135 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
15137 struct sk_buff
*msg
;
15139 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
15143 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
15144 goto nla_put_failure
;
15146 cfg80211_send_cqm(msg
, gfp
);
15152 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
15154 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
15155 struct net_device
*netdev
, const u8
*bssid
,
15156 const u8
*replay_ctr
, gfp_t gfp
)
15158 struct sk_buff
*msg
;
15159 struct nlattr
*rekey_attr
;
15162 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15166 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
15172 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15173 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15174 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
15175 goto nla_put_failure
;
15177 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
15179 goto nla_put_failure
;
15181 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
15182 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
15183 goto nla_put_failure
;
15185 nla_nest_end(msg
, rekey_attr
);
15187 genlmsg_end(msg
, hdr
);
15189 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15190 NL80211_MCGRP_MLME
, gfp
);
15197 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
15198 const u8
*replay_ctr
, gfp_t gfp
)
15200 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15201 struct wiphy
*wiphy
= wdev
->wiphy
;
15202 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15204 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
15205 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
15207 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
15210 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
15211 struct net_device
*netdev
, int index
,
15212 const u8
*bssid
, bool preauth
, gfp_t gfp
)
15214 struct sk_buff
*msg
;
15215 struct nlattr
*attr
;
15218 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15222 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
15228 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15229 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
15230 goto nla_put_failure
;
15232 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
15234 goto nla_put_failure
;
15236 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
15237 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
15239 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
15240 goto nla_put_failure
;
15242 nla_nest_end(msg
, attr
);
15244 genlmsg_end(msg
, hdr
);
15246 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15247 NL80211_MCGRP_MLME
, gfp
);
15254 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
15255 const u8
*bssid
, bool preauth
, gfp_t gfp
)
15257 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15258 struct wiphy
*wiphy
= wdev
->wiphy
;
15259 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15261 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
15262 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
15264 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
15266 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
15267 struct net_device
*netdev
,
15268 struct cfg80211_chan_def
*chandef
,
15270 enum nl80211_commands notif
,
15273 struct sk_buff
*msg
;
15276 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15280 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
15286 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
15287 goto nla_put_failure
;
15289 if (nl80211_send_chandef(msg
, chandef
))
15290 goto nla_put_failure
;
15292 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
15293 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
15294 goto nla_put_failure
;
15296 genlmsg_end(msg
, hdr
);
15298 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15299 NL80211_MCGRP_MLME
, gfp
);
15306 void cfg80211_ch_switch_notify(struct net_device
*dev
,
15307 struct cfg80211_chan_def
*chandef
)
15309 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15310 struct wiphy
*wiphy
= wdev
->wiphy
;
15311 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15313 ASSERT_WDEV_LOCK(wdev
);
15315 trace_cfg80211_ch_switch_notify(dev
, chandef
);
15317 wdev
->chandef
= *chandef
;
15318 wdev
->preset_chandef
= *chandef
;
15319 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
15320 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
15322 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
15324 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
15325 struct cfg80211_chan_def
*chandef
,
15328 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15329 struct wiphy
*wiphy
= wdev
->wiphy
;
15330 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15332 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
15334 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
15335 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
15337 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
15340 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
15341 const struct cfg80211_chan_def
*chandef
,
15342 enum nl80211_radar_event event
,
15343 struct net_device
*netdev
, gfp_t gfp
)
15345 struct sk_buff
*msg
;
15348 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15352 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
15358 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
15359 goto nla_put_failure
;
15361 /* NOP and radar events don't need a netdev parameter */
15363 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
15365 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15366 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15368 goto nla_put_failure
;
15371 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
15372 goto nla_put_failure
;
15374 if (nl80211_send_chandef(msg
, chandef
))
15375 goto nla_put_failure
;
15377 genlmsg_end(msg
, hdr
);
15379 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15380 NL80211_MCGRP_MLME
, gfp
);
15387 void cfg80211_sta_opmode_change_notify(struct net_device
*dev
, const u8
*mac
,
15388 struct sta_opmode_info
*sta_opmode
,
15391 struct sk_buff
*msg
;
15392 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15393 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15399 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15403 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED
);
15409 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
15410 goto nla_put_failure
;
15412 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
15413 goto nla_put_failure
;
15415 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
15416 goto nla_put_failure
;
15418 if ((sta_opmode
->changed
& STA_OPMODE_SMPS_MODE_CHANGED
) &&
15419 nla_put_u8(msg
, NL80211_ATTR_SMPS_MODE
, sta_opmode
->smps_mode
))
15420 goto nla_put_failure
;
15422 if ((sta_opmode
->changed
& STA_OPMODE_MAX_BW_CHANGED
) &&
15423 nla_put_u8(msg
, NL80211_ATTR_CHANNEL_WIDTH
, sta_opmode
->bw
))
15424 goto nla_put_failure
;
15426 if ((sta_opmode
->changed
& STA_OPMODE_N_SS_CHANGED
) &&
15427 nla_put_u8(msg
, NL80211_ATTR_NSS
, sta_opmode
->rx_nss
))
15428 goto nla_put_failure
;
15430 genlmsg_end(msg
, hdr
);
15432 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15433 NL80211_MCGRP_MLME
, gfp
);
15440 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify
);
15442 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
15443 u64 cookie
, bool acked
, s32 ack_signal
,
15444 bool is_valid_ack_signal
, gfp_t gfp
)
15446 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15447 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15448 struct sk_buff
*msg
;
15451 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
15453 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15458 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
15464 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15465 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15466 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
15467 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
15468 NL80211_ATTR_PAD
) ||
15469 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)) ||
15470 (is_valid_ack_signal
&& nla_put_s32(msg
, NL80211_ATTR_ACK_SIGNAL
,
15472 goto nla_put_failure
;
15474 genlmsg_end(msg
, hdr
);
15476 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15477 NL80211_MCGRP_MLME
, gfp
);
15483 EXPORT_SYMBOL(cfg80211_probe_status
);
15485 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
15486 const u8
*frame
, size_t len
,
15487 int freq
, int sig_dbm
)
15489 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15490 struct sk_buff
*msg
;
15492 struct cfg80211_beacon_registration
*reg
;
15494 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
15496 spin_lock_bh(&rdev
->beacon_registrations_lock
);
15497 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
15498 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
15500 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15504 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
15506 goto nla_put_failure
;
15508 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15510 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
15512 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
15513 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
15514 goto nla_put_failure
;
15516 genlmsg_end(msg
, hdr
);
15518 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
15520 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15524 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15527 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
15530 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
15531 struct cfg80211_wowlan_wakeup
*wakeup
)
15533 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
15534 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
15537 nl_results
= nla_nest_start(
15538 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
15542 for (i
= 0; i
< nd
->n_matches
; i
++) {
15543 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
15545 nl_match
= nla_nest_start(msg
, i
);
15549 /* The SSID attribute is optional in nl80211, but for
15550 * simplicity reasons it's always present in the
15551 * cfg80211 structure. If a driver can't pass the
15552 * SSID, that needs to be changed. A zero length SSID
15553 * is still a valid SSID (wildcard), so it cannot be
15554 * used for this purpose.
15556 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
15557 match
->ssid
.ssid
)) {
15558 nla_nest_cancel(msg
, nl_match
);
15562 if (match
->n_channels
) {
15563 nl_freqs
= nla_nest_start(
15564 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
15566 nla_nest_cancel(msg
, nl_match
);
15570 for (j
= 0; j
< match
->n_channels
; j
++) {
15571 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
15572 nla_nest_cancel(msg
, nl_freqs
);
15573 nla_nest_cancel(msg
, nl_match
);
15578 nla_nest_end(msg
, nl_freqs
);
15581 nla_nest_end(msg
, nl_match
);
15585 nla_nest_end(msg
, nl_results
);
15589 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
15590 struct cfg80211_wowlan_wakeup
*wakeup
,
15593 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15594 struct sk_buff
*msg
;
15598 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
15601 size
+= wakeup
->packet_present_len
;
15603 msg
= nlmsg_new(size
, gfp
);
15607 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
15611 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15612 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15616 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
15617 wdev
->netdev
->ifindex
))
15621 struct nlattr
*reasons
;
15623 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
15627 if (wakeup
->disconnect
&&
15628 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
15630 if (wakeup
->magic_pkt
&&
15631 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
15633 if (wakeup
->gtk_rekey_failure
&&
15634 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
15636 if (wakeup
->eap_identity_req
&&
15637 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
15639 if (wakeup
->four_way_handshake
&&
15640 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
15642 if (wakeup
->rfkill_release
&&
15643 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
15646 if (wakeup
->pattern_idx
>= 0 &&
15647 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
15648 wakeup
->pattern_idx
))
15651 if (wakeup
->tcp_match
&&
15652 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
15655 if (wakeup
->tcp_connlost
&&
15656 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
15659 if (wakeup
->tcp_nomoretokens
&&
15661 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
15664 if (wakeup
->packet
) {
15665 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
15666 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
15668 if (!wakeup
->packet_80211
) {
15670 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
15672 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
15675 if (wakeup
->packet_len
&&
15676 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
15679 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
15684 if (wakeup
->net_detect
&&
15685 cfg80211_net_detect_results(msg
, wakeup
))
15688 nla_nest_end(msg
, reasons
);
15691 genlmsg_end(msg
, hdr
);
15693 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15694 NL80211_MCGRP_MLME
, gfp
);
15700 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
15703 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
15704 enum nl80211_tdls_operation oper
,
15705 u16 reason_code
, gfp_t gfp
)
15707 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15708 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15709 struct sk_buff
*msg
;
15712 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
15715 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15719 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
15725 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15726 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15727 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
15728 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
15729 (reason_code
> 0 &&
15730 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
15731 goto nla_put_failure
;
15733 genlmsg_end(msg
, hdr
);
15735 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15736 NL80211_MCGRP_MLME
, gfp
);
15742 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
15744 static int nl80211_netlink_notify(struct notifier_block
* nb
,
15745 unsigned long state
,
15748 struct netlink_notify
*notify
= _notify
;
15749 struct cfg80211_registered_device
*rdev
;
15750 struct wireless_dev
*wdev
;
15751 struct cfg80211_beacon_registration
*reg
, *tmp
;
15753 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
15754 return NOTIFY_DONE
;
15758 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
15759 struct cfg80211_sched_scan_request
*sched_scan_req
;
15761 list_for_each_entry_rcu(sched_scan_req
,
15762 &rdev
->sched_scan_req_list
,
15764 if (sched_scan_req
->owner_nlportid
== notify
->portid
) {
15765 sched_scan_req
->nl_owner_dead
= true;
15766 schedule_work(&rdev
->sched_scan_stop_wk
);
15770 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
15771 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
15773 if (wdev
->owner_nlportid
== notify
->portid
) {
15774 wdev
->nl_owner_dead
= true;
15775 schedule_work(&rdev
->destroy_work
);
15776 } else if (wdev
->conn_owner_nlportid
== notify
->portid
) {
15777 schedule_work(&wdev
->disconnect_wk
);
15781 spin_lock_bh(&rdev
->beacon_registrations_lock
);
15782 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
15784 if (reg
->nlportid
== notify
->portid
) {
15785 list_del(®
->list
);
15790 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15796 * It is possible that the user space process that is controlling the
15797 * indoor setting disappeared, so notify the regulatory core.
15799 regulatory_netlink_notify(notify
->portid
);
15803 static struct notifier_block nl80211_netlink_notifier
= {
15804 .notifier_call
= nl80211_netlink_notify
,
15807 void cfg80211_ft_event(struct net_device
*netdev
,
15808 struct cfg80211_ft_event_params
*ft_event
)
15810 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
15811 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15812 struct sk_buff
*msg
;
15815 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
15817 if (!ft_event
->target_ap
)
15820 msg
= nlmsg_new(100 + ft_event
->ies_len
+ ft_event
->ric_ies_len
,
15825 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
15829 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15830 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15831 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
15834 if (ft_event
->ies
&&
15835 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
15837 if (ft_event
->ric_ies
&&
15838 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
15839 ft_event
->ric_ies
))
15842 genlmsg_end(msg
, hdr
);
15844 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15845 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15850 EXPORT_SYMBOL(cfg80211_ft_event
);
15852 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
15854 struct cfg80211_registered_device
*rdev
;
15855 struct sk_buff
*msg
;
15859 rdev
= wiphy_to_rdev(wdev
->wiphy
);
15860 if (!rdev
->crit_proto_nlportid
)
15863 nlportid
= rdev
->crit_proto_nlportid
;
15864 rdev
->crit_proto_nlportid
= 0;
15866 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15870 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
15872 goto nla_put_failure
;
15874 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15875 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15877 goto nla_put_failure
;
15879 genlmsg_end(msg
, hdr
);
15881 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
15887 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
15889 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
15891 struct wiphy
*wiphy
= wdev
->wiphy
;
15892 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15893 struct sk_buff
*msg
;
15896 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15900 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
15904 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15905 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
15906 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15910 genlmsg_end(msg
, hdr
);
15912 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
15913 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15919 int cfg80211_external_auth_request(struct net_device
*dev
,
15920 struct cfg80211_external_auth_params
*params
,
15923 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15924 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15925 struct sk_buff
*msg
;
15928 if (!wdev
->conn_owner_nlportid
)
15931 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15935 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH
);
15937 goto nla_put_failure
;
15939 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15940 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15941 nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, params
->key_mgmt_suite
) ||
15942 nla_put_u32(msg
, NL80211_ATTR_EXTERNAL_AUTH_ACTION
,
15944 nla_put(msg
, NL80211_ATTR_BSSID
, ETH_ALEN
, params
->bssid
) ||
15945 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid
.ssid_len
,
15946 params
->ssid
.ssid
))
15947 goto nla_put_failure
;
15949 genlmsg_end(msg
, hdr
);
15950 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
15951 wdev
->conn_owner_nlportid
);
15958 EXPORT_SYMBOL(cfg80211_external_auth_request
);
15960 /* initialisation/exit functions */
15962 int __init
nl80211_init(void)
15966 err
= genl_register_family(&nl80211_fam
);
15970 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
15976 genl_unregister_family(&nl80211_fam
);
15980 void nl80211_exit(void)
15982 netlink_unregister_notifier(&nl80211_netlink_notifier
);
15983 genl_unregister_family(&nl80211_fam
);