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 nlattr
*key
, struct key_parse
*k
)
740 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
741 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
742 nl80211_key_policy
, NULL
);
746 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
747 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
756 if (tb
[NL80211_KEY_IDX
])
757 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
759 if (tb
[NL80211_KEY_DATA
]) {
760 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
761 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
764 if (tb
[NL80211_KEY_SEQ
]) {
765 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
766 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
769 if (tb
[NL80211_KEY_CIPHER
])
770 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
772 if (tb
[NL80211_KEY_TYPE
]) {
773 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
774 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
778 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
779 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
781 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
782 tb
[NL80211_KEY_DEFAULT_TYPES
],
783 nl80211_key_default_policy
, NULL
);
787 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
788 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
794 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
796 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
797 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
798 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
801 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
802 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
803 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
806 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
807 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
809 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
810 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
812 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
813 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
822 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
823 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
824 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
828 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
829 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
830 int err
= nla_parse_nested(kdt
,
831 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
832 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
833 nl80211_key_default_policy
,
838 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
839 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
845 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
849 memset(k
, 0, sizeof(*k
));
853 if (info
->attrs
[NL80211_ATTR_KEY
])
854 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
856 err
= nl80211_parse_key_old(info
, k
);
861 if (k
->def
&& k
->defmgmt
)
865 if (k
->def_uni
|| !k
->def_multi
)
871 if (k
->idx
< 4 || k
->idx
> 5)
874 if (k
->idx
< 0 || k
->idx
> 3)
877 if (k
->idx
< 0 || k
->idx
> 5)
885 static struct cfg80211_cached_keys
*
886 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
887 struct nlattr
*keys
, bool *no_ht
)
889 struct key_parse parse
;
891 struct cfg80211_cached_keys
*result
;
892 int rem
, err
, def
= 0;
893 bool have_key
= false;
895 nla_for_each_nested(key
, keys
, rem
) {
903 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
905 return ERR_PTR(-ENOMEM
);
909 nla_for_each_nested(key
, keys
, rem
) {
910 memset(&parse
, 0, sizeof(parse
));
913 err
= nl80211_parse_key_new(key
, &parse
);
919 if (parse
.idx
< 0 || parse
.idx
> 3)
925 result
->def
= parse
.idx
;
926 if (!parse
.def_uni
|| !parse
.def_multi
)
928 } else if (parse
.defmgmt
)
930 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
931 parse
.idx
, false, NULL
);
934 if (parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
935 parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
) {
939 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
940 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
941 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
942 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
944 /* must be WEP key if we got here */
949 if (result
->def
< 0) {
960 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
962 ASSERT_WDEV_LOCK(wdev
);
964 switch (wdev
->iftype
) {
965 case NL80211_IFTYPE_AP
:
966 case NL80211_IFTYPE_AP_VLAN
:
967 case NL80211_IFTYPE_P2P_GO
:
968 case NL80211_IFTYPE_MESH_POINT
:
970 case NL80211_IFTYPE_ADHOC
:
971 case NL80211_IFTYPE_STATION
:
972 case NL80211_IFTYPE_P2P_CLIENT
:
973 if (!wdev
->current_bss
)
976 case NL80211_IFTYPE_UNSPECIFIED
:
977 case NL80211_IFTYPE_OCB
:
978 case NL80211_IFTYPE_MONITOR
:
979 case NL80211_IFTYPE_NAN
:
980 case NL80211_IFTYPE_P2P_DEVICE
:
981 case NL80211_IFTYPE_WDS
:
982 case NUM_NL80211_IFTYPES
:
989 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
992 struct ieee80211_channel
*chan
;
996 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
997 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
1002 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
1004 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
1008 goto nla_put_failure
;
1012 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
1013 goto nla_put_failure
;
1018 nla_nest_end(msg
, nl_modes
);
1025 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
1026 struct sk_buff
*msg
,
1029 struct nlattr
*nl_combis
;
1032 nl_combis
= nla_nest_start(msg
,
1033 NL80211_ATTR_INTERFACE_COMBINATIONS
);
1035 goto nla_put_failure
;
1037 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
1038 const struct ieee80211_iface_combination
*c
;
1039 struct nlattr
*nl_combi
, *nl_limits
;
1041 c
= &wiphy
->iface_combinations
[i
];
1043 nl_combi
= nla_nest_start(msg
, i
+ 1);
1045 goto nla_put_failure
;
1047 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
1049 goto nla_put_failure
;
1051 for (j
= 0; j
< c
->n_limits
; j
++) {
1052 struct nlattr
*nl_limit
;
1054 nl_limit
= nla_nest_start(msg
, j
+ 1);
1056 goto nla_put_failure
;
1057 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
1059 goto nla_put_failure
;
1060 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
1061 c
->limits
[j
].types
))
1062 goto nla_put_failure
;
1063 nla_nest_end(msg
, nl_limit
);
1066 nla_nest_end(msg
, nl_limits
);
1068 if (c
->beacon_int_infra_match
&&
1069 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
1070 goto nla_put_failure
;
1071 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
1072 c
->num_different_channels
) ||
1073 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
1075 goto nla_put_failure
;
1077 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1078 c
->radar_detect_widths
) ||
1079 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1080 c
->radar_detect_regions
)))
1081 goto nla_put_failure
;
1082 if (c
->beacon_int_min_gcd
&&
1083 nla_put_u32(msg
, NL80211_IFACE_COMB_BI_MIN_GCD
,
1084 c
->beacon_int_min_gcd
))
1085 goto nla_put_failure
;
1087 nla_nest_end(msg
, nl_combi
);
1090 nla_nest_end(msg
, nl_combis
);
1098 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1099 struct sk_buff
*msg
)
1101 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1102 struct nlattr
*nl_tcp
;
1107 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1111 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1112 tcp
->data_payload_max
))
1115 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1116 tcp
->data_payload_max
))
1119 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1122 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1123 sizeof(*tcp
->tok
), tcp
->tok
))
1126 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1127 tcp
->data_interval_max
))
1130 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1131 tcp
->wake_payload_max
))
1134 nla_nest_end(msg
, nl_tcp
);
1138 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1139 struct cfg80211_registered_device
*rdev
,
1142 struct nlattr
*nl_wowlan
;
1144 if (!rdev
->wiphy
.wowlan
)
1147 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1151 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1152 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1153 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1154 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1155 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1156 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1157 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1158 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1159 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1160 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1161 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1162 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1163 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1164 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1165 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1166 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1169 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1170 struct nl80211_pattern_support pat
= {
1171 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1172 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1173 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1174 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1177 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1182 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1183 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1184 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1187 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1190 nla_nest_end(msg
, nl_wowlan
);
1196 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1197 struct cfg80211_registered_device
*rdev
)
1199 struct nl80211_coalesce_rule_support rule
;
1201 if (!rdev
->wiphy
.coalesce
)
1204 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1205 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1206 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1207 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1208 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1209 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1211 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1217 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1218 struct ieee80211_supported_band
*sband
)
1220 struct nlattr
*nl_rates
, *nl_rate
;
1221 struct ieee80211_rate
*rate
;
1225 if (sband
->ht_cap
.ht_supported
&&
1226 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1227 sizeof(sband
->ht_cap
.mcs
),
1228 &sband
->ht_cap
.mcs
) ||
1229 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1230 sband
->ht_cap
.cap
) ||
1231 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1232 sband
->ht_cap
.ampdu_factor
) ||
1233 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1234 sband
->ht_cap
.ampdu_density
)))
1238 if (sband
->vht_cap
.vht_supported
&&
1239 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1240 sizeof(sband
->vht_cap
.vht_mcs
),
1241 &sband
->vht_cap
.vht_mcs
) ||
1242 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1243 sband
->vht_cap
.cap
)))
1247 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1251 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1252 nl_rate
= nla_nest_start(msg
, i
);
1256 rate
= &sband
->bitrates
[i
];
1257 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1260 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1262 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1265 nla_nest_end(msg
, nl_rate
);
1268 nla_nest_end(msg
, nl_rates
);
1274 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1275 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1278 struct nlattr
*nl_ftypes
, *nl_ifs
;
1279 enum nl80211_iftype ift
;
1285 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1289 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1290 nl_ftypes
= nla_nest_start(msg
, ift
);
1294 stypes
= mgmt_stypes
[ift
].tx
;
1297 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1298 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1303 nla_nest_end(msg
, nl_ftypes
);
1306 nla_nest_end(msg
, nl_ifs
);
1308 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1312 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1313 nl_ftypes
= nla_nest_start(msg
, ift
);
1317 stypes
= mgmt_stypes
[ift
].rx
;
1320 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1321 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1326 nla_nest_end(msg
, nl_ftypes
);
1328 nla_nest_end(msg
, nl_ifs
);
1333 #define CMD(op, n) \
1335 if (rdev->ops->op) { \
1337 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1338 goto nla_put_failure; \
1342 static int nl80211_add_commands_unsplit(struct cfg80211_registered_device
*rdev
,
1343 struct sk_buff
*msg
)
1348 * do *NOT* add anything into this function, new things need to be
1349 * advertised only to new versions of userspace that can deal with
1350 * the split (and they can't possibly care about new features...
1352 CMD(add_virtual_intf
, NEW_INTERFACE
);
1353 CMD(change_virtual_intf
, SET_INTERFACE
);
1354 CMD(add_key
, NEW_KEY
);
1355 CMD(start_ap
, START_AP
);
1356 CMD(add_station
, NEW_STATION
);
1357 CMD(add_mpath
, NEW_MPATH
);
1358 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1359 CMD(change_bss
, SET_BSS
);
1360 CMD(auth
, AUTHENTICATE
);
1361 CMD(assoc
, ASSOCIATE
);
1362 CMD(deauth
, DEAUTHENTICATE
);
1363 CMD(disassoc
, DISASSOCIATE
);
1364 CMD(join_ibss
, JOIN_IBSS
);
1365 CMD(join_mesh
, JOIN_MESH
);
1366 CMD(set_pmksa
, SET_PMKSA
);
1367 CMD(del_pmksa
, DEL_PMKSA
);
1368 CMD(flush_pmksa
, FLUSH_PMKSA
);
1369 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1370 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1371 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1372 CMD(mgmt_tx
, FRAME
);
1373 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1374 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1376 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1377 goto nla_put_failure
;
1379 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1380 rdev
->ops
->join_mesh
) {
1382 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1383 goto nla_put_failure
;
1385 CMD(set_wds_peer
, SET_WDS_PEER
);
1386 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1387 CMD(tdls_mgmt
, TDLS_MGMT
);
1388 CMD(tdls_oper
, TDLS_OPER
);
1390 if (rdev
->wiphy
.max_sched_scan_reqs
)
1391 CMD(sched_scan_start
, START_SCHED_SCAN
);
1392 CMD(probe_client
, PROBE_CLIENT
);
1393 CMD(set_noack_map
, SET_NOACK_MAP
);
1394 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1396 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1397 goto nla_put_failure
;
1399 CMD(start_p2p_device
, START_P2P_DEVICE
);
1400 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1401 #ifdef CONFIG_NL80211_TESTMODE
1402 CMD(testmode_cmd
, TESTMODE
);
1405 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1407 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1408 goto nla_put_failure
;
1411 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1413 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1414 goto nla_put_failure
;
1422 struct nl80211_dump_wiphy_state
{
1425 long split_start
, band_start
, chan_start
, capa_start
;
1429 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1430 enum nl80211_commands cmd
,
1431 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1432 int flags
, struct nl80211_dump_wiphy_state
*state
)
1435 struct nlattr
*nl_bands
, *nl_band
;
1436 struct nlattr
*nl_freqs
, *nl_freq
;
1437 struct nlattr
*nl_cmds
;
1438 enum nl80211_band band
;
1439 struct ieee80211_channel
*chan
;
1441 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1442 rdev
->wiphy
.mgmt_stypes
;
1445 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1449 if (WARN_ON(!state
))
1452 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1453 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1454 wiphy_name(&rdev
->wiphy
)) ||
1455 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1456 cfg80211_rdev_list_generation
))
1457 goto nla_put_failure
;
1459 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1462 switch (state
->split_start
) {
1464 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1465 rdev
->wiphy
.retry_short
) ||
1466 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1467 rdev
->wiphy
.retry_long
) ||
1468 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1469 rdev
->wiphy
.frag_threshold
) ||
1470 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1471 rdev
->wiphy
.rts_threshold
) ||
1472 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1473 rdev
->wiphy
.coverage_class
) ||
1474 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1475 rdev
->wiphy
.max_scan_ssids
) ||
1476 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1477 rdev
->wiphy
.max_sched_scan_ssids
) ||
1478 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1479 rdev
->wiphy
.max_scan_ie_len
) ||
1480 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1481 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1482 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1483 rdev
->wiphy
.max_match_sets
) ||
1484 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1485 rdev
->wiphy
.max_sched_scan_plans
) ||
1486 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1487 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1488 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1489 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1490 goto nla_put_failure
;
1492 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1493 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1494 goto nla_put_failure
;
1495 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1496 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1497 goto nla_put_failure
;
1498 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1499 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1500 goto nla_put_failure
;
1501 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1502 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1503 goto nla_put_failure
;
1504 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1505 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1506 goto nla_put_failure
;
1507 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1508 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1509 goto nla_put_failure
;
1510 state
->split_start
++;
1514 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1515 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1516 rdev
->wiphy
.cipher_suites
))
1517 goto nla_put_failure
;
1519 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1520 rdev
->wiphy
.max_num_pmkids
))
1521 goto nla_put_failure
;
1523 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1524 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1525 goto nla_put_failure
;
1527 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1528 rdev
->wiphy
.available_antennas_tx
) ||
1529 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1530 rdev
->wiphy
.available_antennas_rx
))
1531 goto nla_put_failure
;
1533 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1534 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1535 rdev
->wiphy
.probe_resp_offload
))
1536 goto nla_put_failure
;
1538 if ((rdev
->wiphy
.available_antennas_tx
||
1539 rdev
->wiphy
.available_antennas_rx
) &&
1540 rdev
->ops
->get_antenna
) {
1541 u32 tx_ant
= 0, rx_ant
= 0;
1544 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1546 if (nla_put_u32(msg
,
1547 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1550 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1552 goto nla_put_failure
;
1556 state
->split_start
++;
1560 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1561 rdev
->wiphy
.interface_modes
))
1562 goto nla_put_failure
;
1563 state
->split_start
++;
1567 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1569 goto nla_put_failure
;
1571 for (band
= state
->band_start
;
1572 band
< NUM_NL80211_BANDS
; band
++) {
1573 struct ieee80211_supported_band
*sband
;
1575 sband
= rdev
->wiphy
.bands
[band
];
1580 nl_band
= nla_nest_start(msg
, band
);
1582 goto nla_put_failure
;
1584 switch (state
->chan_start
) {
1586 if (nl80211_send_band_rateinfo(msg
, sband
))
1587 goto nla_put_failure
;
1588 state
->chan_start
++;
1592 /* add frequencies */
1593 nl_freqs
= nla_nest_start(
1594 msg
, NL80211_BAND_ATTR_FREQS
);
1596 goto nla_put_failure
;
1598 for (i
= state
->chan_start
- 1;
1599 i
< sband
->n_channels
;
1601 nl_freq
= nla_nest_start(msg
, i
);
1603 goto nla_put_failure
;
1605 chan
= &sband
->channels
[i
];
1607 if (nl80211_msg_put_channel(
1610 goto nla_put_failure
;
1612 nla_nest_end(msg
, nl_freq
);
1616 if (i
< sband
->n_channels
)
1617 state
->chan_start
= i
+ 2;
1619 state
->chan_start
= 0;
1620 nla_nest_end(msg
, nl_freqs
);
1623 nla_nest_end(msg
, nl_band
);
1626 /* start again here */
1627 if (state
->chan_start
)
1632 nla_nest_end(msg
, nl_bands
);
1634 if (band
< NUM_NL80211_BANDS
)
1635 state
->band_start
= band
+ 1;
1637 state
->band_start
= 0;
1639 /* if bands & channels are done, continue outside */
1640 if (state
->band_start
== 0 && state
->chan_start
== 0)
1641 state
->split_start
++;
1645 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1647 goto nla_put_failure
;
1649 i
= nl80211_add_commands_unsplit(rdev
, msg
);
1651 goto nla_put_failure
;
1653 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1654 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1655 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1656 CMD(channel_switch
, CHANNEL_SWITCH
);
1657 CMD(set_qos_map
, SET_QOS_MAP
);
1658 if (rdev
->wiphy
.features
&
1659 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1660 CMD(add_tx_ts
, ADD_TX_TS
);
1661 CMD(set_multicast_to_unicast
, SET_MULTICAST_TO_UNICAST
);
1662 CMD(update_connect_params
, UPDATE_CONNECT_PARAMS
);
1666 nla_nest_end(msg
, nl_cmds
);
1667 state
->split_start
++;
1671 if (rdev
->ops
->remain_on_channel
&&
1672 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1674 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1675 rdev
->wiphy
.max_remain_on_channel_duration
))
1676 goto nla_put_failure
;
1678 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1679 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1680 goto nla_put_failure
;
1682 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1683 goto nla_put_failure
;
1684 state
->split_start
++;
1689 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1690 goto nla_put_failure
;
1691 state
->split_start
++;
1695 state
->split_start
++;
1698 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1699 rdev
->wiphy
.software_iftypes
))
1700 goto nla_put_failure
;
1702 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1704 goto nla_put_failure
;
1706 state
->split_start
++;
1710 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1711 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1712 rdev
->wiphy
.ap_sme_capa
))
1713 goto nla_put_failure
;
1715 features
= rdev
->wiphy
.features
;
1717 * We can only add the per-channel limit information if the
1718 * dump is split, otherwise it makes it too big. Therefore
1719 * only advertise it in that case.
1722 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1723 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1724 goto nla_put_failure
;
1726 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1727 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1728 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1729 rdev
->wiphy
.ht_capa_mod_mask
))
1730 goto nla_put_failure
;
1732 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1733 rdev
->wiphy
.max_acl_mac_addrs
&&
1734 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1735 rdev
->wiphy
.max_acl_mac_addrs
))
1736 goto nla_put_failure
;
1739 * Any information below this point is only available to
1740 * applications that can deal with it being split. This
1741 * helps ensure that newly added capabilities don't break
1742 * older tools by overrunning their buffers.
1744 * We still increment split_start so that in the split
1745 * case we'll continue with more data in the next round,
1746 * but break unconditionally so unsplit data stops here.
1748 state
->split_start
++;
1751 if (rdev
->wiphy
.extended_capabilities
&&
1752 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1753 rdev
->wiphy
.extended_capabilities_len
,
1754 rdev
->wiphy
.extended_capabilities
) ||
1755 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1756 rdev
->wiphy
.extended_capabilities_len
,
1757 rdev
->wiphy
.extended_capabilities_mask
)))
1758 goto nla_put_failure
;
1760 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1761 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1762 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1763 rdev
->wiphy
.vht_capa_mod_mask
))
1764 goto nla_put_failure
;
1766 state
->split_start
++;
1769 if (nl80211_send_coalesce(msg
, rdev
))
1770 goto nla_put_failure
;
1772 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1773 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1774 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1775 goto nla_put_failure
;
1777 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1778 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1779 rdev
->wiphy
.max_ap_assoc_sta
))
1780 goto nla_put_failure
;
1782 state
->split_start
++;
1785 if (rdev
->wiphy
.n_vendor_commands
) {
1786 const struct nl80211_vendor_cmd_info
*info
;
1787 struct nlattr
*nested
;
1789 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1791 goto nla_put_failure
;
1793 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1794 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1795 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1796 goto nla_put_failure
;
1798 nla_nest_end(msg
, nested
);
1801 if (rdev
->wiphy
.n_vendor_events
) {
1802 const struct nl80211_vendor_cmd_info
*info
;
1803 struct nlattr
*nested
;
1805 nested
= nla_nest_start(msg
,
1806 NL80211_ATTR_VENDOR_EVENTS
);
1808 goto nla_put_failure
;
1810 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1811 info
= &rdev
->wiphy
.vendor_events
[i
];
1812 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1813 goto nla_put_failure
;
1815 nla_nest_end(msg
, nested
);
1817 state
->split_start
++;
1820 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1821 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1822 rdev
->wiphy
.max_num_csa_counters
))
1823 goto nla_put_failure
;
1825 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1826 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1827 goto nla_put_failure
;
1829 if (rdev
->wiphy
.max_sched_scan_reqs
&&
1830 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_MAX_REQS
,
1831 rdev
->wiphy
.max_sched_scan_reqs
))
1832 goto nla_put_failure
;
1834 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1835 sizeof(rdev
->wiphy
.ext_features
),
1836 rdev
->wiphy
.ext_features
))
1837 goto nla_put_failure
;
1839 if (rdev
->wiphy
.bss_select_support
) {
1840 struct nlattr
*nested
;
1841 u32 bss_select_support
= rdev
->wiphy
.bss_select_support
;
1843 nested
= nla_nest_start(msg
, NL80211_ATTR_BSS_SELECT
);
1845 goto nla_put_failure
;
1848 while (bss_select_support
) {
1849 if ((bss_select_support
& 1) &&
1850 nla_put_flag(msg
, i
))
1851 goto nla_put_failure
;
1853 bss_select_support
>>= 1;
1855 nla_nest_end(msg
, nested
);
1858 state
->split_start
++;
1861 if (rdev
->wiphy
.num_iftype_ext_capab
&&
1862 rdev
->wiphy
.iftype_ext_capab
) {
1863 struct nlattr
*nested_ext_capab
, *nested
;
1865 nested
= nla_nest_start(msg
,
1866 NL80211_ATTR_IFTYPE_EXT_CAPA
);
1868 goto nla_put_failure
;
1870 for (i
= state
->capa_start
;
1871 i
< rdev
->wiphy
.num_iftype_ext_capab
; i
++) {
1872 const struct wiphy_iftype_ext_capab
*capab
;
1874 capab
= &rdev
->wiphy
.iftype_ext_capab
[i
];
1876 nested_ext_capab
= nla_nest_start(msg
, i
);
1877 if (!nested_ext_capab
||
1878 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
1880 nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1881 capab
->extended_capabilities_len
,
1882 capab
->extended_capabilities
) ||
1883 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1884 capab
->extended_capabilities_len
,
1885 capab
->extended_capabilities_mask
))
1886 goto nla_put_failure
;
1888 nla_nest_end(msg
, nested_ext_capab
);
1892 nla_nest_end(msg
, nested
);
1893 if (i
< rdev
->wiphy
.num_iftype_ext_capab
) {
1894 state
->capa_start
= i
+ 1;
1899 if (nla_put_u32(msg
, NL80211_ATTR_BANDS
,
1900 rdev
->wiphy
.nan_supported_bands
))
1901 goto nla_put_failure
;
1904 state
->split_start
= 0;
1908 genlmsg_end(msg
, hdr
);
1912 genlmsg_cancel(msg
, hdr
);
1916 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1917 struct netlink_callback
*cb
,
1918 struct nl80211_dump_wiphy_state
*state
)
1920 struct nlattr
**tb
= genl_family_attrbuf(&nl80211_fam
);
1921 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, tb
,
1922 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
1923 /* ignore parse errors for backward compatibility */
1927 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1928 if (tb
[NL80211_ATTR_WIPHY
])
1929 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1930 if (tb
[NL80211_ATTR_WDEV
])
1931 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1932 if (tb
[NL80211_ATTR_IFINDEX
]) {
1933 struct net_device
*netdev
;
1934 struct cfg80211_registered_device
*rdev
;
1935 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1937 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1940 if (netdev
->ieee80211_ptr
) {
1941 rdev
= wiphy_to_rdev(
1942 netdev
->ieee80211_ptr
->wiphy
);
1943 state
->filter_wiphy
= rdev
->wiphy_idx
;
1950 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1953 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1954 struct cfg80211_registered_device
*rdev
;
1958 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1963 state
->filter_wiphy
= -1;
1964 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1970 cb
->args
[0] = (long)state
;
1973 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1974 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1976 if (++idx
<= state
->start
)
1978 if (state
->filter_wiphy
!= -1 &&
1979 state
->filter_wiphy
!= rdev
->wiphy_idx
)
1981 /* attempt to fit multiple wiphy data chunks into the skb */
1983 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
1985 NETLINK_CB(cb
->skb
).portid
,
1987 NLM_F_MULTI
, state
);
1990 * If sending the wiphy data didn't fit (ENOBUFS
1991 * or EMSGSIZE returned), this SKB is still
1992 * empty (so it's not too big because another
1993 * wiphy dataset is already in the skb) and
1994 * we've not tried to adjust the dump allocation
1995 * yet ... then adjust the alloc size to be
1996 * bigger, and return 1 but with the empty skb.
1997 * This results in an empty message being RX'ed
1998 * in userspace, but that is ignored.
2000 * We can then retry with the larger buffer.
2002 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
2003 !skb
->len
&& !state
->split
&&
2004 cb
->min_dump_alloc
< 4096) {
2005 cb
->min_dump_alloc
= 4096;
2006 state
->split_start
= 0;
2013 } while (state
->split_start
> 0);
2023 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
2025 kfree((void *)cb
->args
[0]);
2029 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2031 struct sk_buff
*msg
;
2032 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2033 struct nl80211_dump_wiphy_state state
= {};
2035 msg
= nlmsg_new(4096, GFP_KERNEL
);
2039 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
2040 info
->snd_portid
, info
->snd_seq
, 0,
2046 return genlmsg_reply(msg
, info
);
2049 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
2050 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
2051 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
2052 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
2053 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
2054 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
2057 static int parse_txq_params(struct nlattr
*tb
[],
2058 struct ieee80211_txq_params
*txq_params
)
2062 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
2063 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
2064 !tb
[NL80211_TXQ_ATTR_AIFS
])
2067 ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
2068 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
2069 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
2070 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
2071 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
2073 if (ac
>= NL80211_NUM_ACS
)
2075 txq_params
->ac
= array_index_nospec(ac
, NL80211_NUM_ACS
);
2079 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
2082 * You can only set the channel explicitly for WDS interfaces,
2083 * all others have their channel managed via their respective
2084 * "establish a connection" command (connect, join, ...)
2086 * For AP/GO and mesh mode, the channel can be set with the
2087 * channel userspace API, but is only stored and passed to the
2088 * low-level driver when the AP starts or the mesh is joined.
2089 * This is for backward compatibility, userspace can also give
2090 * the channel in the start-ap or join-mesh commands instead.
2092 * Monitors are special as they are normally slaved to
2093 * whatever else is going on, so they have their own special
2094 * operation to set the monitor channel if possible.
2097 wdev
->iftype
== NL80211_IFTYPE_AP
||
2098 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
2099 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
2100 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
2103 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
2104 struct genl_info
*info
,
2105 struct cfg80211_chan_def
*chandef
)
2109 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
2112 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
2114 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
2115 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
2116 chandef
->center_freq1
= control_freq
;
2117 chandef
->center_freq2
= 0;
2119 /* Primary channel not allowed */
2120 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
2123 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2124 enum nl80211_channel_type chantype
;
2126 chantype
= nla_get_u32(
2127 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2130 case NL80211_CHAN_NO_HT
:
2131 case NL80211_CHAN_HT20
:
2132 case NL80211_CHAN_HT40PLUS
:
2133 case NL80211_CHAN_HT40MINUS
:
2134 cfg80211_chandef_create(chandef
, chandef
->chan
,
2140 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
2142 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
2143 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
2144 chandef
->center_freq1
=
2146 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
2147 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
2148 chandef
->center_freq2
=
2150 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
2153 if (!cfg80211_chandef_valid(chandef
))
2156 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
2157 IEEE80211_CHAN_DISABLED
))
2160 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
2161 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
2162 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
2168 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
2169 struct net_device
*dev
,
2170 struct genl_info
*info
)
2172 struct cfg80211_chan_def chandef
;
2174 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
2175 struct wireless_dev
*wdev
= NULL
;
2178 wdev
= dev
->ieee80211_ptr
;
2179 if (!nl80211_can_set_dev_channel(wdev
))
2182 iftype
= wdev
->iftype
;
2184 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2189 case NL80211_IFTYPE_AP
:
2190 case NL80211_IFTYPE_P2P_GO
:
2191 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2196 if (wdev
->beacon_interval
) {
2197 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2198 !(rdev
->wiphy
.features
&
2199 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2204 /* Only allow dynamic channel width changes */
2205 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2209 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2213 wdev
->preset_chandef
= chandef
;
2216 case NL80211_IFTYPE_MESH_POINT
:
2217 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2219 case NL80211_IFTYPE_MONITOR
:
2220 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2229 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2231 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2232 struct net_device
*netdev
= info
->user_ptr
[1];
2234 return __nl80211_set_channel(rdev
, netdev
, info
);
2237 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2239 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2240 struct net_device
*dev
= info
->user_ptr
[1];
2241 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2244 if (!info
->attrs
[NL80211_ATTR_MAC
])
2247 if (netif_running(dev
))
2250 if (!rdev
->ops
->set_wds_peer
)
2253 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2256 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2257 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2260 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2262 struct cfg80211_registered_device
*rdev
;
2263 struct net_device
*netdev
= NULL
;
2264 struct wireless_dev
*wdev
;
2265 int result
= 0, rem_txq_params
= 0;
2266 struct nlattr
*nl_txq_params
;
2268 u8 retry_short
= 0, retry_long
= 0;
2269 u32 frag_threshold
= 0, rts_threshold
= 0;
2270 u8 coverage_class
= 0;
2275 * Try to find the wiphy and netdev. Normally this
2276 * function shouldn't need the netdev, but this is
2277 * done for backward compatibility -- previously
2278 * setting the channel was done per wiphy, but now
2279 * it is per netdev. Previous userland like hostapd
2280 * also passed a netdev to set_wiphy, so that it is
2281 * possible to let that go to the right netdev!
2284 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2285 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2287 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2288 if (netdev
&& netdev
->ieee80211_ptr
)
2289 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2295 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2298 return PTR_ERR(rdev
);
2303 wdev
= netdev
->ieee80211_ptr
;
2306 * end workaround code, by now the rdev is available
2307 * and locked, and wdev may or may not be NULL.
2310 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2311 result
= cfg80211_dev_rename(
2312 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2317 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2318 struct ieee80211_txq_params txq_params
;
2319 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2321 if (!rdev
->ops
->set_txq_params
)
2327 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2328 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2331 if (!netif_running(netdev
))
2334 nla_for_each_nested(nl_txq_params
,
2335 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2337 result
= nla_parse_nested(tb
, NL80211_TXQ_ATTR_MAX
,
2343 result
= parse_txq_params(tb
, &txq_params
);
2347 result
= rdev_set_txq_params(rdev
, netdev
,
2354 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2355 result
= __nl80211_set_channel(
2357 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2363 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2364 struct wireless_dev
*txp_wdev
= wdev
;
2365 enum nl80211_tx_power_setting type
;
2368 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2371 if (!rdev
->ops
->set_tx_power
)
2374 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2375 type
= nla_get_u32(info
->attrs
[idx
]);
2377 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2378 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2381 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2382 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2383 mbm
= nla_get_u32(info
->attrs
[idx
]);
2386 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2391 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2392 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2395 if ((!rdev
->wiphy
.available_antennas_tx
&&
2396 !rdev
->wiphy
.available_antennas_rx
) ||
2397 !rdev
->ops
->set_antenna
)
2400 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2401 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2403 /* reject antenna configurations which don't match the
2404 * available antenna masks, except for the "all" mask */
2405 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2406 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2409 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2410 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2412 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2419 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2420 retry_short
= nla_get_u8(
2421 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2422 if (retry_short
== 0)
2425 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2428 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2429 retry_long
= nla_get_u8(
2430 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2431 if (retry_long
== 0)
2434 changed
|= WIPHY_PARAM_RETRY_LONG
;
2437 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2438 frag_threshold
= nla_get_u32(
2439 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2440 if (frag_threshold
< 256)
2443 if (frag_threshold
!= (u32
) -1) {
2445 * Fragments (apart from the last one) are required to
2446 * have even length. Make the fragmentation code
2447 * simpler by stripping LSB should someone try to use
2448 * odd threshold value.
2450 frag_threshold
&= ~0x1;
2452 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2455 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2456 rts_threshold
= nla_get_u32(
2457 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2458 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2461 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2462 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2465 coverage_class
= nla_get_u8(
2466 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2467 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2470 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2471 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2474 changed
|= WIPHY_PARAM_DYN_ACK
;
2478 u8 old_retry_short
, old_retry_long
;
2479 u32 old_frag_threshold
, old_rts_threshold
;
2480 u8 old_coverage_class
;
2482 if (!rdev
->ops
->set_wiphy_params
)
2485 old_retry_short
= rdev
->wiphy
.retry_short
;
2486 old_retry_long
= rdev
->wiphy
.retry_long
;
2487 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2488 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2489 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2491 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2492 rdev
->wiphy
.retry_short
= retry_short
;
2493 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2494 rdev
->wiphy
.retry_long
= retry_long
;
2495 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2496 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2497 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2498 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2499 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2500 rdev
->wiphy
.coverage_class
= coverage_class
;
2502 result
= rdev_set_wiphy_params(rdev
, changed
);
2504 rdev
->wiphy
.retry_short
= old_retry_short
;
2505 rdev
->wiphy
.retry_long
= old_retry_long
;
2506 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2507 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2508 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2515 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2517 return (u64
)wdev
->identifier
|
2518 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2521 static int nl80211_send_chandef(struct sk_buff
*msg
,
2522 const struct cfg80211_chan_def
*chandef
)
2524 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2527 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2528 chandef
->chan
->center_freq
))
2530 switch (chandef
->width
) {
2531 case NL80211_CHAN_WIDTH_20_NOHT
:
2532 case NL80211_CHAN_WIDTH_20
:
2533 case NL80211_CHAN_WIDTH_40
:
2534 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2535 cfg80211_get_chandef_type(chandef
)))
2541 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2543 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2545 if (chandef
->center_freq2
&&
2546 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2551 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2552 struct cfg80211_registered_device
*rdev
,
2553 struct wireless_dev
*wdev
, bool removal
)
2555 struct net_device
*dev
= wdev
->netdev
;
2556 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2560 cmd
= NL80211_CMD_DEL_INTERFACE
;
2562 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2567 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2568 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2569 goto nla_put_failure
;
2571 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2572 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2573 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
2574 NL80211_ATTR_PAD
) ||
2575 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2576 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2577 rdev
->devlist_generation
^
2578 (cfg80211_rdev_list_generation
<< 2)))
2579 goto nla_put_failure
;
2581 if (rdev
->ops
->get_channel
) {
2583 struct cfg80211_chan_def chandef
;
2585 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2587 if (nl80211_send_chandef(msg
, &chandef
))
2588 goto nla_put_failure
;
2592 if (rdev
->ops
->get_tx_power
) {
2595 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2597 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2599 goto nla_put_failure
;
2602 if (wdev
->ssid_len
) {
2603 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2604 goto nla_put_failure
;
2607 genlmsg_end(msg
, hdr
);
2611 genlmsg_cancel(msg
, hdr
);
2615 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2619 int wp_start
= cb
->args
[0];
2620 int if_start
= cb
->args
[1];
2621 int filter_wiphy
= -1;
2622 struct cfg80211_registered_device
*rdev
;
2623 struct wireless_dev
*wdev
;
2628 struct nl80211_dump_wiphy_state state
= {
2632 ret
= nl80211_dump_wiphy_parse(skb
, cb
, &state
);
2636 filter_wiphy
= state
.filter_wiphy
;
2639 * if filtering, set cb->args[2] to +1 since 0 is the default
2640 * value needed to determine that parsing is necessary.
2642 if (filter_wiphy
>= 0)
2643 cb
->args
[2] = filter_wiphy
+ 1;
2646 } else if (cb
->args
[2] > 0) {
2647 filter_wiphy
= cb
->args
[2] - 1;
2650 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2651 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2653 if (wp_idx
< wp_start
) {
2658 if (filter_wiphy
>= 0 && filter_wiphy
!= rdev
->wiphy_idx
)
2663 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
2664 if (if_idx
< if_start
) {
2668 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2669 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2670 rdev
, wdev
, false) < 0) {
2679 cb
->args
[0] = wp_idx
;
2680 cb
->args
[1] = if_idx
;
2689 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2691 struct sk_buff
*msg
;
2692 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2693 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2695 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2699 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2700 rdev
, wdev
, false) < 0) {
2705 return genlmsg_reply(msg
, info
);
2708 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2709 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2710 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2711 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2712 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2713 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2714 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2717 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2719 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2727 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
, nla
,
2728 mntr_flags_policy
, NULL
))
2731 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2733 *mntrflags
|= (1<<flag
);
2735 *mntrflags
|= MONITOR_FLAG_CHANGED
;
2740 static int nl80211_parse_mon_options(struct cfg80211_registered_device
*rdev
,
2741 enum nl80211_iftype type
,
2742 struct genl_info
*info
,
2743 struct vif_params
*params
)
2745 bool change
= false;
2748 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2749 if (type
!= NL80211_IFTYPE_MONITOR
)
2752 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2760 if (params
->flags
& MONITOR_FLAG_ACTIVE
&&
2761 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2764 if (info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]) {
2765 const u8
*mumimo_groups
;
2766 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2768 if (type
!= NL80211_IFTYPE_MONITOR
)
2771 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2775 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]);
2777 /* bits 0 and 63 are reserved and must be zero */
2778 if ((mumimo_groups
[0] & BIT(0)) ||
2779 (mumimo_groups
[VHT_MUMIMO_GROUPS_DATA_LEN
- 1] & BIT(7)))
2782 params
->vht_mumimo_groups
= mumimo_groups
;
2786 if (info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]) {
2787 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2789 if (type
!= NL80211_IFTYPE_MONITOR
)
2792 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2795 params
->vht_mumimo_follow_addr
=
2796 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]);
2800 return change
? 1 : 0;
2803 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2804 struct net_device
*netdev
, u8 use_4addr
,
2805 enum nl80211_iftype iftype
)
2808 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2814 case NL80211_IFTYPE_AP_VLAN
:
2815 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2818 case NL80211_IFTYPE_STATION
:
2819 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2829 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2831 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2832 struct vif_params params
;
2834 enum nl80211_iftype otype
, ntype
;
2835 struct net_device
*dev
= info
->user_ptr
[1];
2836 bool change
= false;
2838 memset(¶ms
, 0, sizeof(params
));
2840 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2842 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2843 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2846 if (ntype
> NL80211_IFTYPE_MAX
)
2850 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2851 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2853 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2855 if (netif_running(dev
))
2859 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2860 IEEE80211_MAX_MESH_ID_LEN
);
2861 wdev
->mesh_id_up_len
=
2862 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2863 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2864 wdev
->mesh_id_up_len
);
2868 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2869 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2871 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2875 params
.use_4addr
= -1;
2878 err
= nl80211_parse_mon_options(rdev
, ntype
, info
, ¶ms
);
2885 err
= cfg80211_change_iface(rdev
, dev
, ntype
, ¶ms
);
2889 if (!err
&& params
.use_4addr
!= -1)
2890 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2895 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2897 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2898 struct vif_params params
;
2899 struct wireless_dev
*wdev
;
2900 struct sk_buff
*msg
;
2902 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2904 /* to avoid failing a new interface creation due to pending removal */
2905 cfg80211_destroy_ifaces(rdev
);
2907 memset(¶ms
, 0, sizeof(params
));
2909 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2912 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2913 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2914 if (type
> NL80211_IFTYPE_MAX
)
2918 if (!rdev
->ops
->add_virtual_intf
||
2919 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2922 if ((type
== NL80211_IFTYPE_P2P_DEVICE
|| type
== NL80211_IFTYPE_NAN
||
2923 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
2924 info
->attrs
[NL80211_ATTR_MAC
]) {
2925 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2927 if (!is_valid_ether_addr(params
.macaddr
))
2928 return -EADDRNOTAVAIL
;
2931 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2932 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2933 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2938 err
= nl80211_parse_mon_options(rdev
, type
, info
, ¶ms
);
2942 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2946 wdev
= rdev_add_virtual_intf(rdev
,
2947 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2948 NET_NAME_USER
, type
, ¶ms
);
2949 if (WARN_ON(!wdev
)) {
2952 } else if (IS_ERR(wdev
)) {
2954 return PTR_ERR(wdev
);
2957 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
2958 wdev
->owner_nlportid
= info
->snd_portid
;
2961 case NL80211_IFTYPE_MESH_POINT
:
2962 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2965 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2966 IEEE80211_MAX_MESH_ID_LEN
);
2967 wdev
->mesh_id_up_len
=
2968 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2969 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2970 wdev
->mesh_id_up_len
);
2973 case NL80211_IFTYPE_NAN
:
2974 case NL80211_IFTYPE_P2P_DEVICE
:
2976 * P2P Device and NAN do not have a netdev, so don't go
2977 * through the netdev notifier and must be added here
2979 mutex_init(&wdev
->mtx
);
2980 INIT_LIST_HEAD(&wdev
->event_list
);
2981 spin_lock_init(&wdev
->event_lock
);
2982 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2983 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2985 wdev
->identifier
= ++rdev
->wdev_id
;
2986 list_add_rcu(&wdev
->list
, &rdev
->wiphy
.wdev_list
);
2987 rdev
->devlist_generation
++;
2993 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2994 rdev
, wdev
, false) < 0) {
3000 * For wdevs which have no associated netdev object (e.g. of type
3001 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
3002 * For all other types, the event will be generated from the
3006 nl80211_notify_iface(rdev
, wdev
, NL80211_CMD_NEW_INTERFACE
);
3008 return genlmsg_reply(msg
, info
);
3011 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
3013 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3014 struct wireless_dev
*wdev
= info
->user_ptr
[1];
3016 if (!rdev
->ops
->del_virtual_intf
)
3020 * If we remove a wireless device without a netdev then clear
3021 * user_ptr[1] so that nl80211_post_doit won't dereference it
3022 * to check if it needs to do dev_put(). Otherwise it crashes
3023 * since the wdev has been freed, unlike with a netdev where
3024 * we need the dev_put() for the netdev to really be freed.
3027 info
->user_ptr
[1] = NULL
;
3029 return rdev_del_virtual_intf(rdev
, wdev
);
3032 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
3034 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3035 struct net_device
*dev
= info
->user_ptr
[1];
3038 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
3041 if (!rdev
->ops
->set_noack_map
)
3044 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
3046 return rdev_set_noack_map(rdev
, dev
, noack_map
);
3049 struct get_key_cookie
{
3050 struct sk_buff
*msg
;
3055 static void get_key_callback(void *c
, struct key_params
*params
)
3058 struct get_key_cookie
*cookie
= c
;
3061 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
3062 params
->key_len
, params
->key
)) ||
3064 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
3065 params
->seq_len
, params
->seq
)) ||
3067 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
3069 goto nla_put_failure
;
3071 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
3073 goto nla_put_failure
;
3076 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
3077 params
->key_len
, params
->key
)) ||
3079 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
3080 params
->seq_len
, params
->seq
)) ||
3082 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
3084 goto nla_put_failure
;
3086 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
3087 goto nla_put_failure
;
3089 nla_nest_end(cookie
->msg
, key
);
3096 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
3098 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3100 struct net_device
*dev
= info
->user_ptr
[1];
3102 const u8
*mac_addr
= NULL
;
3104 struct get_key_cookie cookie
= {
3108 struct sk_buff
*msg
;
3110 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
3111 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
3116 if (info
->attrs
[NL80211_ATTR_MAC
])
3117 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3119 pairwise
= !!mac_addr
;
3120 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
3121 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
3123 if (kt
>= NUM_NL80211_KEYTYPES
)
3125 if (kt
!= NL80211_KEYTYPE_GROUP
&&
3126 kt
!= NL80211_KEYTYPE_PAIRWISE
)
3128 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
3131 if (!rdev
->ops
->get_key
)
3134 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3137 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3141 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3142 NL80211_CMD_NEW_KEY
);
3144 goto nla_put_failure
;
3147 cookie
.idx
= key_idx
;
3149 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3150 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
3151 goto nla_put_failure
;
3153 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
3154 goto nla_put_failure
;
3156 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
3163 goto nla_put_failure
;
3165 genlmsg_end(msg
, hdr
);
3166 return genlmsg_reply(msg
, info
);
3175 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
3177 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3178 struct key_parse key
;
3180 struct net_device
*dev
= info
->user_ptr
[1];
3182 err
= nl80211_parse_key(info
, &key
);
3189 /* only support setting default key */
3190 if (!key
.def
&& !key
.defmgmt
)
3193 wdev_lock(dev
->ieee80211_ptr
);
3196 if (!rdev
->ops
->set_default_key
) {
3201 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3205 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
3206 key
.def_uni
, key
.def_multi
);
3211 #ifdef CONFIG_CFG80211_WEXT
3212 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
3215 if (key
.def_uni
|| !key
.def_multi
) {
3220 if (!rdev
->ops
->set_default_mgmt_key
) {
3225 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3229 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
3233 #ifdef CONFIG_CFG80211_WEXT
3234 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3239 wdev_unlock(dev
->ieee80211_ptr
);
3244 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3246 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3248 struct net_device
*dev
= info
->user_ptr
[1];
3249 struct key_parse key
;
3250 const u8
*mac_addr
= NULL
;
3252 err
= nl80211_parse_key(info
, &key
);
3259 if (info
->attrs
[NL80211_ATTR_MAC
])
3260 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3262 if (key
.type
== -1) {
3264 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3266 key
.type
= NL80211_KEYTYPE_GROUP
;
3270 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3271 key
.type
!= NL80211_KEYTYPE_GROUP
)
3274 if (!rdev
->ops
->add_key
)
3277 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3278 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3282 wdev_lock(dev
->ieee80211_ptr
);
3283 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3285 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3286 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3288 wdev_unlock(dev
->ieee80211_ptr
);
3293 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3295 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3297 struct net_device
*dev
= info
->user_ptr
[1];
3298 u8
*mac_addr
= NULL
;
3299 struct key_parse key
;
3301 err
= nl80211_parse_key(info
, &key
);
3305 if (info
->attrs
[NL80211_ATTR_MAC
])
3306 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3308 if (key
.type
== -1) {
3310 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3312 key
.type
= NL80211_KEYTYPE_GROUP
;
3316 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3317 key
.type
!= NL80211_KEYTYPE_GROUP
)
3320 if (!rdev
->ops
->del_key
)
3323 wdev_lock(dev
->ieee80211_ptr
);
3324 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3326 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3327 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3331 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3332 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3335 #ifdef CONFIG_CFG80211_WEXT
3337 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3338 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3339 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3340 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3343 wdev_unlock(dev
->ieee80211_ptr
);
3348 /* This function returns an error or the number of nested attributes */
3349 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3351 struct nlattr
*attr
;
3352 int n_entries
= 0, tmp
;
3354 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3355 if (nla_len(attr
) != ETH_ALEN
)
3365 * This function parses ACL information and allocates memory for ACL data.
3366 * On successful return, the calling function is responsible to free the
3367 * ACL buffer returned by this function.
3369 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3370 struct genl_info
*info
)
3372 enum nl80211_acl_policy acl_policy
;
3373 struct nlattr
*attr
;
3374 struct cfg80211_acl_data
*acl
;
3375 int i
= 0, n_entries
, tmp
;
3377 if (!wiphy
->max_acl_mac_addrs
)
3378 return ERR_PTR(-EOPNOTSUPP
);
3380 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3381 return ERR_PTR(-EINVAL
);
3383 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3384 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3385 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3386 return ERR_PTR(-EINVAL
);
3388 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3389 return ERR_PTR(-EINVAL
);
3391 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3393 return ERR_PTR(n_entries
);
3395 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3396 return ERR_PTR(-ENOTSUPP
);
3398 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3401 return ERR_PTR(-ENOMEM
);
3403 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3404 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3408 acl
->n_acl_entries
= n_entries
;
3409 acl
->acl_policy
= acl_policy
;
3414 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3416 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3417 struct net_device
*dev
= info
->user_ptr
[1];
3418 struct cfg80211_acl_data
*acl
;
3421 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3422 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3425 if (!dev
->ieee80211_ptr
->beacon_interval
)
3428 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3430 return PTR_ERR(acl
);
3432 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3439 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
3440 u8
*rates
, u8 rates_len
)
3445 for (i
= 0; i
< rates_len
; i
++) {
3446 int rate
= (rates
[i
] & 0x7f) * 5;
3449 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
3450 struct ieee80211_rate
*srate
=
3451 &sband
->bitrates
[ridx
];
3452 if (rate
== srate
->bitrate
) {
3457 if (ridx
== sband
->n_bitrates
)
3458 return 0; /* rate not found */
3464 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
3465 u8
*rates
, u8 rates_len
,
3466 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
3470 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
3472 for (i
= 0; i
< rates_len
; i
++) {
3475 ridx
= rates
[i
] / 8;
3476 rbit
= BIT(rates
[i
] % 8);
3478 /* check validity */
3479 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
3482 /* check availability */
3483 ridx
= array_index_nospec(ridx
, IEEE80211_HT_MCS_MASK_LEN
);
3484 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
3493 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
3497 switch (vht_mcs_map
) {
3498 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
3500 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
3503 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
3506 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
3516 static void vht_build_mcs_mask(u16 vht_mcs_map
,
3517 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
3521 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
3522 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
3527 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
3528 struct nl80211_txrate_vht
*txrate
,
3529 u16 mcs
[NL80211_VHT_NSS_MAX
])
3531 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3532 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
3535 if (!sband
->vht_cap
.vht_supported
)
3538 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
3540 /* Build vht_mcs_mask from VHT capabilities */
3541 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
3543 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3544 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
3545 mcs
[i
] = txrate
->mcs
[i
];
3553 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
3554 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
3555 .len
= NL80211_MAX_SUPP_RATES
},
3556 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
3557 .len
= NL80211_MAX_SUPP_HT_RATES
},
3558 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
3559 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
3562 static int nl80211_parse_tx_bitrate_mask(struct genl_info
*info
,
3563 struct cfg80211_bitrate_mask
*mask
)
3565 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
3566 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3568 struct nlattr
*tx_rates
;
3569 struct ieee80211_supported_band
*sband
;
3572 memset(mask
, 0, sizeof(*mask
));
3573 /* Default to all rates enabled */
3574 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
3575 sband
= rdev
->wiphy
.bands
[i
];
3580 mask
->control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
3581 memcpy(mask
->control
[i
].ht_mcs
,
3582 sband
->ht_cap
.mcs
.rx_mask
,
3583 sizeof(mask
->control
[i
].ht_mcs
));
3585 if (!sband
->vht_cap
.vht_supported
)
3588 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3589 vht_build_mcs_mask(vht_tx_mcs_map
, mask
->control
[i
].vht_mcs
);
3592 /* if no rates are given set it back to the defaults */
3593 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
3596 /* The nested attribute uses enum nl80211_band as the index. This maps
3597 * directly to the enum nl80211_band values used in cfg80211.
3599 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
3600 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
3601 enum nl80211_band band
= nla_type(tx_rates
);
3604 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
3606 sband
= rdev
->wiphy
.bands
[band
];
3609 err
= nla_parse_nested(tb
, NL80211_TXRATE_MAX
, tx_rates
,
3610 nl80211_txattr_policy
, info
->extack
);
3613 if (tb
[NL80211_TXRATE_LEGACY
]) {
3614 mask
->control
[band
].legacy
= rateset_to_mask(
3616 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
3617 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
3618 if ((mask
->control
[band
].legacy
== 0) &&
3619 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
3622 if (tb
[NL80211_TXRATE_HT
]) {
3623 if (!ht_rateset_to_mask(
3625 nla_data(tb
[NL80211_TXRATE_HT
]),
3626 nla_len(tb
[NL80211_TXRATE_HT
]),
3627 mask
->control
[band
].ht_mcs
))
3630 if (tb
[NL80211_TXRATE_VHT
]) {
3631 if (!vht_set_mcs_mask(
3633 nla_data(tb
[NL80211_TXRATE_VHT
]),
3634 mask
->control
[band
].vht_mcs
))
3637 if (tb
[NL80211_TXRATE_GI
]) {
3638 mask
->control
[band
].gi
=
3639 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
3640 if (mask
->control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
3644 if (mask
->control
[band
].legacy
== 0) {
3645 /* don't allow empty legacy rates if HT or VHT
3646 * are not even supported.
3648 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
3649 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
3652 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3653 if (mask
->control
[band
].ht_mcs
[i
])
3656 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3657 if (mask
->control
[band
].vht_mcs
[i
])
3660 /* legacy and mcs rates may not be both empty */
3669 static int validate_beacon_tx_rate(struct cfg80211_registered_device
*rdev
,
3670 enum nl80211_band band
,
3671 struct cfg80211_bitrate_mask
*beacon_rate
)
3673 u32 count_ht
, count_vht
, i
;
3674 u32 rate
= beacon_rate
->control
[band
].legacy
;
3676 /* Allow only one rate */
3677 if (hweight32(rate
) > 1)
3681 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
3682 if (hweight8(beacon_rate
->control
[band
].ht_mcs
[i
]) > 1) {
3684 } else if (beacon_rate
->control
[band
].ht_mcs
[i
]) {
3689 if (count_ht
&& rate
)
3694 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3695 if (hweight16(beacon_rate
->control
[band
].vht_mcs
[i
]) > 1) {
3697 } else if (beacon_rate
->control
[band
].vht_mcs
[i
]) {
3702 if (count_vht
&& rate
)
3706 if ((count_ht
&& count_vht
) || (!rate
&& !count_ht
&& !count_vht
))
3710 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3711 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
))
3714 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3715 NL80211_EXT_FEATURE_BEACON_RATE_HT
))
3718 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3719 NL80211_EXT_FEATURE_BEACON_RATE_VHT
))
3725 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3726 struct cfg80211_beacon_data
*bcn
)
3728 bool haveinfo
= false;
3730 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3731 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3732 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3733 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3736 memset(bcn
, 0, sizeof(*bcn
));
3738 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3739 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3740 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3746 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3747 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3748 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3755 if (attrs
[NL80211_ATTR_IE
]) {
3756 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3757 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3760 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3761 bcn
->proberesp_ies
=
3762 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3763 bcn
->proberesp_ies_len
=
3764 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3767 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3768 bcn
->assocresp_ies
=
3769 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3770 bcn
->assocresp_ies_len
=
3771 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3774 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3775 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3776 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3782 static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings
*params
,
3790 for (i
= 0; i
< rates
[1]; i
++) {
3791 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_HT_PHY
)
3792 params
->ht_required
= true;
3793 if (rates
[2 + i
] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY
)
3794 params
->vht_required
= true;
3799 * Since the nl80211 API didn't include, from the beginning, attributes about
3800 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
3801 * benefit of drivers that rebuild IEs in the firmware.
3803 static void nl80211_calculate_ap_params(struct cfg80211_ap_settings
*params
)
3805 const struct cfg80211_beacon_data
*bcn
= ¶ms
->beacon
;
3806 size_t ies_len
= bcn
->tail_len
;
3807 const u8
*ies
= bcn
->tail
;
3811 rates
= cfg80211_find_ie(WLAN_EID_SUPP_RATES
, ies
, ies_len
);
3812 nl80211_check_ap_rate_selectors(params
, rates
);
3814 rates
= cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES
, ies
, ies_len
);
3815 nl80211_check_ap_rate_selectors(params
, rates
);
3817 cap
= cfg80211_find_ie(WLAN_EID_HT_CAPABILITY
, ies
, ies_len
);
3818 if (cap
&& cap
[1] >= sizeof(*params
->ht_cap
))
3819 params
->ht_cap
= (void *)(cap
+ 2);
3820 cap
= cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY
, ies
, ies_len
);
3821 if (cap
&& cap
[1] >= sizeof(*params
->vht_cap
))
3822 params
->vht_cap
= (void *)(cap
+ 2);
3825 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3826 struct cfg80211_ap_settings
*params
)
3828 struct wireless_dev
*wdev
;
3831 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
3832 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3833 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3836 if (!wdev
->preset_chandef
.chan
)
3839 params
->chandef
= wdev
->preset_chandef
;
3847 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3848 enum nl80211_auth_type auth_type
,
3849 enum nl80211_commands cmd
)
3851 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3855 case NL80211_CMD_AUTHENTICATE
:
3856 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3857 auth_type
== NL80211_AUTHTYPE_SAE
)
3859 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
3860 NL80211_EXT_FEATURE_FILS_STA
) &&
3861 (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
3862 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
3863 auth_type
== NL80211_AUTHTYPE_FILS_PK
))
3866 case NL80211_CMD_CONNECT
:
3867 /* SAE not supported yet */
3868 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3870 /* FILS with SK PFS or PK not supported yet */
3871 if (auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
3872 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
3874 if (!wiphy_ext_feature_isset(
3876 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
3877 auth_type
== NL80211_AUTHTYPE_FILS_SK
)
3880 case NL80211_CMD_START_AP
:
3881 /* SAE not supported yet */
3882 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3884 /* FILS not supported yet */
3885 if (auth_type
== NL80211_AUTHTYPE_FILS_SK
||
3886 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
3887 auth_type
== NL80211_AUTHTYPE_FILS_PK
)
3895 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3897 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3898 struct net_device
*dev
= info
->user_ptr
[1];
3899 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3900 struct cfg80211_ap_settings params
;
3903 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3904 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3907 if (!rdev
->ops
->start_ap
)
3910 if (wdev
->beacon_interval
)
3913 memset(¶ms
, 0, sizeof(params
));
3915 /* these are required for START_AP */
3916 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3917 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3918 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3921 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3925 params
.beacon_interval
=
3926 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3927 params
.dtim_period
=
3928 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3930 err
= cfg80211_validate_beacon_int(rdev
, dev
->ieee80211_ptr
->iftype
,
3931 params
.beacon_interval
);
3936 * In theory, some of these attributes should be required here
3937 * but since they were not used when the command was originally
3938 * added, keep them optional for old user space programs to let
3939 * them continue to work with drivers that do not need the
3940 * additional information -- drivers must check!
3942 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3943 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3945 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3946 if (params
.ssid_len
== 0 ||
3947 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3951 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3952 params
.hidden_ssid
= nla_get_u32(
3953 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3954 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3955 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3956 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3960 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3962 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3963 params
.auth_type
= nla_get_u32(
3964 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3965 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3966 NL80211_CMD_START_AP
))
3969 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3971 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3972 NL80211_MAX_NR_CIPHER_SUITES
);
3976 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3977 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3979 params
.inactivity_timeout
= nla_get_u16(
3980 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3983 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3984 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3986 params
.p2p_ctwindow
=
3987 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3988 if (params
.p2p_ctwindow
> 127)
3990 if (params
.p2p_ctwindow
!= 0 &&
3991 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3995 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3998 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4000 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4003 params
.p2p_opp_ps
= tmp
;
4004 if (params
.p2p_opp_ps
!= 0 &&
4005 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4009 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4010 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
4013 } else if (wdev
->preset_chandef
.chan
) {
4014 params
.chandef
= wdev
->preset_chandef
;
4015 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
4018 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
4022 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
4023 err
= nl80211_parse_tx_bitrate_mask(info
, ¶ms
.beacon_rate
);
4027 err
= validate_beacon_tx_rate(rdev
, params
.chandef
.chan
->band
,
4028 ¶ms
.beacon_rate
);
4033 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
4035 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
4036 switch (params
.smps_mode
) {
4037 case NL80211_SMPS_OFF
:
4039 case NL80211_SMPS_STATIC
:
4040 if (!(rdev
->wiphy
.features
&
4041 NL80211_FEATURE_STATIC_SMPS
))
4044 case NL80211_SMPS_DYNAMIC
:
4045 if (!(rdev
->wiphy
.features
&
4046 NL80211_FEATURE_DYNAMIC_SMPS
))
4053 params
.smps_mode
= NL80211_SMPS_OFF
;
4056 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
4057 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
4060 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
4061 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
4062 if (IS_ERR(params
.acl
))
4063 return PTR_ERR(params
.acl
);
4066 nl80211_calculate_ap_params(¶ms
);
4069 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
4071 wdev
->preset_chandef
= params
.chandef
;
4072 wdev
->beacon_interval
= params
.beacon_interval
;
4073 wdev
->chandef
= params
.chandef
;
4074 wdev
->ssid_len
= params
.ssid_len
;
4075 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
4084 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
4086 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4087 struct net_device
*dev
= info
->user_ptr
[1];
4088 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4089 struct cfg80211_beacon_data params
;
4092 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4093 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4096 if (!rdev
->ops
->change_beacon
)
4099 if (!wdev
->beacon_interval
)
4102 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
4107 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
4113 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
4115 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4116 struct net_device
*dev
= info
->user_ptr
[1];
4118 return cfg80211_stop_ap(rdev
, dev
, false);
4121 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
4122 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
4123 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
4124 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
4125 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
4126 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
4127 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
4130 static int parse_station_flags(struct genl_info
*info
,
4131 enum nl80211_iftype iftype
,
4132 struct station_parameters
*params
)
4134 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
4139 * Try parsing the new attribute first so userspace
4140 * can specify both for older kernels.
4142 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
4144 struct nl80211_sta_flag_update
*sta_flags
;
4146 sta_flags
= nla_data(nla
);
4147 params
->sta_flags_mask
= sta_flags
->mask
;
4148 params
->sta_flags_set
= sta_flags
->set
;
4149 params
->sta_flags_set
&= params
->sta_flags_mask
;
4150 if ((params
->sta_flags_mask
|
4151 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
4156 /* if present, parse the old attribute */
4158 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
4162 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
, nla
,
4163 sta_flags_policy
, info
->extack
))
4167 * Only allow certain flags for interface types so that
4168 * other attributes are silently ignored. Remember that
4169 * this is backward compatibility code with old userspace
4170 * and shouldn't be hit in other cases anyway.
4173 case NL80211_IFTYPE_AP
:
4174 case NL80211_IFTYPE_AP_VLAN
:
4175 case NL80211_IFTYPE_P2P_GO
:
4176 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4177 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4178 BIT(NL80211_STA_FLAG_WME
) |
4179 BIT(NL80211_STA_FLAG_MFP
);
4181 case NL80211_IFTYPE_P2P_CLIENT
:
4182 case NL80211_IFTYPE_STATION
:
4183 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4184 BIT(NL80211_STA_FLAG_TDLS_PEER
);
4186 case NL80211_IFTYPE_MESH_POINT
:
4187 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4188 BIT(NL80211_STA_FLAG_MFP
) |
4189 BIT(NL80211_STA_FLAG_AUTHORIZED
);
4195 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
4197 params
->sta_flags_set
|= (1<<flag
);
4199 /* no longer support new API additions in old API */
4200 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
4208 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
4211 struct nlattr
*rate
;
4214 enum nl80211_rate_info rate_flg
;
4216 rate
= nla_nest_start(msg
, attr
);
4220 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4221 bitrate
= cfg80211_calculate_bitrate(info
);
4222 /* report 16-bit bitrate only if we can */
4223 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
4225 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
4227 if (bitrate_compat
> 0 &&
4228 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
4232 case RATE_INFO_BW_5
:
4233 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
4235 case RATE_INFO_BW_10
:
4236 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
4241 case RATE_INFO_BW_20
:
4244 case RATE_INFO_BW_40
:
4245 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
4247 case RATE_INFO_BW_80
:
4248 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
4250 case RATE_INFO_BW_160
:
4251 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
4255 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
4258 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
4259 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
4261 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4262 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4264 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
4265 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
4267 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
4269 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4270 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4274 nla_nest_end(msg
, rate
);
4278 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
4287 attr
= nla_nest_start(msg
, id
);
4291 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
4292 if (!(mask
& BIT(i
)))
4295 if (nla_put_u8(msg
, i
, signal
[i
]))
4299 nla_nest_end(msg
, attr
);
4304 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
4306 struct cfg80211_registered_device
*rdev
,
4307 struct net_device
*dev
,
4308 const u8
*mac_addr
, struct station_info
*sinfo
)
4311 struct nlattr
*sinfoattr
, *bss_param
;
4313 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
4317 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4318 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
4319 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
4320 goto nla_put_failure
;
4322 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
4324 goto nla_put_failure
;
4326 #define PUT_SINFO(attr, memb, type) do { \
4327 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
4328 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4329 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4331 goto nla_put_failure; \
4333 #define PUT_SINFO_U64(attr, memb) do { \
4334 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4335 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4336 sinfo->memb, NL80211_STA_INFO_PAD)) \
4337 goto nla_put_failure; \
4340 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
4341 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
4343 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
4344 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
4345 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
4346 (u32
)sinfo
->rx_bytes
))
4347 goto nla_put_failure
;
4349 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
4350 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
4351 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
4352 (u32
)sinfo
->tx_bytes
))
4353 goto nla_put_failure
;
4355 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
4356 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
4357 PUT_SINFO(LLID
, llid
, u16
);
4358 PUT_SINFO(PLID
, plid
, u16
);
4359 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
4360 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
4362 switch (rdev
->wiphy
.signal_type
) {
4363 case CFG80211_SIGNAL_TYPE_MBM
:
4364 PUT_SINFO(SIGNAL
, signal
, u8
);
4365 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
4370 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
4371 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4372 sinfo
->chain_signal
,
4373 NL80211_STA_INFO_CHAIN_SIGNAL
))
4374 goto nla_put_failure
;
4376 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
4377 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4378 sinfo
->chain_signal_avg
,
4379 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
4380 goto nla_put_failure
;
4382 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
4383 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
4384 NL80211_STA_INFO_TX_BITRATE
))
4385 goto nla_put_failure
;
4387 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
4388 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
4389 NL80211_STA_INFO_RX_BITRATE
))
4390 goto nla_put_failure
;
4393 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
4394 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
4395 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
4396 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
4397 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
4398 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
4399 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
4400 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
4401 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
4403 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
4404 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
4406 goto nla_put_failure
;
4408 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
4409 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
4410 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
4411 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
4412 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
4413 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
4414 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
4415 sinfo
->bss_param
.dtim_period
) ||
4416 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
4417 sinfo
->bss_param
.beacon_interval
))
4418 goto nla_put_failure
;
4420 nla_nest_end(msg
, bss_param
);
4422 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
4423 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
4424 sizeof(struct nl80211_sta_flag_update
),
4426 goto nla_put_failure
;
4428 PUT_SINFO_U64(T_OFFSET
, t_offset
);
4429 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
4430 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
4431 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
4434 #undef PUT_SINFO_U64
4436 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TID_STATS
)) {
4437 struct nlattr
*tidsattr
;
4440 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
4442 goto nla_put_failure
;
4444 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
4445 struct cfg80211_tid_stats
*tidstats
;
4446 struct nlattr
*tidattr
;
4448 tidstats
= &sinfo
->pertid
[tid
];
4450 if (!tidstats
->filled
)
4453 tidattr
= nla_nest_start(msg
, tid
+ 1);
4455 goto nla_put_failure
;
4457 #define PUT_TIDVAL_U64(attr, memb) do { \
4458 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
4459 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4460 tidstats->memb, NL80211_TID_STATS_PAD)) \
4461 goto nla_put_failure; \
4464 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
4465 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
4466 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
4467 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
4469 #undef PUT_TIDVAL_U64
4470 nla_nest_end(msg
, tidattr
);
4473 nla_nest_end(msg
, tidsattr
);
4476 nla_nest_end(msg
, sinfoattr
);
4478 if (sinfo
->assoc_req_ies_len
&&
4479 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
4480 sinfo
->assoc_req_ies
))
4481 goto nla_put_failure
;
4483 genlmsg_end(msg
, hdr
);
4487 genlmsg_cancel(msg
, hdr
);
4491 static int nl80211_dump_station(struct sk_buff
*skb
,
4492 struct netlink_callback
*cb
)
4494 struct station_info sinfo
;
4495 struct cfg80211_registered_device
*rdev
;
4496 struct wireless_dev
*wdev
;
4497 u8 mac_addr
[ETH_ALEN
];
4498 int sta_idx
= cb
->args
[2];
4502 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4506 if (!wdev
->netdev
) {
4511 if (!rdev
->ops
->dump_station
) {
4517 memset(&sinfo
, 0, sizeof(sinfo
));
4518 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
4525 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
4526 NETLINK_CB(cb
->skb
).portid
,
4527 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4528 rdev
, wdev
->netdev
, mac_addr
,
4536 cb
->args
[2] = sta_idx
;
4544 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
4546 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4547 struct net_device
*dev
= info
->user_ptr
[1];
4548 struct station_info sinfo
;
4549 struct sk_buff
*msg
;
4550 u8
*mac_addr
= NULL
;
4553 memset(&sinfo
, 0, sizeof(sinfo
));
4555 if (!info
->attrs
[NL80211_ATTR_MAC
])
4558 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4560 if (!rdev
->ops
->get_station
)
4563 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
4567 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4571 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
4572 info
->snd_portid
, info
->snd_seq
, 0,
4573 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
4578 return genlmsg_reply(msg
, info
);
4581 int cfg80211_check_station_change(struct wiphy
*wiphy
,
4582 struct station_parameters
*params
,
4583 enum cfg80211_station_type statype
)
4585 if (params
->listen_interval
!= -1 &&
4586 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4589 if (params
->support_p2p_ps
!= -1 &&
4590 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4594 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
4595 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4598 /* When you run into this, adjust the code below for the new flag */
4599 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4602 case CFG80211_STA_MESH_PEER_KERNEL
:
4603 case CFG80211_STA_MESH_PEER_USER
:
4605 * No ignoring the TDLS flag here -- the userspace mesh
4606 * code doesn't have the bug of including TDLS in the
4609 if (params
->sta_flags_mask
&
4610 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4611 BIT(NL80211_STA_FLAG_MFP
) |
4612 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4615 case CFG80211_STA_TDLS_PEER_SETUP
:
4616 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4617 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4619 /* ignore since it can't change */
4620 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4623 /* disallow mesh-specific things */
4624 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4626 if (params
->local_pm
)
4628 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4632 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4633 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4634 /* TDLS can't be set, ... */
4635 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4638 * ... but don't bother the driver with it. This works around
4639 * a hostapd/wpa_supplicant issue -- it always includes the
4640 * TLDS_PEER flag in the mask even for AP mode.
4642 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4645 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4646 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4647 /* reject other things that can't change */
4648 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4650 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4652 if (params
->supported_rates
)
4654 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4658 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4659 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4665 case CFG80211_STA_AP_MLME_CLIENT
:
4666 /* Use this only for authorizing/unauthorizing a station */
4667 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4670 case CFG80211_STA_AP_CLIENT
:
4671 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4672 /* accept only the listed bits */
4673 if (params
->sta_flags_mask
&
4674 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4675 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4676 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4677 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4678 BIT(NL80211_STA_FLAG_WME
) |
4679 BIT(NL80211_STA_FLAG_MFP
)))
4682 /* but authenticated/associated only if driver handles it */
4683 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4684 params
->sta_flags_mask
&
4685 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4686 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4689 case CFG80211_STA_IBSS
:
4690 case CFG80211_STA_AP_STA
:
4691 /* reject any changes other than AUTHORIZED */
4692 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4695 case CFG80211_STA_TDLS_PEER_SETUP
:
4696 /* reject any changes other than AUTHORIZED or WME */
4697 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4698 BIT(NL80211_STA_FLAG_WME
)))
4700 /* force (at least) rates when authorizing */
4701 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4702 !params
->supported_rates
)
4705 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4706 /* reject any changes */
4708 case CFG80211_STA_MESH_PEER_KERNEL
:
4709 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4712 case CFG80211_STA_MESH_PEER_USER
:
4713 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4714 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4720 * Older kernel versions ignored this attribute entirely, so don't
4721 * reject attempts to update it but mark it as unused instead so the
4722 * driver won't look at the data.
4724 if (statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
&&
4725 statype
!= CFG80211_STA_TDLS_PEER_SETUP
)
4726 params
->opmode_notif_used
= false;
4730 EXPORT_SYMBOL(cfg80211_check_station_change
);
4733 * Get vlan interface making sure it is running and on the right wiphy.
4735 static struct net_device
*get_vlan(struct genl_info
*info
,
4736 struct cfg80211_registered_device
*rdev
)
4738 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4739 struct net_device
*v
;
4745 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4747 return ERR_PTR(-ENODEV
);
4749 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4754 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4755 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4756 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4761 if (!netif_running(v
)) {
4769 return ERR_PTR(ret
);
4772 static const struct nla_policy
4773 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
4774 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
4775 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
4778 static int nl80211_parse_sta_wme(struct genl_info
*info
,
4779 struct station_parameters
*params
)
4781 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
4785 /* parse WME attributes if present */
4786 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
4789 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
4790 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
4791 nl80211_sta_wme_policy
, info
->extack
);
4795 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4796 params
->uapsd_queues
= nla_get_u8(
4797 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4798 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4801 if (tb
[NL80211_STA_WME_MAX_SP
])
4802 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4804 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4807 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4812 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4813 struct station_parameters
*params
)
4815 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4816 params
->supported_channels
=
4817 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4818 params
->supported_channels_len
=
4819 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4821 * Need to include at least one (first channel, number of
4822 * channels) tuple for each subband, and must have proper
4823 * tuples for the rest of the data as well.
4825 if (params
->supported_channels_len
< 2)
4827 if (params
->supported_channels_len
% 2)
4831 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4832 params
->supported_oper_classes
=
4833 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4834 params
->supported_oper_classes_len
=
4835 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4837 * The value of the Length field of the Supported Operating
4838 * Classes element is between 2 and 253.
4840 if (params
->supported_oper_classes_len
< 2 ||
4841 params
->supported_oper_classes_len
> 253)
4847 static int nl80211_set_station_tdls(struct genl_info
*info
,
4848 struct station_parameters
*params
)
4851 /* Dummy STA entry gets updated once the peer capabilities are known */
4852 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4853 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4854 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4856 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4857 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4859 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4861 err
= nl80211_parse_sta_channel_info(info
, params
);
4865 return nl80211_parse_sta_wme(info
, params
);
4868 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4870 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4871 struct net_device
*dev
= info
->user_ptr
[1];
4872 struct station_parameters params
;
4876 memset(¶ms
, 0, sizeof(params
));
4878 if (!rdev
->ops
->change_station
)
4882 * AID and listen_interval properties can be set only for unassociated
4883 * station. Include these parameters here and will check them in
4884 * cfg80211_check_station_change().
4886 if (info
->attrs
[NL80211_ATTR_STA_AID
])
4887 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4889 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4890 params
.listen_interval
=
4891 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4893 params
.listen_interval
= -1;
4895 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
4898 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
4899 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
4902 params
.support_p2p_ps
= tmp
;
4904 params
.support_p2p_ps
= -1;
4907 if (!info
->attrs
[NL80211_ATTR_MAC
])
4910 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4912 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4913 params
.supported_rates
=
4914 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4915 params
.supported_rates_len
=
4916 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4919 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4921 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4922 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4925 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4927 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4928 params
.ext_capab_len
=
4929 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4932 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4935 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4936 params
.plink_action
=
4937 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4938 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4942 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4943 params
.plink_state
=
4944 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4945 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4947 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]) {
4948 params
.peer_aid
= nla_get_u16(
4949 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
4950 if (params
.peer_aid
> IEEE80211_MAX_AID
)
4953 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4956 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4957 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4958 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4960 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4961 pm
> NL80211_MESH_POWER_MAX
)
4964 params
.local_pm
= pm
;
4967 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4968 params
.opmode_notif_used
= true;
4969 params
.opmode_notif
=
4970 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4973 /* Include parameters for TDLS peer (will check later) */
4974 err
= nl80211_set_station_tdls(info
, ¶ms
);
4978 params
.vlan
= get_vlan(info
, rdev
);
4979 if (IS_ERR(params
.vlan
))
4980 return PTR_ERR(params
.vlan
);
4982 switch (dev
->ieee80211_ptr
->iftype
) {
4983 case NL80211_IFTYPE_AP
:
4984 case NL80211_IFTYPE_AP_VLAN
:
4985 case NL80211_IFTYPE_P2P_GO
:
4986 case NL80211_IFTYPE_P2P_CLIENT
:
4987 case NL80211_IFTYPE_STATION
:
4988 case NL80211_IFTYPE_ADHOC
:
4989 case NL80211_IFTYPE_MESH_POINT
:
4996 /* driver will call cfg80211_check_station_change() */
4997 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
5001 dev_put(params
.vlan
);
5006 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
5008 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5010 struct net_device
*dev
= info
->user_ptr
[1];
5011 struct station_parameters params
;
5012 u8
*mac_addr
= NULL
;
5013 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
5014 BIT(NL80211_STA_FLAG_ASSOCIATED
);
5016 memset(¶ms
, 0, sizeof(params
));
5018 if (!rdev
->ops
->add_station
)
5021 if (!info
->attrs
[NL80211_ATTR_MAC
])
5024 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
5027 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
5030 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
5031 !info
->attrs
[NL80211_ATTR_PEER_AID
])
5034 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5035 params
.supported_rates
=
5036 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5037 params
.supported_rates_len
=
5038 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
5039 params
.listen_interval
=
5040 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
5042 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
5045 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
5046 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
5049 params
.support_p2p_ps
= tmp
;
5052 * if not specified, assume it's supported for P2P GO interface,
5053 * and is NOT supported for AP interface
5055 params
.support_p2p_ps
=
5056 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
5059 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
5060 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
5062 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
5063 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
5066 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
5068 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
5069 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
5072 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
5074 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5075 params
.ext_capab_len
=
5076 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
5079 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
5081 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5083 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
5085 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
5087 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
5088 params
.opmode_notif_used
= true;
5089 params
.opmode_notif
=
5090 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
5093 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
5094 params
.plink_action
=
5095 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
5096 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
5100 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
5104 err
= nl80211_parse_sta_wme(info
, ¶ms
);
5108 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
5111 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
5112 * as userspace might just pass through the capabilities from the IEs
5113 * directly, rather than enforcing this restriction and returning an
5114 * error in this case.
5116 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
5117 params
.ht_capa
= NULL
;
5118 params
.vht_capa
= NULL
;
5121 /* When you run into this, adjust the code below for the new flag */
5122 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
5124 switch (dev
->ieee80211_ptr
->iftype
) {
5125 case NL80211_IFTYPE_AP
:
5126 case NL80211_IFTYPE_AP_VLAN
:
5127 case NL80211_IFTYPE_P2P_GO
:
5128 /* ignore WME attributes if iface/sta is not capable */
5129 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
5130 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
5131 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5133 /* TDLS peers cannot be added */
5134 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5135 info
->attrs
[NL80211_ATTR_PEER_AID
])
5137 /* but don't bother the driver with it */
5138 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
5140 /* allow authenticated/associated only if driver handles it */
5141 if (!(rdev
->wiphy
.features
&
5142 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
5143 params
.sta_flags_mask
& auth_assoc
)
5146 /* Older userspace, or userspace wanting to be compatible with
5147 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5148 * and assoc flags in the mask, but assumes the station will be
5149 * added as associated anyway since this was the required driver
5150 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5152 * In order to not bother drivers with this quirk in the API
5153 * set the flags in both the mask and set for new stations in
5156 if (!(params
.sta_flags_mask
& auth_assoc
)) {
5157 params
.sta_flags_mask
|= auth_assoc
;
5158 params
.sta_flags_set
|= auth_assoc
;
5161 /* must be last in here for error handling */
5162 params
.vlan
= get_vlan(info
, rdev
);
5163 if (IS_ERR(params
.vlan
))
5164 return PTR_ERR(params
.vlan
);
5166 case NL80211_IFTYPE_MESH_POINT
:
5167 /* ignore uAPSD data */
5168 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5170 /* associated is disallowed */
5171 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
5173 /* TDLS peers cannot be added */
5174 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5175 info
->attrs
[NL80211_ATTR_PEER_AID
])
5178 case NL80211_IFTYPE_STATION
:
5179 case NL80211_IFTYPE_P2P_CLIENT
:
5180 /* ignore uAPSD data */
5181 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5183 /* these are disallowed */
5184 if (params
.sta_flags_mask
&
5185 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
5186 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
5188 /* Only TDLS peers can be added */
5189 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
5191 /* Can only add if TDLS ... */
5192 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
5194 /* ... with external setup is supported */
5195 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
5198 * Older wpa_supplicant versions always mark the TDLS peer
5199 * as authorized, but it shouldn't yet be.
5201 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
5207 /* be aware of params.vlan when changing code here */
5209 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
5212 dev_put(params
.vlan
);
5216 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
5218 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5219 struct net_device
*dev
= info
->user_ptr
[1];
5220 struct station_del_parameters params
;
5222 memset(¶ms
, 0, sizeof(params
));
5224 if (info
->attrs
[NL80211_ATTR_MAC
])
5225 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5227 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5228 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5229 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5230 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5233 if (!rdev
->ops
->del_station
)
5236 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
5238 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
5239 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
5240 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
5243 /* Default to Deauthentication frame */
5244 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
5247 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
5248 params
.reason_code
=
5249 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5250 if (params
.reason_code
== 0)
5251 return -EINVAL
; /* 0 is reserved */
5253 /* Default to reason code 2 */
5254 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
5257 return rdev_del_station(rdev
, dev
, ¶ms
);
5260 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5261 int flags
, struct net_device
*dev
,
5262 u8
*dst
, u8
*next_hop
,
5263 struct mpath_info
*pinfo
)
5266 struct nlattr
*pinfoattr
;
5268 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
5272 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5273 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
5274 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
5275 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
5276 goto nla_put_failure
;
5278 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
5280 goto nla_put_failure
;
5281 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
5282 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
5284 goto nla_put_failure
;
5285 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
5286 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
5287 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
5288 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
5290 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
5291 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
5293 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
5294 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
5296 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
5297 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
5298 pinfo
->discovery_timeout
)) ||
5299 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
5300 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
5301 pinfo
->discovery_retries
)))
5302 goto nla_put_failure
;
5304 nla_nest_end(msg
, pinfoattr
);
5306 genlmsg_end(msg
, hdr
);
5310 genlmsg_cancel(msg
, hdr
);
5314 static int nl80211_dump_mpath(struct sk_buff
*skb
,
5315 struct netlink_callback
*cb
)
5317 struct mpath_info pinfo
;
5318 struct cfg80211_registered_device
*rdev
;
5319 struct wireless_dev
*wdev
;
5321 u8 next_hop
[ETH_ALEN
];
5322 int path_idx
= cb
->args
[2];
5326 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5330 if (!rdev
->ops
->dump_mpath
) {
5335 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5341 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
5348 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5349 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5350 wdev
->netdev
, dst
, next_hop
,
5358 cb
->args
[2] = path_idx
;
5365 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5367 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5369 struct net_device
*dev
= info
->user_ptr
[1];
5370 struct mpath_info pinfo
;
5371 struct sk_buff
*msg
;
5373 u8 next_hop
[ETH_ALEN
];
5375 memset(&pinfo
, 0, sizeof(pinfo
));
5377 if (!info
->attrs
[NL80211_ATTR_MAC
])
5380 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5382 if (!rdev
->ops
->get_mpath
)
5385 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5388 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
5392 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5396 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5397 dev
, dst
, next_hop
, &pinfo
) < 0) {
5402 return genlmsg_reply(msg
, info
);
5405 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5407 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5408 struct net_device
*dev
= info
->user_ptr
[1];
5410 u8
*next_hop
= NULL
;
5412 if (!info
->attrs
[NL80211_ATTR_MAC
])
5415 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5418 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5419 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5421 if (!rdev
->ops
->change_mpath
)
5424 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5427 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
5430 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5432 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5433 struct net_device
*dev
= info
->user_ptr
[1];
5435 u8
*next_hop
= NULL
;
5437 if (!info
->attrs
[NL80211_ATTR_MAC
])
5440 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5443 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5444 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5446 if (!rdev
->ops
->add_mpath
)
5449 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5452 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
5455 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5457 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5458 struct net_device
*dev
= info
->user_ptr
[1];
5461 if (info
->attrs
[NL80211_ATTR_MAC
])
5462 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5464 if (!rdev
->ops
->del_mpath
)
5467 return rdev_del_mpath(rdev
, dev
, dst
);
5470 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
5472 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5474 struct net_device
*dev
= info
->user_ptr
[1];
5475 struct mpath_info pinfo
;
5476 struct sk_buff
*msg
;
5480 memset(&pinfo
, 0, sizeof(pinfo
));
5482 if (!info
->attrs
[NL80211_ATTR_MAC
])
5485 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5487 if (!rdev
->ops
->get_mpp
)
5490 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5493 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
5497 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5501 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5502 dev
, dst
, mpp
, &pinfo
) < 0) {
5507 return genlmsg_reply(msg
, info
);
5510 static int nl80211_dump_mpp(struct sk_buff
*skb
,
5511 struct netlink_callback
*cb
)
5513 struct mpath_info pinfo
;
5514 struct cfg80211_registered_device
*rdev
;
5515 struct wireless_dev
*wdev
;
5518 int path_idx
= cb
->args
[2];
5522 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5526 if (!rdev
->ops
->dump_mpp
) {
5531 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5537 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
5544 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5545 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5546 wdev
->netdev
, dst
, mpp
,
5554 cb
->args
[2] = path_idx
;
5561 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
5563 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5564 struct net_device
*dev
= info
->user_ptr
[1];
5565 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5566 struct bss_parameters params
;
5569 memset(¶ms
, 0, sizeof(params
));
5570 /* default to not changing parameters */
5571 params
.use_cts_prot
= -1;
5572 params
.use_short_preamble
= -1;
5573 params
.use_short_slot_time
= -1;
5574 params
.ap_isolate
= -1;
5575 params
.ht_opmode
= -1;
5576 params
.p2p_ctwindow
= -1;
5577 params
.p2p_opp_ps
= -1;
5579 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
5580 params
.use_cts_prot
=
5581 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
5582 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
5583 params
.use_short_preamble
=
5584 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
5585 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
5586 params
.use_short_slot_time
=
5587 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
5588 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5589 params
.basic_rates
=
5590 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5591 params
.basic_rates_len
=
5592 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5594 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
5595 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
5596 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
5598 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
5600 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
5601 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5603 params
.p2p_ctwindow
=
5604 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
5605 if (params
.p2p_ctwindow
< 0)
5607 if (params
.p2p_ctwindow
!= 0 &&
5608 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
5612 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
5615 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5617 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
5620 params
.p2p_opp_ps
= tmp
;
5621 if (params
.p2p_opp_ps
&&
5622 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
5626 if (!rdev
->ops
->change_bss
)
5629 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5630 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5634 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
5640 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5644 enum nl80211_user_reg_hint_type user_reg_hint_type
;
5648 * You should only get this when cfg80211 hasn't yet initialized
5649 * completely when built-in to the kernel right between the time
5650 * window between nl80211_init() and regulatory_init(), if that is
5653 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
5654 return -EINPROGRESS
;
5656 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
5657 user_reg_hint_type
=
5658 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
5660 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
5662 switch (user_reg_hint_type
) {
5663 case NL80211_USER_REG_HINT_USER
:
5664 case NL80211_USER_REG_HINT_CELL_BASE
:
5665 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5668 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5669 return regulatory_hint_user(data
, user_reg_hint_type
);
5670 case NL80211_USER_REG_HINT_INDOOR
:
5671 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
5672 owner_nlportid
= info
->snd_portid
;
5673 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
5679 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
5685 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
5686 struct genl_info
*info
)
5688 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5689 struct net_device
*dev
= info
->user_ptr
[1];
5690 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5691 struct mesh_config cur_params
;
5694 struct nlattr
*pinfoattr
;
5695 struct sk_buff
*msg
;
5697 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5700 if (!rdev
->ops
->get_mesh_config
)
5704 /* If not connected, get default parameters */
5705 if (!wdev
->mesh_id_len
)
5706 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5708 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5714 /* Draw up a netlink message to send back */
5715 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5718 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5719 NL80211_CMD_GET_MESH_CONFIG
);
5722 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5724 goto nla_put_failure
;
5725 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5726 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5727 cur_params
.dot11MeshRetryTimeout
) ||
5728 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5729 cur_params
.dot11MeshConfirmTimeout
) ||
5730 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5731 cur_params
.dot11MeshHoldingTimeout
) ||
5732 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5733 cur_params
.dot11MeshMaxPeerLinks
) ||
5734 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5735 cur_params
.dot11MeshMaxRetries
) ||
5736 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5737 cur_params
.dot11MeshTTL
) ||
5738 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5739 cur_params
.element_ttl
) ||
5740 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5741 cur_params
.auto_open_plinks
) ||
5742 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5743 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5744 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5745 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5746 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5747 cur_params
.path_refresh_time
) ||
5748 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5749 cur_params
.min_discovery_timeout
) ||
5750 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5751 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5752 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5753 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5754 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5755 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5756 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5757 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5758 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5759 cur_params
.dot11MeshHWMPRootMode
) ||
5760 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5761 cur_params
.dot11MeshHWMPRannInterval
) ||
5762 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5763 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
5764 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
5765 cur_params
.dot11MeshForwarding
) ||
5766 nla_put_s32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5767 cur_params
.rssi_threshold
) ||
5768 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
5769 cur_params
.ht_opmode
) ||
5770 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5771 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
5772 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5773 cur_params
.dot11MeshHWMProotInterval
) ||
5774 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5775 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
5776 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
5777 cur_params
.power_mode
) ||
5778 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
5779 cur_params
.dot11MeshAwakeWindowDuration
) ||
5780 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5781 cur_params
.plink_timeout
))
5782 goto nla_put_failure
;
5783 nla_nest_end(msg
, pinfoattr
);
5784 genlmsg_end(msg
, hdr
);
5785 return genlmsg_reply(msg
, info
);
5788 genlmsg_cancel(msg
, hdr
);
5794 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
5795 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
5796 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
5797 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
5798 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
5799 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
5800 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
5801 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
5802 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
5803 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
5804 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
5805 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
5806 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
5807 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
5808 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
5809 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
5810 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
5811 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
5812 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
5813 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
5814 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
5815 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
5816 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
5817 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
5818 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
5819 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
5820 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
5821 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
5822 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
5825 static const struct nla_policy
5826 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
5827 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
5828 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
5829 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
5830 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
5831 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
5832 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
5833 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
5834 .len
= IEEE80211_MAX_DATA_LEN
},
5835 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
5838 static int nl80211_check_bool(const struct nlattr
*nla
, u8 min
, u8 max
, bool *out
)
5840 u8 val
= nla_get_u8(nla
);
5841 if (val
< min
|| val
> max
)
5847 static int nl80211_check_u8(const struct nlattr
*nla
, u8 min
, u8 max
, u8
*out
)
5849 u8 val
= nla_get_u8(nla
);
5850 if (val
< min
|| val
> max
)
5856 static int nl80211_check_u16(const struct nlattr
*nla
, u16 min
, u16 max
, u16
*out
)
5858 u16 val
= nla_get_u16(nla
);
5859 if (val
< min
|| val
> max
)
5865 static int nl80211_check_u32(const struct nlattr
*nla
, u32 min
, u32 max
, u32
*out
)
5867 u32 val
= nla_get_u32(nla
);
5868 if (val
< min
|| val
> max
)
5874 static int nl80211_check_s32(const struct nlattr
*nla
, s32 min
, s32 max
, s32
*out
)
5876 s32 val
= nla_get_s32(nla
);
5877 if (val
< min
|| val
> max
)
5883 static int nl80211_check_power_mode(const struct nlattr
*nla
,
5884 enum nl80211_mesh_power_mode min
,
5885 enum nl80211_mesh_power_mode max
,
5886 enum nl80211_mesh_power_mode
*out
)
5888 u32 val
= nla_get_u32(nla
);
5889 if (val
< min
|| val
> max
)
5895 static int nl80211_parse_mesh_config(struct genl_info
*info
,
5896 struct mesh_config
*cfg
,
5899 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
5903 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5906 if (fn(tb[attr], min, max, &cfg->param)) \
5908 mask |= (1 << (attr - 1)); \
5912 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
5914 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
5915 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
5916 nl80211_meshconf_params_policy
, info
->extack
))
5919 /* This makes sure that there aren't more than 32 mesh config
5920 * parameters (otherwise our bitfield scheme would not work.) */
5921 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
5923 /* Fill in the params struct */
5924 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
5925 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5927 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
5928 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5930 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
5931 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5933 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
5934 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5936 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
5937 mask
, NL80211_MESHCONF_MAX_RETRIES
,
5939 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
5940 mask
, NL80211_MESHCONF_TTL
, nl80211_check_u8
);
5941 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
5942 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
5944 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
5945 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5946 nl80211_check_bool
);
5947 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
5949 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5951 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
5952 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5954 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
5955 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5957 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
5958 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5960 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
5962 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5964 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
5966 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5968 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
5970 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5972 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5973 dot11MeshHWMPnetDiameterTraversalTime
,
5975 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5977 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
5978 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5980 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
5981 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5983 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5984 dot11MeshGateAnnouncementProtocol
, 0, 1,
5985 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5986 nl80211_check_bool
);
5987 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
5988 mask
, NL80211_MESHCONF_FORWARDING
,
5989 nl80211_check_bool
);
5990 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
5991 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5994 * Check HT operation mode based on
5995 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
5997 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
5998 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
6000 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
6001 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
6002 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
6005 /* NON_HT_STA bit is reserved, but some programs set it */
6006 ht_opmode
&= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
;
6008 cfg
->ht_opmode
= ht_opmode
;
6009 mask
|= (1 << (NL80211_MESHCONF_HT_OPMODE
- 1));
6011 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
6013 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
6015 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
6016 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
6018 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
6019 dot11MeshHWMPconfirmationInterval
,
6021 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
6023 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
6024 NL80211_MESH_POWER_ACTIVE
,
6025 NL80211_MESH_POWER_MAX
,
6026 mask
, NL80211_MESHCONF_POWER_MODE
,
6027 nl80211_check_power_mode
);
6028 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
6030 NL80211_MESHCONF_AWAKE_WINDOW
, nl80211_check_u16
);
6031 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
6032 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
6039 #undef FILL_IN_MESH_PARAM_IF_SET
6042 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
6043 struct mesh_setup
*setup
)
6045 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6046 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
6048 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
6050 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
6051 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
6052 nl80211_mesh_setup_params_policy
, info
->extack
))
6055 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
6056 setup
->sync_method
=
6057 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
6058 IEEE80211_SYNC_METHOD_VENDOR
:
6059 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
6061 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
6062 setup
->path_sel_proto
=
6063 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
6064 IEEE80211_PATH_PROTOCOL_VENDOR
:
6065 IEEE80211_PATH_PROTOCOL_HWMP
;
6067 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
6068 setup
->path_metric
=
6069 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
6070 IEEE80211_PATH_METRIC_VENDOR
:
6071 IEEE80211_PATH_METRIC_AIRTIME
;
6073 if (tb
[NL80211_MESH_SETUP_IE
]) {
6074 struct nlattr
*ieattr
=
6075 tb
[NL80211_MESH_SETUP_IE
];
6076 if (!is_valid_ie_attr(ieattr
))
6078 setup
->ie
= nla_data(ieattr
);
6079 setup
->ie_len
= nla_len(ieattr
);
6081 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
6082 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
6084 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
6085 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
6086 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
6087 if (setup
->is_secure
)
6088 setup
->user_mpm
= true;
6090 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
6091 if (!setup
->user_mpm
)
6094 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
6100 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
6101 struct genl_info
*info
)
6103 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6104 struct net_device
*dev
= info
->user_ptr
[1];
6105 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6106 struct mesh_config cfg
;
6110 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6113 if (!rdev
->ops
->update_mesh_config
)
6116 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
6121 if (!wdev
->mesh_id_len
)
6125 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
6132 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
6133 struct sk_buff
*msg
)
6135 struct nlattr
*nl_reg_rules
;
6138 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
6139 (regdom
->dfs_region
&&
6140 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
6141 goto nla_put_failure
;
6143 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
6145 goto nla_put_failure
;
6147 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
6148 struct nlattr
*nl_reg_rule
;
6149 const struct ieee80211_reg_rule
*reg_rule
;
6150 const struct ieee80211_freq_range
*freq_range
;
6151 const struct ieee80211_power_rule
*power_rule
;
6152 unsigned int max_bandwidth_khz
;
6154 reg_rule
= ®dom
->reg_rules
[i
];
6155 freq_range
= ®_rule
->freq_range
;
6156 power_rule
= ®_rule
->power_rule
;
6158 nl_reg_rule
= nla_nest_start(msg
, i
);
6160 goto nla_put_failure
;
6162 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
6163 if (!max_bandwidth_khz
)
6164 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
6167 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
6169 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
6170 freq_range
->start_freq_khz
) ||
6171 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
6172 freq_range
->end_freq_khz
) ||
6173 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
6174 max_bandwidth_khz
) ||
6175 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
6176 power_rule
->max_antenna_gain
) ||
6177 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
6178 power_rule
->max_eirp
) ||
6179 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
6180 reg_rule
->dfs_cac_ms
))
6181 goto nla_put_failure
;
6183 nla_nest_end(msg
, nl_reg_rule
);
6186 nla_nest_end(msg
, nl_reg_rules
);
6193 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
6195 const struct ieee80211_regdomain
*regdom
= NULL
;
6196 struct cfg80211_registered_device
*rdev
;
6197 struct wiphy
*wiphy
= NULL
;
6198 struct sk_buff
*msg
;
6201 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6205 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6206 NL80211_CMD_GET_REG
);
6210 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
6213 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6216 return PTR_ERR(rdev
);
6219 wiphy
= &rdev
->wiphy
;
6220 self_managed
= wiphy
->regulatory_flags
&
6221 REGULATORY_WIPHY_SELF_MANAGED
;
6222 regdom
= get_wiphy_regdom(wiphy
);
6224 /* a self-managed-reg device must have a private regdom */
6225 if (WARN_ON(!regdom
&& self_managed
)) {
6231 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6232 goto nla_put_failure
;
6235 if (!wiphy
&& reg_last_request_cell_base() &&
6236 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6237 NL80211_USER_REG_HINT_CELL_BASE
))
6238 goto nla_put_failure
;
6243 regdom
= rcu_dereference(cfg80211_regdomain
);
6245 if (nl80211_put_regdom(regdom
, msg
))
6246 goto nla_put_failure_rcu
;
6250 genlmsg_end(msg
, hdr
);
6251 return genlmsg_reply(msg
, info
);
6253 nla_put_failure_rcu
:
6256 genlmsg_cancel(msg
, hdr
);
6262 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6263 u32 seq
, int flags
, struct wiphy
*wiphy
,
6264 const struct ieee80211_regdomain
*regdom
)
6266 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6267 NL80211_CMD_GET_REG
);
6272 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
6274 if (nl80211_put_regdom(regdom
, msg
))
6275 goto nla_put_failure
;
6277 if (!wiphy
&& reg_last_request_cell_base() &&
6278 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6279 NL80211_USER_REG_HINT_CELL_BASE
))
6280 goto nla_put_failure
;
6283 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6284 goto nla_put_failure
;
6286 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
6287 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
6288 goto nla_put_failure
;
6290 genlmsg_end(msg
, hdr
);
6294 genlmsg_cancel(msg
, hdr
);
6298 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
6299 struct netlink_callback
*cb
)
6301 const struct ieee80211_regdomain
*regdom
= NULL
;
6302 struct cfg80211_registered_device
*rdev
;
6303 int err
, reg_idx
, start
= cb
->args
[2];
6307 if (cfg80211_regdomain
&& start
== 0) {
6308 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6310 rtnl_dereference(cfg80211_regdomain
));
6315 /* the global regdom is idx 0 */
6317 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
6318 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
6322 if (++reg_idx
<= start
)
6325 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6326 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
6333 cb
->args
[2] = reg_idx
;
6340 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
6341 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
6342 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
6343 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
6344 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
6345 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
6346 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
6347 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
6348 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
6351 static int parse_reg_rule(struct nlattr
*tb
[],
6352 struct ieee80211_reg_rule
*reg_rule
)
6354 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
6355 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
6357 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
6359 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
6361 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
6363 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
6365 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
6368 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
6370 freq_range
->start_freq_khz
=
6371 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
6372 freq_range
->end_freq_khz
=
6373 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
6374 freq_range
->max_bandwidth_khz
=
6375 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
6377 power_rule
->max_eirp
=
6378 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
6380 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
6381 power_rule
->max_antenna_gain
=
6382 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
6384 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
6385 reg_rule
->dfs_cac_ms
=
6386 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
6391 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
6393 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
6394 struct nlattr
*nl_reg_rule
;
6396 int rem_reg_rules
, r
;
6397 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
6398 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
6399 struct ieee80211_regdomain
*rd
;
6401 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
6404 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
6407 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
6409 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
6410 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
6412 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6415 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
6419 if (!reg_is_valid_request(alpha2
))
6422 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
6423 num_rules
* sizeof(struct ieee80211_reg_rule
);
6425 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
6429 rd
->n_reg_rules
= num_rules
;
6430 rd
->alpha2
[0] = alpha2
[0];
6431 rd
->alpha2
[1] = alpha2
[1];
6434 * Disable DFS master mode if the DFS region was
6435 * not supported or known on this kernel.
6437 if (reg_supported_dfs_region(dfs_region
))
6438 rd
->dfs_region
= dfs_region
;
6440 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6442 r
= nla_parse_nested(tb
, NL80211_REG_RULE_ATTR_MAX
,
6443 nl_reg_rule
, reg_rule_policy
,
6447 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
6453 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
6459 /* set_regdom takes ownership of rd */
6460 return set_regdom(rd
, REGD_SOURCE_CRDA
);
6465 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
6467 static int validate_scan_freqs(struct nlattr
*freqs
)
6469 struct nlattr
*attr1
, *attr2
;
6470 int n_channels
= 0, tmp1
, tmp2
;
6472 nla_for_each_nested(attr1
, freqs
, tmp1
)
6473 if (nla_len(attr1
) != sizeof(u32
))
6476 nla_for_each_nested(attr1
, freqs
, tmp1
) {
6479 * Some hardware has a limited channel list for
6480 * scanning, and it is pretty much nonsensical
6481 * to scan for a channel twice, so disallow that
6482 * and don't require drivers to check that the
6483 * channel list they get isn't longer than what
6484 * they can scan, as long as they can scan all
6485 * the channels they registered at once.
6487 nla_for_each_nested(attr2
, freqs
, tmp2
)
6488 if (attr1
!= attr2
&&
6489 nla_get_u32(attr1
) == nla_get_u32(attr2
))
6496 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
6498 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
6501 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
6502 struct cfg80211_bss_selection
*bss_select
)
6504 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
6505 struct nlattr
*nest
;
6510 /* only process one nested attribute */
6511 nest
= nla_data(nla
);
6512 if (!nla_ok(nest
, nla_len(nest
)))
6515 err
= nla_parse_nested(attr
, NL80211_BSS_SELECT_ATTR_MAX
, nest
,
6516 nl80211_bss_select_policy
, NULL
);
6520 /* only one attribute may be given */
6521 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
6529 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
6531 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
6532 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
6534 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
6535 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
6536 bss_select
->param
.band_pref
=
6537 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
6538 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
6542 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
6543 struct nl80211_bss_select_rssi_adjust
*adj_param
;
6545 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
6546 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
6547 bss_select
->param
.adjust
.band
= adj_param
->band
;
6548 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
6549 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
6553 /* user-space did not provide behaviour attribute */
6554 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
6557 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
6563 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
6564 u8
*mac_addr
, u8
*mac_addr_mask
)
6568 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
6569 eth_zero_addr(mac_addr
);
6570 eth_zero_addr(mac_addr_mask
);
6572 mac_addr_mask
[0] = 0x3;
6577 /* need both or none */
6578 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
6581 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
6582 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
6584 /* don't allow or configure an mcast address */
6585 if (!is_multicast_ether_addr(mac_addr_mask
) ||
6586 is_multicast_ether_addr(mac_addr
))
6590 * allow users to pass a MAC address that has bits set outside
6591 * of the mask, but don't bother drivers with having to deal
6594 for (i
= 0; i
< ETH_ALEN
; i
++)
6595 mac_addr
[i
] &= mac_addr_mask
[i
];
6600 static bool cfg80211_off_channel_oper_allowed(struct wireless_dev
*wdev
)
6602 ASSERT_WDEV_LOCK(wdev
);
6604 if (!cfg80211_beaconing_iface_active(wdev
))
6607 if (!(wdev
->chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
))
6610 return regulatory_pre_cac_allowed(wdev
->wiphy
);
6613 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6615 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6616 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6617 struct cfg80211_scan_request
*request
;
6618 struct nlattr
*attr
;
6619 struct wiphy
*wiphy
;
6620 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
6623 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6626 wiphy
= &rdev
->wiphy
;
6628 if (wdev
->iftype
== NL80211_IFTYPE_NAN
)
6631 if (!rdev
->ops
->scan
)
6634 if (rdev
->scan_req
|| rdev
->scan_msg
) {
6639 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6640 n_channels
= validate_scan_freqs(
6641 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6647 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6650 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
6651 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
6654 if (n_ssids
> wiphy
->max_scan_ssids
) {
6659 if (info
->attrs
[NL80211_ATTR_IE
])
6660 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6664 if (ie_len
> wiphy
->max_scan_ie_len
) {
6669 request
= kzalloc(sizeof(*request
)
6670 + sizeof(*request
->ssids
) * n_ssids
6671 + sizeof(*request
->channels
) * n_channels
6672 + ie_len
, GFP_KERNEL
);
6679 request
->ssids
= (void *)&request
->channels
[n_channels
];
6680 request
->n_ssids
= n_ssids
;
6683 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6685 request
->ie
= (void *)(request
->channels
+ n_channels
);
6689 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6690 /* user specified, bail out if channel not found */
6691 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
6692 struct ieee80211_channel
*chan
;
6694 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6701 /* ignore disabled channels */
6702 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6705 request
->channels
[i
] = chan
;
6709 enum nl80211_band band
;
6712 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
6715 if (!wiphy
->bands
[band
])
6717 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6718 struct ieee80211_channel
*chan
;
6720 chan
= &wiphy
->bands
[band
]->channels
[j
];
6722 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6725 request
->channels
[i
] = chan
;
6736 request
->n_channels
= i
;
6739 if (!cfg80211_off_channel_oper_allowed(wdev
)) {
6740 struct ieee80211_channel
*chan
;
6742 if (request
->n_channels
!= 1) {
6748 chan
= request
->channels
[0];
6749 if (chan
->center_freq
!= wdev
->chandef
.chan
->center_freq
) {
6759 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
6760 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6764 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6765 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
6770 if (info
->attrs
[NL80211_ATTR_IE
]) {
6771 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6772 memcpy((void *)request
->ie
,
6773 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6777 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
6778 if (wiphy
->bands
[i
])
6780 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
6782 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
6783 nla_for_each_nested(attr
,
6784 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
6786 enum nl80211_band band
= nla_type(attr
);
6788 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
6793 if (!wiphy
->bands
[band
])
6796 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
6799 &request
->rates
[band
]);
6805 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
6806 if (!wiphy_ext_feature_isset(wiphy
,
6807 NL80211_EXT_FEATURE_SET_SCAN_DWELL
)) {
6813 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
6814 request
->duration_mandatory
=
6815 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
6818 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
6819 request
->flags
= nla_get_u32(
6820 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6821 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6822 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
6827 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6828 if (!(wiphy
->features
&
6829 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
)) {
6834 if (wdev
->current_bss
) {
6839 err
= nl80211_parse_random_mac(info
->attrs
,
6841 request
->mac_addr_mask
);
6848 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6850 /* Initial implementation used NL80211_ATTR_MAC to set the specific
6851 * BSSID to scan for. This was problematic because that same attribute
6852 * was already used for another purpose (local random MAC address). The
6853 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
6854 * compatibility with older userspace components, also use the
6855 * NL80211_ATTR_MAC value here if it can be determined to be used for
6856 * the specific BSSID use case instead of the random MAC address
6857 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
6859 if (info
->attrs
[NL80211_ATTR_BSSID
])
6860 memcpy(request
->bssid
,
6861 nla_data(info
->attrs
[NL80211_ATTR_BSSID
]), ETH_ALEN
);
6862 else if (!(request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) &&
6863 info
->attrs
[NL80211_ATTR_MAC
])
6864 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
6867 eth_broadcast_addr(request
->bssid
);
6869 request
->wdev
= wdev
;
6870 request
->wiphy
= &rdev
->wiphy
;
6871 request
->scan_start
= jiffies
;
6873 rdev
->scan_req
= request
;
6874 err
= rdev_scan(rdev
, request
);
6877 nl80211_send_scan_start(rdev
, wdev
);
6879 dev_hold(wdev
->netdev
);
6882 rdev
->scan_req
= NULL
;
6890 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6892 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6893 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6895 if (!rdev
->ops
->abort_scan
)
6901 if (!rdev
->scan_req
)
6904 rdev_abort_scan(rdev
, wdev
);
6909 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
6910 struct cfg80211_sched_scan_request
*request
,
6911 struct nlattr
**attrs
)
6913 int tmp
, err
, i
= 0;
6914 struct nlattr
*attr
;
6916 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6920 * If scan plans are not specified,
6921 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
6922 * case one scan plan will be set with the specified scan
6923 * interval and infinite number of iterations.
6925 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
6929 request
->scan_plans
[0].interval
=
6930 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
6931 if (!request
->scan_plans
[0].interval
)
6934 if (request
->scan_plans
[0].interval
>
6935 wiphy
->max_sched_scan_plan_interval
)
6936 request
->scan_plans
[0].interval
=
6937 wiphy
->max_sched_scan_plan_interval
;
6942 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
6943 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
6945 if (WARN_ON(i
>= n_plans
))
6948 err
= nla_parse_nested(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
6949 attr
, nl80211_plan_policy
, NULL
);
6953 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
6956 request
->scan_plans
[i
].interval
=
6957 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
6958 if (!request
->scan_plans
[i
].interval
||
6959 request
->scan_plans
[i
].interval
>
6960 wiphy
->max_sched_scan_plan_interval
)
6963 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
6964 request
->scan_plans
[i
].iterations
=
6965 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
6966 if (!request
->scan_plans
[i
].iterations
||
6967 (request
->scan_plans
[i
].iterations
>
6968 wiphy
->max_sched_scan_plan_iterations
))
6970 } else if (i
< n_plans
- 1) {
6972 * All scan plans but the last one must specify
6973 * a finite number of iterations
6982 * The last scan plan must not specify the number of
6983 * iterations, it is supposed to run infinitely
6985 if (request
->scan_plans
[n_plans
- 1].iterations
)
6991 static struct cfg80211_sched_scan_request
*
6992 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6993 struct nlattr
**attrs
, int max_match_sets
)
6995 struct cfg80211_sched_scan_request
*request
;
6996 struct nlattr
*attr
;
6997 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
6998 enum nl80211_band band
;
7000 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
7001 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
7003 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
7004 return ERR_PTR(-EINVAL
);
7006 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7007 n_channels
= validate_scan_freqs(
7008 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
7010 return ERR_PTR(-EINVAL
);
7012 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
7015 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
7016 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7020 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
7021 return ERR_PTR(-EINVAL
);
7024 * First, count the number of 'real' matchsets. Due to an issue with
7025 * the old implementation, matchsets containing only the RSSI attribute
7026 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
7027 * RSSI for all matchsets, rather than their own matchset for reporting
7028 * all APs with a strong RSSI. This is needed to be compatible with
7029 * older userspace that treated a matchset with only the RSSI as the
7030 * global RSSI for all other matchsets - if there are other matchsets.
7032 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7033 nla_for_each_nested(attr
,
7034 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7036 struct nlattr
*rssi
;
7038 err
= nla_parse_nested(tb
,
7039 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7040 attr
, nl80211_match_policy
,
7043 return ERR_PTR(err
);
7045 /* SSID and BSSID are mutually exclusive */
7046 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] &&
7047 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
])
7048 return ERR_PTR(-EINVAL
);
7050 /* add other standalone attributes here */
7051 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] ||
7052 tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
]) {
7056 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7058 default_match_rssi
= nla_get_s32(rssi
);
7062 /* However, if there's no other matchset, add the RSSI one */
7063 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
7066 if (n_match_sets
> max_match_sets
)
7067 return ERR_PTR(-EINVAL
);
7069 if (attrs
[NL80211_ATTR_IE
])
7070 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
7074 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
7075 return ERR_PTR(-EINVAL
);
7077 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
7079 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
7080 * each scan plan already specifies its own interval
7082 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7083 return ERR_PTR(-EINVAL
);
7085 nla_for_each_nested(attr
,
7086 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
7090 * The scan interval attribute is kept for backward
7091 * compatibility. If no scan plans are specified and sched scan
7092 * interval is specified, one scan plan will be set with this
7093 * scan interval and infinite number of iterations.
7095 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
7096 return ERR_PTR(-EINVAL
);
7101 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
7102 return ERR_PTR(-EINVAL
);
7104 if (!wiphy_ext_feature_isset(
7105 wiphy
, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI
) &&
7106 (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
] ||
7107 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]))
7108 return ERR_PTR(-EINVAL
);
7110 request
= kzalloc(sizeof(*request
)
7111 + sizeof(*request
->ssids
) * n_ssids
7112 + sizeof(*request
->match_sets
) * n_match_sets
7113 + sizeof(*request
->scan_plans
) * n_plans
7114 + sizeof(*request
->channels
) * n_channels
7115 + ie_len
, GFP_KERNEL
);
7117 return ERR_PTR(-ENOMEM
);
7120 request
->ssids
= (void *)&request
->channels
[n_channels
];
7121 request
->n_ssids
= n_ssids
;
7124 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
7126 request
->ie
= (void *)(request
->channels
+ n_channels
);
7131 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
7133 request
->match_sets
=
7134 (void *)(request
->ssids
+ n_ssids
);
7136 request
->match_sets
=
7137 (void *)(request
->channels
+ n_channels
);
7139 request
->n_match_sets
= n_match_sets
;
7142 request
->scan_plans
= (void *)(request
->match_sets
+
7144 else if (request
->ie
)
7145 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
7147 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
7149 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
7151 request
->n_scan_plans
= n_plans
;
7154 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
7155 /* user specified, bail out if channel not found */
7156 nla_for_each_nested(attr
,
7157 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
7159 struct ieee80211_channel
*chan
;
7161 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
7168 /* ignore disabled channels */
7169 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7172 request
->channels
[i
] = chan
;
7177 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7180 if (!wiphy
->bands
[band
])
7182 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
7183 struct ieee80211_channel
*chan
;
7185 chan
= &wiphy
->bands
[band
]->channels
[j
];
7187 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
7190 request
->channels
[i
] = chan
;
7201 request
->n_channels
= i
;
7205 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7207 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7211 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7212 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
7219 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7220 nla_for_each_nested(attr
,
7221 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7223 struct nlattr
*ssid
, *bssid
, *rssi
;
7225 err
= nla_parse_nested(tb
,
7226 NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7227 attr
, nl80211_match_policy
,
7231 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
7232 bssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID
];
7233 if (ssid
|| bssid
) {
7234 if (WARN_ON(i
>= n_match_sets
)) {
7235 /* this indicates a programming error,
7236 * the loop above should have verified
7244 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
7248 memcpy(request
->match_sets
[i
].ssid
.ssid
,
7249 nla_data(ssid
), nla_len(ssid
));
7250 request
->match_sets
[i
].ssid
.ssid_len
=
7254 if (nla_len(bssid
) != ETH_ALEN
) {
7258 memcpy(request
->match_sets
[i
].bssid
,
7259 nla_data(bssid
), ETH_ALEN
);
7262 /* special attribute - old implementation w/a */
7263 request
->match_sets
[i
].rssi_thold
=
7265 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7267 request
->match_sets
[i
].rssi_thold
=
7273 /* there was no other matchset, so the RSSI one is alone */
7274 if (i
== 0 && n_match_sets
)
7275 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
7277 request
->min_rssi_thold
= INT_MAX
;
7278 for (i
= 0; i
< n_match_sets
; i
++)
7279 request
->min_rssi_thold
=
7280 min(request
->match_sets
[i
].rssi_thold
,
7281 request
->min_rssi_thold
);
7283 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
7287 request
->ie_len
= ie_len
;
7288 memcpy((void *)request
->ie
,
7289 nla_data(attrs
[NL80211_ATTR_IE
]),
7293 if (attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
7294 request
->flags
= nla_get_u32(
7295 attrs
[NL80211_ATTR_SCAN_FLAGS
]);
7296 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
7297 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
7302 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
7303 u32 flg
= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
;
7305 if (!wdev
) /* must be net-detect */
7306 flg
= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
7308 if (!(wiphy
->features
& flg
)) {
7313 if (wdev
&& wdev
->current_bss
) {
7318 err
= nl80211_parse_random_mac(attrs
, request
->mac_addr
,
7319 request
->mac_addr_mask
);
7325 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
7327 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
7329 if (attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]) {
7330 request
->relative_rssi
= nla_get_s8(
7331 attrs
[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
]);
7332 request
->relative_rssi_set
= true;
7335 if (request
->relative_rssi_set
&&
7336 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]) {
7337 struct nl80211_bss_select_rssi_adjust
*rssi_adjust
;
7339 rssi_adjust
= nla_data(
7340 attrs
[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
]);
7341 request
->rssi_adjust
.band
= rssi_adjust
->band
;
7342 request
->rssi_adjust
.delta
= rssi_adjust
->delta
;
7343 if (!is_band_valid(wiphy
, request
->rssi_adjust
.band
)) {
7349 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
7353 request
->scan_start
= jiffies
;
7359 return ERR_PTR(err
);
7362 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
7363 struct genl_info
*info
)
7365 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7366 struct net_device
*dev
= info
->user_ptr
[1];
7367 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7368 struct cfg80211_sched_scan_request
*sched_scan_req
;
7372 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_start
)
7375 want_multi
= info
->attrs
[NL80211_ATTR_SCHED_SCAN_MULTI
];
7376 err
= cfg80211_sched_scan_req_possible(rdev
, want_multi
);
7380 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
7382 rdev
->wiphy
.max_match_sets
);
7384 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
7388 /* leave request id zero for legacy request
7389 * or if driver does not support multi-scheduled scan
7391 if (want_multi
&& rdev
->wiphy
.max_sched_scan_reqs
> 1) {
7392 while (!sched_scan_req
->reqid
)
7393 sched_scan_req
->reqid
= rdev
->wiphy
.cookie_counter
++;
7396 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
7400 sched_scan_req
->dev
= dev
;
7401 sched_scan_req
->wiphy
= &rdev
->wiphy
;
7403 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
7404 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
7406 cfg80211_add_sched_scan_req(rdev
, sched_scan_req
);
7408 nl80211_send_sched_scan(sched_scan_req
, NL80211_CMD_START_SCHED_SCAN
);
7412 kfree(sched_scan_req
);
7417 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
7418 struct genl_info
*info
)
7420 struct cfg80211_sched_scan_request
*req
;
7421 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7424 if (!rdev
->wiphy
.max_sched_scan_reqs
|| !rdev
->ops
->sched_scan_stop
)
7427 if (info
->attrs
[NL80211_ATTR_COOKIE
]) {
7428 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7429 return __cfg80211_stop_sched_scan(rdev
, cookie
, false);
7432 req
= list_first_or_null_rcu(&rdev
->sched_scan_req_list
,
7433 struct cfg80211_sched_scan_request
,
7435 if (!req
|| req
->reqid
||
7436 (req
->owner_nlportid
&&
7437 req
->owner_nlportid
!= info
->snd_portid
))
7440 return cfg80211_stop_sched_scan_req(rdev
, req
, false);
7443 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
7444 struct genl_info
*info
)
7446 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7447 struct net_device
*dev
= info
->user_ptr
[1];
7448 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7449 struct cfg80211_chan_def chandef
;
7450 enum nl80211_dfs_regions dfs_region
;
7451 unsigned int cac_time_ms
;
7454 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
7455 if (dfs_region
== NL80211_DFS_UNSET
)
7458 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7462 if (netif_carrier_ok(dev
))
7465 if (wdev
->cac_started
)
7468 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
7476 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
7479 if (!rdev
->ops
->start_radar_detection
)
7482 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
7483 if (WARN_ON(!cac_time_ms
))
7484 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
7486 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
7488 wdev
->chandef
= chandef
;
7489 wdev
->cac_started
= true;
7490 wdev
->cac_start_time
= jiffies
;
7491 wdev
->cac_time_ms
= cac_time_ms
;
7496 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
7498 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7499 struct net_device
*dev
= info
->user_ptr
[1];
7500 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7501 struct cfg80211_csa_settings params
;
7502 /* csa_attrs is defined static to avoid waste of stack size - this
7503 * function is called under RTNL lock, so this should not be a problem.
7505 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
7507 bool need_new_beacon
= false;
7508 bool need_handle_dfs_flag
= true;
7512 if (!rdev
->ops
->channel_switch
||
7513 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
7516 switch (dev
->ieee80211_ptr
->iftype
) {
7517 case NL80211_IFTYPE_AP
:
7518 case NL80211_IFTYPE_P2P_GO
:
7519 need_new_beacon
= true;
7520 /* For all modes except AP the handle_dfs flag needs to be
7521 * supplied to tell the kernel that userspace will handle radar
7522 * events when they happen. Otherwise a switch to a channel
7523 * requiring DFS will be rejected.
7525 need_handle_dfs_flag
= false;
7527 /* useless if AP is not running */
7528 if (!wdev
->beacon_interval
)
7531 case NL80211_IFTYPE_ADHOC
:
7532 if (!wdev
->ssid_len
)
7535 case NL80211_IFTYPE_MESH_POINT
:
7536 if (!wdev
->mesh_id_len
)
7543 memset(¶ms
, 0, sizeof(params
));
7545 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7546 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
7549 /* only important for AP, IBSS and mesh create IEs internally */
7550 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
7553 /* Even though the attribute is u32, the specification says
7554 * u8, so let's make sure we don't overflow.
7556 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
7560 params
.count
= cs_count
;
7562 if (!need_new_beacon
)
7565 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
7569 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
7570 info
->attrs
[NL80211_ATTR_CSA_IES
],
7571 nl80211_policy
, info
->extack
);
7575 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
7579 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
7582 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7583 if (!len
|| (len
% sizeof(u16
)))
7586 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
7587 if (rdev
->wiphy
.max_num_csa_counters
&&
7588 (params
.n_counter_offsets_beacon
>
7589 rdev
->wiphy
.max_num_csa_counters
))
7592 params
.counter_offsets_beacon
=
7593 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7595 /* sanity checks - counters should fit and be the same */
7596 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
7597 u16 offset
= params
.counter_offsets_beacon
[i
];
7599 if (offset
>= params
.beacon_csa
.tail_len
)
7602 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
7606 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
7607 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7608 if (!len
|| (len
% sizeof(u16
)))
7611 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
7612 if (rdev
->wiphy
.max_num_csa_counters
&&
7613 (params
.n_counter_offsets_presp
>
7614 rdev
->wiphy
.max_num_csa_counters
))
7617 params
.counter_offsets_presp
=
7618 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7620 /* sanity checks - counters should fit and be the same */
7621 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
7622 u16 offset
= params
.counter_offsets_presp
[i
];
7624 if (offset
>= params
.beacon_csa
.probe_resp_len
)
7627 if (params
.beacon_csa
.probe_resp
[offset
] !=
7634 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
7638 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
7642 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
7649 params
.radar_required
= true;
7650 if (need_handle_dfs_flag
&&
7651 !nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
])) {
7656 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
7657 params
.block_tx
= true;
7660 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
7666 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
7668 struct cfg80211_registered_device
*rdev
,
7669 struct wireless_dev
*wdev
,
7670 struct cfg80211_internal_bss
*intbss
)
7672 struct cfg80211_bss
*res
= &intbss
->pub
;
7673 const struct cfg80211_bss_ies
*ies
;
7677 ASSERT_WDEV_LOCK(wdev
);
7679 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
7680 NL80211_CMD_NEW_SCAN_RESULTS
);
7684 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
7686 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
7687 goto nla_put_failure
;
7689 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
7690 goto nla_put_failure
;
7691 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
7693 goto nla_put_failure
;
7695 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
7697 goto nla_put_failure
;
7698 if ((!is_zero_ether_addr(res
->bssid
) &&
7699 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
7700 goto nla_put_failure
;
7703 /* indicate whether we have probe response data or not */
7704 if (rcu_access_pointer(res
->proberesp_ies
) &&
7705 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
7706 goto fail_unlock_rcu
;
7708 /* this pointer prefers to be pointed to probe response data
7709 * but is always valid
7711 ies
= rcu_dereference(res
->ies
);
7713 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
7715 goto fail_unlock_rcu
;
7716 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
7717 ies
->len
, ies
->data
))
7718 goto fail_unlock_rcu
;
7721 /* and this pointer is always (unless driver didn't know) beacon data */
7722 ies
= rcu_dereference(res
->beacon_ies
);
7723 if (ies
&& ies
->from_beacon
) {
7724 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
7726 goto fail_unlock_rcu
;
7727 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
7728 ies
->len
, ies
->data
))
7729 goto fail_unlock_rcu
;
7733 if (res
->beacon_interval
&&
7734 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
7735 goto nla_put_failure
;
7736 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
7737 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
7738 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
7739 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
7740 jiffies_to_msecs(jiffies
- intbss
->ts
)))
7741 goto nla_put_failure
;
7743 if (intbss
->parent_tsf
&&
7744 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
7745 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
7746 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
7747 intbss
->parent_bssid
)))
7748 goto nla_put_failure
;
7750 if (intbss
->ts_boottime
&&
7751 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
7752 intbss
->ts_boottime
, NL80211_BSS_PAD
))
7753 goto nla_put_failure
;
7755 switch (rdev
->wiphy
.signal_type
) {
7756 case CFG80211_SIGNAL_TYPE_MBM
:
7757 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
7758 goto nla_put_failure
;
7760 case CFG80211_SIGNAL_TYPE_UNSPEC
:
7761 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
7762 goto nla_put_failure
;
7768 switch (wdev
->iftype
) {
7769 case NL80211_IFTYPE_P2P_CLIENT
:
7770 case NL80211_IFTYPE_STATION
:
7771 if (intbss
== wdev
->current_bss
&&
7772 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7773 NL80211_BSS_STATUS_ASSOCIATED
))
7774 goto nla_put_failure
;
7776 case NL80211_IFTYPE_ADHOC
:
7777 if (intbss
== wdev
->current_bss
&&
7778 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7779 NL80211_BSS_STATUS_IBSS_JOINED
))
7780 goto nla_put_failure
;
7786 nla_nest_end(msg
, bss
);
7788 genlmsg_end(msg
, hdr
);
7794 genlmsg_cancel(msg
, hdr
);
7798 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
7800 struct cfg80211_registered_device
*rdev
;
7801 struct cfg80211_internal_bss
*scan
;
7802 struct wireless_dev
*wdev
;
7803 int start
= cb
->args
[2], idx
= 0;
7807 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
7814 spin_lock_bh(&rdev
->bss_lock
);
7815 cfg80211_bss_expire(rdev
);
7817 cb
->seq
= rdev
->bss_generation
;
7819 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
7822 if (nl80211_send_bss(skb
, cb
,
7823 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7824 rdev
, wdev
, scan
) < 0) {
7830 spin_unlock_bh(&rdev
->bss_lock
);
7839 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
7840 int flags
, struct net_device
*dev
,
7841 bool allow_radio_stats
,
7842 struct survey_info
*survey
)
7845 struct nlattr
*infoattr
;
7847 /* skip radio stats if userspace didn't request them */
7848 if (!survey
->channel
&& !allow_radio_stats
)
7851 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
7852 NL80211_CMD_NEW_SURVEY_RESULTS
);
7856 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
7857 goto nla_put_failure
;
7859 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
7861 goto nla_put_failure
;
7863 if (survey
->channel
&&
7864 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
7865 survey
->channel
->center_freq
))
7866 goto nla_put_failure
;
7868 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
7869 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
7870 goto nla_put_failure
;
7871 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
7872 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
7873 goto nla_put_failure
;
7874 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
7875 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
7876 survey
->time
, NL80211_SURVEY_INFO_PAD
))
7877 goto nla_put_failure
;
7878 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
7879 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
7880 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
7881 goto nla_put_failure
;
7882 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
7883 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
7884 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
7885 goto nla_put_failure
;
7886 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
7887 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
7888 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
7889 goto nla_put_failure
;
7890 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
7891 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
7892 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
7893 goto nla_put_failure
;
7894 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
7895 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
7896 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
7897 goto nla_put_failure
;
7899 nla_nest_end(msg
, infoattr
);
7901 genlmsg_end(msg
, hdr
);
7905 genlmsg_cancel(msg
, hdr
);
7909 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
7911 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
7912 struct survey_info survey
;
7913 struct cfg80211_registered_device
*rdev
;
7914 struct wireless_dev
*wdev
;
7915 int survey_idx
= cb
->args
[2];
7920 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
7924 /* prepare_wdev_dump parsed the attributes */
7925 radio_stats
= attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
7927 if (!wdev
->netdev
) {
7932 if (!rdev
->ops
->dump_survey
) {
7938 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
7944 /* don't send disabled channels, but do send non-channel data */
7945 if (survey
.channel
&&
7946 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
7951 if (nl80211_send_survey(skb
,
7952 NETLINK_CB(cb
->skb
).portid
,
7953 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7954 wdev
->netdev
, radio_stats
, &survey
) < 0)
7960 cb
->args
[2] = survey_idx
;
7967 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
7969 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
7970 NL80211_WPA_VERSION_2
));
7973 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
7975 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7976 struct net_device
*dev
= info
->user_ptr
[1];
7977 struct ieee80211_channel
*chan
;
7978 const u8
*bssid
, *ssid
, *ie
= NULL
, *auth_data
= NULL
;
7979 int err
, ssid_len
, ie_len
= 0, auth_data_len
= 0;
7980 enum nl80211_auth_type auth_type
;
7981 struct key_parse key
;
7982 bool local_state_change
;
7984 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7987 if (!info
->attrs
[NL80211_ATTR_MAC
])
7990 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
7993 if (!info
->attrs
[NL80211_ATTR_SSID
])
7996 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7999 err
= nl80211_parse_key(info
, &key
);
8004 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
8006 if (!key
.p
.key
|| !key
.p
.key_len
)
8008 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
8009 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
8010 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
8011 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
8024 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
8025 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
8034 if (!rdev
->ops
->auth
)
8037 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8038 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8041 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8042 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8043 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8047 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8048 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8050 if (info
->attrs
[NL80211_ATTR_IE
]) {
8051 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8052 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8055 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8056 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
8059 if ((auth_type
== NL80211_AUTHTYPE_SAE
||
8060 auth_type
== NL80211_AUTHTYPE_FILS_SK
||
8061 auth_type
== NL80211_AUTHTYPE_FILS_SK_PFS
||
8062 auth_type
== NL80211_AUTHTYPE_FILS_PK
) &&
8063 !info
->attrs
[NL80211_ATTR_AUTH_DATA
])
8066 if (info
->attrs
[NL80211_ATTR_AUTH_DATA
]) {
8067 if (auth_type
!= NL80211_AUTHTYPE_SAE
&&
8068 auth_type
!= NL80211_AUTHTYPE_FILS_SK
&&
8069 auth_type
!= NL80211_AUTHTYPE_FILS_SK_PFS
&&
8070 auth_type
!= NL80211_AUTHTYPE_FILS_PK
)
8072 auth_data
= nla_data(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8073 auth_data_len
= nla_len(info
->attrs
[NL80211_ATTR_AUTH_DATA
]);
8074 /* need to include at least Auth Transaction and Status Code */
8075 if (auth_data_len
< 4)
8079 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8082 * Since we no longer track auth state, ignore
8083 * requests to only change local state.
8085 if (local_state_change
)
8088 wdev_lock(dev
->ieee80211_ptr
);
8089 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
8090 ssid
, ssid_len
, ie
, ie_len
,
8091 key
.p
.key
, key
.p
.key_len
, key
.idx
,
8092 auth_data
, auth_data_len
);
8093 wdev_unlock(dev
->ieee80211_ptr
);
8097 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
8098 struct genl_info
*info
,
8099 struct cfg80211_crypto_settings
*settings
,
8102 memset(settings
, 0, sizeof(*settings
));
8104 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
8106 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
8109 proto
= nla_get_u16(
8110 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
8111 settings
->control_port_ethertype
= cpu_to_be16(proto
);
8112 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
8115 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
8116 settings
->control_port_no_encrypt
= true;
8118 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
8120 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
8124 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8125 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
8126 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
8128 if (len
% sizeof(u32
))
8131 if (settings
->n_ciphers_pairwise
> cipher_limit
)
8134 memcpy(settings
->ciphers_pairwise
, data
, len
);
8136 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
8137 if (!cfg80211_supported_cipher_suite(
8139 settings
->ciphers_pairwise
[i
]))
8143 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
8144 settings
->cipher_group
=
8145 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
8146 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
8147 settings
->cipher_group
))
8151 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
8152 settings
->wpa_versions
=
8153 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
8154 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
8158 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
8162 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8163 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
8164 settings
->n_akm_suites
= len
/ sizeof(u32
);
8166 if (len
% sizeof(u32
))
8169 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
8172 memcpy(settings
->akm_suites
, data
, len
);
8175 if (info
->attrs
[NL80211_ATTR_PMK
]) {
8176 if (nla_len(info
->attrs
[NL80211_ATTR_PMK
]) != WLAN_PMK_LEN
)
8178 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8179 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK
))
8181 settings
->psk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
8187 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
8189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8190 struct net_device
*dev
= info
->user_ptr
[1];
8191 struct ieee80211_channel
*chan
;
8192 struct cfg80211_assoc_request req
= {};
8193 const u8
*bssid
, *ssid
;
8194 int err
, ssid_len
= 0;
8196 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8199 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
8200 !info
->attrs
[NL80211_ATTR_SSID
] ||
8201 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8204 if (!rdev
->ops
->assoc
)
8207 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8208 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8211 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8213 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
8214 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8218 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8219 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8221 if (info
->attrs
[NL80211_ATTR_IE
]) {
8222 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8223 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8226 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
8227 enum nl80211_mfp mfp
=
8228 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
8229 if (mfp
== NL80211_MFP_REQUIRED
)
8231 else if (mfp
!= NL80211_MFP_NO
)
8235 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
8236 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
8238 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
8239 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
8241 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8242 memcpy(&req
.ht_capa_mask
,
8243 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8244 sizeof(req
.ht_capa_mask
));
8246 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8247 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8249 memcpy(&req
.ht_capa
,
8250 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8251 sizeof(req
.ht_capa
));
8254 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
8255 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
8257 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8258 memcpy(&req
.vht_capa_mask
,
8259 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
8260 sizeof(req
.vht_capa_mask
));
8262 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
8263 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8265 memcpy(&req
.vht_capa
,
8266 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
8267 sizeof(req
.vht_capa
));
8270 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
8271 if (!((rdev
->wiphy
.features
&
8272 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
8273 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
8274 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8275 NL80211_EXT_FEATURE_RRM
))
8277 req
.flags
|= ASSOC_REQ_USE_RRM
;
8280 if (info
->attrs
[NL80211_ATTR_FILS_KEK
]) {
8281 req
.fils_kek
= nla_data(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8282 req
.fils_kek_len
= nla_len(info
->attrs
[NL80211_ATTR_FILS_KEK
]);
8283 if (!info
->attrs
[NL80211_ATTR_FILS_NONCES
])
8286 nla_data(info
->attrs
[NL80211_ATTR_FILS_NONCES
]);
8289 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
8291 wdev_lock(dev
->ieee80211_ptr
);
8293 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
8294 ssid
, ssid_len
, &req
);
8296 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
8297 dev
->ieee80211_ptr
->conn_owner_nlportid
=
8299 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
8303 wdev_unlock(dev
->ieee80211_ptr
);
8309 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8311 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8312 struct net_device
*dev
= info
->user_ptr
[1];
8313 const u8
*ie
= NULL
, *bssid
;
8314 int ie_len
= 0, err
;
8316 bool local_state_change
;
8318 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8321 if (!info
->attrs
[NL80211_ATTR_MAC
])
8324 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8327 if (!rdev
->ops
->deauth
)
8330 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8331 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8334 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8336 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8337 if (reason_code
== 0) {
8338 /* Reason Code 0 is reserved */
8342 if (info
->attrs
[NL80211_ATTR_IE
]) {
8343 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8344 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8347 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8349 wdev_lock(dev
->ieee80211_ptr
);
8350 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8351 local_state_change
);
8352 wdev_unlock(dev
->ieee80211_ptr
);
8356 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
8358 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8359 struct net_device
*dev
= info
->user_ptr
[1];
8360 const u8
*ie
= NULL
, *bssid
;
8361 int ie_len
= 0, err
;
8363 bool local_state_change
;
8365 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8368 if (!info
->attrs
[NL80211_ATTR_MAC
])
8371 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8374 if (!rdev
->ops
->disassoc
)
8377 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8378 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8381 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8383 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8384 if (reason_code
== 0) {
8385 /* Reason Code 0 is reserved */
8389 if (info
->attrs
[NL80211_ATTR_IE
]) {
8390 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8391 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8394 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8396 wdev_lock(dev
->ieee80211_ptr
);
8397 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8398 local_state_change
);
8399 wdev_unlock(dev
->ieee80211_ptr
);
8404 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
8405 int mcast_rate
[NUM_NL80211_BANDS
],
8408 struct wiphy
*wiphy
= &rdev
->wiphy
;
8412 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8413 struct ieee80211_supported_band
*sband
;
8415 sband
= wiphy
->bands
[band
];
8419 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
8420 if (sband
->bitrates
[i
].bitrate
== rateval
) {
8421 mcast_rate
[band
] = i
+ 1;
8431 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8433 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8434 struct net_device
*dev
= info
->user_ptr
[1];
8435 struct cfg80211_ibss_params ibss
;
8436 struct wiphy
*wiphy
;
8437 struct cfg80211_cached_keys
*connkeys
= NULL
;
8440 memset(&ibss
, 0, sizeof(ibss
));
8442 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8445 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8446 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8449 ibss
.beacon_interval
= 100;
8451 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
])
8452 ibss
.beacon_interval
=
8453 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8455 err
= cfg80211_validate_beacon_int(rdev
, NL80211_IFTYPE_ADHOC
,
8456 ibss
.beacon_interval
);
8460 if (!rdev
->ops
->join_ibss
)
8463 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8466 wiphy
= &rdev
->wiphy
;
8468 if (info
->attrs
[NL80211_ATTR_MAC
]) {
8469 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8471 if (!is_valid_ether_addr(ibss
.bssid
))
8474 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8475 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8477 if (info
->attrs
[NL80211_ATTR_IE
]) {
8478 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8479 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8482 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
8486 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
8487 NL80211_IFTYPE_ADHOC
))
8490 switch (ibss
.chandef
.width
) {
8491 case NL80211_CHAN_WIDTH_5
:
8492 case NL80211_CHAN_WIDTH_10
:
8493 case NL80211_CHAN_WIDTH_20_NOHT
:
8495 case NL80211_CHAN_WIDTH_20
:
8496 case NL80211_CHAN_WIDTH_40
:
8497 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8500 case NL80211_CHAN_WIDTH_80
:
8501 case NL80211_CHAN_WIDTH_80P80
:
8502 case NL80211_CHAN_WIDTH_160
:
8503 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8505 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8506 NL80211_EXT_FEATURE_VHT_IBSS
))
8513 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
8514 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
8516 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8518 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8520 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8521 struct ieee80211_supported_band
*sband
=
8522 wiphy
->bands
[ibss
.chandef
.chan
->band
];
8524 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8530 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8531 memcpy(&ibss
.ht_capa_mask
,
8532 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8533 sizeof(ibss
.ht_capa_mask
));
8535 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8536 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8538 memcpy(&ibss
.ht_capa
,
8539 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8540 sizeof(ibss
.ht_capa
));
8543 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8544 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
8545 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8548 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
8551 connkeys
= nl80211_parse_connkeys(rdev
,
8552 info
->attrs
[NL80211_ATTR_KEYS
],
8554 if (IS_ERR(connkeys
))
8555 return PTR_ERR(connkeys
);
8557 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
8565 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
8567 ibss
.userspace_handles_dfs
=
8568 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
8570 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
8576 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8578 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8579 struct net_device
*dev
= info
->user_ptr
[1];
8581 if (!rdev
->ops
->leave_ibss
)
8584 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8587 return cfg80211_leave_ibss(rdev
, dev
, false);
8590 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
8592 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8593 struct net_device
*dev
= info
->user_ptr
[1];
8594 int mcast_rate
[NUM_NL80211_BANDS
];
8598 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
8599 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
8600 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
8603 if (!rdev
->ops
->set_mcast_rate
)
8606 memset(mcast_rate
, 0, sizeof(mcast_rate
));
8608 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
8611 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
8612 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
8615 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
8620 static struct sk_buff
*
8621 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
8622 struct wireless_dev
*wdev
, int approxlen
,
8623 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
8624 enum nl80211_attrs attr
,
8625 const struct nl80211_vendor_cmd_info
*info
,
8628 struct sk_buff
*skb
;
8630 struct nlattr
*data
;
8632 skb
= nlmsg_new(approxlen
+ 100, gfp
);
8636 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
8642 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
8643 goto nla_put_failure
;
8646 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
8648 goto nla_put_failure
;
8649 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
8651 goto nla_put_failure
;
8655 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
8656 wdev_id(wdev
), NL80211_ATTR_PAD
))
8657 goto nla_put_failure
;
8659 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
8660 wdev
->netdev
->ifindex
))
8661 goto nla_put_failure
;
8664 data
= nla_nest_start(skb
, attr
);
8666 goto nla_put_failure
;
8668 ((void **)skb
->cb
)[0] = rdev
;
8669 ((void **)skb
->cb
)[1] = hdr
;
8670 ((void **)skb
->cb
)[2] = data
;
8679 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
8680 struct wireless_dev
*wdev
,
8681 enum nl80211_commands cmd
,
8682 enum nl80211_attrs attr
,
8683 int vendor_event_idx
,
8684 int approxlen
, gfp_t gfp
)
8686 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
8687 const struct nl80211_vendor_cmd_info
*info
;
8690 case NL80211_CMD_TESTMODE
:
8691 if (WARN_ON(vendor_event_idx
!= -1))
8695 case NL80211_CMD_VENDOR
:
8696 if (WARN_ON(vendor_event_idx
< 0 ||
8697 vendor_event_idx
>= wiphy
->n_vendor_events
))
8699 info
= &wiphy
->vendor_events
[vendor_event_idx
];
8706 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
8707 cmd
, attr
, info
, gfp
);
8709 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
8711 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
8713 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8714 void *hdr
= ((void **)skb
->cb
)[1];
8715 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8716 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
8718 /* clear CB data for netlink core to own from now on */
8719 memset(skb
->cb
, 0, sizeof(skb
->cb
));
8721 nla_nest_end(skb
, data
);
8722 genlmsg_end(skb
, hdr
);
8724 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
8725 mcgrp
= NL80211_MCGRP_VENDOR
;
8727 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
8730 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
8732 #ifdef CONFIG_NL80211_TESTMODE
8733 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
8735 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8736 struct wireless_dev
*wdev
=
8737 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8740 if (!rdev
->ops
->testmode_cmd
)
8744 err
= PTR_ERR(wdev
);
8748 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8752 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
8755 rdev
->cur_cmd_info
= info
;
8756 err
= rdev_testmode_cmd(rdev
, wdev
,
8757 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
8758 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
8759 rdev
->cur_cmd_info
= NULL
;
8764 static int nl80211_testmode_dump(struct sk_buff
*skb
,
8765 struct netlink_callback
*cb
)
8767 struct cfg80211_registered_device
*rdev
;
8777 * 0 is a valid index, but not valid for args[0],
8778 * so we need to offset by 1.
8780 phy_idx
= cb
->args
[0] - 1;
8782 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
8788 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
8790 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
8791 attrbuf
, nl80211_fam
.maxattr
,
8792 nl80211_policy
, NULL
);
8796 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
8798 err
= PTR_ERR(rdev
);
8801 phy_idx
= rdev
->wiphy_idx
;
8803 if (attrbuf
[NL80211_ATTR_TESTDATA
])
8804 cb
->args
[1] = (long)attrbuf
[NL80211_ATTR_TESTDATA
];
8808 data
= nla_data((void *)cb
->args
[1]);
8809 data_len
= nla_len((void *)cb
->args
[1]);
8812 if (!rdev
->ops
->testmode_dump
) {
8818 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
8819 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8820 NL80211_CMD_TESTMODE
);
8821 struct nlattr
*tmdata
;
8826 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
8827 genlmsg_cancel(skb
, hdr
);
8831 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
8833 genlmsg_cancel(skb
, hdr
);
8836 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
8837 nla_nest_end(skb
, tmdata
);
8839 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
8840 genlmsg_cancel(skb
, hdr
);
8843 genlmsg_cancel(skb
, hdr
);
8847 genlmsg_end(skb
, hdr
);
8852 cb
->args
[0] = phy_idx
+ 1;
8859 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
8861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8862 struct net_device
*dev
= info
->user_ptr
[1];
8863 struct cfg80211_connect_params connect
;
8864 struct wiphy
*wiphy
;
8865 struct cfg80211_cached_keys
*connkeys
= NULL
;
8868 memset(&connect
, 0, sizeof(connect
));
8870 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8873 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8874 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8877 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
8879 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8880 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
8881 NL80211_CMD_CONNECT
))
8884 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
8886 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
8888 if (info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
] &&
8889 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8890 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
8892 connect
.want_1x
= info
->attrs
[NL80211_ATTR_WANT_1X_4WAY_HS
];
8894 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
8895 NL80211_MAX_NR_CIPHER_SUITES
);
8899 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8900 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8903 wiphy
= &rdev
->wiphy
;
8905 connect
.bg_scan_period
= -1;
8906 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
8907 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
8908 connect
.bg_scan_period
=
8909 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
8912 if (info
->attrs
[NL80211_ATTR_MAC
])
8913 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8914 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
8915 connect
.bssid_hint
=
8916 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
8917 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8918 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8920 if (info
->attrs
[NL80211_ATTR_IE
]) {
8921 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8922 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8925 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
8926 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
8927 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
8928 connect
.mfp
!= NL80211_MFP_NO
)
8931 connect
.mfp
= NL80211_MFP_NO
;
8934 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
8935 connect
.prev_bssid
=
8936 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
8938 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8939 connect
.channel
= nl80211_get_valid_chan(
8940 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8941 if (!connect
.channel
)
8943 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
8944 connect
.channel_hint
= nl80211_get_valid_chan(
8945 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
8946 if (!connect
.channel_hint
)
8950 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
8951 connkeys
= nl80211_parse_connkeys(rdev
,
8952 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
8953 if (IS_ERR(connkeys
))
8954 return PTR_ERR(connkeys
);
8957 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
8958 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
8960 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8961 memcpy(&connect
.ht_capa_mask
,
8962 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8963 sizeof(connect
.ht_capa_mask
));
8965 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8966 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
8970 memcpy(&connect
.ht_capa
,
8971 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8972 sizeof(connect
.ht_capa
));
8975 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
8976 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
8978 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8979 memcpy(&connect
.vht_capa_mask
,
8980 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
8981 sizeof(connect
.vht_capa_mask
));
8983 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
8984 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
8988 memcpy(&connect
.vht_capa
,
8989 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
8990 sizeof(connect
.vht_capa
));
8993 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
8994 if (!((rdev
->wiphy
.features
&
8995 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
8996 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
8997 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8998 NL80211_EXT_FEATURE_RRM
)) {
9002 connect
.flags
|= ASSOC_REQ_USE_RRM
;
9005 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
9006 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
9011 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
9012 /* bss selection makes no sense if bssid is set */
9013 if (connect
.bssid
) {
9018 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
9019 wiphy
, &connect
.bss_select
);
9026 if (wiphy_ext_feature_isset(&rdev
->wiphy
,
9027 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD
) &&
9028 info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] &&
9029 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] &&
9030 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] &&
9031 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9032 connect
.fils_erp_username
=
9033 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9034 connect
.fils_erp_username_len
=
9035 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
]);
9036 connect
.fils_erp_realm
=
9037 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9038 connect
.fils_erp_realm_len
=
9039 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
]);
9040 connect
.fils_erp_next_seq_num
=
9042 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
]);
9043 connect
.fils_erp_rrk
=
9044 nla_data(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9045 connect
.fils_erp_rrk_len
=
9046 nla_len(info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]);
9047 } else if (info
->attrs
[NL80211_ATTR_FILS_ERP_USERNAME
] ||
9048 info
->attrs
[NL80211_ATTR_FILS_ERP_REALM
] ||
9049 info
->attrs
[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
] ||
9050 info
->attrs
[NL80211_ATTR_FILS_ERP_RRK
]) {
9055 wdev_lock(dev
->ieee80211_ptr
);
9057 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
9058 connect
.prev_bssid
);
9062 if (!err
&& info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
9063 dev
->ieee80211_ptr
->conn_owner_nlportid
= info
->snd_portid
;
9065 memcpy(dev
->ieee80211_ptr
->disconnect_bssid
,
9066 connect
.bssid
, ETH_ALEN
);
9068 memset(dev
->ieee80211_ptr
->disconnect_bssid
,
9072 wdev_unlock(dev
->ieee80211_ptr
);
9077 static int nl80211_update_connect_params(struct sk_buff
*skb
,
9078 struct genl_info
*info
)
9080 struct cfg80211_connect_params connect
= {};
9081 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9082 struct net_device
*dev
= info
->user_ptr
[1];
9083 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9087 if (!rdev
->ops
->update_connect_params
)
9090 if (info
->attrs
[NL80211_ATTR_IE
]) {
9091 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9093 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9094 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9095 changed
|= UPDATE_ASSOC_IES
;
9098 wdev_lock(dev
->ieee80211_ptr
);
9099 if (!wdev
->current_bss
)
9102 ret
= rdev_update_connect_params(rdev
, dev
, &connect
, changed
);
9103 wdev_unlock(dev
->ieee80211_ptr
);
9108 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
9110 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9111 struct net_device
*dev
= info
->user_ptr
[1];
9115 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
9116 reason
= WLAN_REASON_DEAUTH_LEAVING
;
9118 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
9123 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9124 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9127 wdev_lock(dev
->ieee80211_ptr
);
9128 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
9129 wdev_unlock(dev
->ieee80211_ptr
);
9133 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
9135 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9139 if (info
->attrs
[NL80211_ATTR_PID
]) {
9140 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
9142 net
= get_net_ns_by_pid(pid
);
9143 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
9144 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
9146 net
= get_net_ns_by_fd(fd
);
9152 return PTR_ERR(net
);
9156 /* check if anything to do */
9157 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
9158 err
= cfg80211_switch_netns(rdev
, net
);
9164 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9166 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9167 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
9168 struct cfg80211_pmksa
*pmksa
) = NULL
;
9169 struct net_device
*dev
= info
->user_ptr
[1];
9170 struct cfg80211_pmksa pmksa
;
9172 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
9174 if (!info
->attrs
[NL80211_ATTR_PMKID
])
9177 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
9179 if (info
->attrs
[NL80211_ATTR_MAC
]) {
9180 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9181 } else if (info
->attrs
[NL80211_ATTR_SSID
] &&
9182 info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
] &&
9183 (info
->genlhdr
->cmd
== NL80211_CMD_DEL_PMKSA
||
9184 info
->attrs
[NL80211_ATTR_PMK
])) {
9185 pmksa
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
9186 pmksa
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
9188 nla_data(info
->attrs
[NL80211_ATTR_FILS_CACHE_ID
]);
9192 if (info
->attrs
[NL80211_ATTR_PMK
]) {
9193 pmksa
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
9194 pmksa
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
9197 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9198 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9201 switch (info
->genlhdr
->cmd
) {
9202 case NL80211_CMD_SET_PMKSA
:
9203 rdev_ops
= rdev
->ops
->set_pmksa
;
9205 case NL80211_CMD_DEL_PMKSA
:
9206 rdev_ops
= rdev
->ops
->del_pmksa
;
9216 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
9219 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
9221 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9222 struct net_device
*dev
= info
->user_ptr
[1];
9224 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
9225 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9228 if (!rdev
->ops
->flush_pmksa
)
9231 return rdev_flush_pmksa(rdev
, dev
);
9234 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9236 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9237 struct net_device
*dev
= info
->user_ptr
[1];
9238 u8 action_code
, dialog_token
;
9239 u32 peer_capability
= 0;
9244 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9245 !rdev
->ops
->tdls_mgmt
)
9248 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
9249 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
9250 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
9251 !info
->attrs
[NL80211_ATTR_IE
] ||
9252 !info
->attrs
[NL80211_ATTR_MAC
])
9255 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9256 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
9257 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
9258 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
9259 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
9260 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
9262 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
9264 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
9265 dialog_token
, status_code
, peer_capability
,
9267 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
9268 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
9271 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
9273 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9274 struct net_device
*dev
= info
->user_ptr
[1];
9275 enum nl80211_tdls_operation operation
;
9278 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
9279 !rdev
->ops
->tdls_oper
)
9282 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
9283 !info
->attrs
[NL80211_ATTR_MAC
])
9286 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
9287 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9289 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
9292 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
9293 struct genl_info
*info
)
9295 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9296 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9297 struct cfg80211_chan_def chandef
;
9298 const struct cfg80211_chan_def
*compat_chandef
;
9299 struct sk_buff
*msg
;
9305 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
9306 !info
->attrs
[NL80211_ATTR_DURATION
])
9309 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9311 if (!rdev
->ops
->remain_on_channel
||
9312 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
9316 * We should be on that channel for at least a minimum amount of
9317 * time (10ms) but no longer than the driver supports.
9319 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9320 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
9323 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9328 if (!cfg80211_off_channel_oper_allowed(wdev
) &&
9329 !cfg80211_chandef_identical(&wdev
->chandef
, &chandef
)) {
9330 compat_chandef
= cfg80211_chandef_compatible(&wdev
->chandef
,
9332 if (compat_chandef
!= &chandef
) {
9339 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9343 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9344 NL80211_CMD_REMAIN_ON_CHANNEL
);
9350 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
9356 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9358 goto nla_put_failure
;
9360 genlmsg_end(msg
, hdr
);
9362 return genlmsg_reply(msg
, info
);
9371 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
9372 struct genl_info
*info
)
9374 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9375 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9378 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9381 if (!rdev
->ops
->cancel_remain_on_channel
)
9384 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9386 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
9389 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
9390 struct genl_info
*info
)
9392 struct cfg80211_bitrate_mask mask
;
9393 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9394 struct net_device
*dev
= info
->user_ptr
[1];
9397 if (!rdev
->ops
->set_bitrate_mask
)
9400 err
= nl80211_parse_tx_bitrate_mask(info
, &mask
);
9404 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
9407 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9409 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9410 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9411 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
9413 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
9416 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
9417 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
9419 switch (wdev
->iftype
) {
9420 case NL80211_IFTYPE_STATION
:
9421 case NL80211_IFTYPE_ADHOC
:
9422 case NL80211_IFTYPE_P2P_CLIENT
:
9423 case NL80211_IFTYPE_AP
:
9424 case NL80211_IFTYPE_AP_VLAN
:
9425 case NL80211_IFTYPE_MESH_POINT
:
9426 case NL80211_IFTYPE_P2P_GO
:
9427 case NL80211_IFTYPE_P2P_DEVICE
:
9429 case NL80211_IFTYPE_NAN
:
9434 /* not much point in registering if we can't reply */
9435 if (!rdev
->ops
->mgmt_tx
)
9438 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
9439 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
9440 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
9443 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9445 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9446 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9447 struct cfg80211_chan_def chandef
;
9451 struct sk_buff
*msg
= NULL
;
9452 struct cfg80211_mgmt_tx_params params
= {
9453 .dont_wait_for_ack
=
9454 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
9457 if (!info
->attrs
[NL80211_ATTR_FRAME
])
9460 if (!rdev
->ops
->mgmt_tx
)
9463 switch (wdev
->iftype
) {
9464 case NL80211_IFTYPE_P2P_DEVICE
:
9465 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9467 case NL80211_IFTYPE_STATION
:
9468 case NL80211_IFTYPE_ADHOC
:
9469 case NL80211_IFTYPE_P2P_CLIENT
:
9470 case NL80211_IFTYPE_AP
:
9471 case NL80211_IFTYPE_AP_VLAN
:
9472 case NL80211_IFTYPE_MESH_POINT
:
9473 case NL80211_IFTYPE_P2P_GO
:
9475 case NL80211_IFTYPE_NAN
:
9480 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
9481 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9483 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9486 * We should wait on the channel for at least a minimum amount
9487 * of time (10ms) but no longer than the driver supports.
9489 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9490 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
9494 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
9496 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9499 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
9501 /* get the channel if any has been specified, otherwise pass NULL to
9502 * the driver. The latter will use the current one
9504 chandef
.chan
= NULL
;
9505 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9506 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9511 if (!chandef
.chan
&& params
.offchan
)
9515 if (params
.offchan
&& !cfg80211_off_channel_oper_allowed(wdev
)) {
9521 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
9522 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
9524 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
9525 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9528 if (len
% sizeof(u16
))
9531 params
.n_csa_offsets
= len
/ sizeof(u16
);
9532 params
.csa_offsets
=
9533 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9535 /* check that all the offsets fit the frame */
9536 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
9537 if (params
.csa_offsets
[i
] >= params
.len
)
9542 if (!params
.dont_wait_for_ack
) {
9543 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9547 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9555 params
.chan
= chandef
.chan
;
9556 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
9561 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9563 goto nla_put_failure
;
9565 genlmsg_end(msg
, hdr
);
9566 return genlmsg_reply(msg
, info
);
9578 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
9580 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9581 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9584 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9587 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
9590 switch (wdev
->iftype
) {
9591 case NL80211_IFTYPE_STATION
:
9592 case NL80211_IFTYPE_ADHOC
:
9593 case NL80211_IFTYPE_P2P_CLIENT
:
9594 case NL80211_IFTYPE_AP
:
9595 case NL80211_IFTYPE_AP_VLAN
:
9596 case NL80211_IFTYPE_P2P_GO
:
9597 case NL80211_IFTYPE_P2P_DEVICE
:
9599 case NL80211_IFTYPE_NAN
:
9604 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9606 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
9609 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9611 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9612 struct wireless_dev
*wdev
;
9613 struct net_device
*dev
= info
->user_ptr
[1];
9618 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
9621 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
9623 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
9626 wdev
= dev
->ieee80211_ptr
;
9628 if (!rdev
->ops
->set_power_mgmt
)
9631 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
9633 if (state
== wdev
->ps
)
9636 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
9642 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9644 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9645 enum nl80211_ps_state ps_state
;
9646 struct wireless_dev
*wdev
;
9647 struct net_device
*dev
= info
->user_ptr
[1];
9648 struct sk_buff
*msg
;
9652 wdev
= dev
->ieee80211_ptr
;
9654 if (!rdev
->ops
->set_power_mgmt
)
9657 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9661 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9662 NL80211_CMD_GET_POWER_SAVE
);
9669 ps_state
= NL80211_PS_ENABLED
;
9671 ps_state
= NL80211_PS_DISABLED
;
9673 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
9674 goto nla_put_failure
;
9676 genlmsg_end(msg
, hdr
);
9677 return genlmsg_reply(msg
, info
);
9686 static const struct nla_policy
9687 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
9688 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_BINARY
},
9689 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
9690 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
9691 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
9692 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
9693 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
9694 [NL80211_ATTR_CQM_RSSI_LEVEL
] = { .type
= NLA_S32
},
9697 static int nl80211_set_cqm_txe(struct genl_info
*info
,
9698 u32 rate
, u32 pkts
, u32 intvl
)
9700 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9701 struct net_device
*dev
= info
->user_ptr
[1];
9702 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9704 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
9707 if (!rdev
->ops
->set_cqm_txe_config
)
9710 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9711 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9714 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
9717 static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device
*rdev
,
9718 struct net_device
*dev
)
9720 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9721 s32 last
, low
, high
;
9723 int i
, n
, low_index
;
9726 /* RSSI reporting disabled? */
9727 if (!wdev
->cqm_config
)
9728 return rdev_set_cqm_rssi_range_config(rdev
, dev
, 0, 0);
9731 * Obtain current RSSI value if possible, if not and no RSSI threshold
9732 * event has been received yet, we should receive an event after a
9733 * connection is established and enough beacons received to calculate
9736 if (!wdev
->cqm_config
->last_rssi_event_value
&& wdev
->current_bss
&&
9737 rdev
->ops
->get_station
) {
9738 struct station_info sinfo
;
9741 mac_addr
= wdev
->current_bss
->pub
.bssid
;
9743 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
9747 if (sinfo
.filled
& BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG
))
9748 wdev
->cqm_config
->last_rssi_event_value
=
9749 (s8
) sinfo
.rx_beacon_signal_avg
;
9752 last
= wdev
->cqm_config
->last_rssi_event_value
;
9753 hyst
= wdev
->cqm_config
->rssi_hyst
;
9754 n
= wdev
->cqm_config
->n_rssi_thresholds
;
9756 for (i
= 0; i
< n
; i
++)
9757 if (last
< wdev
->cqm_config
->rssi_thresholds
[i
])
9761 if (low_index
>= 0) {
9762 low_index
= array_index_nospec(low_index
, n
);
9763 low
= wdev
->cqm_config
->rssi_thresholds
[low_index
] - hyst
;
9768 i
= array_index_nospec(i
, n
);
9769 high
= wdev
->cqm_config
->rssi_thresholds
[i
] + hyst
- 1;
9774 return rdev_set_cqm_rssi_range_config(rdev
, dev
, low
, high
);
9777 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
9778 const s32
*thresholds
, int n_thresholds
,
9781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9782 struct net_device
*dev
= info
->user_ptr
[1];
9783 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9787 /* Check all values negative and sorted */
9788 for (i
= 0; i
< n_thresholds
; i
++) {
9789 if (thresholds
[i
] > 0 || thresholds
[i
] <= prev
)
9792 prev
= thresholds
[i
];
9795 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9796 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9800 cfg80211_cqm_config_free(wdev
);
9803 if (n_thresholds
<= 1 && rdev
->ops
->set_cqm_rssi_config
) {
9804 if (n_thresholds
== 0 || thresholds
[0] == 0) /* Disabling */
9805 return rdev_set_cqm_rssi_config(rdev
, dev
, 0, 0);
9807 return rdev_set_cqm_rssi_config(rdev
, dev
,
9808 thresholds
[0], hysteresis
);
9811 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
9812 NL80211_EXT_FEATURE_CQM_RSSI_LIST
))
9815 if (n_thresholds
== 1 && thresholds
[0] == 0) /* Disabling */
9820 struct cfg80211_cqm_config
*cqm_config
;
9822 cqm_config
= kzalloc(sizeof(struct cfg80211_cqm_config
) +
9823 n_thresholds
* sizeof(s32
), GFP_KERNEL
);
9829 cqm_config
->rssi_hyst
= hysteresis
;
9830 cqm_config
->n_rssi_thresholds
= n_thresholds
;
9831 memcpy(cqm_config
->rssi_thresholds
, thresholds
,
9832 n_thresholds
* sizeof(s32
));
9834 wdev
->cqm_config
= cqm_config
;
9837 err
= cfg80211_cqm_rssi_update(rdev
, dev
);
9845 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
9847 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
9851 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
9855 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
9856 nl80211_attr_cqm_policy
, info
->extack
);
9860 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
9861 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
9862 const s32
*thresholds
=
9863 nla_data(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
9864 int len
= nla_len(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
9865 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
9870 return nl80211_set_cqm_rssi(info
, thresholds
, len
/ 4,
9874 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
9875 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
9876 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
9877 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
9878 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
9879 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
9881 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
9887 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9889 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9890 struct net_device
*dev
= info
->user_ptr
[1];
9891 struct ocb_setup setup
= {};
9894 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
9898 return cfg80211_join_ocb(rdev
, dev
, &setup
);
9901 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9903 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9904 struct net_device
*dev
= info
->user_ptr
[1];
9906 return cfg80211_leave_ocb(rdev
, dev
);
9909 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
9911 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9912 struct net_device
*dev
= info
->user_ptr
[1];
9913 struct mesh_config cfg
;
9914 struct mesh_setup setup
;
9917 /* start with default */
9918 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
9919 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
9921 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
9922 /* and parse parameters if given */
9923 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
9928 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
9929 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
9932 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
9933 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
9935 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
9936 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
9937 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
9940 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
9941 setup
.beacon_interval
=
9942 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
9944 err
= cfg80211_validate_beacon_int(rdev
,
9945 NL80211_IFTYPE_MESH_POINT
,
9946 setup
.beacon_interval
);
9951 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
9953 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
9954 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
9958 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
9959 /* parse additional setup parameters if given */
9960 err
= nl80211_parse_mesh_setup(info
, &setup
);
9966 cfg
.auto_open_plinks
= false;
9968 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9969 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
9973 /* cfg80211_join_mesh() will sort it out */
9974 setup
.chandef
.chan
= NULL
;
9977 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
9978 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9980 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9981 struct ieee80211_supported_band
*sband
;
9983 if (!setup
.chandef
.chan
)
9986 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
9988 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
9989 &setup
.basic_rates
);
9994 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
9995 err
= nl80211_parse_tx_bitrate_mask(info
, &setup
.beacon_rate
);
9999 if (!setup
.chandef
.chan
)
10002 err
= validate_beacon_tx_rate(rdev
, setup
.chandef
.chan
->band
,
10003 &setup
.beacon_rate
);
10008 setup
.userspace_handles_dfs
=
10009 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
10011 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
10014 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
10016 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10017 struct net_device
*dev
= info
->user_ptr
[1];
10019 return cfg80211_leave_mesh(rdev
, dev
);
10023 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
10024 struct cfg80211_registered_device
*rdev
)
10026 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
10027 struct nlattr
*nl_pats
, *nl_pat
;
10030 if (!wowlan
->n_patterns
)
10033 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
10037 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
10038 nl_pat
= nla_nest_start(msg
, i
+ 1);
10041 pat_len
= wowlan
->patterns
[i
].pattern_len
;
10042 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
10043 wowlan
->patterns
[i
].mask
) ||
10044 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
10045 wowlan
->patterns
[i
].pattern
) ||
10046 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
10047 wowlan
->patterns
[i
].pkt_offset
))
10049 nla_nest_end(msg
, nl_pat
);
10051 nla_nest_end(msg
, nl_pats
);
10056 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
10057 struct cfg80211_wowlan_tcp
*tcp
)
10059 struct nlattr
*nl_tcp
;
10064 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
10068 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
10069 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
10070 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
10071 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
10072 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
10073 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
10074 tcp
->payload_len
, tcp
->payload
) ||
10075 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
10076 tcp
->data_interval
) ||
10077 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
10078 tcp
->wake_len
, tcp
->wake_data
) ||
10079 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
10080 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
10083 if (tcp
->payload_seq
.len
&&
10084 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
10085 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
10088 if (tcp
->payload_tok
.len
&&
10089 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
10090 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
10091 &tcp
->payload_tok
))
10094 nla_nest_end(msg
, nl_tcp
);
10099 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
10100 struct cfg80211_sched_scan_request
*req
)
10102 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
10108 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
10112 if (req
->n_scan_plans
== 1 &&
10113 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
10114 req
->scan_plans
[0].interval
* 1000))
10117 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
10120 if (req
->relative_rssi_set
) {
10121 struct nl80211_bss_select_rssi_adjust rssi_adjust
;
10123 if (nla_put_s8(msg
, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI
,
10124 req
->relative_rssi
))
10127 rssi_adjust
.band
= req
->rssi_adjust
.band
;
10128 rssi_adjust
.delta
= req
->rssi_adjust
.delta
;
10129 if (nla_put(msg
, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST
,
10130 sizeof(rssi_adjust
), &rssi_adjust
))
10134 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
10138 for (i
= 0; i
< req
->n_channels
; i
++) {
10139 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
10143 nla_nest_end(msg
, freqs
);
10145 if (req
->n_match_sets
) {
10146 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
10150 for (i
= 0; i
< req
->n_match_sets
; i
++) {
10151 match
= nla_nest_start(msg
, i
);
10155 if (nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
10156 req
->match_sets
[i
].ssid
.ssid_len
,
10157 req
->match_sets
[i
].ssid
.ssid
))
10159 nla_nest_end(msg
, match
);
10161 nla_nest_end(msg
, matches
);
10164 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
10168 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
10169 scan_plan
= nla_nest_start(msg
, i
+ 1);
10174 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
10175 req
->scan_plans
[i
].interval
) ||
10176 (req
->scan_plans
[i
].iterations
&&
10177 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
10178 req
->scan_plans
[i
].iterations
)))
10180 nla_nest_end(msg
, scan_plan
);
10182 nla_nest_end(msg
, scan_plans
);
10184 nla_nest_end(msg
, nd
);
10189 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
10191 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10192 struct sk_buff
*msg
;
10194 u32 size
= NLMSG_DEFAULT_SIZE
;
10196 if (!rdev
->wiphy
.wowlan
)
10197 return -EOPNOTSUPP
;
10199 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
10200 /* adjust size to have room for all the data */
10201 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
10202 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
10203 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
10204 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
10207 msg
= nlmsg_new(size
, GFP_KERNEL
);
10211 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10212 NL80211_CMD_GET_WOWLAN
);
10214 goto nla_put_failure
;
10216 if (rdev
->wiphy
.wowlan_config
) {
10217 struct nlattr
*nl_wowlan
;
10219 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10221 goto nla_put_failure
;
10223 if ((rdev
->wiphy
.wowlan_config
->any
&&
10224 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
10225 (rdev
->wiphy
.wowlan_config
->disconnect
&&
10226 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
10227 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
10228 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
10229 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
10230 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
10231 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
10232 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
10233 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
10234 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
10235 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
10236 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
10237 goto nla_put_failure
;
10239 if (nl80211_send_wowlan_patterns(msg
, rdev
))
10240 goto nla_put_failure
;
10242 if (nl80211_send_wowlan_tcp(msg
,
10243 rdev
->wiphy
.wowlan_config
->tcp
))
10244 goto nla_put_failure
;
10246 if (nl80211_send_wowlan_nd(
10248 rdev
->wiphy
.wowlan_config
->nd_config
))
10249 goto nla_put_failure
;
10251 nla_nest_end(msg
, nl_wowlan
);
10254 genlmsg_end(msg
, hdr
);
10255 return genlmsg_reply(msg
, info
);
10262 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
10263 struct nlattr
*attr
,
10264 struct cfg80211_wowlan
*trig
)
10266 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
10267 struct cfg80211_wowlan_tcp
*cfg
;
10268 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
10269 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
10271 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
10274 if (!rdev
->wiphy
.wowlan
->tcp
)
10277 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TCP
, attr
,
10278 nl80211_wowlan_tcp_policy
, NULL
);
10282 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
10283 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
10284 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
10285 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
10286 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
10287 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
10288 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
10289 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
10292 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
10293 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
10296 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
10297 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
10298 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
10301 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
10302 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
10305 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
10306 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
10309 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
10310 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10312 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
10313 tokens_size
= tokln
- sizeof(*tok
);
10315 if (!tok
->len
|| tokens_size
% tok
->len
)
10317 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
10319 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
10321 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
10323 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
10325 if (tok
->offset
+ tok
->len
> data_size
)
10329 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
10330 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
10331 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
10333 if (seq
->len
== 0 || seq
->len
> 4)
10335 if (seq
->len
+ seq
->offset
> data_size
)
10339 size
= sizeof(*cfg
);
10341 size
+= wake_size
+ wake_mask_size
;
10342 size
+= tokens_size
;
10344 cfg
= kzalloc(size
, GFP_KERNEL
);
10347 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
10348 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
10349 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
10351 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
10352 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
10356 /* allocate a socket and port for it and use it */
10357 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
10358 IPPROTO_TCP
, &cfg
->sock
, 1);
10363 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
10364 sock_release(cfg
->sock
);
10366 return -EADDRINUSE
;
10368 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
10374 cfg
->src_port
= port
;
10377 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
10378 cfg
->payload_len
= data_size
;
10379 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
10380 memcpy((void *)cfg
->payload
,
10381 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
10384 cfg
->payload_seq
= *seq
;
10385 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
10386 cfg
->wake_len
= wake_size
;
10387 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
10388 memcpy((void *)cfg
->wake_data
,
10389 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
10391 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
10392 data_size
+ wake_size
;
10393 memcpy((void *)cfg
->wake_mask
,
10394 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
10397 cfg
->tokens_size
= tokens_size
;
10398 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
10406 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
10407 const struct wiphy_wowlan_support
*wowlan
,
10408 struct nlattr
*attr
,
10409 struct cfg80211_wowlan
*trig
)
10411 struct nlattr
**tb
;
10414 tb
= kzalloc(NUM_NL80211_ATTR
* sizeof(*tb
), GFP_KERNEL
);
10418 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
10423 err
= nla_parse_nested(tb
, NL80211_ATTR_MAX
, attr
, nl80211_policy
,
10428 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
,
10429 wowlan
->max_nd_match_sets
);
10430 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
10432 trig
->nd_config
= NULL
;
10439 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
10441 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10442 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
10443 struct cfg80211_wowlan new_triggers
= {};
10444 struct cfg80211_wowlan
*ntrig
;
10445 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
10447 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
10448 bool regular
= false;
10451 return -EOPNOTSUPP
;
10453 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
10454 cfg80211_rdev_free_wowlan(rdev
);
10455 rdev
->wiphy
.wowlan_config
= NULL
;
10459 err
= nla_parse_nested(tb
, MAX_NL80211_WOWLAN_TRIG
,
10460 info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
],
10461 nl80211_wowlan_policy
, info
->extack
);
10465 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
10466 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
10468 new_triggers
.any
= true;
10471 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
10472 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
10474 new_triggers
.disconnect
= true;
10478 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
10479 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
10481 new_triggers
.magic_pkt
= true;
10485 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
10488 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
10489 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
10491 new_triggers
.gtk_rekey_failure
= true;
10495 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
10496 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
10498 new_triggers
.eap_identity_req
= true;
10502 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
10503 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
10505 new_triggers
.four_way_handshake
= true;
10509 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
10510 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
10512 new_triggers
.rfkill_release
= true;
10516 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
10517 struct nlattr
*pat
;
10518 int n_patterns
= 0;
10519 int rem
, pat_len
, mask_len
, pkt_offset
;
10520 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
10524 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
10527 if (n_patterns
> wowlan
->n_patterns
)
10530 new_triggers
.patterns
= kcalloc(n_patterns
,
10531 sizeof(new_triggers
.patterns
[0]),
10533 if (!new_triggers
.patterns
)
10536 new_triggers
.n_patterns
= n_patterns
;
10539 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
10543 err
= nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
10544 nl80211_packet_pattern_policy
,
10550 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10551 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10553 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10554 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10555 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10557 if (pat_len
> wowlan
->pattern_max_len
||
10558 pat_len
< wowlan
->pattern_min_len
)
10561 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10564 pkt_offset
= nla_get_u32(
10565 pat_tb
[NL80211_PKTPAT_OFFSET
]);
10566 if (pkt_offset
> wowlan
->max_pkt_offset
)
10568 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
10570 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10575 new_triggers
.patterns
[i
].mask
= mask_pat
;
10576 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10578 mask_pat
+= mask_len
;
10579 new_triggers
.patterns
[i
].pattern
= mask_pat
;
10580 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
10582 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
10588 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
10590 err
= nl80211_parse_wowlan_tcp(
10591 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
10597 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
10599 err
= nl80211_parse_wowlan_nd(
10600 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
10606 /* The 'any' trigger means the device continues operating more or less
10607 * as in its normal operation mode and wakes up the host on most of the
10608 * normal interrupts (like packet RX, ...)
10609 * It therefore makes little sense to combine with the more constrained
10610 * wakeup trigger modes.
10612 if (new_triggers
.any
&& regular
) {
10617 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
10622 cfg80211_rdev_free_wowlan(rdev
);
10623 rdev
->wiphy
.wowlan_config
= ntrig
;
10626 if (rdev
->ops
->set_wakeup
&&
10627 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
10628 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
10632 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
10633 kfree(new_triggers
.patterns
[i
].mask
);
10634 kfree(new_triggers
.patterns
);
10635 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
10636 sock_release(new_triggers
.tcp
->sock
);
10637 kfree(new_triggers
.tcp
);
10638 kfree(new_triggers
.nd_config
);
10643 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
10644 struct cfg80211_registered_device
*rdev
)
10646 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
10648 struct cfg80211_coalesce_rules
*rule
;
10650 if (!rdev
->coalesce
->n_rules
)
10653 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
10657 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
10658 nl_rule
= nla_nest_start(msg
, i
+ 1);
10662 rule
= &rdev
->coalesce
->rules
[i
];
10663 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
10667 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
10671 nl_pats
= nla_nest_start(msg
,
10672 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
10676 for (j
= 0; j
< rule
->n_patterns
; j
++) {
10677 nl_pat
= nla_nest_start(msg
, j
+ 1);
10680 pat_len
= rule
->patterns
[j
].pattern_len
;
10681 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
10682 DIV_ROUND_UP(pat_len
, 8),
10683 rule
->patterns
[j
].mask
) ||
10684 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
10685 rule
->patterns
[j
].pattern
) ||
10686 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
10687 rule
->patterns
[j
].pkt_offset
))
10689 nla_nest_end(msg
, nl_pat
);
10691 nla_nest_end(msg
, nl_pats
);
10692 nla_nest_end(msg
, nl_rule
);
10694 nla_nest_end(msg
, nl_rules
);
10699 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
10701 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10702 struct sk_buff
*msg
;
10705 if (!rdev
->wiphy
.coalesce
)
10706 return -EOPNOTSUPP
;
10708 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10712 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10713 NL80211_CMD_GET_COALESCE
);
10715 goto nla_put_failure
;
10717 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
10718 goto nla_put_failure
;
10720 genlmsg_end(msg
, hdr
);
10721 return genlmsg_reply(msg
, info
);
10728 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
10730 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
10732 struct cfg80211_coalesce_rules
*rule
;
10737 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
10738 rule
= &coalesce
->rules
[i
];
10739 for (j
= 0; j
< rule
->n_patterns
; j
++)
10740 kfree(rule
->patterns
[j
].mask
);
10741 kfree(rule
->patterns
);
10743 kfree(coalesce
->rules
);
10745 rdev
->coalesce
= NULL
;
10748 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
10749 struct nlattr
*rule
,
10750 struct cfg80211_coalesce_rules
*new_rule
)
10753 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10754 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
10755 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
10756 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
10758 err
= nla_parse_nested(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, rule
,
10759 nl80211_coalesce_policy
, NULL
);
10763 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
10765 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
10766 if (new_rule
->delay
> coalesce
->max_delay
)
10769 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
10770 new_rule
->condition
=
10771 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
10772 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
10773 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
10776 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
10779 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10782 if (n_patterns
> coalesce
->n_patterns
)
10785 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
10787 if (!new_rule
->patterns
)
10790 new_rule
->n_patterns
= n_patterns
;
10793 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10797 err
= nla_parse_nested(pat_tb
, MAX_NL80211_PKTPAT
, pat
,
10798 nl80211_packet_pattern_policy
, NULL
);
10802 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10803 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10805 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10806 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10807 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10809 if (pat_len
> coalesce
->pattern_max_len
||
10810 pat_len
< coalesce
->pattern_min_len
)
10813 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10816 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
10817 if (pkt_offset
> coalesce
->max_pkt_offset
)
10819 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
10821 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10825 new_rule
->patterns
[i
].mask
= mask_pat
;
10826 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10829 mask_pat
+= mask_len
;
10830 new_rule
->patterns
[i
].pattern
= mask_pat
;
10831 new_rule
->patterns
[i
].pattern_len
= pat_len
;
10832 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
10840 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
10842 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10843 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10844 struct cfg80211_coalesce new_coalesce
= {};
10845 struct cfg80211_coalesce
*n_coalesce
;
10846 int err
, rem_rule
, n_rules
= 0, i
, j
;
10847 struct nlattr
*rule
;
10848 struct cfg80211_coalesce_rules
*tmp_rule
;
10850 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
10851 return -EOPNOTSUPP
;
10853 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
10854 cfg80211_rdev_free_coalesce(rdev
);
10855 rdev_set_coalesce(rdev
, NULL
);
10859 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10862 if (n_rules
> coalesce
->n_rules
)
10865 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
10867 if (!new_coalesce
.rules
)
10870 new_coalesce
.n_rules
= n_rules
;
10873 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10875 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
10876 &new_coalesce
.rules
[i
]);
10883 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
10887 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
10892 cfg80211_rdev_free_coalesce(rdev
);
10893 rdev
->coalesce
= n_coalesce
;
10897 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
10898 tmp_rule
= &new_coalesce
.rules
[i
];
10899 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
10900 kfree(tmp_rule
->patterns
[j
].mask
);
10901 kfree(tmp_rule
->patterns
);
10903 kfree(new_coalesce
.rules
);
10908 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
10910 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10911 struct net_device
*dev
= info
->user_ptr
[1];
10912 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10913 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
10914 struct cfg80211_gtk_rekey_data rekey_data
;
10917 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
10920 err
= nla_parse_nested(tb
, MAX_NL80211_REKEY_DATA
,
10921 info
->attrs
[NL80211_ATTR_REKEY_DATA
],
10922 nl80211_rekey_policy
, info
->extack
);
10926 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
10927 !tb
[NL80211_REKEY_DATA_KCK
])
10929 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
10931 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
10933 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
10936 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
10937 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
10938 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
10941 if (!wdev
->current_bss
) {
10946 if (!rdev
->ops
->set_rekey_data
) {
10951 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
10957 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
10958 struct genl_info
*info
)
10960 struct net_device
*dev
= info
->user_ptr
[1];
10961 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10963 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10964 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
10967 if (wdev
->ap_unexpected_nlportid
)
10970 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
10974 static int nl80211_probe_client(struct sk_buff
*skb
,
10975 struct genl_info
*info
)
10977 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10978 struct net_device
*dev
= info
->user_ptr
[1];
10979 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10980 struct sk_buff
*msg
;
10986 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10987 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
10988 return -EOPNOTSUPP
;
10990 if (!info
->attrs
[NL80211_ATTR_MAC
])
10993 if (!rdev
->ops
->probe_client
)
10994 return -EOPNOTSUPP
;
10996 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11000 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11001 NL80211_CMD_PROBE_CLIENT
);
11007 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11009 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
11013 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11015 goto nla_put_failure
;
11017 genlmsg_end(msg
, hdr
);
11019 return genlmsg_reply(msg
, info
);
11028 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
11030 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11031 struct cfg80211_beacon_registration
*reg
, *nreg
;
11034 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
11035 return -EOPNOTSUPP
;
11037 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
11041 /* First, check if already registered. */
11042 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11043 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
11044 if (reg
->nlportid
== info
->snd_portid
) {
11049 /* Add it to the list */
11050 nreg
->nlportid
= info
->snd_portid
;
11051 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
11053 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11057 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11062 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11064 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11065 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11068 if (!rdev
->ops
->start_p2p_device
)
11069 return -EOPNOTSUPP
;
11071 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11072 return -EOPNOTSUPP
;
11074 if (wdev_running(wdev
))
11077 if (rfkill_blocked(rdev
->rfkill
))
11080 err
= rdev_start_p2p_device(rdev
, wdev
);
11084 wdev
->is_running
= true;
11090 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
11092 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11093 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11095 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
11096 return -EOPNOTSUPP
;
11098 if (!rdev
->ops
->stop_p2p_device
)
11099 return -EOPNOTSUPP
;
11101 cfg80211_stop_p2p_device(rdev
, wdev
);
11106 static int nl80211_start_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11108 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11109 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11110 struct cfg80211_nan_conf conf
= {};
11113 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11114 return -EOPNOTSUPP
;
11116 if (wdev_running(wdev
))
11119 if (rfkill_blocked(rdev
->rfkill
))
11122 if (!info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
])
11126 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
11127 if (!conf
.master_pref
)
11130 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
11131 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
11133 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
11134 return -EOPNOTSUPP
;
11136 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
11139 conf
.bands
= bands
;
11142 err
= rdev_start_nan(rdev
, wdev
, &conf
);
11146 wdev
->is_running
= true;
11152 static int nl80211_stop_nan(struct sk_buff
*skb
, struct genl_info
*info
)
11154 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11155 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11157 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11158 return -EOPNOTSUPP
;
11160 cfg80211_stop_nan(rdev
, wdev
);
11165 static int validate_nan_filter(struct nlattr
*filter_attr
)
11167 struct nlattr
*attr
;
11168 int len
= 0, n_entries
= 0, rem
;
11170 nla_for_each_nested(attr
, filter_attr
, rem
) {
11171 len
+= nla_len(attr
);
11181 static int handle_nan_filter(struct nlattr
*attr_filter
,
11182 struct cfg80211_nan_func
*func
,
11185 struct nlattr
*attr
;
11186 int n_entries
, rem
, i
;
11187 struct cfg80211_nan_func_filter
*filter
;
11189 n_entries
= validate_nan_filter(attr_filter
);
11193 BUILD_BUG_ON(sizeof(*func
->rx_filters
) != sizeof(*func
->tx_filters
));
11195 filter
= kcalloc(n_entries
, sizeof(*func
->rx_filters
), GFP_KERNEL
);
11200 nla_for_each_nested(attr
, attr_filter
, rem
) {
11201 filter
[i
].filter
= nla_memdup(attr
, GFP_KERNEL
);
11202 filter
[i
].len
= nla_len(attr
);
11206 func
->num_tx_filters
= n_entries
;
11207 func
->tx_filters
= filter
;
11209 func
->num_rx_filters
= n_entries
;
11210 func
->rx_filters
= filter
;
11216 static int nl80211_nan_add_func(struct sk_buff
*skb
,
11217 struct genl_info
*info
)
11219 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11220 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11221 struct nlattr
*tb
[NUM_NL80211_NAN_FUNC_ATTR
], *func_attr
;
11222 struct cfg80211_nan_func
*func
;
11223 struct sk_buff
*msg
= NULL
;
11227 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11228 return -EOPNOTSUPP
;
11230 if (!wdev_running(wdev
))
11233 if (!info
->attrs
[NL80211_ATTR_NAN_FUNC
])
11236 err
= nla_parse_nested(tb
, NL80211_NAN_FUNC_ATTR_MAX
,
11237 info
->attrs
[NL80211_ATTR_NAN_FUNC
],
11238 nl80211_nan_func_policy
, info
->extack
);
11242 func
= kzalloc(sizeof(*func
), GFP_KERNEL
);
11246 func
->cookie
= wdev
->wiphy
->cookie_counter
++;
11248 if (!tb
[NL80211_NAN_FUNC_TYPE
] ||
11249 nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]) > NL80211_NAN_FUNC_MAX_TYPE
) {
11255 func
->type
= nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]);
11257 if (!tb
[NL80211_NAN_FUNC_SERVICE_ID
]) {
11262 memcpy(func
->service_id
, nla_data(tb
[NL80211_NAN_FUNC_SERVICE_ID
]),
11263 sizeof(func
->service_id
));
11265 func
->close_range
=
11266 nla_get_flag(tb
[NL80211_NAN_FUNC_CLOSE_RANGE
]);
11268 if (tb
[NL80211_NAN_FUNC_SERVICE_INFO
]) {
11269 func
->serv_spec_info_len
=
11270 nla_len(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]);
11271 func
->serv_spec_info
=
11272 kmemdup(nla_data(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]),
11273 func
->serv_spec_info_len
,
11275 if (!func
->serv_spec_info
) {
11281 if (tb
[NL80211_NAN_FUNC_TTL
])
11282 func
->ttl
= nla_get_u32(tb
[NL80211_NAN_FUNC_TTL
]);
11284 switch (func
->type
) {
11285 case NL80211_NAN_FUNC_PUBLISH
:
11286 if (!tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]) {
11291 func
->publish_type
=
11292 nla_get_u8(tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]);
11293 func
->publish_bcast
=
11294 nla_get_flag(tb
[NL80211_NAN_FUNC_PUBLISH_BCAST
]);
11296 if ((!(func
->publish_type
& NL80211_NAN_SOLICITED_PUBLISH
)) &&
11297 func
->publish_bcast
) {
11302 case NL80211_NAN_FUNC_SUBSCRIBE
:
11303 func
->subscribe_active
=
11304 nla_get_flag(tb
[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
]);
11306 case NL80211_NAN_FUNC_FOLLOW_UP
:
11307 if (!tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
] ||
11308 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] ||
11309 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]) {
11314 func
->followup_id
=
11315 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
]);
11316 func
->followup_reqid
=
11317 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]);
11318 memcpy(func
->followup_dest
.addr
,
11319 nla_data(tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]),
11320 sizeof(func
->followup_dest
.addr
));
11331 if (tb
[NL80211_NAN_FUNC_SRF
]) {
11332 struct nlattr
*srf_tb
[NUM_NL80211_NAN_SRF_ATTR
];
11334 err
= nla_parse_nested(srf_tb
, NL80211_NAN_SRF_ATTR_MAX
,
11335 tb
[NL80211_NAN_FUNC_SRF
],
11336 nl80211_nan_srf_policy
, info
->extack
);
11340 func
->srf_include
=
11341 nla_get_flag(srf_tb
[NL80211_NAN_SRF_INCLUDE
]);
11343 if (srf_tb
[NL80211_NAN_SRF_BF
]) {
11344 if (srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
] ||
11345 !srf_tb
[NL80211_NAN_SRF_BF_IDX
]) {
11351 nla_len(srf_tb
[NL80211_NAN_SRF_BF
]);
11353 kmemdup(nla_data(srf_tb
[NL80211_NAN_SRF_BF
]),
11354 func
->srf_bf_len
, GFP_KERNEL
);
11355 if (!func
->srf_bf
) {
11361 nla_get_u8(srf_tb
[NL80211_NAN_SRF_BF_IDX
]);
11363 struct nlattr
*attr
, *mac_attr
=
11364 srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
];
11365 int n_entries
, rem
, i
= 0;
11372 n_entries
= validate_acl_mac_addrs(mac_attr
);
11373 if (n_entries
<= 0) {
11378 func
->srf_num_macs
= n_entries
;
11380 kzalloc(sizeof(*func
->srf_macs
) * n_entries
,
11382 if (!func
->srf_macs
) {
11387 nla_for_each_nested(attr
, mac_attr
, rem
)
11388 memcpy(func
->srf_macs
[i
++].addr
, nla_data(attr
),
11389 sizeof(*func
->srf_macs
));
11393 if (tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
]) {
11394 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
],
11400 if (tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
]) {
11401 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
],
11407 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11413 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11414 NL80211_CMD_ADD_NAN_FUNCTION
);
11415 /* This can't really happen - we just allocated 4KB */
11416 if (WARN_ON(!hdr
)) {
11421 err
= rdev_add_nan_func(rdev
, wdev
, func
);
11424 cfg80211_free_nan_func(func
);
11429 /* propagate the instance id and cookie to userspace */
11430 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, func
->cookie
,
11432 goto nla_put_failure
;
11434 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
11436 goto nla_put_failure
;
11438 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
,
11439 func
->instance_id
))
11440 goto nla_put_failure
;
11442 nla_nest_end(msg
, func_attr
);
11444 genlmsg_end(msg
, hdr
);
11445 return genlmsg_reply(msg
, info
);
11452 static int nl80211_nan_del_func(struct sk_buff
*skb
,
11453 struct genl_info
*info
)
11455 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11456 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11459 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11460 return -EOPNOTSUPP
;
11462 if (!wdev_running(wdev
))
11465 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
11468 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
11470 rdev_del_nan_func(rdev
, wdev
, cookie
);
11475 static int nl80211_nan_change_config(struct sk_buff
*skb
,
11476 struct genl_info
*info
)
11478 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11479 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11480 struct cfg80211_nan_conf conf
= {};
11483 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
11484 return -EOPNOTSUPP
;
11486 if (!wdev_running(wdev
))
11489 if (info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]) {
11491 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
11492 if (conf
.master_pref
<= 1 || conf
.master_pref
== 255)
11495 changed
|= CFG80211_NAN_CONF_CHANGED_PREF
;
11498 if (info
->attrs
[NL80211_ATTR_BANDS
]) {
11499 u32 bands
= nla_get_u32(info
->attrs
[NL80211_ATTR_BANDS
]);
11501 if (bands
& ~(u32
)wdev
->wiphy
->nan_supported_bands
)
11502 return -EOPNOTSUPP
;
11504 if (bands
&& !(bands
& BIT(NL80211_BAND_2GHZ
)))
11507 conf
.bands
= bands
;
11508 changed
|= CFG80211_NAN_CONF_CHANGED_BANDS
;
11514 return rdev_nan_change_conf(rdev
, wdev
, &conf
, changed
);
11517 void cfg80211_nan_match(struct wireless_dev
*wdev
,
11518 struct cfg80211_nan_match_params
*match
, gfp_t gfp
)
11520 struct wiphy
*wiphy
= wdev
->wiphy
;
11521 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11522 struct nlattr
*match_attr
, *local_func_attr
, *peer_func_attr
;
11523 struct sk_buff
*msg
;
11526 if (WARN_ON(!match
->inst_id
|| !match
->peer_inst_id
|| !match
->addr
))
11529 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11533 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NAN_MATCH
);
11539 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11540 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11541 wdev
->netdev
->ifindex
)) ||
11542 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
11544 goto nla_put_failure
;
11546 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, match
->cookie
,
11547 NL80211_ATTR_PAD
) ||
11548 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, match
->addr
))
11549 goto nla_put_failure
;
11551 match_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_MATCH
);
11553 goto nla_put_failure
;
11555 local_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_LOCAL
);
11556 if (!local_func_attr
)
11557 goto nla_put_failure
;
11559 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->inst_id
))
11560 goto nla_put_failure
;
11562 nla_nest_end(msg
, local_func_attr
);
11564 peer_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_PEER
);
11565 if (!peer_func_attr
)
11566 goto nla_put_failure
;
11568 if (nla_put_u8(msg
, NL80211_NAN_FUNC_TYPE
, match
->type
) ||
11569 nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->peer_inst_id
))
11570 goto nla_put_failure
;
11572 if (match
->info
&& match
->info_len
&&
11573 nla_put(msg
, NL80211_NAN_FUNC_SERVICE_INFO
, match
->info_len
,
11575 goto nla_put_failure
;
11577 nla_nest_end(msg
, peer_func_attr
);
11578 nla_nest_end(msg
, match_attr
);
11579 genlmsg_end(msg
, hdr
);
11581 if (!wdev
->owner_nlportid
)
11582 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
11583 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
11585 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
11586 wdev
->owner_nlportid
);
11593 EXPORT_SYMBOL(cfg80211_nan_match
);
11595 void cfg80211_nan_func_terminated(struct wireless_dev
*wdev
,
11597 enum nl80211_nan_func_term_reason reason
,
11598 u64 cookie
, gfp_t gfp
)
11600 struct wiphy
*wiphy
= wdev
->wiphy
;
11601 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11602 struct sk_buff
*msg
;
11603 struct nlattr
*func_attr
;
11606 if (WARN_ON(!inst_id
))
11609 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11613 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION
);
11619 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11620 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11621 wdev
->netdev
->ifindex
)) ||
11622 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
11624 goto nla_put_failure
;
11626 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11628 goto nla_put_failure
;
11630 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
11632 goto nla_put_failure
;
11634 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, inst_id
) ||
11635 nla_put_u8(msg
, NL80211_NAN_FUNC_TERM_REASON
, reason
))
11636 goto nla_put_failure
;
11638 nla_nest_end(msg
, func_attr
);
11639 genlmsg_end(msg
, hdr
);
11641 if (!wdev
->owner_nlportid
)
11642 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
11643 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
11645 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
11646 wdev
->owner_nlportid
);
11653 EXPORT_SYMBOL(cfg80211_nan_func_terminated
);
11655 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
11656 struct genl_info
*info
)
11659 struct sk_buff
*msg
;
11661 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11665 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11666 NL80211_CMD_GET_PROTOCOL_FEATURES
);
11668 goto nla_put_failure
;
11670 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
11671 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
11672 goto nla_put_failure
;
11674 genlmsg_end(msg
, hdr
);
11675 return genlmsg_reply(msg
, info
);
11682 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
11684 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11685 struct cfg80211_update_ft_ies_params ft_params
;
11686 struct net_device
*dev
= info
->user_ptr
[1];
11688 if (!rdev
->ops
->update_ft_ies
)
11689 return -EOPNOTSUPP
;
11691 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
11692 !info
->attrs
[NL80211_ATTR_IE
] ||
11693 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
11696 memset(&ft_params
, 0, sizeof(ft_params
));
11697 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
11698 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
11699 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
11701 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
11704 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
11705 struct genl_info
*info
)
11707 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11708 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11709 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
11713 if (!rdev
->ops
->crit_proto_start
)
11714 return -EOPNOTSUPP
;
11716 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
11719 if (rdev
->crit_proto_nlportid
)
11722 /* determine protocol if provided */
11723 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
11724 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
11726 if (proto
>= NUM_NL80211_CRIT_PROTO
)
11729 /* timeout must be provided */
11730 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
11734 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
11736 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
11739 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
11741 rdev
->crit_proto_nlportid
= info
->snd_portid
;
11746 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
11747 struct genl_info
*info
)
11749 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11750 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11752 if (!rdev
->ops
->crit_proto_stop
)
11753 return -EOPNOTSUPP
;
11755 if (rdev
->crit_proto_nlportid
) {
11756 rdev
->crit_proto_nlportid
= 0;
11757 rdev_crit_proto_stop(rdev
, wdev
);
11762 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
11764 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11765 struct wireless_dev
*wdev
=
11766 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
11770 if (!rdev
->wiphy
.vendor_commands
)
11771 return -EOPNOTSUPP
;
11773 if (IS_ERR(wdev
)) {
11774 err
= PTR_ERR(wdev
);
11775 if (err
!= -EINVAL
)
11778 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
11782 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
11783 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
11786 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
11787 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
11788 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
11789 const struct wiphy_vendor_command
*vcmd
;
11793 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
11795 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
11798 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
11799 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
11802 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
11806 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
11807 if (!wdev_running(wdev
))
11812 return -EOPNOTSUPP
;
11817 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
11818 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
11819 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
11822 rdev
->cur_cmd_info
= info
;
11823 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
11825 rdev
->cur_cmd_info
= NULL
;
11829 return -EOPNOTSUPP
;
11832 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
11833 struct netlink_callback
*cb
,
11834 struct cfg80211_registered_device
**rdev
,
11835 struct wireless_dev
**wdev
)
11837 struct nlattr
**attrbuf
= genl_family_attrbuf(&nl80211_fam
);
11843 unsigned int data_len
= 0;
11846 /* subtract the 1 again here */
11847 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
11848 struct wireless_dev
*tmp
;
11852 *rdev
= wiphy_to_rdev(wiphy
);
11856 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
11857 if (tmp
->identifier
== cb
->args
[1] - 1) {
11864 /* keep rtnl locked in successful case */
11868 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
, attrbuf
,
11869 nl80211_fam
.maxattr
, nl80211_policy
, NULL
);
11873 if (!attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
11874 !attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
])
11877 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
11881 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
), attrbuf
);
11883 return PTR_ERR(*rdev
);
11885 vid
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_ID
]);
11886 subcmd
= nla_get_u32(attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
11888 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
11889 const struct wiphy_vendor_command
*vcmd
;
11891 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
11893 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
11897 return -EOPNOTSUPP
;
11904 return -EOPNOTSUPP
;
11906 if (attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
11907 data
= nla_data(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
11908 data_len
= nla_len(attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
11911 /* 0 is the first index - add 1 to parse only once */
11912 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
11913 /* add 1 to know if it was NULL */
11914 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
11915 cb
->args
[2] = vcmd_idx
;
11916 cb
->args
[3] = (unsigned long)data
;
11917 cb
->args
[4] = data_len
;
11919 /* keep rtnl locked in successful case */
11923 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
11924 struct netlink_callback
*cb
)
11926 struct cfg80211_registered_device
*rdev
;
11927 struct wireless_dev
*wdev
;
11928 unsigned int vcmd_idx
;
11929 const struct wiphy_vendor_command
*vcmd
;
11933 struct nlattr
*vendor_data
;
11936 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
11940 vcmd_idx
= cb
->args
[2];
11941 data
= (void *)cb
->args
[3];
11942 data_len
= cb
->args
[4];
11943 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
11945 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
11946 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
11951 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
11957 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
11958 if (!wdev_running(wdev
)) {
11966 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
11967 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
11968 NL80211_CMD_VENDOR
);
11972 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11973 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
11975 NL80211_ATTR_PAD
))) {
11976 genlmsg_cancel(skb
, hdr
);
11980 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
11981 if (!vendor_data
) {
11982 genlmsg_cancel(skb
, hdr
);
11986 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
11987 (unsigned long *)&cb
->args
[5]);
11988 nla_nest_end(skb
, vendor_data
);
11990 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
11991 genlmsg_cancel(skb
, hdr
);
11994 genlmsg_cancel(skb
, hdr
);
11998 genlmsg_end(skb
, hdr
);
12007 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
12008 enum nl80211_commands cmd
,
12009 enum nl80211_attrs attr
,
12012 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12014 if (WARN_ON(!rdev
->cur_cmd_info
))
12017 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
12018 rdev
->cur_cmd_info
->snd_portid
,
12019 rdev
->cur_cmd_info
->snd_seq
,
12020 cmd
, attr
, NULL
, GFP_KERNEL
);
12022 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
12024 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
12026 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
12027 void *hdr
= ((void **)skb
->cb
)[1];
12028 struct nlattr
*data
= ((void **)skb
->cb
)[2];
12030 /* clear CB data for netlink core to own from now on */
12031 memset(skb
->cb
, 0, sizeof(skb
->cb
));
12033 if (WARN_ON(!rdev
->cur_cmd_info
)) {
12038 nla_nest_end(skb
, data
);
12039 genlmsg_end(skb
, hdr
);
12040 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
12042 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
12044 static int nl80211_set_qos_map(struct sk_buff
*skb
,
12045 struct genl_info
*info
)
12047 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12048 struct cfg80211_qos_map
*qos_map
= NULL
;
12049 struct net_device
*dev
= info
->user_ptr
[1];
12050 u8
*pos
, len
, num_des
, des_len
, des
;
12053 if (!rdev
->ops
->set_qos_map
)
12054 return -EOPNOTSUPP
;
12056 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
12057 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12058 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
12060 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
12061 len
> IEEE80211_QOS_MAP_LEN_MAX
)
12064 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
12068 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
12070 des_len
= num_des
*
12071 sizeof(struct cfg80211_dscp_exception
);
12072 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
12073 qos_map
->num_des
= num_des
;
12074 for (des
= 0; des
< num_des
; des
++) {
12075 if (qos_map
->dscp_exception
[des
].up
> 7) {
12082 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
12085 wdev_lock(dev
->ieee80211_ptr
);
12086 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
12088 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
12089 wdev_unlock(dev
->ieee80211_ptr
);
12095 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12097 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12098 struct net_device
*dev
= info
->user_ptr
[1];
12099 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12102 u16 admitted_time
= 0;
12105 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
12106 return -EOPNOTSUPP
;
12108 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
12109 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
12112 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12113 if (tsid
>= IEEE80211_NUM_TIDS
)
12116 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
12117 if (up
>= IEEE80211_NUM_UPS
)
12120 /* WMM uses TIDs 0-7 even for TSPEC */
12121 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
12122 /* TODO: handle 802.11 TSPEC/admission control
12123 * need more attributes for that (e.g. BA session requirement);
12124 * change the WMM adminssion test above to allow both then
12129 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12131 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
12133 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
12134 if (!admitted_time
)
12139 switch (wdev
->iftype
) {
12140 case NL80211_IFTYPE_STATION
:
12141 case NL80211_IFTYPE_P2P_CLIENT
:
12142 if (wdev
->current_bss
)
12151 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
12158 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
12160 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12161 struct net_device
*dev
= info
->user_ptr
[1];
12162 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12167 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
12170 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
12171 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12174 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
12180 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
12181 struct genl_info
*info
)
12183 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12184 struct net_device
*dev
= info
->user_ptr
[1];
12185 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12186 struct cfg80211_chan_def chandef
= {};
12191 if (!rdev
->ops
->tdls_channel_switch
||
12192 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12193 return -EOPNOTSUPP
;
12195 switch (dev
->ieee80211_ptr
->iftype
) {
12196 case NL80211_IFTYPE_STATION
:
12197 case NL80211_IFTYPE_P2P_CLIENT
:
12200 return -EOPNOTSUPP
;
12203 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
12204 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
12207 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
12212 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
12213 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
12214 * specification is not defined for them.
12216 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
12217 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
12218 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
12221 /* we will be active on the TDLS link */
12222 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
12226 /* don't allow switching to DFS channels */
12227 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
12230 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12231 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
12234 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
12240 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
12241 struct genl_info
*info
)
12243 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12244 struct net_device
*dev
= info
->user_ptr
[1];
12245 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12248 if (!rdev
->ops
->tdls_channel_switch
||
12249 !rdev
->ops
->tdls_cancel_channel_switch
||
12250 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
12251 return -EOPNOTSUPP
;
12253 switch (dev
->ieee80211_ptr
->iftype
) {
12254 case NL80211_IFTYPE_STATION
:
12255 case NL80211_IFTYPE_P2P_CLIENT
:
12258 return -EOPNOTSUPP
;
12261 if (!info
->attrs
[NL80211_ATTR_MAC
])
12264 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12267 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
12273 static int nl80211_set_multicast_to_unicast(struct sk_buff
*skb
,
12274 struct genl_info
*info
)
12276 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12277 struct net_device
*dev
= info
->user_ptr
[1];
12278 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12279 const struct nlattr
*nla
;
12282 if (!rdev
->ops
->set_multicast_to_unicast
)
12283 return -EOPNOTSUPP
;
12285 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12286 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
12287 return -EOPNOTSUPP
;
12289 nla
= info
->attrs
[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED
];
12290 enabled
= nla_get_flag(nla
);
12292 return rdev_set_multicast_to_unicast(rdev
, dev
, enabled
);
12295 static int nl80211_set_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12297 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12298 struct net_device
*dev
= info
->user_ptr
[1];
12299 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12300 struct cfg80211_pmk_conf pmk_conf
= {};
12303 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12304 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12305 return -EOPNOTSUPP
;
12307 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12308 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12309 return -EOPNOTSUPP
;
12311 if (!info
->attrs
[NL80211_ATTR_MAC
] || !info
->attrs
[NL80211_ATTR_PMK
])
12315 if (!wdev
->current_bss
) {
12320 pmk_conf
.aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12321 if (memcmp(pmk_conf
.aa
, wdev
->current_bss
->pub
.bssid
, ETH_ALEN
)) {
12326 pmk_conf
.pmk
= nla_data(info
->attrs
[NL80211_ATTR_PMK
]);
12327 pmk_conf
.pmk_len
= nla_len(info
->attrs
[NL80211_ATTR_PMK
]);
12328 if (pmk_conf
.pmk_len
!= WLAN_PMK_LEN
&&
12329 pmk_conf
.pmk_len
!= WLAN_PMK_LEN_SUITE_B_192
) {
12334 if (info
->attrs
[NL80211_ATTR_PMKR0_NAME
]) {
12335 int r0_name_len
= nla_len(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12337 if (r0_name_len
!= WLAN_PMK_NAME_LEN
) {
12342 pmk_conf
.pmk_r0_name
=
12343 nla_data(info
->attrs
[NL80211_ATTR_PMKR0_NAME
]);
12346 ret
= rdev_set_pmk(rdev
, dev
, &pmk_conf
);
12352 static int nl80211_del_pmk(struct sk_buff
*skb
, struct genl_info
*info
)
12354 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
12355 struct net_device
*dev
= info
->user_ptr
[1];
12356 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12360 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
12361 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
12362 return -EOPNOTSUPP
;
12364 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
12365 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X
))
12366 return -EOPNOTSUPP
;
12368 if (!info
->attrs
[NL80211_ATTR_MAC
])
12372 aa
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
12373 ret
= rdev_del_pmk(rdev
, dev
, aa
);
12379 #define NL80211_FLAG_NEED_WIPHY 0x01
12380 #define NL80211_FLAG_NEED_NETDEV 0x02
12381 #define NL80211_FLAG_NEED_RTNL 0x04
12382 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
12383 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
12384 NL80211_FLAG_CHECK_NETDEV_UP)
12385 #define NL80211_FLAG_NEED_WDEV 0x10
12386 /* If a netdev is associated, it must be UP, P2P must be started */
12387 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
12388 NL80211_FLAG_CHECK_NETDEV_UP)
12389 #define NL80211_FLAG_CLEAR_SKB 0x20
12391 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
12392 struct genl_info
*info
)
12394 struct cfg80211_registered_device
*rdev
;
12395 struct wireless_dev
*wdev
;
12396 struct net_device
*dev
;
12397 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
12402 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
12403 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
12404 if (IS_ERR(rdev
)) {
12407 return PTR_ERR(rdev
);
12409 info
->user_ptr
[0] = rdev
;
12410 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
12411 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
12414 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
12416 if (IS_ERR(wdev
)) {
12419 return PTR_ERR(wdev
);
12422 dev
= wdev
->netdev
;
12423 rdev
= wiphy_to_rdev(wdev
->wiphy
);
12425 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
12432 info
->user_ptr
[1] = dev
;
12434 info
->user_ptr
[1] = wdev
;
12437 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
12438 !wdev_running(wdev
)) {
12447 info
->user_ptr
[0] = rdev
;
12453 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
12454 struct genl_info
*info
)
12456 if (info
->user_ptr
[1]) {
12457 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
12458 struct wireless_dev
*wdev
= info
->user_ptr
[1];
12461 dev_put(wdev
->netdev
);
12463 dev_put(info
->user_ptr
[1]);
12467 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
12470 /* If needed, clear the netlink message payload from the SKB
12471 * as it might contain key data that shouldn't stick around on
12472 * the heap after the SKB is freed. The netlink message header
12473 * is still needed for further processing, so leave it intact.
12475 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
12476 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
12478 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
12482 static const struct genl_ops nl80211_ops
[] = {
12484 .cmd
= NL80211_CMD_GET_WIPHY
,
12485 .doit
= nl80211_get_wiphy
,
12486 .dumpit
= nl80211_dump_wiphy
,
12487 .done
= nl80211_dump_wiphy_done
,
12488 .policy
= nl80211_policy
,
12489 /* can be retrieved by unprivileged users */
12490 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12491 NL80211_FLAG_NEED_RTNL
,
12494 .cmd
= NL80211_CMD_SET_WIPHY
,
12495 .doit
= nl80211_set_wiphy
,
12496 .policy
= nl80211_policy
,
12497 .flags
= GENL_UNS_ADMIN_PERM
,
12498 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12501 .cmd
= NL80211_CMD_GET_INTERFACE
,
12502 .doit
= nl80211_get_interface
,
12503 .dumpit
= nl80211_dump_interface
,
12504 .policy
= nl80211_policy
,
12505 /* can be retrieved by unprivileged users */
12506 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12507 NL80211_FLAG_NEED_RTNL
,
12510 .cmd
= NL80211_CMD_SET_INTERFACE
,
12511 .doit
= nl80211_set_interface
,
12512 .policy
= nl80211_policy
,
12513 .flags
= GENL_UNS_ADMIN_PERM
,
12514 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12515 NL80211_FLAG_NEED_RTNL
,
12518 .cmd
= NL80211_CMD_NEW_INTERFACE
,
12519 .doit
= nl80211_new_interface
,
12520 .policy
= nl80211_policy
,
12521 .flags
= GENL_UNS_ADMIN_PERM
,
12522 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12523 NL80211_FLAG_NEED_RTNL
,
12526 .cmd
= NL80211_CMD_DEL_INTERFACE
,
12527 .doit
= nl80211_del_interface
,
12528 .policy
= nl80211_policy
,
12529 .flags
= GENL_UNS_ADMIN_PERM
,
12530 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12531 NL80211_FLAG_NEED_RTNL
,
12534 .cmd
= NL80211_CMD_GET_KEY
,
12535 .doit
= nl80211_get_key
,
12536 .policy
= nl80211_policy
,
12537 .flags
= GENL_UNS_ADMIN_PERM
,
12538 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12539 NL80211_FLAG_NEED_RTNL
,
12542 .cmd
= NL80211_CMD_SET_KEY
,
12543 .doit
= nl80211_set_key
,
12544 .policy
= nl80211_policy
,
12545 .flags
= GENL_UNS_ADMIN_PERM
,
12546 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12547 NL80211_FLAG_NEED_RTNL
|
12548 NL80211_FLAG_CLEAR_SKB
,
12551 .cmd
= NL80211_CMD_NEW_KEY
,
12552 .doit
= nl80211_new_key
,
12553 .policy
= nl80211_policy
,
12554 .flags
= GENL_UNS_ADMIN_PERM
,
12555 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12556 NL80211_FLAG_NEED_RTNL
|
12557 NL80211_FLAG_CLEAR_SKB
,
12560 .cmd
= NL80211_CMD_DEL_KEY
,
12561 .doit
= nl80211_del_key
,
12562 .policy
= nl80211_policy
,
12563 .flags
= GENL_UNS_ADMIN_PERM
,
12564 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12565 NL80211_FLAG_NEED_RTNL
,
12568 .cmd
= NL80211_CMD_SET_BEACON
,
12569 .policy
= nl80211_policy
,
12570 .flags
= GENL_UNS_ADMIN_PERM
,
12571 .doit
= nl80211_set_beacon
,
12572 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12573 NL80211_FLAG_NEED_RTNL
,
12576 .cmd
= NL80211_CMD_START_AP
,
12577 .policy
= nl80211_policy
,
12578 .flags
= GENL_UNS_ADMIN_PERM
,
12579 .doit
= nl80211_start_ap
,
12580 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12581 NL80211_FLAG_NEED_RTNL
,
12584 .cmd
= NL80211_CMD_STOP_AP
,
12585 .policy
= nl80211_policy
,
12586 .flags
= GENL_UNS_ADMIN_PERM
,
12587 .doit
= nl80211_stop_ap
,
12588 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12589 NL80211_FLAG_NEED_RTNL
,
12592 .cmd
= NL80211_CMD_GET_STATION
,
12593 .doit
= nl80211_get_station
,
12594 .dumpit
= nl80211_dump_station
,
12595 .policy
= nl80211_policy
,
12596 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12597 NL80211_FLAG_NEED_RTNL
,
12600 .cmd
= NL80211_CMD_SET_STATION
,
12601 .doit
= nl80211_set_station
,
12602 .policy
= nl80211_policy
,
12603 .flags
= GENL_UNS_ADMIN_PERM
,
12604 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12605 NL80211_FLAG_NEED_RTNL
,
12608 .cmd
= NL80211_CMD_NEW_STATION
,
12609 .doit
= nl80211_new_station
,
12610 .policy
= nl80211_policy
,
12611 .flags
= GENL_UNS_ADMIN_PERM
,
12612 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12613 NL80211_FLAG_NEED_RTNL
,
12616 .cmd
= NL80211_CMD_DEL_STATION
,
12617 .doit
= nl80211_del_station
,
12618 .policy
= nl80211_policy
,
12619 .flags
= GENL_UNS_ADMIN_PERM
,
12620 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12621 NL80211_FLAG_NEED_RTNL
,
12624 .cmd
= NL80211_CMD_GET_MPATH
,
12625 .doit
= nl80211_get_mpath
,
12626 .dumpit
= nl80211_dump_mpath
,
12627 .policy
= nl80211_policy
,
12628 .flags
= GENL_UNS_ADMIN_PERM
,
12629 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12630 NL80211_FLAG_NEED_RTNL
,
12633 .cmd
= NL80211_CMD_GET_MPP
,
12634 .doit
= nl80211_get_mpp
,
12635 .dumpit
= nl80211_dump_mpp
,
12636 .policy
= nl80211_policy
,
12637 .flags
= GENL_UNS_ADMIN_PERM
,
12638 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12639 NL80211_FLAG_NEED_RTNL
,
12642 .cmd
= NL80211_CMD_SET_MPATH
,
12643 .doit
= nl80211_set_mpath
,
12644 .policy
= nl80211_policy
,
12645 .flags
= GENL_UNS_ADMIN_PERM
,
12646 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12647 NL80211_FLAG_NEED_RTNL
,
12650 .cmd
= NL80211_CMD_NEW_MPATH
,
12651 .doit
= nl80211_new_mpath
,
12652 .policy
= nl80211_policy
,
12653 .flags
= GENL_UNS_ADMIN_PERM
,
12654 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12655 NL80211_FLAG_NEED_RTNL
,
12658 .cmd
= NL80211_CMD_DEL_MPATH
,
12659 .doit
= nl80211_del_mpath
,
12660 .policy
= nl80211_policy
,
12661 .flags
= GENL_UNS_ADMIN_PERM
,
12662 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12663 NL80211_FLAG_NEED_RTNL
,
12666 .cmd
= NL80211_CMD_SET_BSS
,
12667 .doit
= nl80211_set_bss
,
12668 .policy
= nl80211_policy
,
12669 .flags
= GENL_UNS_ADMIN_PERM
,
12670 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12671 NL80211_FLAG_NEED_RTNL
,
12674 .cmd
= NL80211_CMD_GET_REG
,
12675 .doit
= nl80211_get_reg_do
,
12676 .dumpit
= nl80211_get_reg_dump
,
12677 .policy
= nl80211_policy
,
12678 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12679 /* can be retrieved by unprivileged users */
12681 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
12683 .cmd
= NL80211_CMD_SET_REG
,
12684 .doit
= nl80211_set_reg
,
12685 .policy
= nl80211_policy
,
12686 .flags
= GENL_ADMIN_PERM
,
12687 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12691 .cmd
= NL80211_CMD_REQ_SET_REG
,
12692 .doit
= nl80211_req_set_reg
,
12693 .policy
= nl80211_policy
,
12694 .flags
= GENL_ADMIN_PERM
,
12697 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
12698 .doit
= nl80211_get_mesh_config
,
12699 .policy
= nl80211_policy
,
12700 /* can be retrieved by unprivileged users */
12701 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12702 NL80211_FLAG_NEED_RTNL
,
12705 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
12706 .doit
= nl80211_update_mesh_config
,
12707 .policy
= nl80211_policy
,
12708 .flags
= GENL_UNS_ADMIN_PERM
,
12709 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12710 NL80211_FLAG_NEED_RTNL
,
12713 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
12714 .doit
= nl80211_trigger_scan
,
12715 .policy
= nl80211_policy
,
12716 .flags
= GENL_UNS_ADMIN_PERM
,
12717 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12718 NL80211_FLAG_NEED_RTNL
,
12721 .cmd
= NL80211_CMD_ABORT_SCAN
,
12722 .doit
= nl80211_abort_scan
,
12723 .policy
= nl80211_policy
,
12724 .flags
= GENL_UNS_ADMIN_PERM
,
12725 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12726 NL80211_FLAG_NEED_RTNL
,
12729 .cmd
= NL80211_CMD_GET_SCAN
,
12730 .policy
= nl80211_policy
,
12731 .dumpit
= nl80211_dump_scan
,
12734 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
12735 .doit
= nl80211_start_sched_scan
,
12736 .policy
= nl80211_policy
,
12737 .flags
= GENL_UNS_ADMIN_PERM
,
12738 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12739 NL80211_FLAG_NEED_RTNL
,
12742 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
12743 .doit
= nl80211_stop_sched_scan
,
12744 .policy
= nl80211_policy
,
12745 .flags
= GENL_UNS_ADMIN_PERM
,
12746 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12747 NL80211_FLAG_NEED_RTNL
,
12750 .cmd
= NL80211_CMD_AUTHENTICATE
,
12751 .doit
= nl80211_authenticate
,
12752 .policy
= nl80211_policy
,
12753 .flags
= GENL_UNS_ADMIN_PERM
,
12754 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12755 NL80211_FLAG_NEED_RTNL
|
12756 NL80211_FLAG_CLEAR_SKB
,
12759 .cmd
= NL80211_CMD_ASSOCIATE
,
12760 .doit
= nl80211_associate
,
12761 .policy
= nl80211_policy
,
12762 .flags
= GENL_UNS_ADMIN_PERM
,
12763 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12764 NL80211_FLAG_NEED_RTNL
,
12767 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
12768 .doit
= nl80211_deauthenticate
,
12769 .policy
= nl80211_policy
,
12770 .flags
= GENL_UNS_ADMIN_PERM
,
12771 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12772 NL80211_FLAG_NEED_RTNL
,
12775 .cmd
= NL80211_CMD_DISASSOCIATE
,
12776 .doit
= nl80211_disassociate
,
12777 .policy
= nl80211_policy
,
12778 .flags
= GENL_UNS_ADMIN_PERM
,
12779 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12780 NL80211_FLAG_NEED_RTNL
,
12783 .cmd
= NL80211_CMD_JOIN_IBSS
,
12784 .doit
= nl80211_join_ibss
,
12785 .policy
= nl80211_policy
,
12786 .flags
= GENL_UNS_ADMIN_PERM
,
12787 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12788 NL80211_FLAG_NEED_RTNL
,
12791 .cmd
= NL80211_CMD_LEAVE_IBSS
,
12792 .doit
= nl80211_leave_ibss
,
12793 .policy
= nl80211_policy
,
12794 .flags
= GENL_UNS_ADMIN_PERM
,
12795 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12796 NL80211_FLAG_NEED_RTNL
,
12798 #ifdef CONFIG_NL80211_TESTMODE
12800 .cmd
= NL80211_CMD_TESTMODE
,
12801 .doit
= nl80211_testmode_do
,
12802 .dumpit
= nl80211_testmode_dump
,
12803 .policy
= nl80211_policy
,
12804 .flags
= GENL_UNS_ADMIN_PERM
,
12805 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12806 NL80211_FLAG_NEED_RTNL
,
12810 .cmd
= NL80211_CMD_CONNECT
,
12811 .doit
= nl80211_connect
,
12812 .policy
= nl80211_policy
,
12813 .flags
= GENL_UNS_ADMIN_PERM
,
12814 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12815 NL80211_FLAG_NEED_RTNL
,
12818 .cmd
= NL80211_CMD_UPDATE_CONNECT_PARAMS
,
12819 .doit
= nl80211_update_connect_params
,
12820 .policy
= nl80211_policy
,
12821 .flags
= GENL_ADMIN_PERM
,
12822 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12823 NL80211_FLAG_NEED_RTNL
,
12826 .cmd
= NL80211_CMD_DISCONNECT
,
12827 .doit
= nl80211_disconnect
,
12828 .policy
= nl80211_policy
,
12829 .flags
= GENL_UNS_ADMIN_PERM
,
12830 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12831 NL80211_FLAG_NEED_RTNL
,
12834 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
12835 .doit
= nl80211_wiphy_netns
,
12836 .policy
= nl80211_policy
,
12837 .flags
= GENL_UNS_ADMIN_PERM
,
12838 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12839 NL80211_FLAG_NEED_RTNL
,
12842 .cmd
= NL80211_CMD_GET_SURVEY
,
12843 .policy
= nl80211_policy
,
12844 .dumpit
= nl80211_dump_survey
,
12847 .cmd
= NL80211_CMD_SET_PMKSA
,
12848 .doit
= nl80211_setdel_pmksa
,
12849 .policy
= nl80211_policy
,
12850 .flags
= GENL_UNS_ADMIN_PERM
,
12851 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12852 NL80211_FLAG_NEED_RTNL
,
12855 .cmd
= NL80211_CMD_DEL_PMKSA
,
12856 .doit
= nl80211_setdel_pmksa
,
12857 .policy
= nl80211_policy
,
12858 .flags
= GENL_UNS_ADMIN_PERM
,
12859 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12860 NL80211_FLAG_NEED_RTNL
,
12863 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
12864 .doit
= nl80211_flush_pmksa
,
12865 .policy
= nl80211_policy
,
12866 .flags
= GENL_UNS_ADMIN_PERM
,
12867 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12868 NL80211_FLAG_NEED_RTNL
,
12871 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
12872 .doit
= nl80211_remain_on_channel
,
12873 .policy
= nl80211_policy
,
12874 .flags
= GENL_UNS_ADMIN_PERM
,
12875 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12876 NL80211_FLAG_NEED_RTNL
,
12879 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
12880 .doit
= nl80211_cancel_remain_on_channel
,
12881 .policy
= nl80211_policy
,
12882 .flags
= GENL_UNS_ADMIN_PERM
,
12883 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12884 NL80211_FLAG_NEED_RTNL
,
12887 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
12888 .doit
= nl80211_set_tx_bitrate_mask
,
12889 .policy
= nl80211_policy
,
12890 .flags
= GENL_UNS_ADMIN_PERM
,
12891 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12892 NL80211_FLAG_NEED_RTNL
,
12895 .cmd
= NL80211_CMD_REGISTER_FRAME
,
12896 .doit
= nl80211_register_mgmt
,
12897 .policy
= nl80211_policy
,
12898 .flags
= GENL_UNS_ADMIN_PERM
,
12899 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12900 NL80211_FLAG_NEED_RTNL
,
12903 .cmd
= NL80211_CMD_FRAME
,
12904 .doit
= nl80211_tx_mgmt
,
12905 .policy
= nl80211_policy
,
12906 .flags
= GENL_UNS_ADMIN_PERM
,
12907 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12908 NL80211_FLAG_NEED_RTNL
,
12911 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
12912 .doit
= nl80211_tx_mgmt_cancel_wait
,
12913 .policy
= nl80211_policy
,
12914 .flags
= GENL_UNS_ADMIN_PERM
,
12915 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12916 NL80211_FLAG_NEED_RTNL
,
12919 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
12920 .doit
= nl80211_set_power_save
,
12921 .policy
= nl80211_policy
,
12922 .flags
= GENL_UNS_ADMIN_PERM
,
12923 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12924 NL80211_FLAG_NEED_RTNL
,
12927 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
12928 .doit
= nl80211_get_power_save
,
12929 .policy
= nl80211_policy
,
12930 /* can be retrieved by unprivileged users */
12931 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12932 NL80211_FLAG_NEED_RTNL
,
12935 .cmd
= NL80211_CMD_SET_CQM
,
12936 .doit
= nl80211_set_cqm
,
12937 .policy
= nl80211_policy
,
12938 .flags
= GENL_UNS_ADMIN_PERM
,
12939 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12940 NL80211_FLAG_NEED_RTNL
,
12943 .cmd
= NL80211_CMD_SET_CHANNEL
,
12944 .doit
= nl80211_set_channel
,
12945 .policy
= nl80211_policy
,
12946 .flags
= GENL_UNS_ADMIN_PERM
,
12947 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12948 NL80211_FLAG_NEED_RTNL
,
12951 .cmd
= NL80211_CMD_SET_WDS_PEER
,
12952 .doit
= nl80211_set_wds_peer
,
12953 .policy
= nl80211_policy
,
12954 .flags
= GENL_UNS_ADMIN_PERM
,
12955 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12956 NL80211_FLAG_NEED_RTNL
,
12959 .cmd
= NL80211_CMD_JOIN_MESH
,
12960 .doit
= nl80211_join_mesh
,
12961 .policy
= nl80211_policy
,
12962 .flags
= GENL_UNS_ADMIN_PERM
,
12963 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12964 NL80211_FLAG_NEED_RTNL
,
12967 .cmd
= NL80211_CMD_LEAVE_MESH
,
12968 .doit
= nl80211_leave_mesh
,
12969 .policy
= nl80211_policy
,
12970 .flags
= GENL_UNS_ADMIN_PERM
,
12971 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12972 NL80211_FLAG_NEED_RTNL
,
12975 .cmd
= NL80211_CMD_JOIN_OCB
,
12976 .doit
= nl80211_join_ocb
,
12977 .policy
= nl80211_policy
,
12978 .flags
= GENL_UNS_ADMIN_PERM
,
12979 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12980 NL80211_FLAG_NEED_RTNL
,
12983 .cmd
= NL80211_CMD_LEAVE_OCB
,
12984 .doit
= nl80211_leave_ocb
,
12985 .policy
= nl80211_policy
,
12986 .flags
= GENL_UNS_ADMIN_PERM
,
12987 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12988 NL80211_FLAG_NEED_RTNL
,
12992 .cmd
= NL80211_CMD_GET_WOWLAN
,
12993 .doit
= nl80211_get_wowlan
,
12994 .policy
= nl80211_policy
,
12995 /* can be retrieved by unprivileged users */
12996 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12997 NL80211_FLAG_NEED_RTNL
,
13000 .cmd
= NL80211_CMD_SET_WOWLAN
,
13001 .doit
= nl80211_set_wowlan
,
13002 .policy
= nl80211_policy
,
13003 .flags
= GENL_UNS_ADMIN_PERM
,
13004 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13005 NL80211_FLAG_NEED_RTNL
,
13009 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
13010 .doit
= nl80211_set_rekey_data
,
13011 .policy
= nl80211_policy
,
13012 .flags
= GENL_UNS_ADMIN_PERM
,
13013 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13014 NL80211_FLAG_NEED_RTNL
|
13015 NL80211_FLAG_CLEAR_SKB
,
13018 .cmd
= NL80211_CMD_TDLS_MGMT
,
13019 .doit
= nl80211_tdls_mgmt
,
13020 .policy
= nl80211_policy
,
13021 .flags
= GENL_UNS_ADMIN_PERM
,
13022 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13023 NL80211_FLAG_NEED_RTNL
,
13026 .cmd
= NL80211_CMD_TDLS_OPER
,
13027 .doit
= nl80211_tdls_oper
,
13028 .policy
= nl80211_policy
,
13029 .flags
= GENL_UNS_ADMIN_PERM
,
13030 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13031 NL80211_FLAG_NEED_RTNL
,
13034 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
13035 .doit
= nl80211_register_unexpected_frame
,
13036 .policy
= nl80211_policy
,
13037 .flags
= GENL_UNS_ADMIN_PERM
,
13038 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13039 NL80211_FLAG_NEED_RTNL
,
13042 .cmd
= NL80211_CMD_PROBE_CLIENT
,
13043 .doit
= nl80211_probe_client
,
13044 .policy
= nl80211_policy
,
13045 .flags
= GENL_UNS_ADMIN_PERM
,
13046 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13047 NL80211_FLAG_NEED_RTNL
,
13050 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
13051 .doit
= nl80211_register_beacons
,
13052 .policy
= nl80211_policy
,
13053 .flags
= GENL_UNS_ADMIN_PERM
,
13054 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13055 NL80211_FLAG_NEED_RTNL
,
13058 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
13059 .doit
= nl80211_set_noack_map
,
13060 .policy
= nl80211_policy
,
13061 .flags
= GENL_UNS_ADMIN_PERM
,
13062 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13063 NL80211_FLAG_NEED_RTNL
,
13066 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
13067 .doit
= nl80211_start_p2p_device
,
13068 .policy
= nl80211_policy
,
13069 .flags
= GENL_UNS_ADMIN_PERM
,
13070 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13071 NL80211_FLAG_NEED_RTNL
,
13074 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
13075 .doit
= nl80211_stop_p2p_device
,
13076 .policy
= nl80211_policy
,
13077 .flags
= GENL_UNS_ADMIN_PERM
,
13078 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13079 NL80211_FLAG_NEED_RTNL
,
13082 .cmd
= NL80211_CMD_START_NAN
,
13083 .doit
= nl80211_start_nan
,
13084 .policy
= nl80211_policy
,
13085 .flags
= GENL_ADMIN_PERM
,
13086 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
13087 NL80211_FLAG_NEED_RTNL
,
13090 .cmd
= NL80211_CMD_STOP_NAN
,
13091 .doit
= nl80211_stop_nan
,
13092 .policy
= nl80211_policy
,
13093 .flags
= GENL_ADMIN_PERM
,
13094 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13095 NL80211_FLAG_NEED_RTNL
,
13098 .cmd
= NL80211_CMD_ADD_NAN_FUNCTION
,
13099 .doit
= nl80211_nan_add_func
,
13100 .policy
= nl80211_policy
,
13101 .flags
= GENL_ADMIN_PERM
,
13102 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13103 NL80211_FLAG_NEED_RTNL
,
13106 .cmd
= NL80211_CMD_DEL_NAN_FUNCTION
,
13107 .doit
= nl80211_nan_del_func
,
13108 .policy
= nl80211_policy
,
13109 .flags
= GENL_ADMIN_PERM
,
13110 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13111 NL80211_FLAG_NEED_RTNL
,
13114 .cmd
= NL80211_CMD_CHANGE_NAN_CONFIG
,
13115 .doit
= nl80211_nan_change_config
,
13116 .policy
= nl80211_policy
,
13117 .flags
= GENL_ADMIN_PERM
,
13118 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13119 NL80211_FLAG_NEED_RTNL
,
13122 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
13123 .doit
= nl80211_set_mcast_rate
,
13124 .policy
= nl80211_policy
,
13125 .flags
= GENL_UNS_ADMIN_PERM
,
13126 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13127 NL80211_FLAG_NEED_RTNL
,
13130 .cmd
= NL80211_CMD_SET_MAC_ACL
,
13131 .doit
= nl80211_set_mac_acl
,
13132 .policy
= nl80211_policy
,
13133 .flags
= GENL_UNS_ADMIN_PERM
,
13134 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13135 NL80211_FLAG_NEED_RTNL
,
13138 .cmd
= NL80211_CMD_RADAR_DETECT
,
13139 .doit
= nl80211_start_radar_detection
,
13140 .policy
= nl80211_policy
,
13141 .flags
= GENL_UNS_ADMIN_PERM
,
13142 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13143 NL80211_FLAG_NEED_RTNL
,
13146 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
13147 .doit
= nl80211_get_protocol_features
,
13148 .policy
= nl80211_policy
,
13151 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
13152 .doit
= nl80211_update_ft_ies
,
13153 .policy
= nl80211_policy
,
13154 .flags
= GENL_UNS_ADMIN_PERM
,
13155 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13156 NL80211_FLAG_NEED_RTNL
,
13159 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
13160 .doit
= nl80211_crit_protocol_start
,
13161 .policy
= nl80211_policy
,
13162 .flags
= GENL_UNS_ADMIN_PERM
,
13163 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
13164 NL80211_FLAG_NEED_RTNL
,
13167 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
13168 .doit
= nl80211_crit_protocol_stop
,
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_GET_COALESCE
,
13176 .doit
= nl80211_get_coalesce
,
13177 .policy
= nl80211_policy
,
13178 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13179 NL80211_FLAG_NEED_RTNL
,
13182 .cmd
= NL80211_CMD_SET_COALESCE
,
13183 .doit
= nl80211_set_coalesce
,
13184 .policy
= nl80211_policy
,
13185 .flags
= GENL_UNS_ADMIN_PERM
,
13186 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13187 NL80211_FLAG_NEED_RTNL
,
13190 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
13191 .doit
= nl80211_channel_switch
,
13192 .policy
= nl80211_policy
,
13193 .flags
= GENL_UNS_ADMIN_PERM
,
13194 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13195 NL80211_FLAG_NEED_RTNL
,
13198 .cmd
= NL80211_CMD_VENDOR
,
13199 .doit
= nl80211_vendor_cmd
,
13200 .dumpit
= nl80211_vendor_cmd_dump
,
13201 .policy
= nl80211_policy
,
13202 .flags
= GENL_UNS_ADMIN_PERM
,
13203 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
13204 NL80211_FLAG_NEED_RTNL
,
13207 .cmd
= NL80211_CMD_SET_QOS_MAP
,
13208 .doit
= nl80211_set_qos_map
,
13209 .policy
= nl80211_policy
,
13210 .flags
= GENL_UNS_ADMIN_PERM
,
13211 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13212 NL80211_FLAG_NEED_RTNL
,
13215 .cmd
= NL80211_CMD_ADD_TX_TS
,
13216 .doit
= nl80211_add_tx_ts
,
13217 .policy
= nl80211_policy
,
13218 .flags
= GENL_UNS_ADMIN_PERM
,
13219 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13220 NL80211_FLAG_NEED_RTNL
,
13223 .cmd
= NL80211_CMD_DEL_TX_TS
,
13224 .doit
= nl80211_del_tx_ts
,
13225 .policy
= nl80211_policy
,
13226 .flags
= GENL_UNS_ADMIN_PERM
,
13227 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13228 NL80211_FLAG_NEED_RTNL
,
13231 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
13232 .doit
= nl80211_tdls_channel_switch
,
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_TDLS_CANCEL_CHANNEL_SWITCH
,
13240 .doit
= nl80211_tdls_cancel_channel_switch
,
13241 .policy
= nl80211_policy
,
13242 .flags
= GENL_UNS_ADMIN_PERM
,
13243 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13244 NL80211_FLAG_NEED_RTNL
,
13247 .cmd
= NL80211_CMD_SET_MULTICAST_TO_UNICAST
,
13248 .doit
= nl80211_set_multicast_to_unicast
,
13249 .policy
= nl80211_policy
,
13250 .flags
= GENL_UNS_ADMIN_PERM
,
13251 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
13252 NL80211_FLAG_NEED_RTNL
,
13255 .cmd
= NL80211_CMD_SET_PMK
,
13256 .doit
= nl80211_set_pmk
,
13257 .policy
= nl80211_policy
,
13258 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13259 NL80211_FLAG_NEED_RTNL
,
13262 .cmd
= NL80211_CMD_DEL_PMK
,
13263 .doit
= nl80211_del_pmk
,
13264 .policy
= nl80211_policy
,
13265 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
13266 NL80211_FLAG_NEED_RTNL
,
13271 static struct genl_family nl80211_fam __ro_after_init
= {
13272 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
13273 .hdrsize
= 0, /* no private header */
13274 .version
= 1, /* no particular meaning now */
13275 .maxattr
= NL80211_ATTR_MAX
,
13277 .pre_doit
= nl80211_pre_doit
,
13278 .post_doit
= nl80211_post_doit
,
13279 .module
= THIS_MODULE
,
13280 .ops
= nl80211_ops
,
13281 .n_ops
= ARRAY_SIZE(nl80211_ops
),
13282 .mcgrps
= nl80211_mcgrps
,
13283 .n_mcgrps
= ARRAY_SIZE(nl80211_mcgrps
),
13286 /* notification functions */
13288 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
13289 enum nl80211_commands cmd
)
13291 struct sk_buff
*msg
;
13292 struct nl80211_dump_wiphy_state state
= {};
13294 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
13295 cmd
!= NL80211_CMD_DEL_WIPHY
);
13297 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13301 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
13306 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13307 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
13310 void nl80211_notify_iface(struct cfg80211_registered_device
*rdev
,
13311 struct wireless_dev
*wdev
,
13312 enum nl80211_commands cmd
)
13314 struct sk_buff
*msg
;
13316 WARN_ON(cmd
!= NL80211_CMD_NEW_INTERFACE
&&
13317 cmd
!= NL80211_CMD_DEL_INTERFACE
);
13319 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13323 if (nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
,
13324 cmd
== NL80211_CMD_DEL_INTERFACE
) < 0) {
13329 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13330 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
13333 static int nl80211_add_scan_req(struct sk_buff
*msg
,
13334 struct cfg80211_registered_device
*rdev
)
13336 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
13337 struct nlattr
*nest
;
13343 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
13345 goto nla_put_failure
;
13346 for (i
= 0; i
< req
->n_ssids
; i
++) {
13347 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
13348 goto nla_put_failure
;
13350 nla_nest_end(msg
, nest
);
13352 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
13354 goto nla_put_failure
;
13355 for (i
= 0; i
< req
->n_channels
; i
++) {
13356 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
13357 goto nla_put_failure
;
13359 nla_nest_end(msg
, nest
);
13362 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
13363 goto nla_put_failure
;
13366 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
13367 goto nla_put_failure
;
13369 if (req
->info
.scan_start_tsf
&&
13370 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
13371 req
->info
.scan_start_tsf
, NL80211_BSS_PAD
) ||
13372 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
13373 req
->info
.tsf_bssid
)))
13374 goto nla_put_failure
;
13381 static int nl80211_prep_scan_msg(struct sk_buff
*msg
,
13382 struct cfg80211_registered_device
*rdev
,
13383 struct wireless_dev
*wdev
,
13384 u32 portid
, u32 seq
, int flags
,
13389 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
13393 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13394 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13395 wdev
->netdev
->ifindex
)) ||
13396 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13398 goto nla_put_failure
;
13400 /* ignore errors and send incomplete event anyway */
13401 nl80211_add_scan_req(msg
, rdev
);
13403 genlmsg_end(msg
, hdr
);
13407 genlmsg_cancel(msg
, hdr
);
13412 nl80211_prep_sched_scan_msg(struct sk_buff
*msg
,
13413 struct cfg80211_sched_scan_request
*req
, u32 cmd
)
13417 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13421 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
,
13422 wiphy_to_rdev(req
->wiphy
)->wiphy_idx
) ||
13423 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, req
->dev
->ifindex
) ||
13424 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, req
->reqid
,
13426 goto nla_put_failure
;
13428 genlmsg_end(msg
, hdr
);
13432 genlmsg_cancel(msg
, hdr
);
13436 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
13437 struct wireless_dev
*wdev
)
13439 struct sk_buff
*msg
;
13441 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13445 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
13446 NL80211_CMD_TRIGGER_SCAN
) < 0) {
13451 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13452 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
13455 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
13456 struct wireless_dev
*wdev
, bool aborted
)
13458 struct sk_buff
*msg
;
13460 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13464 if (nl80211_prep_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
13465 aborted
? NL80211_CMD_SCAN_ABORTED
:
13466 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
13474 /* send message created by nl80211_build_scan_msg() */
13475 void nl80211_send_scan_msg(struct cfg80211_registered_device
*rdev
,
13476 struct sk_buff
*msg
)
13481 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13482 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
13485 void nl80211_send_sched_scan(struct cfg80211_sched_scan_request
*req
, u32 cmd
)
13487 struct sk_buff
*msg
;
13489 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13493 if (nl80211_prep_sched_scan_msg(msg
, req
, cmd
) < 0) {
13498 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(req
->wiphy
), msg
, 0,
13499 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
13502 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
13503 struct regulatory_request
*request
)
13505 /* Userspace can always count this one always being set */
13506 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
13507 goto nla_put_failure
;
13509 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
13510 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13511 NL80211_REGDOM_TYPE_WORLD
))
13512 goto nla_put_failure
;
13513 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
13514 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13515 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
13516 goto nla_put_failure
;
13517 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
13518 request
->intersect
) {
13519 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13520 NL80211_REGDOM_TYPE_INTERSECTION
))
13521 goto nla_put_failure
;
13523 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
13524 NL80211_REGDOM_TYPE_COUNTRY
) ||
13525 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
13527 goto nla_put_failure
;
13530 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
13531 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
13534 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
13535 goto nla_put_failure
;
13538 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
13539 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
13540 goto nla_put_failure
;
13550 * This can happen on global regulatory changes or device specific settings
13551 * based on custom regulatory domains.
13553 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
13554 struct regulatory_request
*request
)
13556 struct sk_buff
*msg
;
13559 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13563 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
13569 if (nl80211_reg_change_event_fill(msg
, request
) == false)
13570 goto nla_put_failure
;
13572 genlmsg_end(msg
, hdr
);
13575 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
13576 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
13582 genlmsg_cancel(msg
, hdr
);
13586 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
13587 struct net_device
*netdev
,
13588 const u8
*buf
, size_t len
,
13589 enum nl80211_commands cmd
, gfp_t gfp
,
13592 struct sk_buff
*msg
;
13595 msg
= nlmsg_new(100 + len
, gfp
);
13599 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13605 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13606 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13607 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
13608 goto nla_put_failure
;
13610 if (uapsd_queues
>= 0) {
13611 struct nlattr
*nla_wmm
=
13612 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
13614 goto nla_put_failure
;
13616 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
13618 goto nla_put_failure
;
13620 nla_nest_end(msg
, nla_wmm
);
13623 genlmsg_end(msg
, hdr
);
13625 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13626 NL80211_MCGRP_MLME
, gfp
);
13630 genlmsg_cancel(msg
, hdr
);
13634 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
13635 struct net_device
*netdev
, const u8
*buf
,
13636 size_t len
, gfp_t gfp
)
13638 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13639 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
13642 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
13643 struct net_device
*netdev
, const u8
*buf
,
13644 size_t len
, gfp_t gfp
, int uapsd_queues
)
13646 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13647 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
13650 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
13651 struct net_device
*netdev
, const u8
*buf
,
13652 size_t len
, gfp_t gfp
)
13654 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13655 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
13658 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
13659 struct net_device
*netdev
, const u8
*buf
,
13660 size_t len
, gfp_t gfp
)
13662 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
13663 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
13666 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
13669 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13670 struct wiphy
*wiphy
= wdev
->wiphy
;
13671 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13672 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
13675 if (WARN_ON(len
< 2))
13678 if (ieee80211_is_deauth(mgmt
->frame_control
))
13679 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
13681 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
13683 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
13684 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
13686 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
13688 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
13689 struct net_device
*netdev
, int cmd
,
13690 const u8
*addr
, gfp_t gfp
)
13692 struct sk_buff
*msg
;
13695 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13699 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13705 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13706 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13707 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
13708 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
13709 goto nla_put_failure
;
13711 genlmsg_end(msg
, hdr
);
13713 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13714 NL80211_MCGRP_MLME
, gfp
);
13718 genlmsg_cancel(msg
, hdr
);
13722 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
13723 struct net_device
*netdev
, const u8
*addr
,
13726 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
13730 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
13731 struct net_device
*netdev
, const u8
*addr
,
13734 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
13738 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
13739 struct net_device
*netdev
,
13740 struct cfg80211_connect_resp_params
*cr
,
13743 struct sk_buff
*msg
;
13746 msg
= nlmsg_new(100 + cr
->req_ie_len
+ cr
->resp_ie_len
+
13747 cr
->fils_kek_len
+ cr
->pmk_len
+
13748 (cr
->pmkid
? WLAN_PMKID_LEN
: 0), gfp
);
13752 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
13758 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13759 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13761 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, cr
->bssid
)) ||
13762 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
13763 cr
->status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
13766 (nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
13767 nla_put_u32(msg
, NL80211_ATTR_TIMEOUT_REASON
,
13768 cr
->timeout_reason
))) ||
13770 nla_put(msg
, NL80211_ATTR_REQ_IE
, cr
->req_ie_len
, cr
->req_ie
)) ||
13772 nla_put(msg
, NL80211_ATTR_RESP_IE
, cr
->resp_ie_len
,
13774 (cr
->update_erp_next_seq_num
&&
13775 nla_put_u16(msg
, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM
,
13776 cr
->fils_erp_next_seq_num
)) ||
13777 (cr
->status
== WLAN_STATUS_SUCCESS
&&
13779 nla_put(msg
, NL80211_ATTR_FILS_KEK
, cr
->fils_kek_len
,
13782 nla_put(msg
, NL80211_ATTR_PMK
, cr
->pmk_len
, cr
->pmk
)) ||
13784 nla_put(msg
, NL80211_ATTR_PMKID
, WLAN_PMKID_LEN
, cr
->pmkid
)))))
13785 goto nla_put_failure
;
13787 genlmsg_end(msg
, hdr
);
13789 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13790 NL80211_MCGRP_MLME
, gfp
);
13794 genlmsg_cancel(msg
, hdr
);
13798 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
13799 struct net_device
*netdev
,
13800 struct cfg80211_roam_info
*info
, gfp_t gfp
)
13802 struct sk_buff
*msg
;
13804 const u8
*bssid
= info
->bss
? info
->bss
->bssid
: info
->bssid
;
13806 msg
= nlmsg_new(100 + info
->req_ie_len
+ info
->resp_ie_len
, gfp
);
13810 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
13816 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13817 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13818 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
13820 nla_put(msg
, NL80211_ATTR_REQ_IE
, info
->req_ie_len
,
13823 nla_put(msg
, NL80211_ATTR_RESP_IE
, info
->resp_ie_len
,
13825 (info
->authorized
&&
13826 nla_put_flag(msg
, NL80211_ATTR_PORT_AUTHORIZED
)))
13827 goto nla_put_failure
;
13829 genlmsg_end(msg
, hdr
);
13831 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13832 NL80211_MCGRP_MLME
, gfp
);
13836 genlmsg_cancel(msg
, hdr
);
13840 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
13841 struct net_device
*netdev
, u16 reason
,
13842 const u8
*ie
, size_t ie_len
, bool from_ap
)
13844 struct sk_buff
*msg
;
13847 msg
= nlmsg_new(100 + ie_len
, GFP_KERNEL
);
13851 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
13857 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13858 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13859 (from_ap
&& reason
&&
13860 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
13862 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
13863 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
13864 goto nla_put_failure
;
13866 genlmsg_end(msg
, hdr
);
13868 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13869 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13873 genlmsg_cancel(msg
, hdr
);
13877 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
13878 struct net_device
*netdev
, const u8
*bssid
,
13881 struct sk_buff
*msg
;
13884 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13888 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
13894 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13895 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13896 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
13897 goto nla_put_failure
;
13899 genlmsg_end(msg
, hdr
);
13901 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13902 NL80211_MCGRP_MLME
, gfp
);
13906 genlmsg_cancel(msg
, hdr
);
13910 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
13911 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
13913 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13914 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13915 struct sk_buff
*msg
;
13918 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
13921 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
13923 msg
= nlmsg_new(100 + ie_len
, gfp
);
13927 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
13933 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13934 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13935 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
13937 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
13938 goto nla_put_failure
;
13940 genlmsg_end(msg
, hdr
);
13942 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13943 NL80211_MCGRP_MLME
, gfp
);
13947 genlmsg_cancel(msg
, hdr
);
13950 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
13952 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
13953 struct net_device
*netdev
, const u8
*addr
,
13954 enum nl80211_key_type key_type
, int key_id
,
13955 const u8
*tsc
, gfp_t gfp
)
13957 struct sk_buff
*msg
;
13960 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13964 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
13970 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13971 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13972 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
13973 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
13975 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
13976 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
13977 goto nla_put_failure
;
13979 genlmsg_end(msg
, hdr
);
13981 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13982 NL80211_MCGRP_MLME
, gfp
);
13986 genlmsg_cancel(msg
, hdr
);
13990 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
13991 struct ieee80211_channel
*channel_before
,
13992 struct ieee80211_channel
*channel_after
)
13994 struct sk_buff
*msg
;
13996 struct nlattr
*nl_freq
;
13998 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
14002 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
14009 * Since we are applying the beacon hint to a wiphy we know its
14010 * wiphy_idx is valid
14012 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
14013 goto nla_put_failure
;
14016 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
14018 goto nla_put_failure
;
14019 if (nl80211_msg_put_channel(msg
, channel_before
, false))
14020 goto nla_put_failure
;
14021 nla_nest_end(msg
, nl_freq
);
14024 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
14026 goto nla_put_failure
;
14027 if (nl80211_msg_put_channel(msg
, channel_after
, false))
14028 goto nla_put_failure
;
14029 nla_nest_end(msg
, nl_freq
);
14031 genlmsg_end(msg
, hdr
);
14034 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
14035 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
14041 genlmsg_cancel(msg
, hdr
);
14045 static void nl80211_send_remain_on_chan_event(
14046 int cmd
, struct cfg80211_registered_device
*rdev
,
14047 struct wireless_dev
*wdev
, u64 cookie
,
14048 struct ieee80211_channel
*chan
,
14049 unsigned int duration
, gfp_t gfp
)
14051 struct sk_buff
*msg
;
14054 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14064 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14065 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14066 wdev
->netdev
->ifindex
)) ||
14067 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14068 NL80211_ATTR_PAD
) ||
14069 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
14070 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
14071 NL80211_CHAN_NO_HT
) ||
14072 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14074 goto nla_put_failure
;
14076 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
14077 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
14078 goto nla_put_failure
;
14080 genlmsg_end(msg
, hdr
);
14082 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14083 NL80211_MCGRP_MLME
, gfp
);
14087 genlmsg_cancel(msg
, hdr
);
14091 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
14092 struct ieee80211_channel
*chan
,
14093 unsigned int duration
, gfp_t gfp
)
14095 struct wiphy
*wiphy
= wdev
->wiphy
;
14096 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14098 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
14099 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
14100 rdev
, wdev
, cookie
, chan
,
14103 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
14105 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
14106 struct ieee80211_channel
*chan
,
14109 struct wiphy
*wiphy
= wdev
->wiphy
;
14110 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14112 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
14113 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
14114 rdev
, wdev
, cookie
, chan
, 0, gfp
);
14116 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
14118 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
14119 struct station_info
*sinfo
, gfp_t gfp
)
14121 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14122 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14123 struct sk_buff
*msg
;
14125 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
14127 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14131 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
14132 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14137 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14138 NL80211_MCGRP_MLME
, gfp
);
14140 EXPORT_SYMBOL(cfg80211_new_sta
);
14142 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
14143 struct station_info
*sinfo
, gfp_t gfp
)
14145 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14146 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14147 struct sk_buff
*msg
;
14148 struct station_info empty_sinfo
= {};
14151 sinfo
= &empty_sinfo
;
14153 trace_cfg80211_del_sta(dev
, mac_addr
);
14155 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14159 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
14160 rdev
, dev
, mac_addr
, sinfo
) < 0) {
14165 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14166 NL80211_MCGRP_MLME
, gfp
);
14168 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
14170 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
14171 enum nl80211_connect_failed_reason reason
,
14174 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
14175 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14176 struct sk_buff
*msg
;
14179 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
14183 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
14189 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14190 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
14191 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
14192 goto nla_put_failure
;
14194 genlmsg_end(msg
, hdr
);
14196 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14197 NL80211_MCGRP_MLME
, gfp
);
14201 genlmsg_cancel(msg
, hdr
);
14204 EXPORT_SYMBOL(cfg80211_conn_failed
);
14206 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
14207 const u8
*addr
, gfp_t gfp
)
14209 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14210 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14211 struct sk_buff
*msg
;
14213 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
14218 msg
= nlmsg_new(100, gfp
);
14222 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
14228 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14229 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14230 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
14231 goto nla_put_failure
;
14233 genlmsg_end(msg
, hdr
);
14234 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14238 genlmsg_cancel(msg
, hdr
);
14243 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
14244 const u8
*addr
, gfp_t gfp
)
14246 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14249 trace_cfg80211_rx_spurious_frame(dev
, addr
);
14251 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14252 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
14253 trace_cfg80211_return_bool(false);
14256 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
14258 trace_cfg80211_return_bool(ret
);
14261 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
14263 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
14264 const u8
*addr
, gfp_t gfp
)
14266 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14269 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
14271 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
14272 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
14273 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
14274 trace_cfg80211_return_bool(false);
14277 ret
= __nl80211_unexpected_frame(dev
,
14278 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
14280 trace_cfg80211_return_bool(ret
);
14283 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
14285 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
14286 struct wireless_dev
*wdev
, u32 nlportid
,
14287 int freq
, int sig_dbm
,
14288 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
14290 struct net_device
*netdev
= wdev
->netdev
;
14291 struct sk_buff
*msg
;
14294 msg
= nlmsg_new(100 + len
, gfp
);
14298 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
14304 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14305 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14306 netdev
->ifindex
)) ||
14307 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14308 NL80211_ATTR_PAD
) ||
14309 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
14311 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
14312 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
14314 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
14315 goto nla_put_failure
;
14317 genlmsg_end(msg
, hdr
);
14319 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14322 genlmsg_cancel(msg
, hdr
);
14327 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
14328 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
14330 struct wiphy
*wiphy
= wdev
->wiphy
;
14331 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14332 struct net_device
*netdev
= wdev
->netdev
;
14333 struct sk_buff
*msg
;
14336 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
14338 msg
= nlmsg_new(100 + len
, gfp
);
14342 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
14348 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14349 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14350 netdev
->ifindex
)) ||
14351 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14352 NL80211_ATTR_PAD
) ||
14353 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
14354 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14355 NL80211_ATTR_PAD
) ||
14356 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
14357 goto nla_put_failure
;
14359 genlmsg_end(msg
, hdr
);
14361 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14362 NL80211_MCGRP_MLME
, gfp
);
14366 genlmsg_cancel(msg
, hdr
);
14369 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
14371 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
14372 const char *mac
, gfp_t gfp
)
14374 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14375 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14376 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14382 cb
= (void **)msg
->cb
;
14384 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
14390 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14391 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
14392 goto nla_put_failure
;
14394 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
14395 goto nla_put_failure
;
14397 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
14399 goto nla_put_failure
;
14409 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
14411 void **cb
= (void **)msg
->cb
;
14412 struct cfg80211_registered_device
*rdev
= cb
[2];
14414 nla_nest_end(msg
, cb
[1]);
14415 genlmsg_end(msg
, cb
[0]);
14417 memset(msg
->cb
, 0, sizeof(msg
->cb
));
14419 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14420 NL80211_MCGRP_MLME
, gfp
);
14423 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
14424 enum nl80211_cqm_rssi_threshold_event rssi_event
,
14425 s32 rssi_level
, gfp_t gfp
)
14427 struct sk_buff
*msg
;
14428 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14429 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14431 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
, rssi_level
);
14433 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
14434 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
14437 if (wdev
->cqm_config
) {
14438 wdev
->cqm_config
->last_rssi_event_value
= rssi_level
;
14440 cfg80211_cqm_rssi_update(rdev
, dev
);
14442 if (rssi_level
== 0)
14443 rssi_level
= wdev
->cqm_config
->last_rssi_event_value
;
14446 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
14450 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
14452 goto nla_put_failure
;
14454 if (rssi_level
&& nla_put_s32(msg
, NL80211_ATTR_CQM_RSSI_LEVEL
,
14456 goto nla_put_failure
;
14458 cfg80211_send_cqm(msg
, gfp
);
14465 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
14467 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
14468 const u8
*peer
, u32 num_packets
,
14469 u32 rate
, u32 intvl
, gfp_t gfp
)
14471 struct sk_buff
*msg
;
14473 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
14477 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
14478 goto nla_put_failure
;
14480 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
14481 goto nla_put_failure
;
14483 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
14484 goto nla_put_failure
;
14486 cfg80211_send_cqm(msg
, gfp
);
14492 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
14494 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
14495 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
14497 struct sk_buff
*msg
;
14499 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
14501 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
14505 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
14506 goto nla_put_failure
;
14508 cfg80211_send_cqm(msg
, gfp
);
14514 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
14516 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
14518 struct sk_buff
*msg
;
14520 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
14524 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
14525 goto nla_put_failure
;
14527 cfg80211_send_cqm(msg
, gfp
);
14533 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
14535 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
14536 struct net_device
*netdev
, const u8
*bssid
,
14537 const u8
*replay_ctr
, gfp_t gfp
)
14539 struct sk_buff
*msg
;
14540 struct nlattr
*rekey_attr
;
14543 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14547 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
14553 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14554 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14555 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
14556 goto nla_put_failure
;
14558 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
14560 goto nla_put_failure
;
14562 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
14563 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
14564 goto nla_put_failure
;
14566 nla_nest_end(msg
, rekey_attr
);
14568 genlmsg_end(msg
, hdr
);
14570 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14571 NL80211_MCGRP_MLME
, gfp
);
14575 genlmsg_cancel(msg
, hdr
);
14579 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
14580 const u8
*replay_ctr
, gfp_t gfp
)
14582 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14583 struct wiphy
*wiphy
= wdev
->wiphy
;
14584 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14586 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
14587 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
14589 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
14592 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
14593 struct net_device
*netdev
, int index
,
14594 const u8
*bssid
, bool preauth
, gfp_t gfp
)
14596 struct sk_buff
*msg
;
14597 struct nlattr
*attr
;
14600 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14604 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
14610 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14611 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
14612 goto nla_put_failure
;
14614 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
14616 goto nla_put_failure
;
14618 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
14619 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
14621 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
14622 goto nla_put_failure
;
14624 nla_nest_end(msg
, attr
);
14626 genlmsg_end(msg
, hdr
);
14628 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14629 NL80211_MCGRP_MLME
, gfp
);
14633 genlmsg_cancel(msg
, hdr
);
14637 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
14638 const u8
*bssid
, bool preauth
, gfp_t gfp
)
14640 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14641 struct wiphy
*wiphy
= wdev
->wiphy
;
14642 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14644 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
14645 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
14647 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
14649 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
14650 struct net_device
*netdev
,
14651 struct cfg80211_chan_def
*chandef
,
14653 enum nl80211_commands notif
,
14656 struct sk_buff
*msg
;
14659 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14663 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
14669 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
14670 goto nla_put_failure
;
14672 if (nl80211_send_chandef(msg
, chandef
))
14673 goto nla_put_failure
;
14675 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
14676 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
14677 goto nla_put_failure
;
14679 genlmsg_end(msg
, hdr
);
14681 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14682 NL80211_MCGRP_MLME
, gfp
);
14686 genlmsg_cancel(msg
, hdr
);
14690 void cfg80211_ch_switch_notify(struct net_device
*dev
,
14691 struct cfg80211_chan_def
*chandef
)
14693 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14694 struct wiphy
*wiphy
= wdev
->wiphy
;
14695 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14697 ASSERT_WDEV_LOCK(wdev
);
14699 trace_cfg80211_ch_switch_notify(dev
, chandef
);
14701 wdev
->chandef
= *chandef
;
14702 wdev
->preset_chandef
= *chandef
;
14703 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
14704 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
14706 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
14708 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
14709 struct cfg80211_chan_def
*chandef
,
14712 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14713 struct wiphy
*wiphy
= wdev
->wiphy
;
14714 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14716 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
14718 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
14719 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
14721 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
14724 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
14725 const struct cfg80211_chan_def
*chandef
,
14726 enum nl80211_radar_event event
,
14727 struct net_device
*netdev
, gfp_t gfp
)
14729 struct sk_buff
*msg
;
14732 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14736 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
14742 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
14743 goto nla_put_failure
;
14745 /* NOP and radar events don't need a netdev parameter */
14747 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
14749 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14750 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14752 goto nla_put_failure
;
14755 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
14756 goto nla_put_failure
;
14758 if (nl80211_send_chandef(msg
, chandef
))
14759 goto nla_put_failure
;
14761 genlmsg_end(msg
, hdr
);
14763 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14764 NL80211_MCGRP_MLME
, gfp
);
14768 genlmsg_cancel(msg
, hdr
);
14772 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
14773 u64 cookie
, bool acked
, gfp_t gfp
)
14775 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14776 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14777 struct sk_buff
*msg
;
14780 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
14782 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14787 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
14793 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14794 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14795 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
14796 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14797 NL80211_ATTR_PAD
) ||
14798 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
14799 goto nla_put_failure
;
14801 genlmsg_end(msg
, hdr
);
14803 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14804 NL80211_MCGRP_MLME
, gfp
);
14808 genlmsg_cancel(msg
, hdr
);
14811 EXPORT_SYMBOL(cfg80211_probe_status
);
14813 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
14814 const u8
*frame
, size_t len
,
14815 int freq
, int sig_dbm
)
14817 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14818 struct sk_buff
*msg
;
14820 struct cfg80211_beacon_registration
*reg
;
14822 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
14824 spin_lock_bh(&rdev
->beacon_registrations_lock
);
14825 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
14826 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
14828 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14832 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
14834 goto nla_put_failure
;
14836 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14838 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
14840 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
14841 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
14842 goto nla_put_failure
;
14844 genlmsg_end(msg
, hdr
);
14846 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
14848 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14852 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14854 genlmsg_cancel(msg
, hdr
);
14857 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
14860 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
14861 struct cfg80211_wowlan_wakeup
*wakeup
)
14863 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
14864 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
14867 nl_results
= nla_nest_start(
14868 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
14872 for (i
= 0; i
< nd
->n_matches
; i
++) {
14873 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
14875 nl_match
= nla_nest_start(msg
, i
);
14879 /* The SSID attribute is optional in nl80211, but for
14880 * simplicity reasons it's always present in the
14881 * cfg80211 structure. If a driver can't pass the
14882 * SSID, that needs to be changed. A zero length SSID
14883 * is still a valid SSID (wildcard), so it cannot be
14884 * used for this purpose.
14886 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
14887 match
->ssid
.ssid
)) {
14888 nla_nest_cancel(msg
, nl_match
);
14892 if (match
->n_channels
) {
14893 nl_freqs
= nla_nest_start(
14894 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
14896 nla_nest_cancel(msg
, nl_match
);
14900 for (j
= 0; j
< match
->n_channels
; j
++) {
14901 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
14902 nla_nest_cancel(msg
, nl_freqs
);
14903 nla_nest_cancel(msg
, nl_match
);
14908 nla_nest_end(msg
, nl_freqs
);
14911 nla_nest_end(msg
, nl_match
);
14915 nla_nest_end(msg
, nl_results
);
14919 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
14920 struct cfg80211_wowlan_wakeup
*wakeup
,
14923 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14924 struct sk_buff
*msg
;
14928 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
14931 size
+= wakeup
->packet_present_len
;
14933 msg
= nlmsg_new(size
, gfp
);
14937 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
14941 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14942 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14946 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14947 wdev
->netdev
->ifindex
))
14951 struct nlattr
*reasons
;
14953 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
14957 if (wakeup
->disconnect
&&
14958 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
14960 if (wakeup
->magic_pkt
&&
14961 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
14963 if (wakeup
->gtk_rekey_failure
&&
14964 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
14966 if (wakeup
->eap_identity_req
&&
14967 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
14969 if (wakeup
->four_way_handshake
&&
14970 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
14972 if (wakeup
->rfkill_release
&&
14973 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
14976 if (wakeup
->pattern_idx
>= 0 &&
14977 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
14978 wakeup
->pattern_idx
))
14981 if (wakeup
->tcp_match
&&
14982 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
14985 if (wakeup
->tcp_connlost
&&
14986 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
14989 if (wakeup
->tcp_nomoretokens
&&
14991 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
14994 if (wakeup
->packet
) {
14995 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
14996 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
14998 if (!wakeup
->packet_80211
) {
15000 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
15002 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
15005 if (wakeup
->packet_len
&&
15006 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
15009 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
15014 if (wakeup
->net_detect
&&
15015 cfg80211_net_detect_results(msg
, wakeup
))
15018 nla_nest_end(msg
, reasons
);
15021 genlmsg_end(msg
, hdr
);
15023 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15024 NL80211_MCGRP_MLME
, gfp
);
15030 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
15033 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
15034 enum nl80211_tdls_operation oper
,
15035 u16 reason_code
, gfp_t gfp
)
15037 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
15038 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
15039 struct sk_buff
*msg
;
15042 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
15045 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15049 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
15055 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15056 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
15057 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
15058 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
15059 (reason_code
> 0 &&
15060 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
15061 goto nla_put_failure
;
15063 genlmsg_end(msg
, hdr
);
15065 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15066 NL80211_MCGRP_MLME
, gfp
);
15070 genlmsg_cancel(msg
, hdr
);
15073 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
15075 static int nl80211_netlink_notify(struct notifier_block
* nb
,
15076 unsigned long state
,
15079 struct netlink_notify
*notify
= _notify
;
15080 struct cfg80211_registered_device
*rdev
;
15081 struct wireless_dev
*wdev
;
15082 struct cfg80211_beacon_registration
*reg
, *tmp
;
15084 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
15085 return NOTIFY_DONE
;
15089 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
15090 struct cfg80211_sched_scan_request
*sched_scan_req
;
15092 list_for_each_entry_rcu(sched_scan_req
,
15093 &rdev
->sched_scan_req_list
,
15095 if (sched_scan_req
->owner_nlportid
== notify
->portid
) {
15096 sched_scan_req
->nl_owner_dead
= true;
15097 schedule_work(&rdev
->sched_scan_stop_wk
);
15101 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
15102 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
15104 if (wdev
->owner_nlportid
== notify
->portid
) {
15105 wdev
->nl_owner_dead
= true;
15106 schedule_work(&rdev
->destroy_work
);
15107 } else if (wdev
->conn_owner_nlportid
== notify
->portid
) {
15108 schedule_work(&wdev
->disconnect_wk
);
15112 spin_lock_bh(&rdev
->beacon_registrations_lock
);
15113 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
15115 if (reg
->nlportid
== notify
->portid
) {
15116 list_del(®
->list
);
15121 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
15127 * It is possible that the user space process that is controlling the
15128 * indoor setting disappeared, so notify the regulatory core.
15130 regulatory_netlink_notify(notify
->portid
);
15134 static struct notifier_block nl80211_netlink_notifier
= {
15135 .notifier_call
= nl80211_netlink_notify
,
15138 void cfg80211_ft_event(struct net_device
*netdev
,
15139 struct cfg80211_ft_event_params
*ft_event
)
15141 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
15142 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15143 struct sk_buff
*msg
;
15146 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
15148 if (!ft_event
->target_ap
)
15151 msg
= nlmsg_new(100 + ft_event
->ric_ies_len
, GFP_KERNEL
);
15155 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
15159 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15160 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
15161 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
15164 if (ft_event
->ies
&&
15165 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
15167 if (ft_event
->ric_ies
&&
15168 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
15169 ft_event
->ric_ies
))
15172 genlmsg_end(msg
, hdr
);
15174 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
15175 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15180 EXPORT_SYMBOL(cfg80211_ft_event
);
15182 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
15184 struct cfg80211_registered_device
*rdev
;
15185 struct sk_buff
*msg
;
15189 rdev
= wiphy_to_rdev(wdev
->wiphy
);
15190 if (!rdev
->crit_proto_nlportid
)
15193 nlportid
= rdev
->crit_proto_nlportid
;
15194 rdev
->crit_proto_nlportid
= 0;
15196 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
15200 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
15202 goto nla_put_failure
;
15204 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15205 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15207 goto nla_put_failure
;
15209 genlmsg_end(msg
, hdr
);
15211 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
15216 genlmsg_cancel(msg
, hdr
);
15219 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
15221 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
15223 struct wiphy
*wiphy
= wdev
->wiphy
;
15224 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
15225 struct sk_buff
*msg
;
15228 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
15232 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
15236 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
15237 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
15238 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
15242 genlmsg_end(msg
, hdr
);
15244 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
15245 NL80211_MCGRP_MLME
, GFP_KERNEL
);
15251 /* initialisation/exit functions */
15253 int __init
nl80211_init(void)
15257 err
= genl_register_family(&nl80211_fam
);
15261 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
15267 genl_unregister_family(&nl80211_fam
);
15271 void nl80211_exit(void)
15273 netlink_unregister_notifier(&nl80211_netlink_notifier
);
15274 genl_unregister_family(&nl80211_fam
);