2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
22 #include <net/inet_connection_sock.h>
28 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
29 struct genl_info
*info
,
30 struct cfg80211_crypto_settings
*settings
,
33 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
34 struct genl_info
*info
);
35 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
38 /* the netlink family */
39 static struct genl_family nl80211_fam
= {
40 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
41 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
42 .hdrsize
= 0, /* no private header */
43 .version
= 1, /* no particular meaning now */
44 .maxattr
= NL80211_ATTR_MAX
,
46 .pre_doit
= nl80211_pre_doit
,
47 .post_doit
= nl80211_post_doit
,
50 /* multicast groups */
51 enum nl80211_multicast_groups
{
54 NL80211_MCGRP_REGULATORY
,
57 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
60 static const struct genl_multicast_group nl80211_mcgrps
[] = {
61 [NL80211_MCGRP_CONFIG
] = { .name
= "config", },
62 [NL80211_MCGRP_SCAN
] = { .name
= "scan", },
63 [NL80211_MCGRP_REGULATORY
] = { .name
= "regulatory", },
64 [NL80211_MCGRP_MLME
] = { .name
= "mlme", },
65 [NL80211_MCGRP_VENDOR
] = { .name
= "vendor", },
66 #ifdef CONFIG_NL80211_TESTMODE
67 [NL80211_MCGRP_TESTMODE
] = { .name
= "testmode", }
71 /* returns ERR_PTR values */
72 static struct wireless_dev
*
73 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
75 struct cfg80211_registered_device
*rdev
;
76 struct wireless_dev
*result
= NULL
;
77 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
78 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
85 if (!have_ifidx
&& !have_wdev_id
)
86 return ERR_PTR(-EINVAL
);
89 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
91 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
92 wiphy_idx
= wdev_id
>> 32;
95 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
96 struct wireless_dev
*wdev
;
98 if (wiphy_net(&rdev
->wiphy
) != netns
)
101 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
104 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
105 if (have_ifidx
&& wdev
->netdev
&&
106 wdev
->netdev
->ifindex
== ifidx
) {
110 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
122 return ERR_PTR(-ENODEV
);
125 static struct cfg80211_registered_device
*
126 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
128 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
129 struct net_device
*netdev
;
133 if (!attrs
[NL80211_ATTR_WIPHY
] &&
134 !attrs
[NL80211_ATTR_IFINDEX
] &&
135 !attrs
[NL80211_ATTR_WDEV
])
136 return ERR_PTR(-EINVAL
);
138 if (attrs
[NL80211_ATTR_WIPHY
])
139 rdev
= cfg80211_rdev_by_wiphy_idx(
140 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
142 if (attrs
[NL80211_ATTR_WDEV
]) {
143 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
144 struct wireless_dev
*wdev
;
147 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
149 /* make sure wdev exists */
150 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
151 if (wdev
->identifier
!= (u32
)wdev_id
)
160 if (rdev
&& tmp
!= rdev
)
161 return ERR_PTR(-EINVAL
);
166 if (attrs
[NL80211_ATTR_IFINDEX
]) {
167 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
168 netdev
= __dev_get_by_index(netns
, ifindex
);
170 if (netdev
->ieee80211_ptr
)
172 netdev
->ieee80211_ptr
->wiphy
);
176 /* not wireless device -- return error */
178 return ERR_PTR(-EINVAL
);
180 /* mismatch -- return error */
181 if (rdev
&& tmp
!= rdev
)
182 return ERR_PTR(-EINVAL
);
189 return ERR_PTR(-ENODEV
);
191 if (netns
!= wiphy_net(&rdev
->wiphy
))
192 return ERR_PTR(-ENODEV
);
198 * This function returns a pointer to the driver
199 * that the genl_info item that is passed refers to.
201 * The result of this can be a PTR_ERR and hence must
202 * be checked with IS_ERR() for errors.
204 static struct cfg80211_registered_device
*
205 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
207 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
210 /* policy for the attributes */
211 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
212 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
213 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
215 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
217 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
218 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
219 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
220 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
221 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
224 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
225 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
226 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
227 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
229 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
233 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
234 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
236 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
237 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
238 .len
= WLAN_MAX_KEY_LEN
},
239 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
240 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
241 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
242 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
243 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
245 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
246 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
247 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
248 .len
= IEEE80211_MAX_DATA_LEN
},
249 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
250 .len
= IEEE80211_MAX_DATA_LEN
},
251 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
252 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
253 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
254 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
255 .len
= NL80211_MAX_SUPP_RATES
},
256 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
257 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
258 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
259 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
260 .len
= IEEE80211_MAX_MESH_ID_LEN
},
261 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
263 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
264 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
266 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
267 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
268 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
269 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
270 .len
= NL80211_MAX_SUPP_RATES
},
271 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
273 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
274 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
276 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
278 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
279 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
280 .len
= IEEE80211_MAX_DATA_LEN
},
281 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
282 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
284 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
285 .len
= IEEE80211_MAX_SSID_LEN
},
286 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
287 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
288 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
289 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
290 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
291 [NL80211_ATTR_STA_FLAGS2
] = {
292 .len
= sizeof(struct nl80211_sta_flag_update
),
294 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
295 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
296 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
297 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
298 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
299 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
300 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
301 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
302 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
303 .len
= WLAN_PMKID_LEN
},
304 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
306 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
307 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
308 .len
= IEEE80211_MAX_DATA_LEN
},
309 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
310 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
312 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
313 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
314 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
315 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
317 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
318 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
319 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
321 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
322 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
323 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
324 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
325 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
326 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
327 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
328 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
329 .len
= IEEE80211_MAX_DATA_LEN
},
330 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
331 .len
= IEEE80211_MAX_DATA_LEN
},
332 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
333 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
334 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
335 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
336 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
337 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
338 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
339 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
340 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
341 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
342 .len
= IEEE80211_MAX_DATA_LEN
},
343 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
344 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
346 .len
= NL80211_HT_CAPABILITY_LEN
348 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
349 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
350 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
351 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
352 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
353 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
354 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
355 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
356 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
357 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
358 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
359 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
360 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
361 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
362 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
363 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
364 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
365 .len
= NL80211_VHT_CAPABILITY_LEN
,
367 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
368 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
369 .len
= IEEE80211_MAX_DATA_LEN
},
370 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
371 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
372 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
373 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
374 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_U16
},
375 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_U16
},
376 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
377 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
378 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
379 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
380 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
381 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
382 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
384 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
385 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
386 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
387 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
388 [NL80211_ATTR_IFACE_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
391 /* policy for the key attributes */
392 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
393 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
394 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
395 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
396 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
397 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
398 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
399 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
400 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
403 /* policy for the key default flags */
404 static const struct nla_policy
405 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
406 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
407 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
410 /* policy for WoWLAN attributes */
411 static const struct nla_policy
412 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
413 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
414 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
415 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
416 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
417 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
418 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
419 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
420 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
421 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
424 static const struct nla_policy
425 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
426 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
427 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
428 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
429 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
430 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
431 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
432 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
433 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
435 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
436 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
438 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
439 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
440 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
443 /* policy for coalesce rule attributes */
444 static const struct nla_policy
445 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
446 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
447 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
448 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
451 /* policy for GTK rekey offload attributes */
452 static const struct nla_policy
453 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
454 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
455 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
456 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
459 static const struct nla_policy
460 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
461 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
462 .len
= IEEE80211_MAX_SSID_LEN
},
463 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
466 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
467 struct netlink_callback
*cb
,
468 struct cfg80211_registered_device
**rdev
,
469 struct wireless_dev
**wdev
)
476 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
477 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
482 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
483 nl80211_fam
.attrbuf
);
485 err
= PTR_ERR(*wdev
);
488 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
489 /* 0 is the first index - add 1 to parse only once */
490 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
491 cb
->args
[1] = (*wdev
)->identifier
;
493 /* subtract the 1 again here */
494 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
495 struct wireless_dev
*tmp
;
501 *rdev
= wiphy_to_dev(wiphy
);
504 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
505 if (tmp
->identifier
== cb
->args
[1]) {
523 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
529 static bool is_valid_ie_attr(const struct nlattr
*attr
)
537 pos
= nla_data(attr
);
558 /* message building helper */
559 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
562 /* since there is no private header just add the generic one */
563 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
566 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
567 struct ieee80211_channel
*chan
,
570 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
572 goto nla_put_failure
;
574 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
575 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
576 goto nla_put_failure
;
577 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
578 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
579 goto nla_put_failure
;
580 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
581 goto nla_put_failure
;
583 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
584 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
585 goto nla_put_failure
;
589 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
591 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
593 goto nla_put_failure
;
594 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
596 goto nla_put_failure
;
598 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
600 goto nla_put_failure
;
605 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
606 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
607 goto nla_put_failure
;
608 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
609 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
610 goto nla_put_failure
;
611 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
612 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
613 goto nla_put_failure
;
614 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
615 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
616 goto nla_put_failure
;
617 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
618 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
619 goto nla_put_failure
;
620 if ((chan
->flags
& IEEE80211_CHAN_GO_CONCURRENT
) &&
621 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_GO_CONCURRENT
))
622 goto nla_put_failure
;
625 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
626 DBM_TO_MBM(chan
->max_power
)))
627 goto nla_put_failure
;
635 /* netlink command implementations */
642 bool def_uni
, def_multi
;
645 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
647 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
648 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
653 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
654 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
663 if (tb
[NL80211_KEY_IDX
])
664 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
666 if (tb
[NL80211_KEY_DATA
]) {
667 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
668 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
671 if (tb
[NL80211_KEY_SEQ
]) {
672 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
673 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
676 if (tb
[NL80211_KEY_CIPHER
])
677 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
679 if (tb
[NL80211_KEY_TYPE
]) {
680 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
681 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
685 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
686 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
687 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
688 tb
[NL80211_KEY_DEFAULT_TYPES
],
689 nl80211_key_default_policy
);
693 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
694 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
700 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
702 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
703 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
704 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
707 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
708 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
709 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
712 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
713 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
715 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
716 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
718 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
719 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
728 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
729 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
730 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
734 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
735 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
736 int err
= nla_parse_nested(
737 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
738 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
739 nl80211_key_default_policy
);
743 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
744 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
750 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
754 memset(k
, 0, sizeof(*k
));
758 if (info
->attrs
[NL80211_ATTR_KEY
])
759 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
761 err
= nl80211_parse_key_old(info
, k
);
766 if (k
->def
&& k
->defmgmt
)
770 if (k
->def_uni
|| !k
->def_multi
)
776 if (k
->idx
< 4 || k
->idx
> 5)
779 if (k
->idx
< 0 || k
->idx
> 3)
782 if (k
->idx
< 0 || k
->idx
> 5)
790 static struct cfg80211_cached_keys
*
791 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
792 struct nlattr
*keys
, bool *no_ht
)
794 struct key_parse parse
;
796 struct cfg80211_cached_keys
*result
;
797 int rem
, err
, def
= 0;
799 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
801 return ERR_PTR(-ENOMEM
);
804 result
->defmgmt
= -1;
806 nla_for_each_nested(key
, keys
, rem
) {
807 memset(&parse
, 0, sizeof(parse
));
810 err
= nl80211_parse_key_new(key
, &parse
);
816 if (parse
.idx
< 0 || parse
.idx
> 4)
822 result
->def
= parse
.idx
;
823 if (!parse
.def_uni
|| !parse
.def_multi
)
825 } else if (parse
.defmgmt
)
827 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
828 parse
.idx
, false, NULL
);
831 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
832 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
833 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
834 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
836 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
837 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
849 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
851 ASSERT_WDEV_LOCK(wdev
);
853 switch (wdev
->iftype
) {
854 case NL80211_IFTYPE_AP
:
855 case NL80211_IFTYPE_AP_VLAN
:
856 case NL80211_IFTYPE_P2P_GO
:
857 case NL80211_IFTYPE_MESH_POINT
:
859 case NL80211_IFTYPE_ADHOC
:
860 case NL80211_IFTYPE_STATION
:
861 case NL80211_IFTYPE_P2P_CLIENT
:
862 if (!wdev
->current_bss
)
872 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
875 struct ieee80211_channel
*chan
;
879 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
880 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
885 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
887 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
891 goto nla_put_failure
;
895 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
896 goto nla_put_failure
;
901 nla_nest_end(msg
, nl_modes
);
908 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
912 struct nlattr
*nl_combis
;
915 nl_combis
= nla_nest_start(msg
,
916 NL80211_ATTR_INTERFACE_COMBINATIONS
);
918 goto nla_put_failure
;
920 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
921 const struct ieee80211_iface_combination
*c
;
922 struct nlattr
*nl_combi
, *nl_limits
;
924 c
= &wiphy
->iface_combinations
[i
];
926 nl_combi
= nla_nest_start(msg
, i
+ 1);
928 goto nla_put_failure
;
930 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
932 goto nla_put_failure
;
934 for (j
= 0; j
< c
->n_limits
; j
++) {
935 struct nlattr
*nl_limit
;
937 nl_limit
= nla_nest_start(msg
, j
+ 1);
939 goto nla_put_failure
;
940 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
942 goto nla_put_failure
;
943 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
945 goto nla_put_failure
;
946 nla_nest_end(msg
, nl_limit
);
949 nla_nest_end(msg
, nl_limits
);
951 if (c
->beacon_int_infra_match
&&
952 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
953 goto nla_put_failure
;
954 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
955 c
->num_different_channels
) ||
956 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
958 goto nla_put_failure
;
960 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
961 c
->radar_detect_widths
))
962 goto nla_put_failure
;
964 nla_nest_end(msg
, nl_combi
);
967 nla_nest_end(msg
, nl_combis
);
975 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
978 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
979 struct nlattr
*nl_tcp
;
984 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
988 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
989 tcp
->data_payload_max
))
992 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
993 tcp
->data_payload_max
))
996 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
999 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1000 sizeof(*tcp
->tok
), tcp
->tok
))
1003 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1004 tcp
->data_interval_max
))
1007 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1008 tcp
->wake_payload_max
))
1011 nla_nest_end(msg
, nl_tcp
);
1015 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1016 struct cfg80211_registered_device
*dev
,
1019 struct nlattr
*nl_wowlan
;
1021 if (!dev
->wiphy
.wowlan
)
1024 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1028 if (((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1029 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1030 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1031 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1032 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1033 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1034 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1035 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1036 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1037 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1038 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1039 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1040 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1041 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1042 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1043 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1046 if (dev
->wiphy
.wowlan
->n_patterns
) {
1047 struct nl80211_pattern_support pat
= {
1048 .max_patterns
= dev
->wiphy
.wowlan
->n_patterns
,
1049 .min_pattern_len
= dev
->wiphy
.wowlan
->pattern_min_len
,
1050 .max_pattern_len
= dev
->wiphy
.wowlan
->pattern_max_len
,
1051 .max_pkt_offset
= dev
->wiphy
.wowlan
->max_pkt_offset
,
1054 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1059 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
1062 nla_nest_end(msg
, nl_wowlan
);
1068 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1069 struct cfg80211_registered_device
*dev
)
1071 struct nl80211_coalesce_rule_support rule
;
1073 if (!dev
->wiphy
.coalesce
)
1076 rule
.max_rules
= dev
->wiphy
.coalesce
->n_rules
;
1077 rule
.max_delay
= dev
->wiphy
.coalesce
->max_delay
;
1078 rule
.pat
.max_patterns
= dev
->wiphy
.coalesce
->n_patterns
;
1079 rule
.pat
.min_pattern_len
= dev
->wiphy
.coalesce
->pattern_min_len
;
1080 rule
.pat
.max_pattern_len
= dev
->wiphy
.coalesce
->pattern_max_len
;
1081 rule
.pat
.max_pkt_offset
= dev
->wiphy
.coalesce
->max_pkt_offset
;
1083 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1089 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1090 struct ieee80211_supported_band
*sband
)
1092 struct nlattr
*nl_rates
, *nl_rate
;
1093 struct ieee80211_rate
*rate
;
1097 if (sband
->ht_cap
.ht_supported
&&
1098 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1099 sizeof(sband
->ht_cap
.mcs
),
1100 &sband
->ht_cap
.mcs
) ||
1101 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1102 sband
->ht_cap
.cap
) ||
1103 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1104 sband
->ht_cap
.ampdu_factor
) ||
1105 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1106 sband
->ht_cap
.ampdu_density
)))
1110 if (sband
->vht_cap
.vht_supported
&&
1111 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1112 sizeof(sband
->vht_cap
.vht_mcs
),
1113 &sband
->vht_cap
.vht_mcs
) ||
1114 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1115 sband
->vht_cap
.cap
)))
1119 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1123 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1124 nl_rate
= nla_nest_start(msg
, i
);
1128 rate
= &sband
->bitrates
[i
];
1129 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1132 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1134 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1137 nla_nest_end(msg
, nl_rate
);
1140 nla_nest_end(msg
, nl_rates
);
1146 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1147 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1150 struct nlattr
*nl_ftypes
, *nl_ifs
;
1151 enum nl80211_iftype ift
;
1157 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1161 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1162 nl_ftypes
= nla_nest_start(msg
, ift
);
1166 stypes
= mgmt_stypes
[ift
].tx
;
1169 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1170 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1175 nla_nest_end(msg
, nl_ftypes
);
1178 nla_nest_end(msg
, nl_ifs
);
1180 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1184 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1185 nl_ftypes
= nla_nest_start(msg
, ift
);
1189 stypes
= mgmt_stypes
[ift
].rx
;
1192 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1193 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1198 nla_nest_end(msg
, nl_ftypes
);
1200 nla_nest_end(msg
, nl_ifs
);
1205 struct nl80211_dump_wiphy_state
{
1208 long split_start
, band_start
, chan_start
;
1212 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1213 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1214 int flags
, struct nl80211_dump_wiphy_state
*state
)
1217 struct nlattr
*nl_bands
, *nl_band
;
1218 struct nlattr
*nl_freqs
, *nl_freq
;
1219 struct nlattr
*nl_cmds
;
1220 enum ieee80211_band band
;
1221 struct ieee80211_channel
*chan
;
1223 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1224 dev
->wiphy
.mgmt_stypes
;
1227 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1231 if (WARN_ON(!state
))
1234 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1235 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1236 wiphy_name(&dev
->wiphy
)) ||
1237 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1238 cfg80211_rdev_list_generation
))
1239 goto nla_put_failure
;
1241 switch (state
->split_start
) {
1243 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1244 dev
->wiphy
.retry_short
) ||
1245 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1246 dev
->wiphy
.retry_long
) ||
1247 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1248 dev
->wiphy
.frag_threshold
) ||
1249 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1250 dev
->wiphy
.rts_threshold
) ||
1251 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1252 dev
->wiphy
.coverage_class
) ||
1253 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1254 dev
->wiphy
.max_scan_ssids
) ||
1255 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1256 dev
->wiphy
.max_sched_scan_ssids
) ||
1257 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1258 dev
->wiphy
.max_scan_ie_len
) ||
1259 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1260 dev
->wiphy
.max_sched_scan_ie_len
) ||
1261 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1262 dev
->wiphy
.max_match_sets
))
1263 goto nla_put_failure
;
1265 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1266 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1267 goto nla_put_failure
;
1268 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1269 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1270 goto nla_put_failure
;
1271 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1272 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1273 goto nla_put_failure
;
1274 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1275 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1276 goto nla_put_failure
;
1277 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1278 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1279 goto nla_put_failure
;
1280 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1281 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1282 goto nla_put_failure
;
1283 state
->split_start
++;
1287 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1288 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1289 dev
->wiphy
.cipher_suites
))
1290 goto nla_put_failure
;
1292 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1293 dev
->wiphy
.max_num_pmkids
))
1294 goto nla_put_failure
;
1296 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1297 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1298 goto nla_put_failure
;
1300 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1301 dev
->wiphy
.available_antennas_tx
) ||
1302 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1303 dev
->wiphy
.available_antennas_rx
))
1304 goto nla_put_failure
;
1306 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1307 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1308 dev
->wiphy
.probe_resp_offload
))
1309 goto nla_put_failure
;
1311 if ((dev
->wiphy
.available_antennas_tx
||
1312 dev
->wiphy
.available_antennas_rx
) &&
1313 dev
->ops
->get_antenna
) {
1314 u32 tx_ant
= 0, rx_ant
= 0;
1316 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1318 if (nla_put_u32(msg
,
1319 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1322 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1324 goto nla_put_failure
;
1328 state
->split_start
++;
1332 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1333 dev
->wiphy
.interface_modes
))
1334 goto nla_put_failure
;
1335 state
->split_start
++;
1339 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1341 goto nla_put_failure
;
1343 for (band
= state
->band_start
;
1344 band
< IEEE80211_NUM_BANDS
; band
++) {
1345 struct ieee80211_supported_band
*sband
;
1347 sband
= dev
->wiphy
.bands
[band
];
1352 nl_band
= nla_nest_start(msg
, band
);
1354 goto nla_put_failure
;
1356 switch (state
->chan_start
) {
1358 if (nl80211_send_band_rateinfo(msg
, sband
))
1359 goto nla_put_failure
;
1360 state
->chan_start
++;
1364 /* add frequencies */
1365 nl_freqs
= nla_nest_start(
1366 msg
, NL80211_BAND_ATTR_FREQS
);
1368 goto nla_put_failure
;
1370 for (i
= state
->chan_start
- 1;
1371 i
< sband
->n_channels
;
1373 nl_freq
= nla_nest_start(msg
, i
);
1375 goto nla_put_failure
;
1377 chan
= &sband
->channels
[i
];
1379 if (nl80211_msg_put_channel(
1382 goto nla_put_failure
;
1384 nla_nest_end(msg
, nl_freq
);
1388 if (i
< sband
->n_channels
)
1389 state
->chan_start
= i
+ 2;
1391 state
->chan_start
= 0;
1392 nla_nest_end(msg
, nl_freqs
);
1395 nla_nest_end(msg
, nl_band
);
1398 /* start again here */
1399 if (state
->chan_start
)
1404 nla_nest_end(msg
, nl_bands
);
1406 if (band
< IEEE80211_NUM_BANDS
)
1407 state
->band_start
= band
+ 1;
1409 state
->band_start
= 0;
1411 /* if bands & channels are done, continue outside */
1412 if (state
->band_start
== 0 && state
->chan_start
== 0)
1413 state
->split_start
++;
1417 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1419 goto nla_put_failure
;
1422 #define CMD(op, n) \
1424 if (dev->ops->op) { \
1426 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1427 goto nla_put_failure; \
1431 CMD(add_virtual_intf
, NEW_INTERFACE
);
1432 CMD(change_virtual_intf
, SET_INTERFACE
);
1433 CMD(add_key
, NEW_KEY
);
1434 CMD(start_ap
, START_AP
);
1435 CMD(add_station
, NEW_STATION
);
1436 CMD(add_mpath
, NEW_MPATH
);
1437 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1438 CMD(change_bss
, SET_BSS
);
1439 CMD(auth
, AUTHENTICATE
);
1440 CMD(assoc
, ASSOCIATE
);
1441 CMD(deauth
, DEAUTHENTICATE
);
1442 CMD(disassoc
, DISASSOCIATE
);
1443 CMD(join_ibss
, JOIN_IBSS
);
1444 CMD(join_mesh
, JOIN_MESH
);
1445 CMD(set_pmksa
, SET_PMKSA
);
1446 CMD(del_pmksa
, DEL_PMKSA
);
1447 CMD(flush_pmksa
, FLUSH_PMKSA
);
1448 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1449 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1450 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1451 CMD(mgmt_tx
, FRAME
);
1452 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1453 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1455 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1456 goto nla_put_failure
;
1458 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1459 dev
->ops
->join_mesh
) {
1461 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1462 goto nla_put_failure
;
1464 CMD(set_wds_peer
, SET_WDS_PEER
);
1465 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1466 CMD(tdls_mgmt
, TDLS_MGMT
);
1467 CMD(tdls_oper
, TDLS_OPER
);
1469 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1470 CMD(sched_scan_start
, START_SCHED_SCAN
);
1471 CMD(probe_client
, PROBE_CLIENT
);
1472 CMD(set_noack_map
, SET_NOACK_MAP
);
1473 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1475 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1476 goto nla_put_failure
;
1478 CMD(start_p2p_device
, START_P2P_DEVICE
);
1479 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1481 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1482 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1483 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1484 CMD(channel_switch
, CHANNEL_SWITCH
);
1486 CMD(set_qos_map
, SET_QOS_MAP
);
1488 #ifdef CONFIG_NL80211_TESTMODE
1489 CMD(testmode_cmd
, TESTMODE
);
1494 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1496 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1497 goto nla_put_failure
;
1500 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1502 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1503 goto nla_put_failure
;
1506 nla_nest_end(msg
, nl_cmds
);
1507 state
->split_start
++;
1511 if (dev
->ops
->remain_on_channel
&&
1512 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1514 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1515 dev
->wiphy
.max_remain_on_channel_duration
))
1516 goto nla_put_failure
;
1518 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1519 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1520 goto nla_put_failure
;
1522 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1523 goto nla_put_failure
;
1524 state
->split_start
++;
1529 if (nl80211_send_wowlan(msg
, dev
, state
->split
))
1530 goto nla_put_failure
;
1531 state
->split_start
++;
1535 state
->split_start
++;
1538 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1539 dev
->wiphy
.software_iftypes
))
1540 goto nla_put_failure
;
1542 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
,
1544 goto nla_put_failure
;
1546 state
->split_start
++;
1550 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1551 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1552 dev
->wiphy
.ap_sme_capa
))
1553 goto nla_put_failure
;
1555 features
= dev
->wiphy
.features
;
1557 * We can only add the per-channel limit information if the
1558 * dump is split, otherwise it makes it too big. Therefore
1559 * only advertise it in that case.
1562 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1563 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1564 goto nla_put_failure
;
1566 if (dev
->wiphy
.ht_capa_mod_mask
&&
1567 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1568 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1569 dev
->wiphy
.ht_capa_mod_mask
))
1570 goto nla_put_failure
;
1572 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1573 dev
->wiphy
.max_acl_mac_addrs
&&
1574 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1575 dev
->wiphy
.max_acl_mac_addrs
))
1576 goto nla_put_failure
;
1579 * Any information below this point is only available to
1580 * applications that can deal with it being split. This
1581 * helps ensure that newly added capabilities don't break
1582 * older tools by overrunning their buffers.
1584 * We still increment split_start so that in the split
1585 * case we'll continue with more data in the next round,
1586 * but break unconditionally so unsplit data stops here.
1588 state
->split_start
++;
1591 if (dev
->wiphy
.extended_capabilities
&&
1592 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1593 dev
->wiphy
.extended_capabilities_len
,
1594 dev
->wiphy
.extended_capabilities
) ||
1595 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1596 dev
->wiphy
.extended_capabilities_len
,
1597 dev
->wiphy
.extended_capabilities_mask
)))
1598 goto nla_put_failure
;
1600 if (dev
->wiphy
.vht_capa_mod_mask
&&
1601 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1602 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1603 dev
->wiphy
.vht_capa_mod_mask
))
1604 goto nla_put_failure
;
1606 state
->split_start
++;
1609 if (nl80211_send_coalesce(msg
, dev
))
1610 goto nla_put_failure
;
1612 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1613 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1614 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1615 goto nla_put_failure
;
1617 if (dev
->wiphy
.max_ap_assoc_sta
&&
1618 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1619 dev
->wiphy
.max_ap_assoc_sta
))
1620 goto nla_put_failure
;
1622 state
->split_start
++;
1625 if (dev
->wiphy
.n_vendor_commands
) {
1626 const struct nl80211_vendor_cmd_info
*info
;
1627 struct nlattr
*nested
;
1629 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1631 goto nla_put_failure
;
1633 for (i
= 0; i
< dev
->wiphy
.n_vendor_commands
; i
++) {
1634 info
= &dev
->wiphy
.vendor_commands
[i
].info
;
1635 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1636 goto nla_put_failure
;
1638 nla_nest_end(msg
, nested
);
1641 if (dev
->wiphy
.n_vendor_events
) {
1642 const struct nl80211_vendor_cmd_info
*info
;
1643 struct nlattr
*nested
;
1645 nested
= nla_nest_start(msg
,
1646 NL80211_ATTR_VENDOR_EVENTS
);
1648 goto nla_put_failure
;
1650 for (i
= 0; i
< dev
->wiphy
.n_vendor_events
; i
++) {
1651 info
= &dev
->wiphy
.vendor_events
[i
];
1652 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1653 goto nla_put_failure
;
1655 nla_nest_end(msg
, nested
);
1659 state
->split_start
= 0;
1662 return genlmsg_end(msg
, hdr
);
1665 genlmsg_cancel(msg
, hdr
);
1669 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1670 struct netlink_callback
*cb
,
1671 struct nl80211_dump_wiphy_state
*state
)
1673 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1674 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1675 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1676 /* ignore parse errors for backward compatibility */
1680 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1681 if (tb
[NL80211_ATTR_WIPHY
])
1682 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1683 if (tb
[NL80211_ATTR_WDEV
])
1684 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1685 if (tb
[NL80211_ATTR_IFINDEX
]) {
1686 struct net_device
*netdev
;
1687 struct cfg80211_registered_device
*rdev
;
1688 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1690 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1693 if (netdev
->ieee80211_ptr
) {
1694 rdev
= wiphy_to_dev(
1695 netdev
->ieee80211_ptr
->wiphy
);
1696 state
->filter_wiphy
= rdev
->wiphy_idx
;
1703 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1706 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1707 struct cfg80211_registered_device
*dev
;
1711 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1716 state
->filter_wiphy
= -1;
1717 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1723 cb
->args
[0] = (long)state
;
1726 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1727 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1729 if (++idx
<= state
->start
)
1731 if (state
->filter_wiphy
!= -1 &&
1732 state
->filter_wiphy
!= dev
->wiphy_idx
)
1734 /* attempt to fit multiple wiphy data chunks into the skb */
1736 ret
= nl80211_send_wiphy(dev
, skb
,
1737 NETLINK_CB(cb
->skb
).portid
,
1739 NLM_F_MULTI
, state
);
1742 * If sending the wiphy data didn't fit (ENOBUFS
1743 * or EMSGSIZE returned), this SKB is still
1744 * empty (so it's not too big because another
1745 * wiphy dataset is already in the skb) and
1746 * we've not tried to adjust the dump allocation
1747 * yet ... then adjust the alloc size to be
1748 * bigger, and return 1 but with the empty skb.
1749 * This results in an empty message being RX'ed
1750 * in userspace, but that is ignored.
1752 * We can then retry with the larger buffer.
1754 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1755 !skb
->len
&& !state
->split
&&
1756 cb
->min_dump_alloc
< 4096) {
1757 cb
->min_dump_alloc
= 4096;
1758 state
->split_start
= 0;
1765 } while (state
->split_start
> 0);
1775 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1777 kfree((void *)cb
->args
[0]);
1781 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1783 struct sk_buff
*msg
;
1784 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1785 struct nl80211_dump_wiphy_state state
= {};
1787 msg
= nlmsg_new(4096, GFP_KERNEL
);
1791 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1797 return genlmsg_reply(msg
, info
);
1800 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1801 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1802 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1803 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1804 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1805 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1808 static int parse_txq_params(struct nlattr
*tb
[],
1809 struct ieee80211_txq_params
*txq_params
)
1811 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1812 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1813 !tb
[NL80211_TXQ_ATTR_AIFS
])
1816 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1817 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1818 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1819 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1820 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1822 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1828 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1831 * You can only set the channel explicitly for WDS interfaces,
1832 * all others have their channel managed via their respective
1833 * "establish a connection" command (connect, join, ...)
1835 * For AP/GO and mesh mode, the channel can be set with the
1836 * channel userspace API, but is only stored and passed to the
1837 * low-level driver when the AP starts or the mesh is joined.
1838 * This is for backward compatibility, userspace can also give
1839 * the channel in the start-ap or join-mesh commands instead.
1841 * Monitors are special as they are normally slaved to
1842 * whatever else is going on, so they have their own special
1843 * operation to set the monitor channel if possible.
1846 wdev
->iftype
== NL80211_IFTYPE_AP
||
1847 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1848 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1849 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1852 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1853 struct genl_info
*info
,
1854 struct cfg80211_chan_def
*chandef
)
1858 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1861 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1863 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1864 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1865 chandef
->center_freq1
= control_freq
;
1866 chandef
->center_freq2
= 0;
1868 /* Primary channel not allowed */
1869 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1872 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1873 enum nl80211_channel_type chantype
;
1875 chantype
= nla_get_u32(
1876 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1879 case NL80211_CHAN_NO_HT
:
1880 case NL80211_CHAN_HT20
:
1881 case NL80211_CHAN_HT40PLUS
:
1882 case NL80211_CHAN_HT40MINUS
:
1883 cfg80211_chandef_create(chandef
, chandef
->chan
,
1889 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1891 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1892 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1893 chandef
->center_freq1
=
1895 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1896 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1897 chandef
->center_freq2
=
1899 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1902 if (!cfg80211_chandef_valid(chandef
))
1905 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1906 IEEE80211_CHAN_DISABLED
))
1909 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1910 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1911 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1917 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1918 struct wireless_dev
*wdev
,
1919 struct genl_info
*info
)
1921 struct cfg80211_chan_def chandef
;
1923 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1926 iftype
= wdev
->iftype
;
1928 if (!nl80211_can_set_dev_channel(wdev
))
1931 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1936 case NL80211_IFTYPE_AP
:
1937 case NL80211_IFTYPE_P2P_GO
:
1938 if (wdev
->beacon_interval
) {
1942 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
, iftype
)) {
1946 wdev
->preset_chandef
= chandef
;
1949 case NL80211_IFTYPE_MESH_POINT
:
1950 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1952 case NL80211_IFTYPE_MONITOR
:
1953 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1962 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1964 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1965 struct net_device
*netdev
= info
->user_ptr
[1];
1967 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1970 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1972 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1973 struct net_device
*dev
= info
->user_ptr
[1];
1974 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1977 if (!info
->attrs
[NL80211_ATTR_MAC
])
1980 if (netif_running(dev
))
1983 if (!rdev
->ops
->set_wds_peer
)
1986 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1989 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1990 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1994 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1996 struct cfg80211_registered_device
*rdev
;
1997 struct net_device
*netdev
= NULL
;
1998 struct wireless_dev
*wdev
;
1999 int result
= 0, rem_txq_params
= 0;
2000 struct nlattr
*nl_txq_params
;
2002 u8 retry_short
= 0, retry_long
= 0;
2003 u32 frag_threshold
= 0, rts_threshold
= 0;
2004 u8 coverage_class
= 0;
2009 * Try to find the wiphy and netdev. Normally this
2010 * function shouldn't need the netdev, but this is
2011 * done for backward compatibility -- previously
2012 * setting the channel was done per wiphy, but now
2013 * it is per netdev. Previous userland like hostapd
2014 * also passed a netdev to set_wiphy, so that it is
2015 * possible to let that go to the right netdev!
2018 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2019 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2021 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2022 if (netdev
&& netdev
->ieee80211_ptr
)
2023 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
2029 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2032 return PTR_ERR(rdev
);
2037 wdev
= netdev
->ieee80211_ptr
;
2040 * end workaround code, by now the rdev is available
2041 * and locked, and wdev may or may not be NULL.
2044 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2045 result
= cfg80211_dev_rename(
2046 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2051 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2052 struct ieee80211_txq_params txq_params
;
2053 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2055 if (!rdev
->ops
->set_txq_params
)
2061 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2062 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2065 if (!netif_running(netdev
))
2068 nla_for_each_nested(nl_txq_params
,
2069 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2071 result
= nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
2072 nla_data(nl_txq_params
),
2073 nla_len(nl_txq_params
),
2077 result
= parse_txq_params(tb
, &txq_params
);
2081 result
= rdev_set_txq_params(rdev
, netdev
,
2088 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2089 result
= __nl80211_set_channel(rdev
,
2090 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
2096 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2097 struct wireless_dev
*txp_wdev
= wdev
;
2098 enum nl80211_tx_power_setting type
;
2101 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2104 if (!rdev
->ops
->set_tx_power
)
2107 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2108 type
= nla_get_u32(info
->attrs
[idx
]);
2110 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2111 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2114 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2115 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2116 mbm
= nla_get_u32(info
->attrs
[idx
]);
2119 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2124 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2125 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2127 if ((!rdev
->wiphy
.available_antennas_tx
&&
2128 !rdev
->wiphy
.available_antennas_rx
) ||
2129 !rdev
->ops
->set_antenna
)
2132 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2133 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2135 /* reject antenna configurations which don't match the
2136 * available antenna masks, except for the "all" mask */
2137 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2138 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2141 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2142 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2144 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2151 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2152 retry_short
= nla_get_u8(
2153 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2154 if (retry_short
== 0)
2157 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2160 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2161 retry_long
= nla_get_u8(
2162 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2163 if (retry_long
== 0)
2166 changed
|= WIPHY_PARAM_RETRY_LONG
;
2169 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2170 frag_threshold
= nla_get_u32(
2171 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2172 if (frag_threshold
< 256)
2175 if (frag_threshold
!= (u32
) -1) {
2177 * Fragments (apart from the last one) are required to
2178 * have even length. Make the fragmentation code
2179 * simpler by stripping LSB should someone try to use
2180 * odd threshold value.
2182 frag_threshold
&= ~0x1;
2184 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2187 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2188 rts_threshold
= nla_get_u32(
2189 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2190 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2193 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2194 coverage_class
= nla_get_u8(
2195 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2196 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2200 u8 old_retry_short
, old_retry_long
;
2201 u32 old_frag_threshold
, old_rts_threshold
;
2202 u8 old_coverage_class
;
2204 if (!rdev
->ops
->set_wiphy_params
)
2207 old_retry_short
= rdev
->wiphy
.retry_short
;
2208 old_retry_long
= rdev
->wiphy
.retry_long
;
2209 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2210 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2211 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2213 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2214 rdev
->wiphy
.retry_short
= retry_short
;
2215 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2216 rdev
->wiphy
.retry_long
= retry_long
;
2217 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2218 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2219 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2220 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2221 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2222 rdev
->wiphy
.coverage_class
= coverage_class
;
2224 result
= rdev_set_wiphy_params(rdev
, changed
);
2226 rdev
->wiphy
.retry_short
= old_retry_short
;
2227 rdev
->wiphy
.retry_long
= old_retry_long
;
2228 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2229 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2230 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2236 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2238 return (u64
)wdev
->identifier
|
2239 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2242 static int nl80211_send_chandef(struct sk_buff
*msg
,
2243 const struct cfg80211_chan_def
*chandef
)
2245 WARN_ON(!cfg80211_chandef_valid(chandef
));
2247 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2248 chandef
->chan
->center_freq
))
2250 switch (chandef
->width
) {
2251 case NL80211_CHAN_WIDTH_20_NOHT
:
2252 case NL80211_CHAN_WIDTH_20
:
2253 case NL80211_CHAN_WIDTH_40
:
2254 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2255 cfg80211_get_chandef_type(chandef
)))
2261 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2263 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2265 if (chandef
->center_freq2
&&
2266 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2271 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2272 struct cfg80211_registered_device
*rdev
,
2273 struct wireless_dev
*wdev
)
2275 struct net_device
*dev
= wdev
->netdev
;
2278 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2283 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2284 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2285 goto nla_put_failure
;
2287 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2288 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2289 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2290 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2291 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2292 rdev
->devlist_generation
^
2293 (cfg80211_rdev_list_generation
<< 2)))
2294 goto nla_put_failure
;
2296 if (rdev
->ops
->get_channel
) {
2298 struct cfg80211_chan_def chandef
;
2300 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2302 if (nl80211_send_chandef(msg
, &chandef
))
2303 goto nla_put_failure
;
2307 if (wdev
->ssid_len
) {
2308 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2309 goto nla_put_failure
;
2312 return genlmsg_end(msg
, hdr
);
2315 genlmsg_cancel(msg
, hdr
);
2319 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2323 int wp_start
= cb
->args
[0];
2324 int if_start
= cb
->args
[1];
2325 struct cfg80211_registered_device
*rdev
;
2326 struct wireless_dev
*wdev
;
2329 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2330 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2332 if (wp_idx
< wp_start
) {
2338 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2339 if (if_idx
< if_start
) {
2343 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2344 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2356 cb
->args
[0] = wp_idx
;
2357 cb
->args
[1] = if_idx
;
2362 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2364 struct sk_buff
*msg
;
2365 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2366 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2368 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2372 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2378 return genlmsg_reply(msg
, info
);
2381 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2382 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2383 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2384 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2385 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2386 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2387 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2390 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2392 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2400 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2401 nla
, mntr_flags_policy
))
2404 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2406 *mntrflags
|= (1<<flag
);
2411 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2412 struct net_device
*netdev
, u8 use_4addr
,
2413 enum nl80211_iftype iftype
)
2416 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2422 case NL80211_IFTYPE_AP_VLAN
:
2423 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2426 case NL80211_IFTYPE_STATION
:
2427 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2437 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2439 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2440 struct vif_params params
;
2442 enum nl80211_iftype otype
, ntype
;
2443 struct net_device
*dev
= info
->user_ptr
[1];
2444 u32 _flags
, *flags
= NULL
;
2445 bool change
= false;
2447 memset(¶ms
, 0, sizeof(params
));
2449 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2451 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2452 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2455 if (ntype
> NL80211_IFTYPE_MAX
)
2459 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2460 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2462 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2464 if (netif_running(dev
))
2468 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2469 IEEE80211_MAX_MESH_ID_LEN
);
2470 wdev
->mesh_id_up_len
=
2471 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2472 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2473 wdev
->mesh_id_up_len
);
2477 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2478 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2480 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2484 params
.use_4addr
= -1;
2487 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2488 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2490 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2499 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2500 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2504 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2508 if (!err
&& params
.use_4addr
!= -1)
2509 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2514 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2516 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2517 struct vif_params params
;
2518 struct wireless_dev
*wdev
;
2519 struct sk_buff
*msg
;
2521 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2524 /* to avoid failing a new interface creation due to pending removal */
2525 cfg80211_destroy_ifaces(rdev
);
2527 memset(¶ms
, 0, sizeof(params
));
2529 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2532 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2533 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2534 if (type
> NL80211_IFTYPE_MAX
)
2538 if (!rdev
->ops
->add_virtual_intf
||
2539 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2542 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2543 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2545 if (!is_valid_ether_addr(params
.macaddr
))
2546 return -EADDRNOTAVAIL
;
2549 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2550 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2551 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2556 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2560 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2561 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2564 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2565 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2568 wdev
= rdev_add_virtual_intf(rdev
,
2569 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2570 type
, err
? NULL
: &flags
, ¶ms
);
2573 return PTR_ERR(wdev
);
2576 if (info
->attrs
[NL80211_ATTR_IFACE_SOCKET_OWNER
])
2577 wdev
->owner_nlportid
= info
->snd_portid
;
2580 case NL80211_IFTYPE_MESH_POINT
:
2581 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2584 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2585 IEEE80211_MAX_MESH_ID_LEN
);
2586 wdev
->mesh_id_up_len
=
2587 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2588 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2589 wdev
->mesh_id_up_len
);
2592 case NL80211_IFTYPE_P2P_DEVICE
:
2594 * P2P Device doesn't have a netdev, so doesn't go
2595 * through the netdev notifier and must be added here
2597 mutex_init(&wdev
->mtx
);
2598 INIT_LIST_HEAD(&wdev
->event_list
);
2599 spin_lock_init(&wdev
->event_lock
);
2600 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2601 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2603 wdev
->identifier
= ++rdev
->wdev_id
;
2604 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2605 rdev
->devlist_generation
++;
2611 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2617 return genlmsg_reply(msg
, info
);
2620 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2622 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2623 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2625 if (!rdev
->ops
->del_virtual_intf
)
2629 * If we remove a wireless device without a netdev then clear
2630 * user_ptr[1] so that nl80211_post_doit won't dereference it
2631 * to check if it needs to do dev_put(). Otherwise it crashes
2632 * since the wdev has been freed, unlike with a netdev where
2633 * we need the dev_put() for the netdev to really be freed.
2636 info
->user_ptr
[1] = NULL
;
2638 return rdev_del_virtual_intf(rdev
, wdev
);
2641 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2643 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2644 struct net_device
*dev
= info
->user_ptr
[1];
2647 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2650 if (!rdev
->ops
->set_noack_map
)
2653 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2655 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2658 struct get_key_cookie
{
2659 struct sk_buff
*msg
;
2664 static void get_key_callback(void *c
, struct key_params
*params
)
2667 struct get_key_cookie
*cookie
= c
;
2670 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2671 params
->key_len
, params
->key
)) ||
2673 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2674 params
->seq_len
, params
->seq
)) ||
2676 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2678 goto nla_put_failure
;
2680 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2682 goto nla_put_failure
;
2685 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2686 params
->key_len
, params
->key
)) ||
2688 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2689 params
->seq_len
, params
->seq
)) ||
2691 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2693 goto nla_put_failure
;
2695 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2696 goto nla_put_failure
;
2698 nla_nest_end(cookie
->msg
, key
);
2705 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2707 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2709 struct net_device
*dev
= info
->user_ptr
[1];
2711 const u8
*mac_addr
= NULL
;
2713 struct get_key_cookie cookie
= {
2717 struct sk_buff
*msg
;
2719 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2720 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2725 if (info
->attrs
[NL80211_ATTR_MAC
])
2726 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2728 pairwise
= !!mac_addr
;
2729 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2730 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2731 if (kt
>= NUM_NL80211_KEYTYPES
)
2733 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2734 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2736 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2739 if (!rdev
->ops
->get_key
)
2742 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2746 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2747 NL80211_CMD_NEW_KEY
);
2749 goto nla_put_failure
;
2752 cookie
.idx
= key_idx
;
2754 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2755 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2756 goto nla_put_failure
;
2758 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2759 goto nla_put_failure
;
2761 if (pairwise
&& mac_addr
&&
2762 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2765 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2772 goto nla_put_failure
;
2774 genlmsg_end(msg
, hdr
);
2775 return genlmsg_reply(msg
, info
);
2784 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2786 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2787 struct key_parse key
;
2789 struct net_device
*dev
= info
->user_ptr
[1];
2791 err
= nl80211_parse_key(info
, &key
);
2798 /* only support setting default key */
2799 if (!key
.def
&& !key
.defmgmt
)
2802 wdev_lock(dev
->ieee80211_ptr
);
2805 if (!rdev
->ops
->set_default_key
) {
2810 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2814 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2815 key
.def_uni
, key
.def_multi
);
2820 #ifdef CONFIG_CFG80211_WEXT
2821 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2824 if (key
.def_uni
|| !key
.def_multi
) {
2829 if (!rdev
->ops
->set_default_mgmt_key
) {
2834 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2838 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2842 #ifdef CONFIG_CFG80211_WEXT
2843 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2848 wdev_unlock(dev
->ieee80211_ptr
);
2853 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2855 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2857 struct net_device
*dev
= info
->user_ptr
[1];
2858 struct key_parse key
;
2859 const u8
*mac_addr
= NULL
;
2861 err
= nl80211_parse_key(info
, &key
);
2868 if (info
->attrs
[NL80211_ATTR_MAC
])
2869 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2871 if (key
.type
== -1) {
2873 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2875 key
.type
= NL80211_KEYTYPE_GROUP
;
2879 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2880 key
.type
!= NL80211_KEYTYPE_GROUP
)
2883 if (!rdev
->ops
->add_key
)
2886 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2887 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2891 wdev_lock(dev
->ieee80211_ptr
);
2892 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2894 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2895 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2897 wdev_unlock(dev
->ieee80211_ptr
);
2902 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2904 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2906 struct net_device
*dev
= info
->user_ptr
[1];
2907 u8
*mac_addr
= NULL
;
2908 struct key_parse key
;
2910 err
= nl80211_parse_key(info
, &key
);
2914 if (info
->attrs
[NL80211_ATTR_MAC
])
2915 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2917 if (key
.type
== -1) {
2919 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2921 key
.type
= NL80211_KEYTYPE_GROUP
;
2925 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2926 key
.type
!= NL80211_KEYTYPE_GROUP
)
2929 if (!rdev
->ops
->del_key
)
2932 wdev_lock(dev
->ieee80211_ptr
);
2933 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2935 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2936 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2940 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2941 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2944 #ifdef CONFIG_CFG80211_WEXT
2946 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2947 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2948 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2949 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2952 wdev_unlock(dev
->ieee80211_ptr
);
2957 /* This function returns an error or the number of nested attributes */
2958 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2960 struct nlattr
*attr
;
2961 int n_entries
= 0, tmp
;
2963 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2964 if (nla_len(attr
) != ETH_ALEN
)
2974 * This function parses ACL information and allocates memory for ACL data.
2975 * On successful return, the calling function is responsible to free the
2976 * ACL buffer returned by this function.
2978 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2979 struct genl_info
*info
)
2981 enum nl80211_acl_policy acl_policy
;
2982 struct nlattr
*attr
;
2983 struct cfg80211_acl_data
*acl
;
2984 int i
= 0, n_entries
, tmp
;
2986 if (!wiphy
->max_acl_mac_addrs
)
2987 return ERR_PTR(-EOPNOTSUPP
);
2989 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2990 return ERR_PTR(-EINVAL
);
2992 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2993 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2994 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2995 return ERR_PTR(-EINVAL
);
2997 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2998 return ERR_PTR(-EINVAL
);
3000 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3002 return ERR_PTR(n_entries
);
3004 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3005 return ERR_PTR(-ENOTSUPP
);
3007 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3010 return ERR_PTR(-ENOMEM
);
3012 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3013 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3017 acl
->n_acl_entries
= n_entries
;
3018 acl
->acl_policy
= acl_policy
;
3023 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3025 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3026 struct net_device
*dev
= info
->user_ptr
[1];
3027 struct cfg80211_acl_data
*acl
;
3030 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3031 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3034 if (!dev
->ieee80211_ptr
->beacon_interval
)
3037 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3039 return PTR_ERR(acl
);
3041 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3048 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3049 struct cfg80211_beacon_data
*bcn
)
3051 bool haveinfo
= false;
3053 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3054 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3055 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3056 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3059 memset(bcn
, 0, sizeof(*bcn
));
3061 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3062 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3063 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3069 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3070 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3071 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3078 if (attrs
[NL80211_ATTR_IE
]) {
3079 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3080 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3083 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3084 bcn
->proberesp_ies
=
3085 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3086 bcn
->proberesp_ies_len
=
3087 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3090 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3091 bcn
->assocresp_ies
=
3092 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3093 bcn
->assocresp_ies_len
=
3094 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3097 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3098 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3099 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3105 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3106 struct cfg80211_ap_settings
*params
)
3108 struct wireless_dev
*wdev
;
3111 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3112 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3113 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3116 if (!wdev
->preset_chandef
.chan
)
3119 params
->chandef
= wdev
->preset_chandef
;
3127 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3128 enum nl80211_auth_type auth_type
,
3129 enum nl80211_commands cmd
)
3131 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3135 case NL80211_CMD_AUTHENTICATE
:
3136 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3137 auth_type
== NL80211_AUTHTYPE_SAE
)
3140 case NL80211_CMD_CONNECT
:
3141 case NL80211_CMD_START_AP
:
3142 /* SAE not supported yet */
3143 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3151 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3153 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3154 struct net_device
*dev
= info
->user_ptr
[1];
3155 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3156 struct cfg80211_ap_settings params
;
3158 u8 radar_detect_width
= 0;
3160 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3161 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3164 if (!rdev
->ops
->start_ap
)
3167 if (wdev
->beacon_interval
)
3170 memset(¶ms
, 0, sizeof(params
));
3172 /* these are required for START_AP */
3173 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3174 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3175 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3178 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3182 params
.beacon_interval
=
3183 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3184 params
.dtim_period
=
3185 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3187 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3192 * In theory, some of these attributes should be required here
3193 * but since they were not used when the command was originally
3194 * added, keep them optional for old user space programs to let
3195 * them continue to work with drivers that do not need the
3196 * additional information -- drivers must check!
3198 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3199 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3201 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3202 if (params
.ssid_len
== 0 ||
3203 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3207 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3208 params
.hidden_ssid
= nla_get_u32(
3209 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3210 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3211 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3212 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3216 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3218 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3219 params
.auth_type
= nla_get_u32(
3220 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3221 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3222 NL80211_CMD_START_AP
))
3225 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3227 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3228 NL80211_MAX_NR_CIPHER_SUITES
);
3232 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3233 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3235 params
.inactivity_timeout
= nla_get_u16(
3236 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3239 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3240 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3242 params
.p2p_ctwindow
=
3243 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3244 if (params
.p2p_ctwindow
> 127)
3246 if (params
.p2p_ctwindow
!= 0 &&
3247 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3251 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3254 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3256 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3259 params
.p2p_opp_ps
= tmp
;
3260 if (params
.p2p_opp_ps
!= 0 &&
3261 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3265 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3266 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3269 } else if (wdev
->preset_chandef
.chan
) {
3270 params
.chandef
= wdev
->preset_chandef
;
3271 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3274 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
,
3278 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3282 radar_detect_width
= BIT(params
.chandef
.width
);
3283 params
.radar_required
= true;
3286 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3287 params
.chandef
.chan
,
3289 radar_detect_width
);
3293 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3294 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3295 if (IS_ERR(params
.acl
))
3296 return PTR_ERR(params
.acl
);
3300 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3302 wdev
->preset_chandef
= params
.chandef
;
3303 wdev
->beacon_interval
= params
.beacon_interval
;
3304 wdev
->chandef
= params
.chandef
;
3305 wdev
->ssid_len
= params
.ssid_len
;
3306 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3315 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3317 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3318 struct net_device
*dev
= info
->user_ptr
[1];
3319 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3320 struct cfg80211_beacon_data params
;
3323 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3324 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3327 if (!rdev
->ops
->change_beacon
)
3330 if (!wdev
->beacon_interval
)
3333 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3338 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
3344 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3346 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3347 struct net_device
*dev
= info
->user_ptr
[1];
3349 return cfg80211_stop_ap(rdev
, dev
, false);
3352 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3353 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3354 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3355 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3356 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3357 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3358 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3361 static int parse_station_flags(struct genl_info
*info
,
3362 enum nl80211_iftype iftype
,
3363 struct station_parameters
*params
)
3365 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3370 * Try parsing the new attribute first so userspace
3371 * can specify both for older kernels.
3373 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3375 struct nl80211_sta_flag_update
*sta_flags
;
3377 sta_flags
= nla_data(nla
);
3378 params
->sta_flags_mask
= sta_flags
->mask
;
3379 params
->sta_flags_set
= sta_flags
->set
;
3380 params
->sta_flags_set
&= params
->sta_flags_mask
;
3381 if ((params
->sta_flags_mask
|
3382 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3387 /* if present, parse the old attribute */
3389 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3393 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3394 nla
, sta_flags_policy
))
3398 * Only allow certain flags for interface types so that
3399 * other attributes are silently ignored. Remember that
3400 * this is backward compatibility code with old userspace
3401 * and shouldn't be hit in other cases anyway.
3404 case NL80211_IFTYPE_AP
:
3405 case NL80211_IFTYPE_AP_VLAN
:
3406 case NL80211_IFTYPE_P2P_GO
:
3407 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3408 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3409 BIT(NL80211_STA_FLAG_WME
) |
3410 BIT(NL80211_STA_FLAG_MFP
);
3412 case NL80211_IFTYPE_P2P_CLIENT
:
3413 case NL80211_IFTYPE_STATION
:
3414 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3415 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3417 case NL80211_IFTYPE_MESH_POINT
:
3418 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3419 BIT(NL80211_STA_FLAG_MFP
) |
3420 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3425 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3427 params
->sta_flags_set
|= (1<<flag
);
3429 /* no longer support new API additions in old API */
3430 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3438 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3441 struct nlattr
*rate
;
3445 rate
= nla_nest_start(msg
, attr
);
3449 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3450 bitrate
= cfg80211_calculate_bitrate(info
);
3451 /* report 16-bit bitrate only if we can */
3452 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3454 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3456 if (bitrate_compat
> 0 &&
3457 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3460 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3461 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3463 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3464 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3466 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3467 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3469 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3470 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3472 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3474 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3475 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3477 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3478 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3480 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3481 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3483 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3484 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3486 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3487 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3491 nla_nest_end(msg
, rate
);
3495 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3504 attr
= nla_nest_start(msg
, id
);
3508 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3509 if (!(mask
& BIT(i
)))
3512 if (nla_put_u8(msg
, i
, signal
[i
]))
3516 nla_nest_end(msg
, attr
);
3521 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3523 struct cfg80211_registered_device
*rdev
,
3524 struct net_device
*dev
,
3525 const u8
*mac_addr
, struct station_info
*sinfo
)
3528 struct nlattr
*sinfoattr
, *bss_param
;
3530 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3534 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3535 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3536 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3537 goto nla_put_failure
;
3539 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3541 goto nla_put_failure
;
3542 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3543 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3544 sinfo
->connected_time
))
3545 goto nla_put_failure
;
3546 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3547 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3548 sinfo
->inactive_time
))
3549 goto nla_put_failure
;
3550 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3551 STATION_INFO_RX_BYTES64
)) &&
3552 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3553 (u32
)sinfo
->rx_bytes
))
3554 goto nla_put_failure
;
3555 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3556 STATION_INFO_TX_BYTES64
)) &&
3557 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3558 (u32
)sinfo
->tx_bytes
))
3559 goto nla_put_failure
;
3560 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3561 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3563 goto nla_put_failure
;
3564 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3565 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3567 goto nla_put_failure
;
3568 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3569 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3570 goto nla_put_failure
;
3571 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3572 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3573 goto nla_put_failure
;
3574 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3575 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3576 sinfo
->plink_state
))
3577 goto nla_put_failure
;
3578 switch (rdev
->wiphy
.signal_type
) {
3579 case CFG80211_SIGNAL_TYPE_MBM
:
3580 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3581 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3583 goto nla_put_failure
;
3584 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3585 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3587 goto nla_put_failure
;
3592 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL
) {
3593 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3594 sinfo
->chain_signal
,
3595 NL80211_STA_INFO_CHAIN_SIGNAL
))
3596 goto nla_put_failure
;
3598 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL_AVG
) {
3599 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3600 sinfo
->chain_signal_avg
,
3601 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3602 goto nla_put_failure
;
3604 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3605 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3606 NL80211_STA_INFO_TX_BITRATE
))
3607 goto nla_put_failure
;
3609 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3610 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3611 NL80211_STA_INFO_RX_BITRATE
))
3612 goto nla_put_failure
;
3614 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3615 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3617 goto nla_put_failure
;
3618 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3619 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3621 goto nla_put_failure
;
3622 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3623 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3625 goto nla_put_failure
;
3626 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3627 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3629 goto nla_put_failure
;
3630 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3631 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3632 sinfo
->beacon_loss_count
))
3633 goto nla_put_failure
;
3634 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3635 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3637 goto nla_put_failure
;
3638 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3639 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3641 goto nla_put_failure
;
3642 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3643 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3645 goto nla_put_failure
;
3646 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3647 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3649 goto nla_put_failure
;
3651 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3652 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3653 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3654 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3655 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3656 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3657 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3658 sinfo
->bss_param
.dtim_period
) ||
3659 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3660 sinfo
->bss_param
.beacon_interval
))
3661 goto nla_put_failure
;
3663 nla_nest_end(msg
, bss_param
);
3665 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3666 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3667 sizeof(struct nl80211_sta_flag_update
),
3669 goto nla_put_failure
;
3670 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3671 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3673 goto nla_put_failure
;
3674 nla_nest_end(msg
, sinfoattr
);
3676 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3677 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3678 sinfo
->assoc_req_ies
))
3679 goto nla_put_failure
;
3681 return genlmsg_end(msg
, hdr
);
3684 genlmsg_cancel(msg
, hdr
);
3688 static int nl80211_dump_station(struct sk_buff
*skb
,
3689 struct netlink_callback
*cb
)
3691 struct station_info sinfo
;
3692 struct cfg80211_registered_device
*dev
;
3693 struct wireless_dev
*wdev
;
3694 u8 mac_addr
[ETH_ALEN
];
3695 int sta_idx
= cb
->args
[2];
3698 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3702 if (!wdev
->netdev
) {
3707 if (!dev
->ops
->dump_station
) {
3713 memset(&sinfo
, 0, sizeof(sinfo
));
3714 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3721 if (nl80211_send_station(skb
,
3722 NETLINK_CB(cb
->skb
).portid
,
3723 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3724 dev
, wdev
->netdev
, mac_addr
,
3733 cb
->args
[2] = sta_idx
;
3736 nl80211_finish_wdev_dump(dev
);
3741 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3743 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3744 struct net_device
*dev
= info
->user_ptr
[1];
3745 struct station_info sinfo
;
3746 struct sk_buff
*msg
;
3747 u8
*mac_addr
= NULL
;
3750 memset(&sinfo
, 0, sizeof(sinfo
));
3752 if (!info
->attrs
[NL80211_ATTR_MAC
])
3755 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3757 if (!rdev
->ops
->get_station
)
3760 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3764 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3768 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3769 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3774 return genlmsg_reply(msg
, info
);
3777 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3778 struct station_parameters
*params
,
3779 enum cfg80211_station_type statype
)
3781 if (params
->listen_interval
!= -1)
3786 /* When you run into this, adjust the code below for the new flag */
3787 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3790 case CFG80211_STA_MESH_PEER_KERNEL
:
3791 case CFG80211_STA_MESH_PEER_USER
:
3793 * No ignoring the TDLS flag here -- the userspace mesh
3794 * code doesn't have the bug of including TDLS in the
3797 if (params
->sta_flags_mask
&
3798 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3799 BIT(NL80211_STA_FLAG_MFP
) |
3800 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3803 case CFG80211_STA_TDLS_PEER_SETUP
:
3804 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3805 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3807 /* ignore since it can't change */
3808 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3811 /* disallow mesh-specific things */
3812 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3814 if (params
->local_pm
)
3816 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3820 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3821 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3822 /* TDLS can't be set, ... */
3823 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3826 * ... but don't bother the driver with it. This works around
3827 * a hostapd/wpa_supplicant issue -- it always includes the
3828 * TLDS_PEER flag in the mask even for AP mode.
3830 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3833 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3834 /* reject other things that can't change */
3835 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3837 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3839 if (params
->supported_rates
)
3841 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3845 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3851 case CFG80211_STA_AP_MLME_CLIENT
:
3852 /* Use this only for authorizing/unauthorizing a station */
3853 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3856 case CFG80211_STA_AP_CLIENT
:
3857 /* accept only the listed bits */
3858 if (params
->sta_flags_mask
&
3859 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3860 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3861 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3862 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3863 BIT(NL80211_STA_FLAG_WME
) |
3864 BIT(NL80211_STA_FLAG_MFP
)))
3867 /* but authenticated/associated only if driver handles it */
3868 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3869 params
->sta_flags_mask
&
3870 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3871 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3874 case CFG80211_STA_IBSS
:
3875 case CFG80211_STA_AP_STA
:
3876 /* reject any changes other than AUTHORIZED */
3877 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3880 case CFG80211_STA_TDLS_PEER_SETUP
:
3881 /* reject any changes other than AUTHORIZED or WME */
3882 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3883 BIT(NL80211_STA_FLAG_WME
)))
3885 /* force (at least) rates when authorizing */
3886 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3887 !params
->supported_rates
)
3890 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3891 /* reject any changes */
3893 case CFG80211_STA_MESH_PEER_KERNEL
:
3894 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3897 case CFG80211_STA_MESH_PEER_USER
:
3898 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3905 EXPORT_SYMBOL(cfg80211_check_station_change
);
3908 * Get vlan interface making sure it is running and on the right wiphy.
3910 static struct net_device
*get_vlan(struct genl_info
*info
,
3911 struct cfg80211_registered_device
*rdev
)
3913 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3914 struct net_device
*v
;
3920 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3922 return ERR_PTR(-ENODEV
);
3924 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3929 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3930 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3931 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3936 if (!netif_running(v
)) {
3944 return ERR_PTR(ret
);
3947 static const struct nla_policy
3948 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
3949 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3950 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3953 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3954 struct station_parameters
*params
)
3956 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3960 /* parse WME attributes if present */
3961 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3964 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3965 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3966 nl80211_sta_wme_policy
);
3970 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3971 params
->uapsd_queues
= nla_get_u8(
3972 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3973 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3976 if (tb
[NL80211_STA_WME_MAX_SP
])
3977 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3979 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3982 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3987 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
3988 struct station_parameters
*params
)
3990 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
3991 params
->supported_channels
=
3992 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
3993 params
->supported_channels_len
=
3994 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
3996 * Need to include at least one (first channel, number of
3997 * channels) tuple for each subband, and must have proper
3998 * tuples for the rest of the data as well.
4000 if (params
->supported_channels_len
< 2)
4002 if (params
->supported_channels_len
% 2)
4006 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4007 params
->supported_oper_classes
=
4008 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4009 params
->supported_oper_classes_len
=
4010 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4012 * The value of the Length field of the Supported Operating
4013 * Classes element is between 2 and 253.
4015 if (params
->supported_oper_classes_len
< 2 ||
4016 params
->supported_oper_classes_len
> 253)
4022 static int nl80211_set_station_tdls(struct genl_info
*info
,
4023 struct station_parameters
*params
)
4026 /* Dummy STA entry gets updated once the peer capabilities are known */
4027 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4028 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4029 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4031 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4032 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4034 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4036 err
= nl80211_parse_sta_channel_info(info
, params
);
4040 return nl80211_parse_sta_wme(info
, params
);
4043 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4045 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4046 struct net_device
*dev
= info
->user_ptr
[1];
4047 struct station_parameters params
;
4051 memset(¶ms
, 0, sizeof(params
));
4053 params
.listen_interval
= -1;
4055 if (!rdev
->ops
->change_station
)
4058 if (info
->attrs
[NL80211_ATTR_STA_AID
])
4061 if (!info
->attrs
[NL80211_ATTR_MAC
])
4064 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4066 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4067 params
.supported_rates
=
4068 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4069 params
.supported_rates_len
=
4070 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4073 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4075 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4076 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4079 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4081 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4082 params
.ext_capab_len
=
4083 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4086 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4089 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4092 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4093 params
.plink_action
=
4094 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4095 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4099 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4100 params
.plink_state
=
4101 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4102 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4104 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4107 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4108 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4109 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4111 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4112 pm
> NL80211_MESH_POWER_MAX
)
4115 params
.local_pm
= pm
;
4118 /* Include parameters for TDLS peer (will check later) */
4119 err
= nl80211_set_station_tdls(info
, ¶ms
);
4123 params
.vlan
= get_vlan(info
, rdev
);
4124 if (IS_ERR(params
.vlan
))
4125 return PTR_ERR(params
.vlan
);
4127 switch (dev
->ieee80211_ptr
->iftype
) {
4128 case NL80211_IFTYPE_AP
:
4129 case NL80211_IFTYPE_AP_VLAN
:
4130 case NL80211_IFTYPE_P2P_GO
:
4131 case NL80211_IFTYPE_P2P_CLIENT
:
4132 case NL80211_IFTYPE_STATION
:
4133 case NL80211_IFTYPE_ADHOC
:
4134 case NL80211_IFTYPE_MESH_POINT
:
4141 /* driver will call cfg80211_check_station_change() */
4142 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4146 dev_put(params
.vlan
);
4151 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4153 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4155 struct net_device
*dev
= info
->user_ptr
[1];
4156 struct station_parameters params
;
4157 u8
*mac_addr
= NULL
;
4159 memset(¶ms
, 0, sizeof(params
));
4161 if (!rdev
->ops
->add_station
)
4164 if (!info
->attrs
[NL80211_ATTR_MAC
])
4167 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4170 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4173 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4174 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4177 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4178 params
.supported_rates
=
4179 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4180 params
.supported_rates_len
=
4181 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4182 params
.listen_interval
=
4183 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4185 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4186 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4188 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4189 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4192 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4194 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4195 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4198 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4200 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4201 params
.ext_capab_len
=
4202 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4205 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4207 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4209 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4211 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4213 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4214 params
.opmode_notif_used
= true;
4215 params
.opmode_notif
=
4216 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4219 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4220 params
.plink_action
=
4221 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4222 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4226 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
4230 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4234 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4237 /* When you run into this, adjust the code below for the new flag */
4238 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4240 switch (dev
->ieee80211_ptr
->iftype
) {
4241 case NL80211_IFTYPE_AP
:
4242 case NL80211_IFTYPE_AP_VLAN
:
4243 case NL80211_IFTYPE_P2P_GO
:
4244 /* ignore WME attributes if iface/sta is not capable */
4245 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4246 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4247 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4249 /* TDLS peers cannot be added */
4250 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4251 info
->attrs
[NL80211_ATTR_PEER_AID
])
4253 /* but don't bother the driver with it */
4254 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4256 /* allow authenticated/associated only if driver handles it */
4257 if (!(rdev
->wiphy
.features
&
4258 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4259 params
.sta_flags_mask
&
4260 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4261 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4264 /* must be last in here for error handling */
4265 params
.vlan
= get_vlan(info
, rdev
);
4266 if (IS_ERR(params
.vlan
))
4267 return PTR_ERR(params
.vlan
);
4269 case NL80211_IFTYPE_MESH_POINT
:
4270 /* ignore uAPSD data */
4271 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4273 /* associated is disallowed */
4274 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4276 /* TDLS peers cannot be added */
4277 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4278 info
->attrs
[NL80211_ATTR_PEER_AID
])
4281 case NL80211_IFTYPE_STATION
:
4282 case NL80211_IFTYPE_P2P_CLIENT
:
4283 /* ignore uAPSD data */
4284 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4286 /* these are disallowed */
4287 if (params
.sta_flags_mask
&
4288 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4289 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4291 /* Only TDLS peers can be added */
4292 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4294 /* Can only add if TDLS ... */
4295 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4297 /* ... with external setup is supported */
4298 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4301 * Older wpa_supplicant versions always mark the TDLS peer
4302 * as authorized, but it shouldn't yet be.
4304 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4310 /* be aware of params.vlan when changing code here */
4312 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4315 dev_put(params
.vlan
);
4319 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4321 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4322 struct net_device
*dev
= info
->user_ptr
[1];
4323 u8
*mac_addr
= NULL
;
4325 if (info
->attrs
[NL80211_ATTR_MAC
])
4326 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4328 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4329 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4330 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4331 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4334 if (!rdev
->ops
->del_station
)
4337 return rdev_del_station(rdev
, dev
, mac_addr
);
4340 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4341 int flags
, struct net_device
*dev
,
4342 u8
*dst
, u8
*next_hop
,
4343 struct mpath_info
*pinfo
)
4346 struct nlattr
*pinfoattr
;
4348 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4352 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4353 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4354 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4355 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4356 goto nla_put_failure
;
4358 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4360 goto nla_put_failure
;
4361 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4362 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4364 goto nla_put_failure
;
4365 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4366 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4367 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4368 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4370 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4371 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4373 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4374 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4376 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4377 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4378 pinfo
->discovery_timeout
)) ||
4379 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4380 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4381 pinfo
->discovery_retries
)))
4382 goto nla_put_failure
;
4384 nla_nest_end(msg
, pinfoattr
);
4386 return genlmsg_end(msg
, hdr
);
4389 genlmsg_cancel(msg
, hdr
);
4393 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4394 struct netlink_callback
*cb
)
4396 struct mpath_info pinfo
;
4397 struct cfg80211_registered_device
*dev
;
4398 struct wireless_dev
*wdev
;
4400 u8 next_hop
[ETH_ALEN
];
4401 int path_idx
= cb
->args
[2];
4404 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4408 if (!dev
->ops
->dump_mpath
) {
4413 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4419 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4426 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4427 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4428 wdev
->netdev
, dst
, next_hop
,
4437 cb
->args
[2] = path_idx
;
4440 nl80211_finish_wdev_dump(dev
);
4444 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4446 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4448 struct net_device
*dev
= info
->user_ptr
[1];
4449 struct mpath_info pinfo
;
4450 struct sk_buff
*msg
;
4452 u8 next_hop
[ETH_ALEN
];
4454 memset(&pinfo
, 0, sizeof(pinfo
));
4456 if (!info
->attrs
[NL80211_ATTR_MAC
])
4459 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4461 if (!rdev
->ops
->get_mpath
)
4464 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4467 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4471 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4475 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4476 dev
, dst
, next_hop
, &pinfo
) < 0) {
4481 return genlmsg_reply(msg
, info
);
4484 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4486 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4487 struct net_device
*dev
= info
->user_ptr
[1];
4489 u8
*next_hop
= NULL
;
4491 if (!info
->attrs
[NL80211_ATTR_MAC
])
4494 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4497 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4498 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4500 if (!rdev
->ops
->change_mpath
)
4503 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4506 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4509 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4511 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4512 struct net_device
*dev
= info
->user_ptr
[1];
4514 u8
*next_hop
= NULL
;
4516 if (!info
->attrs
[NL80211_ATTR_MAC
])
4519 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4522 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4523 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4525 if (!rdev
->ops
->add_mpath
)
4528 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4531 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4534 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4536 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4537 struct net_device
*dev
= info
->user_ptr
[1];
4540 if (info
->attrs
[NL80211_ATTR_MAC
])
4541 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4543 if (!rdev
->ops
->del_mpath
)
4546 return rdev_del_mpath(rdev
, dev
, dst
);
4549 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4551 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4552 struct net_device
*dev
= info
->user_ptr
[1];
4553 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4554 struct bss_parameters params
;
4557 memset(¶ms
, 0, sizeof(params
));
4558 /* default to not changing parameters */
4559 params
.use_cts_prot
= -1;
4560 params
.use_short_preamble
= -1;
4561 params
.use_short_slot_time
= -1;
4562 params
.ap_isolate
= -1;
4563 params
.ht_opmode
= -1;
4564 params
.p2p_ctwindow
= -1;
4565 params
.p2p_opp_ps
= -1;
4567 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4568 params
.use_cts_prot
=
4569 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4570 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4571 params
.use_short_preamble
=
4572 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4573 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4574 params
.use_short_slot_time
=
4575 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4576 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4577 params
.basic_rates
=
4578 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4579 params
.basic_rates_len
=
4580 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4582 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4583 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4584 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4586 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4588 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4589 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4591 params
.p2p_ctwindow
=
4592 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4593 if (params
.p2p_ctwindow
< 0)
4595 if (params
.p2p_ctwindow
!= 0 &&
4596 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4600 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4603 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4605 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4608 params
.p2p_opp_ps
= tmp
;
4609 if (params
.p2p_opp_ps
&&
4610 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4614 if (!rdev
->ops
->change_bss
)
4617 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4618 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4622 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
4628 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4629 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4630 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4631 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4632 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4633 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4634 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4635 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
4638 static int parse_reg_rule(struct nlattr
*tb
[],
4639 struct ieee80211_reg_rule
*reg_rule
)
4641 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4642 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4644 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4646 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4648 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4650 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4652 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4655 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4657 freq_range
->start_freq_khz
=
4658 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4659 freq_range
->end_freq_khz
=
4660 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4661 freq_range
->max_bandwidth_khz
=
4662 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4664 power_rule
->max_eirp
=
4665 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4667 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4668 power_rule
->max_antenna_gain
=
4669 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4671 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
4672 reg_rule
->dfs_cac_ms
=
4673 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
4678 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4681 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4684 * You should only get this when cfg80211 hasn't yet initialized
4685 * completely when built-in to the kernel right between the time
4686 * window between nl80211_init() and regulatory_init(), if that is
4689 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4690 return -EINPROGRESS
;
4692 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4693 user_reg_hint_type
=
4694 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4696 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4698 switch (user_reg_hint_type
) {
4699 case NL80211_USER_REG_HINT_USER
:
4700 case NL80211_USER_REG_HINT_CELL_BASE
:
4701 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4704 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4705 return regulatory_hint_user(data
, user_reg_hint_type
);
4706 case NL80211_USER_REG_HINT_INDOOR
:
4707 return regulatory_hint_indoor_user();
4713 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4714 struct genl_info
*info
)
4716 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4717 struct net_device
*dev
= info
->user_ptr
[1];
4718 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4719 struct mesh_config cur_params
;
4722 struct nlattr
*pinfoattr
;
4723 struct sk_buff
*msg
;
4725 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4728 if (!rdev
->ops
->get_mesh_config
)
4732 /* If not connected, get default parameters */
4733 if (!wdev
->mesh_id_len
)
4734 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4736 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4742 /* Draw up a netlink message to send back */
4743 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4746 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4747 NL80211_CMD_GET_MESH_CONFIG
);
4750 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4752 goto nla_put_failure
;
4753 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4754 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4755 cur_params
.dot11MeshRetryTimeout
) ||
4756 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4757 cur_params
.dot11MeshConfirmTimeout
) ||
4758 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4759 cur_params
.dot11MeshHoldingTimeout
) ||
4760 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4761 cur_params
.dot11MeshMaxPeerLinks
) ||
4762 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4763 cur_params
.dot11MeshMaxRetries
) ||
4764 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4765 cur_params
.dot11MeshTTL
) ||
4766 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4767 cur_params
.element_ttl
) ||
4768 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4769 cur_params
.auto_open_plinks
) ||
4770 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4771 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4772 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4773 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4774 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4775 cur_params
.path_refresh_time
) ||
4776 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4777 cur_params
.min_discovery_timeout
) ||
4778 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4779 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4780 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4781 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4782 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4783 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4784 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4785 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4786 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4787 cur_params
.dot11MeshHWMPRootMode
) ||
4788 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4789 cur_params
.dot11MeshHWMPRannInterval
) ||
4790 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4791 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4792 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4793 cur_params
.dot11MeshForwarding
) ||
4794 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4795 cur_params
.rssi_threshold
) ||
4796 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4797 cur_params
.ht_opmode
) ||
4798 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4799 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4800 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4801 cur_params
.dot11MeshHWMProotInterval
) ||
4802 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4803 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4804 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4805 cur_params
.power_mode
) ||
4806 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4807 cur_params
.dot11MeshAwakeWindowDuration
) ||
4808 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4809 cur_params
.plink_timeout
))
4810 goto nla_put_failure
;
4811 nla_nest_end(msg
, pinfoattr
);
4812 genlmsg_end(msg
, hdr
);
4813 return genlmsg_reply(msg
, info
);
4816 genlmsg_cancel(msg
, hdr
);
4822 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4823 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4824 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4825 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4826 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4827 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4828 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4829 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4830 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4831 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4832 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4833 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4834 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4835 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4836 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4837 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4838 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4839 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4840 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4841 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4842 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4843 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4844 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4845 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4846 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4847 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4848 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4849 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4850 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
4853 static const struct nla_policy
4854 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4855 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4856 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4857 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4858 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4859 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
4860 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4861 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4862 .len
= IEEE80211_MAX_DATA_LEN
},
4863 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4866 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4867 struct mesh_config
*cfg
,
4870 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4873 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4876 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4878 cfg->param = fn(tb[attr]); \
4879 mask |= (1 << (attr - 1)); \
4884 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4886 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4887 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4888 nl80211_meshconf_params_policy
))
4891 /* This makes sure that there aren't more than 32 mesh config
4892 * parameters (otherwise our bitfield scheme would not work.) */
4893 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4895 /* Fill in the params struct */
4896 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4897 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4899 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4900 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4902 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4903 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4905 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4906 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4908 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4909 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4911 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4912 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4913 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4914 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4916 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4917 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4919 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4921 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4923 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4924 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4926 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4927 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4929 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4930 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4932 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4934 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4936 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4938 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4940 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4942 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4944 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4945 dot11MeshHWMPnetDiameterTraversalTime
,
4947 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4949 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4950 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4952 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4953 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4955 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4956 dot11MeshGateAnnouncementProtocol
, 0, 1,
4957 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4959 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4960 mask
, NL80211_MESHCONF_FORWARDING
,
4962 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
4963 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4965 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4966 mask
, NL80211_MESHCONF_HT_OPMODE
,
4968 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4970 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4972 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4973 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4975 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4976 dot11MeshHWMPconfirmationInterval
,
4978 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4980 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4981 NL80211_MESH_POWER_ACTIVE
,
4982 NL80211_MESH_POWER_MAX
,
4983 mask
, NL80211_MESHCONF_POWER_MODE
,
4985 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4987 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4988 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 1, 0xffffffff,
4989 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4996 #undef FILL_IN_MESH_PARAM_IF_SET
4999 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
5000 struct mesh_setup
*setup
)
5002 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5003 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
5005 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
5007 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
5008 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
5009 nl80211_mesh_setup_params_policy
))
5012 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
5013 setup
->sync_method
=
5014 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
5015 IEEE80211_SYNC_METHOD_VENDOR
:
5016 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
5018 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
5019 setup
->path_sel_proto
=
5020 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
5021 IEEE80211_PATH_PROTOCOL_VENDOR
:
5022 IEEE80211_PATH_PROTOCOL_HWMP
;
5024 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
5025 setup
->path_metric
=
5026 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
5027 IEEE80211_PATH_METRIC_VENDOR
:
5028 IEEE80211_PATH_METRIC_AIRTIME
;
5031 if (tb
[NL80211_MESH_SETUP_IE
]) {
5032 struct nlattr
*ieattr
=
5033 tb
[NL80211_MESH_SETUP_IE
];
5034 if (!is_valid_ie_attr(ieattr
))
5036 setup
->ie
= nla_data(ieattr
);
5037 setup
->ie_len
= nla_len(ieattr
);
5039 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
5040 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
5042 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
5043 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
5044 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
5045 if (setup
->is_secure
)
5046 setup
->user_mpm
= true;
5048 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
5049 if (!setup
->user_mpm
)
5052 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
5058 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
5059 struct genl_info
*info
)
5061 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5062 struct net_device
*dev
= info
->user_ptr
[1];
5063 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5064 struct mesh_config cfg
;
5068 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5071 if (!rdev
->ops
->update_mesh_config
)
5074 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
5079 if (!wdev
->mesh_id_len
)
5083 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
5090 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5092 const struct ieee80211_regdomain
*regdom
;
5093 struct sk_buff
*msg
;
5095 struct nlattr
*nl_reg_rules
;
5098 if (!cfg80211_regdomain
)
5101 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5105 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5106 NL80211_CMD_GET_REG
);
5110 if (reg_last_request_cell_base() &&
5111 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5112 NL80211_USER_REG_HINT_CELL_BASE
))
5113 goto nla_put_failure
;
5116 regdom
= rcu_dereference(cfg80211_regdomain
);
5118 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
5119 (regdom
->dfs_region
&&
5120 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
5121 goto nla_put_failure_rcu
;
5123 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
5125 goto nla_put_failure_rcu
;
5127 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
5128 struct nlattr
*nl_reg_rule
;
5129 const struct ieee80211_reg_rule
*reg_rule
;
5130 const struct ieee80211_freq_range
*freq_range
;
5131 const struct ieee80211_power_rule
*power_rule
;
5132 unsigned int max_bandwidth_khz
;
5134 reg_rule
= ®dom
->reg_rules
[i
];
5135 freq_range
= ®_rule
->freq_range
;
5136 power_rule
= ®_rule
->power_rule
;
5138 nl_reg_rule
= nla_nest_start(msg
, i
);
5140 goto nla_put_failure_rcu
;
5142 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
5143 if (!max_bandwidth_khz
)
5144 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
5147 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
5149 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
5150 freq_range
->start_freq_khz
) ||
5151 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
5152 freq_range
->end_freq_khz
) ||
5153 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
5154 max_bandwidth_khz
) ||
5155 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
5156 power_rule
->max_antenna_gain
) ||
5157 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
5158 power_rule
->max_eirp
) ||
5159 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
5160 reg_rule
->dfs_cac_ms
))
5161 goto nla_put_failure_rcu
;
5163 nla_nest_end(msg
, nl_reg_rule
);
5167 nla_nest_end(msg
, nl_reg_rules
);
5169 genlmsg_end(msg
, hdr
);
5170 return genlmsg_reply(msg
, info
);
5172 nla_put_failure_rcu
:
5175 genlmsg_cancel(msg
, hdr
);
5181 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5183 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5184 struct nlattr
*nl_reg_rule
;
5185 char *alpha2
= NULL
;
5186 int rem_reg_rules
= 0, r
= 0;
5187 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5188 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
5189 struct ieee80211_regdomain
*rd
= NULL
;
5191 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5194 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5197 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5199 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5200 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5202 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5205 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5209 if (!reg_is_valid_request(alpha2
))
5212 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5213 num_rules
* sizeof(struct ieee80211_reg_rule
);
5215 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5219 rd
->n_reg_rules
= num_rules
;
5220 rd
->alpha2
[0] = alpha2
[0];
5221 rd
->alpha2
[1] = alpha2
[1];
5224 * Disable DFS master mode if the DFS region was
5225 * not supported or known on this kernel.
5227 if (reg_supported_dfs_region(dfs_region
))
5228 rd
->dfs_region
= dfs_region
;
5230 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5232 r
= nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5233 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5237 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5243 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5250 /* set_regdom took ownership */
5258 static int validate_scan_freqs(struct nlattr
*freqs
)
5260 struct nlattr
*attr1
, *attr2
;
5261 int n_channels
= 0, tmp1
, tmp2
;
5263 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5266 * Some hardware has a limited channel list for
5267 * scanning, and it is pretty much nonsensical
5268 * to scan for a channel twice, so disallow that
5269 * and don't require drivers to check that the
5270 * channel list they get isn't longer than what
5271 * they can scan, as long as they can scan all
5272 * the channels they registered at once.
5274 nla_for_each_nested(attr2
, freqs
, tmp2
)
5275 if (attr1
!= attr2
&&
5276 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5283 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5285 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5286 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5287 struct cfg80211_scan_request
*request
;
5288 struct nlattr
*attr
;
5289 struct wiphy
*wiphy
;
5290 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5293 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5296 wiphy
= &rdev
->wiphy
;
5298 if (!rdev
->ops
->scan
)
5301 if (rdev
->scan_req
|| rdev
->scan_msg
) {
5306 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5307 n_channels
= validate_scan_freqs(
5308 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5314 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
5317 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5318 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5321 if (n_ssids
> wiphy
->max_scan_ssids
) {
5326 if (info
->attrs
[NL80211_ATTR_IE
])
5327 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5331 if (ie_len
> wiphy
->max_scan_ie_len
) {
5336 request
= kzalloc(sizeof(*request
)
5337 + sizeof(*request
->ssids
) * n_ssids
5338 + sizeof(*request
->channels
) * n_channels
5339 + ie_len
, GFP_KERNEL
);
5346 request
->ssids
= (void *)&request
->channels
[n_channels
];
5347 request
->n_ssids
= n_ssids
;
5350 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5352 request
->ie
= (void *)(request
->channels
+ n_channels
);
5356 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5357 /* user specified, bail out if channel not found */
5358 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5359 struct ieee80211_channel
*chan
;
5361 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5368 /* ignore disabled channels */
5369 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5372 request
->channels
[i
] = chan
;
5376 enum ieee80211_band band
;
5379 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5381 if (!wiphy
->bands
[band
])
5383 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5384 struct ieee80211_channel
*chan
;
5386 chan
= &wiphy
->bands
[band
]->channels
[j
];
5388 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5391 request
->channels
[i
] = chan
;
5402 request
->n_channels
= i
;
5405 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5406 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5407 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5411 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5412 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5417 if (info
->attrs
[NL80211_ATTR_IE
]) {
5418 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5419 memcpy((void *)request
->ie
,
5420 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5424 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5425 if (wiphy
->bands
[i
])
5427 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5429 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5430 nla_for_each_nested(attr
,
5431 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5433 enum ieee80211_band band
= nla_type(attr
);
5435 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5440 if (!wiphy
->bands
[band
])
5443 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5446 &request
->rates
[band
]);
5452 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5453 request
->flags
= nla_get_u32(
5454 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5455 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5456 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
5463 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5465 request
->wdev
= wdev
;
5466 request
->wiphy
= &rdev
->wiphy
;
5467 request
->scan_start
= jiffies
;
5469 rdev
->scan_req
= request
;
5470 err
= rdev_scan(rdev
, request
);
5473 nl80211_send_scan_start(rdev
, wdev
);
5475 dev_hold(wdev
->netdev
);
5478 rdev
->scan_req
= NULL
;
5486 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5487 struct genl_info
*info
)
5489 struct cfg80211_sched_scan_request
*request
;
5490 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5491 struct net_device
*dev
= info
->user_ptr
[1];
5492 struct nlattr
*attr
;
5493 struct wiphy
*wiphy
;
5494 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5496 enum ieee80211_band band
;
5498 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5499 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
5501 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5502 !rdev
->ops
->sched_scan_start
)
5505 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5508 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5511 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5515 wiphy
= &rdev
->wiphy
;
5517 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5518 n_channels
= validate_scan_freqs(
5519 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5523 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
5526 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5527 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5531 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5535 * First, count the number of 'real' matchsets. Due to an issue with
5536 * the old implementation, matchsets containing only the RSSI attribute
5537 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5538 * RSSI for all matchsets, rather than their own matchset for reporting
5539 * all APs with a strong RSSI. This is needed to be compatible with
5540 * older userspace that treated a matchset with only the RSSI as the
5541 * global RSSI for all other matchsets - if there are other matchsets.
5543 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5544 nla_for_each_nested(attr
,
5545 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5547 struct nlattr
*rssi
;
5549 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5550 nla_data(attr
), nla_len(attr
),
5551 nl80211_match_policy
);
5554 /* add other standalone attributes here */
5555 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
]) {
5559 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5561 default_match_rssi
= nla_get_s32(rssi
);
5565 /* However, if there's no other matchset, add the RSSI one */
5566 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
5569 if (n_match_sets
> wiphy
->max_match_sets
)
5572 if (info
->attrs
[NL80211_ATTR_IE
])
5573 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5577 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5580 if (rdev
->sched_scan_req
) {
5585 request
= kzalloc(sizeof(*request
)
5586 + sizeof(*request
->ssids
) * n_ssids
5587 + sizeof(*request
->match_sets
) * n_match_sets
5588 + sizeof(*request
->channels
) * n_channels
5589 + ie_len
, GFP_KERNEL
);
5596 request
->ssids
= (void *)&request
->channels
[n_channels
];
5597 request
->n_ssids
= n_ssids
;
5600 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5602 request
->ie
= (void *)(request
->channels
+ n_channels
);
5607 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5608 else if (request
->ssids
)
5609 request
->match_sets
=
5610 (void *)(request
->ssids
+ n_ssids
);
5612 request
->match_sets
=
5613 (void *)(request
->channels
+ n_channels
);
5615 request
->n_match_sets
= n_match_sets
;
5618 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5619 /* user specified, bail out if channel not found */
5620 nla_for_each_nested(attr
,
5621 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5623 struct ieee80211_channel
*chan
;
5625 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5632 /* ignore disabled channels */
5633 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5636 request
->channels
[i
] = chan
;
5641 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5643 if (!wiphy
->bands
[band
])
5645 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5646 struct ieee80211_channel
*chan
;
5648 chan
= &wiphy
->bands
[band
]->channels
[j
];
5650 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5653 request
->channels
[i
] = chan
;
5664 request
->n_channels
= i
;
5667 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5668 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5670 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5674 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5675 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5682 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5683 nla_for_each_nested(attr
,
5684 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5686 struct nlattr
*ssid
, *rssi
;
5688 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5689 nla_data(attr
), nla_len(attr
),
5690 nl80211_match_policy
);
5693 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5695 if (WARN_ON(i
>= n_match_sets
)) {
5696 /* this indicates a programming error,
5697 * the loop above should have verified
5704 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5708 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5709 nla_data(ssid
), nla_len(ssid
));
5710 request
->match_sets
[i
].ssid
.ssid_len
=
5712 /* special attribute - old implemenation w/a */
5713 request
->match_sets
[i
].rssi_thold
=
5715 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5717 request
->match_sets
[i
].rssi_thold
=
5723 /* there was no other matchset, so the RSSI one is alone */
5725 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
5727 request
->min_rssi_thold
= INT_MAX
;
5728 for (i
= 0; i
< n_match_sets
; i
++)
5729 request
->min_rssi_thold
=
5730 min(request
->match_sets
[i
].rssi_thold
,
5731 request
->min_rssi_thold
);
5733 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
5737 request
->ie_len
= ie_len
;
5738 memcpy((void *)request
->ie
,
5739 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5743 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5744 request
->flags
= nla_get_u32(
5745 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5746 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5747 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
5754 request
->wiphy
= &rdev
->wiphy
;
5755 request
->interval
= interval
;
5756 request
->scan_start
= jiffies
;
5758 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5760 rdev
->sched_scan_req
= request
;
5761 nl80211_send_sched_scan(rdev
, dev
,
5762 NL80211_CMD_START_SCHED_SCAN
);
5772 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5773 struct genl_info
*info
)
5775 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5777 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5778 !rdev
->ops
->sched_scan_stop
)
5781 return __cfg80211_stop_sched_scan(rdev
, false);
5784 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5785 struct genl_info
*info
)
5787 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5788 struct net_device
*dev
= info
->user_ptr
[1];
5789 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5790 struct cfg80211_chan_def chandef
;
5791 enum nl80211_dfs_regions dfs_region
;
5792 unsigned int cac_time_ms
;
5795 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
5796 if (dfs_region
== NL80211_DFS_UNSET
)
5799 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5803 if (netif_carrier_ok(dev
))
5806 if (wdev
->cac_started
)
5809 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5816 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
5819 if (!rdev
->ops
->start_radar_detection
)
5822 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5823 chandef
.chan
, CHAN_MODE_SHARED
,
5824 BIT(chandef
.width
));
5828 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
5829 if (WARN_ON(!cac_time_ms
))
5830 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
5832 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
,
5835 wdev
->chandef
= chandef
;
5836 wdev
->cac_started
= true;
5837 wdev
->cac_start_time
= jiffies
;
5838 wdev
->cac_time_ms
= cac_time_ms
;
5843 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
5845 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5846 struct net_device
*dev
= info
->user_ptr
[1];
5847 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5848 struct cfg80211_csa_settings params
;
5849 /* csa_attrs is defined static to avoid waste of stack size - this
5850 * function is called under RTNL lock, so this should not be a problem.
5852 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
5853 u8 radar_detect_width
= 0;
5855 bool need_new_beacon
= false;
5857 if (!rdev
->ops
->channel_switch
||
5858 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
5861 switch (dev
->ieee80211_ptr
->iftype
) {
5862 case NL80211_IFTYPE_AP
:
5863 case NL80211_IFTYPE_P2P_GO
:
5864 need_new_beacon
= true;
5866 /* useless if AP is not running */
5867 if (!wdev
->beacon_interval
)
5870 case NL80211_IFTYPE_ADHOC
:
5871 if (!wdev
->ssid_len
)
5874 case NL80211_IFTYPE_MESH_POINT
:
5875 if (!wdev
->mesh_id_len
)
5882 memset(¶ms
, 0, sizeof(params
));
5884 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5885 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
5888 /* only important for AP, IBSS and mesh create IEs internally */
5889 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
5892 params
.count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
5894 if (!need_new_beacon
)
5897 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
5901 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
5902 info
->attrs
[NL80211_ATTR_CSA_IES
],
5907 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
5911 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
5914 params
.counter_offset_beacon
=
5915 nla_get_u16(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
5916 if (params
.counter_offset_beacon
>= params
.beacon_csa
.tail_len
)
5919 /* sanity check - counters should be the same */
5920 if (params
.beacon_csa
.tail
[params
.counter_offset_beacon
] !=
5924 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
5925 params
.counter_offset_presp
=
5926 nla_get_u16(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
5927 if (params
.counter_offset_presp
>=
5928 params
.beacon_csa
.probe_resp_len
)
5931 if (params
.beacon_csa
.probe_resp
[params
.counter_offset_presp
] !=
5937 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
5941 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
,
5945 switch (dev
->ieee80211_ptr
->iftype
) {
5946 case NL80211_IFTYPE_AP
:
5947 case NL80211_IFTYPE_P2P_GO
:
5948 case NL80211_IFTYPE_ADHOC
:
5949 case NL80211_IFTYPE_MESH_POINT
:
5950 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
5955 radar_detect_width
= BIT(params
.chandef
.width
);
5956 params
.radar_required
= true;
5963 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5964 params
.chandef
.chan
,
5966 radar_detect_width
);
5970 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
5971 params
.block_tx
= true;
5974 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
5980 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5982 struct cfg80211_registered_device
*rdev
,
5983 struct wireless_dev
*wdev
,
5984 struct cfg80211_internal_bss
*intbss
)
5986 struct cfg80211_bss
*res
= &intbss
->pub
;
5987 const struct cfg80211_bss_ies
*ies
;
5992 ASSERT_WDEV_LOCK(wdev
);
5994 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5995 NL80211_CMD_NEW_SCAN_RESULTS
);
5999 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
6001 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
6002 goto nla_put_failure
;
6004 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
6005 goto nla_put_failure
;
6006 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
6007 goto nla_put_failure
;
6009 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
6011 goto nla_put_failure
;
6012 if ((!is_zero_ether_addr(res
->bssid
) &&
6013 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
6014 goto nla_put_failure
;
6017 ies
= rcu_dereference(res
->ies
);
6019 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
6020 goto fail_unlock_rcu
;
6022 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
6023 ies
->len
, ies
->data
))
6024 goto fail_unlock_rcu
;
6026 ies
= rcu_dereference(res
->beacon_ies
);
6028 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
6029 goto fail_unlock_rcu
;
6030 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
6031 ies
->len
, ies
->data
))
6032 goto fail_unlock_rcu
;
6036 if (res
->beacon_interval
&&
6037 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
6038 goto nla_put_failure
;
6039 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
6040 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
6041 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
6042 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
6043 jiffies_to_msecs(jiffies
- intbss
->ts
)))
6044 goto nla_put_failure
;
6046 switch (rdev
->wiphy
.signal_type
) {
6047 case CFG80211_SIGNAL_TYPE_MBM
:
6048 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
6049 goto nla_put_failure
;
6051 case CFG80211_SIGNAL_TYPE_UNSPEC
:
6052 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
6053 goto nla_put_failure
;
6059 switch (wdev
->iftype
) {
6060 case NL80211_IFTYPE_P2P_CLIENT
:
6061 case NL80211_IFTYPE_STATION
:
6062 if (intbss
== wdev
->current_bss
&&
6063 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6064 NL80211_BSS_STATUS_ASSOCIATED
))
6065 goto nla_put_failure
;
6067 case NL80211_IFTYPE_ADHOC
:
6068 if (intbss
== wdev
->current_bss
&&
6069 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6070 NL80211_BSS_STATUS_IBSS_JOINED
))
6071 goto nla_put_failure
;
6077 nla_nest_end(msg
, bss
);
6079 return genlmsg_end(msg
, hdr
);
6084 genlmsg_cancel(msg
, hdr
);
6088 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6090 struct cfg80211_registered_device
*rdev
;
6091 struct cfg80211_internal_bss
*scan
;
6092 struct wireless_dev
*wdev
;
6093 int start
= cb
->args
[2], idx
= 0;
6096 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6101 spin_lock_bh(&rdev
->bss_lock
);
6102 cfg80211_bss_expire(rdev
);
6104 cb
->seq
= rdev
->bss_generation
;
6106 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
6109 if (nl80211_send_bss(skb
, cb
,
6110 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6111 rdev
, wdev
, scan
) < 0) {
6117 spin_unlock_bh(&rdev
->bss_lock
);
6121 nl80211_finish_wdev_dump(rdev
);
6126 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
6127 int flags
, struct net_device
*dev
,
6128 struct survey_info
*survey
)
6131 struct nlattr
*infoattr
;
6133 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
6134 NL80211_CMD_NEW_SURVEY_RESULTS
);
6138 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
6139 goto nla_put_failure
;
6141 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
6143 goto nla_put_failure
;
6145 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
6146 survey
->channel
->center_freq
))
6147 goto nla_put_failure
;
6149 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
6150 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
6151 goto nla_put_failure
;
6152 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
6153 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
6154 goto nla_put_failure
;
6155 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
6156 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
6157 survey
->channel_time
))
6158 goto nla_put_failure
;
6159 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
6160 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
6161 survey
->channel_time_busy
))
6162 goto nla_put_failure
;
6163 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
6164 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
6165 survey
->channel_time_ext_busy
))
6166 goto nla_put_failure
;
6167 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
6168 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
6169 survey
->channel_time_rx
))
6170 goto nla_put_failure
;
6171 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
6172 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
6173 survey
->channel_time_tx
))
6174 goto nla_put_failure
;
6176 nla_nest_end(msg
, infoattr
);
6178 return genlmsg_end(msg
, hdr
);
6181 genlmsg_cancel(msg
, hdr
);
6185 static int nl80211_dump_survey(struct sk_buff
*skb
,
6186 struct netlink_callback
*cb
)
6188 struct survey_info survey
;
6189 struct cfg80211_registered_device
*dev
;
6190 struct wireless_dev
*wdev
;
6191 int survey_idx
= cb
->args
[2];
6194 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
6198 if (!wdev
->netdev
) {
6203 if (!dev
->ops
->dump_survey
) {
6209 struct ieee80211_channel
*chan
;
6211 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
6217 /* Survey without a channel doesn't make sense */
6218 if (!survey
.channel
) {
6223 chan
= ieee80211_get_channel(&dev
->wiphy
,
6224 survey
.channel
->center_freq
);
6225 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
6230 if (nl80211_send_survey(skb
,
6231 NETLINK_CB(cb
->skb
).portid
,
6232 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6233 wdev
->netdev
, &survey
) < 0)
6239 cb
->args
[2] = survey_idx
;
6242 nl80211_finish_wdev_dump(dev
);
6246 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
6248 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
6249 NL80211_WPA_VERSION_2
));
6252 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6254 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6255 struct net_device
*dev
= info
->user_ptr
[1];
6256 struct ieee80211_channel
*chan
;
6257 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
6258 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
6259 enum nl80211_auth_type auth_type
;
6260 struct key_parse key
;
6261 bool local_state_change
;
6263 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6266 if (!info
->attrs
[NL80211_ATTR_MAC
])
6269 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
6272 if (!info
->attrs
[NL80211_ATTR_SSID
])
6275 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6278 err
= nl80211_parse_key(info
, &key
);
6283 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
6285 if (!key
.p
.key
|| !key
.p
.key_len
)
6287 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
6288 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
6289 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
6290 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
6302 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
6303 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
6312 if (!rdev
->ops
->auth
)
6315 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6316 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6319 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6320 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
6321 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6325 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6326 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6328 if (info
->attrs
[NL80211_ATTR_IE
]) {
6329 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6330 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6333 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6334 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
6337 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
6338 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
6341 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
6342 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
6344 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
6345 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
6346 /* need to include at least Auth Transaction and Status Code */
6347 if (sae_data_len
< 4)
6351 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6354 * Since we no longer track auth state, ignore
6355 * requests to only change local state.
6357 if (local_state_change
)
6360 wdev_lock(dev
->ieee80211_ptr
);
6361 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
6362 ssid
, ssid_len
, ie
, ie_len
,
6363 key
.p
.key
, key
.p
.key_len
, key
.idx
,
6364 sae_data
, sae_data_len
);
6365 wdev_unlock(dev
->ieee80211_ptr
);
6369 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
6370 struct genl_info
*info
,
6371 struct cfg80211_crypto_settings
*settings
,
6374 memset(settings
, 0, sizeof(*settings
));
6376 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6378 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6380 proto
= nla_get_u16(
6381 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6382 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6383 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6386 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6387 settings
->control_port_no_encrypt
= true;
6389 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6391 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6395 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6396 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6397 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6399 if (len
% sizeof(u32
))
6402 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6405 memcpy(settings
->ciphers_pairwise
, data
, len
);
6407 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6408 if (!cfg80211_supported_cipher_suite(
6410 settings
->ciphers_pairwise
[i
]))
6414 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6415 settings
->cipher_group
=
6416 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6417 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6418 settings
->cipher_group
))
6422 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6423 settings
->wpa_versions
=
6424 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6425 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6429 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6433 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6434 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6435 settings
->n_akm_suites
= len
/ sizeof(u32
);
6437 if (len
% sizeof(u32
))
6440 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6443 memcpy(settings
->akm_suites
, data
, len
);
6449 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6451 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6452 struct net_device
*dev
= info
->user_ptr
[1];
6453 struct ieee80211_channel
*chan
;
6454 struct cfg80211_assoc_request req
= {};
6455 const u8
*bssid
, *ssid
;
6456 int err
, ssid_len
= 0;
6458 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6461 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6462 !info
->attrs
[NL80211_ATTR_SSID
] ||
6463 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6466 if (!rdev
->ops
->assoc
)
6469 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6470 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6473 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6475 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
6476 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6480 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6481 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6483 if (info
->attrs
[NL80211_ATTR_IE
]) {
6484 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6485 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6488 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6489 enum nl80211_mfp mfp
=
6490 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6491 if (mfp
== NL80211_MFP_REQUIRED
)
6493 else if (mfp
!= NL80211_MFP_NO
)
6497 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6498 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6500 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6501 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6503 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6504 memcpy(&req
.ht_capa_mask
,
6505 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6506 sizeof(req
.ht_capa_mask
));
6508 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6509 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6511 memcpy(&req
.ht_capa
,
6512 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6513 sizeof(req
.ht_capa
));
6516 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6517 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6519 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6520 memcpy(&req
.vht_capa_mask
,
6521 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6522 sizeof(req
.vht_capa_mask
));
6524 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6525 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6527 memcpy(&req
.vht_capa
,
6528 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6529 sizeof(req
.vht_capa
));
6532 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6534 wdev_lock(dev
->ieee80211_ptr
);
6535 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6536 ssid
, ssid_len
, &req
);
6537 wdev_unlock(dev
->ieee80211_ptr
);
6543 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6545 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6546 struct net_device
*dev
= info
->user_ptr
[1];
6547 const u8
*ie
= NULL
, *bssid
;
6548 int ie_len
= 0, err
;
6550 bool local_state_change
;
6552 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6555 if (!info
->attrs
[NL80211_ATTR_MAC
])
6558 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6561 if (!rdev
->ops
->deauth
)
6564 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6565 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6568 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6570 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6571 if (reason_code
== 0) {
6572 /* Reason Code 0 is reserved */
6576 if (info
->attrs
[NL80211_ATTR_IE
]) {
6577 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6578 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6581 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6583 wdev_lock(dev
->ieee80211_ptr
);
6584 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6585 local_state_change
);
6586 wdev_unlock(dev
->ieee80211_ptr
);
6590 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6592 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6593 struct net_device
*dev
= info
->user_ptr
[1];
6594 const u8
*ie
= NULL
, *bssid
;
6595 int ie_len
= 0, err
;
6597 bool local_state_change
;
6599 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6602 if (!info
->attrs
[NL80211_ATTR_MAC
])
6605 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6608 if (!rdev
->ops
->disassoc
)
6611 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6612 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6615 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6617 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6618 if (reason_code
== 0) {
6619 /* Reason Code 0 is reserved */
6623 if (info
->attrs
[NL80211_ATTR_IE
]) {
6624 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6625 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6628 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6630 wdev_lock(dev
->ieee80211_ptr
);
6631 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6632 local_state_change
);
6633 wdev_unlock(dev
->ieee80211_ptr
);
6638 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6639 int mcast_rate
[IEEE80211_NUM_BANDS
],
6642 struct wiphy
*wiphy
= &rdev
->wiphy
;
6646 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6647 struct ieee80211_supported_band
*sband
;
6649 sband
= wiphy
->bands
[band
];
6653 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6654 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6655 mcast_rate
[band
] = i
+ 1;
6665 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6667 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6668 struct net_device
*dev
= info
->user_ptr
[1];
6669 struct cfg80211_ibss_params ibss
;
6670 struct wiphy
*wiphy
;
6671 struct cfg80211_cached_keys
*connkeys
= NULL
;
6674 memset(&ibss
, 0, sizeof(ibss
));
6676 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6679 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6680 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6683 ibss
.beacon_interval
= 100;
6685 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6686 ibss
.beacon_interval
=
6687 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6688 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6692 if (!rdev
->ops
->join_ibss
)
6695 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6698 wiphy
= &rdev
->wiphy
;
6700 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6701 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6703 if (!is_valid_ether_addr(ibss
.bssid
))
6706 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6707 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6709 if (info
->attrs
[NL80211_ATTR_IE
]) {
6710 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6711 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6714 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6718 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
6719 NL80211_IFTYPE_ADHOC
))
6722 switch (ibss
.chandef
.width
) {
6723 case NL80211_CHAN_WIDTH_5
:
6724 case NL80211_CHAN_WIDTH_10
:
6725 case NL80211_CHAN_WIDTH_20_NOHT
:
6727 case NL80211_CHAN_WIDTH_20
:
6728 case NL80211_CHAN_WIDTH_40
:
6729 if (rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
)
6735 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6736 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6738 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6740 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6742 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6743 struct ieee80211_supported_band
*sband
=
6744 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6746 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6752 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6753 memcpy(&ibss
.ht_capa_mask
,
6754 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6755 sizeof(ibss
.ht_capa_mask
));
6757 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6758 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6760 memcpy(&ibss
.ht_capa
,
6761 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6762 sizeof(ibss
.ht_capa
));
6765 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6766 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6767 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6770 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6773 connkeys
= nl80211_parse_connkeys(rdev
,
6774 info
->attrs
[NL80211_ATTR_KEYS
],
6776 if (IS_ERR(connkeys
))
6777 return PTR_ERR(connkeys
);
6779 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6787 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6789 ibss
.userspace_handles_dfs
=
6790 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
6792 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6798 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6800 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6801 struct net_device
*dev
= info
->user_ptr
[1];
6803 if (!rdev
->ops
->leave_ibss
)
6806 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6809 return cfg80211_leave_ibss(rdev
, dev
, false);
6812 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6814 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6815 struct net_device
*dev
= info
->user_ptr
[1];
6816 int mcast_rate
[IEEE80211_NUM_BANDS
];
6820 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6821 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6824 if (!rdev
->ops
->set_mcast_rate
)
6827 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6829 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6832 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6833 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6836 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6841 static struct sk_buff
*
6842 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
6843 int approxlen
, u32 portid
, u32 seq
,
6844 enum nl80211_commands cmd
,
6845 enum nl80211_attrs attr
,
6846 const struct nl80211_vendor_cmd_info
*info
,
6849 struct sk_buff
*skb
;
6851 struct nlattr
*data
;
6853 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6857 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
6863 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6864 goto nla_put_failure
;
6867 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
6869 goto nla_put_failure
;
6870 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
6872 goto nla_put_failure
;
6875 data
= nla_nest_start(skb
, attr
);
6877 ((void **)skb
->cb
)[0] = rdev
;
6878 ((void **)skb
->cb
)[1] = hdr
;
6879 ((void **)skb
->cb
)[2] = data
;
6888 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
6889 enum nl80211_commands cmd
,
6890 enum nl80211_attrs attr
,
6891 int vendor_event_idx
,
6892 int approxlen
, gfp_t gfp
)
6894 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6895 const struct nl80211_vendor_cmd_info
*info
;
6898 case NL80211_CMD_TESTMODE
:
6899 if (WARN_ON(vendor_event_idx
!= -1))
6903 case NL80211_CMD_VENDOR
:
6904 if (WARN_ON(vendor_event_idx
< 0 ||
6905 vendor_event_idx
>= wiphy
->n_vendor_events
))
6907 info
= &wiphy
->vendor_events
[vendor_event_idx
];
6914 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
, 0, 0,
6915 cmd
, attr
, info
, gfp
);
6917 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
6919 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
6921 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6922 void *hdr
= ((void **)skb
->cb
)[1];
6923 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6924 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
6926 nla_nest_end(skb
, data
);
6927 genlmsg_end(skb
, hdr
);
6929 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
6930 mcgrp
= NL80211_MCGRP_VENDOR
;
6932 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
6935 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
6937 #ifdef CONFIG_NL80211_TESTMODE
6938 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6940 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6941 struct wireless_dev
*wdev
=
6942 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
6945 if (!rdev
->ops
->testmode_cmd
)
6949 err
= PTR_ERR(wdev
);
6953 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
6957 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6960 rdev
->cur_cmd_info
= info
;
6961 err
= rdev_testmode_cmd(rdev
, wdev
,
6962 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6963 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6964 rdev
->cur_cmd_info
= NULL
;
6969 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6970 struct netlink_callback
*cb
)
6972 struct cfg80211_registered_device
*rdev
;
6982 * 0 is a valid index, but not valid for args[0],
6983 * so we need to offset by 1.
6985 phy_idx
= cb
->args
[0] - 1;
6987 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6988 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6993 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6994 nl80211_fam
.attrbuf
);
6996 err
= PTR_ERR(rdev
);
6999 phy_idx
= rdev
->wiphy_idx
;
7002 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
7004 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
7008 data
= nla_data((void *)cb
->args
[1]);
7009 data_len
= nla_len((void *)cb
->args
[1]);
7012 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
7018 if (!rdev
->ops
->testmode_dump
) {
7024 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
7025 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7026 NL80211_CMD_TESTMODE
);
7027 struct nlattr
*tmdata
;
7032 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
7033 genlmsg_cancel(skb
, hdr
);
7037 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
7039 genlmsg_cancel(skb
, hdr
);
7042 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
7043 nla_nest_end(skb
, tmdata
);
7045 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
7046 genlmsg_cancel(skb
, hdr
);
7049 genlmsg_cancel(skb
, hdr
);
7053 genlmsg_end(skb
, hdr
);
7058 cb
->args
[0] = phy_idx
+ 1;
7065 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
7067 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7068 struct net_device
*dev
= info
->user_ptr
[1];
7069 struct cfg80211_connect_params connect
;
7070 struct wiphy
*wiphy
;
7071 struct cfg80211_cached_keys
*connkeys
= NULL
;
7074 memset(&connect
, 0, sizeof(connect
));
7076 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7079 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7080 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7083 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
7085 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7086 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
7087 NL80211_CMD_CONNECT
))
7090 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
7092 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
7094 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
7095 NL80211_MAX_NR_CIPHER_SUITES
);
7099 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7100 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7103 wiphy
= &rdev
->wiphy
;
7105 connect
.bg_scan_period
= -1;
7106 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
7107 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
7108 connect
.bg_scan_period
=
7109 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
7112 if (info
->attrs
[NL80211_ATTR_MAC
])
7113 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7114 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
7115 connect
.bssid_hint
=
7116 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
7117 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7118 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7120 if (info
->attrs
[NL80211_ATTR_IE
]) {
7121 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7122 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7125 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7126 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7127 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
7128 connect
.mfp
!= NL80211_MFP_NO
)
7131 connect
.mfp
= NL80211_MFP_NO
;
7134 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7135 connect
.channel
= nl80211_get_valid_chan(
7136 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7137 if (!connect
.channel
)
7139 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
7140 connect
.channel_hint
= nl80211_get_valid_chan(
7141 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
7142 if (!connect
.channel_hint
)
7146 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7147 connkeys
= nl80211_parse_connkeys(rdev
,
7148 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
7149 if (IS_ERR(connkeys
))
7150 return PTR_ERR(connkeys
);
7153 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7154 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
7156 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7157 memcpy(&connect
.ht_capa_mask
,
7158 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7159 sizeof(connect
.ht_capa_mask
));
7161 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7162 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
7166 memcpy(&connect
.ht_capa
,
7167 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7168 sizeof(connect
.ht_capa
));
7171 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7172 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7174 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7175 memcpy(&connect
.vht_capa_mask
,
7176 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7177 sizeof(connect
.vht_capa_mask
));
7179 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7180 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
7184 memcpy(&connect
.vht_capa
,
7185 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7186 sizeof(connect
.vht_capa
));
7189 wdev_lock(dev
->ieee80211_ptr
);
7190 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
7191 wdev_unlock(dev
->ieee80211_ptr
);
7197 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
7199 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7200 struct net_device
*dev
= info
->user_ptr
[1];
7204 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7205 reason
= WLAN_REASON_DEAUTH_LEAVING
;
7207 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7212 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7213 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7216 wdev_lock(dev
->ieee80211_ptr
);
7217 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
7218 wdev_unlock(dev
->ieee80211_ptr
);
7222 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
7224 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7229 if (!info
->attrs
[NL80211_ATTR_PID
])
7232 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
7234 net
= get_net_ns_by_pid(pid
);
7236 return PTR_ERR(net
);
7240 /* check if anything to do */
7241 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
7242 err
= cfg80211_switch_netns(rdev
, net
);
7248 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
7250 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7251 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
7252 struct cfg80211_pmksa
*pmksa
) = NULL
;
7253 struct net_device
*dev
= info
->user_ptr
[1];
7254 struct cfg80211_pmksa pmksa
;
7256 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
7258 if (!info
->attrs
[NL80211_ATTR_MAC
])
7261 if (!info
->attrs
[NL80211_ATTR_PMKID
])
7264 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
7265 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7267 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7268 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7271 switch (info
->genlhdr
->cmd
) {
7272 case NL80211_CMD_SET_PMKSA
:
7273 rdev_ops
= rdev
->ops
->set_pmksa
;
7275 case NL80211_CMD_DEL_PMKSA
:
7276 rdev_ops
= rdev
->ops
->del_pmksa
;
7286 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
7289 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
7291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7292 struct net_device
*dev
= info
->user_ptr
[1];
7294 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7295 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7298 if (!rdev
->ops
->flush_pmksa
)
7301 return rdev_flush_pmksa(rdev
, dev
);
7304 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7306 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7307 struct net_device
*dev
= info
->user_ptr
[1];
7308 u8 action_code
, dialog_token
;
7309 u32 peer_capability
= 0;
7313 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
7314 !rdev
->ops
->tdls_mgmt
)
7317 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
7318 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
7319 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
7320 !info
->attrs
[NL80211_ATTR_IE
] ||
7321 !info
->attrs
[NL80211_ATTR_MAC
])
7324 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7325 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
7326 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
7327 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
7328 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
7330 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
7332 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
7333 dialog_token
, status_code
, peer_capability
,
7334 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
7335 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
7338 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
7340 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7341 struct net_device
*dev
= info
->user_ptr
[1];
7342 enum nl80211_tdls_operation operation
;
7345 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
7346 !rdev
->ops
->tdls_oper
)
7349 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
7350 !info
->attrs
[NL80211_ATTR_MAC
])
7353 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
7354 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7356 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
7359 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
7360 struct genl_info
*info
)
7362 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7363 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7364 struct cfg80211_chan_def chandef
;
7365 struct sk_buff
*msg
;
7371 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7372 !info
->attrs
[NL80211_ATTR_DURATION
])
7375 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7377 if (!rdev
->ops
->remain_on_channel
||
7378 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
7382 * We should be on that channel for at least a minimum amount of
7383 * time (10ms) but no longer than the driver supports.
7385 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7386 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
7389 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7393 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7397 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7398 NL80211_CMD_REMAIN_ON_CHANNEL
);
7404 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
7410 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7411 goto nla_put_failure
;
7413 genlmsg_end(msg
, hdr
);
7415 return genlmsg_reply(msg
, info
);
7424 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7425 struct genl_info
*info
)
7427 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7428 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7431 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7434 if (!rdev
->ops
->cancel_remain_on_channel
)
7437 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7439 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7442 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7443 u8
*rates
, u8 rates_len
)
7448 for (i
= 0; i
< rates_len
; i
++) {
7449 int rate
= (rates
[i
] & 0x7f) * 5;
7451 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7452 struct ieee80211_rate
*srate
=
7453 &sband
->bitrates
[ridx
];
7454 if (rate
== srate
->bitrate
) {
7459 if (ridx
== sband
->n_bitrates
)
7460 return 0; /* rate not found */
7466 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7467 u8
*rates
, u8 rates_len
,
7468 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7472 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7474 for (i
= 0; i
< rates_len
; i
++) {
7477 ridx
= rates
[i
] / 8;
7478 rbit
= BIT(rates
[i
] % 8);
7480 /* check validity */
7481 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7484 /* check availability */
7485 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7494 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
7498 switch (vht_mcs_map
) {
7499 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
7501 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
7504 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
7507 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
7517 static void vht_build_mcs_mask(u16 vht_mcs_map
,
7518 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
7522 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
7523 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
7528 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
7529 struct nl80211_txrate_vht
*txrate
,
7530 u16 mcs
[NL80211_VHT_NSS_MAX
])
7532 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
7533 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
7536 if (!sband
->vht_cap
.vht_supported
)
7539 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
7541 /* Build vht_mcs_mask from VHT capabilities */
7542 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
7544 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
7545 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
7546 mcs
[i
] = txrate
->mcs
[i
];
7554 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7555 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7556 .len
= NL80211_MAX_SUPP_RATES
},
7557 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
7558 .len
= NL80211_MAX_SUPP_HT_RATES
},
7559 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
7560 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
7563 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7564 struct genl_info
*info
)
7566 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7567 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7568 struct cfg80211_bitrate_mask mask
;
7570 struct net_device
*dev
= info
->user_ptr
[1];
7571 struct nlattr
*tx_rates
;
7572 struct ieee80211_supported_band
*sband
;
7575 if (!rdev
->ops
->set_bitrate_mask
)
7578 memset(&mask
, 0, sizeof(mask
));
7579 /* Default to all rates enabled */
7580 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7581 sband
= rdev
->wiphy
.bands
[i
];
7586 mask
.control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
7587 memcpy(mask
.control
[i
].ht_mcs
,
7588 sband
->ht_cap
.mcs
.rx_mask
,
7589 sizeof(mask
.control
[i
].ht_mcs
));
7591 if (!sband
->vht_cap
.vht_supported
)
7594 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
7595 vht_build_mcs_mask(vht_tx_mcs_map
, mask
.control
[i
].vht_mcs
);
7598 /* if no rates are given set it back to the defaults */
7599 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
7603 * The nested attribute uses enum nl80211_band as the index. This maps
7604 * directly to the enum ieee80211_band values used in cfg80211.
7606 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7607 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
7608 enum ieee80211_band band
= nla_type(tx_rates
);
7611 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7613 sband
= rdev
->wiphy
.bands
[band
];
7616 err
= nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7617 nla_len(tx_rates
), nl80211_txattr_policy
);
7620 if (tb
[NL80211_TXRATE_LEGACY
]) {
7621 mask
.control
[band
].legacy
= rateset_to_mask(
7623 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7624 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7625 if ((mask
.control
[band
].legacy
== 0) &&
7626 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7629 if (tb
[NL80211_TXRATE_HT
]) {
7630 if (!ht_rateset_to_mask(
7632 nla_data(tb
[NL80211_TXRATE_HT
]),
7633 nla_len(tb
[NL80211_TXRATE_HT
]),
7634 mask
.control
[band
].ht_mcs
))
7637 if (tb
[NL80211_TXRATE_VHT
]) {
7638 if (!vht_set_mcs_mask(
7640 nla_data(tb
[NL80211_TXRATE_VHT
]),
7641 mask
.control
[band
].vht_mcs
))
7644 if (tb
[NL80211_TXRATE_GI
]) {
7645 mask
.control
[band
].gi
=
7646 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
7647 if (mask
.control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
7651 if (mask
.control
[band
].legacy
== 0) {
7652 /* don't allow empty legacy rates if HT or VHT
7653 * are not even supported.
7655 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
7656 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
7659 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7660 if (mask
.control
[band
].ht_mcs
[i
])
7663 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
7664 if (mask
.control
[band
].vht_mcs
[i
])
7667 /* legacy and mcs rates may not be both empty */
7673 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7676 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7678 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7679 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7680 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7682 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7685 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7686 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7688 switch (wdev
->iftype
) {
7689 case NL80211_IFTYPE_STATION
:
7690 case NL80211_IFTYPE_ADHOC
:
7691 case NL80211_IFTYPE_P2P_CLIENT
:
7692 case NL80211_IFTYPE_AP
:
7693 case NL80211_IFTYPE_AP_VLAN
:
7694 case NL80211_IFTYPE_MESH_POINT
:
7695 case NL80211_IFTYPE_P2P_GO
:
7696 case NL80211_IFTYPE_P2P_DEVICE
:
7702 /* not much point in registering if we can't reply */
7703 if (!rdev
->ops
->mgmt_tx
)
7706 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7707 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7708 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7711 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7713 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7714 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7715 struct cfg80211_chan_def chandef
;
7719 struct sk_buff
*msg
= NULL
;
7720 struct cfg80211_mgmt_tx_params params
= {
7721 .dont_wait_for_ack
=
7722 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
7725 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7728 if (!rdev
->ops
->mgmt_tx
)
7731 switch (wdev
->iftype
) {
7732 case NL80211_IFTYPE_P2P_DEVICE
:
7733 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7735 case NL80211_IFTYPE_STATION
:
7736 case NL80211_IFTYPE_ADHOC
:
7737 case NL80211_IFTYPE_P2P_CLIENT
:
7738 case NL80211_IFTYPE_AP
:
7739 case NL80211_IFTYPE_AP_VLAN
:
7740 case NL80211_IFTYPE_MESH_POINT
:
7741 case NL80211_IFTYPE_P2P_GO
:
7747 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7748 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7750 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7753 * We should wait on the channel for at least a minimum amount
7754 * of time (10ms) but no longer than the driver supports.
7756 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7757 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7762 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7764 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7767 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7769 /* get the channel if any has been specified, otherwise pass NULL to
7770 * the driver. The latter will use the current one
7772 chandef
.chan
= NULL
;
7773 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7774 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7779 if (!chandef
.chan
&& params
.offchan
)
7782 if (!params
.dont_wait_for_ack
) {
7783 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7787 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7795 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
7796 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
7797 params
.chan
= chandef
.chan
;
7798 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
7803 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7804 goto nla_put_failure
;
7806 genlmsg_end(msg
, hdr
);
7807 return genlmsg_reply(msg
, info
);
7819 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7821 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7822 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7825 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7828 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7831 switch (wdev
->iftype
) {
7832 case NL80211_IFTYPE_STATION
:
7833 case NL80211_IFTYPE_ADHOC
:
7834 case NL80211_IFTYPE_P2P_CLIENT
:
7835 case NL80211_IFTYPE_AP
:
7836 case NL80211_IFTYPE_AP_VLAN
:
7837 case NL80211_IFTYPE_P2P_GO
:
7838 case NL80211_IFTYPE_P2P_DEVICE
:
7844 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7846 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7849 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7851 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7852 struct wireless_dev
*wdev
;
7853 struct net_device
*dev
= info
->user_ptr
[1];
7858 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7861 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7863 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7866 wdev
= dev
->ieee80211_ptr
;
7868 if (!rdev
->ops
->set_power_mgmt
)
7871 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7873 if (state
== wdev
->ps
)
7876 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7882 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7884 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7885 enum nl80211_ps_state ps_state
;
7886 struct wireless_dev
*wdev
;
7887 struct net_device
*dev
= info
->user_ptr
[1];
7888 struct sk_buff
*msg
;
7892 wdev
= dev
->ieee80211_ptr
;
7894 if (!rdev
->ops
->set_power_mgmt
)
7897 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7901 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7902 NL80211_CMD_GET_POWER_SAVE
);
7909 ps_state
= NL80211_PS_ENABLED
;
7911 ps_state
= NL80211_PS_DISABLED
;
7913 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7914 goto nla_put_failure
;
7916 genlmsg_end(msg
, hdr
);
7917 return genlmsg_reply(msg
, info
);
7926 static const struct nla_policy
7927 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
7928 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7929 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7930 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7931 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7932 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7933 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7936 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7937 u32 rate
, u32 pkts
, u32 intvl
)
7939 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7940 struct net_device
*dev
= info
->user_ptr
[1];
7941 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7943 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7946 if (!rdev
->ops
->set_cqm_txe_config
)
7949 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7950 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7953 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7956 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7957 s32 threshold
, u32 hysteresis
)
7959 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7960 struct net_device
*dev
= info
->user_ptr
[1];
7961 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7966 /* disabling - hysteresis should also be zero then */
7970 if (!rdev
->ops
->set_cqm_rssi_config
)
7973 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7974 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7977 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7980 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7982 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7986 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7990 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7991 nl80211_attr_cqm_policy
);
7995 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7996 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7997 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7998 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
8000 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
8003 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
8004 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
8005 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
8006 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
8007 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
8008 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
8010 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
8016 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8018 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8019 struct net_device
*dev
= info
->user_ptr
[1];
8020 struct mesh_config cfg
;
8021 struct mesh_setup setup
;
8024 /* start with default */
8025 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
8026 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
8028 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
8029 /* and parse parameters if given */
8030 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
8035 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
8036 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
8039 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8040 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8042 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8043 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
8044 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8047 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
8048 setup
.beacon_interval
=
8049 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8050 if (setup
.beacon_interval
< 10 ||
8051 setup
.beacon_interval
> 10000)
8055 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
8057 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
8058 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
8062 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
8063 /* parse additional setup parameters if given */
8064 err
= nl80211_parse_mesh_setup(info
, &setup
);
8070 cfg
.auto_open_plinks
= false;
8072 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8073 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8077 /* cfg80211_join_mesh() will sort it out */
8078 setup
.chandef
.chan
= NULL
;
8081 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8082 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8084 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8085 struct ieee80211_supported_band
*sband
;
8087 if (!setup
.chandef
.chan
)
8090 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
8092 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8093 &setup
.basic_rates
);
8098 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
8101 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8103 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8104 struct net_device
*dev
= info
->user_ptr
[1];
8106 return cfg80211_leave_mesh(rdev
, dev
);
8110 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
8111 struct cfg80211_registered_device
*rdev
)
8113 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
8114 struct nlattr
*nl_pats
, *nl_pat
;
8117 if (!wowlan
->n_patterns
)
8120 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
8124 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
8125 nl_pat
= nla_nest_start(msg
, i
+ 1);
8128 pat_len
= wowlan
->patterns
[i
].pattern_len
;
8129 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
8130 wowlan
->patterns
[i
].mask
) ||
8131 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8132 wowlan
->patterns
[i
].pattern
) ||
8133 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8134 wowlan
->patterns
[i
].pkt_offset
))
8136 nla_nest_end(msg
, nl_pat
);
8138 nla_nest_end(msg
, nl_pats
);
8143 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
8144 struct cfg80211_wowlan_tcp
*tcp
)
8146 struct nlattr
*nl_tcp
;
8151 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
8155 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
8156 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
8157 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
8158 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
8159 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
8160 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
8161 tcp
->payload_len
, tcp
->payload
) ||
8162 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
8163 tcp
->data_interval
) ||
8164 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
8165 tcp
->wake_len
, tcp
->wake_data
) ||
8166 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
8167 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
8170 if (tcp
->payload_seq
.len
&&
8171 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
8172 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
8175 if (tcp
->payload_tok
.len
&&
8176 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
8177 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
8181 nla_nest_end(msg
, nl_tcp
);
8186 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
8188 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8189 struct sk_buff
*msg
;
8191 u32 size
= NLMSG_DEFAULT_SIZE
;
8193 if (!rdev
->wiphy
.wowlan
)
8196 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
8197 /* adjust size to have room for all the data */
8198 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
8199 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
8200 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
8201 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
8204 msg
= nlmsg_new(size
, GFP_KERNEL
);
8208 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8209 NL80211_CMD_GET_WOWLAN
);
8211 goto nla_put_failure
;
8213 if (rdev
->wiphy
.wowlan_config
) {
8214 struct nlattr
*nl_wowlan
;
8216 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
8218 goto nla_put_failure
;
8220 if ((rdev
->wiphy
.wowlan_config
->any
&&
8221 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
8222 (rdev
->wiphy
.wowlan_config
->disconnect
&&
8223 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
8224 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
8225 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
8226 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
8227 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
8228 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
8229 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
8230 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
8231 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
8232 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
8233 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
8234 goto nla_put_failure
;
8236 if (nl80211_send_wowlan_patterns(msg
, rdev
))
8237 goto nla_put_failure
;
8239 if (nl80211_send_wowlan_tcp(msg
,
8240 rdev
->wiphy
.wowlan_config
->tcp
))
8241 goto nla_put_failure
;
8243 nla_nest_end(msg
, nl_wowlan
);
8246 genlmsg_end(msg
, hdr
);
8247 return genlmsg_reply(msg
, info
);
8254 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
8255 struct nlattr
*attr
,
8256 struct cfg80211_wowlan
*trig
)
8258 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
8259 struct cfg80211_wowlan_tcp
*cfg
;
8260 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
8261 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
8263 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
8266 if (!rdev
->wiphy
.wowlan
->tcp
)
8269 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
8270 nla_data(attr
), nla_len(attr
),
8271 nl80211_wowlan_tcp_policy
);
8275 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
8276 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
8277 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
8278 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
8279 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
8280 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
8281 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
8282 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
8285 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
8286 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
8289 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
8290 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
8291 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
8294 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
8295 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
8298 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
8299 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
8302 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
8303 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
8305 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
8306 tokens_size
= tokln
- sizeof(*tok
);
8308 if (!tok
->len
|| tokens_size
% tok
->len
)
8310 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
8312 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
8314 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
8316 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
8318 if (tok
->offset
+ tok
->len
> data_size
)
8322 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
8323 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
8324 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
8326 if (seq
->len
== 0 || seq
->len
> 4)
8328 if (seq
->len
+ seq
->offset
> data_size
)
8332 size
= sizeof(*cfg
);
8334 size
+= wake_size
+ wake_mask_size
;
8335 size
+= tokens_size
;
8337 cfg
= kzalloc(size
, GFP_KERNEL
);
8340 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
8341 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
8342 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
8344 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
8345 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
8349 /* allocate a socket and port for it and use it */
8350 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
8351 IPPROTO_TCP
, &cfg
->sock
, 1);
8356 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
8357 sock_release(cfg
->sock
);
8361 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
8367 cfg
->src_port
= port
;
8370 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
8371 cfg
->payload_len
= data_size
;
8372 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
8373 memcpy((void *)cfg
->payload
,
8374 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
8377 cfg
->payload_seq
= *seq
;
8378 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
8379 cfg
->wake_len
= wake_size
;
8380 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
8381 memcpy((void *)cfg
->wake_data
,
8382 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
8384 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
8385 data_size
+ wake_size
;
8386 memcpy((void *)cfg
->wake_mask
,
8387 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
8390 cfg
->tokens_size
= tokens_size
;
8391 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
8399 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
8401 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8402 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
8403 struct cfg80211_wowlan new_triggers
= {};
8404 struct cfg80211_wowlan
*ntrig
;
8405 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
8407 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
8412 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
8413 cfg80211_rdev_free_wowlan(rdev
);
8414 rdev
->wiphy
.wowlan_config
= NULL
;
8418 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
8419 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
8420 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
8421 nl80211_wowlan_policy
);
8425 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
8426 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
8428 new_triggers
.any
= true;
8431 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
8432 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
8434 new_triggers
.disconnect
= true;
8437 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
8438 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
8440 new_triggers
.magic_pkt
= true;
8443 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
8446 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
8447 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
8449 new_triggers
.gtk_rekey_failure
= true;
8452 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
8453 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
8455 new_triggers
.eap_identity_req
= true;
8458 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
8459 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
8461 new_triggers
.four_way_handshake
= true;
8464 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
8465 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
8467 new_triggers
.rfkill_release
= true;
8470 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
8473 int rem
, pat_len
, mask_len
, pkt_offset
;
8474 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
8476 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
8479 if (n_patterns
> wowlan
->n_patterns
)
8482 new_triggers
.patterns
= kcalloc(n_patterns
,
8483 sizeof(new_triggers
.patterns
[0]),
8485 if (!new_triggers
.patterns
)
8488 new_triggers
.n_patterns
= n_patterns
;
8491 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
8493 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
8494 nla_len(pat
), NULL
);
8496 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
8497 !pat_tb
[NL80211_PKTPAT_PATTERN
])
8499 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
8500 mask_len
= DIV_ROUND_UP(pat_len
, 8);
8501 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
8503 if (pat_len
> wowlan
->pattern_max_len
||
8504 pat_len
< wowlan
->pattern_min_len
)
8507 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
8510 pkt_offset
= nla_get_u32(
8511 pat_tb
[NL80211_PKTPAT_OFFSET
]);
8512 if (pkt_offset
> wowlan
->max_pkt_offset
)
8514 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
8516 new_triggers
.patterns
[i
].mask
=
8517 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
8518 if (!new_triggers
.patterns
[i
].mask
) {
8522 new_triggers
.patterns
[i
].pattern
=
8523 new_triggers
.patterns
[i
].mask
+ mask_len
;
8524 memcpy(new_triggers
.patterns
[i
].mask
,
8525 nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
8527 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
8528 memcpy(new_triggers
.patterns
[i
].pattern
,
8529 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
8535 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8536 err
= nl80211_parse_wowlan_tcp(
8537 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8543 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8548 cfg80211_rdev_free_wowlan(rdev
);
8549 rdev
->wiphy
.wowlan_config
= ntrig
;
8552 if (rdev
->ops
->set_wakeup
&&
8553 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
8554 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
8558 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8559 kfree(new_triggers
.patterns
[i
].mask
);
8560 kfree(new_triggers
.patterns
);
8561 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8562 sock_release(new_triggers
.tcp
->sock
);
8563 kfree(new_triggers
.tcp
);
8568 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
8569 struct cfg80211_registered_device
*rdev
)
8571 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
8573 struct cfg80211_coalesce_rules
*rule
;
8575 if (!rdev
->coalesce
->n_rules
)
8578 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
8582 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
8583 nl_rule
= nla_nest_start(msg
, i
+ 1);
8587 rule
= &rdev
->coalesce
->rules
[i
];
8588 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
8592 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
8596 nl_pats
= nla_nest_start(msg
,
8597 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
8601 for (j
= 0; j
< rule
->n_patterns
; j
++) {
8602 nl_pat
= nla_nest_start(msg
, j
+ 1);
8605 pat_len
= rule
->patterns
[j
].pattern_len
;
8606 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
8607 DIV_ROUND_UP(pat_len
, 8),
8608 rule
->patterns
[j
].mask
) ||
8609 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8610 rule
->patterns
[j
].pattern
) ||
8611 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8612 rule
->patterns
[j
].pkt_offset
))
8614 nla_nest_end(msg
, nl_pat
);
8616 nla_nest_end(msg
, nl_pats
);
8617 nla_nest_end(msg
, nl_rule
);
8619 nla_nest_end(msg
, nl_rules
);
8624 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
8626 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8627 struct sk_buff
*msg
;
8630 if (!rdev
->wiphy
.coalesce
)
8633 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8637 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8638 NL80211_CMD_GET_COALESCE
);
8640 goto nla_put_failure
;
8642 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
8643 goto nla_put_failure
;
8645 genlmsg_end(msg
, hdr
);
8646 return genlmsg_reply(msg
, info
);
8653 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
8655 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
8657 struct cfg80211_coalesce_rules
*rule
;
8662 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
8663 rule
= &coalesce
->rules
[i
];
8664 for (j
= 0; j
< rule
->n_patterns
; j
++)
8665 kfree(rule
->patterns
[j
].mask
);
8666 kfree(rule
->patterns
);
8668 kfree(coalesce
->rules
);
8670 rdev
->coalesce
= NULL
;
8673 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
8674 struct nlattr
*rule
,
8675 struct cfg80211_coalesce_rules
*new_rule
)
8678 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
8679 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
8680 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
8681 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
8683 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
8684 nla_len(rule
), nl80211_coalesce_policy
);
8688 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
8690 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
8691 if (new_rule
->delay
> coalesce
->max_delay
)
8694 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
8695 new_rule
->condition
=
8696 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
8697 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
8698 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
8701 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
8704 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
8707 if (n_patterns
> coalesce
->n_patterns
)
8710 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
8712 if (!new_rule
->patterns
)
8715 new_rule
->n_patterns
= n_patterns
;
8718 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
8720 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
8721 nla_len(pat
), NULL
);
8722 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
8723 !pat_tb
[NL80211_PKTPAT_PATTERN
])
8725 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
8726 mask_len
= DIV_ROUND_UP(pat_len
, 8);
8727 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
8729 if (pat_len
> coalesce
->pattern_max_len
||
8730 pat_len
< coalesce
->pattern_min_len
)
8733 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
8736 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
8737 if (pkt_offset
> coalesce
->max_pkt_offset
)
8739 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
8741 new_rule
->patterns
[i
].mask
=
8742 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
8743 if (!new_rule
->patterns
[i
].mask
)
8745 new_rule
->patterns
[i
].pattern
=
8746 new_rule
->patterns
[i
].mask
+ mask_len
;
8747 memcpy(new_rule
->patterns
[i
].mask
,
8748 nla_data(pat_tb
[NL80211_PKTPAT_MASK
]), mask_len
);
8749 new_rule
->patterns
[i
].pattern_len
= pat_len
;
8750 memcpy(new_rule
->patterns
[i
].pattern
,
8751 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]), pat_len
);
8758 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
8760 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8761 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
8762 struct cfg80211_coalesce new_coalesce
= {};
8763 struct cfg80211_coalesce
*n_coalesce
;
8764 int err
, rem_rule
, n_rules
= 0, i
, j
;
8765 struct nlattr
*rule
;
8766 struct cfg80211_coalesce_rules
*tmp_rule
;
8768 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
8771 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
8772 cfg80211_rdev_free_coalesce(rdev
);
8773 rdev
->ops
->set_coalesce(&rdev
->wiphy
, NULL
);
8777 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
8780 if (n_rules
> coalesce
->n_rules
)
8783 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
8785 if (!new_coalesce
.rules
)
8788 new_coalesce
.n_rules
= n_rules
;
8791 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
8793 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
8794 &new_coalesce
.rules
[i
]);
8801 err
= rdev
->ops
->set_coalesce(&rdev
->wiphy
, &new_coalesce
);
8805 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
8810 cfg80211_rdev_free_coalesce(rdev
);
8811 rdev
->coalesce
= n_coalesce
;
8815 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
8816 tmp_rule
= &new_coalesce
.rules
[i
];
8817 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
8818 kfree(tmp_rule
->patterns
[j
].mask
);
8819 kfree(tmp_rule
->patterns
);
8821 kfree(new_coalesce
.rules
);
8826 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8828 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8829 struct net_device
*dev
= info
->user_ptr
[1];
8830 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8831 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8832 struct cfg80211_gtk_rekey_data rekey_data
;
8835 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8838 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8839 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8840 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8841 nl80211_rekey_policy
);
8845 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8847 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8849 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8852 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8854 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8856 memcpy(rekey_data
.replay_ctr
,
8857 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8858 NL80211_REPLAY_CTR_LEN
);
8861 if (!wdev
->current_bss
) {
8866 if (!rdev
->ops
->set_rekey_data
) {
8871 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8877 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8878 struct genl_info
*info
)
8880 struct net_device
*dev
= info
->user_ptr
[1];
8881 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8883 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8884 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8887 if (wdev
->ap_unexpected_nlportid
)
8890 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8894 static int nl80211_probe_client(struct sk_buff
*skb
,
8895 struct genl_info
*info
)
8897 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8898 struct net_device
*dev
= info
->user_ptr
[1];
8899 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8900 struct sk_buff
*msg
;
8906 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8907 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8910 if (!info
->attrs
[NL80211_ATTR_MAC
])
8913 if (!rdev
->ops
->probe_client
)
8916 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8920 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8921 NL80211_CMD_PROBE_CLIENT
);
8927 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8929 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8933 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8934 goto nla_put_failure
;
8936 genlmsg_end(msg
, hdr
);
8938 return genlmsg_reply(msg
, info
);
8947 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8949 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8950 struct cfg80211_beacon_registration
*reg
, *nreg
;
8953 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8956 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8960 /* First, check if already registered. */
8961 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8962 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8963 if (reg
->nlportid
== info
->snd_portid
) {
8968 /* Add it to the list */
8969 nreg
->nlportid
= info
->snd_portid
;
8970 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8972 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8976 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8981 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8983 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8984 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8987 if (!rdev
->ops
->start_p2p_device
)
8990 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8993 if (wdev
->p2p_started
)
8996 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
9000 err
= rdev_start_p2p_device(rdev
, wdev
);
9004 wdev
->p2p_started
= true;
9010 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9012 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9013 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9015 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9018 if (!rdev
->ops
->stop_p2p_device
)
9021 cfg80211_stop_p2p_device(rdev
, wdev
);
9026 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
9027 struct genl_info
*info
)
9030 struct sk_buff
*msg
;
9032 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9036 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9037 NL80211_CMD_GET_PROTOCOL_FEATURES
);
9039 goto nla_put_failure
;
9041 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
9042 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
9043 goto nla_put_failure
;
9045 genlmsg_end(msg
, hdr
);
9046 return genlmsg_reply(msg
, info
);
9053 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
9055 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9056 struct cfg80211_update_ft_ies_params ft_params
;
9057 struct net_device
*dev
= info
->user_ptr
[1];
9059 if (!rdev
->ops
->update_ft_ies
)
9062 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
9063 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9066 memset(&ft_params
, 0, sizeof(ft_params
));
9067 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
9068 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9069 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9071 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
9074 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
9075 struct genl_info
*info
)
9077 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9078 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9079 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
9083 if (!rdev
->ops
->crit_proto_start
)
9086 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
9089 if (rdev
->crit_proto_nlportid
)
9092 /* determine protocol if provided */
9093 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
9094 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
9096 if (proto
>= NUM_NL80211_CRIT_PROTO
)
9099 /* timeout must be provided */
9100 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
9104 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
9106 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
9109 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
9111 rdev
->crit_proto_nlportid
= info
->snd_portid
;
9116 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
9117 struct genl_info
*info
)
9119 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9120 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9122 if (!rdev
->ops
->crit_proto_stop
)
9125 if (rdev
->crit_proto_nlportid
) {
9126 rdev
->crit_proto_nlportid
= 0;
9127 rdev_crit_proto_stop(rdev
, wdev
);
9132 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
9134 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9135 struct wireless_dev
*wdev
=
9136 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
9140 if (!rdev
->wiphy
.vendor_commands
)
9144 err
= PTR_ERR(wdev
);
9148 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
9152 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
9153 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
9156 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
9157 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
9158 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
9159 const struct wiphy_vendor_command
*vcmd
;
9163 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
9165 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
9168 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
9169 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
9172 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
9176 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
9178 !netif_running(wdev
->netdev
))
9180 if (!wdev
->netdev
&& !wdev
->p2p_started
)
9187 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
9188 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
9189 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
9192 rdev
->cur_cmd_info
= info
;
9193 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
9195 rdev
->cur_cmd_info
= NULL
;
9202 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
9203 enum nl80211_commands cmd
,
9204 enum nl80211_attrs attr
,
9207 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9209 if (WARN_ON(!rdev
->cur_cmd_info
))
9212 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
,
9213 rdev
->cur_cmd_info
->snd_portid
,
9214 rdev
->cur_cmd_info
->snd_seq
,
9215 cmd
, attr
, NULL
, GFP_KERNEL
);
9217 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
9219 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
9221 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
9222 void *hdr
= ((void **)skb
->cb
)[1];
9223 struct nlattr
*data
= ((void **)skb
->cb
)[2];
9225 if (WARN_ON(!rdev
->cur_cmd_info
)) {
9230 nla_nest_end(skb
, data
);
9231 genlmsg_end(skb
, hdr
);
9232 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
9234 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
9237 static int nl80211_set_qos_map(struct sk_buff
*skb
,
9238 struct genl_info
*info
)
9240 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9241 struct cfg80211_qos_map
*qos_map
= NULL
;
9242 struct net_device
*dev
= info
->user_ptr
[1];
9243 u8
*pos
, len
, num_des
, des_len
, des
;
9246 if (!rdev
->ops
->set_qos_map
)
9249 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
9250 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
9251 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
9253 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
9254 len
> IEEE80211_QOS_MAP_LEN_MAX
)
9257 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
9261 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
9264 sizeof(struct cfg80211_dscp_exception
);
9265 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
9266 qos_map
->num_des
= num_des
;
9267 for (des
= 0; des
< num_des
; des
++) {
9268 if (qos_map
->dscp_exception
[des
].up
> 7) {
9275 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
9278 wdev_lock(dev
->ieee80211_ptr
);
9279 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
9281 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
9282 wdev_unlock(dev
->ieee80211_ptr
);
9288 #define NL80211_FLAG_NEED_WIPHY 0x01
9289 #define NL80211_FLAG_NEED_NETDEV 0x02
9290 #define NL80211_FLAG_NEED_RTNL 0x04
9291 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9292 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9293 NL80211_FLAG_CHECK_NETDEV_UP)
9294 #define NL80211_FLAG_NEED_WDEV 0x10
9295 /* If a netdev is associated, it must be UP, P2P must be started */
9296 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9297 NL80211_FLAG_CHECK_NETDEV_UP)
9299 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
9300 struct genl_info
*info
)
9302 struct cfg80211_registered_device
*rdev
;
9303 struct wireless_dev
*wdev
;
9304 struct net_device
*dev
;
9305 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
9310 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
9311 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
9315 return PTR_ERR(rdev
);
9317 info
->user_ptr
[0] = rdev
;
9318 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
9319 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
9322 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
9327 return PTR_ERR(wdev
);
9331 rdev
= wiphy_to_dev(wdev
->wiphy
);
9333 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
9340 info
->user_ptr
[1] = dev
;
9342 info
->user_ptr
[1] = wdev
;
9346 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
9347 !netif_running(dev
)) {
9354 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
9355 if (!wdev
->p2p_started
) {
9362 info
->user_ptr
[0] = rdev
;
9368 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
9369 struct genl_info
*info
)
9371 if (info
->user_ptr
[1]) {
9372 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
9373 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9376 dev_put(wdev
->netdev
);
9378 dev_put(info
->user_ptr
[1]);
9381 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
9385 static const struct genl_ops nl80211_ops
[] = {
9387 .cmd
= NL80211_CMD_GET_WIPHY
,
9388 .doit
= nl80211_get_wiphy
,
9389 .dumpit
= nl80211_dump_wiphy
,
9390 .done
= nl80211_dump_wiphy_done
,
9391 .policy
= nl80211_policy
,
9392 /* can be retrieved by unprivileged users */
9393 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9394 NL80211_FLAG_NEED_RTNL
,
9397 .cmd
= NL80211_CMD_SET_WIPHY
,
9398 .doit
= nl80211_set_wiphy
,
9399 .policy
= nl80211_policy
,
9400 .flags
= GENL_ADMIN_PERM
,
9401 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9404 .cmd
= NL80211_CMD_GET_INTERFACE
,
9405 .doit
= nl80211_get_interface
,
9406 .dumpit
= nl80211_dump_interface
,
9407 .policy
= nl80211_policy
,
9408 /* can be retrieved by unprivileged users */
9409 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9410 NL80211_FLAG_NEED_RTNL
,
9413 .cmd
= NL80211_CMD_SET_INTERFACE
,
9414 .doit
= nl80211_set_interface
,
9415 .policy
= nl80211_policy
,
9416 .flags
= GENL_ADMIN_PERM
,
9417 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9418 NL80211_FLAG_NEED_RTNL
,
9421 .cmd
= NL80211_CMD_NEW_INTERFACE
,
9422 .doit
= nl80211_new_interface
,
9423 .policy
= nl80211_policy
,
9424 .flags
= GENL_ADMIN_PERM
,
9425 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9426 NL80211_FLAG_NEED_RTNL
,
9429 .cmd
= NL80211_CMD_DEL_INTERFACE
,
9430 .doit
= nl80211_del_interface
,
9431 .policy
= nl80211_policy
,
9432 .flags
= GENL_ADMIN_PERM
,
9433 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9434 NL80211_FLAG_NEED_RTNL
,
9437 .cmd
= NL80211_CMD_GET_KEY
,
9438 .doit
= nl80211_get_key
,
9439 .policy
= nl80211_policy
,
9440 .flags
= GENL_ADMIN_PERM
,
9441 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9442 NL80211_FLAG_NEED_RTNL
,
9445 .cmd
= NL80211_CMD_SET_KEY
,
9446 .doit
= nl80211_set_key
,
9447 .policy
= nl80211_policy
,
9448 .flags
= GENL_ADMIN_PERM
,
9449 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9450 NL80211_FLAG_NEED_RTNL
,
9453 .cmd
= NL80211_CMD_NEW_KEY
,
9454 .doit
= nl80211_new_key
,
9455 .policy
= nl80211_policy
,
9456 .flags
= GENL_ADMIN_PERM
,
9457 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9458 NL80211_FLAG_NEED_RTNL
,
9461 .cmd
= NL80211_CMD_DEL_KEY
,
9462 .doit
= nl80211_del_key
,
9463 .policy
= nl80211_policy
,
9464 .flags
= GENL_ADMIN_PERM
,
9465 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9466 NL80211_FLAG_NEED_RTNL
,
9469 .cmd
= NL80211_CMD_SET_BEACON
,
9470 .policy
= nl80211_policy
,
9471 .flags
= GENL_ADMIN_PERM
,
9472 .doit
= nl80211_set_beacon
,
9473 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9474 NL80211_FLAG_NEED_RTNL
,
9477 .cmd
= NL80211_CMD_START_AP
,
9478 .policy
= nl80211_policy
,
9479 .flags
= GENL_ADMIN_PERM
,
9480 .doit
= nl80211_start_ap
,
9481 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9482 NL80211_FLAG_NEED_RTNL
,
9485 .cmd
= NL80211_CMD_STOP_AP
,
9486 .policy
= nl80211_policy
,
9487 .flags
= GENL_ADMIN_PERM
,
9488 .doit
= nl80211_stop_ap
,
9489 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9490 NL80211_FLAG_NEED_RTNL
,
9493 .cmd
= NL80211_CMD_GET_STATION
,
9494 .doit
= nl80211_get_station
,
9495 .dumpit
= nl80211_dump_station
,
9496 .policy
= nl80211_policy
,
9497 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9498 NL80211_FLAG_NEED_RTNL
,
9501 .cmd
= NL80211_CMD_SET_STATION
,
9502 .doit
= nl80211_set_station
,
9503 .policy
= nl80211_policy
,
9504 .flags
= GENL_ADMIN_PERM
,
9505 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9506 NL80211_FLAG_NEED_RTNL
,
9509 .cmd
= NL80211_CMD_NEW_STATION
,
9510 .doit
= nl80211_new_station
,
9511 .policy
= nl80211_policy
,
9512 .flags
= GENL_ADMIN_PERM
,
9513 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9514 NL80211_FLAG_NEED_RTNL
,
9517 .cmd
= NL80211_CMD_DEL_STATION
,
9518 .doit
= nl80211_del_station
,
9519 .policy
= nl80211_policy
,
9520 .flags
= GENL_ADMIN_PERM
,
9521 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9522 NL80211_FLAG_NEED_RTNL
,
9525 .cmd
= NL80211_CMD_GET_MPATH
,
9526 .doit
= nl80211_get_mpath
,
9527 .dumpit
= nl80211_dump_mpath
,
9528 .policy
= nl80211_policy
,
9529 .flags
= GENL_ADMIN_PERM
,
9530 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9531 NL80211_FLAG_NEED_RTNL
,
9534 .cmd
= NL80211_CMD_SET_MPATH
,
9535 .doit
= nl80211_set_mpath
,
9536 .policy
= nl80211_policy
,
9537 .flags
= GENL_ADMIN_PERM
,
9538 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9539 NL80211_FLAG_NEED_RTNL
,
9542 .cmd
= NL80211_CMD_NEW_MPATH
,
9543 .doit
= nl80211_new_mpath
,
9544 .policy
= nl80211_policy
,
9545 .flags
= GENL_ADMIN_PERM
,
9546 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9547 NL80211_FLAG_NEED_RTNL
,
9550 .cmd
= NL80211_CMD_DEL_MPATH
,
9551 .doit
= nl80211_del_mpath
,
9552 .policy
= nl80211_policy
,
9553 .flags
= GENL_ADMIN_PERM
,
9554 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9555 NL80211_FLAG_NEED_RTNL
,
9558 .cmd
= NL80211_CMD_SET_BSS
,
9559 .doit
= nl80211_set_bss
,
9560 .policy
= nl80211_policy
,
9561 .flags
= GENL_ADMIN_PERM
,
9562 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9563 NL80211_FLAG_NEED_RTNL
,
9566 .cmd
= NL80211_CMD_GET_REG
,
9567 .doit
= nl80211_get_reg
,
9568 .policy
= nl80211_policy
,
9569 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9570 /* can be retrieved by unprivileged users */
9573 .cmd
= NL80211_CMD_SET_REG
,
9574 .doit
= nl80211_set_reg
,
9575 .policy
= nl80211_policy
,
9576 .flags
= GENL_ADMIN_PERM
,
9577 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9580 .cmd
= NL80211_CMD_REQ_SET_REG
,
9581 .doit
= nl80211_req_set_reg
,
9582 .policy
= nl80211_policy
,
9583 .flags
= GENL_ADMIN_PERM
,
9586 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
9587 .doit
= nl80211_get_mesh_config
,
9588 .policy
= nl80211_policy
,
9589 /* can be retrieved by unprivileged users */
9590 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9591 NL80211_FLAG_NEED_RTNL
,
9594 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
9595 .doit
= nl80211_update_mesh_config
,
9596 .policy
= nl80211_policy
,
9597 .flags
= GENL_ADMIN_PERM
,
9598 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9599 NL80211_FLAG_NEED_RTNL
,
9602 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
9603 .doit
= nl80211_trigger_scan
,
9604 .policy
= nl80211_policy
,
9605 .flags
= GENL_ADMIN_PERM
,
9606 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9607 NL80211_FLAG_NEED_RTNL
,
9610 .cmd
= NL80211_CMD_GET_SCAN
,
9611 .policy
= nl80211_policy
,
9612 .dumpit
= nl80211_dump_scan
,
9615 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
9616 .doit
= nl80211_start_sched_scan
,
9617 .policy
= nl80211_policy
,
9618 .flags
= GENL_ADMIN_PERM
,
9619 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9620 NL80211_FLAG_NEED_RTNL
,
9623 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
9624 .doit
= nl80211_stop_sched_scan
,
9625 .policy
= nl80211_policy
,
9626 .flags
= GENL_ADMIN_PERM
,
9627 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9628 NL80211_FLAG_NEED_RTNL
,
9631 .cmd
= NL80211_CMD_AUTHENTICATE
,
9632 .doit
= nl80211_authenticate
,
9633 .policy
= nl80211_policy
,
9634 .flags
= GENL_ADMIN_PERM
,
9635 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9636 NL80211_FLAG_NEED_RTNL
,
9639 .cmd
= NL80211_CMD_ASSOCIATE
,
9640 .doit
= nl80211_associate
,
9641 .policy
= nl80211_policy
,
9642 .flags
= GENL_ADMIN_PERM
,
9643 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9644 NL80211_FLAG_NEED_RTNL
,
9647 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
9648 .doit
= nl80211_deauthenticate
,
9649 .policy
= nl80211_policy
,
9650 .flags
= GENL_ADMIN_PERM
,
9651 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9652 NL80211_FLAG_NEED_RTNL
,
9655 .cmd
= NL80211_CMD_DISASSOCIATE
,
9656 .doit
= nl80211_disassociate
,
9657 .policy
= nl80211_policy
,
9658 .flags
= GENL_ADMIN_PERM
,
9659 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9660 NL80211_FLAG_NEED_RTNL
,
9663 .cmd
= NL80211_CMD_JOIN_IBSS
,
9664 .doit
= nl80211_join_ibss
,
9665 .policy
= nl80211_policy
,
9666 .flags
= GENL_ADMIN_PERM
,
9667 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9668 NL80211_FLAG_NEED_RTNL
,
9671 .cmd
= NL80211_CMD_LEAVE_IBSS
,
9672 .doit
= nl80211_leave_ibss
,
9673 .policy
= nl80211_policy
,
9674 .flags
= GENL_ADMIN_PERM
,
9675 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9676 NL80211_FLAG_NEED_RTNL
,
9678 #ifdef CONFIG_NL80211_TESTMODE
9680 .cmd
= NL80211_CMD_TESTMODE
,
9681 .doit
= nl80211_testmode_do
,
9682 .dumpit
= nl80211_testmode_dump
,
9683 .policy
= nl80211_policy
,
9684 .flags
= GENL_ADMIN_PERM
,
9685 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9686 NL80211_FLAG_NEED_RTNL
,
9690 .cmd
= NL80211_CMD_CONNECT
,
9691 .doit
= nl80211_connect
,
9692 .policy
= nl80211_policy
,
9693 .flags
= GENL_ADMIN_PERM
,
9694 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9695 NL80211_FLAG_NEED_RTNL
,
9698 .cmd
= NL80211_CMD_DISCONNECT
,
9699 .doit
= nl80211_disconnect
,
9700 .policy
= nl80211_policy
,
9701 .flags
= GENL_ADMIN_PERM
,
9702 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9703 NL80211_FLAG_NEED_RTNL
,
9706 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
9707 .doit
= nl80211_wiphy_netns
,
9708 .policy
= nl80211_policy
,
9709 .flags
= GENL_ADMIN_PERM
,
9710 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9711 NL80211_FLAG_NEED_RTNL
,
9714 .cmd
= NL80211_CMD_GET_SURVEY
,
9715 .policy
= nl80211_policy
,
9716 .dumpit
= nl80211_dump_survey
,
9719 .cmd
= NL80211_CMD_SET_PMKSA
,
9720 .doit
= nl80211_setdel_pmksa
,
9721 .policy
= nl80211_policy
,
9722 .flags
= GENL_ADMIN_PERM
,
9723 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9724 NL80211_FLAG_NEED_RTNL
,
9727 .cmd
= NL80211_CMD_DEL_PMKSA
,
9728 .doit
= nl80211_setdel_pmksa
,
9729 .policy
= nl80211_policy
,
9730 .flags
= GENL_ADMIN_PERM
,
9731 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9732 NL80211_FLAG_NEED_RTNL
,
9735 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
9736 .doit
= nl80211_flush_pmksa
,
9737 .policy
= nl80211_policy
,
9738 .flags
= GENL_ADMIN_PERM
,
9739 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9740 NL80211_FLAG_NEED_RTNL
,
9743 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
9744 .doit
= nl80211_remain_on_channel
,
9745 .policy
= nl80211_policy
,
9746 .flags
= GENL_ADMIN_PERM
,
9747 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9748 NL80211_FLAG_NEED_RTNL
,
9751 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9752 .doit
= nl80211_cancel_remain_on_channel
,
9753 .policy
= nl80211_policy
,
9754 .flags
= GENL_ADMIN_PERM
,
9755 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9756 NL80211_FLAG_NEED_RTNL
,
9759 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
9760 .doit
= nl80211_set_tx_bitrate_mask
,
9761 .policy
= nl80211_policy
,
9762 .flags
= GENL_ADMIN_PERM
,
9763 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9764 NL80211_FLAG_NEED_RTNL
,
9767 .cmd
= NL80211_CMD_REGISTER_FRAME
,
9768 .doit
= nl80211_register_mgmt
,
9769 .policy
= nl80211_policy
,
9770 .flags
= GENL_ADMIN_PERM
,
9771 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9772 NL80211_FLAG_NEED_RTNL
,
9775 .cmd
= NL80211_CMD_FRAME
,
9776 .doit
= nl80211_tx_mgmt
,
9777 .policy
= nl80211_policy
,
9778 .flags
= GENL_ADMIN_PERM
,
9779 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9780 NL80211_FLAG_NEED_RTNL
,
9783 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
9784 .doit
= nl80211_tx_mgmt_cancel_wait
,
9785 .policy
= nl80211_policy
,
9786 .flags
= GENL_ADMIN_PERM
,
9787 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9788 NL80211_FLAG_NEED_RTNL
,
9791 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
9792 .doit
= nl80211_set_power_save
,
9793 .policy
= nl80211_policy
,
9794 .flags
= GENL_ADMIN_PERM
,
9795 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9796 NL80211_FLAG_NEED_RTNL
,
9799 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
9800 .doit
= nl80211_get_power_save
,
9801 .policy
= nl80211_policy
,
9802 /* can be retrieved by unprivileged users */
9803 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9804 NL80211_FLAG_NEED_RTNL
,
9807 .cmd
= NL80211_CMD_SET_CQM
,
9808 .doit
= nl80211_set_cqm
,
9809 .policy
= nl80211_policy
,
9810 .flags
= GENL_ADMIN_PERM
,
9811 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9812 NL80211_FLAG_NEED_RTNL
,
9815 .cmd
= NL80211_CMD_SET_CHANNEL
,
9816 .doit
= nl80211_set_channel
,
9817 .policy
= nl80211_policy
,
9818 .flags
= GENL_ADMIN_PERM
,
9819 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9820 NL80211_FLAG_NEED_RTNL
,
9823 .cmd
= NL80211_CMD_SET_WDS_PEER
,
9824 .doit
= nl80211_set_wds_peer
,
9825 .policy
= nl80211_policy
,
9826 .flags
= GENL_ADMIN_PERM
,
9827 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9828 NL80211_FLAG_NEED_RTNL
,
9831 .cmd
= NL80211_CMD_JOIN_MESH
,
9832 .doit
= nl80211_join_mesh
,
9833 .policy
= nl80211_policy
,
9834 .flags
= GENL_ADMIN_PERM
,
9835 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9836 NL80211_FLAG_NEED_RTNL
,
9839 .cmd
= NL80211_CMD_LEAVE_MESH
,
9840 .doit
= nl80211_leave_mesh
,
9841 .policy
= nl80211_policy
,
9842 .flags
= GENL_ADMIN_PERM
,
9843 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9844 NL80211_FLAG_NEED_RTNL
,
9848 .cmd
= NL80211_CMD_GET_WOWLAN
,
9849 .doit
= nl80211_get_wowlan
,
9850 .policy
= nl80211_policy
,
9851 /* can be retrieved by unprivileged users */
9852 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9853 NL80211_FLAG_NEED_RTNL
,
9856 .cmd
= NL80211_CMD_SET_WOWLAN
,
9857 .doit
= nl80211_set_wowlan
,
9858 .policy
= nl80211_policy
,
9859 .flags
= GENL_ADMIN_PERM
,
9860 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9861 NL80211_FLAG_NEED_RTNL
,
9865 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9866 .doit
= nl80211_set_rekey_data
,
9867 .policy
= nl80211_policy
,
9868 .flags
= GENL_ADMIN_PERM
,
9869 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9870 NL80211_FLAG_NEED_RTNL
,
9873 .cmd
= NL80211_CMD_TDLS_MGMT
,
9874 .doit
= nl80211_tdls_mgmt
,
9875 .policy
= nl80211_policy
,
9876 .flags
= GENL_ADMIN_PERM
,
9877 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9878 NL80211_FLAG_NEED_RTNL
,
9881 .cmd
= NL80211_CMD_TDLS_OPER
,
9882 .doit
= nl80211_tdls_oper
,
9883 .policy
= nl80211_policy
,
9884 .flags
= GENL_ADMIN_PERM
,
9885 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9886 NL80211_FLAG_NEED_RTNL
,
9889 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9890 .doit
= nl80211_register_unexpected_frame
,
9891 .policy
= nl80211_policy
,
9892 .flags
= GENL_ADMIN_PERM
,
9893 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9894 NL80211_FLAG_NEED_RTNL
,
9897 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9898 .doit
= nl80211_probe_client
,
9899 .policy
= nl80211_policy
,
9900 .flags
= GENL_ADMIN_PERM
,
9901 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9902 NL80211_FLAG_NEED_RTNL
,
9905 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9906 .doit
= nl80211_register_beacons
,
9907 .policy
= nl80211_policy
,
9908 .flags
= GENL_ADMIN_PERM
,
9909 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9910 NL80211_FLAG_NEED_RTNL
,
9913 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
9914 .doit
= nl80211_set_noack_map
,
9915 .policy
= nl80211_policy
,
9916 .flags
= GENL_ADMIN_PERM
,
9917 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9918 NL80211_FLAG_NEED_RTNL
,
9921 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
9922 .doit
= nl80211_start_p2p_device
,
9923 .policy
= nl80211_policy
,
9924 .flags
= GENL_ADMIN_PERM
,
9925 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9926 NL80211_FLAG_NEED_RTNL
,
9929 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
9930 .doit
= nl80211_stop_p2p_device
,
9931 .policy
= nl80211_policy
,
9932 .flags
= GENL_ADMIN_PERM
,
9933 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9934 NL80211_FLAG_NEED_RTNL
,
9937 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
9938 .doit
= nl80211_set_mcast_rate
,
9939 .policy
= nl80211_policy
,
9940 .flags
= GENL_ADMIN_PERM
,
9941 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9942 NL80211_FLAG_NEED_RTNL
,
9945 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9946 .doit
= nl80211_set_mac_acl
,
9947 .policy
= nl80211_policy
,
9948 .flags
= GENL_ADMIN_PERM
,
9949 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9950 NL80211_FLAG_NEED_RTNL
,
9953 .cmd
= NL80211_CMD_RADAR_DETECT
,
9954 .doit
= nl80211_start_radar_detection
,
9955 .policy
= nl80211_policy
,
9956 .flags
= GENL_ADMIN_PERM
,
9957 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9958 NL80211_FLAG_NEED_RTNL
,
9961 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9962 .doit
= nl80211_get_protocol_features
,
9963 .policy
= nl80211_policy
,
9966 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9967 .doit
= nl80211_update_ft_ies
,
9968 .policy
= nl80211_policy
,
9969 .flags
= GENL_ADMIN_PERM
,
9970 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9971 NL80211_FLAG_NEED_RTNL
,
9974 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9975 .doit
= nl80211_crit_protocol_start
,
9976 .policy
= nl80211_policy
,
9977 .flags
= GENL_ADMIN_PERM
,
9978 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9979 NL80211_FLAG_NEED_RTNL
,
9982 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9983 .doit
= nl80211_crit_protocol_stop
,
9984 .policy
= nl80211_policy
,
9985 .flags
= GENL_ADMIN_PERM
,
9986 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9987 NL80211_FLAG_NEED_RTNL
,
9990 .cmd
= NL80211_CMD_GET_COALESCE
,
9991 .doit
= nl80211_get_coalesce
,
9992 .policy
= nl80211_policy
,
9993 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9994 NL80211_FLAG_NEED_RTNL
,
9997 .cmd
= NL80211_CMD_SET_COALESCE
,
9998 .doit
= nl80211_set_coalesce
,
9999 .policy
= nl80211_policy
,
10000 .flags
= GENL_ADMIN_PERM
,
10001 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10002 NL80211_FLAG_NEED_RTNL
,
10005 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
10006 .doit
= nl80211_channel_switch
,
10007 .policy
= nl80211_policy
,
10008 .flags
= GENL_ADMIN_PERM
,
10009 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10010 NL80211_FLAG_NEED_RTNL
,
10013 .cmd
= NL80211_CMD_VENDOR
,
10014 .doit
= nl80211_vendor_cmd
,
10015 .policy
= nl80211_policy
,
10016 .flags
= GENL_ADMIN_PERM
,
10017 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10018 NL80211_FLAG_NEED_RTNL
,
10021 .cmd
= NL80211_CMD_SET_QOS_MAP
,
10022 .doit
= nl80211_set_qos_map
,
10023 .policy
= nl80211_policy
,
10024 .flags
= GENL_ADMIN_PERM
,
10025 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10026 NL80211_FLAG_NEED_RTNL
,
10030 /* notification functions */
10032 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
10034 struct sk_buff
*msg
;
10035 struct nl80211_dump_wiphy_state state
= {};
10037 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10041 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0, &state
) < 0) {
10046 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10047 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
10050 static int nl80211_add_scan_req(struct sk_buff
*msg
,
10051 struct cfg80211_registered_device
*rdev
)
10053 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
10054 struct nlattr
*nest
;
10060 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
10062 goto nla_put_failure
;
10063 for (i
= 0; i
< req
->n_ssids
; i
++) {
10064 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
10065 goto nla_put_failure
;
10067 nla_nest_end(msg
, nest
);
10069 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
10071 goto nla_put_failure
;
10072 for (i
= 0; i
< req
->n_channels
; i
++) {
10073 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
10074 goto nla_put_failure
;
10076 nla_nest_end(msg
, nest
);
10079 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
10080 goto nla_put_failure
;
10083 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
10084 goto nla_put_failure
;
10091 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
10092 struct cfg80211_registered_device
*rdev
,
10093 struct wireless_dev
*wdev
,
10094 u32 portid
, u32 seq
, int flags
,
10099 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
10103 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10104 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10105 wdev
->netdev
->ifindex
)) ||
10106 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10107 goto nla_put_failure
;
10109 /* ignore errors and send incomplete event anyway */
10110 nl80211_add_scan_req(msg
, rdev
);
10112 return genlmsg_end(msg
, hdr
);
10115 genlmsg_cancel(msg
, hdr
);
10120 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
10121 struct cfg80211_registered_device
*rdev
,
10122 struct net_device
*netdev
,
10123 u32 portid
, u32 seq
, int flags
, u32 cmd
)
10127 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
10131 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10132 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10133 goto nla_put_failure
;
10135 return genlmsg_end(msg
, hdr
);
10138 genlmsg_cancel(msg
, hdr
);
10142 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
10143 struct wireless_dev
*wdev
)
10145 struct sk_buff
*msg
;
10147 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10151 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
10152 NL80211_CMD_TRIGGER_SCAN
) < 0) {
10157 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10158 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10161 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
10162 struct wireless_dev
*wdev
, bool aborted
)
10164 struct sk_buff
*msg
;
10166 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10170 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
10171 aborted
? NL80211_CMD_SCAN_ABORTED
:
10172 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
10180 void nl80211_send_scan_result(struct cfg80211_registered_device
*rdev
,
10181 struct sk_buff
*msg
)
10186 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10187 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10190 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
10191 struct net_device
*netdev
)
10193 struct sk_buff
*msg
;
10195 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10199 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
10200 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
10205 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10206 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10209 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
10210 struct net_device
*netdev
, u32 cmd
)
10212 struct sk_buff
*msg
;
10214 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10218 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
10223 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10224 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10228 * This can happen on global regulatory changes or device specific settings
10229 * based on custom world regulatory domains.
10231 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
10233 struct sk_buff
*msg
;
10236 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10240 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
10246 /* Userspace can always count this one always being set */
10247 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
10248 goto nla_put_failure
;
10250 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
10251 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10252 NL80211_REGDOM_TYPE_WORLD
))
10253 goto nla_put_failure
;
10254 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
10255 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10256 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
10257 goto nla_put_failure
;
10258 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
10259 request
->intersect
) {
10260 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10261 NL80211_REGDOM_TYPE_INTERSECTION
))
10262 goto nla_put_failure
;
10264 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10265 NL80211_REGDOM_TYPE_COUNTRY
) ||
10266 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
10268 goto nla_put_failure
;
10271 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
10272 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
10273 goto nla_put_failure
;
10275 genlmsg_end(msg
, hdr
);
10278 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
10279 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
10285 genlmsg_cancel(msg
, hdr
);
10289 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
10290 struct net_device
*netdev
,
10291 const u8
*buf
, size_t len
,
10292 enum nl80211_commands cmd
, gfp_t gfp
)
10294 struct sk_buff
*msg
;
10297 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10301 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10307 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10308 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10309 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10310 goto nla_put_failure
;
10312 genlmsg_end(msg
, hdr
);
10314 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10315 NL80211_MCGRP_MLME
, gfp
);
10319 genlmsg_cancel(msg
, hdr
);
10323 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
10324 struct net_device
*netdev
, const u8
*buf
,
10325 size_t len
, gfp_t gfp
)
10327 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10328 NL80211_CMD_AUTHENTICATE
, gfp
);
10331 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
10332 struct net_device
*netdev
, const u8
*buf
,
10333 size_t len
, gfp_t gfp
)
10335 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10336 NL80211_CMD_ASSOCIATE
, gfp
);
10339 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
10340 struct net_device
*netdev
, const u8
*buf
,
10341 size_t len
, gfp_t gfp
)
10343 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10344 NL80211_CMD_DEAUTHENTICATE
, gfp
);
10347 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
10348 struct net_device
*netdev
, const u8
*buf
,
10349 size_t len
, gfp_t gfp
)
10351 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10352 NL80211_CMD_DISASSOCIATE
, gfp
);
10355 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
10358 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10359 struct wiphy
*wiphy
= wdev
->wiphy
;
10360 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10361 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
10364 if (WARN_ON(len
< 2))
10367 if (ieee80211_is_deauth(mgmt
->frame_control
))
10368 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
10370 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
10372 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
10373 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
);
10375 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
10377 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
10378 struct net_device
*netdev
, int cmd
,
10379 const u8
*addr
, gfp_t gfp
)
10381 struct sk_buff
*msg
;
10384 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10388 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10394 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10395 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10396 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
10397 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10398 goto nla_put_failure
;
10400 genlmsg_end(msg
, hdr
);
10402 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10403 NL80211_MCGRP_MLME
, gfp
);
10407 genlmsg_cancel(msg
, hdr
);
10411 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
10412 struct net_device
*netdev
, const u8
*addr
,
10415 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
10419 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
10420 struct net_device
*netdev
, const u8
*addr
,
10423 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
10427 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
10428 struct net_device
*netdev
, const u8
*bssid
,
10429 const u8
*req_ie
, size_t req_ie_len
,
10430 const u8
*resp_ie
, size_t resp_ie_len
,
10431 u16 status
, gfp_t gfp
)
10433 struct sk_buff
*msg
;
10436 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10440 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
10446 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10447 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10448 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
10449 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
10451 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
10453 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
10454 goto nla_put_failure
;
10456 genlmsg_end(msg
, hdr
);
10458 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10459 NL80211_MCGRP_MLME
, gfp
);
10463 genlmsg_cancel(msg
, hdr
);
10468 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
10469 struct net_device
*netdev
, const u8
*bssid
,
10470 const u8
*req_ie
, size_t req_ie_len
,
10471 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
10473 struct sk_buff
*msg
;
10476 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10480 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
10486 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10487 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10488 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
10490 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
10492 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
10493 goto nla_put_failure
;
10495 genlmsg_end(msg
, hdr
);
10497 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10498 NL80211_MCGRP_MLME
, gfp
);
10502 genlmsg_cancel(msg
, hdr
);
10507 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
10508 struct net_device
*netdev
, u16 reason
,
10509 const u8
*ie
, size_t ie_len
, bool from_ap
)
10511 struct sk_buff
*msg
;
10514 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10518 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
10524 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10525 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10526 (from_ap
&& reason
&&
10527 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
10529 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
10530 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
10531 goto nla_put_failure
;
10533 genlmsg_end(msg
, hdr
);
10535 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10536 NL80211_MCGRP_MLME
, GFP_KERNEL
);
10540 genlmsg_cancel(msg
, hdr
);
10545 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
10546 struct net_device
*netdev
, const u8
*bssid
,
10549 struct sk_buff
*msg
;
10552 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10556 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
10562 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10563 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10564 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10565 goto nla_put_failure
;
10567 genlmsg_end(msg
, hdr
);
10569 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10570 NL80211_MCGRP_MLME
, gfp
);
10574 genlmsg_cancel(msg
, hdr
);
10578 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
10579 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
10581 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10582 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10583 struct sk_buff
*msg
;
10586 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
10589 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
10591 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10595 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
10601 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10602 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10603 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10605 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
10606 goto nla_put_failure
;
10608 genlmsg_end(msg
, hdr
);
10610 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10611 NL80211_MCGRP_MLME
, gfp
);
10615 genlmsg_cancel(msg
, hdr
);
10618 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
10620 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
10621 struct net_device
*netdev
, const u8
*addr
,
10622 enum nl80211_key_type key_type
, int key_id
,
10623 const u8
*tsc
, gfp_t gfp
)
10625 struct sk_buff
*msg
;
10628 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10632 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
10638 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10639 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10640 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
10641 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
10643 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
10644 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
10645 goto nla_put_failure
;
10647 genlmsg_end(msg
, hdr
);
10649 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10650 NL80211_MCGRP_MLME
, gfp
);
10654 genlmsg_cancel(msg
, hdr
);
10658 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
10659 struct ieee80211_channel
*channel_before
,
10660 struct ieee80211_channel
*channel_after
)
10662 struct sk_buff
*msg
;
10664 struct nlattr
*nl_freq
;
10666 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
10670 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
10677 * Since we are applying the beacon hint to a wiphy we know its
10678 * wiphy_idx is valid
10680 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
10681 goto nla_put_failure
;
10684 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
10686 goto nla_put_failure
;
10687 if (nl80211_msg_put_channel(msg
, channel_before
, false))
10688 goto nla_put_failure
;
10689 nla_nest_end(msg
, nl_freq
);
10692 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
10694 goto nla_put_failure
;
10695 if (nl80211_msg_put_channel(msg
, channel_after
, false))
10696 goto nla_put_failure
;
10697 nla_nest_end(msg
, nl_freq
);
10699 genlmsg_end(msg
, hdr
);
10702 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
10703 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
10709 genlmsg_cancel(msg
, hdr
);
10713 static void nl80211_send_remain_on_chan_event(
10714 int cmd
, struct cfg80211_registered_device
*rdev
,
10715 struct wireless_dev
*wdev
, u64 cookie
,
10716 struct ieee80211_channel
*chan
,
10717 unsigned int duration
, gfp_t gfp
)
10719 struct sk_buff
*msg
;
10722 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10726 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10732 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10733 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10734 wdev
->netdev
->ifindex
)) ||
10735 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10736 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
10737 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10738 NL80211_CHAN_NO_HT
) ||
10739 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
10740 goto nla_put_failure
;
10742 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
10743 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
10744 goto nla_put_failure
;
10746 genlmsg_end(msg
, hdr
);
10748 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10749 NL80211_MCGRP_MLME
, gfp
);
10753 genlmsg_cancel(msg
, hdr
);
10757 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
10758 struct ieee80211_channel
*chan
,
10759 unsigned int duration
, gfp_t gfp
)
10761 struct wiphy
*wiphy
= wdev
->wiphy
;
10762 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10764 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
10765 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
10766 rdev
, wdev
, cookie
, chan
,
10769 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
10771 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
10772 struct ieee80211_channel
*chan
,
10775 struct wiphy
*wiphy
= wdev
->wiphy
;
10776 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10778 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
10779 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
10780 rdev
, wdev
, cookie
, chan
, 0, gfp
);
10782 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
10784 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
10785 struct station_info
*sinfo
, gfp_t gfp
)
10787 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10788 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10789 struct sk_buff
*msg
;
10791 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
10793 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10797 if (nl80211_send_station(msg
, 0, 0, 0,
10798 rdev
, dev
, mac_addr
, sinfo
) < 0) {
10803 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10804 NL80211_MCGRP_MLME
, gfp
);
10806 EXPORT_SYMBOL(cfg80211_new_sta
);
10808 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
10810 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10811 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10812 struct sk_buff
*msg
;
10815 trace_cfg80211_del_sta(dev
, mac_addr
);
10817 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10821 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
10827 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10828 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
10829 goto nla_put_failure
;
10831 genlmsg_end(msg
, hdr
);
10833 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10834 NL80211_MCGRP_MLME
, gfp
);
10838 genlmsg_cancel(msg
, hdr
);
10841 EXPORT_SYMBOL(cfg80211_del_sta
);
10843 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10844 enum nl80211_connect_failed_reason reason
,
10847 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10848 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10849 struct sk_buff
*msg
;
10852 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10856 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10862 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10863 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10864 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10865 goto nla_put_failure
;
10867 genlmsg_end(msg
, hdr
);
10869 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10870 NL80211_MCGRP_MLME
, gfp
);
10874 genlmsg_cancel(msg
, hdr
);
10877 EXPORT_SYMBOL(cfg80211_conn_failed
);
10879 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10880 const u8
*addr
, gfp_t gfp
)
10882 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10883 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10884 struct sk_buff
*msg
;
10886 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10891 msg
= nlmsg_new(100, gfp
);
10895 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10901 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10902 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10903 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10904 goto nla_put_failure
;
10906 genlmsg_end(msg
, hdr
);
10907 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10911 genlmsg_cancel(msg
, hdr
);
10916 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
10917 const u8
*addr
, gfp_t gfp
)
10919 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10922 trace_cfg80211_rx_spurious_frame(dev
, addr
);
10924 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10925 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
10926 trace_cfg80211_return_bool(false);
10929 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
10931 trace_cfg80211_return_bool(ret
);
10934 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
10936 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
10937 const u8
*addr
, gfp_t gfp
)
10939 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10942 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
10944 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10945 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10946 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
10947 trace_cfg80211_return_bool(false);
10950 ret
= __nl80211_unexpected_frame(dev
,
10951 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
10953 trace_cfg80211_return_bool(ret
);
10956 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10958 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10959 struct wireless_dev
*wdev
, u32 nlportid
,
10960 int freq
, int sig_dbm
,
10961 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
10963 struct net_device
*netdev
= wdev
->netdev
;
10964 struct sk_buff
*msg
;
10967 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10971 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10977 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10978 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10979 netdev
->ifindex
)) ||
10980 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10981 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10983 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10984 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10986 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
10987 goto nla_put_failure
;
10989 genlmsg_end(msg
, hdr
);
10991 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10994 genlmsg_cancel(msg
, hdr
);
10999 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
11000 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
11002 struct wiphy
*wiphy
= wdev
->wiphy
;
11003 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11004 struct net_device
*netdev
= wdev
->netdev
;
11005 struct sk_buff
*msg
;
11008 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
11010 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11014 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
11020 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11021 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11022 netdev
->ifindex
)) ||
11023 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
11024 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
11025 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
11026 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
11027 goto nla_put_failure
;
11029 genlmsg_end(msg
, hdr
);
11031 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11032 NL80211_MCGRP_MLME
, gfp
);
11036 genlmsg_cancel(msg
, hdr
);
11039 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
11041 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
11042 enum nl80211_cqm_rssi_threshold_event rssi_event
,
11045 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11046 struct wiphy
*wiphy
= wdev
->wiphy
;
11047 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11048 struct sk_buff
*msg
;
11049 struct nlattr
*pinfoattr
;
11052 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
11054 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
11064 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11065 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
11066 goto nla_put_failure
;
11068 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
11070 goto nla_put_failure
;
11072 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
11074 goto nla_put_failure
;
11076 nla_nest_end(msg
, pinfoattr
);
11078 genlmsg_end(msg
, hdr
);
11080 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11081 NL80211_MCGRP_MLME
, gfp
);
11085 genlmsg_cancel(msg
, hdr
);
11088 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
11090 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
11091 struct net_device
*netdev
, const u8
*bssid
,
11092 const u8
*replay_ctr
, gfp_t gfp
)
11094 struct sk_buff
*msg
;
11095 struct nlattr
*rekey_attr
;
11098 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11102 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
11108 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11109 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11110 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
11111 goto nla_put_failure
;
11113 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
11115 goto nla_put_failure
;
11117 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
11118 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
11119 goto nla_put_failure
;
11121 nla_nest_end(msg
, rekey_attr
);
11123 genlmsg_end(msg
, hdr
);
11125 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11126 NL80211_MCGRP_MLME
, gfp
);
11130 genlmsg_cancel(msg
, hdr
);
11134 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
11135 const u8
*replay_ctr
, gfp_t gfp
)
11137 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11138 struct wiphy
*wiphy
= wdev
->wiphy
;
11139 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11141 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
11142 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
11144 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
11147 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
11148 struct net_device
*netdev
, int index
,
11149 const u8
*bssid
, bool preauth
, gfp_t gfp
)
11151 struct sk_buff
*msg
;
11152 struct nlattr
*attr
;
11155 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11159 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
11165 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11166 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11167 goto nla_put_failure
;
11169 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
11171 goto nla_put_failure
;
11173 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
11174 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
11176 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
11177 goto nla_put_failure
;
11179 nla_nest_end(msg
, attr
);
11181 genlmsg_end(msg
, hdr
);
11183 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11184 NL80211_MCGRP_MLME
, gfp
);
11188 genlmsg_cancel(msg
, hdr
);
11192 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
11193 const u8
*bssid
, bool preauth
, gfp_t gfp
)
11195 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11196 struct wiphy
*wiphy
= wdev
->wiphy
;
11197 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11199 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
11200 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
11202 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
11204 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
11205 struct net_device
*netdev
,
11206 struct cfg80211_chan_def
*chandef
,
11209 struct sk_buff
*msg
;
11212 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11216 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
11222 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11223 goto nla_put_failure
;
11225 if (nl80211_send_chandef(msg
, chandef
))
11226 goto nla_put_failure
;
11228 genlmsg_end(msg
, hdr
);
11230 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11231 NL80211_MCGRP_MLME
, gfp
);
11235 genlmsg_cancel(msg
, hdr
);
11239 void cfg80211_ch_switch_notify(struct net_device
*dev
,
11240 struct cfg80211_chan_def
*chandef
)
11242 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11243 struct wiphy
*wiphy
= wdev
->wiphy
;
11244 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11246 ASSERT_WDEV_LOCK(wdev
);
11248 trace_cfg80211_ch_switch_notify(dev
, chandef
);
11250 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11251 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
11252 wdev
->iftype
!= NL80211_IFTYPE_ADHOC
&&
11253 wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
11256 wdev
->chandef
= *chandef
;
11257 wdev
->preset_chandef
= *chandef
;
11258 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
11260 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
11262 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
11263 const u8
*peer
, u32 num_packets
,
11264 u32 rate
, u32 intvl
, gfp_t gfp
)
11266 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11267 struct wiphy
*wiphy
= wdev
->wiphy
;
11268 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11269 struct sk_buff
*msg
;
11270 struct nlattr
*pinfoattr
;
11273 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
11277 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
11283 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11284 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11285 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
11286 goto nla_put_failure
;
11288 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
11290 goto nla_put_failure
;
11292 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
11293 goto nla_put_failure
;
11295 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
11296 goto nla_put_failure
;
11298 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
11299 goto nla_put_failure
;
11301 nla_nest_end(msg
, pinfoattr
);
11303 genlmsg_end(msg
, hdr
);
11305 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11306 NL80211_MCGRP_MLME
, gfp
);
11310 genlmsg_cancel(msg
, hdr
);
11313 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
11316 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
11317 const struct cfg80211_chan_def
*chandef
,
11318 enum nl80211_radar_event event
,
11319 struct net_device
*netdev
, gfp_t gfp
)
11321 struct sk_buff
*msg
;
11324 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11328 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
11334 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
11335 goto nla_put_failure
;
11337 /* NOP and radar events don't need a netdev parameter */
11339 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
11341 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11342 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11343 goto nla_put_failure
;
11346 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
11347 goto nla_put_failure
;
11349 if (nl80211_send_chandef(msg
, chandef
))
11350 goto nla_put_failure
;
11352 genlmsg_end(msg
, hdr
);
11354 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11355 NL80211_MCGRP_MLME
, gfp
);
11359 genlmsg_cancel(msg
, hdr
);
11363 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
11364 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
11366 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11367 struct wiphy
*wiphy
= wdev
->wiphy
;
11368 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11369 struct sk_buff
*msg
;
11370 struct nlattr
*pinfoattr
;
11373 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
11375 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11379 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
11385 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11386 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11387 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
11388 goto nla_put_failure
;
11390 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
11392 goto nla_put_failure
;
11394 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
11395 goto nla_put_failure
;
11397 nla_nest_end(msg
, pinfoattr
);
11399 genlmsg_end(msg
, hdr
);
11401 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11402 NL80211_MCGRP_MLME
, gfp
);
11406 genlmsg_cancel(msg
, hdr
);
11409 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
11411 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
11412 u64 cookie
, bool acked
, gfp_t gfp
)
11414 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11415 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
11416 struct sk_buff
*msg
;
11419 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
11421 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11426 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
11432 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11433 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11434 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
11435 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
11436 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
11437 goto nla_put_failure
;
11439 genlmsg_end(msg
, hdr
);
11441 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11442 NL80211_MCGRP_MLME
, gfp
);
11446 genlmsg_cancel(msg
, hdr
);
11449 EXPORT_SYMBOL(cfg80211_probe_status
);
11451 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
11452 const u8
*frame
, size_t len
,
11453 int freq
, int sig_dbm
)
11455 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11456 struct sk_buff
*msg
;
11458 struct cfg80211_beacon_registration
*reg
;
11460 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
11462 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11463 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
11464 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
11466 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11470 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
11472 goto nla_put_failure
;
11474 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11476 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
11478 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
11479 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
11480 goto nla_put_failure
;
11482 genlmsg_end(msg
, hdr
);
11484 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
11486 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11490 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11492 genlmsg_cancel(msg
, hdr
);
11495 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
11498 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
11499 struct cfg80211_wowlan_wakeup
*wakeup
,
11502 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
11503 struct sk_buff
*msg
;
11507 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
11510 size
+= wakeup
->packet_present_len
;
11512 msg
= nlmsg_new(size
, gfp
);
11516 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
11520 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11521 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11524 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11525 wdev
->netdev
->ifindex
))
11529 struct nlattr
*reasons
;
11531 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
11535 if (wakeup
->disconnect
&&
11536 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
11538 if (wakeup
->magic_pkt
&&
11539 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
11541 if (wakeup
->gtk_rekey_failure
&&
11542 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
11544 if (wakeup
->eap_identity_req
&&
11545 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
11547 if (wakeup
->four_way_handshake
&&
11548 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
11550 if (wakeup
->rfkill_release
&&
11551 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
11554 if (wakeup
->pattern_idx
>= 0 &&
11555 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
11556 wakeup
->pattern_idx
))
11559 if (wakeup
->tcp_match
&&
11560 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
11563 if (wakeup
->tcp_connlost
&&
11564 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
11567 if (wakeup
->tcp_nomoretokens
&&
11569 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
11572 if (wakeup
->packet
) {
11573 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
11574 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
11576 if (!wakeup
->packet_80211
) {
11578 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
11580 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
11583 if (wakeup
->packet_len
&&
11584 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
11587 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
11592 nla_nest_end(msg
, reasons
);
11595 genlmsg_end(msg
, hdr
);
11597 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11598 NL80211_MCGRP_MLME
, gfp
);
11604 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
11607 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
11608 enum nl80211_tdls_operation oper
,
11609 u16 reason_code
, gfp_t gfp
)
11611 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11612 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
11613 struct sk_buff
*msg
;
11616 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
11619 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11623 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
11629 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11630 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11631 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
11632 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
11633 (reason_code
> 0 &&
11634 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
11635 goto nla_put_failure
;
11637 genlmsg_end(msg
, hdr
);
11639 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11640 NL80211_MCGRP_MLME
, gfp
);
11644 genlmsg_cancel(msg
, hdr
);
11647 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
11649 static int nl80211_netlink_notify(struct notifier_block
* nb
,
11650 unsigned long state
,
11653 struct netlink_notify
*notify
= _notify
;
11654 struct cfg80211_registered_device
*rdev
;
11655 struct wireless_dev
*wdev
;
11656 struct cfg80211_beacon_registration
*reg
, *tmp
;
11658 if (state
!= NETLINK_URELEASE
)
11659 return NOTIFY_DONE
;
11663 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
11664 bool schedule_destroy_work
= false;
11666 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
) {
11667 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
11669 if (wdev
->owner_nlportid
== notify
->portid
)
11670 schedule_destroy_work
= true;
11673 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11674 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
11676 if (reg
->nlportid
== notify
->portid
) {
11677 list_del(®
->list
);
11682 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11684 if (schedule_destroy_work
) {
11685 struct cfg80211_iface_destroy
*destroy
;
11687 destroy
= kzalloc(sizeof(*destroy
), GFP_ATOMIC
);
11689 destroy
->nlportid
= notify
->portid
;
11690 spin_lock(&rdev
->destroy_list_lock
);
11691 list_add(&destroy
->list
, &rdev
->destroy_list
);
11692 spin_unlock(&rdev
->destroy_list_lock
);
11693 schedule_work(&rdev
->destroy_work
);
11700 return NOTIFY_DONE
;
11703 static struct notifier_block nl80211_netlink_notifier
= {
11704 .notifier_call
= nl80211_netlink_notify
,
11707 void cfg80211_ft_event(struct net_device
*netdev
,
11708 struct cfg80211_ft_event_params
*ft_event
)
11710 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
11711 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11712 struct sk_buff
*msg
;
11715 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
11717 if (!ft_event
->target_ap
)
11720 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11724 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
11728 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11729 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11730 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
11733 if (ft_event
->ies
&&
11734 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
11736 if (ft_event
->ric_ies
&&
11737 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
11738 ft_event
->ric_ies
))
11741 genlmsg_end(msg
, hdr
);
11743 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11744 NL80211_MCGRP_MLME
, GFP_KERNEL
);
11749 EXPORT_SYMBOL(cfg80211_ft_event
);
11751 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
11753 struct cfg80211_registered_device
*rdev
;
11754 struct sk_buff
*msg
;
11758 rdev
= wiphy_to_dev(wdev
->wiphy
);
11759 if (!rdev
->crit_proto_nlportid
)
11762 nlportid
= rdev
->crit_proto_nlportid
;
11763 rdev
->crit_proto_nlportid
= 0;
11765 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11769 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
11771 goto nla_put_failure
;
11773 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11774 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11775 goto nla_put_failure
;
11777 genlmsg_end(msg
, hdr
);
11779 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
11784 genlmsg_cancel(msg
, hdr
);
11788 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
11790 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
11792 struct wiphy
*wiphy
= wdev
->wiphy
;
11793 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11794 struct sk_buff
*msg
;
11797 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11801 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
11805 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11806 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
11807 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11810 genlmsg_end(msg
, hdr
);
11812 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
11813 NL80211_MCGRP_MLME
, GFP_KERNEL
);
11819 /* initialisation/exit functions */
11821 int nl80211_init(void)
11825 err
= genl_register_family_with_ops_groups(&nl80211_fam
, nl80211_ops
,
11830 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
11836 genl_unregister_family(&nl80211_fam
);
11840 void nl80211_exit(void)
11842 netlink_unregister_notifier(&nl80211_netlink_notifier
);
11843 genl_unregister_family(&nl80211_fam
);