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 static int validate_beacon_head(const struct nlattr
*attr
,
204 struct netlink_ext_ack
*extack
)
206 const u8
*data
= nla_data(attr
);
207 unsigned int len
= nla_len(attr
);
208 const struct element
*elem
;
209 const struct ieee80211_mgmt
*mgmt
= (void *)data
;
210 unsigned int fixedlen
= offsetof(struct ieee80211_mgmt
,
216 if (ieee80211_hdrlen(mgmt
->frame_control
) !=
217 offsetof(struct ieee80211_mgmt
, u
.beacon
))
223 for_each_element(elem
, data
, len
) {
227 if (for_each_element_completed(elem
, data
, len
))
231 NL_SET_ERR_MSG_ATTR(extack
, attr
, "malformed beacon head");
235 /* policy for the attributes */
236 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
237 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
238 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
240 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
242 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
243 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
244 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
245 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
246 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
248 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
249 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
250 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
253 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
255 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
256 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
259 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
260 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
262 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
263 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
264 .len
= WLAN_MAX_KEY_LEN
},
265 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
266 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
267 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
268 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
269 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
271 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
272 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
273 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
274 .len
= IEEE80211_MAX_DATA_LEN
},
275 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
276 .len
= IEEE80211_MAX_DATA_LEN
},
277 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
278 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
279 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
280 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
281 .len
= NL80211_MAX_SUPP_RATES
},
282 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
283 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
284 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
285 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
286 .len
= IEEE80211_MAX_MESH_ID_LEN
},
287 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_BINARY
,
290 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
291 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
293 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
294 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
295 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
296 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
297 .len
= NL80211_MAX_SUPP_RATES
},
298 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
300 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
301 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
303 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
305 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
306 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
307 .len
= IEEE80211_MAX_DATA_LEN
},
308 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
309 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
311 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
312 .len
= IEEE80211_MAX_SSID_LEN
},
313 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
314 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
315 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
316 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
317 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
318 [NL80211_ATTR_STA_FLAGS2
] = {
319 .len
= sizeof(struct nl80211_sta_flag_update
),
321 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
322 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
323 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
324 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211
] = { .type
= NLA_FLAG
},
325 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
326 [NL80211_ATTR_STATUS_CODE
] = { .type
= NLA_U16
},
327 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
328 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
331 [NL80211_ATTR_PMKID
] = { .len
= WLAN_PMKID_LEN
},
332 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
333 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
334 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
335 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
336 .len
= IEEE80211_MAX_DATA_LEN
},
337 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
338 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
339 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
340 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
341 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
342 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
343 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
344 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
345 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
346 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
347 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
348 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
349 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
350 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
351 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
352 [NL80211_ATTR_MEASUREMENT_DURATION
] = { .type
= NLA_U16
},
353 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
] = { .type
= NLA_FLAG
},
354 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
355 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
356 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
357 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
358 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
359 .len
= IEEE80211_MAX_DATA_LEN
},
360 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
361 .len
= IEEE80211_MAX_DATA_LEN
},
362 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
363 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
364 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
365 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
366 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
367 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
368 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
369 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
370 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
371 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
372 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
373 .len
= IEEE80211_MAX_DATA_LEN
},
374 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
375 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
376 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
377 .len
= NL80211_HT_CAPABILITY_LEN
379 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
380 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
381 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
382 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
383 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
384 [NL80211_ATTR_AUTH_DATA
] = { .type
= NLA_BINARY
, },
385 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
386 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
387 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
388 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
389 [NL80211_ATTR_LOCAL_MESH_POWER_MODE
] = {. type
= NLA_U32
},
390 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
391 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
392 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
393 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
394 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
395 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
396 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
397 .len
= NL80211_VHT_CAPABILITY_LEN
,
399 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
400 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
401 .len
= IEEE80211_MAX_DATA_LEN
},
402 [NL80211_ATTR_CRIT_PROT_ID
] = { .type
= NLA_U16
},
403 [NL80211_ATTR_MAX_CRIT_PROT_DURATION
] = { .type
= NLA_U16
},
404 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
405 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
406 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
407 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
408 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
409 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
410 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
411 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
412 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
413 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
414 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
415 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
416 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
417 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
418 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
419 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
420 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
421 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
422 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
423 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
424 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
425 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
426 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
427 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
428 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
429 [NL80211_ATTR_OPER_CLASS
] = { .type
= NLA_U8
},
430 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
431 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
432 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
433 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
434 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
435 [NL80211_ATTR_PBSS
] = { .type
= NLA_FLAG
},
436 [NL80211_ATTR_BSS_SELECT
] = { .type
= NLA_NESTED
},
437 [NL80211_ATTR_STA_SUPPORT_P2P_PS
] = { .type
= NLA_U8
},
438 [NL80211_ATTR_MU_MIMO_GROUP_DATA
] = {
439 .len
= VHT_MUMIMO_GROUPS_DATA_LEN
441 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
] = { .len
= ETH_ALEN
},
442 [NL80211_ATTR_NAN_MASTER_PREF
] = { .type
= NLA_U8
},
443 [NL80211_ATTR_BANDS
] = { .type
= NLA_U32
},
444 [NL80211_ATTR_NAN_FUNC
] = { .type
= NLA_NESTED
},
445 [NL80211_ATTR_FILS_KEK
] = { .type
= NLA_BINARY
,
446 .len
= FILS_MAX_KEK_LEN
},
447 [NL80211_ATTR_FILS_NONCES
] = { .len
= 2 * FILS_NONCE_LEN
},
448 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
] = { .type
= NLA_FLAG
, },
449 [NL80211_ATTR_BSSID
] = { .len
= ETH_ALEN
},
450 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] = { .type
= NLA_S8
},
451 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
] = {
452 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
454 [NL80211_ATTR_TIMEOUT_REASON
] = { .type
= NLA_U32
},
455 [NL80211_ATTR_FILS_ERP_USERNAME
] = { .type
= NLA_BINARY
,
456 .len
= FILS_ERP_MAX_USERNAME_LEN
},
457 [NL80211_ATTR_FILS_ERP_REALM
] = { .type
= NLA_BINARY
,
458 .len
= FILS_ERP_MAX_REALM_LEN
},
459 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] = { .type
= NLA_U16
},
460 [NL80211_ATTR_FILS_ERP_RRK
] = { .type
= NLA_BINARY
,
461 .len
= FILS_ERP_MAX_RRK_LEN
},
462 [NL80211_ATTR_FILS_CACHE_ID
] = { .len
= 2 },
463 [NL80211_ATTR_PMK
] = { .type
= NLA_BINARY
, .len
= PMK_MAX_LEN
},
464 [NL80211_ATTR_SCHED_SCAN_MULTI
] = { .type
= NLA_FLAG
},
465 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
] = { .type
= NLA_FLAG
},
467 [NL80211_ATTR_TXQ_LIMIT
] = { .type
= NLA_U32
},
468 [NL80211_ATTR_TXQ_MEMORY_LIMIT
] = { .type
= NLA_U32
},
469 [NL80211_ATTR_TXQ_QUANTUM
] = { .type
= NLA_U32
},
470 [NL80211_ATTR_HE_CAPABILITY
] = { .type
= NLA_BINARY
,
471 .len
= NL80211_HE_MAX_CAPABILITY_LEN
},
474 /* policy for the key attributes */
475 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
476 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
477 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
478 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
479 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
480 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
481 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
482 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
483 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
486 /* policy for the key default flags */
487 static const struct nla_policy
488 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
489 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
490 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
494 /* policy for WoWLAN attributes */
495 static const struct nla_policy
496 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
497 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
498 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
499 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
500 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
501 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
502 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
503 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
504 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
505 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
506 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
509 static const struct nla_policy
510 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
511 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
512 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
513 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
514 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
515 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
516 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
517 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
518 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
520 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
521 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
523 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
524 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
525 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
527 #endif /* CONFIG_PM */
529 /* policy for coalesce rule attributes */
530 static const struct nla_policy
531 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
532 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
533 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
534 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
537 /* policy for GTK rekey offload attributes */
538 static const struct nla_policy
539 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
540 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
541 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
542 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
545 static const struct nla_policy
546 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
547 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
548 .len
= IEEE80211_MAX_SSID_LEN
},
549 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
] = { .len
= ETH_ALEN
},
550 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
553 static const struct nla_policy
554 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
555 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
556 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
559 static const struct nla_policy
560 nl80211_bss_select_policy
[NL80211_BSS_SELECT_ATTR_MAX
+ 1] = {
561 [NL80211_BSS_SELECT_ATTR_RSSI
] = { .type
= NLA_FLAG
},
562 [NL80211_BSS_SELECT_ATTR_BAND_PREF
] = { .type
= NLA_U32
},
563 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
] = {
564 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
568 /* policy for NAN function attributes */
569 static const struct nla_policy
570 nl80211_nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
571 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
572 [NL80211_NAN_FUNC_SERVICE_ID
] = {
573 .len
= NL80211_NAN_FUNC_SERVICE_ID_LEN
},
574 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
575 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
576 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
577 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
578 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
579 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { .len
= ETH_ALEN
},
580 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
581 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
582 [NL80211_NAN_FUNC_SERVICE_INFO
] = { .type
= NLA_BINARY
,
583 .len
= NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN
},
584 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
585 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
586 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
587 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
588 [NL80211_NAN_FUNC_TERM_REASON
] = { .type
= NLA_U8
},
591 /* policy for Service Response Filter attributes */
592 static const struct nla_policy
593 nl80211_nan_srf_policy
[NL80211_NAN_SRF_ATTR_MAX
+ 1] = {
594 [NL80211_NAN_SRF_INCLUDE
] = { .type
= NLA_FLAG
},
595 [NL80211_NAN_SRF_BF
] = { .type
= NLA_BINARY
,
596 .len
= NL80211_NAN_FUNC_SRF_MAX_LEN
},
597 [NL80211_NAN_SRF_BF_IDX
] = { .type
= NLA_U8
},
598 [NL80211_NAN_SRF_MAC_ADDRS
] = { .type
= NLA_NESTED
},
601 /* policy for packet pattern attributes */
602 static const struct nla_policy
603 nl80211_packet_pattern_policy
[MAX_NL80211_PKTPAT
+ 1] = {
604 [NL80211_PKTPAT_MASK
] = { .type
= NLA_BINARY
, },
605 [NL80211_PKTPAT_PATTERN
] = { .type
= NLA_BINARY
, },
606 [NL80211_PKTPAT_OFFSET
] = { .type
= NLA_U32
},
609 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
610 struct netlink_callback
*cb
,
611 struct cfg80211_registered_device
**rdev
,
612 struct wireless_dev
**wdev
)
617 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
618 genl_family_attrbuf(&nl80211_fam
),
619 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
623 *wdev
= __cfg80211_wdev_from_attrs(
625 genl_family_attrbuf(&nl80211_fam
));
627 return PTR_ERR(*wdev
);
628 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
629 /* 0 is the first index - add 1 to parse only once */
630 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
631 cb
->args
[1] = (*wdev
)->identifier
;
633 /* subtract the 1 again here */
634 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
635 struct wireless_dev
*tmp
;
639 *rdev
= wiphy_to_rdev(wiphy
);
642 list_for_each_entry(tmp
, &(*rdev
)->wiphy
.wdev_list
, list
) {
643 if (tmp
->identifier
== cb
->args
[1]) {
657 static bool is_valid_ie_attr(const struct nlattr
*attr
)
665 pos
= nla_data(attr
);
686 /* message building helper */
687 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
690 /* since there is no private header just add the generic one */
691 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
694 static int nl80211_msg_put_wmm_rules(struct sk_buff
*msg
,
695 const struct ieee80211_reg_rule
*rule
)
698 struct nlattr
*nl_wmm_rules
=
699 nla_nest_start(msg
, NL80211_FREQUENCY_ATTR_WMM
);
702 goto nla_put_failure
;
704 for (j
= 0; j
< IEEE80211_NUM_ACS
; j
++) {
705 struct nlattr
*nl_wmm_rule
= nla_nest_start(msg
, j
);
708 goto nla_put_failure
;
710 if (nla_put_u16(msg
, NL80211_WMMR_CW_MIN
,
711 rule
->wmm_rule
.client
[j
].cw_min
) ||
712 nla_put_u16(msg
, NL80211_WMMR_CW_MAX
,
713 rule
->wmm_rule
.client
[j
].cw_max
) ||
714 nla_put_u8(msg
, NL80211_WMMR_AIFSN
,
715 rule
->wmm_rule
.client
[j
].aifsn
) ||
716 nla_put_u16(msg
, NL80211_WMMR_TXOP
,
717 rule
->wmm_rule
.client
[j
].cot
))
718 goto nla_put_failure
;
720 nla_nest_end(msg
, nl_wmm_rule
);
722 nla_nest_end(msg
, nl_wmm_rules
);
730 static int nl80211_msg_put_channel(struct sk_buff
*msg
, struct wiphy
*wiphy
,
731 struct ieee80211_channel
*chan
,
734 /* Some channels must be completely excluded from the
735 * list to protect old user-space tools from breaking
737 if (!large
&& chan
->flags
&
738 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
741 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
743 goto nla_put_failure
;
745 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
746 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
747 goto nla_put_failure
;
748 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
749 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
750 goto nla_put_failure
;
751 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
752 goto nla_put_failure
;
754 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
755 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
756 goto nla_put_failure
;
760 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
762 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
764 goto nla_put_failure
;
765 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
767 goto nla_put_failure
;
769 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
771 goto nla_put_failure
;
776 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
777 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
778 goto nla_put_failure
;
779 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
780 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
781 goto nla_put_failure
;
782 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
783 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
784 goto nla_put_failure
;
785 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
786 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
787 goto nla_put_failure
;
788 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
789 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
790 goto nla_put_failure
;
791 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
792 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
793 goto nla_put_failure
;
794 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
795 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
796 goto nla_put_failure
;
797 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
798 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
799 goto nla_put_failure
;
802 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
803 DBM_TO_MBM(chan
->max_power
)))
804 goto nla_put_failure
;
807 const struct ieee80211_reg_rule
*rule
=
808 freq_reg_info(wiphy
, MHZ_TO_KHZ(chan
->center_freq
));
810 if (!IS_ERR_OR_NULL(rule
) && rule
->has_wmm
) {
811 if (nl80211_msg_put_wmm_rules(msg
, rule
))
812 goto nla_put_failure
;
822 static bool nl80211_put_txq_stats(struct sk_buff
*msg
,
823 struct cfg80211_txq_stats
*txqstats
,
826 struct nlattr
*txqattr
;
828 #define PUT_TXQVAL_U32(attr, memb) do { \
829 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
830 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
834 txqattr
= nla_nest_start(msg
, attrtype
);
838 PUT_TXQVAL_U32(BACKLOG_BYTES
, backlog_bytes
);
839 PUT_TXQVAL_U32(BACKLOG_PACKETS
, backlog_packets
);
840 PUT_TXQVAL_U32(FLOWS
, flows
);
841 PUT_TXQVAL_U32(DROPS
, drops
);
842 PUT_TXQVAL_U32(ECN_MARKS
, ecn_marks
);
843 PUT_TXQVAL_U32(OVERLIMIT
, overlimit
);
844 PUT_TXQVAL_U32(OVERMEMORY
, overmemory
);
845 PUT_TXQVAL_U32(COLLISIONS
, collisions
);
846 PUT_TXQVAL_U32(TX_BYTES
, tx_bytes
);
847 PUT_TXQVAL_U32(TX_PACKETS
, tx_packets
);
848 PUT_TXQVAL_U32(MAX_FLOWS
, max_flows
);
849 nla_nest_end(msg
, txqattr
);
851 #undef PUT_TXQVAL_U32
855 /* netlink command implementations */
862 bool def_uni
, def_multi
;
865 static int nl80211_parse_key_new(struct genl_info
*info
, struct nlattr
*key
,
868 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
869 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
870 nl80211_key_policy
, info
->extack
);
874 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
875 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
884 if (tb
[NL80211_KEY_IDX
])
885 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
887 if (tb
[NL80211_KEY_DATA
]) {
888 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
889 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
892 if (tb
[NL80211_KEY_SEQ
]) {
893 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
894 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
897 if (tb
[NL80211_KEY_CIPHER
])
898 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
900 if (tb
[NL80211_KEY_TYPE
]) {
901 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
902 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
903 return genl_err_attr(info
, -EINVAL
,
904 tb
[NL80211_KEY_TYPE
]);
907 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
908 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
910 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
911 tb
[NL80211_KEY_DEFAULT_TYPES
],
912 nl80211_key_default_policy
,
917 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
918 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
924 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
926 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
927 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
928 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
931 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
932 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
933 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
936 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
937 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
939 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
940 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
942 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
943 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
952 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
953 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
954 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
) {
955 GENL_SET_ERR_MSG(info
, "key type out of range");
960 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
961 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
962 int err
= nla_parse_nested(kdt
,
963 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
964 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
965 nl80211_key_default_policy
,
970 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
971 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
977 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
981 memset(k
, 0, sizeof(*k
));
985 if (info
->attrs
[NL80211_ATTR_KEY
])
986 err
= nl80211_parse_key_new(info
, info
->attrs
[NL80211_ATTR_KEY
], k
);
988 err
= nl80211_parse_key_old(info
, k
);
993 if (k
->def
&& k
->defmgmt
) {
994 GENL_SET_ERR_MSG(info
, "key with def && defmgmt is invalid");
999 if (k
->def_uni
|| !k
->def_multi
) {
1000 GENL_SET_ERR_MSG(info
, "defmgmt key must be mcast");
1007 if (k
->idx
< 4 || k
->idx
> 5) {
1008 GENL_SET_ERR_MSG(info
,
1009 "defmgmt key idx not 4 or 5");
1012 } else if (k
->def
) {
1013 if (k
->idx
< 0 || k
->idx
> 3) {
1014 GENL_SET_ERR_MSG(info
, "def key idx not 0-3");
1018 if (k
->idx
< 0 || k
->idx
> 5) {
1019 GENL_SET_ERR_MSG(info
, "key idx not 0-5");
1028 static struct cfg80211_cached_keys
*
1029 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
1030 struct genl_info
*info
, bool *no_ht
)
1032 struct nlattr
*keys
= info
->attrs
[NL80211_ATTR_KEYS
];
1033 struct key_parse parse
;
1035 struct cfg80211_cached_keys
*result
;
1036 int rem
, err
, def
= 0;
1037 bool have_key
= false;
1039 nla_for_each_nested(key
, keys
, rem
) {
1047 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
1049 return ERR_PTR(-ENOMEM
);
1053 nla_for_each_nested(key
, keys
, rem
) {
1054 memset(&parse
, 0, sizeof(parse
));
1057 err
= nl80211_parse_key_new(info
, key
, &parse
);
1063 if (parse
.idx
< 0 || parse
.idx
> 3) {
1064 GENL_SET_ERR_MSG(info
, "key index out of range [0-3]");
1069 GENL_SET_ERR_MSG(info
,
1070 "only one key can be default");
1074 result
->def
= parse
.idx
;
1075 if (!parse
.def_uni
|| !parse
.def_multi
)
1077 } else if (parse
.defmgmt
)
1079 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
1080 parse
.idx
, false, NULL
);
1083 if (parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1084 parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
) {
1085 GENL_SET_ERR_MSG(info
, "connect key must be WEP");
1089 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
1090 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
1091 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
1092 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
1094 /* must be WEP key if we got here */
1099 if (result
->def
< 0) {
1101 GENL_SET_ERR_MSG(info
, "need a default/TX key");
1108 return ERR_PTR(err
);
1111 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
1113 ASSERT_WDEV_LOCK(wdev
);
1115 switch (wdev
->iftype
) {
1116 case NL80211_IFTYPE_AP
:
1117 case NL80211_IFTYPE_AP_VLAN
:
1118 case NL80211_IFTYPE_P2P_GO
:
1119 case NL80211_IFTYPE_MESH_POINT
:
1121 case NL80211_IFTYPE_ADHOC
:
1122 case NL80211_IFTYPE_STATION
:
1123 case NL80211_IFTYPE_P2P_CLIENT
:
1124 if (!wdev
->current_bss
)
1127 case NL80211_IFTYPE_UNSPECIFIED
:
1128 case NL80211_IFTYPE_OCB
:
1129 case NL80211_IFTYPE_MONITOR
:
1130 case NL80211_IFTYPE_NAN
:
1131 case NL80211_IFTYPE_P2P_DEVICE
:
1132 case NL80211_IFTYPE_WDS
:
1133 case NUM_NL80211_IFTYPES
:
1140 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
1143 struct ieee80211_channel
*chan
;
1147 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
1148 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
1153 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
1155 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
1159 goto nla_put_failure
;
1163 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
1164 goto nla_put_failure
;
1169 nla_nest_end(msg
, nl_modes
);
1176 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
1177 struct sk_buff
*msg
,
1180 struct nlattr
*nl_combis
;
1183 nl_combis
= nla_nest_start(msg
,
1184 NL80211_ATTR_INTERFACE_COMBINATIONS
);
1186 goto nla_put_failure
;
1188 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
1189 const struct ieee80211_iface_combination
*c
;
1190 struct nlattr
*nl_combi
, *nl_limits
;
1192 c
= &wiphy
->iface_combinations
[i
];
1194 nl_combi
= nla_nest_start(msg
, i
+ 1);
1196 goto nla_put_failure
;
1198 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
1200 goto nla_put_failure
;
1202 for (j
= 0; j
< c
->n_limits
; j
++) {
1203 struct nlattr
*nl_limit
;
1205 nl_limit
= nla_nest_start(msg
, j
+ 1);
1207 goto nla_put_failure
;
1208 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
1210 goto nla_put_failure
;
1211 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
1212 c
->limits
[j
].types
))
1213 goto nla_put_failure
;
1214 nla_nest_end(msg
, nl_limit
);
1217 nla_nest_end(msg
, nl_limits
);
1219 if (c
->beacon_int_infra_match
&&
1220 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
1221 goto nla_put_failure
;
1222 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
1223 c
->num_different_channels
) ||
1224 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
1226 goto nla_put_failure
;
1228 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1229 c
->radar_detect_widths
) ||
1230 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1231 c
->radar_detect_regions
)))
1232 goto nla_put_failure
;
1233 if (c
->beacon_int_min_gcd
&&
1234 nla_put_u32(msg
, NL80211_IFACE_COMB_BI_MIN_GCD
,
1235 c
->beacon_int_min_gcd
))
1236 goto nla_put_failure
;
1238 nla_nest_end(msg
, nl_combi
);
1241 nla_nest_end(msg
, nl_combis
);
1249 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1250 struct sk_buff
*msg
)
1252 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1253 struct nlattr
*nl_tcp
;
1258 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1262 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1263 tcp
->data_payload_max
))
1266 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1267 tcp
->data_payload_max
))
1270 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1273 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1274 sizeof(*tcp
->tok
), tcp
->tok
))
1277 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1278 tcp
->data_interval_max
))
1281 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1282 tcp
->wake_payload_max
))
1285 nla_nest_end(msg
, nl_tcp
);
1289 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1290 struct cfg80211_registered_device
*rdev
,
1293 struct nlattr
*nl_wowlan
;
1295 if (!rdev
->wiphy
.wowlan
)
1298 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1302 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1303 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1304 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1305 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1306 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1307 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1308 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1309 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1310 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1311 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1312 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1313 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1314 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1315 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1316 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1317 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1320 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1321 struct nl80211_pattern_support pat
= {
1322 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1323 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1324 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1325 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1328 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1333 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1334 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1335 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1338 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1341 nla_nest_end(msg
, nl_wowlan
);
1347 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1348 struct cfg80211_registered_device
*rdev
)
1350 struct nl80211_coalesce_rule_support rule
;
1352 if (!rdev
->wiphy
.coalesce
)
1355 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1356 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1357 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1358 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1359 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1360 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1362 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1369 nl80211_send_iftype_data(struct sk_buff
*msg
,
1370 const struct ieee80211_sband_iftype_data
*iftdata
)
1372 const struct ieee80211_sta_he_cap
*he_cap
= &iftdata
->he_cap
;
1374 if (nl80211_put_iftypes(msg
, NL80211_BAND_IFTYPE_ATTR_IFTYPES
,
1375 iftdata
->types_mask
))
1378 if (he_cap
->has_he
) {
1379 if (nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
,
1380 sizeof(he_cap
->he_cap_elem
.mac_cap_info
),
1381 he_cap
->he_cap_elem
.mac_cap_info
) ||
1382 nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
,
1383 sizeof(he_cap
->he_cap_elem
.phy_cap_info
),
1384 he_cap
->he_cap_elem
.phy_cap_info
) ||
1385 nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
,
1386 sizeof(he_cap
->he_mcs_nss_supp
),
1387 &he_cap
->he_mcs_nss_supp
) ||
1388 nla_put(msg
, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
,
1389 sizeof(he_cap
->ppe_thres
), he_cap
->ppe_thres
))
1396 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1397 struct ieee80211_supported_band
*sband
)
1399 struct nlattr
*nl_rates
, *nl_rate
;
1400 struct ieee80211_rate
*rate
;
1404 if (sband
->ht_cap
.ht_supported
&&
1405 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1406 sizeof(sband
->ht_cap
.mcs
),
1407 &sband
->ht_cap
.mcs
) ||
1408 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1409 sband
->ht_cap
.cap
) ||
1410 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1411 sband
->ht_cap
.ampdu_factor
) ||
1412 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1413 sband
->ht_cap
.ampdu_density
)))
1417 if (sband
->vht_cap
.vht_supported
&&
1418 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1419 sizeof(sband
->vht_cap
.vht_mcs
),
1420 &sband
->vht_cap
.vht_mcs
) ||
1421 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1422 sband
->vht_cap
.cap
)))
1425 if (sband
->n_iftype_data
) {
1426 struct nlattr
*nl_iftype_data
=
1427 nla_nest_start(msg
, NL80211_BAND_ATTR_IFTYPE_DATA
);
1430 if (!nl_iftype_data
)
1433 for (i
= 0; i
< sband
->n_iftype_data
; i
++) {
1434 struct nlattr
*iftdata
;
1436 iftdata
= nla_nest_start(msg
, i
+ 1);
1440 err
= nl80211_send_iftype_data(msg
,
1441 &sband
->iftype_data
[i
]);
1445 nla_nest_end(msg
, iftdata
);
1448 nla_nest_end(msg
, nl_iftype_data
);
1452 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1456 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1457 nl_rate
= nla_nest_start(msg
, i
);
1461 rate
= &sband
->bitrates
[i
];
1462 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1465 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1467 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1470 nla_nest_end(msg
, nl_rate
);
1473 nla_nest_end(msg
, nl_rates
);
1479 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1480 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1483 struct nlattr
*nl_ftypes
, *nl_ifs
;
1484 enum nl80211_iftype ift
;
1490 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1494 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1495 nl_ftypes
= nla_nest_start(msg
, ift
);
1499 stypes
= mgmt_stypes
[ift
].tx
;
1502 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1503 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1508 nla_nest_end(msg
, nl_ftypes
);
1511 nla_nest_end(msg
, nl_ifs
);
1513 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1517 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1518 nl_ftypes
= nla_nest_start(msg
, ift
);
1522 stypes
= mgmt_stypes
[ift
].rx
;
1525 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1526 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1531 nla_nest_end(msg
, nl_ftypes
);
1533 nla_nest_end(msg
, nl_ifs
);
1538 #define CMD(op, n) \
1540 if (rdev->ops->op) { \
1542 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1543 goto nla_put_failure; \
1547 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device
*rdev
,
1548 struct sk_buff
*msg
)
1553 * do *NOT* add anything into this function, new things need to be
1554 * advertised only to new versions of userspace that can deal with
1555 * the split (and they can't possibly care about new features...
1557 CMD(add_virtual_intf
, NEW_INTERFACE
);
1558 CMD(change_virtual_intf
, SET_INTERFACE
);
1559 CMD(add_key
, NEW_KEY
);
1560 CMD(start_ap
, START_AP
);
1561 CMD(add_station
, NEW_STATION
);
1562 CMD(add_mpath
, NEW_MPATH
);
1563 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1564 CMD(change_bss
, SET_BSS
);
1565 CMD(auth
, AUTHENTICATE
);
1566 CMD(assoc
, ASSOCIATE
);
1567 CMD(deauth
, DEAUTHENTICATE
);
1568 CMD(disassoc
, DISASSOCIATE
);
1569 CMD(join_ibss
, JOIN_IBSS
);
1570 CMD(join_mesh
, JOIN_MESH
);
1571 CMD(set_pmksa
, SET_PMKSA
);
1572 CMD(del_pmksa
, DEL_PMKSA
);
1573 CMD(flush_pmksa
, FLUSH_PMKSA
);
1574 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1575 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1576 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1577 CMD(mgmt_tx
, FRAME
);
1578 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1579 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1581 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1582 goto nla_put_failure
;
1584 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1585 rdev
->ops
->join_mesh
) {
1587 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1588 goto nla_put_failure
;
1590 CMD(set_wds_peer
, SET_WDS_PEER
);
1591 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1592 CMD(tdls_mgmt
, TDLS_MGMT
);
1593 CMD(tdls_oper
, TDLS_OPER
);
1595 if (rdev
->wiphy
.max_sched_scan_reqs
)
1596 CMD(sched_scan_start
, START_SCHED_SCAN
);
1597 CMD(probe_client
, PROBE_CLIENT
);
1598 CMD(set_noack_map
, SET_NOACK_MAP
);
1599 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1601 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1602 goto nla_put_failure
;
1604 CMD(start_p2p_device
, START_P2P_DEVICE
);
1605 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1606 #ifdef CONFIG_NL80211_TESTMODE
1607 CMD(testmode_cmd
, TESTMODE
);
1610 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1612 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1613 goto nla_put_failure
;
1616 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1618 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1619 goto nla_put_failure
;
1627 struct nl80211_dump_wiphy_state
{
1630 long split_start
, band_start
, chan_start
, capa_start
;
1634 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1635 enum nl80211_commands cmd
,
1636 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1637 int flags
, struct nl80211_dump_wiphy_state
*state
)
1640 struct nlattr
*nl_bands
, *nl_band
;
1641 struct nlattr
*nl_freqs
, *nl_freq
;
1642 struct nlattr
*nl_cmds
;
1643 enum nl80211_band band
;
1644 struct ieee80211_channel
*chan
;
1646 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1647 rdev
->wiphy
.mgmt_stypes
;
1650 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1654 if (WARN_ON(!state
))
1657 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1658 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1659 wiphy_name(&rdev
->wiphy
)) ||
1660 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1661 cfg80211_rdev_list_generation
))
1662 goto nla_put_failure
;
1664 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1667 switch (state
->split_start
) {
1669 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1670 rdev
->wiphy
.retry_short
) ||
1671 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1672 rdev
->wiphy
.retry_long
) ||
1673 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1674 rdev
->wiphy
.frag_threshold
) ||
1675 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1676 rdev
->wiphy
.rts_threshold
) ||
1677 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1678 rdev
->wiphy
.coverage_class
) ||
1679 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1680 rdev
->wiphy
.max_scan_ssids
) ||
1681 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1682 rdev
->wiphy
.max_sched_scan_ssids
) ||
1683 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1684 rdev
->wiphy
.max_scan_ie_len
) ||
1685 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1686 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1687 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1688 rdev
->wiphy
.max_match_sets
) ||
1689 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1690 rdev
->wiphy
.max_sched_scan_plans
) ||
1691 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1692 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1693 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1694 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1695 goto nla_put_failure
;
1697 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1698 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1699 goto nla_put_failure
;
1700 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1701 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1702 goto nla_put_failure
;
1703 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1704 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1705 goto nla_put_failure
;
1706 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1707 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1708 goto nla_put_failure
;
1709 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1710 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1711 goto nla_put_failure
;
1712 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1713 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1714 goto nla_put_failure
;
1715 state
->split_start
++;
1719 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1720 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1721 rdev
->wiphy
.cipher_suites
))
1722 goto nla_put_failure
;
1724 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1725 rdev
->wiphy
.max_num_pmkids
))
1726 goto nla_put_failure
;
1728 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1729 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1730 goto nla_put_failure
;
1732 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1733 rdev
->wiphy
.available_antennas_tx
) ||
1734 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1735 rdev
->wiphy
.available_antennas_rx
))
1736 goto nla_put_failure
;
1738 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1739 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1740 rdev
->wiphy
.probe_resp_offload
))
1741 goto nla_put_failure
;
1743 if ((rdev
->wiphy
.available_antennas_tx
||
1744 rdev
->wiphy
.available_antennas_rx
) &&
1745 rdev
->ops
->get_antenna
) {
1746 u32 tx_ant
= 0, rx_ant
= 0;
1749 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1751 if (nla_put_u32(msg
,
1752 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1755 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1757 goto nla_put_failure
;
1761 state
->split_start
++;
1765 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1766 rdev
->wiphy
.interface_modes
))
1767 goto nla_put_failure
;
1768 state
->split_start
++;
1772 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1774 goto nla_put_failure
;
1776 for (band
= state
->band_start
;
1777 band
< NUM_NL80211_BANDS
; band
++) {
1778 struct ieee80211_supported_band
*sband
;
1780 sband
= rdev
->wiphy
.bands
[band
];
1785 nl_band
= nla_nest_start(msg
, band
);
1787 goto nla_put_failure
;
1789 switch (state
->chan_start
) {
1791 if (nl80211_send_band_rateinfo(msg
, sband
))
1792 goto nla_put_failure
;
1793 state
->chan_start
++;
1797 /* add frequencies */
1798 nl_freqs
= nla_nest_start(
1799 msg
, NL80211_BAND_ATTR_FREQS
);
1801 goto nla_put_failure
;
1803 for (i
= state
->chan_start
- 1;
1804 i
< sband
->n_channels
;
1806 nl_freq
= nla_nest_start(msg
, i
);
1808 goto nla_put_failure
;
1810 chan
= &sband
->channels
[i
];
1812 if (nl80211_msg_put_channel(
1813 msg
, &rdev
->wiphy
, chan
,
1815 goto nla_put_failure
;
1817 nla_nest_end(msg
, nl_freq
);
1821 if (i
< sband
->n_channels
)
1822 state
->chan_start
= i
+ 2;
1824 state
->chan_start
= 0;
1825 nla_nest_end(msg
, nl_freqs
);
1828 nla_nest_end(msg
, nl_band
);
1831 /* start again here */
1832 if (state
->chan_start
)
1837 nla_nest_end(msg
, nl_bands
);
1839 if (band
< NUM_NL80211_BANDS
)
1840 state
->band_start
= band
+ 1;
1842 state
->band_start
= 0;
1844 /* if bands & channels are done, continue outside */
1845 if (state
->band_start
== 0 && state
->chan_start
== 0)
1846 state
->split_start
++;
1850 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1852 goto nla_put_failure
;
1854 i
= nl80211_add_commands_unsplit(rdev
, msg
);
1856 goto nla_put_failure
;
1858 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1859 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1860 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1861 CMD(channel_switch
, CHANNEL_SWITCH
);
1862 CMD(set_qos_map
, SET_QOS_MAP
);
1863 if (rdev
->wiphy
.features
&
1864 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1865 CMD(add_tx_ts
, ADD_TX_TS
);
1866 CMD(set_multicast_to_unicast
, SET_MULTICAST_TO_UNICAST
);
1867 CMD(update_connect_params
, UPDATE_CONNECT_PARAMS
);
1871 nla_nest_end(msg
, nl_cmds
);
1872 state
->split_start
++;
1876 if (rdev
->ops
->remain_on_channel
&&
1877 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1879 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1880 rdev
->wiphy
.max_remain_on_channel_duration
))
1881 goto nla_put_failure
;
1883 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1884 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1885 goto nla_put_failure
;
1887 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1888 goto nla_put_failure
;
1889 state
->split_start
++;
1894 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1895 goto nla_put_failure
;
1896 state
->split_start
++;
1900 state
->split_start
++;
1903 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1904 rdev
->wiphy
.software_iftypes
))
1905 goto nla_put_failure
;
1907 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1909 goto nla_put_failure
;
1911 state
->split_start
++;
1915 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1916 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1917 rdev
->wiphy
.ap_sme_capa
))
1918 goto nla_put_failure
;
1920 features
= rdev
->wiphy
.features
;
1922 * We can only add the per-channel limit information if the
1923 * dump is split, otherwise it makes it too big. Therefore
1924 * only advertise it in that case.
1927 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1928 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1929 goto nla_put_failure
;
1931 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1932 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1933 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1934 rdev
->wiphy
.ht_capa_mod_mask
))
1935 goto nla_put_failure
;
1937 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1938 rdev
->wiphy
.max_acl_mac_addrs
&&
1939 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1940 rdev
->wiphy
.max_acl_mac_addrs
))
1941 goto nla_put_failure
;
1944 * Any information below this point is only available to
1945 * applications that can deal with it being split. This
1946 * helps ensure that newly added capabilities don't break
1947 * older tools by overrunning their buffers.
1949 * We still increment split_start so that in the split
1950 * case we'll continue with more data in the next round,
1951 * but break unconditionally so unsplit data stops here.
1953 state
->split_start
++;
1956 if (rdev
->wiphy
.extended_capabilities
&&
1957 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1958 rdev
->wiphy
.extended_capabilities_len
,
1959 rdev
->wiphy
.extended_capabilities
) ||
1960 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1961 rdev
->wiphy
.extended_capabilities_len
,
1962 rdev
->wiphy
.extended_capabilities_mask
)))
1963 goto nla_put_failure
;
1965 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1966 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1967 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1968 rdev
->wiphy
.vht_capa_mod_mask
))
1969 goto nla_put_failure
;
1971 state
->split_start
++;
1974 if (nl80211_send_coalesce(msg
, rdev
))
1975 goto nla_put_failure
;
1977 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1978 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1979 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1980 goto nla_put_failure
;
1982 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1983 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1984 rdev
->wiphy
.max_ap_assoc_sta
))
1985 goto nla_put_failure
;
1987 state
->split_start
++;
1990 if (rdev
->wiphy
.n_vendor_commands
) {
1991 const struct nl80211_vendor_cmd_info
*info
;
1992 struct nlattr
*nested
;
1994 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1996 goto nla_put_failure
;
1998 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1999 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
2000 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
2001 goto nla_put_failure
;
2003 nla_nest_end(msg
, nested
);
2006 if (rdev
->wiphy
.n_vendor_events
) {
2007 const struct nl80211_vendor_cmd_info
*info
;
2008 struct nlattr
*nested
;
2010 nested
= nla_nest_start(msg
,
2011 NL80211_ATTR_VENDOR_EVENTS
);
2013 goto nla_put_failure
;
2015 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
2016 info
= &rdev
->wiphy
.vendor_events
[i
];
2017 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
2018 goto nla_put_failure
;
2020 nla_nest_end(msg
, nested
);
2022 state
->split_start
++;
2025 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
2026 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
2027 rdev
->wiphy
.max_num_csa_counters
))
2028 goto nla_put_failure
;
2030 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
2031 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
2032 goto nla_put_failure
;
2034 if (rdev
->wiphy
.max_sched_scan_reqs
&&
2035 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_MAX_REQS
,
2036 rdev
->wiphy
.max_sched_scan_reqs
))
2037 goto nla_put_failure
;
2039 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
2040 sizeof(rdev
->wiphy
.ext_features
),
2041 rdev
->wiphy
.ext_features
))
2042 goto nla_put_failure
;
2044 if (rdev
->wiphy
.bss_select_support
) {
2045 struct nlattr
*nested
;
2046 u32 bss_select_support
= rdev
->wiphy
.bss_select_support
;
2048 nested
= nla_nest_start(msg
, NL80211_ATTR_BSS_SELECT
);
2050 goto nla_put_failure
;
2053 while (bss_select_support
) {
2054 if ((bss_select_support
& 1) &&
2055 nla_put_flag(msg
, i
))
2056 goto nla_put_failure
;
2058 bss_select_support
>>= 1;
2060 nla_nest_end(msg
, nested
);
2063 state
->split_start
++;
2066 if (rdev
->wiphy
.num_iftype_ext_capab
&&
2067 rdev
->wiphy
.iftype_ext_capab
) {
2068 struct nlattr
*nested_ext_capab
, *nested
;
2070 nested
= nla_nest_start(msg
,
2071 NL80211_ATTR_IFTYPE_EXT_CAPA
);
2073 goto nla_put_failure
;
2075 for (i
= state
->capa_start
;
2076 i
< rdev
->wiphy
.num_iftype_ext_capab
; i
++) {
2077 const struct wiphy_iftype_ext_capab
*capab
;
2079 capab
= &rdev
->wiphy
.iftype_ext_capab
[i
];
2081 nested_ext_capab
= nla_nest_start(msg
, i
);
2082 if (!nested_ext_capab
||
2083 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
2085 nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
2086 capab
->extended_capabilities_len
,
2087 capab
->extended_capabilities
) ||
2088 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
2089 capab
->extended_capabilities_len
,
2090 capab
->extended_capabilities_mask
))
2091 goto nla_put_failure
;
2093 nla_nest_end(msg
, nested_ext_capab
);
2097 nla_nest_end(msg
, nested
);
2098 if (i
< rdev
->wiphy
.num_iftype_ext_capab
) {
2099 state
->capa_start
= i
+ 1;
2104 if (nla_put_u32(msg
, NL80211_ATTR_BANDS
,
2105 rdev
->wiphy
.nan_supported_bands
))
2106 goto nla_put_failure
;
2108 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
2109 NL80211_EXT_FEATURE_TXQS
)) {
2110 struct cfg80211_txq_stats txqstats
= {};
2113 res
= rdev_get_txq_stats(rdev
, NULL
, &txqstats
);
2115 !nl80211_put_txq_stats(msg
, &txqstats
,
2116 NL80211_ATTR_TXQ_STATS
))
2117 goto nla_put_failure
;
2119 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_LIMIT
,
2120 rdev
->wiphy
.txq_limit
))
2121 goto nla_put_failure
;
2122 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_MEMORY_LIMIT
,
2123 rdev
->wiphy
.txq_memory_limit
))
2124 goto nla_put_failure
;
2125 if (nla_put_u32(msg
, NL80211_ATTR_TXQ_QUANTUM
,
2126 rdev
->wiphy
.txq_quantum
))
2127 goto nla_put_failure
;
2131 state
->split_start
= 0;
2135 genlmsg_end(msg
, hdr
);
2139 genlmsg_cancel(msg
, hdr
);
2143 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
2144 struct netlink_callback
*cb
,
2145 struct nl80211_dump_wiphy_state
*state
)
2147 struct nlattr
**tb
= genl_family_attrbuf(&nl80211_fam
);
2148 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, tb
,
2149 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
2150 /* ignore parse errors for backward compatibility */
2154 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
2155 if (tb
[NL80211_ATTR_WIPHY
])
2156 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
2157 if (tb
[NL80211_ATTR_WDEV
])
2158 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
2159 if (tb
[NL80211_ATTR_IFINDEX
]) {
2160 struct net_device
*netdev
;
2161 struct cfg80211_registered_device
*rdev
;
2162 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2164 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2167 if (netdev
->ieee80211_ptr
) {
2168 rdev
= wiphy_to_rdev(
2169 netdev
->ieee80211_ptr
->wiphy
);
2170 state
->filter_wiphy
= rdev
->wiphy_idx
;
2177 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2180 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
2181 struct cfg80211_registered_device
*rdev
;
2185 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
2190 state
->filter_wiphy
= -1;
2191 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
2197 cb
->args
[0] = (long)state
;
2200 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2201 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2203 if (++idx
<= state
->start
)
2205 if (state
->filter_wiphy
!= -1 &&
2206 state
->filter_wiphy
!= rdev
->wiphy_idx
)
2208 /* attempt to fit multiple wiphy data chunks into the skb */
2210 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
2212 NETLINK_CB(cb
->skb
).portid
,
2214 NLM_F_MULTI
, state
);
2217 * If sending the wiphy data didn't fit (ENOBUFS
2218 * or EMSGSIZE returned), this SKB is still
2219 * empty (so it's not too big because another
2220 * wiphy dataset is already in the skb) and
2221 * we've not tried to adjust the dump allocation
2222 * yet ... then adjust the alloc size to be
2223 * bigger, and return 1 but with the empty skb.
2224 * This results in an empty message being RX'ed
2225 * in userspace, but that is ignored.
2227 * We can then retry with the larger buffer.
2229 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
2230 !skb
->len
&& !state
->split
&&
2231 cb
->min_dump_alloc
< 4096) {
2232 cb
->min_dump_alloc
= 4096;
2233 state
->split_start
= 0;
2240 } while (state
->split_start
> 0);
2250 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
2252 kfree((void *)cb
->args
[0]);
2256 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2258 struct sk_buff
*msg
;
2259 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2260 struct nl80211_dump_wiphy_state state
= {};
2262 msg
= nlmsg_new(4096, GFP_KERNEL
);
2266 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
2267 info
->snd_portid
, info
->snd_seq
, 0,
2273 return genlmsg_reply(msg
, info
);
2276 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
2277 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
2278 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
2279 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
2280 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
2281 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
2284 static int parse_txq_params(struct nlattr
*tb
[],
2285 struct ieee80211_txq_params
*txq_params
)
2289 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
2290 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
2291 !tb
[NL80211_TXQ_ATTR_AIFS
])
2294 ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
2295 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
2296 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
2297 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
2298 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
2300 if (ac
>= NL80211_NUM_ACS
)
2302 txq_params
->ac
= array_index_nospec(ac
, NL80211_NUM_ACS
);
2306 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
2309 * You can only set the channel explicitly for WDS interfaces,
2310 * all others have their channel managed via their respective
2311 * "establish a connection" command (connect, join, ...)
2313 * For AP/GO and mesh mode, the channel can be set with the
2314 * channel userspace API, but is only stored and passed to the
2315 * low-level driver when the AP starts or the mesh is joined.
2316 * This is for backward compatibility, userspace can also give
2317 * the channel in the start-ap or join-mesh commands instead.
2319 * Monitors are special as they are normally slaved to
2320 * whatever else is going on, so they have their own special
2321 * operation to set the monitor channel if possible.
2324 wdev
->iftype
== NL80211_IFTYPE_AP
||
2325 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
2326 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
2327 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
2330 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
2331 struct genl_info
*info
,
2332 struct cfg80211_chan_def
*chandef
)
2336 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
2339 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
2341 memset(chandef
, 0, sizeof(*chandef
));
2343 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
2344 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
2345 chandef
->center_freq1
= control_freq
;
2346 chandef
->center_freq2
= 0;
2348 /* Primary channel not allowed */
2349 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
2352 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2353 enum nl80211_channel_type chantype
;
2355 chantype
= nla_get_u32(
2356 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2359 case NL80211_CHAN_NO_HT
:
2360 case NL80211_CHAN_HT20
:
2361 case NL80211_CHAN_HT40PLUS
:
2362 case NL80211_CHAN_HT40MINUS
:
2363 cfg80211_chandef_create(chandef
, chandef
->chan
,
2365 /* user input for center_freq is incorrect */
2366 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
] &&
2367 chandef
->center_freq1
!= nla_get_u32(
2368 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]))
2370 /* center_freq2 must be zero */
2371 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
] &&
2372 nla_get_u32(info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]))
2378 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
2380 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
2381 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
2382 chandef
->center_freq1
=
2384 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
2385 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
2386 chandef
->center_freq2
=
2388 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
2391 if (!cfg80211_chandef_valid(chandef
))
2394 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
2395 IEEE80211_CHAN_DISABLED
))
2398 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
2399 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
2400 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
2406 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
2407 struct net_device
*dev
,
2408 struct genl_info
*info
)
2410 struct cfg80211_chan_def chandef
;
2412 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
2413 struct wireless_dev
*wdev
= NULL
;
2416 wdev
= dev
->ieee80211_ptr
;
2417 if (!nl80211_can_set_dev_channel(wdev
))
2420 iftype
= wdev
->iftype
;
2422 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2427 case NL80211_IFTYPE_AP
:
2428 case NL80211_IFTYPE_P2P_GO
:
2429 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2434 if (wdev
->beacon_interval
) {
2435 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2436 !(rdev
->wiphy
.features
&
2437 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2442 /* Only allow dynamic channel width changes */
2443 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2447 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2451 wdev
->preset_chandef
= chandef
;
2454 case NL80211_IFTYPE_MESH_POINT
:
2455 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2457 case NL80211_IFTYPE_MONITOR
:
2458 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2467 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2469 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2470 struct net_device
*netdev
= info
->user_ptr
[1];
2472 return __nl80211_set_channel(rdev
, netdev
, info
);
2475 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2477 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2478 struct net_device
*dev
= info
->user_ptr
[1];
2479 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2482 if (!info
->attrs
[NL80211_ATTR_MAC
])
2485 if (netif_running(dev
))
2488 if (!rdev
->ops
->set_wds_peer
)
2491 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2494 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2495 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2498 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2500 struct cfg80211_registered_device
*rdev
;
2501 struct net_device
*netdev
= NULL
;
2502 struct wireless_dev
*wdev
;
2503 int result
= 0, rem_txq_params
= 0;
2504 struct nlattr
*nl_txq_params
;
2506 u8 retry_short
= 0, retry_long
= 0;
2507 u32 frag_threshold
= 0, rts_threshold
= 0;
2508 u8 coverage_class
= 0;
2509 u32 txq_limit
= 0, txq_memory_limit
= 0, txq_quantum
= 0;
2514 * Try to find the wiphy and netdev. Normally this
2515 * function shouldn't need the netdev, but this is
2516 * done for backward compatibility -- previously
2517 * setting the channel was done per wiphy, but now
2518 * it is per netdev. Previous userland like hostapd
2519 * also passed a netdev to set_wiphy, so that it is
2520 * possible to let that go to the right netdev!
2523 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2524 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2526 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2527 if (netdev
&& netdev
->ieee80211_ptr
)
2528 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2534 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2537 return PTR_ERR(rdev
);
2542 wdev
= netdev
->ieee80211_ptr
;
2545 * end workaround code, by now the rdev is available
2546 * and locked, and wdev may or may not be NULL.
2549 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2550 result
= cfg80211_dev_rename(
2551 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2556 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2557 struct ieee80211_txq_params txq_params
;
2558 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2560 if (!rdev
->ops
->set_txq_params
)
2566 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2567 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2570 if (!netif_running(netdev
))
2573 nla_for_each_nested(nl_txq_params
,
2574 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2576 result
= nla_parse_nested(tb
, NL80211_TXQ_ATTR_MAX
,
2582 result
= parse_txq_params(tb
, &txq_params
);
2586 result
= rdev_set_txq_params(rdev
, netdev
,
2593 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2594 result
= __nl80211_set_channel(
2596 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2602 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2603 struct wireless_dev
*txp_wdev
= wdev
;
2604 enum nl80211_tx_power_setting type
;
2607 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2610 if (!rdev
->ops
->set_tx_power
)
2613 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2614 type
= nla_get_u32(info
->attrs
[idx
]);
2616 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2617 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2620 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2621 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2622 mbm
= nla_get_u32(info
->attrs
[idx
]);
2625 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2630 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2631 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2634 if ((!rdev
->wiphy
.available_antennas_tx
&&
2635 !rdev
->wiphy
.available_antennas_rx
) ||
2636 !rdev
->ops
->set_antenna
)
2639 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2640 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2642 /* reject antenna configurations which don't match the
2643 * available antenna masks, except for the "all" mask */
2644 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2645 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2648 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2649 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2651 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2658 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2659 retry_short
= nla_get_u8(
2660 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2661 if (retry_short
== 0)
2664 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2667 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2668 retry_long
= nla_get_u8(
2669 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2670 if (retry_long
== 0)
2673 changed
|= WIPHY_PARAM_RETRY_LONG
;
2676 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2677 frag_threshold
= nla_get_u32(
2678 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2679 if (frag_threshold
< 256)
2682 if (frag_threshold
!= (u32
) -1) {
2684 * Fragments (apart from the last one) are required to
2685 * have even length. Make the fragmentation code
2686 * simpler by stripping LSB should someone try to use
2687 * odd threshold value.
2689 frag_threshold
&= ~0x1;
2691 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2694 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2695 rts_threshold
= nla_get_u32(
2696 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2697 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2700 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2701 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2704 coverage_class
= nla_get_u8(
2705 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2706 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2709 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2710 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2713 changed
|= WIPHY_PARAM_DYN_ACK
;
2716 if (info
->attrs
[NL80211_ATTR_TXQ_LIMIT
]) {
2717 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
2718 NL80211_EXT_FEATURE_TXQS
))
2720 txq_limit
= nla_get_u32(
2721 info
->attrs
[NL80211_ATTR_TXQ_LIMIT
]);
2722 changed
|= WIPHY_PARAM_TXQ_LIMIT
;
2725 if (info
->attrs
[NL80211_ATTR_TXQ_MEMORY_LIMIT
]) {
2726 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
2727 NL80211_EXT_FEATURE_TXQS
))
2729 txq_memory_limit
= nla_get_u32(
2730 info
->attrs
[NL80211_ATTR_TXQ_MEMORY_LIMIT
]);
2731 changed
|= WIPHY_PARAM_TXQ_MEMORY_LIMIT
;
2734 if (info
->attrs
[NL80211_ATTR_TXQ_QUANTUM
]) {
2735 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
2736 NL80211_EXT_FEATURE_TXQS
))
2738 txq_quantum
= nla_get_u32(
2739 info
->attrs
[NL80211_ATTR_TXQ_QUANTUM
]);
2740 changed
|= WIPHY_PARAM_TXQ_QUANTUM
;
2744 u8 old_retry_short
, old_retry_long
;
2745 u32 old_frag_threshold
, old_rts_threshold
;
2746 u8 old_coverage_class
;
2747 u32 old_txq_limit
, old_txq_memory_limit
, old_txq_quantum
;
2749 if (!rdev
->ops
->set_wiphy_params
)
2752 old_retry_short
= rdev
->wiphy
.retry_short
;
2753 old_retry_long
= rdev
->wiphy
.retry_long
;
2754 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2755 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2756 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2757 old_txq_limit
= rdev
->wiphy
.txq_limit
;
2758 old_txq_memory_limit
= rdev
->wiphy
.txq_memory_limit
;
2759 old_txq_quantum
= rdev
->wiphy
.txq_quantum
;
2761 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2762 rdev
->wiphy
.retry_short
= retry_short
;
2763 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2764 rdev
->wiphy
.retry_long
= retry_long
;
2765 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2766 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2767 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2768 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2769 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2770 rdev
->wiphy
.coverage_class
= coverage_class
;
2771 if (changed
& WIPHY_PARAM_TXQ_LIMIT
)
2772 rdev
->wiphy
.txq_limit
= txq_limit
;
2773 if (changed
& WIPHY_PARAM_TXQ_MEMORY_LIMIT
)
2774 rdev
->wiphy
.txq_memory_limit
= txq_memory_limit
;
2775 if (changed
& WIPHY_PARAM_TXQ_QUANTUM
)
2776 rdev
->wiphy
.txq_quantum
= txq_quantum
;
2778 result
= rdev_set_wiphy_params(rdev
, changed
);
2780 rdev
->wiphy
.retry_short
= old_retry_short
;
2781 rdev
->wiphy
.retry_long
= old_retry_long
;
2782 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2783 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2784 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2785 rdev
->wiphy
.txq_limit
= old_txq_limit
;
2786 rdev
->wiphy
.txq_memory_limit
= old_txq_memory_limit
;
2787 rdev
->wiphy
.txq_quantum
= old_txq_quantum
;
2794 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2796 return (u64
)wdev
->identifier
|
2797 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2800 static int nl80211_send_chandef(struct sk_buff
*msg
,
2801 const struct cfg80211_chan_def
*chandef
)
2803 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2806 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2807 chandef
->chan
->center_freq
))
2809 switch (chandef
->width
) {
2810 case NL80211_CHAN_WIDTH_20_NOHT
:
2811 case NL80211_CHAN_WIDTH_20
:
2812 case NL80211_CHAN_WIDTH_40
:
2813 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2814 cfg80211_get_chandef_type(chandef
)))
2820 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2822 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2824 if (chandef
->center_freq2
&&
2825 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2830 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2831 struct cfg80211_registered_device
*rdev
,
2832 struct wireless_dev
*wdev
, bool removal
)
2834 struct net_device
*dev
= wdev
->netdev
;
2835 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2839 cmd
= NL80211_CMD_DEL_INTERFACE
;
2841 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2846 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2847 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2848 goto nla_put_failure
;
2850 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2851 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2852 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
2853 NL80211_ATTR_PAD
) ||
2854 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2855 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2856 rdev
->devlist_generation
^
2857 (cfg80211_rdev_list_generation
<< 2)) ||
2858 nla_put_u8(msg
, NL80211_ATTR_4ADDR
, wdev
->use_4addr
))
2859 goto nla_put_failure
;
2861 if (rdev
->ops
->get_channel
) {
2863 struct cfg80211_chan_def chandef
= {};
2865 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2867 if (nl80211_send_chandef(msg
, &chandef
))
2868 goto nla_put_failure
;
2872 if (rdev
->ops
->get_tx_power
) {
2875 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2877 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2879 goto nla_put_failure
;
2883 switch (wdev
->iftype
) {
2884 case NL80211_IFTYPE_AP
:
2885 if (wdev
->ssid_len
&&
2886 nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2887 goto nla_put_failure_locked
;
2889 case NL80211_IFTYPE_STATION
:
2890 case NL80211_IFTYPE_P2P_CLIENT
:
2891 case NL80211_IFTYPE_ADHOC
: {
2893 if (!wdev
->current_bss
)
2896 ssid_ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
2899 nla_put(msg
, NL80211_ATTR_SSID
, ssid_ie
[1], ssid_ie
+ 2))
2900 goto nla_put_failure_rcu_locked
;
2910 if (rdev
->ops
->get_txq_stats
) {
2911 struct cfg80211_txq_stats txqstats
= {};
2912 int ret
= rdev_get_txq_stats(rdev
, wdev
, &txqstats
);
2915 !nl80211_put_txq_stats(msg
, &txqstats
,
2916 NL80211_ATTR_TXQ_STATS
))
2917 goto nla_put_failure
;
2920 genlmsg_end(msg
, hdr
);
2923 nla_put_failure_rcu_locked
:
2925 nla_put_failure_locked
:
2928 genlmsg_cancel(msg
, hdr
);
2932 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2936 int wp_start
= cb
->args
[0];
2937 int if_start
= cb
->args
[1];
2938 int filter_wiphy
= -1;
2939 struct cfg80211_registered_device
*rdev
;
2940 struct wireless_dev
*wdev
;
2945 struct nl80211_dump_wiphy_state state
= {
2949 ret
= nl80211_dump_wiphy_parse(skb
, cb
, &state
);
2953 filter_wiphy
= state
.filter_wiphy
;
2956 * if filtering, set cb->args[2] to +1 since 0 is the default
2957 * value needed to determine that parsing is necessary.
2959 if (filter_wiphy
>= 0)
2960 cb
->args
[2] = filter_wiphy
+ 1;
2963 } else if (cb
->args
[2] > 0) {
2964 filter_wiphy
= cb
->args
[2] - 1;
2967 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2968 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2970 if (wp_idx
< wp_start
) {
2975 if (filter_wiphy
>= 0 && filter_wiphy
!= rdev
->wiphy_idx
)
2980 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
2981 if (if_idx
< if_start
) {
2985 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2986 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2987 rdev
, wdev
, false) < 0) {
2996 cb
->args
[0] = wp_idx
;
2997 cb
->args
[1] = if_idx
;
3006 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3008 struct sk_buff
*msg
;
3009 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3010 struct wireless_dev
*wdev
= info
->user_ptr
[1];
3012 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3016 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3017 rdev
, wdev
, false) < 0) {
3022 return genlmsg_reply(msg
, info
);
3025 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
3026 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
3027 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
3028 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
3029 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
3030 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
3031 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
3034 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
3036 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
3044 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
, nla
,
3045 mntr_flags_policy
, NULL
))
3048 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
3050 *mntrflags
|= (1<<flag
);
3052 *mntrflags
|= MONITOR_FLAG_CHANGED
;
3057 static int nl80211_parse_mon_options(struct cfg80211_registered_device
*rdev
,
3058 enum nl80211_iftype type
,
3059 struct genl_info
*info
,
3060 struct vif_params
*params
)
3062 bool change
= false;
3065 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
3066 if (type
!= NL80211_IFTYPE_MONITOR
)
3069 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
3077 if (params
->flags
& MONITOR_FLAG_ACTIVE
&&
3078 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
3081 if (info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]) {
3082 const u8
*mumimo_groups
;
3083 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
3085 if (type
!= NL80211_IFTYPE_MONITOR
)
3088 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
3092 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]);
3094 /* bits 0 and 63 are reserved and must be zero */
3095 if ((mumimo_groups
[0] & BIT(0)) ||
3096 (mumimo_groups
[VHT_MUMIMO_GROUPS_DATA_LEN
- 1] & BIT(7)))
3099 params
->vht_mumimo_groups
= mumimo_groups
;
3103 if (info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]) {
3104 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
3106 if (type
!= NL80211_IFTYPE_MONITOR
)
3109 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
3112 params
->vht_mumimo_follow_addr
=
3113 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]);
3117 return change
? 1 : 0;
3120 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
3121 struct net_device
*netdev
, u8 use_4addr
,
3122 enum nl80211_iftype iftype
)
3125 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
3131 case NL80211_IFTYPE_AP_VLAN
:
3132 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
3135 case NL80211_IFTYPE_STATION
:
3136 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
3146 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3148 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3149 struct vif_params params
;
3151 enum nl80211_iftype otype
, ntype
;
3152 struct net_device
*dev
= info
->user_ptr
[1];
3153 bool change
= false;
3155 memset(¶ms
, 0, sizeof(params
));
3157 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
3159 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
3160 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
3163 if (ntype
> NL80211_IFTYPE_MAX
)
3167 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
3168 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3170 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
3172 if (netif_running(dev
))
3176 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
3177 IEEE80211_MAX_MESH_ID_LEN
);
3178 wdev
->mesh_id_up_len
=
3179 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
3180 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
3181 wdev
->mesh_id_up_len
);
3185 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
3186 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
3188 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
3192 params
.use_4addr
= -1;
3195 err
= nl80211_parse_mon_options(rdev
, ntype
, info
, ¶ms
);
3202 err
= cfg80211_change_iface(rdev
, dev
, ntype
, ¶ms
);
3206 if (!err
&& params
.use_4addr
!= -1)
3207 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
3212 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3214 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3215 struct vif_params params
;
3216 struct wireless_dev
*wdev
;
3217 struct sk_buff
*msg
;
3219 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
3221 /* to avoid failing a new interface creation due to pending removal */
3222 cfg80211_destroy_ifaces(rdev
);
3224 memset(¶ms
, 0, sizeof(params
));
3226 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
3229 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
3230 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
3231 if (type
> NL80211_IFTYPE_MAX
)
3235 if (!rdev
->ops
->add_virtual_intf
)
3238 if ((type
== NL80211_IFTYPE_P2P_DEVICE
|| type
== NL80211_IFTYPE_NAN
||
3239 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
3240 info
->attrs
[NL80211_ATTR_MAC
]) {
3241 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
3243 if (!is_valid_ether_addr(params
.macaddr
))
3244 return -EADDRNOTAVAIL
;
3247 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
3248 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
3249 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
3254 if (!cfg80211_iftype_allowed(&rdev
->wiphy
, type
, params
.use_4addr
, 0))
3257 err
= nl80211_parse_mon_options(rdev
, type
, info
, ¶ms
);
3261 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3265 wdev
= rdev_add_virtual_intf(rdev
,
3266 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
3267 NET_NAME_USER
, type
, ¶ms
);
3268 if (WARN_ON(!wdev
)) {
3271 } else if (IS_ERR(wdev
)) {
3273 return PTR_ERR(wdev
);
3276 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
3277 wdev
->owner_nlportid
= info
->snd_portid
;
3280 case NL80211_IFTYPE_MESH_POINT
:
3281 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
3284 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
3285 IEEE80211_MAX_MESH_ID_LEN
);
3286 wdev
->mesh_id_up_len
=
3287 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
3288 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
3289 wdev
->mesh_id_up_len
);
3292 case NL80211_IFTYPE_NAN
:
3293 case NL80211_IFTYPE_P2P_DEVICE
:
3295 * P2P Device and NAN do not have a netdev, so don't go
3296 * through the netdev notifier and must be added here
3298 mutex_init(&wdev
->mtx
);
3299 INIT_LIST_HEAD(&wdev
->event_list
);
3300 spin_lock_init(&wdev
->event_lock
);
3301 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
3302 spin_lock_init(&wdev
->mgmt_registrations_lock
);
3304 wdev
->identifier
= ++rdev
->wdev_id
;
3305 list_add_rcu(&wdev
->list
, &rdev
->wiphy
.wdev_list
);
3306 rdev
->devlist_generation
++;
3312 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3313 rdev
, wdev
, false) < 0) {
3319 * For wdevs which have no associated netdev object (e.g. of type
3320 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3321 * For all other types, the event will be generated from the
3325 nl80211_notify_iface(rdev
, wdev
, NL80211_CMD_NEW_INTERFACE
);
3327 return genlmsg_reply(msg
, info
);
3330 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3332 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3333 struct wireless_dev
*wdev
= info
->user_ptr
[1];
3335 if (!rdev
->ops
->del_virtual_intf
)
3339 * If we remove a wireless device without a netdev then clear
3340 * user_ptr[1] so that nl80211_post_doit won't dereference it
3341 * to check if it needs to do dev_put(). Otherwise it crashes
3342 * since the wdev has been freed, unlike with a netdev where
3343 * we need the dev_put() for the netdev to really be freed.
3346 info
->user_ptr
[1] = NULL
;
3348 return rdev_del_virtual_intf(rdev
, wdev
);
3351 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
3353 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3354 struct net_device
*dev
= info
->user_ptr
[1];
3357 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
3360 if (!rdev
->ops
->set_noack_map
)
3363 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
3365 return rdev_set_noack_map(rdev
, dev
, noack_map
);
3368 struct get_key_cookie
{
3369 struct sk_buff
*msg
;
3374 static void get_key_callback(void *c
, struct key_params
*params
)
3377 struct get_key_cookie
*cookie
= c
;
3380 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
3381 params
->key_len
, params
->key
)) ||
3383 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
3384 params
->seq_len
, params
->seq
)) ||
3386 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
3388 goto nla_put_failure
;
3390 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
3392 goto nla_put_failure
;
3395 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
3396 params
->key_len
, params
->key
)) ||
3398 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
3399 params
->seq_len
, params
->seq
)) ||
3401 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
3403 goto nla_put_failure
;
3405 if (nla_put_u8(cookie
->msg
, NL80211_KEY_IDX
, cookie
->idx
))
3406 goto nla_put_failure
;
3408 nla_nest_end(cookie
->msg
, key
);
3415 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
3417 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3419 struct net_device
*dev
= info
->user_ptr
[1];
3421 const u8
*mac_addr
= NULL
;
3423 struct get_key_cookie cookie
= {
3427 struct sk_buff
*msg
;
3429 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
3430 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
3435 if (info
->attrs
[NL80211_ATTR_MAC
])
3436 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3438 pairwise
= !!mac_addr
;
3439 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
3440 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
3442 if (kt
>= NUM_NL80211_KEYTYPES
)
3444 if (kt
!= NL80211_KEYTYPE_GROUP
&&
3445 kt
!= NL80211_KEYTYPE_PAIRWISE
)
3447 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
3450 if (!rdev
->ops
->get_key
)
3453 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3456 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3460 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3461 NL80211_CMD_NEW_KEY
);
3463 goto nla_put_failure
;
3466 cookie
.idx
= key_idx
;
3468 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3469 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
3470 goto nla_put_failure
;
3472 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
3473 goto nla_put_failure
;
3475 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
3482 goto nla_put_failure
;
3484 genlmsg_end(msg
, hdr
);
3485 return genlmsg_reply(msg
, info
);
3494 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
3496 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3497 struct key_parse key
;
3499 struct net_device
*dev
= info
->user_ptr
[1];
3501 err
= nl80211_parse_key(info
, &key
);
3508 /* only support setting default key */
3509 if (!key
.def
&& !key
.defmgmt
)
3512 wdev_lock(dev
->ieee80211_ptr
);
3515 if (!rdev
->ops
->set_default_key
) {
3520 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3524 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
3525 key
.def_uni
, key
.def_multi
);
3530 #ifdef CONFIG_CFG80211_WEXT
3531 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
3534 if (key
.def_uni
|| !key
.def_multi
) {
3539 if (!rdev
->ops
->set_default_mgmt_key
) {
3544 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3548 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
3552 #ifdef CONFIG_CFG80211_WEXT
3553 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3558 wdev_unlock(dev
->ieee80211_ptr
);
3563 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3565 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3567 struct net_device
*dev
= info
->user_ptr
[1];
3568 struct key_parse key
;
3569 const u8
*mac_addr
= NULL
;
3571 err
= nl80211_parse_key(info
, &key
);
3578 if (info
->attrs
[NL80211_ATTR_MAC
])
3579 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3581 if (key
.type
== -1) {
3583 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3585 key
.type
= NL80211_KEYTYPE_GROUP
;
3589 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3590 key
.type
!= NL80211_KEYTYPE_GROUP
)
3593 if (!rdev
->ops
->add_key
)
3596 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3597 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3601 wdev_lock(dev
->ieee80211_ptr
);
3602 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3604 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3605 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3607 wdev_unlock(dev
->ieee80211_ptr
);
3612 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3614 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3616 struct net_device
*dev
= info
->user_ptr
[1];
3617 u8
*mac_addr
= NULL
;
3618 struct key_parse key
;
3620 err
= nl80211_parse_key(info
, &key
);
3624 if (info
->attrs
[NL80211_ATTR_MAC
])
3625 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3627 if (key
.type
== -1) {
3629 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3631 key
.type
= NL80211_KEYTYPE_GROUP
;
3635 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3636 key
.type
!= NL80211_KEYTYPE_GROUP
)
3639 if (!rdev
->ops
->del_key
)
3642 wdev_lock(dev
->ieee80211_ptr
);
3643 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3645 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3646 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3650 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3651 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3654 #ifdef CONFIG_CFG80211_WEXT
3656 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3657 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3658 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3659 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3662 wdev_unlock(dev
->ieee80211_ptr
);
3667 /* This function returns an error or the number of nested attributes */
3668 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3670 struct nlattr
*attr
;
3671 int n_entries
= 0, tmp
;
3673 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3674 if (nla_len(attr
) != ETH_ALEN
)
3684 * This function parses ACL information and allocates memory for ACL data.
3685 * On successful return, the calling function is responsible to free the
3686 * ACL buffer returned by this function.
3688 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3689 struct genl_info
*info
)
3691 enum nl80211_acl_policy acl_policy
;
3692 struct nlattr
*attr
;
3693 struct cfg80211_acl_data
*acl
;
3694 int i
= 0, n_entries
, tmp
;
3696 if (!wiphy
->max_acl_mac_addrs
)
3697 return ERR_PTR(-EOPNOTSUPP
);
3699 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3700 return ERR_PTR(-EINVAL
);
3702 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3703 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3704 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3705 return ERR_PTR(-EINVAL
);
3707 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3708 return ERR_PTR(-EINVAL
);
3710 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3712 return ERR_PTR(n_entries
);
3714 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3715 return ERR_PTR(-ENOTSUPP
);
3717 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3720 return ERR_PTR(-ENOMEM
);
3722 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3723 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3727 acl
->n_acl_entries
= n_entries
;
3728 acl
->acl_policy
= acl_policy
;
3733 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3735 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3736 struct net_device
*dev
= info
->user_ptr
[1];
3737 struct cfg80211_acl_data
*acl
;
3740 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3741 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3744 if (!dev
->ieee80211_ptr
->beacon_interval
)
3747 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3749 return PTR_ERR(acl
);
3751 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3758 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
3759 u8
*rates
, u8 rates_len
)
3764 for (i
= 0; i
< rates_len
; i
++) {
3765 int rate
= (rates
[i
] & 0x7f) * 5;
3768 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
3769 struct ieee80211_rate
*srate
=
3770 &sband
->bitrates
[ridx
];
3771 if (rate
== srate
->bitrate
) {
3776 if (ridx
== sband
->n_bitrates
)
3777 return 0; /* rate not found */
3783 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
3784 u8
*rates
, u8 rates_len
,
3785 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
3789 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
3791 for (i
= 0; i
< rates_len
; i
++) {
3794 ridx
= rates
[i
] / 8;
3795 rbit
= BIT(rates
[i
] % 8);
3797 /* check validity */
3798 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
3801 /* check availability */
3802 ridx
= array_index_nospec(ridx
, IEEE80211_HT_MCS_MASK_LEN
);
3803 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
3812 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
3816 switch (vht_mcs_map
) {
3817 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
3819 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
3822 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
3825 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
3835 static void vht_build_mcs_mask(u16 vht_mcs_map
,
3836 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
3840 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
3841 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
3846 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
3847 struct nl80211_txrate_vht
*txrate
,
3848 u16 mcs
[NL80211_VHT_NSS_MAX
])
3850 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3851 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
3854 if (!sband
->vht_cap
.vht_supported
)
3857 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
3859 /* Build vht_mcs_mask from VHT capabilities */
3860 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
3862 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3863 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
3864 mcs
[i
] = txrate
->mcs
[i
];
3872 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
3873 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
3874 .len
= NL80211_MAX_SUPP_RATES
},
3875 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
3876 .len
= NL80211_MAX_SUPP_HT_RATES
},
3877 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
3878 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
3881 static int nl80211_parse_tx_bitrate_mask(struct genl_info
*info
,
3882 struct cfg80211_bitrate_mask
*mask
)
3884 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
3885 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3887 struct nlattr
*tx_rates
;
3888 struct ieee80211_supported_band
*sband
;
3891 memset(mask
, 0, sizeof(*mask
));
3892 /* Default to all rates enabled */
3893 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
3894 sband
= rdev
->wiphy
.bands
[i
];
3899 mask
->control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
3900 memcpy(mask
->control
[i
].ht_mcs
,
3901 sband
->ht_cap
.mcs
.rx_mask
,
3902 sizeof(mask
->control
[i
].ht_mcs
));
3904 if (!sband
->vht_cap
.vht_supported
)
3907 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3908 vht_build_mcs_mask(vht_tx_mcs_map
, mask
->control
[i
].vht_mcs
);
3911 /* if no rates are given set it back to the defaults */
3912 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
3915 /* The nested attribute uses enum nl80211_band as the index. This maps
3916 * directly to the enum nl80211_band values used in cfg80211.
3918 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
3919 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
3920 enum nl80211_band band
= nla_type(tx_rates
);
3923 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
3925 sband
= rdev
->wiphy
.bands
[band
];
3928 err
= nla_parse_nested(tb
, NL80211_TXRATE_MAX
, tx_rates
,
3929 nl80211_txattr_policy
, info
->extack
);
3932 if (tb
[NL80211_TXRATE_LEGACY
]) {
3933 mask
->control
[band
].legacy
= rateset_to_mask(
3935 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
3936 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
3937 if ((mask
->control
[band
].legacy
== 0) &&
3938 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
3941 if (tb
[NL80211_TXRATE_HT
]) {
3942 if (!ht_rateset_to_mask(
3944 nla_data(tb
[NL80211_TXRATE_HT
]),
3945 nla_len(tb
[NL80211_TXRATE_HT
]),
3946 mask
->control
[band
].ht_mcs
))
3949 if (tb
[NL80211_TXRATE_VHT
]) {
3950 if (!vht_set_mcs_mask(
3952 nla_data(tb
[NL80211_TXRATE_VHT
]),
3953 mask
->control
[band
].vht_mcs
))
3956 if (tb
[NL80211_TXRATE_GI
]) {
3957 mask
->control
[band
].gi
=
3958 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
3959 if (mask
->control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
3963 if (mask
->control
[band
].legacy
== 0) {
3964 /* don't allow empty legacy rates if HT or VHT
3965 * are not even supported.
3967 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
3968 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
3971 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3972 if (mask
->control
[band
].ht_mcs
[i
])
3975 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3976 if (mask
->control
[band
].vht_mcs
[i
])
3979 /* legacy and mcs rates may not be both empty */
3988 static int validate_beacon_tx_rate(struct cfg80211_registered_device
*rdev
,
3989 enum nl80211_band band
,
3990 struct cfg80211_bitrate_mask
*beacon_rate
)
3992 u32 count_ht
, count_vht
, i
;
3993 u32 rate
= beacon_rate
->control
[band
].legacy
;
3995 /* Allow only one rate */
3996 if (hweight32(rate
) > 1)
4000 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
4001 if (hweight8(beacon_rate
->control
[band
].ht_mcs
[i
]) > 1) {
4003 } else if (beacon_rate
->control
[band
].ht_mcs
[i
]) {
4008 if (count_ht
&& rate
)
4013 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4014 if (hweight16(beacon_rate
->control
[band
].vht_mcs
[i
]) > 1) {
4016 } else if (beacon_rate
->control
[band
].vht_mcs
[i
]) {
4021 if (count_vht
&& rate
)
4025 if ((count_ht
&& count_vht
) || (!rate
&& !count_ht
&& !count_vht
))
4029 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4030 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
))
4033 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4034 NL80211_EXT_FEATURE_BEACON_RATE_HT
))
4037 !wiphy_ext_feature_isset(&rdev
->wiphy
,
4038 NL80211_EXT_FEATURE_BEACON_RATE_VHT
))
4044 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
4045 struct cfg80211_beacon_data
*bcn
)
4047 bool haveinfo
= false;
4049 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
4050 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
4051 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
4052 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
4055 memset(bcn
, 0, sizeof(*bcn
));
4057 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
4058 int ret
= validate_beacon_head(attrs
[NL80211_ATTR_BEACON_HEAD
],
4064 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
4065 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
4071 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
4072 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
4073 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
4080 if (attrs
[NL80211_ATTR_IE
]) {
4081 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
4082 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
4085 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
4086 bcn
->proberesp_ies
=
4087 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
4088 bcn
->proberesp_ies_len
=
4089 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
4092 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
4093 bcn
->assocresp_ies
=
4094 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
4095 bcn
->assocresp_ies_len
=
4096 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
4099 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
4100 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
4101 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
4107 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings
*params
,
4115 for (i
= 0; i
< rates
[1]; i
++) {
4116 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HT_PHY
)
4117 params
->ht_required
= true;
4118 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)
4119 params
->vht_required
= true;
4124 * Since the nl80211 API didn't include, from the beginning, attributes about
4125 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4126 * benefit of drivers that rebuild IEs in the firmware.
4128 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings
*params
)
4130 const struct cfg80211_beacon_data
*bcn
= ¶ms
->beacon
;
4131 size_t ies_len
= bcn
->tail_len
;
4132 const u8
*ies
= bcn
->tail
;
4136 rates
= cfg80211_find_ie(WLAN_EID_SUPP_RATES
, ies
, ies_len
);
4137 nl80211_check_ap_rate_selectors(params
, rates
);
4139 rates
= cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES
, ies
, ies_len
);
4140 nl80211_check_ap_rate_selectors(params
, rates
);
4142 cap
= cfg80211_find_ie(WLAN_EID_HT_CAPABILITY
, ies
, ies_len
);
4143 if (cap
&& cap
[1] >= sizeof(*params
->ht_cap
))
4144 params
->ht_cap
= (void *)(cap
+ 2);
4145 cap
= cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY
, ies
, ies_len
);
4146 if (cap
&& cap
[1] >= sizeof(*params
->vht_cap
))
4147 params
->vht_cap
= (void *)(cap
+ 2);
4150 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
4151 struct cfg80211_ap_settings
*params
)
4153 struct wireless_dev
*wdev
;
4156 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
4157 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
4158 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4161 if (!wdev
->preset_chandef
.chan
)
4164 params
->chandef
= wdev
->preset_chandef
;
4172 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
4173 enum nl80211_auth_type auth_type
,
4174 enum nl80211_commands cmd
)
4176 if (auth_type
> NL80211_AUTHTYPE_MAX
)
4180 case NL80211_CMD_AUTHENTICATE
:
4181 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
4182 auth_type
== NL80211_AUTHTYPE_SAE
)
4184 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
4185 NL80211_EXT_FEATURE_FILS_STA
) &&
4186 (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
4187 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4188 auth_type
== NL80211_AUTHTYPE_FILS_PK
))
4191 case NL80211_CMD_CONNECT
:
4192 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
4193 auth_type
== NL80211_AUTHTYPE_SAE
)
4196 /* FILS with SK PFS or PK not supported yet */
4197 if (auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4198 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
4200 if (!wiphy_ext_feature_isset(
4202 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
4203 auth_type
== NL80211_AUTHTYPE_FILS_SK
)
4206 case NL80211_CMD_START_AP
:
4207 /* SAE not supported yet */
4208 if (auth_type
== NL80211_AUTHTYPE_SAE
)
4210 /* FILS not supported yet */
4211 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
4212 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
4213 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
4221 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
4223 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4224 struct net_device
*dev
= info
->user_ptr
[1];
4225 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4226 struct cfg80211_ap_settings params
;
4229 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4230 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4233 if (!rdev
->ops
->start_ap
)
4236 if (wdev
->beacon_interval
)
4239 memset(¶ms
, 0, sizeof(params
));
4241 /* these are required for START_AP */
4242 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
4243 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
4244 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
4247 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
4251 params
.beacon_interval
=
4252 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4253 params
.dtim_period
=
4254 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
4256 err
= cfg80211_validate_beacon_int(rdev
, dev
->ieee80211_ptr
->iftype
,
4257 params
.beacon_interval
);
4262 * In theory, some of these attributes should be required here
4263 * but since they were not used when the command was originally
4264 * added, keep them optional for old user space programs to let
4265 * them continue to work with drivers that do not need the
4266 * additional information -- drivers must check!
4268 if (info
->attrs
[NL80211_ATTR_SSID
]) {
4269 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4271 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4272 if (params
.ssid_len
== 0 ||
4273 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
4277 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
4278 params
.hidden_ssid
= nla_get_u32(
4279 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
4280 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
4281 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
4282 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
4286 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4288 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4289 params
.auth_type
= nla_get_u32(
4290 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4291 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
4292 NL80211_CMD_START_AP
))
4295 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4297 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
4298 NL80211_MAX_NR_CIPHER_SUITES
);
4302 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
4303 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
4305 params
.inactivity_timeout
= nla_get_u16(
4306 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
4309 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4310 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4312 params
.p2p_ctwindow
=
4313 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4314 if (params
.p2p_ctwindow
> 127)
4316 if (params
.p2p_ctwindow
!= 0 &&
4317 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4321 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4324 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4326 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4329 params
.p2p_opp_ps
= tmp
;
4330 if (params
.p2p_opp_ps
!= 0 &&
4331 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4335 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4336 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
4339 } else if (wdev
->preset_chandef
.chan
) {
4340 params
.chandef
= wdev
->preset_chandef
;
4341 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
4344 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
4348 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
4349 err
= nl80211_parse_tx_bitrate_mask(info
, ¶ms
.beacon_rate
);
4353 err
= validate_beacon_tx_rate(rdev
, params
.chandef
.chan
->band
,
4354 ¶ms
.beacon_rate
);
4359 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
4361 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
4362 switch (params
.smps_mode
) {
4363 case NL80211_SMPS_OFF
:
4365 case NL80211_SMPS_STATIC
:
4366 if (!(rdev
->wiphy
.features
&
4367 NL80211_FEATURE_STATIC_SMPS
))
4370 case NL80211_SMPS_DYNAMIC
:
4371 if (!(rdev
->wiphy
.features
&
4372 NL80211_FEATURE_DYNAMIC_SMPS
))
4379 params
.smps_mode
= NL80211_SMPS_OFF
;
4382 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
4383 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
4386 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
4387 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
4388 if (IS_ERR(params
.acl
))
4389 return PTR_ERR(params
.acl
);
4392 nl80211_calculate_ap_params(¶ms
);
4395 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
4397 wdev
->preset_chandef
= params
.chandef
;
4398 wdev
->beacon_interval
= params
.beacon_interval
;
4399 wdev
->chandef
= params
.chandef
;
4400 wdev
->ssid_len
= params
.ssid_len
;
4401 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
4403 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
4404 wdev
->conn_owner_nlportid
= info
->snd_portid
;
4413 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
4415 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4416 struct net_device
*dev
= info
->user_ptr
[1];
4417 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4418 struct cfg80211_beacon_data params
;
4421 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4422 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4425 if (!rdev
->ops
->change_beacon
)
4428 if (!wdev
->beacon_interval
)
4431 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
4436 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
4442 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
4444 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4445 struct net_device
*dev
= info
->user_ptr
[1];
4447 return cfg80211_stop_ap(rdev
, dev
, false);
4450 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
4451 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
4452 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
4453 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
4454 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
4455 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
4456 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
4459 static int parse_station_flags(struct genl_info
*info
,
4460 enum nl80211_iftype iftype
,
4461 struct station_parameters
*params
)
4463 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
4468 * Try parsing the new attribute first so userspace
4469 * can specify both for older kernels.
4471 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
4473 struct nl80211_sta_flag_update
*sta_flags
;
4475 sta_flags
= nla_data(nla
);
4476 params
->sta_flags_mask
= sta_flags
->mask
;
4477 params
->sta_flags_set
= sta_flags
->set
;
4478 params
->sta_flags_set
&= params
->sta_flags_mask
;
4479 if ((params
->sta_flags_mask
|
4480 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
4485 /* if present, parse the old attribute */
4487 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
4491 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
, nla
,
4492 sta_flags_policy
, info
->extack
))
4496 * Only allow certain flags for interface types so that
4497 * other attributes are silently ignored. Remember that
4498 * this is backward compatibility code with old userspace
4499 * and shouldn't be hit in other cases anyway.
4502 case NL80211_IFTYPE_AP
:
4503 case NL80211_IFTYPE_AP_VLAN
:
4504 case NL80211_IFTYPE_P2P_GO
:
4505 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4506 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4507 BIT(NL80211_STA_FLAG_WME
) |
4508 BIT(NL80211_STA_FLAG_MFP
);
4510 case NL80211_IFTYPE_P2P_CLIENT
:
4511 case NL80211_IFTYPE_STATION
:
4512 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4513 BIT(NL80211_STA_FLAG_TDLS_PEER
);
4515 case NL80211_IFTYPE_MESH_POINT
:
4516 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4517 BIT(NL80211_STA_FLAG_MFP
) |
4518 BIT(NL80211_STA_FLAG_AUTHORIZED
);
4524 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
4526 params
->sta_flags_set
|= (1<<flag
);
4528 /* no longer support new API additions in old API */
4529 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
4537 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
4540 struct nlattr
*rate
;
4543 enum nl80211_rate_info rate_flg
;
4545 rate
= nla_nest_start(msg
, attr
);
4549 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4550 bitrate
= cfg80211_calculate_bitrate(info
);
4551 /* report 16-bit bitrate only if we can */
4552 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
4554 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
4556 if (bitrate_compat
> 0 &&
4557 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
4561 case RATE_INFO_BW_5
:
4562 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
4564 case RATE_INFO_BW_10
:
4565 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
4570 case RATE_INFO_BW_20
:
4573 case RATE_INFO_BW_40
:
4574 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
4576 case RATE_INFO_BW_80
:
4577 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
4579 case RATE_INFO_BW_160
:
4580 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
4582 case RATE_INFO_BW_HE_RU
:
4584 WARN_ON(!(info
->flags
& RATE_INFO_FLAGS_HE_MCS
));
4587 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
4590 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
4591 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
4593 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4594 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4596 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
4597 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
4599 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
4601 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4602 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4604 } else if (info
->flags
& RATE_INFO_FLAGS_HE_MCS
) {
4605 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_MCS
, info
->mcs
))
4607 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_NSS
, info
->nss
))
4609 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_GI
, info
->he_gi
))
4611 if (nla_put_u8(msg
, NL80211_RATE_INFO_HE_DCM
, info
->he_dcm
))
4613 if (info
->bw
== RATE_INFO_BW_HE_RU
&&
4614 nla_put_u8(msg
, NL80211_RATE_INFO_HE_RU_ALLOC
,
4619 nla_nest_end(msg
, rate
);
4623 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
4632 attr
= nla_nest_start(msg
, id
);
4636 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
4637 if (!(mask
& BIT(i
)))
4640 if (nla_put_u8(msg
, i
, signal
[i
]))
4644 nla_nest_end(msg
, attr
);
4649 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
4651 struct cfg80211_registered_device
*rdev
,
4652 struct net_device
*dev
,
4653 const u8
*mac_addr
, struct station_info
*sinfo
)
4656 struct nlattr
*sinfoattr
, *bss_param
;
4658 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
4660 cfg80211_sinfo_release_content(sinfo
);
4664 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4665 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
4666 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
4667 goto nla_put_failure
;
4669 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
4671 goto nla_put_failure
;
4673 #define PUT_SINFO(attr, memb, type) do { \
4674 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
4675 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
4676 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4678 goto nla_put_failure; \
4680 #define PUT_SINFO_U64(attr, memb) do { \
4681 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
4682 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4683 sinfo->memb, NL80211_STA_INFO_PAD)) \
4684 goto nla_put_failure; \
4687 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
4688 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
4690 if (sinfo
->filled
& (BIT_ULL(NL80211_STA_INFO_RX_BYTES
) |
4691 BIT_ULL(NL80211_STA_INFO_RX_BYTES64
)) &&
4692 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
4693 (u32
)sinfo
->rx_bytes
))
4694 goto nla_put_failure
;
4696 if (sinfo
->filled
& (BIT_ULL(NL80211_STA_INFO_TX_BYTES
) |
4697 BIT_ULL(NL80211_STA_INFO_TX_BYTES64
)) &&
4698 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
4699 (u32
)sinfo
->tx_bytes
))
4700 goto nla_put_failure
;
4702 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
4703 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
4704 PUT_SINFO(LLID
, llid
, u16
);
4705 PUT_SINFO(PLID
, plid
, u16
);
4706 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
4707 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
4709 switch (rdev
->wiphy
.signal_type
) {
4710 case CFG80211_SIGNAL_TYPE_MBM
:
4711 PUT_SINFO(SIGNAL
, signal
, u8
);
4712 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
4717 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
4718 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4719 sinfo
->chain_signal
,
4720 NL80211_STA_INFO_CHAIN_SIGNAL
))
4721 goto nla_put_failure
;
4723 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
4724 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4725 sinfo
->chain_signal_avg
,
4726 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
4727 goto nla_put_failure
;
4729 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_TX_BITRATE
)) {
4730 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
4731 NL80211_STA_INFO_TX_BITRATE
))
4732 goto nla_put_failure
;
4734 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_RX_BITRATE
)) {
4735 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
4736 NL80211_STA_INFO_RX_BITRATE
))
4737 goto nla_put_failure
;
4740 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
4741 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
4742 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
4743 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
4744 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
4745 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
4746 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
4747 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
4748 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
4750 if (sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_BSS_PARAM
)) {
4751 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
4753 goto nla_put_failure
;
4755 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
4756 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
4757 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
4758 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
4759 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
4760 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
4761 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
4762 sinfo
->bss_param
.dtim_period
) ||
4763 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
4764 sinfo
->bss_param
.beacon_interval
))
4765 goto nla_put_failure
;
4767 nla_nest_end(msg
, bss_param
);
4769 if ((sinfo
->filled
& BIT_ULL(NL80211_STA_INFO_STA_FLAGS
)) &&
4770 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
4771 sizeof(struct nl80211_sta_flag_update
),
4773 goto nla_put_failure
;
4775 PUT_SINFO_U64(T_OFFSET
, t_offset
);
4776 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
4777 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
4778 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
4779 PUT_SINFO(ACK_SIGNAL
, ack_signal
, u8
);
4780 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
4781 NL80211_EXT_FEATURE_DATA_ACK_SIGNAL_SUPPORT
))
4782 PUT_SINFO(DATA_ACK_SIGNAL_AVG
, avg_ack_signal
, s8
);
4785 #undef PUT_SINFO_U64
4787 if (sinfo
->pertid
) {
4788 struct nlattr
*tidsattr
;
4791 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
4793 goto nla_put_failure
;
4795 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
4796 struct cfg80211_tid_stats
*tidstats
;
4797 struct nlattr
*tidattr
;
4799 tidstats
= &sinfo
->pertid
[tid
];
4801 if (!tidstats
->filled
)
4804 tidattr
= nla_nest_start(msg
, tid
+ 1);
4806 goto nla_put_failure
;
4808 #define PUT_TIDVAL_U64(attr, memb) do { \
4809 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
4810 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4811 tidstats->memb, NL80211_TID_STATS_PAD)) \
4812 goto nla_put_failure; \
4815 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
4816 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
4817 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
4818 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
4820 #undef PUT_TIDVAL_U64
4821 if ((tidstats
->filled
&
4822 BIT(NL80211_TID_STATS_TXQ_STATS
)) &&
4823 !nl80211_put_txq_stats(msg
, &tidstats
->txq_stats
,
4824 NL80211_TID_STATS_TXQ_STATS
))
4825 goto nla_put_failure
;
4827 nla_nest_end(msg
, tidattr
);
4830 nla_nest_end(msg
, tidsattr
);
4833 nla_nest_end(msg
, sinfoattr
);
4835 if (sinfo
->assoc_req_ies_len
&&
4836 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
4837 sinfo
->assoc_req_ies
))
4838 goto nla_put_failure
;
4840 cfg80211_sinfo_release_content(sinfo
);
4841 genlmsg_end(msg
, hdr
);
4845 cfg80211_sinfo_release_content(sinfo
);
4846 genlmsg_cancel(msg
, hdr
);
4850 static int nl80211_dump_station(struct sk_buff
*skb
,
4851 struct netlink_callback
*cb
)
4853 struct station_info sinfo
;
4854 struct cfg80211_registered_device
*rdev
;
4855 struct wireless_dev
*wdev
;
4856 u8 mac_addr
[ETH_ALEN
];
4857 int sta_idx
= cb
->args
[2];
4861 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4865 if (!wdev
->netdev
) {
4870 if (!rdev
->ops
->dump_station
) {
4876 memset(&sinfo
, 0, sizeof(sinfo
));
4877 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
4884 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
4885 NETLINK_CB(cb
->skb
).portid
,
4886 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4887 rdev
, wdev
->netdev
, mac_addr
,
4895 cb
->args
[2] = sta_idx
;
4903 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
4905 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4906 struct net_device
*dev
= info
->user_ptr
[1];
4907 struct station_info sinfo
;
4908 struct sk_buff
*msg
;
4909 u8
*mac_addr
= NULL
;
4912 memset(&sinfo
, 0, sizeof(sinfo
));
4914 if (!info
->attrs
[NL80211_ATTR_MAC
])
4917 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4919 if (!rdev
->ops
->get_station
)
4922 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
4926 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4928 cfg80211_sinfo_release_content(&sinfo
);
4932 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
4933 info
->snd_portid
, info
->snd_seq
, 0,
4934 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
4939 return genlmsg_reply(msg
, info
);
4942 int cfg80211_check_station_change(struct wiphy
*wiphy
,
4943 struct station_parameters
*params
,
4944 enum cfg80211_station_type statype
)
4946 if (params
->listen_interval
!= -1 &&
4947 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4950 if (params
->support_p2p_ps
!= -1 &&
4951 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4955 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
4956 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4959 /* When you run into this, adjust the code below for the new flag */
4960 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4963 case CFG80211_STA_MESH_PEER_KERNEL
:
4964 case CFG80211_STA_MESH_PEER_USER
:
4966 * No ignoring the TDLS flag here -- the userspace mesh
4967 * code doesn't have the bug of including TDLS in the
4970 if (params
->sta_flags_mask
&
4971 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4972 BIT(NL80211_STA_FLAG_MFP
) |
4973 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4976 case CFG80211_STA_TDLS_PEER_SETUP
:
4977 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4978 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4980 /* ignore since it can't change */
4981 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4984 /* disallow mesh-specific things */
4985 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4987 if (params
->local_pm
)
4989 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4993 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4994 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4995 /* TDLS can't be set, ... */
4996 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4999 * ... but don't bother the driver with it. This works around
5000 * a hostapd/wpa_supplicant issue -- it always includes the
5001 * TLDS_PEER flag in the mask even for AP mode.
5003 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
5006 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
5007 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
5008 /* reject other things that can't change */
5009 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
5011 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
5013 if (params
->supported_rates
)
5015 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
||
5020 if (statype
!= CFG80211_STA_AP_CLIENT
&&
5021 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
5027 case CFG80211_STA_AP_MLME_CLIENT
:
5028 /* Use this only for authorizing/unauthorizing a station */
5029 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
5032 case CFG80211_STA_AP_CLIENT
:
5033 case CFG80211_STA_AP_CLIENT_UNASSOC
:
5034 /* accept only the listed bits */
5035 if (params
->sta_flags_mask
&
5036 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5037 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5038 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
5039 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
5040 BIT(NL80211_STA_FLAG_WME
) |
5041 BIT(NL80211_STA_FLAG_MFP
)))
5044 /* but authenticated/associated only if driver handles it */
5045 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
5046 params
->sta_flags_mask
&
5047 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5048 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
5051 case CFG80211_STA_IBSS
:
5052 case CFG80211_STA_AP_STA
:
5053 /* reject any changes other than AUTHORIZED */
5054 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
5057 case CFG80211_STA_TDLS_PEER_SETUP
:
5058 /* reject any changes other than AUTHORIZED or WME */
5059 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
5060 BIT(NL80211_STA_FLAG_WME
)))
5062 /* force (at least) rates when authorizing */
5063 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
5064 !params
->supported_rates
)
5067 case CFG80211_STA_TDLS_PEER_ACTIVE
:
5068 /* reject any changes */
5070 case CFG80211_STA_MESH_PEER_KERNEL
:
5071 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
5074 case CFG80211_STA_MESH_PEER_USER
:
5075 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
5076 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
5082 * Older kernel versions ignored this attribute entirely, so don't
5083 * reject attempts to update it but mark it as unused instead so the
5084 * driver won't look at the data.
5086 if (statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
&&
5087 statype
!= CFG80211_STA_TDLS_PEER_SETUP
)
5088 params
->opmode_notif_used
= false;
5092 EXPORT_SYMBOL(cfg80211_check_station_change
);
5095 * Get vlan interface making sure it is running and on the right wiphy.
5097 static struct net_device
*get_vlan(struct genl_info
*info
,
5098 struct cfg80211_registered_device
*rdev
)
5100 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
5101 struct net_device
*v
;
5107 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
5109 return ERR_PTR(-ENODEV
);
5111 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
5116 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5117 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5118 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
5123 if (!netif_running(v
)) {
5131 return ERR_PTR(ret
);
5134 static const struct nla_policy
5135 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
5136 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
5137 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
5140 static int nl80211_parse_sta_wme(struct genl_info
*info
,
5141 struct station_parameters
*params
)
5143 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
5147 /* parse WME attributes if present */
5148 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
5151 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
5152 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
5153 nl80211_sta_wme_policy
, info
->extack
);
5157 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
5158 params
->uapsd_queues
= nla_get_u8(
5159 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
5160 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
5163 if (tb
[NL80211_STA_WME_MAX_SP
])
5164 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
5166 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
5169 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
5174 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
5175 struct station_parameters
*params
)
5177 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
5178 params
->supported_channels
=
5179 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
5180 params
->supported_channels_len
=
5181 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
5183 * Need to include at least one (first channel, number of
5184 * channels) tuple for each subband, and must have proper
5185 * tuples for the rest of the data as well.
5187 if (params
->supported_channels_len
< 2)
5189 if (params
->supported_channels_len
% 2)
5193 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
5194 params
->supported_oper_classes
=
5195 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
5196 params
->supported_oper_classes_len
=
5197 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
5199 * The value of the Length field of the Supported Operating
5200 * Classes element is between 2 and 253.
5202 if (params
->supported_oper_classes_len
< 2 ||
5203 params
->supported_oper_classes_len
> 253)
5209 static int nl80211_set_station_tdls(struct genl_info
*info
,
5210 struct station_parameters
*params
)
5213 /* Dummy STA entry gets updated once the peer capabilities are known */
5214 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
5215 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
5216 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
5218 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5219 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
5221 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
5222 if (info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]) {
5224 nla_data(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
5225 params
->he_capa_len
=
5226 nla_len(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
5228 if (params
->he_capa_len
< NL80211_HE_MIN_CAPABILITY_LEN
)
5232 err
= nl80211_parse_sta_channel_info(info
, params
);
5236 return nl80211_parse_sta_wme(info
, params
);
5239 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
5241 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5242 struct net_device
*dev
= info
->user_ptr
[1];
5243 struct station_parameters params
;
5247 memset(¶ms
, 0, sizeof(params
));
5249 if (!rdev
->ops
->change_station
)
5253 * AID and listen_interval properties can be set only for unassociated
5254 * station. Include these parameters here and will check them in
5255 * cfg80211_check_station_change().
5257 if (info
->attrs
[NL80211_ATTR_STA_AID
])
5258 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
5260 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
5261 params
.listen_interval
=
5262 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
5264 params
.listen_interval
= -1;
5266 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
5269 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
5270 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
5273 params
.support_p2p_ps
= tmp
;
5275 params
.support_p2p_ps
= -1;
5278 if (!info
->attrs
[NL80211_ATTR_MAC
])
5281 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5283 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
5284 params
.supported_rates
=
5285 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5286 params
.supported_rates_len
=
5287 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5290 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
5292 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
5293 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
5296 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
5298 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5299 params
.ext_capab_len
=
5300 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5303 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
5306 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
5307 params
.plink_action
=
5308 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
5309 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
5313 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
5314 params
.plink_state
=
5315 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
5316 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
5318 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]) {
5319 params
.peer_aid
= nla_get_u16(
5320 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
5321 if (params
.peer_aid
> IEEE80211_MAX_AID
)
5324 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
5327 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
5328 enum nl80211_mesh_power_mode pm
= nla_get_u32(
5329 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
5331 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
5332 pm
> NL80211_MESH_POWER_MAX
)
5335 params
.local_pm
= pm
;
5338 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
5339 params
.opmode_notif_used
= true;
5340 params
.opmode_notif
=
5341 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
5344 /* Include parameters for TDLS peer (will check later) */
5345 err
= nl80211_set_station_tdls(info
, ¶ms
);
5349 params
.vlan
= get_vlan(info
, rdev
);
5350 if (IS_ERR(params
.vlan
))
5351 return PTR_ERR(params
.vlan
);
5353 switch (dev
->ieee80211_ptr
->iftype
) {
5354 case NL80211_IFTYPE_AP
:
5355 case NL80211_IFTYPE_AP_VLAN
:
5356 case NL80211_IFTYPE_P2P_GO
:
5357 case NL80211_IFTYPE_P2P_CLIENT
:
5358 case NL80211_IFTYPE_STATION
:
5359 case NL80211_IFTYPE_ADHOC
:
5360 case NL80211_IFTYPE_MESH_POINT
:
5367 /* driver will call cfg80211_check_station_change() */
5368 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
5372 dev_put(params
.vlan
);
5377 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
5379 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5381 struct net_device
*dev
= info
->user_ptr
[1];
5382 struct station_parameters params
;
5383 u8
*mac_addr
= NULL
;
5384 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5385 BIT(NL80211_STA_FLAG_ASSOCIATED
);
5387 memset(¶ms
, 0, sizeof(params
));
5389 if (!rdev
->ops
->add_station
)
5392 if (!info
->attrs
[NL80211_ATTR_MAC
])
5395 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
5398 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
5401 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
5402 !info
->attrs
[NL80211_ATTR_PEER_AID
])
5405 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5406 params
.supported_rates
=
5407 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5408 params
.supported_rates_len
=
5409 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5410 params
.listen_interval
=
5411 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
5413 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
5416 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
5417 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
5420 params
.support_p2p_ps
= tmp
;
5423 * if not specified, assume it's supported for P2P GO interface,
5424 * and is NOT supported for AP interface
5426 params
.support_p2p_ps
=
5427 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
5430 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
5431 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
5433 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
5434 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
5437 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
5439 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
5440 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
5443 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
5445 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5446 params
.ext_capab_len
=
5447 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5450 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
5452 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5454 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
5456 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
5458 if (info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]) {
5460 nla_data(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
5461 params
.he_capa_len
=
5462 nla_len(info
->attrs
[NL80211_ATTR_HE_CAPABILITY
]);
5464 /* max len is validated in nla policy */
5465 if (params
.he_capa_len
< NL80211_HE_MIN_CAPABILITY_LEN
)
5469 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
5470 params
.opmode_notif_used
= true;
5471 params
.opmode_notif
=
5472 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
5475 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
5476 params
.plink_action
=
5477 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
5478 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
5482 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
5486 err
= nl80211_parse_sta_wme(info
, ¶ms
);
5490 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
5493 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5494 * as userspace might just pass through the capabilities from the IEs
5495 * directly, rather than enforcing this restriction and returning an
5496 * error in this case.
5498 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
5499 params
.ht_capa
= NULL
;
5500 params
.vht_capa
= NULL
;
5502 /* HE requires WME */
5503 if (params
.he_capa_len
)
5507 /* When you run into this, adjust the code below for the new flag */
5508 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
5510 switch (dev
->ieee80211_ptr
->iftype
) {
5511 case NL80211_IFTYPE_AP
:
5512 case NL80211_IFTYPE_AP_VLAN
:
5513 case NL80211_IFTYPE_P2P_GO
:
5514 /* ignore WME attributes if iface/sta is not capable */
5515 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
5516 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
5517 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5519 /* TDLS peers cannot be added */
5520 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5521 info
->attrs
[NL80211_ATTR_PEER_AID
])
5523 /* but don't bother the driver with it */
5524 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
5526 /* allow authenticated/associated only if driver handles it */
5527 if (!(rdev
->wiphy
.features
&
5528 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
5529 params
.sta_flags_mask
& auth_assoc
)
5532 /* Older userspace, or userspace wanting to be compatible with
5533 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5534 * and assoc flags in the mask, but assumes the station will be
5535 * added as associated anyway since this was the required driver
5536 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5538 * In order to not bother drivers with this quirk in the API
5539 * set the flags in both the mask and set for new stations in
5542 if (!(params
.sta_flags_mask
& auth_assoc
)) {
5543 params
.sta_flags_mask
|= auth_assoc
;
5544 params
.sta_flags_set
|= auth_assoc
;
5547 /* must be last in here for error handling */
5548 params
.vlan
= get_vlan(info
, rdev
);
5549 if (IS_ERR(params
.vlan
))
5550 return PTR_ERR(params
.vlan
);
5552 case NL80211_IFTYPE_MESH_POINT
:
5553 /* ignore uAPSD data */
5554 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5556 /* associated is disallowed */
5557 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
5559 /* TDLS peers cannot be added */
5560 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5561 info
->attrs
[NL80211_ATTR_PEER_AID
])
5564 case NL80211_IFTYPE_STATION
:
5565 case NL80211_IFTYPE_P2P_CLIENT
:
5566 /* ignore uAPSD data */
5567 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5569 /* these are disallowed */
5570 if (params
.sta_flags_mask
&
5571 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
5572 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
5574 /* Only TDLS peers can be added */
5575 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
5577 /* Can only add if TDLS ... */
5578 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
5580 /* ... with external setup is supported */
5581 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
5584 * Older wpa_supplicant versions always mark the TDLS peer
5585 * as authorized, but it shouldn't yet be.
5587 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
5593 /* be aware of params.vlan when changing code here */
5595 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
5598 dev_put(params
.vlan
);
5602 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
5604 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5605 struct net_device
*dev
= info
->user_ptr
[1];
5606 struct station_del_parameters params
;
5608 memset(¶ms
, 0, sizeof(params
));
5610 if (info
->attrs
[NL80211_ATTR_MAC
])
5611 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5613 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5614 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5615 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5616 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5619 if (!rdev
->ops
->del_station
)
5622 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
5624 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
5625 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
5626 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
5629 /* Default to Deauthentication frame */
5630 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
5633 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
5634 params
.reason_code
=
5635 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5636 if (params
.reason_code
== 0)
5637 return -EINVAL
; /* 0 is reserved */
5639 /* Default to reason code 2 */
5640 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
5643 return rdev_del_station(rdev
, dev
, ¶ms
);
5646 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5647 int flags
, struct net_device
*dev
,
5648 u8
*dst
, u8
*next_hop
,
5649 struct mpath_info
*pinfo
)
5652 struct nlattr
*pinfoattr
;
5654 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
5658 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5659 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
5660 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
5661 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
5662 goto nla_put_failure
;
5664 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
5666 goto nla_put_failure
;
5667 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
5668 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
5670 goto nla_put_failure
;
5671 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
5672 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
5673 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
5674 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
5676 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
5677 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
5679 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
5680 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
5682 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
5683 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
5684 pinfo
->discovery_timeout
)) ||
5685 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
5686 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
5687 pinfo
->discovery_retries
)))
5688 goto nla_put_failure
;
5690 nla_nest_end(msg
, pinfoattr
);
5692 genlmsg_end(msg
, hdr
);
5696 genlmsg_cancel(msg
, hdr
);
5700 static int nl80211_dump_mpath(struct sk_buff
*skb
,
5701 struct netlink_callback
*cb
)
5703 struct mpath_info pinfo
;
5704 struct cfg80211_registered_device
*rdev
;
5705 struct wireless_dev
*wdev
;
5707 u8 next_hop
[ETH_ALEN
];
5708 int path_idx
= cb
->args
[2];
5712 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5716 if (!rdev
->ops
->dump_mpath
) {
5721 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5727 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
5734 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5735 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5736 wdev
->netdev
, dst
, next_hop
,
5744 cb
->args
[2] = path_idx
;
5751 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5753 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5755 struct net_device
*dev
= info
->user_ptr
[1];
5756 struct mpath_info pinfo
;
5757 struct sk_buff
*msg
;
5759 u8 next_hop
[ETH_ALEN
];
5761 memset(&pinfo
, 0, sizeof(pinfo
));
5763 if (!info
->attrs
[NL80211_ATTR_MAC
])
5766 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5768 if (!rdev
->ops
->get_mpath
)
5771 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5774 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
5778 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5782 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5783 dev
, dst
, next_hop
, &pinfo
) < 0) {
5788 return genlmsg_reply(msg
, info
);
5791 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5793 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5794 struct net_device
*dev
= info
->user_ptr
[1];
5796 u8
*next_hop
= NULL
;
5798 if (!info
->attrs
[NL80211_ATTR_MAC
])
5801 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5804 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5805 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5807 if (!rdev
->ops
->change_mpath
)
5810 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5813 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
5816 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5818 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5819 struct net_device
*dev
= info
->user_ptr
[1];
5821 u8
*next_hop
= NULL
;
5823 if (!info
->attrs
[NL80211_ATTR_MAC
])
5826 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5829 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5830 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5832 if (!rdev
->ops
->add_mpath
)
5835 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5838 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
5841 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5843 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5844 struct net_device
*dev
= info
->user_ptr
[1];
5847 if (info
->attrs
[NL80211_ATTR_MAC
])
5848 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5850 if (!rdev
->ops
->del_mpath
)
5853 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5856 return rdev_del_mpath(rdev
, dev
, dst
);
5859 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
5861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5863 struct net_device
*dev
= info
->user_ptr
[1];
5864 struct mpath_info pinfo
;
5865 struct sk_buff
*msg
;
5869 memset(&pinfo
, 0, sizeof(pinfo
));
5871 if (!info
->attrs
[NL80211_ATTR_MAC
])
5874 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5876 if (!rdev
->ops
->get_mpp
)
5879 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5882 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
5886 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5890 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5891 dev
, dst
, mpp
, &pinfo
) < 0) {
5896 return genlmsg_reply(msg
, info
);
5899 static int nl80211_dump_mpp(struct sk_buff
*skb
,
5900 struct netlink_callback
*cb
)
5902 struct mpath_info pinfo
;
5903 struct cfg80211_registered_device
*rdev
;
5904 struct wireless_dev
*wdev
;
5907 int path_idx
= cb
->args
[2];
5911 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5915 if (!rdev
->ops
->dump_mpp
) {
5920 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5926 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
5933 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5934 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5935 wdev
->netdev
, dst
, mpp
,
5943 cb
->args
[2] = path_idx
;
5950 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
5952 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5953 struct net_device
*dev
= info
->user_ptr
[1];
5954 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5955 struct bss_parameters params
;
5958 memset(¶ms
, 0, sizeof(params
));
5959 /* default to not changing parameters */
5960 params
.use_cts_prot
= -1;
5961 params
.use_short_preamble
= -1;
5962 params
.use_short_slot_time
= -1;
5963 params
.ap_isolate
= -1;
5964 params
.ht_opmode
= -1;
5965 params
.p2p_ctwindow
= -1;
5966 params
.p2p_opp_ps
= -1;
5968 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
5969 params
.use_cts_prot
=
5970 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
5971 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
5972 params
.use_short_preamble
=
5973 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
5974 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
5975 params
.use_short_slot_time
=
5976 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
5977 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5978 params
.basic_rates
=
5979 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5980 params
.basic_rates_len
=
5981 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5983 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
5984 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
5985 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
5987 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
5989 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
5990 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5992 params
.p2p_ctwindow
=
5993 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
5994 if (params
.p2p_ctwindow
< 0)
5996 if (params
.p2p_ctwindow
!= 0 &&
5997 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
6001 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
6004 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6006 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
6009 params
.p2p_opp_ps
= tmp
;
6010 if (params
.p2p_opp_ps
&&
6011 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
6015 if (!rdev
->ops
->change_bss
)
6018 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
6019 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6023 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
6029 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
6033 enum nl80211_user_reg_hint_type user_reg_hint_type
;
6037 * You should only get this when cfg80211 hasn't yet initialized
6038 * completely when built-in to the kernel right between the time
6039 * window between nl80211_init() and regulatory_init(), if that is
6042 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
6043 return -EINPROGRESS
;
6045 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
6046 user_reg_hint_type
=
6047 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
6049 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
6051 switch (user_reg_hint_type
) {
6052 case NL80211_USER_REG_HINT_USER
:
6053 case NL80211_USER_REG_HINT_CELL_BASE
:
6054 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
6057 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
6058 return regulatory_hint_user(data
, user_reg_hint_type
);
6059 case NL80211_USER_REG_HINT_INDOOR
:
6060 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
6061 owner_nlportid
= info
->snd_portid
;
6062 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
6068 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
6074 static int nl80211_reload_regdb(struct sk_buff
*skb
, struct genl_info
*info
)
6076 return reg_reload_regdb();
6079 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
6080 struct genl_info
*info
)
6082 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6083 struct net_device
*dev
= info
->user_ptr
[1];
6084 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6085 struct mesh_config cur_params
;
6088 struct nlattr
*pinfoattr
;
6089 struct sk_buff
*msg
;
6091 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6094 if (!rdev
->ops
->get_mesh_config
)
6098 /* If not connected, get default parameters */
6099 if (!wdev
->mesh_id_len
)
6100 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
6102 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
6108 /* Draw up a netlink message to send back */
6109 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6112 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6113 NL80211_CMD_GET_MESH_CONFIG
);
6116 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
6118 goto nla_put_failure
;
6119 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
6120 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
6121 cur_params
.dot11MeshRetryTimeout
) ||
6122 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
6123 cur_params
.dot11MeshConfirmTimeout
) ||
6124 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
6125 cur_params
.dot11MeshHoldingTimeout
) ||
6126 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
6127 cur_params
.dot11MeshMaxPeerLinks
) ||
6128 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
6129 cur_params
.dot11MeshMaxRetries
) ||
6130 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
6131 cur_params
.dot11MeshTTL
) ||
6132 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
6133 cur_params
.element_ttl
) ||
6134 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
6135 cur_params
.auto_open_plinks
) ||
6136 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
6137 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
6138 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
6139 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
6140 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
6141 cur_params
.path_refresh_time
) ||
6142 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
6143 cur_params
.min_discovery_timeout
) ||
6144 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
6145 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
6146 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
6147 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
6148 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
6149 cur_params
.dot11MeshHWMPperrMinInterval
) ||
6150 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
6151 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
6152 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
6153 cur_params
.dot11MeshHWMPRootMode
) ||
6154 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
6155 cur_params
.dot11MeshHWMPRannInterval
) ||
6156 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
6157 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
6158 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
6159 cur_params
.dot11MeshForwarding
) ||
6160 nla_put_s32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
6161 cur_params
.rssi_threshold
) ||
6162 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
6163 cur_params
.ht_opmode
) ||
6164 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
6165 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
6166 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
6167 cur_params
.dot11MeshHWMProotInterval
) ||
6168 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
6169 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
6170 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
6171 cur_params
.power_mode
) ||
6172 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
6173 cur_params
.dot11MeshAwakeWindowDuration
) ||
6174 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
6175 cur_params
.plink_timeout
))
6176 goto nla_put_failure
;
6177 nla_nest_end(msg
, pinfoattr
);
6178 genlmsg_end(msg
, hdr
);
6179 return genlmsg_reply(msg
, info
);
6187 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
6188 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
6189 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
6190 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
6191 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
6192 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
6193 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
6194 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
6195 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
6196 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
6197 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
6198 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
6199 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
6200 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
6201 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
6202 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
6203 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
6204 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
6205 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
6206 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
6207 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
6208 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
6209 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
6210 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
6211 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
6212 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
6213 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
6214 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
6215 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
6218 static const struct nla_policy
6219 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
6220 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
6221 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
6222 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
6223 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
6224 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
6225 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
6226 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
6227 .len
= IEEE80211_MAX_DATA_LEN
},
6228 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
6231 static int nl80211_check_bool(const struct nlattr
*nla
, u8 min
, u8 max
, bool *out
)
6233 u8 val
= nla_get_u8(nla
);
6234 if (val
< min
|| val
> max
)
6240 static int nl80211_check_u8(const struct nlattr
*nla
, u8 min
, u8 max
, u8
*out
)
6242 u8 val
= nla_get_u8(nla
);
6243 if (val
< min
|| val
> max
)
6249 static int nl80211_check_u16(const struct nlattr
*nla
, u16 min
, u16 max
, u16
*out
)
6251 u16 val
= nla_get_u16(nla
);
6252 if (val
< min
|| val
> max
)
6258 static int nl80211_check_u32(const struct nlattr
*nla
, u32 min
, u32 max
, u32
*out
)
6260 u32 val
= nla_get_u32(nla
);
6261 if (val
< min
|| val
> max
)
6267 static int nl80211_check_s32(const struct nlattr
*nla
, s32 min
, s32 max
, s32
*out
)
6269 s32 val
= nla_get_s32(nla
);
6270 if (val
< min
|| val
> max
)
6276 static int nl80211_check_power_mode(const struct nlattr
*nla
,
6277 enum nl80211_mesh_power_mode min
,
6278 enum nl80211_mesh_power_mode max
,
6279 enum nl80211_mesh_power_mode
*out
)
6281 u32 val
= nla_get_u32(nla
);
6282 if (val
< min
|| val
> max
)
6288 static int nl80211_parse_mesh_config(struct genl_info
*info
,
6289 struct mesh_config
*cfg
,
6292 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
6296 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
6299 if (fn(tb[attr], min, max, &cfg->param)) \
6301 mask |= (1 << (attr - 1)); \
6305 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
6307 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
6308 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
6309 nl80211_meshconf_params_policy
, info
->extack
))
6312 /* This makes sure that there aren't more than 32 mesh config
6313 * parameters (otherwise our bitfield scheme would not work.) */
6314 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
6316 /* Fill in the params struct */
6317 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
6318 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
6320 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
6321 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
6323 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
6324 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
6326 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
6327 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
6329 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
6330 mask
, NL80211_MESHCONF_MAX_RETRIES
,
6332 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
6333 mask
, NL80211_MESHCONF_TTL
, nl80211_check_u8
);
6334 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
6335 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
6337 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
6338 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
6339 nl80211_check_bool
);
6340 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
6342 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
6344 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
6345 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
6347 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
6348 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
6350 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
6351 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
6353 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
6355 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
6357 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
6359 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
6361 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
6363 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
6365 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6366 dot11MeshHWMPnetDiameterTraversalTime
,
6368 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
6370 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
6371 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
6373 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
6374 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
6376 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6377 dot11MeshGateAnnouncementProtocol
, 0, 1,
6378 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
6379 nl80211_check_bool
);
6380 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
6381 mask
, NL80211_MESHCONF_FORWARDING
,
6382 nl80211_check_bool
);
6383 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
6384 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
6387 * Check HT operation mode based on
6388 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
6390 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
6391 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
6393 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
6394 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
6395 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6398 /* NON_HT_STA bit is reserved, but some programs set it */
6399 ht_opmode
&= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
;
6401 cfg
->ht_opmode
= ht_opmode
;
6402 mask
|= (1 << (NL80211_MESHCONF_HT_OPMODE
- 1));
6404 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
6406 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
6408 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
6409 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
6411 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6412 dot11MeshHWMPconfirmationInterval
,
6414 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
6416 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
6417 NL80211_MESH_POWER_ACTIVE
,
6418 NL80211_MESH_POWER_MAX
,
6419 mask
, NL80211_MESHCONF_POWER_MODE
,
6420 nl80211_check_power_mode
);
6421 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
6423 NL80211_MESHCONF_AWAKE_WINDOW
, nl80211_check_u16
);
6424 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
6425 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
6432 #undef FILL_IN_MESH_PARAM_IF_SET
6435 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
6436 struct mesh_setup
*setup
)
6438 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6439 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
6441 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
6443 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
6444 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
6445 nl80211_mesh_setup_params_policy
, info
->extack
))
6448 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
6449 setup
->sync_method
=
6450 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
6451 IEEE80211_SYNC_METHOD_VENDOR
:
6452 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
6454 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
6455 setup
->path_sel_proto
=
6456 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
6457 IEEE80211_PATH_PROTOCOL_VENDOR
:
6458 IEEE80211_PATH_PROTOCOL_HWMP
;
6460 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
6461 setup
->path_metric
=
6462 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
6463 IEEE80211_PATH_METRIC_VENDOR
:
6464 IEEE80211_PATH_METRIC_AIRTIME
;
6466 if (tb
[NL80211_MESH_SETUP_IE
]) {
6467 struct nlattr
*ieattr
=
6468 tb
[NL80211_MESH_SETUP_IE
];
6469 if (!is_valid_ie_attr(ieattr
))
6471 setup
->ie
= nla_data(ieattr
);
6472 setup
->ie_len
= nla_len(ieattr
);
6474 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
6475 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
6477 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
6478 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
6479 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
6480 if (setup
->is_secure
)
6481 setup
->user_mpm
= true;
6483 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
6484 if (!setup
->user_mpm
)
6487 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
6493 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
6494 struct genl_info
*info
)
6496 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6497 struct net_device
*dev
= info
->user_ptr
[1];
6498 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6499 struct mesh_config cfg
;
6503 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6506 if (!rdev
->ops
->update_mesh_config
)
6509 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
6514 if (!wdev
->mesh_id_len
)
6518 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
6525 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
6526 struct sk_buff
*msg
)
6528 struct nlattr
*nl_reg_rules
;
6531 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
6532 (regdom
->dfs_region
&&
6533 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
6534 goto nla_put_failure
;
6536 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
6538 goto nla_put_failure
;
6540 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
6541 struct nlattr
*nl_reg_rule
;
6542 const struct ieee80211_reg_rule
*reg_rule
;
6543 const struct ieee80211_freq_range
*freq_range
;
6544 const struct ieee80211_power_rule
*power_rule
;
6545 unsigned int max_bandwidth_khz
;
6547 reg_rule
= ®dom
->reg_rules
[i
];
6548 freq_range
= ®_rule
->freq_range
;
6549 power_rule
= ®_rule
->power_rule
;
6551 nl_reg_rule
= nla_nest_start(msg
, i
);
6553 goto nla_put_failure
;
6555 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
6556 if (!max_bandwidth_khz
)
6557 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
6560 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
6562 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
6563 freq_range
->start_freq_khz
) ||
6564 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
6565 freq_range
->end_freq_khz
) ||
6566 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
6567 max_bandwidth_khz
) ||
6568 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
6569 power_rule
->max_antenna_gain
) ||
6570 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
6571 power_rule
->max_eirp
) ||
6572 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
6573 reg_rule
->dfs_cac_ms
))
6574 goto nla_put_failure
;
6576 nla_nest_end(msg
, nl_reg_rule
);
6579 nla_nest_end(msg
, nl_reg_rules
);
6586 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
6588 const struct ieee80211_regdomain
*regdom
= NULL
;
6589 struct cfg80211_registered_device
*rdev
;
6590 struct wiphy
*wiphy
= NULL
;
6591 struct sk_buff
*msg
;
6594 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6598 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6599 NL80211_CMD_GET_REG
);
6603 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
6606 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6609 return PTR_ERR(rdev
);
6612 wiphy
= &rdev
->wiphy
;
6613 self_managed
= wiphy
->regulatory_flags
&
6614 REGULATORY_WIPHY_SELF_MANAGED
;
6615 regdom
= get_wiphy_regdom(wiphy
);
6617 /* a self-managed-reg device must have a private regdom */
6618 if (WARN_ON(!regdom
&& self_managed
)) {
6624 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6625 goto nla_put_failure
;
6628 if (!wiphy
&& reg_last_request_cell_base() &&
6629 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6630 NL80211_USER_REG_HINT_CELL_BASE
))
6631 goto nla_put_failure
;
6636 regdom
= rcu_dereference(cfg80211_regdomain
);
6638 if (nl80211_put_regdom(regdom
, msg
))
6639 goto nla_put_failure_rcu
;
6643 genlmsg_end(msg
, hdr
);
6644 return genlmsg_reply(msg
, info
);
6646 nla_put_failure_rcu
:
6654 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6655 u32 seq
, int flags
, struct wiphy
*wiphy
,
6656 const struct ieee80211_regdomain
*regdom
)
6658 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6659 NL80211_CMD_GET_REG
);
6664 genl_dump_check_consistent(cb
, hdr
);
6666 if (nl80211_put_regdom(regdom
, msg
))
6667 goto nla_put_failure
;
6669 if (!wiphy
&& reg_last_request_cell_base() &&
6670 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6671 NL80211_USER_REG_HINT_CELL_BASE
))
6672 goto nla_put_failure
;
6675 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6676 goto nla_put_failure
;
6678 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
6679 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
6680 goto nla_put_failure
;
6682 genlmsg_end(msg
, hdr
);
6686 genlmsg_cancel(msg
, hdr
);
6690 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
6691 struct netlink_callback
*cb
)
6693 const struct ieee80211_regdomain
*regdom
= NULL
;
6694 struct cfg80211_registered_device
*rdev
;
6695 int err
, reg_idx
, start
= cb
->args
[2];
6699 if (cfg80211_regdomain
&& start
== 0) {
6700 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6702 rtnl_dereference(cfg80211_regdomain
));
6707 /* the global regdom is idx 0 */
6709 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
6710 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
6714 if (++reg_idx
<= start
)
6717 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6718 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
6725 cb
->args
[2] = reg_idx
;
6732 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
6733 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
6734 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
6735 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
6736 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
6737 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
6738 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
6739 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
6740 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
6743 static int parse_reg_rule(struct nlattr
*tb
[],
6744 struct ieee80211_reg_rule
*reg_rule
)
6746 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
6747 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
6749 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
6751 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
6753 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
6755 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
6757 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
6760 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
6762 freq_range
->start_freq_khz
=
6763 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
6764 freq_range
->end_freq_khz
=
6765 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
6766 freq_range
->max_bandwidth_khz
=
6767 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
6769 power_rule
->max_eirp
=
6770 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
6772 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
6773 power_rule
->max_antenna_gain
=
6774 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
6776 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
6777 reg_rule
->dfs_cac_ms
=
6778 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
6783 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
6785 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
6786 struct nlattr
*nl_reg_rule
;
6788 int rem_reg_rules
, r
;
6789 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
6790 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
6791 struct ieee80211_regdomain
*rd
;
6793 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
6796 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
6799 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
6801 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
6802 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
6804 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6807 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
6811 if (!reg_is_valid_request(alpha2
))
6814 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
6815 num_rules
* sizeof(struct ieee80211_reg_rule
);
6817 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
6821 rd
->n_reg_rules
= num_rules
;
6822 rd
->alpha2
[0] = alpha2
[0];
6823 rd
->alpha2
[1] = alpha2
[1];
6826 * Disable DFS master mode if the DFS region was
6827 * not supported or known on this kernel.
6829 if (reg_supported_dfs_region(dfs_region
))
6830 rd
->dfs_region
= dfs_region
;
6832 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6834 r
= nla_parse_nested(tb
, NL80211_REG_RULE_ATTR_MAX
,
6835 nl_reg_rule
, reg_rule_policy
,
6839 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
6845 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
6851 /* set_regdom takes ownership of rd */
6852 return set_regdom(rd
, REGD_SOURCE_CRDA
);
6857 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
6859 static int validate_scan_freqs(struct nlattr
*freqs
)
6861 struct nlattr
*attr1
, *attr2
;
6862 int n_channels
= 0, tmp1
, tmp2
;
6864 nla_for_each_nested(attr1
, freqs
, tmp1
)
6865 if (nla_len(attr1
) != sizeof(u32
))
6868 nla_for_each_nested(attr1
, freqs
, tmp1
) {
6871 * Some hardware has a limited channel list for
6872 * scanning, and it is pretty much nonsensical
6873 * to scan for a channel twice, so disallow that
6874 * and don't require drivers to check that the
6875 * channel list they get isn't longer than what
6876 * they can scan, as long as they can scan all
6877 * the channels they registered at once.
6879 nla_for_each_nested(attr2
, freqs
, tmp2
)
6880 if (attr1
!= attr2
&&
6881 nla_get_u32(attr1
) == nla_get_u32(attr2
))
6888 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
6890 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
6893 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
6894 struct cfg80211_bss_selection
*bss_select
)
6896 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
6897 struct nlattr
*nest
;
6902 /* only process one nested attribute */
6903 nest
= nla_data(nla
);
6904 if (!nla_ok(nest
, nla_len(nest
)))
6907 err
= nla_parse_nested(attr
, NL80211_BSS_SELECT_ATTR_MAX
, nest
,
6908 nl80211_bss_select_policy
, NULL
);
6912 /* only one attribute may be given */
6913 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
6921 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
6923 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
6924 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
6926 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
6927 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
6928 bss_select
->param
.band_pref
=
6929 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
6930 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
6934 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
6935 struct nl80211_bss_select_rssi_adjust
*adj_param
;
6937 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
6938 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
6939 bss_select
->param
.adjust
.band
= adj_param
->band
;
6940 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
6941 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
6945 /* user-space did not provide behaviour attribute */
6946 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
6949 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
6955 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
6956 u8
*mac_addr
, u8
*mac_addr_mask
)
6960 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
6961 eth_zero_addr(mac_addr
);
6962 eth_zero_addr(mac_addr_mask
);
6964 mac_addr_mask
[0] = 0x3;
6969 /* need both or none */
6970 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
6973 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
6974 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
6976 /* don't allow or configure an mcast address */
6977 if (!is_multicast_ether_addr(mac_addr_mask
) ||
6978 is_multicast_ether_addr(mac_addr
))
6982 * allow users to pass a MAC address that has bits set outside
6983 * of the mask, but don't bother drivers with having to deal
6986 for (i
= 0; i
< ETH_ALEN
; i
++)
6987 mac_addr
[i
] &= mac_addr_mask
[i
];
6992 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev
*wdev
)
6994 ASSERT_WDEV_LOCK(wdev
);
6996 if (!cfg80211_beaconing_iface_active(wdev
))
6999 if (!(wdev
->chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
))
7002 return regulatory_pre_cac_allowed(wdev
->wiphy
);
7005 static bool nl80211_check_scan_feat(struct wiphy
*wiphy
, u32 flags
, u32 flag
,
7006 enum nl80211_ext_feature_index feat
)
7008 if (!(flags
& flag
))
7010 if (wiphy_ext_feature_isset(wiphy
, feat
))
7016 nl80211_check_scan_flags(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
7017 void *request
, struct nlattr
**attrs
,
7020 u8
*mac_addr
, *mac_addr_mask
;
7022 enum nl80211_feature_flags randomness_flag
;
7024 if (!attrs
[NL80211_ATTR_SCAN_FLAGS
])
7027 if (is_sched_scan
) {
7028 struct cfg80211_sched_scan_request
*req
= request
;
7030 randomness_flag
= wdev
?
7031 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
:
7032 NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
7033 flags
= &req
->flags
;
7034 mac_addr
= req
->mac_addr
;
7035 mac_addr_mask
= req
->mac_addr_mask
;
7037 struct cfg80211_scan_request
*req
= request
;
7039 randomness_flag
= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
7040 flags
= &req
->flags
;
7041 mac_addr
= req
->mac_addr
;
7042 mac_addr_mask
= req
->mac_addr_mask
;
7045 *flags
= nla_get_u32(attrs
[NL80211_ATTR_SCAN_FLAGS
]);
7047 if (((*flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
7048 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
7049 !nl80211_check_scan_feat(wiphy
, *flags
,
7050 NL80211_SCAN_FLAG_LOW_SPAN
,
7051 NL80211_EXT_FEATURE_LOW_SPAN_SCAN
) ||
7052 !nl80211_check_scan_feat(wiphy
, *flags
,
7053 NL80211_SCAN_FLAG_LOW_POWER
,
7054 NL80211_EXT_FEATURE_LOW_POWER_SCAN
) ||
7055 !nl80211_check_scan_feat(wiphy
, *flags
,
7056 NL80211_SCAN_FLAG_HIGH_ACCURACY
,
7057 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN
) ||
7058 !nl80211_check_scan_feat(wiphy
, *flags
,
7059 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME
,
7060 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME
) ||
7061 !nl80211_check_scan_feat(wiphy
, *flags
,
7062 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP
,
7063 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP
) ||
7064 !nl80211_check_scan_feat(wiphy
, *flags
,
7065 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
,
7066 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
) ||
7067 !nl80211_check_scan_feat(wiphy
, *flags
,
7068 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE
,
7069 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE
) ||
7070 !nl80211_check_scan_feat(wiphy
, *flags
,
7071 NL80211_SCAN_FLAG_RANDOM_SN
,
7072 NL80211_EXT_FEATURE_SCAN_RANDOM_SN
) ||
7073 !nl80211_check_scan_feat(wiphy
, *flags
,
7074 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT
,
7075 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT
))
7078 if (*flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
7081 if (!(wiphy
->features
& randomness_flag
) ||
7082 (wdev
&& wdev
->current_bss
))
7085 err
= nl80211_parse_random_mac(attrs
, mac_addr
, mac_addr_mask
);
7093 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
7095 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7096 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7097 struct cfg80211_scan_request
*request
;
7098 struct nlattr
*attr
;
7099 struct wiphy
*wiphy
;
7100 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
7103 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7106 wiphy
= &rdev
->wiphy
;
7108 if (wdev
->iftype
== NL80211_IFTYPE_NAN
)
7111 if (!rdev
->ops
->scan
)
7114 if (rdev
->scan_req
|| rdev
->scan_msg
) {
7119 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7120 n_channels
= validate_scan_freqs(
7121 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
7127 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
7130 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
7131 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
7134 if (n_ssids
> wiphy
->max_scan_ssids
) {
7139 if (info
->attrs
[NL80211_ATTR_IE
])
7140 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7144 if (ie_len
> wiphy
->max_scan_ie_len
) {
7149 request
= kzalloc(sizeof(*request
)
7150 + sizeof(*request
->ssids
) * n_ssids
7151 + sizeof(*request
->channels
) * n_channels
7152 + ie_len
, GFP_KERNEL
);
7159 request
->ssids
= (void *)&request
->channels
[n_channels
];
7160 request
->n_ssids
= n_ssids
;
7163 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
7165 request
->ie
= (void *)(request
->channels
+ n_channels
);
7169 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7170 /* user specified, bail out if channel not found */
7171 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
7172 struct ieee80211_channel
*chan
;
7174 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
7181 /* ignore disabled channels */
7182 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7185 request
->channels
[i
] = chan
;
7189 enum nl80211_band band
;
7192 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7195 if (!wiphy
->bands
[band
])
7197 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
7198 struct ieee80211_channel
*chan
;
7200 chan
= &wiphy
->bands
[band
]->channels
[j
];
7202 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7205 request
->channels
[i
] = chan
;
7216 request
->n_channels
= i
;
7219 if (!cfg80211_off_channel_oper_allowed(wdev
)) {
7220 struct ieee80211_channel
*chan
;
7222 if (request
->n_channels
!= 1) {
7228 chan
= request
->channels
[0];
7229 if (chan
->center_freq
!= wdev
->chandef
.chan
->center_freq
) {
7239 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
7240 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7244 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7245 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
7250 if (info
->attrs
[NL80211_ATTR_IE
]) {
7251 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7252 memcpy((void *)request
->ie
,
7253 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
7257 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
7258 if (wiphy
->bands
[i
])
7260 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
7262 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
7263 nla_for_each_nested(attr
,
7264 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
7266 enum nl80211_band band
= nla_type(attr
);
7268 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
7273 if (!wiphy
->bands
[band
])
7276 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
7279 &request
->rates
[band
]);
7285 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
7286 if (!wiphy_ext_feature_isset(wiphy
,
7287 NL80211_EXT_FEATURE_SET_SCAN_DWELL
)) {
7293 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
7294 request
->duration_mandatory
=
7295 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
7298 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, info
->attrs
,
7304 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7306 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7307 * BSSID to scan for. This was problematic because that same attribute
7308 * was already used for another purpose (local random MAC address). The
7309 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7310 * compatibility with older userspace components, also use the
7311 * NL80211_ATTR_MAC value here if it can be determined to be used for
7312 * the specific BSSID use case instead of the random MAC address
7313 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7315 if (info
->attrs
[NL80211_ATTR_BSSID
])
7316 memcpy(request
->bssid
,
7317 nla_data(info
->attrs
[NL80211_ATTR_BSSID
]), ETH_ALEN
);
7318 else if (!(request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) &&
7319 info
->attrs
[NL80211_ATTR_MAC
])
7320 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
7323 eth_broadcast_addr(request
->bssid
);
7325 request
->wdev
= wdev
;
7326 request
->wiphy
= &rdev
->wiphy
;
7327 request
->scan_start
= jiffies
;
7329 rdev
->scan_req
= request
;
7330 err
= rdev_scan(rdev
, request
);
7333 nl80211_send_scan_start(rdev
, wdev
);
7335 dev_hold(wdev
->netdev
);
7338 rdev
->scan_req
= NULL
;
7346 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
7348 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7349 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7351 if (!rdev
->ops
->abort_scan
)
7357 if (!rdev
->scan_req
)
7360 rdev_abort_scan(rdev
, wdev
);
7365 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
7366 struct cfg80211_sched_scan_request
*request
,
7367 struct nlattr
**attrs
)
7369 int tmp
, err
, i
= 0;
7370 struct nlattr
*attr
;
7372 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
7376 * If scan plans are not specified,
7377 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
7378 * case one scan plan will be set with the specified scan
7379 * interval and infinite number of iterations.
7381 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
7385 request
->scan_plans
[0].interval
=
7386 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
7387 if (!request
->scan_plans
[0].interval
)
7390 if (request
->scan_plans
[0].interval
>
7391 wiphy
->max_sched_scan_plan_interval
)
7392 request
->scan_plans
[0].interval
=
7393 wiphy
->max_sched_scan_plan_interval
;
7398 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
7399 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
7401 if (WARN_ON(i
>= n_plans
))
7404 err
= nla_parse_nested(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
7405 attr
, nl80211_plan_policy
, NULL
);
7409 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
7412 request
->scan_plans
[i
].interval
=
7413 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
7414 if (!request
->scan_plans
[i
].interval
||
7415 request
->scan_plans
[i
].interval
>
7416 wiphy
->max_sched_scan_plan_interval
)
7419 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
7420 request
->scan_plans
[i
].iterations
=
7421 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
7422 if (!request
->scan_plans
[i
].iterations
||
7423 (request
->scan_plans
[i
].iterations
>
7424 wiphy
->max_sched_scan_plan_iterations
))
7426 } else if (i
< n_plans
- 1) {
7428 * All scan plans but the last one must specify
7429 * a finite number of iterations
7438 * The last scan plan must not specify the number of
7439 * iterations, it is supposed to run infinitely
7441 if (request
->scan_plans
[n_plans
- 1].iterations
)
7447 static struct cfg80211_sched_scan_request
*
7448 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
7449 struct nlattr
**attrs
, int max_match_sets
)
7451 struct cfg80211_sched_scan_request
*request
;
7452 struct nlattr
*attr
;
7453 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
7454 enum nl80211_band band
;
7456 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
7457 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
7459 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
7460 return ERR_PTR(-EINVAL
);
7462 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7463 n_channels
= validate_scan_freqs(
7464 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
7466 return ERR_PTR(-EINVAL
);
7468 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
7471 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
7472 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7476 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
7477 return ERR_PTR(-EINVAL
);
7480 * First, count the number of 'real' matchsets. Due to an issue with
7481 * the old implementation, matchsets containing only the RSSI attribute
7482 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7483 * RSSI for all matchsets, rather than their own matchset for reporting
7484 * all APs with a strong RSSI. This is needed to be compatible with
7485 * older userspace that treated a matchset with only the RSSI as the
7486 * global RSSI for all other matchsets - if there are other matchsets.
7488 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7489 nla_for_each_nested(attr
,
7490 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7492 struct nlattr
*rssi
;
7494 err
= nla_parse_nested(tb
,
7495 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7496 attr
, nl80211_match_policy
,
7499 return ERR_PTR(err
);
7501 /* SSID and BSSID are mutually exclusive */
7502 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] &&
7503 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
])
7504 return ERR_PTR(-EINVAL
);
7506 /* add other standalone attributes here */
7507 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] ||
7508 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
]) {
7512 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7514 default_match_rssi
= nla_get_s32(rssi
);
7518 /* However, if there's no other matchset, add the RSSI one */
7519 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
7522 if (n_match_sets
> max_match_sets
)
7523 return ERR_PTR(-EINVAL
);
7525 if (attrs
[NL80211_ATTR_IE
])
7526 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
7530 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
7531 return ERR_PTR(-EINVAL
);
7533 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
7535 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7536 * each scan plan already specifies its own interval
7538 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7539 return ERR_PTR(-EINVAL
);
7541 nla_for_each_nested(attr
,
7542 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
7546 * The scan interval attribute is kept for backward
7547 * compatibility. If no scan plans are specified and sched scan
7548 * interval is specified, one scan plan will be set with this
7549 * scan interval and infinite number of iterations.
7551 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7552 return ERR_PTR(-EINVAL
);
7557 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
7558 return ERR_PTR(-EINVAL
);
7560 if (!wiphy_ext_feature_isset(
7561 wiphy
, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI
) &&
7562 (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] ||
7563 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]))
7564 return ERR_PTR(-EINVAL
);
7566 request
= kzalloc(sizeof(*request
)
7567 + sizeof(*request
->ssids
) * n_ssids
7568 + sizeof(*request
->match_sets
) * n_match_sets
7569 + sizeof(*request
->scan_plans
) * n_plans
7570 + sizeof(*request
->channels
) * n_channels
7571 + ie_len
, GFP_KERNEL
);
7573 return ERR_PTR(-ENOMEM
);
7576 request
->ssids
= (void *)&request
->channels
[n_channels
];
7577 request
->n_ssids
= n_ssids
;
7580 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
7582 request
->ie
= (void *)(request
->channels
+ n_channels
);
7587 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
7589 request
->match_sets
=
7590 (void *)(request
->ssids
+ n_ssids
);
7592 request
->match_sets
=
7593 (void *)(request
->channels
+ n_channels
);
7595 request
->n_match_sets
= n_match_sets
;
7598 request
->scan_plans
= (void *)(request
->match_sets
+
7600 else if (request
->ie
)
7601 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
7603 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
7605 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
7607 request
->n_scan_plans
= n_plans
;
7610 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7611 /* user specified, bail out if channel not found */
7612 nla_for_each_nested(attr
,
7613 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
7615 struct ieee80211_channel
*chan
;
7617 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
7624 /* ignore disabled channels */
7625 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7628 request
->channels
[i
] = chan
;
7633 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7636 if (!wiphy
->bands
[band
])
7638 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
7639 struct ieee80211_channel
*chan
;
7641 chan
= &wiphy
->bands
[band
]->channels
[j
];
7643 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7646 request
->channels
[i
] = chan
;
7657 request
->n_channels
= i
;
7661 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7663 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7667 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7668 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
7675 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7676 nla_for_each_nested(attr
,
7677 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7679 struct nlattr
*ssid
, *bssid
, *rssi
;
7681 err
= nla_parse_nested(tb
,
7682 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7683 attr
, nl80211_match_policy
,
7687 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
7688 bssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
];
7689 if (ssid
|| bssid
) {
7690 if (WARN_ON(i
>= n_match_sets
)) {
7691 /* this indicates a programming error,
7692 * the loop above should have verified
7700 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
7704 memcpy(request
->match_sets
[i
].ssid
.ssid
,
7705 nla_data(ssid
), nla_len(ssid
));
7706 request
->match_sets
[i
].ssid
.ssid_len
=
7710 if (nla_len(bssid
) != ETH_ALEN
) {
7714 memcpy(request
->match_sets
[i
].bssid
,
7715 nla_data(bssid
), ETH_ALEN
);
7718 /* special attribute - old implementation w/a */
7719 request
->match_sets
[i
].rssi_thold
=
7721 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7723 request
->match_sets
[i
].rssi_thold
=
7729 /* there was no other matchset, so the RSSI one is alone */
7730 if (i
== 0 && n_match_sets
)
7731 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
7733 request
->min_rssi_thold
= INT_MAX
;
7734 for (i
= 0; i
< n_match_sets
; i
++)
7735 request
->min_rssi_thold
=
7736 min(request
->match_sets
[i
].rssi_thold
,
7737 request
->min_rssi_thold
);
7739 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
7743 request
->ie_len
= ie_len
;
7744 memcpy((void *)request
->ie
,
7745 nla_data(attrs
[NL80211_ATTR_IE
]),
7749 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, attrs
, true);
7753 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
7755 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
7757 if (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]) {
7758 request
->relative_rssi
= nla_get_s8(
7759 attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]);
7760 request
->relative_rssi_set
= true;
7763 if (request
->relative_rssi_set
&&
7764 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]) {
7765 struct nl80211_bss_select_rssi_adjust
*rssi_adjust
;
7767 rssi_adjust
= nla_data(
7768 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]);
7769 request
->rssi_adjust
.band
= rssi_adjust
->band
;
7770 request
->rssi_adjust
.delta
= rssi_adjust
->delta
;
7771 if (!is_band_valid(wiphy
, request
->rssi_adjust
.band
)) {
7777 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
7781 request
->scan_start
= jiffies
;
7787 return ERR_PTR(err
);
7790 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
7791 struct genl_info
*info
)
7793 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7794 struct net_device
*dev
= info
->user_ptr
[1];
7795 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7796 struct cfg80211_sched_scan_request
*sched_scan_req
;
7800 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_start
)
7803 want_multi
= info
->attrs
[NL80211_ATTR_SCHED_SCAN_MULTI
];
7804 err
= cfg80211_sched_scan_req_possible(rdev
, want_multi
);
7808 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
7810 rdev
->wiphy
.max_match_sets
);
7812 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
7816 /* leave request id zero for legacy request
7817 * or if driver does not support multi-scheduled scan
7819 if (want_multi
&& rdev
->wiphy
.max_sched_scan_reqs
> 1) {
7820 while (!sched_scan_req
->reqid
)
7821 sched_scan_req
->reqid
= rdev
->wiphy
.cookie_counter
++;
7824 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
7828 sched_scan_req
->dev
= dev
;
7829 sched_scan_req
->wiphy
= &rdev
->wiphy
;
7831 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
7832 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
7834 cfg80211_add_sched_scan_req(rdev
, sched_scan_req
);
7836 nl80211_send_sched_scan(sched_scan_req
, NL80211_CMD_START_SCHED_SCAN
);
7840 kfree(sched_scan_req
);
7845 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
7846 struct genl_info
*info
)
7848 struct cfg80211_sched_scan_request
*req
;
7849 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7852 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_stop
)
7855 if (info
->attrs
[NL80211_ATTR_COOKIE
]) {
7856 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7857 return __cfg80211_stop_sched_scan(rdev
, cookie
, false);
7860 req
= list_first_or_null_rcu(&rdev
->sched_scan_req_list
,
7861 struct cfg80211_sched_scan_request
,
7863 if (!req
|| req
->reqid
||
7864 (req
->owner_nlportid
&&
7865 req
->owner_nlportid
!= info
->snd_portid
))
7868 return cfg80211_stop_sched_scan_req(rdev
, req
, false);
7871 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
7872 struct genl_info
*info
)
7874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7875 struct net_device
*dev
= info
->user_ptr
[1];
7876 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7877 struct wiphy
*wiphy
= wdev
->wiphy
;
7878 struct cfg80211_chan_def chandef
;
7879 enum nl80211_dfs_regions dfs_region
;
7880 unsigned int cac_time_ms
;
7883 dfs_region
= reg_get_dfs_region(wiphy
);
7884 if (dfs_region
== NL80211_DFS_UNSET
)
7887 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7891 if (netif_carrier_ok(dev
))
7894 if (wdev
->cac_started
)
7897 err
= cfg80211_chandef_dfs_required(wiphy
, &chandef
, wdev
->iftype
);
7904 if (!cfg80211_chandef_dfs_usable(wiphy
, &chandef
))
7907 /* CAC start is offloaded to HW and can't be started manually */
7908 if (wiphy_ext_feature_isset(wiphy
, NL80211_EXT_FEATURE_DFS_OFFLOAD
))
7911 if (!rdev
->ops
->start_radar_detection
)
7914 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
7915 if (WARN_ON(!cac_time_ms
))
7916 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
7918 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
7920 wdev
->chandef
= chandef
;
7921 wdev
->cac_started
= true;
7922 wdev
->cac_start_time
= jiffies
;
7923 wdev
->cac_time_ms
= cac_time_ms
;
7928 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
7930 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7931 struct net_device
*dev
= info
->user_ptr
[1];
7932 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7933 struct cfg80211_csa_settings params
;
7934 /* csa_attrs is defined static to avoid waste of stack size - this
7935 * function is called under RTNL lock, so this should not be a problem.
7937 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
7939 bool need_new_beacon
= false;
7940 bool need_handle_dfs_flag
= true;
7944 if (!rdev
->ops
->channel_switch
||
7945 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
7948 switch (dev
->ieee80211_ptr
->iftype
) {
7949 case NL80211_IFTYPE_AP
:
7950 case NL80211_IFTYPE_P2P_GO
:
7951 need_new_beacon
= true;
7952 /* For all modes except AP the handle_dfs flag needs to be
7953 * supplied to tell the kernel that userspace will handle radar
7954 * events when they happen. Otherwise a switch to a channel
7955 * requiring DFS will be rejected.
7957 need_handle_dfs_flag
= false;
7959 /* useless if AP is not running */
7960 if (!wdev
->beacon_interval
)
7963 case NL80211_IFTYPE_ADHOC
:
7964 if (!wdev
->ssid_len
)
7967 case NL80211_IFTYPE_MESH_POINT
:
7968 if (!wdev
->mesh_id_len
)
7975 memset(¶ms
, 0, sizeof(params
));
7977 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7978 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
7981 /* only important for AP, IBSS and mesh create IEs internally */
7982 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
7985 /* Even though the attribute is u32, the specification says
7986 * u8, so let's make sure we don't overflow.
7988 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
7992 params
.count
= cs_count
;
7994 if (!need_new_beacon
)
7997 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
8001 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
8002 info
->attrs
[NL80211_ATTR_CSA_IES
],
8003 nl80211_policy
, info
->extack
);
8007 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
8011 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
8014 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
8015 if (!len
|| (len
% sizeof(u16
)))
8018 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
8019 if (rdev
->wiphy
.max_num_csa_counters
&&
8020 (params
.n_counter_offsets_beacon
>
8021 rdev
->wiphy
.max_num_csa_counters
))
8024 params
.counter_offsets_beacon
=
8025 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
8027 /* sanity checks - counters should fit and be the same */
8028 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
8029 u16 offset
= params
.counter_offsets_beacon
[i
];
8031 if (offset
>= params
.beacon_csa
.tail_len
)
8034 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
8038 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
8039 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
8040 if (!len
|| (len
% sizeof(u16
)))
8043 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
8044 if (rdev
->wiphy
.max_num_csa_counters
&&
8045 (params
.n_counter_offsets_presp
>
8046 rdev
->wiphy
.max_num_csa_counters
))
8049 params
.counter_offsets_presp
=
8050 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
8052 /* sanity checks - counters should fit and be the same */
8053 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
8054 u16 offset
= params
.counter_offsets_presp
[i
];
8056 if (offset
>= params
.beacon_csa
.probe_resp_len
)
8059 if (params
.beacon_csa
.probe_resp
[offset
] !=
8066 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
8070 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
8074 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
8081 params
.radar_required
= true;
8082 if (need_handle_dfs_flag
&&
8083 !nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
])) {
8088 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
8089 params
.block_tx
= true;
8092 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
8098 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
8100 struct cfg80211_registered_device
*rdev
,
8101 struct wireless_dev
*wdev
,
8102 struct cfg80211_internal_bss
*intbss
)
8104 struct cfg80211_bss
*res
= &intbss
->pub
;
8105 const struct cfg80211_bss_ies
*ies
;
8109 ASSERT_WDEV_LOCK(wdev
);
8111 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
8112 NL80211_CMD_NEW_SCAN_RESULTS
);
8116 genl_dump_check_consistent(cb
, hdr
);
8118 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
8119 goto nla_put_failure
;
8121 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
8122 goto nla_put_failure
;
8123 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
8125 goto nla_put_failure
;
8127 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
8129 goto nla_put_failure
;
8130 if ((!is_zero_ether_addr(res
->bssid
) &&
8131 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
8132 goto nla_put_failure
;
8135 /* indicate whether we have probe response data or not */
8136 if (rcu_access_pointer(res
->proberesp_ies
) &&
8137 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
8138 goto fail_unlock_rcu
;
8140 /* this pointer prefers to be pointed to probe response data
8141 * but is always valid
8143 ies
= rcu_dereference(res
->ies
);
8145 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
8147 goto fail_unlock_rcu
;
8148 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
8149 ies
->len
, ies
->data
))
8150 goto fail_unlock_rcu
;
8153 /* and this pointer is always (unless driver didn't know) beacon data */
8154 ies
= rcu_dereference(res
->beacon_ies
);
8155 if (ies
&& ies
->from_beacon
) {
8156 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
8158 goto fail_unlock_rcu
;
8159 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
8160 ies
->len
, ies
->data
))
8161 goto fail_unlock_rcu
;
8165 if (res
->beacon_interval
&&
8166 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
8167 goto nla_put_failure
;
8168 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
8169 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
8170 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
8171 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
8172 jiffies_to_msecs(jiffies
- intbss
->ts
)))
8173 goto nla_put_failure
;
8175 if (intbss
->parent_tsf
&&
8176 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
8177 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
8178 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
8179 intbss
->parent_bssid
)))
8180 goto nla_put_failure
;
8182 if (intbss
->ts_boottime
&&
8183 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
8184 intbss
->ts_boottime
, NL80211_BSS_PAD
))
8185 goto nla_put_failure
;
8187 if (!nl80211_put_signal(msg
, intbss
->pub
.chains
,
8188 intbss
->pub
.chain_signal
,
8189 NL80211_BSS_CHAIN_SIGNAL
))
8190 goto nla_put_failure
;
8192 switch (rdev
->wiphy
.signal_type
) {
8193 case CFG80211_SIGNAL_TYPE_MBM
:
8194 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
8195 goto nla_put_failure
;
8197 case CFG80211_SIGNAL_TYPE_UNSPEC
:
8198 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
8199 goto nla_put_failure
;
8205 switch (wdev
->iftype
) {
8206 case NL80211_IFTYPE_P2P_CLIENT
:
8207 case NL80211_IFTYPE_STATION
:
8208 if (intbss
== wdev
->current_bss
&&
8209 nla_put_u32(msg
, NL80211_BSS_STATUS
,
8210 NL80211_BSS_STATUS_ASSOCIATED
))
8211 goto nla_put_failure
;
8213 case NL80211_IFTYPE_ADHOC
:
8214 if (intbss
== wdev
->current_bss
&&
8215 nla_put_u32(msg
, NL80211_BSS_STATUS
,
8216 NL80211_BSS_STATUS_IBSS_JOINED
))
8217 goto nla_put_failure
;
8223 nla_nest_end(msg
, bss
);
8225 genlmsg_end(msg
, hdr
);
8231 genlmsg_cancel(msg
, hdr
);
8235 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
8237 struct cfg80211_registered_device
*rdev
;
8238 struct cfg80211_internal_bss
*scan
;
8239 struct wireless_dev
*wdev
;
8240 int start
= cb
->args
[2], idx
= 0;
8244 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
8251 spin_lock_bh(&rdev
->bss_lock
);
8254 * dump_scan will be called multiple times to break up the scan results
8255 * into multiple messages. It is unlikely that any more bss-es will be
8256 * expired after the first call, so only call only call this on the
8257 * first dump_scan invocation.
8260 cfg80211_bss_expire(rdev
);
8262 cb
->seq
= rdev
->bss_generation
;
8264 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
8267 if (nl80211_send_bss(skb
, cb
,
8268 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8269 rdev
, wdev
, scan
) < 0) {
8275 spin_unlock_bh(&rdev
->bss_lock
);
8284 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
8285 int flags
, struct net_device
*dev
,
8286 bool allow_radio_stats
,
8287 struct survey_info
*survey
)
8290 struct nlattr
*infoattr
;
8292 /* skip radio stats if userspace didn't request them */
8293 if (!survey
->channel
&& !allow_radio_stats
)
8296 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
8297 NL80211_CMD_NEW_SURVEY_RESULTS
);
8301 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
8302 goto nla_put_failure
;
8304 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
8306 goto nla_put_failure
;
8308 if (survey
->channel
&&
8309 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
8310 survey
->channel
->center_freq
))
8311 goto nla_put_failure
;
8313 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
8314 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
8315 goto nla_put_failure
;
8316 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
8317 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
8318 goto nla_put_failure
;
8319 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
8320 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
8321 survey
->time
, NL80211_SURVEY_INFO_PAD
))
8322 goto nla_put_failure
;
8323 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
8324 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
8325 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
8326 goto nla_put_failure
;
8327 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
8328 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
8329 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
8330 goto nla_put_failure
;
8331 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
8332 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
8333 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
8334 goto nla_put_failure
;
8335 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
8336 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
8337 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
8338 goto nla_put_failure
;
8339 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
8340 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
8341 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
8342 goto nla_put_failure
;
8344 nla_nest_end(msg
, infoattr
);
8346 genlmsg_end(msg
, hdr
);
8350 genlmsg_cancel(msg
, hdr
);
8354 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
8356 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
8357 struct survey_info survey
;
8358 struct cfg80211_registered_device
*rdev
;
8359 struct wireless_dev
*wdev
;
8360 int survey_idx
= cb
->args
[2];
8365 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
8369 /* prepare_wdev_dump parsed the attributes */
8370 radio_stats
= attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
8372 if (!wdev
->netdev
) {
8377 if (!rdev
->ops
->dump_survey
) {
8383 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
8389 /* don't send disabled channels, but do send non-channel data */
8390 if (survey
.channel
&&
8391 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
8396 if (nl80211_send_survey(skb
,
8397 NETLINK_CB(cb
->skb
).portid
,
8398 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8399 wdev
->netdev
, radio_stats
, &survey
) < 0)
8405 cb
->args
[2] = survey_idx
;
8412 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
8414 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
8415 NL80211_WPA_VERSION_2
));
8418 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8420 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8421 struct net_device
*dev
= info
->user_ptr
[1];
8422 struct ieee80211_channel
*chan
;
8423 const u8
*bssid
, *ssid
, *ie
= NULL
, *auth_data
= NULL
;
8424 int err
, ssid_len
, ie_len
= 0, auth_data_len
= 0;
8425 enum nl80211_auth_type auth_type
;
8426 struct key_parse key
;
8427 bool local_state_change
;
8429 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8432 if (!info
->attrs
[NL80211_ATTR_MAC
])
8435 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
8438 if (!info
->attrs
[NL80211_ATTR_SSID
])
8441 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8444 err
= nl80211_parse_key(info
, &key
);
8449 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
8451 if (!key
.p
.key
|| !key
.p
.key_len
)
8453 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
8454 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
8455 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
8456 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
8469 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
8470 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
8479 if (!rdev
->ops
->auth
)
8482 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8483 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8486 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8487 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8488 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8492 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8493 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8495 if (info
->attrs
[NL80211_ATTR_IE
]) {
8496 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8497 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8500 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8501 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
8504 if ((auth_type
== NL80211_AUTHTYPE_SAE
||
8505 auth_type
== NL80211_AUTHTYPE_FILS_SK
||
8506 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
8507 auth_type
== NL80211_AUTHTYPE_FILS_PK
) &&
8508 !info
->attrs
[NL80211_ATTR_AUTH_DATA
])
8511 if (info
->attrs
[NL80211_ATTR_AUTH_DATA
]) {
8512 if (auth_type
!= NL80211_AUTHTYPE_SAE
&&
8513 auth_type
!= NL80211_AUTHTYPE_FILS_SK
&&
8514 auth_type
!= NL80211_AUTHTYPE_FILS_SK_PFS
&&
8515 auth_type
!= NL80211_AUTHTYPE_FILS_PK
)
8517 auth_data
= nla_data(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8518 auth_data_len
= nla_len(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8519 /* need to include at least Auth Transaction and Status Code */
8520 if (auth_data_len
< 4)
8524 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8527 * Since we no longer track auth state, ignore
8528 * requests to only change local state.
8530 if (local_state_change
)
8533 wdev_lock(dev
->ieee80211_ptr
);
8534 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
8535 ssid
, ssid_len
, ie
, ie_len
,
8536 key
.p
.key
, key
.p
.key_len
, key
.idx
,
8537 auth_data
, auth_data_len
);
8538 wdev_unlock(dev
->ieee80211_ptr
);
8542 static int validate_pae_over_nl80211(struct cfg80211_registered_device
*rdev
,
8543 struct genl_info
*info
)
8545 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
8546 GENL_SET_ERR_MSG(info
, "SOCKET_OWNER not set");
8550 if (!rdev
->ops
->tx_control_port
||
8551 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8552 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
8558 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
8559 struct genl_info
*info
,
8560 struct cfg80211_crypto_settings
*settings
,
8563 memset(settings
, 0, sizeof(*settings
));
8565 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
8567 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
8570 proto
= nla_get_u16(
8571 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
8572 settings
->control_port_ethertype
= cpu_to_be16(proto
);
8573 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
8576 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
8577 settings
->control_port_no_encrypt
= true;
8579 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
8581 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
8582 int r
= validate_pae_over_nl80211(rdev
, info
);
8587 settings
->control_port_over_nl80211
= true;
8590 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
8594 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8595 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8596 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
8598 if (len
% sizeof(u32
))
8601 if (settings
->n_ciphers_pairwise
> cipher_limit
)
8604 memcpy(settings
->ciphers_pairwise
, data
, len
);
8606 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
8607 if (!cfg80211_supported_cipher_suite(
8609 settings
->ciphers_pairwise
[i
]))
8613 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
8614 settings
->cipher_group
=
8615 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
8616 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
8617 settings
->cipher_group
))
8621 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
8622 settings
->wpa_versions
=
8623 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
8624 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
8628 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
8632 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8633 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8634 settings
->n_akm_suites
= len
/ sizeof(u32
);
8636 if (len
% sizeof(u32
))
8639 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
8642 memcpy(settings
->akm_suites
, data
, len
);
8645 if (info
->attrs
[NL80211_ATTR_PMK
]) {
8646 if (nla_len(info
->attrs
[NL80211_ATTR_PMK
]) != WLAN_PMK_LEN
)
8648 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8649 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK
))
8651 settings
->psk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
8657 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
8659 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8660 struct net_device
*dev
= info
->user_ptr
[1];
8661 struct ieee80211_channel
*chan
;
8662 struct cfg80211_assoc_request req
= {};
8663 const u8
*bssid
, *ssid
;
8664 int err
, ssid_len
= 0;
8666 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
8667 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
8670 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8673 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
8674 !info
->attrs
[NL80211_ATTR_SSID
] ||
8675 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8678 if (!rdev
->ops
->assoc
)
8681 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8682 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8685 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8687 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8688 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8692 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8693 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8695 if (info
->attrs
[NL80211_ATTR_IE
]) {
8696 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8697 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8700 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
8701 enum nl80211_mfp mfp
=
8702 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
8703 if (mfp
== NL80211_MFP_REQUIRED
)
8705 else if (mfp
!= NL80211_MFP_NO
)
8709 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
8710 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
8712 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
8713 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
8715 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8716 memcpy(&req
.ht_capa_mask
,
8717 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8718 sizeof(req
.ht_capa_mask
));
8720 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8721 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8723 memcpy(&req
.ht_capa
,
8724 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8725 sizeof(req
.ht_capa
));
8728 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
8729 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
8731 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8732 memcpy(&req
.vht_capa_mask
,
8733 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
8734 sizeof(req
.vht_capa_mask
));
8736 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
8737 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8739 memcpy(&req
.vht_capa
,
8740 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
8741 sizeof(req
.vht_capa
));
8744 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
8745 if (!((rdev
->wiphy
.features
&
8746 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
8747 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
8748 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8749 NL80211_EXT_FEATURE_RRM
))
8751 req
.flags
|= ASSOC_REQ_USE_RRM
;
8754 if (info
->attrs
[NL80211_ATTR_FILS_KEK
]) {
8755 req
.fils_kek
= nla_data(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8756 req
.fils_kek_len
= nla_len(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8757 if (!info
->attrs
[NL80211_ATTR_FILS_NONCES
])
8760 nla_data(info
->attrs
[NL80211_ATTR_FILS_NONCES
]);
8763 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
8765 wdev_lock(dev
->ieee80211_ptr
);
8767 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
8768 ssid
, ssid_len
, &req
);
8770 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
8771 dev
->ieee80211_ptr
->conn_owner_nlportid
=
8773 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
8777 wdev_unlock(dev
->ieee80211_ptr
);
8783 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8785 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8786 struct net_device
*dev
= info
->user_ptr
[1];
8787 const u8
*ie
= NULL
, *bssid
;
8788 int ie_len
= 0, err
;
8790 bool local_state_change
;
8792 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
8793 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
8796 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8799 if (!info
->attrs
[NL80211_ATTR_MAC
])
8802 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8805 if (!rdev
->ops
->deauth
)
8808 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8809 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8812 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8814 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8815 if (reason_code
== 0) {
8816 /* Reason Code 0 is reserved */
8820 if (info
->attrs
[NL80211_ATTR_IE
]) {
8821 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8822 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8825 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8827 wdev_lock(dev
->ieee80211_ptr
);
8828 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8829 local_state_change
);
8830 wdev_unlock(dev
->ieee80211_ptr
);
8834 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
8836 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8837 struct net_device
*dev
= info
->user_ptr
[1];
8838 const u8
*ie
= NULL
, *bssid
;
8839 int ie_len
= 0, err
;
8841 bool local_state_change
;
8843 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
8844 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
8847 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8850 if (!info
->attrs
[NL80211_ATTR_MAC
])
8853 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8856 if (!rdev
->ops
->disassoc
)
8859 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8860 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8863 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8865 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8866 if (reason_code
== 0) {
8867 /* Reason Code 0 is reserved */
8871 if (info
->attrs
[NL80211_ATTR_IE
]) {
8872 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8873 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8876 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8878 wdev_lock(dev
->ieee80211_ptr
);
8879 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8880 local_state_change
);
8881 wdev_unlock(dev
->ieee80211_ptr
);
8886 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
8887 int mcast_rate
[NUM_NL80211_BANDS
],
8890 struct wiphy
*wiphy
= &rdev
->wiphy
;
8894 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8895 struct ieee80211_supported_band
*sband
;
8897 sband
= wiphy
->bands
[band
];
8901 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
8902 if (sband
->bitrates
[i
].bitrate
== rateval
) {
8903 mcast_rate
[band
] = i
+ 1;
8913 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8915 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8916 struct net_device
*dev
= info
->user_ptr
[1];
8917 struct cfg80211_ibss_params ibss
;
8918 struct wiphy
*wiphy
;
8919 struct cfg80211_cached_keys
*connkeys
= NULL
;
8922 memset(&ibss
, 0, sizeof(ibss
));
8924 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8927 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8928 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8931 ibss
.beacon_interval
= 100;
8933 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
])
8934 ibss
.beacon_interval
=
8935 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8937 err
= cfg80211_validate_beacon_int(rdev
, NL80211_IFTYPE_ADHOC
,
8938 ibss
.beacon_interval
);
8942 if (!rdev
->ops
->join_ibss
)
8945 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8948 wiphy
= &rdev
->wiphy
;
8950 if (info
->attrs
[NL80211_ATTR_MAC
]) {
8951 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8953 if (!is_valid_ether_addr(ibss
.bssid
))
8956 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8957 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8959 if (info
->attrs
[NL80211_ATTR_IE
]) {
8960 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8961 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8964 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
8968 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
8969 NL80211_IFTYPE_ADHOC
))
8972 switch (ibss
.chandef
.width
) {
8973 case NL80211_CHAN_WIDTH_5
:
8974 case NL80211_CHAN_WIDTH_10
:
8975 case NL80211_CHAN_WIDTH_20_NOHT
:
8977 case NL80211_CHAN_WIDTH_20
:
8978 case NL80211_CHAN_WIDTH_40
:
8979 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8982 case NL80211_CHAN_WIDTH_80
:
8983 case NL80211_CHAN_WIDTH_80P80
:
8984 case NL80211_CHAN_WIDTH_160
:
8985 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8987 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8988 NL80211_EXT_FEATURE_VHT_IBSS
))
8995 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
8996 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
8998 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
9000 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9002 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9003 struct ieee80211_supported_band
*sband
=
9004 wiphy
->bands
[ibss
.chandef
.chan
->band
];
9006 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
9012 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9013 memcpy(&ibss
.ht_capa_mask
,
9014 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
9015 sizeof(ibss
.ht_capa_mask
));
9017 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
9018 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9020 memcpy(&ibss
.ht_capa
,
9021 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
9022 sizeof(ibss
.ht_capa
));
9025 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
9026 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
9027 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
9030 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
9033 connkeys
= nl80211_parse_connkeys(rdev
, info
, &no_ht
);
9034 if (IS_ERR(connkeys
))
9035 return PTR_ERR(connkeys
);
9037 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
9045 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
9047 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
9048 int r
= validate_pae_over_nl80211(rdev
, info
);
9055 ibss
.control_port_over_nl80211
= true;
9058 ibss
.userspace_handles_dfs
=
9059 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
9061 wdev_lock(dev
->ieee80211_ptr
);
9062 err
= __cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
9065 else if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
9066 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
9067 wdev_unlock(dev
->ieee80211_ptr
);
9072 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
9074 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9075 struct net_device
*dev
= info
->user_ptr
[1];
9077 if (!rdev
->ops
->leave_ibss
)
9080 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
9083 return cfg80211_leave_ibss(rdev
, dev
, false);
9086 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
9088 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9089 struct net_device
*dev
= info
->user_ptr
[1];
9090 int mcast_rate
[NUM_NL80211_BANDS
];
9094 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
9095 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
9096 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
9099 if (!rdev
->ops
->set_mcast_rate
)
9102 memset(mcast_rate
, 0, sizeof(mcast_rate
));
9104 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
9107 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
9108 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
9111 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
9116 static struct sk_buff
*
9117 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
9118 struct wireless_dev
*wdev
, int approxlen
,
9119 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
9120 enum nl80211_attrs attr
,
9121 const struct nl80211_vendor_cmd_info
*info
,
9124 struct sk_buff
*skb
;
9126 struct nlattr
*data
;
9128 skb
= nlmsg_new(approxlen
+ 100, gfp
);
9132 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
9138 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
9139 goto nla_put_failure
;
9142 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
9144 goto nla_put_failure
;
9145 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
9147 goto nla_put_failure
;
9151 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
9152 wdev_id(wdev
), NL80211_ATTR_PAD
))
9153 goto nla_put_failure
;
9155 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
9156 wdev
->netdev
->ifindex
))
9157 goto nla_put_failure
;
9160 data
= nla_nest_start(skb
, attr
);
9162 goto nla_put_failure
;
9164 ((void **)skb
->cb
)[0] = rdev
;
9165 ((void **)skb
->cb
)[1] = hdr
;
9166 ((void **)skb
->cb
)[2] = data
;
9175 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
9176 struct wireless_dev
*wdev
,
9177 enum nl80211_commands cmd
,
9178 enum nl80211_attrs attr
,
9179 int vendor_event_idx
,
9180 int approxlen
, gfp_t gfp
)
9182 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
9183 const struct nl80211_vendor_cmd_info
*info
;
9186 case NL80211_CMD_TESTMODE
:
9187 if (WARN_ON(vendor_event_idx
!= -1))
9191 case NL80211_CMD_VENDOR
:
9192 if (WARN_ON(vendor_event_idx
< 0 ||
9193 vendor_event_idx
>= wiphy
->n_vendor_events
))
9195 info
= &wiphy
->vendor_events
[vendor_event_idx
];
9202 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
9203 cmd
, attr
, info
, gfp
);
9205 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
9207 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
9209 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
9210 void *hdr
= ((void **)skb
->cb
)[1];
9211 struct nlattr
*data
= ((void **)skb
->cb
)[2];
9212 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
9214 /* clear CB data for netlink core to own from now on */
9215 memset(skb
->cb
, 0, sizeof(skb
->cb
));
9217 nla_nest_end(skb
, data
);
9218 genlmsg_end(skb
, hdr
);
9220 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
9221 mcgrp
= NL80211_MCGRP_VENDOR
;
9223 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
9226 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
9228 #ifdef CONFIG_NL80211_TESTMODE
9229 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
9231 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9232 struct wireless_dev
*wdev
=
9233 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
9236 if (!rdev
->ops
->testmode_cmd
)
9240 err
= PTR_ERR(wdev
);
9244 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
9248 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
9251 rdev
->cur_cmd_info
= info
;
9252 err
= rdev_testmode_cmd(rdev
, wdev
,
9253 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
9254 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
9255 rdev
->cur_cmd_info
= NULL
;
9260 static int nl80211_testmode_dump(struct sk_buff
*skb
,
9261 struct netlink_callback
*cb
)
9263 struct cfg80211_registered_device
*rdev
;
9273 * 0 is a valid index, but not valid for args[0],
9274 * so we need to offset by 1.
9276 phy_idx
= cb
->args
[0] - 1;
9278 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
9284 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
9286 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
9287 attrbuf
, nl80211_fam
.maxattr
,
9288 nl80211_policy
, NULL
);
9292 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
9294 err
= PTR_ERR(rdev
);
9297 phy_idx
= rdev
->wiphy_idx
;
9299 if (attrbuf
[NL80211_ATTR_TESTDATA
])
9300 cb
->args
[1] = (long)attrbuf
[NL80211_ATTR_TESTDATA
];
9304 data
= nla_data((void *)cb
->args
[1]);
9305 data_len
= nla_len((void *)cb
->args
[1]);
9308 if (!rdev
->ops
->testmode_dump
) {
9314 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
9315 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
9316 NL80211_CMD_TESTMODE
);
9317 struct nlattr
*tmdata
;
9322 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
9323 genlmsg_cancel(skb
, hdr
);
9327 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
9329 genlmsg_cancel(skb
, hdr
);
9332 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
9333 nla_nest_end(skb
, tmdata
);
9335 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
9336 genlmsg_cancel(skb
, hdr
);
9339 genlmsg_cancel(skb
, hdr
);
9343 genlmsg_end(skb
, hdr
);
9348 cb
->args
[0] = phy_idx
+ 1;
9355 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
9357 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9358 struct net_device
*dev
= info
->user_ptr
[1];
9359 struct cfg80211_connect_params connect
;
9360 struct wiphy
*wiphy
;
9361 struct cfg80211_cached_keys
*connkeys
= NULL
;
9364 memset(&connect
, 0, sizeof(connect
));
9366 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9369 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
9370 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
9373 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
9375 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
9376 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
9377 NL80211_CMD_CONNECT
))
9380 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
9382 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
9384 if (info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
] &&
9385 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9386 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
9388 connect
.want_1x
= info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
];
9390 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
9391 NL80211_MAX_NR_CIPHER_SUITES
);
9395 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9396 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9399 wiphy
= &rdev
->wiphy
;
9401 connect
.bg_scan_period
= -1;
9402 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
9403 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
9404 connect
.bg_scan_period
=
9405 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
9408 if (info
->attrs
[NL80211_ATTR_MAC
])
9409 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9410 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
9411 connect
.bssid_hint
=
9412 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
9413 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9414 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9416 if (info
->attrs
[NL80211_ATTR_IE
]) {
9417 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9418 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9421 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
9422 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
9423 if (connect
.mfp
== NL80211_MFP_OPTIONAL
&&
9424 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9425 NL80211_EXT_FEATURE_MFP_OPTIONAL
))
9428 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
9429 connect
.mfp
!= NL80211_MFP_NO
&&
9430 connect
.mfp
!= NL80211_MFP_OPTIONAL
)
9433 connect
.mfp
= NL80211_MFP_NO
;
9436 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
9437 connect
.prev_bssid
=
9438 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
9440 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9441 connect
.channel
= nl80211_get_valid_chan(
9442 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
9443 if (!connect
.channel
)
9445 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
9446 connect
.channel_hint
= nl80211_get_valid_chan(
9447 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
9448 if (!connect
.channel_hint
)
9452 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
9453 connkeys
= nl80211_parse_connkeys(rdev
, info
, NULL
);
9454 if (IS_ERR(connkeys
))
9455 return PTR_ERR(connkeys
);
9458 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
9459 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
9461 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9462 memcpy(&connect
.ht_capa_mask
,
9463 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
9464 sizeof(connect
.ht_capa_mask
));
9466 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
9467 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
9471 memcpy(&connect
.ht_capa
,
9472 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
9473 sizeof(connect
.ht_capa
));
9476 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
9477 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
9479 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
9480 memcpy(&connect
.vht_capa_mask
,
9481 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
9482 sizeof(connect
.vht_capa_mask
));
9484 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
9485 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
9489 memcpy(&connect
.vht_capa
,
9490 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
9491 sizeof(connect
.vht_capa
));
9494 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
9495 if (!((rdev
->wiphy
.features
&
9496 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
9497 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
9498 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9499 NL80211_EXT_FEATURE_RRM
)) {
9503 connect
.flags
|= ASSOC_REQ_USE_RRM
;
9506 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
9507 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
9512 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
9513 /* bss selection makes no sense if bssid is set */
9514 if (connect
.bssid
) {
9519 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
9520 wiphy
, &connect
.bss_select
);
9527 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
9528 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
9529 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
9530 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
9531 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
9532 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9533 connect
.fils_erp_username
=
9534 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9535 connect
.fils_erp_username_len
=
9536 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9537 connect
.fils_erp_realm
=
9538 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9539 connect
.fils_erp_realm_len
=
9540 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9541 connect
.fils_erp_next_seq_num
=
9543 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
9544 connect
.fils_erp_rrk
=
9545 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9546 connect
.fils_erp_rrk_len
=
9547 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9548 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
9549 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
9550 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
9551 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9556 if (nla_get_flag(info
->attrs
[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT
])) {
9557 if (!info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9559 GENL_SET_ERR_MSG(info
,
9560 "external auth requires connection ownership");
9563 connect
.flags
|= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT
;
9566 wdev_lock(dev
->ieee80211_ptr
);
9568 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
9569 connect
.prev_bssid
);
9573 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9574 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
9576 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
9577 connect
.bssid
, ETH_ALEN
);
9579 memset(dev
->ieee80211_ptr
->disconnect_bssid
,
9583 wdev_unlock(dev
->ieee80211_ptr
);
9588 static int nl80211_update_connect_params(struct sk_buff
*skb
,
9589 struct genl_info
*info
)
9591 struct cfg80211_connect_params connect
= {};
9592 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9593 struct net_device
*dev
= info
->user_ptr
[1];
9594 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9595 bool fils_sk_offload
;
9600 if (!rdev
->ops
->update_connect_params
)
9603 if (info
->attrs
[NL80211_ATTR_IE
]) {
9604 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9606 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9607 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9608 changed
|= UPDATE_ASSOC_IES
;
9611 fils_sk_offload
= wiphy_ext_feature_isset(&rdev
->wiphy
,
9612 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
);
9615 * when driver supports fils-sk offload all attributes must be
9616 * provided. So the else covers "fils-sk-not-all" and
9619 if (fils_sk_offload
&&
9620 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
9621 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
9622 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
9623 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9624 connect
.fils_erp_username
=
9625 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9626 connect
.fils_erp_username_len
=
9627 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9628 connect
.fils_erp_realm
=
9629 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9630 connect
.fils_erp_realm_len
=
9631 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9632 connect
.fils_erp_next_seq_num
=
9634 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
9635 connect
.fils_erp_rrk
=
9636 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9637 connect
.fils_erp_rrk_len
=
9638 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9639 changed
|= UPDATE_FILS_ERP_INFO
;
9640 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
9641 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
9642 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
9643 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9647 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
9648 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
9649 if (!nl80211_valid_auth_type(rdev
, auth_type
,
9650 NL80211_CMD_CONNECT
))
9653 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
&&
9654 fils_sk_offload
&& !(changed
& UPDATE_FILS_ERP_INFO
))
9657 connect
.auth_type
= auth_type
;
9658 changed
|= UPDATE_AUTH_TYPE
;
9661 wdev_lock(dev
->ieee80211_ptr
);
9662 if (!wdev
->current_bss
)
9665 ret
= rdev_update_connect_params(rdev
, dev
, &connect
, changed
);
9666 wdev_unlock(dev
->ieee80211_ptr
);
9671 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
9673 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9674 struct net_device
*dev
= info
->user_ptr
[1];
9678 if (dev
->ieee80211_ptr
->conn_owner_nlportid
&&
9679 dev
->ieee80211_ptr
->conn_owner_nlportid
!= info
->snd_portid
)
9682 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
9683 reason
= WLAN_REASON_DEAUTH_LEAVING
;
9685 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
9690 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9691 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9694 wdev_lock(dev
->ieee80211_ptr
);
9695 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
9696 wdev_unlock(dev
->ieee80211_ptr
);
9700 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
9702 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9706 if (info
->attrs
[NL80211_ATTR_PID
]) {
9707 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
9709 net
= get_net_ns_by_pid(pid
);
9710 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
9711 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
9713 net
= get_net_ns_by_fd(fd
);
9719 return PTR_ERR(net
);
9723 /* check if anything to do */
9724 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
9725 err
= cfg80211_switch_netns(rdev
, net
);
9731 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9733 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9734 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
9735 struct cfg80211_pmksa
*pmksa
) = NULL
;
9736 struct net_device
*dev
= info
->user_ptr
[1];
9737 struct cfg80211_pmksa pmksa
;
9739 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
9741 if (!info
->attrs
[NL80211_ATTR_PMKID
])
9744 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
9746 if (info
->attrs
[NL80211_ATTR_MAC
]) {
9747 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9748 } else if (info
->attrs
[NL80211_ATTR_SSID
] &&
9749 info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
] &&
9750 (info
->genlhdr
->cmd
== NL80211_CMD_DEL_PMKSA
||
9751 info
->attrs
[NL80211_ATTR_PMK
])) {
9752 pmksa
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9753 pmksa
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9755 nla_data(info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
]);
9759 if (info
->attrs
[NL80211_ATTR_PMK
]) {
9760 pmksa
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
9761 pmksa
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
9764 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9765 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9768 switch (info
->genlhdr
->cmd
) {
9769 case NL80211_CMD_SET_PMKSA
:
9770 rdev_ops
= rdev
->ops
->set_pmksa
;
9772 case NL80211_CMD_DEL_PMKSA
:
9773 rdev_ops
= rdev
->ops
->del_pmksa
;
9783 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
9786 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9788 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9789 struct net_device
*dev
= info
->user_ptr
[1];
9791 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9792 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9795 if (!rdev
->ops
->flush_pmksa
)
9798 return rdev_flush_pmksa(rdev
, dev
);
9801 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9803 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9804 struct net_device
*dev
= info
->user_ptr
[1];
9805 u8 action_code
, dialog_token
;
9806 u32 peer_capability
= 0;
9811 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9812 !rdev
->ops
->tdls_mgmt
)
9815 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
9816 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
9817 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
9818 !info
->attrs
[NL80211_ATTR_IE
] ||
9819 !info
->attrs
[NL80211_ATTR_MAC
])
9822 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9823 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
9824 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
9825 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
9826 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
9827 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
9829 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
9831 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
9832 dialog_token
, status_code
, peer_capability
,
9834 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
9835 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
9838 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
9840 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9841 struct net_device
*dev
= info
->user_ptr
[1];
9842 enum nl80211_tdls_operation operation
;
9845 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9846 !rdev
->ops
->tdls_oper
)
9849 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
9850 !info
->attrs
[NL80211_ATTR_MAC
])
9853 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
9854 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9856 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
9859 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
9860 struct genl_info
*info
)
9862 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9863 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9864 struct cfg80211_chan_def chandef
;
9865 const struct cfg80211_chan_def
*compat_chandef
;
9866 struct sk_buff
*msg
;
9872 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
9873 !info
->attrs
[NL80211_ATTR_DURATION
])
9876 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9878 if (!rdev
->ops
->remain_on_channel
||
9879 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
9883 * We should be on that channel for at least a minimum amount of
9884 * time (10ms) but no longer than the driver supports.
9886 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9887 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
9890 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9895 if (!cfg80211_off_channel_oper_allowed(wdev
) &&
9896 !cfg80211_chandef_identical(&wdev
->chandef
, &chandef
)) {
9897 compat_chandef
= cfg80211_chandef_compatible(&wdev
->chandef
,
9899 if (compat_chandef
!= &chandef
) {
9906 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9910 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9911 NL80211_CMD_REMAIN_ON_CHANNEL
);
9917 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
9923 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9925 goto nla_put_failure
;
9927 genlmsg_end(msg
, hdr
);
9929 return genlmsg_reply(msg
, info
);
9938 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
9939 struct genl_info
*info
)
9941 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9942 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9945 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9948 if (!rdev
->ops
->cancel_remain_on_channel
)
9951 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9953 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
9956 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
9957 struct genl_info
*info
)
9959 struct cfg80211_bitrate_mask mask
;
9960 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9961 struct net_device
*dev
= info
->user_ptr
[1];
9964 if (!rdev
->ops
->set_bitrate_mask
)
9967 err
= nl80211_parse_tx_bitrate_mask(info
, &mask
);
9971 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
9974 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9976 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9977 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9978 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
9980 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
9983 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
9984 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
9986 switch (wdev
->iftype
) {
9987 case NL80211_IFTYPE_STATION
:
9988 case NL80211_IFTYPE_ADHOC
:
9989 case NL80211_IFTYPE_P2P_CLIENT
:
9990 case NL80211_IFTYPE_AP
:
9991 case NL80211_IFTYPE_AP_VLAN
:
9992 case NL80211_IFTYPE_MESH_POINT
:
9993 case NL80211_IFTYPE_P2P_GO
:
9994 case NL80211_IFTYPE_P2P_DEVICE
:
9996 case NL80211_IFTYPE_NAN
:
10001 /* not much point in registering if we can't reply */
10002 if (!rdev
->ops
->mgmt_tx
)
10003 return -EOPNOTSUPP
;
10005 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
10006 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
10007 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
10010 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
10012 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10013 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10014 struct cfg80211_chan_def chandef
;
10018 struct sk_buff
*msg
= NULL
;
10019 struct cfg80211_mgmt_tx_params params
= {
10020 .dont_wait_for_ack
=
10021 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
10024 if (!info
->attrs
[NL80211_ATTR_FRAME
])
10027 if (!rdev
->ops
->mgmt_tx
)
10028 return -EOPNOTSUPP
;
10030 switch (wdev
->iftype
) {
10031 case NL80211_IFTYPE_P2P_DEVICE
:
10032 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
10034 case NL80211_IFTYPE_STATION
:
10035 case NL80211_IFTYPE_ADHOC
:
10036 case NL80211_IFTYPE_P2P_CLIENT
:
10037 case NL80211_IFTYPE_AP
:
10038 case NL80211_IFTYPE_AP_VLAN
:
10039 case NL80211_IFTYPE_MESH_POINT
:
10040 case NL80211_IFTYPE_P2P_GO
:
10042 case NL80211_IFTYPE_NAN
:
10044 return -EOPNOTSUPP
;
10047 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
10048 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
10050 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
10053 * We should wait on the channel for at least a minimum amount
10054 * of time (10ms) but no longer than the driver supports.
10056 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
10057 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
10061 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
10063 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
10066 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
10068 /* get the channel if any has been specified, otherwise pass NULL to
10069 * the driver. The latter will use the current one
10071 chandef
.chan
= NULL
;
10072 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
10073 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
10078 if (!chandef
.chan
&& params
.offchan
)
10082 if (params
.offchan
&& !cfg80211_off_channel_oper_allowed(wdev
)) {
10088 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
10089 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
10091 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
10092 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
10095 if (len
% sizeof(u16
))
10098 params
.n_csa_offsets
= len
/ sizeof(u16
);
10099 params
.csa_offsets
=
10100 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
10102 /* check that all the offsets fit the frame */
10103 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
10104 if (params
.csa_offsets
[i
] >= params
.len
)
10109 if (!params
.dont_wait_for_ack
) {
10110 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10114 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10115 NL80211_CMD_FRAME
);
10122 params
.chan
= chandef
.chan
;
10123 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
10128 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
10130 goto nla_put_failure
;
10132 genlmsg_end(msg
, hdr
);
10133 return genlmsg_reply(msg
, info
);
10145 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
10147 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10148 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10151 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
10154 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
10155 return -EOPNOTSUPP
;
10157 switch (wdev
->iftype
) {
10158 case NL80211_IFTYPE_STATION
:
10159 case NL80211_IFTYPE_ADHOC
:
10160 case NL80211_IFTYPE_P2P_CLIENT
:
10161 case NL80211_IFTYPE_AP
:
10162 case NL80211_IFTYPE_AP_VLAN
:
10163 case NL80211_IFTYPE_P2P_GO
:
10164 case NL80211_IFTYPE_P2P_DEVICE
:
10166 case NL80211_IFTYPE_NAN
:
10168 return -EOPNOTSUPP
;
10171 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
10173 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
10176 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
10178 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10179 struct wireless_dev
*wdev
;
10180 struct net_device
*dev
= info
->user_ptr
[1];
10185 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
10188 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
10190 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
10193 wdev
= dev
->ieee80211_ptr
;
10195 if (!rdev
->ops
->set_power_mgmt
)
10196 return -EOPNOTSUPP
;
10198 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
10200 if (state
== wdev
->ps
)
10203 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
10209 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
10211 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10212 enum nl80211_ps_state ps_state
;
10213 struct wireless_dev
*wdev
;
10214 struct net_device
*dev
= info
->user_ptr
[1];
10215 struct sk_buff
*msg
;
10219 wdev
= dev
->ieee80211_ptr
;
10221 if (!rdev
->ops
->set_power_mgmt
)
10222 return -EOPNOTSUPP
;
10224 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10228 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10229 NL80211_CMD_GET_POWER_SAVE
);
10236 ps_state
= NL80211_PS_ENABLED
;
10238 ps_state
= NL80211_PS_DISABLED
;
10240 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
10241 goto nla_put_failure
;
10243 genlmsg_end(msg
, hdr
);
10244 return genlmsg_reply(msg
, info
);
10253 static const struct nla_policy
10254 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
10255 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_BINARY
},
10256 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
10257 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
10258 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
10259 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
10260 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
10261 [NL80211_ATTR_CQM_RSSI_LEVEL
] = { .type
= NLA_S32
},
10264 static int nl80211_set_cqm_txe(struct genl_info
*info
,
10265 u32 rate
, u32 pkts
, u32 intvl
)
10267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10268 struct net_device
*dev
= info
->user_ptr
[1];
10269 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10271 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
10274 if (!rdev
->ops
->set_cqm_txe_config
)
10275 return -EOPNOTSUPP
;
10277 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
10278 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10279 return -EOPNOTSUPP
;
10281 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
10284 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device
*rdev
,
10285 struct net_device
*dev
)
10287 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10288 s32 last
, low
, high
;
10290 int i
, n
, low_index
;
10293 /* RSSI reporting disabled? */
10294 if (!wdev
->cqm_config
)
10295 return rdev_set_cqm_rssi_range_config(rdev
, dev
, 0, 0);
10298 * Obtain current RSSI value if possible, if not and no RSSI threshold
10299 * event has been received yet, we should receive an event after a
10300 * connection is established and enough beacons received to calculate
10303 if (!wdev
->cqm_config
->last_rssi_event_value
&& wdev
->current_bss
&&
10304 rdev
->ops
->get_station
) {
10305 struct station_info sinfo
= {};
10308 mac_addr
= wdev
->current_bss
->pub
.bssid
;
10310 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
10314 cfg80211_sinfo_release_content(&sinfo
);
10315 if (sinfo
.filled
& BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG
))
10316 wdev
->cqm_config
->last_rssi_event_value
=
10317 (s8
) sinfo
.rx_beacon_signal_avg
;
10320 last
= wdev
->cqm_config
->last_rssi_event_value
;
10321 hyst
= wdev
->cqm_config
->rssi_hyst
;
10322 n
= wdev
->cqm_config
->n_rssi_thresholds
;
10324 for (i
= 0; i
< n
; i
++) {
10325 i
= array_index_nospec(i
, n
);
10326 if (last
< wdev
->cqm_config
->rssi_thresholds
[i
])
10331 if (low_index
>= 0) {
10332 low_index
= array_index_nospec(low_index
, n
);
10333 low
= wdev
->cqm_config
->rssi_thresholds
[low_index
] - hyst
;
10338 i
= array_index_nospec(i
, n
);
10339 high
= wdev
->cqm_config
->rssi_thresholds
[i
] + hyst
- 1;
10344 return rdev_set_cqm_rssi_range_config(rdev
, dev
, low
, high
);
10347 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
10348 const s32
*thresholds
, int n_thresholds
,
10351 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10352 struct net_device
*dev
= info
->user_ptr
[1];
10353 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10355 s32 prev
= S32_MIN
;
10357 /* Check all values negative and sorted */
10358 for (i
= 0; i
< n_thresholds
; i
++) {
10359 if (thresholds
[i
] > 0 || thresholds
[i
] <= prev
)
10362 prev
= thresholds
[i
];
10365 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
10366 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
10367 return -EOPNOTSUPP
;
10370 cfg80211_cqm_config_free(wdev
);
10373 if (n_thresholds
<= 1 && rdev
->ops
->set_cqm_rssi_config
) {
10374 if (n_thresholds
== 0 || thresholds
[0] == 0) /* Disabling */
10375 return rdev_set_cqm_rssi_config(rdev
, dev
, 0, 0);
10377 return rdev_set_cqm_rssi_config(rdev
, dev
,
10378 thresholds
[0], hysteresis
);
10381 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
10382 NL80211_EXT_FEATURE_CQM_RSSI_LIST
))
10383 return -EOPNOTSUPP
;
10385 if (n_thresholds
== 1 && thresholds
[0] == 0) /* Disabling */
10389 if (n_thresholds
) {
10390 struct cfg80211_cqm_config
*cqm_config
;
10392 cqm_config
= kzalloc(sizeof(struct cfg80211_cqm_config
) +
10393 n_thresholds
* sizeof(s32
), GFP_KERNEL
);
10399 cqm_config
->rssi_hyst
= hysteresis
;
10400 cqm_config
->n_rssi_thresholds
= n_thresholds
;
10401 memcpy(cqm_config
->rssi_thresholds
, thresholds
,
10402 n_thresholds
* sizeof(s32
));
10404 wdev
->cqm_config
= cqm_config
;
10407 err
= cfg80211_cqm_rssi_update(rdev
, dev
);
10415 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
10417 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
10418 struct nlattr
*cqm
;
10421 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
10425 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
10426 nl80211_attr_cqm_policy
, info
->extack
);
10430 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
10431 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
10432 const s32
*thresholds
=
10433 nla_data(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
10434 int len
= nla_len(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
10435 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
10440 return nl80211_set_cqm_rssi(info
, thresholds
, len
/ 4,
10444 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
10445 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
10446 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
10447 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
10448 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
10449 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
10451 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
10457 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
10459 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10460 struct net_device
*dev
= info
->user_ptr
[1];
10461 struct ocb_setup setup
= {};
10464 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
10468 return cfg80211_join_ocb(rdev
, dev
, &setup
);
10471 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
10473 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10474 struct net_device
*dev
= info
->user_ptr
[1];
10476 return cfg80211_leave_ocb(rdev
, dev
);
10479 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
10481 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10482 struct net_device
*dev
= info
->user_ptr
[1];
10483 struct mesh_config cfg
;
10484 struct mesh_setup setup
;
10487 /* start with default */
10488 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
10489 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
10491 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
10492 /* and parse parameters if given */
10493 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
10498 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
10499 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
10502 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
10503 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
10505 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
10506 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
10507 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
10510 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
10511 setup
.beacon_interval
=
10512 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
10514 err
= cfg80211_validate_beacon_int(rdev
,
10515 NL80211_IFTYPE_MESH_POINT
,
10516 setup
.beacon_interval
);
10521 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
10522 setup
.dtim_period
=
10523 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
10524 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
10528 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
10529 /* parse additional setup parameters if given */
10530 err
= nl80211_parse_mesh_setup(info
, &setup
);
10535 if (setup
.user_mpm
)
10536 cfg
.auto_open_plinks
= false;
10538 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
10539 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
10543 /* __cfg80211_join_mesh() will sort it out */
10544 setup
.chandef
.chan
= NULL
;
10547 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
10548 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10550 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10551 struct ieee80211_supported_band
*sband
;
10553 if (!setup
.chandef
.chan
)
10556 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
10558 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
10559 &setup
.basic_rates
);
10564 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
10565 err
= nl80211_parse_tx_bitrate_mask(info
, &setup
.beacon_rate
);
10569 if (!setup
.chandef
.chan
)
10572 err
= validate_beacon_tx_rate(rdev
, setup
.chandef
.chan
->band
,
10573 &setup
.beacon_rate
);
10578 setup
.userspace_handles_dfs
=
10579 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
10581 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_OVER_NL80211
]) {
10582 int r
= validate_pae_over_nl80211(rdev
, info
);
10587 setup
.control_port_over_nl80211
= true;
10590 wdev_lock(dev
->ieee80211_ptr
);
10591 err
= __cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
10592 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
10593 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
10594 wdev_unlock(dev
->ieee80211_ptr
);
10599 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
10601 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10602 struct net_device
*dev
= info
->user_ptr
[1];
10604 return cfg80211_leave_mesh(rdev
, dev
);
10608 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
10609 struct cfg80211_registered_device
*rdev
)
10611 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
10612 struct nlattr
*nl_pats
, *nl_pat
;
10615 if (!wowlan
->n_patterns
)
10618 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
10622 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
10623 nl_pat
= nla_nest_start(msg
, i
+ 1);
10626 pat_len
= wowlan
->patterns
[i
].pattern_len
;
10627 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
10628 wowlan
->patterns
[i
].mask
) ||
10629 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
10630 wowlan
->patterns
[i
].pattern
) ||
10631 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
10632 wowlan
->patterns
[i
].pkt_offset
))
10634 nla_nest_end(msg
, nl_pat
);
10636 nla_nest_end(msg
, nl_pats
);
10641 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
10642 struct cfg80211_wowlan_tcp
*tcp
)
10644 struct nlattr
*nl_tcp
;
10649 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
10653 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
10654 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
10655 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
10656 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
10657 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
10658 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
10659 tcp
->payload_len
, tcp
->payload
) ||
10660 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
10661 tcp
->data_interval
) ||
10662 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
10663 tcp
->wake_len
, tcp
->wake_data
) ||
10664 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
10665 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
10668 if (tcp
->payload_seq
.len
&&
10669 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
10670 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
10673 if (tcp
->payload_tok
.len
&&
10674 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
10675 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
10676 &tcp
->payload_tok
))
10679 nla_nest_end(msg
, nl_tcp
);
10684 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
10685 struct cfg80211_sched_scan_request
*req
)
10687 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
10693 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
10697 if (req
->n_scan_plans
== 1 &&
10698 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
10699 req
->scan_plans
[0].interval
* 1000))
10702 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
10705 if (req
->relative_rssi_set
) {
10706 struct nl80211_bss_select_rssi_adjust rssi_adjust
;
10708 if (nla_put_s8(msg
, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
,
10709 req
->relative_rssi
))
10712 rssi_adjust
.band
= req
->rssi_adjust
.band
;
10713 rssi_adjust
.delta
= req
->rssi_adjust
.delta
;
10714 if (nla_put(msg
, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
,
10715 sizeof(rssi_adjust
), &rssi_adjust
))
10719 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
10723 for (i
= 0; i
< req
->n_channels
; i
++) {
10724 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
10728 nla_nest_end(msg
, freqs
);
10730 if (req
->n_match_sets
) {
10731 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
10735 for (i
= 0; i
< req
->n_match_sets
; i
++) {
10736 match
= nla_nest_start(msg
, i
);
10740 if (nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
10741 req
->match_sets
[i
].ssid
.ssid_len
,
10742 req
->match_sets
[i
].ssid
.ssid
))
10744 nla_nest_end(msg
, match
);
10746 nla_nest_end(msg
, matches
);
10749 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
10753 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
10754 scan_plan
= nla_nest_start(msg
, i
+ 1);
10759 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
10760 req
->scan_plans
[i
].interval
) ||
10761 (req
->scan_plans
[i
].iterations
&&
10762 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
10763 req
->scan_plans
[i
].iterations
)))
10765 nla_nest_end(msg
, scan_plan
);
10767 nla_nest_end(msg
, scan_plans
);
10769 nla_nest_end(msg
, nd
);
10774 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
10776 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10777 struct sk_buff
*msg
;
10779 u32 size
= NLMSG_DEFAULT_SIZE
;
10781 if (!rdev
->wiphy
.wowlan
)
10782 return -EOPNOTSUPP
;
10784 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
10785 /* adjust size to have room for all the data */
10786 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
10787 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
10788 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
10789 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
10792 msg
= nlmsg_new(size
, GFP_KERNEL
);
10796 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10797 NL80211_CMD_GET_WOWLAN
);
10799 goto nla_put_failure
;
10801 if (rdev
->wiphy
.wowlan_config
) {
10802 struct nlattr
*nl_wowlan
;
10804 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10806 goto nla_put_failure
;
10808 if ((rdev
->wiphy
.wowlan_config
->any
&&
10809 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
10810 (rdev
->wiphy
.wowlan_config
->disconnect
&&
10811 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
10812 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
10813 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
10814 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
10815 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
10816 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
10817 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
10818 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
10819 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
10820 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
10821 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
10822 goto nla_put_failure
;
10824 if (nl80211_send_wowlan_patterns(msg
, rdev
))
10825 goto nla_put_failure
;
10827 if (nl80211_send_wowlan_tcp(msg
,
10828 rdev
->wiphy
.wowlan_config
->tcp
))
10829 goto nla_put_failure
;
10831 if (nl80211_send_wowlan_nd(
10833 rdev
->wiphy
.wowlan_config
->nd_config
))
10834 goto nla_put_failure
;
10836 nla_nest_end(msg
, nl_wowlan
);
10839 genlmsg_end(msg
, hdr
);
10840 return genlmsg_reply(msg
, info
);
10847 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
10848 struct nlattr
*attr
,
10849 struct cfg80211_wowlan
*trig
)
10851 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
10852 struct cfg80211_wowlan_tcp
*cfg
;
10853 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
10854 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
10856 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
10859 if (!rdev
->wiphy
.wowlan
->tcp
)
10862 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TCP
, attr
,
10863 nl80211_wowlan_tcp_policy
, NULL
);
10867 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
10868 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
10869 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
10870 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
10871 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
10872 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
10873 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
10874 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
10877 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
10878 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
10881 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
10882 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
10883 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
10886 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
10887 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
10890 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
10891 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
10894 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
10895 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10897 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10898 tokens_size
= tokln
- sizeof(*tok
);
10900 if (!tok
->len
|| tokens_size
% tok
->len
)
10902 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
10904 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
10906 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
10908 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
10910 if (tok
->offset
+ tok
->len
> data_size
)
10914 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
10915 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
10916 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
10918 if (seq
->len
== 0 || seq
->len
> 4)
10920 if (seq
->len
+ seq
->offset
> data_size
)
10924 size
= sizeof(*cfg
);
10926 size
+= wake_size
+ wake_mask_size
;
10927 size
+= tokens_size
;
10929 cfg
= kzalloc(size
, GFP_KERNEL
);
10932 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
10933 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
10934 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
10936 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
10937 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
10941 /* allocate a socket and port for it and use it */
10942 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
10943 IPPROTO_TCP
, &cfg
->sock
, 1);
10948 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
10949 sock_release(cfg
->sock
);
10951 return -EADDRINUSE
;
10953 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
10959 cfg
->src_port
= port
;
10962 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
10963 cfg
->payload_len
= data_size
;
10964 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
10965 memcpy((void *)cfg
->payload
,
10966 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
10969 cfg
->payload_seq
= *seq
;
10970 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
10971 cfg
->wake_len
= wake_size
;
10972 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
10973 memcpy((void *)cfg
->wake_data
,
10974 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
10976 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
10977 data_size
+ wake_size
;
10978 memcpy((void *)cfg
->wake_mask
,
10979 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
10982 cfg
->tokens_size
= tokens_size
;
10983 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
10991 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
10992 const struct wiphy_wowlan_support
*wowlan
,
10993 struct nlattr
*attr
,
10994 struct cfg80211_wowlan
*trig
)
10996 struct nlattr
**tb
;
10999 tb
= kcalloc(NUM_NL80211_ATTR
, sizeof(*tb
), GFP_KERNEL
);
11003 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
11008 err
= nla_parse_nested(tb
, NL80211_ATTR_MAX
, attr
, nl80211_policy
,
11013 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
,
11014 wowlan
->max_nd_match_sets
);
11015 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
11017 trig
->nd_config
= NULL
;
11024 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
11026 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11027 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
11028 struct cfg80211_wowlan new_triggers
= {};
11029 struct cfg80211_wowlan
*ntrig
;
11030 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
11032 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
11033 bool regular
= false;
11036 return -EOPNOTSUPP
;
11038 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
11039 cfg80211_rdev_free_wowlan(rdev
);
11040 rdev
->wiphy
.wowlan_config
= NULL
;
11044 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TRIG
,
11045 info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
],
11046 nl80211_wowlan_policy
, info
->extack
);
11050 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
11051 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
11053 new_triggers
.any
= true;
11056 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
11057 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
11059 new_triggers
.disconnect
= true;
11063 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
11064 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
11066 new_triggers
.magic_pkt
= true;
11070 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
11073 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
11074 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
11076 new_triggers
.gtk_rekey_failure
= true;
11080 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
11081 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
11083 new_triggers
.eap_identity_req
= true;
11087 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
11088 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
11090 new_triggers
.four_way_handshake
= true;
11094 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
11095 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
11097 new_triggers
.rfkill_release
= true;
11101 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
11102 struct nlattr
*pat
;
11103 int n_patterns
= 0;
11104 int rem
, pat_len
, mask_len
, pkt_offset
;
11105 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
11109 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
11112 if (n_patterns
> wowlan
->n_patterns
)
11115 new_triggers
.patterns
= kcalloc(n_patterns
,
11116 sizeof(new_triggers
.patterns
[0]),
11118 if (!new_triggers
.patterns
)
11121 new_triggers
.n_patterns
= n_patterns
;
11124 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
11128 err
= nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
11129 nl80211_packet_pattern_policy
,
11135 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
11136 !pat_tb
[NL80211_PKTPAT_PATTERN
])
11138 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
11139 mask_len
= DIV_ROUND_UP(pat_len
, 8);
11140 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
11142 if (pat_len
> wowlan
->pattern_max_len
||
11143 pat_len
< wowlan
->pattern_min_len
)
11146 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
11149 pkt_offset
= nla_get_u32(
11150 pat_tb
[NL80211_PKTPAT_OFFSET
]);
11151 if (pkt_offset
> wowlan
->max_pkt_offset
)
11153 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
11155 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
11160 new_triggers
.patterns
[i
].mask
= mask_pat
;
11161 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
11163 mask_pat
+= mask_len
;
11164 new_triggers
.patterns
[i
].pattern
= mask_pat
;
11165 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
11167 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
11173 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
11175 err
= nl80211_parse_wowlan_tcp(
11176 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
11182 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
11184 err
= nl80211_parse_wowlan_nd(
11185 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
11191 /* The 'any' trigger means the device continues operating more or less
11192 * as in its normal operation mode and wakes up the host on most of the
11193 * normal interrupts (like packet RX, ...)
11194 * It therefore makes little sense to combine with the more constrained
11195 * wakeup trigger modes.
11197 if (new_triggers
.any
&& regular
) {
11202 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
11207 cfg80211_rdev_free_wowlan(rdev
);
11208 rdev
->wiphy
.wowlan_config
= ntrig
;
11211 if (rdev
->ops
->set_wakeup
&&
11212 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
11213 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
11217 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
11218 kfree(new_triggers
.patterns
[i
].mask
);
11219 kfree(new_triggers
.patterns
);
11220 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
11221 sock_release(new_triggers
.tcp
->sock
);
11222 kfree(new_triggers
.tcp
);
11223 kfree(new_triggers
.nd_config
);
11228 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
11229 struct cfg80211_registered_device
*rdev
)
11231 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
11233 struct cfg80211_coalesce_rules
*rule
;
11235 if (!rdev
->coalesce
->n_rules
)
11238 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
11242 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
11243 nl_rule
= nla_nest_start(msg
, i
+ 1);
11247 rule
= &rdev
->coalesce
->rules
[i
];
11248 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
11252 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
11256 nl_pats
= nla_nest_start(msg
,
11257 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
11261 for (j
= 0; j
< rule
->n_patterns
; j
++) {
11262 nl_pat
= nla_nest_start(msg
, j
+ 1);
11265 pat_len
= rule
->patterns
[j
].pattern_len
;
11266 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
11267 DIV_ROUND_UP(pat_len
, 8),
11268 rule
->patterns
[j
].mask
) ||
11269 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
11270 rule
->patterns
[j
].pattern
) ||
11271 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
11272 rule
->patterns
[j
].pkt_offset
))
11274 nla_nest_end(msg
, nl_pat
);
11276 nla_nest_end(msg
, nl_pats
);
11277 nla_nest_end(msg
, nl_rule
);
11279 nla_nest_end(msg
, nl_rules
);
11284 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
11286 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11287 struct sk_buff
*msg
;
11290 if (!rdev
->wiphy
.coalesce
)
11291 return -EOPNOTSUPP
;
11293 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11297 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11298 NL80211_CMD_GET_COALESCE
);
11300 goto nla_put_failure
;
11302 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
11303 goto nla_put_failure
;
11305 genlmsg_end(msg
, hdr
);
11306 return genlmsg_reply(msg
, info
);
11313 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
11315 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
11317 struct cfg80211_coalesce_rules
*rule
;
11322 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
11323 rule
= &coalesce
->rules
[i
];
11324 for (j
= 0; j
< rule
->n_patterns
; j
++)
11325 kfree(rule
->patterns
[j
].mask
);
11326 kfree(rule
->patterns
);
11328 kfree(coalesce
->rules
);
11330 rdev
->coalesce
= NULL
;
11333 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
11334 struct nlattr
*rule
,
11335 struct cfg80211_coalesce_rules
*new_rule
)
11338 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
11339 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
11340 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
11341 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
11343 err
= nla_parse_nested(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, rule
,
11344 nl80211_coalesce_policy
, NULL
);
11348 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
11350 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
11351 if (new_rule
->delay
> coalesce
->max_delay
)
11354 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
11355 new_rule
->condition
=
11356 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
11357 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
11358 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
11361 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
11364 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
11367 if (n_patterns
> coalesce
->n_patterns
)
11370 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
11372 if (!new_rule
->patterns
)
11375 new_rule
->n_patterns
= n_patterns
;
11378 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
11382 err
= nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
11383 nl80211_packet_pattern_policy
, NULL
);
11387 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
11388 !pat_tb
[NL80211_PKTPAT_PATTERN
])
11390 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
11391 mask_len
= DIV_ROUND_UP(pat_len
, 8);
11392 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
11394 if (pat_len
> coalesce
->pattern_max_len
||
11395 pat_len
< coalesce
->pattern_min_len
)
11398 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
11401 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
11402 if (pkt_offset
> coalesce
->max_pkt_offset
)
11404 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
11406 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
11410 new_rule
->patterns
[i
].mask
= mask_pat
;
11411 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
11414 mask_pat
+= mask_len
;
11415 new_rule
->patterns
[i
].pattern
= mask_pat
;
11416 new_rule
->patterns
[i
].pattern_len
= pat_len
;
11417 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
11425 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
11427 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11428 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
11429 struct cfg80211_coalesce new_coalesce
= {};
11430 struct cfg80211_coalesce
*n_coalesce
;
11431 int err
, rem_rule
, n_rules
= 0, i
, j
;
11432 struct nlattr
*rule
;
11433 struct cfg80211_coalesce_rules
*tmp_rule
;
11435 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
11436 return -EOPNOTSUPP
;
11438 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
11439 cfg80211_rdev_free_coalesce(rdev
);
11440 rdev_set_coalesce(rdev
, NULL
);
11444 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
11447 if (n_rules
> coalesce
->n_rules
)
11450 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
11452 if (!new_coalesce
.rules
)
11455 new_coalesce
.n_rules
= n_rules
;
11458 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
11460 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
11461 &new_coalesce
.rules
[i
]);
11468 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
11472 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
11477 cfg80211_rdev_free_coalesce(rdev
);
11478 rdev
->coalesce
= n_coalesce
;
11482 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
11483 tmp_rule
= &new_coalesce
.rules
[i
];
11484 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
11485 kfree(tmp_rule
->patterns
[j
].mask
);
11486 kfree(tmp_rule
->patterns
);
11488 kfree(new_coalesce
.rules
);
11493 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
11495 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11496 struct net_device
*dev
= info
->user_ptr
[1];
11497 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11498 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
11499 struct cfg80211_gtk_rekey_data rekey_data
;
11502 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
11505 err
= nla_parse_nested(tb
, MAX_NL80211_REKEY_DATA
,
11506 info
->attrs
[NL80211_ATTR_REKEY_DATA
],
11507 nl80211_rekey_policy
, info
->extack
);
11511 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
11512 !tb
[NL80211_REKEY_DATA_KCK
])
11514 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
11516 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
11518 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
11521 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
11522 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
11523 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
11526 if (!wdev
->current_bss
) {
11531 if (!rdev
->ops
->set_rekey_data
) {
11536 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
11542 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
11543 struct genl_info
*info
)
11545 struct net_device
*dev
= info
->user_ptr
[1];
11546 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11548 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11549 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
11552 if (wdev
->ap_unexpected_nlportid
)
11555 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
11559 static int nl80211_probe_client(struct sk_buff
*skb
,
11560 struct genl_info
*info
)
11562 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11563 struct net_device
*dev
= info
->user_ptr
[1];
11564 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11565 struct sk_buff
*msg
;
11571 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11572 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
11573 return -EOPNOTSUPP
;
11575 if (!info
->attrs
[NL80211_ATTR_MAC
])
11578 if (!rdev
->ops
->probe_client
)
11579 return -EOPNOTSUPP
;
11581 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11585 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11586 NL80211_CMD_PROBE_CLIENT
);
11592 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11594 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
11598 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11600 goto nla_put_failure
;
11602 genlmsg_end(msg
, hdr
);
11604 return genlmsg_reply(msg
, info
);
11613 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
11615 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11616 struct cfg80211_beacon_registration
*reg
, *nreg
;
11619 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
11620 return -EOPNOTSUPP
;
11622 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
11626 /* First, check if already registered. */
11627 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11628 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
11629 if (reg
->nlportid
== info
->snd_portid
) {
11634 /* Add it to the list */
11635 nreg
->nlportid
= info
->snd_portid
;
11636 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
11638 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11642 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11647 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11649 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11650 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11653 if (!rdev
->ops
->start_p2p_device
)
11654 return -EOPNOTSUPP
;
11656 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11657 return -EOPNOTSUPP
;
11659 if (wdev_running(wdev
))
11662 if (rfkill_blocked(rdev
->rfkill
))
11665 err
= rdev_start_p2p_device(rdev
, wdev
);
11669 wdev
->is_running
= true;
11675 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11677 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11678 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11680 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11681 return -EOPNOTSUPP
;
11683 if (!rdev
->ops
->stop_p2p_device
)
11684 return -EOPNOTSUPP
;
11686 cfg80211_stop_p2p_device(rdev
, wdev
);
11691 static int nl80211_start_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11693 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11694 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11695 struct cfg80211_nan_conf conf
= {};
11698 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11699 return -EOPNOTSUPP
;
11701 if (wdev_running(wdev
))
11704 if (rfkill_blocked(rdev
->rfkill
))
11707 if (!info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
])
11711 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
11712 if (!conf
.master_pref
)
11715 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
11716 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
11718 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
11719 return -EOPNOTSUPP
;
11721 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
11724 conf
.bands
= bands
;
11727 err
= rdev_start_nan(rdev
, wdev
, &conf
);
11731 wdev
->is_running
= true;
11737 static int nl80211_stop_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11739 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11740 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11742 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11743 return -EOPNOTSUPP
;
11745 cfg80211_stop_nan(rdev
, wdev
);
11750 static int validate_nan_filter(struct nlattr
*filter_attr
)
11752 struct nlattr
*attr
;
11753 int len
= 0, n_entries
= 0, rem
;
11755 nla_for_each_nested(attr
, filter_attr
, rem
) {
11756 len
+= nla_len(attr
);
11766 static int handle_nan_filter(struct nlattr
*attr_filter
,
11767 struct cfg80211_nan_func
*func
,
11770 struct nlattr
*attr
;
11771 int n_entries
, rem
, i
;
11772 struct cfg80211_nan_func_filter
*filter
;
11774 n_entries
= validate_nan_filter(attr_filter
);
11778 BUILD_BUG_ON(sizeof(*func
->rx_filters
) != sizeof(*func
->tx_filters
));
11780 filter
= kcalloc(n_entries
, sizeof(*func
->rx_filters
), GFP_KERNEL
);
11785 nla_for_each_nested(attr
, attr_filter
, rem
) {
11786 filter
[i
].filter
= nla_memdup(attr
, GFP_KERNEL
);
11787 filter
[i
].len
= nla_len(attr
);
11791 func
->num_tx_filters
= n_entries
;
11792 func
->tx_filters
= filter
;
11794 func
->num_rx_filters
= n_entries
;
11795 func
->rx_filters
= filter
;
11801 static int nl80211_nan_add_func(struct sk_buff
*skb
,
11802 struct genl_info
*info
)
11804 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11805 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11806 struct nlattr
*tb
[NUM_NL80211_NAN_FUNC_ATTR
], *func_attr
;
11807 struct cfg80211_nan_func
*func
;
11808 struct sk_buff
*msg
= NULL
;
11812 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11813 return -EOPNOTSUPP
;
11815 if (!wdev_running(wdev
))
11818 if (!info
->attrs
[NL80211_ATTR_NAN_FUNC
])
11821 err
= nla_parse_nested(tb
, NL80211_NAN_FUNC_ATTR_MAX
,
11822 info
->attrs
[NL80211_ATTR_NAN_FUNC
],
11823 nl80211_nan_func_policy
, info
->extack
);
11827 func
= kzalloc(sizeof(*func
), GFP_KERNEL
);
11831 func
->cookie
= wdev
->wiphy
->cookie_counter
++;
11833 if (!tb
[NL80211_NAN_FUNC_TYPE
] ||
11834 nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]) > NL80211_NAN_FUNC_MAX_TYPE
) {
11840 func
->type
= nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]);
11842 if (!tb
[NL80211_NAN_FUNC_SERVICE_ID
]) {
11847 memcpy(func
->service_id
, nla_data(tb
[NL80211_NAN_FUNC_SERVICE_ID
]),
11848 sizeof(func
->service_id
));
11850 func
->close_range
=
11851 nla_get_flag(tb
[NL80211_NAN_FUNC_CLOSE_RANGE
]);
11853 if (tb
[NL80211_NAN_FUNC_SERVICE_INFO
]) {
11854 func
->serv_spec_info_len
=
11855 nla_len(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]);
11856 func
->serv_spec_info
=
11857 kmemdup(nla_data(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]),
11858 func
->serv_spec_info_len
,
11860 if (!func
->serv_spec_info
) {
11866 if (tb
[NL80211_NAN_FUNC_TTL
])
11867 func
->ttl
= nla_get_u32(tb
[NL80211_NAN_FUNC_TTL
]);
11869 switch (func
->type
) {
11870 case NL80211_NAN_FUNC_PUBLISH
:
11871 if (!tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]) {
11876 func
->publish_type
=
11877 nla_get_u8(tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]);
11878 func
->publish_bcast
=
11879 nla_get_flag(tb
[NL80211_NAN_FUNC_PUBLISH_BCAST
]);
11881 if ((!(func
->publish_type
& NL80211_NAN_SOLICITED_PUBLISH
)) &&
11882 func
->publish_bcast
) {
11887 case NL80211_NAN_FUNC_SUBSCRIBE
:
11888 func
->subscribe_active
=
11889 nla_get_flag(tb
[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
]);
11891 case NL80211_NAN_FUNC_FOLLOW_UP
:
11892 if (!tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
] ||
11893 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] ||
11894 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]) {
11899 func
->followup_id
=
11900 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
]);
11901 func
->followup_reqid
=
11902 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]);
11903 memcpy(func
->followup_dest
.addr
,
11904 nla_data(tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]),
11905 sizeof(func
->followup_dest
.addr
));
11916 if (tb
[NL80211_NAN_FUNC_SRF
]) {
11917 struct nlattr
*srf_tb
[NUM_NL80211_NAN_SRF_ATTR
];
11919 err
= nla_parse_nested(srf_tb
, NL80211_NAN_SRF_ATTR_MAX
,
11920 tb
[NL80211_NAN_FUNC_SRF
],
11921 nl80211_nan_srf_policy
, info
->extack
);
11925 func
->srf_include
=
11926 nla_get_flag(srf_tb
[NL80211_NAN_SRF_INCLUDE
]);
11928 if (srf_tb
[NL80211_NAN_SRF_BF
]) {
11929 if (srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
] ||
11930 !srf_tb
[NL80211_NAN_SRF_BF_IDX
]) {
11936 nla_len(srf_tb
[NL80211_NAN_SRF_BF
]);
11938 kmemdup(nla_data(srf_tb
[NL80211_NAN_SRF_BF
]),
11939 func
->srf_bf_len
, GFP_KERNEL
);
11940 if (!func
->srf_bf
) {
11946 nla_get_u8(srf_tb
[NL80211_NAN_SRF_BF_IDX
]);
11948 struct nlattr
*attr
, *mac_attr
=
11949 srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
];
11950 int n_entries
, rem
, i
= 0;
11957 n_entries
= validate_acl_mac_addrs(mac_attr
);
11958 if (n_entries
<= 0) {
11963 func
->srf_num_macs
= n_entries
;
11965 kcalloc(n_entries
, sizeof(*func
->srf_macs
),
11967 if (!func
->srf_macs
) {
11972 nla_for_each_nested(attr
, mac_attr
, rem
)
11973 memcpy(func
->srf_macs
[i
++].addr
, nla_data(attr
),
11974 sizeof(*func
->srf_macs
));
11978 if (tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
]) {
11979 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
],
11985 if (tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
]) {
11986 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
],
11992 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11998 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11999 NL80211_CMD_ADD_NAN_FUNCTION
);
12000 /* This can't really happen - we just allocated 4KB */
12001 if (WARN_ON(!hdr
)) {
12006 err
= rdev_add_nan_func(rdev
, wdev
, func
);
12009 cfg80211_free_nan_func(func
);
12014 /* propagate the instance id and cookie to userspace */
12015 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, func
->cookie
,
12017 goto nla_put_failure
;
12019 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
12021 goto nla_put_failure
;
12023 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
,
12024 func
->instance_id
))
12025 goto nla_put_failure
;
12027 nla_nest_end(msg
, func_attr
);
12029 genlmsg_end(msg
, hdr
);
12030 return genlmsg_reply(msg
, info
);
12037 static int nl80211_nan_del_func(struct sk_buff
*skb
,
12038 struct genl_info
*info
)
12040 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12041 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12044 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12045 return -EOPNOTSUPP
;
12047 if (!wdev_running(wdev
))
12050 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
12053 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
12055 rdev_del_nan_func(rdev
, wdev
, cookie
);
12060 static int nl80211_nan_change_config(struct sk_buff
*skb
,
12061 struct genl_info
*info
)
12063 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12064 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12065 struct cfg80211_nan_conf conf
= {};
12068 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
12069 return -EOPNOTSUPP
;
12071 if (!wdev_running(wdev
))
12074 if (info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]) {
12076 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
12077 if (conf
.master_pref
<= 1 || conf
.master_pref
== 255)
12080 changed
|= CFG80211_NAN_CONF_CHANGED_PREF
;
12083 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
12084 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
12086 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
12087 return -EOPNOTSUPP
;
12089 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
12092 conf
.bands
= bands
;
12093 changed
|= CFG80211_NAN_CONF_CHANGED_BANDS
;
12099 return rdev_nan_change_conf(rdev
, wdev
, &conf
, changed
);
12102 void cfg80211_nan_match(struct wireless_dev
*wdev
,
12103 struct cfg80211_nan_match_params
*match
, gfp_t gfp
)
12105 struct wiphy
*wiphy
= wdev
->wiphy
;
12106 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12107 struct nlattr
*match_attr
, *local_func_attr
, *peer_func_attr
;
12108 struct sk_buff
*msg
;
12111 if (WARN_ON(!match
->inst_id
|| !match
->peer_inst_id
|| !match
->addr
))
12114 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12118 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NAN_MATCH
);
12124 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12125 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12126 wdev
->netdev
->ifindex
)) ||
12127 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12129 goto nla_put_failure
;
12131 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, match
->cookie
,
12132 NL80211_ATTR_PAD
) ||
12133 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, match
->addr
))
12134 goto nla_put_failure
;
12136 match_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_MATCH
);
12138 goto nla_put_failure
;
12140 local_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_LOCAL
);
12141 if (!local_func_attr
)
12142 goto nla_put_failure
;
12144 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->inst_id
))
12145 goto nla_put_failure
;
12147 nla_nest_end(msg
, local_func_attr
);
12149 peer_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_PEER
);
12150 if (!peer_func_attr
)
12151 goto nla_put_failure
;
12153 if (nla_put_u8(msg
, NL80211_NAN_FUNC_TYPE
, match
->type
) ||
12154 nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->peer_inst_id
))
12155 goto nla_put_failure
;
12157 if (match
->info
&& match
->info_len
&&
12158 nla_put(msg
, NL80211_NAN_FUNC_SERVICE_INFO
, match
->info_len
,
12160 goto nla_put_failure
;
12162 nla_nest_end(msg
, peer_func_attr
);
12163 nla_nest_end(msg
, match_attr
);
12164 genlmsg_end(msg
, hdr
);
12166 if (!wdev
->owner_nlportid
)
12167 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
12168 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
12170 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
12171 wdev
->owner_nlportid
);
12178 EXPORT_SYMBOL(cfg80211_nan_match
);
12180 void cfg80211_nan_func_terminated(struct wireless_dev
*wdev
,
12182 enum nl80211_nan_func_term_reason reason
,
12183 u64 cookie
, gfp_t gfp
)
12185 struct wiphy
*wiphy
= wdev
->wiphy
;
12186 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12187 struct sk_buff
*msg
;
12188 struct nlattr
*func_attr
;
12191 if (WARN_ON(!inst_id
))
12194 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12198 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION
);
12204 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12205 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12206 wdev
->netdev
->ifindex
)) ||
12207 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12209 goto nla_put_failure
;
12211 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
12213 goto nla_put_failure
;
12215 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
12217 goto nla_put_failure
;
12219 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, inst_id
) ||
12220 nla_put_u8(msg
, NL80211_NAN_FUNC_TERM_REASON
, reason
))
12221 goto nla_put_failure
;
12223 nla_nest_end(msg
, func_attr
);
12224 genlmsg_end(msg
, hdr
);
12226 if (!wdev
->owner_nlportid
)
12227 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
12228 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
12230 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
12231 wdev
->owner_nlportid
);
12238 EXPORT_SYMBOL(cfg80211_nan_func_terminated
);
12240 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
12241 struct genl_info
*info
)
12244 struct sk_buff
*msg
;
12246 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12250 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
12251 NL80211_CMD_GET_PROTOCOL_FEATURES
);
12253 goto nla_put_failure
;
12255 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
12256 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
12257 goto nla_put_failure
;
12259 genlmsg_end(msg
, hdr
);
12260 return genlmsg_reply(msg
, info
);
12267 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
12269 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12270 struct cfg80211_update_ft_ies_params ft_params
;
12271 struct net_device
*dev
= info
->user_ptr
[1];
12273 if (!rdev
->ops
->update_ft_ies
)
12274 return -EOPNOTSUPP
;
12276 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
12277 !info
->attrs
[NL80211_ATTR_IE
] ||
12278 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
12281 memset(&ft_params
, 0, sizeof(ft_params
));
12282 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
12283 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
12284 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
12286 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
12289 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
12290 struct genl_info
*info
)
12292 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12293 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12294 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
12298 if (!rdev
->ops
->crit_proto_start
)
12299 return -EOPNOTSUPP
;
12301 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
12304 if (rdev
->crit_proto_nlportid
)
12307 /* determine protocol if provided */
12308 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
12309 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
12311 if (proto
>= NUM_NL80211_CRIT_PROTO
)
12314 /* timeout must be provided */
12315 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
12319 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
12321 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
12324 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
12326 rdev
->crit_proto_nlportid
= info
->snd_portid
;
12331 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
12332 struct genl_info
*info
)
12334 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12335 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12337 if (!rdev
->ops
->crit_proto_stop
)
12338 return -EOPNOTSUPP
;
12340 if (rdev
->crit_proto_nlportid
) {
12341 rdev
->crit_proto_nlportid
= 0;
12342 rdev_crit_proto_stop(rdev
, wdev
);
12347 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
12349 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12350 struct wireless_dev
*wdev
=
12351 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
12355 if (!rdev
->wiphy
.vendor_commands
)
12356 return -EOPNOTSUPP
;
12358 if (IS_ERR(wdev
)) {
12359 err
= PTR_ERR(wdev
);
12360 if (err
!= -EINVAL
)
12363 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
12367 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
12368 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
12371 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
12372 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
12373 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
12374 const struct wiphy_vendor_command
*vcmd
;
12378 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
12380 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
12383 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
12384 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
12387 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
12391 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
12392 if (!wdev_running(wdev
))
12397 return -EOPNOTSUPP
;
12402 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
12403 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
12404 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
12407 rdev
->cur_cmd_info
= info
;
12408 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
12410 rdev
->cur_cmd_info
= NULL
;
12414 return -EOPNOTSUPP
;
12417 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
12418 struct netlink_callback
*cb
,
12419 struct cfg80211_registered_device
**rdev
,
12420 struct wireless_dev
**wdev
)
12422 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
12428 unsigned int data_len
= 0;
12431 /* subtract the 1 again here */
12432 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
12433 struct wireless_dev
*tmp
;
12437 *rdev
= wiphy_to_rdev(wiphy
);
12441 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
12442 if (tmp
->identifier
== cb
->args
[1] - 1) {
12449 /* keep rtnl locked in successful case */
12453 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, attrbuf
,
12454 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
12458 if (!attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
12459 !attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
])
12462 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
12466 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
12468 return PTR_ERR(*rdev
);
12470 vid
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_ID
]);
12471 subcmd
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
12473 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
12474 const struct wiphy_vendor_command
*vcmd
;
12476 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
12478 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
12482 return -EOPNOTSUPP
;
12489 return -EOPNOTSUPP
;
12491 if (attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
12492 data
= nla_data(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
12493 data_len
= nla_len(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
12496 /* 0 is the first index - add 1 to parse only once */
12497 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
12498 /* add 1 to know if it was NULL */
12499 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
12500 cb
->args
[2] = vcmd_idx
;
12501 cb
->args
[3] = (unsigned long)data
;
12502 cb
->args
[4] = data_len
;
12504 /* keep rtnl locked in successful case */
12508 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
12509 struct netlink_callback
*cb
)
12511 struct cfg80211_registered_device
*rdev
;
12512 struct wireless_dev
*wdev
;
12513 unsigned int vcmd_idx
;
12514 const struct wiphy_vendor_command
*vcmd
;
12518 struct nlattr
*vendor_data
;
12521 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
12525 vcmd_idx
= cb
->args
[2];
12526 data
= (void *)cb
->args
[3];
12527 data_len
= cb
->args
[4];
12528 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
12530 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
12531 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
12536 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
12542 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
12543 if (!wdev_running(wdev
)) {
12551 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
12552 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
12553 NL80211_CMD_VENDOR
);
12557 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12558 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
12560 NL80211_ATTR_PAD
))) {
12561 genlmsg_cancel(skb
, hdr
);
12565 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
12566 if (!vendor_data
) {
12567 genlmsg_cancel(skb
, hdr
);
12571 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
12572 (unsigned long *)&cb
->args
[5]);
12573 nla_nest_end(skb
, vendor_data
);
12575 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
12576 genlmsg_cancel(skb
, hdr
);
12579 genlmsg_cancel(skb
, hdr
);
12583 genlmsg_end(skb
, hdr
);
12592 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
12593 enum nl80211_commands cmd
,
12594 enum nl80211_attrs attr
,
12597 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12599 if (WARN_ON(!rdev
->cur_cmd_info
))
12602 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
12603 rdev
->cur_cmd_info
->snd_portid
,
12604 rdev
->cur_cmd_info
->snd_seq
,
12605 cmd
, attr
, NULL
, GFP_KERNEL
);
12607 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
12609 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
12611 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
12612 void *hdr
= ((void **)skb
->cb
)[1];
12613 struct nlattr
*data
= ((void **)skb
->cb
)[2];
12615 /* clear CB data for netlink core to own from now on */
12616 memset(skb
->cb
, 0, sizeof(skb
->cb
));
12618 if (WARN_ON(!rdev
->cur_cmd_info
)) {
12623 nla_nest_end(skb
, data
);
12624 genlmsg_end(skb
, hdr
);
12625 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
12627 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
12629 static int nl80211_set_qos_map(struct sk_buff
*skb
,
12630 struct genl_info
*info
)
12632 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12633 struct cfg80211_qos_map
*qos_map
= NULL
;
12634 struct net_device
*dev
= info
->user_ptr
[1];
12635 u8
*pos
, len
, num_des
, des_len
, des
;
12638 if (!rdev
->ops
->set_qos_map
)
12639 return -EOPNOTSUPP
;
12641 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
12642 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12643 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12645 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
12646 len
> IEEE80211_QOS_MAP_LEN_MAX
)
12649 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
12653 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
12655 des_len
= num_des
*
12656 sizeof(struct cfg80211_dscp_exception
);
12657 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
12658 qos_map
->num_des
= num_des
;
12659 for (des
= 0; des
< num_des
; des
++) {
12660 if (qos_map
->dscp_exception
[des
].up
> 7) {
12667 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
12670 wdev_lock(dev
->ieee80211_ptr
);
12671 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
12673 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
12674 wdev_unlock(dev
->ieee80211_ptr
);
12680 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12682 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12683 struct net_device
*dev
= info
->user_ptr
[1];
12684 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12687 u16 admitted_time
= 0;
12690 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
12691 return -EOPNOTSUPP
;
12693 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
12694 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
12697 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12698 if (tsid
>= IEEE80211_NUM_TIDS
)
12701 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
12702 if (up
>= IEEE80211_NUM_UPS
)
12705 /* WMM uses TIDs 0-7 even for TSPEC */
12706 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
12707 /* TODO: handle 802.11 TSPEC/admission control
12708 * need more attributes for that (e.g. BA session requirement);
12709 * change the WMM adminssion test above to allow both then
12714 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12716 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
12718 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
12719 if (!admitted_time
)
12724 switch (wdev
->iftype
) {
12725 case NL80211_IFTYPE_STATION
:
12726 case NL80211_IFTYPE_P2P_CLIENT
:
12727 if (wdev
->current_bss
)
12736 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
12743 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12745 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12746 struct net_device
*dev
= info
->user_ptr
[1];
12747 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12752 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
12755 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12756 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12759 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
12765 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
12766 struct genl_info
*info
)
12768 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12769 struct net_device
*dev
= info
->user_ptr
[1];
12770 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12771 struct cfg80211_chan_def chandef
= {};
12776 if (!rdev
->ops
->tdls_channel_switch
||
12777 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12778 return -EOPNOTSUPP
;
12780 switch (dev
->ieee80211_ptr
->iftype
) {
12781 case NL80211_IFTYPE_STATION
:
12782 case NL80211_IFTYPE_P2P_CLIENT
:
12785 return -EOPNOTSUPP
;
12788 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
12789 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
12792 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
12797 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12798 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12799 * specification is not defined for them.
12801 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
12802 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
12803 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
12806 /* we will be active on the TDLS link */
12807 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
12811 /* don't allow switching to DFS channels */
12812 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
12815 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12816 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
12819 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
12825 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
12826 struct genl_info
*info
)
12828 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12829 struct net_device
*dev
= info
->user_ptr
[1];
12830 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12833 if (!rdev
->ops
->tdls_channel_switch
||
12834 !rdev
->ops
->tdls_cancel_channel_switch
||
12835 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12836 return -EOPNOTSUPP
;
12838 switch (dev
->ieee80211_ptr
->iftype
) {
12839 case NL80211_IFTYPE_STATION
:
12840 case NL80211_IFTYPE_P2P_CLIENT
:
12843 return -EOPNOTSUPP
;
12846 if (!info
->attrs
[NL80211_ATTR_MAC
])
12849 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12852 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
12858 static int nl80211_set_multicast_to_unicast(struct sk_buff
*skb
,
12859 struct genl_info
*info
)
12861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12862 struct net_device
*dev
= info
->user_ptr
[1];
12863 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12864 const struct nlattr
*nla
;
12867 if (!rdev
->ops
->set_multicast_to_unicast
)
12868 return -EOPNOTSUPP
;
12870 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12871 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12872 return -EOPNOTSUPP
;
12874 nla
= info
->attrs
[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
];
12875 enabled
= nla_get_flag(nla
);
12877 return rdev_set_multicast_to_unicast(rdev
, dev
, enabled
);
12880 static int nl80211_set_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12882 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12883 struct net_device
*dev
= info
->user_ptr
[1];
12884 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12885 struct cfg80211_pmk_conf pmk_conf
= {};
12888 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12889 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12890 return -EOPNOTSUPP
;
12892 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12893 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12894 return -EOPNOTSUPP
;
12896 if (!info
->attrs
[NL80211_ATTR_MAC
] || !info
->attrs
[NL80211_ATTR_PMK
])
12900 if (!wdev
->current_bss
) {
12905 pmk_conf
.aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12906 if (memcmp(pmk_conf
.aa
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
)) {
12911 pmk_conf
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
12912 pmk_conf
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
12913 if (pmk_conf
.pmk_len
!= WLAN_PMK_LEN
&&
12914 pmk_conf
.pmk_len
!= WLAN_PMK_LEN_SUITE_B_192
) {
12919 if (info
->attrs
[NL80211_ATTR_PMKR0_NAME
]) {
12920 int r0_name_len
= nla_len(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12922 if (r0_name_len
!= WLAN_PMK_NAME_LEN
) {
12927 pmk_conf
.pmk_r0_name
=
12928 nla_data(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12931 ret
= rdev_set_pmk(rdev
, dev
, &pmk_conf
);
12937 static int nl80211_del_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12939 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12940 struct net_device
*dev
= info
->user_ptr
[1];
12941 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12945 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12946 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12947 return -EOPNOTSUPP
;
12949 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12950 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12951 return -EOPNOTSUPP
;
12953 if (!info
->attrs
[NL80211_ATTR_MAC
])
12957 aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12958 ret
= rdev_del_pmk(rdev
, dev
, aa
);
12964 static int nl80211_external_auth(struct sk_buff
*skb
, struct genl_info
*info
)
12966 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12967 struct net_device
*dev
= info
->user_ptr
[1];
12968 struct cfg80211_external_auth_params params
;
12970 if (!rdev
->ops
->external_auth
)
12971 return -EOPNOTSUPP
;
12973 if (!info
->attrs
[NL80211_ATTR_SSID
])
12976 if (!info
->attrs
[NL80211_ATTR_BSSID
])
12979 if (!info
->attrs
[NL80211_ATTR_STATUS_CODE
])
12982 memset(¶ms
, 0, sizeof(params
));
12984 params
.ssid
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
12985 if (params
.ssid
.ssid_len
== 0 ||
12986 params
.ssid
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
12988 memcpy(params
.ssid
.ssid
, nla_data(info
->attrs
[NL80211_ATTR_SSID
]),
12989 params
.ssid
.ssid_len
);
12991 memcpy(params
.bssid
, nla_data(info
->attrs
[NL80211_ATTR_BSSID
]),
12994 params
.status
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
12996 return rdev_external_auth(rdev
, dev
, ¶ms
);
12999 static int nl80211_tx_control_port(struct sk_buff
*skb
, struct genl_info
*info
)
13001 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
13002 struct net_device
*dev
= info
->user_ptr
[1];
13003 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13011 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
13012 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211
))
13013 return -EOPNOTSUPP
;
13015 if (!rdev
->ops
->tx_control_port
)
13016 return -EOPNOTSUPP
;
13018 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
13019 !info
->attrs
[NL80211_ATTR_MAC
] ||
13020 !info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
13021 GENL_SET_ERR_MSG(info
, "Frame, MAC or ethertype missing");
13027 switch (wdev
->iftype
) {
13028 case NL80211_IFTYPE_AP
:
13029 case NL80211_IFTYPE_P2P_GO
:
13030 case NL80211_IFTYPE_MESH_POINT
:
13032 case NL80211_IFTYPE_ADHOC
:
13033 case NL80211_IFTYPE_STATION
:
13034 case NL80211_IFTYPE_P2P_CLIENT
:
13035 if (wdev
->current_bss
)
13046 buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
13047 len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
13048 dest
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
13049 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
13051 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
]);
13053 return rdev_tx_control_port(rdev
, dev
, buf
, len
,
13054 dest
, cpu_to_be16(proto
), noencrypt
);
13061 #define NL80211_FLAG_NEED_WIPHY 0x01
13062 #define NL80211_FLAG_NEED_NETDEV 0x02
13063 #define NL80211_FLAG_NEED_RTNL 0x04
13064 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
13065 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
13066 NL80211_FLAG_CHECK_NETDEV_UP)
13067 #define NL80211_FLAG_NEED_WDEV 0x10
13068 /* If a netdev is associated, it must be UP, P2P must be started */
13069 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
13070 NL80211_FLAG_CHECK_NETDEV_UP)
13071 #define NL80211_FLAG_CLEAR_SKB 0x20
13073 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
13074 struct genl_info
*info
)
13076 struct cfg80211_registered_device
*rdev
;
13077 struct wireless_dev
*wdev
;
13078 struct net_device
*dev
;
13079 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
13084 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
13085 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
13086 if (IS_ERR(rdev
)) {
13089 return PTR_ERR(rdev
);
13091 info
->user_ptr
[0] = rdev
;
13092 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
13093 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
13096 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
13098 if (IS_ERR(wdev
)) {
13101 return PTR_ERR(wdev
);
13104 dev
= wdev
->netdev
;
13105 rdev
= wiphy_to_rdev(wdev
->wiphy
);
13107 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
13114 info
->user_ptr
[1] = dev
;
13116 info
->user_ptr
[1] = wdev
;
13119 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
13120 !wdev_running(wdev
)) {
13129 info
->user_ptr
[0] = rdev
;
13135 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
13136 struct genl_info
*info
)
13138 if (info
->user_ptr
[1]) {
13139 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
13140 struct wireless_dev
*wdev
= info
->user_ptr
[1];
13143 dev_put(wdev
->netdev
);
13145 dev_put(info
->user_ptr
[1]);
13149 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
13152 /* If needed, clear the netlink message payload from the SKB
13153 * as it might contain key data that shouldn't stick around on
13154 * the heap after the SKB is freed. The netlink message header
13155 * is still needed for further processing, so leave it intact.
13157 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
13158 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
13160 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
13164 static const struct genl_ops nl80211_ops
[] = {
13166 .cmd
= NL80211_CMD_GET_WIPHY
,
13167 .doit
= nl80211_get_wiphy
,
13168 .dumpit
= nl80211_dump_wiphy
,
13169 .done
= nl80211_dump_wiphy_done
,
13170 .policy
= nl80211_policy
,
13171 /* can be retrieved by unprivileged users */
13172 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13173 NL80211_FLAG_NEED_RTNL
,
13176 .cmd
= NL80211_CMD_SET_WIPHY
,
13177 .doit
= nl80211_set_wiphy
,
13178 .policy
= nl80211_policy
,
13179 .flags
= GENL_UNS_ADMIN_PERM
,
13180 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
13183 .cmd
= NL80211_CMD_GET_INTERFACE
,
13184 .doit
= nl80211_get_interface
,
13185 .dumpit
= nl80211_dump_interface
,
13186 .policy
= nl80211_policy
,
13187 /* can be retrieved by unprivileged users */
13188 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13189 NL80211_FLAG_NEED_RTNL
,
13192 .cmd
= NL80211_CMD_SET_INTERFACE
,
13193 .doit
= nl80211_set_interface
,
13194 .policy
= nl80211_policy
,
13195 .flags
= GENL_UNS_ADMIN_PERM
,
13196 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13197 NL80211_FLAG_NEED_RTNL
,
13200 .cmd
= NL80211_CMD_NEW_INTERFACE
,
13201 .doit
= nl80211_new_interface
,
13202 .policy
= nl80211_policy
,
13203 .flags
= GENL_UNS_ADMIN_PERM
,
13204 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13205 NL80211_FLAG_NEED_RTNL
,
13208 .cmd
= NL80211_CMD_DEL_INTERFACE
,
13209 .doit
= nl80211_del_interface
,
13210 .policy
= nl80211_policy
,
13211 .flags
= GENL_UNS_ADMIN_PERM
,
13212 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13213 NL80211_FLAG_NEED_RTNL
,
13216 .cmd
= NL80211_CMD_GET_KEY
,
13217 .doit
= nl80211_get_key
,
13218 .policy
= nl80211_policy
,
13219 .flags
= GENL_UNS_ADMIN_PERM
,
13220 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13221 NL80211_FLAG_NEED_RTNL
,
13224 .cmd
= NL80211_CMD_SET_KEY
,
13225 .doit
= nl80211_set_key
,
13226 .policy
= nl80211_policy
,
13227 .flags
= GENL_UNS_ADMIN_PERM
,
13228 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13229 NL80211_FLAG_NEED_RTNL
|
13230 NL80211_FLAG_CLEAR_SKB
,
13233 .cmd
= NL80211_CMD_NEW_KEY
,
13234 .doit
= nl80211_new_key
,
13235 .policy
= nl80211_policy
,
13236 .flags
= GENL_UNS_ADMIN_PERM
,
13237 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13238 NL80211_FLAG_NEED_RTNL
|
13239 NL80211_FLAG_CLEAR_SKB
,
13242 .cmd
= NL80211_CMD_DEL_KEY
,
13243 .doit
= nl80211_del_key
,
13244 .policy
= nl80211_policy
,
13245 .flags
= GENL_UNS_ADMIN_PERM
,
13246 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13247 NL80211_FLAG_NEED_RTNL
,
13250 .cmd
= NL80211_CMD_SET_BEACON
,
13251 .policy
= nl80211_policy
,
13252 .flags
= GENL_UNS_ADMIN_PERM
,
13253 .doit
= nl80211_set_beacon
,
13254 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13255 NL80211_FLAG_NEED_RTNL
,
13258 .cmd
= NL80211_CMD_START_AP
,
13259 .policy
= nl80211_policy
,
13260 .flags
= GENL_UNS_ADMIN_PERM
,
13261 .doit
= nl80211_start_ap
,
13262 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13263 NL80211_FLAG_NEED_RTNL
,
13266 .cmd
= NL80211_CMD_STOP_AP
,
13267 .policy
= nl80211_policy
,
13268 .flags
= GENL_UNS_ADMIN_PERM
,
13269 .doit
= nl80211_stop_ap
,
13270 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13271 NL80211_FLAG_NEED_RTNL
,
13274 .cmd
= NL80211_CMD_GET_STATION
,
13275 .doit
= nl80211_get_station
,
13276 .dumpit
= nl80211_dump_station
,
13277 .policy
= nl80211_policy
,
13278 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13279 NL80211_FLAG_NEED_RTNL
,
13282 .cmd
= NL80211_CMD_SET_STATION
,
13283 .doit
= nl80211_set_station
,
13284 .policy
= nl80211_policy
,
13285 .flags
= GENL_UNS_ADMIN_PERM
,
13286 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13287 NL80211_FLAG_NEED_RTNL
,
13290 .cmd
= NL80211_CMD_NEW_STATION
,
13291 .doit
= nl80211_new_station
,
13292 .policy
= nl80211_policy
,
13293 .flags
= GENL_UNS_ADMIN_PERM
,
13294 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13295 NL80211_FLAG_NEED_RTNL
,
13298 .cmd
= NL80211_CMD_DEL_STATION
,
13299 .doit
= nl80211_del_station
,
13300 .policy
= nl80211_policy
,
13301 .flags
= GENL_UNS_ADMIN_PERM
,
13302 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13303 NL80211_FLAG_NEED_RTNL
,
13306 .cmd
= NL80211_CMD_GET_MPATH
,
13307 .doit
= nl80211_get_mpath
,
13308 .dumpit
= nl80211_dump_mpath
,
13309 .policy
= nl80211_policy
,
13310 .flags
= GENL_UNS_ADMIN_PERM
,
13311 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13312 NL80211_FLAG_NEED_RTNL
,
13315 .cmd
= NL80211_CMD_GET_MPP
,
13316 .doit
= nl80211_get_mpp
,
13317 .dumpit
= nl80211_dump_mpp
,
13318 .policy
= nl80211_policy
,
13319 .flags
= GENL_UNS_ADMIN_PERM
,
13320 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13321 NL80211_FLAG_NEED_RTNL
,
13324 .cmd
= NL80211_CMD_SET_MPATH
,
13325 .doit
= nl80211_set_mpath
,
13326 .policy
= nl80211_policy
,
13327 .flags
= GENL_UNS_ADMIN_PERM
,
13328 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13329 NL80211_FLAG_NEED_RTNL
,
13332 .cmd
= NL80211_CMD_NEW_MPATH
,
13333 .doit
= nl80211_new_mpath
,
13334 .policy
= nl80211_policy
,
13335 .flags
= GENL_UNS_ADMIN_PERM
,
13336 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13337 NL80211_FLAG_NEED_RTNL
,
13340 .cmd
= NL80211_CMD_DEL_MPATH
,
13341 .doit
= nl80211_del_mpath
,
13342 .policy
= nl80211_policy
,
13343 .flags
= GENL_UNS_ADMIN_PERM
,
13344 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13345 NL80211_FLAG_NEED_RTNL
,
13348 .cmd
= NL80211_CMD_SET_BSS
,
13349 .doit
= nl80211_set_bss
,
13350 .policy
= nl80211_policy
,
13351 .flags
= GENL_UNS_ADMIN_PERM
,
13352 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13353 NL80211_FLAG_NEED_RTNL
,
13356 .cmd
= NL80211_CMD_GET_REG
,
13357 .doit
= nl80211_get_reg_do
,
13358 .dumpit
= nl80211_get_reg_dump
,
13359 .policy
= nl80211_policy
,
13360 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
13361 /* can be retrieved by unprivileged users */
13363 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
13365 .cmd
= NL80211_CMD_SET_REG
,
13366 .doit
= nl80211_set_reg
,
13367 .policy
= nl80211_policy
,
13368 .flags
= GENL_ADMIN_PERM
,
13369 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
13373 .cmd
= NL80211_CMD_REQ_SET_REG
,
13374 .doit
= nl80211_req_set_reg
,
13375 .policy
= nl80211_policy
,
13376 .flags
= GENL_ADMIN_PERM
,
13379 .cmd
= NL80211_CMD_RELOAD_REGDB
,
13380 .doit
= nl80211_reload_regdb
,
13381 .policy
= nl80211_policy
,
13382 .flags
= GENL_ADMIN_PERM
,
13385 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
13386 .doit
= nl80211_get_mesh_config
,
13387 .policy
= nl80211_policy
,
13388 /* can be retrieved by unprivileged users */
13389 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13390 NL80211_FLAG_NEED_RTNL
,
13393 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
13394 .doit
= nl80211_update_mesh_config
,
13395 .policy
= nl80211_policy
,
13396 .flags
= GENL_UNS_ADMIN_PERM
,
13397 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13398 NL80211_FLAG_NEED_RTNL
,
13401 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
13402 .doit
= nl80211_trigger_scan
,
13403 .policy
= nl80211_policy
,
13404 .flags
= GENL_UNS_ADMIN_PERM
,
13405 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13406 NL80211_FLAG_NEED_RTNL
,
13409 .cmd
= NL80211_CMD_ABORT_SCAN
,
13410 .doit
= nl80211_abort_scan
,
13411 .policy
= nl80211_policy
,
13412 .flags
= GENL_UNS_ADMIN_PERM
,
13413 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13414 NL80211_FLAG_NEED_RTNL
,
13417 .cmd
= NL80211_CMD_GET_SCAN
,
13418 .policy
= nl80211_policy
,
13419 .dumpit
= nl80211_dump_scan
,
13422 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
13423 .doit
= nl80211_start_sched_scan
,
13424 .policy
= nl80211_policy
,
13425 .flags
= GENL_UNS_ADMIN_PERM
,
13426 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13427 NL80211_FLAG_NEED_RTNL
,
13430 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
13431 .doit
= nl80211_stop_sched_scan
,
13432 .policy
= nl80211_policy
,
13433 .flags
= GENL_UNS_ADMIN_PERM
,
13434 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13435 NL80211_FLAG_NEED_RTNL
,
13438 .cmd
= NL80211_CMD_AUTHENTICATE
,
13439 .doit
= nl80211_authenticate
,
13440 .policy
= nl80211_policy
,
13441 .flags
= GENL_UNS_ADMIN_PERM
,
13442 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13443 NL80211_FLAG_NEED_RTNL
|
13444 NL80211_FLAG_CLEAR_SKB
,
13447 .cmd
= NL80211_CMD_ASSOCIATE
,
13448 .doit
= nl80211_associate
,
13449 .policy
= nl80211_policy
,
13450 .flags
= GENL_UNS_ADMIN_PERM
,
13451 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13452 NL80211_FLAG_NEED_RTNL
|
13453 NL80211_FLAG_CLEAR_SKB
,
13456 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
13457 .doit
= nl80211_deauthenticate
,
13458 .policy
= nl80211_policy
,
13459 .flags
= GENL_UNS_ADMIN_PERM
,
13460 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13461 NL80211_FLAG_NEED_RTNL
,
13464 .cmd
= NL80211_CMD_DISASSOCIATE
,
13465 .doit
= nl80211_disassociate
,
13466 .policy
= nl80211_policy
,
13467 .flags
= GENL_UNS_ADMIN_PERM
,
13468 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13469 NL80211_FLAG_NEED_RTNL
,
13472 .cmd
= NL80211_CMD_JOIN_IBSS
,
13473 .doit
= nl80211_join_ibss
,
13474 .policy
= nl80211_policy
,
13475 .flags
= GENL_UNS_ADMIN_PERM
,
13476 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13477 NL80211_FLAG_NEED_RTNL
,
13480 .cmd
= NL80211_CMD_LEAVE_IBSS
,
13481 .doit
= nl80211_leave_ibss
,
13482 .policy
= nl80211_policy
,
13483 .flags
= GENL_UNS_ADMIN_PERM
,
13484 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13485 NL80211_FLAG_NEED_RTNL
,
13487 #ifdef CONFIG_NL80211_TESTMODE
13489 .cmd
= NL80211_CMD_TESTMODE
,
13490 .doit
= nl80211_testmode_do
,
13491 .dumpit
= nl80211_testmode_dump
,
13492 .policy
= nl80211_policy
,
13493 .flags
= GENL_UNS_ADMIN_PERM
,
13494 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13495 NL80211_FLAG_NEED_RTNL
,
13499 .cmd
= NL80211_CMD_CONNECT
,
13500 .doit
= nl80211_connect
,
13501 .policy
= nl80211_policy
,
13502 .flags
= GENL_UNS_ADMIN_PERM
,
13503 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13504 NL80211_FLAG_NEED_RTNL
|
13505 NL80211_FLAG_CLEAR_SKB
,
13508 .cmd
= NL80211_CMD_UPDATE_CONNECT_PARAMS
,
13509 .doit
= nl80211_update_connect_params
,
13510 .policy
= nl80211_policy
,
13511 .flags
= GENL_ADMIN_PERM
,
13512 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13513 NL80211_FLAG_NEED_RTNL
|
13514 NL80211_FLAG_CLEAR_SKB
,
13517 .cmd
= NL80211_CMD_DISCONNECT
,
13518 .doit
= nl80211_disconnect
,
13519 .policy
= nl80211_policy
,
13520 .flags
= GENL_UNS_ADMIN_PERM
,
13521 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13522 NL80211_FLAG_NEED_RTNL
,
13525 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
13526 .doit
= nl80211_wiphy_netns
,
13527 .policy
= nl80211_policy
,
13528 .flags
= GENL_UNS_ADMIN_PERM
,
13529 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13530 NL80211_FLAG_NEED_RTNL
,
13533 .cmd
= NL80211_CMD_GET_SURVEY
,
13534 .policy
= nl80211_policy
,
13535 .dumpit
= nl80211_dump_survey
,
13538 .cmd
= NL80211_CMD_SET_PMKSA
,
13539 .doit
= nl80211_setdel_pmksa
,
13540 .policy
= nl80211_policy
,
13541 .flags
= GENL_UNS_ADMIN_PERM
,
13542 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13543 NL80211_FLAG_NEED_RTNL
|
13544 NL80211_FLAG_CLEAR_SKB
,
13547 .cmd
= NL80211_CMD_DEL_PMKSA
,
13548 .doit
= nl80211_setdel_pmksa
,
13549 .policy
= nl80211_policy
,
13550 .flags
= GENL_UNS_ADMIN_PERM
,
13551 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13552 NL80211_FLAG_NEED_RTNL
,
13555 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
13556 .doit
= nl80211_flush_pmksa
,
13557 .policy
= nl80211_policy
,
13558 .flags
= GENL_UNS_ADMIN_PERM
,
13559 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13560 NL80211_FLAG_NEED_RTNL
,
13563 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
13564 .doit
= nl80211_remain_on_channel
,
13565 .policy
= nl80211_policy
,
13566 .flags
= GENL_UNS_ADMIN_PERM
,
13567 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13568 NL80211_FLAG_NEED_RTNL
,
13571 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
13572 .doit
= nl80211_cancel_remain_on_channel
,
13573 .policy
= nl80211_policy
,
13574 .flags
= GENL_UNS_ADMIN_PERM
,
13575 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13576 NL80211_FLAG_NEED_RTNL
,
13579 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
13580 .doit
= nl80211_set_tx_bitrate_mask
,
13581 .policy
= nl80211_policy
,
13582 .flags
= GENL_UNS_ADMIN_PERM
,
13583 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13584 NL80211_FLAG_NEED_RTNL
,
13587 .cmd
= NL80211_CMD_REGISTER_FRAME
,
13588 .doit
= nl80211_register_mgmt
,
13589 .policy
= nl80211_policy
,
13590 .flags
= GENL_UNS_ADMIN_PERM
,
13591 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13592 NL80211_FLAG_NEED_RTNL
,
13595 .cmd
= NL80211_CMD_FRAME
,
13596 .doit
= nl80211_tx_mgmt
,
13597 .policy
= nl80211_policy
,
13598 .flags
= GENL_UNS_ADMIN_PERM
,
13599 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13600 NL80211_FLAG_NEED_RTNL
,
13603 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
13604 .doit
= nl80211_tx_mgmt_cancel_wait
,
13605 .policy
= nl80211_policy
,
13606 .flags
= GENL_UNS_ADMIN_PERM
,
13607 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13608 NL80211_FLAG_NEED_RTNL
,
13611 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
13612 .doit
= nl80211_set_power_save
,
13613 .policy
= nl80211_policy
,
13614 .flags
= GENL_UNS_ADMIN_PERM
,
13615 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13616 NL80211_FLAG_NEED_RTNL
,
13619 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
13620 .doit
= nl80211_get_power_save
,
13621 .policy
= nl80211_policy
,
13622 /* can be retrieved by unprivileged users */
13623 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13624 NL80211_FLAG_NEED_RTNL
,
13627 .cmd
= NL80211_CMD_SET_CQM
,
13628 .doit
= nl80211_set_cqm
,
13629 .policy
= nl80211_policy
,
13630 .flags
= GENL_UNS_ADMIN_PERM
,
13631 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13632 NL80211_FLAG_NEED_RTNL
,
13635 .cmd
= NL80211_CMD_SET_CHANNEL
,
13636 .doit
= nl80211_set_channel
,
13637 .policy
= nl80211_policy
,
13638 .flags
= GENL_UNS_ADMIN_PERM
,
13639 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13640 NL80211_FLAG_NEED_RTNL
,
13643 .cmd
= NL80211_CMD_SET_WDS_PEER
,
13644 .doit
= nl80211_set_wds_peer
,
13645 .policy
= nl80211_policy
,
13646 .flags
= GENL_UNS_ADMIN_PERM
,
13647 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13648 NL80211_FLAG_NEED_RTNL
,
13651 .cmd
= NL80211_CMD_JOIN_MESH
,
13652 .doit
= nl80211_join_mesh
,
13653 .policy
= nl80211_policy
,
13654 .flags
= GENL_UNS_ADMIN_PERM
,
13655 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13656 NL80211_FLAG_NEED_RTNL
,
13659 .cmd
= NL80211_CMD_LEAVE_MESH
,
13660 .doit
= nl80211_leave_mesh
,
13661 .policy
= nl80211_policy
,
13662 .flags
= GENL_UNS_ADMIN_PERM
,
13663 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13664 NL80211_FLAG_NEED_RTNL
,
13667 .cmd
= NL80211_CMD_JOIN_OCB
,
13668 .doit
= nl80211_join_ocb
,
13669 .policy
= nl80211_policy
,
13670 .flags
= GENL_UNS_ADMIN_PERM
,
13671 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13672 NL80211_FLAG_NEED_RTNL
,
13675 .cmd
= NL80211_CMD_LEAVE_OCB
,
13676 .doit
= nl80211_leave_ocb
,
13677 .policy
= nl80211_policy
,
13678 .flags
= GENL_UNS_ADMIN_PERM
,
13679 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13680 NL80211_FLAG_NEED_RTNL
,
13684 .cmd
= NL80211_CMD_GET_WOWLAN
,
13685 .doit
= nl80211_get_wowlan
,
13686 .policy
= nl80211_policy
,
13687 /* can be retrieved by unprivileged users */
13688 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13689 NL80211_FLAG_NEED_RTNL
,
13692 .cmd
= NL80211_CMD_SET_WOWLAN
,
13693 .doit
= nl80211_set_wowlan
,
13694 .policy
= nl80211_policy
,
13695 .flags
= GENL_UNS_ADMIN_PERM
,
13696 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13697 NL80211_FLAG_NEED_RTNL
,
13701 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
13702 .doit
= nl80211_set_rekey_data
,
13703 .policy
= nl80211_policy
,
13704 .flags
= GENL_UNS_ADMIN_PERM
,
13705 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13706 NL80211_FLAG_NEED_RTNL
|
13707 NL80211_FLAG_CLEAR_SKB
,
13710 .cmd
= NL80211_CMD_TDLS_MGMT
,
13711 .doit
= nl80211_tdls_mgmt
,
13712 .policy
= nl80211_policy
,
13713 .flags
= GENL_UNS_ADMIN_PERM
,
13714 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13715 NL80211_FLAG_NEED_RTNL
,
13718 .cmd
= NL80211_CMD_TDLS_OPER
,
13719 .doit
= nl80211_tdls_oper
,
13720 .policy
= nl80211_policy
,
13721 .flags
= GENL_UNS_ADMIN_PERM
,
13722 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13723 NL80211_FLAG_NEED_RTNL
,
13726 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
13727 .doit
= nl80211_register_unexpected_frame
,
13728 .policy
= nl80211_policy
,
13729 .flags
= GENL_UNS_ADMIN_PERM
,
13730 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13731 NL80211_FLAG_NEED_RTNL
,
13734 .cmd
= NL80211_CMD_PROBE_CLIENT
,
13735 .doit
= nl80211_probe_client
,
13736 .policy
= nl80211_policy
,
13737 .flags
= GENL_UNS_ADMIN_PERM
,
13738 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13739 NL80211_FLAG_NEED_RTNL
,
13742 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
13743 .doit
= nl80211_register_beacons
,
13744 .policy
= nl80211_policy
,
13745 .flags
= GENL_UNS_ADMIN_PERM
,
13746 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13747 NL80211_FLAG_NEED_RTNL
,
13750 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
13751 .doit
= nl80211_set_noack_map
,
13752 .policy
= nl80211_policy
,
13753 .flags
= GENL_UNS_ADMIN_PERM
,
13754 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13755 NL80211_FLAG_NEED_RTNL
,
13758 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
13759 .doit
= nl80211_start_p2p_device
,
13760 .policy
= nl80211_policy
,
13761 .flags
= GENL_UNS_ADMIN_PERM
,
13762 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13763 NL80211_FLAG_NEED_RTNL
,
13766 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
13767 .doit
= nl80211_stop_p2p_device
,
13768 .policy
= nl80211_policy
,
13769 .flags
= GENL_UNS_ADMIN_PERM
,
13770 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13771 NL80211_FLAG_NEED_RTNL
,
13774 .cmd
= NL80211_CMD_START_NAN
,
13775 .doit
= nl80211_start_nan
,
13776 .policy
= nl80211_policy
,
13777 .flags
= GENL_ADMIN_PERM
,
13778 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13779 NL80211_FLAG_NEED_RTNL
,
13782 .cmd
= NL80211_CMD_STOP_NAN
,
13783 .doit
= nl80211_stop_nan
,
13784 .policy
= nl80211_policy
,
13785 .flags
= GENL_ADMIN_PERM
,
13786 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13787 NL80211_FLAG_NEED_RTNL
,
13790 .cmd
= NL80211_CMD_ADD_NAN_FUNCTION
,
13791 .doit
= nl80211_nan_add_func
,
13792 .policy
= nl80211_policy
,
13793 .flags
= GENL_ADMIN_PERM
,
13794 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13795 NL80211_FLAG_NEED_RTNL
,
13798 .cmd
= NL80211_CMD_DEL_NAN_FUNCTION
,
13799 .doit
= nl80211_nan_del_func
,
13800 .policy
= nl80211_policy
,
13801 .flags
= GENL_ADMIN_PERM
,
13802 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13803 NL80211_FLAG_NEED_RTNL
,
13806 .cmd
= NL80211_CMD_CHANGE_NAN_CONFIG
,
13807 .doit
= nl80211_nan_change_config
,
13808 .policy
= nl80211_policy
,
13809 .flags
= GENL_ADMIN_PERM
,
13810 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13811 NL80211_FLAG_NEED_RTNL
,
13814 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
13815 .doit
= nl80211_set_mcast_rate
,
13816 .policy
= nl80211_policy
,
13817 .flags
= GENL_UNS_ADMIN_PERM
,
13818 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13819 NL80211_FLAG_NEED_RTNL
,
13822 .cmd
= NL80211_CMD_SET_MAC_ACL
,
13823 .doit
= nl80211_set_mac_acl
,
13824 .policy
= nl80211_policy
,
13825 .flags
= GENL_UNS_ADMIN_PERM
,
13826 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13827 NL80211_FLAG_NEED_RTNL
,
13830 .cmd
= NL80211_CMD_RADAR_DETECT
,
13831 .doit
= nl80211_start_radar_detection
,
13832 .policy
= nl80211_policy
,
13833 .flags
= GENL_UNS_ADMIN_PERM
,
13834 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13835 NL80211_FLAG_NEED_RTNL
,
13838 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
13839 .doit
= nl80211_get_protocol_features
,
13840 .policy
= nl80211_policy
,
13843 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
13844 .doit
= nl80211_update_ft_ies
,
13845 .policy
= nl80211_policy
,
13846 .flags
= GENL_UNS_ADMIN_PERM
,
13847 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13848 NL80211_FLAG_NEED_RTNL
,
13851 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
13852 .doit
= nl80211_crit_protocol_start
,
13853 .policy
= nl80211_policy
,
13854 .flags
= GENL_UNS_ADMIN_PERM
,
13855 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13856 NL80211_FLAG_NEED_RTNL
,
13859 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
13860 .doit
= nl80211_crit_protocol_stop
,
13861 .policy
= nl80211_policy
,
13862 .flags
= GENL_UNS_ADMIN_PERM
,
13863 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13864 NL80211_FLAG_NEED_RTNL
,
13867 .cmd
= NL80211_CMD_GET_COALESCE
,
13868 .doit
= nl80211_get_coalesce
,
13869 .policy
= nl80211_policy
,
13870 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13871 NL80211_FLAG_NEED_RTNL
,
13874 .cmd
= NL80211_CMD_SET_COALESCE
,
13875 .doit
= nl80211_set_coalesce
,
13876 .policy
= nl80211_policy
,
13877 .flags
= GENL_UNS_ADMIN_PERM
,
13878 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13879 NL80211_FLAG_NEED_RTNL
,
13882 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
13883 .doit
= nl80211_channel_switch
,
13884 .policy
= nl80211_policy
,
13885 .flags
= GENL_UNS_ADMIN_PERM
,
13886 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13887 NL80211_FLAG_NEED_RTNL
,
13890 .cmd
= NL80211_CMD_VENDOR
,
13891 .doit
= nl80211_vendor_cmd
,
13892 .dumpit
= nl80211_vendor_cmd_dump
,
13893 .policy
= nl80211_policy
,
13894 .flags
= GENL_UNS_ADMIN_PERM
,
13895 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13896 NL80211_FLAG_NEED_RTNL
|
13897 NL80211_FLAG_CLEAR_SKB
,
13900 .cmd
= NL80211_CMD_SET_QOS_MAP
,
13901 .doit
= nl80211_set_qos_map
,
13902 .policy
= nl80211_policy
,
13903 .flags
= GENL_UNS_ADMIN_PERM
,
13904 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13905 NL80211_FLAG_NEED_RTNL
,
13908 .cmd
= NL80211_CMD_ADD_TX_TS
,
13909 .doit
= nl80211_add_tx_ts
,
13910 .policy
= nl80211_policy
,
13911 .flags
= GENL_UNS_ADMIN_PERM
,
13912 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13913 NL80211_FLAG_NEED_RTNL
,
13916 .cmd
= NL80211_CMD_DEL_TX_TS
,
13917 .doit
= nl80211_del_tx_ts
,
13918 .policy
= nl80211_policy
,
13919 .flags
= GENL_UNS_ADMIN_PERM
,
13920 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13921 NL80211_FLAG_NEED_RTNL
,
13924 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
13925 .doit
= nl80211_tdls_channel_switch
,
13926 .policy
= nl80211_policy
,
13927 .flags
= GENL_UNS_ADMIN_PERM
,
13928 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13929 NL80211_FLAG_NEED_RTNL
,
13932 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
13933 .doit
= nl80211_tdls_cancel_channel_switch
,
13934 .policy
= nl80211_policy
,
13935 .flags
= GENL_UNS_ADMIN_PERM
,
13936 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13937 NL80211_FLAG_NEED_RTNL
,
13940 .cmd
= NL80211_CMD_SET_MULTICAST_TO_UNICAST
,
13941 .doit
= nl80211_set_multicast_to_unicast
,
13942 .policy
= nl80211_policy
,
13943 .flags
= GENL_UNS_ADMIN_PERM
,
13944 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13945 NL80211_FLAG_NEED_RTNL
,
13948 .cmd
= NL80211_CMD_SET_PMK
,
13949 .doit
= nl80211_set_pmk
,
13950 .policy
= nl80211_policy
,
13951 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13952 NL80211_FLAG_NEED_RTNL
|
13953 NL80211_FLAG_CLEAR_SKB
,
13956 .cmd
= NL80211_CMD_DEL_PMK
,
13957 .doit
= nl80211_del_pmk
,
13958 .policy
= nl80211_policy
,
13959 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13960 NL80211_FLAG_NEED_RTNL
,
13963 .cmd
= NL80211_CMD_EXTERNAL_AUTH
,
13964 .doit
= nl80211_external_auth
,
13965 .policy
= nl80211_policy
,
13966 .flags
= GENL_ADMIN_PERM
,
13967 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13968 NL80211_FLAG_NEED_RTNL
,
13971 .cmd
= NL80211_CMD_CONTROL_PORT_FRAME
,
13972 .doit
= nl80211_tx_control_port
,
13973 .policy
= nl80211_policy
,
13974 .flags
= GENL_UNS_ADMIN_PERM
,
13975 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13976 NL80211_FLAG_NEED_RTNL
,
13980 static struct genl_family nl80211_fam __ro_after_init
= {
13981 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
13982 .hdrsize
= 0, /* no private header */
13983 .version
= 1, /* no particular meaning now */
13984 .maxattr
= NL80211_ATTR_MAX
,
13986 .pre_doit
= nl80211_pre_doit
,
13987 .post_doit
= nl80211_post_doit
,
13988 .module
= THIS_MODULE
,
13989 .ops
= nl80211_ops
,
13990 .n_ops
= ARRAY_SIZE(nl80211_ops
),
13991 .mcgrps
= nl80211_mcgrps
,
13992 .n_mcgrps
= ARRAY_SIZE(nl80211_mcgrps
),
13995 /* notification functions */
13997 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
13998 enum nl80211_commands cmd
)
14000 struct sk_buff
*msg
;
14001 struct nl80211_dump_wiphy_state state
= {};
14003 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
14004 cmd
!= NL80211_CMD_DEL_WIPHY
);
14006 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14010 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
14015 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14016 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
14019 void nl80211_notify_iface(struct cfg80211_registered_device
*rdev
,
14020 struct wireless_dev
*wdev
,
14021 enum nl80211_commands cmd
)
14023 struct sk_buff
*msg
;
14025 WARN_ON(cmd
!= NL80211_CMD_NEW_INTERFACE
&&
14026 cmd
!= NL80211_CMD_DEL_INTERFACE
);
14028 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14032 if (nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
,
14033 cmd
== NL80211_CMD_DEL_INTERFACE
) < 0) {
14038 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14039 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
14042 static int nl80211_add_scan_req(struct sk_buff
*msg
,
14043 struct cfg80211_registered_device
*rdev
)
14045 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
14046 struct nlattr
*nest
;
14052 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
14054 goto nla_put_failure
;
14055 for (i
= 0; i
< req
->n_ssids
; i
++) {
14056 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
14057 goto nla_put_failure
;
14059 nla_nest_end(msg
, nest
);
14061 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
14063 goto nla_put_failure
;
14064 for (i
= 0; i
< req
->n_channels
; i
++) {
14065 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
14066 goto nla_put_failure
;
14068 nla_nest_end(msg
, nest
);
14071 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
14072 goto nla_put_failure
;
14075 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
14076 goto nla_put_failure
;
14078 if (req
->info
.scan_start_tsf
&&
14079 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
14080 req
->info
.scan_start_tsf
, NL80211_BSS_PAD
) ||
14081 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
14082 req
->info
.tsf_bssid
)))
14083 goto nla_put_failure
;
14090 static int nl80211_prep_scan_msg(struct sk_buff
*msg
,
14091 struct cfg80211_registered_device
*rdev
,
14092 struct wireless_dev
*wdev
,
14093 u32 portid
, u32 seq
, int flags
,
14098 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
14102 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14103 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14104 wdev
->netdev
->ifindex
)) ||
14105 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14107 goto nla_put_failure
;
14109 /* ignore errors and send incomplete event anyway */
14110 nl80211_add_scan_req(msg
, rdev
);
14112 genlmsg_end(msg
, hdr
);
14116 genlmsg_cancel(msg
, hdr
);
14121 nl80211_prep_sched_scan_msg(struct sk_buff
*msg
,
14122 struct cfg80211_sched_scan_request
*req
, u32 cmd
)
14126 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14130 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
,
14131 wiphy_to_rdev(req
->wiphy
)->wiphy_idx
) ||
14132 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, req
->dev
->ifindex
) ||
14133 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, req
->reqid
,
14135 goto nla_put_failure
;
14137 genlmsg_end(msg
, hdr
);
14141 genlmsg_cancel(msg
, hdr
);
14145 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
14146 struct wireless_dev
*wdev
)
14148 struct sk_buff
*msg
;
14150 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14154 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
14155 NL80211_CMD_TRIGGER_SCAN
) < 0) {
14160 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14161 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
14164 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
14165 struct wireless_dev
*wdev
, bool aborted
)
14167 struct sk_buff
*msg
;
14169 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14173 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
14174 aborted
? NL80211_CMD_SCAN_ABORTED
:
14175 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
14183 /* send message created by nl80211_build_scan_msg() */
14184 void nl80211_send_scan_msg(struct cfg80211_registered_device
*rdev
,
14185 struct sk_buff
*msg
)
14190 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14191 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
14194 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request
*req
, u32 cmd
)
14196 struct sk_buff
*msg
;
14198 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14202 if (nl80211_prep_sched_scan_msg(msg
, req
, cmd
) < 0) {
14207 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(req
->wiphy
), msg
, 0,
14208 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
14211 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
14212 struct regulatory_request
*request
)
14214 /* Userspace can always count this one always being set */
14215 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
14216 goto nla_put_failure
;
14218 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
14219 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14220 NL80211_REGDOM_TYPE_WORLD
))
14221 goto nla_put_failure
;
14222 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
14223 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14224 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
14225 goto nla_put_failure
;
14226 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
14227 request
->intersect
) {
14228 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14229 NL80211_REGDOM_TYPE_INTERSECTION
))
14230 goto nla_put_failure
;
14232 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
14233 NL80211_REGDOM_TYPE_COUNTRY
) ||
14234 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
14236 goto nla_put_failure
;
14239 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
14240 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
14243 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
14244 goto nla_put_failure
;
14247 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
14248 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
14249 goto nla_put_failure
;
14259 * This can happen on global regulatory changes or device specific settings
14260 * based on custom regulatory domains.
14262 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
14263 struct regulatory_request
*request
)
14265 struct sk_buff
*msg
;
14268 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14272 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
14278 if (nl80211_reg_change_event_fill(msg
, request
) == false)
14279 goto nla_put_failure
;
14281 genlmsg_end(msg
, hdr
);
14284 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
14285 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
14294 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
14295 struct net_device
*netdev
,
14296 const u8
*buf
, size_t len
,
14297 enum nl80211_commands cmd
, gfp_t gfp
,
14300 struct sk_buff
*msg
;
14303 msg
= nlmsg_new(100 + len
, gfp
);
14307 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14313 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14314 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14315 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
14316 goto nla_put_failure
;
14318 if (uapsd_queues
>= 0) {
14319 struct nlattr
*nla_wmm
=
14320 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
14322 goto nla_put_failure
;
14324 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
14326 goto nla_put_failure
;
14328 nla_nest_end(msg
, nla_wmm
);
14331 genlmsg_end(msg
, hdr
);
14333 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14334 NL80211_MCGRP_MLME
, gfp
);
14341 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
14342 struct net_device
*netdev
, const u8
*buf
,
14343 size_t len
, gfp_t gfp
)
14345 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14346 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
14349 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
14350 struct net_device
*netdev
, const u8
*buf
,
14351 size_t len
, gfp_t gfp
, int uapsd_queues
)
14353 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14354 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
14357 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
14358 struct net_device
*netdev
, const u8
*buf
,
14359 size_t len
, gfp_t gfp
)
14361 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14362 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
14365 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
14366 struct net_device
*netdev
, const u8
*buf
,
14367 size_t len
, gfp_t gfp
)
14369 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
14370 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
14373 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
14376 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14377 struct wiphy
*wiphy
= wdev
->wiphy
;
14378 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14379 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
14382 if (WARN_ON(len
< 2))
14385 if (ieee80211_is_deauth(mgmt
->frame_control
))
14386 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
14388 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
14390 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
14391 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
14393 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
14395 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
14396 struct net_device
*netdev
, int cmd
,
14397 const u8
*addr
, gfp_t gfp
)
14399 struct sk_buff
*msg
;
14402 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14406 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14412 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14413 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14414 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
14415 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
14416 goto nla_put_failure
;
14418 genlmsg_end(msg
, hdr
);
14420 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14421 NL80211_MCGRP_MLME
, gfp
);
14428 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
14429 struct net_device
*netdev
, const u8
*addr
,
14432 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
14436 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
14437 struct net_device
*netdev
, const u8
*addr
,
14440 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
14444 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
14445 struct net_device
*netdev
,
14446 struct cfg80211_connect_resp_params
*cr
,
14449 struct sk_buff
*msg
;
14452 msg
= nlmsg_new(100 + cr
->req_ie_len
+ cr
->resp_ie_len
+
14453 cr
->fils
.kek_len
+ cr
->fils
.pmk_len
+
14454 (cr
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
14458 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
14464 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14465 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14467 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, cr
->bssid
)) ||
14468 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
14469 cr
->status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
14472 (nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
14473 nla_put_u32(msg
, NL80211_ATTR_TIMEOUT_REASON
,
14474 cr
->timeout_reason
))) ||
14476 nla_put(msg
, NL80211_ATTR_REQ_IE
, cr
->req_ie_len
, cr
->req_ie
)) ||
14478 nla_put(msg
, NL80211_ATTR_RESP_IE
, cr
->resp_ie_len
,
14480 (cr
->fils
.update_erp_next_seq_num
&&
14481 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
14482 cr
->fils
.erp_next_seq_num
)) ||
14483 (cr
->status
== WLAN_STATUS_SUCCESS
&&
14485 nla_put(msg
, NL80211_ATTR_FILS_KEK
, cr
->fils
.kek_len
,
14488 nla_put(msg
, NL80211_ATTR_PMK
, cr
->fils
.pmk_len
, cr
->fils
.pmk
)) ||
14490 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, cr
->fils
.pmkid
)))))
14491 goto nla_put_failure
;
14493 genlmsg_end(msg
, hdr
);
14495 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14496 NL80211_MCGRP_MLME
, gfp
);
14503 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
14504 struct net_device
*netdev
,
14505 struct cfg80211_roam_info
*info
, gfp_t gfp
)
14507 struct sk_buff
*msg
;
14509 const u8
*bssid
= info
->bss
? info
->bss
->bssid
: info
->bssid
;
14511 msg
= nlmsg_new(100 + info
->req_ie_len
+ info
->resp_ie_len
+
14512 info
->fils
.kek_len
+ info
->fils
.pmk_len
+
14513 (info
->fils
.pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
14517 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
14523 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14524 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14525 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
14527 nla_put(msg
, NL80211_ATTR_REQ_IE
, info
->req_ie_len
,
14530 nla_put(msg
, NL80211_ATTR_RESP_IE
, info
->resp_ie_len
,
14532 (info
->fils
.update_erp_next_seq_num
&&
14533 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
14534 info
->fils
.erp_next_seq_num
)) ||
14536 nla_put(msg
, NL80211_ATTR_FILS_KEK
, info
->fils
.kek_len
,
14537 info
->fils
.kek
)) ||
14539 nla_put(msg
, NL80211_ATTR_PMK
, info
->fils
.pmk_len
, info
->fils
.pmk
)) ||
14540 (info
->fils
.pmkid
&&
14541 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, info
->fils
.pmkid
)))
14542 goto nla_put_failure
;
14544 genlmsg_end(msg
, hdr
);
14546 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14547 NL80211_MCGRP_MLME
, gfp
);
14554 void nl80211_send_port_authorized(struct cfg80211_registered_device
*rdev
,
14555 struct net_device
*netdev
, const u8
*bssid
)
14557 struct sk_buff
*msg
;
14560 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14564 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED
);
14570 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
14571 goto nla_put_failure
;
14573 genlmsg_end(msg
, hdr
);
14575 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14576 NL80211_MCGRP_MLME
, GFP_KERNEL
);
14583 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
14584 struct net_device
*netdev
, u16 reason
,
14585 const u8
*ie
, size_t ie_len
, bool from_ap
)
14587 struct sk_buff
*msg
;
14590 msg
= nlmsg_new(100 + ie_len
, GFP_KERNEL
);
14594 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
14600 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14601 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14603 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
14605 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
14606 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
14607 goto nla_put_failure
;
14609 genlmsg_end(msg
, hdr
);
14611 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14612 NL80211_MCGRP_MLME
, GFP_KERNEL
);
14619 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
14620 struct net_device
*netdev
, const u8
*bssid
,
14623 struct sk_buff
*msg
;
14626 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14630 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
14636 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14637 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14638 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
14639 goto nla_put_failure
;
14641 genlmsg_end(msg
, hdr
);
14643 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14644 NL80211_MCGRP_MLME
, gfp
);
14651 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
14652 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
14654 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14655 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14656 struct sk_buff
*msg
;
14659 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
14662 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
14664 msg
= nlmsg_new(100 + ie_len
, gfp
);
14668 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
14674 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14675 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14676 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
14678 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
14679 goto nla_put_failure
;
14681 genlmsg_end(msg
, hdr
);
14683 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14684 NL80211_MCGRP_MLME
, gfp
);
14690 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
14692 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
14693 struct net_device
*netdev
, const u8
*addr
,
14694 enum nl80211_key_type key_type
, int key_id
,
14695 const u8
*tsc
, gfp_t gfp
)
14697 struct sk_buff
*msg
;
14700 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14704 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
14710 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14711 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14712 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
14713 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
14715 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
14716 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
14717 goto nla_put_failure
;
14719 genlmsg_end(msg
, hdr
);
14721 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14722 NL80211_MCGRP_MLME
, gfp
);
14729 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
14730 struct ieee80211_channel
*channel_before
,
14731 struct ieee80211_channel
*channel_after
)
14733 struct sk_buff
*msg
;
14735 struct nlattr
*nl_freq
;
14737 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
14741 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
14748 * Since we are applying the beacon hint to a wiphy we know its
14749 * wiphy_idx is valid
14751 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
14752 goto nla_put_failure
;
14755 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
14757 goto nla_put_failure
;
14759 if (nl80211_msg_put_channel(msg
, wiphy
, channel_before
, false))
14760 goto nla_put_failure
;
14761 nla_nest_end(msg
, nl_freq
);
14764 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
14766 goto nla_put_failure
;
14768 if (nl80211_msg_put_channel(msg
, wiphy
, channel_after
, false))
14769 goto nla_put_failure
;
14770 nla_nest_end(msg
, nl_freq
);
14772 genlmsg_end(msg
, hdr
);
14775 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
14776 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
14785 static void nl80211_send_remain_on_chan_event(
14786 int cmd
, struct cfg80211_registered_device
*rdev
,
14787 struct wireless_dev
*wdev
, u64 cookie
,
14788 struct ieee80211_channel
*chan
,
14789 unsigned int duration
, gfp_t gfp
)
14791 struct sk_buff
*msg
;
14794 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14798 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14804 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14805 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14806 wdev
->netdev
->ifindex
)) ||
14807 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14808 NL80211_ATTR_PAD
) ||
14809 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
14810 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
14811 NL80211_CHAN_NO_HT
) ||
14812 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14814 goto nla_put_failure
;
14816 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
14817 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
14818 goto nla_put_failure
;
14820 genlmsg_end(msg
, hdr
);
14822 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14823 NL80211_MCGRP_MLME
, gfp
);
14830 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
14831 struct ieee80211_channel
*chan
,
14832 unsigned int duration
, gfp_t gfp
)
14834 struct wiphy
*wiphy
= wdev
->wiphy
;
14835 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14837 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
14838 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
14839 rdev
, wdev
, cookie
, chan
,
14842 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
14844 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
14845 struct ieee80211_channel
*chan
,
14848 struct wiphy
*wiphy
= wdev
->wiphy
;
14849 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14851 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
14852 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
14853 rdev
, wdev
, cookie
, chan
, 0, gfp
);
14855 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
14857 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
14858 struct station_info
*sinfo
, gfp_t gfp
)
14860 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14861 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14862 struct sk_buff
*msg
;
14864 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
14866 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14870 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
14871 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14876 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14877 NL80211_MCGRP_MLME
, gfp
);
14879 EXPORT_SYMBOL(cfg80211_new_sta
);
14881 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
14882 struct station_info
*sinfo
, gfp_t gfp
)
14884 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14885 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14886 struct sk_buff
*msg
;
14887 struct station_info empty_sinfo
= {};
14890 sinfo
= &empty_sinfo
;
14892 trace_cfg80211_del_sta(dev
, mac_addr
);
14894 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14896 cfg80211_sinfo_release_content(sinfo
);
14900 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
14901 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14906 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14907 NL80211_MCGRP_MLME
, gfp
);
14909 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
14911 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
14912 enum nl80211_connect_failed_reason reason
,
14915 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14916 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14917 struct sk_buff
*msg
;
14920 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
14924 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
14930 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14931 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
14932 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
14933 goto nla_put_failure
;
14935 genlmsg_end(msg
, hdr
);
14937 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14938 NL80211_MCGRP_MLME
, gfp
);
14944 EXPORT_SYMBOL(cfg80211_conn_failed
);
14946 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
14947 const u8
*addr
, gfp_t gfp
)
14949 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14950 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14951 struct sk_buff
*msg
;
14953 u32 nlportid
= READ_ONCE(wdev
->ap_unexpected_nlportid
);
14958 msg
= nlmsg_new(100, gfp
);
14962 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14968 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14969 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14970 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
14971 goto nla_put_failure
;
14973 genlmsg_end(msg
, hdr
);
14974 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14982 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
14983 const u8
*addr
, gfp_t gfp
)
14985 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14988 trace_cfg80211_rx_spurious_frame(dev
, addr
);
14990 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14991 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
14992 trace_cfg80211_return_bool(false);
14995 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
14997 trace_cfg80211_return_bool(ret
);
15000 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
15002 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
15003 const u8
*addr
, gfp_t gfp
)
15005 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15008 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
15010 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
15011 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
15012 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
15013 trace_cfg80211_return_bool(false);
15016 ret
= __nl80211_unexpected_frame(dev
,
15017 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
15019 trace_cfg80211_return_bool(ret
);
15022 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
15024 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
15025 struct wireless_dev
*wdev
, u32 nlportid
,
15026 int freq
, int sig_dbm
,
15027 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
15029 struct net_device
*netdev
= wdev
->netdev
;
15030 struct sk_buff
*msg
;
15033 msg
= nlmsg_new(100 + len
, gfp
);
15037 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
15043 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15044 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
15045 netdev
->ifindex
)) ||
15046 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15047 NL80211_ATTR_PAD
) ||
15048 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
15050 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
15051 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
15053 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
15054 goto nla_put_failure
;
15056 genlmsg_end(msg
, hdr
);
15058 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
15065 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
15066 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
15068 struct wiphy
*wiphy
= wdev
->wiphy
;
15069 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15070 struct net_device
*netdev
= wdev
->netdev
;
15071 struct sk_buff
*msg
;
15074 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
15076 msg
= nlmsg_new(100 + len
, gfp
);
15080 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
15086 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15087 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
15088 netdev
->ifindex
)) ||
15089 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15090 NL80211_ATTR_PAD
) ||
15091 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
15092 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
15093 NL80211_ATTR_PAD
) ||
15094 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
15095 goto nla_put_failure
;
15097 genlmsg_end(msg
, hdr
);
15099 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15100 NL80211_MCGRP_MLME
, gfp
);
15106 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
15108 static int __nl80211_rx_control_port(struct net_device
*dev
,
15109 struct sk_buff
*skb
,
15110 bool unencrypted
, gfp_t gfp
)
15112 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15113 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15114 struct ethhdr
*ehdr
= eth_hdr(skb
);
15115 const u8
*addr
= ehdr
->h_source
;
15116 u16 proto
= be16_to_cpu(skb
->protocol
);
15117 struct sk_buff
*msg
;
15119 struct nlattr
*frame
;
15121 u32 nlportid
= READ_ONCE(wdev
->conn_owner_nlportid
);
15126 msg
= nlmsg_new(100 + skb
->len
, gfp
);
15130 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME
);
15136 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15137 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15138 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15139 NL80211_ATTR_PAD
) ||
15140 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
15141 nla_put_u16(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
, proto
) ||
15142 (unencrypted
&& nla_put_flag(msg
,
15143 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
)))
15144 goto nla_put_failure
;
15146 frame
= nla_reserve(msg
, NL80211_ATTR_FRAME
, skb
->len
);
15148 goto nla_put_failure
;
15150 skb_copy_bits(skb
, 0, nla_data(frame
), skb
->len
);
15151 genlmsg_end(msg
, hdr
);
15153 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
15160 bool cfg80211_rx_control_port(struct net_device
*dev
,
15161 struct sk_buff
*skb
, bool unencrypted
)
15165 trace_cfg80211_rx_control_port(dev
, skb
, unencrypted
);
15166 ret
= __nl80211_rx_control_port(dev
, skb
, unencrypted
, GFP_ATOMIC
);
15167 trace_cfg80211_return_bool(ret
== 0);
15170 EXPORT_SYMBOL(cfg80211_rx_control_port
);
15172 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
15173 const char *mac
, gfp_t gfp
)
15175 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15176 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15177 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15183 cb
= (void **)msg
->cb
;
15185 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
15191 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15192 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
15193 goto nla_put_failure
;
15195 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
15196 goto nla_put_failure
;
15198 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
15200 goto nla_put_failure
;
15210 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
15212 void **cb
= (void **)msg
->cb
;
15213 struct cfg80211_registered_device
*rdev
= cb
[2];
15215 nla_nest_end(msg
, cb
[1]);
15216 genlmsg_end(msg
, cb
[0]);
15218 memset(msg
->cb
, 0, sizeof(msg
->cb
));
15220 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15221 NL80211_MCGRP_MLME
, gfp
);
15224 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
15225 enum nl80211_cqm_rssi_threshold_event rssi_event
,
15226 s32 rssi_level
, gfp_t gfp
)
15228 struct sk_buff
*msg
;
15229 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15230 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15232 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
, rssi_level
);
15234 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
15235 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
15238 if (wdev
->cqm_config
) {
15239 wdev
->cqm_config
->last_rssi_event_value
= rssi_level
;
15241 cfg80211_cqm_rssi_update(rdev
, dev
);
15243 if (rssi_level
== 0)
15244 rssi_level
= wdev
->cqm_config
->last_rssi_event_value
;
15247 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
15251 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
15253 goto nla_put_failure
;
15255 if (rssi_level
&& nla_put_s32(msg
, NL80211_ATTR_CQM_RSSI_LEVEL
,
15257 goto nla_put_failure
;
15259 cfg80211_send_cqm(msg
, gfp
);
15266 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
15268 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
15269 const u8
*peer
, u32 num_packets
,
15270 u32 rate
, u32 intvl
, gfp_t gfp
)
15272 struct sk_buff
*msg
;
15274 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
15278 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
15279 goto nla_put_failure
;
15281 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
15282 goto nla_put_failure
;
15284 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
15285 goto nla_put_failure
;
15287 cfg80211_send_cqm(msg
, gfp
);
15293 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
15295 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
15296 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
15298 struct sk_buff
*msg
;
15300 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
15302 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
15306 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
15307 goto nla_put_failure
;
15309 cfg80211_send_cqm(msg
, gfp
);
15315 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
15317 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
15319 struct sk_buff
*msg
;
15321 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
15325 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
15326 goto nla_put_failure
;
15328 cfg80211_send_cqm(msg
, gfp
);
15334 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
15336 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
15337 struct net_device
*netdev
, const u8
*bssid
,
15338 const u8
*replay_ctr
, gfp_t gfp
)
15340 struct sk_buff
*msg
;
15341 struct nlattr
*rekey_attr
;
15344 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15348 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
15354 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15355 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15356 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
15357 goto nla_put_failure
;
15359 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
15361 goto nla_put_failure
;
15363 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
15364 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
15365 goto nla_put_failure
;
15367 nla_nest_end(msg
, rekey_attr
);
15369 genlmsg_end(msg
, hdr
);
15371 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15372 NL80211_MCGRP_MLME
, gfp
);
15379 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
15380 const u8
*replay_ctr
, gfp_t gfp
)
15382 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15383 struct wiphy
*wiphy
= wdev
->wiphy
;
15384 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15386 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
15387 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
15389 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
15392 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
15393 struct net_device
*netdev
, int index
,
15394 const u8
*bssid
, bool preauth
, gfp_t gfp
)
15396 struct sk_buff
*msg
;
15397 struct nlattr
*attr
;
15400 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15404 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
15410 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15411 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
15412 goto nla_put_failure
;
15414 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
15416 goto nla_put_failure
;
15418 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
15419 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
15421 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
15422 goto nla_put_failure
;
15424 nla_nest_end(msg
, attr
);
15426 genlmsg_end(msg
, hdr
);
15428 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15429 NL80211_MCGRP_MLME
, gfp
);
15436 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
15437 const u8
*bssid
, bool preauth
, gfp_t gfp
)
15439 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15440 struct wiphy
*wiphy
= wdev
->wiphy
;
15441 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15443 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
15444 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
15446 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
15448 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
15449 struct net_device
*netdev
,
15450 struct cfg80211_chan_def
*chandef
,
15452 enum nl80211_commands notif
,
15455 struct sk_buff
*msg
;
15458 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15462 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
15468 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
15469 goto nla_put_failure
;
15471 if (nl80211_send_chandef(msg
, chandef
))
15472 goto nla_put_failure
;
15474 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
15475 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
15476 goto nla_put_failure
;
15478 genlmsg_end(msg
, hdr
);
15480 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15481 NL80211_MCGRP_MLME
, gfp
);
15488 void cfg80211_ch_switch_notify(struct net_device
*dev
,
15489 struct cfg80211_chan_def
*chandef
)
15491 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15492 struct wiphy
*wiphy
= wdev
->wiphy
;
15493 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15495 ASSERT_WDEV_LOCK(wdev
);
15497 trace_cfg80211_ch_switch_notify(dev
, chandef
);
15499 wdev
->chandef
= *chandef
;
15500 wdev
->preset_chandef
= *chandef
;
15502 if (wdev
->iftype
== NL80211_IFTYPE_STATION
&&
15503 !WARN_ON(!wdev
->current_bss
))
15504 wdev
->current_bss
->pub
.channel
= chandef
->chan
;
15506 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
15507 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
15509 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
15511 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
15512 struct cfg80211_chan_def
*chandef
,
15515 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15516 struct wiphy
*wiphy
= wdev
->wiphy
;
15517 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15519 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
15521 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
15522 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
15524 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
15527 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
15528 const struct cfg80211_chan_def
*chandef
,
15529 enum nl80211_radar_event event
,
15530 struct net_device
*netdev
, gfp_t gfp
)
15532 struct sk_buff
*msg
;
15535 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15539 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
15545 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
15546 goto nla_put_failure
;
15548 /* NOP and radar events don't need a netdev parameter */
15550 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
15552 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15553 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15555 goto nla_put_failure
;
15558 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
15559 goto nla_put_failure
;
15561 if (nl80211_send_chandef(msg
, chandef
))
15562 goto nla_put_failure
;
15564 genlmsg_end(msg
, hdr
);
15566 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15567 NL80211_MCGRP_MLME
, gfp
);
15574 void cfg80211_sta_opmode_change_notify(struct net_device
*dev
, const u8
*mac
,
15575 struct sta_opmode_info
*sta_opmode
,
15578 struct sk_buff
*msg
;
15579 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15580 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15586 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15590 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED
);
15596 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
15597 goto nla_put_failure
;
15599 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
15600 goto nla_put_failure
;
15602 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
15603 goto nla_put_failure
;
15605 if ((sta_opmode
->changed
& STA_OPMODE_SMPS_MODE_CHANGED
) &&
15606 nla_put_u8(msg
, NL80211_ATTR_SMPS_MODE
, sta_opmode
->smps_mode
))
15607 goto nla_put_failure
;
15609 if ((sta_opmode
->changed
& STA_OPMODE_MAX_BW_CHANGED
) &&
15610 nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, sta_opmode
->bw
))
15611 goto nla_put_failure
;
15613 if ((sta_opmode
->changed
& STA_OPMODE_N_SS_CHANGED
) &&
15614 nla_put_u8(msg
, NL80211_ATTR_NSS
, sta_opmode
->rx_nss
))
15615 goto nla_put_failure
;
15617 genlmsg_end(msg
, hdr
);
15619 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15620 NL80211_MCGRP_MLME
, gfp
);
15627 EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify
);
15629 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
15630 u64 cookie
, bool acked
, s32 ack_signal
,
15631 bool is_valid_ack_signal
, gfp_t gfp
)
15633 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15634 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15635 struct sk_buff
*msg
;
15638 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
15640 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15645 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
15651 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15652 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15653 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
15654 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
15655 NL80211_ATTR_PAD
) ||
15656 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)) ||
15657 (is_valid_ack_signal
&& nla_put_s32(msg
, NL80211_ATTR_ACK_SIGNAL
,
15659 goto nla_put_failure
;
15661 genlmsg_end(msg
, hdr
);
15663 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15664 NL80211_MCGRP_MLME
, gfp
);
15670 EXPORT_SYMBOL(cfg80211_probe_status
);
15672 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
15673 const u8
*frame
, size_t len
,
15674 int freq
, int sig_dbm
)
15676 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15677 struct sk_buff
*msg
;
15679 struct cfg80211_beacon_registration
*reg
;
15681 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
15683 spin_lock_bh(&rdev
->beacon_registrations_lock
);
15684 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
15685 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
15687 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15691 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
15693 goto nla_put_failure
;
15695 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15697 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
15699 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
15700 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
15701 goto nla_put_failure
;
15703 genlmsg_end(msg
, hdr
);
15705 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
15707 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15711 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15714 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
15717 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
15718 struct cfg80211_wowlan_wakeup
*wakeup
)
15720 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
15721 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
15724 nl_results
= nla_nest_start(
15725 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
15729 for (i
= 0; i
< nd
->n_matches
; i
++) {
15730 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
15732 nl_match
= nla_nest_start(msg
, i
);
15736 /* The SSID attribute is optional in nl80211, but for
15737 * simplicity reasons it's always present in the
15738 * cfg80211 structure. If a driver can't pass the
15739 * SSID, that needs to be changed. A zero length SSID
15740 * is still a valid SSID (wildcard), so it cannot be
15741 * used for this purpose.
15743 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
15744 match
->ssid
.ssid
)) {
15745 nla_nest_cancel(msg
, nl_match
);
15749 if (match
->n_channels
) {
15750 nl_freqs
= nla_nest_start(
15751 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
15753 nla_nest_cancel(msg
, nl_match
);
15757 for (j
= 0; j
< match
->n_channels
; j
++) {
15758 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
15759 nla_nest_cancel(msg
, nl_freqs
);
15760 nla_nest_cancel(msg
, nl_match
);
15765 nla_nest_end(msg
, nl_freqs
);
15768 nla_nest_end(msg
, nl_match
);
15772 nla_nest_end(msg
, nl_results
);
15776 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
15777 struct cfg80211_wowlan_wakeup
*wakeup
,
15780 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15781 struct sk_buff
*msg
;
15785 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
15788 size
+= wakeup
->packet_present_len
;
15790 msg
= nlmsg_new(size
, gfp
);
15794 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
15798 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15799 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15803 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
15804 wdev
->netdev
->ifindex
))
15808 struct nlattr
*reasons
;
15810 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
15814 if (wakeup
->disconnect
&&
15815 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
15817 if (wakeup
->magic_pkt
&&
15818 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
15820 if (wakeup
->gtk_rekey_failure
&&
15821 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
15823 if (wakeup
->eap_identity_req
&&
15824 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
15826 if (wakeup
->four_way_handshake
&&
15827 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
15829 if (wakeup
->rfkill_release
&&
15830 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
15833 if (wakeup
->pattern_idx
>= 0 &&
15834 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
15835 wakeup
->pattern_idx
))
15838 if (wakeup
->tcp_match
&&
15839 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
15842 if (wakeup
->tcp_connlost
&&
15843 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
15846 if (wakeup
->tcp_nomoretokens
&&
15848 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
15851 if (wakeup
->packet
) {
15852 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
15853 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
15855 if (!wakeup
->packet_80211
) {
15857 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
15859 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
15862 if (wakeup
->packet_len
&&
15863 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
15866 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
15871 if (wakeup
->net_detect
&&
15872 cfg80211_net_detect_results(msg
, wakeup
))
15875 nla_nest_end(msg
, reasons
);
15878 genlmsg_end(msg
, hdr
);
15880 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15881 NL80211_MCGRP_MLME
, gfp
);
15887 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
15890 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
15891 enum nl80211_tdls_operation oper
,
15892 u16 reason_code
, gfp_t gfp
)
15894 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15895 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15896 struct sk_buff
*msg
;
15899 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
15902 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15906 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
15912 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15913 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15914 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
15915 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
15916 (reason_code
> 0 &&
15917 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
15918 goto nla_put_failure
;
15920 genlmsg_end(msg
, hdr
);
15922 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15923 NL80211_MCGRP_MLME
, gfp
);
15929 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
15931 static int nl80211_netlink_notify(struct notifier_block
* nb
,
15932 unsigned long state
,
15935 struct netlink_notify
*notify
= _notify
;
15936 struct cfg80211_registered_device
*rdev
;
15937 struct wireless_dev
*wdev
;
15938 struct cfg80211_beacon_registration
*reg
, *tmp
;
15940 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
15941 return NOTIFY_DONE
;
15945 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
15946 struct cfg80211_sched_scan_request
*sched_scan_req
;
15948 list_for_each_entry_rcu(sched_scan_req
,
15949 &rdev
->sched_scan_req_list
,
15951 if (sched_scan_req
->owner_nlportid
== notify
->portid
) {
15952 sched_scan_req
->nl_owner_dead
= true;
15953 schedule_work(&rdev
->sched_scan_stop_wk
);
15957 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
15958 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
15960 if (wdev
->owner_nlportid
== notify
->portid
) {
15961 wdev
->nl_owner_dead
= true;
15962 schedule_work(&rdev
->destroy_work
);
15963 } else if (wdev
->conn_owner_nlportid
== notify
->portid
) {
15964 schedule_work(&wdev
->disconnect_wk
);
15968 spin_lock_bh(&rdev
->beacon_registrations_lock
);
15969 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
15971 if (reg
->nlportid
== notify
->portid
) {
15972 list_del(®
->list
);
15977 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15983 * It is possible that the user space process that is controlling the
15984 * indoor setting disappeared, so notify the regulatory core.
15986 regulatory_netlink_notify(notify
->portid
);
15990 static struct notifier_block nl80211_netlink_notifier
= {
15991 .notifier_call
= nl80211_netlink_notify
,
15994 void cfg80211_ft_event(struct net_device
*netdev
,
15995 struct cfg80211_ft_event_params
*ft_event
)
15997 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
15998 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15999 struct sk_buff
*msg
;
16002 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
16004 if (!ft_event
->target_ap
)
16007 msg
= nlmsg_new(100 + ft_event
->ies_len
+ ft_event
->ric_ies_len
,
16012 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
16016 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16017 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
16018 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
16021 if (ft_event
->ies
&&
16022 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
16024 if (ft_event
->ric_ies
&&
16025 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
16026 ft_event
->ric_ies
))
16029 genlmsg_end(msg
, hdr
);
16031 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
16032 NL80211_MCGRP_MLME
, GFP_KERNEL
);
16037 EXPORT_SYMBOL(cfg80211_ft_event
);
16039 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
16041 struct cfg80211_registered_device
*rdev
;
16042 struct sk_buff
*msg
;
16046 rdev
= wiphy_to_rdev(wdev
->wiphy
);
16047 if (!rdev
->crit_proto_nlportid
)
16050 nlportid
= rdev
->crit_proto_nlportid
;
16051 rdev
->crit_proto_nlportid
= 0;
16053 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16057 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
16059 goto nla_put_failure
;
16061 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16062 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16064 goto nla_put_failure
;
16066 genlmsg_end(msg
, hdr
);
16068 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
16074 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
16076 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
16078 struct wiphy
*wiphy
= wdev
->wiphy
;
16079 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
16080 struct sk_buff
*msg
;
16083 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
16087 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
16091 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16092 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
16093 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
16097 genlmsg_end(msg
, hdr
);
16099 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
16100 NL80211_MCGRP_MLME
, GFP_KERNEL
);
16106 int cfg80211_external_auth_request(struct net_device
*dev
,
16107 struct cfg80211_external_auth_params
*params
,
16110 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
16111 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
16112 struct sk_buff
*msg
;
16115 if (!wdev
->conn_owner_nlportid
)
16118 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
16122 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH
);
16124 goto nla_put_failure
;
16126 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
16127 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
16128 nla_put_u32(msg
, NL80211_ATTR_AKM_SUITES
, params
->key_mgmt_suite
) ||
16129 nla_put_u32(msg
, NL80211_ATTR_EXTERNAL_AUTH_ACTION
,
16131 nla_put(msg
, NL80211_ATTR_BSSID
, ETH_ALEN
, params
->bssid
) ||
16132 nla_put(msg
, NL80211_ATTR_SSID
, params
->ssid
.ssid_len
,
16133 params
->ssid
.ssid
))
16134 goto nla_put_failure
;
16136 genlmsg_end(msg
, hdr
);
16137 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
16138 wdev
->conn_owner_nlportid
);
16145 EXPORT_SYMBOL(cfg80211_external_auth_request
);
16147 /* initialisation/exit functions */
16149 int __init
nl80211_init(void)
16153 err
= genl_register_family(&nl80211_fam
);
16157 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
16163 genl_unregister_family(&nl80211_fam
);
16167 void nl80211_exit(void)
16169 netlink_unregister_notifier(&nl80211_netlink_notifier
);
16170 genl_unregister_family(&nl80211_fam
);