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-2016 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/etherdevice.h>
20 #include <net/net_namespace.h>
21 #include <net/genetlink.h>
22 #include <net/cfg80211.h>
24 #include <net/inet_connection_sock.h>
30 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
31 struct genl_info
*info
,
32 struct cfg80211_crypto_settings
*settings
,
35 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
37 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
38 struct genl_info
*info
);
40 /* the netlink family */
41 static struct genl_family nl80211_fam
= {
42 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
43 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
44 .hdrsize
= 0, /* no private header */
45 .version
= 1, /* no particular meaning now */
46 .maxattr
= NL80211_ATTR_MAX
,
48 .pre_doit
= nl80211_pre_doit
,
49 .post_doit
= nl80211_post_doit
,
52 /* multicast groups */
53 enum nl80211_multicast_groups
{
56 NL80211_MCGRP_REGULATORY
,
60 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
63 static const struct genl_multicast_group nl80211_mcgrps
[] = {
64 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
65 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
66 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
67 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
68 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
69 [NL80211_MCGRP_NAN
] = { .name
= NL80211_MULTICAST_GROUP_NAN
},
70 #ifdef CONFIG_NL80211_TESTMODE
71 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
75 /* returns ERR_PTR values */
76 static struct wireless_dev
*
77 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
79 struct cfg80211_registered_device
*rdev
;
80 struct wireless_dev
*result
= NULL
;
81 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
82 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
89 if (!have_ifidx
&& !have_wdev_id
)
90 return ERR_PTR(-EINVAL
);
93 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
95 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
96 wiphy_idx
= wdev_id
>> 32;
99 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
100 struct wireless_dev
*wdev
;
102 if (wiphy_net(&rdev
->wiphy
) != netns
)
105 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
108 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
109 if (have_ifidx
&& wdev
->netdev
&&
110 wdev
->netdev
->ifindex
== ifidx
) {
114 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
126 return ERR_PTR(-ENODEV
);
129 static struct cfg80211_registered_device
*
130 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
132 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
133 struct net_device
*netdev
;
137 if (!attrs
[NL80211_ATTR_WIPHY
] &&
138 !attrs
[NL80211_ATTR_IFINDEX
] &&
139 !attrs
[NL80211_ATTR_WDEV
])
140 return ERR_PTR(-EINVAL
);
142 if (attrs
[NL80211_ATTR_WIPHY
])
143 rdev
= cfg80211_rdev_by_wiphy_idx(
144 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
146 if (attrs
[NL80211_ATTR_WDEV
]) {
147 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
148 struct wireless_dev
*wdev
;
151 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
153 /* make sure wdev exists */
154 list_for_each_entry(wdev
, &tmp
->wiphy
.wdev_list
, list
) {
155 if (wdev
->identifier
!= (u32
)wdev_id
)
164 if (rdev
&& tmp
!= rdev
)
165 return ERR_PTR(-EINVAL
);
170 if (attrs
[NL80211_ATTR_IFINDEX
]) {
171 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
173 netdev
= __dev_get_by_index(netns
, ifindex
);
175 if (netdev
->ieee80211_ptr
)
177 netdev
->ieee80211_ptr
->wiphy
);
181 /* not wireless device -- return error */
183 return ERR_PTR(-EINVAL
);
185 /* mismatch -- return error */
186 if (rdev
&& tmp
!= rdev
)
187 return ERR_PTR(-EINVAL
);
194 return ERR_PTR(-ENODEV
);
196 if (netns
!= wiphy_net(&rdev
->wiphy
))
197 return ERR_PTR(-ENODEV
);
203 * This function returns a pointer to the driver
204 * that the genl_info item that is passed refers to.
206 * The result of this can be a PTR_ERR and hence must
207 * be checked with IS_ERR() for errors.
209 static struct cfg80211_registered_device
*
210 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
212 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
215 /* policy for the attributes */
216 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
217 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
218 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
220 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
222 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
225 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
226 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
229 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
230 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
233 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
235 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
236 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
237 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
239 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
240 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
242 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
243 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
244 .len
= WLAN_MAX_KEY_LEN
},
245 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
246 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
247 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
248 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
249 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
253 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
254 .len
= IEEE80211_MAX_DATA_LEN
},
255 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
256 .len
= IEEE80211_MAX_DATA_LEN
},
257 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
258 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
259 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
260 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
261 .len
= NL80211_MAX_SUPP_RATES
},
262 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
263 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
264 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
265 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
266 .len
= IEEE80211_MAX_MESH_ID_LEN
},
267 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
269 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
270 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
272 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
274 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
275 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
276 .len
= NL80211_MAX_SUPP_RATES
},
277 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
279 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
280 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
282 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
284 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
285 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
286 .len
= IEEE80211_MAX_DATA_LEN
},
287 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
288 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
290 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
291 .len
= IEEE80211_MAX_SSID_LEN
},
292 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
293 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
294 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
295 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
296 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
297 [NL80211_ATTR_STA_FLAGS2
] = {
298 .len
= sizeof(struct nl80211_sta_flag_update
),
300 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
302 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
303 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
304 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
306 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
307 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
308 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
309 .len
= WLAN_PMKID_LEN
},
310 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
312 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
313 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
314 .len
= IEEE80211_MAX_DATA_LEN
},
315 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
316 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
317 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
318 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
319 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
320 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
323 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
324 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
325 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
326 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
327 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
328 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
329 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
330 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
331 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
332 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
333 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
334 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
335 .len
= IEEE80211_MAX_DATA_LEN
},
336 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
337 .len
= IEEE80211_MAX_DATA_LEN
},
338 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
339 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
340 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
341 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
342 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
343 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
344 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
347 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
348 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
349 .len
= IEEE80211_MAX_DATA_LEN
},
350 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
351 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
352 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
353 .len
= NL80211_HT_CAPABILITY_LEN
355 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
356 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
357 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
358 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
359 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
360 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
361 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
362 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
363 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
364 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
365 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
366 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
367 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
368 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
369 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
370 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
371 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
372 .len
= NL80211_VHT_CAPABILITY_LEN
,
374 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
375 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
376 .len
= IEEE80211_MAX_DATA_LEN
},
377 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
378 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
379 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
380 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
381 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
382 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
384 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
385 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
386 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
387 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
388 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
389 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
390 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
391 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
392 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
393 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
394 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
395 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
396 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
397 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
398 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
399 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
400 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
401 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
402 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
403 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
404 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
405 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
406 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
407 [NL80211_ATTR_PBSS
] = { .type
= NLA_FLAG
},
408 [NL80211_ATTR_BSS_SELECT
] = { .type
= NLA_NESTED
},
409 [NL80211_ATTR_STA_SUPPORT_P2P_PS
] = { .type
= NLA_U8
},
410 [NL80211_ATTR_MU_MIMO_GROUP_DATA
] = {
411 .len
= VHT_MUMIMO_GROUPS_DATA_LEN
413 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
] = { .len
= ETH_ALEN
},
414 [NL80211_ATTR_NAN_MASTER_PREF
] = { .type
= NLA_U8
},
415 [NL80211_ATTR_NAN_DUAL
] = { .type
= NLA_U8
},
416 [NL80211_ATTR_NAN_FUNC
] = { .type
= NLA_NESTED
},
419 /* policy for the key attributes */
420 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
421 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
422 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
423 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
424 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
425 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
426 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
427 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
428 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
431 /* policy for the key default flags */
432 static const struct nla_policy
433 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
434 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
435 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
438 /* policy for WoWLAN attributes */
439 static const struct nla_policy
440 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
441 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
442 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
443 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
444 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
445 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
446 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
447 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
448 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
449 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
450 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
453 static const struct nla_policy
454 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
455 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
456 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
457 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
458 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
459 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
460 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
461 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
462 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
464 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
465 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
467 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
468 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
469 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
472 /* policy for coalesce rule attributes */
473 static const struct nla_policy
474 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
475 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
476 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
477 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
480 /* policy for GTK rekey offload attributes */
481 static const struct nla_policy
482 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
483 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
484 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
485 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
488 static const struct nla_policy
489 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
490 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
491 .len
= IEEE80211_MAX_SSID_LEN
},
492 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
495 static const struct nla_policy
496 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
497 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
498 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
501 static const struct nla_policy
502 nl80211_bss_select_policy
[NL80211_BSS_SELECT_ATTR_MAX
+ 1] = {
503 [NL80211_BSS_SELECT_ATTR_RSSI
] = { .type
= NLA_FLAG
},
504 [NL80211_BSS_SELECT_ATTR_BAND_PREF
] = { .type
= NLA_U32
},
505 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
] = {
506 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
510 /* policy for NAN function attributes */
511 static const struct nla_policy
512 nl80211_nan_func_policy
[NL80211_NAN_FUNC_ATTR_MAX
+ 1] = {
513 [NL80211_NAN_FUNC_TYPE
] = { .type
= NLA_U8
},
514 [NL80211_NAN_FUNC_SERVICE_ID
] = { .type
= NLA_BINARY
,
515 .len
= NL80211_NAN_FUNC_SERVICE_ID_LEN
},
516 [NL80211_NAN_FUNC_PUBLISH_TYPE
] = { .type
= NLA_U8
},
517 [NL80211_NAN_FUNC_PUBLISH_BCAST
] = { .type
= NLA_FLAG
},
518 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
] = { .type
= NLA_FLAG
},
519 [NL80211_NAN_FUNC_FOLLOW_UP_ID
] = { .type
= NLA_U8
},
520 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
] = { .type
= NLA_U8
},
521 [NL80211_NAN_FUNC_FOLLOW_UP_DEST
] = { .len
= ETH_ALEN
},
522 [NL80211_NAN_FUNC_CLOSE_RANGE
] = { .type
= NLA_FLAG
},
523 [NL80211_NAN_FUNC_TTL
] = { .type
= NLA_U32
},
524 [NL80211_NAN_FUNC_SERVICE_INFO
] = { .type
= NLA_BINARY
,
525 .len
= NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN
},
526 [NL80211_NAN_FUNC_SRF
] = { .type
= NLA_NESTED
},
527 [NL80211_NAN_FUNC_RX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
528 [NL80211_NAN_FUNC_TX_MATCH_FILTER
] = { .type
= NLA_NESTED
},
529 [NL80211_NAN_FUNC_INSTANCE_ID
] = { .type
= NLA_U8
},
530 [NL80211_NAN_FUNC_TERM_REASON
] = { .type
= NLA_U8
},
533 /* policy for Service Response Filter attributes */
534 static const struct nla_policy
535 nl80211_nan_srf_policy
[NL80211_NAN_SRF_ATTR_MAX
+ 1] = {
536 [NL80211_NAN_SRF_INCLUDE
] = { .type
= NLA_FLAG
},
537 [NL80211_NAN_SRF_BF
] = { .type
= NLA_BINARY
,
538 .len
= NL80211_NAN_FUNC_SRF_MAX_LEN
},
539 [NL80211_NAN_SRF_BF_IDX
] = { .type
= NLA_U8
},
540 [NL80211_NAN_SRF_MAC_ADDRS
] = { .type
= NLA_NESTED
},
543 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
544 struct netlink_callback
*cb
,
545 struct cfg80211_registered_device
**rdev
,
546 struct wireless_dev
**wdev
)
553 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
554 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
559 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
560 nl80211_fam
.attrbuf
);
562 err
= PTR_ERR(*wdev
);
565 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
566 /* 0 is the first index - add 1 to parse only once */
567 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
568 cb
->args
[1] = (*wdev
)->identifier
;
570 /* subtract the 1 again here */
571 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
572 struct wireless_dev
*tmp
;
578 *rdev
= wiphy_to_rdev(wiphy
);
581 list_for_each_entry(tmp
, &(*rdev
)->wiphy
.wdev_list
, list
) {
582 if (tmp
->identifier
== cb
->args
[1]) {
600 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
606 static bool is_valid_ie_attr(const struct nlattr
*attr
)
614 pos
= nla_data(attr
);
635 /* message building helper */
636 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
639 /* since there is no private header just add the generic one */
640 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
643 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
644 struct ieee80211_channel
*chan
,
647 /* Some channels must be completely excluded from the
648 * list to protect old user-space tools from breaking
650 if (!large
&& chan
->flags
&
651 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
654 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
656 goto nla_put_failure
;
658 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
659 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
660 goto nla_put_failure
;
661 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
662 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
663 goto nla_put_failure
;
664 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
665 goto nla_put_failure
;
667 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
668 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
669 goto nla_put_failure
;
673 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
675 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
677 goto nla_put_failure
;
678 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
680 goto nla_put_failure
;
682 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
684 goto nla_put_failure
;
689 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
690 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
691 goto nla_put_failure
;
692 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
693 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
694 goto nla_put_failure
;
695 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
696 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
697 goto nla_put_failure
;
698 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
699 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
700 goto nla_put_failure
;
701 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
702 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
703 goto nla_put_failure
;
704 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
705 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
706 goto nla_put_failure
;
707 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
708 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
709 goto nla_put_failure
;
710 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
711 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
712 goto nla_put_failure
;
715 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
716 DBM_TO_MBM(chan
->max_power
)))
717 goto nla_put_failure
;
725 /* netlink command implementations */
732 bool def_uni
, def_multi
;
735 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
737 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
738 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
743 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
744 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
753 if (tb
[NL80211_KEY_IDX
])
754 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
756 if (tb
[NL80211_KEY_DATA
]) {
757 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
758 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
761 if (tb
[NL80211_KEY_SEQ
]) {
762 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
763 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
766 if (tb
[NL80211_KEY_CIPHER
])
767 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
769 if (tb
[NL80211_KEY_TYPE
]) {
770 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
771 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
775 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
776 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
778 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
779 tb
[NL80211_KEY_DEFAULT_TYPES
],
780 nl80211_key_default_policy
);
784 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
785 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
791 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
793 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
794 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
795 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
798 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
799 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
800 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
803 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
804 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
806 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
807 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
809 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
810 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
819 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
820 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
821 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
825 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
826 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
827 int err
= nla_parse_nested(
828 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
829 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
830 nl80211_key_default_policy
);
834 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
835 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
841 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
845 memset(k
, 0, sizeof(*k
));
849 if (info
->attrs
[NL80211_ATTR_KEY
])
850 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
852 err
= nl80211_parse_key_old(info
, k
);
857 if (k
->def
&& k
->defmgmt
)
861 if (k
->def_uni
|| !k
->def_multi
)
867 if (k
->idx
< 4 || k
->idx
> 5)
870 if (k
->idx
< 0 || k
->idx
> 3)
873 if (k
->idx
< 0 || k
->idx
> 5)
881 static struct cfg80211_cached_keys
*
882 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
883 struct nlattr
*keys
, bool *no_ht
)
885 struct key_parse parse
;
887 struct cfg80211_cached_keys
*result
;
888 int rem
, err
, def
= 0;
889 bool have_key
= false;
891 nla_for_each_nested(key
, keys
, rem
) {
899 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
901 return ERR_PTR(-ENOMEM
);
905 nla_for_each_nested(key
, keys
, rem
) {
906 memset(&parse
, 0, sizeof(parse
));
909 err
= nl80211_parse_key_new(key
, &parse
);
915 if (parse
.idx
< 0 || parse
.idx
> 3)
921 result
->def
= parse
.idx
;
922 if (!parse
.def_uni
|| !parse
.def_multi
)
924 } else if (parse
.defmgmt
)
926 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
927 parse
.idx
, false, NULL
);
930 if (parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
931 parse
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
) {
935 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
936 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
937 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
938 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
940 /* must be WEP key if we got here */
945 if (result
->def
< 0) {
956 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
958 ASSERT_WDEV_LOCK(wdev
);
960 switch (wdev
->iftype
) {
961 case NL80211_IFTYPE_AP
:
962 case NL80211_IFTYPE_AP_VLAN
:
963 case NL80211_IFTYPE_P2P_GO
:
964 case NL80211_IFTYPE_MESH_POINT
:
966 case NL80211_IFTYPE_ADHOC
:
967 case NL80211_IFTYPE_STATION
:
968 case NL80211_IFTYPE_P2P_CLIENT
:
969 if (!wdev
->current_bss
)
972 case NL80211_IFTYPE_UNSPECIFIED
:
973 case NL80211_IFTYPE_OCB
:
974 case NL80211_IFTYPE_MONITOR
:
975 case NL80211_IFTYPE_NAN
:
976 case NL80211_IFTYPE_P2P_DEVICE
:
977 case NL80211_IFTYPE_WDS
:
978 case NUM_NL80211_IFTYPES
:
985 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
988 struct ieee80211_channel
*chan
;
992 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
993 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
998 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
1000 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
1004 goto nla_put_failure
;
1008 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
1009 goto nla_put_failure
;
1014 nla_nest_end(msg
, nl_modes
);
1021 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
1022 struct sk_buff
*msg
,
1025 struct nlattr
*nl_combis
;
1028 nl_combis
= nla_nest_start(msg
,
1029 NL80211_ATTR_INTERFACE_COMBINATIONS
);
1031 goto nla_put_failure
;
1033 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
1034 const struct ieee80211_iface_combination
*c
;
1035 struct nlattr
*nl_combi
, *nl_limits
;
1037 c
= &wiphy
->iface_combinations
[i
];
1039 nl_combi
= nla_nest_start(msg
, i
+ 1);
1041 goto nla_put_failure
;
1043 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
1045 goto nla_put_failure
;
1047 for (j
= 0; j
< c
->n_limits
; j
++) {
1048 struct nlattr
*nl_limit
;
1050 nl_limit
= nla_nest_start(msg
, j
+ 1);
1052 goto nla_put_failure
;
1053 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
1055 goto nla_put_failure
;
1056 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
1057 c
->limits
[j
].types
))
1058 goto nla_put_failure
;
1059 nla_nest_end(msg
, nl_limit
);
1062 nla_nest_end(msg
, nl_limits
);
1064 if (c
->beacon_int_infra_match
&&
1065 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
1066 goto nla_put_failure
;
1067 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
1068 c
->num_different_channels
) ||
1069 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
1071 goto nla_put_failure
;
1073 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1074 c
->radar_detect_widths
) ||
1075 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1076 c
->radar_detect_regions
)))
1077 goto nla_put_failure
;
1079 nla_nest_end(msg
, nl_combi
);
1082 nla_nest_end(msg
, nl_combis
);
1090 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1091 struct sk_buff
*msg
)
1093 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1094 struct nlattr
*nl_tcp
;
1099 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1103 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1104 tcp
->data_payload_max
))
1107 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1108 tcp
->data_payload_max
))
1111 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1114 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1115 sizeof(*tcp
->tok
), tcp
->tok
))
1118 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1119 tcp
->data_interval_max
))
1122 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1123 tcp
->wake_payload_max
))
1126 nla_nest_end(msg
, nl_tcp
);
1130 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1131 struct cfg80211_registered_device
*rdev
,
1134 struct nlattr
*nl_wowlan
;
1136 if (!rdev
->wiphy
.wowlan
)
1139 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1143 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1144 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1145 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1146 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1147 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1148 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1149 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1150 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1151 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1152 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1153 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1154 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1155 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1156 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1157 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1158 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1161 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1162 struct nl80211_pattern_support pat
= {
1163 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1164 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1165 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1166 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1169 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1174 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1175 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1176 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1179 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1182 nla_nest_end(msg
, nl_wowlan
);
1188 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1189 struct cfg80211_registered_device
*rdev
)
1191 struct nl80211_coalesce_rule_support rule
;
1193 if (!rdev
->wiphy
.coalesce
)
1196 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1197 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1198 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1199 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1200 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1201 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1203 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1209 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1210 struct ieee80211_supported_band
*sband
)
1212 struct nlattr
*nl_rates
, *nl_rate
;
1213 struct ieee80211_rate
*rate
;
1217 if (sband
->ht_cap
.ht_supported
&&
1218 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1219 sizeof(sband
->ht_cap
.mcs
),
1220 &sband
->ht_cap
.mcs
) ||
1221 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1222 sband
->ht_cap
.cap
) ||
1223 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1224 sband
->ht_cap
.ampdu_factor
) ||
1225 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1226 sband
->ht_cap
.ampdu_density
)))
1230 if (sband
->vht_cap
.vht_supported
&&
1231 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1232 sizeof(sband
->vht_cap
.vht_mcs
),
1233 &sband
->vht_cap
.vht_mcs
) ||
1234 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1235 sband
->vht_cap
.cap
)))
1239 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1243 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1244 nl_rate
= nla_nest_start(msg
, i
);
1248 rate
= &sband
->bitrates
[i
];
1249 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1252 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1254 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1257 nla_nest_end(msg
, nl_rate
);
1260 nla_nest_end(msg
, nl_rates
);
1266 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1267 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1270 struct nlattr
*nl_ftypes
, *nl_ifs
;
1271 enum nl80211_iftype ift
;
1277 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1281 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1282 nl_ftypes
= nla_nest_start(msg
, ift
);
1286 stypes
= mgmt_stypes
[ift
].tx
;
1289 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1290 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1295 nla_nest_end(msg
, nl_ftypes
);
1298 nla_nest_end(msg
, nl_ifs
);
1300 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1304 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1305 nl_ftypes
= nla_nest_start(msg
, ift
);
1309 stypes
= mgmt_stypes
[ift
].rx
;
1312 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1313 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1318 nla_nest_end(msg
, nl_ftypes
);
1320 nla_nest_end(msg
, nl_ifs
);
1325 struct nl80211_dump_wiphy_state
{
1328 long split_start
, band_start
, chan_start
, capa_start
;
1332 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1333 enum nl80211_commands cmd
,
1334 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1335 int flags
, struct nl80211_dump_wiphy_state
*state
)
1338 struct nlattr
*nl_bands
, *nl_band
;
1339 struct nlattr
*nl_freqs
, *nl_freq
;
1340 struct nlattr
*nl_cmds
;
1341 enum nl80211_band band
;
1342 struct ieee80211_channel
*chan
;
1344 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1345 rdev
->wiphy
.mgmt_stypes
;
1348 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1352 if (WARN_ON(!state
))
1355 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1356 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1357 wiphy_name(&rdev
->wiphy
)) ||
1358 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1359 cfg80211_rdev_list_generation
))
1360 goto nla_put_failure
;
1362 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1365 switch (state
->split_start
) {
1367 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1368 rdev
->wiphy
.retry_short
) ||
1369 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1370 rdev
->wiphy
.retry_long
) ||
1371 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1372 rdev
->wiphy
.frag_threshold
) ||
1373 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1374 rdev
->wiphy
.rts_threshold
) ||
1375 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1376 rdev
->wiphy
.coverage_class
) ||
1377 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1378 rdev
->wiphy
.max_scan_ssids
) ||
1379 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1380 rdev
->wiphy
.max_sched_scan_ssids
) ||
1381 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1382 rdev
->wiphy
.max_scan_ie_len
) ||
1383 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1384 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1385 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1386 rdev
->wiphy
.max_match_sets
) ||
1387 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1388 rdev
->wiphy
.max_sched_scan_plans
) ||
1389 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1390 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1391 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1392 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1393 goto nla_put_failure
;
1395 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1396 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1397 goto nla_put_failure
;
1398 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1399 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1400 goto nla_put_failure
;
1401 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1402 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1403 goto nla_put_failure
;
1404 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1405 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1406 goto nla_put_failure
;
1407 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1408 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1409 goto nla_put_failure
;
1410 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1411 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1412 goto nla_put_failure
;
1413 state
->split_start
++;
1417 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1418 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1419 rdev
->wiphy
.cipher_suites
))
1420 goto nla_put_failure
;
1422 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1423 rdev
->wiphy
.max_num_pmkids
))
1424 goto nla_put_failure
;
1426 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1427 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1428 goto nla_put_failure
;
1430 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1431 rdev
->wiphy
.available_antennas_tx
) ||
1432 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1433 rdev
->wiphy
.available_antennas_rx
))
1434 goto nla_put_failure
;
1436 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1437 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1438 rdev
->wiphy
.probe_resp_offload
))
1439 goto nla_put_failure
;
1441 if ((rdev
->wiphy
.available_antennas_tx
||
1442 rdev
->wiphy
.available_antennas_rx
) &&
1443 rdev
->ops
->get_antenna
) {
1444 u32 tx_ant
= 0, rx_ant
= 0;
1447 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1449 if (nla_put_u32(msg
,
1450 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1453 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1455 goto nla_put_failure
;
1459 state
->split_start
++;
1463 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1464 rdev
->wiphy
.interface_modes
))
1465 goto nla_put_failure
;
1466 state
->split_start
++;
1470 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1472 goto nla_put_failure
;
1474 for (band
= state
->band_start
;
1475 band
< NUM_NL80211_BANDS
; band
++) {
1476 struct ieee80211_supported_band
*sband
;
1478 sband
= rdev
->wiphy
.bands
[band
];
1483 nl_band
= nla_nest_start(msg
, band
);
1485 goto nla_put_failure
;
1487 switch (state
->chan_start
) {
1489 if (nl80211_send_band_rateinfo(msg
, sband
))
1490 goto nla_put_failure
;
1491 state
->chan_start
++;
1495 /* add frequencies */
1496 nl_freqs
= nla_nest_start(
1497 msg
, NL80211_BAND_ATTR_FREQS
);
1499 goto nla_put_failure
;
1501 for (i
= state
->chan_start
- 1;
1502 i
< sband
->n_channels
;
1504 nl_freq
= nla_nest_start(msg
, i
);
1506 goto nla_put_failure
;
1508 chan
= &sband
->channels
[i
];
1510 if (nl80211_msg_put_channel(
1513 goto nla_put_failure
;
1515 nla_nest_end(msg
, nl_freq
);
1519 if (i
< sband
->n_channels
)
1520 state
->chan_start
= i
+ 2;
1522 state
->chan_start
= 0;
1523 nla_nest_end(msg
, nl_freqs
);
1526 nla_nest_end(msg
, nl_band
);
1529 /* start again here */
1530 if (state
->chan_start
)
1535 nla_nest_end(msg
, nl_bands
);
1537 if (band
< NUM_NL80211_BANDS
)
1538 state
->band_start
= band
+ 1;
1540 state
->band_start
= 0;
1542 /* if bands & channels are done, continue outside */
1543 if (state
->band_start
== 0 && state
->chan_start
== 0)
1544 state
->split_start
++;
1548 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1550 goto nla_put_failure
;
1553 #define CMD(op, n) \
1555 if (rdev->ops->op) { \
1557 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1558 goto nla_put_failure; \
1562 CMD(add_virtual_intf
, NEW_INTERFACE
);
1563 CMD(change_virtual_intf
, SET_INTERFACE
);
1564 CMD(add_key
, NEW_KEY
);
1565 CMD(start_ap
, START_AP
);
1566 CMD(add_station
, NEW_STATION
);
1567 CMD(add_mpath
, NEW_MPATH
);
1568 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1569 CMD(change_bss
, SET_BSS
);
1570 CMD(auth
, AUTHENTICATE
);
1571 CMD(assoc
, ASSOCIATE
);
1572 CMD(deauth
, DEAUTHENTICATE
);
1573 CMD(disassoc
, DISASSOCIATE
);
1574 CMD(join_ibss
, JOIN_IBSS
);
1575 CMD(join_mesh
, JOIN_MESH
);
1576 CMD(set_pmksa
, SET_PMKSA
);
1577 CMD(del_pmksa
, DEL_PMKSA
);
1578 CMD(flush_pmksa
, FLUSH_PMKSA
);
1579 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1580 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1581 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1582 CMD(mgmt_tx
, FRAME
);
1583 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1584 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1586 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1587 goto nla_put_failure
;
1589 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1590 rdev
->ops
->join_mesh
) {
1592 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1593 goto nla_put_failure
;
1595 CMD(set_wds_peer
, SET_WDS_PEER
);
1596 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1597 CMD(tdls_mgmt
, TDLS_MGMT
);
1598 CMD(tdls_oper
, TDLS_OPER
);
1600 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1601 CMD(sched_scan_start
, START_SCHED_SCAN
);
1602 CMD(probe_client
, PROBE_CLIENT
);
1603 CMD(set_noack_map
, SET_NOACK_MAP
);
1604 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1606 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1607 goto nla_put_failure
;
1609 CMD(start_p2p_device
, START_P2P_DEVICE
);
1610 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1611 #ifdef CONFIG_NL80211_TESTMODE
1612 CMD(testmode_cmd
, TESTMODE
);
1615 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1616 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1617 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1618 CMD(channel_switch
, CHANNEL_SWITCH
);
1619 CMD(set_qos_map
, SET_QOS_MAP
);
1620 if (rdev
->wiphy
.features
&
1621 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1622 CMD(add_tx_ts
, ADD_TX_TS
);
1624 /* add into the if now */
1627 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1629 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1630 goto nla_put_failure
;
1633 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1635 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1636 goto nla_put_failure
;
1639 nla_nest_end(msg
, nl_cmds
);
1640 state
->split_start
++;
1644 if (rdev
->ops
->remain_on_channel
&&
1645 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1647 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1648 rdev
->wiphy
.max_remain_on_channel_duration
))
1649 goto nla_put_failure
;
1651 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1652 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1653 goto nla_put_failure
;
1655 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1656 goto nla_put_failure
;
1657 state
->split_start
++;
1662 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1663 goto nla_put_failure
;
1664 state
->split_start
++;
1668 state
->split_start
++;
1671 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1672 rdev
->wiphy
.software_iftypes
))
1673 goto nla_put_failure
;
1675 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1677 goto nla_put_failure
;
1679 state
->split_start
++;
1683 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1684 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1685 rdev
->wiphy
.ap_sme_capa
))
1686 goto nla_put_failure
;
1688 features
= rdev
->wiphy
.features
;
1690 * We can only add the per-channel limit information if the
1691 * dump is split, otherwise it makes it too big. Therefore
1692 * only advertise it in that case.
1695 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1696 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1697 goto nla_put_failure
;
1699 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1700 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1701 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1702 rdev
->wiphy
.ht_capa_mod_mask
))
1703 goto nla_put_failure
;
1705 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1706 rdev
->wiphy
.max_acl_mac_addrs
&&
1707 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1708 rdev
->wiphy
.max_acl_mac_addrs
))
1709 goto nla_put_failure
;
1712 * Any information below this point is only available to
1713 * applications that can deal with it being split. This
1714 * helps ensure that newly added capabilities don't break
1715 * older tools by overrunning their buffers.
1717 * We still increment split_start so that in the split
1718 * case we'll continue with more data in the next round,
1719 * but break unconditionally so unsplit data stops here.
1721 state
->split_start
++;
1724 if (rdev
->wiphy
.extended_capabilities
&&
1725 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1726 rdev
->wiphy
.extended_capabilities_len
,
1727 rdev
->wiphy
.extended_capabilities
) ||
1728 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1729 rdev
->wiphy
.extended_capabilities_len
,
1730 rdev
->wiphy
.extended_capabilities_mask
)))
1731 goto nla_put_failure
;
1733 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1734 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1735 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1736 rdev
->wiphy
.vht_capa_mod_mask
))
1737 goto nla_put_failure
;
1739 state
->split_start
++;
1742 if (nl80211_send_coalesce(msg
, rdev
))
1743 goto nla_put_failure
;
1745 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1746 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1747 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1748 goto nla_put_failure
;
1750 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1751 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1752 rdev
->wiphy
.max_ap_assoc_sta
))
1753 goto nla_put_failure
;
1755 state
->split_start
++;
1758 if (rdev
->wiphy
.n_vendor_commands
) {
1759 const struct nl80211_vendor_cmd_info
*info
;
1760 struct nlattr
*nested
;
1762 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1764 goto nla_put_failure
;
1766 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1767 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1768 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1769 goto nla_put_failure
;
1771 nla_nest_end(msg
, nested
);
1774 if (rdev
->wiphy
.n_vendor_events
) {
1775 const struct nl80211_vendor_cmd_info
*info
;
1776 struct nlattr
*nested
;
1778 nested
= nla_nest_start(msg
,
1779 NL80211_ATTR_VENDOR_EVENTS
);
1781 goto nla_put_failure
;
1783 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1784 info
= &rdev
->wiphy
.vendor_events
[i
];
1785 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1786 goto nla_put_failure
;
1788 nla_nest_end(msg
, nested
);
1790 state
->split_start
++;
1793 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1794 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1795 rdev
->wiphy
.max_num_csa_counters
))
1796 goto nla_put_failure
;
1798 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1799 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1800 goto nla_put_failure
;
1802 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1803 sizeof(rdev
->wiphy
.ext_features
),
1804 rdev
->wiphy
.ext_features
))
1805 goto nla_put_failure
;
1807 if (rdev
->wiphy
.bss_select_support
) {
1808 struct nlattr
*nested
;
1809 u32 bss_select_support
= rdev
->wiphy
.bss_select_support
;
1811 nested
= nla_nest_start(msg
, NL80211_ATTR_BSS_SELECT
);
1813 goto nla_put_failure
;
1816 while (bss_select_support
) {
1817 if ((bss_select_support
& 1) &&
1818 nla_put_flag(msg
, i
))
1819 goto nla_put_failure
;
1821 bss_select_support
>>= 1;
1823 nla_nest_end(msg
, nested
);
1826 state
->split_start
++;
1829 if (rdev
->wiphy
.num_iftype_ext_capab
&&
1830 rdev
->wiphy
.iftype_ext_capab
) {
1831 struct nlattr
*nested_ext_capab
, *nested
;
1833 nested
= nla_nest_start(msg
,
1834 NL80211_ATTR_IFTYPE_EXT_CAPA
);
1836 goto nla_put_failure
;
1838 for (i
= state
->capa_start
;
1839 i
< rdev
->wiphy
.num_iftype_ext_capab
; i
++) {
1840 const struct wiphy_iftype_ext_capab
*capab
;
1842 capab
= &rdev
->wiphy
.iftype_ext_capab
[i
];
1844 nested_ext_capab
= nla_nest_start(msg
, i
);
1845 if (!nested_ext_capab
||
1846 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
1848 nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1849 capab
->extended_capabilities_len
,
1850 capab
->extended_capabilities
) ||
1851 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1852 capab
->extended_capabilities_len
,
1853 capab
->extended_capabilities_mask
))
1854 goto nla_put_failure
;
1856 nla_nest_end(msg
, nested_ext_capab
);
1860 nla_nest_end(msg
, nested
);
1861 if (i
< rdev
->wiphy
.num_iftype_ext_capab
) {
1862 state
->capa_start
= i
+ 1;
1868 state
->split_start
= 0;
1872 genlmsg_end(msg
, hdr
);
1876 genlmsg_cancel(msg
, hdr
);
1880 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1881 struct netlink_callback
*cb
,
1882 struct nl80211_dump_wiphy_state
*state
)
1884 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1885 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1886 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1887 /* ignore parse errors for backward compatibility */
1891 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1892 if (tb
[NL80211_ATTR_WIPHY
])
1893 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1894 if (tb
[NL80211_ATTR_WDEV
])
1895 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1896 if (tb
[NL80211_ATTR_IFINDEX
]) {
1897 struct net_device
*netdev
;
1898 struct cfg80211_registered_device
*rdev
;
1899 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1901 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1904 if (netdev
->ieee80211_ptr
) {
1905 rdev
= wiphy_to_rdev(
1906 netdev
->ieee80211_ptr
->wiphy
);
1907 state
->filter_wiphy
= rdev
->wiphy_idx
;
1914 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1917 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1918 struct cfg80211_registered_device
*rdev
;
1922 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1927 state
->filter_wiphy
= -1;
1928 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1934 cb
->args
[0] = (long)state
;
1937 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1938 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1940 if (++idx
<= state
->start
)
1942 if (state
->filter_wiphy
!= -1 &&
1943 state
->filter_wiphy
!= rdev
->wiphy_idx
)
1945 /* attempt to fit multiple wiphy data chunks into the skb */
1947 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
1949 NETLINK_CB(cb
->skb
).portid
,
1951 NLM_F_MULTI
, state
);
1954 * If sending the wiphy data didn't fit (ENOBUFS
1955 * or EMSGSIZE returned), this SKB is still
1956 * empty (so it's not too big because another
1957 * wiphy dataset is already in the skb) and
1958 * we've not tried to adjust the dump allocation
1959 * yet ... then adjust the alloc size to be
1960 * bigger, and return 1 but with the empty skb.
1961 * This results in an empty message being RX'ed
1962 * in userspace, but that is ignored.
1964 * We can then retry with the larger buffer.
1966 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1967 !skb
->len
&& !state
->split
&&
1968 cb
->min_dump_alloc
< 4096) {
1969 cb
->min_dump_alloc
= 4096;
1970 state
->split_start
= 0;
1977 } while (state
->split_start
> 0);
1987 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1989 kfree((void *)cb
->args
[0]);
1993 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1995 struct sk_buff
*msg
;
1996 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1997 struct nl80211_dump_wiphy_state state
= {};
1999 msg
= nlmsg_new(4096, GFP_KERNEL
);
2003 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
2004 info
->snd_portid
, info
->snd_seq
, 0,
2010 return genlmsg_reply(msg
, info
);
2013 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
2014 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
2015 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
2016 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
2017 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
2018 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
2021 static int parse_txq_params(struct nlattr
*tb
[],
2022 struct ieee80211_txq_params
*txq_params
)
2024 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
2025 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
2026 !tb
[NL80211_TXQ_ATTR_AIFS
])
2029 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
2030 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
2031 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
2032 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
2033 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
2035 if (txq_params
->ac
>= NL80211_NUM_ACS
)
2041 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
2044 * You can only set the channel explicitly for WDS interfaces,
2045 * all others have their channel managed via their respective
2046 * "establish a connection" command (connect, join, ...)
2048 * For AP/GO and mesh mode, the channel can be set with the
2049 * channel userspace API, but is only stored and passed to the
2050 * low-level driver when the AP starts or the mesh is joined.
2051 * This is for backward compatibility, userspace can also give
2052 * the channel in the start-ap or join-mesh commands instead.
2054 * Monitors are special as they are normally slaved to
2055 * whatever else is going on, so they have their own special
2056 * operation to set the monitor channel if possible.
2059 wdev
->iftype
== NL80211_IFTYPE_AP
||
2060 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
2061 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
2062 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
2065 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
2066 struct genl_info
*info
,
2067 struct cfg80211_chan_def
*chandef
)
2071 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
2074 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
2076 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
2077 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
2078 chandef
->center_freq1
= control_freq
;
2079 chandef
->center_freq2
= 0;
2081 /* Primary channel not allowed */
2082 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
2085 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2086 enum nl80211_channel_type chantype
;
2088 chantype
= nla_get_u32(
2089 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2092 case NL80211_CHAN_NO_HT
:
2093 case NL80211_CHAN_HT20
:
2094 case NL80211_CHAN_HT40PLUS
:
2095 case NL80211_CHAN_HT40MINUS
:
2096 cfg80211_chandef_create(chandef
, chandef
->chan
,
2102 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
2104 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
2105 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
2106 chandef
->center_freq1
=
2108 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
2109 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
2110 chandef
->center_freq2
=
2112 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
2115 if (!cfg80211_chandef_valid(chandef
))
2118 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
2119 IEEE80211_CHAN_DISABLED
))
2122 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
2123 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
2124 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
2130 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
2131 struct net_device
*dev
,
2132 struct genl_info
*info
)
2134 struct cfg80211_chan_def chandef
;
2136 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
2137 struct wireless_dev
*wdev
= NULL
;
2140 wdev
= dev
->ieee80211_ptr
;
2141 if (!nl80211_can_set_dev_channel(wdev
))
2144 iftype
= wdev
->iftype
;
2146 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2151 case NL80211_IFTYPE_AP
:
2152 case NL80211_IFTYPE_P2P_GO
:
2153 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2158 if (wdev
->beacon_interval
) {
2159 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2160 !(rdev
->wiphy
.features
&
2161 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2166 /* Only allow dynamic channel width changes */
2167 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2171 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2175 wdev
->preset_chandef
= chandef
;
2178 case NL80211_IFTYPE_MESH_POINT
:
2179 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2181 case NL80211_IFTYPE_MONITOR
:
2182 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2191 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2193 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2194 struct net_device
*netdev
= info
->user_ptr
[1];
2196 return __nl80211_set_channel(rdev
, netdev
, info
);
2199 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2201 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2202 struct net_device
*dev
= info
->user_ptr
[1];
2203 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2206 if (!info
->attrs
[NL80211_ATTR_MAC
])
2209 if (netif_running(dev
))
2212 if (!rdev
->ops
->set_wds_peer
)
2215 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2218 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2219 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2222 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2224 struct cfg80211_registered_device
*rdev
;
2225 struct net_device
*netdev
= NULL
;
2226 struct wireless_dev
*wdev
;
2227 int result
= 0, rem_txq_params
= 0;
2228 struct nlattr
*nl_txq_params
;
2230 u8 retry_short
= 0, retry_long
= 0;
2231 u32 frag_threshold
= 0, rts_threshold
= 0;
2232 u8 coverage_class
= 0;
2237 * Try to find the wiphy and netdev. Normally this
2238 * function shouldn't need the netdev, but this is
2239 * done for backward compatibility -- previously
2240 * setting the channel was done per wiphy, but now
2241 * it is per netdev. Previous userland like hostapd
2242 * also passed a netdev to set_wiphy, so that it is
2243 * possible to let that go to the right netdev!
2246 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2247 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2249 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2250 if (netdev
&& netdev
->ieee80211_ptr
)
2251 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2257 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2260 return PTR_ERR(rdev
);
2265 wdev
= netdev
->ieee80211_ptr
;
2268 * end workaround code, by now the rdev is available
2269 * and locked, and wdev may or may not be NULL.
2272 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2273 result
= cfg80211_dev_rename(
2274 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2279 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2280 struct ieee80211_txq_params txq_params
;
2281 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2283 if (!rdev
->ops
->set_txq_params
)
2289 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2290 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2293 if (!netif_running(netdev
))
2296 nla_for_each_nested(nl_txq_params
,
2297 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2299 result
= nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
2300 nla_data(nl_txq_params
),
2301 nla_len(nl_txq_params
),
2305 result
= parse_txq_params(tb
, &txq_params
);
2309 result
= rdev_set_txq_params(rdev
, netdev
,
2316 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2317 result
= __nl80211_set_channel(
2319 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2325 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2326 struct wireless_dev
*txp_wdev
= wdev
;
2327 enum nl80211_tx_power_setting type
;
2330 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2333 if (!rdev
->ops
->set_tx_power
)
2336 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2337 type
= nla_get_u32(info
->attrs
[idx
]);
2339 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2340 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2343 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2344 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2345 mbm
= nla_get_u32(info
->attrs
[idx
]);
2348 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2353 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2354 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2357 if ((!rdev
->wiphy
.available_antennas_tx
&&
2358 !rdev
->wiphy
.available_antennas_rx
) ||
2359 !rdev
->ops
->set_antenna
)
2362 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2363 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2365 /* reject antenna configurations which don't match the
2366 * available antenna masks, except for the "all" mask */
2367 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2368 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2371 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2372 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2374 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2381 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2382 retry_short
= nla_get_u8(
2383 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2384 if (retry_short
== 0)
2387 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2390 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2391 retry_long
= nla_get_u8(
2392 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2393 if (retry_long
== 0)
2396 changed
|= WIPHY_PARAM_RETRY_LONG
;
2399 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2400 frag_threshold
= nla_get_u32(
2401 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2402 if (frag_threshold
< 256)
2405 if (frag_threshold
!= (u32
) -1) {
2407 * Fragments (apart from the last one) are required to
2408 * have even length. Make the fragmentation code
2409 * simpler by stripping LSB should someone try to use
2410 * odd threshold value.
2412 frag_threshold
&= ~0x1;
2414 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2417 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2418 rts_threshold
= nla_get_u32(
2419 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2420 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2423 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2424 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2427 coverage_class
= nla_get_u8(
2428 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2429 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2432 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2433 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2436 changed
|= WIPHY_PARAM_DYN_ACK
;
2440 u8 old_retry_short
, old_retry_long
;
2441 u32 old_frag_threshold
, old_rts_threshold
;
2442 u8 old_coverage_class
;
2444 if (!rdev
->ops
->set_wiphy_params
)
2447 old_retry_short
= rdev
->wiphy
.retry_short
;
2448 old_retry_long
= rdev
->wiphy
.retry_long
;
2449 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2450 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2451 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2453 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2454 rdev
->wiphy
.retry_short
= retry_short
;
2455 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2456 rdev
->wiphy
.retry_long
= retry_long
;
2457 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2458 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2459 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2460 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2461 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2462 rdev
->wiphy
.coverage_class
= coverage_class
;
2464 result
= rdev_set_wiphy_params(rdev
, changed
);
2466 rdev
->wiphy
.retry_short
= old_retry_short
;
2467 rdev
->wiphy
.retry_long
= old_retry_long
;
2468 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2469 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2470 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2477 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2479 return (u64
)wdev
->identifier
|
2480 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2483 static int nl80211_send_chandef(struct sk_buff
*msg
,
2484 const struct cfg80211_chan_def
*chandef
)
2486 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2489 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2490 chandef
->chan
->center_freq
))
2492 switch (chandef
->width
) {
2493 case NL80211_CHAN_WIDTH_20_NOHT
:
2494 case NL80211_CHAN_WIDTH_20
:
2495 case NL80211_CHAN_WIDTH_40
:
2496 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2497 cfg80211_get_chandef_type(chandef
)))
2503 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2505 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2507 if (chandef
->center_freq2
&&
2508 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2513 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2514 struct cfg80211_registered_device
*rdev
,
2515 struct wireless_dev
*wdev
, bool removal
)
2517 struct net_device
*dev
= wdev
->netdev
;
2518 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2522 cmd
= NL80211_CMD_DEL_INTERFACE
;
2524 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2529 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2530 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2531 goto nla_put_failure
;
2533 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2534 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2535 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
2536 NL80211_ATTR_PAD
) ||
2537 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2538 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2539 rdev
->devlist_generation
^
2540 (cfg80211_rdev_list_generation
<< 2)))
2541 goto nla_put_failure
;
2543 if (rdev
->ops
->get_channel
) {
2545 struct cfg80211_chan_def chandef
;
2547 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2549 if (nl80211_send_chandef(msg
, &chandef
))
2550 goto nla_put_failure
;
2554 if (rdev
->ops
->get_tx_power
) {
2557 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2559 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2561 goto nla_put_failure
;
2564 if (wdev
->ssid_len
) {
2565 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2566 goto nla_put_failure
;
2569 genlmsg_end(msg
, hdr
);
2573 genlmsg_cancel(msg
, hdr
);
2577 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2581 int wp_start
= cb
->args
[0];
2582 int if_start
= cb
->args
[1];
2583 int filter_wiphy
= -1;
2584 struct cfg80211_registered_device
*rdev
;
2585 struct wireless_dev
*wdev
;
2589 struct nl80211_dump_wiphy_state state
= {
2594 ret
= nl80211_dump_wiphy_parse(skb
, cb
, &state
);
2598 filter_wiphy
= state
.filter_wiphy
;
2601 * if filtering, set cb->args[2] to +1 since 0 is the default
2602 * value needed to determine that parsing is necessary.
2604 if (filter_wiphy
>= 0)
2605 cb
->args
[2] = filter_wiphy
+ 1;
2608 } else if (cb
->args
[2] > 0) {
2609 filter_wiphy
= cb
->args
[2] - 1;
2612 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2613 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2615 if (wp_idx
< wp_start
) {
2620 if (filter_wiphy
>= 0 && filter_wiphy
!= rdev
->wiphy_idx
)
2625 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
2626 if (if_idx
< if_start
) {
2630 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2631 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2632 rdev
, wdev
, false) < 0) {
2643 cb
->args
[0] = wp_idx
;
2644 cb
->args
[1] = if_idx
;
2649 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2651 struct sk_buff
*msg
;
2652 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2653 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2655 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2659 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2660 rdev
, wdev
, false) < 0) {
2665 return genlmsg_reply(msg
, info
);
2668 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2669 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2670 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2671 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2672 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2673 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2674 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2677 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2679 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2687 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2688 nla
, mntr_flags_policy
))
2691 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2693 *mntrflags
|= (1<<flag
);
2698 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2699 struct net_device
*netdev
, u8 use_4addr
,
2700 enum nl80211_iftype iftype
)
2703 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2709 case NL80211_IFTYPE_AP_VLAN
:
2710 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2713 case NL80211_IFTYPE_STATION
:
2714 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2724 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2726 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2727 struct vif_params params
;
2729 enum nl80211_iftype otype
, ntype
;
2730 struct net_device
*dev
= info
->user_ptr
[1];
2731 u32 _flags
, *flags
= NULL
;
2732 bool change
= false;
2734 memset(¶ms
, 0, sizeof(params
));
2736 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2738 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2739 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2742 if (ntype
> NL80211_IFTYPE_MAX
)
2746 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2747 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2749 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2751 if (netif_running(dev
))
2755 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2756 IEEE80211_MAX_MESH_ID_LEN
);
2757 wdev
->mesh_id_up_len
=
2758 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2759 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2760 wdev
->mesh_id_up_len
);
2764 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2765 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2767 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2771 params
.use_4addr
= -1;
2774 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2775 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2777 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2786 if (info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]) {
2787 const u8
*mumimo_groups
;
2788 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2790 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2794 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]);
2796 /* bits 0 and 63 are reserved and must be zero */
2797 if ((mumimo_groups
[0] & BIT(7)) ||
2798 (mumimo_groups
[VHT_MUMIMO_GROUPS_DATA_LEN
- 1] & BIT(0)))
2801 memcpy(params
.vht_mumimo_groups
, mumimo_groups
,
2802 VHT_MUMIMO_GROUPS_DATA_LEN
);
2806 if (info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]) {
2807 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2809 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2812 nla_memcpy(params
.macaddr
,
2813 info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
],
2818 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2819 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2823 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2827 if (!err
&& params
.use_4addr
!= -1)
2828 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2833 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2835 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2836 struct vif_params params
;
2837 struct wireless_dev
*wdev
;
2838 struct sk_buff
*msg
;
2840 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2843 /* to avoid failing a new interface creation due to pending removal */
2844 cfg80211_destroy_ifaces(rdev
);
2846 memset(¶ms
, 0, sizeof(params
));
2848 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2851 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2852 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2853 if (type
> NL80211_IFTYPE_MAX
)
2857 if (!rdev
->ops
->add_virtual_intf
||
2858 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2861 if ((type
== NL80211_IFTYPE_P2P_DEVICE
|| type
== NL80211_IFTYPE_NAN
||
2862 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
2863 info
->attrs
[NL80211_ATTR_MAC
]) {
2864 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2866 if (!is_valid_ether_addr(params
.macaddr
))
2867 return -EADDRNOTAVAIL
;
2870 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2871 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2872 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2877 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2878 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2881 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2882 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2885 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2889 wdev
= rdev_add_virtual_intf(rdev
,
2890 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2891 NET_NAME_USER
, type
, err
? NULL
: &flags
,
2893 if (WARN_ON(!wdev
)) {
2896 } else if (IS_ERR(wdev
)) {
2898 return PTR_ERR(wdev
);
2901 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
2902 wdev
->owner_nlportid
= info
->snd_portid
;
2905 case NL80211_IFTYPE_MESH_POINT
:
2906 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2909 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2910 IEEE80211_MAX_MESH_ID_LEN
);
2911 wdev
->mesh_id_up_len
=
2912 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2913 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2914 wdev
->mesh_id_up_len
);
2917 case NL80211_IFTYPE_NAN
:
2918 case NL80211_IFTYPE_P2P_DEVICE
:
2920 * P2P Device and NAN do not have a netdev, so don't go
2921 * through the netdev notifier and must be added here
2923 mutex_init(&wdev
->mtx
);
2924 INIT_LIST_HEAD(&wdev
->event_list
);
2925 spin_lock_init(&wdev
->event_lock
);
2926 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2927 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2929 wdev
->identifier
= ++rdev
->wdev_id
;
2930 list_add_rcu(&wdev
->list
, &rdev
->wiphy
.wdev_list
);
2931 rdev
->devlist_generation
++;
2937 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2938 rdev
, wdev
, false) < 0) {
2944 * For wdevs which have no associated netdev object (e.g. of type
2945 * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here.
2946 * For all other types, the event will be generated from the
2950 nl80211_notify_iface(rdev
, wdev
, NL80211_CMD_NEW_INTERFACE
);
2952 return genlmsg_reply(msg
, info
);
2955 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2957 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2958 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2960 if (!rdev
->ops
->del_virtual_intf
)
2964 * If we remove a wireless device without a netdev then clear
2965 * user_ptr[1] so that nl80211_post_doit won't dereference it
2966 * to check if it needs to do dev_put(). Otherwise it crashes
2967 * since the wdev has been freed, unlike with a netdev where
2968 * we need the dev_put() for the netdev to really be freed.
2971 info
->user_ptr
[1] = NULL
;
2973 return rdev_del_virtual_intf(rdev
, wdev
);
2976 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2978 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2979 struct net_device
*dev
= info
->user_ptr
[1];
2982 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2985 if (!rdev
->ops
->set_noack_map
)
2988 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2990 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2993 struct get_key_cookie
{
2994 struct sk_buff
*msg
;
2999 static void get_key_callback(void *c
, struct key_params
*params
)
3002 struct get_key_cookie
*cookie
= c
;
3005 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
3006 params
->key_len
, params
->key
)) ||
3008 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
3009 params
->seq_len
, params
->seq
)) ||
3011 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
3013 goto nla_put_failure
;
3015 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
3017 goto nla_put_failure
;
3020 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
3021 params
->key_len
, params
->key
)) ||
3023 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
3024 params
->seq_len
, params
->seq
)) ||
3026 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
3028 goto nla_put_failure
;
3030 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
3031 goto nla_put_failure
;
3033 nla_nest_end(cookie
->msg
, key
);
3040 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
3042 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3044 struct net_device
*dev
= info
->user_ptr
[1];
3046 const u8
*mac_addr
= NULL
;
3048 struct get_key_cookie cookie
= {
3052 struct sk_buff
*msg
;
3054 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
3055 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
3060 if (info
->attrs
[NL80211_ATTR_MAC
])
3061 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3063 pairwise
= !!mac_addr
;
3064 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
3065 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
3067 if (kt
>= NUM_NL80211_KEYTYPES
)
3069 if (kt
!= NL80211_KEYTYPE_GROUP
&&
3070 kt
!= NL80211_KEYTYPE_PAIRWISE
)
3072 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
3075 if (!rdev
->ops
->get_key
)
3078 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3081 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3085 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3086 NL80211_CMD_NEW_KEY
);
3088 goto nla_put_failure
;
3091 cookie
.idx
= key_idx
;
3093 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3094 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
3095 goto nla_put_failure
;
3097 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
3098 goto nla_put_failure
;
3100 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
3107 goto nla_put_failure
;
3109 genlmsg_end(msg
, hdr
);
3110 return genlmsg_reply(msg
, info
);
3119 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
3121 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3122 struct key_parse key
;
3124 struct net_device
*dev
= info
->user_ptr
[1];
3126 err
= nl80211_parse_key(info
, &key
);
3133 /* only support setting default key */
3134 if (!key
.def
&& !key
.defmgmt
)
3137 wdev_lock(dev
->ieee80211_ptr
);
3140 if (!rdev
->ops
->set_default_key
) {
3145 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3149 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
3150 key
.def_uni
, key
.def_multi
);
3155 #ifdef CONFIG_CFG80211_WEXT
3156 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
3159 if (key
.def_uni
|| !key
.def_multi
) {
3164 if (!rdev
->ops
->set_default_mgmt_key
) {
3169 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3173 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
3177 #ifdef CONFIG_CFG80211_WEXT
3178 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3183 wdev_unlock(dev
->ieee80211_ptr
);
3188 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3190 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3192 struct net_device
*dev
= info
->user_ptr
[1];
3193 struct key_parse key
;
3194 const u8
*mac_addr
= NULL
;
3196 err
= nl80211_parse_key(info
, &key
);
3203 if (info
->attrs
[NL80211_ATTR_MAC
])
3204 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3206 if (key
.type
== -1) {
3208 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3210 key
.type
= NL80211_KEYTYPE_GROUP
;
3214 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3215 key
.type
!= NL80211_KEYTYPE_GROUP
)
3218 if (!rdev
->ops
->add_key
)
3221 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3222 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3226 wdev_lock(dev
->ieee80211_ptr
);
3227 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3229 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3230 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3232 wdev_unlock(dev
->ieee80211_ptr
);
3237 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3239 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3241 struct net_device
*dev
= info
->user_ptr
[1];
3242 u8
*mac_addr
= NULL
;
3243 struct key_parse key
;
3245 err
= nl80211_parse_key(info
, &key
);
3249 if (info
->attrs
[NL80211_ATTR_MAC
])
3250 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3252 if (key
.type
== -1) {
3254 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3256 key
.type
= NL80211_KEYTYPE_GROUP
;
3260 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3261 key
.type
!= NL80211_KEYTYPE_GROUP
)
3264 if (!rdev
->ops
->del_key
)
3267 wdev_lock(dev
->ieee80211_ptr
);
3268 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3270 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3271 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3275 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3276 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3279 #ifdef CONFIG_CFG80211_WEXT
3281 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3282 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3283 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3284 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3287 wdev_unlock(dev
->ieee80211_ptr
);
3292 /* This function returns an error or the number of nested attributes */
3293 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3295 struct nlattr
*attr
;
3296 int n_entries
= 0, tmp
;
3298 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3299 if (nla_len(attr
) != ETH_ALEN
)
3309 * This function parses ACL information and allocates memory for ACL data.
3310 * On successful return, the calling function is responsible to free the
3311 * ACL buffer returned by this function.
3313 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3314 struct genl_info
*info
)
3316 enum nl80211_acl_policy acl_policy
;
3317 struct nlattr
*attr
;
3318 struct cfg80211_acl_data
*acl
;
3319 int i
= 0, n_entries
, tmp
;
3321 if (!wiphy
->max_acl_mac_addrs
)
3322 return ERR_PTR(-EOPNOTSUPP
);
3324 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3325 return ERR_PTR(-EINVAL
);
3327 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3328 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3329 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3330 return ERR_PTR(-EINVAL
);
3332 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3333 return ERR_PTR(-EINVAL
);
3335 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3337 return ERR_PTR(n_entries
);
3339 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3340 return ERR_PTR(-ENOTSUPP
);
3342 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3345 return ERR_PTR(-ENOMEM
);
3347 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3348 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3352 acl
->n_acl_entries
= n_entries
;
3353 acl
->acl_policy
= acl_policy
;
3358 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3360 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3361 struct net_device
*dev
= info
->user_ptr
[1];
3362 struct cfg80211_acl_data
*acl
;
3365 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3366 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3369 if (!dev
->ieee80211_ptr
->beacon_interval
)
3372 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3374 return PTR_ERR(acl
);
3376 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3383 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
3384 u8
*rates
, u8 rates_len
)
3389 for (i
= 0; i
< rates_len
; i
++) {
3390 int rate
= (rates
[i
] & 0x7f) * 5;
3393 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
3394 struct ieee80211_rate
*srate
=
3395 &sband
->bitrates
[ridx
];
3396 if (rate
== srate
->bitrate
) {
3401 if (ridx
== sband
->n_bitrates
)
3402 return 0; /* rate not found */
3408 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
3409 u8
*rates
, u8 rates_len
,
3410 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
3414 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
3416 for (i
= 0; i
< rates_len
; i
++) {
3419 ridx
= rates
[i
] / 8;
3420 rbit
= BIT(rates
[i
] % 8);
3422 /* check validity */
3423 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
3426 /* check availability */
3427 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
3436 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
3440 switch (vht_mcs_map
) {
3441 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
3443 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
3446 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
3449 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
3459 static void vht_build_mcs_mask(u16 vht_mcs_map
,
3460 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
3464 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
3465 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
3470 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
3471 struct nl80211_txrate_vht
*txrate
,
3472 u16 mcs
[NL80211_VHT_NSS_MAX
])
3474 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3475 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
3478 if (!sband
->vht_cap
.vht_supported
)
3481 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
3483 /* Build vht_mcs_mask from VHT capabilities */
3484 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
3486 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3487 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
3488 mcs
[i
] = txrate
->mcs
[i
];
3496 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
3497 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
3498 .len
= NL80211_MAX_SUPP_RATES
},
3499 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
3500 .len
= NL80211_MAX_SUPP_HT_RATES
},
3501 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
3502 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
3505 static int nl80211_parse_tx_bitrate_mask(struct genl_info
*info
,
3506 struct cfg80211_bitrate_mask
*mask
)
3508 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
3509 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3511 struct nlattr
*tx_rates
;
3512 struct ieee80211_supported_band
*sband
;
3515 memset(mask
, 0, sizeof(*mask
));
3516 /* Default to all rates enabled */
3517 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
3518 sband
= rdev
->wiphy
.bands
[i
];
3523 mask
->control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
3524 memcpy(mask
->control
[i
].ht_mcs
,
3525 sband
->ht_cap
.mcs
.rx_mask
,
3526 sizeof(mask
->control
[i
].ht_mcs
));
3528 if (!sband
->vht_cap
.vht_supported
)
3531 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
3532 vht_build_mcs_mask(vht_tx_mcs_map
, mask
->control
[i
].vht_mcs
);
3535 /* if no rates are given set it back to the defaults */
3536 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
3539 /* The nested attribute uses enum nl80211_band as the index. This maps
3540 * directly to the enum nl80211_band values used in cfg80211.
3542 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
3543 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
3544 enum nl80211_band band
= nla_type(tx_rates
);
3547 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
3549 sband
= rdev
->wiphy
.bands
[band
];
3552 err
= nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
3553 nla_len(tx_rates
), nl80211_txattr_policy
);
3556 if (tb
[NL80211_TXRATE_LEGACY
]) {
3557 mask
->control
[band
].legacy
= rateset_to_mask(
3559 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
3560 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
3561 if ((mask
->control
[band
].legacy
== 0) &&
3562 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
3565 if (tb
[NL80211_TXRATE_HT
]) {
3566 if (!ht_rateset_to_mask(
3568 nla_data(tb
[NL80211_TXRATE_HT
]),
3569 nla_len(tb
[NL80211_TXRATE_HT
]),
3570 mask
->control
[band
].ht_mcs
))
3573 if (tb
[NL80211_TXRATE_VHT
]) {
3574 if (!vht_set_mcs_mask(
3576 nla_data(tb
[NL80211_TXRATE_VHT
]),
3577 mask
->control
[band
].vht_mcs
))
3580 if (tb
[NL80211_TXRATE_GI
]) {
3581 mask
->control
[band
].gi
=
3582 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
3583 if (mask
->control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
3587 if (mask
->control
[band
].legacy
== 0) {
3588 /* don't allow empty legacy rates if HT or VHT
3589 * are not even supported.
3591 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
3592 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
3595 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3596 if (mask
->control
[band
].ht_mcs
[i
])
3599 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3600 if (mask
->control
[band
].vht_mcs
[i
])
3603 /* legacy and mcs rates may not be both empty */
3612 static int validate_beacon_tx_rate(struct cfg80211_registered_device
*rdev
,
3613 enum nl80211_band band
,
3614 struct cfg80211_bitrate_mask
*beacon_rate
)
3616 u32 count_ht
, count_vht
, i
;
3617 u32 rate
= beacon_rate
->control
[band
].legacy
;
3619 /* Allow only one rate */
3620 if (hweight32(rate
) > 1)
3624 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
3625 if (hweight8(beacon_rate
->control
[band
].ht_mcs
[i
]) > 1) {
3627 } else if (beacon_rate
->control
[band
].ht_mcs
[i
]) {
3632 if (count_ht
&& rate
)
3637 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3638 if (hweight16(beacon_rate
->control
[band
].vht_mcs
[i
]) > 1) {
3640 } else if (beacon_rate
->control
[band
].vht_mcs
[i
]) {
3645 if (count_vht
&& rate
)
3649 if ((count_ht
&& count_vht
) || (!rate
&& !count_ht
&& !count_vht
))
3653 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3654 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
))
3657 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3658 NL80211_EXT_FEATURE_BEACON_RATE_HT
))
3661 !wiphy_ext_feature_isset(&rdev
->wiphy
,
3662 NL80211_EXT_FEATURE_BEACON_RATE_VHT
))
3668 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3669 struct cfg80211_beacon_data
*bcn
)
3671 bool haveinfo
= false;
3673 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3674 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3675 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3676 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3679 memset(bcn
, 0, sizeof(*bcn
));
3681 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3682 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3683 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3689 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3690 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3691 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3698 if (attrs
[NL80211_ATTR_IE
]) {
3699 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3700 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3703 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3704 bcn
->proberesp_ies
=
3705 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3706 bcn
->proberesp_ies_len
=
3707 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3710 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3711 bcn
->assocresp_ies
=
3712 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3713 bcn
->assocresp_ies_len
=
3714 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3717 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3718 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3719 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3725 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3726 struct cfg80211_ap_settings
*params
)
3728 struct wireless_dev
*wdev
;
3731 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
3732 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3733 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3736 if (!wdev
->preset_chandef
.chan
)
3739 params
->chandef
= wdev
->preset_chandef
;
3747 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3748 enum nl80211_auth_type auth_type
,
3749 enum nl80211_commands cmd
)
3751 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3755 case NL80211_CMD_AUTHENTICATE
:
3756 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3757 auth_type
== NL80211_AUTHTYPE_SAE
)
3760 case NL80211_CMD_CONNECT
:
3761 case NL80211_CMD_START_AP
:
3762 /* SAE not supported yet */
3763 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3771 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3773 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3774 struct net_device
*dev
= info
->user_ptr
[1];
3775 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3776 struct cfg80211_ap_settings params
;
3779 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3780 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3783 if (!rdev
->ops
->start_ap
)
3786 if (wdev
->beacon_interval
)
3789 memset(¶ms
, 0, sizeof(params
));
3791 /* these are required for START_AP */
3792 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3793 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3794 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3797 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3801 params
.beacon_interval
=
3802 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3803 params
.dtim_period
=
3804 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3806 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3811 * In theory, some of these attributes should be required here
3812 * but since they were not used when the command was originally
3813 * added, keep them optional for old user space programs to let
3814 * them continue to work with drivers that do not need the
3815 * additional information -- drivers must check!
3817 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3818 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3820 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3821 if (params
.ssid_len
== 0 ||
3822 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3826 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3827 params
.hidden_ssid
= nla_get_u32(
3828 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3829 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3830 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3831 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3835 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3837 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3838 params
.auth_type
= nla_get_u32(
3839 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3840 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3841 NL80211_CMD_START_AP
))
3844 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3846 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3847 NL80211_MAX_NR_CIPHER_SUITES
);
3851 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3852 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3854 params
.inactivity_timeout
= nla_get_u16(
3855 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3858 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3859 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3861 params
.p2p_ctwindow
=
3862 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3863 if (params
.p2p_ctwindow
> 127)
3865 if (params
.p2p_ctwindow
!= 0 &&
3866 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3870 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3873 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3875 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3878 params
.p2p_opp_ps
= tmp
;
3879 if (params
.p2p_opp_ps
!= 0 &&
3880 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3884 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3885 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3888 } else if (wdev
->preset_chandef
.chan
) {
3889 params
.chandef
= wdev
->preset_chandef
;
3890 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3893 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
3897 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
3898 err
= nl80211_parse_tx_bitrate_mask(info
, ¶ms
.beacon_rate
);
3902 err
= validate_beacon_tx_rate(rdev
, params
.chandef
.chan
->band
,
3903 ¶ms
.beacon_rate
);
3908 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
3910 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
3911 switch (params
.smps_mode
) {
3912 case NL80211_SMPS_OFF
:
3914 case NL80211_SMPS_STATIC
:
3915 if (!(rdev
->wiphy
.features
&
3916 NL80211_FEATURE_STATIC_SMPS
))
3919 case NL80211_SMPS_DYNAMIC
:
3920 if (!(rdev
->wiphy
.features
&
3921 NL80211_FEATURE_DYNAMIC_SMPS
))
3928 params
.smps_mode
= NL80211_SMPS_OFF
;
3931 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
3932 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
3935 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3936 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3937 if (IS_ERR(params
.acl
))
3938 return PTR_ERR(params
.acl
);
3942 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3944 wdev
->preset_chandef
= params
.chandef
;
3945 wdev
->beacon_interval
= params
.beacon_interval
;
3946 wdev
->chandef
= params
.chandef
;
3947 wdev
->ssid_len
= params
.ssid_len
;
3948 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3957 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3959 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3960 struct net_device
*dev
= info
->user_ptr
[1];
3961 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3962 struct cfg80211_beacon_data params
;
3965 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3966 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3969 if (!rdev
->ops
->change_beacon
)
3972 if (!wdev
->beacon_interval
)
3975 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3980 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
3986 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3988 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3989 struct net_device
*dev
= info
->user_ptr
[1];
3991 return cfg80211_stop_ap(rdev
, dev
, false);
3994 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3995 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3996 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3997 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3998 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3999 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
4000 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
4003 static int parse_station_flags(struct genl_info
*info
,
4004 enum nl80211_iftype iftype
,
4005 struct station_parameters
*params
)
4007 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
4012 * Try parsing the new attribute first so userspace
4013 * can specify both for older kernels.
4015 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
4017 struct nl80211_sta_flag_update
*sta_flags
;
4019 sta_flags
= nla_data(nla
);
4020 params
->sta_flags_mask
= sta_flags
->mask
;
4021 params
->sta_flags_set
= sta_flags
->set
;
4022 params
->sta_flags_set
&= params
->sta_flags_mask
;
4023 if ((params
->sta_flags_mask
|
4024 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
4029 /* if present, parse the old attribute */
4031 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
4035 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
4036 nla
, sta_flags_policy
))
4040 * Only allow certain flags for interface types so that
4041 * other attributes are silently ignored. Remember that
4042 * this is backward compatibility code with old userspace
4043 * and shouldn't be hit in other cases anyway.
4046 case NL80211_IFTYPE_AP
:
4047 case NL80211_IFTYPE_AP_VLAN
:
4048 case NL80211_IFTYPE_P2P_GO
:
4049 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4050 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4051 BIT(NL80211_STA_FLAG_WME
) |
4052 BIT(NL80211_STA_FLAG_MFP
);
4054 case NL80211_IFTYPE_P2P_CLIENT
:
4055 case NL80211_IFTYPE_STATION
:
4056 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4057 BIT(NL80211_STA_FLAG_TDLS_PEER
);
4059 case NL80211_IFTYPE_MESH_POINT
:
4060 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4061 BIT(NL80211_STA_FLAG_MFP
) |
4062 BIT(NL80211_STA_FLAG_AUTHORIZED
);
4067 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
4069 params
->sta_flags_set
|= (1<<flag
);
4071 /* no longer support new API additions in old API */
4072 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
4080 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
4083 struct nlattr
*rate
;
4086 enum nl80211_attrs rate_flg
;
4088 rate
= nla_nest_start(msg
, attr
);
4092 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
4093 bitrate
= cfg80211_calculate_bitrate(info
);
4094 /* report 16-bit bitrate only if we can */
4095 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
4097 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
4099 if (bitrate_compat
> 0 &&
4100 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
4104 case RATE_INFO_BW_5
:
4105 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
4107 case RATE_INFO_BW_10
:
4108 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
4113 case RATE_INFO_BW_20
:
4116 case RATE_INFO_BW_40
:
4117 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
4119 case RATE_INFO_BW_80
:
4120 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
4122 case RATE_INFO_BW_160
:
4123 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
4127 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
4130 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
4131 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
4133 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4134 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4136 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
4137 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
4139 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
4141 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
4142 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
4146 nla_nest_end(msg
, rate
);
4150 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
4159 attr
= nla_nest_start(msg
, id
);
4163 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
4164 if (!(mask
& BIT(i
)))
4167 if (nla_put_u8(msg
, i
, signal
[i
]))
4171 nla_nest_end(msg
, attr
);
4176 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
4178 struct cfg80211_registered_device
*rdev
,
4179 struct net_device
*dev
,
4180 const u8
*mac_addr
, struct station_info
*sinfo
)
4183 struct nlattr
*sinfoattr
, *bss_param
;
4185 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
4189 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4190 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
4191 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
4192 goto nla_put_failure
;
4194 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
4196 goto nla_put_failure
;
4198 #define PUT_SINFO(attr, memb, type) do { \
4199 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
4200 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4201 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
4203 goto nla_put_failure; \
4205 #define PUT_SINFO_U64(attr, memb) do { \
4206 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
4207 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
4208 sinfo->memb, NL80211_STA_INFO_PAD)) \
4209 goto nla_put_failure; \
4212 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
4213 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
4215 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
4216 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
4217 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
4218 (u32
)sinfo
->rx_bytes
))
4219 goto nla_put_failure
;
4221 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
4222 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
4223 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
4224 (u32
)sinfo
->tx_bytes
))
4225 goto nla_put_failure
;
4227 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
4228 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
4229 PUT_SINFO(LLID
, llid
, u16
);
4230 PUT_SINFO(PLID
, plid
, u16
);
4231 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
4232 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
4234 switch (rdev
->wiphy
.signal_type
) {
4235 case CFG80211_SIGNAL_TYPE_MBM
:
4236 PUT_SINFO(SIGNAL
, signal
, u8
);
4237 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
4242 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
4243 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4244 sinfo
->chain_signal
,
4245 NL80211_STA_INFO_CHAIN_SIGNAL
))
4246 goto nla_put_failure
;
4248 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
4249 if (!nl80211_put_signal(msg
, sinfo
->chains
,
4250 sinfo
->chain_signal_avg
,
4251 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
4252 goto nla_put_failure
;
4254 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
4255 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
4256 NL80211_STA_INFO_TX_BITRATE
))
4257 goto nla_put_failure
;
4259 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
4260 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
4261 NL80211_STA_INFO_RX_BITRATE
))
4262 goto nla_put_failure
;
4265 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
4266 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
4267 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
4268 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
4269 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
4270 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
4271 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
4272 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
4273 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
4275 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
4276 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
4278 goto nla_put_failure
;
4280 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
4281 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
4282 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
4283 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
4284 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
4285 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
4286 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
4287 sinfo
->bss_param
.dtim_period
) ||
4288 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
4289 sinfo
->bss_param
.beacon_interval
))
4290 goto nla_put_failure
;
4292 nla_nest_end(msg
, bss_param
);
4294 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
4295 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
4296 sizeof(struct nl80211_sta_flag_update
),
4298 goto nla_put_failure
;
4300 PUT_SINFO_U64(T_OFFSET
, t_offset
);
4301 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
4302 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
4303 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
4306 #undef PUT_SINFO_U64
4308 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TID_STATS
)) {
4309 struct nlattr
*tidsattr
;
4312 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
4314 goto nla_put_failure
;
4316 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
4317 struct cfg80211_tid_stats
*tidstats
;
4318 struct nlattr
*tidattr
;
4320 tidstats
= &sinfo
->pertid
[tid
];
4322 if (!tidstats
->filled
)
4325 tidattr
= nla_nest_start(msg
, tid
+ 1);
4327 goto nla_put_failure
;
4329 #define PUT_TIDVAL_U64(attr, memb) do { \
4330 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
4331 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
4332 tidstats->memb, NL80211_TID_STATS_PAD)) \
4333 goto nla_put_failure; \
4336 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
4337 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
4338 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
4339 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
4341 #undef PUT_TIDVAL_U64
4342 nla_nest_end(msg
, tidattr
);
4345 nla_nest_end(msg
, tidsattr
);
4348 nla_nest_end(msg
, sinfoattr
);
4350 if (sinfo
->assoc_req_ies_len
&&
4351 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
4352 sinfo
->assoc_req_ies
))
4353 goto nla_put_failure
;
4355 genlmsg_end(msg
, hdr
);
4359 genlmsg_cancel(msg
, hdr
);
4363 static int nl80211_dump_station(struct sk_buff
*skb
,
4364 struct netlink_callback
*cb
)
4366 struct station_info sinfo
;
4367 struct cfg80211_registered_device
*rdev
;
4368 struct wireless_dev
*wdev
;
4369 u8 mac_addr
[ETH_ALEN
];
4370 int sta_idx
= cb
->args
[2];
4373 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4377 if (!wdev
->netdev
) {
4382 if (!rdev
->ops
->dump_station
) {
4388 memset(&sinfo
, 0, sizeof(sinfo
));
4389 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
4396 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
4397 NETLINK_CB(cb
->skb
).portid
,
4398 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4399 rdev
, wdev
->netdev
, mac_addr
,
4407 cb
->args
[2] = sta_idx
;
4410 nl80211_finish_wdev_dump(rdev
);
4415 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
4417 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4418 struct net_device
*dev
= info
->user_ptr
[1];
4419 struct station_info sinfo
;
4420 struct sk_buff
*msg
;
4421 u8
*mac_addr
= NULL
;
4424 memset(&sinfo
, 0, sizeof(sinfo
));
4426 if (!info
->attrs
[NL80211_ATTR_MAC
])
4429 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4431 if (!rdev
->ops
->get_station
)
4434 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
4438 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4442 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
4443 info
->snd_portid
, info
->snd_seq
, 0,
4444 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
4449 return genlmsg_reply(msg
, info
);
4452 int cfg80211_check_station_change(struct wiphy
*wiphy
,
4453 struct station_parameters
*params
,
4454 enum cfg80211_station_type statype
)
4456 if (params
->listen_interval
!= -1 &&
4457 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4460 if (params
->support_p2p_ps
!= -1 &&
4461 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4465 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
4466 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4469 /* When you run into this, adjust the code below for the new flag */
4470 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4473 case CFG80211_STA_MESH_PEER_KERNEL
:
4474 case CFG80211_STA_MESH_PEER_USER
:
4476 * No ignoring the TDLS flag here -- the userspace mesh
4477 * code doesn't have the bug of including TDLS in the
4480 if (params
->sta_flags_mask
&
4481 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4482 BIT(NL80211_STA_FLAG_MFP
) |
4483 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4486 case CFG80211_STA_TDLS_PEER_SETUP
:
4487 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4488 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4490 /* ignore since it can't change */
4491 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4494 /* disallow mesh-specific things */
4495 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4497 if (params
->local_pm
)
4499 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4503 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4504 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4505 /* TDLS can't be set, ... */
4506 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4509 * ... but don't bother the driver with it. This works around
4510 * a hostapd/wpa_supplicant issue -- it always includes the
4511 * TLDS_PEER flag in the mask even for AP mode.
4513 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4516 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4517 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4518 /* reject other things that can't change */
4519 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4521 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4523 if (params
->supported_rates
)
4525 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4529 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4530 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4536 case CFG80211_STA_AP_MLME_CLIENT
:
4537 /* Use this only for authorizing/unauthorizing a station */
4538 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4541 case CFG80211_STA_AP_CLIENT
:
4542 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4543 /* accept only the listed bits */
4544 if (params
->sta_flags_mask
&
4545 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4546 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4547 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4548 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4549 BIT(NL80211_STA_FLAG_WME
) |
4550 BIT(NL80211_STA_FLAG_MFP
)))
4553 /* but authenticated/associated only if driver handles it */
4554 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4555 params
->sta_flags_mask
&
4556 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4557 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4560 case CFG80211_STA_IBSS
:
4561 case CFG80211_STA_AP_STA
:
4562 /* reject any changes other than AUTHORIZED */
4563 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4566 case CFG80211_STA_TDLS_PEER_SETUP
:
4567 /* reject any changes other than AUTHORIZED or WME */
4568 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4569 BIT(NL80211_STA_FLAG_WME
)))
4571 /* force (at least) rates when authorizing */
4572 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4573 !params
->supported_rates
)
4576 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4577 /* reject any changes */
4579 case CFG80211_STA_MESH_PEER_KERNEL
:
4580 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4583 case CFG80211_STA_MESH_PEER_USER
:
4584 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4585 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4592 EXPORT_SYMBOL(cfg80211_check_station_change
);
4595 * Get vlan interface making sure it is running and on the right wiphy.
4597 static struct net_device
*get_vlan(struct genl_info
*info
,
4598 struct cfg80211_registered_device
*rdev
)
4600 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4601 struct net_device
*v
;
4607 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4609 return ERR_PTR(-ENODEV
);
4611 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4616 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4617 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4618 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4623 if (!netif_running(v
)) {
4631 return ERR_PTR(ret
);
4634 static const struct nla_policy
4635 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
4636 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
4637 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
4640 static int nl80211_parse_sta_wme(struct genl_info
*info
,
4641 struct station_parameters
*params
)
4643 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
4647 /* parse WME attributes if present */
4648 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
4651 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
4652 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
4653 nl80211_sta_wme_policy
);
4657 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4658 params
->uapsd_queues
= nla_get_u8(
4659 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4660 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4663 if (tb
[NL80211_STA_WME_MAX_SP
])
4664 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4666 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4669 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4674 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4675 struct station_parameters
*params
)
4677 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4678 params
->supported_channels
=
4679 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4680 params
->supported_channels_len
=
4681 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4683 * Need to include at least one (first channel, number of
4684 * channels) tuple for each subband, and must have proper
4685 * tuples for the rest of the data as well.
4687 if (params
->supported_channels_len
< 2)
4689 if (params
->supported_channels_len
% 2)
4693 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4694 params
->supported_oper_classes
=
4695 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4696 params
->supported_oper_classes_len
=
4697 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4699 * The value of the Length field of the Supported Operating
4700 * Classes element is between 2 and 253.
4702 if (params
->supported_oper_classes_len
< 2 ||
4703 params
->supported_oper_classes_len
> 253)
4709 static int nl80211_set_station_tdls(struct genl_info
*info
,
4710 struct station_parameters
*params
)
4713 /* Dummy STA entry gets updated once the peer capabilities are known */
4714 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4715 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4716 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4718 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4719 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4721 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4723 err
= nl80211_parse_sta_channel_info(info
, params
);
4727 return nl80211_parse_sta_wme(info
, params
);
4730 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4732 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4733 struct net_device
*dev
= info
->user_ptr
[1];
4734 struct station_parameters params
;
4738 memset(¶ms
, 0, sizeof(params
));
4740 if (!rdev
->ops
->change_station
)
4744 * AID and listen_interval properties can be set only for unassociated
4745 * station. Include these parameters here and will check them in
4746 * cfg80211_check_station_change().
4748 if (info
->attrs
[NL80211_ATTR_STA_AID
])
4749 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4751 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4752 params
.listen_interval
=
4753 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4755 params
.listen_interval
= -1;
4757 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
4760 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
4761 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
4764 params
.support_p2p_ps
= tmp
;
4766 params
.support_p2p_ps
= -1;
4769 if (!info
->attrs
[NL80211_ATTR_MAC
])
4772 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4774 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4775 params
.supported_rates
=
4776 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4777 params
.supported_rates_len
=
4778 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4781 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4783 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4784 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4787 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4789 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4790 params
.ext_capab_len
=
4791 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4794 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4797 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4798 params
.plink_action
=
4799 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4800 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4804 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4805 params
.plink_state
=
4806 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4807 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4809 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]) {
4810 params
.peer_aid
= nla_get_u16(
4811 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
4812 if (params
.peer_aid
> IEEE80211_MAX_AID
)
4815 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4818 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4819 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4820 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4822 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4823 pm
> NL80211_MESH_POWER_MAX
)
4826 params
.local_pm
= pm
;
4829 /* Include parameters for TDLS peer (will check later) */
4830 err
= nl80211_set_station_tdls(info
, ¶ms
);
4834 params
.vlan
= get_vlan(info
, rdev
);
4835 if (IS_ERR(params
.vlan
))
4836 return PTR_ERR(params
.vlan
);
4838 switch (dev
->ieee80211_ptr
->iftype
) {
4839 case NL80211_IFTYPE_AP
:
4840 case NL80211_IFTYPE_AP_VLAN
:
4841 case NL80211_IFTYPE_P2P_GO
:
4842 case NL80211_IFTYPE_P2P_CLIENT
:
4843 case NL80211_IFTYPE_STATION
:
4844 case NL80211_IFTYPE_ADHOC
:
4845 case NL80211_IFTYPE_MESH_POINT
:
4852 /* driver will call cfg80211_check_station_change() */
4853 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4857 dev_put(params
.vlan
);
4862 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4864 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4866 struct net_device
*dev
= info
->user_ptr
[1];
4867 struct station_parameters params
;
4868 u8
*mac_addr
= NULL
;
4869 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4870 BIT(NL80211_STA_FLAG_ASSOCIATED
);
4872 memset(¶ms
, 0, sizeof(params
));
4874 if (!rdev
->ops
->add_station
)
4877 if (!info
->attrs
[NL80211_ATTR_MAC
])
4880 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4883 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4886 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4887 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4890 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4891 params
.supported_rates
=
4892 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4893 params
.supported_rates_len
=
4894 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4895 params
.listen_interval
=
4896 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4898 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
4901 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
4902 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
4905 params
.support_p2p_ps
= tmp
;
4908 * if not specified, assume it's supported for P2P GO interface,
4909 * and is NOT supported for AP interface
4911 params
.support_p2p_ps
=
4912 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
4915 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4916 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4918 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4919 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4922 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4924 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4925 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4928 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4930 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4931 params
.ext_capab_len
=
4932 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4935 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4937 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4939 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4941 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4943 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4944 params
.opmode_notif_used
= true;
4945 params
.opmode_notif
=
4946 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4949 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4950 params
.plink_action
=
4951 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4952 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4956 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
4960 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4964 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4967 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4968 * as userspace might just pass through the capabilities from the IEs
4969 * directly, rather than enforcing this restriction and returning an
4970 * error in this case.
4972 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4973 params
.ht_capa
= NULL
;
4974 params
.vht_capa
= NULL
;
4977 /* When you run into this, adjust the code below for the new flag */
4978 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4980 switch (dev
->ieee80211_ptr
->iftype
) {
4981 case NL80211_IFTYPE_AP
:
4982 case NL80211_IFTYPE_AP_VLAN
:
4983 case NL80211_IFTYPE_P2P_GO
:
4984 /* ignore WME attributes if iface/sta is not capable */
4985 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4986 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4987 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4989 /* TDLS peers cannot be added */
4990 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4991 info
->attrs
[NL80211_ATTR_PEER_AID
])
4993 /* but don't bother the driver with it */
4994 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4996 /* allow authenticated/associated only if driver handles it */
4997 if (!(rdev
->wiphy
.features
&
4998 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4999 params
.sta_flags_mask
& auth_assoc
)
5002 /* Older userspace, or userspace wanting to be compatible with
5003 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
5004 * and assoc flags in the mask, but assumes the station will be
5005 * added as associated anyway since this was the required driver
5006 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
5008 * In order to not bother drivers with this quirk in the API
5009 * set the flags in both the mask and set for new stations in
5012 if (!(params
.sta_flags_mask
& auth_assoc
)) {
5013 params
.sta_flags_mask
|= auth_assoc
;
5014 params
.sta_flags_set
|= auth_assoc
;
5017 /* must be last in here for error handling */
5018 params
.vlan
= get_vlan(info
, rdev
);
5019 if (IS_ERR(params
.vlan
))
5020 return PTR_ERR(params
.vlan
);
5022 case NL80211_IFTYPE_MESH_POINT
:
5023 /* ignore uAPSD data */
5024 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5026 /* associated is disallowed */
5027 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
5029 /* TDLS peers cannot be added */
5030 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
5031 info
->attrs
[NL80211_ATTR_PEER_AID
])
5034 case NL80211_IFTYPE_STATION
:
5035 case NL80211_IFTYPE_P2P_CLIENT
:
5036 /* ignore uAPSD data */
5037 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
5039 /* these are disallowed */
5040 if (params
.sta_flags_mask
&
5041 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
5042 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
5044 /* Only TDLS peers can be added */
5045 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
5047 /* Can only add if TDLS ... */
5048 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
5050 /* ... with external setup is supported */
5051 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
5054 * Older wpa_supplicant versions always mark the TDLS peer
5055 * as authorized, but it shouldn't yet be.
5057 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
5063 /* be aware of params.vlan when changing code here */
5065 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
5068 dev_put(params
.vlan
);
5072 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
5074 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5075 struct net_device
*dev
= info
->user_ptr
[1];
5076 struct station_del_parameters params
;
5078 memset(¶ms
, 0, sizeof(params
));
5080 if (info
->attrs
[NL80211_ATTR_MAC
])
5081 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5083 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5084 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5085 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5086 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5089 if (!rdev
->ops
->del_station
)
5092 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
5094 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
5095 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
5096 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
5099 /* Default to Deauthentication frame */
5100 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
5103 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
5104 params
.reason_code
=
5105 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5106 if (params
.reason_code
== 0)
5107 return -EINVAL
; /* 0 is reserved */
5109 /* Default to reason code 2 */
5110 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
5113 return rdev_del_station(rdev
, dev
, ¶ms
);
5116 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5117 int flags
, struct net_device
*dev
,
5118 u8
*dst
, u8
*next_hop
,
5119 struct mpath_info
*pinfo
)
5122 struct nlattr
*pinfoattr
;
5124 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
5128 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5129 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
5130 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
5131 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
5132 goto nla_put_failure
;
5134 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
5136 goto nla_put_failure
;
5137 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
5138 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
5140 goto nla_put_failure
;
5141 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
5142 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
5143 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
5144 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
5146 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
5147 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
5149 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
5150 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
5152 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
5153 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
5154 pinfo
->discovery_timeout
)) ||
5155 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
5156 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
5157 pinfo
->discovery_retries
)))
5158 goto nla_put_failure
;
5160 nla_nest_end(msg
, pinfoattr
);
5162 genlmsg_end(msg
, hdr
);
5166 genlmsg_cancel(msg
, hdr
);
5170 static int nl80211_dump_mpath(struct sk_buff
*skb
,
5171 struct netlink_callback
*cb
)
5173 struct mpath_info pinfo
;
5174 struct cfg80211_registered_device
*rdev
;
5175 struct wireless_dev
*wdev
;
5177 u8 next_hop
[ETH_ALEN
];
5178 int path_idx
= cb
->args
[2];
5181 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5185 if (!rdev
->ops
->dump_mpath
) {
5190 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5196 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
5203 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5204 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5205 wdev
->netdev
, dst
, next_hop
,
5213 cb
->args
[2] = path_idx
;
5216 nl80211_finish_wdev_dump(rdev
);
5220 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5222 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5224 struct net_device
*dev
= info
->user_ptr
[1];
5225 struct mpath_info pinfo
;
5226 struct sk_buff
*msg
;
5228 u8 next_hop
[ETH_ALEN
];
5230 memset(&pinfo
, 0, sizeof(pinfo
));
5232 if (!info
->attrs
[NL80211_ATTR_MAC
])
5235 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5237 if (!rdev
->ops
->get_mpath
)
5240 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5243 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
5247 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5251 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5252 dev
, dst
, next_hop
, &pinfo
) < 0) {
5257 return genlmsg_reply(msg
, info
);
5260 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5262 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5263 struct net_device
*dev
= info
->user_ptr
[1];
5265 u8
*next_hop
= NULL
;
5267 if (!info
->attrs
[NL80211_ATTR_MAC
])
5270 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5273 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5274 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5276 if (!rdev
->ops
->change_mpath
)
5279 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5282 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
5285 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5287 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5288 struct net_device
*dev
= info
->user_ptr
[1];
5290 u8
*next_hop
= NULL
;
5292 if (!info
->attrs
[NL80211_ATTR_MAC
])
5295 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
5298 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5299 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
5301 if (!rdev
->ops
->add_mpath
)
5304 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5307 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
5310 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
5312 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5313 struct net_device
*dev
= info
->user_ptr
[1];
5316 if (info
->attrs
[NL80211_ATTR_MAC
])
5317 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5319 if (!rdev
->ops
->del_mpath
)
5322 return rdev_del_mpath(rdev
, dev
, dst
);
5325 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
5327 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5329 struct net_device
*dev
= info
->user_ptr
[1];
5330 struct mpath_info pinfo
;
5331 struct sk_buff
*msg
;
5335 memset(&pinfo
, 0, sizeof(pinfo
));
5337 if (!info
->attrs
[NL80211_ATTR_MAC
])
5340 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5342 if (!rdev
->ops
->get_mpp
)
5345 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5348 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
5352 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5356 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5357 dev
, dst
, mpp
, &pinfo
) < 0) {
5362 return genlmsg_reply(msg
, info
);
5365 static int nl80211_dump_mpp(struct sk_buff
*skb
,
5366 struct netlink_callback
*cb
)
5368 struct mpath_info pinfo
;
5369 struct cfg80211_registered_device
*rdev
;
5370 struct wireless_dev
*wdev
;
5373 int path_idx
= cb
->args
[2];
5376 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5380 if (!rdev
->ops
->dump_mpp
) {
5385 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5391 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
5398 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5399 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5400 wdev
->netdev
, dst
, mpp
,
5408 cb
->args
[2] = path_idx
;
5411 nl80211_finish_wdev_dump(rdev
);
5415 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
5417 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5418 struct net_device
*dev
= info
->user_ptr
[1];
5419 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5420 struct bss_parameters params
;
5423 memset(¶ms
, 0, sizeof(params
));
5424 /* default to not changing parameters */
5425 params
.use_cts_prot
= -1;
5426 params
.use_short_preamble
= -1;
5427 params
.use_short_slot_time
= -1;
5428 params
.ap_isolate
= -1;
5429 params
.ht_opmode
= -1;
5430 params
.p2p_ctwindow
= -1;
5431 params
.p2p_opp_ps
= -1;
5433 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
5434 params
.use_cts_prot
=
5435 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
5436 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
5437 params
.use_short_preamble
=
5438 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
5439 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
5440 params
.use_short_slot_time
=
5441 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
5442 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5443 params
.basic_rates
=
5444 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5445 params
.basic_rates_len
=
5446 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5448 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
5449 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
5450 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
5452 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
5454 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
5455 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5457 params
.p2p_ctwindow
=
5458 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
5459 if (params
.p2p_ctwindow
< 0)
5461 if (params
.p2p_ctwindow
!= 0 &&
5462 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
5466 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
5469 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5471 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
5474 params
.p2p_opp_ps
= tmp
;
5475 if (params
.p2p_opp_ps
&&
5476 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
5480 if (!rdev
->ops
->change_bss
)
5483 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5484 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5488 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
5494 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5498 enum nl80211_user_reg_hint_type user_reg_hint_type
;
5502 * You should only get this when cfg80211 hasn't yet initialized
5503 * completely when built-in to the kernel right between the time
5504 * window between nl80211_init() and regulatory_init(), if that is
5507 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
5508 return -EINPROGRESS
;
5510 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
5511 user_reg_hint_type
=
5512 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
5514 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
5516 switch (user_reg_hint_type
) {
5517 case NL80211_USER_REG_HINT_USER
:
5518 case NL80211_USER_REG_HINT_CELL_BASE
:
5519 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5522 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5523 return regulatory_hint_user(data
, user_reg_hint_type
);
5524 case NL80211_USER_REG_HINT_INDOOR
:
5525 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
5526 owner_nlportid
= info
->snd_portid
;
5527 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
5533 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
5539 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
5540 struct genl_info
*info
)
5542 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5543 struct net_device
*dev
= info
->user_ptr
[1];
5544 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5545 struct mesh_config cur_params
;
5548 struct nlattr
*pinfoattr
;
5549 struct sk_buff
*msg
;
5551 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5554 if (!rdev
->ops
->get_mesh_config
)
5558 /* If not connected, get default parameters */
5559 if (!wdev
->mesh_id_len
)
5560 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5562 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5568 /* Draw up a netlink message to send back */
5569 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5572 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5573 NL80211_CMD_GET_MESH_CONFIG
);
5576 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5578 goto nla_put_failure
;
5579 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5580 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5581 cur_params
.dot11MeshRetryTimeout
) ||
5582 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5583 cur_params
.dot11MeshConfirmTimeout
) ||
5584 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5585 cur_params
.dot11MeshHoldingTimeout
) ||
5586 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5587 cur_params
.dot11MeshMaxPeerLinks
) ||
5588 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5589 cur_params
.dot11MeshMaxRetries
) ||
5590 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5591 cur_params
.dot11MeshTTL
) ||
5592 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5593 cur_params
.element_ttl
) ||
5594 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5595 cur_params
.auto_open_plinks
) ||
5596 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5597 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5598 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5599 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5600 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5601 cur_params
.path_refresh_time
) ||
5602 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5603 cur_params
.min_discovery_timeout
) ||
5604 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5605 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5606 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5607 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5608 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5609 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5610 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5611 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5612 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5613 cur_params
.dot11MeshHWMPRootMode
) ||
5614 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5615 cur_params
.dot11MeshHWMPRannInterval
) ||
5616 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5617 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
5618 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
5619 cur_params
.dot11MeshForwarding
) ||
5620 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5621 cur_params
.rssi_threshold
) ||
5622 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
5623 cur_params
.ht_opmode
) ||
5624 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5625 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
5626 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5627 cur_params
.dot11MeshHWMProotInterval
) ||
5628 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5629 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
5630 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
5631 cur_params
.power_mode
) ||
5632 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
5633 cur_params
.dot11MeshAwakeWindowDuration
) ||
5634 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5635 cur_params
.plink_timeout
))
5636 goto nla_put_failure
;
5637 nla_nest_end(msg
, pinfoattr
);
5638 genlmsg_end(msg
, hdr
);
5639 return genlmsg_reply(msg
, info
);
5642 genlmsg_cancel(msg
, hdr
);
5648 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
5649 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
5650 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
5651 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
5652 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
5653 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
5654 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
5655 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
5656 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
5657 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
5658 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
5659 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
5660 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
5661 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
5662 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
5663 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
5664 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
5665 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
5666 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
5667 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
5668 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
5669 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
5670 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
5671 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
5672 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
5673 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
5674 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
5675 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
5676 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
5679 static const struct nla_policy
5680 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
5681 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
5682 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
5683 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
5684 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
5685 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
5686 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
5687 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
5688 .len
= IEEE80211_MAX_DATA_LEN
},
5689 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
5692 static int nl80211_check_bool(const struct nlattr
*nla
, u8 min
, u8 max
, bool *out
)
5694 u8 val
= nla_get_u8(nla
);
5695 if (val
< min
|| val
> max
)
5701 static int nl80211_check_u8(const struct nlattr
*nla
, u8 min
, u8 max
, u8
*out
)
5703 u8 val
= nla_get_u8(nla
);
5704 if (val
< min
|| val
> max
)
5710 static int nl80211_check_u16(const struct nlattr
*nla
, u16 min
, u16 max
, u16
*out
)
5712 u16 val
= nla_get_u16(nla
);
5713 if (val
< min
|| val
> max
)
5719 static int nl80211_check_u32(const struct nlattr
*nla
, u32 min
, u32 max
, u32
*out
)
5721 u32 val
= nla_get_u32(nla
);
5722 if (val
< min
|| val
> max
)
5728 static int nl80211_check_s32(const struct nlattr
*nla
, s32 min
, s32 max
, s32
*out
)
5730 s32 val
= nla_get_s32(nla
);
5731 if (val
< min
|| val
> max
)
5737 static int nl80211_check_power_mode(const struct nlattr
*nla
,
5738 enum nl80211_mesh_power_mode min
,
5739 enum nl80211_mesh_power_mode max
,
5740 enum nl80211_mesh_power_mode
*out
)
5742 u32 val
= nla_get_u32(nla
);
5743 if (val
< min
|| val
> max
)
5749 static int nl80211_parse_mesh_config(struct genl_info
*info
,
5750 struct mesh_config
*cfg
,
5753 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
5757 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5760 if (fn(tb[attr], min, max, &cfg->param)) \
5762 mask |= (1 << (attr - 1)); \
5766 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
5768 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
5769 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
5770 nl80211_meshconf_params_policy
))
5773 /* This makes sure that there aren't more than 32 mesh config
5774 * parameters (otherwise our bitfield scheme would not work.) */
5775 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
5777 /* Fill in the params struct */
5778 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
5779 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5781 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
5782 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5784 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
5785 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5787 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
5788 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5790 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
5791 mask
, NL80211_MESHCONF_MAX_RETRIES
,
5793 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
5794 mask
, NL80211_MESHCONF_TTL
, nl80211_check_u8
);
5795 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
5796 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
5798 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
5799 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5800 nl80211_check_bool
);
5801 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
5803 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5805 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
5806 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5808 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
5809 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5811 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
5812 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5814 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
5816 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5818 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
5820 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5822 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
5824 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5826 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5827 dot11MeshHWMPnetDiameterTraversalTime
,
5829 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5831 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
5832 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5834 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
5835 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5837 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5838 dot11MeshGateAnnouncementProtocol
, 0, 1,
5839 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5840 nl80211_check_bool
);
5841 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
5842 mask
, NL80211_MESHCONF_FORWARDING
,
5843 nl80211_check_bool
);
5844 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
5845 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5848 * Check HT operation mode based on
5849 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5851 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
5852 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
5854 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
5855 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
5856 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
5859 if ((ht_opmode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
) &&
5860 (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
5863 switch (ht_opmode
& IEEE80211_HT_OP_MODE_PROTECTION
) {
5864 case IEEE80211_HT_OP_MODE_PROTECTION_NONE
:
5865 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
5866 if (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
)
5869 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER
:
5870 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
5871 if (!(ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
5875 cfg
->ht_opmode
= ht_opmode
;
5877 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
5879 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5881 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
5882 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5884 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5885 dot11MeshHWMPconfirmationInterval
,
5887 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5889 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
5890 NL80211_MESH_POWER_ACTIVE
,
5891 NL80211_MESH_POWER_MAX
,
5892 mask
, NL80211_MESHCONF_POWER_MODE
,
5893 nl80211_check_power_mode
);
5894 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
5896 NL80211_MESHCONF_AWAKE_WINDOW
, nl80211_check_u16
);
5897 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
5898 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5905 #undef FILL_IN_MESH_PARAM_IF_SET
5908 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
5909 struct mesh_setup
*setup
)
5911 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5912 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
5914 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
5916 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
5917 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
5918 nl80211_mesh_setup_params_policy
))
5921 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
5922 setup
->sync_method
=
5923 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
5924 IEEE80211_SYNC_METHOD_VENDOR
:
5925 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
5927 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
5928 setup
->path_sel_proto
=
5929 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
5930 IEEE80211_PATH_PROTOCOL_VENDOR
:
5931 IEEE80211_PATH_PROTOCOL_HWMP
;
5933 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
5934 setup
->path_metric
=
5935 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
5936 IEEE80211_PATH_METRIC_VENDOR
:
5937 IEEE80211_PATH_METRIC_AIRTIME
;
5939 if (tb
[NL80211_MESH_SETUP_IE
]) {
5940 struct nlattr
*ieattr
=
5941 tb
[NL80211_MESH_SETUP_IE
];
5942 if (!is_valid_ie_attr(ieattr
))
5944 setup
->ie
= nla_data(ieattr
);
5945 setup
->ie_len
= nla_len(ieattr
);
5947 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
5948 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
5950 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
5951 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
5952 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
5953 if (setup
->is_secure
)
5954 setup
->user_mpm
= true;
5956 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
5957 if (!setup
->user_mpm
)
5960 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
5966 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
5967 struct genl_info
*info
)
5969 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5970 struct net_device
*dev
= info
->user_ptr
[1];
5971 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5972 struct mesh_config cfg
;
5976 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5979 if (!rdev
->ops
->update_mesh_config
)
5982 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
5987 if (!wdev
->mesh_id_len
)
5991 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
5998 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
5999 struct sk_buff
*msg
)
6001 struct nlattr
*nl_reg_rules
;
6004 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
6005 (regdom
->dfs_region
&&
6006 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
6007 goto nla_put_failure
;
6009 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
6011 goto nla_put_failure
;
6013 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
6014 struct nlattr
*nl_reg_rule
;
6015 const struct ieee80211_reg_rule
*reg_rule
;
6016 const struct ieee80211_freq_range
*freq_range
;
6017 const struct ieee80211_power_rule
*power_rule
;
6018 unsigned int max_bandwidth_khz
;
6020 reg_rule
= ®dom
->reg_rules
[i
];
6021 freq_range
= ®_rule
->freq_range
;
6022 power_rule
= ®_rule
->power_rule
;
6024 nl_reg_rule
= nla_nest_start(msg
, i
);
6026 goto nla_put_failure
;
6028 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
6029 if (!max_bandwidth_khz
)
6030 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
6033 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
6035 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
6036 freq_range
->start_freq_khz
) ||
6037 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
6038 freq_range
->end_freq_khz
) ||
6039 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
6040 max_bandwidth_khz
) ||
6041 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
6042 power_rule
->max_antenna_gain
) ||
6043 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
6044 power_rule
->max_eirp
) ||
6045 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
6046 reg_rule
->dfs_cac_ms
))
6047 goto nla_put_failure
;
6049 nla_nest_end(msg
, nl_reg_rule
);
6052 nla_nest_end(msg
, nl_reg_rules
);
6059 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
6061 const struct ieee80211_regdomain
*regdom
= NULL
;
6062 struct cfg80211_registered_device
*rdev
;
6063 struct wiphy
*wiphy
= NULL
;
6064 struct sk_buff
*msg
;
6067 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6071 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6072 NL80211_CMD_GET_REG
);
6076 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
6079 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
6082 return PTR_ERR(rdev
);
6085 wiphy
= &rdev
->wiphy
;
6086 self_managed
= wiphy
->regulatory_flags
&
6087 REGULATORY_WIPHY_SELF_MANAGED
;
6088 regdom
= get_wiphy_regdom(wiphy
);
6090 /* a self-managed-reg device must have a private regdom */
6091 if (WARN_ON(!regdom
&& self_managed
)) {
6097 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6098 goto nla_put_failure
;
6101 if (!wiphy
&& reg_last_request_cell_base() &&
6102 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6103 NL80211_USER_REG_HINT_CELL_BASE
))
6104 goto nla_put_failure
;
6109 regdom
= rcu_dereference(cfg80211_regdomain
);
6111 if (nl80211_put_regdom(regdom
, msg
))
6112 goto nla_put_failure_rcu
;
6116 genlmsg_end(msg
, hdr
);
6117 return genlmsg_reply(msg
, info
);
6119 nla_put_failure_rcu
:
6122 genlmsg_cancel(msg
, hdr
);
6128 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6129 u32 seq
, int flags
, struct wiphy
*wiphy
,
6130 const struct ieee80211_regdomain
*regdom
)
6132 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6133 NL80211_CMD_GET_REG
);
6138 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
6140 if (nl80211_put_regdom(regdom
, msg
))
6141 goto nla_put_failure
;
6143 if (!wiphy
&& reg_last_request_cell_base() &&
6144 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
6145 NL80211_USER_REG_HINT_CELL_BASE
))
6146 goto nla_put_failure
;
6149 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
6150 goto nla_put_failure
;
6152 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
6153 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
6154 goto nla_put_failure
;
6156 genlmsg_end(msg
, hdr
);
6160 genlmsg_cancel(msg
, hdr
);
6164 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
6165 struct netlink_callback
*cb
)
6167 const struct ieee80211_regdomain
*regdom
= NULL
;
6168 struct cfg80211_registered_device
*rdev
;
6169 int err
, reg_idx
, start
= cb
->args
[2];
6173 if (cfg80211_regdomain
&& start
== 0) {
6174 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6176 rtnl_dereference(cfg80211_regdomain
));
6181 /* the global regdom is idx 0 */
6183 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
6184 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
6188 if (++reg_idx
<= start
)
6191 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
6192 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
6199 cb
->args
[2] = reg_idx
;
6206 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
6207 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
6208 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
6209 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
6210 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
6211 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
6212 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
6213 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
6214 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
6217 static int parse_reg_rule(struct nlattr
*tb
[],
6218 struct ieee80211_reg_rule
*reg_rule
)
6220 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
6221 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
6223 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
6225 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
6227 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
6229 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
6231 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
6234 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
6236 freq_range
->start_freq_khz
=
6237 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
6238 freq_range
->end_freq_khz
=
6239 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
6240 freq_range
->max_bandwidth_khz
=
6241 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
6243 power_rule
->max_eirp
=
6244 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
6246 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
6247 power_rule
->max_antenna_gain
=
6248 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
6250 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
6251 reg_rule
->dfs_cac_ms
=
6252 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
6257 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
6259 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
6260 struct nlattr
*nl_reg_rule
;
6262 int rem_reg_rules
, r
;
6263 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
6264 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
6265 struct ieee80211_regdomain
*rd
;
6267 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
6270 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
6273 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
6275 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
6276 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
6278 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6281 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
6285 if (!reg_is_valid_request(alpha2
))
6288 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
6289 num_rules
* sizeof(struct ieee80211_reg_rule
);
6291 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
6295 rd
->n_reg_rules
= num_rules
;
6296 rd
->alpha2
[0] = alpha2
[0];
6297 rd
->alpha2
[1] = alpha2
[1];
6300 * Disable DFS master mode if the DFS region was
6301 * not supported or known on this kernel.
6303 if (reg_supported_dfs_region(dfs_region
))
6304 rd
->dfs_region
= dfs_region
;
6306 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
6308 r
= nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
6309 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
6313 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
6319 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
6325 /* set_regdom takes ownership of rd */
6326 return set_regdom(rd
, REGD_SOURCE_CRDA
);
6331 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
6333 static int validate_scan_freqs(struct nlattr
*freqs
)
6335 struct nlattr
*attr1
, *attr2
;
6336 int n_channels
= 0, tmp1
, tmp2
;
6338 nla_for_each_nested(attr1
, freqs
, tmp1
) {
6341 * Some hardware has a limited channel list for
6342 * scanning, and it is pretty much nonsensical
6343 * to scan for a channel twice, so disallow that
6344 * and don't require drivers to check that the
6345 * channel list they get isn't longer than what
6346 * they can scan, as long as they can scan all
6347 * the channels they registered at once.
6349 nla_for_each_nested(attr2
, freqs
, tmp2
)
6350 if (attr1
!= attr2
&&
6351 nla_get_u32(attr1
) == nla_get_u32(attr2
))
6358 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
6360 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
6363 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
6364 struct cfg80211_bss_selection
*bss_select
)
6366 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
6367 struct nlattr
*nest
;
6372 /* only process one nested attribute */
6373 nest
= nla_data(nla
);
6374 if (!nla_ok(nest
, nla_len(nest
)))
6377 err
= nla_parse(attr
, NL80211_BSS_SELECT_ATTR_MAX
, nla_data(nest
),
6378 nla_len(nest
), nl80211_bss_select_policy
);
6382 /* only one attribute may be given */
6383 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
6391 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
6393 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
6394 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
6396 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
6397 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
6398 bss_select
->param
.band_pref
=
6399 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
6400 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
6404 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
6405 struct nl80211_bss_select_rssi_adjust
*adj_param
;
6407 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
6408 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
6409 bss_select
->param
.adjust
.band
= adj_param
->band
;
6410 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
6411 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
6415 /* user-space did not provide behaviour attribute */
6416 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
6419 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
6425 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
6426 u8
*mac_addr
, u8
*mac_addr_mask
)
6430 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
6431 eth_zero_addr(mac_addr
);
6432 eth_zero_addr(mac_addr_mask
);
6434 mac_addr_mask
[0] = 0x3;
6439 /* need both or none */
6440 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
6443 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
6444 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
6446 /* don't allow or configure an mcast address */
6447 if (!is_multicast_ether_addr(mac_addr_mask
) ||
6448 is_multicast_ether_addr(mac_addr
))
6452 * allow users to pass a MAC address that has bits set outside
6453 * of the mask, but don't bother drivers with having to deal
6456 for (i
= 0; i
< ETH_ALEN
; i
++)
6457 mac_addr
[i
] &= mac_addr_mask
[i
];
6462 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6464 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6465 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6466 struct cfg80211_scan_request
*request
;
6467 struct nlattr
*attr
;
6468 struct wiphy
*wiphy
;
6469 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
6472 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6475 wiphy
= &rdev
->wiphy
;
6477 if (wdev
->iftype
== NL80211_IFTYPE_NAN
)
6480 if (!rdev
->ops
->scan
)
6483 if (rdev
->scan_req
|| rdev
->scan_msg
) {
6488 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6489 n_channels
= validate_scan_freqs(
6490 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6496 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6499 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
6500 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
6503 if (n_ssids
> wiphy
->max_scan_ssids
) {
6508 if (info
->attrs
[NL80211_ATTR_IE
])
6509 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6513 if (ie_len
> wiphy
->max_scan_ie_len
) {
6518 request
= kzalloc(sizeof(*request
)
6519 + sizeof(*request
->ssids
) * n_ssids
6520 + sizeof(*request
->channels
) * n_channels
6521 + ie_len
, GFP_KERNEL
);
6528 request
->ssids
= (void *)&request
->channels
[n_channels
];
6529 request
->n_ssids
= n_ssids
;
6532 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6534 request
->ie
= (void *)(request
->channels
+ n_channels
);
6538 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6539 /* user specified, bail out if channel not found */
6540 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
6541 struct ieee80211_channel
*chan
;
6543 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6550 /* ignore disabled channels */
6551 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6554 request
->channels
[i
] = chan
;
6558 enum nl80211_band band
;
6561 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
6564 if (!wiphy
->bands
[band
])
6566 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6567 struct ieee80211_channel
*chan
;
6569 chan
= &wiphy
->bands
[band
]->channels
[j
];
6571 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6574 request
->channels
[i
] = chan
;
6585 request
->n_channels
= i
;
6589 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
6590 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6594 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6595 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
6600 if (info
->attrs
[NL80211_ATTR_IE
]) {
6601 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6602 memcpy((void *)request
->ie
,
6603 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6607 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
6608 if (wiphy
->bands
[i
])
6610 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
6612 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
6613 nla_for_each_nested(attr
,
6614 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
6616 enum nl80211_band band
= nla_type(attr
);
6618 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
6623 if (!wiphy
->bands
[band
])
6626 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
6629 &request
->rates
[band
]);
6635 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
6636 if (!wiphy_ext_feature_isset(wiphy
,
6637 NL80211_EXT_FEATURE_SET_SCAN_DWELL
)) {
6643 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
6644 request
->duration_mandatory
=
6645 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
6648 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
6649 request
->flags
= nla_get_u32(
6650 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6651 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6652 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
6657 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6658 if (!(wiphy
->features
&
6659 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
)) {
6664 if (wdev
->current_bss
) {
6669 err
= nl80211_parse_random_mac(info
->attrs
,
6671 request
->mac_addr_mask
);
6678 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6680 if (info
->attrs
[NL80211_ATTR_MAC
])
6681 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
6684 eth_broadcast_addr(request
->bssid
);
6686 request
->wdev
= wdev
;
6687 request
->wiphy
= &rdev
->wiphy
;
6688 request
->scan_start
= jiffies
;
6690 rdev
->scan_req
= request
;
6691 err
= rdev_scan(rdev
, request
);
6694 nl80211_send_scan_start(rdev
, wdev
);
6696 dev_hold(wdev
->netdev
);
6699 rdev
->scan_req
= NULL
;
6707 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6709 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6710 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6712 if (!rdev
->ops
->abort_scan
)
6718 if (!rdev
->scan_req
)
6721 rdev_abort_scan(rdev
, wdev
);
6726 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
6727 struct cfg80211_sched_scan_request
*request
,
6728 struct nlattr
**attrs
)
6730 int tmp
, err
, i
= 0;
6731 struct nlattr
*attr
;
6733 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6737 * If scan plans are not specified,
6738 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6739 * case one scan plan will be set with the specified scan
6740 * interval and infinite number of iterations.
6742 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6745 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
6749 request
->scan_plans
[0].interval
=
6750 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
6751 if (!request
->scan_plans
[0].interval
)
6754 if (request
->scan_plans
[0].interval
>
6755 wiphy
->max_sched_scan_plan_interval
)
6756 request
->scan_plans
[0].interval
=
6757 wiphy
->max_sched_scan_plan_interval
;
6762 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
6763 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
6765 if (WARN_ON(i
>= n_plans
))
6768 err
= nla_parse(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
6769 nla_data(attr
), nla_len(attr
),
6770 nl80211_plan_policy
);
6774 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
6777 request
->scan_plans
[i
].interval
=
6778 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
6779 if (!request
->scan_plans
[i
].interval
||
6780 request
->scan_plans
[i
].interval
>
6781 wiphy
->max_sched_scan_plan_interval
)
6784 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
6785 request
->scan_plans
[i
].iterations
=
6786 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
6787 if (!request
->scan_plans
[i
].iterations
||
6788 (request
->scan_plans
[i
].iterations
>
6789 wiphy
->max_sched_scan_plan_iterations
))
6791 } else if (i
< n_plans
- 1) {
6793 * All scan plans but the last one must specify
6794 * a finite number of iterations
6803 * The last scan plan must not specify the number of
6804 * iterations, it is supposed to run infinitely
6806 if (request
->scan_plans
[n_plans
- 1].iterations
)
6812 static struct cfg80211_sched_scan_request
*
6813 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6814 struct nlattr
**attrs
)
6816 struct cfg80211_sched_scan_request
*request
;
6817 struct nlattr
*attr
;
6818 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
6819 enum nl80211_band band
;
6821 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
6822 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
6824 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
6825 return ERR_PTR(-EINVAL
);
6827 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6828 n_channels
= validate_scan_freqs(
6829 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6831 return ERR_PTR(-EINVAL
);
6833 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6836 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
6837 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6841 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
6842 return ERR_PTR(-EINVAL
);
6845 * First, count the number of 'real' matchsets. Due to an issue with
6846 * the old implementation, matchsets containing only the RSSI attribute
6847 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6848 * RSSI for all matchsets, rather than their own matchset for reporting
6849 * all APs with a strong RSSI. This is needed to be compatible with
6850 * older userspace that treated a matchset with only the RSSI as the
6851 * global RSSI for all other matchsets - if there are other matchsets.
6853 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6854 nla_for_each_nested(attr
,
6855 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6857 struct nlattr
*rssi
;
6859 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6860 nla_data(attr
), nla_len(attr
),
6861 nl80211_match_policy
);
6863 return ERR_PTR(err
);
6864 /* add other standalone attributes here */
6865 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
]) {
6869 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6871 default_match_rssi
= nla_get_s32(rssi
);
6875 /* However, if there's no other matchset, add the RSSI one */
6876 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
6879 if (n_match_sets
> wiphy
->max_match_sets
)
6880 return ERR_PTR(-EINVAL
);
6882 if (attrs
[NL80211_ATTR_IE
])
6883 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
6887 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
6888 return ERR_PTR(-EINVAL
);
6890 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6892 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6893 * each scan plan already specifies its own interval
6895 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6896 return ERR_PTR(-EINVAL
);
6898 nla_for_each_nested(attr
,
6899 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
6903 * The scan interval attribute is kept for backward
6904 * compatibility. If no scan plans are specified and sched scan
6905 * interval is specified, one scan plan will be set with this
6906 * scan interval and infinite number of iterations.
6908 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6909 return ERR_PTR(-EINVAL
);
6914 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
6915 return ERR_PTR(-EINVAL
);
6917 request
= kzalloc(sizeof(*request
)
6918 + sizeof(*request
->ssids
) * n_ssids
6919 + sizeof(*request
->match_sets
) * n_match_sets
6920 + sizeof(*request
->scan_plans
) * n_plans
6921 + sizeof(*request
->channels
) * n_channels
6922 + ie_len
, GFP_KERNEL
);
6924 return ERR_PTR(-ENOMEM
);
6927 request
->ssids
= (void *)&request
->channels
[n_channels
];
6928 request
->n_ssids
= n_ssids
;
6931 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6933 request
->ie
= (void *)(request
->channels
+ n_channels
);
6938 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
6940 request
->match_sets
=
6941 (void *)(request
->ssids
+ n_ssids
);
6943 request
->match_sets
=
6944 (void *)(request
->channels
+ n_channels
);
6946 request
->n_match_sets
= n_match_sets
;
6949 request
->scan_plans
= (void *)(request
->match_sets
+
6951 else if (request
->ie
)
6952 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
6954 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
6956 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
6958 request
->n_scan_plans
= n_plans
;
6961 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6962 /* user specified, bail out if channel not found */
6963 nla_for_each_nested(attr
,
6964 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
6966 struct ieee80211_channel
*chan
;
6968 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6975 /* ignore disabled channels */
6976 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6979 request
->channels
[i
] = chan
;
6984 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
6987 if (!wiphy
->bands
[band
])
6989 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6990 struct ieee80211_channel
*chan
;
6992 chan
= &wiphy
->bands
[band
]->channels
[j
];
6994 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6997 request
->channels
[i
] = chan
;
7008 request
->n_channels
= i
;
7012 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
7014 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
7018 request
->ssids
[i
].ssid_len
= nla_len(attr
);
7019 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
7026 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
7027 nla_for_each_nested(attr
,
7028 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
7030 struct nlattr
*ssid
, *rssi
;
7032 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
7033 nla_data(attr
), nla_len(attr
),
7034 nl80211_match_policy
);
7037 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
7039 if (WARN_ON(i
>= n_match_sets
)) {
7040 /* this indicates a programming error,
7041 * the loop above should have verified
7048 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
7052 memcpy(request
->match_sets
[i
].ssid
.ssid
,
7053 nla_data(ssid
), nla_len(ssid
));
7054 request
->match_sets
[i
].ssid
.ssid_len
=
7056 /* special attribute - old implementation w/a */
7057 request
->match_sets
[i
].rssi_thold
=
7059 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
7061 request
->match_sets
[i
].rssi_thold
=
7067 /* there was no other matchset, so the RSSI one is alone */
7068 if (i
== 0 && n_match_sets
)
7069 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
7071 request
->min_rssi_thold
= INT_MAX
;
7072 for (i
= 0; i
< n_match_sets
; i
++)
7073 request
->min_rssi_thold
=
7074 min(request
->match_sets
[i
].rssi_thold
,
7075 request
->min_rssi_thold
);
7077 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
7081 request
->ie_len
= ie_len
;
7082 memcpy((void *)request
->ie
,
7083 nla_data(attrs
[NL80211_ATTR_IE
]),
7087 if (attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
7088 request
->flags
= nla_get_u32(
7089 attrs
[NL80211_ATTR_SCAN_FLAGS
]);
7090 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
7091 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
7096 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
7097 u32 flg
= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
;
7099 if (!wdev
) /* must be net-detect */
7100 flg
= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
7102 if (!(wiphy
->features
& flg
)) {
7107 if (wdev
&& wdev
->current_bss
) {
7112 err
= nl80211_parse_random_mac(attrs
, request
->mac_addr
,
7113 request
->mac_addr_mask
);
7119 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
7121 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
7123 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
7127 request
->scan_start
= jiffies
;
7133 return ERR_PTR(err
);
7136 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
7137 struct genl_info
*info
)
7139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7140 struct net_device
*dev
= info
->user_ptr
[1];
7141 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7142 struct cfg80211_sched_scan_request
*sched_scan_req
;
7145 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
7146 !rdev
->ops
->sched_scan_start
)
7149 if (rdev
->sched_scan_req
)
7150 return -EINPROGRESS
;
7152 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
7155 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
7159 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
7163 sched_scan_req
->dev
= dev
;
7164 sched_scan_req
->wiphy
= &rdev
->wiphy
;
7166 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
7167 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
7169 rcu_assign_pointer(rdev
->sched_scan_req
, sched_scan_req
);
7171 nl80211_send_sched_scan(rdev
, dev
,
7172 NL80211_CMD_START_SCHED_SCAN
);
7176 kfree(sched_scan_req
);
7181 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
7182 struct genl_info
*info
)
7184 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7186 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
7187 !rdev
->ops
->sched_scan_stop
)
7190 return __cfg80211_stop_sched_scan(rdev
, false);
7193 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
7194 struct genl_info
*info
)
7196 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7197 struct net_device
*dev
= info
->user_ptr
[1];
7198 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7199 struct cfg80211_chan_def chandef
;
7200 enum nl80211_dfs_regions dfs_region
;
7201 unsigned int cac_time_ms
;
7204 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
7205 if (dfs_region
== NL80211_DFS_UNSET
)
7208 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7212 if (netif_carrier_ok(dev
))
7215 if (wdev
->cac_started
)
7218 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
7226 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
7229 if (!rdev
->ops
->start_radar_detection
)
7232 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
7233 if (WARN_ON(!cac_time_ms
))
7234 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
7236 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
7238 wdev
->chandef
= chandef
;
7239 wdev
->cac_started
= true;
7240 wdev
->cac_start_time
= jiffies
;
7241 wdev
->cac_time_ms
= cac_time_ms
;
7246 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
7248 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7249 struct net_device
*dev
= info
->user_ptr
[1];
7250 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7251 struct cfg80211_csa_settings params
;
7252 /* csa_attrs is defined static to avoid waste of stack size - this
7253 * function is called under RTNL lock, so this should not be a problem.
7255 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
7257 bool need_new_beacon
= false;
7261 if (!rdev
->ops
->channel_switch
||
7262 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
7265 switch (dev
->ieee80211_ptr
->iftype
) {
7266 case NL80211_IFTYPE_AP
:
7267 case NL80211_IFTYPE_P2P_GO
:
7268 need_new_beacon
= true;
7270 /* useless if AP is not running */
7271 if (!wdev
->beacon_interval
)
7274 case NL80211_IFTYPE_ADHOC
:
7275 if (!wdev
->ssid_len
)
7278 case NL80211_IFTYPE_MESH_POINT
:
7279 if (!wdev
->mesh_id_len
)
7286 memset(¶ms
, 0, sizeof(params
));
7288 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7289 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
7292 /* only important for AP, IBSS and mesh create IEs internally */
7293 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
7296 /* Even though the attribute is u32, the specification says
7297 * u8, so let's make sure we don't overflow.
7299 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
7303 params
.count
= cs_count
;
7305 if (!need_new_beacon
)
7308 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
7312 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
7313 info
->attrs
[NL80211_ATTR_CSA_IES
],
7318 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
7322 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
7325 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7326 if (!len
|| (len
% sizeof(u16
)))
7329 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
7330 if (rdev
->wiphy
.max_num_csa_counters
&&
7331 (params
.n_counter_offsets_beacon
>
7332 rdev
->wiphy
.max_num_csa_counters
))
7335 params
.counter_offsets_beacon
=
7336 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
7338 /* sanity checks - counters should fit and be the same */
7339 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
7340 u16 offset
= params
.counter_offsets_beacon
[i
];
7342 if (offset
>= params
.beacon_csa
.tail_len
)
7345 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
7349 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
7350 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7351 if (!len
|| (len
% sizeof(u16
)))
7354 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
7355 if (rdev
->wiphy
.max_num_csa_counters
&&
7356 (params
.n_counter_offsets_presp
>
7357 rdev
->wiphy
.max_num_csa_counters
))
7360 params
.counter_offsets_presp
=
7361 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
7363 /* sanity checks - counters should fit and be the same */
7364 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
7365 u16 offset
= params
.counter_offsets_presp
[i
];
7367 if (offset
>= params
.beacon_csa
.probe_resp_len
)
7370 if (params
.beacon_csa
.probe_resp
[offset
] !=
7377 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
7381 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
7385 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
7392 params
.radar_required
= true;
7394 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
7395 params
.block_tx
= true;
7398 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
7404 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
7406 struct cfg80211_registered_device
*rdev
,
7407 struct wireless_dev
*wdev
,
7408 struct cfg80211_internal_bss
*intbss
)
7410 struct cfg80211_bss
*res
= &intbss
->pub
;
7411 const struct cfg80211_bss_ies
*ies
;
7415 ASSERT_WDEV_LOCK(wdev
);
7417 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
7418 NL80211_CMD_NEW_SCAN_RESULTS
);
7422 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
7424 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
7425 goto nla_put_failure
;
7427 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
7428 goto nla_put_failure
;
7429 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
7431 goto nla_put_failure
;
7433 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
7435 goto nla_put_failure
;
7436 if ((!is_zero_ether_addr(res
->bssid
) &&
7437 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
7438 goto nla_put_failure
;
7441 /* indicate whether we have probe response data or not */
7442 if (rcu_access_pointer(res
->proberesp_ies
) &&
7443 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
7444 goto fail_unlock_rcu
;
7446 /* this pointer prefers to be pointed to probe response data
7447 * but is always valid
7449 ies
= rcu_dereference(res
->ies
);
7451 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
7453 goto fail_unlock_rcu
;
7454 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
7455 ies
->len
, ies
->data
))
7456 goto fail_unlock_rcu
;
7459 /* and this pointer is always (unless driver didn't know) beacon data */
7460 ies
= rcu_dereference(res
->beacon_ies
);
7461 if (ies
&& ies
->from_beacon
) {
7462 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
7464 goto fail_unlock_rcu
;
7465 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
7466 ies
->len
, ies
->data
))
7467 goto fail_unlock_rcu
;
7471 if (res
->beacon_interval
&&
7472 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
7473 goto nla_put_failure
;
7474 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
7475 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
7476 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
7477 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
7478 jiffies_to_msecs(jiffies
- intbss
->ts
)))
7479 goto nla_put_failure
;
7481 if (intbss
->parent_tsf
&&
7482 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
7483 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
7484 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
7485 intbss
->parent_bssid
)))
7486 goto nla_put_failure
;
7488 if (intbss
->ts_boottime
&&
7489 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
7490 intbss
->ts_boottime
, NL80211_BSS_PAD
))
7491 goto nla_put_failure
;
7493 switch (rdev
->wiphy
.signal_type
) {
7494 case CFG80211_SIGNAL_TYPE_MBM
:
7495 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
7496 goto nla_put_failure
;
7498 case CFG80211_SIGNAL_TYPE_UNSPEC
:
7499 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
7500 goto nla_put_failure
;
7506 switch (wdev
->iftype
) {
7507 case NL80211_IFTYPE_P2P_CLIENT
:
7508 case NL80211_IFTYPE_STATION
:
7509 if (intbss
== wdev
->current_bss
&&
7510 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7511 NL80211_BSS_STATUS_ASSOCIATED
))
7512 goto nla_put_failure
;
7514 case NL80211_IFTYPE_ADHOC
:
7515 if (intbss
== wdev
->current_bss
&&
7516 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7517 NL80211_BSS_STATUS_IBSS_JOINED
))
7518 goto nla_put_failure
;
7524 nla_nest_end(msg
, bss
);
7526 genlmsg_end(msg
, hdr
);
7532 genlmsg_cancel(msg
, hdr
);
7536 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
7538 struct cfg80211_registered_device
*rdev
;
7539 struct cfg80211_internal_bss
*scan
;
7540 struct wireless_dev
*wdev
;
7541 int start
= cb
->args
[2], idx
= 0;
7544 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
7549 spin_lock_bh(&rdev
->bss_lock
);
7550 cfg80211_bss_expire(rdev
);
7552 cb
->seq
= rdev
->bss_generation
;
7554 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
7557 if (nl80211_send_bss(skb
, cb
,
7558 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7559 rdev
, wdev
, scan
) < 0) {
7565 spin_unlock_bh(&rdev
->bss_lock
);
7569 nl80211_finish_wdev_dump(rdev
);
7574 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
7575 int flags
, struct net_device
*dev
,
7576 bool allow_radio_stats
,
7577 struct survey_info
*survey
)
7580 struct nlattr
*infoattr
;
7582 /* skip radio stats if userspace didn't request them */
7583 if (!survey
->channel
&& !allow_radio_stats
)
7586 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
7587 NL80211_CMD_NEW_SURVEY_RESULTS
);
7591 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
7592 goto nla_put_failure
;
7594 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
7596 goto nla_put_failure
;
7598 if (survey
->channel
&&
7599 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
7600 survey
->channel
->center_freq
))
7601 goto nla_put_failure
;
7603 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
7604 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
7605 goto nla_put_failure
;
7606 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
7607 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
7608 goto nla_put_failure
;
7609 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
7610 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
7611 survey
->time
, NL80211_SURVEY_INFO_PAD
))
7612 goto nla_put_failure
;
7613 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
7614 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
7615 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
7616 goto nla_put_failure
;
7617 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
7618 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
7619 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
7620 goto nla_put_failure
;
7621 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
7622 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
7623 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
7624 goto nla_put_failure
;
7625 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
7626 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
7627 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
7628 goto nla_put_failure
;
7629 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
7630 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
7631 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
7632 goto nla_put_failure
;
7634 nla_nest_end(msg
, infoattr
);
7636 genlmsg_end(msg
, hdr
);
7640 genlmsg_cancel(msg
, hdr
);
7644 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
7646 struct survey_info survey
;
7647 struct cfg80211_registered_device
*rdev
;
7648 struct wireless_dev
*wdev
;
7649 int survey_idx
= cb
->args
[2];
7653 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
7657 /* prepare_wdev_dump parsed the attributes */
7658 radio_stats
= nl80211_fam
.attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
7660 if (!wdev
->netdev
) {
7665 if (!rdev
->ops
->dump_survey
) {
7671 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
7677 /* don't send disabled channels, but do send non-channel data */
7678 if (survey
.channel
&&
7679 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
7684 if (nl80211_send_survey(skb
,
7685 NETLINK_CB(cb
->skb
).portid
,
7686 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7687 wdev
->netdev
, radio_stats
, &survey
) < 0)
7693 cb
->args
[2] = survey_idx
;
7696 nl80211_finish_wdev_dump(rdev
);
7700 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
7702 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
7703 NL80211_WPA_VERSION_2
));
7706 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
7708 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7709 struct net_device
*dev
= info
->user_ptr
[1];
7710 struct ieee80211_channel
*chan
;
7711 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
7712 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
7713 enum nl80211_auth_type auth_type
;
7714 struct key_parse key
;
7715 bool local_state_change
;
7717 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7720 if (!info
->attrs
[NL80211_ATTR_MAC
])
7723 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
7726 if (!info
->attrs
[NL80211_ATTR_SSID
])
7729 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7732 err
= nl80211_parse_key(info
, &key
);
7737 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
7739 if (!key
.p
.key
|| !key
.p
.key_len
)
7741 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
7742 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
7743 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
7744 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
7757 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
7758 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
7767 if (!rdev
->ops
->auth
)
7770 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7771 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7774 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7775 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7776 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7780 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7781 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7783 if (info
->attrs
[NL80211_ATTR_IE
]) {
7784 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7785 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7788 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7789 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
7792 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
7793 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
7796 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
7797 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
7799 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7800 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7801 /* need to include at least Auth Transaction and Status Code */
7802 if (sae_data_len
< 4)
7806 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7809 * Since we no longer track auth state, ignore
7810 * requests to only change local state.
7812 if (local_state_change
)
7815 wdev_lock(dev
->ieee80211_ptr
);
7816 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
7817 ssid
, ssid_len
, ie
, ie_len
,
7818 key
.p
.key
, key
.p
.key_len
, key
.idx
,
7819 sae_data
, sae_data_len
);
7820 wdev_unlock(dev
->ieee80211_ptr
);
7824 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
7825 struct genl_info
*info
,
7826 struct cfg80211_crypto_settings
*settings
,
7829 memset(settings
, 0, sizeof(*settings
));
7831 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
7833 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
7836 proto
= nla_get_u16(
7837 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
7838 settings
->control_port_ethertype
= cpu_to_be16(proto
);
7839 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
7842 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
7843 settings
->control_port_no_encrypt
= true;
7845 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
7847 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
7851 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7852 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7853 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
7855 if (len
% sizeof(u32
))
7858 if (settings
->n_ciphers_pairwise
> cipher_limit
)
7861 memcpy(settings
->ciphers_pairwise
, data
, len
);
7863 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
7864 if (!cfg80211_supported_cipher_suite(
7866 settings
->ciphers_pairwise
[i
]))
7870 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
7871 settings
->cipher_group
=
7872 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
7873 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
7874 settings
->cipher_group
))
7878 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
7879 settings
->wpa_versions
=
7880 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
7881 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
7885 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
7889 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7890 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7891 settings
->n_akm_suites
= len
/ sizeof(u32
);
7893 if (len
% sizeof(u32
))
7896 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
7899 memcpy(settings
->akm_suites
, data
, len
);
7905 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
7907 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7908 struct net_device
*dev
= info
->user_ptr
[1];
7909 struct ieee80211_channel
*chan
;
7910 struct cfg80211_assoc_request req
= {};
7911 const u8
*bssid
, *ssid
;
7912 int err
, ssid_len
= 0;
7914 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7917 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
7918 !info
->attrs
[NL80211_ATTR_SSID
] ||
7919 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7922 if (!rdev
->ops
->assoc
)
7925 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7926 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7929 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7931 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7932 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7936 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7937 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7939 if (info
->attrs
[NL80211_ATTR_IE
]) {
7940 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7941 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7944 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7945 enum nl80211_mfp mfp
=
7946 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7947 if (mfp
== NL80211_MFP_REQUIRED
)
7949 else if (mfp
!= NL80211_MFP_NO
)
7953 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
7954 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
7956 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7957 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
7959 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7960 memcpy(&req
.ht_capa_mask
,
7961 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7962 sizeof(req
.ht_capa_mask
));
7964 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7965 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7967 memcpy(&req
.ht_capa
,
7968 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7969 sizeof(req
.ht_capa
));
7972 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7973 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7975 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7976 memcpy(&req
.vht_capa_mask
,
7977 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7978 sizeof(req
.vht_capa_mask
));
7980 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7981 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7983 memcpy(&req
.vht_capa
,
7984 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7985 sizeof(req
.vht_capa
));
7988 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7989 if (!((rdev
->wiphy
.features
&
7990 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
7991 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
7992 !wiphy_ext_feature_isset(&rdev
->wiphy
,
7993 NL80211_EXT_FEATURE_RRM
))
7995 req
.flags
|= ASSOC_REQ_USE_RRM
;
7998 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
8000 wdev_lock(dev
->ieee80211_ptr
);
8001 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
8002 ssid
, ssid_len
, &req
);
8003 wdev_unlock(dev
->ieee80211_ptr
);
8009 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
8011 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8012 struct net_device
*dev
= info
->user_ptr
[1];
8013 const u8
*ie
= NULL
, *bssid
;
8014 int ie_len
= 0, err
;
8016 bool local_state_change
;
8018 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8021 if (!info
->attrs
[NL80211_ATTR_MAC
])
8024 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8027 if (!rdev
->ops
->deauth
)
8030 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8031 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8034 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8036 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8037 if (reason_code
== 0) {
8038 /* Reason Code 0 is reserved */
8042 if (info
->attrs
[NL80211_ATTR_IE
]) {
8043 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8044 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8047 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8049 wdev_lock(dev
->ieee80211_ptr
);
8050 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8051 local_state_change
);
8052 wdev_unlock(dev
->ieee80211_ptr
);
8056 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
8058 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8059 struct net_device
*dev
= info
->user_ptr
[1];
8060 const u8
*ie
= NULL
, *bssid
;
8061 int ie_len
= 0, err
;
8063 bool local_state_change
;
8065 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8068 if (!info
->attrs
[NL80211_ATTR_MAC
])
8071 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8074 if (!rdev
->ops
->disassoc
)
8077 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8078 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8081 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8083 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8084 if (reason_code
== 0) {
8085 /* Reason Code 0 is reserved */
8089 if (info
->attrs
[NL80211_ATTR_IE
]) {
8090 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8091 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8094 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
8096 wdev_lock(dev
->ieee80211_ptr
);
8097 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
8098 local_state_change
);
8099 wdev_unlock(dev
->ieee80211_ptr
);
8104 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
8105 int mcast_rate
[NUM_NL80211_BANDS
],
8108 struct wiphy
*wiphy
= &rdev
->wiphy
;
8112 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
8113 struct ieee80211_supported_band
*sband
;
8115 sband
= wiphy
->bands
[band
];
8119 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
8120 if (sband
->bitrates
[i
].bitrate
== rateval
) {
8121 mcast_rate
[band
] = i
+ 1;
8131 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8133 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8134 struct net_device
*dev
= info
->user_ptr
[1];
8135 struct cfg80211_ibss_params ibss
;
8136 struct wiphy
*wiphy
;
8137 struct cfg80211_cached_keys
*connkeys
= NULL
;
8140 memset(&ibss
, 0, sizeof(ibss
));
8142 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8145 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8146 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8149 ibss
.beacon_interval
= 100;
8151 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
])
8152 ibss
.beacon_interval
=
8153 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8155 err
= cfg80211_validate_beacon_int(rdev
, ibss
.beacon_interval
);
8159 if (!rdev
->ops
->join_ibss
)
8162 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8165 wiphy
= &rdev
->wiphy
;
8167 if (info
->attrs
[NL80211_ATTR_MAC
]) {
8168 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8170 if (!is_valid_ether_addr(ibss
.bssid
))
8173 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8174 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8176 if (info
->attrs
[NL80211_ATTR_IE
]) {
8177 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8178 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8181 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
8185 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
8186 NL80211_IFTYPE_ADHOC
))
8189 switch (ibss
.chandef
.width
) {
8190 case NL80211_CHAN_WIDTH_5
:
8191 case NL80211_CHAN_WIDTH_10
:
8192 case NL80211_CHAN_WIDTH_20_NOHT
:
8194 case NL80211_CHAN_WIDTH_20
:
8195 case NL80211_CHAN_WIDTH_40
:
8196 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8199 case NL80211_CHAN_WIDTH_80
:
8200 case NL80211_CHAN_WIDTH_80P80
:
8201 case NL80211_CHAN_WIDTH_160
:
8202 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
8204 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
8205 NL80211_EXT_FEATURE_VHT_IBSS
))
8212 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
8213 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
8215 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8217 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8219 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8220 struct ieee80211_supported_band
*sband
=
8221 wiphy
->bands
[ibss
.chandef
.chan
->band
];
8223 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8229 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8230 memcpy(&ibss
.ht_capa_mask
,
8231 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8232 sizeof(ibss
.ht_capa_mask
));
8234 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8235 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8237 memcpy(&ibss
.ht_capa
,
8238 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8239 sizeof(ibss
.ht_capa
));
8242 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8243 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
8244 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8247 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
8250 connkeys
= nl80211_parse_connkeys(rdev
,
8251 info
->attrs
[NL80211_ATTR_KEYS
],
8253 if (IS_ERR(connkeys
))
8254 return PTR_ERR(connkeys
);
8256 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
8264 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
8266 ibss
.userspace_handles_dfs
=
8267 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
8269 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
8275 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
8277 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8278 struct net_device
*dev
= info
->user_ptr
[1];
8280 if (!rdev
->ops
->leave_ibss
)
8283 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
8286 return cfg80211_leave_ibss(rdev
, dev
, false);
8289 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
8291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8292 struct net_device
*dev
= info
->user_ptr
[1];
8293 int mcast_rate
[NUM_NL80211_BANDS
];
8297 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
8298 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
8299 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
8302 if (!rdev
->ops
->set_mcast_rate
)
8305 memset(mcast_rate
, 0, sizeof(mcast_rate
));
8307 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
8310 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
8311 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
8314 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
8319 static struct sk_buff
*
8320 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
8321 struct wireless_dev
*wdev
, int approxlen
,
8322 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
8323 enum nl80211_attrs attr
,
8324 const struct nl80211_vendor_cmd_info
*info
,
8327 struct sk_buff
*skb
;
8329 struct nlattr
*data
;
8331 skb
= nlmsg_new(approxlen
+ 100, gfp
);
8335 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
8341 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
8342 goto nla_put_failure
;
8345 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
8347 goto nla_put_failure
;
8348 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
8350 goto nla_put_failure
;
8354 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
8355 wdev_id(wdev
), NL80211_ATTR_PAD
))
8356 goto nla_put_failure
;
8358 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
8359 wdev
->netdev
->ifindex
))
8360 goto nla_put_failure
;
8363 data
= nla_nest_start(skb
, attr
);
8365 goto nla_put_failure
;
8367 ((void **)skb
->cb
)[0] = rdev
;
8368 ((void **)skb
->cb
)[1] = hdr
;
8369 ((void **)skb
->cb
)[2] = data
;
8378 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
8379 struct wireless_dev
*wdev
,
8380 enum nl80211_commands cmd
,
8381 enum nl80211_attrs attr
,
8382 int vendor_event_idx
,
8383 int approxlen
, gfp_t gfp
)
8385 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
8386 const struct nl80211_vendor_cmd_info
*info
;
8389 case NL80211_CMD_TESTMODE
:
8390 if (WARN_ON(vendor_event_idx
!= -1))
8394 case NL80211_CMD_VENDOR
:
8395 if (WARN_ON(vendor_event_idx
< 0 ||
8396 vendor_event_idx
>= wiphy
->n_vendor_events
))
8398 info
= &wiphy
->vendor_events
[vendor_event_idx
];
8405 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
8406 cmd
, attr
, info
, gfp
);
8408 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
8410 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
8412 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8413 void *hdr
= ((void **)skb
->cb
)[1];
8414 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8415 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
8417 /* clear CB data for netlink core to own from now on */
8418 memset(skb
->cb
, 0, sizeof(skb
->cb
));
8420 nla_nest_end(skb
, data
);
8421 genlmsg_end(skb
, hdr
);
8423 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
8424 mcgrp
= NL80211_MCGRP_VENDOR
;
8426 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
8429 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
8431 #ifdef CONFIG_NL80211_TESTMODE
8432 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
8434 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8435 struct wireless_dev
*wdev
=
8436 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8439 if (!rdev
->ops
->testmode_cmd
)
8443 err
= PTR_ERR(wdev
);
8447 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8451 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
8454 rdev
->cur_cmd_info
= info
;
8455 err
= rdev_testmode_cmd(rdev
, wdev
,
8456 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
8457 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
8458 rdev
->cur_cmd_info
= NULL
;
8463 static int nl80211_testmode_dump(struct sk_buff
*skb
,
8464 struct netlink_callback
*cb
)
8466 struct cfg80211_registered_device
*rdev
;
8476 * 0 is a valid index, but not valid for args[0],
8477 * so we need to offset by 1.
8479 phy_idx
= cb
->args
[0] - 1;
8481 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
8482 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
8487 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
8488 nl80211_fam
.attrbuf
);
8490 err
= PTR_ERR(rdev
);
8493 phy_idx
= rdev
->wiphy_idx
;
8496 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
8498 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
8502 data
= nla_data((void *)cb
->args
[1]);
8503 data_len
= nla_len((void *)cb
->args
[1]);
8506 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
8512 if (!rdev
->ops
->testmode_dump
) {
8518 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
8519 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8520 NL80211_CMD_TESTMODE
);
8521 struct nlattr
*tmdata
;
8526 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
8527 genlmsg_cancel(skb
, hdr
);
8531 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
8533 genlmsg_cancel(skb
, hdr
);
8536 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
8537 nla_nest_end(skb
, tmdata
);
8539 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
8540 genlmsg_cancel(skb
, hdr
);
8543 genlmsg_cancel(skb
, hdr
);
8547 genlmsg_end(skb
, hdr
);
8552 cb
->args
[0] = phy_idx
+ 1;
8559 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
8561 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8562 struct net_device
*dev
= info
->user_ptr
[1];
8563 struct cfg80211_connect_params connect
;
8564 struct wiphy
*wiphy
;
8565 struct cfg80211_cached_keys
*connkeys
= NULL
;
8568 memset(&connect
, 0, sizeof(connect
));
8570 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8573 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8574 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8577 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
8579 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8580 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
8581 NL80211_CMD_CONNECT
))
8584 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
8586 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
8588 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
8589 NL80211_MAX_NR_CIPHER_SUITES
);
8593 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8594 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8597 wiphy
= &rdev
->wiphy
;
8599 connect
.bg_scan_period
= -1;
8600 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
8601 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
8602 connect
.bg_scan_period
=
8603 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
8606 if (info
->attrs
[NL80211_ATTR_MAC
])
8607 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8608 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
8609 connect
.bssid_hint
=
8610 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
8611 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8612 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8614 if (info
->attrs
[NL80211_ATTR_IE
]) {
8615 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8616 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8619 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
8620 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
8621 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
8622 connect
.mfp
!= NL80211_MFP_NO
)
8625 connect
.mfp
= NL80211_MFP_NO
;
8628 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
8629 connect
.prev_bssid
=
8630 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
8632 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8633 connect
.channel
= nl80211_get_valid_chan(
8634 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8635 if (!connect
.channel
)
8637 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
8638 connect
.channel_hint
= nl80211_get_valid_chan(
8639 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
8640 if (!connect
.channel_hint
)
8644 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
8645 connkeys
= nl80211_parse_connkeys(rdev
,
8646 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
8647 if (IS_ERR(connkeys
))
8648 return PTR_ERR(connkeys
);
8651 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
8652 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
8654 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8655 memcpy(&connect
.ht_capa_mask
,
8656 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8657 sizeof(connect
.ht_capa_mask
));
8659 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8660 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
8664 memcpy(&connect
.ht_capa
,
8665 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8666 sizeof(connect
.ht_capa
));
8669 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
8670 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
8672 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8673 memcpy(&connect
.vht_capa_mask
,
8674 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
8675 sizeof(connect
.vht_capa_mask
));
8677 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
8678 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
8682 memcpy(&connect
.vht_capa
,
8683 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
8684 sizeof(connect
.vht_capa
));
8687 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
8688 if (!((rdev
->wiphy
.features
&
8689 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
8690 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
8691 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8692 NL80211_EXT_FEATURE_RRM
)) {
8696 connect
.flags
|= ASSOC_REQ_USE_RRM
;
8699 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
8700 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
8705 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
8706 /* bss selection makes no sense if bssid is set */
8707 if (connect
.bssid
) {
8712 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
8713 wiphy
, &connect
.bss_select
);
8720 wdev_lock(dev
->ieee80211_ptr
);
8721 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
8722 connect
.prev_bssid
);
8723 wdev_unlock(dev
->ieee80211_ptr
);
8729 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
8731 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8732 struct net_device
*dev
= info
->user_ptr
[1];
8736 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8737 reason
= WLAN_REASON_DEAUTH_LEAVING
;
8739 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8744 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8745 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8748 wdev_lock(dev
->ieee80211_ptr
);
8749 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
8750 wdev_unlock(dev
->ieee80211_ptr
);
8754 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
8756 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8760 if (info
->attrs
[NL80211_ATTR_PID
]) {
8761 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
8763 net
= get_net_ns_by_pid(pid
);
8764 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
8765 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
8767 net
= get_net_ns_by_fd(fd
);
8773 return PTR_ERR(net
);
8777 /* check if anything to do */
8778 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
8779 err
= cfg80211_switch_netns(rdev
, net
);
8785 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8787 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8788 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
8789 struct cfg80211_pmksa
*pmksa
) = NULL
;
8790 struct net_device
*dev
= info
->user_ptr
[1];
8791 struct cfg80211_pmksa pmksa
;
8793 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
8795 if (!info
->attrs
[NL80211_ATTR_MAC
])
8798 if (!info
->attrs
[NL80211_ATTR_PMKID
])
8801 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
8802 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8804 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8805 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8808 switch (info
->genlhdr
->cmd
) {
8809 case NL80211_CMD_SET_PMKSA
:
8810 rdev_ops
= rdev
->ops
->set_pmksa
;
8812 case NL80211_CMD_DEL_PMKSA
:
8813 rdev_ops
= rdev
->ops
->del_pmksa
;
8823 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
8826 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8828 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8829 struct net_device
*dev
= info
->user_ptr
[1];
8831 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8832 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8835 if (!rdev
->ops
->flush_pmksa
)
8838 return rdev_flush_pmksa(rdev
, dev
);
8841 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8843 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8844 struct net_device
*dev
= info
->user_ptr
[1];
8845 u8 action_code
, dialog_token
;
8846 u32 peer_capability
= 0;
8851 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8852 !rdev
->ops
->tdls_mgmt
)
8855 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
8856 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
8857 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
8858 !info
->attrs
[NL80211_ATTR_IE
] ||
8859 !info
->attrs
[NL80211_ATTR_MAC
])
8862 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8863 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
8864 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
8865 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
8866 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
8867 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
8869 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
8871 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
8872 dialog_token
, status_code
, peer_capability
,
8874 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
8875 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
8878 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
8880 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8881 struct net_device
*dev
= info
->user_ptr
[1];
8882 enum nl80211_tdls_operation operation
;
8885 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8886 !rdev
->ops
->tdls_oper
)
8889 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
8890 !info
->attrs
[NL80211_ATTR_MAC
])
8893 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
8894 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8896 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
8899 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
8900 struct genl_info
*info
)
8902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8903 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8904 struct cfg80211_chan_def chandef
;
8905 struct sk_buff
*msg
;
8911 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
8912 !info
->attrs
[NL80211_ATTR_DURATION
])
8915 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8917 if (!rdev
->ops
->remain_on_channel
||
8918 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
8922 * We should be on that channel for at least a minimum amount of
8923 * time (10ms) but no longer than the driver supports.
8925 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8926 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
8929 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8933 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8937 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8938 NL80211_CMD_REMAIN_ON_CHANNEL
);
8944 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
8950 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
8952 goto nla_put_failure
;
8954 genlmsg_end(msg
, hdr
);
8956 return genlmsg_reply(msg
, info
);
8965 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
8966 struct genl_info
*info
)
8968 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8969 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8972 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8975 if (!rdev
->ops
->cancel_remain_on_channel
)
8978 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8980 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
8983 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
8984 struct genl_info
*info
)
8986 struct cfg80211_bitrate_mask mask
;
8987 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8988 struct net_device
*dev
= info
->user_ptr
[1];
8991 if (!rdev
->ops
->set_bitrate_mask
)
8994 err
= nl80211_parse_tx_bitrate_mask(info
, &mask
);
8998 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
9001 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9003 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9004 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9005 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
9007 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
9010 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
9011 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
9013 switch (wdev
->iftype
) {
9014 case NL80211_IFTYPE_STATION
:
9015 case NL80211_IFTYPE_ADHOC
:
9016 case NL80211_IFTYPE_P2P_CLIENT
:
9017 case NL80211_IFTYPE_AP
:
9018 case NL80211_IFTYPE_AP_VLAN
:
9019 case NL80211_IFTYPE_MESH_POINT
:
9020 case NL80211_IFTYPE_P2P_GO
:
9021 case NL80211_IFTYPE_P2P_DEVICE
:
9023 case NL80211_IFTYPE_NAN
:
9028 /* not much point in registering if we can't reply */
9029 if (!rdev
->ops
->mgmt_tx
)
9032 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
9033 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
9034 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
9037 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
9039 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9040 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9041 struct cfg80211_chan_def chandef
;
9045 struct sk_buff
*msg
= NULL
;
9046 struct cfg80211_mgmt_tx_params params
= {
9047 .dont_wait_for_ack
=
9048 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
9051 if (!info
->attrs
[NL80211_ATTR_FRAME
])
9054 if (!rdev
->ops
->mgmt_tx
)
9057 switch (wdev
->iftype
) {
9058 case NL80211_IFTYPE_P2P_DEVICE
:
9059 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
9061 case NL80211_IFTYPE_STATION
:
9062 case NL80211_IFTYPE_ADHOC
:
9063 case NL80211_IFTYPE_P2P_CLIENT
:
9064 case NL80211_IFTYPE_AP
:
9065 case NL80211_IFTYPE_AP_VLAN
:
9066 case NL80211_IFTYPE_MESH_POINT
:
9067 case NL80211_IFTYPE_P2P_GO
:
9069 case NL80211_IFTYPE_NAN
:
9074 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
9075 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9077 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
9080 * We should wait on the channel for at least a minimum amount
9081 * of time (10ms) but no longer than the driver supports.
9083 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
9084 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
9088 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
9090 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
9093 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
9095 /* get the channel if any has been specified, otherwise pass NULL to
9096 * the driver. The latter will use the current one
9098 chandef
.chan
= NULL
;
9099 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9100 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
9105 if (!chandef
.chan
&& params
.offchan
)
9108 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
9109 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
9111 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
9112 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9115 if (len
% sizeof(u16
))
9118 params
.n_csa_offsets
= len
/ sizeof(u16
);
9119 params
.csa_offsets
=
9120 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
9122 /* check that all the offsets fit the frame */
9123 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
9124 if (params
.csa_offsets
[i
] >= params
.len
)
9129 if (!params
.dont_wait_for_ack
) {
9130 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9134 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9142 params
.chan
= chandef
.chan
;
9143 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
9148 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
9150 goto nla_put_failure
;
9152 genlmsg_end(msg
, hdr
);
9153 return genlmsg_reply(msg
, info
);
9165 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
9167 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9168 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9171 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9174 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
9177 switch (wdev
->iftype
) {
9178 case NL80211_IFTYPE_STATION
:
9179 case NL80211_IFTYPE_ADHOC
:
9180 case NL80211_IFTYPE_P2P_CLIENT
:
9181 case NL80211_IFTYPE_AP
:
9182 case NL80211_IFTYPE_AP_VLAN
:
9183 case NL80211_IFTYPE_P2P_GO
:
9184 case NL80211_IFTYPE_P2P_DEVICE
:
9186 case NL80211_IFTYPE_NAN
:
9191 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9193 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
9196 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9198 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9199 struct wireless_dev
*wdev
;
9200 struct net_device
*dev
= info
->user_ptr
[1];
9205 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
9208 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
9210 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
9213 wdev
= dev
->ieee80211_ptr
;
9215 if (!rdev
->ops
->set_power_mgmt
)
9218 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
9220 if (state
== wdev
->ps
)
9223 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
9229 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9231 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9232 enum nl80211_ps_state ps_state
;
9233 struct wireless_dev
*wdev
;
9234 struct net_device
*dev
= info
->user_ptr
[1];
9235 struct sk_buff
*msg
;
9239 wdev
= dev
->ieee80211_ptr
;
9241 if (!rdev
->ops
->set_power_mgmt
)
9244 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9248 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9249 NL80211_CMD_GET_POWER_SAVE
);
9256 ps_state
= NL80211_PS_ENABLED
;
9258 ps_state
= NL80211_PS_DISABLED
;
9260 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
9261 goto nla_put_failure
;
9263 genlmsg_end(msg
, hdr
);
9264 return genlmsg_reply(msg
, info
);
9273 static const struct nla_policy
9274 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
9275 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
9276 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
9277 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
9278 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
9279 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
9280 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
9283 static int nl80211_set_cqm_txe(struct genl_info
*info
,
9284 u32 rate
, u32 pkts
, u32 intvl
)
9286 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9287 struct net_device
*dev
= info
->user_ptr
[1];
9288 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9290 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
9293 if (!rdev
->ops
->set_cqm_txe_config
)
9296 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9297 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9300 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
9303 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
9304 s32 threshold
, u32 hysteresis
)
9306 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9307 struct net_device
*dev
= info
->user_ptr
[1];
9308 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9313 /* disabling - hysteresis should also be zero then */
9317 if (!rdev
->ops
->set_cqm_rssi_config
)
9320 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9321 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9324 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
9327 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
9329 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
9333 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
9337 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
9338 nl80211_attr_cqm_policy
);
9342 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
9343 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
9344 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
9345 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
9347 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
9350 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
9351 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
9352 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
9353 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
9354 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
9355 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
9357 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
9363 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9365 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9366 struct net_device
*dev
= info
->user_ptr
[1];
9367 struct ocb_setup setup
= {};
9370 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
9374 return cfg80211_join_ocb(rdev
, dev
, &setup
);
9377 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9379 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9380 struct net_device
*dev
= info
->user_ptr
[1];
9382 return cfg80211_leave_ocb(rdev
, dev
);
9385 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
9387 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9388 struct net_device
*dev
= info
->user_ptr
[1];
9389 struct mesh_config cfg
;
9390 struct mesh_setup setup
;
9393 /* start with default */
9394 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
9395 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
9397 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
9398 /* and parse parameters if given */
9399 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
9404 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
9405 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
9408 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
9409 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
9411 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
9412 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
9413 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
9416 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
9417 setup
.beacon_interval
=
9418 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
9420 err
= cfg80211_validate_beacon_int(rdev
, setup
.beacon_interval
);
9425 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
9427 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
9428 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
9432 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
9433 /* parse additional setup parameters if given */
9434 err
= nl80211_parse_mesh_setup(info
, &setup
);
9440 cfg
.auto_open_plinks
= false;
9442 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9443 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
9447 /* cfg80211_join_mesh() will sort it out */
9448 setup
.chandef
.chan
= NULL
;
9451 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
9452 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9454 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9455 struct ieee80211_supported_band
*sband
;
9457 if (!setup
.chandef
.chan
)
9460 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
9462 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
9463 &setup
.basic_rates
);
9468 if (info
->attrs
[NL80211_ATTR_TX_RATES
]) {
9469 err
= nl80211_parse_tx_bitrate_mask(info
, &setup
.beacon_rate
);
9473 err
= validate_beacon_tx_rate(rdev
, setup
.chandef
.chan
->band
,
9474 &setup
.beacon_rate
);
9479 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
9482 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
9484 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9485 struct net_device
*dev
= info
->user_ptr
[1];
9487 return cfg80211_leave_mesh(rdev
, dev
);
9491 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
9492 struct cfg80211_registered_device
*rdev
)
9494 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
9495 struct nlattr
*nl_pats
, *nl_pat
;
9498 if (!wowlan
->n_patterns
)
9501 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
9505 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
9506 nl_pat
= nla_nest_start(msg
, i
+ 1);
9509 pat_len
= wowlan
->patterns
[i
].pattern_len
;
9510 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
9511 wowlan
->patterns
[i
].mask
) ||
9512 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
9513 wowlan
->patterns
[i
].pattern
) ||
9514 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
9515 wowlan
->patterns
[i
].pkt_offset
))
9517 nla_nest_end(msg
, nl_pat
);
9519 nla_nest_end(msg
, nl_pats
);
9524 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
9525 struct cfg80211_wowlan_tcp
*tcp
)
9527 struct nlattr
*nl_tcp
;
9532 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
9536 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
9537 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
9538 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
9539 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
9540 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
9541 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
9542 tcp
->payload_len
, tcp
->payload
) ||
9543 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
9544 tcp
->data_interval
) ||
9545 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
9546 tcp
->wake_len
, tcp
->wake_data
) ||
9547 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
9548 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
9551 if (tcp
->payload_seq
.len
&&
9552 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
9553 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
9556 if (tcp
->payload_tok
.len
&&
9557 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
9558 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
9562 nla_nest_end(msg
, nl_tcp
);
9567 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
9568 struct cfg80211_sched_scan_request
*req
)
9570 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
9576 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
9580 if (req
->n_scan_plans
== 1 &&
9581 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
9582 req
->scan_plans
[0].interval
* 1000))
9585 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
9588 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9592 for (i
= 0; i
< req
->n_channels
; i
++) {
9593 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9597 nla_nest_end(msg
, freqs
);
9599 if (req
->n_match_sets
) {
9600 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
9604 for (i
= 0; i
< req
->n_match_sets
; i
++) {
9605 match
= nla_nest_start(msg
, i
);
9609 if (nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
9610 req
->match_sets
[i
].ssid
.ssid_len
,
9611 req
->match_sets
[i
].ssid
.ssid
))
9613 nla_nest_end(msg
, match
);
9615 nla_nest_end(msg
, matches
);
9618 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
9622 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
9623 scan_plan
= nla_nest_start(msg
, i
+ 1);
9628 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
9629 req
->scan_plans
[i
].interval
) ||
9630 (req
->scan_plans
[i
].iterations
&&
9631 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
9632 req
->scan_plans
[i
].iterations
)))
9634 nla_nest_end(msg
, scan_plan
);
9636 nla_nest_end(msg
, scan_plans
);
9638 nla_nest_end(msg
, nd
);
9643 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9645 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9646 struct sk_buff
*msg
;
9648 u32 size
= NLMSG_DEFAULT_SIZE
;
9650 if (!rdev
->wiphy
.wowlan
)
9653 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
9654 /* adjust size to have room for all the data */
9655 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
9656 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
9657 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
9658 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
9661 msg
= nlmsg_new(size
, GFP_KERNEL
);
9665 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9666 NL80211_CMD_GET_WOWLAN
);
9668 goto nla_put_failure
;
9670 if (rdev
->wiphy
.wowlan_config
) {
9671 struct nlattr
*nl_wowlan
;
9673 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
9675 goto nla_put_failure
;
9677 if ((rdev
->wiphy
.wowlan_config
->any
&&
9678 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
9679 (rdev
->wiphy
.wowlan_config
->disconnect
&&
9680 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
9681 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
9682 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
9683 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
9684 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
9685 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
9686 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
9687 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
9688 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
9689 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
9690 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
9691 goto nla_put_failure
;
9693 if (nl80211_send_wowlan_patterns(msg
, rdev
))
9694 goto nla_put_failure
;
9696 if (nl80211_send_wowlan_tcp(msg
,
9697 rdev
->wiphy
.wowlan_config
->tcp
))
9698 goto nla_put_failure
;
9700 if (nl80211_send_wowlan_nd(
9702 rdev
->wiphy
.wowlan_config
->nd_config
))
9703 goto nla_put_failure
;
9705 nla_nest_end(msg
, nl_wowlan
);
9708 genlmsg_end(msg
, hdr
);
9709 return genlmsg_reply(msg
, info
);
9716 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
9717 struct nlattr
*attr
,
9718 struct cfg80211_wowlan
*trig
)
9720 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
9721 struct cfg80211_wowlan_tcp
*cfg
;
9722 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
9723 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
9725 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
9728 if (!rdev
->wiphy
.wowlan
->tcp
)
9731 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
9732 nla_data(attr
), nla_len(attr
),
9733 nl80211_wowlan_tcp_policy
);
9737 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
9738 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
9739 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
9740 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
9741 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
9742 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
9743 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
9744 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
9747 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
9748 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
9751 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
9752 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
9753 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
9756 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
9757 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
9760 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
9761 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
9764 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
9765 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9767 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9768 tokens_size
= tokln
- sizeof(*tok
);
9770 if (!tok
->len
|| tokens_size
% tok
->len
)
9772 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
9774 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
9776 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
9778 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
9780 if (tok
->offset
+ tok
->len
> data_size
)
9784 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
9785 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
9786 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
9788 if (seq
->len
== 0 || seq
->len
> 4)
9790 if (seq
->len
+ seq
->offset
> data_size
)
9794 size
= sizeof(*cfg
);
9796 size
+= wake_size
+ wake_mask_size
;
9797 size
+= tokens_size
;
9799 cfg
= kzalloc(size
, GFP_KERNEL
);
9802 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
9803 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
9804 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
9806 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
9807 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
9811 /* allocate a socket and port for it and use it */
9812 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
9813 IPPROTO_TCP
, &cfg
->sock
, 1);
9818 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
9819 sock_release(cfg
->sock
);
9823 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
9829 cfg
->src_port
= port
;
9832 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
9833 cfg
->payload_len
= data_size
;
9834 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
9835 memcpy((void *)cfg
->payload
,
9836 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
9839 cfg
->payload_seq
= *seq
;
9840 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
9841 cfg
->wake_len
= wake_size
;
9842 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
9843 memcpy((void *)cfg
->wake_data
,
9844 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
9846 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
9847 data_size
+ wake_size
;
9848 memcpy((void *)cfg
->wake_mask
,
9849 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
9852 cfg
->tokens_size
= tokens_size
;
9853 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
9861 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
9862 const struct wiphy_wowlan_support
*wowlan
,
9863 struct nlattr
*attr
,
9864 struct cfg80211_wowlan
*trig
)
9869 tb
= kzalloc(NUM_NL80211_ATTR
* sizeof(*tb
), GFP_KERNEL
);
9873 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
9878 err
= nla_parse(tb
, NL80211_ATTR_MAX
,
9879 nla_data(attr
), nla_len(attr
),
9884 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
);
9885 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
9887 trig
->nd_config
= NULL
;
9894 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9896 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9897 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
9898 struct cfg80211_wowlan new_triggers
= {};
9899 struct cfg80211_wowlan
*ntrig
;
9900 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
9902 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
9903 bool regular
= false;
9908 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
9909 cfg80211_rdev_free_wowlan(rdev
);
9910 rdev
->wiphy
.wowlan_config
= NULL
;
9914 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
9915 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9916 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9917 nl80211_wowlan_policy
);
9921 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
9922 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
9924 new_triggers
.any
= true;
9927 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
9928 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
9930 new_triggers
.disconnect
= true;
9934 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
9935 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
9937 new_triggers
.magic_pkt
= true;
9941 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
9944 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
9945 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
9947 new_triggers
.gtk_rekey_failure
= true;
9951 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
9952 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
9954 new_triggers
.eap_identity_req
= true;
9958 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
9959 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
9961 new_triggers
.four_way_handshake
= true;
9965 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
9966 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
9968 new_triggers
.rfkill_release
= true;
9972 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
9975 int rem
, pat_len
, mask_len
, pkt_offset
;
9976 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9980 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9983 if (n_patterns
> wowlan
->n_patterns
)
9986 new_triggers
.patterns
= kcalloc(n_patterns
,
9987 sizeof(new_triggers
.patterns
[0]),
9989 if (!new_triggers
.patterns
)
9992 new_triggers
.n_patterns
= n_patterns
;
9995 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9999 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
10000 nla_len(pat
), NULL
);
10002 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10003 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10005 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10006 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10007 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10009 if (pat_len
> wowlan
->pattern_max_len
||
10010 pat_len
< wowlan
->pattern_min_len
)
10013 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10016 pkt_offset
= nla_get_u32(
10017 pat_tb
[NL80211_PKTPAT_OFFSET
]);
10018 if (pkt_offset
> wowlan
->max_pkt_offset
)
10020 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
10022 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10027 new_triggers
.patterns
[i
].mask
= mask_pat
;
10028 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10030 mask_pat
+= mask_len
;
10031 new_triggers
.patterns
[i
].pattern
= mask_pat
;
10032 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
10034 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
10040 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
10042 err
= nl80211_parse_wowlan_tcp(
10043 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
10049 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
10051 err
= nl80211_parse_wowlan_nd(
10052 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
10058 /* The 'any' trigger means the device continues operating more or less
10059 * as in its normal operation mode and wakes up the host on most of the
10060 * normal interrupts (like packet RX, ...)
10061 * It therefore makes little sense to combine with the more constrained
10062 * wakeup trigger modes.
10064 if (new_triggers
.any
&& regular
) {
10069 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
10074 cfg80211_rdev_free_wowlan(rdev
);
10075 rdev
->wiphy
.wowlan_config
= ntrig
;
10078 if (rdev
->ops
->set_wakeup
&&
10079 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
10080 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
10084 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
10085 kfree(new_triggers
.patterns
[i
].mask
);
10086 kfree(new_triggers
.patterns
);
10087 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
10088 sock_release(new_triggers
.tcp
->sock
);
10089 kfree(new_triggers
.tcp
);
10090 kfree(new_triggers
.nd_config
);
10095 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
10096 struct cfg80211_registered_device
*rdev
)
10098 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
10100 struct cfg80211_coalesce_rules
*rule
;
10102 if (!rdev
->coalesce
->n_rules
)
10105 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
10109 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
10110 nl_rule
= nla_nest_start(msg
, i
+ 1);
10114 rule
= &rdev
->coalesce
->rules
[i
];
10115 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
10119 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
10123 nl_pats
= nla_nest_start(msg
,
10124 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
10128 for (j
= 0; j
< rule
->n_patterns
; j
++) {
10129 nl_pat
= nla_nest_start(msg
, j
+ 1);
10132 pat_len
= rule
->patterns
[j
].pattern_len
;
10133 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
10134 DIV_ROUND_UP(pat_len
, 8),
10135 rule
->patterns
[j
].mask
) ||
10136 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
10137 rule
->patterns
[j
].pattern
) ||
10138 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
10139 rule
->patterns
[j
].pkt_offset
))
10141 nla_nest_end(msg
, nl_pat
);
10143 nla_nest_end(msg
, nl_pats
);
10144 nla_nest_end(msg
, nl_rule
);
10146 nla_nest_end(msg
, nl_rules
);
10151 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
10153 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10154 struct sk_buff
*msg
;
10157 if (!rdev
->wiphy
.coalesce
)
10158 return -EOPNOTSUPP
;
10160 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10164 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10165 NL80211_CMD_GET_COALESCE
);
10167 goto nla_put_failure
;
10169 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
10170 goto nla_put_failure
;
10172 genlmsg_end(msg
, hdr
);
10173 return genlmsg_reply(msg
, info
);
10180 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
10182 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
10184 struct cfg80211_coalesce_rules
*rule
;
10189 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
10190 rule
= &coalesce
->rules
[i
];
10191 for (j
= 0; j
< rule
->n_patterns
; j
++)
10192 kfree(rule
->patterns
[j
].mask
);
10193 kfree(rule
->patterns
);
10195 kfree(coalesce
->rules
);
10197 rdev
->coalesce
= NULL
;
10200 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
10201 struct nlattr
*rule
,
10202 struct cfg80211_coalesce_rules
*new_rule
)
10205 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10206 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
10207 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
10208 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
10210 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
10211 nla_len(rule
), nl80211_coalesce_policy
);
10215 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
10217 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
10218 if (new_rule
->delay
> coalesce
->max_delay
)
10221 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
10222 new_rule
->condition
=
10223 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
10224 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
10225 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
10228 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
10231 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10234 if (n_patterns
> coalesce
->n_patterns
)
10237 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
10239 if (!new_rule
->patterns
)
10242 new_rule
->n_patterns
= n_patterns
;
10245 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10249 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
10250 nla_len(pat
), NULL
);
10251 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10252 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10254 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10255 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10256 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10258 if (pat_len
> coalesce
->pattern_max_len
||
10259 pat_len
< coalesce
->pattern_min_len
)
10262 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10265 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
10266 if (pkt_offset
> coalesce
->max_pkt_offset
)
10268 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
10270 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10274 new_rule
->patterns
[i
].mask
= mask_pat
;
10275 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10278 mask_pat
+= mask_len
;
10279 new_rule
->patterns
[i
].pattern
= mask_pat
;
10280 new_rule
->patterns
[i
].pattern_len
= pat_len
;
10281 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
10289 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
10291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10292 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10293 struct cfg80211_coalesce new_coalesce
= {};
10294 struct cfg80211_coalesce
*n_coalesce
;
10295 int err
, rem_rule
, n_rules
= 0, i
, j
;
10296 struct nlattr
*rule
;
10297 struct cfg80211_coalesce_rules
*tmp_rule
;
10299 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
10300 return -EOPNOTSUPP
;
10302 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
10303 cfg80211_rdev_free_coalesce(rdev
);
10304 rdev_set_coalesce(rdev
, NULL
);
10308 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10311 if (n_rules
> coalesce
->n_rules
)
10314 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
10316 if (!new_coalesce
.rules
)
10319 new_coalesce
.n_rules
= n_rules
;
10322 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10324 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
10325 &new_coalesce
.rules
[i
]);
10332 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
10336 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
10341 cfg80211_rdev_free_coalesce(rdev
);
10342 rdev
->coalesce
= n_coalesce
;
10346 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
10347 tmp_rule
= &new_coalesce
.rules
[i
];
10348 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
10349 kfree(tmp_rule
->patterns
[j
].mask
);
10350 kfree(tmp_rule
->patterns
);
10352 kfree(new_coalesce
.rules
);
10357 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
10359 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10360 struct net_device
*dev
= info
->user_ptr
[1];
10361 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10362 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
10363 struct cfg80211_gtk_rekey_data rekey_data
;
10366 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
10369 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
10370 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
10371 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
10372 nl80211_rekey_policy
);
10376 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
10378 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
10380 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
10383 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
10384 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
10385 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
10388 if (!wdev
->current_bss
) {
10393 if (!rdev
->ops
->set_rekey_data
) {
10398 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
10404 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
10405 struct genl_info
*info
)
10407 struct net_device
*dev
= info
->user_ptr
[1];
10408 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10410 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10411 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
10414 if (wdev
->ap_unexpected_nlportid
)
10417 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
10421 static int nl80211_probe_client(struct sk_buff
*skb
,
10422 struct genl_info
*info
)
10424 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10425 struct net_device
*dev
= info
->user_ptr
[1];
10426 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10427 struct sk_buff
*msg
;
10433 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10434 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
10435 return -EOPNOTSUPP
;
10437 if (!info
->attrs
[NL80211_ATTR_MAC
])
10440 if (!rdev
->ops
->probe_client
)
10441 return -EOPNOTSUPP
;
10443 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10447 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10448 NL80211_CMD_PROBE_CLIENT
);
10454 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10456 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
10460 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
10462 goto nla_put_failure
;
10464 genlmsg_end(msg
, hdr
);
10466 return genlmsg_reply(msg
, info
);
10475 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
10477 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10478 struct cfg80211_beacon_registration
*reg
, *nreg
;
10481 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
10482 return -EOPNOTSUPP
;
10484 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
10488 /* First, check if already registered. */
10489 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10490 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10491 if (reg
->nlportid
== info
->snd_portid
) {
10496 /* Add it to the list */
10497 nreg
->nlportid
= info
->snd_portid
;
10498 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
10500 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10504 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10509 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
10511 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10512 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10515 if (!rdev
->ops
->start_p2p_device
)
10516 return -EOPNOTSUPP
;
10518 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
10519 return -EOPNOTSUPP
;
10521 if (wdev
->p2p_started
)
10524 if (rfkill_blocked(rdev
->rfkill
))
10527 err
= rdev_start_p2p_device(rdev
, wdev
);
10531 wdev
->p2p_started
= true;
10537 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
10539 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10540 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10542 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
10543 return -EOPNOTSUPP
;
10545 if (!rdev
->ops
->stop_p2p_device
)
10546 return -EOPNOTSUPP
;
10548 cfg80211_stop_p2p_device(rdev
, wdev
);
10553 static int nl80211_start_nan(struct sk_buff
*skb
, struct genl_info
*info
)
10555 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10556 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10557 struct cfg80211_nan_conf conf
= {};
10560 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
10561 return -EOPNOTSUPP
;
10563 if (wdev
->nan_started
)
10566 if (rfkill_blocked(rdev
->rfkill
))
10569 if (!info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
])
10572 if (!info
->attrs
[NL80211_ATTR_NAN_DUAL
])
10576 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
10577 if (!conf
.master_pref
)
10580 conf
.dual
= nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_DUAL
]);
10582 err
= rdev_start_nan(rdev
, wdev
, &conf
);
10586 wdev
->nan_started
= true;
10592 static int nl80211_stop_nan(struct sk_buff
*skb
, struct genl_info
*info
)
10594 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10595 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10597 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
10598 return -EOPNOTSUPP
;
10600 cfg80211_stop_nan(rdev
, wdev
);
10605 static int validate_nan_filter(struct nlattr
*filter_attr
)
10607 struct nlattr
*attr
;
10608 int len
= 0, n_entries
= 0, rem
;
10610 nla_for_each_nested(attr
, filter_attr
, rem
) {
10611 len
+= nla_len(attr
);
10621 static int handle_nan_filter(struct nlattr
*attr_filter
,
10622 struct cfg80211_nan_func
*func
,
10625 struct nlattr
*attr
;
10626 int n_entries
, rem
, i
;
10627 struct cfg80211_nan_func_filter
*filter
;
10629 n_entries
= validate_nan_filter(attr_filter
);
10633 BUILD_BUG_ON(sizeof(*func
->rx_filters
) != sizeof(*func
->tx_filters
));
10635 filter
= kcalloc(n_entries
, sizeof(*func
->rx_filters
), GFP_KERNEL
);
10640 nla_for_each_nested(attr
, attr_filter
, rem
) {
10641 filter
[i
].filter
= kmemdup(nla_data(attr
), nla_len(attr
),
10643 filter
[i
].len
= nla_len(attr
);
10647 func
->num_tx_filters
= n_entries
;
10648 func
->tx_filters
= filter
;
10650 func
->num_rx_filters
= n_entries
;
10651 func
->rx_filters
= filter
;
10657 static int nl80211_nan_add_func(struct sk_buff
*skb
,
10658 struct genl_info
*info
)
10660 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10661 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10662 struct nlattr
*tb
[NUM_NL80211_NAN_FUNC_ATTR
], *func_attr
;
10663 struct cfg80211_nan_func
*func
;
10664 struct sk_buff
*msg
= NULL
;
10668 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
10669 return -EOPNOTSUPP
;
10671 if (!wdev
->nan_started
)
10674 if (!info
->attrs
[NL80211_ATTR_NAN_FUNC
])
10677 if (wdev
->owner_nlportid
&&
10678 wdev
->owner_nlportid
!= info
->snd_portid
)
10681 err
= nla_parse(tb
, NL80211_NAN_FUNC_ATTR_MAX
,
10682 nla_data(info
->attrs
[NL80211_ATTR_NAN_FUNC
]),
10683 nla_len(info
->attrs
[NL80211_ATTR_NAN_FUNC
]),
10684 nl80211_nan_func_policy
);
10688 func
= kzalloc(sizeof(*func
), GFP_KERNEL
);
10692 func
->cookie
= wdev
->wiphy
->cookie_counter
++;
10694 if (!tb
[NL80211_NAN_FUNC_TYPE
] ||
10695 nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]) > NL80211_NAN_FUNC_MAX_TYPE
) {
10701 func
->type
= nla_get_u8(tb
[NL80211_NAN_FUNC_TYPE
]);
10703 if (!tb
[NL80211_NAN_FUNC_SERVICE_ID
]) {
10708 memcpy(func
->service_id
, nla_data(tb
[NL80211_NAN_FUNC_SERVICE_ID
]),
10709 sizeof(func
->service_id
));
10711 func
->close_range
=
10712 nla_get_flag(tb
[NL80211_NAN_FUNC_CLOSE_RANGE
]);
10714 if (tb
[NL80211_NAN_FUNC_SERVICE_INFO
]) {
10715 func
->serv_spec_info_len
=
10716 nla_len(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]);
10717 func
->serv_spec_info
=
10718 kmemdup(nla_data(tb
[NL80211_NAN_FUNC_SERVICE_INFO
]),
10719 func
->serv_spec_info_len
,
10721 if (!func
->serv_spec_info
) {
10727 if (tb
[NL80211_NAN_FUNC_TTL
])
10728 func
->ttl
= nla_get_u32(tb
[NL80211_NAN_FUNC_TTL
]);
10730 switch (func
->type
) {
10731 case NL80211_NAN_FUNC_PUBLISH
:
10732 if (!tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]) {
10737 func
->publish_type
=
10738 nla_get_u8(tb
[NL80211_NAN_FUNC_PUBLISH_TYPE
]);
10739 func
->publish_bcast
=
10740 nla_get_flag(tb
[NL80211_NAN_FUNC_PUBLISH_BCAST
]);
10742 if ((!(func
->publish_type
& NL80211_NAN_SOLICITED_PUBLISH
)) &&
10743 func
->publish_bcast
) {
10748 case NL80211_NAN_FUNC_SUBSCRIBE
:
10749 func
->subscribe_active
=
10750 nla_get_flag(tb
[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE
]);
10752 case NL80211_NAN_FUNC_FOLLOW_UP
:
10753 if (!tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
] ||
10754 !tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]) {
10759 func
->followup_id
=
10760 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_ID
]);
10761 func
->followup_reqid
=
10762 nla_get_u8(tb
[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID
]);
10763 memcpy(func
->followup_dest
.addr
,
10764 nla_data(tb
[NL80211_NAN_FUNC_FOLLOW_UP_DEST
]),
10765 sizeof(func
->followup_dest
.addr
));
10776 if (tb
[NL80211_NAN_FUNC_SRF
]) {
10777 struct nlattr
*srf_tb
[NUM_NL80211_NAN_SRF_ATTR
];
10779 err
= nla_parse(srf_tb
, NL80211_NAN_SRF_ATTR_MAX
,
10780 nla_data(tb
[NL80211_NAN_FUNC_SRF
]),
10781 nla_len(tb
[NL80211_NAN_FUNC_SRF
]), NULL
);
10785 func
->srf_include
=
10786 nla_get_flag(srf_tb
[NL80211_NAN_SRF_INCLUDE
]);
10788 if (srf_tb
[NL80211_NAN_SRF_BF
]) {
10789 if (srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
] ||
10790 !srf_tb
[NL80211_NAN_SRF_BF_IDX
]) {
10796 nla_len(srf_tb
[NL80211_NAN_SRF_BF
]);
10798 kmemdup(nla_data(srf_tb
[NL80211_NAN_SRF_BF
]),
10799 func
->srf_bf_len
, GFP_KERNEL
);
10800 if (!func
->srf_bf
) {
10806 nla_get_u8(srf_tb
[NL80211_NAN_SRF_BF_IDX
]);
10808 struct nlattr
*attr
, *mac_attr
=
10809 srf_tb
[NL80211_NAN_SRF_MAC_ADDRS
];
10810 int n_entries
, rem
, i
= 0;
10817 n_entries
= validate_acl_mac_addrs(mac_attr
);
10818 if (n_entries
<= 0) {
10823 func
->srf_num_macs
= n_entries
;
10825 kzalloc(sizeof(*func
->srf_macs
) * n_entries
,
10827 if (!func
->srf_macs
) {
10832 nla_for_each_nested(attr
, mac_attr
, rem
)
10833 memcpy(func
->srf_macs
[i
++].addr
, nla_data(attr
),
10834 sizeof(*func
->srf_macs
));
10838 if (tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
]) {
10839 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_TX_MATCH_FILTER
],
10845 if (tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
]) {
10846 err
= handle_nan_filter(tb
[NL80211_NAN_FUNC_RX_MATCH_FILTER
],
10852 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10858 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10859 NL80211_CMD_ADD_NAN_FUNCTION
);
10860 /* This can't really happen - we just allocated 4KB */
10861 if (WARN_ON(!hdr
)) {
10866 err
= rdev_add_nan_func(rdev
, wdev
, func
);
10869 cfg80211_free_nan_func(func
);
10874 /* propagate the instance id and cookie to userspace */
10875 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, func
->cookie
,
10877 goto nla_put_failure
;
10879 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
10881 goto nla_put_failure
;
10883 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
,
10884 func
->instance_id
))
10885 goto nla_put_failure
;
10887 nla_nest_end(msg
, func_attr
);
10889 genlmsg_end(msg
, hdr
);
10890 return genlmsg_reply(msg
, info
);
10897 static int nl80211_nan_del_func(struct sk_buff
*skb
,
10898 struct genl_info
*info
)
10900 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10901 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10904 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
10905 return -EOPNOTSUPP
;
10907 if (!wdev
->nan_started
)
10910 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
10913 if (wdev
->owner_nlportid
&&
10914 wdev
->owner_nlportid
!= info
->snd_portid
)
10917 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
10919 rdev_del_nan_func(rdev
, wdev
, cookie
);
10924 static int nl80211_nan_change_config(struct sk_buff
*skb
,
10925 struct genl_info
*info
)
10927 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10928 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10929 struct cfg80211_nan_conf conf
= {};
10932 if (wdev
->iftype
!= NL80211_IFTYPE_NAN
)
10933 return -EOPNOTSUPP
;
10935 if (!wdev
->nan_started
)
10938 if (info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]) {
10940 nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_MASTER_PREF
]);
10941 if (conf
.master_pref
<= 1 || conf
.master_pref
== 255)
10944 changed
|= CFG80211_NAN_CONF_CHANGED_PREF
;
10947 if (info
->attrs
[NL80211_ATTR_NAN_DUAL
]) {
10948 conf
.dual
= nla_get_u8(info
->attrs
[NL80211_ATTR_NAN_DUAL
]);
10949 changed
|= CFG80211_NAN_CONF_CHANGED_DUAL
;
10955 return rdev_nan_change_conf(rdev
, wdev
, &conf
, changed
);
10958 void cfg80211_nan_match(struct wireless_dev
*wdev
,
10959 struct cfg80211_nan_match_params
*match
, gfp_t gfp
)
10961 struct wiphy
*wiphy
= wdev
->wiphy
;
10962 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10963 struct nlattr
*match_attr
, *local_func_attr
, *peer_func_attr
;
10964 struct sk_buff
*msg
;
10967 if (WARN_ON(!match
->inst_id
|| !match
->peer_inst_id
|| !match
->addr
))
10970 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10974 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NAN_MATCH
);
10980 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10981 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10982 wdev
->netdev
->ifindex
)) ||
10983 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
10985 goto nla_put_failure
;
10987 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, match
->cookie
,
10988 NL80211_ATTR_PAD
) ||
10989 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, match
->addr
))
10990 goto nla_put_failure
;
10992 match_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_MATCH
);
10994 goto nla_put_failure
;
10996 local_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_LOCAL
);
10997 if (!local_func_attr
)
10998 goto nla_put_failure
;
11000 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->inst_id
))
11001 goto nla_put_failure
;
11003 nla_nest_end(msg
, local_func_attr
);
11005 peer_func_attr
= nla_nest_start(msg
, NL80211_NAN_MATCH_FUNC_PEER
);
11006 if (!peer_func_attr
)
11007 goto nla_put_failure
;
11009 if (nla_put_u8(msg
, NL80211_NAN_FUNC_TYPE
, match
->type
) ||
11010 nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, match
->peer_inst_id
))
11011 goto nla_put_failure
;
11013 if (match
->info
&& match
->info_len
&&
11014 nla_put(msg
, NL80211_NAN_FUNC_SERVICE_INFO
, match
->info_len
,
11016 goto nla_put_failure
;
11018 nla_nest_end(msg
, peer_func_attr
);
11019 nla_nest_end(msg
, match_attr
);
11020 genlmsg_end(msg
, hdr
);
11022 if (!wdev
->owner_nlportid
)
11023 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
11024 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
11026 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
11027 wdev
->owner_nlportid
);
11034 EXPORT_SYMBOL(cfg80211_nan_match
);
11036 void cfg80211_nan_func_terminated(struct wireless_dev
*wdev
,
11038 enum nl80211_nan_func_term_reason reason
,
11039 u64 cookie
, gfp_t gfp
)
11041 struct wiphy
*wiphy
= wdev
->wiphy
;
11042 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11043 struct sk_buff
*msg
;
11044 struct nlattr
*func_attr
;
11047 if (WARN_ON(!inst_id
))
11050 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11054 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION
);
11060 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11061 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11062 wdev
->netdev
->ifindex
)) ||
11063 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
11065 goto nla_put_failure
;
11067 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
11069 goto nla_put_failure
;
11071 func_attr
= nla_nest_start(msg
, NL80211_ATTR_NAN_FUNC
);
11073 goto nla_put_failure
;
11075 if (nla_put_u8(msg
, NL80211_NAN_FUNC_INSTANCE_ID
, inst_id
) ||
11076 nla_put_u8(msg
, NL80211_NAN_FUNC_TERM_REASON
, reason
))
11077 goto nla_put_failure
;
11079 nla_nest_end(msg
, func_attr
);
11080 genlmsg_end(msg
, hdr
);
11082 if (!wdev
->owner_nlportid
)
11083 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
11084 msg
, 0, NL80211_MCGRP_NAN
, gfp
);
11086 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
,
11087 wdev
->owner_nlportid
);
11094 EXPORT_SYMBOL(cfg80211_nan_func_terminated
);
11096 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
11097 struct genl_info
*info
)
11100 struct sk_buff
*msg
;
11102 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11106 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
11107 NL80211_CMD_GET_PROTOCOL_FEATURES
);
11109 goto nla_put_failure
;
11111 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
11112 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
11113 goto nla_put_failure
;
11115 genlmsg_end(msg
, hdr
);
11116 return genlmsg_reply(msg
, info
);
11123 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
11125 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11126 struct cfg80211_update_ft_ies_params ft_params
;
11127 struct net_device
*dev
= info
->user_ptr
[1];
11129 if (!rdev
->ops
->update_ft_ies
)
11130 return -EOPNOTSUPP
;
11132 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
11133 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
11136 memset(&ft_params
, 0, sizeof(ft_params
));
11137 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
11138 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
11139 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
11141 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
11144 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
11145 struct genl_info
*info
)
11147 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11148 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11149 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
11153 if (!rdev
->ops
->crit_proto_start
)
11154 return -EOPNOTSUPP
;
11156 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
11159 if (rdev
->crit_proto_nlportid
)
11162 /* determine protocol if provided */
11163 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
11164 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
11166 if (proto
>= NUM_NL80211_CRIT_PROTO
)
11169 /* timeout must be provided */
11170 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
11174 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
11176 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
11179 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
11181 rdev
->crit_proto_nlportid
= info
->snd_portid
;
11186 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
11187 struct genl_info
*info
)
11189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11190 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11192 if (!rdev
->ops
->crit_proto_stop
)
11193 return -EOPNOTSUPP
;
11195 if (rdev
->crit_proto_nlportid
) {
11196 rdev
->crit_proto_nlportid
= 0;
11197 rdev_crit_proto_stop(rdev
, wdev
);
11202 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
11204 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11205 struct wireless_dev
*wdev
=
11206 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
11210 if (!rdev
->wiphy
.vendor_commands
)
11211 return -EOPNOTSUPP
;
11213 if (IS_ERR(wdev
)) {
11214 err
= PTR_ERR(wdev
);
11215 if (err
!= -EINVAL
)
11218 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
11222 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
11223 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
11226 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
11227 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
11228 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
11229 const struct wiphy_vendor_command
*vcmd
;
11233 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
11235 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
11238 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
11239 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
11242 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
11246 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
11247 if (wdev
->netdev
&&
11248 !netif_running(wdev
->netdev
))
11250 if (!wdev
->netdev
&& !wdev
->p2p_started
)
11255 return -EOPNOTSUPP
;
11260 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
11261 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
11262 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
11265 rdev
->cur_cmd_info
= info
;
11266 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
11268 rdev
->cur_cmd_info
= NULL
;
11272 return -EOPNOTSUPP
;
11275 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
11276 struct netlink_callback
*cb
,
11277 struct cfg80211_registered_device
**rdev
,
11278 struct wireless_dev
**wdev
)
11285 unsigned int data_len
= 0;
11290 /* subtract the 1 again here */
11291 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
11292 struct wireless_dev
*tmp
;
11298 *rdev
= wiphy_to_rdev(wiphy
);
11302 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
11303 if (tmp
->identifier
== cb
->args
[1] - 1) {
11310 /* keep rtnl locked in successful case */
11314 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
11315 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
11320 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
11321 !nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]) {
11326 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
11327 nl80211_fam
.attrbuf
);
11331 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
11332 nl80211_fam
.attrbuf
);
11333 if (IS_ERR(*rdev
)) {
11334 err
= PTR_ERR(*rdev
);
11338 vid
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
]);
11339 subcmd
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
11341 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
11342 const struct wiphy_vendor_command
*vcmd
;
11344 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
11346 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
11349 if (!vcmd
->dumpit
) {
11358 if (vcmd_idx
< 0) {
11363 if (nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
11364 data
= nla_data(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
11365 data_len
= nla_len(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
11368 /* 0 is the first index - add 1 to parse only once */
11369 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
11370 /* add 1 to know if it was NULL */
11371 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
11372 cb
->args
[2] = vcmd_idx
;
11373 cb
->args
[3] = (unsigned long)data
;
11374 cb
->args
[4] = data_len
;
11376 /* keep rtnl locked in successful case */
11383 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
11384 struct netlink_callback
*cb
)
11386 struct cfg80211_registered_device
*rdev
;
11387 struct wireless_dev
*wdev
;
11388 unsigned int vcmd_idx
;
11389 const struct wiphy_vendor_command
*vcmd
;
11393 struct nlattr
*vendor_data
;
11395 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
11399 vcmd_idx
= cb
->args
[2];
11400 data
= (void *)cb
->args
[3];
11401 data_len
= cb
->args
[4];
11402 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
11404 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
11405 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
11408 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
11412 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
11413 if (wdev
->netdev
&&
11414 !netif_running(wdev
->netdev
))
11416 if (!wdev
->netdev
&& !wdev
->p2p_started
)
11422 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
11423 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
11424 NL80211_CMD_VENDOR
);
11428 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11429 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
11431 NL80211_ATTR_PAD
))) {
11432 genlmsg_cancel(skb
, hdr
);
11436 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
11437 if (!vendor_data
) {
11438 genlmsg_cancel(skb
, hdr
);
11442 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
11443 (unsigned long *)&cb
->args
[5]);
11444 nla_nest_end(skb
, vendor_data
);
11446 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
11447 genlmsg_cancel(skb
, hdr
);
11450 genlmsg_cancel(skb
, hdr
);
11454 genlmsg_end(skb
, hdr
);
11463 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
11464 enum nl80211_commands cmd
,
11465 enum nl80211_attrs attr
,
11468 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11470 if (WARN_ON(!rdev
->cur_cmd_info
))
11473 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
11474 rdev
->cur_cmd_info
->snd_portid
,
11475 rdev
->cur_cmd_info
->snd_seq
,
11476 cmd
, attr
, NULL
, GFP_KERNEL
);
11478 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
11480 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
11482 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
11483 void *hdr
= ((void **)skb
->cb
)[1];
11484 struct nlattr
*data
= ((void **)skb
->cb
)[2];
11486 /* clear CB data for netlink core to own from now on */
11487 memset(skb
->cb
, 0, sizeof(skb
->cb
));
11489 if (WARN_ON(!rdev
->cur_cmd_info
)) {
11494 nla_nest_end(skb
, data
);
11495 genlmsg_end(skb
, hdr
);
11496 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
11498 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
11500 static int nl80211_set_qos_map(struct sk_buff
*skb
,
11501 struct genl_info
*info
)
11503 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11504 struct cfg80211_qos_map
*qos_map
= NULL
;
11505 struct net_device
*dev
= info
->user_ptr
[1];
11506 u8
*pos
, len
, num_des
, des_len
, des
;
11509 if (!rdev
->ops
->set_qos_map
)
11510 return -EOPNOTSUPP
;
11512 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
11513 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
11514 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
11516 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
11517 len
> IEEE80211_QOS_MAP_LEN_MAX
)
11520 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
11524 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
11526 des_len
= num_des
*
11527 sizeof(struct cfg80211_dscp_exception
);
11528 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
11529 qos_map
->num_des
= num_des
;
11530 for (des
= 0; des
< num_des
; des
++) {
11531 if (qos_map
->dscp_exception
[des
].up
> 7) {
11538 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
11541 wdev_lock(dev
->ieee80211_ptr
);
11542 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
11544 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
11545 wdev_unlock(dev
->ieee80211_ptr
);
11551 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
11553 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11554 struct net_device
*dev
= info
->user_ptr
[1];
11555 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11558 u16 admitted_time
= 0;
11561 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
11562 return -EOPNOTSUPP
;
11564 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
11565 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
11568 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
11569 if (tsid
>= IEEE80211_NUM_TIDS
)
11572 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
11573 if (up
>= IEEE80211_NUM_UPS
)
11576 /* WMM uses TIDs 0-7 even for TSPEC */
11577 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
11578 /* TODO: handle 802.11 TSPEC/admission control
11579 * need more attributes for that (e.g. BA session requirement);
11580 * change the WMM adminssion test above to allow both then
11585 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11587 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
11589 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
11590 if (!admitted_time
)
11595 switch (wdev
->iftype
) {
11596 case NL80211_IFTYPE_STATION
:
11597 case NL80211_IFTYPE_P2P_CLIENT
:
11598 if (wdev
->current_bss
)
11607 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
11614 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
11616 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11617 struct net_device
*dev
= info
->user_ptr
[1];
11618 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11623 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
11626 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
11627 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11630 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
11636 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
11637 struct genl_info
*info
)
11639 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11640 struct net_device
*dev
= info
->user_ptr
[1];
11641 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11642 struct cfg80211_chan_def chandef
= {};
11647 if (!rdev
->ops
->tdls_channel_switch
||
11648 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
11649 return -EOPNOTSUPP
;
11651 switch (dev
->ieee80211_ptr
->iftype
) {
11652 case NL80211_IFTYPE_STATION
:
11653 case NL80211_IFTYPE_P2P_CLIENT
:
11656 return -EOPNOTSUPP
;
11659 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
11660 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
11663 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
11668 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
11669 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
11670 * specification is not defined for them.
11672 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
11673 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
11674 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
11677 /* we will be active on the TDLS link */
11678 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
11682 /* don't allow switching to DFS channels */
11683 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
11686 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11687 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
11690 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
11696 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
11697 struct genl_info
*info
)
11699 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
11700 struct net_device
*dev
= info
->user_ptr
[1];
11701 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11704 if (!rdev
->ops
->tdls_channel_switch
||
11705 !rdev
->ops
->tdls_cancel_channel_switch
||
11706 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
11707 return -EOPNOTSUPP
;
11709 switch (dev
->ieee80211_ptr
->iftype
) {
11710 case NL80211_IFTYPE_STATION
:
11711 case NL80211_IFTYPE_P2P_CLIENT
:
11714 return -EOPNOTSUPP
;
11717 if (!info
->attrs
[NL80211_ATTR_MAC
])
11720 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
11723 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
11729 #define NL80211_FLAG_NEED_WIPHY 0x01
11730 #define NL80211_FLAG_NEED_NETDEV 0x02
11731 #define NL80211_FLAG_NEED_RTNL 0x04
11732 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11733 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11734 NL80211_FLAG_CHECK_NETDEV_UP)
11735 #define NL80211_FLAG_NEED_WDEV 0x10
11736 /* If a netdev is associated, it must be UP, P2P must be started */
11737 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11738 NL80211_FLAG_CHECK_NETDEV_UP)
11739 #define NL80211_FLAG_CLEAR_SKB 0x20
11741 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
11742 struct genl_info
*info
)
11744 struct cfg80211_registered_device
*rdev
;
11745 struct wireless_dev
*wdev
;
11746 struct net_device
*dev
;
11747 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
11752 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
11753 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
11754 if (IS_ERR(rdev
)) {
11757 return PTR_ERR(rdev
);
11759 info
->user_ptr
[0] = rdev
;
11760 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
11761 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
11764 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
11766 if (IS_ERR(wdev
)) {
11769 return PTR_ERR(wdev
);
11772 dev
= wdev
->netdev
;
11773 rdev
= wiphy_to_rdev(wdev
->wiphy
);
11775 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
11782 info
->user_ptr
[1] = dev
;
11784 info
->user_ptr
[1] = wdev
;
11788 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
11789 !netif_running(dev
)) {
11796 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
11797 if (wdev
->iftype
== NL80211_IFTYPE_P2P_DEVICE
&&
11798 !wdev
->p2p_started
) {
11803 if (wdev
->iftype
== NL80211_IFTYPE_NAN
&&
11804 !wdev
->nan_started
) {
11811 info
->user_ptr
[0] = rdev
;
11817 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
11818 struct genl_info
*info
)
11820 if (info
->user_ptr
[1]) {
11821 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
11822 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11825 dev_put(wdev
->netdev
);
11827 dev_put(info
->user_ptr
[1]);
11831 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
11834 /* If needed, clear the netlink message payload from the SKB
11835 * as it might contain key data that shouldn't stick around on
11836 * the heap after the SKB is freed. The netlink message header
11837 * is still needed for further processing, so leave it intact.
11839 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
11840 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
11842 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
11846 static const struct genl_ops nl80211_ops
[] = {
11848 .cmd
= NL80211_CMD_GET_WIPHY
,
11849 .doit
= nl80211_get_wiphy
,
11850 .dumpit
= nl80211_dump_wiphy
,
11851 .done
= nl80211_dump_wiphy_done
,
11852 .policy
= nl80211_policy
,
11853 /* can be retrieved by unprivileged users */
11854 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11855 NL80211_FLAG_NEED_RTNL
,
11858 .cmd
= NL80211_CMD_SET_WIPHY
,
11859 .doit
= nl80211_set_wiphy
,
11860 .policy
= nl80211_policy
,
11861 .flags
= GENL_UNS_ADMIN_PERM
,
11862 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
11865 .cmd
= NL80211_CMD_GET_INTERFACE
,
11866 .doit
= nl80211_get_interface
,
11867 .dumpit
= nl80211_dump_interface
,
11868 .policy
= nl80211_policy
,
11869 /* can be retrieved by unprivileged users */
11870 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11871 NL80211_FLAG_NEED_RTNL
,
11874 .cmd
= NL80211_CMD_SET_INTERFACE
,
11875 .doit
= nl80211_set_interface
,
11876 .policy
= nl80211_policy
,
11877 .flags
= GENL_UNS_ADMIN_PERM
,
11878 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11879 NL80211_FLAG_NEED_RTNL
,
11882 .cmd
= NL80211_CMD_NEW_INTERFACE
,
11883 .doit
= nl80211_new_interface
,
11884 .policy
= nl80211_policy
,
11885 .flags
= GENL_UNS_ADMIN_PERM
,
11886 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11887 NL80211_FLAG_NEED_RTNL
,
11890 .cmd
= NL80211_CMD_DEL_INTERFACE
,
11891 .doit
= nl80211_del_interface
,
11892 .policy
= nl80211_policy
,
11893 .flags
= GENL_UNS_ADMIN_PERM
,
11894 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11895 NL80211_FLAG_NEED_RTNL
,
11898 .cmd
= NL80211_CMD_GET_KEY
,
11899 .doit
= nl80211_get_key
,
11900 .policy
= nl80211_policy
,
11901 .flags
= GENL_UNS_ADMIN_PERM
,
11902 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11903 NL80211_FLAG_NEED_RTNL
,
11906 .cmd
= NL80211_CMD_SET_KEY
,
11907 .doit
= nl80211_set_key
,
11908 .policy
= nl80211_policy
,
11909 .flags
= GENL_UNS_ADMIN_PERM
,
11910 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11911 NL80211_FLAG_NEED_RTNL
|
11912 NL80211_FLAG_CLEAR_SKB
,
11915 .cmd
= NL80211_CMD_NEW_KEY
,
11916 .doit
= nl80211_new_key
,
11917 .policy
= nl80211_policy
,
11918 .flags
= GENL_UNS_ADMIN_PERM
,
11919 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11920 NL80211_FLAG_NEED_RTNL
|
11921 NL80211_FLAG_CLEAR_SKB
,
11924 .cmd
= NL80211_CMD_DEL_KEY
,
11925 .doit
= nl80211_del_key
,
11926 .policy
= nl80211_policy
,
11927 .flags
= GENL_UNS_ADMIN_PERM
,
11928 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11929 NL80211_FLAG_NEED_RTNL
,
11932 .cmd
= NL80211_CMD_SET_BEACON
,
11933 .policy
= nl80211_policy
,
11934 .flags
= GENL_UNS_ADMIN_PERM
,
11935 .doit
= nl80211_set_beacon
,
11936 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11937 NL80211_FLAG_NEED_RTNL
,
11940 .cmd
= NL80211_CMD_START_AP
,
11941 .policy
= nl80211_policy
,
11942 .flags
= GENL_UNS_ADMIN_PERM
,
11943 .doit
= nl80211_start_ap
,
11944 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11945 NL80211_FLAG_NEED_RTNL
,
11948 .cmd
= NL80211_CMD_STOP_AP
,
11949 .policy
= nl80211_policy
,
11950 .flags
= GENL_UNS_ADMIN_PERM
,
11951 .doit
= nl80211_stop_ap
,
11952 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11953 NL80211_FLAG_NEED_RTNL
,
11956 .cmd
= NL80211_CMD_GET_STATION
,
11957 .doit
= nl80211_get_station
,
11958 .dumpit
= nl80211_dump_station
,
11959 .policy
= nl80211_policy
,
11960 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11961 NL80211_FLAG_NEED_RTNL
,
11964 .cmd
= NL80211_CMD_SET_STATION
,
11965 .doit
= nl80211_set_station
,
11966 .policy
= nl80211_policy
,
11967 .flags
= GENL_UNS_ADMIN_PERM
,
11968 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11969 NL80211_FLAG_NEED_RTNL
,
11972 .cmd
= NL80211_CMD_NEW_STATION
,
11973 .doit
= nl80211_new_station
,
11974 .policy
= nl80211_policy
,
11975 .flags
= GENL_UNS_ADMIN_PERM
,
11976 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11977 NL80211_FLAG_NEED_RTNL
,
11980 .cmd
= NL80211_CMD_DEL_STATION
,
11981 .doit
= nl80211_del_station
,
11982 .policy
= nl80211_policy
,
11983 .flags
= GENL_UNS_ADMIN_PERM
,
11984 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11985 NL80211_FLAG_NEED_RTNL
,
11988 .cmd
= NL80211_CMD_GET_MPATH
,
11989 .doit
= nl80211_get_mpath
,
11990 .dumpit
= nl80211_dump_mpath
,
11991 .policy
= nl80211_policy
,
11992 .flags
= GENL_UNS_ADMIN_PERM
,
11993 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11994 NL80211_FLAG_NEED_RTNL
,
11997 .cmd
= NL80211_CMD_GET_MPP
,
11998 .doit
= nl80211_get_mpp
,
11999 .dumpit
= nl80211_dump_mpp
,
12000 .policy
= nl80211_policy
,
12001 .flags
= GENL_UNS_ADMIN_PERM
,
12002 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12003 NL80211_FLAG_NEED_RTNL
,
12006 .cmd
= NL80211_CMD_SET_MPATH
,
12007 .doit
= nl80211_set_mpath
,
12008 .policy
= nl80211_policy
,
12009 .flags
= GENL_UNS_ADMIN_PERM
,
12010 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12011 NL80211_FLAG_NEED_RTNL
,
12014 .cmd
= NL80211_CMD_NEW_MPATH
,
12015 .doit
= nl80211_new_mpath
,
12016 .policy
= nl80211_policy
,
12017 .flags
= GENL_UNS_ADMIN_PERM
,
12018 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12019 NL80211_FLAG_NEED_RTNL
,
12022 .cmd
= NL80211_CMD_DEL_MPATH
,
12023 .doit
= nl80211_del_mpath
,
12024 .policy
= nl80211_policy
,
12025 .flags
= GENL_UNS_ADMIN_PERM
,
12026 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12027 NL80211_FLAG_NEED_RTNL
,
12030 .cmd
= NL80211_CMD_SET_BSS
,
12031 .doit
= nl80211_set_bss
,
12032 .policy
= nl80211_policy
,
12033 .flags
= GENL_UNS_ADMIN_PERM
,
12034 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12035 NL80211_FLAG_NEED_RTNL
,
12038 .cmd
= NL80211_CMD_GET_REG
,
12039 .doit
= nl80211_get_reg_do
,
12040 .dumpit
= nl80211_get_reg_dump
,
12041 .policy
= nl80211_policy
,
12042 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12043 /* can be retrieved by unprivileged users */
12045 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
12047 .cmd
= NL80211_CMD_SET_REG
,
12048 .doit
= nl80211_set_reg
,
12049 .policy
= nl80211_policy
,
12050 .flags
= GENL_ADMIN_PERM
,
12051 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
12055 .cmd
= NL80211_CMD_REQ_SET_REG
,
12056 .doit
= nl80211_req_set_reg
,
12057 .policy
= nl80211_policy
,
12058 .flags
= GENL_ADMIN_PERM
,
12061 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
12062 .doit
= nl80211_get_mesh_config
,
12063 .policy
= nl80211_policy
,
12064 /* can be retrieved by unprivileged users */
12065 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12066 NL80211_FLAG_NEED_RTNL
,
12069 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
12070 .doit
= nl80211_update_mesh_config
,
12071 .policy
= nl80211_policy
,
12072 .flags
= GENL_UNS_ADMIN_PERM
,
12073 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12074 NL80211_FLAG_NEED_RTNL
,
12077 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
12078 .doit
= nl80211_trigger_scan
,
12079 .policy
= nl80211_policy
,
12080 .flags
= GENL_UNS_ADMIN_PERM
,
12081 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12082 NL80211_FLAG_NEED_RTNL
,
12085 .cmd
= NL80211_CMD_ABORT_SCAN
,
12086 .doit
= nl80211_abort_scan
,
12087 .policy
= nl80211_policy
,
12088 .flags
= GENL_UNS_ADMIN_PERM
,
12089 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12090 NL80211_FLAG_NEED_RTNL
,
12093 .cmd
= NL80211_CMD_GET_SCAN
,
12094 .policy
= nl80211_policy
,
12095 .dumpit
= nl80211_dump_scan
,
12098 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
12099 .doit
= nl80211_start_sched_scan
,
12100 .policy
= nl80211_policy
,
12101 .flags
= GENL_UNS_ADMIN_PERM
,
12102 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12103 NL80211_FLAG_NEED_RTNL
,
12106 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
12107 .doit
= nl80211_stop_sched_scan
,
12108 .policy
= nl80211_policy
,
12109 .flags
= GENL_UNS_ADMIN_PERM
,
12110 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12111 NL80211_FLAG_NEED_RTNL
,
12114 .cmd
= NL80211_CMD_AUTHENTICATE
,
12115 .doit
= nl80211_authenticate
,
12116 .policy
= nl80211_policy
,
12117 .flags
= GENL_UNS_ADMIN_PERM
,
12118 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12119 NL80211_FLAG_NEED_RTNL
|
12120 NL80211_FLAG_CLEAR_SKB
,
12123 .cmd
= NL80211_CMD_ASSOCIATE
,
12124 .doit
= nl80211_associate
,
12125 .policy
= nl80211_policy
,
12126 .flags
= GENL_UNS_ADMIN_PERM
,
12127 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12128 NL80211_FLAG_NEED_RTNL
,
12131 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
12132 .doit
= nl80211_deauthenticate
,
12133 .policy
= nl80211_policy
,
12134 .flags
= GENL_UNS_ADMIN_PERM
,
12135 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12136 NL80211_FLAG_NEED_RTNL
,
12139 .cmd
= NL80211_CMD_DISASSOCIATE
,
12140 .doit
= nl80211_disassociate
,
12141 .policy
= nl80211_policy
,
12142 .flags
= GENL_UNS_ADMIN_PERM
,
12143 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12144 NL80211_FLAG_NEED_RTNL
,
12147 .cmd
= NL80211_CMD_JOIN_IBSS
,
12148 .doit
= nl80211_join_ibss
,
12149 .policy
= nl80211_policy
,
12150 .flags
= GENL_UNS_ADMIN_PERM
,
12151 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12152 NL80211_FLAG_NEED_RTNL
,
12155 .cmd
= NL80211_CMD_LEAVE_IBSS
,
12156 .doit
= nl80211_leave_ibss
,
12157 .policy
= nl80211_policy
,
12158 .flags
= GENL_UNS_ADMIN_PERM
,
12159 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12160 NL80211_FLAG_NEED_RTNL
,
12162 #ifdef CONFIG_NL80211_TESTMODE
12164 .cmd
= NL80211_CMD_TESTMODE
,
12165 .doit
= nl80211_testmode_do
,
12166 .dumpit
= nl80211_testmode_dump
,
12167 .policy
= nl80211_policy
,
12168 .flags
= GENL_UNS_ADMIN_PERM
,
12169 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12170 NL80211_FLAG_NEED_RTNL
,
12174 .cmd
= NL80211_CMD_CONNECT
,
12175 .doit
= nl80211_connect
,
12176 .policy
= nl80211_policy
,
12177 .flags
= GENL_UNS_ADMIN_PERM
,
12178 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12179 NL80211_FLAG_NEED_RTNL
,
12182 .cmd
= NL80211_CMD_DISCONNECT
,
12183 .doit
= nl80211_disconnect
,
12184 .policy
= nl80211_policy
,
12185 .flags
= GENL_UNS_ADMIN_PERM
,
12186 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12187 NL80211_FLAG_NEED_RTNL
,
12190 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
12191 .doit
= nl80211_wiphy_netns
,
12192 .policy
= nl80211_policy
,
12193 .flags
= GENL_UNS_ADMIN_PERM
,
12194 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12195 NL80211_FLAG_NEED_RTNL
,
12198 .cmd
= NL80211_CMD_GET_SURVEY
,
12199 .policy
= nl80211_policy
,
12200 .dumpit
= nl80211_dump_survey
,
12203 .cmd
= NL80211_CMD_SET_PMKSA
,
12204 .doit
= nl80211_setdel_pmksa
,
12205 .policy
= nl80211_policy
,
12206 .flags
= GENL_UNS_ADMIN_PERM
,
12207 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12208 NL80211_FLAG_NEED_RTNL
,
12211 .cmd
= NL80211_CMD_DEL_PMKSA
,
12212 .doit
= nl80211_setdel_pmksa
,
12213 .policy
= nl80211_policy
,
12214 .flags
= GENL_UNS_ADMIN_PERM
,
12215 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12216 NL80211_FLAG_NEED_RTNL
,
12219 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
12220 .doit
= nl80211_flush_pmksa
,
12221 .policy
= nl80211_policy
,
12222 .flags
= GENL_UNS_ADMIN_PERM
,
12223 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12224 NL80211_FLAG_NEED_RTNL
,
12227 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
12228 .doit
= nl80211_remain_on_channel
,
12229 .policy
= nl80211_policy
,
12230 .flags
= GENL_UNS_ADMIN_PERM
,
12231 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12232 NL80211_FLAG_NEED_RTNL
,
12235 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
12236 .doit
= nl80211_cancel_remain_on_channel
,
12237 .policy
= nl80211_policy
,
12238 .flags
= GENL_UNS_ADMIN_PERM
,
12239 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12240 NL80211_FLAG_NEED_RTNL
,
12243 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
12244 .doit
= nl80211_set_tx_bitrate_mask
,
12245 .policy
= nl80211_policy
,
12246 .flags
= GENL_UNS_ADMIN_PERM
,
12247 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12248 NL80211_FLAG_NEED_RTNL
,
12251 .cmd
= NL80211_CMD_REGISTER_FRAME
,
12252 .doit
= nl80211_register_mgmt
,
12253 .policy
= nl80211_policy
,
12254 .flags
= GENL_UNS_ADMIN_PERM
,
12255 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12256 NL80211_FLAG_NEED_RTNL
,
12259 .cmd
= NL80211_CMD_FRAME
,
12260 .doit
= nl80211_tx_mgmt
,
12261 .policy
= nl80211_policy
,
12262 .flags
= GENL_UNS_ADMIN_PERM
,
12263 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12264 NL80211_FLAG_NEED_RTNL
,
12267 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
12268 .doit
= nl80211_tx_mgmt_cancel_wait
,
12269 .policy
= nl80211_policy
,
12270 .flags
= GENL_UNS_ADMIN_PERM
,
12271 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12272 NL80211_FLAG_NEED_RTNL
,
12275 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
12276 .doit
= nl80211_set_power_save
,
12277 .policy
= nl80211_policy
,
12278 .flags
= GENL_UNS_ADMIN_PERM
,
12279 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12280 NL80211_FLAG_NEED_RTNL
,
12283 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
12284 .doit
= nl80211_get_power_save
,
12285 .policy
= nl80211_policy
,
12286 /* can be retrieved by unprivileged users */
12287 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12288 NL80211_FLAG_NEED_RTNL
,
12291 .cmd
= NL80211_CMD_SET_CQM
,
12292 .doit
= nl80211_set_cqm
,
12293 .policy
= nl80211_policy
,
12294 .flags
= GENL_UNS_ADMIN_PERM
,
12295 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12296 NL80211_FLAG_NEED_RTNL
,
12299 .cmd
= NL80211_CMD_SET_CHANNEL
,
12300 .doit
= nl80211_set_channel
,
12301 .policy
= nl80211_policy
,
12302 .flags
= GENL_UNS_ADMIN_PERM
,
12303 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12304 NL80211_FLAG_NEED_RTNL
,
12307 .cmd
= NL80211_CMD_SET_WDS_PEER
,
12308 .doit
= nl80211_set_wds_peer
,
12309 .policy
= nl80211_policy
,
12310 .flags
= GENL_UNS_ADMIN_PERM
,
12311 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12312 NL80211_FLAG_NEED_RTNL
,
12315 .cmd
= NL80211_CMD_JOIN_MESH
,
12316 .doit
= nl80211_join_mesh
,
12317 .policy
= nl80211_policy
,
12318 .flags
= GENL_UNS_ADMIN_PERM
,
12319 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12320 NL80211_FLAG_NEED_RTNL
,
12323 .cmd
= NL80211_CMD_LEAVE_MESH
,
12324 .doit
= nl80211_leave_mesh
,
12325 .policy
= nl80211_policy
,
12326 .flags
= GENL_UNS_ADMIN_PERM
,
12327 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12328 NL80211_FLAG_NEED_RTNL
,
12331 .cmd
= NL80211_CMD_JOIN_OCB
,
12332 .doit
= nl80211_join_ocb
,
12333 .policy
= nl80211_policy
,
12334 .flags
= GENL_UNS_ADMIN_PERM
,
12335 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12336 NL80211_FLAG_NEED_RTNL
,
12339 .cmd
= NL80211_CMD_LEAVE_OCB
,
12340 .doit
= nl80211_leave_ocb
,
12341 .policy
= nl80211_policy
,
12342 .flags
= GENL_UNS_ADMIN_PERM
,
12343 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12344 NL80211_FLAG_NEED_RTNL
,
12348 .cmd
= NL80211_CMD_GET_WOWLAN
,
12349 .doit
= nl80211_get_wowlan
,
12350 .policy
= nl80211_policy
,
12351 /* can be retrieved by unprivileged users */
12352 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12353 NL80211_FLAG_NEED_RTNL
,
12356 .cmd
= NL80211_CMD_SET_WOWLAN
,
12357 .doit
= nl80211_set_wowlan
,
12358 .policy
= nl80211_policy
,
12359 .flags
= GENL_UNS_ADMIN_PERM
,
12360 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12361 NL80211_FLAG_NEED_RTNL
,
12365 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
12366 .doit
= nl80211_set_rekey_data
,
12367 .policy
= nl80211_policy
,
12368 .flags
= GENL_UNS_ADMIN_PERM
,
12369 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12370 NL80211_FLAG_NEED_RTNL
|
12371 NL80211_FLAG_CLEAR_SKB
,
12374 .cmd
= NL80211_CMD_TDLS_MGMT
,
12375 .doit
= nl80211_tdls_mgmt
,
12376 .policy
= nl80211_policy
,
12377 .flags
= GENL_UNS_ADMIN_PERM
,
12378 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12379 NL80211_FLAG_NEED_RTNL
,
12382 .cmd
= NL80211_CMD_TDLS_OPER
,
12383 .doit
= nl80211_tdls_oper
,
12384 .policy
= nl80211_policy
,
12385 .flags
= GENL_UNS_ADMIN_PERM
,
12386 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12387 NL80211_FLAG_NEED_RTNL
,
12390 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
12391 .doit
= nl80211_register_unexpected_frame
,
12392 .policy
= nl80211_policy
,
12393 .flags
= GENL_UNS_ADMIN_PERM
,
12394 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12395 NL80211_FLAG_NEED_RTNL
,
12398 .cmd
= NL80211_CMD_PROBE_CLIENT
,
12399 .doit
= nl80211_probe_client
,
12400 .policy
= nl80211_policy
,
12401 .flags
= GENL_UNS_ADMIN_PERM
,
12402 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12403 NL80211_FLAG_NEED_RTNL
,
12406 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
12407 .doit
= nl80211_register_beacons
,
12408 .policy
= nl80211_policy
,
12409 .flags
= GENL_UNS_ADMIN_PERM
,
12410 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12411 NL80211_FLAG_NEED_RTNL
,
12414 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
12415 .doit
= nl80211_set_noack_map
,
12416 .policy
= nl80211_policy
,
12417 .flags
= GENL_UNS_ADMIN_PERM
,
12418 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12419 NL80211_FLAG_NEED_RTNL
,
12422 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
12423 .doit
= nl80211_start_p2p_device
,
12424 .policy
= nl80211_policy
,
12425 .flags
= GENL_UNS_ADMIN_PERM
,
12426 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12427 NL80211_FLAG_NEED_RTNL
,
12430 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
12431 .doit
= nl80211_stop_p2p_device
,
12432 .policy
= nl80211_policy
,
12433 .flags
= GENL_UNS_ADMIN_PERM
,
12434 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12435 NL80211_FLAG_NEED_RTNL
,
12438 .cmd
= NL80211_CMD_START_NAN
,
12439 .doit
= nl80211_start_nan
,
12440 .policy
= nl80211_policy
,
12441 .flags
= GENL_ADMIN_PERM
,
12442 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
12443 NL80211_FLAG_NEED_RTNL
,
12446 .cmd
= NL80211_CMD_STOP_NAN
,
12447 .doit
= nl80211_stop_nan
,
12448 .policy
= nl80211_policy
,
12449 .flags
= GENL_ADMIN_PERM
,
12450 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12451 NL80211_FLAG_NEED_RTNL
,
12454 .cmd
= NL80211_CMD_ADD_NAN_FUNCTION
,
12455 .doit
= nl80211_nan_add_func
,
12456 .policy
= nl80211_policy
,
12457 .flags
= GENL_ADMIN_PERM
,
12458 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12459 NL80211_FLAG_NEED_RTNL
,
12462 .cmd
= NL80211_CMD_DEL_NAN_FUNCTION
,
12463 .doit
= nl80211_nan_del_func
,
12464 .policy
= nl80211_policy
,
12465 .flags
= GENL_ADMIN_PERM
,
12466 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12467 NL80211_FLAG_NEED_RTNL
,
12470 .cmd
= NL80211_CMD_CHANGE_NAN_CONFIG
,
12471 .doit
= nl80211_nan_change_config
,
12472 .policy
= nl80211_policy
,
12473 .flags
= GENL_ADMIN_PERM
,
12474 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12475 NL80211_FLAG_NEED_RTNL
,
12478 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
12479 .doit
= nl80211_set_mcast_rate
,
12480 .policy
= nl80211_policy
,
12481 .flags
= GENL_UNS_ADMIN_PERM
,
12482 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12483 NL80211_FLAG_NEED_RTNL
,
12486 .cmd
= NL80211_CMD_SET_MAC_ACL
,
12487 .doit
= nl80211_set_mac_acl
,
12488 .policy
= nl80211_policy
,
12489 .flags
= GENL_UNS_ADMIN_PERM
,
12490 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
12491 NL80211_FLAG_NEED_RTNL
,
12494 .cmd
= NL80211_CMD_RADAR_DETECT
,
12495 .doit
= nl80211_start_radar_detection
,
12496 .policy
= nl80211_policy
,
12497 .flags
= GENL_UNS_ADMIN_PERM
,
12498 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12499 NL80211_FLAG_NEED_RTNL
,
12502 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
12503 .doit
= nl80211_get_protocol_features
,
12504 .policy
= nl80211_policy
,
12507 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
12508 .doit
= nl80211_update_ft_ies
,
12509 .policy
= nl80211_policy
,
12510 .flags
= GENL_UNS_ADMIN_PERM
,
12511 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12512 NL80211_FLAG_NEED_RTNL
,
12515 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
12516 .doit
= nl80211_crit_protocol_start
,
12517 .policy
= nl80211_policy
,
12518 .flags
= GENL_UNS_ADMIN_PERM
,
12519 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12520 NL80211_FLAG_NEED_RTNL
,
12523 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
12524 .doit
= nl80211_crit_protocol_stop
,
12525 .policy
= nl80211_policy
,
12526 .flags
= GENL_UNS_ADMIN_PERM
,
12527 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
12528 NL80211_FLAG_NEED_RTNL
,
12531 .cmd
= NL80211_CMD_GET_COALESCE
,
12532 .doit
= nl80211_get_coalesce
,
12533 .policy
= nl80211_policy
,
12534 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12535 NL80211_FLAG_NEED_RTNL
,
12538 .cmd
= NL80211_CMD_SET_COALESCE
,
12539 .doit
= nl80211_set_coalesce
,
12540 .policy
= nl80211_policy
,
12541 .flags
= GENL_UNS_ADMIN_PERM
,
12542 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12543 NL80211_FLAG_NEED_RTNL
,
12546 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
12547 .doit
= nl80211_channel_switch
,
12548 .policy
= nl80211_policy
,
12549 .flags
= GENL_UNS_ADMIN_PERM
,
12550 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12551 NL80211_FLAG_NEED_RTNL
,
12554 .cmd
= NL80211_CMD_VENDOR
,
12555 .doit
= nl80211_vendor_cmd
,
12556 .dumpit
= nl80211_vendor_cmd_dump
,
12557 .policy
= nl80211_policy
,
12558 .flags
= GENL_UNS_ADMIN_PERM
,
12559 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
12560 NL80211_FLAG_NEED_RTNL
,
12563 .cmd
= NL80211_CMD_SET_QOS_MAP
,
12564 .doit
= nl80211_set_qos_map
,
12565 .policy
= nl80211_policy
,
12566 .flags
= GENL_UNS_ADMIN_PERM
,
12567 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12568 NL80211_FLAG_NEED_RTNL
,
12571 .cmd
= NL80211_CMD_ADD_TX_TS
,
12572 .doit
= nl80211_add_tx_ts
,
12573 .policy
= nl80211_policy
,
12574 .flags
= GENL_UNS_ADMIN_PERM
,
12575 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12576 NL80211_FLAG_NEED_RTNL
,
12579 .cmd
= NL80211_CMD_DEL_TX_TS
,
12580 .doit
= nl80211_del_tx_ts
,
12581 .policy
= nl80211_policy
,
12582 .flags
= GENL_UNS_ADMIN_PERM
,
12583 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12584 NL80211_FLAG_NEED_RTNL
,
12587 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
12588 .doit
= nl80211_tdls_channel_switch
,
12589 .policy
= nl80211_policy
,
12590 .flags
= GENL_UNS_ADMIN_PERM
,
12591 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12592 NL80211_FLAG_NEED_RTNL
,
12595 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
12596 .doit
= nl80211_tdls_cancel_channel_switch
,
12597 .policy
= nl80211_policy
,
12598 .flags
= GENL_UNS_ADMIN_PERM
,
12599 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
12600 NL80211_FLAG_NEED_RTNL
,
12604 /* notification functions */
12606 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
12607 enum nl80211_commands cmd
)
12609 struct sk_buff
*msg
;
12610 struct nl80211_dump_wiphy_state state
= {};
12612 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
12613 cmd
!= NL80211_CMD_DEL_WIPHY
);
12615 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12619 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
12624 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12625 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
12628 void nl80211_notify_iface(struct cfg80211_registered_device
*rdev
,
12629 struct wireless_dev
*wdev
,
12630 enum nl80211_commands cmd
)
12632 struct sk_buff
*msg
;
12634 WARN_ON(cmd
!= NL80211_CMD_NEW_INTERFACE
&&
12635 cmd
!= NL80211_CMD_DEL_INTERFACE
);
12637 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12641 if (nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
,
12642 cmd
== NL80211_CMD_DEL_INTERFACE
) < 0) {
12647 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12648 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
12651 static int nl80211_add_scan_req(struct sk_buff
*msg
,
12652 struct cfg80211_registered_device
*rdev
)
12654 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
12655 struct nlattr
*nest
;
12661 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
12663 goto nla_put_failure
;
12664 for (i
= 0; i
< req
->n_ssids
; i
++) {
12665 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
12666 goto nla_put_failure
;
12668 nla_nest_end(msg
, nest
);
12670 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
12672 goto nla_put_failure
;
12673 for (i
= 0; i
< req
->n_channels
; i
++) {
12674 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
12675 goto nla_put_failure
;
12677 nla_nest_end(msg
, nest
);
12680 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
12681 goto nla_put_failure
;
12684 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
12685 goto nla_put_failure
;
12687 if (req
->info
.scan_start_tsf
&&
12688 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
12689 req
->info
.scan_start_tsf
, NL80211_BSS_PAD
) ||
12690 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
12691 req
->info
.tsf_bssid
)))
12692 goto nla_put_failure
;
12699 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
12700 struct cfg80211_registered_device
*rdev
,
12701 struct wireless_dev
*wdev
,
12702 u32 portid
, u32 seq
, int flags
,
12707 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
12711 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12712 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12713 wdev
->netdev
->ifindex
)) ||
12714 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12716 goto nla_put_failure
;
12718 /* ignore errors and send incomplete event anyway */
12719 nl80211_add_scan_req(msg
, rdev
);
12721 genlmsg_end(msg
, hdr
);
12725 genlmsg_cancel(msg
, hdr
);
12730 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
12731 struct cfg80211_registered_device
*rdev
,
12732 struct net_device
*netdev
,
12733 u32 portid
, u32 seq
, int flags
, u32 cmd
)
12737 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
12741 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12742 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
12743 goto nla_put_failure
;
12745 genlmsg_end(msg
, hdr
);
12749 genlmsg_cancel(msg
, hdr
);
12753 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
12754 struct wireless_dev
*wdev
)
12756 struct sk_buff
*msg
;
12758 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12762 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
12763 NL80211_CMD_TRIGGER_SCAN
) < 0) {
12768 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12769 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
12772 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
12773 struct wireless_dev
*wdev
, bool aborted
)
12775 struct sk_buff
*msg
;
12777 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12781 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
12782 aborted
? NL80211_CMD_SCAN_ABORTED
:
12783 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
12791 void nl80211_send_scan_result(struct cfg80211_registered_device
*rdev
,
12792 struct sk_buff
*msg
)
12797 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12798 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
12801 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
12802 struct net_device
*netdev
)
12804 struct sk_buff
*msg
;
12806 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12810 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
12811 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
12816 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12817 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
12820 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
12821 struct net_device
*netdev
, u32 cmd
)
12823 struct sk_buff
*msg
;
12825 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12829 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
12834 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12835 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
12838 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
12839 struct regulatory_request
*request
)
12841 /* Userspace can always count this one always being set */
12842 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
12843 goto nla_put_failure
;
12845 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
12846 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12847 NL80211_REGDOM_TYPE_WORLD
))
12848 goto nla_put_failure
;
12849 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
12850 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12851 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
12852 goto nla_put_failure
;
12853 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
12854 request
->intersect
) {
12855 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12856 NL80211_REGDOM_TYPE_INTERSECTION
))
12857 goto nla_put_failure
;
12859 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12860 NL80211_REGDOM_TYPE_COUNTRY
) ||
12861 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
12863 goto nla_put_failure
;
12866 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
12867 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
12870 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
12871 goto nla_put_failure
;
12874 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
12875 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
12876 goto nla_put_failure
;
12886 * This can happen on global regulatory changes or device specific settings
12887 * based on custom regulatory domains.
12889 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
12890 struct regulatory_request
*request
)
12892 struct sk_buff
*msg
;
12895 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12899 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
12905 if (nl80211_reg_change_event_fill(msg
, request
) == false)
12906 goto nla_put_failure
;
12908 genlmsg_end(msg
, hdr
);
12911 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
12912 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
12918 genlmsg_cancel(msg
, hdr
);
12922 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
12923 struct net_device
*netdev
,
12924 const u8
*buf
, size_t len
,
12925 enum nl80211_commands cmd
, gfp_t gfp
,
12928 struct sk_buff
*msg
;
12931 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12935 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12941 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12942 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12943 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
12944 goto nla_put_failure
;
12946 if (uapsd_queues
>= 0) {
12947 struct nlattr
*nla_wmm
=
12948 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
12950 goto nla_put_failure
;
12952 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
12954 goto nla_put_failure
;
12956 nla_nest_end(msg
, nla_wmm
);
12959 genlmsg_end(msg
, hdr
);
12961 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12962 NL80211_MCGRP_MLME
, gfp
);
12966 genlmsg_cancel(msg
, hdr
);
12970 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
12971 struct net_device
*netdev
, const u8
*buf
,
12972 size_t len
, gfp_t gfp
)
12974 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12975 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
12978 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
12979 struct net_device
*netdev
, const u8
*buf
,
12980 size_t len
, gfp_t gfp
, int uapsd_queues
)
12982 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12983 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
12986 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
12987 struct net_device
*netdev
, const u8
*buf
,
12988 size_t len
, gfp_t gfp
)
12990 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12991 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
12994 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
12995 struct net_device
*netdev
, const u8
*buf
,
12996 size_t len
, gfp_t gfp
)
12998 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12999 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
13002 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
13005 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13006 struct wiphy
*wiphy
= wdev
->wiphy
;
13007 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13008 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
13011 if (WARN_ON(len
< 2))
13014 if (ieee80211_is_deauth(mgmt
->frame_control
))
13015 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
13017 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
13019 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
13020 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
13022 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
13024 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
13025 struct net_device
*netdev
, int cmd
,
13026 const u8
*addr
, gfp_t gfp
)
13028 struct sk_buff
*msg
;
13031 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13035 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13041 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13042 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13043 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
13044 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
13045 goto nla_put_failure
;
13047 genlmsg_end(msg
, hdr
);
13049 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13050 NL80211_MCGRP_MLME
, gfp
);
13054 genlmsg_cancel(msg
, hdr
);
13058 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
13059 struct net_device
*netdev
, const u8
*addr
,
13062 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
13066 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
13067 struct net_device
*netdev
, const u8
*addr
,
13070 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
13074 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
13075 struct net_device
*netdev
, const u8
*bssid
,
13076 const u8
*req_ie
, size_t req_ie_len
,
13077 const u8
*resp_ie
, size_t resp_ie_len
,
13078 int status
, gfp_t gfp
)
13080 struct sk_buff
*msg
;
13083 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13087 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
13093 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13094 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13095 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
13096 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
13097 status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
13099 (status
< 0 && nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
)) ||
13101 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
13103 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
13104 goto nla_put_failure
;
13106 genlmsg_end(msg
, hdr
);
13108 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13109 NL80211_MCGRP_MLME
, gfp
);
13113 genlmsg_cancel(msg
, hdr
);
13117 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
13118 struct net_device
*netdev
, const u8
*bssid
,
13119 const u8
*req_ie
, size_t req_ie_len
,
13120 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
13122 struct sk_buff
*msg
;
13125 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13129 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
13135 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13136 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13137 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
13139 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
13141 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
13142 goto nla_put_failure
;
13144 genlmsg_end(msg
, hdr
);
13146 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13147 NL80211_MCGRP_MLME
, gfp
);
13151 genlmsg_cancel(msg
, hdr
);
13155 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
13156 struct net_device
*netdev
, u16 reason
,
13157 const u8
*ie
, size_t ie_len
, bool from_ap
)
13159 struct sk_buff
*msg
;
13162 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13166 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
13172 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13173 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13174 (from_ap
&& reason
&&
13175 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
13177 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
13178 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
13179 goto nla_put_failure
;
13181 genlmsg_end(msg
, hdr
);
13183 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13184 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13188 genlmsg_cancel(msg
, hdr
);
13192 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
13193 struct net_device
*netdev
, const u8
*bssid
,
13196 struct sk_buff
*msg
;
13199 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13203 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
13209 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13210 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13211 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
13212 goto nla_put_failure
;
13214 genlmsg_end(msg
, hdr
);
13216 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13217 NL80211_MCGRP_MLME
, gfp
);
13221 genlmsg_cancel(msg
, hdr
);
13225 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
13226 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
13228 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13229 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13230 struct sk_buff
*msg
;
13233 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
13236 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
13238 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13242 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
13248 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13249 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13250 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
13252 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
13253 goto nla_put_failure
;
13255 genlmsg_end(msg
, hdr
);
13257 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13258 NL80211_MCGRP_MLME
, gfp
);
13262 genlmsg_cancel(msg
, hdr
);
13265 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
13267 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
13268 struct net_device
*netdev
, const u8
*addr
,
13269 enum nl80211_key_type key_type
, int key_id
,
13270 const u8
*tsc
, gfp_t gfp
)
13272 struct sk_buff
*msg
;
13275 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13279 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
13285 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13286 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13287 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
13288 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
13290 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
13291 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
13292 goto nla_put_failure
;
13294 genlmsg_end(msg
, hdr
);
13296 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13297 NL80211_MCGRP_MLME
, gfp
);
13301 genlmsg_cancel(msg
, hdr
);
13305 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
13306 struct ieee80211_channel
*channel_before
,
13307 struct ieee80211_channel
*channel_after
)
13309 struct sk_buff
*msg
;
13311 struct nlattr
*nl_freq
;
13313 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
13317 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
13324 * Since we are applying the beacon hint to a wiphy we know its
13325 * wiphy_idx is valid
13327 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
13328 goto nla_put_failure
;
13331 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
13333 goto nla_put_failure
;
13334 if (nl80211_msg_put_channel(msg
, channel_before
, false))
13335 goto nla_put_failure
;
13336 nla_nest_end(msg
, nl_freq
);
13339 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
13341 goto nla_put_failure
;
13342 if (nl80211_msg_put_channel(msg
, channel_after
, false))
13343 goto nla_put_failure
;
13344 nla_nest_end(msg
, nl_freq
);
13346 genlmsg_end(msg
, hdr
);
13349 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
13350 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
13356 genlmsg_cancel(msg
, hdr
);
13360 static void nl80211_send_remain_on_chan_event(
13361 int cmd
, struct cfg80211_registered_device
*rdev
,
13362 struct wireless_dev
*wdev
, u64 cookie
,
13363 struct ieee80211_channel
*chan
,
13364 unsigned int duration
, gfp_t gfp
)
13366 struct sk_buff
*msg
;
13369 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13373 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13379 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13380 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13381 wdev
->netdev
->ifindex
)) ||
13382 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13383 NL80211_ATTR_PAD
) ||
13384 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
13385 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
13386 NL80211_CHAN_NO_HT
) ||
13387 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
13389 goto nla_put_failure
;
13391 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
13392 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
13393 goto nla_put_failure
;
13395 genlmsg_end(msg
, hdr
);
13397 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13398 NL80211_MCGRP_MLME
, gfp
);
13402 genlmsg_cancel(msg
, hdr
);
13406 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
13407 struct ieee80211_channel
*chan
,
13408 unsigned int duration
, gfp_t gfp
)
13410 struct wiphy
*wiphy
= wdev
->wiphy
;
13411 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13413 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
13414 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
13415 rdev
, wdev
, cookie
, chan
,
13418 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
13420 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
13421 struct ieee80211_channel
*chan
,
13424 struct wiphy
*wiphy
= wdev
->wiphy
;
13425 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13427 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
13428 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
13429 rdev
, wdev
, cookie
, chan
, 0, gfp
);
13431 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
13433 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
13434 struct station_info
*sinfo
, gfp_t gfp
)
13436 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
13437 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13438 struct sk_buff
*msg
;
13440 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
13442 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13446 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
13447 rdev
, dev
, mac_addr
, sinfo
) < 0) {
13452 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13453 NL80211_MCGRP_MLME
, gfp
);
13455 EXPORT_SYMBOL(cfg80211_new_sta
);
13457 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
13458 struct station_info
*sinfo
, gfp_t gfp
)
13460 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
13461 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13462 struct sk_buff
*msg
;
13463 struct station_info empty_sinfo
= {};
13466 sinfo
= &empty_sinfo
;
13468 trace_cfg80211_del_sta(dev
, mac_addr
);
13470 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13474 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
13475 rdev
, dev
, mac_addr
, sinfo
) < 0) {
13480 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13481 NL80211_MCGRP_MLME
, gfp
);
13483 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
13485 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
13486 enum nl80211_connect_failed_reason reason
,
13489 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
13490 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13491 struct sk_buff
*msg
;
13494 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
13498 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
13504 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13505 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
13506 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
13507 goto nla_put_failure
;
13509 genlmsg_end(msg
, hdr
);
13511 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13512 NL80211_MCGRP_MLME
, gfp
);
13516 genlmsg_cancel(msg
, hdr
);
13519 EXPORT_SYMBOL(cfg80211_conn_failed
);
13521 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
13522 const u8
*addr
, gfp_t gfp
)
13524 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13525 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13526 struct sk_buff
*msg
;
13528 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
13533 msg
= nlmsg_new(100, gfp
);
13537 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
13543 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13544 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13545 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
13546 goto nla_put_failure
;
13548 genlmsg_end(msg
, hdr
);
13549 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
13553 genlmsg_cancel(msg
, hdr
);
13558 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
13559 const u8
*addr
, gfp_t gfp
)
13561 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13564 trace_cfg80211_rx_spurious_frame(dev
, addr
);
13566 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
13567 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
13568 trace_cfg80211_return_bool(false);
13571 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
13573 trace_cfg80211_return_bool(ret
);
13576 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
13578 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
13579 const u8
*addr
, gfp_t gfp
)
13581 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13584 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
13586 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
13587 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
13588 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
13589 trace_cfg80211_return_bool(false);
13592 ret
= __nl80211_unexpected_frame(dev
,
13593 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
13595 trace_cfg80211_return_bool(ret
);
13598 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
13600 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
13601 struct wireless_dev
*wdev
, u32 nlportid
,
13602 int freq
, int sig_dbm
,
13603 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
13605 struct net_device
*netdev
= wdev
->netdev
;
13606 struct sk_buff
*msg
;
13609 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13613 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
13619 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13620 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13621 netdev
->ifindex
)) ||
13622 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13623 NL80211_ATTR_PAD
) ||
13624 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
13626 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
13627 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
13629 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
13630 goto nla_put_failure
;
13632 genlmsg_end(msg
, hdr
);
13634 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
13637 genlmsg_cancel(msg
, hdr
);
13642 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
13643 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
13645 struct wiphy
*wiphy
= wdev
->wiphy
;
13646 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13647 struct net_device
*netdev
= wdev
->netdev
;
13648 struct sk_buff
*msg
;
13651 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
13653 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13657 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
13663 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13664 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13665 netdev
->ifindex
)) ||
13666 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13667 NL80211_ATTR_PAD
) ||
13668 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
13669 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
13670 NL80211_ATTR_PAD
) ||
13671 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
13672 goto nla_put_failure
;
13674 genlmsg_end(msg
, hdr
);
13676 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13677 NL80211_MCGRP_MLME
, gfp
);
13681 genlmsg_cancel(msg
, hdr
);
13684 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
13686 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
13687 const char *mac
, gfp_t gfp
)
13689 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13690 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13691 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13697 cb
= (void **)msg
->cb
;
13699 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
13705 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13706 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
13707 goto nla_put_failure
;
13709 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
13710 goto nla_put_failure
;
13712 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
13714 goto nla_put_failure
;
13724 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
13726 void **cb
= (void **)msg
->cb
;
13727 struct cfg80211_registered_device
*rdev
= cb
[2];
13729 nla_nest_end(msg
, cb
[1]);
13730 genlmsg_end(msg
, cb
[0]);
13732 memset(msg
->cb
, 0, sizeof(msg
->cb
));
13734 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13735 NL80211_MCGRP_MLME
, gfp
);
13738 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
13739 enum nl80211_cqm_rssi_threshold_event rssi_event
,
13742 struct sk_buff
*msg
;
13744 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
13746 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
13747 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
13750 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
13754 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
13756 goto nla_put_failure
;
13758 cfg80211_send_cqm(msg
, gfp
);
13765 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
13767 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
13768 const u8
*peer
, u32 num_packets
,
13769 u32 rate
, u32 intvl
, gfp_t gfp
)
13771 struct sk_buff
*msg
;
13773 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
13777 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
13778 goto nla_put_failure
;
13780 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
13781 goto nla_put_failure
;
13783 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
13784 goto nla_put_failure
;
13786 cfg80211_send_cqm(msg
, gfp
);
13792 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
13794 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
13795 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
13797 struct sk_buff
*msg
;
13799 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
13801 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
13805 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
13806 goto nla_put_failure
;
13808 cfg80211_send_cqm(msg
, gfp
);
13814 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
13816 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
13818 struct sk_buff
*msg
;
13820 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
13824 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
13825 goto nla_put_failure
;
13827 cfg80211_send_cqm(msg
, gfp
);
13833 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
13835 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
13836 struct net_device
*netdev
, const u8
*bssid
,
13837 const u8
*replay_ctr
, gfp_t gfp
)
13839 struct sk_buff
*msg
;
13840 struct nlattr
*rekey_attr
;
13843 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13847 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
13853 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13854 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13855 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
13856 goto nla_put_failure
;
13858 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
13860 goto nla_put_failure
;
13862 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
13863 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
13864 goto nla_put_failure
;
13866 nla_nest_end(msg
, rekey_attr
);
13868 genlmsg_end(msg
, hdr
);
13870 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13871 NL80211_MCGRP_MLME
, gfp
);
13875 genlmsg_cancel(msg
, hdr
);
13879 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
13880 const u8
*replay_ctr
, gfp_t gfp
)
13882 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13883 struct wiphy
*wiphy
= wdev
->wiphy
;
13884 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13886 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
13887 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
13889 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
13892 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
13893 struct net_device
*netdev
, int index
,
13894 const u8
*bssid
, bool preauth
, gfp_t gfp
)
13896 struct sk_buff
*msg
;
13897 struct nlattr
*attr
;
13900 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13904 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
13910 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13911 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
13912 goto nla_put_failure
;
13914 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
13916 goto nla_put_failure
;
13918 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
13919 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
13921 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
13922 goto nla_put_failure
;
13924 nla_nest_end(msg
, attr
);
13926 genlmsg_end(msg
, hdr
);
13928 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13929 NL80211_MCGRP_MLME
, gfp
);
13933 genlmsg_cancel(msg
, hdr
);
13937 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
13938 const u8
*bssid
, bool preauth
, gfp_t gfp
)
13940 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13941 struct wiphy
*wiphy
= wdev
->wiphy
;
13942 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13944 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
13945 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
13947 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
13949 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
13950 struct net_device
*netdev
,
13951 struct cfg80211_chan_def
*chandef
,
13953 enum nl80211_commands notif
,
13956 struct sk_buff
*msg
;
13959 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13963 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
13969 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
13970 goto nla_put_failure
;
13972 if (nl80211_send_chandef(msg
, chandef
))
13973 goto nla_put_failure
;
13975 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
13976 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
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 cfg80211_ch_switch_notify(struct net_device
*dev
,
13991 struct cfg80211_chan_def
*chandef
)
13993 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13994 struct wiphy
*wiphy
= wdev
->wiphy
;
13995 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13997 ASSERT_WDEV_LOCK(wdev
);
13999 trace_cfg80211_ch_switch_notify(dev
, chandef
);
14001 wdev
->chandef
= *chandef
;
14002 wdev
->preset_chandef
= *chandef
;
14003 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
14004 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
14006 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
14008 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
14009 struct cfg80211_chan_def
*chandef
,
14012 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14013 struct wiphy
*wiphy
= wdev
->wiphy
;
14014 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14016 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
14018 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
14019 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
14021 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
14024 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
14025 const struct cfg80211_chan_def
*chandef
,
14026 enum nl80211_radar_event event
,
14027 struct net_device
*netdev
, gfp_t gfp
)
14029 struct sk_buff
*msg
;
14032 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14036 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
14042 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
14043 goto nla_put_failure
;
14045 /* NOP and radar events don't need a netdev parameter */
14047 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
14049 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14050 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14052 goto nla_put_failure
;
14055 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
14056 goto nla_put_failure
;
14058 if (nl80211_send_chandef(msg
, chandef
))
14059 goto nla_put_failure
;
14061 genlmsg_end(msg
, hdr
);
14063 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14064 NL80211_MCGRP_MLME
, gfp
);
14068 genlmsg_cancel(msg
, hdr
);
14072 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
14073 u64 cookie
, bool acked
, gfp_t gfp
)
14075 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14076 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14077 struct sk_buff
*msg
;
14080 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
14082 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14087 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
14093 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14094 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14095 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
14096 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
14097 NL80211_ATTR_PAD
) ||
14098 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
14099 goto nla_put_failure
;
14101 genlmsg_end(msg
, hdr
);
14103 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14104 NL80211_MCGRP_MLME
, gfp
);
14108 genlmsg_cancel(msg
, hdr
);
14111 EXPORT_SYMBOL(cfg80211_probe_status
);
14113 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
14114 const u8
*frame
, size_t len
,
14115 int freq
, int sig_dbm
)
14117 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14118 struct sk_buff
*msg
;
14120 struct cfg80211_beacon_registration
*reg
;
14122 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
14124 spin_lock_bh(&rdev
->beacon_registrations_lock
);
14125 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
14126 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
14128 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14132 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
14134 goto nla_put_failure
;
14136 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14138 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
14140 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
14141 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
14142 goto nla_put_failure
;
14144 genlmsg_end(msg
, hdr
);
14146 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
14148 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14152 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14154 genlmsg_cancel(msg
, hdr
);
14157 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
14160 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
14161 struct cfg80211_wowlan_wakeup
*wakeup
)
14163 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
14164 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
14167 nl_results
= nla_nest_start(
14168 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
14172 for (i
= 0; i
< nd
->n_matches
; i
++) {
14173 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
14175 nl_match
= nla_nest_start(msg
, i
);
14179 /* The SSID attribute is optional in nl80211, but for
14180 * simplicity reasons it's always present in the
14181 * cfg80211 structure. If a driver can't pass the
14182 * SSID, that needs to be changed. A zero length SSID
14183 * is still a valid SSID (wildcard), so it cannot be
14184 * used for this purpose.
14186 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
14187 match
->ssid
.ssid
)) {
14188 nla_nest_cancel(msg
, nl_match
);
14192 if (match
->n_channels
) {
14193 nl_freqs
= nla_nest_start(
14194 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
14196 nla_nest_cancel(msg
, nl_match
);
14200 for (j
= 0; j
< match
->n_channels
; j
++) {
14201 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
14202 nla_nest_cancel(msg
, nl_freqs
);
14203 nla_nest_cancel(msg
, nl_match
);
14208 nla_nest_end(msg
, nl_freqs
);
14211 nla_nest_end(msg
, nl_match
);
14215 nla_nest_end(msg
, nl_results
);
14219 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
14220 struct cfg80211_wowlan_wakeup
*wakeup
,
14223 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14224 struct sk_buff
*msg
;
14228 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
14231 size
+= wakeup
->packet_present_len
;
14233 msg
= nlmsg_new(size
, gfp
);
14237 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
14241 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14242 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14246 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
14247 wdev
->netdev
->ifindex
))
14251 struct nlattr
*reasons
;
14253 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
14257 if (wakeup
->disconnect
&&
14258 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
14260 if (wakeup
->magic_pkt
&&
14261 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
14263 if (wakeup
->gtk_rekey_failure
&&
14264 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
14266 if (wakeup
->eap_identity_req
&&
14267 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
14269 if (wakeup
->four_way_handshake
&&
14270 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
14272 if (wakeup
->rfkill_release
&&
14273 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
14276 if (wakeup
->pattern_idx
>= 0 &&
14277 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
14278 wakeup
->pattern_idx
))
14281 if (wakeup
->tcp_match
&&
14282 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
14285 if (wakeup
->tcp_connlost
&&
14286 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
14289 if (wakeup
->tcp_nomoretokens
&&
14291 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
14294 if (wakeup
->packet
) {
14295 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
14296 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
14298 if (!wakeup
->packet_80211
) {
14300 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
14302 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
14305 if (wakeup
->packet_len
&&
14306 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
14309 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
14314 if (wakeup
->net_detect
&&
14315 cfg80211_net_detect_results(msg
, wakeup
))
14318 nla_nest_end(msg
, reasons
);
14321 genlmsg_end(msg
, hdr
);
14323 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14324 NL80211_MCGRP_MLME
, gfp
);
14330 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
14333 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
14334 enum nl80211_tdls_operation oper
,
14335 u16 reason_code
, gfp_t gfp
)
14337 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
14338 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
14339 struct sk_buff
*msg
;
14342 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
14345 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14349 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
14355 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14356 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
14357 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
14358 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
14359 (reason_code
> 0 &&
14360 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
14361 goto nla_put_failure
;
14363 genlmsg_end(msg
, hdr
);
14365 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14366 NL80211_MCGRP_MLME
, gfp
);
14370 genlmsg_cancel(msg
, hdr
);
14373 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
14375 static int nl80211_netlink_notify(struct notifier_block
* nb
,
14376 unsigned long state
,
14379 struct netlink_notify
*notify
= _notify
;
14380 struct cfg80211_registered_device
*rdev
;
14381 struct wireless_dev
*wdev
;
14382 struct cfg80211_beacon_registration
*reg
, *tmp
;
14384 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
14385 return NOTIFY_DONE
;
14389 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
14390 bool schedule_destroy_work
= false;
14391 bool schedule_scan_stop
= false;
14392 struct cfg80211_sched_scan_request
*sched_scan_req
=
14393 rcu_dereference(rdev
->sched_scan_req
);
14395 if (sched_scan_req
&& notify
->portid
&&
14396 sched_scan_req
->owner_nlportid
== notify
->portid
)
14397 schedule_scan_stop
= true;
14399 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
14400 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
14402 if (wdev
->owner_nlportid
== notify
->portid
)
14403 schedule_destroy_work
= true;
14406 spin_lock_bh(&rdev
->beacon_registrations_lock
);
14407 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
14409 if (reg
->nlportid
== notify
->portid
) {
14410 list_del(®
->list
);
14415 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
14417 if (schedule_destroy_work
) {
14418 struct cfg80211_iface_destroy
*destroy
;
14420 destroy
= kzalloc(sizeof(*destroy
), GFP_ATOMIC
);
14422 destroy
->nlportid
= notify
->portid
;
14423 spin_lock(&rdev
->destroy_list_lock
);
14424 list_add(&destroy
->list
, &rdev
->destroy_list
);
14425 spin_unlock(&rdev
->destroy_list_lock
);
14426 schedule_work(&rdev
->destroy_work
);
14428 } else if (schedule_scan_stop
) {
14429 sched_scan_req
->owner_nlportid
= 0;
14431 if (rdev
->ops
->sched_scan_stop
&&
14432 rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
14433 schedule_work(&rdev
->sched_scan_stop_wk
);
14440 * It is possible that the user space process that is controlling the
14441 * indoor setting disappeared, so notify the regulatory core.
14443 regulatory_netlink_notify(notify
->portid
);
14447 static struct notifier_block nl80211_netlink_notifier
= {
14448 .notifier_call
= nl80211_netlink_notify
,
14451 void cfg80211_ft_event(struct net_device
*netdev
,
14452 struct cfg80211_ft_event_params
*ft_event
)
14454 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
14455 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14456 struct sk_buff
*msg
;
14459 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
14461 if (!ft_event
->target_ap
)
14464 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14468 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
14472 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14473 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
14474 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
14477 if (ft_event
->ies
&&
14478 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
14480 if (ft_event
->ric_ies
&&
14481 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
14482 ft_event
->ric_ies
))
14485 genlmsg_end(msg
, hdr
);
14487 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
14488 NL80211_MCGRP_MLME
, GFP_KERNEL
);
14493 EXPORT_SYMBOL(cfg80211_ft_event
);
14495 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
14497 struct cfg80211_registered_device
*rdev
;
14498 struct sk_buff
*msg
;
14502 rdev
= wiphy_to_rdev(wdev
->wiphy
);
14503 if (!rdev
->crit_proto_nlportid
)
14506 nlportid
= rdev
->crit_proto_nlportid
;
14507 rdev
->crit_proto_nlportid
= 0;
14509 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
14513 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
14515 goto nla_put_failure
;
14517 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14518 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14520 goto nla_put_failure
;
14522 genlmsg_end(msg
, hdr
);
14524 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
14529 genlmsg_cancel(msg
, hdr
);
14532 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
14534 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
14536 struct wiphy
*wiphy
= wdev
->wiphy
;
14537 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
14538 struct sk_buff
*msg
;
14541 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
14545 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
14549 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
14550 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
14551 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
14555 genlmsg_end(msg
, hdr
);
14557 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
14558 NL80211_MCGRP_MLME
, GFP_KERNEL
);
14564 /* initialisation/exit functions */
14566 int nl80211_init(void)
14570 err
= genl_register_family_with_ops_groups(&nl80211_fam
, nl80211_ops
,
14575 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
14581 genl_unregister_family(&nl80211_fam
);
14585 void nl80211_exit(void)
14587 netlink_unregister_notifier(&nl80211_netlink_notifier
);
14588 genl_unregister_family(&nl80211_fam
);