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
,
59 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
62 static const struct genl_multicast_group nl80211_mcgrps
[] = {
63 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
64 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
65 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
66 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
67 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
68 #ifdef CONFIG_NL80211_TESTMODE
69 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
73 /* returns ERR_PTR values */
74 static struct wireless_dev
*
75 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
77 struct cfg80211_registered_device
*rdev
;
78 struct wireless_dev
*result
= NULL
;
79 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
80 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
87 if (!have_ifidx
&& !have_wdev_id
)
88 return ERR_PTR(-EINVAL
);
91 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
93 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
94 wiphy_idx
= wdev_id
>> 32;
97 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
98 struct wireless_dev
*wdev
;
100 if (wiphy_net(&rdev
->wiphy
) != netns
)
103 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
106 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
107 if (have_ifidx
&& wdev
->netdev
&&
108 wdev
->netdev
->ifindex
== ifidx
) {
112 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
124 return ERR_PTR(-ENODEV
);
127 static struct cfg80211_registered_device
*
128 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
130 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
131 struct net_device
*netdev
;
135 if (!attrs
[NL80211_ATTR_WIPHY
] &&
136 !attrs
[NL80211_ATTR_IFINDEX
] &&
137 !attrs
[NL80211_ATTR_WDEV
])
138 return ERR_PTR(-EINVAL
);
140 if (attrs
[NL80211_ATTR_WIPHY
])
141 rdev
= cfg80211_rdev_by_wiphy_idx(
142 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
144 if (attrs
[NL80211_ATTR_WDEV
]) {
145 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
146 struct wireless_dev
*wdev
;
149 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
151 /* make sure wdev exists */
152 list_for_each_entry(wdev
, &tmp
->wiphy
.wdev_list
, list
) {
153 if (wdev
->identifier
!= (u32
)wdev_id
)
162 if (rdev
&& tmp
!= rdev
)
163 return ERR_PTR(-EINVAL
);
168 if (attrs
[NL80211_ATTR_IFINDEX
]) {
169 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
171 netdev
= __dev_get_by_index(netns
, ifindex
);
173 if (netdev
->ieee80211_ptr
)
175 netdev
->ieee80211_ptr
->wiphy
);
179 /* not wireless device -- return error */
181 return ERR_PTR(-EINVAL
);
183 /* mismatch -- return error */
184 if (rdev
&& tmp
!= rdev
)
185 return ERR_PTR(-EINVAL
);
192 return ERR_PTR(-ENODEV
);
194 if (netns
!= wiphy_net(&rdev
->wiphy
))
195 return ERR_PTR(-ENODEV
);
201 * This function returns a pointer to the driver
202 * that the genl_info item that is passed refers to.
204 * The result of this can be a PTR_ERR and hence must
205 * be checked with IS_ERR() for errors.
207 static struct cfg80211_registered_device
*
208 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
210 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
213 /* policy for the attributes */
214 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
215 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
216 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
218 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
220 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
221 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
222 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
226 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
227 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
228 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
231 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
233 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
235 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
237 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
238 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
240 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
241 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
242 .len
= WLAN_MAX_KEY_LEN
},
243 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
244 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
245 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
246 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
247 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
249 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
252 .len
= IEEE80211_MAX_DATA_LEN
},
253 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
254 .len
= IEEE80211_MAX_DATA_LEN
},
255 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
256 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
257 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
258 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
259 .len
= NL80211_MAX_SUPP_RATES
},
260 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
261 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
262 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
263 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
264 .len
= IEEE80211_MAX_MESH_ID_LEN
},
265 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
267 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
268 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
270 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
271 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
274 .len
= NL80211_MAX_SUPP_RATES
},
275 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
277 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
278 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
280 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
282 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
283 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
284 .len
= IEEE80211_MAX_DATA_LEN
},
285 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
286 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
288 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
289 .len
= IEEE80211_MAX_SSID_LEN
},
290 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
291 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
292 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
293 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
295 [NL80211_ATTR_STA_FLAGS2
] = {
296 .len
= sizeof(struct nl80211_sta_flag_update
),
298 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
303 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
306 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
307 .len
= WLAN_PMKID_LEN
},
308 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
309 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
310 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
311 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
312 .len
= IEEE80211_MAX_DATA_LEN
},
313 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
314 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
315 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
316 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
317 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
318 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
319 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
321 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
323 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
324 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
325 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
326 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
327 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
328 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
330 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
331 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
332 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
333 .len
= IEEE80211_MAX_DATA_LEN
},
334 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
335 .len
= IEEE80211_MAX_DATA_LEN
},
336 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
337 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
338 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
339 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
340 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
341 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
342 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
343 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
347 .len
= IEEE80211_MAX_DATA_LEN
},
348 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
351 .len
= NL80211_HT_CAPABILITY_LEN
353 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
354 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
355 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
356 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
357 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
358 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
359 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
360 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
361 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
362 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
363 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
364 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
365 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
366 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
367 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
368 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
369 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
370 .len
= NL80211_VHT_CAPABILITY_LEN
,
372 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
373 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
374 .len
= IEEE80211_MAX_DATA_LEN
},
375 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
376 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
377 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
378 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
379 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
380 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
381 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
382 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
384 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
385 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
386 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
387 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
388 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
389 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
390 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
391 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
392 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
393 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
394 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
395 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
396 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
397 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
398 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
399 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
400 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
401 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
402 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
403 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
404 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
405 [NL80211_ATTR_PBSS
] = { .type
= NLA_FLAG
},
406 [NL80211_ATTR_BSS_SELECT
] = { .type
= NLA_NESTED
},
407 [NL80211_ATTR_STA_SUPPORT_P2P_PS
] = { .type
= NLA_U8
},
408 [NL80211_ATTR_MU_MIMO_GROUP_DATA
] = {
409 .len
= VHT_MUMIMO_GROUPS_DATA_LEN
411 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
] = { .len
= ETH_ALEN
},
414 /* policy for the key attributes */
415 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
416 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
417 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
418 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
419 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
420 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
421 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
422 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
423 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
426 /* policy for the key default flags */
427 static const struct nla_policy
428 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
429 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
430 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
433 /* policy for WoWLAN attributes */
434 static const struct nla_policy
435 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
436 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
437 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
438 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
439 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
440 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
441 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
442 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
443 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
444 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
445 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
448 static const struct nla_policy
449 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
450 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
451 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
452 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
453 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
454 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
455 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
456 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
457 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
459 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
460 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
462 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
463 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
464 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
467 /* policy for coalesce rule attributes */
468 static const struct nla_policy
469 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
470 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
471 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
472 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
475 /* policy for GTK rekey offload attributes */
476 static const struct nla_policy
477 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
478 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
479 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
480 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
483 static const struct nla_policy
484 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
485 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
486 .len
= IEEE80211_MAX_SSID_LEN
},
487 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
490 static const struct nla_policy
491 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
492 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
493 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
496 static const struct nla_policy
497 nl80211_bss_select_policy
[NL80211_BSS_SELECT_ATTR_MAX
+ 1] = {
498 [NL80211_BSS_SELECT_ATTR_RSSI
] = { .type
= NLA_FLAG
},
499 [NL80211_BSS_SELECT_ATTR_BAND_PREF
] = { .type
= NLA_U32
},
500 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
] = {
501 .len
= sizeof(struct nl80211_bss_select_rssi_adjust
)
505 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
506 struct netlink_callback
*cb
,
507 struct cfg80211_registered_device
**rdev
,
508 struct wireless_dev
**wdev
)
515 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
516 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
521 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
522 nl80211_fam
.attrbuf
);
524 err
= PTR_ERR(*wdev
);
527 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
528 /* 0 is the first index - add 1 to parse only once */
529 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
530 cb
->args
[1] = (*wdev
)->identifier
;
532 /* subtract the 1 again here */
533 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
534 struct wireless_dev
*tmp
;
540 *rdev
= wiphy_to_rdev(wiphy
);
543 list_for_each_entry(tmp
, &(*rdev
)->wiphy
.wdev_list
, list
) {
544 if (tmp
->identifier
== cb
->args
[1]) {
562 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
568 static bool is_valid_ie_attr(const struct nlattr
*attr
)
576 pos
= nla_data(attr
);
597 /* message building helper */
598 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
601 /* since there is no private header just add the generic one */
602 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
605 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
606 struct ieee80211_channel
*chan
,
609 /* Some channels must be completely excluded from the
610 * list to protect old user-space tools from breaking
612 if (!large
&& chan
->flags
&
613 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
616 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
618 goto nla_put_failure
;
620 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
621 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
622 goto nla_put_failure
;
623 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
624 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
625 goto nla_put_failure
;
626 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
627 goto nla_put_failure
;
629 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
630 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
631 goto nla_put_failure
;
635 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
637 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
639 goto nla_put_failure
;
640 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
642 goto nla_put_failure
;
644 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
646 goto nla_put_failure
;
651 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
652 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
653 goto nla_put_failure
;
654 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
655 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
656 goto nla_put_failure
;
657 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
658 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
659 goto nla_put_failure
;
660 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
661 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
662 goto nla_put_failure
;
663 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
664 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
665 goto nla_put_failure
;
666 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
667 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
668 goto nla_put_failure
;
669 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
670 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
671 goto nla_put_failure
;
672 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
673 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
674 goto nla_put_failure
;
677 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
678 DBM_TO_MBM(chan
->max_power
)))
679 goto nla_put_failure
;
687 /* netlink command implementations */
694 bool def_uni
, def_multi
;
697 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
699 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
700 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
705 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
706 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
715 if (tb
[NL80211_KEY_IDX
])
716 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
718 if (tb
[NL80211_KEY_DATA
]) {
719 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
720 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
723 if (tb
[NL80211_KEY_SEQ
]) {
724 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
725 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
728 if (tb
[NL80211_KEY_CIPHER
])
729 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
731 if (tb
[NL80211_KEY_TYPE
]) {
732 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
733 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
737 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
738 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
740 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
741 tb
[NL80211_KEY_DEFAULT_TYPES
],
742 nl80211_key_default_policy
);
746 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
747 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
753 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
755 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
756 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
757 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
760 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
761 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
762 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
765 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
766 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
768 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
769 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
771 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
772 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
781 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
782 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
783 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
787 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
788 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
789 int err
= nla_parse_nested(
790 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
791 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
792 nl80211_key_default_policy
);
796 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
797 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
803 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
807 memset(k
, 0, sizeof(*k
));
811 if (info
->attrs
[NL80211_ATTR_KEY
])
812 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
814 err
= nl80211_parse_key_old(info
, k
);
819 if (k
->def
&& k
->defmgmt
)
823 if (k
->def_uni
|| !k
->def_multi
)
829 if (k
->idx
< 4 || k
->idx
> 5)
832 if (k
->idx
< 0 || k
->idx
> 3)
835 if (k
->idx
< 0 || k
->idx
> 5)
843 static struct cfg80211_cached_keys
*
844 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
845 struct nlattr
*keys
, bool *no_ht
)
847 struct key_parse parse
;
849 struct cfg80211_cached_keys
*result
;
850 int rem
, err
, def
= 0;
852 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
854 return ERR_PTR(-ENOMEM
);
857 result
->defmgmt
= -1;
859 nla_for_each_nested(key
, keys
, rem
) {
860 memset(&parse
, 0, sizeof(parse
));
863 err
= nl80211_parse_key_new(key
, &parse
);
869 if (parse
.idx
< 0 || parse
.idx
> 4)
875 result
->def
= parse
.idx
;
876 if (!parse
.def_uni
|| !parse
.def_multi
)
878 } else if (parse
.defmgmt
)
880 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
881 parse
.idx
, false, NULL
);
884 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
885 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
886 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
887 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
889 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
890 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
902 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
904 ASSERT_WDEV_LOCK(wdev
);
906 switch (wdev
->iftype
) {
907 case NL80211_IFTYPE_AP
:
908 case NL80211_IFTYPE_AP_VLAN
:
909 case NL80211_IFTYPE_P2P_GO
:
910 case NL80211_IFTYPE_MESH_POINT
:
912 case NL80211_IFTYPE_ADHOC
:
913 case NL80211_IFTYPE_STATION
:
914 case NL80211_IFTYPE_P2P_CLIENT
:
915 if (!wdev
->current_bss
)
918 case NL80211_IFTYPE_UNSPECIFIED
:
919 case NL80211_IFTYPE_OCB
:
920 case NL80211_IFTYPE_MONITOR
:
921 case NL80211_IFTYPE_P2P_DEVICE
:
922 case NL80211_IFTYPE_WDS
:
923 case NUM_NL80211_IFTYPES
:
930 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
933 struct ieee80211_channel
*chan
;
937 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
938 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
943 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
945 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
949 goto nla_put_failure
;
953 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
954 goto nla_put_failure
;
959 nla_nest_end(msg
, nl_modes
);
966 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
970 struct nlattr
*nl_combis
;
973 nl_combis
= nla_nest_start(msg
,
974 NL80211_ATTR_INTERFACE_COMBINATIONS
);
976 goto nla_put_failure
;
978 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
979 const struct ieee80211_iface_combination
*c
;
980 struct nlattr
*nl_combi
, *nl_limits
;
982 c
= &wiphy
->iface_combinations
[i
];
984 nl_combi
= nla_nest_start(msg
, i
+ 1);
986 goto nla_put_failure
;
988 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
990 goto nla_put_failure
;
992 for (j
= 0; j
< c
->n_limits
; j
++) {
993 struct nlattr
*nl_limit
;
995 nl_limit
= nla_nest_start(msg
, j
+ 1);
997 goto nla_put_failure
;
998 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
1000 goto nla_put_failure
;
1001 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
1002 c
->limits
[j
].types
))
1003 goto nla_put_failure
;
1004 nla_nest_end(msg
, nl_limit
);
1007 nla_nest_end(msg
, nl_limits
);
1009 if (c
->beacon_int_infra_match
&&
1010 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
1011 goto nla_put_failure
;
1012 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
1013 c
->num_different_channels
) ||
1014 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
1016 goto nla_put_failure
;
1018 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1019 c
->radar_detect_widths
) ||
1020 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1021 c
->radar_detect_regions
)))
1022 goto nla_put_failure
;
1024 nla_nest_end(msg
, nl_combi
);
1027 nla_nest_end(msg
, nl_combis
);
1035 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1036 struct sk_buff
*msg
)
1038 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1039 struct nlattr
*nl_tcp
;
1044 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1048 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1049 tcp
->data_payload_max
))
1052 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1053 tcp
->data_payload_max
))
1056 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1059 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1060 sizeof(*tcp
->tok
), tcp
->tok
))
1063 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1064 tcp
->data_interval_max
))
1067 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1068 tcp
->wake_payload_max
))
1071 nla_nest_end(msg
, nl_tcp
);
1075 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1076 struct cfg80211_registered_device
*rdev
,
1079 struct nlattr
*nl_wowlan
;
1081 if (!rdev
->wiphy
.wowlan
)
1084 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1088 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1089 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1090 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1091 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1092 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1093 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1094 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1095 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1096 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1097 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1098 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1099 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1100 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1101 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1102 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1103 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1106 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1107 struct nl80211_pattern_support pat
= {
1108 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1109 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1110 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1111 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1114 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1119 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1120 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1121 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1124 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1127 nla_nest_end(msg
, nl_wowlan
);
1133 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1134 struct cfg80211_registered_device
*rdev
)
1136 struct nl80211_coalesce_rule_support rule
;
1138 if (!rdev
->wiphy
.coalesce
)
1141 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1142 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1143 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1144 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1145 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1146 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1148 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1154 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1155 struct ieee80211_supported_band
*sband
)
1157 struct nlattr
*nl_rates
, *nl_rate
;
1158 struct ieee80211_rate
*rate
;
1162 if (sband
->ht_cap
.ht_supported
&&
1163 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1164 sizeof(sband
->ht_cap
.mcs
),
1165 &sband
->ht_cap
.mcs
) ||
1166 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1167 sband
->ht_cap
.cap
) ||
1168 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1169 sband
->ht_cap
.ampdu_factor
) ||
1170 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1171 sband
->ht_cap
.ampdu_density
)))
1175 if (sband
->vht_cap
.vht_supported
&&
1176 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1177 sizeof(sband
->vht_cap
.vht_mcs
),
1178 &sband
->vht_cap
.vht_mcs
) ||
1179 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1180 sband
->vht_cap
.cap
)))
1184 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1188 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1189 nl_rate
= nla_nest_start(msg
, i
);
1193 rate
= &sband
->bitrates
[i
];
1194 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1197 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1199 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1202 nla_nest_end(msg
, nl_rate
);
1205 nla_nest_end(msg
, nl_rates
);
1211 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1212 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1215 struct nlattr
*nl_ftypes
, *nl_ifs
;
1216 enum nl80211_iftype ift
;
1222 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1226 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1227 nl_ftypes
= nla_nest_start(msg
, ift
);
1231 stypes
= mgmt_stypes
[ift
].tx
;
1234 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1235 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1240 nla_nest_end(msg
, nl_ftypes
);
1243 nla_nest_end(msg
, nl_ifs
);
1245 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1249 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1250 nl_ftypes
= nla_nest_start(msg
, ift
);
1254 stypes
= mgmt_stypes
[ift
].rx
;
1257 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1258 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1263 nla_nest_end(msg
, nl_ftypes
);
1265 nla_nest_end(msg
, nl_ifs
);
1270 struct nl80211_dump_wiphy_state
{
1273 long split_start
, band_start
, chan_start
, capa_start
;
1277 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1278 enum nl80211_commands cmd
,
1279 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1280 int flags
, struct nl80211_dump_wiphy_state
*state
)
1283 struct nlattr
*nl_bands
, *nl_band
;
1284 struct nlattr
*nl_freqs
, *nl_freq
;
1285 struct nlattr
*nl_cmds
;
1286 enum nl80211_band band
;
1287 struct ieee80211_channel
*chan
;
1289 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1290 rdev
->wiphy
.mgmt_stypes
;
1293 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1297 if (WARN_ON(!state
))
1300 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1301 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1302 wiphy_name(&rdev
->wiphy
)) ||
1303 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1304 cfg80211_rdev_list_generation
))
1305 goto nla_put_failure
;
1307 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1310 switch (state
->split_start
) {
1312 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1313 rdev
->wiphy
.retry_short
) ||
1314 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1315 rdev
->wiphy
.retry_long
) ||
1316 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1317 rdev
->wiphy
.frag_threshold
) ||
1318 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1319 rdev
->wiphy
.rts_threshold
) ||
1320 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1321 rdev
->wiphy
.coverage_class
) ||
1322 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1323 rdev
->wiphy
.max_scan_ssids
) ||
1324 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1325 rdev
->wiphy
.max_sched_scan_ssids
) ||
1326 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1327 rdev
->wiphy
.max_scan_ie_len
) ||
1328 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1329 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1330 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1331 rdev
->wiphy
.max_match_sets
) ||
1332 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1333 rdev
->wiphy
.max_sched_scan_plans
) ||
1334 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1335 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1336 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1337 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1338 goto nla_put_failure
;
1340 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1341 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1342 goto nla_put_failure
;
1343 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1344 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1345 goto nla_put_failure
;
1346 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1347 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1348 goto nla_put_failure
;
1349 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1350 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1351 goto nla_put_failure
;
1352 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1353 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1354 goto nla_put_failure
;
1355 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1356 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1357 goto nla_put_failure
;
1358 state
->split_start
++;
1362 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1363 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1364 rdev
->wiphy
.cipher_suites
))
1365 goto nla_put_failure
;
1367 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1368 rdev
->wiphy
.max_num_pmkids
))
1369 goto nla_put_failure
;
1371 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1372 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1373 goto nla_put_failure
;
1375 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1376 rdev
->wiphy
.available_antennas_tx
) ||
1377 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1378 rdev
->wiphy
.available_antennas_rx
))
1379 goto nla_put_failure
;
1381 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1382 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1383 rdev
->wiphy
.probe_resp_offload
))
1384 goto nla_put_failure
;
1386 if ((rdev
->wiphy
.available_antennas_tx
||
1387 rdev
->wiphy
.available_antennas_rx
) &&
1388 rdev
->ops
->get_antenna
) {
1389 u32 tx_ant
= 0, rx_ant
= 0;
1392 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1394 if (nla_put_u32(msg
,
1395 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1398 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1400 goto nla_put_failure
;
1404 state
->split_start
++;
1408 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1409 rdev
->wiphy
.interface_modes
))
1410 goto nla_put_failure
;
1411 state
->split_start
++;
1415 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1417 goto nla_put_failure
;
1419 for (band
= state
->band_start
;
1420 band
< NUM_NL80211_BANDS
; band
++) {
1421 struct ieee80211_supported_band
*sband
;
1423 sband
= rdev
->wiphy
.bands
[band
];
1428 nl_band
= nla_nest_start(msg
, band
);
1430 goto nla_put_failure
;
1432 switch (state
->chan_start
) {
1434 if (nl80211_send_band_rateinfo(msg
, sband
))
1435 goto nla_put_failure
;
1436 state
->chan_start
++;
1440 /* add frequencies */
1441 nl_freqs
= nla_nest_start(
1442 msg
, NL80211_BAND_ATTR_FREQS
);
1444 goto nla_put_failure
;
1446 for (i
= state
->chan_start
- 1;
1447 i
< sband
->n_channels
;
1449 nl_freq
= nla_nest_start(msg
, i
);
1451 goto nla_put_failure
;
1453 chan
= &sband
->channels
[i
];
1455 if (nl80211_msg_put_channel(
1458 goto nla_put_failure
;
1460 nla_nest_end(msg
, nl_freq
);
1464 if (i
< sband
->n_channels
)
1465 state
->chan_start
= i
+ 2;
1467 state
->chan_start
= 0;
1468 nla_nest_end(msg
, nl_freqs
);
1471 nla_nest_end(msg
, nl_band
);
1474 /* start again here */
1475 if (state
->chan_start
)
1480 nla_nest_end(msg
, nl_bands
);
1482 if (band
< NUM_NL80211_BANDS
)
1483 state
->band_start
= band
+ 1;
1485 state
->band_start
= 0;
1487 /* if bands & channels are done, continue outside */
1488 if (state
->band_start
== 0 && state
->chan_start
== 0)
1489 state
->split_start
++;
1493 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1495 goto nla_put_failure
;
1498 #define CMD(op, n) \
1500 if (rdev->ops->op) { \
1502 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1503 goto nla_put_failure; \
1507 CMD(add_virtual_intf
, NEW_INTERFACE
);
1508 CMD(change_virtual_intf
, SET_INTERFACE
);
1509 CMD(add_key
, NEW_KEY
);
1510 CMD(start_ap
, START_AP
);
1511 CMD(add_station
, NEW_STATION
);
1512 CMD(add_mpath
, NEW_MPATH
);
1513 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1514 CMD(change_bss
, SET_BSS
);
1515 CMD(auth
, AUTHENTICATE
);
1516 CMD(assoc
, ASSOCIATE
);
1517 CMD(deauth
, DEAUTHENTICATE
);
1518 CMD(disassoc
, DISASSOCIATE
);
1519 CMD(join_ibss
, JOIN_IBSS
);
1520 CMD(join_mesh
, JOIN_MESH
);
1521 CMD(set_pmksa
, SET_PMKSA
);
1522 CMD(del_pmksa
, DEL_PMKSA
);
1523 CMD(flush_pmksa
, FLUSH_PMKSA
);
1524 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1525 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1526 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1527 CMD(mgmt_tx
, FRAME
);
1528 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1529 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1531 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1532 goto nla_put_failure
;
1534 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1535 rdev
->ops
->join_mesh
) {
1537 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1538 goto nla_put_failure
;
1540 CMD(set_wds_peer
, SET_WDS_PEER
);
1541 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1542 CMD(tdls_mgmt
, TDLS_MGMT
);
1543 CMD(tdls_oper
, TDLS_OPER
);
1545 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1546 CMD(sched_scan_start
, START_SCHED_SCAN
);
1547 CMD(probe_client
, PROBE_CLIENT
);
1548 CMD(set_noack_map
, SET_NOACK_MAP
);
1549 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1551 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1552 goto nla_put_failure
;
1554 CMD(start_p2p_device
, START_P2P_DEVICE
);
1555 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1556 #ifdef CONFIG_NL80211_TESTMODE
1557 CMD(testmode_cmd
, TESTMODE
);
1560 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1561 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1562 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1563 CMD(channel_switch
, CHANNEL_SWITCH
);
1564 CMD(set_qos_map
, SET_QOS_MAP
);
1565 if (rdev
->wiphy
.features
&
1566 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1567 CMD(add_tx_ts
, ADD_TX_TS
);
1569 /* add into the if now */
1572 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1574 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1575 goto nla_put_failure
;
1578 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1580 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1581 goto nla_put_failure
;
1584 nla_nest_end(msg
, nl_cmds
);
1585 state
->split_start
++;
1589 if (rdev
->ops
->remain_on_channel
&&
1590 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1592 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1593 rdev
->wiphy
.max_remain_on_channel_duration
))
1594 goto nla_put_failure
;
1596 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1597 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1598 goto nla_put_failure
;
1600 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1601 goto nla_put_failure
;
1602 state
->split_start
++;
1607 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1608 goto nla_put_failure
;
1609 state
->split_start
++;
1613 state
->split_start
++;
1616 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1617 rdev
->wiphy
.software_iftypes
))
1618 goto nla_put_failure
;
1620 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1622 goto nla_put_failure
;
1624 state
->split_start
++;
1628 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1629 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1630 rdev
->wiphy
.ap_sme_capa
))
1631 goto nla_put_failure
;
1633 features
= rdev
->wiphy
.features
;
1635 * We can only add the per-channel limit information if the
1636 * dump is split, otherwise it makes it too big. Therefore
1637 * only advertise it in that case.
1640 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1641 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1642 goto nla_put_failure
;
1644 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1645 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1646 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1647 rdev
->wiphy
.ht_capa_mod_mask
))
1648 goto nla_put_failure
;
1650 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1651 rdev
->wiphy
.max_acl_mac_addrs
&&
1652 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1653 rdev
->wiphy
.max_acl_mac_addrs
))
1654 goto nla_put_failure
;
1657 * Any information below this point is only available to
1658 * applications that can deal with it being split. This
1659 * helps ensure that newly added capabilities don't break
1660 * older tools by overrunning their buffers.
1662 * We still increment split_start so that in the split
1663 * case we'll continue with more data in the next round,
1664 * but break unconditionally so unsplit data stops here.
1666 state
->split_start
++;
1669 if (rdev
->wiphy
.extended_capabilities
&&
1670 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1671 rdev
->wiphy
.extended_capabilities_len
,
1672 rdev
->wiphy
.extended_capabilities
) ||
1673 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1674 rdev
->wiphy
.extended_capabilities_len
,
1675 rdev
->wiphy
.extended_capabilities_mask
)))
1676 goto nla_put_failure
;
1678 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1679 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1680 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1681 rdev
->wiphy
.vht_capa_mod_mask
))
1682 goto nla_put_failure
;
1684 state
->split_start
++;
1687 if (nl80211_send_coalesce(msg
, rdev
))
1688 goto nla_put_failure
;
1690 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1691 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1692 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1693 goto nla_put_failure
;
1695 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1696 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1697 rdev
->wiphy
.max_ap_assoc_sta
))
1698 goto nla_put_failure
;
1700 state
->split_start
++;
1703 if (rdev
->wiphy
.n_vendor_commands
) {
1704 const struct nl80211_vendor_cmd_info
*info
;
1705 struct nlattr
*nested
;
1707 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1709 goto nla_put_failure
;
1711 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1712 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1713 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1714 goto nla_put_failure
;
1716 nla_nest_end(msg
, nested
);
1719 if (rdev
->wiphy
.n_vendor_events
) {
1720 const struct nl80211_vendor_cmd_info
*info
;
1721 struct nlattr
*nested
;
1723 nested
= nla_nest_start(msg
,
1724 NL80211_ATTR_VENDOR_EVENTS
);
1726 goto nla_put_failure
;
1728 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1729 info
= &rdev
->wiphy
.vendor_events
[i
];
1730 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1731 goto nla_put_failure
;
1733 nla_nest_end(msg
, nested
);
1735 state
->split_start
++;
1738 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1739 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1740 rdev
->wiphy
.max_num_csa_counters
))
1741 goto nla_put_failure
;
1743 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1744 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1745 goto nla_put_failure
;
1747 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1748 sizeof(rdev
->wiphy
.ext_features
),
1749 rdev
->wiphy
.ext_features
))
1750 goto nla_put_failure
;
1752 if (rdev
->wiphy
.bss_select_support
) {
1753 struct nlattr
*nested
;
1754 u32 bss_select_support
= rdev
->wiphy
.bss_select_support
;
1756 nested
= nla_nest_start(msg
, NL80211_ATTR_BSS_SELECT
);
1758 goto nla_put_failure
;
1761 while (bss_select_support
) {
1762 if ((bss_select_support
& 1) &&
1763 nla_put_flag(msg
, i
))
1764 goto nla_put_failure
;
1766 bss_select_support
>>= 1;
1768 nla_nest_end(msg
, nested
);
1771 state
->split_start
++;
1774 if (rdev
->wiphy
.num_iftype_ext_capab
&&
1775 rdev
->wiphy
.iftype_ext_capab
) {
1776 struct nlattr
*nested_ext_capab
, *nested
;
1778 nested
= nla_nest_start(msg
,
1779 NL80211_ATTR_IFTYPE_EXT_CAPA
);
1781 goto nla_put_failure
;
1783 for (i
= state
->capa_start
;
1784 i
< rdev
->wiphy
.num_iftype_ext_capab
; i
++) {
1785 const struct wiphy_iftype_ext_capab
*capab
;
1787 capab
= &rdev
->wiphy
.iftype_ext_capab
[i
];
1789 nested_ext_capab
= nla_nest_start(msg
, i
);
1790 if (!nested_ext_capab
||
1791 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
,
1793 nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1794 capab
->extended_capabilities_len
,
1795 capab
->extended_capabilities
) ||
1796 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1797 capab
->extended_capabilities_len
,
1798 capab
->extended_capabilities_mask
))
1799 goto nla_put_failure
;
1801 nla_nest_end(msg
, nested_ext_capab
);
1805 nla_nest_end(msg
, nested
);
1806 if (i
< rdev
->wiphy
.num_iftype_ext_capab
) {
1807 state
->capa_start
= i
+ 1;
1813 state
->split_start
= 0;
1817 genlmsg_end(msg
, hdr
);
1821 genlmsg_cancel(msg
, hdr
);
1825 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1826 struct netlink_callback
*cb
,
1827 struct nl80211_dump_wiphy_state
*state
)
1829 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1830 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1831 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1832 /* ignore parse errors for backward compatibility */
1836 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1837 if (tb
[NL80211_ATTR_WIPHY
])
1838 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1839 if (tb
[NL80211_ATTR_WDEV
])
1840 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1841 if (tb
[NL80211_ATTR_IFINDEX
]) {
1842 struct net_device
*netdev
;
1843 struct cfg80211_registered_device
*rdev
;
1844 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1846 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1849 if (netdev
->ieee80211_ptr
) {
1850 rdev
= wiphy_to_rdev(
1851 netdev
->ieee80211_ptr
->wiphy
);
1852 state
->filter_wiphy
= rdev
->wiphy_idx
;
1859 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1862 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1863 struct cfg80211_registered_device
*rdev
;
1867 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1872 state
->filter_wiphy
= -1;
1873 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1879 cb
->args
[0] = (long)state
;
1882 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1883 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1885 if (++idx
<= state
->start
)
1887 if (state
->filter_wiphy
!= -1 &&
1888 state
->filter_wiphy
!= rdev
->wiphy_idx
)
1890 /* attempt to fit multiple wiphy data chunks into the skb */
1892 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
1894 NETLINK_CB(cb
->skb
).portid
,
1896 NLM_F_MULTI
, state
);
1899 * If sending the wiphy data didn't fit (ENOBUFS
1900 * or EMSGSIZE returned), this SKB is still
1901 * empty (so it's not too big because another
1902 * wiphy dataset is already in the skb) and
1903 * we've not tried to adjust the dump allocation
1904 * yet ... then adjust the alloc size to be
1905 * bigger, and return 1 but with the empty skb.
1906 * This results in an empty message being RX'ed
1907 * in userspace, but that is ignored.
1909 * We can then retry with the larger buffer.
1911 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1912 !skb
->len
&& !state
->split
&&
1913 cb
->min_dump_alloc
< 4096) {
1914 cb
->min_dump_alloc
= 4096;
1915 state
->split_start
= 0;
1922 } while (state
->split_start
> 0);
1932 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1934 kfree((void *)cb
->args
[0]);
1938 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1940 struct sk_buff
*msg
;
1941 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1942 struct nl80211_dump_wiphy_state state
= {};
1944 msg
= nlmsg_new(4096, GFP_KERNEL
);
1948 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
1949 info
->snd_portid
, info
->snd_seq
, 0,
1955 return genlmsg_reply(msg
, info
);
1958 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1959 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1960 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1961 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1962 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1963 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1966 static int parse_txq_params(struct nlattr
*tb
[],
1967 struct ieee80211_txq_params
*txq_params
)
1969 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1970 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1971 !tb
[NL80211_TXQ_ATTR_AIFS
])
1974 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1975 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1976 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1977 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1978 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1980 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1986 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1989 * You can only set the channel explicitly for WDS interfaces,
1990 * all others have their channel managed via their respective
1991 * "establish a connection" command (connect, join, ...)
1993 * For AP/GO and mesh mode, the channel can be set with the
1994 * channel userspace API, but is only stored and passed to the
1995 * low-level driver when the AP starts or the mesh is joined.
1996 * This is for backward compatibility, userspace can also give
1997 * the channel in the start-ap or join-mesh commands instead.
1999 * Monitors are special as they are normally slaved to
2000 * whatever else is going on, so they have their own special
2001 * operation to set the monitor channel if possible.
2004 wdev
->iftype
== NL80211_IFTYPE_AP
||
2005 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
2006 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
2007 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
2010 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
2011 struct genl_info
*info
,
2012 struct cfg80211_chan_def
*chandef
)
2016 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
2019 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
2021 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
2022 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
2023 chandef
->center_freq1
= control_freq
;
2024 chandef
->center_freq2
= 0;
2026 /* Primary channel not allowed */
2027 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
2030 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2031 enum nl80211_channel_type chantype
;
2033 chantype
= nla_get_u32(
2034 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2037 case NL80211_CHAN_NO_HT
:
2038 case NL80211_CHAN_HT20
:
2039 case NL80211_CHAN_HT40PLUS
:
2040 case NL80211_CHAN_HT40MINUS
:
2041 cfg80211_chandef_create(chandef
, chandef
->chan
,
2047 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
2049 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
2050 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
2051 chandef
->center_freq1
=
2053 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
2054 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
2055 chandef
->center_freq2
=
2057 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
2060 if (!cfg80211_chandef_valid(chandef
))
2063 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
2064 IEEE80211_CHAN_DISABLED
))
2067 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
2068 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
2069 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
2075 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
2076 struct net_device
*dev
,
2077 struct genl_info
*info
)
2079 struct cfg80211_chan_def chandef
;
2081 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
2082 struct wireless_dev
*wdev
= NULL
;
2085 wdev
= dev
->ieee80211_ptr
;
2086 if (!nl80211_can_set_dev_channel(wdev
))
2089 iftype
= wdev
->iftype
;
2091 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2096 case NL80211_IFTYPE_AP
:
2097 case NL80211_IFTYPE_P2P_GO
:
2098 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2103 if (wdev
->beacon_interval
) {
2104 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2105 !(rdev
->wiphy
.features
&
2106 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2111 /* Only allow dynamic channel width changes */
2112 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2116 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2120 wdev
->preset_chandef
= chandef
;
2123 case NL80211_IFTYPE_MESH_POINT
:
2124 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2126 case NL80211_IFTYPE_MONITOR
:
2127 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2136 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2138 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2139 struct net_device
*netdev
= info
->user_ptr
[1];
2141 return __nl80211_set_channel(rdev
, netdev
, info
);
2144 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2146 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2147 struct net_device
*dev
= info
->user_ptr
[1];
2148 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2151 if (!info
->attrs
[NL80211_ATTR_MAC
])
2154 if (netif_running(dev
))
2157 if (!rdev
->ops
->set_wds_peer
)
2160 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2163 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2164 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2167 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2169 struct cfg80211_registered_device
*rdev
;
2170 struct net_device
*netdev
= NULL
;
2171 struct wireless_dev
*wdev
;
2172 int result
= 0, rem_txq_params
= 0;
2173 struct nlattr
*nl_txq_params
;
2175 u8 retry_short
= 0, retry_long
= 0;
2176 u32 frag_threshold
= 0, rts_threshold
= 0;
2177 u8 coverage_class
= 0;
2182 * Try to find the wiphy and netdev. Normally this
2183 * function shouldn't need the netdev, but this is
2184 * done for backward compatibility -- previously
2185 * setting the channel was done per wiphy, but now
2186 * it is per netdev. Previous userland like hostapd
2187 * also passed a netdev to set_wiphy, so that it is
2188 * possible to let that go to the right netdev!
2191 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2192 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2194 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2195 if (netdev
&& netdev
->ieee80211_ptr
)
2196 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2202 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2205 return PTR_ERR(rdev
);
2210 wdev
= netdev
->ieee80211_ptr
;
2213 * end workaround code, by now the rdev is available
2214 * and locked, and wdev may or may not be NULL.
2217 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2218 result
= cfg80211_dev_rename(
2219 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2224 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2225 struct ieee80211_txq_params txq_params
;
2226 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2228 if (!rdev
->ops
->set_txq_params
)
2234 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2235 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2238 if (!netif_running(netdev
))
2241 nla_for_each_nested(nl_txq_params
,
2242 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2244 result
= nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
2245 nla_data(nl_txq_params
),
2246 nla_len(nl_txq_params
),
2250 result
= parse_txq_params(tb
, &txq_params
);
2254 result
= rdev_set_txq_params(rdev
, netdev
,
2261 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2262 result
= __nl80211_set_channel(
2264 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2270 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2271 struct wireless_dev
*txp_wdev
= wdev
;
2272 enum nl80211_tx_power_setting type
;
2275 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2278 if (!rdev
->ops
->set_tx_power
)
2281 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2282 type
= nla_get_u32(info
->attrs
[idx
]);
2284 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2285 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2288 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2289 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2290 mbm
= nla_get_u32(info
->attrs
[idx
]);
2293 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2298 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2299 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2302 if ((!rdev
->wiphy
.available_antennas_tx
&&
2303 !rdev
->wiphy
.available_antennas_rx
) ||
2304 !rdev
->ops
->set_antenna
)
2307 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2308 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2310 /* reject antenna configurations which don't match the
2311 * available antenna masks, except for the "all" mask */
2312 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2313 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2316 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2317 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2319 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2326 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2327 retry_short
= nla_get_u8(
2328 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2329 if (retry_short
== 0)
2332 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2335 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2336 retry_long
= nla_get_u8(
2337 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2338 if (retry_long
== 0)
2341 changed
|= WIPHY_PARAM_RETRY_LONG
;
2344 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2345 frag_threshold
= nla_get_u32(
2346 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2347 if (frag_threshold
< 256)
2350 if (frag_threshold
!= (u32
) -1) {
2352 * Fragments (apart from the last one) are required to
2353 * have even length. Make the fragmentation code
2354 * simpler by stripping LSB should someone try to use
2355 * odd threshold value.
2357 frag_threshold
&= ~0x1;
2359 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2362 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2363 rts_threshold
= nla_get_u32(
2364 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2365 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2368 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2369 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2372 coverage_class
= nla_get_u8(
2373 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2374 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2377 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2378 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2381 changed
|= WIPHY_PARAM_DYN_ACK
;
2385 u8 old_retry_short
, old_retry_long
;
2386 u32 old_frag_threshold
, old_rts_threshold
;
2387 u8 old_coverage_class
;
2389 if (!rdev
->ops
->set_wiphy_params
)
2392 old_retry_short
= rdev
->wiphy
.retry_short
;
2393 old_retry_long
= rdev
->wiphy
.retry_long
;
2394 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2395 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2396 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2398 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2399 rdev
->wiphy
.retry_short
= retry_short
;
2400 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2401 rdev
->wiphy
.retry_long
= retry_long
;
2402 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2403 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2404 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2405 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2406 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2407 rdev
->wiphy
.coverage_class
= coverage_class
;
2409 result
= rdev_set_wiphy_params(rdev
, changed
);
2411 rdev
->wiphy
.retry_short
= old_retry_short
;
2412 rdev
->wiphy
.retry_long
= old_retry_long
;
2413 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2414 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2415 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2422 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2424 return (u64
)wdev
->identifier
|
2425 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2428 static int nl80211_send_chandef(struct sk_buff
*msg
,
2429 const struct cfg80211_chan_def
*chandef
)
2431 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2434 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2435 chandef
->chan
->center_freq
))
2437 switch (chandef
->width
) {
2438 case NL80211_CHAN_WIDTH_20_NOHT
:
2439 case NL80211_CHAN_WIDTH_20
:
2440 case NL80211_CHAN_WIDTH_40
:
2441 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2442 cfg80211_get_chandef_type(chandef
)))
2448 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2450 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2452 if (chandef
->center_freq2
&&
2453 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2458 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2459 struct cfg80211_registered_device
*rdev
,
2460 struct wireless_dev
*wdev
, bool removal
)
2462 struct net_device
*dev
= wdev
->netdev
;
2463 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2467 cmd
= NL80211_CMD_DEL_INTERFACE
;
2469 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2474 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2475 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2476 goto nla_put_failure
;
2478 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2479 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2480 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
2481 NL80211_ATTR_PAD
) ||
2482 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2483 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2484 rdev
->devlist_generation
^
2485 (cfg80211_rdev_list_generation
<< 2)))
2486 goto nla_put_failure
;
2488 if (rdev
->ops
->get_channel
) {
2490 struct cfg80211_chan_def chandef
;
2492 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2494 if (nl80211_send_chandef(msg
, &chandef
))
2495 goto nla_put_failure
;
2499 if (rdev
->ops
->get_tx_power
) {
2502 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2504 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2506 goto nla_put_failure
;
2509 if (wdev
->ssid_len
) {
2510 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2511 goto nla_put_failure
;
2514 genlmsg_end(msg
, hdr
);
2518 genlmsg_cancel(msg
, hdr
);
2522 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2526 int wp_start
= cb
->args
[0];
2527 int if_start
= cb
->args
[1];
2528 struct cfg80211_registered_device
*rdev
;
2529 struct wireless_dev
*wdev
;
2532 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2533 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2535 if (wp_idx
< wp_start
) {
2541 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
2542 if (if_idx
< if_start
) {
2546 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2547 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2548 rdev
, wdev
, false) < 0) {
2559 cb
->args
[0] = wp_idx
;
2560 cb
->args
[1] = if_idx
;
2565 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2567 struct sk_buff
*msg
;
2568 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2569 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2571 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2575 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2576 rdev
, wdev
, false) < 0) {
2581 return genlmsg_reply(msg
, info
);
2584 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2585 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2586 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2587 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2588 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2589 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2590 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2593 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2595 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2603 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2604 nla
, mntr_flags_policy
))
2607 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2609 *mntrflags
|= (1<<flag
);
2614 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2615 struct net_device
*netdev
, u8 use_4addr
,
2616 enum nl80211_iftype iftype
)
2619 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2625 case NL80211_IFTYPE_AP_VLAN
:
2626 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2629 case NL80211_IFTYPE_STATION
:
2630 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2640 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2642 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2643 struct vif_params params
;
2645 enum nl80211_iftype otype
, ntype
;
2646 struct net_device
*dev
= info
->user_ptr
[1];
2647 u32 _flags
, *flags
= NULL
;
2648 bool change
= false;
2650 memset(¶ms
, 0, sizeof(params
));
2652 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2654 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2655 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2658 if (ntype
> NL80211_IFTYPE_MAX
)
2662 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2663 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2665 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2667 if (netif_running(dev
))
2671 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2672 IEEE80211_MAX_MESH_ID_LEN
);
2673 wdev
->mesh_id_up_len
=
2674 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2675 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2676 wdev
->mesh_id_up_len
);
2680 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2681 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2683 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2687 params
.use_4addr
= -1;
2690 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2691 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2693 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2702 if (info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]) {
2703 const u8
*mumimo_groups
;
2704 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2706 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2710 nla_data(info
->attrs
[NL80211_ATTR_MU_MIMO_GROUP_DATA
]);
2712 /* bits 0 and 63 are reserved and must be zero */
2713 if ((mumimo_groups
[0] & BIT(7)) ||
2714 (mumimo_groups
[VHT_MUMIMO_GROUPS_DATA_LEN
- 1] & BIT(0)))
2717 memcpy(params
.vht_mumimo_groups
, mumimo_groups
,
2718 VHT_MUMIMO_GROUPS_DATA_LEN
);
2722 if (info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
]) {
2723 u32 cap_flag
= NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
;
2725 if (!wiphy_ext_feature_isset(&rdev
->wiphy
, cap_flag
))
2728 nla_memcpy(params
.macaddr
,
2729 info
->attrs
[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR
],
2734 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2735 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2739 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2743 if (!err
&& params
.use_4addr
!= -1)
2744 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2749 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2751 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2752 struct vif_params params
;
2753 struct wireless_dev
*wdev
;
2754 struct sk_buff
*msg
, *event
;
2756 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2759 /* to avoid failing a new interface creation due to pending removal */
2760 cfg80211_destroy_ifaces(rdev
);
2762 memset(¶ms
, 0, sizeof(params
));
2764 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2767 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2768 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2769 if (type
> NL80211_IFTYPE_MAX
)
2773 if (!rdev
->ops
->add_virtual_intf
||
2774 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2777 if ((type
== NL80211_IFTYPE_P2P_DEVICE
||
2778 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
2779 info
->attrs
[NL80211_ATTR_MAC
]) {
2780 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2782 if (!is_valid_ether_addr(params
.macaddr
))
2783 return -EADDRNOTAVAIL
;
2786 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2787 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2788 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2793 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2794 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2797 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2798 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2801 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2805 wdev
= rdev_add_virtual_intf(rdev
,
2806 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2807 NET_NAME_USER
, type
, err
? NULL
: &flags
,
2809 if (WARN_ON(!wdev
)) {
2812 } else if (IS_ERR(wdev
)) {
2814 return PTR_ERR(wdev
);
2817 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
2818 wdev
->owner_nlportid
= info
->snd_portid
;
2821 case NL80211_IFTYPE_MESH_POINT
:
2822 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2825 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2826 IEEE80211_MAX_MESH_ID_LEN
);
2827 wdev
->mesh_id_up_len
=
2828 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2829 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2830 wdev
->mesh_id_up_len
);
2833 case NL80211_IFTYPE_P2P_DEVICE
:
2835 * P2P Device doesn't have a netdev, so doesn't go
2836 * through the netdev notifier and must be added here
2838 mutex_init(&wdev
->mtx
);
2839 INIT_LIST_HEAD(&wdev
->event_list
);
2840 spin_lock_init(&wdev
->event_lock
);
2841 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2842 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2844 wdev
->identifier
= ++rdev
->wdev_id
;
2845 list_add_rcu(&wdev
->list
, &rdev
->wiphy
.wdev_list
);
2846 rdev
->devlist_generation
++;
2852 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2853 rdev
, wdev
, false) < 0) {
2858 event
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2860 if (nl80211_send_iface(event
, 0, 0, 0,
2861 rdev
, wdev
, false) < 0) {
2866 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2867 event
, 0, NL80211_MCGRP_CONFIG
,
2872 return genlmsg_reply(msg
, info
);
2875 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2877 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2878 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2879 struct sk_buff
*msg
;
2882 if (!rdev
->ops
->del_virtual_intf
)
2885 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2886 if (msg
&& nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
, true) < 0) {
2892 * If we remove a wireless device without a netdev then clear
2893 * user_ptr[1] so that nl80211_post_doit won't dereference it
2894 * to check if it needs to do dev_put(). Otherwise it crashes
2895 * since the wdev has been freed, unlike with a netdev where
2896 * we need the dev_put() for the netdev to really be freed.
2899 info
->user_ptr
[1] = NULL
;
2901 status
= rdev_del_virtual_intf(rdev
, wdev
);
2902 if (status
>= 0 && msg
)
2903 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2904 msg
, 0, NL80211_MCGRP_CONFIG
,
2912 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2914 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2915 struct net_device
*dev
= info
->user_ptr
[1];
2918 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2921 if (!rdev
->ops
->set_noack_map
)
2924 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2926 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2929 struct get_key_cookie
{
2930 struct sk_buff
*msg
;
2935 static void get_key_callback(void *c
, struct key_params
*params
)
2938 struct get_key_cookie
*cookie
= c
;
2941 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2942 params
->key_len
, params
->key
)) ||
2944 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2945 params
->seq_len
, params
->seq
)) ||
2947 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2949 goto nla_put_failure
;
2951 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2953 goto nla_put_failure
;
2956 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2957 params
->key_len
, params
->key
)) ||
2959 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2960 params
->seq_len
, params
->seq
)) ||
2962 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2964 goto nla_put_failure
;
2966 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2967 goto nla_put_failure
;
2969 nla_nest_end(cookie
->msg
, key
);
2976 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2978 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2980 struct net_device
*dev
= info
->user_ptr
[1];
2982 const u8
*mac_addr
= NULL
;
2984 struct get_key_cookie cookie
= {
2988 struct sk_buff
*msg
;
2990 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2991 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2996 if (info
->attrs
[NL80211_ATTR_MAC
])
2997 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2999 pairwise
= !!mac_addr
;
3000 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
3001 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
3003 if (kt
>= NUM_NL80211_KEYTYPES
)
3005 if (kt
!= NL80211_KEYTYPE_GROUP
&&
3006 kt
!= NL80211_KEYTYPE_PAIRWISE
)
3008 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
3011 if (!rdev
->ops
->get_key
)
3014 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3017 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3021 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3022 NL80211_CMD_NEW_KEY
);
3024 goto nla_put_failure
;
3027 cookie
.idx
= key_idx
;
3029 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3030 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
3031 goto nla_put_failure
;
3033 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
3034 goto nla_put_failure
;
3036 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
3043 goto nla_put_failure
;
3045 genlmsg_end(msg
, hdr
);
3046 return genlmsg_reply(msg
, info
);
3055 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
3057 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3058 struct key_parse key
;
3060 struct net_device
*dev
= info
->user_ptr
[1];
3062 err
= nl80211_parse_key(info
, &key
);
3069 /* only support setting default key */
3070 if (!key
.def
&& !key
.defmgmt
)
3073 wdev_lock(dev
->ieee80211_ptr
);
3076 if (!rdev
->ops
->set_default_key
) {
3081 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3085 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
3086 key
.def_uni
, key
.def_multi
);
3091 #ifdef CONFIG_CFG80211_WEXT
3092 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
3095 if (key
.def_uni
|| !key
.def_multi
) {
3100 if (!rdev
->ops
->set_default_mgmt_key
) {
3105 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3109 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
3113 #ifdef CONFIG_CFG80211_WEXT
3114 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3119 wdev_unlock(dev
->ieee80211_ptr
);
3124 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3126 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3128 struct net_device
*dev
= info
->user_ptr
[1];
3129 struct key_parse key
;
3130 const u8
*mac_addr
= NULL
;
3132 err
= nl80211_parse_key(info
, &key
);
3139 if (info
->attrs
[NL80211_ATTR_MAC
])
3140 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3142 if (key
.type
== -1) {
3144 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3146 key
.type
= NL80211_KEYTYPE_GROUP
;
3150 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3151 key
.type
!= NL80211_KEYTYPE_GROUP
)
3154 if (!rdev
->ops
->add_key
)
3157 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3158 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3162 wdev_lock(dev
->ieee80211_ptr
);
3163 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3165 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3166 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3168 wdev_unlock(dev
->ieee80211_ptr
);
3173 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3175 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3177 struct net_device
*dev
= info
->user_ptr
[1];
3178 u8
*mac_addr
= NULL
;
3179 struct key_parse key
;
3181 err
= nl80211_parse_key(info
, &key
);
3185 if (info
->attrs
[NL80211_ATTR_MAC
])
3186 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3188 if (key
.type
== -1) {
3190 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3192 key
.type
= NL80211_KEYTYPE_GROUP
;
3196 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3197 key
.type
!= NL80211_KEYTYPE_GROUP
)
3200 if (!rdev
->ops
->del_key
)
3203 wdev_lock(dev
->ieee80211_ptr
);
3204 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3206 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3207 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3211 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3212 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3215 #ifdef CONFIG_CFG80211_WEXT
3217 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3218 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3219 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3220 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3223 wdev_unlock(dev
->ieee80211_ptr
);
3228 /* This function returns an error or the number of nested attributes */
3229 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3231 struct nlattr
*attr
;
3232 int n_entries
= 0, tmp
;
3234 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3235 if (nla_len(attr
) != ETH_ALEN
)
3245 * This function parses ACL information and allocates memory for ACL data.
3246 * On successful return, the calling function is responsible to free the
3247 * ACL buffer returned by this function.
3249 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3250 struct genl_info
*info
)
3252 enum nl80211_acl_policy acl_policy
;
3253 struct nlattr
*attr
;
3254 struct cfg80211_acl_data
*acl
;
3255 int i
= 0, n_entries
, tmp
;
3257 if (!wiphy
->max_acl_mac_addrs
)
3258 return ERR_PTR(-EOPNOTSUPP
);
3260 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3261 return ERR_PTR(-EINVAL
);
3263 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3264 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3265 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3266 return ERR_PTR(-EINVAL
);
3268 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3269 return ERR_PTR(-EINVAL
);
3271 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3273 return ERR_PTR(n_entries
);
3275 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3276 return ERR_PTR(-ENOTSUPP
);
3278 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3281 return ERR_PTR(-ENOMEM
);
3283 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3284 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3288 acl
->n_acl_entries
= n_entries
;
3289 acl
->acl_policy
= acl_policy
;
3294 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3296 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3297 struct net_device
*dev
= info
->user_ptr
[1];
3298 struct cfg80211_acl_data
*acl
;
3301 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3302 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3305 if (!dev
->ieee80211_ptr
->beacon_interval
)
3308 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3310 return PTR_ERR(acl
);
3312 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3319 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3320 struct cfg80211_beacon_data
*bcn
)
3322 bool haveinfo
= false;
3324 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3325 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3326 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3327 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3330 memset(bcn
, 0, sizeof(*bcn
));
3332 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3333 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3334 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3340 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3341 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3342 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3349 if (attrs
[NL80211_ATTR_IE
]) {
3350 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3351 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3354 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3355 bcn
->proberesp_ies
=
3356 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3357 bcn
->proberesp_ies_len
=
3358 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3361 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3362 bcn
->assocresp_ies
=
3363 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3364 bcn
->assocresp_ies_len
=
3365 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3368 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3369 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3370 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3376 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3377 struct cfg80211_ap_settings
*params
)
3379 struct wireless_dev
*wdev
;
3382 list_for_each_entry(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
3383 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3384 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3387 if (!wdev
->preset_chandef
.chan
)
3390 params
->chandef
= wdev
->preset_chandef
;
3398 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3399 enum nl80211_auth_type auth_type
,
3400 enum nl80211_commands cmd
)
3402 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3406 case NL80211_CMD_AUTHENTICATE
:
3407 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3408 auth_type
== NL80211_AUTHTYPE_SAE
)
3411 case NL80211_CMD_CONNECT
:
3412 case NL80211_CMD_START_AP
:
3413 /* SAE not supported yet */
3414 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3422 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3424 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3425 struct net_device
*dev
= info
->user_ptr
[1];
3426 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3427 struct cfg80211_ap_settings params
;
3430 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3431 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3434 if (!rdev
->ops
->start_ap
)
3437 if (wdev
->beacon_interval
)
3440 memset(¶ms
, 0, sizeof(params
));
3442 /* these are required for START_AP */
3443 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3444 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3445 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3448 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3452 params
.beacon_interval
=
3453 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3454 params
.dtim_period
=
3455 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3457 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3462 * In theory, some of these attributes should be required here
3463 * but since they were not used when the command was originally
3464 * added, keep them optional for old user space programs to let
3465 * them continue to work with drivers that do not need the
3466 * additional information -- drivers must check!
3468 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3469 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3471 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3472 if (params
.ssid_len
== 0 ||
3473 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3477 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3478 params
.hidden_ssid
= nla_get_u32(
3479 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3480 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3481 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3482 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3486 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3488 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3489 params
.auth_type
= nla_get_u32(
3490 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3491 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3492 NL80211_CMD_START_AP
))
3495 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3497 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3498 NL80211_MAX_NR_CIPHER_SUITES
);
3502 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3503 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3505 params
.inactivity_timeout
= nla_get_u16(
3506 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3509 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3510 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3512 params
.p2p_ctwindow
=
3513 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3514 if (params
.p2p_ctwindow
> 127)
3516 if (params
.p2p_ctwindow
!= 0 &&
3517 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3521 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3524 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3526 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3529 params
.p2p_opp_ps
= tmp
;
3530 if (params
.p2p_opp_ps
!= 0 &&
3531 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3535 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3536 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3539 } else if (wdev
->preset_chandef
.chan
) {
3540 params
.chandef
= wdev
->preset_chandef
;
3541 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3544 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
3548 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
3550 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
3551 switch (params
.smps_mode
) {
3552 case NL80211_SMPS_OFF
:
3554 case NL80211_SMPS_STATIC
:
3555 if (!(rdev
->wiphy
.features
&
3556 NL80211_FEATURE_STATIC_SMPS
))
3559 case NL80211_SMPS_DYNAMIC
:
3560 if (!(rdev
->wiphy
.features
&
3561 NL80211_FEATURE_DYNAMIC_SMPS
))
3568 params
.smps_mode
= NL80211_SMPS_OFF
;
3571 params
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
3572 if (params
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
])
3575 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3576 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3577 if (IS_ERR(params
.acl
))
3578 return PTR_ERR(params
.acl
);
3582 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3584 wdev
->preset_chandef
= params
.chandef
;
3585 wdev
->beacon_interval
= params
.beacon_interval
;
3586 wdev
->chandef
= params
.chandef
;
3587 wdev
->ssid_len
= params
.ssid_len
;
3588 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3597 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3599 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3600 struct net_device
*dev
= info
->user_ptr
[1];
3601 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3602 struct cfg80211_beacon_data params
;
3605 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3606 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3609 if (!rdev
->ops
->change_beacon
)
3612 if (!wdev
->beacon_interval
)
3615 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3620 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
3626 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3628 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3629 struct net_device
*dev
= info
->user_ptr
[1];
3631 return cfg80211_stop_ap(rdev
, dev
, false);
3634 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3635 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3636 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3637 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3638 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3639 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3640 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3643 static int parse_station_flags(struct genl_info
*info
,
3644 enum nl80211_iftype iftype
,
3645 struct station_parameters
*params
)
3647 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3652 * Try parsing the new attribute first so userspace
3653 * can specify both for older kernels.
3655 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3657 struct nl80211_sta_flag_update
*sta_flags
;
3659 sta_flags
= nla_data(nla
);
3660 params
->sta_flags_mask
= sta_flags
->mask
;
3661 params
->sta_flags_set
= sta_flags
->set
;
3662 params
->sta_flags_set
&= params
->sta_flags_mask
;
3663 if ((params
->sta_flags_mask
|
3664 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3669 /* if present, parse the old attribute */
3671 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3675 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3676 nla
, sta_flags_policy
))
3680 * Only allow certain flags for interface types so that
3681 * other attributes are silently ignored. Remember that
3682 * this is backward compatibility code with old userspace
3683 * and shouldn't be hit in other cases anyway.
3686 case NL80211_IFTYPE_AP
:
3687 case NL80211_IFTYPE_AP_VLAN
:
3688 case NL80211_IFTYPE_P2P_GO
:
3689 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3690 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3691 BIT(NL80211_STA_FLAG_WME
) |
3692 BIT(NL80211_STA_FLAG_MFP
);
3694 case NL80211_IFTYPE_P2P_CLIENT
:
3695 case NL80211_IFTYPE_STATION
:
3696 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3697 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3699 case NL80211_IFTYPE_MESH_POINT
:
3700 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3701 BIT(NL80211_STA_FLAG_MFP
) |
3702 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3707 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3709 params
->sta_flags_set
|= (1<<flag
);
3711 /* no longer support new API additions in old API */
3712 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3720 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3723 struct nlattr
*rate
;
3726 enum nl80211_attrs rate_flg
;
3728 rate
= nla_nest_start(msg
, attr
);
3732 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3733 bitrate
= cfg80211_calculate_bitrate(info
);
3734 /* report 16-bit bitrate only if we can */
3735 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3737 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3739 if (bitrate_compat
> 0 &&
3740 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3744 case RATE_INFO_BW_5
:
3745 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
3747 case RATE_INFO_BW_10
:
3748 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
3753 case RATE_INFO_BW_20
:
3756 case RATE_INFO_BW_40
:
3757 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
3759 case RATE_INFO_BW_80
:
3760 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
3762 case RATE_INFO_BW_160
:
3763 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
3767 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
3770 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3771 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3773 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3774 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3776 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3777 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3779 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3781 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3782 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3786 nla_nest_end(msg
, rate
);
3790 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3799 attr
= nla_nest_start(msg
, id
);
3803 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3804 if (!(mask
& BIT(i
)))
3807 if (nla_put_u8(msg
, i
, signal
[i
]))
3811 nla_nest_end(msg
, attr
);
3816 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
3818 struct cfg80211_registered_device
*rdev
,
3819 struct net_device
*dev
,
3820 const u8
*mac_addr
, struct station_info
*sinfo
)
3823 struct nlattr
*sinfoattr
, *bss_param
;
3825 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
3829 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3830 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3831 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3832 goto nla_put_failure
;
3834 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3836 goto nla_put_failure
;
3838 #define PUT_SINFO(attr, memb, type) do { \
3839 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
3840 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3841 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3843 goto nla_put_failure; \
3845 #define PUT_SINFO_U64(attr, memb) do { \
3846 if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \
3847 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
3848 sinfo->memb, NL80211_STA_INFO_PAD)) \
3849 goto nla_put_failure; \
3852 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
3853 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
3855 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
3856 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
3857 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3858 (u32
)sinfo
->rx_bytes
))
3859 goto nla_put_failure
;
3861 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
3862 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
3863 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3864 (u32
)sinfo
->tx_bytes
))
3865 goto nla_put_failure
;
3867 PUT_SINFO_U64(RX_BYTES64
, rx_bytes
);
3868 PUT_SINFO_U64(TX_BYTES64
, tx_bytes
);
3869 PUT_SINFO(LLID
, llid
, u16
);
3870 PUT_SINFO(PLID
, plid
, u16
);
3871 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
3872 PUT_SINFO_U64(RX_DURATION
, rx_duration
);
3874 switch (rdev
->wiphy
.signal_type
) {
3875 case CFG80211_SIGNAL_TYPE_MBM
:
3876 PUT_SINFO(SIGNAL
, signal
, u8
);
3877 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
3882 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
3883 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3884 sinfo
->chain_signal
,
3885 NL80211_STA_INFO_CHAIN_SIGNAL
))
3886 goto nla_put_failure
;
3888 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
3889 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3890 sinfo
->chain_signal_avg
,
3891 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3892 goto nla_put_failure
;
3894 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
3895 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3896 NL80211_STA_INFO_TX_BITRATE
))
3897 goto nla_put_failure
;
3899 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
3900 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3901 NL80211_STA_INFO_RX_BITRATE
))
3902 goto nla_put_failure
;
3905 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
3906 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
3907 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
3908 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
3909 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
3910 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
3911 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
3912 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
3913 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
3915 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
3916 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3918 goto nla_put_failure
;
3920 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3921 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3922 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3923 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3924 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3925 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3926 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3927 sinfo
->bss_param
.dtim_period
) ||
3928 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3929 sinfo
->bss_param
.beacon_interval
))
3930 goto nla_put_failure
;
3932 nla_nest_end(msg
, bss_param
);
3934 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
3935 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3936 sizeof(struct nl80211_sta_flag_update
),
3938 goto nla_put_failure
;
3940 PUT_SINFO_U64(T_OFFSET
, t_offset
);
3941 PUT_SINFO_U64(RX_DROP_MISC
, rx_dropped_misc
);
3942 PUT_SINFO_U64(BEACON_RX
, rx_beacon
);
3943 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
3946 #undef PUT_SINFO_U64
3948 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TID_STATS
)) {
3949 struct nlattr
*tidsattr
;
3952 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
3954 goto nla_put_failure
;
3956 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
3957 struct cfg80211_tid_stats
*tidstats
;
3958 struct nlattr
*tidattr
;
3960 tidstats
= &sinfo
->pertid
[tid
];
3962 if (!tidstats
->filled
)
3965 tidattr
= nla_nest_start(msg
, tid
+ 1);
3967 goto nla_put_failure
;
3969 #define PUT_TIDVAL_U64(attr, memb) do { \
3970 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3971 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
3972 tidstats->memb, NL80211_TID_STATS_PAD)) \
3973 goto nla_put_failure; \
3976 PUT_TIDVAL_U64(RX_MSDU
, rx_msdu
);
3977 PUT_TIDVAL_U64(TX_MSDU
, tx_msdu
);
3978 PUT_TIDVAL_U64(TX_MSDU_RETRIES
, tx_msdu_retries
);
3979 PUT_TIDVAL_U64(TX_MSDU_FAILED
, tx_msdu_failed
);
3981 #undef PUT_TIDVAL_U64
3982 nla_nest_end(msg
, tidattr
);
3985 nla_nest_end(msg
, tidsattr
);
3988 nla_nest_end(msg
, sinfoattr
);
3990 if (sinfo
->assoc_req_ies_len
&&
3991 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3992 sinfo
->assoc_req_ies
))
3993 goto nla_put_failure
;
3995 genlmsg_end(msg
, hdr
);
3999 genlmsg_cancel(msg
, hdr
);
4003 static int nl80211_dump_station(struct sk_buff
*skb
,
4004 struct netlink_callback
*cb
)
4006 struct station_info sinfo
;
4007 struct cfg80211_registered_device
*rdev
;
4008 struct wireless_dev
*wdev
;
4009 u8 mac_addr
[ETH_ALEN
];
4010 int sta_idx
= cb
->args
[2];
4013 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4017 if (!wdev
->netdev
) {
4022 if (!rdev
->ops
->dump_station
) {
4028 memset(&sinfo
, 0, sizeof(sinfo
));
4029 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
4036 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
4037 NETLINK_CB(cb
->skb
).portid
,
4038 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4039 rdev
, wdev
->netdev
, mac_addr
,
4047 cb
->args
[2] = sta_idx
;
4050 nl80211_finish_wdev_dump(rdev
);
4055 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
4057 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4058 struct net_device
*dev
= info
->user_ptr
[1];
4059 struct station_info sinfo
;
4060 struct sk_buff
*msg
;
4061 u8
*mac_addr
= NULL
;
4064 memset(&sinfo
, 0, sizeof(sinfo
));
4066 if (!info
->attrs
[NL80211_ATTR_MAC
])
4069 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4071 if (!rdev
->ops
->get_station
)
4074 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
4078 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4082 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
4083 info
->snd_portid
, info
->snd_seq
, 0,
4084 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
4089 return genlmsg_reply(msg
, info
);
4092 int cfg80211_check_station_change(struct wiphy
*wiphy
,
4093 struct station_parameters
*params
,
4094 enum cfg80211_station_type statype
)
4096 if (params
->listen_interval
!= -1 &&
4097 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4100 if (params
->support_p2p_ps
!= -1 &&
4101 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4105 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
4106 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
4109 /* When you run into this, adjust the code below for the new flag */
4110 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4113 case CFG80211_STA_MESH_PEER_KERNEL
:
4114 case CFG80211_STA_MESH_PEER_USER
:
4116 * No ignoring the TDLS flag here -- the userspace mesh
4117 * code doesn't have the bug of including TDLS in the
4120 if (params
->sta_flags_mask
&
4121 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4122 BIT(NL80211_STA_FLAG_MFP
) |
4123 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4126 case CFG80211_STA_TDLS_PEER_SETUP
:
4127 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4128 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4130 /* ignore since it can't change */
4131 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4134 /* disallow mesh-specific things */
4135 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4137 if (params
->local_pm
)
4139 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4143 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4144 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4145 /* TDLS can't be set, ... */
4146 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4149 * ... but don't bother the driver with it. This works around
4150 * a hostapd/wpa_supplicant issue -- it always includes the
4151 * TLDS_PEER flag in the mask even for AP mode.
4153 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4156 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4157 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4158 /* reject other things that can't change */
4159 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4161 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4163 if (params
->supported_rates
)
4165 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4169 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4170 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4176 case CFG80211_STA_AP_MLME_CLIENT
:
4177 /* Use this only for authorizing/unauthorizing a station */
4178 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4181 case CFG80211_STA_AP_CLIENT
:
4182 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4183 /* accept only the listed bits */
4184 if (params
->sta_flags_mask
&
4185 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4186 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4187 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4188 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4189 BIT(NL80211_STA_FLAG_WME
) |
4190 BIT(NL80211_STA_FLAG_MFP
)))
4193 /* but authenticated/associated only if driver handles it */
4194 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4195 params
->sta_flags_mask
&
4196 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4197 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4200 case CFG80211_STA_IBSS
:
4201 case CFG80211_STA_AP_STA
:
4202 /* reject any changes other than AUTHORIZED */
4203 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4206 case CFG80211_STA_TDLS_PEER_SETUP
:
4207 /* reject any changes other than AUTHORIZED or WME */
4208 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4209 BIT(NL80211_STA_FLAG_WME
)))
4211 /* force (at least) rates when authorizing */
4212 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4213 !params
->supported_rates
)
4216 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4217 /* reject any changes */
4219 case CFG80211_STA_MESH_PEER_KERNEL
:
4220 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4223 case CFG80211_STA_MESH_PEER_USER
:
4224 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4225 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4232 EXPORT_SYMBOL(cfg80211_check_station_change
);
4235 * Get vlan interface making sure it is running and on the right wiphy.
4237 static struct net_device
*get_vlan(struct genl_info
*info
,
4238 struct cfg80211_registered_device
*rdev
)
4240 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4241 struct net_device
*v
;
4247 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4249 return ERR_PTR(-ENODEV
);
4251 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4256 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4257 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4258 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4263 if (!netif_running(v
)) {
4271 return ERR_PTR(ret
);
4274 static const struct nla_policy
4275 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
4276 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
4277 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
4280 static int nl80211_parse_sta_wme(struct genl_info
*info
,
4281 struct station_parameters
*params
)
4283 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
4287 /* parse WME attributes if present */
4288 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
4291 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
4292 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
4293 nl80211_sta_wme_policy
);
4297 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4298 params
->uapsd_queues
= nla_get_u8(
4299 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4300 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4303 if (tb
[NL80211_STA_WME_MAX_SP
])
4304 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4306 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4309 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4314 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4315 struct station_parameters
*params
)
4317 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4318 params
->supported_channels
=
4319 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4320 params
->supported_channels_len
=
4321 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4323 * Need to include at least one (first channel, number of
4324 * channels) tuple for each subband, and must have proper
4325 * tuples for the rest of the data as well.
4327 if (params
->supported_channels_len
< 2)
4329 if (params
->supported_channels_len
% 2)
4333 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4334 params
->supported_oper_classes
=
4335 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4336 params
->supported_oper_classes_len
=
4337 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4339 * The value of the Length field of the Supported Operating
4340 * Classes element is between 2 and 253.
4342 if (params
->supported_oper_classes_len
< 2 ||
4343 params
->supported_oper_classes_len
> 253)
4349 static int nl80211_set_station_tdls(struct genl_info
*info
,
4350 struct station_parameters
*params
)
4353 /* Dummy STA entry gets updated once the peer capabilities are known */
4354 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4355 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4356 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4358 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4359 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4361 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4363 err
= nl80211_parse_sta_channel_info(info
, params
);
4367 return nl80211_parse_sta_wme(info
, params
);
4370 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4372 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4373 struct net_device
*dev
= info
->user_ptr
[1];
4374 struct station_parameters params
;
4378 memset(¶ms
, 0, sizeof(params
));
4380 if (!rdev
->ops
->change_station
)
4384 * AID and listen_interval properties can be set only for unassociated
4385 * station. Include these parameters here and will check them in
4386 * cfg80211_check_station_change().
4388 if (info
->attrs
[NL80211_ATTR_STA_AID
])
4389 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4391 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4392 params
.listen_interval
=
4393 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4395 params
.listen_interval
= -1;
4397 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
4400 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
4401 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
4404 params
.support_p2p_ps
= tmp
;
4406 params
.support_p2p_ps
= -1;
4409 if (!info
->attrs
[NL80211_ATTR_MAC
])
4412 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4414 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4415 params
.supported_rates
=
4416 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4417 params
.supported_rates_len
=
4418 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4421 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4423 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4424 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4427 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4429 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4430 params
.ext_capab_len
=
4431 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4434 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4437 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4438 params
.plink_action
=
4439 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4440 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4444 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4445 params
.plink_state
=
4446 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4447 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4449 if (info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]) {
4450 params
.peer_aid
= nla_get_u16(
4451 info
->attrs
[NL80211_ATTR_MESH_PEER_AID
]);
4452 if (params
.peer_aid
> IEEE80211_MAX_AID
)
4455 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4458 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4459 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4460 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4462 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4463 pm
> NL80211_MESH_POWER_MAX
)
4466 params
.local_pm
= pm
;
4469 /* Include parameters for TDLS peer (will check later) */
4470 err
= nl80211_set_station_tdls(info
, ¶ms
);
4474 params
.vlan
= get_vlan(info
, rdev
);
4475 if (IS_ERR(params
.vlan
))
4476 return PTR_ERR(params
.vlan
);
4478 switch (dev
->ieee80211_ptr
->iftype
) {
4479 case NL80211_IFTYPE_AP
:
4480 case NL80211_IFTYPE_AP_VLAN
:
4481 case NL80211_IFTYPE_P2P_GO
:
4482 case NL80211_IFTYPE_P2P_CLIENT
:
4483 case NL80211_IFTYPE_STATION
:
4484 case NL80211_IFTYPE_ADHOC
:
4485 case NL80211_IFTYPE_MESH_POINT
:
4492 /* driver will call cfg80211_check_station_change() */
4493 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4497 dev_put(params
.vlan
);
4502 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4504 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4506 struct net_device
*dev
= info
->user_ptr
[1];
4507 struct station_parameters params
;
4508 u8
*mac_addr
= NULL
;
4509 u32 auth_assoc
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4510 BIT(NL80211_STA_FLAG_ASSOCIATED
);
4512 memset(¶ms
, 0, sizeof(params
));
4514 if (!rdev
->ops
->add_station
)
4517 if (!info
->attrs
[NL80211_ATTR_MAC
])
4520 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4523 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4526 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4527 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4530 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4531 params
.supported_rates
=
4532 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4533 params
.supported_rates_len
=
4534 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4535 params
.listen_interval
=
4536 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4538 if (info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]) {
4541 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_STA_SUPPORT_P2P_PS
]);
4542 if (tmp
>= NUM_NL80211_P2P_PS_STATUS
)
4545 params
.support_p2p_ps
= tmp
;
4548 * if not specified, assume it's supported for P2P GO interface,
4549 * and is NOT supported for AP interface
4551 params
.support_p2p_ps
=
4552 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
;
4555 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4556 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4558 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4559 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4562 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4564 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4565 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4568 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4570 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4571 params
.ext_capab_len
=
4572 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4575 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4577 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4579 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4581 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4583 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4584 params
.opmode_notif_used
= true;
4585 params
.opmode_notif
=
4586 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4589 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4590 params
.plink_action
=
4591 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4592 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4596 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
4600 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4604 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4607 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4608 * as userspace might just pass through the capabilities from the IEs
4609 * directly, rather than enforcing this restriction and returning an
4610 * error in this case.
4612 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4613 params
.ht_capa
= NULL
;
4614 params
.vht_capa
= NULL
;
4617 /* When you run into this, adjust the code below for the new flag */
4618 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4620 switch (dev
->ieee80211_ptr
->iftype
) {
4621 case NL80211_IFTYPE_AP
:
4622 case NL80211_IFTYPE_AP_VLAN
:
4623 case NL80211_IFTYPE_P2P_GO
:
4624 /* ignore WME attributes if iface/sta is not capable */
4625 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4626 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4627 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4629 /* TDLS peers cannot be added */
4630 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4631 info
->attrs
[NL80211_ATTR_PEER_AID
])
4633 /* but don't bother the driver with it */
4634 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4636 /* allow authenticated/associated only if driver handles it */
4637 if (!(rdev
->wiphy
.features
&
4638 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4639 params
.sta_flags_mask
& auth_assoc
)
4642 /* Older userspace, or userspace wanting to be compatible with
4643 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4644 * and assoc flags in the mask, but assumes the station will be
4645 * added as associated anyway since this was the required driver
4646 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4648 * In order to not bother drivers with this quirk in the API
4649 * set the flags in both the mask and set for new stations in
4652 if (!(params
.sta_flags_mask
& auth_assoc
)) {
4653 params
.sta_flags_mask
|= auth_assoc
;
4654 params
.sta_flags_set
|= auth_assoc
;
4657 /* must be last in here for error handling */
4658 params
.vlan
= get_vlan(info
, rdev
);
4659 if (IS_ERR(params
.vlan
))
4660 return PTR_ERR(params
.vlan
);
4662 case NL80211_IFTYPE_MESH_POINT
:
4663 /* ignore uAPSD data */
4664 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4666 /* associated is disallowed */
4667 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4669 /* TDLS peers cannot be added */
4670 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4671 info
->attrs
[NL80211_ATTR_PEER_AID
])
4674 case NL80211_IFTYPE_STATION
:
4675 case NL80211_IFTYPE_P2P_CLIENT
:
4676 /* ignore uAPSD data */
4677 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4679 /* these are disallowed */
4680 if (params
.sta_flags_mask
&
4681 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4682 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4684 /* Only TDLS peers can be added */
4685 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4687 /* Can only add if TDLS ... */
4688 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4690 /* ... with external setup is supported */
4691 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4694 * Older wpa_supplicant versions always mark the TDLS peer
4695 * as authorized, but it shouldn't yet be.
4697 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4703 /* be aware of params.vlan when changing code here */
4705 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4708 dev_put(params
.vlan
);
4712 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4714 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4715 struct net_device
*dev
= info
->user_ptr
[1];
4716 struct station_del_parameters params
;
4718 memset(¶ms
, 0, sizeof(params
));
4720 if (info
->attrs
[NL80211_ATTR_MAC
])
4721 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4723 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4724 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4725 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4726 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4729 if (!rdev
->ops
->del_station
)
4732 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
4734 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
4735 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
4736 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
4739 /* Default to Deauthentication frame */
4740 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
4743 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
4744 params
.reason_code
=
4745 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4746 if (params
.reason_code
== 0)
4747 return -EINVAL
; /* 0 is reserved */
4749 /* Default to reason code 2 */
4750 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
4753 return rdev_del_station(rdev
, dev
, ¶ms
);
4756 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4757 int flags
, struct net_device
*dev
,
4758 u8
*dst
, u8
*next_hop
,
4759 struct mpath_info
*pinfo
)
4762 struct nlattr
*pinfoattr
;
4764 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
4768 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4769 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4770 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4771 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4772 goto nla_put_failure
;
4774 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4776 goto nla_put_failure
;
4777 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4778 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4780 goto nla_put_failure
;
4781 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4782 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4783 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4784 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4786 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4787 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4789 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4790 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4792 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4793 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4794 pinfo
->discovery_timeout
)) ||
4795 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4796 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4797 pinfo
->discovery_retries
)))
4798 goto nla_put_failure
;
4800 nla_nest_end(msg
, pinfoattr
);
4802 genlmsg_end(msg
, hdr
);
4806 genlmsg_cancel(msg
, hdr
);
4810 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4811 struct netlink_callback
*cb
)
4813 struct mpath_info pinfo
;
4814 struct cfg80211_registered_device
*rdev
;
4815 struct wireless_dev
*wdev
;
4817 u8 next_hop
[ETH_ALEN
];
4818 int path_idx
= cb
->args
[2];
4821 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4825 if (!rdev
->ops
->dump_mpath
) {
4830 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4836 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
4843 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4844 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4845 wdev
->netdev
, dst
, next_hop
,
4853 cb
->args
[2] = path_idx
;
4856 nl80211_finish_wdev_dump(rdev
);
4860 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4862 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4864 struct net_device
*dev
= info
->user_ptr
[1];
4865 struct mpath_info pinfo
;
4866 struct sk_buff
*msg
;
4868 u8 next_hop
[ETH_ALEN
];
4870 memset(&pinfo
, 0, sizeof(pinfo
));
4872 if (!info
->attrs
[NL80211_ATTR_MAC
])
4875 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4877 if (!rdev
->ops
->get_mpath
)
4880 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4883 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4887 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4891 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4892 dev
, dst
, next_hop
, &pinfo
) < 0) {
4897 return genlmsg_reply(msg
, info
);
4900 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4903 struct net_device
*dev
= info
->user_ptr
[1];
4905 u8
*next_hop
= NULL
;
4907 if (!info
->attrs
[NL80211_ATTR_MAC
])
4910 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4913 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4914 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4916 if (!rdev
->ops
->change_mpath
)
4919 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4922 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4925 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4927 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4928 struct net_device
*dev
= info
->user_ptr
[1];
4930 u8
*next_hop
= NULL
;
4932 if (!info
->attrs
[NL80211_ATTR_MAC
])
4935 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4938 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4939 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4941 if (!rdev
->ops
->add_mpath
)
4944 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4947 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4950 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4952 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4953 struct net_device
*dev
= info
->user_ptr
[1];
4956 if (info
->attrs
[NL80211_ATTR_MAC
])
4957 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4959 if (!rdev
->ops
->del_mpath
)
4962 return rdev_del_mpath(rdev
, dev
, dst
);
4965 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
4967 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4969 struct net_device
*dev
= info
->user_ptr
[1];
4970 struct mpath_info pinfo
;
4971 struct sk_buff
*msg
;
4975 memset(&pinfo
, 0, sizeof(pinfo
));
4977 if (!info
->attrs
[NL80211_ATTR_MAC
])
4980 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4982 if (!rdev
->ops
->get_mpp
)
4985 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4988 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
4992 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4996 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4997 dev
, dst
, mpp
, &pinfo
) < 0) {
5002 return genlmsg_reply(msg
, info
);
5005 static int nl80211_dump_mpp(struct sk_buff
*skb
,
5006 struct netlink_callback
*cb
)
5008 struct mpath_info pinfo
;
5009 struct cfg80211_registered_device
*rdev
;
5010 struct wireless_dev
*wdev
;
5013 int path_idx
= cb
->args
[2];
5016 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5020 if (!rdev
->ops
->dump_mpp
) {
5025 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
5031 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
5038 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
5039 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5040 wdev
->netdev
, dst
, mpp
,
5048 cb
->args
[2] = path_idx
;
5051 nl80211_finish_wdev_dump(rdev
);
5055 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
5057 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5058 struct net_device
*dev
= info
->user_ptr
[1];
5059 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5060 struct bss_parameters params
;
5063 memset(¶ms
, 0, sizeof(params
));
5064 /* default to not changing parameters */
5065 params
.use_cts_prot
= -1;
5066 params
.use_short_preamble
= -1;
5067 params
.use_short_slot_time
= -1;
5068 params
.ap_isolate
= -1;
5069 params
.ht_opmode
= -1;
5070 params
.p2p_ctwindow
= -1;
5071 params
.p2p_opp_ps
= -1;
5073 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
5074 params
.use_cts_prot
=
5075 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
5076 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
5077 params
.use_short_preamble
=
5078 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
5079 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
5080 params
.use_short_slot_time
=
5081 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
5082 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5083 params
.basic_rates
=
5084 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5085 params
.basic_rates_len
=
5086 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5088 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
5089 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
5090 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
5092 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
5094 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
5095 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5097 params
.p2p_ctwindow
=
5098 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
5099 if (params
.p2p_ctwindow
< 0)
5101 if (params
.p2p_ctwindow
!= 0 &&
5102 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
5106 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
5109 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5111 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
5114 params
.p2p_opp_ps
= tmp
;
5115 if (params
.p2p_opp_ps
&&
5116 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
5120 if (!rdev
->ops
->change_bss
)
5123 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5124 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5128 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
5134 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5138 enum nl80211_user_reg_hint_type user_reg_hint_type
;
5142 * You should only get this when cfg80211 hasn't yet initialized
5143 * completely when built-in to the kernel right between the time
5144 * window between nl80211_init() and regulatory_init(), if that is
5147 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
5148 return -EINPROGRESS
;
5150 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
5151 user_reg_hint_type
=
5152 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
5154 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
5156 switch (user_reg_hint_type
) {
5157 case NL80211_USER_REG_HINT_USER
:
5158 case NL80211_USER_REG_HINT_CELL_BASE
:
5159 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5162 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5163 return regulatory_hint_user(data
, user_reg_hint_type
);
5164 case NL80211_USER_REG_HINT_INDOOR
:
5165 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
5166 owner_nlportid
= info
->snd_portid
;
5167 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
5173 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
5179 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
5180 struct genl_info
*info
)
5182 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5183 struct net_device
*dev
= info
->user_ptr
[1];
5184 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5185 struct mesh_config cur_params
;
5188 struct nlattr
*pinfoattr
;
5189 struct sk_buff
*msg
;
5191 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5194 if (!rdev
->ops
->get_mesh_config
)
5198 /* If not connected, get default parameters */
5199 if (!wdev
->mesh_id_len
)
5200 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5202 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5208 /* Draw up a netlink message to send back */
5209 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5212 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5213 NL80211_CMD_GET_MESH_CONFIG
);
5216 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5218 goto nla_put_failure
;
5219 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5220 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5221 cur_params
.dot11MeshRetryTimeout
) ||
5222 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5223 cur_params
.dot11MeshConfirmTimeout
) ||
5224 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5225 cur_params
.dot11MeshHoldingTimeout
) ||
5226 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5227 cur_params
.dot11MeshMaxPeerLinks
) ||
5228 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5229 cur_params
.dot11MeshMaxRetries
) ||
5230 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5231 cur_params
.dot11MeshTTL
) ||
5232 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5233 cur_params
.element_ttl
) ||
5234 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5235 cur_params
.auto_open_plinks
) ||
5236 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5237 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5238 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5239 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5240 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5241 cur_params
.path_refresh_time
) ||
5242 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5243 cur_params
.min_discovery_timeout
) ||
5244 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5245 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5246 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5247 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5248 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5249 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5250 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5251 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5252 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5253 cur_params
.dot11MeshHWMPRootMode
) ||
5254 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5255 cur_params
.dot11MeshHWMPRannInterval
) ||
5256 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5257 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
5258 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
5259 cur_params
.dot11MeshForwarding
) ||
5260 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5261 cur_params
.rssi_threshold
) ||
5262 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
5263 cur_params
.ht_opmode
) ||
5264 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5265 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
5266 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5267 cur_params
.dot11MeshHWMProotInterval
) ||
5268 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5269 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
5270 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
5271 cur_params
.power_mode
) ||
5272 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
5273 cur_params
.dot11MeshAwakeWindowDuration
) ||
5274 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5275 cur_params
.plink_timeout
))
5276 goto nla_put_failure
;
5277 nla_nest_end(msg
, pinfoattr
);
5278 genlmsg_end(msg
, hdr
);
5279 return genlmsg_reply(msg
, info
);
5282 genlmsg_cancel(msg
, hdr
);
5288 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
5289 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
5290 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
5291 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
5292 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
5293 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
5294 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
5295 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
5296 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
5297 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
5298 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
5299 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
5300 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
5301 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
5302 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
5303 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
5304 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
5305 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
5306 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
5307 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
5308 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
5309 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
5310 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
5311 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
5312 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
5313 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
5314 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
5315 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
5316 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
5319 static const struct nla_policy
5320 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
5321 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
5322 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
5323 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
5324 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
5325 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
5326 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
5327 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
5328 .len
= IEEE80211_MAX_DATA_LEN
},
5329 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
5332 static int nl80211_check_bool(const struct nlattr
*nla
, u8 min
, u8 max
, bool *out
)
5334 u8 val
= nla_get_u8(nla
);
5335 if (val
< min
|| val
> max
)
5341 static int nl80211_check_u8(const struct nlattr
*nla
, u8 min
, u8 max
, u8
*out
)
5343 u8 val
= nla_get_u8(nla
);
5344 if (val
< min
|| val
> max
)
5350 static int nl80211_check_u16(const struct nlattr
*nla
, u16 min
, u16 max
, u16
*out
)
5352 u16 val
= nla_get_u16(nla
);
5353 if (val
< min
|| val
> max
)
5359 static int nl80211_check_u32(const struct nlattr
*nla
, u32 min
, u32 max
, u32
*out
)
5361 u32 val
= nla_get_u32(nla
);
5362 if (val
< min
|| val
> max
)
5368 static int nl80211_check_s32(const struct nlattr
*nla
, s32 min
, s32 max
, s32
*out
)
5370 s32 val
= nla_get_s32(nla
);
5371 if (val
< min
|| val
> max
)
5377 static int nl80211_parse_mesh_config(struct genl_info
*info
,
5378 struct mesh_config
*cfg
,
5381 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
5385 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5388 if (fn(tb[attr], min, max, &cfg->param)) \
5390 mask |= (1 << (attr - 1)); \
5394 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
5396 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
5397 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
5398 nl80211_meshconf_params_policy
))
5401 /* This makes sure that there aren't more than 32 mesh config
5402 * parameters (otherwise our bitfield scheme would not work.) */
5403 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
5405 /* Fill in the params struct */
5406 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
5407 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5409 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
5410 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5412 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
5413 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5415 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
5416 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5418 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
5419 mask
, NL80211_MESHCONF_MAX_RETRIES
,
5421 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
5422 mask
, NL80211_MESHCONF_TTL
, nl80211_check_u8
);
5423 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
5424 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
5426 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
5427 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5428 nl80211_check_bool
);
5429 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
5431 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5433 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
5434 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5436 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
5437 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5439 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
5440 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5442 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
5444 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5446 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
5448 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5450 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
5452 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5454 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5455 dot11MeshHWMPnetDiameterTraversalTime
,
5457 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5459 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
5460 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5462 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
5463 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5465 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5466 dot11MeshGateAnnouncementProtocol
, 0, 1,
5467 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5468 nl80211_check_bool
);
5469 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
5470 mask
, NL80211_MESHCONF_FORWARDING
,
5471 nl80211_check_bool
);
5472 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
5473 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5476 * Check HT operation mode based on
5477 * IEEE 802.11 2012 8.4.2.59 HT Operation element.
5479 if (tb
[NL80211_MESHCONF_HT_OPMODE
]) {
5480 ht_opmode
= nla_get_u16(tb
[NL80211_MESHCONF_HT_OPMODE
]);
5482 if (ht_opmode
& ~(IEEE80211_HT_OP_MODE_PROTECTION
|
5483 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
|
5484 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
5487 if ((ht_opmode
& IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
) &&
5488 (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
5491 switch (ht_opmode
& IEEE80211_HT_OP_MODE_PROTECTION
) {
5492 case IEEE80211_HT_OP_MODE_PROTECTION_NONE
:
5493 case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
:
5494 if (ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
)
5497 case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER
:
5498 case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
:
5499 if (!(ht_opmode
& IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT
))
5503 cfg
->ht_opmode
= ht_opmode
;
5505 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
5507 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5509 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
5510 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5512 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5513 dot11MeshHWMPconfirmationInterval
,
5515 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5517 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
5518 NL80211_MESH_POWER_ACTIVE
,
5519 NL80211_MESH_POWER_MAX
,
5520 mask
, NL80211_MESHCONF_POWER_MODE
,
5522 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
5524 NL80211_MESHCONF_AWAKE_WINDOW
, nl80211_check_u16
);
5525 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
5526 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5533 #undef FILL_IN_MESH_PARAM_IF_SET
5536 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
5537 struct mesh_setup
*setup
)
5539 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5540 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
5542 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
5544 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
5545 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
5546 nl80211_mesh_setup_params_policy
))
5549 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
5550 setup
->sync_method
=
5551 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
5552 IEEE80211_SYNC_METHOD_VENDOR
:
5553 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
5555 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
5556 setup
->path_sel_proto
=
5557 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
5558 IEEE80211_PATH_PROTOCOL_VENDOR
:
5559 IEEE80211_PATH_PROTOCOL_HWMP
;
5561 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
5562 setup
->path_metric
=
5563 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
5564 IEEE80211_PATH_METRIC_VENDOR
:
5565 IEEE80211_PATH_METRIC_AIRTIME
;
5567 if (tb
[NL80211_MESH_SETUP_IE
]) {
5568 struct nlattr
*ieattr
=
5569 tb
[NL80211_MESH_SETUP_IE
];
5570 if (!is_valid_ie_attr(ieattr
))
5572 setup
->ie
= nla_data(ieattr
);
5573 setup
->ie_len
= nla_len(ieattr
);
5575 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
5576 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
5578 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
5579 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
5580 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
5581 if (setup
->is_secure
)
5582 setup
->user_mpm
= true;
5584 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
5585 if (!setup
->user_mpm
)
5588 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
5594 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
5595 struct genl_info
*info
)
5597 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5598 struct net_device
*dev
= info
->user_ptr
[1];
5599 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5600 struct mesh_config cfg
;
5604 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5607 if (!rdev
->ops
->update_mesh_config
)
5610 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
5615 if (!wdev
->mesh_id_len
)
5619 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
5626 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
5627 struct sk_buff
*msg
)
5629 struct nlattr
*nl_reg_rules
;
5632 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
5633 (regdom
->dfs_region
&&
5634 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
5635 goto nla_put_failure
;
5637 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
5639 goto nla_put_failure
;
5641 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
5642 struct nlattr
*nl_reg_rule
;
5643 const struct ieee80211_reg_rule
*reg_rule
;
5644 const struct ieee80211_freq_range
*freq_range
;
5645 const struct ieee80211_power_rule
*power_rule
;
5646 unsigned int max_bandwidth_khz
;
5648 reg_rule
= ®dom
->reg_rules
[i
];
5649 freq_range
= ®_rule
->freq_range
;
5650 power_rule
= ®_rule
->power_rule
;
5652 nl_reg_rule
= nla_nest_start(msg
, i
);
5654 goto nla_put_failure
;
5656 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
5657 if (!max_bandwidth_khz
)
5658 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
5661 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
5663 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
5664 freq_range
->start_freq_khz
) ||
5665 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
5666 freq_range
->end_freq_khz
) ||
5667 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
5668 max_bandwidth_khz
) ||
5669 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
5670 power_rule
->max_antenna_gain
) ||
5671 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
5672 power_rule
->max_eirp
) ||
5673 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
5674 reg_rule
->dfs_cac_ms
))
5675 goto nla_put_failure
;
5677 nla_nest_end(msg
, nl_reg_rule
);
5680 nla_nest_end(msg
, nl_reg_rules
);
5687 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
5689 const struct ieee80211_regdomain
*regdom
= NULL
;
5690 struct cfg80211_registered_device
*rdev
;
5691 struct wiphy
*wiphy
= NULL
;
5692 struct sk_buff
*msg
;
5695 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5699 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5700 NL80211_CMD_GET_REG
);
5704 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
5707 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
5710 return PTR_ERR(rdev
);
5713 wiphy
= &rdev
->wiphy
;
5714 self_managed
= wiphy
->regulatory_flags
&
5715 REGULATORY_WIPHY_SELF_MANAGED
;
5716 regdom
= get_wiphy_regdom(wiphy
);
5718 /* a self-managed-reg device must have a private regdom */
5719 if (WARN_ON(!regdom
&& self_managed
)) {
5725 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5726 goto nla_put_failure
;
5729 if (!wiphy
&& reg_last_request_cell_base() &&
5730 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5731 NL80211_USER_REG_HINT_CELL_BASE
))
5732 goto nla_put_failure
;
5737 regdom
= rcu_dereference(cfg80211_regdomain
);
5739 if (nl80211_put_regdom(regdom
, msg
))
5740 goto nla_put_failure_rcu
;
5744 genlmsg_end(msg
, hdr
);
5745 return genlmsg_reply(msg
, info
);
5747 nla_put_failure_rcu
:
5750 genlmsg_cancel(msg
, hdr
);
5756 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5757 u32 seq
, int flags
, struct wiphy
*wiphy
,
5758 const struct ieee80211_regdomain
*regdom
)
5760 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5761 NL80211_CMD_GET_REG
);
5766 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5768 if (nl80211_put_regdom(regdom
, msg
))
5769 goto nla_put_failure
;
5771 if (!wiphy
&& reg_last_request_cell_base() &&
5772 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5773 NL80211_USER_REG_HINT_CELL_BASE
))
5774 goto nla_put_failure
;
5777 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5778 goto nla_put_failure
;
5780 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
5781 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
5782 goto nla_put_failure
;
5784 genlmsg_end(msg
, hdr
);
5788 genlmsg_cancel(msg
, hdr
);
5792 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
5793 struct netlink_callback
*cb
)
5795 const struct ieee80211_regdomain
*regdom
= NULL
;
5796 struct cfg80211_registered_device
*rdev
;
5797 int err
, reg_idx
, start
= cb
->args
[2];
5801 if (cfg80211_regdomain
&& start
== 0) {
5802 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5804 rtnl_dereference(cfg80211_regdomain
));
5809 /* the global regdom is idx 0 */
5811 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
5812 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
5816 if (++reg_idx
<= start
)
5819 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5820 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
5827 cb
->args
[2] = reg_idx
;
5834 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
5835 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
5836 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
5837 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
5838 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
5839 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
5840 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
5841 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
5842 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
5845 static int parse_reg_rule(struct nlattr
*tb
[],
5846 struct ieee80211_reg_rule
*reg_rule
)
5848 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
5849 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
5851 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
5853 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
5855 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
5857 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
5859 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
5862 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
5864 freq_range
->start_freq_khz
=
5865 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
5866 freq_range
->end_freq_khz
=
5867 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
5868 freq_range
->max_bandwidth_khz
=
5869 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
5871 power_rule
->max_eirp
=
5872 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
5874 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
5875 power_rule
->max_antenna_gain
=
5876 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
5878 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
5879 reg_rule
->dfs_cac_ms
=
5880 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
5885 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5887 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5888 struct nlattr
*nl_reg_rule
;
5890 int rem_reg_rules
, r
;
5891 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5892 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
5893 struct ieee80211_regdomain
*rd
;
5895 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5898 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5901 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5903 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5904 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5906 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5909 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5913 if (!reg_is_valid_request(alpha2
))
5916 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5917 num_rules
* sizeof(struct ieee80211_reg_rule
);
5919 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5923 rd
->n_reg_rules
= num_rules
;
5924 rd
->alpha2
[0] = alpha2
[0];
5925 rd
->alpha2
[1] = alpha2
[1];
5928 * Disable DFS master mode if the DFS region was
5929 * not supported or known on this kernel.
5931 if (reg_supported_dfs_region(dfs_region
))
5932 rd
->dfs_region
= dfs_region
;
5934 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5936 r
= nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5937 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5941 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5947 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5953 /* set_regdom takes ownership of rd */
5954 return set_regdom(rd
, REGD_SOURCE_CRDA
);
5959 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
5961 static int validate_scan_freqs(struct nlattr
*freqs
)
5963 struct nlattr
*attr1
, *attr2
;
5964 int n_channels
= 0, tmp1
, tmp2
;
5966 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5969 * Some hardware has a limited channel list for
5970 * scanning, and it is pretty much nonsensical
5971 * to scan for a channel twice, so disallow that
5972 * and don't require drivers to check that the
5973 * channel list they get isn't longer than what
5974 * they can scan, as long as they can scan all
5975 * the channels they registered at once.
5977 nla_for_each_nested(attr2
, freqs
, tmp2
)
5978 if (attr1
!= attr2
&&
5979 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5986 static bool is_band_valid(struct wiphy
*wiphy
, enum nl80211_band b
)
5988 return b
< NUM_NL80211_BANDS
&& wiphy
->bands
[b
];
5991 static int parse_bss_select(struct nlattr
*nla
, struct wiphy
*wiphy
,
5992 struct cfg80211_bss_selection
*bss_select
)
5994 struct nlattr
*attr
[NL80211_BSS_SELECT_ATTR_MAX
+ 1];
5995 struct nlattr
*nest
;
6000 /* only process one nested attribute */
6001 nest
= nla_data(nla
);
6002 if (!nla_ok(nest
, nla_len(nest
)))
6005 err
= nla_parse(attr
, NL80211_BSS_SELECT_ATTR_MAX
, nla_data(nest
),
6006 nla_len(nest
), nl80211_bss_select_policy
);
6010 /* only one attribute may be given */
6011 for (i
= 0; i
<= NL80211_BSS_SELECT_ATTR_MAX
; i
++) {
6019 bss_select
->behaviour
= __NL80211_BSS_SELECT_ATTR_INVALID
;
6021 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI
])
6022 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI
;
6024 if (attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]) {
6025 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_BAND_PREF
;
6026 bss_select
->param
.band_pref
=
6027 nla_get_u32(attr
[NL80211_BSS_SELECT_ATTR_BAND_PREF
]);
6028 if (!is_band_valid(wiphy
, bss_select
->param
.band_pref
))
6032 if (attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]) {
6033 struct nl80211_bss_select_rssi_adjust
*adj_param
;
6035 adj_param
= nla_data(attr
[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
]);
6036 bss_select
->behaviour
= NL80211_BSS_SELECT_ATTR_RSSI_ADJUST
;
6037 bss_select
->param
.adjust
.band
= adj_param
->band
;
6038 bss_select
->param
.adjust
.delta
= adj_param
->delta
;
6039 if (!is_band_valid(wiphy
, bss_select
->param
.adjust
.band
))
6043 /* user-space did not provide behaviour attribute */
6044 if (bss_select
->behaviour
== __NL80211_BSS_SELECT_ATTR_INVALID
)
6047 if (!(wiphy
->bss_select_support
& BIT(bss_select
->behaviour
)))
6053 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
6054 u8
*mac_addr
, u8
*mac_addr_mask
)
6058 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
6059 eth_zero_addr(mac_addr
);
6060 eth_zero_addr(mac_addr_mask
);
6062 mac_addr_mask
[0] = 0x3;
6067 /* need both or none */
6068 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
6071 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
6072 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
6074 /* don't allow or configure an mcast address */
6075 if (!is_multicast_ether_addr(mac_addr_mask
) ||
6076 is_multicast_ether_addr(mac_addr
))
6080 * allow users to pass a MAC address that has bits set outside
6081 * of the mask, but don't bother drivers with having to deal
6084 for (i
= 0; i
< ETH_ALEN
; i
++)
6085 mac_addr
[i
] &= mac_addr_mask
[i
];
6090 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6092 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6093 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6094 struct cfg80211_scan_request
*request
;
6095 struct nlattr
*attr
;
6096 struct wiphy
*wiphy
;
6097 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
6100 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6103 wiphy
= &rdev
->wiphy
;
6105 if (!rdev
->ops
->scan
)
6108 if (rdev
->scan_req
|| rdev
->scan_msg
) {
6113 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6114 n_channels
= validate_scan_freqs(
6115 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6121 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6124 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
6125 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
6128 if (n_ssids
> wiphy
->max_scan_ssids
) {
6133 if (info
->attrs
[NL80211_ATTR_IE
])
6134 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6138 if (ie_len
> wiphy
->max_scan_ie_len
) {
6143 request
= kzalloc(sizeof(*request
)
6144 + sizeof(*request
->ssids
) * n_ssids
6145 + sizeof(*request
->channels
) * n_channels
6146 + ie_len
, GFP_KERNEL
);
6153 request
->ssids
= (void *)&request
->channels
[n_channels
];
6154 request
->n_ssids
= n_ssids
;
6157 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6159 request
->ie
= (void *)(request
->channels
+ n_channels
);
6163 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6164 /* user specified, bail out if channel not found */
6165 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
6166 struct ieee80211_channel
*chan
;
6168 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6175 /* ignore disabled channels */
6176 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6179 request
->channels
[i
] = chan
;
6183 enum nl80211_band band
;
6186 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
6189 if (!wiphy
->bands
[band
])
6191 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6192 struct ieee80211_channel
*chan
;
6194 chan
= &wiphy
->bands
[band
]->channels
[j
];
6196 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6199 request
->channels
[i
] = chan
;
6210 request
->n_channels
= i
;
6214 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
6215 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6219 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6220 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
6225 if (info
->attrs
[NL80211_ATTR_IE
]) {
6226 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6227 memcpy((void *)request
->ie
,
6228 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6232 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
6233 if (wiphy
->bands
[i
])
6235 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
6237 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
6238 nla_for_each_nested(attr
,
6239 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
6241 enum nl80211_band band
= nla_type(attr
);
6243 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
6248 if (!wiphy
->bands
[band
])
6251 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
6254 &request
->rates
[band
]);
6260 if (info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]) {
6261 if (!wiphy_ext_feature_isset(wiphy
,
6262 NL80211_EXT_FEATURE_SET_SCAN_DWELL
)) {
6268 nla_get_u16(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION
]);
6269 request
->duration_mandatory
=
6270 nla_get_flag(info
->attrs
[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY
]);
6273 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
6274 request
->flags
= nla_get_u32(
6275 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6276 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6277 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
6282 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6283 if (!(wiphy
->features
&
6284 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
)) {
6289 if (wdev
->current_bss
) {
6294 err
= nl80211_parse_random_mac(info
->attrs
,
6296 request
->mac_addr_mask
);
6303 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6305 if (info
->attrs
[NL80211_ATTR_MAC
])
6306 memcpy(request
->bssid
, nla_data(info
->attrs
[NL80211_ATTR_MAC
]),
6309 eth_broadcast_addr(request
->bssid
);
6311 request
->wdev
= wdev
;
6312 request
->wiphy
= &rdev
->wiphy
;
6313 request
->scan_start
= jiffies
;
6315 rdev
->scan_req
= request
;
6316 err
= rdev_scan(rdev
, request
);
6319 nl80211_send_scan_start(rdev
, wdev
);
6321 dev_hold(wdev
->netdev
);
6324 rdev
->scan_req
= NULL
;
6332 static int nl80211_abort_scan(struct sk_buff
*skb
, struct genl_info
*info
)
6334 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6335 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6337 if (!rdev
->ops
->abort_scan
)
6343 if (!rdev
->scan_req
)
6346 rdev_abort_scan(rdev
, wdev
);
6351 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
6352 struct cfg80211_sched_scan_request
*request
,
6353 struct nlattr
**attrs
)
6355 int tmp
, err
, i
= 0;
6356 struct nlattr
*attr
;
6358 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6362 * If scan plans are not specified,
6363 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6364 * case one scan plan will be set with the specified scan
6365 * interval and infinite number of iterations.
6367 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6370 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
6374 request
->scan_plans
[0].interval
=
6375 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
6376 if (!request
->scan_plans
[0].interval
)
6379 if (request
->scan_plans
[0].interval
>
6380 wiphy
->max_sched_scan_plan_interval
)
6381 request
->scan_plans
[0].interval
=
6382 wiphy
->max_sched_scan_plan_interval
;
6387 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
6388 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
6390 if (WARN_ON(i
>= n_plans
))
6393 err
= nla_parse(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
6394 nla_data(attr
), nla_len(attr
),
6395 nl80211_plan_policy
);
6399 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
6402 request
->scan_plans
[i
].interval
=
6403 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
6404 if (!request
->scan_plans
[i
].interval
||
6405 request
->scan_plans
[i
].interval
>
6406 wiphy
->max_sched_scan_plan_interval
)
6409 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
6410 request
->scan_plans
[i
].iterations
=
6411 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
6412 if (!request
->scan_plans
[i
].iterations
||
6413 (request
->scan_plans
[i
].iterations
>
6414 wiphy
->max_sched_scan_plan_iterations
))
6416 } else if (i
< n_plans
- 1) {
6418 * All scan plans but the last one must specify
6419 * a finite number of iterations
6428 * The last scan plan must not specify the number of
6429 * iterations, it is supposed to run infinitely
6431 if (request
->scan_plans
[n_plans
- 1].iterations
)
6437 static struct cfg80211_sched_scan_request
*
6438 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6439 struct nlattr
**attrs
)
6441 struct cfg80211_sched_scan_request
*request
;
6442 struct nlattr
*attr
;
6443 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
6444 enum nl80211_band band
;
6446 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
6447 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
6449 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
6450 return ERR_PTR(-EINVAL
);
6452 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6453 n_channels
= validate_scan_freqs(
6454 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6456 return ERR_PTR(-EINVAL
);
6458 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6461 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
6462 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6466 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
6467 return ERR_PTR(-EINVAL
);
6470 * First, count the number of 'real' matchsets. Due to an issue with
6471 * the old implementation, matchsets containing only the RSSI attribute
6472 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6473 * RSSI for all matchsets, rather than their own matchset for reporting
6474 * all APs with a strong RSSI. This is needed to be compatible with
6475 * older userspace that treated a matchset with only the RSSI as the
6476 * global RSSI for all other matchsets - if there are other matchsets.
6478 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6479 nla_for_each_nested(attr
,
6480 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6482 struct nlattr
*rssi
;
6484 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6485 nla_data(attr
), nla_len(attr
),
6486 nl80211_match_policy
);
6488 return ERR_PTR(err
);
6489 /* add other standalone attributes here */
6490 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
]) {
6494 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6496 default_match_rssi
= nla_get_s32(rssi
);
6500 /* However, if there's no other matchset, add the RSSI one */
6501 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
6504 if (n_match_sets
> wiphy
->max_match_sets
)
6505 return ERR_PTR(-EINVAL
);
6507 if (attrs
[NL80211_ATTR_IE
])
6508 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
6512 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
6513 return ERR_PTR(-EINVAL
);
6515 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6517 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6518 * each scan plan already specifies its own interval
6520 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6521 return ERR_PTR(-EINVAL
);
6523 nla_for_each_nested(attr
,
6524 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
6528 * The scan interval attribute is kept for backward
6529 * compatibility. If no scan plans are specified and sched scan
6530 * interval is specified, one scan plan will be set with this
6531 * scan interval and infinite number of iterations.
6533 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6534 return ERR_PTR(-EINVAL
);
6539 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
6540 return ERR_PTR(-EINVAL
);
6542 request
= kzalloc(sizeof(*request
)
6543 + sizeof(*request
->ssids
) * n_ssids
6544 + sizeof(*request
->match_sets
) * n_match_sets
6545 + sizeof(*request
->scan_plans
) * n_plans
6546 + sizeof(*request
->channels
) * n_channels
6547 + ie_len
, GFP_KERNEL
);
6549 return ERR_PTR(-ENOMEM
);
6552 request
->ssids
= (void *)&request
->channels
[n_channels
];
6553 request
->n_ssids
= n_ssids
;
6556 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6558 request
->ie
= (void *)(request
->channels
+ n_channels
);
6563 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
6565 request
->match_sets
=
6566 (void *)(request
->ssids
+ n_ssids
);
6568 request
->match_sets
=
6569 (void *)(request
->channels
+ n_channels
);
6571 request
->n_match_sets
= n_match_sets
;
6574 request
->scan_plans
= (void *)(request
->match_sets
+
6576 else if (request
->ie
)
6577 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
6579 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
6581 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
6583 request
->n_scan_plans
= n_plans
;
6586 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6587 /* user specified, bail out if channel not found */
6588 nla_for_each_nested(attr
,
6589 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
6591 struct ieee80211_channel
*chan
;
6593 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6600 /* ignore disabled channels */
6601 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6604 request
->channels
[i
] = chan
;
6609 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
6612 if (!wiphy
->bands
[band
])
6614 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6615 struct ieee80211_channel
*chan
;
6617 chan
= &wiphy
->bands
[band
]->channels
[j
];
6619 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6622 request
->channels
[i
] = chan
;
6633 request
->n_channels
= i
;
6637 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6639 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6643 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6644 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
6651 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6652 nla_for_each_nested(attr
,
6653 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6655 struct nlattr
*ssid
, *rssi
;
6657 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6658 nla_data(attr
), nla_len(attr
),
6659 nl80211_match_policy
);
6662 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
6664 if (WARN_ON(i
>= n_match_sets
)) {
6665 /* this indicates a programming error,
6666 * the loop above should have verified
6673 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
6677 memcpy(request
->match_sets
[i
].ssid
.ssid
,
6678 nla_data(ssid
), nla_len(ssid
));
6679 request
->match_sets
[i
].ssid
.ssid_len
=
6681 /* special attribute - old implementation w/a */
6682 request
->match_sets
[i
].rssi_thold
=
6684 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6686 request
->match_sets
[i
].rssi_thold
=
6692 /* there was no other matchset, so the RSSI one is alone */
6693 if (i
== 0 && n_match_sets
)
6694 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
6696 request
->min_rssi_thold
= INT_MAX
;
6697 for (i
= 0; i
< n_match_sets
; i
++)
6698 request
->min_rssi_thold
=
6699 min(request
->match_sets
[i
].rssi_thold
,
6700 request
->min_rssi_thold
);
6702 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
6706 request
->ie_len
= ie_len
;
6707 memcpy((void *)request
->ie
,
6708 nla_data(attrs
[NL80211_ATTR_IE
]),
6712 if (attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
6713 request
->flags
= nla_get_u32(
6714 attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6715 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6716 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
6721 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6722 u32 flg
= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
;
6724 if (!wdev
) /* must be net-detect */
6725 flg
= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
6727 if (!(wiphy
->features
& flg
)) {
6732 if (wdev
&& wdev
->current_bss
) {
6737 err
= nl80211_parse_random_mac(attrs
, request
->mac_addr
,
6738 request
->mac_addr_mask
);
6744 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
6746 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
6748 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
6752 request
->scan_start
= jiffies
;
6758 return ERR_PTR(err
);
6761 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
6762 struct genl_info
*info
)
6764 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6765 struct net_device
*dev
= info
->user_ptr
[1];
6766 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6767 struct cfg80211_sched_scan_request
*sched_scan_req
;
6770 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6771 !rdev
->ops
->sched_scan_start
)
6774 if (rdev
->sched_scan_req
)
6775 return -EINPROGRESS
;
6777 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
6780 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
6784 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
6788 sched_scan_req
->dev
= dev
;
6789 sched_scan_req
->wiphy
= &rdev
->wiphy
;
6791 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
6792 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
6794 rcu_assign_pointer(rdev
->sched_scan_req
, sched_scan_req
);
6796 nl80211_send_sched_scan(rdev
, dev
,
6797 NL80211_CMD_START_SCHED_SCAN
);
6801 kfree(sched_scan_req
);
6806 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
6807 struct genl_info
*info
)
6809 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6811 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6812 !rdev
->ops
->sched_scan_stop
)
6815 return __cfg80211_stop_sched_scan(rdev
, false);
6818 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
6819 struct genl_info
*info
)
6821 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6822 struct net_device
*dev
= info
->user_ptr
[1];
6823 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6824 struct cfg80211_chan_def chandef
;
6825 enum nl80211_dfs_regions dfs_region
;
6826 unsigned int cac_time_ms
;
6829 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
6830 if (dfs_region
== NL80211_DFS_UNSET
)
6833 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6837 if (netif_carrier_ok(dev
))
6840 if (wdev
->cac_started
)
6843 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
6851 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
6854 if (!rdev
->ops
->start_radar_detection
)
6857 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
6858 if (WARN_ON(!cac_time_ms
))
6859 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
6861 err
= rdev_start_radar_detection(rdev
, dev
, &chandef
, cac_time_ms
);
6863 wdev
->chandef
= chandef
;
6864 wdev
->cac_started
= true;
6865 wdev
->cac_start_time
= jiffies
;
6866 wdev
->cac_time_ms
= cac_time_ms
;
6871 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
6873 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6874 struct net_device
*dev
= info
->user_ptr
[1];
6875 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6876 struct cfg80211_csa_settings params
;
6877 /* csa_attrs is defined static to avoid waste of stack size - this
6878 * function is called under RTNL lock, so this should not be a problem.
6880 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
6882 bool need_new_beacon
= false;
6886 if (!rdev
->ops
->channel_switch
||
6887 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
6890 switch (dev
->ieee80211_ptr
->iftype
) {
6891 case NL80211_IFTYPE_AP
:
6892 case NL80211_IFTYPE_P2P_GO
:
6893 need_new_beacon
= true;
6895 /* useless if AP is not running */
6896 if (!wdev
->beacon_interval
)
6899 case NL80211_IFTYPE_ADHOC
:
6900 if (!wdev
->ssid_len
)
6903 case NL80211_IFTYPE_MESH_POINT
:
6904 if (!wdev
->mesh_id_len
)
6911 memset(¶ms
, 0, sizeof(params
));
6913 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6914 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
6917 /* only important for AP, IBSS and mesh create IEs internally */
6918 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
6921 /* Even though the attribute is u32, the specification says
6922 * u8, so let's make sure we don't overflow.
6924 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
6928 params
.count
= cs_count
;
6930 if (!need_new_beacon
)
6933 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
6937 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
6938 info
->attrs
[NL80211_ATTR_CSA_IES
],
6943 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
6947 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
6950 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6951 if (!len
|| (len
% sizeof(u16
)))
6954 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
6955 if (rdev
->wiphy
.max_num_csa_counters
&&
6956 (params
.n_counter_offsets_beacon
>
6957 rdev
->wiphy
.max_num_csa_counters
))
6960 params
.counter_offsets_beacon
=
6961 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6963 /* sanity checks - counters should fit and be the same */
6964 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
6965 u16 offset
= params
.counter_offsets_beacon
[i
];
6967 if (offset
>= params
.beacon_csa
.tail_len
)
6970 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
6974 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
6975 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6976 if (!len
|| (len
% sizeof(u16
)))
6979 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
6980 if (rdev
->wiphy
.max_num_csa_counters
&&
6981 (params
.n_counter_offsets_presp
>
6982 rdev
->wiphy
.max_num_csa_counters
))
6985 params
.counter_offsets_presp
=
6986 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6988 /* sanity checks - counters should fit and be the same */
6989 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
6990 u16 offset
= params
.counter_offsets_presp
[i
];
6992 if (offset
>= params
.beacon_csa
.probe_resp_len
)
6995 if (params
.beacon_csa
.probe_resp
[offset
] !=
7002 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
7006 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
7010 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
7017 params
.radar_required
= true;
7019 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
7020 params
.block_tx
= true;
7023 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
7029 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
7031 struct cfg80211_registered_device
*rdev
,
7032 struct wireless_dev
*wdev
,
7033 struct cfg80211_internal_bss
*intbss
)
7035 struct cfg80211_bss
*res
= &intbss
->pub
;
7036 const struct cfg80211_bss_ies
*ies
;
7040 ASSERT_WDEV_LOCK(wdev
);
7042 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
7043 NL80211_CMD_NEW_SCAN_RESULTS
);
7047 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
7049 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
7050 goto nla_put_failure
;
7052 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
7053 goto nla_put_failure
;
7054 if (nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
7056 goto nla_put_failure
;
7058 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
7060 goto nla_put_failure
;
7061 if ((!is_zero_ether_addr(res
->bssid
) &&
7062 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
7063 goto nla_put_failure
;
7066 /* indicate whether we have probe response data or not */
7067 if (rcu_access_pointer(res
->proberesp_ies
) &&
7068 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
7069 goto fail_unlock_rcu
;
7071 /* this pointer prefers to be pointed to probe response data
7072 * but is always valid
7074 ies
= rcu_dereference(res
->ies
);
7076 if (nla_put_u64_64bit(msg
, NL80211_BSS_TSF
, ies
->tsf
,
7078 goto fail_unlock_rcu
;
7079 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
7080 ies
->len
, ies
->data
))
7081 goto fail_unlock_rcu
;
7084 /* and this pointer is always (unless driver didn't know) beacon data */
7085 ies
= rcu_dereference(res
->beacon_ies
);
7086 if (ies
&& ies
->from_beacon
) {
7087 if (nla_put_u64_64bit(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
,
7089 goto fail_unlock_rcu
;
7090 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
7091 ies
->len
, ies
->data
))
7092 goto fail_unlock_rcu
;
7096 if (res
->beacon_interval
&&
7097 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
7098 goto nla_put_failure
;
7099 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
7100 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
7101 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
7102 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
7103 jiffies_to_msecs(jiffies
- intbss
->ts
)))
7104 goto nla_put_failure
;
7106 if (intbss
->parent_tsf
&&
7107 (nla_put_u64_64bit(msg
, NL80211_BSS_PARENT_TSF
,
7108 intbss
->parent_tsf
, NL80211_BSS_PAD
) ||
7109 nla_put(msg
, NL80211_BSS_PARENT_BSSID
, ETH_ALEN
,
7110 intbss
->parent_bssid
)))
7111 goto nla_put_failure
;
7113 if (intbss
->ts_boottime
&&
7114 nla_put_u64_64bit(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
7115 intbss
->ts_boottime
, NL80211_BSS_PAD
))
7116 goto nla_put_failure
;
7118 switch (rdev
->wiphy
.signal_type
) {
7119 case CFG80211_SIGNAL_TYPE_MBM
:
7120 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
7121 goto nla_put_failure
;
7123 case CFG80211_SIGNAL_TYPE_UNSPEC
:
7124 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
7125 goto nla_put_failure
;
7131 switch (wdev
->iftype
) {
7132 case NL80211_IFTYPE_P2P_CLIENT
:
7133 case NL80211_IFTYPE_STATION
:
7134 if (intbss
== wdev
->current_bss
&&
7135 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7136 NL80211_BSS_STATUS_ASSOCIATED
))
7137 goto nla_put_failure
;
7139 case NL80211_IFTYPE_ADHOC
:
7140 if (intbss
== wdev
->current_bss
&&
7141 nla_put_u32(msg
, NL80211_BSS_STATUS
,
7142 NL80211_BSS_STATUS_IBSS_JOINED
))
7143 goto nla_put_failure
;
7149 nla_nest_end(msg
, bss
);
7151 genlmsg_end(msg
, hdr
);
7157 genlmsg_cancel(msg
, hdr
);
7161 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
7163 struct cfg80211_registered_device
*rdev
;
7164 struct cfg80211_internal_bss
*scan
;
7165 struct wireless_dev
*wdev
;
7166 int start
= cb
->args
[2], idx
= 0;
7169 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
7174 spin_lock_bh(&rdev
->bss_lock
);
7175 cfg80211_bss_expire(rdev
);
7177 cb
->seq
= rdev
->bss_generation
;
7179 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
7182 if (nl80211_send_bss(skb
, cb
,
7183 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7184 rdev
, wdev
, scan
) < 0) {
7190 spin_unlock_bh(&rdev
->bss_lock
);
7194 nl80211_finish_wdev_dump(rdev
);
7199 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
7200 int flags
, struct net_device
*dev
,
7201 bool allow_radio_stats
,
7202 struct survey_info
*survey
)
7205 struct nlattr
*infoattr
;
7207 /* skip radio stats if userspace didn't request them */
7208 if (!survey
->channel
&& !allow_radio_stats
)
7211 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
7212 NL80211_CMD_NEW_SURVEY_RESULTS
);
7216 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
7217 goto nla_put_failure
;
7219 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
7221 goto nla_put_failure
;
7223 if (survey
->channel
&&
7224 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
7225 survey
->channel
->center_freq
))
7226 goto nla_put_failure
;
7228 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
7229 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
7230 goto nla_put_failure
;
7231 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
7232 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
7233 goto nla_put_failure
;
7234 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
7235 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME
,
7236 survey
->time
, NL80211_SURVEY_INFO_PAD
))
7237 goto nla_put_failure
;
7238 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
7239 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
7240 survey
->time_busy
, NL80211_SURVEY_INFO_PAD
))
7241 goto nla_put_failure
;
7242 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
7243 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
7244 survey
->time_ext_busy
, NL80211_SURVEY_INFO_PAD
))
7245 goto nla_put_failure
;
7246 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
7247 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_RX
,
7248 survey
->time_rx
, NL80211_SURVEY_INFO_PAD
))
7249 goto nla_put_failure
;
7250 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
7251 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_TX
,
7252 survey
->time_tx
, NL80211_SURVEY_INFO_PAD
))
7253 goto nla_put_failure
;
7254 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
7255 nla_put_u64_64bit(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
7256 survey
->time_scan
, NL80211_SURVEY_INFO_PAD
))
7257 goto nla_put_failure
;
7259 nla_nest_end(msg
, infoattr
);
7261 genlmsg_end(msg
, hdr
);
7265 genlmsg_cancel(msg
, hdr
);
7269 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
7271 struct survey_info survey
;
7272 struct cfg80211_registered_device
*rdev
;
7273 struct wireless_dev
*wdev
;
7274 int survey_idx
= cb
->args
[2];
7278 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
7282 /* prepare_wdev_dump parsed the attributes */
7283 radio_stats
= nl80211_fam
.attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
7285 if (!wdev
->netdev
) {
7290 if (!rdev
->ops
->dump_survey
) {
7296 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
7302 /* don't send disabled channels, but do send non-channel data */
7303 if (survey
.channel
&&
7304 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
7309 if (nl80211_send_survey(skb
,
7310 NETLINK_CB(cb
->skb
).portid
,
7311 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7312 wdev
->netdev
, radio_stats
, &survey
) < 0)
7318 cb
->args
[2] = survey_idx
;
7321 nl80211_finish_wdev_dump(rdev
);
7325 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
7327 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
7328 NL80211_WPA_VERSION_2
));
7331 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
7333 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7334 struct net_device
*dev
= info
->user_ptr
[1];
7335 struct ieee80211_channel
*chan
;
7336 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
7337 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
7338 enum nl80211_auth_type auth_type
;
7339 struct key_parse key
;
7340 bool local_state_change
;
7342 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7345 if (!info
->attrs
[NL80211_ATTR_MAC
])
7348 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
7351 if (!info
->attrs
[NL80211_ATTR_SSID
])
7354 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7357 err
= nl80211_parse_key(info
, &key
);
7362 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
7364 if (!key
.p
.key
|| !key
.p
.key_len
)
7366 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
7367 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
7368 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
7369 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
7382 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
7383 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
7392 if (!rdev
->ops
->auth
)
7395 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7396 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7399 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7400 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7401 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7405 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7406 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7408 if (info
->attrs
[NL80211_ATTR_IE
]) {
7409 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7410 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7413 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7414 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
7417 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
7418 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
7421 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
7422 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
7424 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7425 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7426 /* need to include at least Auth Transaction and Status Code */
7427 if (sae_data_len
< 4)
7431 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7434 * Since we no longer track auth state, ignore
7435 * requests to only change local state.
7437 if (local_state_change
)
7440 wdev_lock(dev
->ieee80211_ptr
);
7441 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
7442 ssid
, ssid_len
, ie
, ie_len
,
7443 key
.p
.key
, key
.p
.key_len
, key
.idx
,
7444 sae_data
, sae_data_len
);
7445 wdev_unlock(dev
->ieee80211_ptr
);
7449 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
7450 struct genl_info
*info
,
7451 struct cfg80211_crypto_settings
*settings
,
7454 memset(settings
, 0, sizeof(*settings
));
7456 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
7458 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
7461 proto
= nla_get_u16(
7462 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
7463 settings
->control_port_ethertype
= cpu_to_be16(proto
);
7464 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
7467 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
7468 settings
->control_port_no_encrypt
= true;
7470 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
7472 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
7476 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7477 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7478 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
7480 if (len
% sizeof(u32
))
7483 if (settings
->n_ciphers_pairwise
> cipher_limit
)
7486 memcpy(settings
->ciphers_pairwise
, data
, len
);
7488 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
7489 if (!cfg80211_supported_cipher_suite(
7491 settings
->ciphers_pairwise
[i
]))
7495 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
7496 settings
->cipher_group
=
7497 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
7498 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
7499 settings
->cipher_group
))
7503 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
7504 settings
->wpa_versions
=
7505 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
7506 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
7510 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
7514 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7515 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7516 settings
->n_akm_suites
= len
/ sizeof(u32
);
7518 if (len
% sizeof(u32
))
7521 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
7524 memcpy(settings
->akm_suites
, data
, len
);
7530 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
7532 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7533 struct net_device
*dev
= info
->user_ptr
[1];
7534 struct ieee80211_channel
*chan
;
7535 struct cfg80211_assoc_request req
= {};
7536 const u8
*bssid
, *ssid
;
7537 int err
, ssid_len
= 0;
7539 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7542 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
7543 !info
->attrs
[NL80211_ATTR_SSID
] ||
7544 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7547 if (!rdev
->ops
->assoc
)
7550 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7551 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7554 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7556 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7557 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7561 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7562 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7564 if (info
->attrs
[NL80211_ATTR_IE
]) {
7565 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7566 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7569 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7570 enum nl80211_mfp mfp
=
7571 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7572 if (mfp
== NL80211_MFP_REQUIRED
)
7574 else if (mfp
!= NL80211_MFP_NO
)
7578 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
7579 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
7581 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7582 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
7584 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7585 memcpy(&req
.ht_capa_mask
,
7586 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7587 sizeof(req
.ht_capa_mask
));
7589 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7590 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7592 memcpy(&req
.ht_capa
,
7593 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7594 sizeof(req
.ht_capa
));
7597 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7598 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7600 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7601 memcpy(&req
.vht_capa_mask
,
7602 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7603 sizeof(req
.vht_capa_mask
));
7605 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7606 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7608 memcpy(&req
.vht_capa
,
7609 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7610 sizeof(req
.vht_capa
));
7613 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7614 if (!((rdev
->wiphy
.features
&
7615 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
7616 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
7617 !wiphy_ext_feature_isset(&rdev
->wiphy
,
7618 NL80211_EXT_FEATURE_RRM
))
7620 req
.flags
|= ASSOC_REQ_USE_RRM
;
7623 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
7625 wdev_lock(dev
->ieee80211_ptr
);
7626 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
7627 ssid
, ssid_len
, &req
);
7628 wdev_unlock(dev
->ieee80211_ptr
);
7634 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
7636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7637 struct net_device
*dev
= info
->user_ptr
[1];
7638 const u8
*ie
= NULL
, *bssid
;
7639 int ie_len
= 0, err
;
7641 bool local_state_change
;
7643 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7646 if (!info
->attrs
[NL80211_ATTR_MAC
])
7649 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7652 if (!rdev
->ops
->deauth
)
7655 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7656 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7659 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7661 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7662 if (reason_code
== 0) {
7663 /* Reason Code 0 is reserved */
7667 if (info
->attrs
[NL80211_ATTR_IE
]) {
7668 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7669 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7672 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7674 wdev_lock(dev
->ieee80211_ptr
);
7675 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7676 local_state_change
);
7677 wdev_unlock(dev
->ieee80211_ptr
);
7681 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
7683 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7684 struct net_device
*dev
= info
->user_ptr
[1];
7685 const u8
*ie
= NULL
, *bssid
;
7686 int ie_len
= 0, err
;
7688 bool local_state_change
;
7690 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7693 if (!info
->attrs
[NL80211_ATTR_MAC
])
7696 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7699 if (!rdev
->ops
->disassoc
)
7702 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7703 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7706 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7708 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7709 if (reason_code
== 0) {
7710 /* Reason Code 0 is reserved */
7714 if (info
->attrs
[NL80211_ATTR_IE
]) {
7715 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7716 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7719 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7721 wdev_lock(dev
->ieee80211_ptr
);
7722 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7723 local_state_change
);
7724 wdev_unlock(dev
->ieee80211_ptr
);
7729 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
7730 int mcast_rate
[NUM_NL80211_BANDS
],
7733 struct wiphy
*wiphy
= &rdev
->wiphy
;
7737 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7738 struct ieee80211_supported_band
*sband
;
7740 sband
= wiphy
->bands
[band
];
7744 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
7745 if (sband
->bitrates
[i
].bitrate
== rateval
) {
7746 mcast_rate
[band
] = i
+ 1;
7756 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7758 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7759 struct net_device
*dev
= info
->user_ptr
[1];
7760 struct cfg80211_ibss_params ibss
;
7761 struct wiphy
*wiphy
;
7762 struct cfg80211_cached_keys
*connkeys
= NULL
;
7765 memset(&ibss
, 0, sizeof(ibss
));
7767 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7770 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7771 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7774 ibss
.beacon_interval
= 100;
7776 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7777 ibss
.beacon_interval
=
7778 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7779 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
7783 if (!rdev
->ops
->join_ibss
)
7786 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7789 wiphy
= &rdev
->wiphy
;
7791 if (info
->attrs
[NL80211_ATTR_MAC
]) {
7792 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7794 if (!is_valid_ether_addr(ibss
.bssid
))
7797 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7798 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7800 if (info
->attrs
[NL80211_ATTR_IE
]) {
7801 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7802 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7805 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
7809 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
7810 NL80211_IFTYPE_ADHOC
))
7813 switch (ibss
.chandef
.width
) {
7814 case NL80211_CHAN_WIDTH_5
:
7815 case NL80211_CHAN_WIDTH_10
:
7816 case NL80211_CHAN_WIDTH_20_NOHT
:
7818 case NL80211_CHAN_WIDTH_20
:
7819 case NL80211_CHAN_WIDTH_40
:
7820 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7823 case NL80211_CHAN_WIDTH_80
:
7824 case NL80211_CHAN_WIDTH_80P80
:
7825 case NL80211_CHAN_WIDTH_160
:
7826 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7828 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
7829 NL80211_EXT_FEATURE_VHT_IBSS
))
7836 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
7837 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
7839 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7841 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7843 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7844 struct ieee80211_supported_band
*sband
=
7845 wiphy
->bands
[ibss
.chandef
.chan
->band
];
7847 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7853 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7854 memcpy(&ibss
.ht_capa_mask
,
7855 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7856 sizeof(ibss
.ht_capa_mask
));
7858 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7859 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7861 memcpy(&ibss
.ht_capa
,
7862 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7863 sizeof(ibss
.ht_capa
));
7866 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7867 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
7868 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7871 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7874 connkeys
= nl80211_parse_connkeys(rdev
,
7875 info
->attrs
[NL80211_ATTR_KEYS
],
7877 if (IS_ERR(connkeys
))
7878 return PTR_ERR(connkeys
);
7880 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
7888 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
7890 ibss
.userspace_handles_dfs
=
7891 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
7893 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
7899 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7901 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7902 struct net_device
*dev
= info
->user_ptr
[1];
7904 if (!rdev
->ops
->leave_ibss
)
7907 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7910 return cfg80211_leave_ibss(rdev
, dev
, false);
7913 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
7915 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7916 struct net_device
*dev
= info
->user_ptr
[1];
7917 int mcast_rate
[NUM_NL80211_BANDS
];
7921 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
7922 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
7923 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
7926 if (!rdev
->ops
->set_mcast_rate
)
7929 memset(mcast_rate
, 0, sizeof(mcast_rate
));
7931 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
7934 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
7935 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
7938 err
= rdev_set_mcast_rate(rdev
, dev
, mcast_rate
);
7943 static struct sk_buff
*
7944 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
7945 struct wireless_dev
*wdev
, int approxlen
,
7946 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
7947 enum nl80211_attrs attr
,
7948 const struct nl80211_vendor_cmd_info
*info
,
7951 struct sk_buff
*skb
;
7953 struct nlattr
*data
;
7955 skb
= nlmsg_new(approxlen
+ 100, gfp
);
7959 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
7965 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
7966 goto nla_put_failure
;
7969 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
7971 goto nla_put_failure
;
7972 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
7974 goto nla_put_failure
;
7978 if (nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
7979 wdev_id(wdev
), NL80211_ATTR_PAD
))
7980 goto nla_put_failure
;
7982 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
7983 wdev
->netdev
->ifindex
))
7984 goto nla_put_failure
;
7987 data
= nla_nest_start(skb
, attr
);
7989 ((void **)skb
->cb
)[0] = rdev
;
7990 ((void **)skb
->cb
)[1] = hdr
;
7991 ((void **)skb
->cb
)[2] = data
;
8000 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
8001 struct wireless_dev
*wdev
,
8002 enum nl80211_commands cmd
,
8003 enum nl80211_attrs attr
,
8004 int vendor_event_idx
,
8005 int approxlen
, gfp_t gfp
)
8007 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
8008 const struct nl80211_vendor_cmd_info
*info
;
8011 case NL80211_CMD_TESTMODE
:
8012 if (WARN_ON(vendor_event_idx
!= -1))
8016 case NL80211_CMD_VENDOR
:
8017 if (WARN_ON(vendor_event_idx
< 0 ||
8018 vendor_event_idx
>= wiphy
->n_vendor_events
))
8020 info
= &wiphy
->vendor_events
[vendor_event_idx
];
8027 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
8028 cmd
, attr
, info
, gfp
);
8030 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
8032 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
8034 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8035 void *hdr
= ((void **)skb
->cb
)[1];
8036 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8037 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
8039 /* clear CB data for netlink core to own from now on */
8040 memset(skb
->cb
, 0, sizeof(skb
->cb
));
8042 nla_nest_end(skb
, data
);
8043 genlmsg_end(skb
, hdr
);
8045 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
8046 mcgrp
= NL80211_MCGRP_VENDOR
;
8048 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
8051 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
8053 #ifdef CONFIG_NL80211_TESTMODE
8054 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
8056 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8057 struct wireless_dev
*wdev
=
8058 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8061 if (!rdev
->ops
->testmode_cmd
)
8065 err
= PTR_ERR(wdev
);
8069 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8073 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
8076 rdev
->cur_cmd_info
= info
;
8077 err
= rdev_testmode_cmd(rdev
, wdev
,
8078 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
8079 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
8080 rdev
->cur_cmd_info
= NULL
;
8085 static int nl80211_testmode_dump(struct sk_buff
*skb
,
8086 struct netlink_callback
*cb
)
8088 struct cfg80211_registered_device
*rdev
;
8098 * 0 is a valid index, but not valid for args[0],
8099 * so we need to offset by 1.
8101 phy_idx
= cb
->args
[0] - 1;
8103 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
8104 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
8109 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
8110 nl80211_fam
.attrbuf
);
8112 err
= PTR_ERR(rdev
);
8115 phy_idx
= rdev
->wiphy_idx
;
8118 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
8120 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
8124 data
= nla_data((void *)cb
->args
[1]);
8125 data_len
= nla_len((void *)cb
->args
[1]);
8128 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
8134 if (!rdev
->ops
->testmode_dump
) {
8140 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
8141 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
8142 NL80211_CMD_TESTMODE
);
8143 struct nlattr
*tmdata
;
8148 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
8149 genlmsg_cancel(skb
, hdr
);
8153 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
8155 genlmsg_cancel(skb
, hdr
);
8158 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
8159 nla_nest_end(skb
, tmdata
);
8161 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
8162 genlmsg_cancel(skb
, hdr
);
8165 genlmsg_cancel(skb
, hdr
);
8169 genlmsg_end(skb
, hdr
);
8174 cb
->args
[0] = phy_idx
+ 1;
8181 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
8183 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8184 struct net_device
*dev
= info
->user_ptr
[1];
8185 struct cfg80211_connect_params connect
;
8186 struct wiphy
*wiphy
;
8187 struct cfg80211_cached_keys
*connkeys
= NULL
;
8190 memset(&connect
, 0, sizeof(connect
));
8192 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8195 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
8196 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
8199 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
8201 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
8202 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
8203 NL80211_CMD_CONNECT
))
8206 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
8208 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
8210 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
8211 NL80211_MAX_NR_CIPHER_SUITES
);
8215 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8216 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8219 wiphy
= &rdev
->wiphy
;
8221 connect
.bg_scan_period
= -1;
8222 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
8223 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
8224 connect
.bg_scan_period
=
8225 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
8228 if (info
->attrs
[NL80211_ATTR_MAC
])
8229 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8230 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
8231 connect
.bssid_hint
=
8232 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
8233 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
8234 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
8236 if (info
->attrs
[NL80211_ATTR_IE
]) {
8237 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8238 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8241 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
8242 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
8243 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
8244 connect
.mfp
!= NL80211_MFP_NO
)
8247 connect
.mfp
= NL80211_MFP_NO
;
8250 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
8251 connect
.prev_bssid
=
8252 nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
8254 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8255 connect
.channel
= nl80211_get_valid_chan(
8256 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
8257 if (!connect
.channel
)
8259 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
8260 connect
.channel_hint
= nl80211_get_valid_chan(
8261 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
8262 if (!connect
.channel_hint
)
8266 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
8267 connkeys
= nl80211_parse_connkeys(rdev
,
8268 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
8269 if (IS_ERR(connkeys
))
8270 return PTR_ERR(connkeys
);
8273 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
8274 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
8276 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
8277 memcpy(&connect
.ht_capa_mask
,
8278 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
8279 sizeof(connect
.ht_capa_mask
));
8281 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
8282 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
8286 memcpy(&connect
.ht_capa
,
8287 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
8288 sizeof(connect
.ht_capa
));
8291 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
8292 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
8294 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
8295 memcpy(&connect
.vht_capa_mask
,
8296 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
8297 sizeof(connect
.vht_capa_mask
));
8299 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
8300 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
8304 memcpy(&connect
.vht_capa
,
8305 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
8306 sizeof(connect
.vht_capa
));
8309 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
8310 if (!((rdev
->wiphy
.features
&
8311 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) &&
8312 (rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) &&
8313 !wiphy_ext_feature_isset(&rdev
->wiphy
,
8314 NL80211_EXT_FEATURE_RRM
)) {
8318 connect
.flags
|= ASSOC_REQ_USE_RRM
;
8321 connect
.pbss
= nla_get_flag(info
->attrs
[NL80211_ATTR_PBSS
]);
8322 if (connect
.pbss
&& !rdev
->wiphy
.bands
[NL80211_BAND_60GHZ
]) {
8327 if (info
->attrs
[NL80211_ATTR_BSS_SELECT
]) {
8328 /* bss selection makes no sense if bssid is set */
8329 if (connect
.bssid
) {
8334 err
= parse_bss_select(info
->attrs
[NL80211_ATTR_BSS_SELECT
],
8335 wiphy
, &connect
.bss_select
);
8342 wdev_lock(dev
->ieee80211_ptr
);
8343 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
,
8344 connect
.prev_bssid
);
8345 wdev_unlock(dev
->ieee80211_ptr
);
8351 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
8353 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8354 struct net_device
*dev
= info
->user_ptr
[1];
8358 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
8359 reason
= WLAN_REASON_DEAUTH_LEAVING
;
8361 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
8366 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8367 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8370 wdev_lock(dev
->ieee80211_ptr
);
8371 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
8372 wdev_unlock(dev
->ieee80211_ptr
);
8376 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
8378 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8382 if (info
->attrs
[NL80211_ATTR_PID
]) {
8383 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
8385 net
= get_net_ns_by_pid(pid
);
8386 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
8387 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
8389 net
= get_net_ns_by_fd(fd
);
8395 return PTR_ERR(net
);
8399 /* check if anything to do */
8400 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
8401 err
= cfg80211_switch_netns(rdev
, net
);
8407 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8409 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8410 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
8411 struct cfg80211_pmksa
*pmksa
) = NULL
;
8412 struct net_device
*dev
= info
->user_ptr
[1];
8413 struct cfg80211_pmksa pmksa
;
8415 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
8417 if (!info
->attrs
[NL80211_ATTR_MAC
])
8420 if (!info
->attrs
[NL80211_ATTR_PMKID
])
8423 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
8424 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8426 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8427 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8430 switch (info
->genlhdr
->cmd
) {
8431 case NL80211_CMD_SET_PMKSA
:
8432 rdev_ops
= rdev
->ops
->set_pmksa
;
8434 case NL80211_CMD_DEL_PMKSA
:
8435 rdev_ops
= rdev
->ops
->del_pmksa
;
8445 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
8448 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8450 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8451 struct net_device
*dev
= info
->user_ptr
[1];
8453 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8454 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8457 if (!rdev
->ops
->flush_pmksa
)
8460 return rdev_flush_pmksa(rdev
, dev
);
8463 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8465 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8466 struct net_device
*dev
= info
->user_ptr
[1];
8467 u8 action_code
, dialog_token
;
8468 u32 peer_capability
= 0;
8473 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8474 !rdev
->ops
->tdls_mgmt
)
8477 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
8478 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
8479 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
8480 !info
->attrs
[NL80211_ATTR_IE
] ||
8481 !info
->attrs
[NL80211_ATTR_MAC
])
8484 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8485 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
8486 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
8487 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
8488 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
8489 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
8491 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
8493 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
8494 dialog_token
, status_code
, peer_capability
,
8496 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
8497 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
8500 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
8502 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8503 struct net_device
*dev
= info
->user_ptr
[1];
8504 enum nl80211_tdls_operation operation
;
8507 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8508 !rdev
->ops
->tdls_oper
)
8511 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
8512 !info
->attrs
[NL80211_ATTR_MAC
])
8515 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
8516 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8518 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
8521 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
8522 struct genl_info
*info
)
8524 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8525 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8526 struct cfg80211_chan_def chandef
;
8527 struct sk_buff
*msg
;
8533 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
8534 !info
->attrs
[NL80211_ATTR_DURATION
])
8537 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8539 if (!rdev
->ops
->remain_on_channel
||
8540 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
8544 * We should be on that channel for at least a minimum amount of
8545 * time (10ms) but no longer than the driver supports.
8547 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8548 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
8551 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8555 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8559 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8560 NL80211_CMD_REMAIN_ON_CHANNEL
);
8566 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
8572 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
8574 goto nla_put_failure
;
8576 genlmsg_end(msg
, hdr
);
8578 return genlmsg_reply(msg
, info
);
8587 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
8588 struct genl_info
*info
)
8590 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8591 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8594 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8597 if (!rdev
->ops
->cancel_remain_on_channel
)
8600 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8602 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
8605 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
8606 u8
*rates
, u8 rates_len
)
8611 for (i
= 0; i
< rates_len
; i
++) {
8612 int rate
= (rates
[i
] & 0x7f) * 5;
8615 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
8616 struct ieee80211_rate
*srate
=
8617 &sband
->bitrates
[ridx
];
8618 if (rate
== srate
->bitrate
) {
8623 if (ridx
== sband
->n_bitrates
)
8624 return 0; /* rate not found */
8630 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
8631 u8
*rates
, u8 rates_len
,
8632 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
8636 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
8638 for (i
= 0; i
< rates_len
; i
++) {
8641 ridx
= rates
[i
] / 8;
8642 rbit
= BIT(rates
[i
] % 8);
8644 /* check validity */
8645 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
8648 /* check availability */
8649 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
8658 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
8662 switch (vht_mcs_map
) {
8663 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
8665 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
8668 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
8671 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
8681 static void vht_build_mcs_mask(u16 vht_mcs_map
,
8682 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
8686 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
8687 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
8692 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
8693 struct nl80211_txrate_vht
*txrate
,
8694 u16 mcs
[NL80211_VHT_NSS_MAX
])
8696 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8697 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
8700 if (!sband
->vht_cap
.vht_supported
)
8703 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
8705 /* Build vht_mcs_mask from VHT capabilities */
8706 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
8708 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
8709 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
8710 mcs
[i
] = txrate
->mcs
[i
];
8718 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
8719 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
8720 .len
= NL80211_MAX_SUPP_RATES
},
8721 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
8722 .len
= NL80211_MAX_SUPP_HT_RATES
},
8723 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
8724 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
8727 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
8728 struct genl_info
*info
)
8730 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
8731 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8732 struct cfg80211_bitrate_mask mask
;
8734 struct net_device
*dev
= info
->user_ptr
[1];
8735 struct nlattr
*tx_rates
;
8736 struct ieee80211_supported_band
*sband
;
8739 if (!rdev
->ops
->set_bitrate_mask
)
8742 memset(&mask
, 0, sizeof(mask
));
8743 /* Default to all rates enabled */
8744 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
8745 sband
= rdev
->wiphy
.bands
[i
];
8750 mask
.control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
8751 memcpy(mask
.control
[i
].ht_mcs
,
8752 sband
->ht_cap
.mcs
.rx_mask
,
8753 sizeof(mask
.control
[i
].ht_mcs
));
8755 if (!sband
->vht_cap
.vht_supported
)
8758 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8759 vht_build_mcs_mask(vht_tx_mcs_map
, mask
.control
[i
].vht_mcs
);
8762 /* if no rates are given set it back to the defaults */
8763 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
8767 * The nested attribute uses enum nl80211_band as the index. This maps
8768 * directly to the enum nl80211_band values used in cfg80211.
8770 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
8771 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
8772 enum nl80211_band band
= nla_type(tx_rates
);
8775 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
8777 sband
= rdev
->wiphy
.bands
[band
];
8780 err
= nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
8781 nla_len(tx_rates
), nl80211_txattr_policy
);
8784 if (tb
[NL80211_TXRATE_LEGACY
]) {
8785 mask
.control
[band
].legacy
= rateset_to_mask(
8787 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
8788 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
8789 if ((mask
.control
[band
].legacy
== 0) &&
8790 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
8793 if (tb
[NL80211_TXRATE_HT
]) {
8794 if (!ht_rateset_to_mask(
8796 nla_data(tb
[NL80211_TXRATE_HT
]),
8797 nla_len(tb
[NL80211_TXRATE_HT
]),
8798 mask
.control
[band
].ht_mcs
))
8801 if (tb
[NL80211_TXRATE_VHT
]) {
8802 if (!vht_set_mcs_mask(
8804 nla_data(tb
[NL80211_TXRATE_VHT
]),
8805 mask
.control
[band
].vht_mcs
))
8808 if (tb
[NL80211_TXRATE_GI
]) {
8809 mask
.control
[band
].gi
=
8810 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
8811 if (mask
.control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
8815 if (mask
.control
[band
].legacy
== 0) {
8816 /* don't allow empty legacy rates if HT or VHT
8817 * are not even supported.
8819 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
8820 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
8823 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
8824 if (mask
.control
[band
].ht_mcs
[i
])
8827 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
8828 if (mask
.control
[band
].vht_mcs
[i
])
8831 /* legacy and mcs rates may not be both empty */
8837 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
8840 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8842 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8843 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8844 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
8846 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
8849 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
8850 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
8852 switch (wdev
->iftype
) {
8853 case NL80211_IFTYPE_STATION
:
8854 case NL80211_IFTYPE_ADHOC
:
8855 case NL80211_IFTYPE_P2P_CLIENT
:
8856 case NL80211_IFTYPE_AP
:
8857 case NL80211_IFTYPE_AP_VLAN
:
8858 case NL80211_IFTYPE_MESH_POINT
:
8859 case NL80211_IFTYPE_P2P_GO
:
8860 case NL80211_IFTYPE_P2P_DEVICE
:
8866 /* not much point in registering if we can't reply */
8867 if (!rdev
->ops
->mgmt_tx
)
8870 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
8871 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
8872 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
8875 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8877 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8878 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8879 struct cfg80211_chan_def chandef
;
8883 struct sk_buff
*msg
= NULL
;
8884 struct cfg80211_mgmt_tx_params params
= {
8885 .dont_wait_for_ack
=
8886 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
8889 if (!info
->attrs
[NL80211_ATTR_FRAME
])
8892 if (!rdev
->ops
->mgmt_tx
)
8895 switch (wdev
->iftype
) {
8896 case NL80211_IFTYPE_P2P_DEVICE
:
8897 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8899 case NL80211_IFTYPE_STATION
:
8900 case NL80211_IFTYPE_ADHOC
:
8901 case NL80211_IFTYPE_P2P_CLIENT
:
8902 case NL80211_IFTYPE_AP
:
8903 case NL80211_IFTYPE_AP_VLAN
:
8904 case NL80211_IFTYPE_MESH_POINT
:
8905 case NL80211_IFTYPE_P2P_GO
:
8911 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
8912 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8914 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8917 * We should wait on the channel for at least a minimum amount
8918 * of time (10ms) but no longer than the driver supports.
8920 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8921 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
8925 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
8927 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8930 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
8932 /* get the channel if any has been specified, otherwise pass NULL to
8933 * the driver. The latter will use the current one
8935 chandef
.chan
= NULL
;
8936 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8937 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8942 if (!chandef
.chan
&& params
.offchan
)
8945 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
8946 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
8948 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
8949 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8952 if (len
% sizeof(u16
))
8955 params
.n_csa_offsets
= len
/ sizeof(u16
);
8956 params
.csa_offsets
=
8957 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8959 /* check that all the offsets fit the frame */
8960 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
8961 if (params
.csa_offsets
[i
] >= params
.len
)
8966 if (!params
.dont_wait_for_ack
) {
8967 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8971 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8979 params
.chan
= chandef
.chan
;
8980 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
8985 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
8987 goto nla_put_failure
;
8989 genlmsg_end(msg
, hdr
);
8990 return genlmsg_reply(msg
, info
);
9002 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
9004 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9005 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9008 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
9011 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
9014 switch (wdev
->iftype
) {
9015 case NL80211_IFTYPE_STATION
:
9016 case NL80211_IFTYPE_ADHOC
:
9017 case NL80211_IFTYPE_P2P_CLIENT
:
9018 case NL80211_IFTYPE_AP
:
9019 case NL80211_IFTYPE_AP_VLAN
:
9020 case NL80211_IFTYPE_P2P_GO
:
9021 case NL80211_IFTYPE_P2P_DEVICE
:
9027 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
9029 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
9032 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9034 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9035 struct wireless_dev
*wdev
;
9036 struct net_device
*dev
= info
->user_ptr
[1];
9041 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
9044 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
9046 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
9049 wdev
= dev
->ieee80211_ptr
;
9051 if (!rdev
->ops
->set_power_mgmt
)
9054 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
9056 if (state
== wdev
->ps
)
9059 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
9065 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
9067 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9068 enum nl80211_ps_state ps_state
;
9069 struct wireless_dev
*wdev
;
9070 struct net_device
*dev
= info
->user_ptr
[1];
9071 struct sk_buff
*msg
;
9075 wdev
= dev
->ieee80211_ptr
;
9077 if (!rdev
->ops
->set_power_mgmt
)
9080 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9084 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9085 NL80211_CMD_GET_POWER_SAVE
);
9092 ps_state
= NL80211_PS_ENABLED
;
9094 ps_state
= NL80211_PS_DISABLED
;
9096 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
9097 goto nla_put_failure
;
9099 genlmsg_end(msg
, hdr
);
9100 return genlmsg_reply(msg
, info
);
9109 static const struct nla_policy
9110 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
9111 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
9112 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
9113 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
9114 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
9115 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
9116 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
9119 static int nl80211_set_cqm_txe(struct genl_info
*info
,
9120 u32 rate
, u32 pkts
, u32 intvl
)
9122 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9123 struct net_device
*dev
= info
->user_ptr
[1];
9124 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9126 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
9129 if (!rdev
->ops
->set_cqm_txe_config
)
9132 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9133 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9136 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
9139 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
9140 s32 threshold
, u32 hysteresis
)
9142 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9143 struct net_device
*dev
= info
->user_ptr
[1];
9144 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9149 /* disabling - hysteresis should also be zero then */
9153 if (!rdev
->ops
->set_cqm_rssi_config
)
9156 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
9157 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
9160 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
9163 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
9165 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
9169 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
9173 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
9174 nl80211_attr_cqm_policy
);
9178 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
9179 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
9180 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
9181 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
9183 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
9186 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
9187 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
9188 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
9189 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
9190 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
9191 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
9193 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
9199 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9201 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9202 struct net_device
*dev
= info
->user_ptr
[1];
9203 struct ocb_setup setup
= {};
9206 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
9210 return cfg80211_join_ocb(rdev
, dev
, &setup
);
9213 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
9215 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9216 struct net_device
*dev
= info
->user_ptr
[1];
9218 return cfg80211_leave_ocb(rdev
, dev
);
9221 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
9223 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9224 struct net_device
*dev
= info
->user_ptr
[1];
9225 struct mesh_config cfg
;
9226 struct mesh_setup setup
;
9229 /* start with default */
9230 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
9231 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
9233 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
9234 /* and parse parameters if given */
9235 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
9240 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
9241 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
9244 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
9245 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
9247 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
9248 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
9249 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
9252 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
9253 setup
.beacon_interval
=
9254 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
9255 if (setup
.beacon_interval
< 10 ||
9256 setup
.beacon_interval
> 10000)
9260 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
9262 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
9263 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
9267 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
9268 /* parse additional setup parameters if given */
9269 err
= nl80211_parse_mesh_setup(info
, &setup
);
9275 cfg
.auto_open_plinks
= false;
9277 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
9278 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
9282 /* cfg80211_join_mesh() will sort it out */
9283 setup
.chandef
.chan
= NULL
;
9286 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
9287 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9289 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
9290 struct ieee80211_supported_band
*sband
;
9292 if (!setup
.chandef
.chan
)
9295 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
9297 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
9298 &setup
.basic_rates
);
9303 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
9306 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
9308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9309 struct net_device
*dev
= info
->user_ptr
[1];
9311 return cfg80211_leave_mesh(rdev
, dev
);
9315 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
9316 struct cfg80211_registered_device
*rdev
)
9318 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
9319 struct nlattr
*nl_pats
, *nl_pat
;
9322 if (!wowlan
->n_patterns
)
9325 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
9329 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
9330 nl_pat
= nla_nest_start(msg
, i
+ 1);
9333 pat_len
= wowlan
->patterns
[i
].pattern_len
;
9334 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
9335 wowlan
->patterns
[i
].mask
) ||
9336 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
9337 wowlan
->patterns
[i
].pattern
) ||
9338 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
9339 wowlan
->patterns
[i
].pkt_offset
))
9341 nla_nest_end(msg
, nl_pat
);
9343 nla_nest_end(msg
, nl_pats
);
9348 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
9349 struct cfg80211_wowlan_tcp
*tcp
)
9351 struct nlattr
*nl_tcp
;
9356 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
9360 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
9361 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
9362 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
9363 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
9364 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
9365 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
9366 tcp
->payload_len
, tcp
->payload
) ||
9367 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
9368 tcp
->data_interval
) ||
9369 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
9370 tcp
->wake_len
, tcp
->wake_data
) ||
9371 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
9372 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
9375 if (tcp
->payload_seq
.len
&&
9376 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
9377 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
9380 if (tcp
->payload_tok
.len
&&
9381 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
9382 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
9386 nla_nest_end(msg
, nl_tcp
);
9391 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
9392 struct cfg80211_sched_scan_request
*req
)
9394 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
9400 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
9404 if (req
->n_scan_plans
== 1 &&
9405 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
9406 req
->scan_plans
[0].interval
* 1000))
9409 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
9412 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9416 for (i
= 0; i
< req
->n_channels
; i
++)
9417 nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
);
9419 nla_nest_end(msg
, freqs
);
9421 if (req
->n_match_sets
) {
9422 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
9423 for (i
= 0; i
< req
->n_match_sets
; i
++) {
9424 match
= nla_nest_start(msg
, i
);
9425 nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
9426 req
->match_sets
[i
].ssid
.ssid_len
,
9427 req
->match_sets
[i
].ssid
.ssid
);
9428 nla_nest_end(msg
, match
);
9430 nla_nest_end(msg
, matches
);
9433 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
9437 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
9438 scan_plan
= nla_nest_start(msg
, i
+ 1);
9440 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
9441 req
->scan_plans
[i
].interval
) ||
9442 (req
->scan_plans
[i
].iterations
&&
9443 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
9444 req
->scan_plans
[i
].iterations
)))
9446 nla_nest_end(msg
, scan_plan
);
9448 nla_nest_end(msg
, scan_plans
);
9450 nla_nest_end(msg
, nd
);
9455 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9457 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9458 struct sk_buff
*msg
;
9460 u32 size
= NLMSG_DEFAULT_SIZE
;
9462 if (!rdev
->wiphy
.wowlan
)
9465 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
9466 /* adjust size to have room for all the data */
9467 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
9468 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
9469 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
9470 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
9473 msg
= nlmsg_new(size
, GFP_KERNEL
);
9477 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9478 NL80211_CMD_GET_WOWLAN
);
9480 goto nla_put_failure
;
9482 if (rdev
->wiphy
.wowlan_config
) {
9483 struct nlattr
*nl_wowlan
;
9485 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
9487 goto nla_put_failure
;
9489 if ((rdev
->wiphy
.wowlan_config
->any
&&
9490 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
9491 (rdev
->wiphy
.wowlan_config
->disconnect
&&
9492 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
9493 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
9494 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
9495 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
9496 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
9497 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
9498 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
9499 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
9500 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
9501 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
9502 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
9503 goto nla_put_failure
;
9505 if (nl80211_send_wowlan_patterns(msg
, rdev
))
9506 goto nla_put_failure
;
9508 if (nl80211_send_wowlan_tcp(msg
,
9509 rdev
->wiphy
.wowlan_config
->tcp
))
9510 goto nla_put_failure
;
9512 if (nl80211_send_wowlan_nd(
9514 rdev
->wiphy
.wowlan_config
->nd_config
))
9515 goto nla_put_failure
;
9517 nla_nest_end(msg
, nl_wowlan
);
9520 genlmsg_end(msg
, hdr
);
9521 return genlmsg_reply(msg
, info
);
9528 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
9529 struct nlattr
*attr
,
9530 struct cfg80211_wowlan
*trig
)
9532 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
9533 struct cfg80211_wowlan_tcp
*cfg
;
9534 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
9535 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
9537 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
9540 if (!rdev
->wiphy
.wowlan
->tcp
)
9543 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
9544 nla_data(attr
), nla_len(attr
),
9545 nl80211_wowlan_tcp_policy
);
9549 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
9550 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
9551 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
9552 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
9553 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
9554 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
9555 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
9556 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
9559 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
9560 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
9563 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
9564 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
9565 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
9568 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
9569 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
9572 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
9573 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
9576 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
9577 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9579 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9580 tokens_size
= tokln
- sizeof(*tok
);
9582 if (!tok
->len
|| tokens_size
% tok
->len
)
9584 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
9586 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
9588 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
9590 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
9592 if (tok
->offset
+ tok
->len
> data_size
)
9596 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
9597 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
9598 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
9600 if (seq
->len
== 0 || seq
->len
> 4)
9602 if (seq
->len
+ seq
->offset
> data_size
)
9606 size
= sizeof(*cfg
);
9608 size
+= wake_size
+ wake_mask_size
;
9609 size
+= tokens_size
;
9611 cfg
= kzalloc(size
, GFP_KERNEL
);
9614 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
9615 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
9616 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
9618 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
9619 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
9623 /* allocate a socket and port for it and use it */
9624 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
9625 IPPROTO_TCP
, &cfg
->sock
, 1);
9630 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
9631 sock_release(cfg
->sock
);
9635 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
9641 cfg
->src_port
= port
;
9644 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
9645 cfg
->payload_len
= data_size
;
9646 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
9647 memcpy((void *)cfg
->payload
,
9648 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
9651 cfg
->payload_seq
= *seq
;
9652 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
9653 cfg
->wake_len
= wake_size
;
9654 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
9655 memcpy((void *)cfg
->wake_data
,
9656 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
9658 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
9659 data_size
+ wake_size
;
9660 memcpy((void *)cfg
->wake_mask
,
9661 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
9664 cfg
->tokens_size
= tokens_size
;
9665 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
9673 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
9674 const struct wiphy_wowlan_support
*wowlan
,
9675 struct nlattr
*attr
,
9676 struct cfg80211_wowlan
*trig
)
9681 tb
= kzalloc(NUM_NL80211_ATTR
* sizeof(*tb
), GFP_KERNEL
);
9685 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
9690 err
= nla_parse(tb
, NL80211_ATTR_MAX
,
9691 nla_data(attr
), nla_len(attr
),
9696 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
);
9697 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
9699 trig
->nd_config
= NULL
;
9706 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9708 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9709 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
9710 struct cfg80211_wowlan new_triggers
= {};
9711 struct cfg80211_wowlan
*ntrig
;
9712 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
9714 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
9715 bool regular
= false;
9720 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
9721 cfg80211_rdev_free_wowlan(rdev
);
9722 rdev
->wiphy
.wowlan_config
= NULL
;
9726 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
9727 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9728 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9729 nl80211_wowlan_policy
);
9733 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
9734 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
9736 new_triggers
.any
= true;
9739 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
9740 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
9742 new_triggers
.disconnect
= true;
9746 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
9747 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
9749 new_triggers
.magic_pkt
= true;
9753 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
9756 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
9757 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
9759 new_triggers
.gtk_rekey_failure
= true;
9763 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
9764 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
9766 new_triggers
.eap_identity_req
= true;
9770 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
9771 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
9773 new_triggers
.four_way_handshake
= true;
9777 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
9778 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
9780 new_triggers
.rfkill_release
= true;
9784 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
9787 int rem
, pat_len
, mask_len
, pkt_offset
;
9788 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9792 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9795 if (n_patterns
> wowlan
->n_patterns
)
9798 new_triggers
.patterns
= kcalloc(n_patterns
,
9799 sizeof(new_triggers
.patterns
[0]),
9801 if (!new_triggers
.patterns
)
9804 new_triggers
.n_patterns
= n_patterns
;
9807 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9811 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
9812 nla_len(pat
), NULL
);
9814 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
9815 !pat_tb
[NL80211_PKTPAT_PATTERN
])
9817 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
9818 mask_len
= DIV_ROUND_UP(pat_len
, 8);
9819 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
9821 if (pat_len
> wowlan
->pattern_max_len
||
9822 pat_len
< wowlan
->pattern_min_len
)
9825 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
9828 pkt_offset
= nla_get_u32(
9829 pat_tb
[NL80211_PKTPAT_OFFSET
]);
9830 if (pkt_offset
> wowlan
->max_pkt_offset
)
9832 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
9834 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
9839 new_triggers
.patterns
[i
].mask
= mask_pat
;
9840 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
9842 mask_pat
+= mask_len
;
9843 new_triggers
.patterns
[i
].pattern
= mask_pat
;
9844 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
9846 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
9852 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
9854 err
= nl80211_parse_wowlan_tcp(
9855 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
9861 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
9863 err
= nl80211_parse_wowlan_nd(
9864 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
9870 /* The 'any' trigger means the device continues operating more or less
9871 * as in its normal operation mode and wakes up the host on most of the
9872 * normal interrupts (like packet RX, ...)
9873 * It therefore makes little sense to combine with the more constrained
9874 * wakeup trigger modes.
9876 if (new_triggers
.any
&& regular
) {
9881 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
9886 cfg80211_rdev_free_wowlan(rdev
);
9887 rdev
->wiphy
.wowlan_config
= ntrig
;
9890 if (rdev
->ops
->set_wakeup
&&
9891 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
9892 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
9896 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
9897 kfree(new_triggers
.patterns
[i
].mask
);
9898 kfree(new_triggers
.patterns
);
9899 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
9900 sock_release(new_triggers
.tcp
->sock
);
9901 kfree(new_triggers
.tcp
);
9902 kfree(new_triggers
.nd_config
);
9907 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
9908 struct cfg80211_registered_device
*rdev
)
9910 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
9912 struct cfg80211_coalesce_rules
*rule
;
9914 if (!rdev
->coalesce
->n_rules
)
9917 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
9921 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
9922 nl_rule
= nla_nest_start(msg
, i
+ 1);
9926 rule
= &rdev
->coalesce
->rules
[i
];
9927 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
9931 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
9935 nl_pats
= nla_nest_start(msg
,
9936 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
9940 for (j
= 0; j
< rule
->n_patterns
; j
++) {
9941 nl_pat
= nla_nest_start(msg
, j
+ 1);
9944 pat_len
= rule
->patterns
[j
].pattern_len
;
9945 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
9946 DIV_ROUND_UP(pat_len
, 8),
9947 rule
->patterns
[j
].mask
) ||
9948 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
9949 rule
->patterns
[j
].pattern
) ||
9950 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
9951 rule
->patterns
[j
].pkt_offset
))
9953 nla_nest_end(msg
, nl_pat
);
9955 nla_nest_end(msg
, nl_pats
);
9956 nla_nest_end(msg
, nl_rule
);
9958 nla_nest_end(msg
, nl_rules
);
9963 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
9965 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9966 struct sk_buff
*msg
;
9969 if (!rdev
->wiphy
.coalesce
)
9972 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9976 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9977 NL80211_CMD_GET_COALESCE
);
9979 goto nla_put_failure
;
9981 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
9982 goto nla_put_failure
;
9984 genlmsg_end(msg
, hdr
);
9985 return genlmsg_reply(msg
, info
);
9992 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
9994 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
9996 struct cfg80211_coalesce_rules
*rule
;
10001 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
10002 rule
= &coalesce
->rules
[i
];
10003 for (j
= 0; j
< rule
->n_patterns
; j
++)
10004 kfree(rule
->patterns
[j
].mask
);
10005 kfree(rule
->patterns
);
10007 kfree(coalesce
->rules
);
10009 rdev
->coalesce
= NULL
;
10012 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
10013 struct nlattr
*rule
,
10014 struct cfg80211_coalesce_rules
*new_rule
)
10017 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10018 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
10019 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
10020 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
10022 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
10023 nla_len(rule
), nl80211_coalesce_policy
);
10027 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
10029 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
10030 if (new_rule
->delay
> coalesce
->max_delay
)
10033 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
10034 new_rule
->condition
=
10035 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
10036 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
10037 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
10040 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
10043 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10046 if (n_patterns
> coalesce
->n_patterns
)
10049 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
10051 if (!new_rule
->patterns
)
10054 new_rule
->n_patterns
= n_patterns
;
10057 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
10061 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
10062 nla_len(pat
), NULL
);
10063 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
10064 !pat_tb
[NL80211_PKTPAT_PATTERN
])
10066 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
10067 mask_len
= DIV_ROUND_UP(pat_len
, 8);
10068 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
10070 if (pat_len
> coalesce
->pattern_max_len
||
10071 pat_len
< coalesce
->pattern_min_len
)
10074 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
10077 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
10078 if (pkt_offset
> coalesce
->max_pkt_offset
)
10080 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
10082 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
10086 new_rule
->patterns
[i
].mask
= mask_pat
;
10087 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
10090 mask_pat
+= mask_len
;
10091 new_rule
->patterns
[i
].pattern
= mask_pat
;
10092 new_rule
->patterns
[i
].pattern_len
= pat_len
;
10093 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
10101 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
10103 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10104 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
10105 struct cfg80211_coalesce new_coalesce
= {};
10106 struct cfg80211_coalesce
*n_coalesce
;
10107 int err
, rem_rule
, n_rules
= 0, i
, j
;
10108 struct nlattr
*rule
;
10109 struct cfg80211_coalesce_rules
*tmp_rule
;
10111 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
10112 return -EOPNOTSUPP
;
10114 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
10115 cfg80211_rdev_free_coalesce(rdev
);
10116 rdev_set_coalesce(rdev
, NULL
);
10120 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10123 if (n_rules
> coalesce
->n_rules
)
10126 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
10128 if (!new_coalesce
.rules
)
10131 new_coalesce
.n_rules
= n_rules
;
10134 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
10136 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
10137 &new_coalesce
.rules
[i
]);
10144 err
= rdev_set_coalesce(rdev
, &new_coalesce
);
10148 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
10153 cfg80211_rdev_free_coalesce(rdev
);
10154 rdev
->coalesce
= n_coalesce
;
10158 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
10159 tmp_rule
= &new_coalesce
.rules
[i
];
10160 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
10161 kfree(tmp_rule
->patterns
[j
].mask
);
10162 kfree(tmp_rule
->patterns
);
10164 kfree(new_coalesce
.rules
);
10169 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
10171 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10172 struct net_device
*dev
= info
->user_ptr
[1];
10173 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10174 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
10175 struct cfg80211_gtk_rekey_data rekey_data
;
10178 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
10181 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
10182 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
10183 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
10184 nl80211_rekey_policy
);
10188 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
10190 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
10192 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
10195 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
10196 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
10197 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
10200 if (!wdev
->current_bss
) {
10205 if (!rdev
->ops
->set_rekey_data
) {
10210 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
10216 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
10217 struct genl_info
*info
)
10219 struct net_device
*dev
= info
->user_ptr
[1];
10220 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10222 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10223 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
10226 if (wdev
->ap_unexpected_nlportid
)
10229 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
10233 static int nl80211_probe_client(struct sk_buff
*skb
,
10234 struct genl_info
*info
)
10236 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10237 struct net_device
*dev
= info
->user_ptr
[1];
10238 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10239 struct sk_buff
*msg
;
10245 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10246 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
10247 return -EOPNOTSUPP
;
10249 if (!info
->attrs
[NL80211_ATTR_MAC
])
10252 if (!rdev
->ops
->probe_client
)
10253 return -EOPNOTSUPP
;
10255 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10259 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10260 NL80211_CMD_PROBE_CLIENT
);
10266 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10268 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
10272 if (nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
10274 goto nla_put_failure
;
10276 genlmsg_end(msg
, hdr
);
10278 return genlmsg_reply(msg
, info
);
10287 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
10289 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10290 struct cfg80211_beacon_registration
*reg
, *nreg
;
10293 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
10294 return -EOPNOTSUPP
;
10296 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
10300 /* First, check if already registered. */
10301 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10302 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10303 if (reg
->nlportid
== info
->snd_portid
) {
10308 /* Add it to the list */
10309 nreg
->nlportid
= info
->snd_portid
;
10310 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
10312 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10316 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10321 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
10323 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10324 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10327 if (!rdev
->ops
->start_p2p_device
)
10328 return -EOPNOTSUPP
;
10330 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
10331 return -EOPNOTSUPP
;
10333 if (wdev
->p2p_started
)
10336 if (rfkill_blocked(rdev
->rfkill
))
10339 err
= rdev_start_p2p_device(rdev
, wdev
);
10343 wdev
->p2p_started
= true;
10349 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
10351 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10352 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10354 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
10355 return -EOPNOTSUPP
;
10357 if (!rdev
->ops
->stop_p2p_device
)
10358 return -EOPNOTSUPP
;
10360 cfg80211_stop_p2p_device(rdev
, wdev
);
10365 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
10366 struct genl_info
*info
)
10369 struct sk_buff
*msg
;
10371 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10375 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
10376 NL80211_CMD_GET_PROTOCOL_FEATURES
);
10378 goto nla_put_failure
;
10380 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
10381 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
10382 goto nla_put_failure
;
10384 genlmsg_end(msg
, hdr
);
10385 return genlmsg_reply(msg
, info
);
10392 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
10394 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10395 struct cfg80211_update_ft_ies_params ft_params
;
10396 struct net_device
*dev
= info
->user_ptr
[1];
10398 if (!rdev
->ops
->update_ft_ies
)
10399 return -EOPNOTSUPP
;
10401 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
10402 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
10405 memset(&ft_params
, 0, sizeof(ft_params
));
10406 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
10407 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10408 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10410 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
10413 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
10414 struct genl_info
*info
)
10416 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10417 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10418 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
10422 if (!rdev
->ops
->crit_proto_start
)
10423 return -EOPNOTSUPP
;
10425 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
10428 if (rdev
->crit_proto_nlportid
)
10431 /* determine protocol if provided */
10432 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
10433 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
10435 if (proto
>= NUM_NL80211_CRIT_PROTO
)
10438 /* timeout must be provided */
10439 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
10443 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
10445 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
10448 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
10450 rdev
->crit_proto_nlportid
= info
->snd_portid
;
10455 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
10456 struct genl_info
*info
)
10458 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10459 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10461 if (!rdev
->ops
->crit_proto_stop
)
10462 return -EOPNOTSUPP
;
10464 if (rdev
->crit_proto_nlportid
) {
10465 rdev
->crit_proto_nlportid
= 0;
10466 rdev_crit_proto_stop(rdev
, wdev
);
10471 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
10473 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10474 struct wireless_dev
*wdev
=
10475 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
10479 if (!rdev
->wiphy
.vendor_commands
)
10480 return -EOPNOTSUPP
;
10482 if (IS_ERR(wdev
)) {
10483 err
= PTR_ERR(wdev
);
10484 if (err
!= -EINVAL
)
10487 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
10491 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
10492 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
10495 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
10496 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
10497 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
10498 const struct wiphy_vendor_command
*vcmd
;
10502 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
10504 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10507 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
10508 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
10511 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10515 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10516 if (wdev
->netdev
&&
10517 !netif_running(wdev
->netdev
))
10519 if (!wdev
->netdev
&& !wdev
->p2p_started
)
10524 return -EOPNOTSUPP
;
10529 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
10530 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10531 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10534 rdev
->cur_cmd_info
= info
;
10535 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
10537 rdev
->cur_cmd_info
= NULL
;
10541 return -EOPNOTSUPP
;
10544 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
10545 struct netlink_callback
*cb
,
10546 struct cfg80211_registered_device
**rdev
,
10547 struct wireless_dev
**wdev
)
10554 unsigned int data_len
= 0;
10559 /* subtract the 1 again here */
10560 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
10561 struct wireless_dev
*tmp
;
10567 *rdev
= wiphy_to_rdev(wiphy
);
10571 list_for_each_entry(tmp
, &wiphy
->wdev_list
, list
) {
10572 if (tmp
->identifier
== cb
->args
[1] - 1) {
10579 /* keep rtnl locked in successful case */
10583 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
10584 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
10589 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
10590 !nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]) {
10595 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
10596 nl80211_fam
.attrbuf
);
10600 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
10601 nl80211_fam
.attrbuf
);
10602 if (IS_ERR(*rdev
)) {
10603 err
= PTR_ERR(*rdev
);
10607 vid
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
]);
10608 subcmd
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
10610 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
10611 const struct wiphy_vendor_command
*vcmd
;
10613 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
10615 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10618 if (!vcmd
->dumpit
) {
10627 if (vcmd_idx
< 0) {
10632 if (nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
10633 data
= nla_data(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10634 data_len
= nla_len(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10637 /* 0 is the first index - add 1 to parse only once */
10638 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
10639 /* add 1 to know if it was NULL */
10640 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
10641 cb
->args
[2] = vcmd_idx
;
10642 cb
->args
[3] = (unsigned long)data
;
10643 cb
->args
[4] = data_len
;
10645 /* keep rtnl locked in successful case */
10652 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
10653 struct netlink_callback
*cb
)
10655 struct cfg80211_registered_device
*rdev
;
10656 struct wireless_dev
*wdev
;
10657 unsigned int vcmd_idx
;
10658 const struct wiphy_vendor_command
*vcmd
;
10662 struct nlattr
*vendor_data
;
10664 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
10668 vcmd_idx
= cb
->args
[2];
10669 data
= (void *)cb
->args
[3];
10670 data_len
= cb
->args
[4];
10671 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
10673 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
10674 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
10677 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10681 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10682 if (wdev
->netdev
&&
10683 !netif_running(wdev
->netdev
))
10685 if (!wdev
->netdev
&& !wdev
->p2p_started
)
10691 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
10692 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
10693 NL80211_CMD_VENDOR
);
10697 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10698 (wdev
&& nla_put_u64_64bit(skb
, NL80211_ATTR_WDEV
,
10700 NL80211_ATTR_PAD
))) {
10701 genlmsg_cancel(skb
, hdr
);
10705 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
10706 if (!vendor_data
) {
10707 genlmsg_cancel(skb
, hdr
);
10711 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
10712 (unsigned long *)&cb
->args
[5]);
10713 nla_nest_end(skb
, vendor_data
);
10715 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
10716 genlmsg_cancel(skb
, hdr
);
10719 genlmsg_cancel(skb
, hdr
);
10723 genlmsg_end(skb
, hdr
);
10732 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
10733 enum nl80211_commands cmd
,
10734 enum nl80211_attrs attr
,
10737 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10739 if (WARN_ON(!rdev
->cur_cmd_info
))
10742 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
10743 rdev
->cur_cmd_info
->snd_portid
,
10744 rdev
->cur_cmd_info
->snd_seq
,
10745 cmd
, attr
, NULL
, GFP_KERNEL
);
10747 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
10749 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
10751 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
10752 void *hdr
= ((void **)skb
->cb
)[1];
10753 struct nlattr
*data
= ((void **)skb
->cb
)[2];
10755 /* clear CB data for netlink core to own from now on */
10756 memset(skb
->cb
, 0, sizeof(skb
->cb
));
10758 if (WARN_ON(!rdev
->cur_cmd_info
)) {
10763 nla_nest_end(skb
, data
);
10764 genlmsg_end(skb
, hdr
);
10765 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
10767 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
10769 static int nl80211_set_qos_map(struct sk_buff
*skb
,
10770 struct genl_info
*info
)
10772 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10773 struct cfg80211_qos_map
*qos_map
= NULL
;
10774 struct net_device
*dev
= info
->user_ptr
[1];
10775 u8
*pos
, len
, num_des
, des_len
, des
;
10778 if (!rdev
->ops
->set_qos_map
)
10779 return -EOPNOTSUPP
;
10781 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
10782 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10783 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10785 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
10786 len
> IEEE80211_QOS_MAP_LEN_MAX
)
10789 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
10793 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
10795 des_len
= num_des
*
10796 sizeof(struct cfg80211_dscp_exception
);
10797 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
10798 qos_map
->num_des
= num_des
;
10799 for (des
= 0; des
< num_des
; des
++) {
10800 if (qos_map
->dscp_exception
[des
].up
> 7) {
10807 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
10810 wdev_lock(dev
->ieee80211_ptr
);
10811 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
10813 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
10814 wdev_unlock(dev
->ieee80211_ptr
);
10820 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10822 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10823 struct net_device
*dev
= info
->user_ptr
[1];
10824 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10827 u16 admitted_time
= 0;
10830 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
10831 return -EOPNOTSUPP
;
10833 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
10834 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
10837 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10838 if (tsid
>= IEEE80211_NUM_TIDS
)
10841 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
10842 if (up
>= IEEE80211_NUM_UPS
)
10845 /* WMM uses TIDs 0-7 even for TSPEC */
10846 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
10847 /* TODO: handle 802.11 TSPEC/admission control
10848 * need more attributes for that (e.g. BA session requirement);
10849 * change the WMM adminssion test above to allow both then
10854 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10856 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
10858 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
10859 if (!admitted_time
)
10864 switch (wdev
->iftype
) {
10865 case NL80211_IFTYPE_STATION
:
10866 case NL80211_IFTYPE_P2P_CLIENT
:
10867 if (wdev
->current_bss
)
10876 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
10883 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10885 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10886 struct net_device
*dev
= info
->user_ptr
[1];
10887 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10892 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
10895 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10896 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10899 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
10905 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
10906 struct genl_info
*info
)
10908 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10909 struct net_device
*dev
= info
->user_ptr
[1];
10910 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10911 struct cfg80211_chan_def chandef
= {};
10916 if (!rdev
->ops
->tdls_channel_switch
||
10917 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10918 return -EOPNOTSUPP
;
10920 switch (dev
->ieee80211_ptr
->iftype
) {
10921 case NL80211_IFTYPE_STATION
:
10922 case NL80211_IFTYPE_P2P_CLIENT
:
10925 return -EOPNOTSUPP
;
10928 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
10929 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
10932 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
10937 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10938 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10939 * specification is not defined for them.
10941 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
10942 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
10943 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
10946 /* we will be active on the TDLS link */
10947 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
10951 /* don't allow switching to DFS channels */
10952 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
10955 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10956 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
10959 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
10965 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
10966 struct genl_info
*info
)
10968 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10969 struct net_device
*dev
= info
->user_ptr
[1];
10970 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10973 if (!rdev
->ops
->tdls_channel_switch
||
10974 !rdev
->ops
->tdls_cancel_channel_switch
||
10975 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10976 return -EOPNOTSUPP
;
10978 switch (dev
->ieee80211_ptr
->iftype
) {
10979 case NL80211_IFTYPE_STATION
:
10980 case NL80211_IFTYPE_P2P_CLIENT
:
10983 return -EOPNOTSUPP
;
10986 if (!info
->attrs
[NL80211_ATTR_MAC
])
10989 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10992 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
10998 #define NL80211_FLAG_NEED_WIPHY 0x01
10999 #define NL80211_FLAG_NEED_NETDEV 0x02
11000 #define NL80211_FLAG_NEED_RTNL 0x04
11001 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
11002 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
11003 NL80211_FLAG_CHECK_NETDEV_UP)
11004 #define NL80211_FLAG_NEED_WDEV 0x10
11005 /* If a netdev is associated, it must be UP, P2P must be started */
11006 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
11007 NL80211_FLAG_CHECK_NETDEV_UP)
11008 #define NL80211_FLAG_CLEAR_SKB 0x20
11010 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
11011 struct genl_info
*info
)
11013 struct cfg80211_registered_device
*rdev
;
11014 struct wireless_dev
*wdev
;
11015 struct net_device
*dev
;
11016 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
11021 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
11022 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
11023 if (IS_ERR(rdev
)) {
11026 return PTR_ERR(rdev
);
11028 info
->user_ptr
[0] = rdev
;
11029 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
11030 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
11033 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
11035 if (IS_ERR(wdev
)) {
11038 return PTR_ERR(wdev
);
11041 dev
= wdev
->netdev
;
11042 rdev
= wiphy_to_rdev(wdev
->wiphy
);
11044 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
11051 info
->user_ptr
[1] = dev
;
11053 info
->user_ptr
[1] = wdev
;
11057 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
11058 !netif_running(dev
)) {
11065 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
11066 if (!wdev
->p2p_started
) {
11073 info
->user_ptr
[0] = rdev
;
11079 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
11080 struct genl_info
*info
)
11082 if (info
->user_ptr
[1]) {
11083 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
11084 struct wireless_dev
*wdev
= info
->user_ptr
[1];
11087 dev_put(wdev
->netdev
);
11089 dev_put(info
->user_ptr
[1]);
11093 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
11096 /* If needed, clear the netlink message payload from the SKB
11097 * as it might contain key data that shouldn't stick around on
11098 * the heap after the SKB is freed. The netlink message header
11099 * is still needed for further processing, so leave it intact.
11101 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
11102 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
11104 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
11108 static const struct genl_ops nl80211_ops
[] = {
11110 .cmd
= NL80211_CMD_GET_WIPHY
,
11111 .doit
= nl80211_get_wiphy
,
11112 .dumpit
= nl80211_dump_wiphy
,
11113 .done
= nl80211_dump_wiphy_done
,
11114 .policy
= nl80211_policy
,
11115 /* can be retrieved by unprivileged users */
11116 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11117 NL80211_FLAG_NEED_RTNL
,
11120 .cmd
= NL80211_CMD_SET_WIPHY
,
11121 .doit
= nl80211_set_wiphy
,
11122 .policy
= nl80211_policy
,
11123 .flags
= GENL_UNS_ADMIN_PERM
,
11124 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
11127 .cmd
= NL80211_CMD_GET_INTERFACE
,
11128 .doit
= nl80211_get_interface
,
11129 .dumpit
= nl80211_dump_interface
,
11130 .policy
= nl80211_policy
,
11131 /* can be retrieved by unprivileged users */
11132 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11133 NL80211_FLAG_NEED_RTNL
,
11136 .cmd
= NL80211_CMD_SET_INTERFACE
,
11137 .doit
= nl80211_set_interface
,
11138 .policy
= nl80211_policy
,
11139 .flags
= GENL_UNS_ADMIN_PERM
,
11140 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11141 NL80211_FLAG_NEED_RTNL
,
11144 .cmd
= NL80211_CMD_NEW_INTERFACE
,
11145 .doit
= nl80211_new_interface
,
11146 .policy
= nl80211_policy
,
11147 .flags
= GENL_UNS_ADMIN_PERM
,
11148 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11149 NL80211_FLAG_NEED_RTNL
,
11152 .cmd
= NL80211_CMD_DEL_INTERFACE
,
11153 .doit
= nl80211_del_interface
,
11154 .policy
= nl80211_policy
,
11155 .flags
= GENL_UNS_ADMIN_PERM
,
11156 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11157 NL80211_FLAG_NEED_RTNL
,
11160 .cmd
= NL80211_CMD_GET_KEY
,
11161 .doit
= nl80211_get_key
,
11162 .policy
= nl80211_policy
,
11163 .flags
= GENL_UNS_ADMIN_PERM
,
11164 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11165 NL80211_FLAG_NEED_RTNL
,
11168 .cmd
= NL80211_CMD_SET_KEY
,
11169 .doit
= nl80211_set_key
,
11170 .policy
= nl80211_policy
,
11171 .flags
= GENL_UNS_ADMIN_PERM
,
11172 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11173 NL80211_FLAG_NEED_RTNL
|
11174 NL80211_FLAG_CLEAR_SKB
,
11177 .cmd
= NL80211_CMD_NEW_KEY
,
11178 .doit
= nl80211_new_key
,
11179 .policy
= nl80211_policy
,
11180 .flags
= GENL_UNS_ADMIN_PERM
,
11181 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11182 NL80211_FLAG_NEED_RTNL
|
11183 NL80211_FLAG_CLEAR_SKB
,
11186 .cmd
= NL80211_CMD_DEL_KEY
,
11187 .doit
= nl80211_del_key
,
11188 .policy
= nl80211_policy
,
11189 .flags
= GENL_UNS_ADMIN_PERM
,
11190 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11191 NL80211_FLAG_NEED_RTNL
,
11194 .cmd
= NL80211_CMD_SET_BEACON
,
11195 .policy
= nl80211_policy
,
11196 .flags
= GENL_UNS_ADMIN_PERM
,
11197 .doit
= nl80211_set_beacon
,
11198 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11199 NL80211_FLAG_NEED_RTNL
,
11202 .cmd
= NL80211_CMD_START_AP
,
11203 .policy
= nl80211_policy
,
11204 .flags
= GENL_UNS_ADMIN_PERM
,
11205 .doit
= nl80211_start_ap
,
11206 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11207 NL80211_FLAG_NEED_RTNL
,
11210 .cmd
= NL80211_CMD_STOP_AP
,
11211 .policy
= nl80211_policy
,
11212 .flags
= GENL_UNS_ADMIN_PERM
,
11213 .doit
= nl80211_stop_ap
,
11214 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11215 NL80211_FLAG_NEED_RTNL
,
11218 .cmd
= NL80211_CMD_GET_STATION
,
11219 .doit
= nl80211_get_station
,
11220 .dumpit
= nl80211_dump_station
,
11221 .policy
= nl80211_policy
,
11222 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11223 NL80211_FLAG_NEED_RTNL
,
11226 .cmd
= NL80211_CMD_SET_STATION
,
11227 .doit
= nl80211_set_station
,
11228 .policy
= nl80211_policy
,
11229 .flags
= GENL_UNS_ADMIN_PERM
,
11230 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11231 NL80211_FLAG_NEED_RTNL
,
11234 .cmd
= NL80211_CMD_NEW_STATION
,
11235 .doit
= nl80211_new_station
,
11236 .policy
= nl80211_policy
,
11237 .flags
= GENL_UNS_ADMIN_PERM
,
11238 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11239 NL80211_FLAG_NEED_RTNL
,
11242 .cmd
= NL80211_CMD_DEL_STATION
,
11243 .doit
= nl80211_del_station
,
11244 .policy
= nl80211_policy
,
11245 .flags
= GENL_UNS_ADMIN_PERM
,
11246 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11247 NL80211_FLAG_NEED_RTNL
,
11250 .cmd
= NL80211_CMD_GET_MPATH
,
11251 .doit
= nl80211_get_mpath
,
11252 .dumpit
= nl80211_dump_mpath
,
11253 .policy
= nl80211_policy
,
11254 .flags
= GENL_UNS_ADMIN_PERM
,
11255 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11256 NL80211_FLAG_NEED_RTNL
,
11259 .cmd
= NL80211_CMD_GET_MPP
,
11260 .doit
= nl80211_get_mpp
,
11261 .dumpit
= nl80211_dump_mpp
,
11262 .policy
= nl80211_policy
,
11263 .flags
= GENL_UNS_ADMIN_PERM
,
11264 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11265 NL80211_FLAG_NEED_RTNL
,
11268 .cmd
= NL80211_CMD_SET_MPATH
,
11269 .doit
= nl80211_set_mpath
,
11270 .policy
= nl80211_policy
,
11271 .flags
= GENL_UNS_ADMIN_PERM
,
11272 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11273 NL80211_FLAG_NEED_RTNL
,
11276 .cmd
= NL80211_CMD_NEW_MPATH
,
11277 .doit
= nl80211_new_mpath
,
11278 .policy
= nl80211_policy
,
11279 .flags
= GENL_UNS_ADMIN_PERM
,
11280 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11281 NL80211_FLAG_NEED_RTNL
,
11284 .cmd
= NL80211_CMD_DEL_MPATH
,
11285 .doit
= nl80211_del_mpath
,
11286 .policy
= nl80211_policy
,
11287 .flags
= GENL_UNS_ADMIN_PERM
,
11288 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11289 NL80211_FLAG_NEED_RTNL
,
11292 .cmd
= NL80211_CMD_SET_BSS
,
11293 .doit
= nl80211_set_bss
,
11294 .policy
= nl80211_policy
,
11295 .flags
= GENL_UNS_ADMIN_PERM
,
11296 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11297 NL80211_FLAG_NEED_RTNL
,
11300 .cmd
= NL80211_CMD_GET_REG
,
11301 .doit
= nl80211_get_reg_do
,
11302 .dumpit
= nl80211_get_reg_dump
,
11303 .policy
= nl80211_policy
,
11304 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
11305 /* can be retrieved by unprivileged users */
11307 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
11309 .cmd
= NL80211_CMD_SET_REG
,
11310 .doit
= nl80211_set_reg
,
11311 .policy
= nl80211_policy
,
11312 .flags
= GENL_ADMIN_PERM
,
11313 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
11317 .cmd
= NL80211_CMD_REQ_SET_REG
,
11318 .doit
= nl80211_req_set_reg
,
11319 .policy
= nl80211_policy
,
11320 .flags
= GENL_ADMIN_PERM
,
11323 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
11324 .doit
= nl80211_get_mesh_config
,
11325 .policy
= nl80211_policy
,
11326 /* can be retrieved by unprivileged users */
11327 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11328 NL80211_FLAG_NEED_RTNL
,
11331 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
11332 .doit
= nl80211_update_mesh_config
,
11333 .policy
= nl80211_policy
,
11334 .flags
= GENL_UNS_ADMIN_PERM
,
11335 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11336 NL80211_FLAG_NEED_RTNL
,
11339 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
11340 .doit
= nl80211_trigger_scan
,
11341 .policy
= nl80211_policy
,
11342 .flags
= GENL_UNS_ADMIN_PERM
,
11343 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11344 NL80211_FLAG_NEED_RTNL
,
11347 .cmd
= NL80211_CMD_ABORT_SCAN
,
11348 .doit
= nl80211_abort_scan
,
11349 .policy
= nl80211_policy
,
11350 .flags
= GENL_UNS_ADMIN_PERM
,
11351 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11352 NL80211_FLAG_NEED_RTNL
,
11355 .cmd
= NL80211_CMD_GET_SCAN
,
11356 .policy
= nl80211_policy
,
11357 .dumpit
= nl80211_dump_scan
,
11360 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
11361 .doit
= nl80211_start_sched_scan
,
11362 .policy
= nl80211_policy
,
11363 .flags
= GENL_UNS_ADMIN_PERM
,
11364 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11365 NL80211_FLAG_NEED_RTNL
,
11368 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
11369 .doit
= nl80211_stop_sched_scan
,
11370 .policy
= nl80211_policy
,
11371 .flags
= GENL_UNS_ADMIN_PERM
,
11372 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11373 NL80211_FLAG_NEED_RTNL
,
11376 .cmd
= NL80211_CMD_AUTHENTICATE
,
11377 .doit
= nl80211_authenticate
,
11378 .policy
= nl80211_policy
,
11379 .flags
= GENL_UNS_ADMIN_PERM
,
11380 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11381 NL80211_FLAG_NEED_RTNL
|
11382 NL80211_FLAG_CLEAR_SKB
,
11385 .cmd
= NL80211_CMD_ASSOCIATE
,
11386 .doit
= nl80211_associate
,
11387 .policy
= nl80211_policy
,
11388 .flags
= GENL_UNS_ADMIN_PERM
,
11389 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11390 NL80211_FLAG_NEED_RTNL
,
11393 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
11394 .doit
= nl80211_deauthenticate
,
11395 .policy
= nl80211_policy
,
11396 .flags
= GENL_UNS_ADMIN_PERM
,
11397 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11398 NL80211_FLAG_NEED_RTNL
,
11401 .cmd
= NL80211_CMD_DISASSOCIATE
,
11402 .doit
= nl80211_disassociate
,
11403 .policy
= nl80211_policy
,
11404 .flags
= GENL_UNS_ADMIN_PERM
,
11405 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11406 NL80211_FLAG_NEED_RTNL
,
11409 .cmd
= NL80211_CMD_JOIN_IBSS
,
11410 .doit
= nl80211_join_ibss
,
11411 .policy
= nl80211_policy
,
11412 .flags
= GENL_UNS_ADMIN_PERM
,
11413 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11414 NL80211_FLAG_NEED_RTNL
,
11417 .cmd
= NL80211_CMD_LEAVE_IBSS
,
11418 .doit
= nl80211_leave_ibss
,
11419 .policy
= nl80211_policy
,
11420 .flags
= GENL_UNS_ADMIN_PERM
,
11421 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11422 NL80211_FLAG_NEED_RTNL
,
11424 #ifdef CONFIG_NL80211_TESTMODE
11426 .cmd
= NL80211_CMD_TESTMODE
,
11427 .doit
= nl80211_testmode_do
,
11428 .dumpit
= nl80211_testmode_dump
,
11429 .policy
= nl80211_policy
,
11430 .flags
= GENL_UNS_ADMIN_PERM
,
11431 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11432 NL80211_FLAG_NEED_RTNL
,
11436 .cmd
= NL80211_CMD_CONNECT
,
11437 .doit
= nl80211_connect
,
11438 .policy
= nl80211_policy
,
11439 .flags
= GENL_UNS_ADMIN_PERM
,
11440 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11441 NL80211_FLAG_NEED_RTNL
,
11444 .cmd
= NL80211_CMD_DISCONNECT
,
11445 .doit
= nl80211_disconnect
,
11446 .policy
= nl80211_policy
,
11447 .flags
= GENL_UNS_ADMIN_PERM
,
11448 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11449 NL80211_FLAG_NEED_RTNL
,
11452 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
11453 .doit
= nl80211_wiphy_netns
,
11454 .policy
= nl80211_policy
,
11455 .flags
= GENL_UNS_ADMIN_PERM
,
11456 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11457 NL80211_FLAG_NEED_RTNL
,
11460 .cmd
= NL80211_CMD_GET_SURVEY
,
11461 .policy
= nl80211_policy
,
11462 .dumpit
= nl80211_dump_survey
,
11465 .cmd
= NL80211_CMD_SET_PMKSA
,
11466 .doit
= nl80211_setdel_pmksa
,
11467 .policy
= nl80211_policy
,
11468 .flags
= GENL_UNS_ADMIN_PERM
,
11469 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11470 NL80211_FLAG_NEED_RTNL
,
11473 .cmd
= NL80211_CMD_DEL_PMKSA
,
11474 .doit
= nl80211_setdel_pmksa
,
11475 .policy
= nl80211_policy
,
11476 .flags
= GENL_UNS_ADMIN_PERM
,
11477 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11478 NL80211_FLAG_NEED_RTNL
,
11481 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
11482 .doit
= nl80211_flush_pmksa
,
11483 .policy
= nl80211_policy
,
11484 .flags
= GENL_UNS_ADMIN_PERM
,
11485 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11486 NL80211_FLAG_NEED_RTNL
,
11489 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
11490 .doit
= nl80211_remain_on_channel
,
11491 .policy
= nl80211_policy
,
11492 .flags
= GENL_UNS_ADMIN_PERM
,
11493 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11494 NL80211_FLAG_NEED_RTNL
,
11497 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
11498 .doit
= nl80211_cancel_remain_on_channel
,
11499 .policy
= nl80211_policy
,
11500 .flags
= GENL_UNS_ADMIN_PERM
,
11501 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11502 NL80211_FLAG_NEED_RTNL
,
11505 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
11506 .doit
= nl80211_set_tx_bitrate_mask
,
11507 .policy
= nl80211_policy
,
11508 .flags
= GENL_UNS_ADMIN_PERM
,
11509 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11510 NL80211_FLAG_NEED_RTNL
,
11513 .cmd
= NL80211_CMD_REGISTER_FRAME
,
11514 .doit
= nl80211_register_mgmt
,
11515 .policy
= nl80211_policy
,
11516 .flags
= GENL_UNS_ADMIN_PERM
,
11517 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11518 NL80211_FLAG_NEED_RTNL
,
11521 .cmd
= NL80211_CMD_FRAME
,
11522 .doit
= nl80211_tx_mgmt
,
11523 .policy
= nl80211_policy
,
11524 .flags
= GENL_UNS_ADMIN_PERM
,
11525 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11526 NL80211_FLAG_NEED_RTNL
,
11529 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
11530 .doit
= nl80211_tx_mgmt_cancel_wait
,
11531 .policy
= nl80211_policy
,
11532 .flags
= GENL_UNS_ADMIN_PERM
,
11533 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11534 NL80211_FLAG_NEED_RTNL
,
11537 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
11538 .doit
= nl80211_set_power_save
,
11539 .policy
= nl80211_policy
,
11540 .flags
= GENL_UNS_ADMIN_PERM
,
11541 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11542 NL80211_FLAG_NEED_RTNL
,
11545 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
11546 .doit
= nl80211_get_power_save
,
11547 .policy
= nl80211_policy
,
11548 /* can be retrieved by unprivileged users */
11549 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11550 NL80211_FLAG_NEED_RTNL
,
11553 .cmd
= NL80211_CMD_SET_CQM
,
11554 .doit
= nl80211_set_cqm
,
11555 .policy
= nl80211_policy
,
11556 .flags
= GENL_UNS_ADMIN_PERM
,
11557 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11558 NL80211_FLAG_NEED_RTNL
,
11561 .cmd
= NL80211_CMD_SET_CHANNEL
,
11562 .doit
= nl80211_set_channel
,
11563 .policy
= nl80211_policy
,
11564 .flags
= GENL_UNS_ADMIN_PERM
,
11565 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11566 NL80211_FLAG_NEED_RTNL
,
11569 .cmd
= NL80211_CMD_SET_WDS_PEER
,
11570 .doit
= nl80211_set_wds_peer
,
11571 .policy
= nl80211_policy
,
11572 .flags
= GENL_UNS_ADMIN_PERM
,
11573 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11574 NL80211_FLAG_NEED_RTNL
,
11577 .cmd
= NL80211_CMD_JOIN_MESH
,
11578 .doit
= nl80211_join_mesh
,
11579 .policy
= nl80211_policy
,
11580 .flags
= GENL_UNS_ADMIN_PERM
,
11581 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11582 NL80211_FLAG_NEED_RTNL
,
11585 .cmd
= NL80211_CMD_LEAVE_MESH
,
11586 .doit
= nl80211_leave_mesh
,
11587 .policy
= nl80211_policy
,
11588 .flags
= GENL_UNS_ADMIN_PERM
,
11589 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11590 NL80211_FLAG_NEED_RTNL
,
11593 .cmd
= NL80211_CMD_JOIN_OCB
,
11594 .doit
= nl80211_join_ocb
,
11595 .policy
= nl80211_policy
,
11596 .flags
= GENL_UNS_ADMIN_PERM
,
11597 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11598 NL80211_FLAG_NEED_RTNL
,
11601 .cmd
= NL80211_CMD_LEAVE_OCB
,
11602 .doit
= nl80211_leave_ocb
,
11603 .policy
= nl80211_policy
,
11604 .flags
= GENL_UNS_ADMIN_PERM
,
11605 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11606 NL80211_FLAG_NEED_RTNL
,
11610 .cmd
= NL80211_CMD_GET_WOWLAN
,
11611 .doit
= nl80211_get_wowlan
,
11612 .policy
= nl80211_policy
,
11613 /* can be retrieved by unprivileged users */
11614 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11615 NL80211_FLAG_NEED_RTNL
,
11618 .cmd
= NL80211_CMD_SET_WOWLAN
,
11619 .doit
= nl80211_set_wowlan
,
11620 .policy
= nl80211_policy
,
11621 .flags
= GENL_UNS_ADMIN_PERM
,
11622 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11623 NL80211_FLAG_NEED_RTNL
,
11627 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
11628 .doit
= nl80211_set_rekey_data
,
11629 .policy
= nl80211_policy
,
11630 .flags
= GENL_UNS_ADMIN_PERM
,
11631 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11632 NL80211_FLAG_NEED_RTNL
|
11633 NL80211_FLAG_CLEAR_SKB
,
11636 .cmd
= NL80211_CMD_TDLS_MGMT
,
11637 .doit
= nl80211_tdls_mgmt
,
11638 .policy
= nl80211_policy
,
11639 .flags
= GENL_UNS_ADMIN_PERM
,
11640 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11641 NL80211_FLAG_NEED_RTNL
,
11644 .cmd
= NL80211_CMD_TDLS_OPER
,
11645 .doit
= nl80211_tdls_oper
,
11646 .policy
= nl80211_policy
,
11647 .flags
= GENL_UNS_ADMIN_PERM
,
11648 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11649 NL80211_FLAG_NEED_RTNL
,
11652 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
11653 .doit
= nl80211_register_unexpected_frame
,
11654 .policy
= nl80211_policy
,
11655 .flags
= GENL_UNS_ADMIN_PERM
,
11656 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11657 NL80211_FLAG_NEED_RTNL
,
11660 .cmd
= NL80211_CMD_PROBE_CLIENT
,
11661 .doit
= nl80211_probe_client
,
11662 .policy
= nl80211_policy
,
11663 .flags
= GENL_UNS_ADMIN_PERM
,
11664 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11665 NL80211_FLAG_NEED_RTNL
,
11668 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
11669 .doit
= nl80211_register_beacons
,
11670 .policy
= nl80211_policy
,
11671 .flags
= GENL_UNS_ADMIN_PERM
,
11672 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11673 NL80211_FLAG_NEED_RTNL
,
11676 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
11677 .doit
= nl80211_set_noack_map
,
11678 .policy
= nl80211_policy
,
11679 .flags
= GENL_UNS_ADMIN_PERM
,
11680 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11681 NL80211_FLAG_NEED_RTNL
,
11684 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
11685 .doit
= nl80211_start_p2p_device
,
11686 .policy
= nl80211_policy
,
11687 .flags
= GENL_UNS_ADMIN_PERM
,
11688 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11689 NL80211_FLAG_NEED_RTNL
,
11692 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
11693 .doit
= nl80211_stop_p2p_device
,
11694 .policy
= nl80211_policy
,
11695 .flags
= GENL_UNS_ADMIN_PERM
,
11696 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11697 NL80211_FLAG_NEED_RTNL
,
11700 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
11701 .doit
= nl80211_set_mcast_rate
,
11702 .policy
= nl80211_policy
,
11703 .flags
= GENL_UNS_ADMIN_PERM
,
11704 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11705 NL80211_FLAG_NEED_RTNL
,
11708 .cmd
= NL80211_CMD_SET_MAC_ACL
,
11709 .doit
= nl80211_set_mac_acl
,
11710 .policy
= nl80211_policy
,
11711 .flags
= GENL_UNS_ADMIN_PERM
,
11712 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11713 NL80211_FLAG_NEED_RTNL
,
11716 .cmd
= NL80211_CMD_RADAR_DETECT
,
11717 .doit
= nl80211_start_radar_detection
,
11718 .policy
= nl80211_policy
,
11719 .flags
= GENL_UNS_ADMIN_PERM
,
11720 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11721 NL80211_FLAG_NEED_RTNL
,
11724 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
11725 .doit
= nl80211_get_protocol_features
,
11726 .policy
= nl80211_policy
,
11729 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
11730 .doit
= nl80211_update_ft_ies
,
11731 .policy
= nl80211_policy
,
11732 .flags
= GENL_UNS_ADMIN_PERM
,
11733 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11734 NL80211_FLAG_NEED_RTNL
,
11737 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
11738 .doit
= nl80211_crit_protocol_start
,
11739 .policy
= nl80211_policy
,
11740 .flags
= GENL_UNS_ADMIN_PERM
,
11741 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11742 NL80211_FLAG_NEED_RTNL
,
11745 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
11746 .doit
= nl80211_crit_protocol_stop
,
11747 .policy
= nl80211_policy
,
11748 .flags
= GENL_UNS_ADMIN_PERM
,
11749 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11750 NL80211_FLAG_NEED_RTNL
,
11753 .cmd
= NL80211_CMD_GET_COALESCE
,
11754 .doit
= nl80211_get_coalesce
,
11755 .policy
= nl80211_policy
,
11756 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11757 NL80211_FLAG_NEED_RTNL
,
11760 .cmd
= NL80211_CMD_SET_COALESCE
,
11761 .doit
= nl80211_set_coalesce
,
11762 .policy
= nl80211_policy
,
11763 .flags
= GENL_UNS_ADMIN_PERM
,
11764 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11765 NL80211_FLAG_NEED_RTNL
,
11768 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
11769 .doit
= nl80211_channel_switch
,
11770 .policy
= nl80211_policy
,
11771 .flags
= GENL_UNS_ADMIN_PERM
,
11772 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11773 NL80211_FLAG_NEED_RTNL
,
11776 .cmd
= NL80211_CMD_VENDOR
,
11777 .doit
= nl80211_vendor_cmd
,
11778 .dumpit
= nl80211_vendor_cmd_dump
,
11779 .policy
= nl80211_policy
,
11780 .flags
= GENL_UNS_ADMIN_PERM
,
11781 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11782 NL80211_FLAG_NEED_RTNL
,
11785 .cmd
= NL80211_CMD_SET_QOS_MAP
,
11786 .doit
= nl80211_set_qos_map
,
11787 .policy
= nl80211_policy
,
11788 .flags
= GENL_UNS_ADMIN_PERM
,
11789 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11790 NL80211_FLAG_NEED_RTNL
,
11793 .cmd
= NL80211_CMD_ADD_TX_TS
,
11794 .doit
= nl80211_add_tx_ts
,
11795 .policy
= nl80211_policy
,
11796 .flags
= GENL_UNS_ADMIN_PERM
,
11797 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11798 NL80211_FLAG_NEED_RTNL
,
11801 .cmd
= NL80211_CMD_DEL_TX_TS
,
11802 .doit
= nl80211_del_tx_ts
,
11803 .policy
= nl80211_policy
,
11804 .flags
= GENL_UNS_ADMIN_PERM
,
11805 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11806 NL80211_FLAG_NEED_RTNL
,
11809 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
11810 .doit
= nl80211_tdls_channel_switch
,
11811 .policy
= nl80211_policy
,
11812 .flags
= GENL_UNS_ADMIN_PERM
,
11813 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11814 NL80211_FLAG_NEED_RTNL
,
11817 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
11818 .doit
= nl80211_tdls_cancel_channel_switch
,
11819 .policy
= nl80211_policy
,
11820 .flags
= GENL_UNS_ADMIN_PERM
,
11821 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11822 NL80211_FLAG_NEED_RTNL
,
11826 /* notification functions */
11828 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
11829 enum nl80211_commands cmd
)
11831 struct sk_buff
*msg
;
11832 struct nl80211_dump_wiphy_state state
= {};
11834 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
11835 cmd
!= NL80211_CMD_DEL_WIPHY
);
11837 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11841 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
11846 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11847 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
11850 static int nl80211_add_scan_req(struct sk_buff
*msg
,
11851 struct cfg80211_registered_device
*rdev
)
11853 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
11854 struct nlattr
*nest
;
11860 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
11862 goto nla_put_failure
;
11863 for (i
= 0; i
< req
->n_ssids
; i
++) {
11864 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
11865 goto nla_put_failure
;
11867 nla_nest_end(msg
, nest
);
11869 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
11871 goto nla_put_failure
;
11872 for (i
= 0; i
< req
->n_channels
; i
++) {
11873 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
11874 goto nla_put_failure
;
11876 nla_nest_end(msg
, nest
);
11879 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
11880 goto nla_put_failure
;
11883 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
11884 goto nla_put_failure
;
11886 if (req
->info
.scan_start_tsf
&&
11887 (nla_put_u64_64bit(msg
, NL80211_ATTR_SCAN_START_TIME_TSF
,
11888 req
->info
.scan_start_tsf
, NL80211_BSS_PAD
) ||
11889 nla_put(msg
, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID
, ETH_ALEN
,
11890 req
->info
.tsf_bssid
)))
11891 goto nla_put_failure
;
11898 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
11899 struct cfg80211_registered_device
*rdev
,
11900 struct wireless_dev
*wdev
,
11901 u32 portid
, u32 seq
, int flags
,
11906 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11910 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11911 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11912 wdev
->netdev
->ifindex
)) ||
11913 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
11915 goto nla_put_failure
;
11917 /* ignore errors and send incomplete event anyway */
11918 nl80211_add_scan_req(msg
, rdev
);
11920 genlmsg_end(msg
, hdr
);
11924 genlmsg_cancel(msg
, hdr
);
11929 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
11930 struct cfg80211_registered_device
*rdev
,
11931 struct net_device
*netdev
,
11932 u32 portid
, u32 seq
, int flags
, u32 cmd
)
11936 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11940 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11941 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11942 goto nla_put_failure
;
11944 genlmsg_end(msg
, hdr
);
11948 genlmsg_cancel(msg
, hdr
);
11952 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
11953 struct wireless_dev
*wdev
)
11955 struct sk_buff
*msg
;
11957 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11961 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11962 NL80211_CMD_TRIGGER_SCAN
) < 0) {
11967 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11968 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11971 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
11972 struct wireless_dev
*wdev
, bool aborted
)
11974 struct sk_buff
*msg
;
11976 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11980 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11981 aborted
? NL80211_CMD_SCAN_ABORTED
:
11982 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
11990 void nl80211_send_scan_result(struct cfg80211_registered_device
*rdev
,
11991 struct sk_buff
*msg
)
11996 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11997 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
12000 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
12001 struct net_device
*netdev
)
12003 struct sk_buff
*msg
;
12005 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12009 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
12010 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
12015 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12016 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
12019 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
12020 struct net_device
*netdev
, u32 cmd
)
12022 struct sk_buff
*msg
;
12024 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12028 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
12033 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12034 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
12037 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
12038 struct regulatory_request
*request
)
12040 /* Userspace can always count this one always being set */
12041 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
12042 goto nla_put_failure
;
12044 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
12045 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12046 NL80211_REGDOM_TYPE_WORLD
))
12047 goto nla_put_failure
;
12048 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
12049 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12050 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
12051 goto nla_put_failure
;
12052 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
12053 request
->intersect
) {
12054 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12055 NL80211_REGDOM_TYPE_INTERSECTION
))
12056 goto nla_put_failure
;
12058 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
12059 NL80211_REGDOM_TYPE_COUNTRY
) ||
12060 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
12062 goto nla_put_failure
;
12065 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
12066 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
12069 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
12070 goto nla_put_failure
;
12073 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
12074 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
12075 goto nla_put_failure
;
12085 * This can happen on global regulatory changes or device specific settings
12086 * based on custom regulatory domains.
12088 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
12089 struct regulatory_request
*request
)
12091 struct sk_buff
*msg
;
12094 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12098 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
12104 if (nl80211_reg_change_event_fill(msg
, request
) == false)
12105 goto nla_put_failure
;
12107 genlmsg_end(msg
, hdr
);
12110 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
12111 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
12117 genlmsg_cancel(msg
, hdr
);
12121 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
12122 struct net_device
*netdev
,
12123 const u8
*buf
, size_t len
,
12124 enum nl80211_commands cmd
, gfp_t gfp
,
12127 struct sk_buff
*msg
;
12130 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12134 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12140 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12141 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12142 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
12143 goto nla_put_failure
;
12145 if (uapsd_queues
>= 0) {
12146 struct nlattr
*nla_wmm
=
12147 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
12149 goto nla_put_failure
;
12151 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
12153 goto nla_put_failure
;
12155 nla_nest_end(msg
, nla_wmm
);
12158 genlmsg_end(msg
, hdr
);
12160 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12161 NL80211_MCGRP_MLME
, gfp
);
12165 genlmsg_cancel(msg
, hdr
);
12169 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
12170 struct net_device
*netdev
, const u8
*buf
,
12171 size_t len
, gfp_t gfp
)
12173 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12174 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
12177 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
12178 struct net_device
*netdev
, const u8
*buf
,
12179 size_t len
, gfp_t gfp
, int uapsd_queues
)
12181 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12182 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
12185 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
12186 struct net_device
*netdev
, const u8
*buf
,
12187 size_t len
, gfp_t gfp
)
12189 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12190 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
12193 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
12194 struct net_device
*netdev
, const u8
*buf
,
12195 size_t len
, gfp_t gfp
)
12197 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
12198 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
12201 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
12204 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12205 struct wiphy
*wiphy
= wdev
->wiphy
;
12206 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12207 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
12210 if (WARN_ON(len
< 2))
12213 if (ieee80211_is_deauth(mgmt
->frame_control
))
12214 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
12216 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
12218 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
12219 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
12221 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
12223 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
12224 struct net_device
*netdev
, int cmd
,
12225 const u8
*addr
, gfp_t gfp
)
12227 struct sk_buff
*msg
;
12230 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12234 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12240 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12241 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12242 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
12243 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
12244 goto nla_put_failure
;
12246 genlmsg_end(msg
, hdr
);
12248 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12249 NL80211_MCGRP_MLME
, gfp
);
12253 genlmsg_cancel(msg
, hdr
);
12257 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
12258 struct net_device
*netdev
, const u8
*addr
,
12261 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
12265 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
12266 struct net_device
*netdev
, const u8
*addr
,
12269 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
12273 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
12274 struct net_device
*netdev
, const u8
*bssid
,
12275 const u8
*req_ie
, size_t req_ie_len
,
12276 const u8
*resp_ie
, size_t resp_ie_len
,
12277 int status
, gfp_t gfp
)
12279 struct sk_buff
*msg
;
12282 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12286 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
12292 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12293 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12294 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
12295 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
,
12296 status
< 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE
:
12298 (status
< 0 && nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
)) ||
12300 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
12302 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
12303 goto nla_put_failure
;
12305 genlmsg_end(msg
, hdr
);
12307 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12308 NL80211_MCGRP_MLME
, gfp
);
12312 genlmsg_cancel(msg
, hdr
);
12316 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
12317 struct net_device
*netdev
, const u8
*bssid
,
12318 const u8
*req_ie
, size_t req_ie_len
,
12319 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
12321 struct sk_buff
*msg
;
12324 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12328 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
12334 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12335 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12336 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
12338 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
12340 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
12341 goto nla_put_failure
;
12343 genlmsg_end(msg
, hdr
);
12345 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12346 NL80211_MCGRP_MLME
, gfp
);
12350 genlmsg_cancel(msg
, hdr
);
12354 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
12355 struct net_device
*netdev
, u16 reason
,
12356 const u8
*ie
, size_t ie_len
, bool from_ap
)
12358 struct sk_buff
*msg
;
12361 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
12365 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
12371 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12372 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12373 (from_ap
&& reason
&&
12374 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
12376 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
12377 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
12378 goto nla_put_failure
;
12380 genlmsg_end(msg
, hdr
);
12382 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12383 NL80211_MCGRP_MLME
, GFP_KERNEL
);
12387 genlmsg_cancel(msg
, hdr
);
12391 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
12392 struct net_device
*netdev
, const u8
*bssid
,
12395 struct sk_buff
*msg
;
12398 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12402 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
12408 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12409 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12410 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
12411 goto nla_put_failure
;
12413 genlmsg_end(msg
, hdr
);
12415 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12416 NL80211_MCGRP_MLME
, gfp
);
12420 genlmsg_cancel(msg
, hdr
);
12424 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
12425 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
12427 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12428 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12429 struct sk_buff
*msg
;
12432 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
12435 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
12437 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12441 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
12447 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12448 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12449 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
12451 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
12452 goto nla_put_failure
;
12454 genlmsg_end(msg
, hdr
);
12456 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12457 NL80211_MCGRP_MLME
, gfp
);
12461 genlmsg_cancel(msg
, hdr
);
12464 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
12466 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
12467 struct net_device
*netdev
, const u8
*addr
,
12468 enum nl80211_key_type key_type
, int key_id
,
12469 const u8
*tsc
, gfp_t gfp
)
12471 struct sk_buff
*msg
;
12474 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12478 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
12484 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12485 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12486 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
12487 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
12489 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
12490 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
12491 goto nla_put_failure
;
12493 genlmsg_end(msg
, hdr
);
12495 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12496 NL80211_MCGRP_MLME
, gfp
);
12500 genlmsg_cancel(msg
, hdr
);
12504 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
12505 struct ieee80211_channel
*channel_before
,
12506 struct ieee80211_channel
*channel_after
)
12508 struct sk_buff
*msg
;
12510 struct nlattr
*nl_freq
;
12512 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
12516 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
12523 * Since we are applying the beacon hint to a wiphy we know its
12524 * wiphy_idx is valid
12526 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
12527 goto nla_put_failure
;
12530 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
12532 goto nla_put_failure
;
12533 if (nl80211_msg_put_channel(msg
, channel_before
, false))
12534 goto nla_put_failure
;
12535 nla_nest_end(msg
, nl_freq
);
12538 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
12540 goto nla_put_failure
;
12541 if (nl80211_msg_put_channel(msg
, channel_after
, false))
12542 goto nla_put_failure
;
12543 nla_nest_end(msg
, nl_freq
);
12545 genlmsg_end(msg
, hdr
);
12548 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
12549 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
12555 genlmsg_cancel(msg
, hdr
);
12559 static void nl80211_send_remain_on_chan_event(
12560 int cmd
, struct cfg80211_registered_device
*rdev
,
12561 struct wireless_dev
*wdev
, u64 cookie
,
12562 struct ieee80211_channel
*chan
,
12563 unsigned int duration
, gfp_t gfp
)
12565 struct sk_buff
*msg
;
12568 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12572 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12578 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12579 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12580 wdev
->netdev
->ifindex
)) ||
12581 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12582 NL80211_ATTR_PAD
) ||
12583 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
12584 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
12585 NL80211_CHAN_NO_HT
) ||
12586 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
12588 goto nla_put_failure
;
12590 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
12591 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
12592 goto nla_put_failure
;
12594 genlmsg_end(msg
, hdr
);
12596 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12597 NL80211_MCGRP_MLME
, gfp
);
12601 genlmsg_cancel(msg
, hdr
);
12605 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
12606 struct ieee80211_channel
*chan
,
12607 unsigned int duration
, gfp_t gfp
)
12609 struct wiphy
*wiphy
= wdev
->wiphy
;
12610 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12612 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
12613 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
12614 rdev
, wdev
, cookie
, chan
,
12617 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
12619 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
12620 struct ieee80211_channel
*chan
,
12623 struct wiphy
*wiphy
= wdev
->wiphy
;
12624 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12626 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
12627 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
12628 rdev
, wdev
, cookie
, chan
, 0, gfp
);
12630 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
12632 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
12633 struct station_info
*sinfo
, gfp_t gfp
)
12635 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12636 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12637 struct sk_buff
*msg
;
12639 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
12641 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12645 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
12646 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12651 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12652 NL80211_MCGRP_MLME
, gfp
);
12654 EXPORT_SYMBOL(cfg80211_new_sta
);
12656 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
12657 struct station_info
*sinfo
, gfp_t gfp
)
12659 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12660 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12661 struct sk_buff
*msg
;
12662 struct station_info empty_sinfo
= {};
12665 sinfo
= &empty_sinfo
;
12667 trace_cfg80211_del_sta(dev
, mac_addr
);
12669 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12673 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
12674 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12679 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12680 NL80211_MCGRP_MLME
, gfp
);
12682 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
12684 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
12685 enum nl80211_connect_failed_reason reason
,
12688 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12689 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12690 struct sk_buff
*msg
;
12693 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
12697 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
12703 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12704 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
12705 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
12706 goto nla_put_failure
;
12708 genlmsg_end(msg
, hdr
);
12710 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12711 NL80211_MCGRP_MLME
, gfp
);
12715 genlmsg_cancel(msg
, hdr
);
12718 EXPORT_SYMBOL(cfg80211_conn_failed
);
12720 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
12721 const u8
*addr
, gfp_t gfp
)
12723 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12724 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12725 struct sk_buff
*msg
;
12727 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
12732 msg
= nlmsg_new(100, gfp
);
12736 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12742 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12743 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12744 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
12745 goto nla_put_failure
;
12747 genlmsg_end(msg
, hdr
);
12748 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12752 genlmsg_cancel(msg
, hdr
);
12757 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
12758 const u8
*addr
, gfp_t gfp
)
12760 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12763 trace_cfg80211_rx_spurious_frame(dev
, addr
);
12765 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12766 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
12767 trace_cfg80211_return_bool(false);
12770 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
12772 trace_cfg80211_return_bool(ret
);
12775 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
12777 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
12778 const u8
*addr
, gfp_t gfp
)
12780 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12783 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
12785 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12786 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
12787 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
12788 trace_cfg80211_return_bool(false);
12791 ret
= __nl80211_unexpected_frame(dev
,
12792 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
12794 trace_cfg80211_return_bool(ret
);
12797 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
12799 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
12800 struct wireless_dev
*wdev
, u32 nlportid
,
12801 int freq
, int sig_dbm
,
12802 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
12804 struct net_device
*netdev
= wdev
->netdev
;
12805 struct sk_buff
*msg
;
12808 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12812 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
12818 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12819 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12820 netdev
->ifindex
)) ||
12821 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12822 NL80211_ATTR_PAD
) ||
12823 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
12825 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
12826 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12828 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
12829 goto nla_put_failure
;
12831 genlmsg_end(msg
, hdr
);
12833 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12836 genlmsg_cancel(msg
, hdr
);
12841 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
12842 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
12844 struct wiphy
*wiphy
= wdev
->wiphy
;
12845 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12846 struct net_device
*netdev
= wdev
->netdev
;
12847 struct sk_buff
*msg
;
12850 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
12852 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12856 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
12862 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12863 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12864 netdev
->ifindex
)) ||
12865 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
12866 NL80211_ATTR_PAD
) ||
12867 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12868 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
12869 NL80211_ATTR_PAD
) ||
12870 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
12871 goto nla_put_failure
;
12873 genlmsg_end(msg
, hdr
);
12875 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12876 NL80211_MCGRP_MLME
, gfp
);
12880 genlmsg_cancel(msg
, hdr
);
12883 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
12885 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
12886 const char *mac
, gfp_t gfp
)
12888 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12889 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12890 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12896 cb
= (void **)msg
->cb
;
12898 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
12904 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12905 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
12906 goto nla_put_failure
;
12908 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
12909 goto nla_put_failure
;
12911 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
12913 goto nla_put_failure
;
12923 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
12925 void **cb
= (void **)msg
->cb
;
12926 struct cfg80211_registered_device
*rdev
= cb
[2];
12928 nla_nest_end(msg
, cb
[1]);
12929 genlmsg_end(msg
, cb
[0]);
12931 memset(msg
->cb
, 0, sizeof(msg
->cb
));
12933 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12934 NL80211_MCGRP_MLME
, gfp
);
12937 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
12938 enum nl80211_cqm_rssi_threshold_event rssi_event
,
12941 struct sk_buff
*msg
;
12943 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
12945 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
12946 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
12949 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
12953 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
12955 goto nla_put_failure
;
12957 cfg80211_send_cqm(msg
, gfp
);
12964 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
12966 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
12967 const u8
*peer
, u32 num_packets
,
12968 u32 rate
, u32 intvl
, gfp_t gfp
)
12970 struct sk_buff
*msg
;
12972 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
12976 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
12977 goto nla_put_failure
;
12979 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
12980 goto nla_put_failure
;
12982 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
12983 goto nla_put_failure
;
12985 cfg80211_send_cqm(msg
, gfp
);
12991 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
12993 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
12994 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
12996 struct sk_buff
*msg
;
12998 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
13000 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
13004 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
13005 goto nla_put_failure
;
13007 cfg80211_send_cqm(msg
, gfp
);
13013 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
13015 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
13017 struct sk_buff
*msg
;
13019 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
13023 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
13024 goto nla_put_failure
;
13026 cfg80211_send_cqm(msg
, gfp
);
13032 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
13034 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
13035 struct net_device
*netdev
, const u8
*bssid
,
13036 const u8
*replay_ctr
, gfp_t gfp
)
13038 struct sk_buff
*msg
;
13039 struct nlattr
*rekey_attr
;
13042 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13046 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
13052 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13053 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13054 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
13055 goto nla_put_failure
;
13057 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
13059 goto nla_put_failure
;
13061 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
13062 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
13063 goto nla_put_failure
;
13065 nla_nest_end(msg
, rekey_attr
);
13067 genlmsg_end(msg
, hdr
);
13069 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13070 NL80211_MCGRP_MLME
, gfp
);
13074 genlmsg_cancel(msg
, hdr
);
13078 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
13079 const u8
*replay_ctr
, gfp_t gfp
)
13081 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13082 struct wiphy
*wiphy
= wdev
->wiphy
;
13083 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13085 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
13086 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
13088 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
13091 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
13092 struct net_device
*netdev
, int index
,
13093 const u8
*bssid
, bool preauth
, gfp_t gfp
)
13095 struct sk_buff
*msg
;
13096 struct nlattr
*attr
;
13099 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13103 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
13109 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13110 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
13111 goto nla_put_failure
;
13113 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
13115 goto nla_put_failure
;
13117 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
13118 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
13120 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
13121 goto nla_put_failure
;
13123 nla_nest_end(msg
, attr
);
13125 genlmsg_end(msg
, hdr
);
13127 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13128 NL80211_MCGRP_MLME
, gfp
);
13132 genlmsg_cancel(msg
, hdr
);
13136 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
13137 const u8
*bssid
, bool preauth
, gfp_t gfp
)
13139 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13140 struct wiphy
*wiphy
= wdev
->wiphy
;
13141 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13143 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
13144 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
13146 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
13148 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
13149 struct net_device
*netdev
,
13150 struct cfg80211_chan_def
*chandef
,
13152 enum nl80211_commands notif
,
13155 struct sk_buff
*msg
;
13158 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13162 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
13168 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
13169 goto nla_put_failure
;
13171 if (nl80211_send_chandef(msg
, chandef
))
13172 goto nla_put_failure
;
13174 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
13175 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
13176 goto nla_put_failure
;
13178 genlmsg_end(msg
, hdr
);
13180 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13181 NL80211_MCGRP_MLME
, gfp
);
13185 genlmsg_cancel(msg
, hdr
);
13189 void cfg80211_ch_switch_notify(struct net_device
*dev
,
13190 struct cfg80211_chan_def
*chandef
)
13192 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13193 struct wiphy
*wiphy
= wdev
->wiphy
;
13194 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13196 ASSERT_WDEV_LOCK(wdev
);
13198 trace_cfg80211_ch_switch_notify(dev
, chandef
);
13200 wdev
->chandef
= *chandef
;
13201 wdev
->preset_chandef
= *chandef
;
13202 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
13203 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
13205 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
13207 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
13208 struct cfg80211_chan_def
*chandef
,
13211 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13212 struct wiphy
*wiphy
= wdev
->wiphy
;
13213 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13215 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
13217 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
13218 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
13220 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
13223 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
13224 const struct cfg80211_chan_def
*chandef
,
13225 enum nl80211_radar_event event
,
13226 struct net_device
*netdev
, gfp_t gfp
)
13228 struct sk_buff
*msg
;
13231 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13235 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
13241 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
13242 goto nla_put_failure
;
13244 /* NOP and radar events don't need a netdev parameter */
13246 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
13248 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13249 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13251 goto nla_put_failure
;
13254 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
13255 goto nla_put_failure
;
13257 if (nl80211_send_chandef(msg
, chandef
))
13258 goto nla_put_failure
;
13260 genlmsg_end(msg
, hdr
);
13262 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13263 NL80211_MCGRP_MLME
, gfp
);
13267 genlmsg_cancel(msg
, hdr
);
13271 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
13272 u64 cookie
, bool acked
, gfp_t gfp
)
13274 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13275 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13276 struct sk_buff
*msg
;
13279 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
13281 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13286 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
13292 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13293 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13294 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
13295 nla_put_u64_64bit(msg
, NL80211_ATTR_COOKIE
, cookie
,
13296 NL80211_ATTR_PAD
) ||
13297 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
13298 goto nla_put_failure
;
13300 genlmsg_end(msg
, hdr
);
13302 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13303 NL80211_MCGRP_MLME
, gfp
);
13307 genlmsg_cancel(msg
, hdr
);
13310 EXPORT_SYMBOL(cfg80211_probe_status
);
13312 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
13313 const u8
*frame
, size_t len
,
13314 int freq
, int sig_dbm
)
13316 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13317 struct sk_buff
*msg
;
13319 struct cfg80211_beacon_registration
*reg
;
13321 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
13323 spin_lock_bh(&rdev
->beacon_registrations_lock
);
13324 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
13325 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
13327 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
13331 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
13333 goto nla_put_failure
;
13335 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13337 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
13339 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
13340 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
13341 goto nla_put_failure
;
13343 genlmsg_end(msg
, hdr
);
13345 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
13347 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
13351 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
13353 genlmsg_cancel(msg
, hdr
);
13356 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
13359 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
13360 struct cfg80211_wowlan_wakeup
*wakeup
)
13362 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
13363 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
13366 nl_results
= nla_nest_start(
13367 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
13371 for (i
= 0; i
< nd
->n_matches
; i
++) {
13372 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
13374 nl_match
= nla_nest_start(msg
, i
);
13378 /* The SSID attribute is optional in nl80211, but for
13379 * simplicity reasons it's always present in the
13380 * cfg80211 structure. If a driver can't pass the
13381 * SSID, that needs to be changed. A zero length SSID
13382 * is still a valid SSID (wildcard), so it cannot be
13383 * used for this purpose.
13385 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
13386 match
->ssid
.ssid
)) {
13387 nla_nest_cancel(msg
, nl_match
);
13391 if (match
->n_channels
) {
13392 nl_freqs
= nla_nest_start(
13393 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
13395 nla_nest_cancel(msg
, nl_match
);
13399 for (j
= 0; j
< match
->n_channels
; j
++) {
13400 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
13401 nla_nest_cancel(msg
, nl_freqs
);
13402 nla_nest_cancel(msg
, nl_match
);
13407 nla_nest_end(msg
, nl_freqs
);
13410 nla_nest_end(msg
, nl_match
);
13414 nla_nest_end(msg
, nl_results
);
13418 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
13419 struct cfg80211_wowlan_wakeup
*wakeup
,
13422 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13423 struct sk_buff
*msg
;
13427 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
13430 size
+= wakeup
->packet_present_len
;
13432 msg
= nlmsg_new(size
, gfp
);
13436 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
13440 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13441 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13445 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13446 wdev
->netdev
->ifindex
))
13450 struct nlattr
*reasons
;
13452 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
13456 if (wakeup
->disconnect
&&
13457 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
13459 if (wakeup
->magic_pkt
&&
13460 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
13462 if (wakeup
->gtk_rekey_failure
&&
13463 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
13465 if (wakeup
->eap_identity_req
&&
13466 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
13468 if (wakeup
->four_way_handshake
&&
13469 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
13471 if (wakeup
->rfkill_release
&&
13472 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
13475 if (wakeup
->pattern_idx
>= 0 &&
13476 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
13477 wakeup
->pattern_idx
))
13480 if (wakeup
->tcp_match
&&
13481 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
13484 if (wakeup
->tcp_connlost
&&
13485 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
13488 if (wakeup
->tcp_nomoretokens
&&
13490 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
13493 if (wakeup
->packet
) {
13494 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
13495 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
13497 if (!wakeup
->packet_80211
) {
13499 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
13501 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
13504 if (wakeup
->packet_len
&&
13505 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
13508 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
13513 if (wakeup
->net_detect
&&
13514 cfg80211_net_detect_results(msg
, wakeup
))
13517 nla_nest_end(msg
, reasons
);
13520 genlmsg_end(msg
, hdr
);
13522 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13523 NL80211_MCGRP_MLME
, gfp
);
13529 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
13532 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
13533 enum nl80211_tdls_operation oper
,
13534 u16 reason_code
, gfp_t gfp
)
13536 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13537 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13538 struct sk_buff
*msg
;
13541 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
13544 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13548 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
13554 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13555 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13556 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
13557 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
13558 (reason_code
> 0 &&
13559 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
13560 goto nla_put_failure
;
13562 genlmsg_end(msg
, hdr
);
13564 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13565 NL80211_MCGRP_MLME
, gfp
);
13569 genlmsg_cancel(msg
, hdr
);
13572 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
13574 static int nl80211_netlink_notify(struct notifier_block
* nb
,
13575 unsigned long state
,
13578 struct netlink_notify
*notify
= _notify
;
13579 struct cfg80211_registered_device
*rdev
;
13580 struct wireless_dev
*wdev
;
13581 struct cfg80211_beacon_registration
*reg
, *tmp
;
13583 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
13584 return NOTIFY_DONE
;
13588 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
13589 bool schedule_destroy_work
= false;
13590 bool schedule_scan_stop
= false;
13591 struct cfg80211_sched_scan_request
*sched_scan_req
=
13592 rcu_dereference(rdev
->sched_scan_req
);
13594 if (sched_scan_req
&& notify
->portid
&&
13595 sched_scan_req
->owner_nlportid
== notify
->portid
)
13596 schedule_scan_stop
= true;
13598 list_for_each_entry_rcu(wdev
, &rdev
->wiphy
.wdev_list
, list
) {
13599 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
13601 if (wdev
->owner_nlportid
== notify
->portid
)
13602 schedule_destroy_work
= true;
13605 spin_lock_bh(&rdev
->beacon_registrations_lock
);
13606 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
13608 if (reg
->nlportid
== notify
->portid
) {
13609 list_del(®
->list
);
13614 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
13616 if (schedule_destroy_work
) {
13617 struct cfg80211_iface_destroy
*destroy
;
13619 destroy
= kzalloc(sizeof(*destroy
), GFP_ATOMIC
);
13621 destroy
->nlportid
= notify
->portid
;
13622 spin_lock(&rdev
->destroy_list_lock
);
13623 list_add(&destroy
->list
, &rdev
->destroy_list
);
13624 spin_unlock(&rdev
->destroy_list_lock
);
13625 schedule_work(&rdev
->destroy_work
);
13627 } else if (schedule_scan_stop
) {
13628 sched_scan_req
->owner_nlportid
= 0;
13630 if (rdev
->ops
->sched_scan_stop
&&
13631 rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
13632 schedule_work(&rdev
->sched_scan_stop_wk
);
13639 * It is possible that the user space process that is controlling the
13640 * indoor setting disappeared, so notify the regulatory core.
13642 regulatory_netlink_notify(notify
->portid
);
13646 static struct notifier_block nl80211_netlink_notifier
= {
13647 .notifier_call
= nl80211_netlink_notify
,
13650 void cfg80211_ft_event(struct net_device
*netdev
,
13651 struct cfg80211_ft_event_params
*ft_event
)
13653 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
13654 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13655 struct sk_buff
*msg
;
13658 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
13660 if (!ft_event
->target_ap
)
13663 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13667 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
13671 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13672 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13673 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
13676 if (ft_event
->ies
&&
13677 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
13679 if (ft_event
->ric_ies
&&
13680 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
13681 ft_event
->ric_ies
))
13684 genlmsg_end(msg
, hdr
);
13686 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13687 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13692 EXPORT_SYMBOL(cfg80211_ft_event
);
13694 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
13696 struct cfg80211_registered_device
*rdev
;
13697 struct sk_buff
*msg
;
13701 rdev
= wiphy_to_rdev(wdev
->wiphy
);
13702 if (!rdev
->crit_proto_nlportid
)
13705 nlportid
= rdev
->crit_proto_nlportid
;
13706 rdev
->crit_proto_nlportid
= 0;
13708 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13712 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
13714 goto nla_put_failure
;
13716 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13717 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13719 goto nla_put_failure
;
13721 genlmsg_end(msg
, hdr
);
13723 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
13728 genlmsg_cancel(msg
, hdr
);
13731 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
13733 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
13735 struct wiphy
*wiphy
= wdev
->wiphy
;
13736 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13737 struct sk_buff
*msg
;
13740 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13744 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
13748 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13749 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
13750 nla_put_u64_64bit(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
),
13754 genlmsg_end(msg
, hdr
);
13756 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
13757 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13763 /* initialisation/exit functions */
13765 int nl80211_init(void)
13769 err
= genl_register_family_with_ops_groups(&nl80211_fam
, nl80211_ops
,
13774 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
13780 genl_unregister_family(&nl80211_fam
);
13784 void nl80211_exit(void)
13786 netlink_unregister_notifier(&nl80211_netlink_notifier
);
13787 genl_unregister_family(&nl80211_fam
);