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
10 #include <linux/module.h>
11 #include <linux/err.h>
12 #include <linux/slab.h>
13 #include <linux/list.h>
14 #include <linux/if_ether.h>
15 #include <linux/ieee80211.h>
16 #include <linux/nl80211.h>
17 #include <linux/rtnetlink.h>
18 #include <linux/netlink.h>
19 #include <linux/nospec.h>
20 #include <linux/etherdevice.h>
21 #include <net/net_namespace.h>
22 #include <net/genetlink.h>
23 #include <net/cfg80211.h>
25 #include <net/inet_connection_sock.h>
31 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
32 struct genl_info
*info
,
33 struct cfg80211_crypto_settings
*settings
,
36 /* the netlink family */
37 static struct genl_family nl80211_fam
;
39 /* multicast groups */
40 enum nl80211_multicast_groups
{
43 NL80211_MCGRP_REGULATORY
,
47 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
50 static const struct genl_multicast_group nl80211_mcgrps
[] = {
51 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
52 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
53 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
54 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
55 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
56 [NL80211_MCGRP_NAN
] = { .name
= NL80211_MULTICAST_GROUP_NAN
},
57 #ifdef CONFIG_NL80211_TESTMODE
58 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
62 /* returns ERR_PTR values */
63 static struct wireless_dev
*
64 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
66 struct cfg80211_registered_device
*rdev
;
67 struct wireless_dev
*result
= NULL
;
68 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
69 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
76 if (!have_ifidx
&& !have_wdev_id
)
77 return ERR_PTR(-EINVAL
);
80 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
82 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
83 wiphy_idx
= wdev_id
>> 32;
86 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
87 struct wireless_dev
*wdev
;
89 if (wiphy_net(&rdev
->wiphy
) != netns
)
92 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
95 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
96 if (have_ifidx
&& wdev
->netdev
&&
97 wdev
->netdev
->ifindex
== ifidx
) {
101 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
113 return ERR_PTR(-ENODEV
);
116 static struct cfg80211_registered_device
*
117 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
119 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
120 struct net_device
*netdev
;
124 if (!attrs
[NL80211_ATTR_WIPHY
] &&
125 !attrs
[NL80211_ATTR_IFINDEX
] &&
126 !attrs
[NL80211_ATTR_WDEV
])
127 return ERR_PTR(-EINVAL
);
129 if (attrs
[NL80211_ATTR_WIPHY
])
130 rdev
= cfg80211_rdev_by_wiphy_idx(
131 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
133 if (attrs
[NL80211_ATTR_WDEV
]) {
134 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
135 struct wireless_dev
*wdev
;
138 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
140 /* make sure wdev exists */
141 list_for_each_entry(wdev
, &tmp
->wiphy
.wdev_list
, list
) {
142 if (wdev
->identifier
!= (u32
)wdev_id
)
151 if (rdev
&& tmp
!= rdev
)
152 return ERR_PTR(-EINVAL
);
157 if (attrs
[NL80211_ATTR_IFINDEX
]) {
158 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
160 netdev
= __dev_get_by_index(netns
, ifindex
);
162 if (netdev
->ieee80211_ptr
)
164 netdev
->ieee80211_ptr
->wiphy
);
168 /* not wireless device -- return error */
170 return ERR_PTR(-EINVAL
);
172 /* mismatch -- return error */
173 if (rdev
&& tmp
!= rdev
)
174 return ERR_PTR(-EINVAL
);
181 return ERR_PTR(-ENODEV
);
183 if (netns
!= wiphy_net(&rdev
->wiphy
))
184 return ERR_PTR(-ENODEV
);
190 * This function returns a pointer to the driver
191 * that the genl_info item that is passed refers to.
193 * The result of this can be a PTR_ERR and hence must
194 * be checked with IS_ERR() for errors.
196 static struct cfg80211_registered_device
*
197 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
199 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
202 /* policy for the attributes */
203 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
204 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
205 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
207 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
209 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
210 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
211 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
212 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
213 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
215 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
216 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
217 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
218 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
219 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
220 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
222 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
226 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
227 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
229 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
230 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
231 .len
= WLAN_MAX_KEY_LEN
},
232 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
233 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
235 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
236 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
238 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
239 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
240 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
241 .len
= IEEE80211_MAX_DATA_LEN
},
242 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
243 .len
= IEEE80211_MAX_DATA_LEN
},
244 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
245 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
246 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
247 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
248 .len
= NL80211_MAX_SUPP_RATES
},
249 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
250 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
252 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
253 .len
= IEEE80211_MAX_MESH_ID_LEN
},
254 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
256 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
257 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
259 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
260 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
261 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
262 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
263 .len
= NL80211_MAX_SUPP_RATES
},
264 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
266 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
267 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
269 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
271 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
273 .len
= IEEE80211_MAX_DATA_LEN
},
274 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
275 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
277 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
278 .len
= IEEE80211_MAX_SSID_LEN
},
279 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
280 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
281 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
282 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
283 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
284 [NL80211_ATTR_STA_FLAGS2
] = {
285 .len
= sizeof(struct nl80211_sta_flag_update
),
287 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
288 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
289 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
290 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
291 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
292 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
293 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
294 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
295 [NL80211_ATTR_PMKID
] = { .len
= WLAN_PMKID_LEN
},
296 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
297 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
298 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
299 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
300 .len
= IEEE80211_MAX_DATA_LEN
},
301 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
302 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
303 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
304 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
305 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
306 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
307 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
308 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
309 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
312 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
313 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
314 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
315 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
316 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
317 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
318 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
319 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
321 .len
= IEEE80211_MAX_DATA_LEN
},
322 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
323 .len
= IEEE80211_MAX_DATA_LEN
},
324 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
325 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
326 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
327 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
328 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
329 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
330 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
331 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
332 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
333 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
334 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
335 .len
= IEEE80211_MAX_DATA_LEN
},
336 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
337 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
338 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
339 .len
= NL80211_HT_CAPABILITY_LEN
341 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
342 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
343 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
344 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
345 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
346 [NL80211_ATTR_AUTH_DATA
] = { .type
= NLA_BINARY
, },
347 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
348 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
349 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
350 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
351 [NL80211_ATTR_LOCAL_MESH_POWER_MODE
] = {. type
= NLA_U32
},
352 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
353 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
354 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
355 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
356 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
357 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
358 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
359 .len
= NL80211_VHT_CAPABILITY_LEN
,
361 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
362 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
363 .len
= IEEE80211_MAX_DATA_LEN
},
364 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
365 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
366 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
367 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
368 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
369 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
370 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
371 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
372 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
373 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
374 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
375 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
376 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
377 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
378 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
379 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
380 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
381 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
382 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
383 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
384 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
385 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
386 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
387 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
388 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
389 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
390 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
391 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
392 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
393 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
394 [NL80211_ATTR_PBSS
] = { .type
= NLA_FLAG
},
395 [NL80211_ATTR_BSS_SELECT
] = { .type
= NLA_NESTED
},
396 [NL80211_ATTR_STA_SUPPORT_P2P_PS
] = { .type
= NLA_U8
},
397 [NL80211_ATTR_MU_MIMO_GROUP_DATA
] = {
398 .len
= VHT_MUMIMO_GROUPS_DATA_LEN
400 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
] = { .len
= ETH_ALEN
},
401 [NL80211_ATTR_NAN_MASTER_PREF
] = { .type
= NLA_U8
},
402 [NL80211_ATTR_BANDS
] = { .type
= NLA_U32
},
403 [NL80211_ATTR_NAN_FUNC
] = { .type
= NLA_NESTED
},
404 [NL80211_ATTR_FILS_KEK
] = { .type
= NLA_BINARY
,
405 .len
= FILS_MAX_KEK_LEN
},
406 [NL80211_ATTR_FILS_NONCES
] = { .len
= 2 * FILS_NONCE_LEN
},
407 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
] = { .type
= NLA_FLAG
, },
408 [NL80211_ATTR_BSSID
] = { .len
= ETH_ALEN
},
409 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] = { .type
= NLA_S8
},
410 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
] = {
411 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
413 [NL80211_ATTR_TIMEOUT_REASON
] = { .type
= NLA_U32
},
414 [NL80211_ATTR_FILS_ERP_USERNAME
] = { .type
= NLA_BINARY
,
415 .len
= FILS_ERP_MAX_USERNAME_LEN
},
416 [NL80211_ATTR_FILS_ERP_REALM
] = { .type
= NLA_BINARY
,
417 .len
= FILS_ERP_MAX_REALM_LEN
},
418 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] = { .type
= NLA_U16
},
419 [NL80211_ATTR_FILS_ERP_RRK
] = { .type
= NLA_BINARY
,
420 .len
= FILS_ERP_MAX_RRK_LEN
},
421 [NL80211_ATTR_FILS_CACHE_ID
] = { .len
= 2 },
422 [NL80211_ATTR_PMK
] = { .type
= NLA_BINARY
, .len
= PMK_MAX_LEN
},
423 [NL80211_ATTR_SCHED_SCAN_MULTI
] = { .type
= NLA_FLAG
},
426 /* policy for the key attributes */
427 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
428 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
429 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
430 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
431 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
432 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
433 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
434 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
435 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
438 /* policy for the key default flags */
439 static const struct nla_policy
440 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
441 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
442 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
446 /* policy for WoWLAN attributes */
447 static const struct nla_policy
448 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
449 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
450 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
451 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
452 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
453 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
454 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
455 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
456 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
457 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
458 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
461 static const struct nla_policy
462 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
463 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
464 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
465 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
466 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
467 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
468 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
469 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
470 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
472 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
473 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
475 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
476 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
477 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
479 #endif /* CONFIG_PM */
481 /* policy for coalesce rule attributes */
482 static const struct nla_policy
483 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
484 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
485 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
486 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
489 /* policy for GTK rekey offload attributes */
490 static const struct nla_policy
491 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
492 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
493 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
494 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
497 static const struct nla_policy
498 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
499 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
500 .len
= IEEE80211_MAX_SSID_LEN
},
501 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
] = { .len
= ETH_ALEN
},
502 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
505 static const struct nla_policy
506 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
507 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
508 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
511 static const struct nla_policy
512 nl80211_bss_select_policy
[NL80211_BSS_SELECT_ATTR_MAX
+ 1] = {
513 [NL80211_BSS_SELECT_ATTR_RSSI
] = { .type
= NLA_FLAG
},
514 [NL80211_BSS_SELECT_ATTR_BAND_PREF
] = { .type
= NLA_U32
},
515 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
] = {
516 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
520 /* policy for NAN function attributes */
521 static const struct nla_policy
522 nl80211_nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
523 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
524 [NL80211_NAN_FUNC_SERVICE_ID
] = {
525 .len
= NL80211_NAN_FUNC_SERVICE_ID_LEN
},
526 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
527 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
528 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
529 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
530 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
531 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { .len
= ETH_ALEN
},
532 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
533 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
534 [NL80211_NAN_FUNC_SERVICE_INFO
] = { .type
= NLA_BINARY
,
535 .len
= NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN
},
536 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
537 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
538 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
539 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
540 [NL80211_NAN_FUNC_TERM_REASON
] = { .type
= NLA_U8
},
543 /* policy for Service Response Filter attributes */
544 static const struct nla_policy
545 nl80211_nan_srf_policy
[NL80211_NAN_SRF_ATTR_MAX
+ 1] = {
546 [NL80211_NAN_SRF_INCLUDE
] = { .type
= NLA_FLAG
},
547 [NL80211_NAN_SRF_BF
] = { .type
= NLA_BINARY
,
548 .len
= NL80211_NAN_FUNC_SRF_MAX_LEN
},
549 [NL80211_NAN_SRF_BF_IDX
] = { .type
= NLA_U8
},
550 [NL80211_NAN_SRF_MAC_ADDRS
] = { .type
= NLA_NESTED
},
553 /* policy for packet pattern attributes */
554 static const struct nla_policy
555 nl80211_packet_pattern_policy
[MAX_NL80211_PKTPAT
+ 1] = {
556 [NL80211_PKTPAT_MASK
] = { .type
= NLA_BINARY
, },
557 [NL80211_PKTPAT_PATTERN
] = { .type
= NLA_BINARY
, },
558 [NL80211_PKTPAT_OFFSET
] = { .type
= NLA_U32
},
561 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
562 struct netlink_callback
*cb
,
563 struct cfg80211_registered_device
**rdev
,
564 struct wireless_dev
**wdev
)
569 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
570 genl_family_attrbuf(&nl80211_fam
),
571 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
575 *wdev
= __cfg80211_wdev_from_attrs(
577 genl_family_attrbuf(&nl80211_fam
));
579 return PTR_ERR(*wdev
);
580 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
581 /* 0 is the first index - add 1 to parse only once */
582 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
583 cb
->args
[1] = (*wdev
)->identifier
;
585 /* subtract the 1 again here */
586 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
587 struct wireless_dev
*tmp
;
591 *rdev
= wiphy_to_rdev(wiphy
);
594 list_for_each_entry(tmp
, &(*rdev
)->wiphy
.wdev_list
, list
) {
595 if (tmp
->identifier
== cb
->args
[1]) {
609 static bool is_valid_ie_attr(const struct nlattr
*attr
)
617 pos
= nla_data(attr
);
638 /* message building helper */
639 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
642 /* since there is no private header just add the generic one */
643 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
646 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
647 struct ieee80211_channel
*chan
,
650 /* Some channels must be completely excluded from the
651 * list to protect old user-space tools from breaking
653 if (!large
&& chan
->flags
&
654 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
657 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
659 goto nla_put_failure
;
661 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
662 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
663 goto nla_put_failure
;
664 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
665 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
666 goto nla_put_failure
;
667 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
668 goto nla_put_failure
;
670 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
671 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
672 goto nla_put_failure
;
676 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
678 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
680 goto nla_put_failure
;
681 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
683 goto nla_put_failure
;
685 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
687 goto nla_put_failure
;
692 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
693 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
694 goto nla_put_failure
;
695 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
696 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
697 goto nla_put_failure
;
698 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
699 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
700 goto nla_put_failure
;
701 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
702 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
703 goto nla_put_failure
;
704 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
705 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
706 goto nla_put_failure
;
707 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
708 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
709 goto nla_put_failure
;
710 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
711 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
712 goto nla_put_failure
;
713 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
714 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
715 goto nla_put_failure
;
718 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
719 DBM_TO_MBM(chan
->max_power
)))
720 goto nla_put_failure
;
728 /* netlink command implementations */
735 bool def_uni
, def_multi
;
738 static int nl80211_parse_key_new(struct genl_info
*info
, struct nlattr
*key
,
741 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
742 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
743 nl80211_key_policy
, info
->extack
);
747 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
748 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
757 if (tb
[NL80211_KEY_IDX
])
758 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
760 if (tb
[NL80211_KEY_DATA
]) {
761 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
762 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
765 if (tb
[NL80211_KEY_SEQ
]) {
766 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
767 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
770 if (tb
[NL80211_KEY_CIPHER
])
771 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
773 if (tb
[NL80211_KEY_TYPE
]) {
774 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
775 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
776 return genl_err_attr(info
, -EINVAL
,
777 tb
[NL80211_KEY_TYPE
]);
780 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
781 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
783 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
784 tb
[NL80211_KEY_DEFAULT_TYPES
],
785 nl80211_key_default_policy
,
790 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
791 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
797 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
799 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
800 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
801 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
804 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
805 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
806 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
809 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
810 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
812 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
813 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
815 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
816 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
825 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
826 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
827 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
) {
828 GENL_SET_ERR_MSG(info
, "key type out of range");
833 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
834 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
835 int err
= nla_parse_nested(kdt
,
836 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
837 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
838 nl80211_key_default_policy
,
843 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
844 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
850 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
854 memset(k
, 0, sizeof(*k
));
858 if (info
->attrs
[NL80211_ATTR_KEY
])
859 err
= nl80211_parse_key_new(info
, info
->attrs
[NL80211_ATTR_KEY
], k
);
861 err
= nl80211_parse_key_old(info
, k
);
866 if (k
->def
&& k
->defmgmt
) {
867 GENL_SET_ERR_MSG(info
, "key with def && defmgmt is invalid");
872 if (k
->def_uni
|| !k
->def_multi
) {
873 GENL_SET_ERR_MSG(info
, "defmgmt key must be mcast");
880 if (k
->idx
< 4 || k
->idx
> 5) {
881 GENL_SET_ERR_MSG(info
,
882 "defmgmt key idx not 4 or 5");
886 if (k
->idx
< 0 || k
->idx
> 3) {
887 GENL_SET_ERR_MSG(info
, "def key idx not 0-3");
891 if (k
->idx
< 0 || k
->idx
> 5) {
892 GENL_SET_ERR_MSG(info
, "key idx not 0-5");
901 static struct cfg80211_cached_keys
*
902 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
903 struct genl_info
*info
, bool *no_ht
)
905 struct nlattr
*keys
= info
->attrs
[NL80211_ATTR_KEYS
];
906 struct key_parse parse
;
908 struct cfg80211_cached_keys
*result
;
909 int rem
, err
, def
= 0;
910 bool have_key
= false;
912 nla_for_each_nested(key
, keys
, rem
) {
920 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
922 return ERR_PTR(-ENOMEM
);
926 nla_for_each_nested(key
, keys
, rem
) {
927 memset(&parse
, 0, sizeof(parse
));
930 err
= nl80211_parse_key_new(info
, key
, &parse
);
936 if (parse
.idx
< 0 || parse
.idx
> 3) {
937 GENL_SET_ERR_MSG(info
, "key index out of range [0-3]");
942 GENL_SET_ERR_MSG(info
,
943 "only one key can be default");
947 result
->def
= parse
.idx
;
948 if (!parse
.def_uni
|| !parse
.def_multi
)
950 } else if (parse
.defmgmt
)
952 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
953 parse
.idx
, false, NULL
);
956 if (parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
957 parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
) {
958 GENL_SET_ERR_MSG(info
, "connect key must be WEP");
962 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
963 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
964 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
965 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
967 /* must be WEP key if we got here */
972 if (result
->def
< 0) {
974 GENL_SET_ERR_MSG(info
, "need a default/TX key");
984 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
986 ASSERT_WDEV_LOCK(wdev
);
988 switch (wdev
->iftype
) {
989 case NL80211_IFTYPE_AP
:
990 case NL80211_IFTYPE_AP_VLAN
:
991 case NL80211_IFTYPE_P2P_GO
:
992 case NL80211_IFTYPE_MESH_POINT
:
994 case NL80211_IFTYPE_ADHOC
:
995 case NL80211_IFTYPE_STATION
:
996 case NL80211_IFTYPE_P2P_CLIENT
:
997 if (!wdev
->current_bss
)
1000 case NL80211_IFTYPE_UNSPECIFIED
:
1001 case NL80211_IFTYPE_OCB
:
1002 case NL80211_IFTYPE_MONITOR
:
1003 case NL80211_IFTYPE_NAN
:
1004 case NL80211_IFTYPE_P2P_DEVICE
:
1005 case NL80211_IFTYPE_WDS
:
1006 case NUM_NL80211_IFTYPES
:
1013 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
1016 struct ieee80211_channel
*chan
;
1020 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
1021 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
1026 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
1028 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
1032 goto nla_put_failure
;
1036 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
1037 goto nla_put_failure
;
1042 nla_nest_end(msg
, nl_modes
);
1049 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
1050 struct sk_buff
*msg
,
1053 struct nlattr
*nl_combis
;
1056 nl_combis
= nla_nest_start(msg
,
1057 NL80211_ATTR_INTERFACE_COMBINATIONS
);
1059 goto nla_put_failure
;
1061 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
1062 const struct ieee80211_iface_combination
*c
;
1063 struct nlattr
*nl_combi
, *nl_limits
;
1065 c
= &wiphy
->iface_combinations
[i
];
1067 nl_combi
= nla_nest_start(msg
, i
+ 1);
1069 goto nla_put_failure
;
1071 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
1073 goto nla_put_failure
;
1075 for (j
= 0; j
< c
->n_limits
; j
++) {
1076 struct nlattr
*nl_limit
;
1078 nl_limit
= nla_nest_start(msg
, j
+ 1);
1080 goto nla_put_failure
;
1081 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
1083 goto nla_put_failure
;
1084 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
1085 c
->limits
[j
].types
))
1086 goto nla_put_failure
;
1087 nla_nest_end(msg
, nl_limit
);
1090 nla_nest_end(msg
, nl_limits
);
1092 if (c
->beacon_int_infra_match
&&
1093 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
1094 goto nla_put_failure
;
1095 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
1096 c
->num_different_channels
) ||
1097 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
1099 goto nla_put_failure
;
1101 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1102 c
->radar_detect_widths
) ||
1103 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1104 c
->radar_detect_regions
)))
1105 goto nla_put_failure
;
1106 if (c
->beacon_int_min_gcd
&&
1107 nla_put_u32(msg
, NL80211_IFACE_COMB_BI_MIN_GCD
,
1108 c
->beacon_int_min_gcd
))
1109 goto nla_put_failure
;
1111 nla_nest_end(msg
, nl_combi
);
1114 nla_nest_end(msg
, nl_combis
);
1122 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1123 struct sk_buff
*msg
)
1125 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1126 struct nlattr
*nl_tcp
;
1131 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1135 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1136 tcp
->data_payload_max
))
1139 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1140 tcp
->data_payload_max
))
1143 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1146 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1147 sizeof(*tcp
->tok
), tcp
->tok
))
1150 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1151 tcp
->data_interval_max
))
1154 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1155 tcp
->wake_payload_max
))
1158 nla_nest_end(msg
, nl_tcp
);
1162 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1163 struct cfg80211_registered_device
*rdev
,
1166 struct nlattr
*nl_wowlan
;
1168 if (!rdev
->wiphy
.wowlan
)
1171 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1175 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1176 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1177 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1178 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1179 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1180 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1181 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1182 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1183 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1184 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1185 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1186 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1187 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1188 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1189 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1190 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1193 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1194 struct nl80211_pattern_support pat
= {
1195 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1196 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1197 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1198 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1201 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1206 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1207 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1208 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1211 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1214 nla_nest_end(msg
, nl_wowlan
);
1220 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1221 struct cfg80211_registered_device
*rdev
)
1223 struct nl80211_coalesce_rule_support rule
;
1225 if (!rdev
->wiphy
.coalesce
)
1228 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1229 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1230 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1231 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1232 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1233 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1235 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1241 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1242 struct ieee80211_supported_band
*sband
)
1244 struct nlattr
*nl_rates
, *nl_rate
;
1245 struct ieee80211_rate
*rate
;
1249 if (sband
->ht_cap
.ht_supported
&&
1250 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1251 sizeof(sband
->ht_cap
.mcs
),
1252 &sband
->ht_cap
.mcs
) ||
1253 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1254 sband
->ht_cap
.cap
) ||
1255 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1256 sband
->ht_cap
.ampdu_factor
) ||
1257 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1258 sband
->ht_cap
.ampdu_density
)))
1262 if (sband
->vht_cap
.vht_supported
&&
1263 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1264 sizeof(sband
->vht_cap
.vht_mcs
),
1265 &sband
->vht_cap
.vht_mcs
) ||
1266 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1267 sband
->vht_cap
.cap
)))
1271 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1275 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1276 nl_rate
= nla_nest_start(msg
, i
);
1280 rate
= &sband
->bitrates
[i
];
1281 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1284 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1286 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1289 nla_nest_end(msg
, nl_rate
);
1292 nla_nest_end(msg
, nl_rates
);
1298 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1299 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1302 struct nlattr
*nl_ftypes
, *nl_ifs
;
1303 enum nl80211_iftype ift
;
1309 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1313 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1314 nl_ftypes
= nla_nest_start(msg
, ift
);
1318 stypes
= mgmt_stypes
[ift
].tx
;
1321 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1322 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1327 nla_nest_end(msg
, nl_ftypes
);
1330 nla_nest_end(msg
, nl_ifs
);
1332 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1336 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1337 nl_ftypes
= nla_nest_start(msg
, ift
);
1341 stypes
= mgmt_stypes
[ift
].rx
;
1344 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1345 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1350 nla_nest_end(msg
, nl_ftypes
);
1352 nla_nest_end(msg
, nl_ifs
);
1357 #define CMD(op, n) \
1359 if (rdev->ops->op) { \
1361 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1362 goto nla_put_failure; \
1366 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device
*rdev
,
1367 struct sk_buff
*msg
)
1372 * do *NOT* add anything into this function, new things need to be
1373 * advertised only to new versions of userspace that can deal with
1374 * the split (and they can't possibly care about new features...
1376 CMD(add_virtual_intf
, NEW_INTERFACE
);
1377 CMD(change_virtual_intf
, SET_INTERFACE
);
1378 CMD(add_key
, NEW_KEY
);
1379 CMD(start_ap
, START_AP
);
1380 CMD(add_station
, NEW_STATION
);
1381 CMD(add_mpath
, NEW_MPATH
);
1382 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1383 CMD(change_bss
, SET_BSS
);
1384 CMD(auth
, AUTHENTICATE
);
1385 CMD(assoc
, ASSOCIATE
);
1386 CMD(deauth
, DEAUTHENTICATE
);
1387 CMD(disassoc
, DISASSOCIATE
);
1388 CMD(join_ibss
, JOIN_IBSS
);
1389 CMD(join_mesh
, JOIN_MESH
);
1390 CMD(set_pmksa
, SET_PMKSA
);
1391 CMD(del_pmksa
, DEL_PMKSA
);
1392 CMD(flush_pmksa
, FLUSH_PMKSA
);
1393 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1394 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1395 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1396 CMD(mgmt_tx
, FRAME
);
1397 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1398 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1400 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1401 goto nla_put_failure
;
1403 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1404 rdev
->ops
->join_mesh
) {
1406 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1407 goto nla_put_failure
;
1409 CMD(set_wds_peer
, SET_WDS_PEER
);
1410 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1411 CMD(tdls_mgmt
, TDLS_MGMT
);
1412 CMD(tdls_oper
, TDLS_OPER
);
1414 if (rdev
->wiphy
.max_sched_scan_reqs
)
1415 CMD(sched_scan_start
, START_SCHED_SCAN
);
1416 CMD(probe_client
, PROBE_CLIENT
);
1417 CMD(set_noack_map
, SET_NOACK_MAP
);
1418 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1420 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1421 goto nla_put_failure
;
1423 CMD(start_p2p_device
, START_P2P_DEVICE
);
1424 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1425 #ifdef CONFIG_NL80211_TESTMODE
1426 CMD(testmode_cmd
, TESTMODE
);
1429 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1431 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1432 goto nla_put_failure
;
1435 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1437 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1438 goto nla_put_failure
;
1446 struct nl80211_dump_wiphy_state
{
1449 long split_start
, band_start
, chan_start
, capa_start
;
1453 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1454 enum nl80211_commands cmd
,
1455 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1456 int flags
, struct nl80211_dump_wiphy_state
*state
)
1459 struct nlattr
*nl_bands
, *nl_band
;
1460 struct nlattr
*nl_freqs
, *nl_freq
;
1461 struct nlattr
*nl_cmds
;
1462 enum nl80211_band band
;
1463 struct ieee80211_channel
*chan
;
1465 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1466 rdev
->wiphy
.mgmt_stypes
;
1469 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1473 if (WARN_ON(!state
))
1476 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1477 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1478 wiphy_name(&rdev
->wiphy
)) ||
1479 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1480 cfg80211_rdev_list_generation
))
1481 goto nla_put_failure
;
1483 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1486 switch (state
->split_start
) {
1488 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1489 rdev
->wiphy
.retry_short
) ||
1490 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1491 rdev
->wiphy
.retry_long
) ||
1492 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1493 rdev
->wiphy
.frag_threshold
) ||
1494 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1495 rdev
->wiphy
.rts_threshold
) ||
1496 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1497 rdev
->wiphy
.coverage_class
) ||
1498 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1499 rdev
->wiphy
.max_scan_ssids
) ||
1500 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1501 rdev
->wiphy
.max_sched_scan_ssids
) ||
1502 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1503 rdev
->wiphy
.max_scan_ie_len
) ||
1504 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1505 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1506 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1507 rdev
->wiphy
.max_match_sets
) ||
1508 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1509 rdev
->wiphy
.max_sched_scan_plans
) ||
1510 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1511 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1512 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1513 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1514 goto nla_put_failure
;
1516 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1517 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1518 goto nla_put_failure
;
1519 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1520 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1521 goto nla_put_failure
;
1522 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1523 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1524 goto nla_put_failure
;
1525 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1526 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1527 goto nla_put_failure
;
1528 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1529 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1530 goto nla_put_failure
;
1531 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1532 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1533 goto nla_put_failure
;
1534 state
->split_start
++;
1538 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1539 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1540 rdev
->wiphy
.cipher_suites
))
1541 goto nla_put_failure
;
1543 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1544 rdev
->wiphy
.max_num_pmkids
))
1545 goto nla_put_failure
;
1547 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1548 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1549 goto nla_put_failure
;
1551 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1552 rdev
->wiphy
.available_antennas_tx
) ||
1553 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1554 rdev
->wiphy
.available_antennas_rx
))
1555 goto nla_put_failure
;
1557 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1558 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1559 rdev
->wiphy
.probe_resp_offload
))
1560 goto nla_put_failure
;
1562 if ((rdev
->wiphy
.available_antennas_tx
||
1563 rdev
->wiphy
.available_antennas_rx
) &&
1564 rdev
->ops
->get_antenna
) {
1565 u32 tx_ant
= 0, rx_ant
= 0;
1568 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1570 if (nla_put_u32(msg
,
1571 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1574 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1576 goto nla_put_failure
;
1580 state
->split_start
++;
1584 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1585 rdev
->wiphy
.interface_modes
))
1586 goto nla_put_failure
;
1587 state
->split_start
++;
1591 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1593 goto nla_put_failure
;
1595 for (band
= state
->band_start
;
1596 band
< NUM_NL80211_BANDS
; band
++) {
1597 struct ieee80211_supported_band
*sband
;
1599 sband
= rdev
->wiphy
.bands
[band
];
1604 nl_band
= nla_nest_start(msg
, band
);
1606 goto nla_put_failure
;
1608 switch (state
->chan_start
) {
1610 if (nl80211_send_band_rateinfo(msg
, sband
))
1611 goto nla_put_failure
;
1612 state
->chan_start
++;
1616 /* add frequencies */
1617 nl_freqs
= nla_nest_start(
1618 msg
, NL80211_BAND_ATTR_FREQS
);
1620 goto nla_put_failure
;
1622 for (i
= state
->chan_start
- 1;
1623 i
< sband
->n_channels
;
1625 nl_freq
= nla_nest_start(msg
, i
);
1627 goto nla_put_failure
;
1629 chan
= &sband
->channels
[i
];
1631 if (nl80211_msg_put_channel(
1634 goto nla_put_failure
;
1636 nla_nest_end(msg
, nl_freq
);
1640 if (i
< sband
->n_channels
)
1641 state
->chan_start
= i
+ 2;
1643 state
->chan_start
= 0;
1644 nla_nest_end(msg
, nl_freqs
);
1647 nla_nest_end(msg
, nl_band
);
1650 /* start again here */
1651 if (state
->chan_start
)
1656 nla_nest_end(msg
, nl_bands
);
1658 if (band
< NUM_NL80211_BANDS
)
1659 state
->band_start
= band
+ 1;
1661 state
->band_start
= 0;
1663 /* if bands & channels are done, continue outside */
1664 if (state
->band_start
== 0 && state
->chan_start
== 0)
1665 state
->split_start
++;
1669 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1671 goto nla_put_failure
;
1673 i
= nl80211_add_commands_unsplit(rdev
, msg
);
1675 goto nla_put_failure
;
1677 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1678 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1679 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1680 CMD(channel_switch
, CHANNEL_SWITCH
);
1681 CMD(set_qos_map
, SET_QOS_MAP
);
1682 if (rdev
->wiphy
.features
&
1683 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1684 CMD(add_tx_ts
, ADD_TX_TS
);
1685 CMD(set_multicast_to_unicast
, SET_MULTICAST_TO_UNICAST
);
1686 CMD(update_connect_params
, UPDATE_CONNECT_PARAMS
);
1690 nla_nest_end(msg
, nl_cmds
);
1691 state
->split_start
++;
1695 if (rdev
->ops
->remain_on_channel
&&
1696 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1698 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1699 rdev
->wiphy
.max_remain_on_channel_duration
))
1700 goto nla_put_failure
;
1702 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1703 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1704 goto nla_put_failure
;
1706 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1707 goto nla_put_failure
;
1708 state
->split_start
++;
1713 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1714 goto nla_put_failure
;
1715 state
->split_start
++;
1719 state
->split_start
++;
1722 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1723 rdev
->wiphy
.software_iftypes
))
1724 goto nla_put_failure
;
1726 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1728 goto nla_put_failure
;
1730 state
->split_start
++;
1734 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1735 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1736 rdev
->wiphy
.ap_sme_capa
))
1737 goto nla_put_failure
;
1739 features
= rdev
->wiphy
.features
;
1741 * We can only add the per-channel limit information if the
1742 * dump is split, otherwise it makes it too big. Therefore
1743 * only advertise it in that case.
1746 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1747 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1748 goto nla_put_failure
;
1750 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1751 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1752 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1753 rdev
->wiphy
.ht_capa_mod_mask
))
1754 goto nla_put_failure
;
1756 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1757 rdev
->wiphy
.max_acl_mac_addrs
&&
1758 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1759 rdev
->wiphy
.max_acl_mac_addrs
))
1760 goto nla_put_failure
;
1763 * Any information below this point is only available to
1764 * applications that can deal with it being split. This
1765 * helps ensure that newly added capabilities don't break
1766 * older tools by overrunning their buffers.
1768 * We still increment split_start so that in the split
1769 * case we'll continue with more data in the next round,
1770 * but break unconditionally so unsplit data stops here.
1772 state
->split_start
++;
1775 if (rdev
->wiphy
.extended_capabilities
&&
1776 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1777 rdev
->wiphy
.extended_capabilities_len
,
1778 rdev
->wiphy
.extended_capabilities
) ||
1779 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1780 rdev
->wiphy
.extended_capabilities_len
,
1781 rdev
->wiphy
.extended_capabilities_mask
)))
1782 goto nla_put_failure
;
1784 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1785 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1786 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1787 rdev
->wiphy
.vht_capa_mod_mask
))
1788 goto nla_put_failure
;
1790 state
->split_start
++;
1793 if (nl80211_send_coalesce(msg
, rdev
))
1794 goto nla_put_failure
;
1796 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1797 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1798 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1799 goto nla_put_failure
;
1801 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1802 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1803 rdev
->wiphy
.max_ap_assoc_sta
))
1804 goto nla_put_failure
;
1806 state
->split_start
++;
1809 if (rdev
->wiphy
.n_vendor_commands
) {
1810 const struct nl80211_vendor_cmd_info
*info
;
1811 struct nlattr
*nested
;
1813 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1815 goto nla_put_failure
;
1817 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1818 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1819 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1820 goto nla_put_failure
;
1822 nla_nest_end(msg
, nested
);
1825 if (rdev
->wiphy
.n_vendor_events
) {
1826 const struct nl80211_vendor_cmd_info
*info
;
1827 struct nlattr
*nested
;
1829 nested
= nla_nest_start(msg
,
1830 NL80211_ATTR_VENDOR_EVENTS
);
1832 goto nla_put_failure
;
1834 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1835 info
= &rdev
->wiphy
.vendor_events
[i
];
1836 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1837 goto nla_put_failure
;
1839 nla_nest_end(msg
, nested
);
1841 state
->split_start
++;
1844 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1845 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1846 rdev
->wiphy
.max_num_csa_counters
))
1847 goto nla_put_failure
;
1849 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1850 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1851 goto nla_put_failure
;
1853 if (rdev
->wiphy
.max_sched_scan_reqs
&&
1854 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_MAX_REQS
,
1855 rdev
->wiphy
.max_sched_scan_reqs
))
1856 goto nla_put_failure
;
1858 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1859 sizeof(rdev
->wiphy
.ext_features
),
1860 rdev
->wiphy
.ext_features
))
1861 goto nla_put_failure
;
1863 if (rdev
->wiphy
.bss_select_support
) {
1864 struct nlattr
*nested
;
1865 u32 bss_select_support
= rdev
->wiphy
.bss_select_support
;
1867 nested
= nla_nest_start(msg
, NL80211_ATTR_BSS_SELECT
);
1869 goto nla_put_failure
;
1872 while (bss_select_support
) {
1873 if ((bss_select_support
& 1) &&
1874 nla_put_flag(msg
, i
))
1875 goto nla_put_failure
;
1877 bss_select_support
>>= 1;
1879 nla_nest_end(msg
, nested
);
1882 state
->split_start
++;
1885 if (rdev
->wiphy
.num_iftype_ext_capab
&&
1886 rdev
->wiphy
.iftype_ext_capab
) {
1887 struct nlattr
*nested_ext_capab
, *nested
;
1889 nested
= nla_nest_start(msg
,
1890 NL80211_ATTR_IFTYPE_EXT_CAPA
);
1892 goto nla_put_failure
;
1894 for (i
= state
->capa_start
;
1895 i
< rdev
->wiphy
.num_iftype_ext_capab
; i
++) {
1896 const struct wiphy_iftype_ext_capab
*capab
;
1898 capab
= &rdev
->wiphy
.iftype_ext_capab
[i
];
1900 nested_ext_capab
= nla_nest_start(msg
, i
);
1901 if (!nested_ext_capab
||
1902 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
1904 nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1905 capab
->extended_capabilities_len
,
1906 capab
->extended_capabilities
) ||
1907 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1908 capab
->extended_capabilities_len
,
1909 capab
->extended_capabilities_mask
))
1910 goto nla_put_failure
;
1912 nla_nest_end(msg
, nested_ext_capab
);
1916 nla_nest_end(msg
, nested
);
1917 if (i
< rdev
->wiphy
.num_iftype_ext_capab
) {
1918 state
->capa_start
= i
+ 1;
1923 if (nla_put_u32(msg
, NL80211_ATTR_BANDS
,
1924 rdev
->wiphy
.nan_supported_bands
))
1925 goto nla_put_failure
;
1928 state
->split_start
= 0;
1932 genlmsg_end(msg
, hdr
);
1936 genlmsg_cancel(msg
, hdr
);
1940 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1941 struct netlink_callback
*cb
,
1942 struct nl80211_dump_wiphy_state
*state
)
1944 struct nlattr
**tb
= genl_family_attrbuf(&nl80211_fam
);
1945 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, tb
,
1946 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
1947 /* ignore parse errors for backward compatibility */
1951 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1952 if (tb
[NL80211_ATTR_WIPHY
])
1953 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1954 if (tb
[NL80211_ATTR_WDEV
])
1955 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1956 if (tb
[NL80211_ATTR_IFINDEX
]) {
1957 struct net_device
*netdev
;
1958 struct cfg80211_registered_device
*rdev
;
1959 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1961 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1964 if (netdev
->ieee80211_ptr
) {
1965 rdev
= wiphy_to_rdev(
1966 netdev
->ieee80211_ptr
->wiphy
);
1967 state
->filter_wiphy
= rdev
->wiphy_idx
;
1974 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1977 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1978 struct cfg80211_registered_device
*rdev
;
1982 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1987 state
->filter_wiphy
= -1;
1988 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1994 cb
->args
[0] = (long)state
;
1997 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1998 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2000 if (++idx
<= state
->start
)
2002 if (state
->filter_wiphy
!= -1 &&
2003 state
->filter_wiphy
!= rdev
->wiphy_idx
)
2005 /* attempt to fit multiple wiphy data chunks into the skb */
2007 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
2009 NETLINK_CB(cb
->skb
).portid
,
2011 NLM_F_MULTI
, state
);
2014 * If sending the wiphy data didn't fit (ENOBUFS
2015 * or EMSGSIZE returned), this SKB is still
2016 * empty (so it's not too big because another
2017 * wiphy dataset is already in the skb) and
2018 * we've not tried to adjust the dump allocation
2019 * yet ... then adjust the alloc size to be
2020 * bigger, and return 1 but with the empty skb.
2021 * This results in an empty message being RX'ed
2022 * in userspace, but that is ignored.
2024 * We can then retry with the larger buffer.
2026 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
2027 !skb
->len
&& !state
->split
&&
2028 cb
->min_dump_alloc
< 4096) {
2029 cb
->min_dump_alloc
= 4096;
2030 state
->split_start
= 0;
2037 } while (state
->split_start
> 0);
2047 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
2049 kfree((void *)cb
->args
[0]);
2053 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2055 struct sk_buff
*msg
;
2056 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2057 struct nl80211_dump_wiphy_state state
= {};
2059 msg
= nlmsg_new(4096, GFP_KERNEL
);
2063 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
2064 info
->snd_portid
, info
->snd_seq
, 0,
2070 return genlmsg_reply(msg
, info
);
2073 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
2074 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
2075 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
2076 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
2077 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
2078 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
2081 static int parse_txq_params(struct nlattr
*tb
[],
2082 struct ieee80211_txq_params
*txq_params
)
2086 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
2087 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
2088 !tb
[NL80211_TXQ_ATTR_AIFS
])
2091 ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
2092 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
2093 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
2094 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
2095 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
2097 if (ac
>= NL80211_NUM_ACS
)
2099 txq_params
->ac
= array_index_nospec(ac
, NL80211_NUM_ACS
);
2103 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
2106 * You can only set the channel explicitly for WDS interfaces,
2107 * all others have their channel managed via their respective
2108 * "establish a connection" command (connect, join, ...)
2110 * For AP/GO and mesh mode, the channel can be set with the
2111 * channel userspace API, but is only stored and passed to the
2112 * low-level driver when the AP starts or the mesh is joined.
2113 * This is for backward compatibility, userspace can also give
2114 * the channel in the start-ap or join-mesh commands instead.
2116 * Monitors are special as they are normally slaved to
2117 * whatever else is going on, so they have their own special
2118 * operation to set the monitor channel if possible.
2121 wdev
->iftype
== NL80211_IFTYPE_AP
||
2122 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
2123 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
2124 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
2127 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
2128 struct genl_info
*info
,
2129 struct cfg80211_chan_def
*chandef
)
2133 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
2136 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
2138 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
2139 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
2140 chandef
->center_freq1
= control_freq
;
2141 chandef
->center_freq2
= 0;
2143 /* Primary channel not allowed */
2144 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
2147 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2148 enum nl80211_channel_type chantype
;
2150 chantype
= nla_get_u32(
2151 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2154 case NL80211_CHAN_NO_HT
:
2155 case NL80211_CHAN_HT20
:
2156 case NL80211_CHAN_HT40PLUS
:
2157 case NL80211_CHAN_HT40MINUS
:
2158 cfg80211_chandef_create(chandef
, chandef
->chan
,
2160 /* user input for center_freq is incorrect */
2161 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
] &&
2162 chandef
->center_freq1
!= nla_get_u32(
2163 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]))
2165 /* center_freq2 must be zero */
2166 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
] &&
2167 nla_get_u32(info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]))
2173 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
2175 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
2176 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
2177 chandef
->center_freq1
=
2179 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
2180 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
2181 chandef
->center_freq2
=
2183 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
2186 if (!cfg80211_chandef_valid(chandef
))
2189 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
2190 IEEE80211_CHAN_DISABLED
))
2193 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
2194 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
2195 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
2201 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
2202 struct net_device
*dev
,
2203 struct genl_info
*info
)
2205 struct cfg80211_chan_def chandef
;
2207 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
2208 struct wireless_dev
*wdev
= NULL
;
2211 wdev
= dev
->ieee80211_ptr
;
2212 if (!nl80211_can_set_dev_channel(wdev
))
2215 iftype
= wdev
->iftype
;
2217 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2222 case NL80211_IFTYPE_AP
:
2223 case NL80211_IFTYPE_P2P_GO
:
2224 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2229 if (wdev
->beacon_interval
) {
2230 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2231 !(rdev
->wiphy
.features
&
2232 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2237 /* Only allow dynamic channel width changes */
2238 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2242 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2246 wdev
->preset_chandef
= chandef
;
2249 case NL80211_IFTYPE_MESH_POINT
:
2250 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2252 case NL80211_IFTYPE_MONITOR
:
2253 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2262 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2264 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2265 struct net_device
*netdev
= info
->user_ptr
[1];
2267 return __nl80211_set_channel(rdev
, netdev
, info
);
2270 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2272 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2273 struct net_device
*dev
= info
->user_ptr
[1];
2274 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2277 if (!info
->attrs
[NL80211_ATTR_MAC
])
2280 if (netif_running(dev
))
2283 if (!rdev
->ops
->set_wds_peer
)
2286 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2289 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2290 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2293 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2295 struct cfg80211_registered_device
*rdev
;
2296 struct net_device
*netdev
= NULL
;
2297 struct wireless_dev
*wdev
;
2298 int result
= 0, rem_txq_params
= 0;
2299 struct nlattr
*nl_txq_params
;
2301 u8 retry_short
= 0, retry_long
= 0;
2302 u32 frag_threshold
= 0, rts_threshold
= 0;
2303 u8 coverage_class
= 0;
2308 * Try to find the wiphy and netdev. Normally this
2309 * function shouldn't need the netdev, but this is
2310 * done for backward compatibility -- previously
2311 * setting the channel was done per wiphy, but now
2312 * it is per netdev. Previous userland like hostapd
2313 * also passed a netdev to set_wiphy, so that it is
2314 * possible to let that go to the right netdev!
2317 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2318 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2320 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2321 if (netdev
&& netdev
->ieee80211_ptr
)
2322 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2328 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2331 return PTR_ERR(rdev
);
2336 wdev
= netdev
->ieee80211_ptr
;
2339 * end workaround code, by now the rdev is available
2340 * and locked, and wdev may or may not be NULL.
2343 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2344 result
= cfg80211_dev_rename(
2345 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2350 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2351 struct ieee80211_txq_params txq_params
;
2352 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2354 if (!rdev
->ops
->set_txq_params
)
2360 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2361 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2364 if (!netif_running(netdev
))
2367 nla_for_each_nested(nl_txq_params
,
2368 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2370 result
= nla_parse_nested(tb
, NL80211_TXQ_ATTR_MAX
,
2376 result
= parse_txq_params(tb
, &txq_params
);
2380 result
= rdev_set_txq_params(rdev
, netdev
,
2387 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2388 result
= __nl80211_set_channel(
2390 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2396 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2397 struct wireless_dev
*txp_wdev
= wdev
;
2398 enum nl80211_tx_power_setting type
;
2401 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2404 if (!rdev
->ops
->set_tx_power
)
2407 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2408 type
= nla_get_u32(info
->attrs
[idx
]);
2410 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2411 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2414 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2415 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2416 mbm
= nla_get_u32(info
->attrs
[idx
]);
2419 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2424 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2425 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2428 if ((!rdev
->wiphy
.available_antennas_tx
&&
2429 !rdev
->wiphy
.available_antennas_rx
) ||
2430 !rdev
->ops
->set_antenna
)
2433 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2434 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2436 /* reject antenna configurations which don't match the
2437 * available antenna masks, except for the "all" mask */
2438 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2439 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2442 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2443 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2445 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2452 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2453 retry_short
= nla_get_u8(
2454 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2455 if (retry_short
== 0)
2458 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2461 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2462 retry_long
= nla_get_u8(
2463 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2464 if (retry_long
== 0)
2467 changed
|= WIPHY_PARAM_RETRY_LONG
;
2470 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2471 frag_threshold
= nla_get_u32(
2472 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2473 if (frag_threshold
< 256)
2476 if (frag_threshold
!= (u32
) -1) {
2478 * Fragments (apart from the last one) are required to
2479 * have even length. Make the fragmentation code
2480 * simpler by stripping LSB should someone try to use
2481 * odd threshold value.
2483 frag_threshold
&= ~0x1;
2485 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2488 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2489 rts_threshold
= nla_get_u32(
2490 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2491 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2494 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2495 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2498 coverage_class
= nla_get_u8(
2499 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2500 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2503 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2504 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2507 changed
|= WIPHY_PARAM_DYN_ACK
;
2511 u8 old_retry_short
, old_retry_long
;
2512 u32 old_frag_threshold
, old_rts_threshold
;
2513 u8 old_coverage_class
;
2515 if (!rdev
->ops
->set_wiphy_params
)
2518 old_retry_short
= rdev
->wiphy
.retry_short
;
2519 old_retry_long
= rdev
->wiphy
.retry_long
;
2520 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2521 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2522 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2524 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2525 rdev
->wiphy
.retry_short
= retry_short
;
2526 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2527 rdev
->wiphy
.retry_long
= retry_long
;
2528 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2529 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2530 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2531 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2532 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2533 rdev
->wiphy
.coverage_class
= coverage_class
;
2535 result
= rdev_set_wiphy_params(rdev
, changed
);
2537 rdev
->wiphy
.retry_short
= old_retry_short
;
2538 rdev
->wiphy
.retry_long
= old_retry_long
;
2539 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2540 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2541 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2548 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2550 return (u64
)wdev
->identifier
|
2551 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2554 static int nl80211_send_chandef(struct sk_buff
*msg
,
2555 const struct cfg80211_chan_def
*chandef
)
2557 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2560 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2561 chandef
->chan
->center_freq
))
2563 switch (chandef
->width
) {
2564 case NL80211_CHAN_WIDTH_20_NOHT
:
2565 case NL80211_CHAN_WIDTH_20
:
2566 case NL80211_CHAN_WIDTH_40
:
2567 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2568 cfg80211_get_chandef_type(chandef
)))
2574 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2576 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2578 if (chandef
->center_freq2
&&
2579 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2584 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2585 struct cfg80211_registered_device
*rdev
,
2586 struct wireless_dev
*wdev
, bool removal
)
2588 struct net_device
*dev
= wdev
->netdev
;
2589 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2593 cmd
= NL80211_CMD_DEL_INTERFACE
;
2595 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2600 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2601 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2602 goto nla_put_failure
;
2604 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2605 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2606 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
2607 NL80211_ATTR_PAD
) ||
2608 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2609 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2610 rdev
->devlist_generation
^
2611 (cfg80211_rdev_list_generation
<< 2)))
2612 goto nla_put_failure
;
2614 if (rdev
->ops
->get_channel
) {
2616 struct cfg80211_chan_def chandef
;
2618 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2620 if (nl80211_send_chandef(msg
, &chandef
))
2621 goto nla_put_failure
;
2625 if (rdev
->ops
->get_tx_power
) {
2628 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2630 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2632 goto nla_put_failure
;
2636 switch (wdev
->iftype
) {
2637 case NL80211_IFTYPE_AP
:
2638 if (wdev
->ssid_len
&&
2639 nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2640 goto nla_put_failure_locked
;
2642 case NL80211_IFTYPE_STATION
:
2643 case NL80211_IFTYPE_P2P_CLIENT
:
2644 case NL80211_IFTYPE_ADHOC
: {
2646 if (!wdev
->current_bss
)
2649 ssid_ie
= ieee80211_bss_get_ie(&wdev
->current_bss
->pub
,
2652 nla_put(msg
, NL80211_ATTR_SSID
, ssid_ie
[1], ssid_ie
+ 2))
2653 goto nla_put_failure_rcu_locked
;
2663 genlmsg_end(msg
, hdr
);
2666 nla_put_failure_rcu_locked
:
2668 nla_put_failure_locked
:
2671 genlmsg_cancel(msg
, hdr
);
2675 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2679 int wp_start
= cb
->args
[0];
2680 int if_start
= cb
->args
[1];
2681 int filter_wiphy
= -1;
2682 struct cfg80211_registered_device
*rdev
;
2683 struct wireless_dev
*wdev
;
2688 struct nl80211_dump_wiphy_state state
= {
2692 ret
= nl80211_dump_wiphy_parse(skb
, cb
, &state
);
2696 filter_wiphy
= state
.filter_wiphy
;
2699 * if filtering, set cb->args[2] to +1 since 0 is the default
2700 * value needed to determine that parsing is necessary.
2702 if (filter_wiphy
>= 0)
2703 cb
->args
[2] = filter_wiphy
+ 1;
2706 } else if (cb
->args
[2] > 0) {
2707 filter_wiphy
= cb
->args
[2] - 1;
2710 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2711 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2713 if (wp_idx
< wp_start
) {
2718 if (filter_wiphy
>= 0 && filter_wiphy
!= rdev
->wiphy_idx
)
2723 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
2724 if (if_idx
< if_start
) {
2728 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2729 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2730 rdev
, wdev
, false) < 0) {
2739 cb
->args
[0] = wp_idx
;
2740 cb
->args
[1] = if_idx
;
2749 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2751 struct sk_buff
*msg
;
2752 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2753 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2755 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2759 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2760 rdev
, wdev
, false) < 0) {
2765 return genlmsg_reply(msg
, info
);
2768 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2769 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2770 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2771 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2772 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2773 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2774 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2777 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2779 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2787 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
, nla
,
2788 mntr_flags_policy
, NULL
))
2791 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2793 *mntrflags
|= (1<<flag
);
2795 *mntrflags
|= MONITOR_FLAG_CHANGED
;
2800 static int nl80211_parse_mon_options(struct cfg80211_registered_device
*rdev
,
2801 enum nl80211_iftype type
,
2802 struct genl_info
*info
,
2803 struct vif_params
*params
)
2805 bool change
= false;
2808 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2809 if (type
!= NL80211_IFTYPE_MONITOR
)
2812 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2820 if (params
->flags
& MONITOR_FLAG_ACTIVE
&&
2821 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2824 if (info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]) {
2825 const u8
*mumimo_groups
;
2826 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2828 if (type
!= NL80211_IFTYPE_MONITOR
)
2831 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2835 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]);
2837 /* bits 0 and 63 are reserved and must be zero */
2838 if ((mumimo_groups
[0] & BIT(0)) ||
2839 (mumimo_groups
[VHT_MUMIMO_GROUPS_DATA_LEN
- 1] & BIT(7)))
2842 params
->vht_mumimo_groups
= mumimo_groups
;
2846 if (info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]) {
2847 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2849 if (type
!= NL80211_IFTYPE_MONITOR
)
2852 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2855 params
->vht_mumimo_follow_addr
=
2856 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]);
2860 return change
? 1 : 0;
2863 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2864 struct net_device
*netdev
, u8 use_4addr
,
2865 enum nl80211_iftype iftype
)
2868 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2874 case NL80211_IFTYPE_AP_VLAN
:
2875 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2878 case NL80211_IFTYPE_STATION
:
2879 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2889 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2891 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2892 struct vif_params params
;
2894 enum nl80211_iftype otype
, ntype
;
2895 struct net_device
*dev
= info
->user_ptr
[1];
2896 bool change
= false;
2898 memset(¶ms
, 0, sizeof(params
));
2900 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2902 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2903 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2906 if (ntype
> NL80211_IFTYPE_MAX
)
2910 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2911 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2913 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2915 if (netif_running(dev
))
2919 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2920 IEEE80211_MAX_MESH_ID_LEN
);
2921 wdev
->mesh_id_up_len
=
2922 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2923 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2924 wdev
->mesh_id_up_len
);
2928 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2929 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2931 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2935 params
.use_4addr
= -1;
2938 err
= nl80211_parse_mon_options(rdev
, ntype
, info
, ¶ms
);
2945 err
= cfg80211_change_iface(rdev
, dev
, ntype
, ¶ms
);
2949 if (!err
&& params
.use_4addr
!= -1)
2950 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2955 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2957 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2958 struct vif_params params
;
2959 struct wireless_dev
*wdev
;
2960 struct sk_buff
*msg
;
2962 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2964 /* to avoid failing a new interface creation due to pending removal */
2965 cfg80211_destroy_ifaces(rdev
);
2967 memset(¶ms
, 0, sizeof(params
));
2969 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2972 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2973 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2974 if (type
> NL80211_IFTYPE_MAX
)
2978 if (!rdev
->ops
->add_virtual_intf
||
2979 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2982 if ((type
== NL80211_IFTYPE_P2P_DEVICE
|| type
== NL80211_IFTYPE_NAN
||
2983 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
2984 info
->attrs
[NL80211_ATTR_MAC
]) {
2985 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2987 if (!is_valid_ether_addr(params
.macaddr
))
2988 return -EADDRNOTAVAIL
;
2991 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2992 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2993 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2998 err
= nl80211_parse_mon_options(rdev
, type
, info
, ¶ms
);
3002 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3006 wdev
= rdev_add_virtual_intf(rdev
,
3007 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
3008 NET_NAME_USER
, type
, ¶ms
);
3009 if (WARN_ON(!wdev
)) {
3012 } else if (IS_ERR(wdev
)) {
3014 return PTR_ERR(wdev
);
3017 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
3018 wdev
->owner_nlportid
= info
->snd_portid
;
3021 case NL80211_IFTYPE_MESH_POINT
:
3022 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
3025 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
3026 IEEE80211_MAX_MESH_ID_LEN
);
3027 wdev
->mesh_id_up_len
=
3028 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
3029 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
3030 wdev
->mesh_id_up_len
);
3033 case NL80211_IFTYPE_NAN
:
3034 case NL80211_IFTYPE_P2P_DEVICE
:
3036 * P2P Device and NAN do not have a netdev, so don't go
3037 * through the netdev notifier and must be added here
3039 mutex_init(&wdev
->mtx
);
3040 INIT_LIST_HEAD(&wdev
->event_list
);
3041 spin_lock_init(&wdev
->event_lock
);
3042 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
3043 spin_lock_init(&wdev
->mgmt_registrations_lock
);
3045 wdev
->identifier
= ++rdev
->wdev_id
;
3046 list_add_rcu(&wdev
->list
, &rdev
->wiphy
.wdev_list
);
3047 rdev
->devlist_generation
++;
3053 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3054 rdev
, wdev
, false) < 0) {
3060 * For wdevs which have no associated netdev object (e.g. of type
3061 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3062 * For all other types, the event will be generated from the
3066 nl80211_notify_iface(rdev
, wdev
, NL80211_CMD_NEW_INTERFACE
);
3068 return genlmsg_reply(msg
, info
);
3071 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3073 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3074 struct wireless_dev
*wdev
= info
->user_ptr
[1];
3076 if (!rdev
->ops
->del_virtual_intf
)
3080 * If we remove a wireless device without a netdev then clear
3081 * user_ptr[1] so that nl80211_post_doit won't dereference it
3082 * to check if it needs to do dev_put(). Otherwise it crashes
3083 * since the wdev has been freed, unlike with a netdev where
3084 * we need the dev_put() for the netdev to really be freed.
3087 info
->user_ptr
[1] = NULL
;
3089 return rdev_del_virtual_intf(rdev
, wdev
);
3092 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
3094 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3095 struct net_device
*dev
= info
->user_ptr
[1];
3098 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
3101 if (!rdev
->ops
->set_noack_map
)
3104 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
3106 return rdev_set_noack_map(rdev
, dev
, noack_map
);
3109 struct get_key_cookie
{
3110 struct sk_buff
*msg
;
3115 static void get_key_callback(void *c
, struct key_params
*params
)
3118 struct get_key_cookie
*cookie
= c
;
3121 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
3122 params
->key_len
, params
->key
)) ||
3124 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
3125 params
->seq_len
, params
->seq
)) ||
3127 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
3129 goto nla_put_failure
;
3131 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
3133 goto nla_put_failure
;
3136 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
3137 params
->key_len
, params
->key
)) ||
3139 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
3140 params
->seq_len
, params
->seq
)) ||
3142 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
3144 goto nla_put_failure
;
3146 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
3147 goto nla_put_failure
;
3149 nla_nest_end(cookie
->msg
, key
);
3156 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
3158 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3160 struct net_device
*dev
= info
->user_ptr
[1];
3162 const u8
*mac_addr
= NULL
;
3164 struct get_key_cookie cookie
= {
3168 struct sk_buff
*msg
;
3170 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
3171 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
3176 if (info
->attrs
[NL80211_ATTR_MAC
])
3177 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3179 pairwise
= !!mac_addr
;
3180 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
3181 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
3183 if (kt
>= NUM_NL80211_KEYTYPES
)
3185 if (kt
!= NL80211_KEYTYPE_GROUP
&&
3186 kt
!= NL80211_KEYTYPE_PAIRWISE
)
3188 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
3191 if (!rdev
->ops
->get_key
)
3194 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3197 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3201 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3202 NL80211_CMD_NEW_KEY
);
3204 goto nla_put_failure
;
3207 cookie
.idx
= key_idx
;
3209 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3210 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
3211 goto nla_put_failure
;
3213 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
3214 goto nla_put_failure
;
3216 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
3223 goto nla_put_failure
;
3225 genlmsg_end(msg
, hdr
);
3226 return genlmsg_reply(msg
, info
);
3235 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
3237 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3238 struct key_parse key
;
3240 struct net_device
*dev
= info
->user_ptr
[1];
3242 err
= nl80211_parse_key(info
, &key
);
3249 /* only support setting default key */
3250 if (!key
.def
&& !key
.defmgmt
)
3253 wdev_lock(dev
->ieee80211_ptr
);
3256 if (!rdev
->ops
->set_default_key
) {
3261 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3265 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
3266 key
.def_uni
, key
.def_multi
);
3271 #ifdef CONFIG_CFG80211_WEXT
3272 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
3275 if (key
.def_uni
|| !key
.def_multi
) {
3280 if (!rdev
->ops
->set_default_mgmt_key
) {
3285 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3289 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
3293 #ifdef CONFIG_CFG80211_WEXT
3294 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3299 wdev_unlock(dev
->ieee80211_ptr
);
3304 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3306 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3308 struct net_device
*dev
= info
->user_ptr
[1];
3309 struct key_parse key
;
3310 const u8
*mac_addr
= NULL
;
3312 err
= nl80211_parse_key(info
, &key
);
3319 if (info
->attrs
[NL80211_ATTR_MAC
])
3320 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3322 if (key
.type
== -1) {
3324 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3326 key
.type
= NL80211_KEYTYPE_GROUP
;
3330 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3331 key
.type
!= NL80211_KEYTYPE_GROUP
)
3334 if (!rdev
->ops
->add_key
)
3337 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3338 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3342 wdev_lock(dev
->ieee80211_ptr
);
3343 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3345 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3346 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3348 wdev_unlock(dev
->ieee80211_ptr
);
3353 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3355 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3357 struct net_device
*dev
= info
->user_ptr
[1];
3358 u8
*mac_addr
= NULL
;
3359 struct key_parse key
;
3361 err
= nl80211_parse_key(info
, &key
);
3365 if (info
->attrs
[NL80211_ATTR_MAC
])
3366 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3368 if (key
.type
== -1) {
3370 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3372 key
.type
= NL80211_KEYTYPE_GROUP
;
3376 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3377 key
.type
!= NL80211_KEYTYPE_GROUP
)
3380 if (!rdev
->ops
->del_key
)
3383 wdev_lock(dev
->ieee80211_ptr
);
3384 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3386 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3387 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3391 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3392 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3395 #ifdef CONFIG_CFG80211_WEXT
3397 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3398 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3399 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3400 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3403 wdev_unlock(dev
->ieee80211_ptr
);
3408 /* This function returns an error or the number of nested attributes */
3409 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3411 struct nlattr
*attr
;
3412 int n_entries
= 0, tmp
;
3414 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3415 if (nla_len(attr
) != ETH_ALEN
)
3425 * This function parses ACL information and allocates memory for ACL data.
3426 * On successful return, the calling function is responsible to free the
3427 * ACL buffer returned by this function.
3429 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3430 struct genl_info
*info
)
3432 enum nl80211_acl_policy acl_policy
;
3433 struct nlattr
*attr
;
3434 struct cfg80211_acl_data
*acl
;
3435 int i
= 0, n_entries
, tmp
;
3437 if (!wiphy
->max_acl_mac_addrs
)
3438 return ERR_PTR(-EOPNOTSUPP
);
3440 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3441 return ERR_PTR(-EINVAL
);
3443 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3444 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3445 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3446 return ERR_PTR(-EINVAL
);
3448 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3449 return ERR_PTR(-EINVAL
);
3451 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3453 return ERR_PTR(n_entries
);
3455 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3456 return ERR_PTR(-ENOTSUPP
);
3458 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3461 return ERR_PTR(-ENOMEM
);
3463 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3464 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3468 acl
->n_acl_entries
= n_entries
;
3469 acl
->acl_policy
= acl_policy
;
3474 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3476 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3477 struct net_device
*dev
= info
->user_ptr
[1];
3478 struct cfg80211_acl_data
*acl
;
3481 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3482 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3485 if (!dev
->ieee80211_ptr
->beacon_interval
)
3488 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3490 return PTR_ERR(acl
);
3492 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3499 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
3500 u8
*rates
, u8 rates_len
)
3505 for (i
= 0; i
< rates_len
; i
++) {
3506 int rate
= (rates
[i
] & 0x7f) * 5;
3509 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
3510 struct ieee80211_rate
*srate
=
3511 &sband
->bitrates
[ridx
];
3512 if (rate
== srate
->bitrate
) {
3517 if (ridx
== sband
->n_bitrates
)
3518 return 0; /* rate not found */
3524 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
3525 u8
*rates
, u8 rates_len
,
3526 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
3530 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
3532 for (i
= 0; i
< rates_len
; i
++) {
3535 ridx
= rates
[i
] / 8;
3536 rbit
= BIT(rates
[i
] % 8);
3538 /* check validity */
3539 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
3542 /* check availability */
3543 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
3552 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
3556 switch (vht_mcs_map
) {
3557 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
3559 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
3562 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
3565 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
3575 static void vht_build_mcs_mask(u16 vht_mcs_map
,
3576 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
3580 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
3581 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
3586 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
3587 struct nl80211_txrate_vht
*txrate
,
3588 u16 mcs
[NL80211_VHT_NSS_MAX
])
3590 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3591 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
3594 if (!sband
->vht_cap
.vht_supported
)
3597 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
3599 /* Build vht_mcs_mask from VHT capabilities */
3600 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
3602 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3603 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
3604 mcs
[i
] = txrate
->mcs
[i
];
3612 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
3613 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
3614 .len
= NL80211_MAX_SUPP_RATES
},
3615 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
3616 .len
= NL80211_MAX_SUPP_HT_RATES
},
3617 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
3618 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
3621 static int nl80211_parse_tx_bitrate_mask(struct genl_info
*info
,
3622 struct cfg80211_bitrate_mask
*mask
)
3624 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
3625 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3627 struct nlattr
*tx_rates
;
3628 struct ieee80211_supported_band
*sband
;
3631 memset(mask
, 0, sizeof(*mask
));
3632 /* Default to all rates enabled */
3633 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
3634 sband
= rdev
->wiphy
.bands
[i
];
3639 mask
->control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
3640 memcpy(mask
->control
[i
].ht_mcs
,
3641 sband
->ht_cap
.mcs
.rx_mask
,
3642 sizeof(mask
->control
[i
].ht_mcs
));
3644 if (!sband
->vht_cap
.vht_supported
)
3647 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3648 vht_build_mcs_mask(vht_tx_mcs_map
, mask
->control
[i
].vht_mcs
);
3651 /* if no rates are given set it back to the defaults */
3652 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
3655 /* The nested attribute uses enum nl80211_band as the index. This maps
3656 * directly to the enum nl80211_band values used in cfg80211.
3658 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
3659 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
3660 enum nl80211_band band
= nla_type(tx_rates
);
3663 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
3665 sband
= rdev
->wiphy
.bands
[band
];
3668 err
= nla_parse_nested(tb
, NL80211_TXRATE_MAX
, tx_rates
,
3669 nl80211_txattr_policy
, info
->extack
);
3672 if (tb
[NL80211_TXRATE_LEGACY
]) {
3673 mask
->control
[band
].legacy
= rateset_to_mask(
3675 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
3676 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
3677 if ((mask
->control
[band
].legacy
== 0) &&
3678 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
3681 if (tb
[NL80211_TXRATE_HT
]) {
3682 if (!ht_rateset_to_mask(
3684 nla_data(tb
[NL80211_TXRATE_HT
]),
3685 nla_len(tb
[NL80211_TXRATE_HT
]),
3686 mask
->control
[band
].ht_mcs
))
3689 if (tb
[NL80211_TXRATE_VHT
]) {
3690 if (!vht_set_mcs_mask(
3692 nla_data(tb
[NL80211_TXRATE_VHT
]),
3693 mask
->control
[band
].vht_mcs
))
3696 if (tb
[NL80211_TXRATE_GI
]) {
3697 mask
->control
[band
].gi
=
3698 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
3699 if (mask
->control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
3703 if (mask
->control
[band
].legacy
== 0) {
3704 /* don't allow empty legacy rates if HT or VHT
3705 * are not even supported.
3707 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
3708 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
3711 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3712 if (mask
->control
[band
].ht_mcs
[i
])
3715 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3716 if (mask
->control
[band
].vht_mcs
[i
])
3719 /* legacy and mcs rates may not be both empty */
3728 static int validate_beacon_tx_rate(struct cfg80211_registered_device
*rdev
,
3729 enum nl80211_band band
,
3730 struct cfg80211_bitrate_mask
*beacon_rate
)
3732 u32 count_ht
, count_vht
, i
;
3733 u32 rate
= beacon_rate
->control
[band
].legacy
;
3735 /* Allow only one rate */
3736 if (hweight32(rate
) > 1)
3740 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
3741 if (hweight8(beacon_rate
->control
[band
].ht_mcs
[i
]) > 1) {
3743 } else if (beacon_rate
->control
[band
].ht_mcs
[i
]) {
3748 if (count_ht
&& rate
)
3753 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3754 if (hweight16(beacon_rate
->control
[band
].vht_mcs
[i
]) > 1) {
3756 } else if (beacon_rate
->control
[band
].vht_mcs
[i
]) {
3761 if (count_vht
&& rate
)
3765 if ((count_ht
&& count_vht
) || (!rate
&& !count_ht
&& !count_vht
))
3769 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3770 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
))
3773 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3774 NL80211_EXT_FEATURE_BEACON_RATE_HT
))
3777 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3778 NL80211_EXT_FEATURE_BEACON_RATE_VHT
))
3784 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3785 struct cfg80211_beacon_data
*bcn
)
3787 bool haveinfo
= false;
3789 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3790 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3791 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3792 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3795 memset(bcn
, 0, sizeof(*bcn
));
3797 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3798 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3799 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3805 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3806 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3807 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3814 if (attrs
[NL80211_ATTR_IE
]) {
3815 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3816 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3819 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3820 bcn
->proberesp_ies
=
3821 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3822 bcn
->proberesp_ies_len
=
3823 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3826 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3827 bcn
->assocresp_ies
=
3828 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3829 bcn
->assocresp_ies_len
=
3830 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3833 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3834 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3835 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3841 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings
*params
,
3849 for (i
= 0; i
< rates
[1]; i
++) {
3850 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HT_PHY
)
3851 params
->ht_required
= true;
3852 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)
3853 params
->vht_required
= true;
3858 * Since the nl80211 API didn't include, from the beginning, attributes about
3859 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3860 * benefit of drivers that rebuild IEs in the firmware.
3862 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings
*params
)
3864 const struct cfg80211_beacon_data
*bcn
= ¶ms
->beacon
;
3865 size_t ies_len
= bcn
->tail_len
;
3866 const u8
*ies
= bcn
->tail
;
3870 rates
= cfg80211_find_ie(WLAN_EID_SUPP_RATES
, ies
, ies_len
);
3871 nl80211_check_ap_rate_selectors(params
, rates
);
3873 rates
= cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES
, ies
, ies_len
);
3874 nl80211_check_ap_rate_selectors(params
, rates
);
3876 cap
= cfg80211_find_ie(WLAN_EID_HT_CAPABILITY
, ies
, ies_len
);
3877 if (cap
&& cap
[1] >= sizeof(*params
->ht_cap
))
3878 params
->ht_cap
= (void *)(cap
+ 2);
3879 cap
= cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY
, ies
, ies_len
);
3880 if (cap
&& cap
[1] >= sizeof(*params
->vht_cap
))
3881 params
->vht_cap
= (void *)(cap
+ 2);
3884 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3885 struct cfg80211_ap_settings
*params
)
3887 struct wireless_dev
*wdev
;
3890 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
3891 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3892 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3895 if (!wdev
->preset_chandef
.chan
)
3898 params
->chandef
= wdev
->preset_chandef
;
3906 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3907 enum nl80211_auth_type auth_type
,
3908 enum nl80211_commands cmd
)
3910 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3914 case NL80211_CMD_AUTHENTICATE
:
3915 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3916 auth_type
== NL80211_AUTHTYPE_SAE
)
3918 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
3919 NL80211_EXT_FEATURE_FILS_STA
) &&
3920 (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
3921 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
3922 auth_type
== NL80211_AUTHTYPE_FILS_PK
))
3925 case NL80211_CMD_CONNECT
:
3926 /* SAE not supported yet */
3927 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3929 /* FILS with SK PFS or PK not supported yet */
3930 if (auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
3931 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
3933 if (!wiphy_ext_feature_isset(
3935 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
3936 auth_type
== NL80211_AUTHTYPE_FILS_SK
)
3939 case NL80211_CMD_START_AP
:
3940 /* SAE not supported yet */
3941 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3943 /* FILS not supported yet */
3944 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
3945 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
3946 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
3954 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3956 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3957 struct net_device
*dev
= info
->user_ptr
[1];
3958 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3959 struct cfg80211_ap_settings params
;
3962 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3963 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3966 if (!rdev
->ops
->start_ap
)
3969 if (wdev
->beacon_interval
)
3972 memset(¶ms
, 0, sizeof(params
));
3974 /* these are required for START_AP */
3975 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3976 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3977 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3980 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3984 params
.beacon_interval
=
3985 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3986 params
.dtim_period
=
3987 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3989 err
= cfg80211_validate_beacon_int(rdev
, dev
->ieee80211_ptr
->iftype
,
3990 params
.beacon_interval
);
3995 * In theory, some of these attributes should be required here
3996 * but since they were not used when the command was originally
3997 * added, keep them optional for old user space programs to let
3998 * them continue to work with drivers that do not need the
3999 * additional information -- drivers must check!
4001 if (info
->attrs
[NL80211_ATTR_SSID
]) {
4002 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4004 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4005 if (params
.ssid_len
== 0 ||
4006 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
4010 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
4011 params
.hidden_ssid
= nla_get_u32(
4012 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
4013 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
4014 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
4015 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
4019 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4021 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4022 params
.auth_type
= nla_get_u32(
4023 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4024 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
4025 NL80211_CMD_START_AP
))
4028 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4030 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
4031 NL80211_MAX_NR_CIPHER_SUITES
);
4035 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
4036 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
4038 params
.inactivity_timeout
= nla_get_u16(
4039 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
4042 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4043 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4045 params
.p2p_ctwindow
=
4046 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4047 if (params
.p2p_ctwindow
> 127)
4049 if (params
.p2p_ctwindow
!= 0 &&
4050 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4054 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4057 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4059 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4062 params
.p2p_opp_ps
= tmp
;
4063 if (params
.p2p_opp_ps
!= 0 &&
4064 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4068 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4069 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
4072 } else if (wdev
->preset_chandef
.chan
) {
4073 params
.chandef
= wdev
->preset_chandef
;
4074 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
4077 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
4081 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
4082 err
= nl80211_parse_tx_bitrate_mask(info
, ¶ms
.beacon_rate
);
4086 err
= validate_beacon_tx_rate(rdev
, params
.chandef
.chan
->band
,
4087 ¶ms
.beacon_rate
);
4092 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
4094 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
4095 switch (params
.smps_mode
) {
4096 case NL80211_SMPS_OFF
:
4098 case NL80211_SMPS_STATIC
:
4099 if (!(rdev
->wiphy
.features
&
4100 NL80211_FEATURE_STATIC_SMPS
))
4103 case NL80211_SMPS_DYNAMIC
:
4104 if (!(rdev
->wiphy
.features
&
4105 NL80211_FEATURE_DYNAMIC_SMPS
))
4112 params
.smps_mode
= NL80211_SMPS_OFF
;
4115 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
4116 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
4119 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
4120 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
4121 if (IS_ERR(params
.acl
))
4122 return PTR_ERR(params
.acl
);
4125 nl80211_calculate_ap_params(¶ms
);
4128 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
4130 wdev
->preset_chandef
= params
.chandef
;
4131 wdev
->beacon_interval
= params
.beacon_interval
;
4132 wdev
->chandef
= params
.chandef
;
4133 wdev
->ssid_len
= params
.ssid_len
;
4134 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
4143 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
4145 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4146 struct net_device
*dev
= info
->user_ptr
[1];
4147 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4148 struct cfg80211_beacon_data params
;
4151 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4152 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4155 if (!rdev
->ops
->change_beacon
)
4158 if (!wdev
->beacon_interval
)
4161 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
4166 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
4172 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
4174 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4175 struct net_device
*dev
= info
->user_ptr
[1];
4177 return cfg80211_stop_ap(rdev
, dev
, false);
4180 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
4181 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
4182 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
4183 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
4184 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
4185 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
4186 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
4189 static int parse_station_flags(struct genl_info
*info
,
4190 enum nl80211_iftype iftype
,
4191 struct station_parameters
*params
)
4193 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
4198 * Try parsing the new attribute first so userspace
4199 * can specify both for older kernels.
4201 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
4203 struct nl80211_sta_flag_update
*sta_flags
;
4205 sta_flags
= nla_data(nla
);
4206 params
->sta_flags_mask
= sta_flags
->mask
;
4207 params
->sta_flags_set
= sta_flags
->set
;
4208 params
->sta_flags_set
&= params
->sta_flags_mask
;
4209 if ((params
->sta_flags_mask
|
4210 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
4215 /* if present, parse the old attribute */
4217 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
4221 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
, nla
,
4222 sta_flags_policy
, info
->extack
))
4226 * Only allow certain flags for interface types so that
4227 * other attributes are silently ignored. Remember that
4228 * this is backward compatibility code with old userspace
4229 * and shouldn't be hit in other cases anyway.
4232 case NL80211_IFTYPE_AP
:
4233 case NL80211_IFTYPE_AP_VLAN
:
4234 case NL80211_IFTYPE_P2P_GO
:
4235 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4236 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4237 BIT(NL80211_STA_FLAG_WME
) |
4238 BIT(NL80211_STA_FLAG_MFP
);
4240 case NL80211_IFTYPE_P2P_CLIENT
:
4241 case NL80211_IFTYPE_STATION
:
4242 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4243 BIT(NL80211_STA_FLAG_TDLS_PEER
);
4245 case NL80211_IFTYPE_MESH_POINT
:
4246 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4247 BIT(NL80211_STA_FLAG_MFP
) |
4248 BIT(NL80211_STA_FLAG_AUTHORIZED
);
4253 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
4255 params
->sta_flags_set
|= (1<<flag
);
4257 /* no longer support new API additions in old API */
4258 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
4266 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
4269 struct nlattr
*rate
;
4272 enum nl80211_rate_info rate_flg
;
4274 rate
= nla_nest_start(msg
, attr
);
4278 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4279 bitrate
= cfg80211_calculate_bitrate(info
);
4280 /* report 16-bit bitrate only if we can */
4281 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
4283 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
4285 if (bitrate_compat
> 0 &&
4286 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
4290 case RATE_INFO_BW_5
:
4291 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
4293 case RATE_INFO_BW_10
:
4294 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
4299 case RATE_INFO_BW_20
:
4302 case RATE_INFO_BW_40
:
4303 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
4305 case RATE_INFO_BW_80
:
4306 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
4308 case RATE_INFO_BW_160
:
4309 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
4313 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
4316 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
4317 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
4319 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4320 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4322 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
4323 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
4325 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
4327 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4328 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4332 nla_nest_end(msg
, rate
);
4336 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
4345 attr
= nla_nest_start(msg
, id
);
4349 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
4350 if (!(mask
& BIT(i
)))
4353 if (nla_put_u8(msg
, i
, signal
[i
]))
4357 nla_nest_end(msg
, attr
);
4362 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
4364 struct cfg80211_registered_device
*rdev
,
4365 struct net_device
*dev
,
4366 const u8
*mac_addr
, struct station_info
*sinfo
)
4369 struct nlattr
*sinfoattr
, *bss_param
;
4371 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
4375 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4376 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
4377 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
4378 goto nla_put_failure
;
4380 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
4382 goto nla_put_failure
;
4384 #define PUT_SINFO(attr, memb, type) do { \
4385 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
4386 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4387 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4389 goto nla_put_failure; \
4391 #define PUT_SINFO_U64(attr, memb) do { \
4392 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4393 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4394 sinfo->memb, NL80211_STA_INFO_PAD)) \
4395 goto nla_put_failure; \
4398 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
4399 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
4401 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
4402 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
4403 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
4404 (u32
)sinfo
->rx_bytes
))
4405 goto nla_put_failure
;
4407 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
4408 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
4409 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
4410 (u32
)sinfo
->tx_bytes
))
4411 goto nla_put_failure
;
4413 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
4414 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
4415 PUT_SINFO(LLID
, llid
, u16
);
4416 PUT_SINFO(PLID
, plid
, u16
);
4417 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
4418 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
4420 switch (rdev
->wiphy
.signal_type
) {
4421 case CFG80211_SIGNAL_TYPE_MBM
:
4422 PUT_SINFO(SIGNAL
, signal
, u8
);
4423 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
4428 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
4429 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4430 sinfo
->chain_signal
,
4431 NL80211_STA_INFO_CHAIN_SIGNAL
))
4432 goto nla_put_failure
;
4434 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
4435 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4436 sinfo
->chain_signal_avg
,
4437 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
4438 goto nla_put_failure
;
4440 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
4441 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
4442 NL80211_STA_INFO_TX_BITRATE
))
4443 goto nla_put_failure
;
4445 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
4446 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
4447 NL80211_STA_INFO_RX_BITRATE
))
4448 goto nla_put_failure
;
4451 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
4452 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
4453 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
4454 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
4455 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
4456 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
4457 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
4458 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
4459 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
4461 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
4462 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
4464 goto nla_put_failure
;
4466 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
4467 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
4468 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
4469 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
4470 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
4471 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
4472 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
4473 sinfo
->bss_param
.dtim_period
) ||
4474 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
4475 sinfo
->bss_param
.beacon_interval
))
4476 goto nla_put_failure
;
4478 nla_nest_end(msg
, bss_param
);
4480 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
4481 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
4482 sizeof(struct nl80211_sta_flag_update
),
4484 goto nla_put_failure
;
4486 PUT_SINFO_U64(T_OFFSET
, t_offset
);
4487 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
4488 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
4489 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
4492 #undef PUT_SINFO_U64
4494 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TID_STATS
)) {
4495 struct nlattr
*tidsattr
;
4498 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
4500 goto nla_put_failure
;
4502 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
4503 struct cfg80211_tid_stats
*tidstats
;
4504 struct nlattr
*tidattr
;
4506 tidstats
= &sinfo
->pertid
[tid
];
4508 if (!tidstats
->filled
)
4511 tidattr
= nla_nest_start(msg
, tid
+ 1);
4513 goto nla_put_failure
;
4515 #define PUT_TIDVAL_U64(attr, memb) do { \
4516 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
4517 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4518 tidstats->memb, NL80211_TID_STATS_PAD)) \
4519 goto nla_put_failure; \
4522 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
4523 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
4524 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
4525 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
4527 #undef PUT_TIDVAL_U64
4528 nla_nest_end(msg
, tidattr
);
4531 nla_nest_end(msg
, tidsattr
);
4534 nla_nest_end(msg
, sinfoattr
);
4536 if (sinfo
->assoc_req_ies_len
&&
4537 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
4538 sinfo
->assoc_req_ies
))
4539 goto nla_put_failure
;
4541 genlmsg_end(msg
, hdr
);
4545 genlmsg_cancel(msg
, hdr
);
4549 static int nl80211_dump_station(struct sk_buff
*skb
,
4550 struct netlink_callback
*cb
)
4552 struct station_info sinfo
;
4553 struct cfg80211_registered_device
*rdev
;
4554 struct wireless_dev
*wdev
;
4555 u8 mac_addr
[ETH_ALEN
];
4556 int sta_idx
= cb
->args
[2];
4560 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4564 if (!wdev
->netdev
) {
4569 if (!rdev
->ops
->dump_station
) {
4575 memset(&sinfo
, 0, sizeof(sinfo
));
4576 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
4583 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
4584 NETLINK_CB(cb
->skb
).portid
,
4585 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4586 rdev
, wdev
->netdev
, mac_addr
,
4594 cb
->args
[2] = sta_idx
;
4602 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
4604 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4605 struct net_device
*dev
= info
->user_ptr
[1];
4606 struct station_info sinfo
;
4607 struct sk_buff
*msg
;
4608 u8
*mac_addr
= NULL
;
4611 memset(&sinfo
, 0, sizeof(sinfo
));
4613 if (!info
->attrs
[NL80211_ATTR_MAC
])
4616 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4618 if (!rdev
->ops
->get_station
)
4621 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
4625 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4629 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
4630 info
->snd_portid
, info
->snd_seq
, 0,
4631 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
4636 return genlmsg_reply(msg
, info
);
4639 int cfg80211_check_station_change(struct wiphy
*wiphy
,
4640 struct station_parameters
*params
,
4641 enum cfg80211_station_type statype
)
4643 if (params
->listen_interval
!= -1 &&
4644 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4647 if (params
->support_p2p_ps
!= -1 &&
4648 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4652 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
4653 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4656 /* When you run into this, adjust the code below for the new flag */
4657 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4660 case CFG80211_STA_MESH_PEER_KERNEL
:
4661 case CFG80211_STA_MESH_PEER_USER
:
4663 * No ignoring the TDLS flag here -- the userspace mesh
4664 * code doesn't have the bug of including TDLS in the
4667 if (params
->sta_flags_mask
&
4668 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4669 BIT(NL80211_STA_FLAG_MFP
) |
4670 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4673 case CFG80211_STA_TDLS_PEER_SETUP
:
4674 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4675 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4677 /* ignore since it can't change */
4678 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4681 /* disallow mesh-specific things */
4682 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4684 if (params
->local_pm
)
4686 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4690 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4691 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4692 /* TDLS can't be set, ... */
4693 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4696 * ... but don't bother the driver with it. This works around
4697 * a hostapd/wpa_supplicant issue -- it always includes the
4698 * TLDS_PEER flag in the mask even for AP mode.
4700 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4703 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4704 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4705 /* reject other things that can't change */
4706 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4708 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4710 if (params
->supported_rates
)
4712 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4716 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4717 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4723 case CFG80211_STA_AP_MLME_CLIENT
:
4724 /* Use this only for authorizing/unauthorizing a station */
4725 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4728 case CFG80211_STA_AP_CLIENT
:
4729 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4730 /* accept only the listed bits */
4731 if (params
->sta_flags_mask
&
4732 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4733 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4734 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4735 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4736 BIT(NL80211_STA_FLAG_WME
) |
4737 BIT(NL80211_STA_FLAG_MFP
)))
4740 /* but authenticated/associated only if driver handles it */
4741 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4742 params
->sta_flags_mask
&
4743 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4744 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4747 case CFG80211_STA_IBSS
:
4748 case CFG80211_STA_AP_STA
:
4749 /* reject any changes other than AUTHORIZED */
4750 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4753 case CFG80211_STA_TDLS_PEER_SETUP
:
4754 /* reject any changes other than AUTHORIZED or WME */
4755 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4756 BIT(NL80211_STA_FLAG_WME
)))
4758 /* force (at least) rates when authorizing */
4759 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4760 !params
->supported_rates
)
4763 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4764 /* reject any changes */
4766 case CFG80211_STA_MESH_PEER_KERNEL
:
4767 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4770 case CFG80211_STA_MESH_PEER_USER
:
4771 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4772 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4778 * Older kernel versions ignored this attribute entirely, so don't
4779 * reject attempts to update it but mark it as unused instead so the
4780 * driver won't look at the data.
4782 if (statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
&&
4783 statype
!= CFG80211_STA_TDLS_PEER_SETUP
)
4784 params
->opmode_notif_used
= false;
4788 EXPORT_SYMBOL(cfg80211_check_station_change
);
4791 * Get vlan interface making sure it is running and on the right wiphy.
4793 static struct net_device
*get_vlan(struct genl_info
*info
,
4794 struct cfg80211_registered_device
*rdev
)
4796 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4797 struct net_device
*v
;
4803 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4805 return ERR_PTR(-ENODEV
);
4807 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4812 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4813 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4814 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4819 if (!netif_running(v
)) {
4827 return ERR_PTR(ret
);
4830 static const struct nla_policy
4831 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
4832 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
4833 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
4836 static int nl80211_parse_sta_wme(struct genl_info
*info
,
4837 struct station_parameters
*params
)
4839 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
4843 /* parse WME attributes if present */
4844 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
4847 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
4848 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
4849 nl80211_sta_wme_policy
, info
->extack
);
4853 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4854 params
->uapsd_queues
= nla_get_u8(
4855 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4856 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4859 if (tb
[NL80211_STA_WME_MAX_SP
])
4860 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4862 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4865 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4870 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4871 struct station_parameters
*params
)
4873 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4874 params
->supported_channels
=
4875 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4876 params
->supported_channels_len
=
4877 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4879 * Need to include at least one (first channel, number of
4880 * channels) tuple for each subband, and must have proper
4881 * tuples for the rest of the data as well.
4883 if (params
->supported_channels_len
< 2)
4885 if (params
->supported_channels_len
% 2)
4889 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4890 params
->supported_oper_classes
=
4891 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4892 params
->supported_oper_classes_len
=
4893 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4895 * The value of the Length field of the Supported Operating
4896 * Classes element is between 2 and 253.
4898 if (params
->supported_oper_classes_len
< 2 ||
4899 params
->supported_oper_classes_len
> 253)
4905 static int nl80211_set_station_tdls(struct genl_info
*info
,
4906 struct station_parameters
*params
)
4909 /* Dummy STA entry gets updated once the peer capabilities are known */
4910 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4911 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4912 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4914 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4915 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4917 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4919 err
= nl80211_parse_sta_channel_info(info
, params
);
4923 return nl80211_parse_sta_wme(info
, params
);
4926 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4928 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4929 struct net_device
*dev
= info
->user_ptr
[1];
4930 struct station_parameters params
;
4934 memset(¶ms
, 0, sizeof(params
));
4936 if (!rdev
->ops
->change_station
)
4940 * AID and listen_interval properties can be set only for unassociated
4941 * station. Include these parameters here and will check them in
4942 * cfg80211_check_station_change().
4944 if (info
->attrs
[NL80211_ATTR_STA_AID
])
4945 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4947 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4948 params
.listen_interval
=
4949 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4951 params
.listen_interval
= -1;
4953 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
4956 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
4957 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
4960 params
.support_p2p_ps
= tmp
;
4962 params
.support_p2p_ps
= -1;
4965 if (!info
->attrs
[NL80211_ATTR_MAC
])
4968 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4970 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4971 params
.supported_rates
=
4972 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4973 params
.supported_rates_len
=
4974 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4977 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4979 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4980 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4983 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4985 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4986 params
.ext_capab_len
=
4987 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4990 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4993 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4994 params
.plink_action
=
4995 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4996 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
5000 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
5001 params
.plink_state
=
5002 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
5003 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
5005 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]) {
5006 params
.peer_aid
= nla_get_u16(
5007 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
5008 if (params
.peer_aid
> IEEE80211_MAX_AID
)
5011 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
5014 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
5015 enum nl80211_mesh_power_mode pm
= nla_get_u32(
5016 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
5018 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
5019 pm
> NL80211_MESH_POWER_MAX
)
5022 params
.local_pm
= pm
;
5025 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
5026 params
.opmode_notif_used
= true;
5027 params
.opmode_notif
=
5028 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
5031 /* Include parameters for TDLS peer (will check later) */
5032 err
= nl80211_set_station_tdls(info
, ¶ms
);
5036 params
.vlan
= get_vlan(info
, rdev
);
5037 if (IS_ERR(params
.vlan
))
5038 return PTR_ERR(params
.vlan
);
5040 switch (dev
->ieee80211_ptr
->iftype
) {
5041 case NL80211_IFTYPE_AP
:
5042 case NL80211_IFTYPE_AP_VLAN
:
5043 case NL80211_IFTYPE_P2P_GO
:
5044 case NL80211_IFTYPE_P2P_CLIENT
:
5045 case NL80211_IFTYPE_STATION
:
5046 case NL80211_IFTYPE_ADHOC
:
5047 case NL80211_IFTYPE_MESH_POINT
:
5054 /* driver will call cfg80211_check_station_change() */
5055 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
5059 dev_put(params
.vlan
);
5064 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
5066 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5068 struct net_device
*dev
= info
->user_ptr
[1];
5069 struct station_parameters params
;
5070 u8
*mac_addr
= NULL
;
5071 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5072 BIT(NL80211_STA_FLAG_ASSOCIATED
);
5074 memset(¶ms
, 0, sizeof(params
));
5076 if (!rdev
->ops
->add_station
)
5079 if (!info
->attrs
[NL80211_ATTR_MAC
])
5082 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
5085 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
5088 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
5089 !info
->attrs
[NL80211_ATTR_PEER_AID
])
5092 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5093 params
.supported_rates
=
5094 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5095 params
.supported_rates_len
=
5096 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5097 params
.listen_interval
=
5098 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
5100 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
5103 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
5104 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
5107 params
.support_p2p_ps
= tmp
;
5110 * if not specified, assume it's supported for P2P GO interface,
5111 * and is NOT supported for AP interface
5113 params
.support_p2p_ps
=
5114 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
5117 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
5118 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
5120 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
5121 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
5124 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
5126 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
5127 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
5130 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
5132 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5133 params
.ext_capab_len
=
5134 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5137 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
5139 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5141 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
5143 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
5145 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
5146 params
.opmode_notif_used
= true;
5147 params
.opmode_notif
=
5148 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
5151 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
5152 params
.plink_action
=
5153 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
5154 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
5158 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
5162 err
= nl80211_parse_sta_wme(info
, ¶ms
);
5166 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
5169 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5170 * as userspace might just pass through the capabilities from the IEs
5171 * directly, rather than enforcing this restriction and returning an
5172 * error in this case.
5174 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
5175 params
.ht_capa
= NULL
;
5176 params
.vht_capa
= NULL
;
5179 /* When you run into this, adjust the code below for the new flag */
5180 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
5182 switch (dev
->ieee80211_ptr
->iftype
) {
5183 case NL80211_IFTYPE_AP
:
5184 case NL80211_IFTYPE_AP_VLAN
:
5185 case NL80211_IFTYPE_P2P_GO
:
5186 /* ignore WME attributes if iface/sta is not capable */
5187 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
5188 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
5189 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5191 /* TDLS peers cannot be added */
5192 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5193 info
->attrs
[NL80211_ATTR_PEER_AID
])
5195 /* but don't bother the driver with it */
5196 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
5198 /* allow authenticated/associated only if driver handles it */
5199 if (!(rdev
->wiphy
.features
&
5200 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
5201 params
.sta_flags_mask
& auth_assoc
)
5204 /* Older userspace, or userspace wanting to be compatible with
5205 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5206 * and assoc flags in the mask, but assumes the station will be
5207 * added as associated anyway since this was the required driver
5208 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5210 * In order to not bother drivers with this quirk in the API
5211 * set the flags in both the mask and set for new stations in
5214 if (!(params
.sta_flags_mask
& auth_assoc
)) {
5215 params
.sta_flags_mask
|= auth_assoc
;
5216 params
.sta_flags_set
|= auth_assoc
;
5219 /* must be last in here for error handling */
5220 params
.vlan
= get_vlan(info
, rdev
);
5221 if (IS_ERR(params
.vlan
))
5222 return PTR_ERR(params
.vlan
);
5224 case NL80211_IFTYPE_MESH_POINT
:
5225 /* ignore uAPSD data */
5226 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5228 /* associated is disallowed */
5229 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
5231 /* TDLS peers cannot be added */
5232 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5233 info
->attrs
[NL80211_ATTR_PEER_AID
])
5236 case NL80211_IFTYPE_STATION
:
5237 case NL80211_IFTYPE_P2P_CLIENT
:
5238 /* ignore uAPSD data */
5239 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5241 /* these are disallowed */
5242 if (params
.sta_flags_mask
&
5243 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
5244 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
5246 /* Only TDLS peers can be added */
5247 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
5249 /* Can only add if TDLS ... */
5250 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
5252 /* ... with external setup is supported */
5253 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
5256 * Older wpa_supplicant versions always mark the TDLS peer
5257 * as authorized, but it shouldn't yet be.
5259 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
5265 /* be aware of params.vlan when changing code here */
5267 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
5270 dev_put(params
.vlan
);
5274 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
5276 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5277 struct net_device
*dev
= info
->user_ptr
[1];
5278 struct station_del_parameters params
;
5280 memset(¶ms
, 0, sizeof(params
));
5282 if (info
->attrs
[NL80211_ATTR_MAC
])
5283 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5285 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5286 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5287 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5288 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5291 if (!rdev
->ops
->del_station
)
5294 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
5296 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
5297 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
5298 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
5301 /* Default to Deauthentication frame */
5302 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
5305 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
5306 params
.reason_code
=
5307 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5308 if (params
.reason_code
== 0)
5309 return -EINVAL
; /* 0 is reserved */
5311 /* Default to reason code 2 */
5312 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
5315 return rdev_del_station(rdev
, dev
, ¶ms
);
5318 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5319 int flags
, struct net_device
*dev
,
5320 u8
*dst
, u8
*next_hop
,
5321 struct mpath_info
*pinfo
)
5324 struct nlattr
*pinfoattr
;
5326 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
5330 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5331 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
5332 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
5333 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
5334 goto nla_put_failure
;
5336 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
5338 goto nla_put_failure
;
5339 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
5340 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
5342 goto nla_put_failure
;
5343 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
5344 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
5345 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
5346 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
5348 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
5349 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
5351 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
5352 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
5354 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
5355 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
5356 pinfo
->discovery_timeout
)) ||
5357 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
5358 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
5359 pinfo
->discovery_retries
)))
5360 goto nla_put_failure
;
5362 nla_nest_end(msg
, pinfoattr
);
5364 genlmsg_end(msg
, hdr
);
5368 genlmsg_cancel(msg
, hdr
);
5372 static int nl80211_dump_mpath(struct sk_buff
*skb
,
5373 struct netlink_callback
*cb
)
5375 struct mpath_info pinfo
;
5376 struct cfg80211_registered_device
*rdev
;
5377 struct wireless_dev
*wdev
;
5379 u8 next_hop
[ETH_ALEN
];
5380 int path_idx
= cb
->args
[2];
5384 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5388 if (!rdev
->ops
->dump_mpath
) {
5393 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5399 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
5406 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5407 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5408 wdev
->netdev
, dst
, next_hop
,
5416 cb
->args
[2] = path_idx
;
5423 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5425 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5427 struct net_device
*dev
= info
->user_ptr
[1];
5428 struct mpath_info pinfo
;
5429 struct sk_buff
*msg
;
5431 u8 next_hop
[ETH_ALEN
];
5433 memset(&pinfo
, 0, sizeof(pinfo
));
5435 if (!info
->attrs
[NL80211_ATTR_MAC
])
5438 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5440 if (!rdev
->ops
->get_mpath
)
5443 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5446 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
5450 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5454 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5455 dev
, dst
, next_hop
, &pinfo
) < 0) {
5460 return genlmsg_reply(msg
, info
);
5463 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5465 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5466 struct net_device
*dev
= info
->user_ptr
[1];
5468 u8
*next_hop
= NULL
;
5470 if (!info
->attrs
[NL80211_ATTR_MAC
])
5473 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5476 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5477 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5479 if (!rdev
->ops
->change_mpath
)
5482 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5485 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
5488 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5490 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5491 struct net_device
*dev
= info
->user_ptr
[1];
5493 u8
*next_hop
= NULL
;
5495 if (!info
->attrs
[NL80211_ATTR_MAC
])
5498 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5501 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5502 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5504 if (!rdev
->ops
->add_mpath
)
5507 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5510 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
5513 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5515 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5516 struct net_device
*dev
= info
->user_ptr
[1];
5519 if (info
->attrs
[NL80211_ATTR_MAC
])
5520 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5522 if (!rdev
->ops
->del_mpath
)
5525 return rdev_del_mpath(rdev
, dev
, dst
);
5528 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
5530 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5532 struct net_device
*dev
= info
->user_ptr
[1];
5533 struct mpath_info pinfo
;
5534 struct sk_buff
*msg
;
5538 memset(&pinfo
, 0, sizeof(pinfo
));
5540 if (!info
->attrs
[NL80211_ATTR_MAC
])
5543 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5545 if (!rdev
->ops
->get_mpp
)
5548 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5551 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
5555 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5559 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5560 dev
, dst
, mpp
, &pinfo
) < 0) {
5565 return genlmsg_reply(msg
, info
);
5568 static int nl80211_dump_mpp(struct sk_buff
*skb
,
5569 struct netlink_callback
*cb
)
5571 struct mpath_info pinfo
;
5572 struct cfg80211_registered_device
*rdev
;
5573 struct wireless_dev
*wdev
;
5576 int path_idx
= cb
->args
[2];
5580 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5584 if (!rdev
->ops
->dump_mpp
) {
5589 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5595 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
5602 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5603 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5604 wdev
->netdev
, dst
, mpp
,
5612 cb
->args
[2] = path_idx
;
5619 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
5621 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5622 struct net_device
*dev
= info
->user_ptr
[1];
5623 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5624 struct bss_parameters params
;
5627 memset(¶ms
, 0, sizeof(params
));
5628 /* default to not changing parameters */
5629 params
.use_cts_prot
= -1;
5630 params
.use_short_preamble
= -1;
5631 params
.use_short_slot_time
= -1;
5632 params
.ap_isolate
= -1;
5633 params
.ht_opmode
= -1;
5634 params
.p2p_ctwindow
= -1;
5635 params
.p2p_opp_ps
= -1;
5637 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
5638 params
.use_cts_prot
=
5639 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
5640 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
5641 params
.use_short_preamble
=
5642 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
5643 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
5644 params
.use_short_slot_time
=
5645 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
5646 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5647 params
.basic_rates
=
5648 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5649 params
.basic_rates_len
=
5650 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5652 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
5653 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
5654 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
5656 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
5658 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
5659 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5661 params
.p2p_ctwindow
=
5662 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
5663 if (params
.p2p_ctwindow
< 0)
5665 if (params
.p2p_ctwindow
!= 0 &&
5666 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
5670 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
5673 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5675 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
5678 params
.p2p_opp_ps
= tmp
;
5679 if (params
.p2p_opp_ps
&&
5680 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
5684 if (!rdev
->ops
->change_bss
)
5687 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5688 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5692 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
5698 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5702 enum nl80211_user_reg_hint_type user_reg_hint_type
;
5706 * You should only get this when cfg80211 hasn't yet initialized
5707 * completely when built-in to the kernel right between the time
5708 * window between nl80211_init() and regulatory_init(), if that is
5711 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
5712 return -EINPROGRESS
;
5714 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
5715 user_reg_hint_type
=
5716 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
5718 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
5720 switch (user_reg_hint_type
) {
5721 case NL80211_USER_REG_HINT_USER
:
5722 case NL80211_USER_REG_HINT_CELL_BASE
:
5723 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5726 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5727 return regulatory_hint_user(data
, user_reg_hint_type
);
5728 case NL80211_USER_REG_HINT_INDOOR
:
5729 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
5730 owner_nlportid
= info
->snd_portid
;
5731 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
5737 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
5743 static int nl80211_reload_regdb(struct sk_buff
*skb
, struct genl_info
*info
)
5745 return reg_reload_regdb();
5748 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
5749 struct genl_info
*info
)
5751 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5752 struct net_device
*dev
= info
->user_ptr
[1];
5753 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5754 struct mesh_config cur_params
;
5757 struct nlattr
*pinfoattr
;
5758 struct sk_buff
*msg
;
5760 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5763 if (!rdev
->ops
->get_mesh_config
)
5767 /* If not connected, get default parameters */
5768 if (!wdev
->mesh_id_len
)
5769 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5771 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5777 /* Draw up a netlink message to send back */
5778 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5781 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5782 NL80211_CMD_GET_MESH_CONFIG
);
5785 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5787 goto nla_put_failure
;
5788 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5789 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5790 cur_params
.dot11MeshRetryTimeout
) ||
5791 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5792 cur_params
.dot11MeshConfirmTimeout
) ||
5793 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5794 cur_params
.dot11MeshHoldingTimeout
) ||
5795 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5796 cur_params
.dot11MeshMaxPeerLinks
) ||
5797 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5798 cur_params
.dot11MeshMaxRetries
) ||
5799 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5800 cur_params
.dot11MeshTTL
) ||
5801 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5802 cur_params
.element_ttl
) ||
5803 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5804 cur_params
.auto_open_plinks
) ||
5805 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5806 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5807 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5808 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5809 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5810 cur_params
.path_refresh_time
) ||
5811 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5812 cur_params
.min_discovery_timeout
) ||
5813 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5814 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5815 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5816 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5817 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5818 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5819 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5820 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5821 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5822 cur_params
.dot11MeshHWMPRootMode
) ||
5823 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5824 cur_params
.dot11MeshHWMPRannInterval
) ||
5825 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5826 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
5827 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
5828 cur_params
.dot11MeshForwarding
) ||
5829 nla_put_s32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5830 cur_params
.rssi_threshold
) ||
5831 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
5832 cur_params
.ht_opmode
) ||
5833 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5834 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
5835 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5836 cur_params
.dot11MeshHWMProotInterval
) ||
5837 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5838 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
5839 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
5840 cur_params
.power_mode
) ||
5841 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
5842 cur_params
.dot11MeshAwakeWindowDuration
) ||
5843 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5844 cur_params
.plink_timeout
))
5845 goto nla_put_failure
;
5846 nla_nest_end(msg
, pinfoattr
);
5847 genlmsg_end(msg
, hdr
);
5848 return genlmsg_reply(msg
, info
);
5851 genlmsg_cancel(msg
, hdr
);
5857 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
5858 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
5859 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
5860 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
5861 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
5862 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
5863 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
5864 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
5865 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
5866 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
5867 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
5868 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
5869 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
5870 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
5871 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
5872 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
5873 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
5874 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
5875 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
5876 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
5877 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
5878 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
5879 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
5880 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
5881 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
5882 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
5883 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
5884 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
5885 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
5888 static const struct nla_policy
5889 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
5890 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
5891 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
5892 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
5893 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
5894 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
5895 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
5896 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
5897 .len
= IEEE80211_MAX_DATA_LEN
},
5898 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
5901 static int nl80211_check_bool(const struct nlattr
*nla
, u8 min
, u8 max
, bool *out
)
5903 u8 val
= nla_get_u8(nla
);
5904 if (val
< min
|| val
> max
)
5910 static int nl80211_check_u8(const struct nlattr
*nla
, u8 min
, u8 max
, u8
*out
)
5912 u8 val
= nla_get_u8(nla
);
5913 if (val
< min
|| val
> max
)
5919 static int nl80211_check_u16(const struct nlattr
*nla
, u16 min
, u16 max
, u16
*out
)
5921 u16 val
= nla_get_u16(nla
);
5922 if (val
< min
|| val
> max
)
5928 static int nl80211_check_u32(const struct nlattr
*nla
, u32 min
, u32 max
, u32
*out
)
5930 u32 val
= nla_get_u32(nla
);
5931 if (val
< min
|| val
> max
)
5937 static int nl80211_check_s32(const struct nlattr
*nla
, s32 min
, s32 max
, s32
*out
)
5939 s32 val
= nla_get_s32(nla
);
5940 if (val
< min
|| val
> max
)
5946 static int nl80211_check_power_mode(const struct nlattr
*nla
,
5947 enum nl80211_mesh_power_mode min
,
5948 enum nl80211_mesh_power_mode max
,
5949 enum nl80211_mesh_power_mode
*out
)
5951 u32 val
= nla_get_u32(nla
);
5952 if (val
< min
|| val
> max
)
5958 static int nl80211_parse_mesh_config(struct genl_info
*info
,
5959 struct mesh_config
*cfg
,
5962 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
5966 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5969 if (fn(tb[attr], min, max, &cfg->param)) \
5971 mask |= (1 << (attr - 1)); \
5975 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
5977 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
5978 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
5979 nl80211_meshconf_params_policy
, info
->extack
))
5982 /* This makes sure that there aren't more than 32 mesh config
5983 * parameters (otherwise our bitfield scheme would not work.) */
5984 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
5986 /* Fill in the params struct */
5987 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
5988 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5990 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
5991 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5993 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
5994 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5996 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
5997 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5999 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
6000 mask
, NL80211_MESHCONF_MAX_RETRIES
,
6002 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
6003 mask
, NL80211_MESHCONF_TTL
, nl80211_check_u8
);
6004 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
6005 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
6007 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
6008 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
6009 nl80211_check_bool
);
6010 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
6012 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
6014 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
6015 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
6017 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
6018 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
6020 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
6021 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
6023 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
6025 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
6027 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
6029 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
6031 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
6033 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
6035 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6036 dot11MeshHWMPnetDiameterTraversalTime
,
6038 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
6040 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
6041 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
6043 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
6044 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
6046 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6047 dot11MeshGateAnnouncementProtocol
, 0, 1,
6048 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
6049 nl80211_check_bool
);
6050 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
6051 mask
, NL80211_MESHCONF_FORWARDING
,
6052 nl80211_check_bool
);
6053 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
6054 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
6057 * Check HT operation mode based on
6058 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
6060 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
6061 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
6063 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
6064 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
6065 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6068 if ((ht_opmode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
) &&
6069 (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6072 switch (ht_opmode
& IEEE80211_HT_OP_MODE_PROTECTION
) {
6073 case IEEE80211_HT_OP_MODE_PROTECTION_NONE
:
6074 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
6075 if (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
)
6078 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER
:
6079 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
6080 if (!(ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6084 cfg
->ht_opmode
= ht_opmode
;
6085 mask
|= (1 << (NL80211_MESHCONF_HT_OPMODE
- 1));
6087 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
6089 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
6091 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
6092 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
6094 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6095 dot11MeshHWMPconfirmationInterval
,
6097 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
6099 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
6100 NL80211_MESH_POWER_ACTIVE
,
6101 NL80211_MESH_POWER_MAX
,
6102 mask
, NL80211_MESHCONF_POWER_MODE
,
6103 nl80211_check_power_mode
);
6104 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
6106 NL80211_MESHCONF_AWAKE_WINDOW
, nl80211_check_u16
);
6107 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
6108 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
6115 #undef FILL_IN_MESH_PARAM_IF_SET
6118 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
6119 struct mesh_setup
*setup
)
6121 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6122 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
6124 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
6126 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
6127 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
6128 nl80211_mesh_setup_params_policy
, info
->extack
))
6131 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
6132 setup
->sync_method
=
6133 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
6134 IEEE80211_SYNC_METHOD_VENDOR
:
6135 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
6137 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
6138 setup
->path_sel_proto
=
6139 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
6140 IEEE80211_PATH_PROTOCOL_VENDOR
:
6141 IEEE80211_PATH_PROTOCOL_HWMP
;
6143 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
6144 setup
->path_metric
=
6145 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
6146 IEEE80211_PATH_METRIC_VENDOR
:
6147 IEEE80211_PATH_METRIC_AIRTIME
;
6149 if (tb
[NL80211_MESH_SETUP_IE
]) {
6150 struct nlattr
*ieattr
=
6151 tb
[NL80211_MESH_SETUP_IE
];
6152 if (!is_valid_ie_attr(ieattr
))
6154 setup
->ie
= nla_data(ieattr
);
6155 setup
->ie_len
= nla_len(ieattr
);
6157 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
6158 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
6160 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
6161 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
6162 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
6163 if (setup
->is_secure
)
6164 setup
->user_mpm
= true;
6166 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
6167 if (!setup
->user_mpm
)
6170 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
6176 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
6177 struct genl_info
*info
)
6179 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6180 struct net_device
*dev
= info
->user_ptr
[1];
6181 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6182 struct mesh_config cfg
;
6186 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6189 if (!rdev
->ops
->update_mesh_config
)
6192 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
6197 if (!wdev
->mesh_id_len
)
6201 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
6208 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
6209 struct sk_buff
*msg
)
6211 struct nlattr
*nl_reg_rules
;
6214 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
6215 (regdom
->dfs_region
&&
6216 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
6217 goto nla_put_failure
;
6219 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
6221 goto nla_put_failure
;
6223 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
6224 struct nlattr
*nl_reg_rule
;
6225 const struct ieee80211_reg_rule
*reg_rule
;
6226 const struct ieee80211_freq_range
*freq_range
;
6227 const struct ieee80211_power_rule
*power_rule
;
6228 unsigned int max_bandwidth_khz
;
6230 reg_rule
= ®dom
->reg_rules
[i
];
6231 freq_range
= ®_rule
->freq_range
;
6232 power_rule
= ®_rule
->power_rule
;
6234 nl_reg_rule
= nla_nest_start(msg
, i
);
6236 goto nla_put_failure
;
6238 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
6239 if (!max_bandwidth_khz
)
6240 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
6243 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
6245 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
6246 freq_range
->start_freq_khz
) ||
6247 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
6248 freq_range
->end_freq_khz
) ||
6249 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
6250 max_bandwidth_khz
) ||
6251 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
6252 power_rule
->max_antenna_gain
) ||
6253 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
6254 power_rule
->max_eirp
) ||
6255 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
6256 reg_rule
->dfs_cac_ms
))
6257 goto nla_put_failure
;
6259 nla_nest_end(msg
, nl_reg_rule
);
6262 nla_nest_end(msg
, nl_reg_rules
);
6269 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
6271 const struct ieee80211_regdomain
*regdom
= NULL
;
6272 struct cfg80211_registered_device
*rdev
;
6273 struct wiphy
*wiphy
= NULL
;
6274 struct sk_buff
*msg
;
6277 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6281 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6282 NL80211_CMD_GET_REG
);
6286 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
6289 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6292 return PTR_ERR(rdev
);
6295 wiphy
= &rdev
->wiphy
;
6296 self_managed
= wiphy
->regulatory_flags
&
6297 REGULATORY_WIPHY_SELF_MANAGED
;
6298 regdom
= get_wiphy_regdom(wiphy
);
6300 /* a self-managed-reg device must have a private regdom */
6301 if (WARN_ON(!regdom
&& self_managed
)) {
6307 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6308 goto nla_put_failure
;
6311 if (!wiphy
&& reg_last_request_cell_base() &&
6312 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6313 NL80211_USER_REG_HINT_CELL_BASE
))
6314 goto nla_put_failure
;
6319 regdom
= rcu_dereference(cfg80211_regdomain
);
6321 if (nl80211_put_regdom(regdom
, msg
))
6322 goto nla_put_failure_rcu
;
6326 genlmsg_end(msg
, hdr
);
6327 return genlmsg_reply(msg
, info
);
6329 nla_put_failure_rcu
:
6332 genlmsg_cancel(msg
, hdr
);
6338 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6339 u32 seq
, int flags
, struct wiphy
*wiphy
,
6340 const struct ieee80211_regdomain
*regdom
)
6342 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6343 NL80211_CMD_GET_REG
);
6348 genl_dump_check_consistent(cb
, hdr
);
6350 if (nl80211_put_regdom(regdom
, msg
))
6351 goto nla_put_failure
;
6353 if (!wiphy
&& reg_last_request_cell_base() &&
6354 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6355 NL80211_USER_REG_HINT_CELL_BASE
))
6356 goto nla_put_failure
;
6359 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6360 goto nla_put_failure
;
6362 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
6363 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
6364 goto nla_put_failure
;
6366 genlmsg_end(msg
, hdr
);
6370 genlmsg_cancel(msg
, hdr
);
6374 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
6375 struct netlink_callback
*cb
)
6377 const struct ieee80211_regdomain
*regdom
= NULL
;
6378 struct cfg80211_registered_device
*rdev
;
6379 int err
, reg_idx
, start
= cb
->args
[2];
6383 if (cfg80211_regdomain
&& start
== 0) {
6384 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6386 rtnl_dereference(cfg80211_regdomain
));
6391 /* the global regdom is idx 0 */
6393 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
6394 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
6398 if (++reg_idx
<= start
)
6401 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6402 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
6409 cb
->args
[2] = reg_idx
;
6416 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
6417 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
6418 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
6419 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
6420 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
6421 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
6422 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
6423 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
6424 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
6427 static int parse_reg_rule(struct nlattr
*tb
[],
6428 struct ieee80211_reg_rule
*reg_rule
)
6430 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
6431 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
6433 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
6435 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
6437 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
6439 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
6441 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
6444 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
6446 freq_range
->start_freq_khz
=
6447 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
6448 freq_range
->end_freq_khz
=
6449 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
6450 freq_range
->max_bandwidth_khz
=
6451 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
6453 power_rule
->max_eirp
=
6454 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
6456 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
6457 power_rule
->max_antenna_gain
=
6458 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
6460 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
6461 reg_rule
->dfs_cac_ms
=
6462 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
6467 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
6469 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
6470 struct nlattr
*nl_reg_rule
;
6472 int rem_reg_rules
, r
;
6473 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
6474 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
6475 struct ieee80211_regdomain
*rd
;
6477 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
6480 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
6483 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
6485 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
6486 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
6488 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6491 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
6495 if (!reg_is_valid_request(alpha2
))
6498 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
6499 num_rules
* sizeof(struct ieee80211_reg_rule
);
6501 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
6505 rd
->n_reg_rules
= num_rules
;
6506 rd
->alpha2
[0] = alpha2
[0];
6507 rd
->alpha2
[1] = alpha2
[1];
6510 * Disable DFS master mode if the DFS region was
6511 * not supported or known on this kernel.
6513 if (reg_supported_dfs_region(dfs_region
))
6514 rd
->dfs_region
= dfs_region
;
6516 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6518 r
= nla_parse_nested(tb
, NL80211_REG_RULE_ATTR_MAX
,
6519 nl_reg_rule
, reg_rule_policy
,
6523 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
6529 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
6535 /* set_regdom takes ownership of rd */
6536 return set_regdom(rd
, REGD_SOURCE_CRDA
);
6541 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
6543 static int validate_scan_freqs(struct nlattr
*freqs
)
6545 struct nlattr
*attr1
, *attr2
;
6546 int n_channels
= 0, tmp1
, tmp2
;
6548 nla_for_each_nested(attr1
, freqs
, tmp1
)
6549 if (nla_len(attr1
) != sizeof(u32
))
6552 nla_for_each_nested(attr1
, freqs
, tmp1
) {
6555 * Some hardware has a limited channel list for
6556 * scanning, and it is pretty much nonsensical
6557 * to scan for a channel twice, so disallow that
6558 * and don't require drivers to check that the
6559 * channel list they get isn't longer than what
6560 * they can scan, as long as they can scan all
6561 * the channels they registered at once.
6563 nla_for_each_nested(attr2
, freqs
, tmp2
)
6564 if (attr1
!= attr2
&&
6565 nla_get_u32(attr1
) == nla_get_u32(attr2
))
6572 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
6574 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
6577 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
6578 struct cfg80211_bss_selection
*bss_select
)
6580 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
6581 struct nlattr
*nest
;
6586 /* only process one nested attribute */
6587 nest
= nla_data(nla
);
6588 if (!nla_ok(nest
, nla_len(nest
)))
6591 err
= nla_parse_nested(attr
, NL80211_BSS_SELECT_ATTR_MAX
, nest
,
6592 nl80211_bss_select_policy
, NULL
);
6596 /* only one attribute may be given */
6597 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
6605 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
6607 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
6608 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
6610 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
6611 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
6612 bss_select
->param
.band_pref
=
6613 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
6614 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
6618 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
6619 struct nl80211_bss_select_rssi_adjust
*adj_param
;
6621 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
6622 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
6623 bss_select
->param
.adjust
.band
= adj_param
->band
;
6624 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
6625 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
6629 /* user-space did not provide behaviour attribute */
6630 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
6633 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
6639 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
6640 u8
*mac_addr
, u8
*mac_addr_mask
)
6644 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
6645 eth_zero_addr(mac_addr
);
6646 eth_zero_addr(mac_addr_mask
);
6648 mac_addr_mask
[0] = 0x3;
6653 /* need both or none */
6654 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
6657 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
6658 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
6660 /* don't allow or configure an mcast address */
6661 if (!is_multicast_ether_addr(mac_addr_mask
) ||
6662 is_multicast_ether_addr(mac_addr
))
6666 * allow users to pass a MAC address that has bits set outside
6667 * of the mask, but don't bother drivers with having to deal
6670 for (i
= 0; i
< ETH_ALEN
; i
++)
6671 mac_addr
[i
] &= mac_addr_mask
[i
];
6676 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev
*wdev
)
6678 ASSERT_WDEV_LOCK(wdev
);
6680 if (!cfg80211_beaconing_iface_active(wdev
))
6683 if (!(wdev
->chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
))
6686 return regulatory_pre_cac_allowed(wdev
->wiphy
);
6690 nl80211_check_scan_flags(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6691 void *request
, struct nlattr
**attrs
,
6694 u8
*mac_addr
, *mac_addr_mask
;
6696 enum nl80211_feature_flags randomness_flag
;
6698 if (!attrs
[NL80211_ATTR_SCAN_FLAGS
])
6701 if (is_sched_scan
) {
6702 struct cfg80211_sched_scan_request
*req
= request
;
6704 randomness_flag
= wdev
?
6705 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
:
6706 NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
6707 flags
= &req
->flags
;
6708 mac_addr
= req
->mac_addr
;
6709 mac_addr_mask
= req
->mac_addr_mask
;
6711 struct cfg80211_scan_request
*req
= request
;
6713 randomness_flag
= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
6714 flags
= &req
->flags
;
6715 mac_addr
= req
->mac_addr
;
6716 mac_addr_mask
= req
->mac_addr_mask
;
6719 *flags
= nla_get_u32(attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6721 if ((*flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6722 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
))
6725 if (*flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6728 if (!(wiphy
->features
& randomness_flag
) ||
6729 (wdev
&& wdev
->current_bss
))
6732 err
= nl80211_parse_random_mac(attrs
, mac_addr
, mac_addr_mask
);
6737 if ((*flags
& NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME
) &&
6738 !wiphy_ext_feature_isset(wiphy
,
6739 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME
))
6742 if ((*flags
& NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP
) &&
6743 !wiphy_ext_feature_isset(wiphy
,
6744 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP
))
6747 if ((*flags
& NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
) &&
6748 !wiphy_ext_feature_isset(wiphy
,
6749 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
))
6752 if ((*flags
& NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE
) &&
6753 !wiphy_ext_feature_isset(wiphy
,
6754 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE
))
6760 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6762 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6763 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6764 struct cfg80211_scan_request
*request
;
6765 struct nlattr
*attr
;
6766 struct wiphy
*wiphy
;
6767 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
6770 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6773 wiphy
= &rdev
->wiphy
;
6775 if (wdev
->iftype
== NL80211_IFTYPE_NAN
)
6778 if (!rdev
->ops
->scan
)
6781 if (rdev
->scan_req
|| rdev
->scan_msg
) {
6786 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6787 n_channels
= validate_scan_freqs(
6788 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6794 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6797 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
6798 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
6801 if (n_ssids
> wiphy
->max_scan_ssids
) {
6806 if (info
->attrs
[NL80211_ATTR_IE
])
6807 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6811 if (ie_len
> wiphy
->max_scan_ie_len
) {
6816 request
= kzalloc(sizeof(*request
)
6817 + sizeof(*request
->ssids
) * n_ssids
6818 + sizeof(*request
->channels
) * n_channels
6819 + ie_len
, GFP_KERNEL
);
6826 request
->ssids
= (void *)&request
->channels
[n_channels
];
6827 request
->n_ssids
= n_ssids
;
6830 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6832 request
->ie
= (void *)(request
->channels
+ n_channels
);
6836 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6837 /* user specified, bail out if channel not found */
6838 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
6839 struct ieee80211_channel
*chan
;
6841 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6848 /* ignore disabled channels */
6849 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6852 request
->channels
[i
] = chan
;
6856 enum nl80211_band band
;
6859 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
6862 if (!wiphy
->bands
[band
])
6864 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6865 struct ieee80211_channel
*chan
;
6867 chan
= &wiphy
->bands
[band
]->channels
[j
];
6869 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6872 request
->channels
[i
] = chan
;
6883 request
->n_channels
= i
;
6886 if (!cfg80211_off_channel_oper_allowed(wdev
)) {
6887 struct ieee80211_channel
*chan
;
6889 if (request
->n_channels
!= 1) {
6895 chan
= request
->channels
[0];
6896 if (chan
->center_freq
!= wdev
->chandef
.chan
->center_freq
) {
6906 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
6907 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6911 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6912 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
6917 if (info
->attrs
[NL80211_ATTR_IE
]) {
6918 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6919 memcpy((void *)request
->ie
,
6920 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6924 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
6925 if (wiphy
->bands
[i
])
6927 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
6929 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
6930 nla_for_each_nested(attr
,
6931 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
6933 enum nl80211_band band
= nla_type(attr
);
6935 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
6940 if (!wiphy
->bands
[band
])
6943 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
6946 &request
->rates
[band
]);
6952 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
6953 if (!wiphy_ext_feature_isset(wiphy
,
6954 NL80211_EXT_FEATURE_SET_SCAN_DWELL
)) {
6960 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
6961 request
->duration_mandatory
=
6962 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
6965 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, info
->attrs
,
6971 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6973 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6974 * BSSID to scan for. This was problematic because that same attribute
6975 * was already used for another purpose (local random MAC address). The
6976 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6977 * compatibility with older userspace components, also use the
6978 * NL80211_ATTR_MAC value here if it can be determined to be used for
6979 * the specific BSSID use case instead of the random MAC address
6980 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6982 if (info
->attrs
[NL80211_ATTR_BSSID
])
6983 memcpy(request
->bssid
,
6984 nla_data(info
->attrs
[NL80211_ATTR_BSSID
]), ETH_ALEN
);
6985 else if (!(request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) &&
6986 info
->attrs
[NL80211_ATTR_MAC
])
6987 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
6990 eth_broadcast_addr(request
->bssid
);
6992 request
->wdev
= wdev
;
6993 request
->wiphy
= &rdev
->wiphy
;
6994 request
->scan_start
= jiffies
;
6996 rdev
->scan_req
= request
;
6997 err
= rdev_scan(rdev
, request
);
7000 nl80211_send_scan_start(rdev
, wdev
);
7002 dev_hold(wdev
->netdev
);
7005 rdev
->scan_req
= NULL
;
7013 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
7015 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7016 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7018 if (!rdev
->ops
->abort_scan
)
7024 if (!rdev
->scan_req
)
7027 rdev_abort_scan(rdev
, wdev
);
7032 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
7033 struct cfg80211_sched_scan_request
*request
,
7034 struct nlattr
**attrs
)
7036 int tmp
, err
, i
= 0;
7037 struct nlattr
*attr
;
7039 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
7043 * If scan plans are not specified,
7044 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
7045 * case one scan plan will be set with the specified scan
7046 * interval and infinite number of iterations.
7048 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
7052 request
->scan_plans
[0].interval
=
7053 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
7054 if (!request
->scan_plans
[0].interval
)
7057 if (request
->scan_plans
[0].interval
>
7058 wiphy
->max_sched_scan_plan_interval
)
7059 request
->scan_plans
[0].interval
=
7060 wiphy
->max_sched_scan_plan_interval
;
7065 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
7066 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
7068 if (WARN_ON(i
>= n_plans
))
7071 err
= nla_parse_nested(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
7072 attr
, nl80211_plan_policy
, NULL
);
7076 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
7079 request
->scan_plans
[i
].interval
=
7080 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
7081 if (!request
->scan_plans
[i
].interval
||
7082 request
->scan_plans
[i
].interval
>
7083 wiphy
->max_sched_scan_plan_interval
)
7086 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
7087 request
->scan_plans
[i
].iterations
=
7088 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
7089 if (!request
->scan_plans
[i
].iterations
||
7090 (request
->scan_plans
[i
].iterations
>
7091 wiphy
->max_sched_scan_plan_iterations
))
7093 } else if (i
< n_plans
- 1) {
7095 * All scan plans but the last one must specify
7096 * a finite number of iterations
7105 * The last scan plan must not specify the number of
7106 * iterations, it is supposed to run infinitely
7108 if (request
->scan_plans
[n_plans
- 1].iterations
)
7114 static struct cfg80211_sched_scan_request
*
7115 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
7116 struct nlattr
**attrs
, int max_match_sets
)
7118 struct cfg80211_sched_scan_request
*request
;
7119 struct nlattr
*attr
;
7120 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
7121 enum nl80211_band band
;
7123 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
7124 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
7126 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
7127 return ERR_PTR(-EINVAL
);
7129 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7130 n_channels
= validate_scan_freqs(
7131 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
7133 return ERR_PTR(-EINVAL
);
7135 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
7138 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
7139 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7143 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
7144 return ERR_PTR(-EINVAL
);
7147 * First, count the number of 'real' matchsets. Due to an issue with
7148 * the old implementation, matchsets containing only the RSSI attribute
7149 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7150 * RSSI for all matchsets, rather than their own matchset for reporting
7151 * all APs with a strong RSSI. This is needed to be compatible with
7152 * older userspace that treated a matchset with only the RSSI as the
7153 * global RSSI for all other matchsets - if there are other matchsets.
7155 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7156 nla_for_each_nested(attr
,
7157 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7159 struct nlattr
*rssi
;
7161 err
= nla_parse_nested(tb
,
7162 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7163 attr
, nl80211_match_policy
,
7166 return ERR_PTR(err
);
7168 /* SSID and BSSID are mutually exclusive */
7169 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] &&
7170 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
])
7171 return ERR_PTR(-EINVAL
);
7173 /* add other standalone attributes here */
7174 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] ||
7175 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
]) {
7179 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7181 default_match_rssi
= nla_get_s32(rssi
);
7185 /* However, if there's no other matchset, add the RSSI one */
7186 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
7189 if (n_match_sets
> max_match_sets
)
7190 return ERR_PTR(-EINVAL
);
7192 if (attrs
[NL80211_ATTR_IE
])
7193 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
7197 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
7198 return ERR_PTR(-EINVAL
);
7200 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
7202 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7203 * each scan plan already specifies its own interval
7205 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7206 return ERR_PTR(-EINVAL
);
7208 nla_for_each_nested(attr
,
7209 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
7213 * The scan interval attribute is kept for backward
7214 * compatibility. If no scan plans are specified and sched scan
7215 * interval is specified, one scan plan will be set with this
7216 * scan interval and infinite number of iterations.
7218 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7219 return ERR_PTR(-EINVAL
);
7224 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
7225 return ERR_PTR(-EINVAL
);
7227 if (!wiphy_ext_feature_isset(
7228 wiphy
, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI
) &&
7229 (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] ||
7230 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]))
7231 return ERR_PTR(-EINVAL
);
7233 request
= kzalloc(sizeof(*request
)
7234 + sizeof(*request
->ssids
) * n_ssids
7235 + sizeof(*request
->match_sets
) * n_match_sets
7236 + sizeof(*request
->scan_plans
) * n_plans
7237 + sizeof(*request
->channels
) * n_channels
7238 + ie_len
, GFP_KERNEL
);
7240 return ERR_PTR(-ENOMEM
);
7243 request
->ssids
= (void *)&request
->channels
[n_channels
];
7244 request
->n_ssids
= n_ssids
;
7247 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
7249 request
->ie
= (void *)(request
->channels
+ n_channels
);
7254 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
7256 request
->match_sets
=
7257 (void *)(request
->ssids
+ n_ssids
);
7259 request
->match_sets
=
7260 (void *)(request
->channels
+ n_channels
);
7262 request
->n_match_sets
= n_match_sets
;
7265 request
->scan_plans
= (void *)(request
->match_sets
+
7267 else if (request
->ie
)
7268 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
7270 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
7272 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
7274 request
->n_scan_plans
= n_plans
;
7277 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7278 /* user specified, bail out if channel not found */
7279 nla_for_each_nested(attr
,
7280 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
7282 struct ieee80211_channel
*chan
;
7284 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
7291 /* ignore disabled channels */
7292 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7295 request
->channels
[i
] = chan
;
7300 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7303 if (!wiphy
->bands
[band
])
7305 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
7306 struct ieee80211_channel
*chan
;
7308 chan
= &wiphy
->bands
[band
]->channels
[j
];
7310 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7313 request
->channels
[i
] = chan
;
7324 request
->n_channels
= i
;
7328 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7330 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7334 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7335 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
7342 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7343 nla_for_each_nested(attr
,
7344 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7346 struct nlattr
*ssid
, *bssid
, *rssi
;
7348 err
= nla_parse_nested(tb
,
7349 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7350 attr
, nl80211_match_policy
,
7354 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
7355 bssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
];
7356 if (ssid
|| bssid
) {
7357 if (WARN_ON(i
>= n_match_sets
)) {
7358 /* this indicates a programming error,
7359 * the loop above should have verified
7367 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
7371 memcpy(request
->match_sets
[i
].ssid
.ssid
,
7372 nla_data(ssid
), nla_len(ssid
));
7373 request
->match_sets
[i
].ssid
.ssid_len
=
7377 if (nla_len(bssid
) != ETH_ALEN
) {
7381 memcpy(request
->match_sets
[i
].bssid
,
7382 nla_data(bssid
), ETH_ALEN
);
7385 /* special attribute - old implementation w/a */
7386 request
->match_sets
[i
].rssi_thold
=
7388 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7390 request
->match_sets
[i
].rssi_thold
=
7396 /* there was no other matchset, so the RSSI one is alone */
7397 if (i
== 0 && n_match_sets
)
7398 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
7400 request
->min_rssi_thold
= INT_MAX
;
7401 for (i
= 0; i
< n_match_sets
; i
++)
7402 request
->min_rssi_thold
=
7403 min(request
->match_sets
[i
].rssi_thold
,
7404 request
->min_rssi_thold
);
7406 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
7410 request
->ie_len
= ie_len
;
7411 memcpy((void *)request
->ie
,
7412 nla_data(attrs
[NL80211_ATTR_IE
]),
7416 err
= nl80211_check_scan_flags(wiphy
, wdev
, request
, attrs
, true);
7420 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
7422 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
7424 if (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]) {
7425 request
->relative_rssi
= nla_get_s8(
7426 attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]);
7427 request
->relative_rssi_set
= true;
7430 if (request
->relative_rssi_set
&&
7431 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]) {
7432 struct nl80211_bss_select_rssi_adjust
*rssi_adjust
;
7434 rssi_adjust
= nla_data(
7435 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]);
7436 request
->rssi_adjust
.band
= rssi_adjust
->band
;
7437 request
->rssi_adjust
.delta
= rssi_adjust
->delta
;
7438 if (!is_band_valid(wiphy
, request
->rssi_adjust
.band
)) {
7444 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
7448 request
->scan_start
= jiffies
;
7454 return ERR_PTR(err
);
7457 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
7458 struct genl_info
*info
)
7460 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7461 struct net_device
*dev
= info
->user_ptr
[1];
7462 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7463 struct cfg80211_sched_scan_request
*sched_scan_req
;
7467 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_start
)
7470 want_multi
= info
->attrs
[NL80211_ATTR_SCHED_SCAN_MULTI
];
7471 err
= cfg80211_sched_scan_req_possible(rdev
, want_multi
);
7475 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
7477 rdev
->wiphy
.max_match_sets
);
7479 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
7483 /* leave request id zero for legacy request
7484 * or if driver does not support multi-scheduled scan
7486 if (want_multi
&& rdev
->wiphy
.max_sched_scan_reqs
> 1) {
7487 while (!sched_scan_req
->reqid
)
7488 sched_scan_req
->reqid
= rdev
->wiphy
.cookie_counter
++;
7491 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
7495 sched_scan_req
->dev
= dev
;
7496 sched_scan_req
->wiphy
= &rdev
->wiphy
;
7498 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
7499 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
7501 cfg80211_add_sched_scan_req(rdev
, sched_scan_req
);
7503 nl80211_send_sched_scan(sched_scan_req
, NL80211_CMD_START_SCHED_SCAN
);
7507 kfree(sched_scan_req
);
7512 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
7513 struct genl_info
*info
)
7515 struct cfg80211_sched_scan_request
*req
;
7516 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7519 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_stop
)
7522 if (info
->attrs
[NL80211_ATTR_COOKIE
]) {
7523 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7524 return __cfg80211_stop_sched_scan(rdev
, cookie
, false);
7527 req
= list_first_or_null_rcu(&rdev
->sched_scan_req_list
,
7528 struct cfg80211_sched_scan_request
,
7530 if (!req
|| req
->reqid
||
7531 (req
->owner_nlportid
&&
7532 req
->owner_nlportid
!= info
->snd_portid
))
7535 return cfg80211_stop_sched_scan_req(rdev
, req
, false);
7538 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
7539 struct genl_info
*info
)
7541 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7542 struct net_device
*dev
= info
->user_ptr
[1];
7543 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7544 struct cfg80211_chan_def chandef
;
7545 enum nl80211_dfs_regions dfs_region
;
7546 unsigned int cac_time_ms
;
7549 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
7550 if (dfs_region
== NL80211_DFS_UNSET
)
7553 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7557 if (netif_carrier_ok(dev
))
7560 if (wdev
->cac_started
)
7563 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
7571 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
7574 if (!rdev
->ops
->start_radar_detection
)
7577 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
7578 if (WARN_ON(!cac_time_ms
))
7579 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
7581 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
7583 wdev
->chandef
= chandef
;
7584 wdev
->cac_started
= true;
7585 wdev
->cac_start_time
= jiffies
;
7586 wdev
->cac_time_ms
= cac_time_ms
;
7591 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
7593 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7594 struct net_device
*dev
= info
->user_ptr
[1];
7595 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7596 struct cfg80211_csa_settings params
;
7597 /* csa_attrs is defined static to avoid waste of stack size - this
7598 * function is called under RTNL lock, so this should not be a problem.
7600 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
7602 bool need_new_beacon
= false;
7603 bool need_handle_dfs_flag
= true;
7607 if (!rdev
->ops
->channel_switch
||
7608 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
7611 switch (dev
->ieee80211_ptr
->iftype
) {
7612 case NL80211_IFTYPE_AP
:
7613 case NL80211_IFTYPE_P2P_GO
:
7614 need_new_beacon
= true;
7615 /* For all modes except AP the handle_dfs flag needs to be
7616 * supplied to tell the kernel that userspace will handle radar
7617 * events when they happen. Otherwise a switch to a channel
7618 * requiring DFS will be rejected.
7620 need_handle_dfs_flag
= false;
7622 /* useless if AP is not running */
7623 if (!wdev
->beacon_interval
)
7626 case NL80211_IFTYPE_ADHOC
:
7627 if (!wdev
->ssid_len
)
7630 case NL80211_IFTYPE_MESH_POINT
:
7631 if (!wdev
->mesh_id_len
)
7638 memset(¶ms
, 0, sizeof(params
));
7640 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7641 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
7644 /* only important for AP, IBSS and mesh create IEs internally */
7645 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
7648 /* Even though the attribute is u32, the specification says
7649 * u8, so let's make sure we don't overflow.
7651 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
7655 params
.count
= cs_count
;
7657 if (!need_new_beacon
)
7660 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
7664 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
7665 info
->attrs
[NL80211_ATTR_CSA_IES
],
7666 nl80211_policy
, info
->extack
);
7670 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
7674 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
7677 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7678 if (!len
|| (len
% sizeof(u16
)))
7681 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
7682 if (rdev
->wiphy
.max_num_csa_counters
&&
7683 (params
.n_counter_offsets_beacon
>
7684 rdev
->wiphy
.max_num_csa_counters
))
7687 params
.counter_offsets_beacon
=
7688 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7690 /* sanity checks - counters should fit and be the same */
7691 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
7692 u16 offset
= params
.counter_offsets_beacon
[i
];
7694 if (offset
>= params
.beacon_csa
.tail_len
)
7697 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
7701 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
7702 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7703 if (!len
|| (len
% sizeof(u16
)))
7706 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
7707 if (rdev
->wiphy
.max_num_csa_counters
&&
7708 (params
.n_counter_offsets_presp
>
7709 rdev
->wiphy
.max_num_csa_counters
))
7712 params
.counter_offsets_presp
=
7713 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7715 /* sanity checks - counters should fit and be the same */
7716 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
7717 u16 offset
= params
.counter_offsets_presp
[i
];
7719 if (offset
>= params
.beacon_csa
.probe_resp_len
)
7722 if (params
.beacon_csa
.probe_resp
[offset
] !=
7729 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
7733 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
7737 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
7744 params
.radar_required
= true;
7745 if (need_handle_dfs_flag
&&
7746 !nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
])) {
7751 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
7752 params
.block_tx
= true;
7755 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
7761 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
7763 struct cfg80211_registered_device
*rdev
,
7764 struct wireless_dev
*wdev
,
7765 struct cfg80211_internal_bss
*intbss
)
7767 struct cfg80211_bss
*res
= &intbss
->pub
;
7768 const struct cfg80211_bss_ies
*ies
;
7772 ASSERT_WDEV_LOCK(wdev
);
7774 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
7775 NL80211_CMD_NEW_SCAN_RESULTS
);
7779 genl_dump_check_consistent(cb
, hdr
);
7781 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
7782 goto nla_put_failure
;
7784 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
7785 goto nla_put_failure
;
7786 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
7788 goto nla_put_failure
;
7790 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
7792 goto nla_put_failure
;
7793 if ((!is_zero_ether_addr(res
->bssid
) &&
7794 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
7795 goto nla_put_failure
;
7798 /* indicate whether we have probe response data or not */
7799 if (rcu_access_pointer(res
->proberesp_ies
) &&
7800 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
7801 goto fail_unlock_rcu
;
7803 /* this pointer prefers to be pointed to probe response data
7804 * but is always valid
7806 ies
= rcu_dereference(res
->ies
);
7808 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
7810 goto fail_unlock_rcu
;
7811 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
7812 ies
->len
, ies
->data
))
7813 goto fail_unlock_rcu
;
7816 /* and this pointer is always (unless driver didn't know) beacon data */
7817 ies
= rcu_dereference(res
->beacon_ies
);
7818 if (ies
&& ies
->from_beacon
) {
7819 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
7821 goto fail_unlock_rcu
;
7822 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
7823 ies
->len
, ies
->data
))
7824 goto fail_unlock_rcu
;
7828 if (res
->beacon_interval
&&
7829 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
7830 goto nla_put_failure
;
7831 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
7832 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
7833 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
7834 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
7835 jiffies_to_msecs(jiffies
- intbss
->ts
)))
7836 goto nla_put_failure
;
7838 if (intbss
->parent_tsf
&&
7839 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
7840 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
7841 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
7842 intbss
->parent_bssid
)))
7843 goto nla_put_failure
;
7845 if (intbss
->ts_boottime
&&
7846 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
7847 intbss
->ts_boottime
, NL80211_BSS_PAD
))
7848 goto nla_put_failure
;
7850 if (!nl80211_put_signal(msg
, intbss
->pub
.chains
,
7851 intbss
->pub
.chain_signal
,
7852 NL80211_BSS_CHAIN_SIGNAL
))
7853 goto nla_put_failure
;
7855 switch (rdev
->wiphy
.signal_type
) {
7856 case CFG80211_SIGNAL_TYPE_MBM
:
7857 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
7858 goto nla_put_failure
;
7860 case CFG80211_SIGNAL_TYPE_UNSPEC
:
7861 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
7862 goto nla_put_failure
;
7868 switch (wdev
->iftype
) {
7869 case NL80211_IFTYPE_P2P_CLIENT
:
7870 case NL80211_IFTYPE_STATION
:
7871 if (intbss
== wdev
->current_bss
&&
7872 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7873 NL80211_BSS_STATUS_ASSOCIATED
))
7874 goto nla_put_failure
;
7876 case NL80211_IFTYPE_ADHOC
:
7877 if (intbss
== wdev
->current_bss
&&
7878 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7879 NL80211_BSS_STATUS_IBSS_JOINED
))
7880 goto nla_put_failure
;
7886 nla_nest_end(msg
, bss
);
7888 genlmsg_end(msg
, hdr
);
7894 genlmsg_cancel(msg
, hdr
);
7898 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
7900 struct cfg80211_registered_device
*rdev
;
7901 struct cfg80211_internal_bss
*scan
;
7902 struct wireless_dev
*wdev
;
7903 int start
= cb
->args
[2], idx
= 0;
7907 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
7914 spin_lock_bh(&rdev
->bss_lock
);
7915 cfg80211_bss_expire(rdev
);
7917 cb
->seq
= rdev
->bss_generation
;
7919 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
7922 if (nl80211_send_bss(skb
, cb
,
7923 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7924 rdev
, wdev
, scan
) < 0) {
7930 spin_unlock_bh(&rdev
->bss_lock
);
7939 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
7940 int flags
, struct net_device
*dev
,
7941 bool allow_radio_stats
,
7942 struct survey_info
*survey
)
7945 struct nlattr
*infoattr
;
7947 /* skip radio stats if userspace didn't request them */
7948 if (!survey
->channel
&& !allow_radio_stats
)
7951 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
7952 NL80211_CMD_NEW_SURVEY_RESULTS
);
7956 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
7957 goto nla_put_failure
;
7959 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
7961 goto nla_put_failure
;
7963 if (survey
->channel
&&
7964 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
7965 survey
->channel
->center_freq
))
7966 goto nla_put_failure
;
7968 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
7969 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
7970 goto nla_put_failure
;
7971 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
7972 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
7973 goto nla_put_failure
;
7974 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
7975 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
7976 survey
->time
, NL80211_SURVEY_INFO_PAD
))
7977 goto nla_put_failure
;
7978 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
7979 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
7980 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
7981 goto nla_put_failure
;
7982 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
7983 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
7984 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
7985 goto nla_put_failure
;
7986 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
7987 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
7988 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
7989 goto nla_put_failure
;
7990 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
7991 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
7992 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
7993 goto nla_put_failure
;
7994 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
7995 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
7996 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
7997 goto nla_put_failure
;
7999 nla_nest_end(msg
, infoattr
);
8001 genlmsg_end(msg
, hdr
);
8005 genlmsg_cancel(msg
, hdr
);
8009 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
8011 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
8012 struct survey_info survey
;
8013 struct cfg80211_registered_device
*rdev
;
8014 struct wireless_dev
*wdev
;
8015 int survey_idx
= cb
->args
[2];
8020 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
8024 /* prepare_wdev_dump parsed the attributes */
8025 radio_stats
= attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
8027 if (!wdev
->netdev
) {
8032 if (!rdev
->ops
->dump_survey
) {
8038 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
8044 /* don't send disabled channels, but do send non-channel data */
8045 if (survey
.channel
&&
8046 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
8051 if (nl80211_send_survey(skb
,
8052 NETLINK_CB(cb
->skb
).portid
,
8053 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8054 wdev
->netdev
, radio_stats
, &survey
) < 0)
8060 cb
->args
[2] = survey_idx
;
8067 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
8069 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
8070 NL80211_WPA_VERSION_2
));
8073 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8075 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8076 struct net_device
*dev
= info
->user_ptr
[1];
8077 struct ieee80211_channel
*chan
;
8078 const u8
*bssid
, *ssid
, *ie
= NULL
, *auth_data
= NULL
;
8079 int err
, ssid_len
, ie_len
= 0, auth_data_len
= 0;
8080 enum nl80211_auth_type auth_type
;
8081 struct key_parse key
;
8082 bool local_state_change
;
8084 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8087 if (!info
->attrs
[NL80211_ATTR_MAC
])
8090 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
8093 if (!info
->attrs
[NL80211_ATTR_SSID
])
8096 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8099 err
= nl80211_parse_key(info
, &key
);
8104 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
8106 if (!key
.p
.key
|| !key
.p
.key_len
)
8108 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
8109 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
8110 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
8111 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
8124 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
8125 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
8134 if (!rdev
->ops
->auth
)
8137 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8138 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8141 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8142 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8143 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8147 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8148 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8150 if (info
->attrs
[NL80211_ATTR_IE
]) {
8151 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8152 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8155 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8156 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
8159 if ((auth_type
== NL80211_AUTHTYPE_SAE
||
8160 auth_type
== NL80211_AUTHTYPE_FILS_SK
||
8161 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
8162 auth_type
== NL80211_AUTHTYPE_FILS_PK
) &&
8163 !info
->attrs
[NL80211_ATTR_AUTH_DATA
])
8166 if (info
->attrs
[NL80211_ATTR_AUTH_DATA
]) {
8167 if (auth_type
!= NL80211_AUTHTYPE_SAE
&&
8168 auth_type
!= NL80211_AUTHTYPE_FILS_SK
&&
8169 auth_type
!= NL80211_AUTHTYPE_FILS_SK_PFS
&&
8170 auth_type
!= NL80211_AUTHTYPE_FILS_PK
)
8172 auth_data
= nla_data(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8173 auth_data_len
= nla_len(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8174 /* need to include at least Auth Transaction and Status Code */
8175 if (auth_data_len
< 4)
8179 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8182 * Since we no longer track auth state, ignore
8183 * requests to only change local state.
8185 if (local_state_change
)
8188 wdev_lock(dev
->ieee80211_ptr
);
8189 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
8190 ssid
, ssid_len
, ie
, ie_len
,
8191 key
.p
.key
, key
.p
.key_len
, key
.idx
,
8192 auth_data
, auth_data_len
);
8193 wdev_unlock(dev
->ieee80211_ptr
);
8197 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
8198 struct genl_info
*info
,
8199 struct cfg80211_crypto_settings
*settings
,
8202 memset(settings
, 0, sizeof(*settings
));
8204 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
8206 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
8209 proto
= nla_get_u16(
8210 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
8211 settings
->control_port_ethertype
= cpu_to_be16(proto
);
8212 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
8215 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
8216 settings
->control_port_no_encrypt
= true;
8218 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
8220 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
8224 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8225 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8226 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
8228 if (len
% sizeof(u32
))
8231 if (settings
->n_ciphers_pairwise
> cipher_limit
)
8234 memcpy(settings
->ciphers_pairwise
, data
, len
);
8236 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
8237 if (!cfg80211_supported_cipher_suite(
8239 settings
->ciphers_pairwise
[i
]))
8243 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
8244 settings
->cipher_group
=
8245 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
8246 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
8247 settings
->cipher_group
))
8251 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
8252 settings
->wpa_versions
=
8253 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
8254 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
8258 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
8262 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8263 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8264 settings
->n_akm_suites
= len
/ sizeof(u32
);
8266 if (len
% sizeof(u32
))
8269 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
8272 memcpy(settings
->akm_suites
, data
, len
);
8275 if (info
->attrs
[NL80211_ATTR_PMK
]) {
8276 if (nla_len(info
->attrs
[NL80211_ATTR_PMK
]) != WLAN_PMK_LEN
)
8278 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8279 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK
))
8281 settings
->psk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
8287 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
8289 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8290 struct net_device
*dev
= info
->user_ptr
[1];
8291 struct ieee80211_channel
*chan
;
8292 struct cfg80211_assoc_request req
= {};
8293 const u8
*bssid
, *ssid
;
8294 int err
, ssid_len
= 0;
8296 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8299 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
8300 !info
->attrs
[NL80211_ATTR_SSID
] ||
8301 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8304 if (!rdev
->ops
->assoc
)
8307 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8308 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8311 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8313 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8314 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8318 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8319 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8321 if (info
->attrs
[NL80211_ATTR_IE
]) {
8322 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8323 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8326 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
8327 enum nl80211_mfp mfp
=
8328 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
8329 if (mfp
== NL80211_MFP_REQUIRED
)
8331 else if (mfp
!= NL80211_MFP_NO
)
8335 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
8336 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
8338 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
8339 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
8341 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8342 memcpy(&req
.ht_capa_mask
,
8343 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8344 sizeof(req
.ht_capa_mask
));
8346 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8347 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8349 memcpy(&req
.ht_capa
,
8350 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8351 sizeof(req
.ht_capa
));
8354 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
8355 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
8357 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8358 memcpy(&req
.vht_capa_mask
,
8359 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
8360 sizeof(req
.vht_capa_mask
));
8362 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
8363 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8365 memcpy(&req
.vht_capa
,
8366 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
8367 sizeof(req
.vht_capa
));
8370 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
8371 if (!((rdev
->wiphy
.features
&
8372 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
8373 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
8374 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8375 NL80211_EXT_FEATURE_RRM
))
8377 req
.flags
|= ASSOC_REQ_USE_RRM
;
8380 if (info
->attrs
[NL80211_ATTR_FILS_KEK
]) {
8381 req
.fils_kek
= nla_data(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8382 req
.fils_kek_len
= nla_len(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8383 if (!info
->attrs
[NL80211_ATTR_FILS_NONCES
])
8386 nla_data(info
->attrs
[NL80211_ATTR_FILS_NONCES
]);
8389 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
8391 wdev_lock(dev
->ieee80211_ptr
);
8393 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
8394 ssid
, ssid_len
, &req
);
8396 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
8397 dev
->ieee80211_ptr
->conn_owner_nlportid
=
8399 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
8403 wdev_unlock(dev
->ieee80211_ptr
);
8409 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8411 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8412 struct net_device
*dev
= info
->user_ptr
[1];
8413 const u8
*ie
= NULL
, *bssid
;
8414 int ie_len
= 0, err
;
8416 bool local_state_change
;
8418 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8421 if (!info
->attrs
[NL80211_ATTR_MAC
])
8424 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8427 if (!rdev
->ops
->deauth
)
8430 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8431 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8434 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8436 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8437 if (reason_code
== 0) {
8438 /* Reason Code 0 is reserved */
8442 if (info
->attrs
[NL80211_ATTR_IE
]) {
8443 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8444 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8447 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8449 wdev_lock(dev
->ieee80211_ptr
);
8450 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8451 local_state_change
);
8452 wdev_unlock(dev
->ieee80211_ptr
);
8456 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
8458 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8459 struct net_device
*dev
= info
->user_ptr
[1];
8460 const u8
*ie
= NULL
, *bssid
;
8461 int ie_len
= 0, err
;
8463 bool local_state_change
;
8465 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8468 if (!info
->attrs
[NL80211_ATTR_MAC
])
8471 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8474 if (!rdev
->ops
->disassoc
)
8477 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8478 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8481 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8483 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8484 if (reason_code
== 0) {
8485 /* Reason Code 0 is reserved */
8489 if (info
->attrs
[NL80211_ATTR_IE
]) {
8490 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8491 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8494 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8496 wdev_lock(dev
->ieee80211_ptr
);
8497 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8498 local_state_change
);
8499 wdev_unlock(dev
->ieee80211_ptr
);
8504 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
8505 int mcast_rate
[NUM_NL80211_BANDS
],
8508 struct wiphy
*wiphy
= &rdev
->wiphy
;
8512 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8513 struct ieee80211_supported_band
*sband
;
8515 sband
= wiphy
->bands
[band
];
8519 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
8520 if (sband
->bitrates
[i
].bitrate
== rateval
) {
8521 mcast_rate
[band
] = i
+ 1;
8531 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8533 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8534 struct net_device
*dev
= info
->user_ptr
[1];
8535 struct cfg80211_ibss_params ibss
;
8536 struct wiphy
*wiphy
;
8537 struct cfg80211_cached_keys
*connkeys
= NULL
;
8540 memset(&ibss
, 0, sizeof(ibss
));
8542 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8545 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8546 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8549 ibss
.beacon_interval
= 100;
8551 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
])
8552 ibss
.beacon_interval
=
8553 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8555 err
= cfg80211_validate_beacon_int(rdev
, NL80211_IFTYPE_ADHOC
,
8556 ibss
.beacon_interval
);
8560 if (!rdev
->ops
->join_ibss
)
8563 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8566 wiphy
= &rdev
->wiphy
;
8568 if (info
->attrs
[NL80211_ATTR_MAC
]) {
8569 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8571 if (!is_valid_ether_addr(ibss
.bssid
))
8574 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8575 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8577 if (info
->attrs
[NL80211_ATTR_IE
]) {
8578 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8579 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8582 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
8586 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
8587 NL80211_IFTYPE_ADHOC
))
8590 switch (ibss
.chandef
.width
) {
8591 case NL80211_CHAN_WIDTH_5
:
8592 case NL80211_CHAN_WIDTH_10
:
8593 case NL80211_CHAN_WIDTH_20_NOHT
:
8595 case NL80211_CHAN_WIDTH_20
:
8596 case NL80211_CHAN_WIDTH_40
:
8597 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8600 case NL80211_CHAN_WIDTH_80
:
8601 case NL80211_CHAN_WIDTH_80P80
:
8602 case NL80211_CHAN_WIDTH_160
:
8603 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8605 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8606 NL80211_EXT_FEATURE_VHT_IBSS
))
8613 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
8614 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
8616 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8618 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8620 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8621 struct ieee80211_supported_band
*sband
=
8622 wiphy
->bands
[ibss
.chandef
.chan
->band
];
8624 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8630 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8631 memcpy(&ibss
.ht_capa_mask
,
8632 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8633 sizeof(ibss
.ht_capa_mask
));
8635 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8636 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8638 memcpy(&ibss
.ht_capa
,
8639 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8640 sizeof(ibss
.ht_capa
));
8643 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8644 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
8645 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8648 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
8651 connkeys
= nl80211_parse_connkeys(rdev
, info
, &no_ht
);
8652 if (IS_ERR(connkeys
))
8653 return PTR_ERR(connkeys
);
8655 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
8663 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
8665 ibss
.userspace_handles_dfs
=
8666 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
8668 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
8674 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8676 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8677 struct net_device
*dev
= info
->user_ptr
[1];
8679 if (!rdev
->ops
->leave_ibss
)
8682 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8685 return cfg80211_leave_ibss(rdev
, dev
, false);
8688 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
8690 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8691 struct net_device
*dev
= info
->user_ptr
[1];
8692 int mcast_rate
[NUM_NL80211_BANDS
];
8696 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
8697 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
8698 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
8701 if (!rdev
->ops
->set_mcast_rate
)
8704 memset(mcast_rate
, 0, sizeof(mcast_rate
));
8706 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
8709 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
8710 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
8713 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
8718 static struct sk_buff
*
8719 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
8720 struct wireless_dev
*wdev
, int approxlen
,
8721 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
8722 enum nl80211_attrs attr
,
8723 const struct nl80211_vendor_cmd_info
*info
,
8726 struct sk_buff
*skb
;
8728 struct nlattr
*data
;
8730 skb
= nlmsg_new(approxlen
+ 100, gfp
);
8734 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
8740 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
8741 goto nla_put_failure
;
8744 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
8746 goto nla_put_failure
;
8747 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
8749 goto nla_put_failure
;
8753 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
8754 wdev_id(wdev
), NL80211_ATTR_PAD
))
8755 goto nla_put_failure
;
8757 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
8758 wdev
->netdev
->ifindex
))
8759 goto nla_put_failure
;
8762 data
= nla_nest_start(skb
, attr
);
8764 goto nla_put_failure
;
8766 ((void **)skb
->cb
)[0] = rdev
;
8767 ((void **)skb
->cb
)[1] = hdr
;
8768 ((void **)skb
->cb
)[2] = data
;
8777 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
8778 struct wireless_dev
*wdev
,
8779 enum nl80211_commands cmd
,
8780 enum nl80211_attrs attr
,
8781 int vendor_event_idx
,
8782 int approxlen
, gfp_t gfp
)
8784 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
8785 const struct nl80211_vendor_cmd_info
*info
;
8788 case NL80211_CMD_TESTMODE
:
8789 if (WARN_ON(vendor_event_idx
!= -1))
8793 case NL80211_CMD_VENDOR
:
8794 if (WARN_ON(vendor_event_idx
< 0 ||
8795 vendor_event_idx
>= wiphy
->n_vendor_events
))
8797 info
= &wiphy
->vendor_events
[vendor_event_idx
];
8804 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
8805 cmd
, attr
, info
, gfp
);
8807 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
8809 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
8811 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8812 void *hdr
= ((void **)skb
->cb
)[1];
8813 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8814 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
8816 /* clear CB data for netlink core to own from now on */
8817 memset(skb
->cb
, 0, sizeof(skb
->cb
));
8819 nla_nest_end(skb
, data
);
8820 genlmsg_end(skb
, hdr
);
8822 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
8823 mcgrp
= NL80211_MCGRP_VENDOR
;
8825 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
8828 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
8830 #ifdef CONFIG_NL80211_TESTMODE
8831 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
8833 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8834 struct wireless_dev
*wdev
=
8835 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8838 if (!rdev
->ops
->testmode_cmd
)
8842 err
= PTR_ERR(wdev
);
8846 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8850 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
8853 rdev
->cur_cmd_info
= info
;
8854 err
= rdev_testmode_cmd(rdev
, wdev
,
8855 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
8856 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
8857 rdev
->cur_cmd_info
= NULL
;
8862 static int nl80211_testmode_dump(struct sk_buff
*skb
,
8863 struct netlink_callback
*cb
)
8865 struct cfg80211_registered_device
*rdev
;
8875 * 0 is a valid index, but not valid for args[0],
8876 * so we need to offset by 1.
8878 phy_idx
= cb
->args
[0] - 1;
8880 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
8886 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
8888 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
8889 attrbuf
, nl80211_fam
.maxattr
,
8890 nl80211_policy
, NULL
);
8894 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
8896 err
= PTR_ERR(rdev
);
8899 phy_idx
= rdev
->wiphy_idx
;
8901 if (attrbuf
[NL80211_ATTR_TESTDATA
])
8902 cb
->args
[1] = (long)attrbuf
[NL80211_ATTR_TESTDATA
];
8906 data
= nla_data((void *)cb
->args
[1]);
8907 data_len
= nla_len((void *)cb
->args
[1]);
8910 if (!rdev
->ops
->testmode_dump
) {
8916 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
8917 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8918 NL80211_CMD_TESTMODE
);
8919 struct nlattr
*tmdata
;
8924 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
8925 genlmsg_cancel(skb
, hdr
);
8929 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
8931 genlmsg_cancel(skb
, hdr
);
8934 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
8935 nla_nest_end(skb
, tmdata
);
8937 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
8938 genlmsg_cancel(skb
, hdr
);
8941 genlmsg_cancel(skb
, hdr
);
8945 genlmsg_end(skb
, hdr
);
8950 cb
->args
[0] = phy_idx
+ 1;
8957 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
8959 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8960 struct net_device
*dev
= info
->user_ptr
[1];
8961 struct cfg80211_connect_params connect
;
8962 struct wiphy
*wiphy
;
8963 struct cfg80211_cached_keys
*connkeys
= NULL
;
8966 memset(&connect
, 0, sizeof(connect
));
8968 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8971 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8972 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8975 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
8977 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8978 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
8979 NL80211_CMD_CONNECT
))
8982 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
8984 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
8986 if (info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
] &&
8987 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8988 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
8990 connect
.want_1x
= info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
];
8992 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
8993 NL80211_MAX_NR_CIPHER_SUITES
);
8997 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8998 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9001 wiphy
= &rdev
->wiphy
;
9003 connect
.bg_scan_period
= -1;
9004 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
9005 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
9006 connect
.bg_scan_period
=
9007 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
9010 if (info
->attrs
[NL80211_ATTR_MAC
])
9011 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9012 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
9013 connect
.bssid_hint
=
9014 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
9015 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9016 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9018 if (info
->attrs
[NL80211_ATTR_IE
]) {
9019 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9020 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9023 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
9024 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
9025 if (connect
.mfp
== NL80211_MFP_OPTIONAL
&&
9026 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9027 NL80211_EXT_FEATURE_MFP_OPTIONAL
))
9030 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
9031 connect
.mfp
!= NL80211_MFP_NO
&&
9032 connect
.mfp
!= NL80211_MFP_OPTIONAL
)
9035 connect
.mfp
= NL80211_MFP_NO
;
9038 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
9039 connect
.prev_bssid
=
9040 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
9042 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9043 connect
.channel
= nl80211_get_valid_chan(
9044 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
9045 if (!connect
.channel
)
9047 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
9048 connect
.channel_hint
= nl80211_get_valid_chan(
9049 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
9050 if (!connect
.channel_hint
)
9054 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
9055 connkeys
= nl80211_parse_connkeys(rdev
, info
, NULL
);
9056 if (IS_ERR(connkeys
))
9057 return PTR_ERR(connkeys
);
9060 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
9061 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
9063 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
9064 memcpy(&connect
.ht_capa_mask
,
9065 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
9066 sizeof(connect
.ht_capa_mask
));
9068 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
9069 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
9073 memcpy(&connect
.ht_capa
,
9074 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
9075 sizeof(connect
.ht_capa
));
9078 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
9079 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
9081 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
9082 memcpy(&connect
.vht_capa_mask
,
9083 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
9084 sizeof(connect
.vht_capa_mask
));
9086 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
9087 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
9091 memcpy(&connect
.vht_capa
,
9092 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
9093 sizeof(connect
.vht_capa
));
9096 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
9097 if (!((rdev
->wiphy
.features
&
9098 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
9099 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
9100 !wiphy_ext_feature_isset(&rdev
->wiphy
,
9101 NL80211_EXT_FEATURE_RRM
)) {
9105 connect
.flags
|= ASSOC_REQ_USE_RRM
;
9108 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
9109 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
9114 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
9115 /* bss selection makes no sense if bssid is set */
9116 if (connect
.bssid
) {
9121 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
9122 wiphy
, &connect
.bss_select
);
9129 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
9130 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
9131 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
9132 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
9133 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
9134 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9135 connect
.fils_erp_username
=
9136 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9137 connect
.fils_erp_username_len
=
9138 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9139 connect
.fils_erp_realm
=
9140 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9141 connect
.fils_erp_realm_len
=
9142 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9143 connect
.fils_erp_next_seq_num
=
9145 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
9146 connect
.fils_erp_rrk
=
9147 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9148 connect
.fils_erp_rrk_len
=
9149 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9150 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
9151 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
9152 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
9153 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9158 wdev_lock(dev
->ieee80211_ptr
);
9160 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
9161 connect
.prev_bssid
);
9165 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9166 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
9168 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
9169 connect
.bssid
, ETH_ALEN
);
9171 memset(dev
->ieee80211_ptr
->disconnect_bssid
,
9175 wdev_unlock(dev
->ieee80211_ptr
);
9180 static int nl80211_update_connect_params(struct sk_buff
*skb
,
9181 struct genl_info
*info
)
9183 struct cfg80211_connect_params connect
= {};
9184 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9185 struct net_device
*dev
= info
->user_ptr
[1];
9186 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9190 if (!rdev
->ops
->update_connect_params
)
9193 if (info
->attrs
[NL80211_ATTR_IE
]) {
9194 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9196 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9197 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9198 changed
|= UPDATE_ASSOC_IES
;
9201 wdev_lock(dev
->ieee80211_ptr
);
9202 if (!wdev
->current_bss
)
9205 ret
= rdev_update_connect_params(rdev
, dev
, &connect
, changed
);
9206 wdev_unlock(dev
->ieee80211_ptr
);
9211 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
9213 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9214 struct net_device
*dev
= info
->user_ptr
[1];
9218 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
9219 reason
= WLAN_REASON_DEAUTH_LEAVING
;
9221 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
9226 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9227 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9230 wdev_lock(dev
->ieee80211_ptr
);
9231 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
9232 wdev_unlock(dev
->ieee80211_ptr
);
9236 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
9238 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9242 if (info
->attrs
[NL80211_ATTR_PID
]) {
9243 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
9245 net
= get_net_ns_by_pid(pid
);
9246 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
9247 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
9249 net
= get_net_ns_by_fd(fd
);
9255 return PTR_ERR(net
);
9259 /* check if anything to do */
9260 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
9261 err
= cfg80211_switch_netns(rdev
, net
);
9267 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9269 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9270 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
9271 struct cfg80211_pmksa
*pmksa
) = NULL
;
9272 struct net_device
*dev
= info
->user_ptr
[1];
9273 struct cfg80211_pmksa pmksa
;
9275 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
9277 if (!info
->attrs
[NL80211_ATTR_PMKID
])
9280 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
9282 if (info
->attrs
[NL80211_ATTR_MAC
]) {
9283 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9284 } else if (info
->attrs
[NL80211_ATTR_SSID
] &&
9285 info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
] &&
9286 (info
->genlhdr
->cmd
== NL80211_CMD_DEL_PMKSA
||
9287 info
->attrs
[NL80211_ATTR_PMK
])) {
9288 pmksa
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9289 pmksa
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9291 nla_data(info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
]);
9295 if (info
->attrs
[NL80211_ATTR_PMK
]) {
9296 pmksa
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
9297 pmksa
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
9300 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9301 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9304 switch (info
->genlhdr
->cmd
) {
9305 case NL80211_CMD_SET_PMKSA
:
9306 rdev_ops
= rdev
->ops
->set_pmksa
;
9308 case NL80211_CMD_DEL_PMKSA
:
9309 rdev_ops
= rdev
->ops
->del_pmksa
;
9319 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
9322 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9324 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9325 struct net_device
*dev
= info
->user_ptr
[1];
9327 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9328 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9331 if (!rdev
->ops
->flush_pmksa
)
9334 return rdev_flush_pmksa(rdev
, dev
);
9337 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9339 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9340 struct net_device
*dev
= info
->user_ptr
[1];
9341 u8 action_code
, dialog_token
;
9342 u32 peer_capability
= 0;
9347 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9348 !rdev
->ops
->tdls_mgmt
)
9351 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
9352 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
9353 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
9354 !info
->attrs
[NL80211_ATTR_IE
] ||
9355 !info
->attrs
[NL80211_ATTR_MAC
])
9358 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9359 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
9360 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
9361 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
9362 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
9363 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
9365 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
9367 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
9368 dialog_token
, status_code
, peer_capability
,
9370 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
9371 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
9374 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
9376 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9377 struct net_device
*dev
= info
->user_ptr
[1];
9378 enum nl80211_tdls_operation operation
;
9381 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9382 !rdev
->ops
->tdls_oper
)
9385 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
9386 !info
->attrs
[NL80211_ATTR_MAC
])
9389 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
9390 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9392 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
9395 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
9396 struct genl_info
*info
)
9398 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9399 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9400 struct cfg80211_chan_def chandef
;
9401 const struct cfg80211_chan_def
*compat_chandef
;
9402 struct sk_buff
*msg
;
9408 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
9409 !info
->attrs
[NL80211_ATTR_DURATION
])
9412 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9414 if (!rdev
->ops
->remain_on_channel
||
9415 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
9419 * We should be on that channel for at least a minimum amount of
9420 * time (10ms) but no longer than the driver supports.
9422 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9423 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
9426 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9431 if (!cfg80211_off_channel_oper_allowed(wdev
) &&
9432 !cfg80211_chandef_identical(&wdev
->chandef
, &chandef
)) {
9433 compat_chandef
= cfg80211_chandef_compatible(&wdev
->chandef
,
9435 if (compat_chandef
!= &chandef
) {
9442 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9446 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9447 NL80211_CMD_REMAIN_ON_CHANNEL
);
9453 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
9459 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9461 goto nla_put_failure
;
9463 genlmsg_end(msg
, hdr
);
9465 return genlmsg_reply(msg
, info
);
9474 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
9475 struct genl_info
*info
)
9477 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9478 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9481 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9484 if (!rdev
->ops
->cancel_remain_on_channel
)
9487 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9489 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
9492 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
9493 struct genl_info
*info
)
9495 struct cfg80211_bitrate_mask mask
;
9496 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9497 struct net_device
*dev
= info
->user_ptr
[1];
9500 if (!rdev
->ops
->set_bitrate_mask
)
9503 err
= nl80211_parse_tx_bitrate_mask(info
, &mask
);
9507 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
9510 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9512 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9513 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9514 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
9516 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
9519 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
9520 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
9522 switch (wdev
->iftype
) {
9523 case NL80211_IFTYPE_STATION
:
9524 case NL80211_IFTYPE_ADHOC
:
9525 case NL80211_IFTYPE_P2P_CLIENT
:
9526 case NL80211_IFTYPE_AP
:
9527 case NL80211_IFTYPE_AP_VLAN
:
9528 case NL80211_IFTYPE_MESH_POINT
:
9529 case NL80211_IFTYPE_P2P_GO
:
9530 case NL80211_IFTYPE_P2P_DEVICE
:
9532 case NL80211_IFTYPE_NAN
:
9537 /* not much point in registering if we can't reply */
9538 if (!rdev
->ops
->mgmt_tx
)
9541 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
9542 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
9543 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
9546 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9548 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9549 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9550 struct cfg80211_chan_def chandef
;
9554 struct sk_buff
*msg
= NULL
;
9555 struct cfg80211_mgmt_tx_params params
= {
9556 .dont_wait_for_ack
=
9557 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
9560 if (!info
->attrs
[NL80211_ATTR_FRAME
])
9563 if (!rdev
->ops
->mgmt_tx
)
9566 switch (wdev
->iftype
) {
9567 case NL80211_IFTYPE_P2P_DEVICE
:
9568 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9570 case NL80211_IFTYPE_STATION
:
9571 case NL80211_IFTYPE_ADHOC
:
9572 case NL80211_IFTYPE_P2P_CLIENT
:
9573 case NL80211_IFTYPE_AP
:
9574 case NL80211_IFTYPE_AP_VLAN
:
9575 case NL80211_IFTYPE_MESH_POINT
:
9576 case NL80211_IFTYPE_P2P_GO
:
9578 case NL80211_IFTYPE_NAN
:
9583 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
9584 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9586 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9589 * We should wait on the channel for at least a minimum amount
9590 * of time (10ms) but no longer than the driver supports.
9592 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9593 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
9597 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
9599 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9602 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
9604 /* get the channel if any has been specified, otherwise pass NULL to
9605 * the driver. The latter will use the current one
9607 chandef
.chan
= NULL
;
9608 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9609 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9614 if (!chandef
.chan
&& params
.offchan
)
9618 if (params
.offchan
&& !cfg80211_off_channel_oper_allowed(wdev
)) {
9624 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
9625 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
9627 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
9628 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9631 if (len
% sizeof(u16
))
9634 params
.n_csa_offsets
= len
/ sizeof(u16
);
9635 params
.csa_offsets
=
9636 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9638 /* check that all the offsets fit the frame */
9639 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
9640 if (params
.csa_offsets
[i
] >= params
.len
)
9645 if (!params
.dont_wait_for_ack
) {
9646 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9650 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9658 params
.chan
= chandef
.chan
;
9659 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
9664 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9666 goto nla_put_failure
;
9668 genlmsg_end(msg
, hdr
);
9669 return genlmsg_reply(msg
, info
);
9681 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
9683 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9684 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9687 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9690 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
9693 switch (wdev
->iftype
) {
9694 case NL80211_IFTYPE_STATION
:
9695 case NL80211_IFTYPE_ADHOC
:
9696 case NL80211_IFTYPE_P2P_CLIENT
:
9697 case NL80211_IFTYPE_AP
:
9698 case NL80211_IFTYPE_AP_VLAN
:
9699 case NL80211_IFTYPE_P2P_GO
:
9700 case NL80211_IFTYPE_P2P_DEVICE
:
9702 case NL80211_IFTYPE_NAN
:
9707 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9709 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
9712 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9714 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9715 struct wireless_dev
*wdev
;
9716 struct net_device
*dev
= info
->user_ptr
[1];
9721 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
9724 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
9726 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
9729 wdev
= dev
->ieee80211_ptr
;
9731 if (!rdev
->ops
->set_power_mgmt
)
9734 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
9736 if (state
== wdev
->ps
)
9739 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
9745 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9747 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9748 enum nl80211_ps_state ps_state
;
9749 struct wireless_dev
*wdev
;
9750 struct net_device
*dev
= info
->user_ptr
[1];
9751 struct sk_buff
*msg
;
9755 wdev
= dev
->ieee80211_ptr
;
9757 if (!rdev
->ops
->set_power_mgmt
)
9760 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9764 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9765 NL80211_CMD_GET_POWER_SAVE
);
9772 ps_state
= NL80211_PS_ENABLED
;
9774 ps_state
= NL80211_PS_DISABLED
;
9776 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
9777 goto nla_put_failure
;
9779 genlmsg_end(msg
, hdr
);
9780 return genlmsg_reply(msg
, info
);
9789 static const struct nla_policy
9790 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
9791 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_BINARY
},
9792 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
9793 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
9794 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
9795 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
9796 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
9797 [NL80211_ATTR_CQM_RSSI_LEVEL
] = { .type
= NLA_S32
},
9800 static int nl80211_set_cqm_txe(struct genl_info
*info
,
9801 u32 rate
, u32 pkts
, u32 intvl
)
9803 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9804 struct net_device
*dev
= info
->user_ptr
[1];
9805 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9807 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
9810 if (!rdev
->ops
->set_cqm_txe_config
)
9813 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9814 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9817 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
9820 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device
*rdev
,
9821 struct net_device
*dev
)
9823 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9824 s32 last
, low
, high
;
9829 /* RSSI reporting disabled? */
9830 if (!wdev
->cqm_config
)
9831 return rdev_set_cqm_rssi_range_config(rdev
, dev
, 0, 0);
9834 * Obtain current RSSI value if possible, if not and no RSSI threshold
9835 * event has been received yet, we should receive an event after a
9836 * connection is established and enough beacons received to calculate
9839 if (!wdev
->cqm_config
->last_rssi_event_value
&& wdev
->current_bss
&&
9840 rdev
->ops
->get_station
) {
9841 struct station_info sinfo
= {};
9844 mac_addr
= wdev
->current_bss
->pub
.bssid
;
9846 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
9850 if (sinfo
.filled
& BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG
))
9851 wdev
->cqm_config
->last_rssi_event_value
=
9852 (s8
) sinfo
.rx_beacon_signal_avg
;
9855 last
= wdev
->cqm_config
->last_rssi_event_value
;
9856 hyst
= wdev
->cqm_config
->rssi_hyst
;
9857 n
= wdev
->cqm_config
->n_rssi_thresholds
;
9859 for (i
= 0; i
< n
; i
++)
9860 if (last
< wdev
->cqm_config
->rssi_thresholds
[i
])
9864 (wdev
->cqm_config
->rssi_thresholds
[i
- 1] - hyst
) : S32_MIN
;
9866 (wdev
->cqm_config
->rssi_thresholds
[i
] + hyst
- 1) : S32_MAX
;
9868 return rdev_set_cqm_rssi_range_config(rdev
, dev
, low
, high
);
9871 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
9872 const s32
*thresholds
, int n_thresholds
,
9875 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9876 struct net_device
*dev
= info
->user_ptr
[1];
9877 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9881 /* Check all values negative and sorted */
9882 for (i
= 0; i
< n_thresholds
; i
++) {
9883 if (thresholds
[i
] > 0 || thresholds
[i
] <= prev
)
9886 prev
= thresholds
[i
];
9889 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9890 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9894 cfg80211_cqm_config_free(wdev
);
9897 if (n_thresholds
<= 1 && rdev
->ops
->set_cqm_rssi_config
) {
9898 if (n_thresholds
== 0 || thresholds
[0] == 0) /* Disabling */
9899 return rdev_set_cqm_rssi_config(rdev
, dev
, 0, 0);
9901 return rdev_set_cqm_rssi_config(rdev
, dev
,
9902 thresholds
[0], hysteresis
);
9905 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
9906 NL80211_EXT_FEATURE_CQM_RSSI_LIST
))
9909 if (n_thresholds
== 1 && thresholds
[0] == 0) /* Disabling */
9914 struct cfg80211_cqm_config
*cqm_config
;
9916 cqm_config
= kzalloc(sizeof(struct cfg80211_cqm_config
) +
9917 n_thresholds
* sizeof(s32
), GFP_KERNEL
);
9923 cqm_config
->rssi_hyst
= hysteresis
;
9924 cqm_config
->n_rssi_thresholds
= n_thresholds
;
9925 memcpy(cqm_config
->rssi_thresholds
, thresholds
,
9926 n_thresholds
* sizeof(s32
));
9928 wdev
->cqm_config
= cqm_config
;
9931 err
= cfg80211_cqm_rssi_update(rdev
, dev
);
9939 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
9941 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
9945 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
9949 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
9950 nl80211_attr_cqm_policy
, info
->extack
);
9954 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
9955 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
9956 const s32
*thresholds
=
9957 nla_data(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
9958 int len
= nla_len(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
9959 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
9964 return nl80211_set_cqm_rssi(info
, thresholds
, len
/ 4,
9968 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
9969 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
9970 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
9971 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
9972 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
9973 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
9975 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
9981 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9983 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9984 struct net_device
*dev
= info
->user_ptr
[1];
9985 struct ocb_setup setup
= {};
9988 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
9992 return cfg80211_join_ocb(rdev
, dev
, &setup
);
9995 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9997 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9998 struct net_device
*dev
= info
->user_ptr
[1];
10000 return cfg80211_leave_ocb(rdev
, dev
);
10003 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
10005 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10006 struct net_device
*dev
= info
->user_ptr
[1];
10007 struct mesh_config cfg
;
10008 struct mesh_setup setup
;
10011 /* start with default */
10012 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
10013 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
10015 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
10016 /* and parse parameters if given */
10017 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
10022 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
10023 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
10026 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
10027 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
10029 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
10030 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
10031 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
10034 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
10035 setup
.beacon_interval
=
10036 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
10038 err
= cfg80211_validate_beacon_int(rdev
,
10039 NL80211_IFTYPE_MESH_POINT
,
10040 setup
.beacon_interval
);
10045 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
10046 setup
.dtim_period
=
10047 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
10048 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
10052 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
10053 /* parse additional setup parameters if given */
10054 err
= nl80211_parse_mesh_setup(info
, &setup
);
10059 if (setup
.user_mpm
)
10060 cfg
.auto_open_plinks
= false;
10062 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
10063 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
10067 /* cfg80211_join_mesh() will sort it out */
10068 setup
.chandef
.chan
= NULL
;
10071 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
10072 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10074 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
10075 struct ieee80211_supported_band
*sband
;
10077 if (!setup
.chandef
.chan
)
10080 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
10082 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
10083 &setup
.basic_rates
);
10088 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
10089 err
= nl80211_parse_tx_bitrate_mask(info
, &setup
.beacon_rate
);
10093 if (!setup
.chandef
.chan
)
10096 err
= validate_beacon_tx_rate(rdev
, setup
.chandef
.chan
->band
,
10097 &setup
.beacon_rate
);
10102 setup
.userspace_handles_dfs
=
10103 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
10105 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
10108 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
10110 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10111 struct net_device
*dev
= info
->user_ptr
[1];
10113 return cfg80211_leave_mesh(rdev
, dev
);
10117 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
10118 struct cfg80211_registered_device
*rdev
)
10120 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
10121 struct nlattr
*nl_pats
, *nl_pat
;
10124 if (!wowlan
->n_patterns
)
10127 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
10131 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
10132 nl_pat
= nla_nest_start(msg
, i
+ 1);
10135 pat_len
= wowlan
->patterns
[i
].pattern_len
;
10136 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
10137 wowlan
->patterns
[i
].mask
) ||
10138 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
10139 wowlan
->patterns
[i
].pattern
) ||
10140 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
10141 wowlan
->patterns
[i
].pkt_offset
))
10143 nla_nest_end(msg
, nl_pat
);
10145 nla_nest_end(msg
, nl_pats
);
10150 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
10151 struct cfg80211_wowlan_tcp
*tcp
)
10153 struct nlattr
*nl_tcp
;
10158 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
10162 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
10163 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
10164 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
10165 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
10166 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
10167 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
10168 tcp
->payload_len
, tcp
->payload
) ||
10169 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
10170 tcp
->data_interval
) ||
10171 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
10172 tcp
->wake_len
, tcp
->wake_data
) ||
10173 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
10174 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
10177 if (tcp
->payload_seq
.len
&&
10178 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
10179 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
10182 if (tcp
->payload_tok
.len
&&
10183 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
10184 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
10185 &tcp
->payload_tok
))
10188 nla_nest_end(msg
, nl_tcp
);
10193 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
10194 struct cfg80211_sched_scan_request
*req
)
10196 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
10202 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
10206 if (req
->n_scan_plans
== 1 &&
10207 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
10208 req
->scan_plans
[0].interval
* 1000))
10211 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
10214 if (req
->relative_rssi_set
) {
10215 struct nl80211_bss_select_rssi_adjust rssi_adjust
;
10217 if (nla_put_s8(msg
, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
,
10218 req
->relative_rssi
))
10221 rssi_adjust
.band
= req
->rssi_adjust
.band
;
10222 rssi_adjust
.delta
= req
->rssi_adjust
.delta
;
10223 if (nla_put(msg
, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
,
10224 sizeof(rssi_adjust
), &rssi_adjust
))
10228 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
10232 for (i
= 0; i
< req
->n_channels
; i
++) {
10233 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
10237 nla_nest_end(msg
, freqs
);
10239 if (req
->n_match_sets
) {
10240 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
10244 for (i
= 0; i
< req
->n_match_sets
; i
++) {
10245 match
= nla_nest_start(msg
, i
);
10249 if (nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
10250 req
->match_sets
[i
].ssid
.ssid_len
,
10251 req
->match_sets
[i
].ssid
.ssid
))
10253 nla_nest_end(msg
, match
);
10255 nla_nest_end(msg
, matches
);
10258 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
10262 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
10263 scan_plan
= nla_nest_start(msg
, i
+ 1);
10268 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
10269 req
->scan_plans
[i
].interval
) ||
10270 (req
->scan_plans
[i
].iterations
&&
10271 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
10272 req
->scan_plans
[i
].iterations
)))
10274 nla_nest_end(msg
, scan_plan
);
10276 nla_nest_end(msg
, scan_plans
);
10278 nla_nest_end(msg
, nd
);
10283 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
10285 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10286 struct sk_buff
*msg
;
10288 u32 size
= NLMSG_DEFAULT_SIZE
;
10290 if (!rdev
->wiphy
.wowlan
)
10291 return -EOPNOTSUPP
;
10293 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
10294 /* adjust size to have room for all the data */
10295 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
10296 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
10297 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
10298 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
10301 msg
= nlmsg_new(size
, GFP_KERNEL
);
10305 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10306 NL80211_CMD_GET_WOWLAN
);
10308 goto nla_put_failure
;
10310 if (rdev
->wiphy
.wowlan_config
) {
10311 struct nlattr
*nl_wowlan
;
10313 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10315 goto nla_put_failure
;
10317 if ((rdev
->wiphy
.wowlan_config
->any
&&
10318 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
10319 (rdev
->wiphy
.wowlan_config
->disconnect
&&
10320 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
10321 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
10322 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
10323 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
10324 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
10325 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
10326 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
10327 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
10328 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
10329 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
10330 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
10331 goto nla_put_failure
;
10333 if (nl80211_send_wowlan_patterns(msg
, rdev
))
10334 goto nla_put_failure
;
10336 if (nl80211_send_wowlan_tcp(msg
,
10337 rdev
->wiphy
.wowlan_config
->tcp
))
10338 goto nla_put_failure
;
10340 if (nl80211_send_wowlan_nd(
10342 rdev
->wiphy
.wowlan_config
->nd_config
))
10343 goto nla_put_failure
;
10345 nla_nest_end(msg
, nl_wowlan
);
10348 genlmsg_end(msg
, hdr
);
10349 return genlmsg_reply(msg
, info
);
10356 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
10357 struct nlattr
*attr
,
10358 struct cfg80211_wowlan
*trig
)
10360 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
10361 struct cfg80211_wowlan_tcp
*cfg
;
10362 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
10363 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
10365 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
10368 if (!rdev
->wiphy
.wowlan
->tcp
)
10371 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TCP
, attr
,
10372 nl80211_wowlan_tcp_policy
, NULL
);
10376 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
10377 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
10378 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
10379 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
10380 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
10381 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
10382 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
10383 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
10386 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
10387 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
10390 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
10391 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
10392 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
10395 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
10396 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
10399 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
10400 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
10403 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
10404 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10406 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10407 tokens_size
= tokln
- sizeof(*tok
);
10409 if (!tok
->len
|| tokens_size
% tok
->len
)
10411 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
10413 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
10415 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
10417 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
10419 if (tok
->offset
+ tok
->len
> data_size
)
10423 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
10424 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
10425 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
10427 if (seq
->len
== 0 || seq
->len
> 4)
10429 if (seq
->len
+ seq
->offset
> data_size
)
10433 size
= sizeof(*cfg
);
10435 size
+= wake_size
+ wake_mask_size
;
10436 size
+= tokens_size
;
10438 cfg
= kzalloc(size
, GFP_KERNEL
);
10441 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
10442 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
10443 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
10445 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
10446 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
10450 /* allocate a socket and port for it and use it */
10451 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
10452 IPPROTO_TCP
, &cfg
->sock
, 1);
10457 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
10458 sock_release(cfg
->sock
);
10460 return -EADDRINUSE
;
10462 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
10468 cfg
->src_port
= port
;
10471 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
10472 cfg
->payload_len
= data_size
;
10473 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
10474 memcpy((void *)cfg
->payload
,
10475 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
10478 cfg
->payload_seq
= *seq
;
10479 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
10480 cfg
->wake_len
= wake_size
;
10481 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
10482 memcpy((void *)cfg
->wake_data
,
10483 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
10485 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
10486 data_size
+ wake_size
;
10487 memcpy((void *)cfg
->wake_mask
,
10488 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
10491 cfg
->tokens_size
= tokens_size
;
10492 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
10500 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
10501 const struct wiphy_wowlan_support
*wowlan
,
10502 struct nlattr
*attr
,
10503 struct cfg80211_wowlan
*trig
)
10505 struct nlattr
**tb
;
10508 tb
= kzalloc(NUM_NL80211_ATTR
* sizeof(*tb
), GFP_KERNEL
);
10512 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
10517 err
= nla_parse_nested(tb
, NL80211_ATTR_MAX
, attr
, nl80211_policy
,
10522 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
,
10523 wowlan
->max_nd_match_sets
);
10524 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
10526 trig
->nd_config
= NULL
;
10533 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
10535 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10536 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
10537 struct cfg80211_wowlan new_triggers
= {};
10538 struct cfg80211_wowlan
*ntrig
;
10539 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
10541 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
10542 bool regular
= false;
10545 return -EOPNOTSUPP
;
10547 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
10548 cfg80211_rdev_free_wowlan(rdev
);
10549 rdev
->wiphy
.wowlan_config
= NULL
;
10553 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TRIG
,
10554 info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
],
10555 nl80211_wowlan_policy
, info
->extack
);
10559 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
10560 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
10562 new_triggers
.any
= true;
10565 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
10566 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
10568 new_triggers
.disconnect
= true;
10572 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
10573 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
10575 new_triggers
.magic_pkt
= true;
10579 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
10582 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
10583 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
10585 new_triggers
.gtk_rekey_failure
= true;
10589 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
10590 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
10592 new_triggers
.eap_identity_req
= true;
10596 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
10597 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
10599 new_triggers
.four_way_handshake
= true;
10603 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
10604 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
10606 new_triggers
.rfkill_release
= true;
10610 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
10611 struct nlattr
*pat
;
10612 int n_patterns
= 0;
10613 int rem
, pat_len
, mask_len
, pkt_offset
;
10614 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
10618 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
10621 if (n_patterns
> wowlan
->n_patterns
)
10624 new_triggers
.patterns
= kcalloc(n_patterns
,
10625 sizeof(new_triggers
.patterns
[0]),
10627 if (!new_triggers
.patterns
)
10630 new_triggers
.n_patterns
= n_patterns
;
10633 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
10637 nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
10638 nl80211_packet_pattern_policy
,
10641 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10642 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10644 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10645 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10646 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10648 if (pat_len
> wowlan
->pattern_max_len
||
10649 pat_len
< wowlan
->pattern_min_len
)
10652 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10655 pkt_offset
= nla_get_u32(
10656 pat_tb
[NL80211_PKTPAT_OFFSET
]);
10657 if (pkt_offset
> wowlan
->max_pkt_offset
)
10659 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
10661 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10666 new_triggers
.patterns
[i
].mask
= mask_pat
;
10667 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10669 mask_pat
+= mask_len
;
10670 new_triggers
.patterns
[i
].pattern
= mask_pat
;
10671 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
10673 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
10679 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
10681 err
= nl80211_parse_wowlan_tcp(
10682 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
10688 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
10690 err
= nl80211_parse_wowlan_nd(
10691 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
10697 /* The 'any' trigger means the device continues operating more or less
10698 * as in its normal operation mode and wakes up the host on most of the
10699 * normal interrupts (like packet RX, ...)
10700 * It therefore makes little sense to combine with the more constrained
10701 * wakeup trigger modes.
10703 if (new_triggers
.any
&& regular
) {
10708 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
10713 cfg80211_rdev_free_wowlan(rdev
);
10714 rdev
->wiphy
.wowlan_config
= ntrig
;
10717 if (rdev
->ops
->set_wakeup
&&
10718 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
10719 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
10723 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
10724 kfree(new_triggers
.patterns
[i
].mask
);
10725 kfree(new_triggers
.patterns
);
10726 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
10727 sock_release(new_triggers
.tcp
->sock
);
10728 kfree(new_triggers
.tcp
);
10729 kfree(new_triggers
.nd_config
);
10734 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
10735 struct cfg80211_registered_device
*rdev
)
10737 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
10739 struct cfg80211_coalesce_rules
*rule
;
10741 if (!rdev
->coalesce
->n_rules
)
10744 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
10748 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
10749 nl_rule
= nla_nest_start(msg
, i
+ 1);
10753 rule
= &rdev
->coalesce
->rules
[i
];
10754 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
10758 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
10762 nl_pats
= nla_nest_start(msg
,
10763 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
10767 for (j
= 0; j
< rule
->n_patterns
; j
++) {
10768 nl_pat
= nla_nest_start(msg
, j
+ 1);
10771 pat_len
= rule
->patterns
[j
].pattern_len
;
10772 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
10773 DIV_ROUND_UP(pat_len
, 8),
10774 rule
->patterns
[j
].mask
) ||
10775 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
10776 rule
->patterns
[j
].pattern
) ||
10777 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
10778 rule
->patterns
[j
].pkt_offset
))
10780 nla_nest_end(msg
, nl_pat
);
10782 nla_nest_end(msg
, nl_pats
);
10783 nla_nest_end(msg
, nl_rule
);
10785 nla_nest_end(msg
, nl_rules
);
10790 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
10792 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10793 struct sk_buff
*msg
;
10796 if (!rdev
->wiphy
.coalesce
)
10797 return -EOPNOTSUPP
;
10799 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10803 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10804 NL80211_CMD_GET_COALESCE
);
10806 goto nla_put_failure
;
10808 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
10809 goto nla_put_failure
;
10811 genlmsg_end(msg
, hdr
);
10812 return genlmsg_reply(msg
, info
);
10819 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
10821 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
10823 struct cfg80211_coalesce_rules
*rule
;
10828 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
10829 rule
= &coalesce
->rules
[i
];
10830 for (j
= 0; j
< rule
->n_patterns
; j
++)
10831 kfree(rule
->patterns
[j
].mask
);
10832 kfree(rule
->patterns
);
10834 kfree(coalesce
->rules
);
10836 rdev
->coalesce
= NULL
;
10839 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
10840 struct nlattr
*rule
,
10841 struct cfg80211_coalesce_rules
*new_rule
)
10844 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10845 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
10846 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
10847 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
10849 err
= nla_parse_nested(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, rule
,
10850 nl80211_coalesce_policy
, NULL
);
10854 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
10856 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
10857 if (new_rule
->delay
> coalesce
->max_delay
)
10860 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
10861 new_rule
->condition
=
10862 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
10863 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
10864 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
10867 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
10870 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10873 if (n_patterns
> coalesce
->n_patterns
)
10876 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
10878 if (!new_rule
->patterns
)
10881 new_rule
->n_patterns
= n_patterns
;
10884 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10888 nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
10889 nl80211_packet_pattern_policy
, NULL
);
10890 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10891 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10893 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10894 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10895 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10897 if (pat_len
> coalesce
->pattern_max_len
||
10898 pat_len
< coalesce
->pattern_min_len
)
10901 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10904 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
10905 if (pkt_offset
> coalesce
->max_pkt_offset
)
10907 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
10909 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10913 new_rule
->patterns
[i
].mask
= mask_pat
;
10914 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10917 mask_pat
+= mask_len
;
10918 new_rule
->patterns
[i
].pattern
= mask_pat
;
10919 new_rule
->patterns
[i
].pattern_len
= pat_len
;
10920 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
10928 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
10930 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10931 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10932 struct cfg80211_coalesce new_coalesce
= {};
10933 struct cfg80211_coalesce
*n_coalesce
;
10934 int err
, rem_rule
, n_rules
= 0, i
, j
;
10935 struct nlattr
*rule
;
10936 struct cfg80211_coalesce_rules
*tmp_rule
;
10938 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
10939 return -EOPNOTSUPP
;
10941 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
10942 cfg80211_rdev_free_coalesce(rdev
);
10943 rdev_set_coalesce(rdev
, NULL
);
10947 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10950 if (n_rules
> coalesce
->n_rules
)
10953 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
10955 if (!new_coalesce
.rules
)
10958 new_coalesce
.n_rules
= n_rules
;
10961 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10963 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
10964 &new_coalesce
.rules
[i
]);
10971 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
10975 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
10980 cfg80211_rdev_free_coalesce(rdev
);
10981 rdev
->coalesce
= n_coalesce
;
10985 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
10986 tmp_rule
= &new_coalesce
.rules
[i
];
10987 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
10988 kfree(tmp_rule
->patterns
[j
].mask
);
10989 kfree(tmp_rule
->patterns
);
10991 kfree(new_coalesce
.rules
);
10996 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
10998 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10999 struct net_device
*dev
= info
->user_ptr
[1];
11000 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11001 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
11002 struct cfg80211_gtk_rekey_data rekey_data
;
11005 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
11008 err
= nla_parse_nested(tb
, MAX_NL80211_REKEY_DATA
,
11009 info
->attrs
[NL80211_ATTR_REKEY_DATA
],
11010 nl80211_rekey_policy
, info
->extack
);
11014 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
11015 !tb
[NL80211_REKEY_DATA_KCK
])
11017 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
11019 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
11021 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
11024 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
11025 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
11026 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
11029 if (!wdev
->current_bss
) {
11034 if (!rdev
->ops
->set_rekey_data
) {
11039 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
11045 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
11046 struct genl_info
*info
)
11048 struct net_device
*dev
= info
->user_ptr
[1];
11049 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11051 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11052 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
11055 if (wdev
->ap_unexpected_nlportid
)
11058 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
11062 static int nl80211_probe_client(struct sk_buff
*skb
,
11063 struct genl_info
*info
)
11065 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11066 struct net_device
*dev
= info
->user_ptr
[1];
11067 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11068 struct sk_buff
*msg
;
11074 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11075 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
11076 return -EOPNOTSUPP
;
11078 if (!info
->attrs
[NL80211_ATTR_MAC
])
11081 if (!rdev
->ops
->probe_client
)
11082 return -EOPNOTSUPP
;
11084 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11088 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11089 NL80211_CMD_PROBE_CLIENT
);
11095 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11097 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
11101 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11103 goto nla_put_failure
;
11105 genlmsg_end(msg
, hdr
);
11107 return genlmsg_reply(msg
, info
);
11116 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
11118 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11119 struct cfg80211_beacon_registration
*reg
, *nreg
;
11122 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
11123 return -EOPNOTSUPP
;
11125 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
11129 /* First, check if already registered. */
11130 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11131 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
11132 if (reg
->nlportid
== info
->snd_portid
) {
11137 /* Add it to the list */
11138 nreg
->nlportid
= info
->snd_portid
;
11139 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
11141 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11145 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11150 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11152 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11153 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11156 if (!rdev
->ops
->start_p2p_device
)
11157 return -EOPNOTSUPP
;
11159 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11160 return -EOPNOTSUPP
;
11162 if (wdev_running(wdev
))
11165 if (rfkill_blocked(rdev
->rfkill
))
11168 err
= rdev_start_p2p_device(rdev
, wdev
);
11172 wdev
->is_running
= true;
11178 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11180 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11181 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11183 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11184 return -EOPNOTSUPP
;
11186 if (!rdev
->ops
->stop_p2p_device
)
11187 return -EOPNOTSUPP
;
11189 cfg80211_stop_p2p_device(rdev
, wdev
);
11194 static int nl80211_start_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11196 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11197 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11198 struct cfg80211_nan_conf conf
= {};
11201 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11202 return -EOPNOTSUPP
;
11204 if (wdev_running(wdev
))
11207 if (rfkill_blocked(rdev
->rfkill
))
11210 if (!info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
])
11214 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
11215 if (!conf
.master_pref
)
11218 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
11219 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
11221 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
11222 return -EOPNOTSUPP
;
11224 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
11227 conf
.bands
= bands
;
11230 err
= rdev_start_nan(rdev
, wdev
, &conf
);
11234 wdev
->is_running
= true;
11240 static int nl80211_stop_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11242 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11243 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11245 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11246 return -EOPNOTSUPP
;
11248 cfg80211_stop_nan(rdev
, wdev
);
11253 static int validate_nan_filter(struct nlattr
*filter_attr
)
11255 struct nlattr
*attr
;
11256 int len
= 0, n_entries
= 0, rem
;
11258 nla_for_each_nested(attr
, filter_attr
, rem
) {
11259 len
+= nla_len(attr
);
11269 static int handle_nan_filter(struct nlattr
*attr_filter
,
11270 struct cfg80211_nan_func
*func
,
11273 struct nlattr
*attr
;
11274 int n_entries
, rem
, i
;
11275 struct cfg80211_nan_func_filter
*filter
;
11277 n_entries
= validate_nan_filter(attr_filter
);
11281 BUILD_BUG_ON(sizeof(*func
->rx_filters
) != sizeof(*func
->tx_filters
));
11283 filter
= kcalloc(n_entries
, sizeof(*func
->rx_filters
), GFP_KERNEL
);
11288 nla_for_each_nested(attr
, attr_filter
, rem
) {
11289 filter
[i
].filter
= nla_memdup(attr
, GFP_KERNEL
);
11290 filter
[i
].len
= nla_len(attr
);
11294 func
->num_tx_filters
= n_entries
;
11295 func
->tx_filters
= filter
;
11297 func
->num_rx_filters
= n_entries
;
11298 func
->rx_filters
= filter
;
11304 static int nl80211_nan_add_func(struct sk_buff
*skb
,
11305 struct genl_info
*info
)
11307 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11308 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11309 struct nlattr
*tb
[NUM_NL80211_NAN_FUNC_ATTR
], *func_attr
;
11310 struct cfg80211_nan_func
*func
;
11311 struct sk_buff
*msg
= NULL
;
11315 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11316 return -EOPNOTSUPP
;
11318 if (!wdev_running(wdev
))
11321 if (!info
->attrs
[NL80211_ATTR_NAN_FUNC
])
11324 err
= nla_parse_nested(tb
, NL80211_NAN_FUNC_ATTR_MAX
,
11325 info
->attrs
[NL80211_ATTR_NAN_FUNC
],
11326 nl80211_nan_func_policy
, info
->extack
);
11330 func
= kzalloc(sizeof(*func
), GFP_KERNEL
);
11334 func
->cookie
= wdev
->wiphy
->cookie_counter
++;
11336 if (!tb
[NL80211_NAN_FUNC_TYPE
] ||
11337 nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]) > NL80211_NAN_FUNC_MAX_TYPE
) {
11343 func
->type
= nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]);
11345 if (!tb
[NL80211_NAN_FUNC_SERVICE_ID
]) {
11350 memcpy(func
->service_id
, nla_data(tb
[NL80211_NAN_FUNC_SERVICE_ID
]),
11351 sizeof(func
->service_id
));
11353 func
->close_range
=
11354 nla_get_flag(tb
[NL80211_NAN_FUNC_CLOSE_RANGE
]);
11356 if (tb
[NL80211_NAN_FUNC_SERVICE_INFO
]) {
11357 func
->serv_spec_info_len
=
11358 nla_len(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]);
11359 func
->serv_spec_info
=
11360 kmemdup(nla_data(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]),
11361 func
->serv_spec_info_len
,
11363 if (!func
->serv_spec_info
) {
11369 if (tb
[NL80211_NAN_FUNC_TTL
])
11370 func
->ttl
= nla_get_u32(tb
[NL80211_NAN_FUNC_TTL
]);
11372 switch (func
->type
) {
11373 case NL80211_NAN_FUNC_PUBLISH
:
11374 if (!tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]) {
11379 func
->publish_type
=
11380 nla_get_u8(tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]);
11381 func
->publish_bcast
=
11382 nla_get_flag(tb
[NL80211_NAN_FUNC_PUBLISH_BCAST
]);
11384 if ((!(func
->publish_type
& NL80211_NAN_SOLICITED_PUBLISH
)) &&
11385 func
->publish_bcast
) {
11390 case NL80211_NAN_FUNC_SUBSCRIBE
:
11391 func
->subscribe_active
=
11392 nla_get_flag(tb
[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
]);
11394 case NL80211_NAN_FUNC_FOLLOW_UP
:
11395 if (!tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
] ||
11396 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] ||
11397 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]) {
11402 func
->followup_id
=
11403 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
]);
11404 func
->followup_reqid
=
11405 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]);
11406 memcpy(func
->followup_dest
.addr
,
11407 nla_data(tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]),
11408 sizeof(func
->followup_dest
.addr
));
11419 if (tb
[NL80211_NAN_FUNC_SRF
]) {
11420 struct nlattr
*srf_tb
[NUM_NL80211_NAN_SRF_ATTR
];
11422 err
= nla_parse_nested(srf_tb
, NL80211_NAN_SRF_ATTR_MAX
,
11423 tb
[NL80211_NAN_FUNC_SRF
],
11424 nl80211_nan_srf_policy
, info
->extack
);
11428 func
->srf_include
=
11429 nla_get_flag(srf_tb
[NL80211_NAN_SRF_INCLUDE
]);
11431 if (srf_tb
[NL80211_NAN_SRF_BF
]) {
11432 if (srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
] ||
11433 !srf_tb
[NL80211_NAN_SRF_BF_IDX
]) {
11439 nla_len(srf_tb
[NL80211_NAN_SRF_BF
]);
11441 kmemdup(nla_data(srf_tb
[NL80211_NAN_SRF_BF
]),
11442 func
->srf_bf_len
, GFP_KERNEL
);
11443 if (!func
->srf_bf
) {
11449 nla_get_u8(srf_tb
[NL80211_NAN_SRF_BF_IDX
]);
11451 struct nlattr
*attr
, *mac_attr
=
11452 srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
];
11453 int n_entries
, rem
, i
= 0;
11460 n_entries
= validate_acl_mac_addrs(mac_attr
);
11461 if (n_entries
<= 0) {
11466 func
->srf_num_macs
= n_entries
;
11468 kzalloc(sizeof(*func
->srf_macs
) * n_entries
,
11470 if (!func
->srf_macs
) {
11475 nla_for_each_nested(attr
, mac_attr
, rem
)
11476 memcpy(func
->srf_macs
[i
++].addr
, nla_data(attr
),
11477 sizeof(*func
->srf_macs
));
11481 if (tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
]) {
11482 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
],
11488 if (tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
]) {
11489 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
],
11495 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11501 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11502 NL80211_CMD_ADD_NAN_FUNCTION
);
11503 /* This can't really happen - we just allocated 4KB */
11504 if (WARN_ON(!hdr
)) {
11509 err
= rdev_add_nan_func(rdev
, wdev
, func
);
11512 cfg80211_free_nan_func(func
);
11517 /* propagate the instance id and cookie to userspace */
11518 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, func
->cookie
,
11520 goto nla_put_failure
;
11522 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
11524 goto nla_put_failure
;
11526 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
,
11527 func
->instance_id
))
11528 goto nla_put_failure
;
11530 nla_nest_end(msg
, func_attr
);
11532 genlmsg_end(msg
, hdr
);
11533 return genlmsg_reply(msg
, info
);
11540 static int nl80211_nan_del_func(struct sk_buff
*skb
,
11541 struct genl_info
*info
)
11543 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11544 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11547 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11548 return -EOPNOTSUPP
;
11550 if (!wdev_running(wdev
))
11553 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
11556 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
11558 rdev_del_nan_func(rdev
, wdev
, cookie
);
11563 static int nl80211_nan_change_config(struct sk_buff
*skb
,
11564 struct genl_info
*info
)
11566 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11567 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11568 struct cfg80211_nan_conf conf
= {};
11571 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11572 return -EOPNOTSUPP
;
11574 if (!wdev_running(wdev
))
11577 if (info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]) {
11579 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
11580 if (conf
.master_pref
<= 1 || conf
.master_pref
== 255)
11583 changed
|= CFG80211_NAN_CONF_CHANGED_PREF
;
11586 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
11587 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
11589 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
11590 return -EOPNOTSUPP
;
11592 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
11595 conf
.bands
= bands
;
11596 changed
|= CFG80211_NAN_CONF_CHANGED_BANDS
;
11602 return rdev_nan_change_conf(rdev
, wdev
, &conf
, changed
);
11605 void cfg80211_nan_match(struct wireless_dev
*wdev
,
11606 struct cfg80211_nan_match_params
*match
, gfp_t gfp
)
11608 struct wiphy
*wiphy
= wdev
->wiphy
;
11609 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11610 struct nlattr
*match_attr
, *local_func_attr
, *peer_func_attr
;
11611 struct sk_buff
*msg
;
11614 if (WARN_ON(!match
->inst_id
|| !match
->peer_inst_id
|| !match
->addr
))
11617 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11621 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NAN_MATCH
);
11627 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11628 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11629 wdev
->netdev
->ifindex
)) ||
11630 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
11632 goto nla_put_failure
;
11634 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, match
->cookie
,
11635 NL80211_ATTR_PAD
) ||
11636 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, match
->addr
))
11637 goto nla_put_failure
;
11639 match_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_MATCH
);
11641 goto nla_put_failure
;
11643 local_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_LOCAL
);
11644 if (!local_func_attr
)
11645 goto nla_put_failure
;
11647 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->inst_id
))
11648 goto nla_put_failure
;
11650 nla_nest_end(msg
, local_func_attr
);
11652 peer_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_PEER
);
11653 if (!peer_func_attr
)
11654 goto nla_put_failure
;
11656 if (nla_put_u8(msg
, NL80211_NAN_FUNC_TYPE
, match
->type
) ||
11657 nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->peer_inst_id
))
11658 goto nla_put_failure
;
11660 if (match
->info
&& match
->info_len
&&
11661 nla_put(msg
, NL80211_NAN_FUNC_SERVICE_INFO
, match
->info_len
,
11663 goto nla_put_failure
;
11665 nla_nest_end(msg
, peer_func_attr
);
11666 nla_nest_end(msg
, match_attr
);
11667 genlmsg_end(msg
, hdr
);
11669 if (!wdev
->owner_nlportid
)
11670 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
11671 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
11673 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
11674 wdev
->owner_nlportid
);
11681 EXPORT_SYMBOL(cfg80211_nan_match
);
11683 void cfg80211_nan_func_terminated(struct wireless_dev
*wdev
,
11685 enum nl80211_nan_func_term_reason reason
,
11686 u64 cookie
, gfp_t gfp
)
11688 struct wiphy
*wiphy
= wdev
->wiphy
;
11689 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11690 struct sk_buff
*msg
;
11691 struct nlattr
*func_attr
;
11694 if (WARN_ON(!inst_id
))
11697 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11701 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION
);
11707 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11708 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11709 wdev
->netdev
->ifindex
)) ||
11710 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
11712 goto nla_put_failure
;
11714 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11716 goto nla_put_failure
;
11718 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
11720 goto nla_put_failure
;
11722 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, inst_id
) ||
11723 nla_put_u8(msg
, NL80211_NAN_FUNC_TERM_REASON
, reason
))
11724 goto nla_put_failure
;
11726 nla_nest_end(msg
, func_attr
);
11727 genlmsg_end(msg
, hdr
);
11729 if (!wdev
->owner_nlportid
)
11730 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
11731 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
11733 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
11734 wdev
->owner_nlportid
);
11741 EXPORT_SYMBOL(cfg80211_nan_func_terminated
);
11743 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
11744 struct genl_info
*info
)
11747 struct sk_buff
*msg
;
11749 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11753 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11754 NL80211_CMD_GET_PROTOCOL_FEATURES
);
11756 goto nla_put_failure
;
11758 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
11759 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
11760 goto nla_put_failure
;
11762 genlmsg_end(msg
, hdr
);
11763 return genlmsg_reply(msg
, info
);
11770 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
11772 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11773 struct cfg80211_update_ft_ies_params ft_params
;
11774 struct net_device
*dev
= info
->user_ptr
[1];
11776 if (!rdev
->ops
->update_ft_ies
)
11777 return -EOPNOTSUPP
;
11779 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
11780 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
11783 memset(&ft_params
, 0, sizeof(ft_params
));
11784 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
11785 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
11786 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
11788 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
11791 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
11792 struct genl_info
*info
)
11794 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11795 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11796 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
11800 if (!rdev
->ops
->crit_proto_start
)
11801 return -EOPNOTSUPP
;
11803 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
11806 if (rdev
->crit_proto_nlportid
)
11809 /* determine protocol if provided */
11810 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
11811 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
11813 if (proto
>= NUM_NL80211_CRIT_PROTO
)
11816 /* timeout must be provided */
11817 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
11821 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
11823 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
11826 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
11828 rdev
->crit_proto_nlportid
= info
->snd_portid
;
11833 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
11834 struct genl_info
*info
)
11836 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11837 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11839 if (!rdev
->ops
->crit_proto_stop
)
11840 return -EOPNOTSUPP
;
11842 if (rdev
->crit_proto_nlportid
) {
11843 rdev
->crit_proto_nlportid
= 0;
11844 rdev_crit_proto_stop(rdev
, wdev
);
11849 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
11851 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11852 struct wireless_dev
*wdev
=
11853 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
11857 if (!rdev
->wiphy
.vendor_commands
)
11858 return -EOPNOTSUPP
;
11860 if (IS_ERR(wdev
)) {
11861 err
= PTR_ERR(wdev
);
11862 if (err
!= -EINVAL
)
11865 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
11869 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
11870 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
11873 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
11874 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
11875 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
11876 const struct wiphy_vendor_command
*vcmd
;
11880 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
11882 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
11885 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
11886 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
11889 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
11893 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
11894 if (!wdev_running(wdev
))
11899 return -EOPNOTSUPP
;
11904 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
11905 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
11906 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
11909 rdev
->cur_cmd_info
= info
;
11910 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
11912 rdev
->cur_cmd_info
= NULL
;
11916 return -EOPNOTSUPP
;
11919 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
11920 struct netlink_callback
*cb
,
11921 struct cfg80211_registered_device
**rdev
,
11922 struct wireless_dev
**wdev
)
11924 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
11930 unsigned int data_len
= 0;
11933 /* subtract the 1 again here */
11934 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
11935 struct wireless_dev
*tmp
;
11939 *rdev
= wiphy_to_rdev(wiphy
);
11943 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
11944 if (tmp
->identifier
== cb
->args
[1] - 1) {
11951 /* keep rtnl locked in successful case */
11955 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, attrbuf
,
11956 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
11960 if (!attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
11961 !attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
])
11964 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
11968 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
11970 return PTR_ERR(*rdev
);
11972 vid
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_ID
]);
11973 subcmd
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
11975 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
11976 const struct wiphy_vendor_command
*vcmd
;
11978 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
11980 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
11984 return -EOPNOTSUPP
;
11991 return -EOPNOTSUPP
;
11993 if (attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
11994 data
= nla_data(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
11995 data_len
= nla_len(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
11998 /* 0 is the first index - add 1 to parse only once */
11999 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
12000 /* add 1 to know if it was NULL */
12001 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
12002 cb
->args
[2] = vcmd_idx
;
12003 cb
->args
[3] = (unsigned long)data
;
12004 cb
->args
[4] = data_len
;
12006 /* keep rtnl locked in successful case */
12010 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
12011 struct netlink_callback
*cb
)
12013 struct cfg80211_registered_device
*rdev
;
12014 struct wireless_dev
*wdev
;
12015 unsigned int vcmd_idx
;
12016 const struct wiphy_vendor_command
*vcmd
;
12020 struct nlattr
*vendor_data
;
12023 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
12027 vcmd_idx
= cb
->args
[2];
12028 data
= (void *)cb
->args
[3];
12029 data_len
= cb
->args
[4];
12030 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
12032 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
12033 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
12038 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
12044 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
12045 if (!wdev_running(wdev
)) {
12053 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
12054 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
12055 NL80211_CMD_VENDOR
);
12059 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12060 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
12062 NL80211_ATTR_PAD
))) {
12063 genlmsg_cancel(skb
, hdr
);
12067 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
12068 if (!vendor_data
) {
12069 genlmsg_cancel(skb
, hdr
);
12073 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
12074 (unsigned long *)&cb
->args
[5]);
12075 nla_nest_end(skb
, vendor_data
);
12077 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
12078 genlmsg_cancel(skb
, hdr
);
12081 genlmsg_cancel(skb
, hdr
);
12085 genlmsg_end(skb
, hdr
);
12094 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
12095 enum nl80211_commands cmd
,
12096 enum nl80211_attrs attr
,
12099 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12101 if (WARN_ON(!rdev
->cur_cmd_info
))
12104 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
12105 rdev
->cur_cmd_info
->snd_portid
,
12106 rdev
->cur_cmd_info
->snd_seq
,
12107 cmd
, attr
, NULL
, GFP_KERNEL
);
12109 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
12111 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
12113 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
12114 void *hdr
= ((void **)skb
->cb
)[1];
12115 struct nlattr
*data
= ((void **)skb
->cb
)[2];
12117 /* clear CB data for netlink core to own from now on */
12118 memset(skb
->cb
, 0, sizeof(skb
->cb
));
12120 if (WARN_ON(!rdev
->cur_cmd_info
)) {
12125 nla_nest_end(skb
, data
);
12126 genlmsg_end(skb
, hdr
);
12127 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
12129 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
12131 static int nl80211_set_qos_map(struct sk_buff
*skb
,
12132 struct genl_info
*info
)
12134 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12135 struct cfg80211_qos_map
*qos_map
= NULL
;
12136 struct net_device
*dev
= info
->user_ptr
[1];
12137 u8
*pos
, len
, num_des
, des_len
, des
;
12140 if (!rdev
->ops
->set_qos_map
)
12141 return -EOPNOTSUPP
;
12143 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
12144 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12145 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12147 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
12148 len
> IEEE80211_QOS_MAP_LEN_MAX
)
12151 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
12155 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
12157 des_len
= num_des
*
12158 sizeof(struct cfg80211_dscp_exception
);
12159 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
12160 qos_map
->num_des
= num_des
;
12161 for (des
= 0; des
< num_des
; des
++) {
12162 if (qos_map
->dscp_exception
[des
].up
> 7) {
12169 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
12172 wdev_lock(dev
->ieee80211_ptr
);
12173 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
12175 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
12176 wdev_unlock(dev
->ieee80211_ptr
);
12182 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12184 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12185 struct net_device
*dev
= info
->user_ptr
[1];
12186 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12189 u16 admitted_time
= 0;
12192 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
12193 return -EOPNOTSUPP
;
12195 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
12196 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
12199 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12200 if (tsid
>= IEEE80211_NUM_TIDS
)
12203 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
12204 if (up
>= IEEE80211_NUM_UPS
)
12207 /* WMM uses TIDs 0-7 even for TSPEC */
12208 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
12209 /* TODO: handle 802.11 TSPEC/admission control
12210 * need more attributes for that (e.g. BA session requirement);
12211 * change the WMM adminssion test above to allow both then
12216 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12218 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
12220 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
12221 if (!admitted_time
)
12226 switch (wdev
->iftype
) {
12227 case NL80211_IFTYPE_STATION
:
12228 case NL80211_IFTYPE_P2P_CLIENT
:
12229 if (wdev
->current_bss
)
12238 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
12245 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12247 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12248 struct net_device
*dev
= info
->user_ptr
[1];
12249 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12254 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
12257 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12258 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12261 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
12267 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
12268 struct genl_info
*info
)
12270 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12271 struct net_device
*dev
= info
->user_ptr
[1];
12272 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12273 struct cfg80211_chan_def chandef
= {};
12278 if (!rdev
->ops
->tdls_channel_switch
||
12279 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12280 return -EOPNOTSUPP
;
12282 switch (dev
->ieee80211_ptr
->iftype
) {
12283 case NL80211_IFTYPE_STATION
:
12284 case NL80211_IFTYPE_P2P_CLIENT
:
12287 return -EOPNOTSUPP
;
12290 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
12291 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
12294 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
12299 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12300 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12301 * specification is not defined for them.
12303 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
12304 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
12305 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
12308 /* we will be active on the TDLS link */
12309 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
12313 /* don't allow switching to DFS channels */
12314 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
12317 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12318 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
12321 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
12327 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
12328 struct genl_info
*info
)
12330 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12331 struct net_device
*dev
= info
->user_ptr
[1];
12332 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12335 if (!rdev
->ops
->tdls_channel_switch
||
12336 !rdev
->ops
->tdls_cancel_channel_switch
||
12337 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12338 return -EOPNOTSUPP
;
12340 switch (dev
->ieee80211_ptr
->iftype
) {
12341 case NL80211_IFTYPE_STATION
:
12342 case NL80211_IFTYPE_P2P_CLIENT
:
12345 return -EOPNOTSUPP
;
12348 if (!info
->attrs
[NL80211_ATTR_MAC
])
12351 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12354 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
12360 static int nl80211_set_multicast_to_unicast(struct sk_buff
*skb
,
12361 struct genl_info
*info
)
12363 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12364 struct net_device
*dev
= info
->user_ptr
[1];
12365 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12366 const struct nlattr
*nla
;
12369 if (!rdev
->ops
->set_multicast_to_unicast
)
12370 return -EOPNOTSUPP
;
12372 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12373 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12374 return -EOPNOTSUPP
;
12376 nla
= info
->attrs
[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
];
12377 enabled
= nla_get_flag(nla
);
12379 return rdev_set_multicast_to_unicast(rdev
, dev
, enabled
);
12382 static int nl80211_set_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12384 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12385 struct net_device
*dev
= info
->user_ptr
[1];
12386 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12387 struct cfg80211_pmk_conf pmk_conf
= {};
12390 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12391 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12392 return -EOPNOTSUPP
;
12394 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12395 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12396 return -EOPNOTSUPP
;
12398 if (!info
->attrs
[NL80211_ATTR_MAC
] || !info
->attrs
[NL80211_ATTR_PMK
])
12402 if (!wdev
->current_bss
) {
12407 pmk_conf
.aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12408 if (memcmp(pmk_conf
.aa
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
)) {
12413 pmk_conf
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
12414 pmk_conf
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
12415 if (pmk_conf
.pmk_len
!= WLAN_PMK_LEN
&&
12416 pmk_conf
.pmk_len
!= WLAN_PMK_LEN_SUITE_B_192
) {
12421 if (info
->attrs
[NL80211_ATTR_PMKR0_NAME
]) {
12422 int r0_name_len
= nla_len(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12424 if (r0_name_len
!= WLAN_PMK_NAME_LEN
) {
12429 pmk_conf
.pmk_r0_name
=
12430 nla_data(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12433 ret
= rdev_set_pmk(rdev
, dev
, &pmk_conf
);
12439 static int nl80211_del_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12441 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12442 struct net_device
*dev
= info
->user_ptr
[1];
12443 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12447 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12448 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12449 return -EOPNOTSUPP
;
12451 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12452 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12453 return -EOPNOTSUPP
;
12455 if (!info
->attrs
[NL80211_ATTR_MAC
])
12459 aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12460 ret
= rdev_del_pmk(rdev
, dev
, aa
);
12466 #define NL80211_FLAG_NEED_WIPHY 0x01
12467 #define NL80211_FLAG_NEED_NETDEV 0x02
12468 #define NL80211_FLAG_NEED_RTNL 0x04
12469 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12470 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12471 NL80211_FLAG_CHECK_NETDEV_UP)
12472 #define NL80211_FLAG_NEED_WDEV 0x10
12473 /* If a netdev is associated, it must be UP, P2P must be started */
12474 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12475 NL80211_FLAG_CHECK_NETDEV_UP)
12476 #define NL80211_FLAG_CLEAR_SKB 0x20
12478 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
12479 struct genl_info
*info
)
12481 struct cfg80211_registered_device
*rdev
;
12482 struct wireless_dev
*wdev
;
12483 struct net_device
*dev
;
12484 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
12489 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
12490 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
12491 if (IS_ERR(rdev
)) {
12494 return PTR_ERR(rdev
);
12496 info
->user_ptr
[0] = rdev
;
12497 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
12498 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
12501 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
12503 if (IS_ERR(wdev
)) {
12506 return PTR_ERR(wdev
);
12509 dev
= wdev
->netdev
;
12510 rdev
= wiphy_to_rdev(wdev
->wiphy
);
12512 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
12519 info
->user_ptr
[1] = dev
;
12521 info
->user_ptr
[1] = wdev
;
12524 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
12525 !wdev_running(wdev
)) {
12534 info
->user_ptr
[0] = rdev
;
12540 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
12541 struct genl_info
*info
)
12543 if (info
->user_ptr
[1]) {
12544 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
12545 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12548 dev_put(wdev
->netdev
);
12550 dev_put(info
->user_ptr
[1]);
12554 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
12557 /* If needed, clear the netlink message payload from the SKB
12558 * as it might contain key data that shouldn't stick around on
12559 * the heap after the SKB is freed. The netlink message header
12560 * is still needed for further processing, so leave it intact.
12562 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
12563 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
12565 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
12569 static const struct genl_ops nl80211_ops
[] = {
12571 .cmd
= NL80211_CMD_GET_WIPHY
,
12572 .doit
= nl80211_get_wiphy
,
12573 .dumpit
= nl80211_dump_wiphy
,
12574 .done
= nl80211_dump_wiphy_done
,
12575 .policy
= nl80211_policy
,
12576 /* can be retrieved by unprivileged users */
12577 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12578 NL80211_FLAG_NEED_RTNL
,
12581 .cmd
= NL80211_CMD_SET_WIPHY
,
12582 .doit
= nl80211_set_wiphy
,
12583 .policy
= nl80211_policy
,
12584 .flags
= GENL_UNS_ADMIN_PERM
,
12585 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12588 .cmd
= NL80211_CMD_GET_INTERFACE
,
12589 .doit
= nl80211_get_interface
,
12590 .dumpit
= nl80211_dump_interface
,
12591 .policy
= nl80211_policy
,
12592 /* can be retrieved by unprivileged users */
12593 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12594 NL80211_FLAG_NEED_RTNL
,
12597 .cmd
= NL80211_CMD_SET_INTERFACE
,
12598 .doit
= nl80211_set_interface
,
12599 .policy
= nl80211_policy
,
12600 .flags
= GENL_UNS_ADMIN_PERM
,
12601 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12602 NL80211_FLAG_NEED_RTNL
,
12605 .cmd
= NL80211_CMD_NEW_INTERFACE
,
12606 .doit
= nl80211_new_interface
,
12607 .policy
= nl80211_policy
,
12608 .flags
= GENL_UNS_ADMIN_PERM
,
12609 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12610 NL80211_FLAG_NEED_RTNL
,
12613 .cmd
= NL80211_CMD_DEL_INTERFACE
,
12614 .doit
= nl80211_del_interface
,
12615 .policy
= nl80211_policy
,
12616 .flags
= GENL_UNS_ADMIN_PERM
,
12617 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12618 NL80211_FLAG_NEED_RTNL
,
12621 .cmd
= NL80211_CMD_GET_KEY
,
12622 .doit
= nl80211_get_key
,
12623 .policy
= nl80211_policy
,
12624 .flags
= GENL_UNS_ADMIN_PERM
,
12625 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12626 NL80211_FLAG_NEED_RTNL
,
12629 .cmd
= NL80211_CMD_SET_KEY
,
12630 .doit
= nl80211_set_key
,
12631 .policy
= nl80211_policy
,
12632 .flags
= GENL_UNS_ADMIN_PERM
,
12633 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12634 NL80211_FLAG_NEED_RTNL
|
12635 NL80211_FLAG_CLEAR_SKB
,
12638 .cmd
= NL80211_CMD_NEW_KEY
,
12639 .doit
= nl80211_new_key
,
12640 .policy
= nl80211_policy
,
12641 .flags
= GENL_UNS_ADMIN_PERM
,
12642 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12643 NL80211_FLAG_NEED_RTNL
|
12644 NL80211_FLAG_CLEAR_SKB
,
12647 .cmd
= NL80211_CMD_DEL_KEY
,
12648 .doit
= nl80211_del_key
,
12649 .policy
= nl80211_policy
,
12650 .flags
= GENL_UNS_ADMIN_PERM
,
12651 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12652 NL80211_FLAG_NEED_RTNL
,
12655 .cmd
= NL80211_CMD_SET_BEACON
,
12656 .policy
= nl80211_policy
,
12657 .flags
= GENL_UNS_ADMIN_PERM
,
12658 .doit
= nl80211_set_beacon
,
12659 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12660 NL80211_FLAG_NEED_RTNL
,
12663 .cmd
= NL80211_CMD_START_AP
,
12664 .policy
= nl80211_policy
,
12665 .flags
= GENL_UNS_ADMIN_PERM
,
12666 .doit
= nl80211_start_ap
,
12667 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12668 NL80211_FLAG_NEED_RTNL
,
12671 .cmd
= NL80211_CMD_STOP_AP
,
12672 .policy
= nl80211_policy
,
12673 .flags
= GENL_UNS_ADMIN_PERM
,
12674 .doit
= nl80211_stop_ap
,
12675 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12676 NL80211_FLAG_NEED_RTNL
,
12679 .cmd
= NL80211_CMD_GET_STATION
,
12680 .doit
= nl80211_get_station
,
12681 .dumpit
= nl80211_dump_station
,
12682 .policy
= nl80211_policy
,
12683 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12684 NL80211_FLAG_NEED_RTNL
,
12687 .cmd
= NL80211_CMD_SET_STATION
,
12688 .doit
= nl80211_set_station
,
12689 .policy
= nl80211_policy
,
12690 .flags
= GENL_UNS_ADMIN_PERM
,
12691 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12692 NL80211_FLAG_NEED_RTNL
,
12695 .cmd
= NL80211_CMD_NEW_STATION
,
12696 .doit
= nl80211_new_station
,
12697 .policy
= nl80211_policy
,
12698 .flags
= GENL_UNS_ADMIN_PERM
,
12699 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12700 NL80211_FLAG_NEED_RTNL
,
12703 .cmd
= NL80211_CMD_DEL_STATION
,
12704 .doit
= nl80211_del_station
,
12705 .policy
= nl80211_policy
,
12706 .flags
= GENL_UNS_ADMIN_PERM
,
12707 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12708 NL80211_FLAG_NEED_RTNL
,
12711 .cmd
= NL80211_CMD_GET_MPATH
,
12712 .doit
= nl80211_get_mpath
,
12713 .dumpit
= nl80211_dump_mpath
,
12714 .policy
= nl80211_policy
,
12715 .flags
= GENL_UNS_ADMIN_PERM
,
12716 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12717 NL80211_FLAG_NEED_RTNL
,
12720 .cmd
= NL80211_CMD_GET_MPP
,
12721 .doit
= nl80211_get_mpp
,
12722 .dumpit
= nl80211_dump_mpp
,
12723 .policy
= nl80211_policy
,
12724 .flags
= GENL_UNS_ADMIN_PERM
,
12725 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12726 NL80211_FLAG_NEED_RTNL
,
12729 .cmd
= NL80211_CMD_SET_MPATH
,
12730 .doit
= nl80211_set_mpath
,
12731 .policy
= nl80211_policy
,
12732 .flags
= GENL_UNS_ADMIN_PERM
,
12733 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12734 NL80211_FLAG_NEED_RTNL
,
12737 .cmd
= NL80211_CMD_NEW_MPATH
,
12738 .doit
= nl80211_new_mpath
,
12739 .policy
= nl80211_policy
,
12740 .flags
= GENL_UNS_ADMIN_PERM
,
12741 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12742 NL80211_FLAG_NEED_RTNL
,
12745 .cmd
= NL80211_CMD_DEL_MPATH
,
12746 .doit
= nl80211_del_mpath
,
12747 .policy
= nl80211_policy
,
12748 .flags
= GENL_UNS_ADMIN_PERM
,
12749 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12750 NL80211_FLAG_NEED_RTNL
,
12753 .cmd
= NL80211_CMD_SET_BSS
,
12754 .doit
= nl80211_set_bss
,
12755 .policy
= nl80211_policy
,
12756 .flags
= GENL_UNS_ADMIN_PERM
,
12757 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12758 NL80211_FLAG_NEED_RTNL
,
12761 .cmd
= NL80211_CMD_GET_REG
,
12762 .doit
= nl80211_get_reg_do
,
12763 .dumpit
= nl80211_get_reg_dump
,
12764 .policy
= nl80211_policy
,
12765 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12766 /* can be retrieved by unprivileged users */
12768 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
12770 .cmd
= NL80211_CMD_SET_REG
,
12771 .doit
= nl80211_set_reg
,
12772 .policy
= nl80211_policy
,
12773 .flags
= GENL_ADMIN_PERM
,
12774 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12778 .cmd
= NL80211_CMD_REQ_SET_REG
,
12779 .doit
= nl80211_req_set_reg
,
12780 .policy
= nl80211_policy
,
12781 .flags
= GENL_ADMIN_PERM
,
12784 .cmd
= NL80211_CMD_RELOAD_REGDB
,
12785 .doit
= nl80211_reload_regdb
,
12786 .policy
= nl80211_policy
,
12787 .flags
= GENL_ADMIN_PERM
,
12790 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
12791 .doit
= nl80211_get_mesh_config
,
12792 .policy
= nl80211_policy
,
12793 /* can be retrieved by unprivileged users */
12794 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12795 NL80211_FLAG_NEED_RTNL
,
12798 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
12799 .doit
= nl80211_update_mesh_config
,
12800 .policy
= nl80211_policy
,
12801 .flags
= GENL_UNS_ADMIN_PERM
,
12802 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12803 NL80211_FLAG_NEED_RTNL
,
12806 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
12807 .doit
= nl80211_trigger_scan
,
12808 .policy
= nl80211_policy
,
12809 .flags
= GENL_UNS_ADMIN_PERM
,
12810 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12811 NL80211_FLAG_NEED_RTNL
,
12814 .cmd
= NL80211_CMD_ABORT_SCAN
,
12815 .doit
= nl80211_abort_scan
,
12816 .policy
= nl80211_policy
,
12817 .flags
= GENL_UNS_ADMIN_PERM
,
12818 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12819 NL80211_FLAG_NEED_RTNL
,
12822 .cmd
= NL80211_CMD_GET_SCAN
,
12823 .policy
= nl80211_policy
,
12824 .dumpit
= nl80211_dump_scan
,
12827 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
12828 .doit
= nl80211_start_sched_scan
,
12829 .policy
= nl80211_policy
,
12830 .flags
= GENL_UNS_ADMIN_PERM
,
12831 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12832 NL80211_FLAG_NEED_RTNL
,
12835 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
12836 .doit
= nl80211_stop_sched_scan
,
12837 .policy
= nl80211_policy
,
12838 .flags
= GENL_UNS_ADMIN_PERM
,
12839 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12840 NL80211_FLAG_NEED_RTNL
,
12843 .cmd
= NL80211_CMD_AUTHENTICATE
,
12844 .doit
= nl80211_authenticate
,
12845 .policy
= nl80211_policy
,
12846 .flags
= GENL_UNS_ADMIN_PERM
,
12847 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12848 NL80211_FLAG_NEED_RTNL
|
12849 NL80211_FLAG_CLEAR_SKB
,
12852 .cmd
= NL80211_CMD_ASSOCIATE
,
12853 .doit
= nl80211_associate
,
12854 .policy
= nl80211_policy
,
12855 .flags
= GENL_UNS_ADMIN_PERM
,
12856 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12857 NL80211_FLAG_NEED_RTNL
,
12860 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
12861 .doit
= nl80211_deauthenticate
,
12862 .policy
= nl80211_policy
,
12863 .flags
= GENL_UNS_ADMIN_PERM
,
12864 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12865 NL80211_FLAG_NEED_RTNL
,
12868 .cmd
= NL80211_CMD_DISASSOCIATE
,
12869 .doit
= nl80211_disassociate
,
12870 .policy
= nl80211_policy
,
12871 .flags
= GENL_UNS_ADMIN_PERM
,
12872 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12873 NL80211_FLAG_NEED_RTNL
,
12876 .cmd
= NL80211_CMD_JOIN_IBSS
,
12877 .doit
= nl80211_join_ibss
,
12878 .policy
= nl80211_policy
,
12879 .flags
= GENL_UNS_ADMIN_PERM
,
12880 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12881 NL80211_FLAG_NEED_RTNL
,
12884 .cmd
= NL80211_CMD_LEAVE_IBSS
,
12885 .doit
= nl80211_leave_ibss
,
12886 .policy
= nl80211_policy
,
12887 .flags
= GENL_UNS_ADMIN_PERM
,
12888 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12889 NL80211_FLAG_NEED_RTNL
,
12891 #ifdef CONFIG_NL80211_TESTMODE
12893 .cmd
= NL80211_CMD_TESTMODE
,
12894 .doit
= nl80211_testmode_do
,
12895 .dumpit
= nl80211_testmode_dump
,
12896 .policy
= nl80211_policy
,
12897 .flags
= GENL_UNS_ADMIN_PERM
,
12898 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12899 NL80211_FLAG_NEED_RTNL
,
12903 .cmd
= NL80211_CMD_CONNECT
,
12904 .doit
= nl80211_connect
,
12905 .policy
= nl80211_policy
,
12906 .flags
= GENL_UNS_ADMIN_PERM
,
12907 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12908 NL80211_FLAG_NEED_RTNL
,
12911 .cmd
= NL80211_CMD_UPDATE_CONNECT_PARAMS
,
12912 .doit
= nl80211_update_connect_params
,
12913 .policy
= nl80211_policy
,
12914 .flags
= GENL_ADMIN_PERM
,
12915 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12916 NL80211_FLAG_NEED_RTNL
,
12919 .cmd
= NL80211_CMD_DISCONNECT
,
12920 .doit
= nl80211_disconnect
,
12921 .policy
= nl80211_policy
,
12922 .flags
= GENL_UNS_ADMIN_PERM
,
12923 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12924 NL80211_FLAG_NEED_RTNL
,
12927 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
12928 .doit
= nl80211_wiphy_netns
,
12929 .policy
= nl80211_policy
,
12930 .flags
= GENL_UNS_ADMIN_PERM
,
12931 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12932 NL80211_FLAG_NEED_RTNL
,
12935 .cmd
= NL80211_CMD_GET_SURVEY
,
12936 .policy
= nl80211_policy
,
12937 .dumpit
= nl80211_dump_survey
,
12940 .cmd
= NL80211_CMD_SET_PMKSA
,
12941 .doit
= nl80211_setdel_pmksa
,
12942 .policy
= nl80211_policy
,
12943 .flags
= GENL_UNS_ADMIN_PERM
,
12944 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12945 NL80211_FLAG_NEED_RTNL
,
12948 .cmd
= NL80211_CMD_DEL_PMKSA
,
12949 .doit
= nl80211_setdel_pmksa
,
12950 .policy
= nl80211_policy
,
12951 .flags
= GENL_UNS_ADMIN_PERM
,
12952 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12953 NL80211_FLAG_NEED_RTNL
,
12956 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
12957 .doit
= nl80211_flush_pmksa
,
12958 .policy
= nl80211_policy
,
12959 .flags
= GENL_UNS_ADMIN_PERM
,
12960 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12961 NL80211_FLAG_NEED_RTNL
,
12964 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
12965 .doit
= nl80211_remain_on_channel
,
12966 .policy
= nl80211_policy
,
12967 .flags
= GENL_UNS_ADMIN_PERM
,
12968 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12969 NL80211_FLAG_NEED_RTNL
,
12972 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
12973 .doit
= nl80211_cancel_remain_on_channel
,
12974 .policy
= nl80211_policy
,
12975 .flags
= GENL_UNS_ADMIN_PERM
,
12976 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12977 NL80211_FLAG_NEED_RTNL
,
12980 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
12981 .doit
= nl80211_set_tx_bitrate_mask
,
12982 .policy
= nl80211_policy
,
12983 .flags
= GENL_UNS_ADMIN_PERM
,
12984 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12985 NL80211_FLAG_NEED_RTNL
,
12988 .cmd
= NL80211_CMD_REGISTER_FRAME
,
12989 .doit
= nl80211_register_mgmt
,
12990 .policy
= nl80211_policy
,
12991 .flags
= GENL_UNS_ADMIN_PERM
,
12992 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12993 NL80211_FLAG_NEED_RTNL
,
12996 .cmd
= NL80211_CMD_FRAME
,
12997 .doit
= nl80211_tx_mgmt
,
12998 .policy
= nl80211_policy
,
12999 .flags
= GENL_UNS_ADMIN_PERM
,
13000 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13001 NL80211_FLAG_NEED_RTNL
,
13004 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
13005 .doit
= nl80211_tx_mgmt_cancel_wait
,
13006 .policy
= nl80211_policy
,
13007 .flags
= GENL_UNS_ADMIN_PERM
,
13008 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13009 NL80211_FLAG_NEED_RTNL
,
13012 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
13013 .doit
= nl80211_set_power_save
,
13014 .policy
= nl80211_policy
,
13015 .flags
= GENL_UNS_ADMIN_PERM
,
13016 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13017 NL80211_FLAG_NEED_RTNL
,
13020 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
13021 .doit
= nl80211_get_power_save
,
13022 .policy
= nl80211_policy
,
13023 /* can be retrieved by unprivileged users */
13024 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13025 NL80211_FLAG_NEED_RTNL
,
13028 .cmd
= NL80211_CMD_SET_CQM
,
13029 .doit
= nl80211_set_cqm
,
13030 .policy
= nl80211_policy
,
13031 .flags
= GENL_UNS_ADMIN_PERM
,
13032 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13033 NL80211_FLAG_NEED_RTNL
,
13036 .cmd
= NL80211_CMD_SET_CHANNEL
,
13037 .doit
= nl80211_set_channel
,
13038 .policy
= nl80211_policy
,
13039 .flags
= GENL_UNS_ADMIN_PERM
,
13040 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13041 NL80211_FLAG_NEED_RTNL
,
13044 .cmd
= NL80211_CMD_SET_WDS_PEER
,
13045 .doit
= nl80211_set_wds_peer
,
13046 .policy
= nl80211_policy
,
13047 .flags
= GENL_UNS_ADMIN_PERM
,
13048 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13049 NL80211_FLAG_NEED_RTNL
,
13052 .cmd
= NL80211_CMD_JOIN_MESH
,
13053 .doit
= nl80211_join_mesh
,
13054 .policy
= nl80211_policy
,
13055 .flags
= GENL_UNS_ADMIN_PERM
,
13056 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13057 NL80211_FLAG_NEED_RTNL
,
13060 .cmd
= NL80211_CMD_LEAVE_MESH
,
13061 .doit
= nl80211_leave_mesh
,
13062 .policy
= nl80211_policy
,
13063 .flags
= GENL_UNS_ADMIN_PERM
,
13064 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13065 NL80211_FLAG_NEED_RTNL
,
13068 .cmd
= NL80211_CMD_JOIN_OCB
,
13069 .doit
= nl80211_join_ocb
,
13070 .policy
= nl80211_policy
,
13071 .flags
= GENL_UNS_ADMIN_PERM
,
13072 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13073 NL80211_FLAG_NEED_RTNL
,
13076 .cmd
= NL80211_CMD_LEAVE_OCB
,
13077 .doit
= nl80211_leave_ocb
,
13078 .policy
= nl80211_policy
,
13079 .flags
= GENL_UNS_ADMIN_PERM
,
13080 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13081 NL80211_FLAG_NEED_RTNL
,
13085 .cmd
= NL80211_CMD_GET_WOWLAN
,
13086 .doit
= nl80211_get_wowlan
,
13087 .policy
= nl80211_policy
,
13088 /* can be retrieved by unprivileged users */
13089 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13090 NL80211_FLAG_NEED_RTNL
,
13093 .cmd
= NL80211_CMD_SET_WOWLAN
,
13094 .doit
= nl80211_set_wowlan
,
13095 .policy
= nl80211_policy
,
13096 .flags
= GENL_UNS_ADMIN_PERM
,
13097 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13098 NL80211_FLAG_NEED_RTNL
,
13102 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
13103 .doit
= nl80211_set_rekey_data
,
13104 .policy
= nl80211_policy
,
13105 .flags
= GENL_UNS_ADMIN_PERM
,
13106 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13107 NL80211_FLAG_NEED_RTNL
|
13108 NL80211_FLAG_CLEAR_SKB
,
13111 .cmd
= NL80211_CMD_TDLS_MGMT
,
13112 .doit
= nl80211_tdls_mgmt
,
13113 .policy
= nl80211_policy
,
13114 .flags
= GENL_UNS_ADMIN_PERM
,
13115 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13116 NL80211_FLAG_NEED_RTNL
,
13119 .cmd
= NL80211_CMD_TDLS_OPER
,
13120 .doit
= nl80211_tdls_oper
,
13121 .policy
= nl80211_policy
,
13122 .flags
= GENL_UNS_ADMIN_PERM
,
13123 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13124 NL80211_FLAG_NEED_RTNL
,
13127 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
13128 .doit
= nl80211_register_unexpected_frame
,
13129 .policy
= nl80211_policy
,
13130 .flags
= GENL_UNS_ADMIN_PERM
,
13131 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13132 NL80211_FLAG_NEED_RTNL
,
13135 .cmd
= NL80211_CMD_PROBE_CLIENT
,
13136 .doit
= nl80211_probe_client
,
13137 .policy
= nl80211_policy
,
13138 .flags
= GENL_UNS_ADMIN_PERM
,
13139 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13140 NL80211_FLAG_NEED_RTNL
,
13143 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
13144 .doit
= nl80211_register_beacons
,
13145 .policy
= nl80211_policy
,
13146 .flags
= GENL_UNS_ADMIN_PERM
,
13147 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13148 NL80211_FLAG_NEED_RTNL
,
13151 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
13152 .doit
= nl80211_set_noack_map
,
13153 .policy
= nl80211_policy
,
13154 .flags
= GENL_UNS_ADMIN_PERM
,
13155 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13156 NL80211_FLAG_NEED_RTNL
,
13159 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
13160 .doit
= nl80211_start_p2p_device
,
13161 .policy
= nl80211_policy
,
13162 .flags
= GENL_UNS_ADMIN_PERM
,
13163 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13164 NL80211_FLAG_NEED_RTNL
,
13167 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
13168 .doit
= nl80211_stop_p2p_device
,
13169 .policy
= nl80211_policy
,
13170 .flags
= GENL_UNS_ADMIN_PERM
,
13171 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13172 NL80211_FLAG_NEED_RTNL
,
13175 .cmd
= NL80211_CMD_START_NAN
,
13176 .doit
= nl80211_start_nan
,
13177 .policy
= nl80211_policy
,
13178 .flags
= GENL_ADMIN_PERM
,
13179 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13180 NL80211_FLAG_NEED_RTNL
,
13183 .cmd
= NL80211_CMD_STOP_NAN
,
13184 .doit
= nl80211_stop_nan
,
13185 .policy
= nl80211_policy
,
13186 .flags
= GENL_ADMIN_PERM
,
13187 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13188 NL80211_FLAG_NEED_RTNL
,
13191 .cmd
= NL80211_CMD_ADD_NAN_FUNCTION
,
13192 .doit
= nl80211_nan_add_func
,
13193 .policy
= nl80211_policy
,
13194 .flags
= GENL_ADMIN_PERM
,
13195 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13196 NL80211_FLAG_NEED_RTNL
,
13199 .cmd
= NL80211_CMD_DEL_NAN_FUNCTION
,
13200 .doit
= nl80211_nan_del_func
,
13201 .policy
= nl80211_policy
,
13202 .flags
= GENL_ADMIN_PERM
,
13203 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13204 NL80211_FLAG_NEED_RTNL
,
13207 .cmd
= NL80211_CMD_CHANGE_NAN_CONFIG
,
13208 .doit
= nl80211_nan_change_config
,
13209 .policy
= nl80211_policy
,
13210 .flags
= GENL_ADMIN_PERM
,
13211 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13212 NL80211_FLAG_NEED_RTNL
,
13215 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
13216 .doit
= nl80211_set_mcast_rate
,
13217 .policy
= nl80211_policy
,
13218 .flags
= GENL_UNS_ADMIN_PERM
,
13219 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13220 NL80211_FLAG_NEED_RTNL
,
13223 .cmd
= NL80211_CMD_SET_MAC_ACL
,
13224 .doit
= nl80211_set_mac_acl
,
13225 .policy
= nl80211_policy
,
13226 .flags
= GENL_UNS_ADMIN_PERM
,
13227 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13228 NL80211_FLAG_NEED_RTNL
,
13231 .cmd
= NL80211_CMD_RADAR_DETECT
,
13232 .doit
= nl80211_start_radar_detection
,
13233 .policy
= nl80211_policy
,
13234 .flags
= GENL_UNS_ADMIN_PERM
,
13235 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13236 NL80211_FLAG_NEED_RTNL
,
13239 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
13240 .doit
= nl80211_get_protocol_features
,
13241 .policy
= nl80211_policy
,
13244 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
13245 .doit
= nl80211_update_ft_ies
,
13246 .policy
= nl80211_policy
,
13247 .flags
= GENL_UNS_ADMIN_PERM
,
13248 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13249 NL80211_FLAG_NEED_RTNL
,
13252 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
13253 .doit
= nl80211_crit_protocol_start
,
13254 .policy
= nl80211_policy
,
13255 .flags
= GENL_UNS_ADMIN_PERM
,
13256 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13257 NL80211_FLAG_NEED_RTNL
,
13260 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
13261 .doit
= nl80211_crit_protocol_stop
,
13262 .policy
= nl80211_policy
,
13263 .flags
= GENL_UNS_ADMIN_PERM
,
13264 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13265 NL80211_FLAG_NEED_RTNL
,
13268 .cmd
= NL80211_CMD_GET_COALESCE
,
13269 .doit
= nl80211_get_coalesce
,
13270 .policy
= nl80211_policy
,
13271 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13272 NL80211_FLAG_NEED_RTNL
,
13275 .cmd
= NL80211_CMD_SET_COALESCE
,
13276 .doit
= nl80211_set_coalesce
,
13277 .policy
= nl80211_policy
,
13278 .flags
= GENL_UNS_ADMIN_PERM
,
13279 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13280 NL80211_FLAG_NEED_RTNL
,
13283 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
13284 .doit
= nl80211_channel_switch
,
13285 .policy
= nl80211_policy
,
13286 .flags
= GENL_UNS_ADMIN_PERM
,
13287 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13288 NL80211_FLAG_NEED_RTNL
,
13291 .cmd
= NL80211_CMD_VENDOR
,
13292 .doit
= nl80211_vendor_cmd
,
13293 .dumpit
= nl80211_vendor_cmd_dump
,
13294 .policy
= nl80211_policy
,
13295 .flags
= GENL_UNS_ADMIN_PERM
,
13296 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13297 NL80211_FLAG_NEED_RTNL
,
13300 .cmd
= NL80211_CMD_SET_QOS_MAP
,
13301 .doit
= nl80211_set_qos_map
,
13302 .policy
= nl80211_policy
,
13303 .flags
= GENL_UNS_ADMIN_PERM
,
13304 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13305 NL80211_FLAG_NEED_RTNL
,
13308 .cmd
= NL80211_CMD_ADD_TX_TS
,
13309 .doit
= nl80211_add_tx_ts
,
13310 .policy
= nl80211_policy
,
13311 .flags
= GENL_UNS_ADMIN_PERM
,
13312 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13313 NL80211_FLAG_NEED_RTNL
,
13316 .cmd
= NL80211_CMD_DEL_TX_TS
,
13317 .doit
= nl80211_del_tx_ts
,
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_TDLS_CHANNEL_SWITCH
,
13325 .doit
= nl80211_tdls_channel_switch
,
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_TDLS_CANCEL_CHANNEL_SWITCH
,
13333 .doit
= nl80211_tdls_cancel_channel_switch
,
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_SET_MULTICAST_TO_UNICAST
,
13341 .doit
= nl80211_set_multicast_to_unicast
,
13342 .policy
= nl80211_policy
,
13343 .flags
= GENL_UNS_ADMIN_PERM
,
13344 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13345 NL80211_FLAG_NEED_RTNL
,
13348 .cmd
= NL80211_CMD_SET_PMK
,
13349 .doit
= nl80211_set_pmk
,
13350 .policy
= nl80211_policy
,
13351 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13352 NL80211_FLAG_NEED_RTNL
,
13355 .cmd
= NL80211_CMD_DEL_PMK
,
13356 .doit
= nl80211_del_pmk
,
13357 .policy
= nl80211_policy
,
13358 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13359 NL80211_FLAG_NEED_RTNL
,
13364 static struct genl_family nl80211_fam __ro_after_init
= {
13365 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
13366 .hdrsize
= 0, /* no private header */
13367 .version
= 1, /* no particular meaning now */
13368 .maxattr
= NL80211_ATTR_MAX
,
13370 .pre_doit
= nl80211_pre_doit
,
13371 .post_doit
= nl80211_post_doit
,
13372 .module
= THIS_MODULE
,
13373 .ops
= nl80211_ops
,
13374 .n_ops
= ARRAY_SIZE(nl80211_ops
),
13375 .mcgrps
= nl80211_mcgrps
,
13376 .n_mcgrps
= ARRAY_SIZE(nl80211_mcgrps
),
13379 /* notification functions */
13381 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
13382 enum nl80211_commands cmd
)
13384 struct sk_buff
*msg
;
13385 struct nl80211_dump_wiphy_state state
= {};
13387 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
13388 cmd
!= NL80211_CMD_DEL_WIPHY
);
13390 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13394 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
13399 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13400 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
13403 void nl80211_notify_iface(struct cfg80211_registered_device
*rdev
,
13404 struct wireless_dev
*wdev
,
13405 enum nl80211_commands cmd
)
13407 struct sk_buff
*msg
;
13409 WARN_ON(cmd
!= NL80211_CMD_NEW_INTERFACE
&&
13410 cmd
!= NL80211_CMD_DEL_INTERFACE
);
13412 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13416 if (nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
,
13417 cmd
== NL80211_CMD_DEL_INTERFACE
) < 0) {
13422 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13423 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
13426 static int nl80211_add_scan_req(struct sk_buff
*msg
,
13427 struct cfg80211_registered_device
*rdev
)
13429 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
13430 struct nlattr
*nest
;
13436 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
13438 goto nla_put_failure
;
13439 for (i
= 0; i
< req
->n_ssids
; i
++) {
13440 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
13441 goto nla_put_failure
;
13443 nla_nest_end(msg
, nest
);
13445 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
13447 goto nla_put_failure
;
13448 for (i
= 0; i
< req
->n_channels
; i
++) {
13449 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
13450 goto nla_put_failure
;
13452 nla_nest_end(msg
, nest
);
13455 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
13456 goto nla_put_failure
;
13459 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
13460 goto nla_put_failure
;
13462 if (req
->info
.scan_start_tsf
&&
13463 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
13464 req
->info
.scan_start_tsf
, NL80211_BSS_PAD
) ||
13465 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
13466 req
->info
.tsf_bssid
)))
13467 goto nla_put_failure
;
13474 static int nl80211_prep_scan_msg(struct sk_buff
*msg
,
13475 struct cfg80211_registered_device
*rdev
,
13476 struct wireless_dev
*wdev
,
13477 u32 portid
, u32 seq
, int flags
,
13482 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
13486 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13487 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13488 wdev
->netdev
->ifindex
)) ||
13489 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13491 goto nla_put_failure
;
13493 /* ignore errors and send incomplete event anyway */
13494 nl80211_add_scan_req(msg
, rdev
);
13496 genlmsg_end(msg
, hdr
);
13500 genlmsg_cancel(msg
, hdr
);
13505 nl80211_prep_sched_scan_msg(struct sk_buff
*msg
,
13506 struct cfg80211_sched_scan_request
*req
, u32 cmd
)
13510 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13514 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
,
13515 wiphy_to_rdev(req
->wiphy
)->wiphy_idx
) ||
13516 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, req
->dev
->ifindex
) ||
13517 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, req
->reqid
,
13519 goto nla_put_failure
;
13521 genlmsg_end(msg
, hdr
);
13525 genlmsg_cancel(msg
, hdr
);
13529 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
13530 struct wireless_dev
*wdev
)
13532 struct sk_buff
*msg
;
13534 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13538 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
13539 NL80211_CMD_TRIGGER_SCAN
) < 0) {
13544 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13545 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
13548 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
13549 struct wireless_dev
*wdev
, bool aborted
)
13551 struct sk_buff
*msg
;
13553 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13557 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
13558 aborted
? NL80211_CMD_SCAN_ABORTED
:
13559 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
13567 /* send message created by nl80211_build_scan_msg() */
13568 void nl80211_send_scan_msg(struct cfg80211_registered_device
*rdev
,
13569 struct sk_buff
*msg
)
13574 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13575 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
13578 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request
*req
, u32 cmd
)
13580 struct sk_buff
*msg
;
13582 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13586 if (nl80211_prep_sched_scan_msg(msg
, req
, cmd
) < 0) {
13591 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(req
->wiphy
), msg
, 0,
13592 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
13595 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
13596 struct regulatory_request
*request
)
13598 /* Userspace can always count this one always being set */
13599 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
13600 goto nla_put_failure
;
13602 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
13603 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13604 NL80211_REGDOM_TYPE_WORLD
))
13605 goto nla_put_failure
;
13606 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
13607 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13608 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
13609 goto nla_put_failure
;
13610 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
13611 request
->intersect
) {
13612 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13613 NL80211_REGDOM_TYPE_INTERSECTION
))
13614 goto nla_put_failure
;
13616 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13617 NL80211_REGDOM_TYPE_COUNTRY
) ||
13618 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
13620 goto nla_put_failure
;
13623 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
13624 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
13627 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
13628 goto nla_put_failure
;
13631 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
13632 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
13633 goto nla_put_failure
;
13643 * This can happen on global regulatory changes or device specific settings
13644 * based on custom regulatory domains.
13646 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
13647 struct regulatory_request
*request
)
13649 struct sk_buff
*msg
;
13652 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13656 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
13662 if (nl80211_reg_change_event_fill(msg
, request
) == false)
13663 goto nla_put_failure
;
13665 genlmsg_end(msg
, hdr
);
13668 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
13669 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
13675 genlmsg_cancel(msg
, hdr
);
13679 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
13680 struct net_device
*netdev
,
13681 const u8
*buf
, size_t len
,
13682 enum nl80211_commands cmd
, gfp_t gfp
,
13685 struct sk_buff
*msg
;
13688 msg
= nlmsg_new(100 + len
, gfp
);
13692 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13698 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13699 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13700 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
13701 goto nla_put_failure
;
13703 if (uapsd_queues
>= 0) {
13704 struct nlattr
*nla_wmm
=
13705 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
13707 goto nla_put_failure
;
13709 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
13711 goto nla_put_failure
;
13713 nla_nest_end(msg
, nla_wmm
);
13716 genlmsg_end(msg
, hdr
);
13718 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13719 NL80211_MCGRP_MLME
, gfp
);
13723 genlmsg_cancel(msg
, hdr
);
13727 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
13728 struct net_device
*netdev
, const u8
*buf
,
13729 size_t len
, gfp_t gfp
)
13731 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13732 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
13735 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
13736 struct net_device
*netdev
, const u8
*buf
,
13737 size_t len
, gfp_t gfp
, int uapsd_queues
)
13739 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13740 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
13743 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
13744 struct net_device
*netdev
, const u8
*buf
,
13745 size_t len
, gfp_t gfp
)
13747 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13748 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
13751 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
13752 struct net_device
*netdev
, const u8
*buf
,
13753 size_t len
, gfp_t gfp
)
13755 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13756 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
13759 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
13762 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13763 struct wiphy
*wiphy
= wdev
->wiphy
;
13764 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13765 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
13768 if (WARN_ON(len
< 2))
13771 if (ieee80211_is_deauth(mgmt
->frame_control
))
13772 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
13774 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
13776 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
13777 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
13779 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
13781 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
13782 struct net_device
*netdev
, int cmd
,
13783 const u8
*addr
, gfp_t gfp
)
13785 struct sk_buff
*msg
;
13788 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13792 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13798 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13799 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13800 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
13801 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
13802 goto nla_put_failure
;
13804 genlmsg_end(msg
, hdr
);
13806 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13807 NL80211_MCGRP_MLME
, gfp
);
13811 genlmsg_cancel(msg
, hdr
);
13815 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
13816 struct net_device
*netdev
, const u8
*addr
,
13819 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
13823 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
13824 struct net_device
*netdev
, const u8
*addr
,
13827 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
13831 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
13832 struct net_device
*netdev
,
13833 struct cfg80211_connect_resp_params
*cr
,
13836 struct sk_buff
*msg
;
13839 msg
= nlmsg_new(100 + cr
->req_ie_len
+ cr
->resp_ie_len
+
13840 cr
->fils_kek_len
+ cr
->pmk_len
+
13841 (cr
->pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
13845 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
13851 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13852 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13854 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, cr
->bssid
)) ||
13855 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
13856 cr
->status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
13859 (nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
13860 nla_put_u32(msg
, NL80211_ATTR_TIMEOUT_REASON
,
13861 cr
->timeout_reason
))) ||
13863 nla_put(msg
, NL80211_ATTR_REQ_IE
, cr
->req_ie_len
, cr
->req_ie
)) ||
13865 nla_put(msg
, NL80211_ATTR_RESP_IE
, cr
->resp_ie_len
,
13867 (cr
->update_erp_next_seq_num
&&
13868 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
13869 cr
->fils_erp_next_seq_num
)) ||
13870 (cr
->status
== WLAN_STATUS_SUCCESS
&&
13872 nla_put(msg
, NL80211_ATTR_FILS_KEK
, cr
->fils_kek_len
,
13875 nla_put(msg
, NL80211_ATTR_PMK
, cr
->pmk_len
, cr
->pmk
)) ||
13877 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, cr
->pmkid
)))))
13878 goto nla_put_failure
;
13880 genlmsg_end(msg
, hdr
);
13882 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13883 NL80211_MCGRP_MLME
, gfp
);
13887 genlmsg_cancel(msg
, hdr
);
13891 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
13892 struct net_device
*netdev
,
13893 struct cfg80211_roam_info
*info
, gfp_t gfp
)
13895 struct sk_buff
*msg
;
13897 const u8
*bssid
= info
->bss
? info
->bss
->bssid
: info
->bssid
;
13899 msg
= nlmsg_new(100 + info
->req_ie_len
+ info
->resp_ie_len
, gfp
);
13903 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
13909 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13910 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13911 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
13913 nla_put(msg
, NL80211_ATTR_REQ_IE
, info
->req_ie_len
,
13916 nla_put(msg
, NL80211_ATTR_RESP_IE
, info
->resp_ie_len
,
13918 goto nla_put_failure
;
13920 genlmsg_end(msg
, hdr
);
13922 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13923 NL80211_MCGRP_MLME
, gfp
);
13927 genlmsg_cancel(msg
, hdr
);
13931 void nl80211_send_port_authorized(struct cfg80211_registered_device
*rdev
,
13932 struct net_device
*netdev
, const u8
*bssid
)
13934 struct sk_buff
*msg
;
13937 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13941 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED
);
13947 if (nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
13948 goto nla_put_failure
;
13950 genlmsg_end(msg
, hdr
);
13952 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13953 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13957 genlmsg_cancel(msg
, hdr
);
13961 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
13962 struct net_device
*netdev
, u16 reason
,
13963 const u8
*ie
, size_t ie_len
, bool from_ap
)
13965 struct sk_buff
*msg
;
13968 msg
= nlmsg_new(100 + ie_len
, GFP_KERNEL
);
13972 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
13978 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13979 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13981 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
13983 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
13984 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
13985 goto nla_put_failure
;
13987 genlmsg_end(msg
, hdr
);
13989 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13990 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13994 genlmsg_cancel(msg
, hdr
);
13998 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
13999 struct net_device
*netdev
, const u8
*bssid
,
14002 struct sk_buff
*msg
;
14005 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14009 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
14015 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14016 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14017 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
14018 goto nla_put_failure
;
14020 genlmsg_end(msg
, hdr
);
14022 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14023 NL80211_MCGRP_MLME
, gfp
);
14027 genlmsg_cancel(msg
, hdr
);
14031 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
14032 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
14034 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14035 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14036 struct sk_buff
*msg
;
14039 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
14042 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
14044 msg
= nlmsg_new(100 + ie_len
, gfp
);
14048 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
14054 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14055 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14056 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
14058 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
14059 goto nla_put_failure
;
14061 genlmsg_end(msg
, hdr
);
14063 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14064 NL80211_MCGRP_MLME
, gfp
);
14068 genlmsg_cancel(msg
, hdr
);
14071 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
14073 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
14074 struct net_device
*netdev
, const u8
*addr
,
14075 enum nl80211_key_type key_type
, int key_id
,
14076 const u8
*tsc
, gfp_t gfp
)
14078 struct sk_buff
*msg
;
14081 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14085 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
14091 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14092 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14093 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
14094 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
14096 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
14097 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
14098 goto nla_put_failure
;
14100 genlmsg_end(msg
, hdr
);
14102 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14103 NL80211_MCGRP_MLME
, gfp
);
14107 genlmsg_cancel(msg
, hdr
);
14111 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
14112 struct ieee80211_channel
*channel_before
,
14113 struct ieee80211_channel
*channel_after
)
14115 struct sk_buff
*msg
;
14117 struct nlattr
*nl_freq
;
14119 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
14123 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
14130 * Since we are applying the beacon hint to a wiphy we know its
14131 * wiphy_idx is valid
14133 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
14134 goto nla_put_failure
;
14137 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
14139 goto nla_put_failure
;
14140 if (nl80211_msg_put_channel(msg
, channel_before
, false))
14141 goto nla_put_failure
;
14142 nla_nest_end(msg
, nl_freq
);
14145 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
14147 goto nla_put_failure
;
14148 if (nl80211_msg_put_channel(msg
, channel_after
, false))
14149 goto nla_put_failure
;
14150 nla_nest_end(msg
, nl_freq
);
14152 genlmsg_end(msg
, hdr
);
14155 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
14156 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
14162 genlmsg_cancel(msg
, hdr
);
14166 static void nl80211_send_remain_on_chan_event(
14167 int cmd
, struct cfg80211_registered_device
*rdev
,
14168 struct wireless_dev
*wdev
, u64 cookie
,
14169 struct ieee80211_channel
*chan
,
14170 unsigned int duration
, gfp_t gfp
)
14172 struct sk_buff
*msg
;
14175 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14179 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14185 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14186 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14187 wdev
->netdev
->ifindex
)) ||
14188 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14189 NL80211_ATTR_PAD
) ||
14190 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
14191 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
14192 NL80211_CHAN_NO_HT
) ||
14193 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14195 goto nla_put_failure
;
14197 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
14198 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
14199 goto nla_put_failure
;
14201 genlmsg_end(msg
, hdr
);
14203 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14204 NL80211_MCGRP_MLME
, gfp
);
14208 genlmsg_cancel(msg
, hdr
);
14212 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
14213 struct ieee80211_channel
*chan
,
14214 unsigned int duration
, gfp_t gfp
)
14216 struct wiphy
*wiphy
= wdev
->wiphy
;
14217 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14219 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
14220 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
14221 rdev
, wdev
, cookie
, chan
,
14224 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
14226 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
14227 struct ieee80211_channel
*chan
,
14230 struct wiphy
*wiphy
= wdev
->wiphy
;
14231 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14233 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
14234 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
14235 rdev
, wdev
, cookie
, chan
, 0, gfp
);
14237 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
14239 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
14240 struct station_info
*sinfo
, gfp_t gfp
)
14242 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14243 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14244 struct sk_buff
*msg
;
14246 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
14248 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14252 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
14253 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14258 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14259 NL80211_MCGRP_MLME
, gfp
);
14261 EXPORT_SYMBOL(cfg80211_new_sta
);
14263 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
14264 struct station_info
*sinfo
, gfp_t gfp
)
14266 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14267 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14268 struct sk_buff
*msg
;
14269 struct station_info empty_sinfo
= {};
14272 sinfo
= &empty_sinfo
;
14274 trace_cfg80211_del_sta(dev
, mac_addr
);
14276 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14280 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
14281 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14286 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14287 NL80211_MCGRP_MLME
, gfp
);
14289 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
14291 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
14292 enum nl80211_connect_failed_reason reason
,
14295 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14296 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14297 struct sk_buff
*msg
;
14300 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
14304 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
14310 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14311 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
14312 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
14313 goto nla_put_failure
;
14315 genlmsg_end(msg
, hdr
);
14317 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14318 NL80211_MCGRP_MLME
, gfp
);
14322 genlmsg_cancel(msg
, hdr
);
14325 EXPORT_SYMBOL(cfg80211_conn_failed
);
14327 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
14328 const u8
*addr
, gfp_t gfp
)
14330 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14331 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14332 struct sk_buff
*msg
;
14334 u32 nlportid
= READ_ONCE(wdev
->ap_unexpected_nlportid
);
14339 msg
= nlmsg_new(100, gfp
);
14343 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14349 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14350 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14351 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
14352 goto nla_put_failure
;
14354 genlmsg_end(msg
, hdr
);
14355 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14359 genlmsg_cancel(msg
, hdr
);
14364 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
14365 const u8
*addr
, gfp_t gfp
)
14367 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14370 trace_cfg80211_rx_spurious_frame(dev
, addr
);
14372 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14373 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
14374 trace_cfg80211_return_bool(false);
14377 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
14379 trace_cfg80211_return_bool(ret
);
14382 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
14384 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
14385 const u8
*addr
, gfp_t gfp
)
14387 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14390 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
14392 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14393 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
14394 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
14395 trace_cfg80211_return_bool(false);
14398 ret
= __nl80211_unexpected_frame(dev
,
14399 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
14401 trace_cfg80211_return_bool(ret
);
14404 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
14406 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
14407 struct wireless_dev
*wdev
, u32 nlportid
,
14408 int freq
, int sig_dbm
,
14409 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
14411 struct net_device
*netdev
= wdev
->netdev
;
14412 struct sk_buff
*msg
;
14415 msg
= nlmsg_new(100 + len
, gfp
);
14419 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
14425 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14426 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14427 netdev
->ifindex
)) ||
14428 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14429 NL80211_ATTR_PAD
) ||
14430 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
14432 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
14433 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
14435 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
14436 goto nla_put_failure
;
14438 genlmsg_end(msg
, hdr
);
14440 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14443 genlmsg_cancel(msg
, hdr
);
14448 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
14449 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
14451 struct wiphy
*wiphy
= wdev
->wiphy
;
14452 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14453 struct net_device
*netdev
= wdev
->netdev
;
14454 struct sk_buff
*msg
;
14457 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
14459 msg
= nlmsg_new(100 + len
, gfp
);
14463 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
14469 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14470 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14471 netdev
->ifindex
)) ||
14472 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14473 NL80211_ATTR_PAD
) ||
14474 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
14475 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14476 NL80211_ATTR_PAD
) ||
14477 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
14478 goto nla_put_failure
;
14480 genlmsg_end(msg
, hdr
);
14482 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14483 NL80211_MCGRP_MLME
, gfp
);
14487 genlmsg_cancel(msg
, hdr
);
14490 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
14492 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
14493 const char *mac
, gfp_t gfp
)
14495 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14496 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14497 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14503 cb
= (void **)msg
->cb
;
14505 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
14511 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14512 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
14513 goto nla_put_failure
;
14515 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
14516 goto nla_put_failure
;
14518 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
14520 goto nla_put_failure
;
14530 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
14532 void **cb
= (void **)msg
->cb
;
14533 struct cfg80211_registered_device
*rdev
= cb
[2];
14535 nla_nest_end(msg
, cb
[1]);
14536 genlmsg_end(msg
, cb
[0]);
14538 memset(msg
->cb
, 0, sizeof(msg
->cb
));
14540 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14541 NL80211_MCGRP_MLME
, gfp
);
14544 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
14545 enum nl80211_cqm_rssi_threshold_event rssi_event
,
14546 s32 rssi_level
, gfp_t gfp
)
14548 struct sk_buff
*msg
;
14549 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14550 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14552 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
, rssi_level
);
14554 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
14555 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
14558 if (wdev
->cqm_config
) {
14559 wdev
->cqm_config
->last_rssi_event_value
= rssi_level
;
14561 cfg80211_cqm_rssi_update(rdev
, dev
);
14563 if (rssi_level
== 0)
14564 rssi_level
= wdev
->cqm_config
->last_rssi_event_value
;
14567 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
14571 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
14573 goto nla_put_failure
;
14575 if (rssi_level
&& nla_put_s32(msg
, NL80211_ATTR_CQM_RSSI_LEVEL
,
14577 goto nla_put_failure
;
14579 cfg80211_send_cqm(msg
, gfp
);
14586 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
14588 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
14589 const u8
*peer
, u32 num_packets
,
14590 u32 rate
, u32 intvl
, gfp_t gfp
)
14592 struct sk_buff
*msg
;
14594 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
14598 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
14599 goto nla_put_failure
;
14601 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
14602 goto nla_put_failure
;
14604 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
14605 goto nla_put_failure
;
14607 cfg80211_send_cqm(msg
, gfp
);
14613 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
14615 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
14616 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
14618 struct sk_buff
*msg
;
14620 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
14622 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
14626 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
14627 goto nla_put_failure
;
14629 cfg80211_send_cqm(msg
, gfp
);
14635 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
14637 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
14639 struct sk_buff
*msg
;
14641 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
14645 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
14646 goto nla_put_failure
;
14648 cfg80211_send_cqm(msg
, gfp
);
14654 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
14656 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
14657 struct net_device
*netdev
, const u8
*bssid
,
14658 const u8
*replay_ctr
, gfp_t gfp
)
14660 struct sk_buff
*msg
;
14661 struct nlattr
*rekey_attr
;
14664 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14668 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
14674 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14675 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14676 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
14677 goto nla_put_failure
;
14679 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
14681 goto nla_put_failure
;
14683 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
14684 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
14685 goto nla_put_failure
;
14687 nla_nest_end(msg
, rekey_attr
);
14689 genlmsg_end(msg
, hdr
);
14691 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14692 NL80211_MCGRP_MLME
, gfp
);
14696 genlmsg_cancel(msg
, hdr
);
14700 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
14701 const u8
*replay_ctr
, gfp_t gfp
)
14703 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14704 struct wiphy
*wiphy
= wdev
->wiphy
;
14705 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14707 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
14708 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
14710 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
14713 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
14714 struct net_device
*netdev
, int index
,
14715 const u8
*bssid
, bool preauth
, gfp_t gfp
)
14717 struct sk_buff
*msg
;
14718 struct nlattr
*attr
;
14721 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14725 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
14731 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14732 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
14733 goto nla_put_failure
;
14735 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
14737 goto nla_put_failure
;
14739 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
14740 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
14742 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
14743 goto nla_put_failure
;
14745 nla_nest_end(msg
, attr
);
14747 genlmsg_end(msg
, hdr
);
14749 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14750 NL80211_MCGRP_MLME
, gfp
);
14754 genlmsg_cancel(msg
, hdr
);
14758 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
14759 const u8
*bssid
, bool preauth
, gfp_t gfp
)
14761 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14762 struct wiphy
*wiphy
= wdev
->wiphy
;
14763 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14765 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
14766 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
14768 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
14770 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
14771 struct net_device
*netdev
,
14772 struct cfg80211_chan_def
*chandef
,
14774 enum nl80211_commands notif
,
14777 struct sk_buff
*msg
;
14780 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14784 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
14790 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
14791 goto nla_put_failure
;
14793 if (nl80211_send_chandef(msg
, chandef
))
14794 goto nla_put_failure
;
14796 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
14797 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
14798 goto nla_put_failure
;
14800 genlmsg_end(msg
, hdr
);
14802 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14803 NL80211_MCGRP_MLME
, gfp
);
14807 genlmsg_cancel(msg
, hdr
);
14811 void cfg80211_ch_switch_notify(struct net_device
*dev
,
14812 struct cfg80211_chan_def
*chandef
)
14814 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14815 struct wiphy
*wiphy
= wdev
->wiphy
;
14816 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14818 ASSERT_WDEV_LOCK(wdev
);
14820 trace_cfg80211_ch_switch_notify(dev
, chandef
);
14822 wdev
->chandef
= *chandef
;
14823 wdev
->preset_chandef
= *chandef
;
14824 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
14825 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
14827 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
14829 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
14830 struct cfg80211_chan_def
*chandef
,
14833 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14834 struct wiphy
*wiphy
= wdev
->wiphy
;
14835 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14837 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
14839 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
14840 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
14842 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
14845 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
14846 const struct cfg80211_chan_def
*chandef
,
14847 enum nl80211_radar_event event
,
14848 struct net_device
*netdev
, gfp_t gfp
)
14850 struct sk_buff
*msg
;
14853 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14857 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
14863 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
14864 goto nla_put_failure
;
14866 /* NOP and radar events don't need a netdev parameter */
14868 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
14870 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14871 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14873 goto nla_put_failure
;
14876 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
14877 goto nla_put_failure
;
14879 if (nl80211_send_chandef(msg
, chandef
))
14880 goto nla_put_failure
;
14882 genlmsg_end(msg
, hdr
);
14884 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14885 NL80211_MCGRP_MLME
, gfp
);
14889 genlmsg_cancel(msg
, hdr
);
14893 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
14894 u64 cookie
, bool acked
, gfp_t gfp
)
14896 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14897 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14898 struct sk_buff
*msg
;
14901 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
14903 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14908 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
14914 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14915 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14916 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
14917 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14918 NL80211_ATTR_PAD
) ||
14919 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
14920 goto nla_put_failure
;
14922 genlmsg_end(msg
, hdr
);
14924 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14925 NL80211_MCGRP_MLME
, gfp
);
14929 genlmsg_cancel(msg
, hdr
);
14932 EXPORT_SYMBOL(cfg80211_probe_status
);
14934 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
14935 const u8
*frame
, size_t len
,
14936 int freq
, int sig_dbm
)
14938 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14939 struct sk_buff
*msg
;
14941 struct cfg80211_beacon_registration
*reg
;
14943 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
14945 spin_lock_bh(&rdev
->beacon_registrations_lock
);
14946 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
14947 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
14949 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14953 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
14955 goto nla_put_failure
;
14957 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14959 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
14961 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
14962 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
14963 goto nla_put_failure
;
14965 genlmsg_end(msg
, hdr
);
14967 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
14969 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14973 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14975 genlmsg_cancel(msg
, hdr
);
14978 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
14981 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
14982 struct cfg80211_wowlan_wakeup
*wakeup
)
14984 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
14985 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
14988 nl_results
= nla_nest_start(
14989 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
14993 for (i
= 0; i
< nd
->n_matches
; i
++) {
14994 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
14996 nl_match
= nla_nest_start(msg
, i
);
15000 /* The SSID attribute is optional in nl80211, but for
15001 * simplicity reasons it's always present in the
15002 * cfg80211 structure. If a driver can't pass the
15003 * SSID, that needs to be changed. A zero length SSID
15004 * is still a valid SSID (wildcard), so it cannot be
15005 * used for this purpose.
15007 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
15008 match
->ssid
.ssid
)) {
15009 nla_nest_cancel(msg
, nl_match
);
15013 if (match
->n_channels
) {
15014 nl_freqs
= nla_nest_start(
15015 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
15017 nla_nest_cancel(msg
, nl_match
);
15021 for (j
= 0; j
< match
->n_channels
; j
++) {
15022 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
15023 nla_nest_cancel(msg
, nl_freqs
);
15024 nla_nest_cancel(msg
, nl_match
);
15029 nla_nest_end(msg
, nl_freqs
);
15032 nla_nest_end(msg
, nl_match
);
15036 nla_nest_end(msg
, nl_results
);
15040 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
15041 struct cfg80211_wowlan_wakeup
*wakeup
,
15044 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15045 struct sk_buff
*msg
;
15049 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
15052 size
+= wakeup
->packet_present_len
;
15054 msg
= nlmsg_new(size
, gfp
);
15058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
15062 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15063 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15067 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
15068 wdev
->netdev
->ifindex
))
15072 struct nlattr
*reasons
;
15074 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
15078 if (wakeup
->disconnect
&&
15079 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
15081 if (wakeup
->magic_pkt
&&
15082 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
15084 if (wakeup
->gtk_rekey_failure
&&
15085 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
15087 if (wakeup
->eap_identity_req
&&
15088 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
15090 if (wakeup
->four_way_handshake
&&
15091 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
15093 if (wakeup
->rfkill_release
&&
15094 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
15097 if (wakeup
->pattern_idx
>= 0 &&
15098 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
15099 wakeup
->pattern_idx
))
15102 if (wakeup
->tcp_match
&&
15103 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
15106 if (wakeup
->tcp_connlost
&&
15107 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
15110 if (wakeup
->tcp_nomoretokens
&&
15112 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
15115 if (wakeup
->packet
) {
15116 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
15117 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
15119 if (!wakeup
->packet_80211
) {
15121 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
15123 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
15126 if (wakeup
->packet_len
&&
15127 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
15130 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
15135 if (wakeup
->net_detect
&&
15136 cfg80211_net_detect_results(msg
, wakeup
))
15139 nla_nest_end(msg
, reasons
);
15142 genlmsg_end(msg
, hdr
);
15144 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15145 NL80211_MCGRP_MLME
, gfp
);
15151 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
15154 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
15155 enum nl80211_tdls_operation oper
,
15156 u16 reason_code
, gfp_t gfp
)
15158 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15159 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15160 struct sk_buff
*msg
;
15163 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
15166 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15170 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
15176 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15177 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15178 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
15179 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
15180 (reason_code
> 0 &&
15181 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
15182 goto nla_put_failure
;
15184 genlmsg_end(msg
, hdr
);
15186 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15187 NL80211_MCGRP_MLME
, gfp
);
15191 genlmsg_cancel(msg
, hdr
);
15194 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
15196 static int nl80211_netlink_notify(struct notifier_block
* nb
,
15197 unsigned long state
,
15200 struct netlink_notify
*notify
= _notify
;
15201 struct cfg80211_registered_device
*rdev
;
15202 struct wireless_dev
*wdev
;
15203 struct cfg80211_beacon_registration
*reg
, *tmp
;
15205 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
15206 return NOTIFY_DONE
;
15210 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
15211 struct cfg80211_sched_scan_request
*sched_scan_req
;
15213 list_for_each_entry_rcu(sched_scan_req
,
15214 &rdev
->sched_scan_req_list
,
15216 if (sched_scan_req
->owner_nlportid
== notify
->portid
) {
15217 sched_scan_req
->nl_owner_dead
= true;
15218 schedule_work(&rdev
->sched_scan_stop_wk
);
15222 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
15223 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
15225 if (wdev
->owner_nlportid
== notify
->portid
) {
15226 wdev
->nl_owner_dead
= true;
15227 schedule_work(&rdev
->destroy_work
);
15228 } else if (wdev
->conn_owner_nlportid
== notify
->portid
) {
15229 schedule_work(&wdev
->disconnect_wk
);
15233 spin_lock_bh(&rdev
->beacon_registrations_lock
);
15234 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
15236 if (reg
->nlportid
== notify
->portid
) {
15237 list_del(®
->list
);
15242 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15248 * It is possible that the user space process that is controlling the
15249 * indoor setting disappeared, so notify the regulatory core.
15251 regulatory_netlink_notify(notify
->portid
);
15255 static struct notifier_block nl80211_netlink_notifier
= {
15256 .notifier_call
= nl80211_netlink_notify
,
15259 void cfg80211_ft_event(struct net_device
*netdev
,
15260 struct cfg80211_ft_event_params
*ft_event
)
15262 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
15263 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15264 struct sk_buff
*msg
;
15267 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
15269 if (!ft_event
->target_ap
)
15272 msg
= nlmsg_new(100 + ft_event
->ric_ies_len
, GFP_KERNEL
);
15276 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
15280 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15281 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15282 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
15285 if (ft_event
->ies
&&
15286 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
15288 if (ft_event
->ric_ies
&&
15289 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
15290 ft_event
->ric_ies
))
15293 genlmsg_end(msg
, hdr
);
15295 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15296 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15301 EXPORT_SYMBOL(cfg80211_ft_event
);
15303 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
15305 struct cfg80211_registered_device
*rdev
;
15306 struct sk_buff
*msg
;
15310 rdev
= wiphy_to_rdev(wdev
->wiphy
);
15311 if (!rdev
->crit_proto_nlportid
)
15314 nlportid
= rdev
->crit_proto_nlportid
;
15315 rdev
->crit_proto_nlportid
= 0;
15317 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15321 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
15323 goto nla_put_failure
;
15325 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15326 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15328 goto nla_put_failure
;
15330 genlmsg_end(msg
, hdr
);
15332 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
15337 genlmsg_cancel(msg
, hdr
);
15340 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
15342 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
15344 struct wiphy
*wiphy
= wdev
->wiphy
;
15345 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15346 struct sk_buff
*msg
;
15349 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15353 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
15357 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15358 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
15359 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15363 genlmsg_end(msg
, hdr
);
15365 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
15366 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15372 /* initialisation/exit functions */
15374 int __init
nl80211_init(void)
15378 err
= genl_register_family(&nl80211_fam
);
15382 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
15388 genl_unregister_family(&nl80211_fam
);
15392 void nl80211_exit(void)
15394 netlink_unregister_notifier(&nl80211_netlink_notifier
);
15395 genl_unregister_family(&nl80211_fam
);