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_BINARY
},
375 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
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
},
389 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
392 /* policy for the key attributes */
393 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
394 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
395 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
396 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
397 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
398 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
399 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
400 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
401 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
404 /* policy for the key default flags */
405 static const struct nla_policy
406 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
407 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
408 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
411 /* policy for WoWLAN attributes */
412 static const struct nla_policy
413 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
414 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
415 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
416 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
417 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
418 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
419 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
420 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
421 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
422 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
425 static const struct nla_policy
426 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
427 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
428 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
429 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
430 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
431 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
432 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
434 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
436 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
437 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
439 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
440 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
441 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
444 /* policy for coalesce rule attributes */
445 static const struct nla_policy
446 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
447 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
448 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
449 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
452 /* policy for GTK rekey offload attributes */
453 static const struct nla_policy
454 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
455 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
456 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
457 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
460 static const struct nla_policy
461 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
462 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
463 .len
= IEEE80211_MAX_SSID_LEN
},
464 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
467 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
468 struct netlink_callback
*cb
,
469 struct cfg80211_registered_device
**rdev
,
470 struct wireless_dev
**wdev
)
477 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
478 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
483 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
484 nl80211_fam
.attrbuf
);
486 err
= PTR_ERR(*wdev
);
489 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
490 /* 0 is the first index - add 1 to parse only once */
491 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
492 cb
->args
[1] = (*wdev
)->identifier
;
494 /* subtract the 1 again here */
495 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
496 struct wireless_dev
*tmp
;
502 *rdev
= wiphy_to_rdev(wiphy
);
505 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
506 if (tmp
->identifier
== cb
->args
[1]) {
524 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
530 static bool is_valid_ie_attr(const struct nlattr
*attr
)
538 pos
= nla_data(attr
);
559 /* message building helper */
560 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
563 /* since there is no private header just add the generic one */
564 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
567 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
568 struct ieee80211_channel
*chan
,
571 /* Some channels must be completely excluded from the
572 * list to protect old user-space tools from breaking
574 if (!large
&& chan
->flags
&
575 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
578 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
580 goto nla_put_failure
;
582 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
583 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
584 goto nla_put_failure
;
585 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
586 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
587 goto nla_put_failure
;
588 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
589 goto nla_put_failure
;
591 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
592 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
593 goto nla_put_failure
;
597 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
599 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
601 goto nla_put_failure
;
602 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
604 goto nla_put_failure
;
606 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
608 goto nla_put_failure
;
613 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
614 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
615 goto nla_put_failure
;
616 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
617 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
618 goto nla_put_failure
;
619 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
620 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
621 goto nla_put_failure
;
622 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
623 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
624 goto nla_put_failure
;
625 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
626 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
627 goto nla_put_failure
;
628 if ((chan
->flags
& IEEE80211_CHAN_GO_CONCURRENT
) &&
629 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_GO_CONCURRENT
))
630 goto nla_put_failure
;
631 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
632 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
633 goto nla_put_failure
;
634 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
635 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
636 goto nla_put_failure
;
639 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
640 DBM_TO_MBM(chan
->max_power
)))
641 goto nla_put_failure
;
649 /* netlink command implementations */
656 bool def_uni
, def_multi
;
659 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
661 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
662 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
667 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
668 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
677 if (tb
[NL80211_KEY_IDX
])
678 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
680 if (tb
[NL80211_KEY_DATA
]) {
681 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
682 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
685 if (tb
[NL80211_KEY_SEQ
]) {
686 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
687 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
690 if (tb
[NL80211_KEY_CIPHER
])
691 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
693 if (tb
[NL80211_KEY_TYPE
]) {
694 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
695 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
699 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
700 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
701 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
702 tb
[NL80211_KEY_DEFAULT_TYPES
],
703 nl80211_key_default_policy
);
707 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
708 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
714 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
716 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
717 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
718 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
721 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
722 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
723 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
726 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
727 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
729 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
730 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
732 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
733 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
742 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
743 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
744 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
748 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
749 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
750 int err
= nla_parse_nested(
751 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
752 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
753 nl80211_key_default_policy
);
757 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
758 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
764 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
768 memset(k
, 0, sizeof(*k
));
772 if (info
->attrs
[NL80211_ATTR_KEY
])
773 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
775 err
= nl80211_parse_key_old(info
, k
);
780 if (k
->def
&& k
->defmgmt
)
784 if (k
->def_uni
|| !k
->def_multi
)
790 if (k
->idx
< 4 || k
->idx
> 5)
793 if (k
->idx
< 0 || k
->idx
> 3)
796 if (k
->idx
< 0 || k
->idx
> 5)
804 static struct cfg80211_cached_keys
*
805 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
806 struct nlattr
*keys
, bool *no_ht
)
808 struct key_parse parse
;
810 struct cfg80211_cached_keys
*result
;
811 int rem
, err
, def
= 0;
813 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
815 return ERR_PTR(-ENOMEM
);
818 result
->defmgmt
= -1;
820 nla_for_each_nested(key
, keys
, rem
) {
821 memset(&parse
, 0, sizeof(parse
));
824 err
= nl80211_parse_key_new(key
, &parse
);
830 if (parse
.idx
< 0 || parse
.idx
> 4)
836 result
->def
= parse
.idx
;
837 if (!parse
.def_uni
|| !parse
.def_multi
)
839 } else if (parse
.defmgmt
)
841 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
842 parse
.idx
, false, NULL
);
845 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
846 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
847 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
848 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
850 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
851 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
863 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
865 ASSERT_WDEV_LOCK(wdev
);
867 switch (wdev
->iftype
) {
868 case NL80211_IFTYPE_AP
:
869 case NL80211_IFTYPE_AP_VLAN
:
870 case NL80211_IFTYPE_P2P_GO
:
871 case NL80211_IFTYPE_MESH_POINT
:
873 case NL80211_IFTYPE_ADHOC
:
874 case NL80211_IFTYPE_STATION
:
875 case NL80211_IFTYPE_P2P_CLIENT
:
876 if (!wdev
->current_bss
)
886 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
889 struct ieee80211_channel
*chan
;
893 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
894 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
899 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
901 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
905 goto nla_put_failure
;
909 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
910 goto nla_put_failure
;
915 nla_nest_end(msg
, nl_modes
);
922 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
926 struct nlattr
*nl_combis
;
929 nl_combis
= nla_nest_start(msg
,
930 NL80211_ATTR_INTERFACE_COMBINATIONS
);
932 goto nla_put_failure
;
934 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
935 const struct ieee80211_iface_combination
*c
;
936 struct nlattr
*nl_combi
, *nl_limits
;
938 c
= &wiphy
->iface_combinations
[i
];
940 nl_combi
= nla_nest_start(msg
, i
+ 1);
942 goto nla_put_failure
;
944 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
946 goto nla_put_failure
;
948 for (j
= 0; j
< c
->n_limits
; j
++) {
949 struct nlattr
*nl_limit
;
951 nl_limit
= nla_nest_start(msg
, j
+ 1);
953 goto nla_put_failure
;
954 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
956 goto nla_put_failure
;
957 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
959 goto nla_put_failure
;
960 nla_nest_end(msg
, nl_limit
);
963 nla_nest_end(msg
, nl_limits
);
965 if (c
->beacon_int_infra_match
&&
966 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
967 goto nla_put_failure
;
968 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
969 c
->num_different_channels
) ||
970 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
972 goto nla_put_failure
;
974 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
975 c
->radar_detect_widths
) ||
976 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
977 c
->radar_detect_regions
)))
978 goto nla_put_failure
;
980 nla_nest_end(msg
, nl_combi
);
983 nla_nest_end(msg
, nl_combis
);
991 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
994 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
995 struct nlattr
*nl_tcp
;
1000 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1004 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1005 tcp
->data_payload_max
))
1008 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1009 tcp
->data_payload_max
))
1012 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1015 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1016 sizeof(*tcp
->tok
), tcp
->tok
))
1019 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1020 tcp
->data_interval_max
))
1023 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1024 tcp
->wake_payload_max
))
1027 nla_nest_end(msg
, nl_tcp
);
1031 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1032 struct cfg80211_registered_device
*rdev
,
1035 struct nlattr
*nl_wowlan
;
1037 if (!rdev
->wiphy
.wowlan
)
1040 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1044 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1045 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1046 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1047 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1048 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1049 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1050 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1051 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1052 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1053 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1054 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1055 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1056 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1057 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1058 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1059 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1062 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1063 struct nl80211_pattern_support pat
= {
1064 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1065 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1066 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1067 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1070 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1075 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1078 nla_nest_end(msg
, nl_wowlan
);
1084 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1085 struct cfg80211_registered_device
*rdev
)
1087 struct nl80211_coalesce_rule_support rule
;
1089 if (!rdev
->wiphy
.coalesce
)
1092 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1093 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1094 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1095 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1096 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1097 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1099 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1105 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1106 struct ieee80211_supported_band
*sband
)
1108 struct nlattr
*nl_rates
, *nl_rate
;
1109 struct ieee80211_rate
*rate
;
1113 if (sband
->ht_cap
.ht_supported
&&
1114 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1115 sizeof(sband
->ht_cap
.mcs
),
1116 &sband
->ht_cap
.mcs
) ||
1117 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1118 sband
->ht_cap
.cap
) ||
1119 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1120 sband
->ht_cap
.ampdu_factor
) ||
1121 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1122 sband
->ht_cap
.ampdu_density
)))
1126 if (sband
->vht_cap
.vht_supported
&&
1127 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1128 sizeof(sband
->vht_cap
.vht_mcs
),
1129 &sband
->vht_cap
.vht_mcs
) ||
1130 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1131 sband
->vht_cap
.cap
)))
1135 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1139 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1140 nl_rate
= nla_nest_start(msg
, i
);
1144 rate
= &sband
->bitrates
[i
];
1145 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1148 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1150 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1153 nla_nest_end(msg
, nl_rate
);
1156 nla_nest_end(msg
, nl_rates
);
1162 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1163 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1166 struct nlattr
*nl_ftypes
, *nl_ifs
;
1167 enum nl80211_iftype ift
;
1173 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1177 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1178 nl_ftypes
= nla_nest_start(msg
, ift
);
1182 stypes
= mgmt_stypes
[ift
].tx
;
1185 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1186 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1191 nla_nest_end(msg
, nl_ftypes
);
1194 nla_nest_end(msg
, nl_ifs
);
1196 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1200 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1201 nl_ftypes
= nla_nest_start(msg
, ift
);
1205 stypes
= mgmt_stypes
[ift
].rx
;
1208 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1209 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1214 nla_nest_end(msg
, nl_ftypes
);
1216 nla_nest_end(msg
, nl_ifs
);
1221 struct nl80211_dump_wiphy_state
{
1224 long split_start
, band_start
, chan_start
;
1228 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1229 enum nl80211_commands cmd
,
1230 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1231 int flags
, struct nl80211_dump_wiphy_state
*state
)
1234 struct nlattr
*nl_bands
, *nl_band
;
1235 struct nlattr
*nl_freqs
, *nl_freq
;
1236 struct nlattr
*nl_cmds
;
1237 enum ieee80211_band band
;
1238 struct ieee80211_channel
*chan
;
1240 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1241 rdev
->wiphy
.mgmt_stypes
;
1244 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1248 if (WARN_ON(!state
))
1251 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1252 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1253 wiphy_name(&rdev
->wiphy
)) ||
1254 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1255 cfg80211_rdev_list_generation
))
1256 goto nla_put_failure
;
1258 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1261 switch (state
->split_start
) {
1263 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1264 rdev
->wiphy
.retry_short
) ||
1265 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1266 rdev
->wiphy
.retry_long
) ||
1267 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1268 rdev
->wiphy
.frag_threshold
) ||
1269 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1270 rdev
->wiphy
.rts_threshold
) ||
1271 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1272 rdev
->wiphy
.coverage_class
) ||
1273 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1274 rdev
->wiphy
.max_scan_ssids
) ||
1275 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1276 rdev
->wiphy
.max_sched_scan_ssids
) ||
1277 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1278 rdev
->wiphy
.max_scan_ie_len
) ||
1279 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1280 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1281 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1282 rdev
->wiphy
.max_match_sets
))
1283 goto nla_put_failure
;
1285 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1286 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1287 goto nla_put_failure
;
1288 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1289 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1290 goto nla_put_failure
;
1291 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1292 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1293 goto nla_put_failure
;
1294 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1295 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1296 goto nla_put_failure
;
1297 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1298 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1299 goto nla_put_failure
;
1300 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1301 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1302 goto nla_put_failure
;
1303 state
->split_start
++;
1307 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1308 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1309 rdev
->wiphy
.cipher_suites
))
1310 goto nla_put_failure
;
1312 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1313 rdev
->wiphy
.max_num_pmkids
))
1314 goto nla_put_failure
;
1316 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1317 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1318 goto nla_put_failure
;
1320 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1321 rdev
->wiphy
.available_antennas_tx
) ||
1322 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1323 rdev
->wiphy
.available_antennas_rx
))
1324 goto nla_put_failure
;
1326 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1327 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1328 rdev
->wiphy
.probe_resp_offload
))
1329 goto nla_put_failure
;
1331 if ((rdev
->wiphy
.available_antennas_tx
||
1332 rdev
->wiphy
.available_antennas_rx
) &&
1333 rdev
->ops
->get_antenna
) {
1334 u32 tx_ant
= 0, rx_ant
= 0;
1336 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1338 if (nla_put_u32(msg
,
1339 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1342 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1344 goto nla_put_failure
;
1348 state
->split_start
++;
1352 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1353 rdev
->wiphy
.interface_modes
))
1354 goto nla_put_failure
;
1355 state
->split_start
++;
1359 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1361 goto nla_put_failure
;
1363 for (band
= state
->band_start
;
1364 band
< IEEE80211_NUM_BANDS
; band
++) {
1365 struct ieee80211_supported_band
*sband
;
1367 sband
= rdev
->wiphy
.bands
[band
];
1372 nl_band
= nla_nest_start(msg
, band
);
1374 goto nla_put_failure
;
1376 switch (state
->chan_start
) {
1378 if (nl80211_send_band_rateinfo(msg
, sband
))
1379 goto nla_put_failure
;
1380 state
->chan_start
++;
1384 /* add frequencies */
1385 nl_freqs
= nla_nest_start(
1386 msg
, NL80211_BAND_ATTR_FREQS
);
1388 goto nla_put_failure
;
1390 for (i
= state
->chan_start
- 1;
1391 i
< sband
->n_channels
;
1393 nl_freq
= nla_nest_start(msg
, i
);
1395 goto nla_put_failure
;
1397 chan
= &sband
->channels
[i
];
1399 if (nl80211_msg_put_channel(
1402 goto nla_put_failure
;
1404 nla_nest_end(msg
, nl_freq
);
1408 if (i
< sband
->n_channels
)
1409 state
->chan_start
= i
+ 2;
1411 state
->chan_start
= 0;
1412 nla_nest_end(msg
, nl_freqs
);
1415 nla_nest_end(msg
, nl_band
);
1418 /* start again here */
1419 if (state
->chan_start
)
1424 nla_nest_end(msg
, nl_bands
);
1426 if (band
< IEEE80211_NUM_BANDS
)
1427 state
->band_start
= band
+ 1;
1429 state
->band_start
= 0;
1431 /* if bands & channels are done, continue outside */
1432 if (state
->band_start
== 0 && state
->chan_start
== 0)
1433 state
->split_start
++;
1437 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1439 goto nla_put_failure
;
1442 #define CMD(op, n) \
1444 if (rdev->ops->op) { \
1446 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1447 goto nla_put_failure; \
1451 CMD(add_virtual_intf
, NEW_INTERFACE
);
1452 CMD(change_virtual_intf
, SET_INTERFACE
);
1453 CMD(add_key
, NEW_KEY
);
1454 CMD(start_ap
, START_AP
);
1455 CMD(add_station
, NEW_STATION
);
1456 CMD(add_mpath
, NEW_MPATH
);
1457 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1458 CMD(change_bss
, SET_BSS
);
1459 CMD(auth
, AUTHENTICATE
);
1460 CMD(assoc
, ASSOCIATE
);
1461 CMD(deauth
, DEAUTHENTICATE
);
1462 CMD(disassoc
, DISASSOCIATE
);
1463 CMD(join_ibss
, JOIN_IBSS
);
1464 CMD(join_mesh
, JOIN_MESH
);
1465 CMD(set_pmksa
, SET_PMKSA
);
1466 CMD(del_pmksa
, DEL_PMKSA
);
1467 CMD(flush_pmksa
, FLUSH_PMKSA
);
1468 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1469 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1470 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1471 CMD(mgmt_tx
, FRAME
);
1472 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1473 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1475 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1476 goto nla_put_failure
;
1478 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1479 rdev
->ops
->join_mesh
) {
1481 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1482 goto nla_put_failure
;
1484 CMD(set_wds_peer
, SET_WDS_PEER
);
1485 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1486 CMD(tdls_mgmt
, TDLS_MGMT
);
1487 CMD(tdls_oper
, TDLS_OPER
);
1489 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1490 CMD(sched_scan_start
, START_SCHED_SCAN
);
1491 CMD(probe_client
, PROBE_CLIENT
);
1492 CMD(set_noack_map
, SET_NOACK_MAP
);
1493 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1495 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1496 goto nla_put_failure
;
1498 CMD(start_p2p_device
, START_P2P_DEVICE
);
1499 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1500 #ifdef CONFIG_NL80211_TESTMODE
1501 CMD(testmode_cmd
, TESTMODE
);
1504 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1505 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1506 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1507 CMD(channel_switch
, CHANNEL_SWITCH
);
1508 CMD(set_qos_map
, SET_QOS_MAP
);
1510 /* add into the if now */
1513 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1515 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1516 goto nla_put_failure
;
1519 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1521 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1522 goto nla_put_failure
;
1525 nla_nest_end(msg
, nl_cmds
);
1526 state
->split_start
++;
1530 if (rdev
->ops
->remain_on_channel
&&
1531 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1533 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1534 rdev
->wiphy
.max_remain_on_channel_duration
))
1535 goto nla_put_failure
;
1537 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1538 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1539 goto nla_put_failure
;
1541 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1542 goto nla_put_failure
;
1543 state
->split_start
++;
1548 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1549 goto nla_put_failure
;
1550 state
->split_start
++;
1554 state
->split_start
++;
1557 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1558 rdev
->wiphy
.software_iftypes
))
1559 goto nla_put_failure
;
1561 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1563 goto nla_put_failure
;
1565 state
->split_start
++;
1569 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1570 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1571 rdev
->wiphy
.ap_sme_capa
))
1572 goto nla_put_failure
;
1574 features
= rdev
->wiphy
.features
;
1576 * We can only add the per-channel limit information if the
1577 * dump is split, otherwise it makes it too big. Therefore
1578 * only advertise it in that case.
1581 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1582 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1583 goto nla_put_failure
;
1585 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1586 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1587 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1588 rdev
->wiphy
.ht_capa_mod_mask
))
1589 goto nla_put_failure
;
1591 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1592 rdev
->wiphy
.max_acl_mac_addrs
&&
1593 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1594 rdev
->wiphy
.max_acl_mac_addrs
))
1595 goto nla_put_failure
;
1598 * Any information below this point is only available to
1599 * applications that can deal with it being split. This
1600 * helps ensure that newly added capabilities don't break
1601 * older tools by overrunning their buffers.
1603 * We still increment split_start so that in the split
1604 * case we'll continue with more data in the next round,
1605 * but break unconditionally so unsplit data stops here.
1607 state
->split_start
++;
1610 if (rdev
->wiphy
.extended_capabilities
&&
1611 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1612 rdev
->wiphy
.extended_capabilities_len
,
1613 rdev
->wiphy
.extended_capabilities
) ||
1614 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1615 rdev
->wiphy
.extended_capabilities_len
,
1616 rdev
->wiphy
.extended_capabilities_mask
)))
1617 goto nla_put_failure
;
1619 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1620 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1621 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1622 rdev
->wiphy
.vht_capa_mod_mask
))
1623 goto nla_put_failure
;
1625 state
->split_start
++;
1628 if (nl80211_send_coalesce(msg
, rdev
))
1629 goto nla_put_failure
;
1631 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1632 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1633 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1634 goto nla_put_failure
;
1636 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1637 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1638 rdev
->wiphy
.max_ap_assoc_sta
))
1639 goto nla_put_failure
;
1641 state
->split_start
++;
1644 if (rdev
->wiphy
.n_vendor_commands
) {
1645 const struct nl80211_vendor_cmd_info
*info
;
1646 struct nlattr
*nested
;
1648 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1650 goto nla_put_failure
;
1652 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1653 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1654 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1655 goto nla_put_failure
;
1657 nla_nest_end(msg
, nested
);
1660 if (rdev
->wiphy
.n_vendor_events
) {
1661 const struct nl80211_vendor_cmd_info
*info
;
1662 struct nlattr
*nested
;
1664 nested
= nla_nest_start(msg
,
1665 NL80211_ATTR_VENDOR_EVENTS
);
1667 goto nla_put_failure
;
1669 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1670 info
= &rdev
->wiphy
.vendor_events
[i
];
1671 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1672 goto nla_put_failure
;
1674 nla_nest_end(msg
, nested
);
1676 state
->split_start
++;
1679 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1680 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1681 rdev
->wiphy
.max_num_csa_counters
))
1682 goto nla_put_failure
;
1685 state
->split_start
= 0;
1689 return genlmsg_end(msg
, hdr
);
1692 genlmsg_cancel(msg
, hdr
);
1696 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1697 struct netlink_callback
*cb
,
1698 struct nl80211_dump_wiphy_state
*state
)
1700 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1701 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1702 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1703 /* ignore parse errors for backward compatibility */
1707 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1708 if (tb
[NL80211_ATTR_WIPHY
])
1709 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1710 if (tb
[NL80211_ATTR_WDEV
])
1711 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1712 if (tb
[NL80211_ATTR_IFINDEX
]) {
1713 struct net_device
*netdev
;
1714 struct cfg80211_registered_device
*rdev
;
1715 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1717 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1720 if (netdev
->ieee80211_ptr
) {
1721 rdev
= wiphy_to_rdev(
1722 netdev
->ieee80211_ptr
->wiphy
);
1723 state
->filter_wiphy
= rdev
->wiphy_idx
;
1730 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1733 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1734 struct cfg80211_registered_device
*rdev
;
1738 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1743 state
->filter_wiphy
= -1;
1744 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1750 cb
->args
[0] = (long)state
;
1753 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1754 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1756 if (++idx
<= state
->start
)
1758 if (state
->filter_wiphy
!= -1 &&
1759 state
->filter_wiphy
!= rdev
->wiphy_idx
)
1761 /* attempt to fit multiple wiphy data chunks into the skb */
1763 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
1765 NETLINK_CB(cb
->skb
).portid
,
1767 NLM_F_MULTI
, state
);
1770 * If sending the wiphy data didn't fit (ENOBUFS
1771 * or EMSGSIZE returned), this SKB is still
1772 * empty (so it's not too big because another
1773 * wiphy dataset is already in the skb) and
1774 * we've not tried to adjust the dump allocation
1775 * yet ... then adjust the alloc size to be
1776 * bigger, and return 1 but with the empty skb.
1777 * This results in an empty message being RX'ed
1778 * in userspace, but that is ignored.
1780 * We can then retry with the larger buffer.
1782 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1783 !skb
->len
&& !state
->split
&&
1784 cb
->min_dump_alloc
< 4096) {
1785 cb
->min_dump_alloc
= 4096;
1786 state
->split_start
= 0;
1793 } while (state
->split_start
> 0);
1803 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1805 kfree((void *)cb
->args
[0]);
1809 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1811 struct sk_buff
*msg
;
1812 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1813 struct nl80211_dump_wiphy_state state
= {};
1815 msg
= nlmsg_new(4096, GFP_KERNEL
);
1819 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
1820 info
->snd_portid
, info
->snd_seq
, 0,
1826 return genlmsg_reply(msg
, info
);
1829 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1830 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1831 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1832 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1833 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1834 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1837 static int parse_txq_params(struct nlattr
*tb
[],
1838 struct ieee80211_txq_params
*txq_params
)
1840 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1841 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1842 !tb
[NL80211_TXQ_ATTR_AIFS
])
1845 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1846 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1847 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1848 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1849 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1851 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1857 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1860 * You can only set the channel explicitly for WDS interfaces,
1861 * all others have their channel managed via their respective
1862 * "establish a connection" command (connect, join, ...)
1864 * For AP/GO and mesh mode, the channel can be set with the
1865 * channel userspace API, but is only stored and passed to the
1866 * low-level driver when the AP starts or the mesh is joined.
1867 * This is for backward compatibility, userspace can also give
1868 * the channel in the start-ap or join-mesh commands instead.
1870 * Monitors are special as they are normally slaved to
1871 * whatever else is going on, so they have their own special
1872 * operation to set the monitor channel if possible.
1875 wdev
->iftype
== NL80211_IFTYPE_AP
||
1876 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1877 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1878 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1881 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1882 struct genl_info
*info
,
1883 struct cfg80211_chan_def
*chandef
)
1887 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1890 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1892 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1893 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1894 chandef
->center_freq1
= control_freq
;
1895 chandef
->center_freq2
= 0;
1897 /* Primary channel not allowed */
1898 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1901 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1902 enum nl80211_channel_type chantype
;
1904 chantype
= nla_get_u32(
1905 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1908 case NL80211_CHAN_NO_HT
:
1909 case NL80211_CHAN_HT20
:
1910 case NL80211_CHAN_HT40PLUS
:
1911 case NL80211_CHAN_HT40MINUS
:
1912 cfg80211_chandef_create(chandef
, chandef
->chan
,
1918 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1920 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1921 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1922 chandef
->center_freq1
=
1924 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1925 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1926 chandef
->center_freq2
=
1928 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1931 if (!cfg80211_chandef_valid(chandef
))
1934 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1935 IEEE80211_CHAN_DISABLED
))
1938 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1939 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1940 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1946 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1947 struct net_device
*dev
,
1948 struct genl_info
*info
)
1950 struct cfg80211_chan_def chandef
;
1952 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1953 struct wireless_dev
*wdev
= NULL
;
1956 wdev
= dev
->ieee80211_ptr
;
1957 if (!nl80211_can_set_dev_channel(wdev
))
1960 iftype
= wdev
->iftype
;
1962 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1967 case NL80211_IFTYPE_AP
:
1968 case NL80211_IFTYPE_P2P_GO
:
1969 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
, iftype
)) {
1973 if (wdev
->beacon_interval
) {
1974 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
1975 !(rdev
->wiphy
.features
&
1976 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
1981 /* Only allow dynamic channel width changes */
1982 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
1986 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
1990 wdev
->preset_chandef
= chandef
;
1993 case NL80211_IFTYPE_MESH_POINT
:
1994 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1996 case NL80211_IFTYPE_MONITOR
:
1997 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2006 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2008 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2009 struct net_device
*netdev
= info
->user_ptr
[1];
2011 return __nl80211_set_channel(rdev
, netdev
, info
);
2014 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2016 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2017 struct net_device
*dev
= info
->user_ptr
[1];
2018 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2021 if (!info
->attrs
[NL80211_ATTR_MAC
])
2024 if (netif_running(dev
))
2027 if (!rdev
->ops
->set_wds_peer
)
2030 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2033 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2034 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2038 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2040 struct cfg80211_registered_device
*rdev
;
2041 struct net_device
*netdev
= NULL
;
2042 struct wireless_dev
*wdev
;
2043 int result
= 0, rem_txq_params
= 0;
2044 struct nlattr
*nl_txq_params
;
2046 u8 retry_short
= 0, retry_long
= 0;
2047 u32 frag_threshold
= 0, rts_threshold
= 0;
2048 u8 coverage_class
= 0;
2053 * Try to find the wiphy and netdev. Normally this
2054 * function shouldn't need the netdev, but this is
2055 * done for backward compatibility -- previously
2056 * setting the channel was done per wiphy, but now
2057 * it is per netdev. Previous userland like hostapd
2058 * also passed a netdev to set_wiphy, so that it is
2059 * possible to let that go to the right netdev!
2062 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2063 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2065 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2066 if (netdev
&& netdev
->ieee80211_ptr
)
2067 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2073 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2076 return PTR_ERR(rdev
);
2081 wdev
= netdev
->ieee80211_ptr
;
2084 * end workaround code, by now the rdev is available
2085 * and locked, and wdev may or may not be NULL.
2088 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2089 result
= cfg80211_dev_rename(
2090 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2095 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2096 struct ieee80211_txq_params txq_params
;
2097 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2099 if (!rdev
->ops
->set_txq_params
)
2105 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2106 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2109 if (!netif_running(netdev
))
2112 nla_for_each_nested(nl_txq_params
,
2113 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2115 result
= nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
2116 nla_data(nl_txq_params
),
2117 nla_len(nl_txq_params
),
2121 result
= parse_txq_params(tb
, &txq_params
);
2125 result
= rdev_set_txq_params(rdev
, netdev
,
2132 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2133 result
= __nl80211_set_channel(
2135 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2141 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2142 struct wireless_dev
*txp_wdev
= wdev
;
2143 enum nl80211_tx_power_setting type
;
2146 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2149 if (!rdev
->ops
->set_tx_power
)
2152 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2153 type
= nla_get_u32(info
->attrs
[idx
]);
2155 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2156 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2159 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2160 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2161 mbm
= nla_get_u32(info
->attrs
[idx
]);
2164 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2169 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2170 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2172 if ((!rdev
->wiphy
.available_antennas_tx
&&
2173 !rdev
->wiphy
.available_antennas_rx
) ||
2174 !rdev
->ops
->set_antenna
)
2177 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2178 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2180 /* reject antenna configurations which don't match the
2181 * available antenna masks, except for the "all" mask */
2182 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2183 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2186 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2187 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2189 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2196 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2197 retry_short
= nla_get_u8(
2198 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2199 if (retry_short
== 0)
2202 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2205 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2206 retry_long
= nla_get_u8(
2207 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2208 if (retry_long
== 0)
2211 changed
|= WIPHY_PARAM_RETRY_LONG
;
2214 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2215 frag_threshold
= nla_get_u32(
2216 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2217 if (frag_threshold
< 256)
2220 if (frag_threshold
!= (u32
) -1) {
2222 * Fragments (apart from the last one) are required to
2223 * have even length. Make the fragmentation code
2224 * simpler by stripping LSB should someone try to use
2225 * odd threshold value.
2227 frag_threshold
&= ~0x1;
2229 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2232 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2233 rts_threshold
= nla_get_u32(
2234 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2235 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2238 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2239 coverage_class
= nla_get_u8(
2240 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2241 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2245 u8 old_retry_short
, old_retry_long
;
2246 u32 old_frag_threshold
, old_rts_threshold
;
2247 u8 old_coverage_class
;
2249 if (!rdev
->ops
->set_wiphy_params
)
2252 old_retry_short
= rdev
->wiphy
.retry_short
;
2253 old_retry_long
= rdev
->wiphy
.retry_long
;
2254 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2255 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2256 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2258 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2259 rdev
->wiphy
.retry_short
= retry_short
;
2260 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2261 rdev
->wiphy
.retry_long
= retry_long
;
2262 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2263 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2264 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2265 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2266 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2267 rdev
->wiphy
.coverage_class
= coverage_class
;
2269 result
= rdev_set_wiphy_params(rdev
, changed
);
2271 rdev
->wiphy
.retry_short
= old_retry_short
;
2272 rdev
->wiphy
.retry_long
= old_retry_long
;
2273 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2274 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2275 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2281 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2283 return (u64
)wdev
->identifier
|
2284 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2287 static int nl80211_send_chandef(struct sk_buff
*msg
,
2288 const struct cfg80211_chan_def
*chandef
)
2290 WARN_ON(!cfg80211_chandef_valid(chandef
));
2292 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2293 chandef
->chan
->center_freq
))
2295 switch (chandef
->width
) {
2296 case NL80211_CHAN_WIDTH_20_NOHT
:
2297 case NL80211_CHAN_WIDTH_20
:
2298 case NL80211_CHAN_WIDTH_40
:
2299 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2300 cfg80211_get_chandef_type(chandef
)))
2306 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2308 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2310 if (chandef
->center_freq2
&&
2311 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2316 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2317 struct cfg80211_registered_device
*rdev
,
2318 struct wireless_dev
*wdev
)
2320 struct net_device
*dev
= wdev
->netdev
;
2323 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2328 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2329 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2330 goto nla_put_failure
;
2332 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2333 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2334 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2335 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2336 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2337 rdev
->devlist_generation
^
2338 (cfg80211_rdev_list_generation
<< 2)))
2339 goto nla_put_failure
;
2341 if (rdev
->ops
->get_channel
) {
2343 struct cfg80211_chan_def chandef
;
2345 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2347 if (nl80211_send_chandef(msg
, &chandef
))
2348 goto nla_put_failure
;
2352 if (wdev
->ssid_len
) {
2353 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2354 goto nla_put_failure
;
2357 return genlmsg_end(msg
, hdr
);
2360 genlmsg_cancel(msg
, hdr
);
2364 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2368 int wp_start
= cb
->args
[0];
2369 int if_start
= cb
->args
[1];
2370 struct cfg80211_registered_device
*rdev
;
2371 struct wireless_dev
*wdev
;
2374 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2375 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2377 if (wp_idx
< wp_start
) {
2383 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2384 if (if_idx
< if_start
) {
2388 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2389 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2401 cb
->args
[0] = wp_idx
;
2402 cb
->args
[1] = if_idx
;
2407 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2409 struct sk_buff
*msg
;
2410 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2411 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2413 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2417 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2423 return genlmsg_reply(msg
, info
);
2426 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2427 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2428 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2429 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2430 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2431 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2432 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2435 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2437 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2445 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2446 nla
, mntr_flags_policy
))
2449 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2451 *mntrflags
|= (1<<flag
);
2456 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2457 struct net_device
*netdev
, u8 use_4addr
,
2458 enum nl80211_iftype iftype
)
2461 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2467 case NL80211_IFTYPE_AP_VLAN
:
2468 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2471 case NL80211_IFTYPE_STATION
:
2472 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2482 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2484 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2485 struct vif_params params
;
2487 enum nl80211_iftype otype
, ntype
;
2488 struct net_device
*dev
= info
->user_ptr
[1];
2489 u32 _flags
, *flags
= NULL
;
2490 bool change
= false;
2492 memset(¶ms
, 0, sizeof(params
));
2494 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2496 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2497 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2500 if (ntype
> NL80211_IFTYPE_MAX
)
2504 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2505 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2507 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2509 if (netif_running(dev
))
2513 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2514 IEEE80211_MAX_MESH_ID_LEN
);
2515 wdev
->mesh_id_up_len
=
2516 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2517 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2518 wdev
->mesh_id_up_len
);
2522 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2523 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2525 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2529 params
.use_4addr
= -1;
2532 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2533 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2535 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2544 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2545 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2549 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2553 if (!err
&& params
.use_4addr
!= -1)
2554 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2559 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2561 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2562 struct vif_params params
;
2563 struct wireless_dev
*wdev
;
2564 struct sk_buff
*msg
;
2566 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2569 /* to avoid failing a new interface creation due to pending removal */
2570 cfg80211_destroy_ifaces(rdev
);
2572 memset(¶ms
, 0, sizeof(params
));
2574 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2577 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2578 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2579 if (type
> NL80211_IFTYPE_MAX
)
2583 if (!rdev
->ops
->add_virtual_intf
||
2584 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2587 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2588 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2590 if (!is_valid_ether_addr(params
.macaddr
))
2591 return -EADDRNOTAVAIL
;
2594 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2595 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2596 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2601 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2605 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2606 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2609 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2610 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2613 wdev
= rdev_add_virtual_intf(rdev
,
2614 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2615 type
, err
? NULL
: &flags
, ¶ms
);
2618 return PTR_ERR(wdev
);
2621 if (info
->attrs
[NL80211_ATTR_IFACE_SOCKET_OWNER
])
2622 wdev
->owner_nlportid
= info
->snd_portid
;
2625 case NL80211_IFTYPE_MESH_POINT
:
2626 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2629 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2630 IEEE80211_MAX_MESH_ID_LEN
);
2631 wdev
->mesh_id_up_len
=
2632 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2633 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2634 wdev
->mesh_id_up_len
);
2637 case NL80211_IFTYPE_P2P_DEVICE
:
2639 * P2P Device doesn't have a netdev, so doesn't go
2640 * through the netdev notifier and must be added here
2642 mutex_init(&wdev
->mtx
);
2643 INIT_LIST_HEAD(&wdev
->event_list
);
2644 spin_lock_init(&wdev
->event_lock
);
2645 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2646 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2648 wdev
->identifier
= ++rdev
->wdev_id
;
2649 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2650 rdev
->devlist_generation
++;
2656 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2662 return genlmsg_reply(msg
, info
);
2665 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2667 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2668 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2670 if (!rdev
->ops
->del_virtual_intf
)
2674 * If we remove a wireless device without a netdev then clear
2675 * user_ptr[1] so that nl80211_post_doit won't dereference it
2676 * to check if it needs to do dev_put(). Otherwise it crashes
2677 * since the wdev has been freed, unlike with a netdev where
2678 * we need the dev_put() for the netdev to really be freed.
2681 info
->user_ptr
[1] = NULL
;
2683 return rdev_del_virtual_intf(rdev
, wdev
);
2686 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2688 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2689 struct net_device
*dev
= info
->user_ptr
[1];
2692 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2695 if (!rdev
->ops
->set_noack_map
)
2698 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2700 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2703 struct get_key_cookie
{
2704 struct sk_buff
*msg
;
2709 static void get_key_callback(void *c
, struct key_params
*params
)
2712 struct get_key_cookie
*cookie
= c
;
2715 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2716 params
->key_len
, params
->key
)) ||
2718 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2719 params
->seq_len
, params
->seq
)) ||
2721 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2723 goto nla_put_failure
;
2725 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2727 goto nla_put_failure
;
2730 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2731 params
->key_len
, params
->key
)) ||
2733 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2734 params
->seq_len
, params
->seq
)) ||
2736 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2738 goto nla_put_failure
;
2740 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2741 goto nla_put_failure
;
2743 nla_nest_end(cookie
->msg
, key
);
2750 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2752 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2754 struct net_device
*dev
= info
->user_ptr
[1];
2756 const u8
*mac_addr
= NULL
;
2758 struct get_key_cookie cookie
= {
2762 struct sk_buff
*msg
;
2764 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2765 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2770 if (info
->attrs
[NL80211_ATTR_MAC
])
2771 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2773 pairwise
= !!mac_addr
;
2774 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2775 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2776 if (kt
>= NUM_NL80211_KEYTYPES
)
2778 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2779 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2781 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2784 if (!rdev
->ops
->get_key
)
2787 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2790 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2794 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2795 NL80211_CMD_NEW_KEY
);
2797 goto nla_put_failure
;
2800 cookie
.idx
= key_idx
;
2802 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2803 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2804 goto nla_put_failure
;
2806 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2807 goto nla_put_failure
;
2809 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2816 goto nla_put_failure
;
2818 genlmsg_end(msg
, hdr
);
2819 return genlmsg_reply(msg
, info
);
2828 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2830 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2831 struct key_parse key
;
2833 struct net_device
*dev
= info
->user_ptr
[1];
2835 err
= nl80211_parse_key(info
, &key
);
2842 /* only support setting default key */
2843 if (!key
.def
&& !key
.defmgmt
)
2846 wdev_lock(dev
->ieee80211_ptr
);
2849 if (!rdev
->ops
->set_default_key
) {
2854 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2858 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2859 key
.def_uni
, key
.def_multi
);
2864 #ifdef CONFIG_CFG80211_WEXT
2865 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2868 if (key
.def_uni
|| !key
.def_multi
) {
2873 if (!rdev
->ops
->set_default_mgmt_key
) {
2878 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2882 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2886 #ifdef CONFIG_CFG80211_WEXT
2887 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2892 wdev_unlock(dev
->ieee80211_ptr
);
2897 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2899 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2901 struct net_device
*dev
= info
->user_ptr
[1];
2902 struct key_parse key
;
2903 const u8
*mac_addr
= NULL
;
2905 err
= nl80211_parse_key(info
, &key
);
2912 if (info
->attrs
[NL80211_ATTR_MAC
])
2913 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2915 if (key
.type
== -1) {
2917 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2919 key
.type
= NL80211_KEYTYPE_GROUP
;
2923 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2924 key
.type
!= NL80211_KEYTYPE_GROUP
)
2927 if (!rdev
->ops
->add_key
)
2930 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2931 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2935 wdev_lock(dev
->ieee80211_ptr
);
2936 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2938 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2939 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2941 wdev_unlock(dev
->ieee80211_ptr
);
2946 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2948 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2950 struct net_device
*dev
= info
->user_ptr
[1];
2951 u8
*mac_addr
= NULL
;
2952 struct key_parse key
;
2954 err
= nl80211_parse_key(info
, &key
);
2958 if (info
->attrs
[NL80211_ATTR_MAC
])
2959 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2961 if (key
.type
== -1) {
2963 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2965 key
.type
= NL80211_KEYTYPE_GROUP
;
2969 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2970 key
.type
!= NL80211_KEYTYPE_GROUP
)
2973 if (!rdev
->ops
->del_key
)
2976 wdev_lock(dev
->ieee80211_ptr
);
2977 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2979 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
2980 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2984 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2985 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2988 #ifdef CONFIG_CFG80211_WEXT
2990 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2991 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2992 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2993 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2996 wdev_unlock(dev
->ieee80211_ptr
);
3001 /* This function returns an error or the number of nested attributes */
3002 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3004 struct nlattr
*attr
;
3005 int n_entries
= 0, tmp
;
3007 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3008 if (nla_len(attr
) != ETH_ALEN
)
3018 * This function parses ACL information and allocates memory for ACL data.
3019 * On successful return, the calling function is responsible to free the
3020 * ACL buffer returned by this function.
3022 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3023 struct genl_info
*info
)
3025 enum nl80211_acl_policy acl_policy
;
3026 struct nlattr
*attr
;
3027 struct cfg80211_acl_data
*acl
;
3028 int i
= 0, n_entries
, tmp
;
3030 if (!wiphy
->max_acl_mac_addrs
)
3031 return ERR_PTR(-EOPNOTSUPP
);
3033 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3034 return ERR_PTR(-EINVAL
);
3036 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3037 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3038 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3039 return ERR_PTR(-EINVAL
);
3041 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3042 return ERR_PTR(-EINVAL
);
3044 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3046 return ERR_PTR(n_entries
);
3048 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3049 return ERR_PTR(-ENOTSUPP
);
3051 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3054 return ERR_PTR(-ENOMEM
);
3056 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3057 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3061 acl
->n_acl_entries
= n_entries
;
3062 acl
->acl_policy
= acl_policy
;
3067 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3069 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3070 struct net_device
*dev
= info
->user_ptr
[1];
3071 struct cfg80211_acl_data
*acl
;
3074 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3075 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3078 if (!dev
->ieee80211_ptr
->beacon_interval
)
3081 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3083 return PTR_ERR(acl
);
3085 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3092 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3093 struct cfg80211_beacon_data
*bcn
)
3095 bool haveinfo
= false;
3097 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3098 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3099 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3100 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3103 memset(bcn
, 0, sizeof(*bcn
));
3105 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3106 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3107 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3113 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3114 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3115 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3122 if (attrs
[NL80211_ATTR_IE
]) {
3123 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3124 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3127 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3128 bcn
->proberesp_ies
=
3129 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3130 bcn
->proberesp_ies_len
=
3131 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3134 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3135 bcn
->assocresp_ies
=
3136 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3137 bcn
->assocresp_ies_len
=
3138 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3141 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3142 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3143 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3149 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3150 struct cfg80211_ap_settings
*params
)
3152 struct wireless_dev
*wdev
;
3155 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3156 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3157 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3160 if (!wdev
->preset_chandef
.chan
)
3163 params
->chandef
= wdev
->preset_chandef
;
3171 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3172 enum nl80211_auth_type auth_type
,
3173 enum nl80211_commands cmd
)
3175 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3179 case NL80211_CMD_AUTHENTICATE
:
3180 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3181 auth_type
== NL80211_AUTHTYPE_SAE
)
3184 case NL80211_CMD_CONNECT
:
3185 case NL80211_CMD_START_AP
:
3186 /* SAE not supported yet */
3187 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3195 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3197 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3198 struct net_device
*dev
= info
->user_ptr
[1];
3199 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3200 struct cfg80211_ap_settings params
;
3203 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3204 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3207 if (!rdev
->ops
->start_ap
)
3210 if (wdev
->beacon_interval
)
3213 memset(¶ms
, 0, sizeof(params
));
3215 /* these are required for START_AP */
3216 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3217 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3218 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3221 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3225 params
.beacon_interval
=
3226 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3227 params
.dtim_period
=
3228 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3230 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3235 * In theory, some of these attributes should be required here
3236 * but since they were not used when the command was originally
3237 * added, keep them optional for old user space programs to let
3238 * them continue to work with drivers that do not need the
3239 * additional information -- drivers must check!
3241 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3242 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3244 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3245 if (params
.ssid_len
== 0 ||
3246 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3250 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3251 params
.hidden_ssid
= nla_get_u32(
3252 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3253 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3254 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3255 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3259 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3261 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3262 params
.auth_type
= nla_get_u32(
3263 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3264 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3265 NL80211_CMD_START_AP
))
3268 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3270 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3271 NL80211_MAX_NR_CIPHER_SUITES
);
3275 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3276 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3278 params
.inactivity_timeout
= nla_get_u16(
3279 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3282 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3283 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3285 params
.p2p_ctwindow
=
3286 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3287 if (params
.p2p_ctwindow
> 127)
3289 if (params
.p2p_ctwindow
!= 0 &&
3290 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3294 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3297 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3299 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3302 params
.p2p_opp_ps
= tmp
;
3303 if (params
.p2p_opp_ps
!= 0 &&
3304 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3308 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3309 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3312 } else if (wdev
->preset_chandef
.chan
) {
3313 params
.chandef
= wdev
->preset_chandef
;
3314 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3317 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
,
3321 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3322 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3323 if (IS_ERR(params
.acl
))
3324 return PTR_ERR(params
.acl
);
3328 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3330 wdev
->preset_chandef
= params
.chandef
;
3331 wdev
->beacon_interval
= params
.beacon_interval
;
3332 wdev
->chandef
= params
.chandef
;
3333 wdev
->ssid_len
= params
.ssid_len
;
3334 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3343 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3345 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3346 struct net_device
*dev
= info
->user_ptr
[1];
3347 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3348 struct cfg80211_beacon_data params
;
3351 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3352 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3355 if (!rdev
->ops
->change_beacon
)
3358 if (!wdev
->beacon_interval
)
3361 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3366 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
3372 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3374 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3375 struct net_device
*dev
= info
->user_ptr
[1];
3377 return cfg80211_stop_ap(rdev
, dev
, false);
3380 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3381 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3382 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3383 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3384 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3385 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3386 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3389 static int parse_station_flags(struct genl_info
*info
,
3390 enum nl80211_iftype iftype
,
3391 struct station_parameters
*params
)
3393 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3398 * Try parsing the new attribute first so userspace
3399 * can specify both for older kernels.
3401 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3403 struct nl80211_sta_flag_update
*sta_flags
;
3405 sta_flags
= nla_data(nla
);
3406 params
->sta_flags_mask
= sta_flags
->mask
;
3407 params
->sta_flags_set
= sta_flags
->set
;
3408 params
->sta_flags_set
&= params
->sta_flags_mask
;
3409 if ((params
->sta_flags_mask
|
3410 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3415 /* if present, parse the old attribute */
3417 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3421 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3422 nla
, sta_flags_policy
))
3426 * Only allow certain flags for interface types so that
3427 * other attributes are silently ignored. Remember that
3428 * this is backward compatibility code with old userspace
3429 * and shouldn't be hit in other cases anyway.
3432 case NL80211_IFTYPE_AP
:
3433 case NL80211_IFTYPE_AP_VLAN
:
3434 case NL80211_IFTYPE_P2P_GO
:
3435 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3436 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3437 BIT(NL80211_STA_FLAG_WME
) |
3438 BIT(NL80211_STA_FLAG_MFP
);
3440 case NL80211_IFTYPE_P2P_CLIENT
:
3441 case NL80211_IFTYPE_STATION
:
3442 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3443 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3445 case NL80211_IFTYPE_MESH_POINT
:
3446 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3447 BIT(NL80211_STA_FLAG_MFP
) |
3448 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3453 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3455 params
->sta_flags_set
|= (1<<flag
);
3457 /* no longer support new API additions in old API */
3458 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3466 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3469 struct nlattr
*rate
;
3473 rate
= nla_nest_start(msg
, attr
);
3477 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3478 bitrate
= cfg80211_calculate_bitrate(info
);
3479 /* report 16-bit bitrate only if we can */
3480 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3482 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3484 if (bitrate_compat
> 0 &&
3485 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3488 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3489 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3491 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3492 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3494 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3495 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3497 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3498 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3500 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3502 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3503 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3505 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3506 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3508 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3509 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3511 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3512 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3514 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3515 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3519 nla_nest_end(msg
, rate
);
3523 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3532 attr
= nla_nest_start(msg
, id
);
3536 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3537 if (!(mask
& BIT(i
)))
3540 if (nla_put_u8(msg
, i
, signal
[i
]))
3544 nla_nest_end(msg
, attr
);
3549 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3551 struct cfg80211_registered_device
*rdev
,
3552 struct net_device
*dev
,
3553 const u8
*mac_addr
, struct station_info
*sinfo
)
3556 struct nlattr
*sinfoattr
, *bss_param
;
3558 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3562 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3563 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3564 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3565 goto nla_put_failure
;
3567 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3569 goto nla_put_failure
;
3570 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3571 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3572 sinfo
->connected_time
))
3573 goto nla_put_failure
;
3574 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3575 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3576 sinfo
->inactive_time
))
3577 goto nla_put_failure
;
3578 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3579 STATION_INFO_RX_BYTES64
)) &&
3580 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3581 (u32
)sinfo
->rx_bytes
))
3582 goto nla_put_failure
;
3583 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3584 STATION_INFO_TX_BYTES64
)) &&
3585 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3586 (u32
)sinfo
->tx_bytes
))
3587 goto nla_put_failure
;
3588 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3589 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3591 goto nla_put_failure
;
3592 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3593 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3595 goto nla_put_failure
;
3596 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3597 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3598 goto nla_put_failure
;
3599 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3600 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3601 goto nla_put_failure
;
3602 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3603 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3604 sinfo
->plink_state
))
3605 goto nla_put_failure
;
3606 switch (rdev
->wiphy
.signal_type
) {
3607 case CFG80211_SIGNAL_TYPE_MBM
:
3608 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3609 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3611 goto nla_put_failure
;
3612 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3613 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3615 goto nla_put_failure
;
3620 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL
) {
3621 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3622 sinfo
->chain_signal
,
3623 NL80211_STA_INFO_CHAIN_SIGNAL
))
3624 goto nla_put_failure
;
3626 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL_AVG
) {
3627 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3628 sinfo
->chain_signal_avg
,
3629 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3630 goto nla_put_failure
;
3632 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3633 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3634 NL80211_STA_INFO_TX_BITRATE
))
3635 goto nla_put_failure
;
3637 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3638 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3639 NL80211_STA_INFO_RX_BITRATE
))
3640 goto nla_put_failure
;
3642 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3643 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3645 goto nla_put_failure
;
3646 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3647 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3649 goto nla_put_failure
;
3650 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3651 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3653 goto nla_put_failure
;
3654 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3655 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3657 goto nla_put_failure
;
3658 if ((sinfo
->filled
& STATION_INFO_EXPECTED_THROUGHPUT
) &&
3659 nla_put_u32(msg
, NL80211_STA_INFO_EXPECTED_THROUGHPUT
,
3660 sinfo
->expected_throughput
))
3661 goto nla_put_failure
;
3662 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3663 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3664 sinfo
->beacon_loss_count
))
3665 goto nla_put_failure
;
3666 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3667 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3669 goto nla_put_failure
;
3670 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3671 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3673 goto nla_put_failure
;
3674 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3675 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3677 goto nla_put_failure
;
3678 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3679 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3681 goto nla_put_failure
;
3683 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3684 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3685 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3686 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3687 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3688 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3689 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3690 sinfo
->bss_param
.dtim_period
) ||
3691 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3692 sinfo
->bss_param
.beacon_interval
))
3693 goto nla_put_failure
;
3695 nla_nest_end(msg
, bss_param
);
3697 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3698 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3699 sizeof(struct nl80211_sta_flag_update
),
3701 goto nla_put_failure
;
3702 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3703 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3705 goto nla_put_failure
;
3706 nla_nest_end(msg
, sinfoattr
);
3708 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3709 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3710 sinfo
->assoc_req_ies
))
3711 goto nla_put_failure
;
3713 return genlmsg_end(msg
, hdr
);
3716 genlmsg_cancel(msg
, hdr
);
3720 static int nl80211_dump_station(struct sk_buff
*skb
,
3721 struct netlink_callback
*cb
)
3723 struct station_info sinfo
;
3724 struct cfg80211_registered_device
*rdev
;
3725 struct wireless_dev
*wdev
;
3726 u8 mac_addr
[ETH_ALEN
];
3727 int sta_idx
= cb
->args
[2];
3730 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
3734 if (!wdev
->netdev
) {
3739 if (!rdev
->ops
->dump_station
) {
3745 memset(&sinfo
, 0, sizeof(sinfo
));
3746 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
3753 if (nl80211_send_station(skb
,
3754 NETLINK_CB(cb
->skb
).portid
,
3755 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3756 rdev
, wdev
->netdev
, mac_addr
,
3765 cb
->args
[2] = sta_idx
;
3768 nl80211_finish_wdev_dump(rdev
);
3773 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3775 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3776 struct net_device
*dev
= info
->user_ptr
[1];
3777 struct station_info sinfo
;
3778 struct sk_buff
*msg
;
3779 u8
*mac_addr
= NULL
;
3782 memset(&sinfo
, 0, sizeof(sinfo
));
3784 if (!info
->attrs
[NL80211_ATTR_MAC
])
3787 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3789 if (!rdev
->ops
->get_station
)
3792 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3796 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3800 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3801 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3806 return genlmsg_reply(msg
, info
);
3809 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3810 struct station_parameters
*params
,
3811 enum cfg80211_station_type statype
)
3813 if (params
->listen_interval
!= -1)
3818 /* When you run into this, adjust the code below for the new flag */
3819 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3822 case CFG80211_STA_MESH_PEER_KERNEL
:
3823 case CFG80211_STA_MESH_PEER_USER
:
3825 * No ignoring the TDLS flag here -- the userspace mesh
3826 * code doesn't have the bug of including TDLS in the
3829 if (params
->sta_flags_mask
&
3830 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3831 BIT(NL80211_STA_FLAG_MFP
) |
3832 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3835 case CFG80211_STA_TDLS_PEER_SETUP
:
3836 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3837 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3839 /* ignore since it can't change */
3840 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3843 /* disallow mesh-specific things */
3844 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3846 if (params
->local_pm
)
3848 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3852 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3853 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3854 /* TDLS can't be set, ... */
3855 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3858 * ... but don't bother the driver with it. This works around
3859 * a hostapd/wpa_supplicant issue -- it always includes the
3860 * TLDS_PEER flag in the mask even for AP mode.
3862 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3865 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3866 /* reject other things that can't change */
3867 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3869 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3871 if (params
->supported_rates
)
3873 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3877 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3883 case CFG80211_STA_AP_MLME_CLIENT
:
3884 /* Use this only for authorizing/unauthorizing a station */
3885 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3888 case CFG80211_STA_AP_CLIENT
:
3889 /* accept only the listed bits */
3890 if (params
->sta_flags_mask
&
3891 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3892 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3893 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3894 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3895 BIT(NL80211_STA_FLAG_WME
) |
3896 BIT(NL80211_STA_FLAG_MFP
)))
3899 /* but authenticated/associated only if driver handles it */
3900 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3901 params
->sta_flags_mask
&
3902 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3903 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3906 case CFG80211_STA_IBSS
:
3907 case CFG80211_STA_AP_STA
:
3908 /* reject any changes other than AUTHORIZED */
3909 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3912 case CFG80211_STA_TDLS_PEER_SETUP
:
3913 /* reject any changes other than AUTHORIZED or WME */
3914 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3915 BIT(NL80211_STA_FLAG_WME
)))
3917 /* force (at least) rates when authorizing */
3918 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3919 !params
->supported_rates
)
3922 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3923 /* reject any changes */
3925 case CFG80211_STA_MESH_PEER_KERNEL
:
3926 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3929 case CFG80211_STA_MESH_PEER_USER
:
3930 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3937 EXPORT_SYMBOL(cfg80211_check_station_change
);
3940 * Get vlan interface making sure it is running and on the right wiphy.
3942 static struct net_device
*get_vlan(struct genl_info
*info
,
3943 struct cfg80211_registered_device
*rdev
)
3945 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3946 struct net_device
*v
;
3952 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3954 return ERR_PTR(-ENODEV
);
3956 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3961 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3962 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3963 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3968 if (!netif_running(v
)) {
3976 return ERR_PTR(ret
);
3979 static const struct nla_policy
3980 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
3981 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3982 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3985 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3986 struct station_parameters
*params
)
3988 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3992 /* parse WME attributes if present */
3993 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3996 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3997 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3998 nl80211_sta_wme_policy
);
4002 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4003 params
->uapsd_queues
= nla_get_u8(
4004 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4005 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4008 if (tb
[NL80211_STA_WME_MAX_SP
])
4009 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4011 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4014 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4019 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4020 struct station_parameters
*params
)
4022 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4023 params
->supported_channels
=
4024 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4025 params
->supported_channels_len
=
4026 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4028 * Need to include at least one (first channel, number of
4029 * channels) tuple for each subband, and must have proper
4030 * tuples for the rest of the data as well.
4032 if (params
->supported_channels_len
< 2)
4034 if (params
->supported_channels_len
% 2)
4038 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4039 params
->supported_oper_classes
=
4040 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4041 params
->supported_oper_classes_len
=
4042 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4044 * The value of the Length field of the Supported Operating
4045 * Classes element is between 2 and 253.
4047 if (params
->supported_oper_classes_len
< 2 ||
4048 params
->supported_oper_classes_len
> 253)
4054 static int nl80211_set_station_tdls(struct genl_info
*info
,
4055 struct station_parameters
*params
)
4058 /* Dummy STA entry gets updated once the peer capabilities are known */
4059 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4060 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4061 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4063 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4064 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4066 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4068 err
= nl80211_parse_sta_channel_info(info
, params
);
4072 return nl80211_parse_sta_wme(info
, params
);
4075 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4077 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4078 struct net_device
*dev
= info
->user_ptr
[1];
4079 struct station_parameters params
;
4083 memset(¶ms
, 0, sizeof(params
));
4085 params
.listen_interval
= -1;
4087 if (!rdev
->ops
->change_station
)
4090 if (info
->attrs
[NL80211_ATTR_STA_AID
])
4093 if (!info
->attrs
[NL80211_ATTR_MAC
])
4096 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4098 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4099 params
.supported_rates
=
4100 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4101 params
.supported_rates_len
=
4102 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4105 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4107 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4108 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4111 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4113 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4114 params
.ext_capab_len
=
4115 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4118 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4121 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4124 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4125 params
.plink_action
=
4126 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4127 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4131 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4132 params
.plink_state
=
4133 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4134 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4136 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4139 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4140 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4141 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4143 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4144 pm
> NL80211_MESH_POWER_MAX
)
4147 params
.local_pm
= pm
;
4150 /* Include parameters for TDLS peer (will check later) */
4151 err
= nl80211_set_station_tdls(info
, ¶ms
);
4155 params
.vlan
= get_vlan(info
, rdev
);
4156 if (IS_ERR(params
.vlan
))
4157 return PTR_ERR(params
.vlan
);
4159 switch (dev
->ieee80211_ptr
->iftype
) {
4160 case NL80211_IFTYPE_AP
:
4161 case NL80211_IFTYPE_AP_VLAN
:
4162 case NL80211_IFTYPE_P2P_GO
:
4163 case NL80211_IFTYPE_P2P_CLIENT
:
4164 case NL80211_IFTYPE_STATION
:
4165 case NL80211_IFTYPE_ADHOC
:
4166 case NL80211_IFTYPE_MESH_POINT
:
4173 /* driver will call cfg80211_check_station_change() */
4174 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4178 dev_put(params
.vlan
);
4183 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4185 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4187 struct net_device
*dev
= info
->user_ptr
[1];
4188 struct station_parameters params
;
4189 u8
*mac_addr
= NULL
;
4191 memset(¶ms
, 0, sizeof(params
));
4193 if (!rdev
->ops
->add_station
)
4196 if (!info
->attrs
[NL80211_ATTR_MAC
])
4199 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4202 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4205 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4206 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4209 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4210 params
.supported_rates
=
4211 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4212 params
.supported_rates_len
=
4213 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4214 params
.listen_interval
=
4215 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4217 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4218 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4220 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4221 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4224 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4226 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4227 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4230 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4232 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4233 params
.ext_capab_len
=
4234 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4237 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4239 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4241 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4243 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4245 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4246 params
.opmode_notif_used
= true;
4247 params
.opmode_notif
=
4248 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4251 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4252 params
.plink_action
=
4253 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4254 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4258 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
4262 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4266 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4269 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4270 * as userspace might just pass through the capabilities from the IEs
4271 * directly, rather than enforcing this restriction and returning an
4272 * error in this case.
4274 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4275 params
.ht_capa
= NULL
;
4276 params
.vht_capa
= NULL
;
4279 /* When you run into this, adjust the code below for the new flag */
4280 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4282 switch (dev
->ieee80211_ptr
->iftype
) {
4283 case NL80211_IFTYPE_AP
:
4284 case NL80211_IFTYPE_AP_VLAN
:
4285 case NL80211_IFTYPE_P2P_GO
:
4286 /* ignore WME attributes if iface/sta is not capable */
4287 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4288 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4289 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4291 /* TDLS peers cannot be added */
4292 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4293 info
->attrs
[NL80211_ATTR_PEER_AID
])
4295 /* but don't bother the driver with it */
4296 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4298 /* allow authenticated/associated only if driver handles it */
4299 if (!(rdev
->wiphy
.features
&
4300 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4301 params
.sta_flags_mask
&
4302 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4303 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4306 /* must be last in here for error handling */
4307 params
.vlan
= get_vlan(info
, rdev
);
4308 if (IS_ERR(params
.vlan
))
4309 return PTR_ERR(params
.vlan
);
4311 case NL80211_IFTYPE_MESH_POINT
:
4312 /* ignore uAPSD data */
4313 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4315 /* associated is disallowed */
4316 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4318 /* TDLS peers cannot be added */
4319 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4320 info
->attrs
[NL80211_ATTR_PEER_AID
])
4323 case NL80211_IFTYPE_STATION
:
4324 case NL80211_IFTYPE_P2P_CLIENT
:
4325 /* ignore uAPSD data */
4326 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4328 /* these are disallowed */
4329 if (params
.sta_flags_mask
&
4330 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4331 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4333 /* Only TDLS peers can be added */
4334 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4336 /* Can only add if TDLS ... */
4337 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4339 /* ... with external setup is supported */
4340 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4343 * Older wpa_supplicant versions always mark the TDLS peer
4344 * as authorized, but it shouldn't yet be.
4346 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4352 /* be aware of params.vlan when changing code here */
4354 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4357 dev_put(params
.vlan
);
4361 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4363 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4364 struct net_device
*dev
= info
->user_ptr
[1];
4365 u8
*mac_addr
= NULL
;
4367 if (info
->attrs
[NL80211_ATTR_MAC
])
4368 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4370 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4371 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4372 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4373 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4376 if (!rdev
->ops
->del_station
)
4379 return rdev_del_station(rdev
, dev
, mac_addr
);
4382 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4383 int flags
, struct net_device
*dev
,
4384 u8
*dst
, u8
*next_hop
,
4385 struct mpath_info
*pinfo
)
4388 struct nlattr
*pinfoattr
;
4390 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4394 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4395 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4396 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4397 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4398 goto nla_put_failure
;
4400 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4402 goto nla_put_failure
;
4403 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4404 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4406 goto nla_put_failure
;
4407 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4408 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4409 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4410 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4412 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4413 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4415 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4416 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4418 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4419 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4420 pinfo
->discovery_timeout
)) ||
4421 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4422 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4423 pinfo
->discovery_retries
)))
4424 goto nla_put_failure
;
4426 nla_nest_end(msg
, pinfoattr
);
4428 return genlmsg_end(msg
, hdr
);
4431 genlmsg_cancel(msg
, hdr
);
4435 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4436 struct netlink_callback
*cb
)
4438 struct mpath_info pinfo
;
4439 struct cfg80211_registered_device
*rdev
;
4440 struct wireless_dev
*wdev
;
4442 u8 next_hop
[ETH_ALEN
];
4443 int path_idx
= cb
->args
[2];
4446 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4450 if (!rdev
->ops
->dump_mpath
) {
4455 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4461 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
4468 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4469 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4470 wdev
->netdev
, dst
, next_hop
,
4479 cb
->args
[2] = path_idx
;
4482 nl80211_finish_wdev_dump(rdev
);
4486 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4488 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4490 struct net_device
*dev
= info
->user_ptr
[1];
4491 struct mpath_info pinfo
;
4492 struct sk_buff
*msg
;
4494 u8 next_hop
[ETH_ALEN
];
4496 memset(&pinfo
, 0, sizeof(pinfo
));
4498 if (!info
->attrs
[NL80211_ATTR_MAC
])
4501 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4503 if (!rdev
->ops
->get_mpath
)
4506 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4509 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4513 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4517 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4518 dev
, dst
, next_hop
, &pinfo
) < 0) {
4523 return genlmsg_reply(msg
, info
);
4526 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4528 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4529 struct net_device
*dev
= info
->user_ptr
[1];
4531 u8
*next_hop
= NULL
;
4533 if (!info
->attrs
[NL80211_ATTR_MAC
])
4536 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4539 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4540 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4542 if (!rdev
->ops
->change_mpath
)
4545 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4548 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4551 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4553 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4554 struct net_device
*dev
= info
->user_ptr
[1];
4556 u8
*next_hop
= NULL
;
4558 if (!info
->attrs
[NL80211_ATTR_MAC
])
4561 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4564 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4565 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4567 if (!rdev
->ops
->add_mpath
)
4570 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4573 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4576 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4578 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4579 struct net_device
*dev
= info
->user_ptr
[1];
4582 if (info
->attrs
[NL80211_ATTR_MAC
])
4583 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4585 if (!rdev
->ops
->del_mpath
)
4588 return rdev_del_mpath(rdev
, dev
, dst
);
4591 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4593 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4594 struct net_device
*dev
= info
->user_ptr
[1];
4595 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4596 struct bss_parameters params
;
4599 memset(¶ms
, 0, sizeof(params
));
4600 /* default to not changing parameters */
4601 params
.use_cts_prot
= -1;
4602 params
.use_short_preamble
= -1;
4603 params
.use_short_slot_time
= -1;
4604 params
.ap_isolate
= -1;
4605 params
.ht_opmode
= -1;
4606 params
.p2p_ctwindow
= -1;
4607 params
.p2p_opp_ps
= -1;
4609 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4610 params
.use_cts_prot
=
4611 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4612 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4613 params
.use_short_preamble
=
4614 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4615 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4616 params
.use_short_slot_time
=
4617 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4618 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4619 params
.basic_rates
=
4620 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4621 params
.basic_rates_len
=
4622 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4624 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4625 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4626 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4628 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4630 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4631 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4633 params
.p2p_ctwindow
=
4634 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4635 if (params
.p2p_ctwindow
< 0)
4637 if (params
.p2p_ctwindow
!= 0 &&
4638 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4642 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4645 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4647 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4650 params
.p2p_opp_ps
= tmp
;
4651 if (params
.p2p_opp_ps
&&
4652 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4656 if (!rdev
->ops
->change_bss
)
4659 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4660 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4664 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
4670 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4671 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4672 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4673 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4674 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4675 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4676 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4677 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
4680 static int parse_reg_rule(struct nlattr
*tb
[],
4681 struct ieee80211_reg_rule
*reg_rule
)
4683 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4684 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4686 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4688 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4690 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4692 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4694 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4697 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4699 freq_range
->start_freq_khz
=
4700 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4701 freq_range
->end_freq_khz
=
4702 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4703 freq_range
->max_bandwidth_khz
=
4704 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4706 power_rule
->max_eirp
=
4707 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4709 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4710 power_rule
->max_antenna_gain
=
4711 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4713 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
4714 reg_rule
->dfs_cac_ms
=
4715 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
4720 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4723 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4726 * You should only get this when cfg80211 hasn't yet initialized
4727 * completely when built-in to the kernel right between the time
4728 * window between nl80211_init() and regulatory_init(), if that is
4731 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4732 return -EINPROGRESS
;
4734 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4735 user_reg_hint_type
=
4736 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4738 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4740 switch (user_reg_hint_type
) {
4741 case NL80211_USER_REG_HINT_USER
:
4742 case NL80211_USER_REG_HINT_CELL_BASE
:
4743 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4746 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4747 return regulatory_hint_user(data
, user_reg_hint_type
);
4748 case NL80211_USER_REG_HINT_INDOOR
:
4749 return regulatory_hint_indoor_user();
4755 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4756 struct genl_info
*info
)
4758 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4759 struct net_device
*dev
= info
->user_ptr
[1];
4760 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4761 struct mesh_config cur_params
;
4764 struct nlattr
*pinfoattr
;
4765 struct sk_buff
*msg
;
4767 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4770 if (!rdev
->ops
->get_mesh_config
)
4774 /* If not connected, get default parameters */
4775 if (!wdev
->mesh_id_len
)
4776 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4778 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4784 /* Draw up a netlink message to send back */
4785 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4788 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4789 NL80211_CMD_GET_MESH_CONFIG
);
4792 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4794 goto nla_put_failure
;
4795 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4796 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4797 cur_params
.dot11MeshRetryTimeout
) ||
4798 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4799 cur_params
.dot11MeshConfirmTimeout
) ||
4800 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4801 cur_params
.dot11MeshHoldingTimeout
) ||
4802 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4803 cur_params
.dot11MeshMaxPeerLinks
) ||
4804 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4805 cur_params
.dot11MeshMaxRetries
) ||
4806 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4807 cur_params
.dot11MeshTTL
) ||
4808 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4809 cur_params
.element_ttl
) ||
4810 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4811 cur_params
.auto_open_plinks
) ||
4812 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4813 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4814 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4815 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4816 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4817 cur_params
.path_refresh_time
) ||
4818 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4819 cur_params
.min_discovery_timeout
) ||
4820 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4821 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4822 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4823 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4824 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4825 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4826 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4827 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4828 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4829 cur_params
.dot11MeshHWMPRootMode
) ||
4830 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4831 cur_params
.dot11MeshHWMPRannInterval
) ||
4832 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4833 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4834 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4835 cur_params
.dot11MeshForwarding
) ||
4836 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4837 cur_params
.rssi_threshold
) ||
4838 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4839 cur_params
.ht_opmode
) ||
4840 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4841 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4842 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4843 cur_params
.dot11MeshHWMProotInterval
) ||
4844 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4845 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4846 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4847 cur_params
.power_mode
) ||
4848 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4849 cur_params
.dot11MeshAwakeWindowDuration
) ||
4850 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4851 cur_params
.plink_timeout
))
4852 goto nla_put_failure
;
4853 nla_nest_end(msg
, pinfoattr
);
4854 genlmsg_end(msg
, hdr
);
4855 return genlmsg_reply(msg
, info
);
4858 genlmsg_cancel(msg
, hdr
);
4864 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4865 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4866 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4867 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4868 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4869 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4870 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4871 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4872 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4873 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4874 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4875 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4876 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4877 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4878 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4879 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4880 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4881 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4882 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4883 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4884 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4885 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4886 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4887 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4888 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4889 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4890 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4891 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4892 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
4895 static const struct nla_policy
4896 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4897 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4898 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4899 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4900 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4901 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
4902 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4903 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4904 .len
= IEEE80211_MAX_DATA_LEN
},
4905 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4908 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4909 struct mesh_config
*cfg
,
4912 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4915 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4918 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4920 cfg->param = fn(tb[attr]); \
4921 mask |= (1 << (attr - 1)); \
4926 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4928 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4929 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4930 nl80211_meshconf_params_policy
))
4933 /* This makes sure that there aren't more than 32 mesh config
4934 * parameters (otherwise our bitfield scheme would not work.) */
4935 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4937 /* Fill in the params struct */
4938 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4939 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4941 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4942 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4944 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4945 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4947 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4948 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4950 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4951 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4953 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4954 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4955 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4956 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4958 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4959 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4961 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4963 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4965 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4966 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4968 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4969 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4971 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4972 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4974 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4976 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4978 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4980 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4982 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4984 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4986 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4987 dot11MeshHWMPnetDiameterTraversalTime
,
4989 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4991 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4992 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4994 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4995 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4997 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4998 dot11MeshGateAnnouncementProtocol
, 0, 1,
4999 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5001 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
5002 mask
, NL80211_MESHCONF_FORWARDING
,
5004 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
5005 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5007 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
5008 mask
, NL80211_MESHCONF_HT_OPMODE
,
5010 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
5012 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5014 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
5015 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5017 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5018 dot11MeshHWMPconfirmationInterval
,
5020 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5022 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
5023 NL80211_MESH_POWER_ACTIVE
,
5024 NL80211_MESH_POWER_MAX
,
5025 mask
, NL80211_MESHCONF_POWER_MODE
,
5027 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
5029 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
5030 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 1, 0xffffffff,
5031 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5038 #undef FILL_IN_MESH_PARAM_IF_SET
5041 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
5042 struct mesh_setup
*setup
)
5044 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5045 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
5047 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
5049 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
5050 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
5051 nl80211_mesh_setup_params_policy
))
5054 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
5055 setup
->sync_method
=
5056 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
5057 IEEE80211_SYNC_METHOD_VENDOR
:
5058 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
5060 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
5061 setup
->path_sel_proto
=
5062 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
5063 IEEE80211_PATH_PROTOCOL_VENDOR
:
5064 IEEE80211_PATH_PROTOCOL_HWMP
;
5066 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
5067 setup
->path_metric
=
5068 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
5069 IEEE80211_PATH_METRIC_VENDOR
:
5070 IEEE80211_PATH_METRIC_AIRTIME
;
5073 if (tb
[NL80211_MESH_SETUP_IE
]) {
5074 struct nlattr
*ieattr
=
5075 tb
[NL80211_MESH_SETUP_IE
];
5076 if (!is_valid_ie_attr(ieattr
))
5078 setup
->ie
= nla_data(ieattr
);
5079 setup
->ie_len
= nla_len(ieattr
);
5081 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
5082 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
5084 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
5085 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
5086 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
5087 if (setup
->is_secure
)
5088 setup
->user_mpm
= true;
5090 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
5091 if (!setup
->user_mpm
)
5094 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
5100 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
5101 struct genl_info
*info
)
5103 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5104 struct net_device
*dev
= info
->user_ptr
[1];
5105 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5106 struct mesh_config cfg
;
5110 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5113 if (!rdev
->ops
->update_mesh_config
)
5116 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
5121 if (!wdev
->mesh_id_len
)
5125 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
5132 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5134 const struct ieee80211_regdomain
*regdom
;
5135 struct sk_buff
*msg
;
5137 struct nlattr
*nl_reg_rules
;
5140 if (!cfg80211_regdomain
)
5143 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5147 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5148 NL80211_CMD_GET_REG
);
5152 if (reg_last_request_cell_base() &&
5153 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5154 NL80211_USER_REG_HINT_CELL_BASE
))
5155 goto nla_put_failure
;
5158 regdom
= rcu_dereference(cfg80211_regdomain
);
5160 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
5161 (regdom
->dfs_region
&&
5162 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
5163 goto nla_put_failure_rcu
;
5165 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
5167 goto nla_put_failure_rcu
;
5169 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
5170 struct nlattr
*nl_reg_rule
;
5171 const struct ieee80211_reg_rule
*reg_rule
;
5172 const struct ieee80211_freq_range
*freq_range
;
5173 const struct ieee80211_power_rule
*power_rule
;
5174 unsigned int max_bandwidth_khz
;
5176 reg_rule
= ®dom
->reg_rules
[i
];
5177 freq_range
= ®_rule
->freq_range
;
5178 power_rule
= ®_rule
->power_rule
;
5180 nl_reg_rule
= nla_nest_start(msg
, i
);
5182 goto nla_put_failure_rcu
;
5184 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
5185 if (!max_bandwidth_khz
)
5186 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
5189 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
5191 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
5192 freq_range
->start_freq_khz
) ||
5193 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
5194 freq_range
->end_freq_khz
) ||
5195 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
5196 max_bandwidth_khz
) ||
5197 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
5198 power_rule
->max_antenna_gain
) ||
5199 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
5200 power_rule
->max_eirp
) ||
5201 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
5202 reg_rule
->dfs_cac_ms
))
5203 goto nla_put_failure_rcu
;
5205 nla_nest_end(msg
, nl_reg_rule
);
5209 nla_nest_end(msg
, nl_reg_rules
);
5211 genlmsg_end(msg
, hdr
);
5212 return genlmsg_reply(msg
, info
);
5214 nla_put_failure_rcu
:
5217 genlmsg_cancel(msg
, hdr
);
5223 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5225 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5226 struct nlattr
*nl_reg_rule
;
5227 char *alpha2
= NULL
;
5228 int rem_reg_rules
= 0, r
= 0;
5229 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5230 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
5231 struct ieee80211_regdomain
*rd
= NULL
;
5233 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5236 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5239 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5241 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5242 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5244 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5247 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5251 if (!reg_is_valid_request(alpha2
))
5254 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5255 num_rules
* sizeof(struct ieee80211_reg_rule
);
5257 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5261 rd
->n_reg_rules
= num_rules
;
5262 rd
->alpha2
[0] = alpha2
[0];
5263 rd
->alpha2
[1] = alpha2
[1];
5266 * Disable DFS master mode if the DFS region was
5267 * not supported or known on this kernel.
5269 if (reg_supported_dfs_region(dfs_region
))
5270 rd
->dfs_region
= dfs_region
;
5272 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5274 r
= nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5275 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5279 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5285 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5292 /* set_regdom took ownership */
5300 static int validate_scan_freqs(struct nlattr
*freqs
)
5302 struct nlattr
*attr1
, *attr2
;
5303 int n_channels
= 0, tmp1
, tmp2
;
5305 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5308 * Some hardware has a limited channel list for
5309 * scanning, and it is pretty much nonsensical
5310 * to scan for a channel twice, so disallow that
5311 * and don't require drivers to check that the
5312 * channel list they get isn't longer than what
5313 * they can scan, as long as they can scan all
5314 * the channels they registered at once.
5316 nla_for_each_nested(attr2
, freqs
, tmp2
)
5317 if (attr1
!= attr2
&&
5318 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5325 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5327 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5328 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5329 struct cfg80211_scan_request
*request
;
5330 struct nlattr
*attr
;
5331 struct wiphy
*wiphy
;
5332 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5335 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5338 wiphy
= &rdev
->wiphy
;
5340 if (!rdev
->ops
->scan
)
5343 if (rdev
->scan_req
|| rdev
->scan_msg
) {
5348 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5349 n_channels
= validate_scan_freqs(
5350 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5356 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
5359 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5360 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5363 if (n_ssids
> wiphy
->max_scan_ssids
) {
5368 if (info
->attrs
[NL80211_ATTR_IE
])
5369 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5373 if (ie_len
> wiphy
->max_scan_ie_len
) {
5378 request
= kzalloc(sizeof(*request
)
5379 + sizeof(*request
->ssids
) * n_ssids
5380 + sizeof(*request
->channels
) * n_channels
5381 + ie_len
, GFP_KERNEL
);
5388 request
->ssids
= (void *)&request
->channels
[n_channels
];
5389 request
->n_ssids
= n_ssids
;
5392 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5394 request
->ie
= (void *)(request
->channels
+ n_channels
);
5398 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5399 /* user specified, bail out if channel not found */
5400 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5401 struct ieee80211_channel
*chan
;
5403 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5410 /* ignore disabled channels */
5411 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5414 request
->channels
[i
] = chan
;
5418 enum ieee80211_band band
;
5421 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5423 if (!wiphy
->bands
[band
])
5425 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5426 struct ieee80211_channel
*chan
;
5428 chan
= &wiphy
->bands
[band
]->channels
[j
];
5430 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5433 request
->channels
[i
] = chan
;
5444 request
->n_channels
= i
;
5447 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5448 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5449 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5453 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5454 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5459 if (info
->attrs
[NL80211_ATTR_IE
]) {
5460 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5461 memcpy((void *)request
->ie
,
5462 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5466 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5467 if (wiphy
->bands
[i
])
5469 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5471 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5472 nla_for_each_nested(attr
,
5473 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5475 enum ieee80211_band band
= nla_type(attr
);
5477 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5482 if (!wiphy
->bands
[band
])
5485 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5488 &request
->rates
[band
]);
5494 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5495 request
->flags
= nla_get_u32(
5496 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5497 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5498 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
5505 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5507 request
->wdev
= wdev
;
5508 request
->wiphy
= &rdev
->wiphy
;
5509 request
->scan_start
= jiffies
;
5511 rdev
->scan_req
= request
;
5512 err
= rdev_scan(rdev
, request
);
5515 nl80211_send_scan_start(rdev
, wdev
);
5517 dev_hold(wdev
->netdev
);
5520 rdev
->scan_req
= NULL
;
5528 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5529 struct genl_info
*info
)
5531 struct cfg80211_sched_scan_request
*request
;
5532 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5533 struct net_device
*dev
= info
->user_ptr
[1];
5534 struct nlattr
*attr
;
5535 struct wiphy
*wiphy
;
5536 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5538 enum ieee80211_band band
;
5540 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5541 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
5543 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5544 !rdev
->ops
->sched_scan_start
)
5547 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5550 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5553 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5557 wiphy
= &rdev
->wiphy
;
5559 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5560 n_channels
= validate_scan_freqs(
5561 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5565 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
5568 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5569 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5573 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5577 * First, count the number of 'real' matchsets. Due to an issue with
5578 * the old implementation, matchsets containing only the RSSI attribute
5579 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5580 * RSSI for all matchsets, rather than their own matchset for reporting
5581 * all APs with a strong RSSI. This is needed to be compatible with
5582 * older userspace that treated a matchset with only the RSSI as the
5583 * global RSSI for all other matchsets - if there are other matchsets.
5585 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5586 nla_for_each_nested(attr
,
5587 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5589 struct nlattr
*rssi
;
5591 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5592 nla_data(attr
), nla_len(attr
),
5593 nl80211_match_policy
);
5596 /* add other standalone attributes here */
5597 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
]) {
5601 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5603 default_match_rssi
= nla_get_s32(rssi
);
5607 /* However, if there's no other matchset, add the RSSI one */
5608 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
5611 if (n_match_sets
> wiphy
->max_match_sets
)
5614 if (info
->attrs
[NL80211_ATTR_IE
])
5615 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5619 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5622 if (rdev
->sched_scan_req
) {
5627 request
= kzalloc(sizeof(*request
)
5628 + sizeof(*request
->ssids
) * n_ssids
5629 + sizeof(*request
->match_sets
) * n_match_sets
5630 + sizeof(*request
->channels
) * n_channels
5631 + ie_len
, GFP_KERNEL
);
5638 request
->ssids
= (void *)&request
->channels
[n_channels
];
5639 request
->n_ssids
= n_ssids
;
5642 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5644 request
->ie
= (void *)(request
->channels
+ n_channels
);
5649 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5650 else if (request
->ssids
)
5651 request
->match_sets
=
5652 (void *)(request
->ssids
+ n_ssids
);
5654 request
->match_sets
=
5655 (void *)(request
->channels
+ n_channels
);
5657 request
->n_match_sets
= n_match_sets
;
5660 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5661 /* user specified, bail out if channel not found */
5662 nla_for_each_nested(attr
,
5663 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5665 struct ieee80211_channel
*chan
;
5667 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5674 /* ignore disabled channels */
5675 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5678 request
->channels
[i
] = chan
;
5683 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5685 if (!wiphy
->bands
[band
])
5687 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5688 struct ieee80211_channel
*chan
;
5690 chan
= &wiphy
->bands
[band
]->channels
[j
];
5692 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5695 request
->channels
[i
] = chan
;
5706 request
->n_channels
= i
;
5709 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5710 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5712 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5716 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5717 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5724 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5725 nla_for_each_nested(attr
,
5726 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5728 struct nlattr
*ssid
, *rssi
;
5730 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5731 nla_data(attr
), nla_len(attr
),
5732 nl80211_match_policy
);
5735 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5737 if (WARN_ON(i
>= n_match_sets
)) {
5738 /* this indicates a programming error,
5739 * the loop above should have verified
5746 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5750 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5751 nla_data(ssid
), nla_len(ssid
));
5752 request
->match_sets
[i
].ssid
.ssid_len
=
5754 /* special attribute - old implemenation w/a */
5755 request
->match_sets
[i
].rssi_thold
=
5757 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5759 request
->match_sets
[i
].rssi_thold
=
5765 /* there was no other matchset, so the RSSI one is alone */
5766 if (i
== 0 && n_match_sets
)
5767 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
5769 request
->min_rssi_thold
= INT_MAX
;
5770 for (i
= 0; i
< n_match_sets
; i
++)
5771 request
->min_rssi_thold
=
5772 min(request
->match_sets
[i
].rssi_thold
,
5773 request
->min_rssi_thold
);
5775 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
5779 request
->ie_len
= ie_len
;
5780 memcpy((void *)request
->ie
,
5781 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5785 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5786 request
->flags
= nla_get_u32(
5787 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5788 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5789 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
5796 request
->wiphy
= &rdev
->wiphy
;
5797 request
->interval
= interval
;
5798 request
->scan_start
= jiffies
;
5800 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5802 rdev
->sched_scan_req
= request
;
5803 nl80211_send_sched_scan(rdev
, dev
,
5804 NL80211_CMD_START_SCHED_SCAN
);
5814 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5815 struct genl_info
*info
)
5817 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5819 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5820 !rdev
->ops
->sched_scan_stop
)
5823 return __cfg80211_stop_sched_scan(rdev
, false);
5826 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5827 struct genl_info
*info
)
5829 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5830 struct net_device
*dev
= info
->user_ptr
[1];
5831 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5832 struct cfg80211_chan_def chandef
;
5833 enum nl80211_dfs_regions dfs_region
;
5834 unsigned int cac_time_ms
;
5837 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
5838 if (dfs_region
== NL80211_DFS_UNSET
)
5841 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5845 if (netif_carrier_ok(dev
))
5848 if (wdev
->cac_started
)
5851 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
5859 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
5862 if (!rdev
->ops
->start_radar_detection
)
5865 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
5866 if (WARN_ON(!cac_time_ms
))
5867 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
5869 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
,
5872 wdev
->chandef
= chandef
;
5873 wdev
->cac_started
= true;
5874 wdev
->cac_start_time
= jiffies
;
5875 wdev
->cac_time_ms
= cac_time_ms
;
5880 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
5882 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5883 struct net_device
*dev
= info
->user_ptr
[1];
5884 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5885 struct cfg80211_csa_settings params
;
5886 /* csa_attrs is defined static to avoid waste of stack size - this
5887 * function is called under RTNL lock, so this should not be a problem.
5889 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
5890 u8 radar_detect_width
= 0;
5892 bool need_new_beacon
= false;
5895 if (!rdev
->ops
->channel_switch
||
5896 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
5899 switch (dev
->ieee80211_ptr
->iftype
) {
5900 case NL80211_IFTYPE_AP
:
5901 case NL80211_IFTYPE_P2P_GO
:
5902 need_new_beacon
= true;
5904 /* useless if AP is not running */
5905 if (!wdev
->beacon_interval
)
5908 case NL80211_IFTYPE_ADHOC
:
5909 if (!wdev
->ssid_len
)
5912 case NL80211_IFTYPE_MESH_POINT
:
5913 if (!wdev
->mesh_id_len
)
5920 memset(¶ms
, 0, sizeof(params
));
5922 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5923 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
5926 /* only important for AP, IBSS and mesh create IEs internally */
5927 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
5930 params
.count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
5932 if (!need_new_beacon
)
5935 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
5939 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
5940 info
->attrs
[NL80211_ATTR_CSA_IES
],
5945 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
5949 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
5952 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
5953 if (!len
|| (len
% sizeof(u16
)))
5956 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
5957 if (rdev
->wiphy
.max_num_csa_counters
&&
5958 (params
.n_counter_offsets_beacon
>
5959 rdev
->wiphy
.max_num_csa_counters
))
5962 params
.counter_offsets_beacon
=
5963 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
5965 /* sanity checks - counters should fit and be the same */
5966 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
5967 u16 offset
= params
.counter_offsets_beacon
[i
];
5969 if (offset
>= params
.beacon_csa
.tail_len
)
5972 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
5976 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
5977 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
5978 if (!len
|| (len
% sizeof(u16
)))
5981 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
5982 if (rdev
->wiphy
.max_num_csa_counters
&&
5983 (params
.n_counter_offsets_beacon
>
5984 rdev
->wiphy
.max_num_csa_counters
))
5987 params
.counter_offsets_presp
=
5988 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
5990 /* sanity checks - counters should fit and be the same */
5991 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
5992 u16 offset
= params
.counter_offsets_presp
[i
];
5994 if (offset
>= params
.beacon_csa
.probe_resp_len
)
5997 if (params
.beacon_csa
.probe_resp
[offset
] !=
6004 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
6008 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
,
6012 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
6019 radar_detect_width
= BIT(params
.chandef
.width
);
6020 params
.radar_required
= true;
6023 /* TODO: I left this here for now. With channel switch, the
6024 * verification is a bit more complicated, because we only do
6025 * it later when the channel switch really happens.
6027 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
6028 params
.chandef
.chan
,
6030 radar_detect_width
);
6034 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
6035 params
.block_tx
= true;
6038 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
6044 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6046 struct cfg80211_registered_device
*rdev
,
6047 struct wireless_dev
*wdev
,
6048 struct cfg80211_internal_bss
*intbss
)
6050 struct cfg80211_bss
*res
= &intbss
->pub
;
6051 const struct cfg80211_bss_ies
*ies
;
6056 ASSERT_WDEV_LOCK(wdev
);
6058 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6059 NL80211_CMD_NEW_SCAN_RESULTS
);
6063 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
6065 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
6066 goto nla_put_failure
;
6068 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
6069 goto nla_put_failure
;
6070 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
6071 goto nla_put_failure
;
6073 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
6075 goto nla_put_failure
;
6076 if ((!is_zero_ether_addr(res
->bssid
) &&
6077 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
6078 goto nla_put_failure
;
6081 ies
= rcu_dereference(res
->ies
);
6083 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
6084 goto fail_unlock_rcu
;
6086 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
6087 ies
->len
, ies
->data
))
6088 goto fail_unlock_rcu
;
6090 ies
= rcu_dereference(res
->beacon_ies
);
6092 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
6093 goto fail_unlock_rcu
;
6094 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
6095 ies
->len
, ies
->data
))
6096 goto fail_unlock_rcu
;
6100 if (res
->beacon_interval
&&
6101 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
6102 goto nla_put_failure
;
6103 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
6104 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
6105 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
6106 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
6107 jiffies_to_msecs(jiffies
- intbss
->ts
)))
6108 goto nla_put_failure
;
6110 switch (rdev
->wiphy
.signal_type
) {
6111 case CFG80211_SIGNAL_TYPE_MBM
:
6112 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
6113 goto nla_put_failure
;
6115 case CFG80211_SIGNAL_TYPE_UNSPEC
:
6116 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
6117 goto nla_put_failure
;
6123 switch (wdev
->iftype
) {
6124 case NL80211_IFTYPE_P2P_CLIENT
:
6125 case NL80211_IFTYPE_STATION
:
6126 if (intbss
== wdev
->current_bss
&&
6127 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6128 NL80211_BSS_STATUS_ASSOCIATED
))
6129 goto nla_put_failure
;
6131 case NL80211_IFTYPE_ADHOC
:
6132 if (intbss
== wdev
->current_bss
&&
6133 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6134 NL80211_BSS_STATUS_IBSS_JOINED
))
6135 goto nla_put_failure
;
6141 nla_nest_end(msg
, bss
);
6143 return genlmsg_end(msg
, hdr
);
6148 genlmsg_cancel(msg
, hdr
);
6152 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6154 struct cfg80211_registered_device
*rdev
;
6155 struct cfg80211_internal_bss
*scan
;
6156 struct wireless_dev
*wdev
;
6157 int start
= cb
->args
[2], idx
= 0;
6160 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6165 spin_lock_bh(&rdev
->bss_lock
);
6166 cfg80211_bss_expire(rdev
);
6168 cb
->seq
= rdev
->bss_generation
;
6170 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
6173 if (nl80211_send_bss(skb
, cb
,
6174 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6175 rdev
, wdev
, scan
) < 0) {
6181 spin_unlock_bh(&rdev
->bss_lock
);
6185 nl80211_finish_wdev_dump(rdev
);
6190 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
6191 int flags
, struct net_device
*dev
,
6192 struct survey_info
*survey
)
6195 struct nlattr
*infoattr
;
6197 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
6198 NL80211_CMD_NEW_SURVEY_RESULTS
);
6202 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
6203 goto nla_put_failure
;
6205 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
6207 goto nla_put_failure
;
6209 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
6210 survey
->channel
->center_freq
))
6211 goto nla_put_failure
;
6213 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
6214 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
6215 goto nla_put_failure
;
6216 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
6217 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
6218 goto nla_put_failure
;
6219 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
6220 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
6221 survey
->channel_time
))
6222 goto nla_put_failure
;
6223 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
6224 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
6225 survey
->channel_time_busy
))
6226 goto nla_put_failure
;
6227 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
6228 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
6229 survey
->channel_time_ext_busy
))
6230 goto nla_put_failure
;
6231 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
6232 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
6233 survey
->channel_time_rx
))
6234 goto nla_put_failure
;
6235 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
6236 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
6237 survey
->channel_time_tx
))
6238 goto nla_put_failure
;
6240 nla_nest_end(msg
, infoattr
);
6242 return genlmsg_end(msg
, hdr
);
6245 genlmsg_cancel(msg
, hdr
);
6249 static int nl80211_dump_survey(struct sk_buff
*skb
,
6250 struct netlink_callback
*cb
)
6252 struct survey_info survey
;
6253 struct cfg80211_registered_device
*rdev
;
6254 struct wireless_dev
*wdev
;
6255 int survey_idx
= cb
->args
[2];
6258 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6262 if (!wdev
->netdev
) {
6267 if (!rdev
->ops
->dump_survey
) {
6273 struct ieee80211_channel
*chan
;
6275 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
6281 /* Survey without a channel doesn't make sense */
6282 if (!survey
.channel
) {
6287 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6288 survey
.channel
->center_freq
);
6289 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
6294 if (nl80211_send_survey(skb
,
6295 NETLINK_CB(cb
->skb
).portid
,
6296 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6297 wdev
->netdev
, &survey
) < 0)
6303 cb
->args
[2] = survey_idx
;
6306 nl80211_finish_wdev_dump(rdev
);
6310 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
6312 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
6313 NL80211_WPA_VERSION_2
));
6316 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6318 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6319 struct net_device
*dev
= info
->user_ptr
[1];
6320 struct ieee80211_channel
*chan
;
6321 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
6322 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
6323 enum nl80211_auth_type auth_type
;
6324 struct key_parse key
;
6325 bool local_state_change
;
6327 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6330 if (!info
->attrs
[NL80211_ATTR_MAC
])
6333 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
6336 if (!info
->attrs
[NL80211_ATTR_SSID
])
6339 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6342 err
= nl80211_parse_key(info
, &key
);
6347 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
6349 if (!key
.p
.key
|| !key
.p
.key_len
)
6351 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
6352 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
6353 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
6354 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
6366 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
6367 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
6376 if (!rdev
->ops
->auth
)
6379 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6380 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6383 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6384 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
6385 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6389 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6390 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6392 if (info
->attrs
[NL80211_ATTR_IE
]) {
6393 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6394 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6397 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6398 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
6401 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
6402 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
6405 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
6406 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
6408 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
6409 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
6410 /* need to include at least Auth Transaction and Status Code */
6411 if (sae_data_len
< 4)
6415 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6418 * Since we no longer track auth state, ignore
6419 * requests to only change local state.
6421 if (local_state_change
)
6424 wdev_lock(dev
->ieee80211_ptr
);
6425 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
6426 ssid
, ssid_len
, ie
, ie_len
,
6427 key
.p
.key
, key
.p
.key_len
, key
.idx
,
6428 sae_data
, sae_data_len
);
6429 wdev_unlock(dev
->ieee80211_ptr
);
6433 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
6434 struct genl_info
*info
,
6435 struct cfg80211_crypto_settings
*settings
,
6438 memset(settings
, 0, sizeof(*settings
));
6440 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6442 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6444 proto
= nla_get_u16(
6445 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6446 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6447 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6450 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6451 settings
->control_port_no_encrypt
= true;
6453 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6455 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6459 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6460 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6461 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6463 if (len
% sizeof(u32
))
6466 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6469 memcpy(settings
->ciphers_pairwise
, data
, len
);
6471 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6472 if (!cfg80211_supported_cipher_suite(
6474 settings
->ciphers_pairwise
[i
]))
6478 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6479 settings
->cipher_group
=
6480 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6481 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6482 settings
->cipher_group
))
6486 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6487 settings
->wpa_versions
=
6488 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6489 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6493 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6497 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6498 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6499 settings
->n_akm_suites
= len
/ sizeof(u32
);
6501 if (len
% sizeof(u32
))
6504 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6507 memcpy(settings
->akm_suites
, data
, len
);
6513 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6515 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6516 struct net_device
*dev
= info
->user_ptr
[1];
6517 struct ieee80211_channel
*chan
;
6518 struct cfg80211_assoc_request req
= {};
6519 const u8
*bssid
, *ssid
;
6520 int err
, ssid_len
= 0;
6522 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6525 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6526 !info
->attrs
[NL80211_ATTR_SSID
] ||
6527 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6530 if (!rdev
->ops
->assoc
)
6533 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6534 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6537 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6539 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
6540 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6544 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6545 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6547 if (info
->attrs
[NL80211_ATTR_IE
]) {
6548 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6549 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6552 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6553 enum nl80211_mfp mfp
=
6554 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6555 if (mfp
== NL80211_MFP_REQUIRED
)
6557 else if (mfp
!= NL80211_MFP_NO
)
6561 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6562 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6564 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6565 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6567 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6568 memcpy(&req
.ht_capa_mask
,
6569 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6570 sizeof(req
.ht_capa_mask
));
6572 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6573 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6575 memcpy(&req
.ht_capa
,
6576 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6577 sizeof(req
.ht_capa
));
6580 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6581 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6583 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6584 memcpy(&req
.vht_capa_mask
,
6585 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6586 sizeof(req
.vht_capa_mask
));
6588 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6589 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6591 memcpy(&req
.vht_capa
,
6592 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6593 sizeof(req
.vht_capa
));
6596 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6598 wdev_lock(dev
->ieee80211_ptr
);
6599 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6600 ssid
, ssid_len
, &req
);
6601 wdev_unlock(dev
->ieee80211_ptr
);
6607 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6609 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6610 struct net_device
*dev
= info
->user_ptr
[1];
6611 const u8
*ie
= NULL
, *bssid
;
6612 int ie_len
= 0, err
;
6614 bool local_state_change
;
6616 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6619 if (!info
->attrs
[NL80211_ATTR_MAC
])
6622 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6625 if (!rdev
->ops
->deauth
)
6628 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6629 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6632 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6634 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6635 if (reason_code
== 0) {
6636 /* Reason Code 0 is reserved */
6640 if (info
->attrs
[NL80211_ATTR_IE
]) {
6641 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6642 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6645 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6647 wdev_lock(dev
->ieee80211_ptr
);
6648 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6649 local_state_change
);
6650 wdev_unlock(dev
->ieee80211_ptr
);
6654 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6656 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6657 struct net_device
*dev
= info
->user_ptr
[1];
6658 const u8
*ie
= NULL
, *bssid
;
6659 int ie_len
= 0, err
;
6661 bool local_state_change
;
6663 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6666 if (!info
->attrs
[NL80211_ATTR_MAC
])
6669 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6672 if (!rdev
->ops
->disassoc
)
6675 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6676 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6679 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6681 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6682 if (reason_code
== 0) {
6683 /* Reason Code 0 is reserved */
6687 if (info
->attrs
[NL80211_ATTR_IE
]) {
6688 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6689 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6692 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6694 wdev_lock(dev
->ieee80211_ptr
);
6695 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6696 local_state_change
);
6697 wdev_unlock(dev
->ieee80211_ptr
);
6702 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6703 int mcast_rate
[IEEE80211_NUM_BANDS
],
6706 struct wiphy
*wiphy
= &rdev
->wiphy
;
6710 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6711 struct ieee80211_supported_band
*sband
;
6713 sband
= wiphy
->bands
[band
];
6717 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6718 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6719 mcast_rate
[band
] = i
+ 1;
6729 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6731 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6732 struct net_device
*dev
= info
->user_ptr
[1];
6733 struct cfg80211_ibss_params ibss
;
6734 struct wiphy
*wiphy
;
6735 struct cfg80211_cached_keys
*connkeys
= NULL
;
6738 memset(&ibss
, 0, sizeof(ibss
));
6740 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6743 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6744 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6747 ibss
.beacon_interval
= 100;
6749 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6750 ibss
.beacon_interval
=
6751 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6752 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6756 if (!rdev
->ops
->join_ibss
)
6759 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6762 wiphy
= &rdev
->wiphy
;
6764 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6765 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6767 if (!is_valid_ether_addr(ibss
.bssid
))
6770 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6771 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6773 if (info
->attrs
[NL80211_ATTR_IE
]) {
6774 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6775 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6778 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6782 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
6783 NL80211_IFTYPE_ADHOC
))
6786 switch (ibss
.chandef
.width
) {
6787 case NL80211_CHAN_WIDTH_5
:
6788 case NL80211_CHAN_WIDTH_10
:
6789 case NL80211_CHAN_WIDTH_20_NOHT
:
6791 case NL80211_CHAN_WIDTH_20
:
6792 case NL80211_CHAN_WIDTH_40
:
6793 if (rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
)
6799 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6800 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6802 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6804 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6806 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6807 struct ieee80211_supported_band
*sband
=
6808 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6810 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6816 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6817 memcpy(&ibss
.ht_capa_mask
,
6818 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6819 sizeof(ibss
.ht_capa_mask
));
6821 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6822 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6824 memcpy(&ibss
.ht_capa
,
6825 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6826 sizeof(ibss
.ht_capa
));
6829 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6830 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6831 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6834 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6837 connkeys
= nl80211_parse_connkeys(rdev
,
6838 info
->attrs
[NL80211_ATTR_KEYS
],
6840 if (IS_ERR(connkeys
))
6841 return PTR_ERR(connkeys
);
6843 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6851 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6853 ibss
.userspace_handles_dfs
=
6854 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
6856 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6862 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6864 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6865 struct net_device
*dev
= info
->user_ptr
[1];
6867 if (!rdev
->ops
->leave_ibss
)
6870 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6873 return cfg80211_leave_ibss(rdev
, dev
, false);
6876 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6878 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6879 struct net_device
*dev
= info
->user_ptr
[1];
6880 int mcast_rate
[IEEE80211_NUM_BANDS
];
6884 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6885 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6888 if (!rdev
->ops
->set_mcast_rate
)
6891 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6893 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6896 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6897 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6900 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6905 static struct sk_buff
*
6906 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
6907 int approxlen
, u32 portid
, u32 seq
,
6908 enum nl80211_commands cmd
,
6909 enum nl80211_attrs attr
,
6910 const struct nl80211_vendor_cmd_info
*info
,
6913 struct sk_buff
*skb
;
6915 struct nlattr
*data
;
6917 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6921 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
6927 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6928 goto nla_put_failure
;
6931 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
6933 goto nla_put_failure
;
6934 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
6936 goto nla_put_failure
;
6939 data
= nla_nest_start(skb
, attr
);
6941 ((void **)skb
->cb
)[0] = rdev
;
6942 ((void **)skb
->cb
)[1] = hdr
;
6943 ((void **)skb
->cb
)[2] = data
;
6952 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
6953 enum nl80211_commands cmd
,
6954 enum nl80211_attrs attr
,
6955 int vendor_event_idx
,
6956 int approxlen
, gfp_t gfp
)
6958 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
6959 const struct nl80211_vendor_cmd_info
*info
;
6962 case NL80211_CMD_TESTMODE
:
6963 if (WARN_ON(vendor_event_idx
!= -1))
6967 case NL80211_CMD_VENDOR
:
6968 if (WARN_ON(vendor_event_idx
< 0 ||
6969 vendor_event_idx
>= wiphy
->n_vendor_events
))
6971 info
= &wiphy
->vendor_events
[vendor_event_idx
];
6978 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
, 0, 0,
6979 cmd
, attr
, info
, gfp
);
6981 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
6983 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
6985 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6986 void *hdr
= ((void **)skb
->cb
)[1];
6987 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6988 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
6990 /* clear CB data for netlink core to own from now on */
6991 memset(skb
->cb
, 0, sizeof(skb
->cb
));
6993 nla_nest_end(skb
, data
);
6994 genlmsg_end(skb
, hdr
);
6996 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
6997 mcgrp
= NL80211_MCGRP_VENDOR
;
6999 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
7002 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
7004 #ifdef CONFIG_NL80211_TESTMODE
7005 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
7007 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7008 struct wireless_dev
*wdev
=
7009 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
7012 if (!rdev
->ops
->testmode_cmd
)
7016 err
= PTR_ERR(wdev
);
7020 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
7024 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
7027 rdev
->cur_cmd_info
= info
;
7028 err
= rdev_testmode_cmd(rdev
, wdev
,
7029 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
7030 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
7031 rdev
->cur_cmd_info
= NULL
;
7036 static int nl80211_testmode_dump(struct sk_buff
*skb
,
7037 struct netlink_callback
*cb
)
7039 struct cfg80211_registered_device
*rdev
;
7049 * 0 is a valid index, but not valid for args[0],
7050 * so we need to offset by 1.
7052 phy_idx
= cb
->args
[0] - 1;
7054 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
7055 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
7060 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
7061 nl80211_fam
.attrbuf
);
7063 err
= PTR_ERR(rdev
);
7066 phy_idx
= rdev
->wiphy_idx
;
7069 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
7071 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
7075 data
= nla_data((void *)cb
->args
[1]);
7076 data_len
= nla_len((void *)cb
->args
[1]);
7079 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
7085 if (!rdev
->ops
->testmode_dump
) {
7091 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
7092 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7093 NL80211_CMD_TESTMODE
);
7094 struct nlattr
*tmdata
;
7099 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
7100 genlmsg_cancel(skb
, hdr
);
7104 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
7106 genlmsg_cancel(skb
, hdr
);
7109 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
7110 nla_nest_end(skb
, tmdata
);
7112 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
7113 genlmsg_cancel(skb
, hdr
);
7116 genlmsg_cancel(skb
, hdr
);
7120 genlmsg_end(skb
, hdr
);
7125 cb
->args
[0] = phy_idx
+ 1;
7132 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
7134 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7135 struct net_device
*dev
= info
->user_ptr
[1];
7136 struct cfg80211_connect_params connect
;
7137 struct wiphy
*wiphy
;
7138 struct cfg80211_cached_keys
*connkeys
= NULL
;
7141 memset(&connect
, 0, sizeof(connect
));
7143 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7146 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7147 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7150 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
7152 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7153 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
7154 NL80211_CMD_CONNECT
))
7157 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
7159 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
7161 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
7162 NL80211_MAX_NR_CIPHER_SUITES
);
7166 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7167 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7170 wiphy
= &rdev
->wiphy
;
7172 connect
.bg_scan_period
= -1;
7173 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
7174 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
7175 connect
.bg_scan_period
=
7176 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
7179 if (info
->attrs
[NL80211_ATTR_MAC
])
7180 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7181 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
7182 connect
.bssid_hint
=
7183 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
7184 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7185 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7187 if (info
->attrs
[NL80211_ATTR_IE
]) {
7188 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7189 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7192 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7193 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7194 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
7195 connect
.mfp
!= NL80211_MFP_NO
)
7198 connect
.mfp
= NL80211_MFP_NO
;
7201 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7202 connect
.channel
= nl80211_get_valid_chan(
7203 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7204 if (!connect
.channel
)
7206 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
7207 connect
.channel_hint
= nl80211_get_valid_chan(
7208 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
7209 if (!connect
.channel_hint
)
7213 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7214 connkeys
= nl80211_parse_connkeys(rdev
,
7215 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
7216 if (IS_ERR(connkeys
))
7217 return PTR_ERR(connkeys
);
7220 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7221 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
7223 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7224 memcpy(&connect
.ht_capa_mask
,
7225 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7226 sizeof(connect
.ht_capa_mask
));
7228 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7229 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
7233 memcpy(&connect
.ht_capa
,
7234 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7235 sizeof(connect
.ht_capa
));
7238 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7239 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7241 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7242 memcpy(&connect
.vht_capa_mask
,
7243 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7244 sizeof(connect
.vht_capa_mask
));
7246 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7247 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
7251 memcpy(&connect
.vht_capa
,
7252 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7253 sizeof(connect
.vht_capa
));
7256 wdev_lock(dev
->ieee80211_ptr
);
7257 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
7258 wdev_unlock(dev
->ieee80211_ptr
);
7264 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
7266 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7267 struct net_device
*dev
= info
->user_ptr
[1];
7271 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7272 reason
= WLAN_REASON_DEAUTH_LEAVING
;
7274 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7279 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7280 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7283 wdev_lock(dev
->ieee80211_ptr
);
7284 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
7285 wdev_unlock(dev
->ieee80211_ptr
);
7289 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
7291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7296 if (!info
->attrs
[NL80211_ATTR_PID
])
7299 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
7301 net
= get_net_ns_by_pid(pid
);
7303 return PTR_ERR(net
);
7307 /* check if anything to do */
7308 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
7309 err
= cfg80211_switch_netns(rdev
, net
);
7315 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
7317 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7318 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
7319 struct cfg80211_pmksa
*pmksa
) = NULL
;
7320 struct net_device
*dev
= info
->user_ptr
[1];
7321 struct cfg80211_pmksa pmksa
;
7323 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
7325 if (!info
->attrs
[NL80211_ATTR_MAC
])
7328 if (!info
->attrs
[NL80211_ATTR_PMKID
])
7331 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
7332 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7334 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7335 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7338 switch (info
->genlhdr
->cmd
) {
7339 case NL80211_CMD_SET_PMKSA
:
7340 rdev_ops
= rdev
->ops
->set_pmksa
;
7342 case NL80211_CMD_DEL_PMKSA
:
7343 rdev_ops
= rdev
->ops
->del_pmksa
;
7353 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
7356 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
7358 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7359 struct net_device
*dev
= info
->user_ptr
[1];
7361 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7362 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7365 if (!rdev
->ops
->flush_pmksa
)
7368 return rdev_flush_pmksa(rdev
, dev
);
7371 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7373 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7374 struct net_device
*dev
= info
->user_ptr
[1];
7375 u8 action_code
, dialog_token
;
7376 u32 peer_capability
= 0;
7380 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
7381 !rdev
->ops
->tdls_mgmt
)
7384 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
7385 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
7386 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
7387 !info
->attrs
[NL80211_ATTR_IE
] ||
7388 !info
->attrs
[NL80211_ATTR_MAC
])
7391 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7392 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
7393 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
7394 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
7395 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
7397 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
7399 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
7400 dialog_token
, status_code
, peer_capability
,
7401 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
7402 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
7405 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
7407 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7408 struct net_device
*dev
= info
->user_ptr
[1];
7409 enum nl80211_tdls_operation operation
;
7412 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
7413 !rdev
->ops
->tdls_oper
)
7416 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
7417 !info
->attrs
[NL80211_ATTR_MAC
])
7420 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
7421 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7423 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
7426 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
7427 struct genl_info
*info
)
7429 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7430 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7431 struct cfg80211_chan_def chandef
;
7432 struct sk_buff
*msg
;
7438 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7439 !info
->attrs
[NL80211_ATTR_DURATION
])
7442 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7444 if (!rdev
->ops
->remain_on_channel
||
7445 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
7449 * We should be on that channel for at least a minimum amount of
7450 * time (10ms) but no longer than the driver supports.
7452 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7453 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
7456 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7460 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7464 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7465 NL80211_CMD_REMAIN_ON_CHANNEL
);
7471 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
7477 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7478 goto nla_put_failure
;
7480 genlmsg_end(msg
, hdr
);
7482 return genlmsg_reply(msg
, info
);
7491 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7492 struct genl_info
*info
)
7494 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7495 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7498 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7501 if (!rdev
->ops
->cancel_remain_on_channel
)
7504 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7506 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7509 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7510 u8
*rates
, u8 rates_len
)
7515 for (i
= 0; i
< rates_len
; i
++) {
7516 int rate
= (rates
[i
] & 0x7f) * 5;
7518 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7519 struct ieee80211_rate
*srate
=
7520 &sband
->bitrates
[ridx
];
7521 if (rate
== srate
->bitrate
) {
7526 if (ridx
== sband
->n_bitrates
)
7527 return 0; /* rate not found */
7533 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7534 u8
*rates
, u8 rates_len
,
7535 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7539 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7541 for (i
= 0; i
< rates_len
; i
++) {
7544 ridx
= rates
[i
] / 8;
7545 rbit
= BIT(rates
[i
] % 8);
7547 /* check validity */
7548 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7551 /* check availability */
7552 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7561 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
7565 switch (vht_mcs_map
) {
7566 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
7568 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
7571 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
7574 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
7584 static void vht_build_mcs_mask(u16 vht_mcs_map
,
7585 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
7589 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
7590 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
7595 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
7596 struct nl80211_txrate_vht
*txrate
,
7597 u16 mcs
[NL80211_VHT_NSS_MAX
])
7599 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
7600 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
7603 if (!sband
->vht_cap
.vht_supported
)
7606 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
7608 /* Build vht_mcs_mask from VHT capabilities */
7609 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
7611 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
7612 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
7613 mcs
[i
] = txrate
->mcs
[i
];
7621 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7622 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7623 .len
= NL80211_MAX_SUPP_RATES
},
7624 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
7625 .len
= NL80211_MAX_SUPP_HT_RATES
},
7626 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
7627 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
7630 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7631 struct genl_info
*info
)
7633 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7634 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7635 struct cfg80211_bitrate_mask mask
;
7637 struct net_device
*dev
= info
->user_ptr
[1];
7638 struct nlattr
*tx_rates
;
7639 struct ieee80211_supported_band
*sband
;
7642 if (!rdev
->ops
->set_bitrate_mask
)
7645 memset(&mask
, 0, sizeof(mask
));
7646 /* Default to all rates enabled */
7647 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7648 sband
= rdev
->wiphy
.bands
[i
];
7653 mask
.control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
7654 memcpy(mask
.control
[i
].ht_mcs
,
7655 sband
->ht_cap
.mcs
.rx_mask
,
7656 sizeof(mask
.control
[i
].ht_mcs
));
7658 if (!sband
->vht_cap
.vht_supported
)
7661 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
7662 vht_build_mcs_mask(vht_tx_mcs_map
, mask
.control
[i
].vht_mcs
);
7665 /* if no rates are given set it back to the defaults */
7666 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
7670 * The nested attribute uses enum nl80211_band as the index. This maps
7671 * directly to the enum ieee80211_band values used in cfg80211.
7673 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7674 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
7675 enum ieee80211_band band
= nla_type(tx_rates
);
7678 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7680 sband
= rdev
->wiphy
.bands
[band
];
7683 err
= nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7684 nla_len(tx_rates
), nl80211_txattr_policy
);
7687 if (tb
[NL80211_TXRATE_LEGACY
]) {
7688 mask
.control
[band
].legacy
= rateset_to_mask(
7690 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7691 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7692 if ((mask
.control
[band
].legacy
== 0) &&
7693 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7696 if (tb
[NL80211_TXRATE_HT
]) {
7697 if (!ht_rateset_to_mask(
7699 nla_data(tb
[NL80211_TXRATE_HT
]),
7700 nla_len(tb
[NL80211_TXRATE_HT
]),
7701 mask
.control
[band
].ht_mcs
))
7704 if (tb
[NL80211_TXRATE_VHT
]) {
7705 if (!vht_set_mcs_mask(
7707 nla_data(tb
[NL80211_TXRATE_VHT
]),
7708 mask
.control
[band
].vht_mcs
))
7711 if (tb
[NL80211_TXRATE_GI
]) {
7712 mask
.control
[band
].gi
=
7713 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
7714 if (mask
.control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
7718 if (mask
.control
[band
].legacy
== 0) {
7719 /* don't allow empty legacy rates if HT or VHT
7720 * are not even supported.
7722 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
7723 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
7726 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7727 if (mask
.control
[band
].ht_mcs
[i
])
7730 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
7731 if (mask
.control
[band
].vht_mcs
[i
])
7734 /* legacy and mcs rates may not be both empty */
7740 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7743 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7745 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7746 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7747 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7749 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7752 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7753 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7755 switch (wdev
->iftype
) {
7756 case NL80211_IFTYPE_STATION
:
7757 case NL80211_IFTYPE_ADHOC
:
7758 case NL80211_IFTYPE_P2P_CLIENT
:
7759 case NL80211_IFTYPE_AP
:
7760 case NL80211_IFTYPE_AP_VLAN
:
7761 case NL80211_IFTYPE_MESH_POINT
:
7762 case NL80211_IFTYPE_P2P_GO
:
7763 case NL80211_IFTYPE_P2P_DEVICE
:
7769 /* not much point in registering if we can't reply */
7770 if (!rdev
->ops
->mgmt_tx
)
7773 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7774 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7775 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7778 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7780 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7781 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7782 struct cfg80211_chan_def chandef
;
7786 struct sk_buff
*msg
= NULL
;
7787 struct cfg80211_mgmt_tx_params params
= {
7788 .dont_wait_for_ack
=
7789 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
7792 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7795 if (!rdev
->ops
->mgmt_tx
)
7798 switch (wdev
->iftype
) {
7799 case NL80211_IFTYPE_P2P_DEVICE
:
7800 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7802 case NL80211_IFTYPE_STATION
:
7803 case NL80211_IFTYPE_ADHOC
:
7804 case NL80211_IFTYPE_P2P_CLIENT
:
7805 case NL80211_IFTYPE_AP
:
7806 case NL80211_IFTYPE_AP_VLAN
:
7807 case NL80211_IFTYPE_MESH_POINT
:
7808 case NL80211_IFTYPE_P2P_GO
:
7814 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7815 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7817 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7820 * We should wait on the channel for at least a minimum amount
7821 * of time (10ms) but no longer than the driver supports.
7823 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7824 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7829 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7831 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7834 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7836 /* get the channel if any has been specified, otherwise pass NULL to
7837 * the driver. The latter will use the current one
7839 chandef
.chan
= NULL
;
7840 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7841 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7846 if (!chandef
.chan
&& params
.offchan
)
7849 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
7850 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
7852 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
7853 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
7856 if (len
% sizeof(u16
))
7859 params
.n_csa_offsets
= len
/ sizeof(u16
);
7860 params
.csa_offsets
=
7861 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
7863 /* check that all the offsets fit the frame */
7864 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
7865 if (params
.csa_offsets
[i
] >= params
.len
)
7870 if (!params
.dont_wait_for_ack
) {
7871 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7875 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7883 params
.chan
= chandef
.chan
;
7884 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
7889 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7890 goto nla_put_failure
;
7892 genlmsg_end(msg
, hdr
);
7893 return genlmsg_reply(msg
, info
);
7905 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7907 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7908 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7911 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7914 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7917 switch (wdev
->iftype
) {
7918 case NL80211_IFTYPE_STATION
:
7919 case NL80211_IFTYPE_ADHOC
:
7920 case NL80211_IFTYPE_P2P_CLIENT
:
7921 case NL80211_IFTYPE_AP
:
7922 case NL80211_IFTYPE_AP_VLAN
:
7923 case NL80211_IFTYPE_P2P_GO
:
7924 case NL80211_IFTYPE_P2P_DEVICE
:
7930 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7932 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7935 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7937 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7938 struct wireless_dev
*wdev
;
7939 struct net_device
*dev
= info
->user_ptr
[1];
7944 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7947 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7949 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7952 wdev
= dev
->ieee80211_ptr
;
7954 if (!rdev
->ops
->set_power_mgmt
)
7957 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7959 if (state
== wdev
->ps
)
7962 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7968 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7970 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7971 enum nl80211_ps_state ps_state
;
7972 struct wireless_dev
*wdev
;
7973 struct net_device
*dev
= info
->user_ptr
[1];
7974 struct sk_buff
*msg
;
7978 wdev
= dev
->ieee80211_ptr
;
7980 if (!rdev
->ops
->set_power_mgmt
)
7983 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7987 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7988 NL80211_CMD_GET_POWER_SAVE
);
7995 ps_state
= NL80211_PS_ENABLED
;
7997 ps_state
= NL80211_PS_DISABLED
;
7999 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
8000 goto nla_put_failure
;
8002 genlmsg_end(msg
, hdr
);
8003 return genlmsg_reply(msg
, info
);
8012 static const struct nla_policy
8013 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
8014 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
8015 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
8016 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
8017 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
8018 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
8019 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
8022 static int nl80211_set_cqm_txe(struct genl_info
*info
,
8023 u32 rate
, u32 pkts
, u32 intvl
)
8025 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8026 struct net_device
*dev
= info
->user_ptr
[1];
8027 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8029 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
8032 if (!rdev
->ops
->set_cqm_txe_config
)
8035 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8036 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8039 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
8042 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
8043 s32 threshold
, u32 hysteresis
)
8045 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8046 struct net_device
*dev
= info
->user_ptr
[1];
8047 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8052 /* disabling - hysteresis should also be zero then */
8056 if (!rdev
->ops
->set_cqm_rssi_config
)
8059 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8060 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8063 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
8066 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
8068 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
8072 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
8076 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
8077 nl80211_attr_cqm_policy
);
8081 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
8082 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
8083 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
8084 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
8086 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
8089 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
8090 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
8091 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
8092 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
8093 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
8094 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
8096 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
8102 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8104 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8105 struct net_device
*dev
= info
->user_ptr
[1];
8106 struct mesh_config cfg
;
8107 struct mesh_setup setup
;
8110 /* start with default */
8111 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
8112 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
8114 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
8115 /* and parse parameters if given */
8116 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
8121 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
8122 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
8125 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8126 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8128 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8129 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
8130 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8133 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
8134 setup
.beacon_interval
=
8135 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8136 if (setup
.beacon_interval
< 10 ||
8137 setup
.beacon_interval
> 10000)
8141 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
8143 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
8144 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
8148 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
8149 /* parse additional setup parameters if given */
8150 err
= nl80211_parse_mesh_setup(info
, &setup
);
8156 cfg
.auto_open_plinks
= false;
8158 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8159 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8163 /* cfg80211_join_mesh() will sort it out */
8164 setup
.chandef
.chan
= NULL
;
8167 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8168 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8170 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8171 struct ieee80211_supported_band
*sband
;
8173 if (!setup
.chandef
.chan
)
8176 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
8178 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8179 &setup
.basic_rates
);
8184 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
8187 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8190 struct net_device
*dev
= info
->user_ptr
[1];
8192 return cfg80211_leave_mesh(rdev
, dev
);
8196 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
8197 struct cfg80211_registered_device
*rdev
)
8199 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
8200 struct nlattr
*nl_pats
, *nl_pat
;
8203 if (!wowlan
->n_patterns
)
8206 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
8210 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
8211 nl_pat
= nla_nest_start(msg
, i
+ 1);
8214 pat_len
= wowlan
->patterns
[i
].pattern_len
;
8215 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
8216 wowlan
->patterns
[i
].mask
) ||
8217 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8218 wowlan
->patterns
[i
].pattern
) ||
8219 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8220 wowlan
->patterns
[i
].pkt_offset
))
8222 nla_nest_end(msg
, nl_pat
);
8224 nla_nest_end(msg
, nl_pats
);
8229 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
8230 struct cfg80211_wowlan_tcp
*tcp
)
8232 struct nlattr
*nl_tcp
;
8237 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
8241 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
8242 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
8243 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
8244 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
8245 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
8246 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
8247 tcp
->payload_len
, tcp
->payload
) ||
8248 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
8249 tcp
->data_interval
) ||
8250 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
8251 tcp
->wake_len
, tcp
->wake_data
) ||
8252 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
8253 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
8256 if (tcp
->payload_seq
.len
&&
8257 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
8258 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
8261 if (tcp
->payload_tok
.len
&&
8262 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
8263 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
8267 nla_nest_end(msg
, nl_tcp
);
8272 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
8274 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8275 struct sk_buff
*msg
;
8277 u32 size
= NLMSG_DEFAULT_SIZE
;
8279 if (!rdev
->wiphy
.wowlan
)
8282 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
8283 /* adjust size to have room for all the data */
8284 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
8285 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
8286 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
8287 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
8290 msg
= nlmsg_new(size
, GFP_KERNEL
);
8294 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8295 NL80211_CMD_GET_WOWLAN
);
8297 goto nla_put_failure
;
8299 if (rdev
->wiphy
.wowlan_config
) {
8300 struct nlattr
*nl_wowlan
;
8302 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
8304 goto nla_put_failure
;
8306 if ((rdev
->wiphy
.wowlan_config
->any
&&
8307 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
8308 (rdev
->wiphy
.wowlan_config
->disconnect
&&
8309 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
8310 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
8311 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
8312 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
8313 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
8314 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
8315 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
8316 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
8317 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
8318 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
8319 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
8320 goto nla_put_failure
;
8322 if (nl80211_send_wowlan_patterns(msg
, rdev
))
8323 goto nla_put_failure
;
8325 if (nl80211_send_wowlan_tcp(msg
,
8326 rdev
->wiphy
.wowlan_config
->tcp
))
8327 goto nla_put_failure
;
8329 nla_nest_end(msg
, nl_wowlan
);
8332 genlmsg_end(msg
, hdr
);
8333 return genlmsg_reply(msg
, info
);
8340 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
8341 struct nlattr
*attr
,
8342 struct cfg80211_wowlan
*trig
)
8344 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
8345 struct cfg80211_wowlan_tcp
*cfg
;
8346 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
8347 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
8349 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
8352 if (!rdev
->wiphy
.wowlan
->tcp
)
8355 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
8356 nla_data(attr
), nla_len(attr
),
8357 nl80211_wowlan_tcp_policy
);
8361 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
8362 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
8363 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
8364 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
8365 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
8366 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
8367 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
8368 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
8371 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
8372 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
8375 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
8376 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
8377 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
8380 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
8381 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
8384 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
8385 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
8388 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
8389 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
8391 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
8392 tokens_size
= tokln
- sizeof(*tok
);
8394 if (!tok
->len
|| tokens_size
% tok
->len
)
8396 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
8398 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
8400 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
8402 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
8404 if (tok
->offset
+ tok
->len
> data_size
)
8408 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
8409 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
8410 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
8412 if (seq
->len
== 0 || seq
->len
> 4)
8414 if (seq
->len
+ seq
->offset
> data_size
)
8418 size
= sizeof(*cfg
);
8420 size
+= wake_size
+ wake_mask_size
;
8421 size
+= tokens_size
;
8423 cfg
= kzalloc(size
, GFP_KERNEL
);
8426 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
8427 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
8428 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
8430 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
8431 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
8435 /* allocate a socket and port for it and use it */
8436 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
8437 IPPROTO_TCP
, &cfg
->sock
, 1);
8442 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
8443 sock_release(cfg
->sock
);
8447 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
8453 cfg
->src_port
= port
;
8456 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
8457 cfg
->payload_len
= data_size
;
8458 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
8459 memcpy((void *)cfg
->payload
,
8460 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
8463 cfg
->payload_seq
= *seq
;
8464 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
8465 cfg
->wake_len
= wake_size
;
8466 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
8467 memcpy((void *)cfg
->wake_data
,
8468 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
8470 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
8471 data_size
+ wake_size
;
8472 memcpy((void *)cfg
->wake_mask
,
8473 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
8476 cfg
->tokens_size
= tokens_size
;
8477 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
8485 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
8487 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8488 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
8489 struct cfg80211_wowlan new_triggers
= {};
8490 struct cfg80211_wowlan
*ntrig
;
8491 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
8493 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
8498 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
8499 cfg80211_rdev_free_wowlan(rdev
);
8500 rdev
->wiphy
.wowlan_config
= NULL
;
8504 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
8505 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
8506 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
8507 nl80211_wowlan_policy
);
8511 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
8512 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
8514 new_triggers
.any
= true;
8517 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
8518 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
8520 new_triggers
.disconnect
= true;
8523 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
8524 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
8526 new_triggers
.magic_pkt
= true;
8529 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
8532 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
8533 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
8535 new_triggers
.gtk_rekey_failure
= true;
8538 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
8539 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
8541 new_triggers
.eap_identity_req
= true;
8544 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
8545 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
8547 new_triggers
.four_way_handshake
= true;
8550 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
8551 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
8553 new_triggers
.rfkill_release
= true;
8556 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
8559 int rem
, pat_len
, mask_len
, pkt_offset
;
8560 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
8562 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
8565 if (n_patterns
> wowlan
->n_patterns
)
8568 new_triggers
.patterns
= kcalloc(n_patterns
,
8569 sizeof(new_triggers
.patterns
[0]),
8571 if (!new_triggers
.patterns
)
8574 new_triggers
.n_patterns
= n_patterns
;
8577 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
8581 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
8582 nla_len(pat
), NULL
);
8584 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
8585 !pat_tb
[NL80211_PKTPAT_PATTERN
])
8587 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
8588 mask_len
= DIV_ROUND_UP(pat_len
, 8);
8589 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
8591 if (pat_len
> wowlan
->pattern_max_len
||
8592 pat_len
< wowlan
->pattern_min_len
)
8595 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
8598 pkt_offset
= nla_get_u32(
8599 pat_tb
[NL80211_PKTPAT_OFFSET
]);
8600 if (pkt_offset
> wowlan
->max_pkt_offset
)
8602 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
8604 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
8609 new_triggers
.patterns
[i
].mask
= mask_pat
;
8610 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
8612 mask_pat
+= mask_len
;
8613 new_triggers
.patterns
[i
].pattern
= mask_pat
;
8614 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
8616 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
8622 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8623 err
= nl80211_parse_wowlan_tcp(
8624 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8630 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8635 cfg80211_rdev_free_wowlan(rdev
);
8636 rdev
->wiphy
.wowlan_config
= ntrig
;
8639 if (rdev
->ops
->set_wakeup
&&
8640 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
8641 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
8645 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8646 kfree(new_triggers
.patterns
[i
].mask
);
8647 kfree(new_triggers
.patterns
);
8648 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8649 sock_release(new_triggers
.tcp
->sock
);
8650 kfree(new_triggers
.tcp
);
8655 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
8656 struct cfg80211_registered_device
*rdev
)
8658 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
8660 struct cfg80211_coalesce_rules
*rule
;
8662 if (!rdev
->coalesce
->n_rules
)
8665 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
8669 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
8670 nl_rule
= nla_nest_start(msg
, i
+ 1);
8674 rule
= &rdev
->coalesce
->rules
[i
];
8675 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
8679 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
8683 nl_pats
= nla_nest_start(msg
,
8684 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
8688 for (j
= 0; j
< rule
->n_patterns
; j
++) {
8689 nl_pat
= nla_nest_start(msg
, j
+ 1);
8692 pat_len
= rule
->patterns
[j
].pattern_len
;
8693 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
8694 DIV_ROUND_UP(pat_len
, 8),
8695 rule
->patterns
[j
].mask
) ||
8696 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8697 rule
->patterns
[j
].pattern
) ||
8698 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8699 rule
->patterns
[j
].pkt_offset
))
8701 nla_nest_end(msg
, nl_pat
);
8703 nla_nest_end(msg
, nl_pats
);
8704 nla_nest_end(msg
, nl_rule
);
8706 nla_nest_end(msg
, nl_rules
);
8711 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
8713 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8714 struct sk_buff
*msg
;
8717 if (!rdev
->wiphy
.coalesce
)
8720 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8724 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8725 NL80211_CMD_GET_COALESCE
);
8727 goto nla_put_failure
;
8729 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
8730 goto nla_put_failure
;
8732 genlmsg_end(msg
, hdr
);
8733 return genlmsg_reply(msg
, info
);
8740 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
8742 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
8744 struct cfg80211_coalesce_rules
*rule
;
8749 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
8750 rule
= &coalesce
->rules
[i
];
8751 for (j
= 0; j
< rule
->n_patterns
; j
++)
8752 kfree(rule
->patterns
[j
].mask
);
8753 kfree(rule
->patterns
);
8755 kfree(coalesce
->rules
);
8757 rdev
->coalesce
= NULL
;
8760 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
8761 struct nlattr
*rule
,
8762 struct cfg80211_coalesce_rules
*new_rule
)
8765 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
8766 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
8767 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
8768 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
8770 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
8771 nla_len(rule
), nl80211_coalesce_policy
);
8775 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
8777 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
8778 if (new_rule
->delay
> coalesce
->max_delay
)
8781 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
8782 new_rule
->condition
=
8783 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
8784 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
8785 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
8788 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
8791 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
8794 if (n_patterns
> coalesce
->n_patterns
)
8797 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
8799 if (!new_rule
->patterns
)
8802 new_rule
->n_patterns
= n_patterns
;
8805 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
8809 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
8810 nla_len(pat
), NULL
);
8811 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
8812 !pat_tb
[NL80211_PKTPAT_PATTERN
])
8814 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
8815 mask_len
= DIV_ROUND_UP(pat_len
, 8);
8816 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
8818 if (pat_len
> coalesce
->pattern_max_len
||
8819 pat_len
< coalesce
->pattern_min_len
)
8822 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
8825 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
8826 if (pkt_offset
> coalesce
->max_pkt_offset
)
8828 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
8830 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
8834 new_rule
->patterns
[i
].mask
= mask_pat
;
8835 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
8838 mask_pat
+= mask_len
;
8839 new_rule
->patterns
[i
].pattern
= mask_pat
;
8840 new_rule
->patterns
[i
].pattern_len
= pat_len
;
8841 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
8849 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
8851 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8852 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
8853 struct cfg80211_coalesce new_coalesce
= {};
8854 struct cfg80211_coalesce
*n_coalesce
;
8855 int err
, rem_rule
, n_rules
= 0, i
, j
;
8856 struct nlattr
*rule
;
8857 struct cfg80211_coalesce_rules
*tmp_rule
;
8859 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
8862 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
8863 cfg80211_rdev_free_coalesce(rdev
);
8864 rdev
->ops
->set_coalesce(&rdev
->wiphy
, NULL
);
8868 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
8871 if (n_rules
> coalesce
->n_rules
)
8874 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
8876 if (!new_coalesce
.rules
)
8879 new_coalesce
.n_rules
= n_rules
;
8882 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
8884 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
8885 &new_coalesce
.rules
[i
]);
8892 err
= rdev
->ops
->set_coalesce(&rdev
->wiphy
, &new_coalesce
);
8896 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
8901 cfg80211_rdev_free_coalesce(rdev
);
8902 rdev
->coalesce
= n_coalesce
;
8906 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
8907 tmp_rule
= &new_coalesce
.rules
[i
];
8908 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
8909 kfree(tmp_rule
->patterns
[j
].mask
);
8910 kfree(tmp_rule
->patterns
);
8912 kfree(new_coalesce
.rules
);
8917 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8919 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8920 struct net_device
*dev
= info
->user_ptr
[1];
8921 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8922 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8923 struct cfg80211_gtk_rekey_data rekey_data
;
8926 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8929 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8930 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8931 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8932 nl80211_rekey_policy
);
8936 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8938 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8940 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8943 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8945 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8947 memcpy(rekey_data
.replay_ctr
,
8948 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8949 NL80211_REPLAY_CTR_LEN
);
8952 if (!wdev
->current_bss
) {
8957 if (!rdev
->ops
->set_rekey_data
) {
8962 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8968 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8969 struct genl_info
*info
)
8971 struct net_device
*dev
= info
->user_ptr
[1];
8972 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8974 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8975 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8978 if (wdev
->ap_unexpected_nlportid
)
8981 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8985 static int nl80211_probe_client(struct sk_buff
*skb
,
8986 struct genl_info
*info
)
8988 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8989 struct net_device
*dev
= info
->user_ptr
[1];
8990 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8991 struct sk_buff
*msg
;
8997 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8998 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
9001 if (!info
->attrs
[NL80211_ATTR_MAC
])
9004 if (!rdev
->ops
->probe_client
)
9007 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9011 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9012 NL80211_CMD_PROBE_CLIENT
);
9018 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9020 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
9024 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9025 goto nla_put_failure
;
9027 genlmsg_end(msg
, hdr
);
9029 return genlmsg_reply(msg
, info
);
9038 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
9040 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9041 struct cfg80211_beacon_registration
*reg
, *nreg
;
9044 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
9047 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
9051 /* First, check if already registered. */
9052 spin_lock_bh(&rdev
->beacon_registrations_lock
);
9053 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
9054 if (reg
->nlportid
== info
->snd_portid
) {
9059 /* Add it to the list */
9060 nreg
->nlportid
= info
->snd_portid
;
9061 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
9063 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9067 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9072 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9074 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9075 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9078 if (!rdev
->ops
->start_p2p_device
)
9081 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9084 if (wdev
->p2p_started
)
9087 if (rfkill_blocked(rdev
->rfkill
))
9090 err
= rdev_start_p2p_device(rdev
, wdev
);
9094 wdev
->p2p_started
= true;
9100 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9102 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9103 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9105 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9108 if (!rdev
->ops
->stop_p2p_device
)
9111 cfg80211_stop_p2p_device(rdev
, wdev
);
9116 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
9117 struct genl_info
*info
)
9120 struct sk_buff
*msg
;
9122 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9126 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9127 NL80211_CMD_GET_PROTOCOL_FEATURES
);
9129 goto nla_put_failure
;
9131 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
9132 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
9133 goto nla_put_failure
;
9135 genlmsg_end(msg
, hdr
);
9136 return genlmsg_reply(msg
, info
);
9143 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
9145 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9146 struct cfg80211_update_ft_ies_params ft_params
;
9147 struct net_device
*dev
= info
->user_ptr
[1];
9149 if (!rdev
->ops
->update_ft_ies
)
9152 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
9153 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
9156 memset(&ft_params
, 0, sizeof(ft_params
));
9157 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
9158 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
9159 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
9161 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
9164 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
9165 struct genl_info
*info
)
9167 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9168 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9169 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
9173 if (!rdev
->ops
->crit_proto_start
)
9176 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
9179 if (rdev
->crit_proto_nlportid
)
9182 /* determine protocol if provided */
9183 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
9184 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
9186 if (proto
>= NUM_NL80211_CRIT_PROTO
)
9189 /* timeout must be provided */
9190 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
9194 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
9196 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
9199 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
9201 rdev
->crit_proto_nlportid
= info
->snd_portid
;
9206 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
9207 struct genl_info
*info
)
9209 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9210 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9212 if (!rdev
->ops
->crit_proto_stop
)
9215 if (rdev
->crit_proto_nlportid
) {
9216 rdev
->crit_proto_nlportid
= 0;
9217 rdev_crit_proto_stop(rdev
, wdev
);
9222 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
9224 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9225 struct wireless_dev
*wdev
=
9226 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
9230 if (!rdev
->wiphy
.vendor_commands
)
9234 err
= PTR_ERR(wdev
);
9238 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
9242 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
9243 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
9246 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
9247 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
9248 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
9249 const struct wiphy_vendor_command
*vcmd
;
9253 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
9255 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
9258 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
9259 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
9262 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
9266 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
9268 !netif_running(wdev
->netdev
))
9270 if (!wdev
->netdev
&& !wdev
->p2p_started
)
9277 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
9278 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
9279 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
9282 rdev
->cur_cmd_info
= info
;
9283 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
9285 rdev
->cur_cmd_info
= NULL
;
9292 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
9293 enum nl80211_commands cmd
,
9294 enum nl80211_attrs attr
,
9297 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
9299 if (WARN_ON(!rdev
->cur_cmd_info
))
9302 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
,
9303 rdev
->cur_cmd_info
->snd_portid
,
9304 rdev
->cur_cmd_info
->snd_seq
,
9305 cmd
, attr
, NULL
, GFP_KERNEL
);
9307 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
9309 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
9311 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
9312 void *hdr
= ((void **)skb
->cb
)[1];
9313 struct nlattr
*data
= ((void **)skb
->cb
)[2];
9315 /* clear CB data for netlink core to own from now on */
9316 memset(skb
->cb
, 0, sizeof(skb
->cb
));
9318 if (WARN_ON(!rdev
->cur_cmd_info
)) {
9323 nla_nest_end(skb
, data
);
9324 genlmsg_end(skb
, hdr
);
9325 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
9327 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
9330 static int nl80211_set_qos_map(struct sk_buff
*skb
,
9331 struct genl_info
*info
)
9333 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9334 struct cfg80211_qos_map
*qos_map
= NULL
;
9335 struct net_device
*dev
= info
->user_ptr
[1];
9336 u8
*pos
, len
, num_des
, des_len
, des
;
9339 if (!rdev
->ops
->set_qos_map
)
9342 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
9343 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
9344 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
9346 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
9347 len
> IEEE80211_QOS_MAP_LEN_MAX
)
9350 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
9354 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
9357 sizeof(struct cfg80211_dscp_exception
);
9358 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
9359 qos_map
->num_des
= num_des
;
9360 for (des
= 0; des
< num_des
; des
++) {
9361 if (qos_map
->dscp_exception
[des
].up
> 7) {
9368 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
9371 wdev_lock(dev
->ieee80211_ptr
);
9372 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
9374 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
9375 wdev_unlock(dev
->ieee80211_ptr
);
9381 #define NL80211_FLAG_NEED_WIPHY 0x01
9382 #define NL80211_FLAG_NEED_NETDEV 0x02
9383 #define NL80211_FLAG_NEED_RTNL 0x04
9384 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9385 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9386 NL80211_FLAG_CHECK_NETDEV_UP)
9387 #define NL80211_FLAG_NEED_WDEV 0x10
9388 /* If a netdev is associated, it must be UP, P2P must be started */
9389 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9390 NL80211_FLAG_CHECK_NETDEV_UP)
9392 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
9393 struct genl_info
*info
)
9395 struct cfg80211_registered_device
*rdev
;
9396 struct wireless_dev
*wdev
;
9397 struct net_device
*dev
;
9398 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
9403 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
9404 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
9408 return PTR_ERR(rdev
);
9410 info
->user_ptr
[0] = rdev
;
9411 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
9412 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
9415 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
9420 return PTR_ERR(wdev
);
9424 rdev
= wiphy_to_rdev(wdev
->wiphy
);
9426 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
9433 info
->user_ptr
[1] = dev
;
9435 info
->user_ptr
[1] = wdev
;
9439 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
9440 !netif_running(dev
)) {
9447 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
9448 if (!wdev
->p2p_started
) {
9455 info
->user_ptr
[0] = rdev
;
9461 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
9462 struct genl_info
*info
)
9464 if (info
->user_ptr
[1]) {
9465 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
9466 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9469 dev_put(wdev
->netdev
);
9471 dev_put(info
->user_ptr
[1]);
9474 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
9478 static const struct genl_ops nl80211_ops
[] = {
9480 .cmd
= NL80211_CMD_GET_WIPHY
,
9481 .doit
= nl80211_get_wiphy
,
9482 .dumpit
= nl80211_dump_wiphy
,
9483 .done
= nl80211_dump_wiphy_done
,
9484 .policy
= nl80211_policy
,
9485 /* can be retrieved by unprivileged users */
9486 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9487 NL80211_FLAG_NEED_RTNL
,
9490 .cmd
= NL80211_CMD_SET_WIPHY
,
9491 .doit
= nl80211_set_wiphy
,
9492 .policy
= nl80211_policy
,
9493 .flags
= GENL_ADMIN_PERM
,
9494 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9497 .cmd
= NL80211_CMD_GET_INTERFACE
,
9498 .doit
= nl80211_get_interface
,
9499 .dumpit
= nl80211_dump_interface
,
9500 .policy
= nl80211_policy
,
9501 /* can be retrieved by unprivileged users */
9502 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9503 NL80211_FLAG_NEED_RTNL
,
9506 .cmd
= NL80211_CMD_SET_INTERFACE
,
9507 .doit
= nl80211_set_interface
,
9508 .policy
= nl80211_policy
,
9509 .flags
= GENL_ADMIN_PERM
,
9510 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9511 NL80211_FLAG_NEED_RTNL
,
9514 .cmd
= NL80211_CMD_NEW_INTERFACE
,
9515 .doit
= nl80211_new_interface
,
9516 .policy
= nl80211_policy
,
9517 .flags
= GENL_ADMIN_PERM
,
9518 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9519 NL80211_FLAG_NEED_RTNL
,
9522 .cmd
= NL80211_CMD_DEL_INTERFACE
,
9523 .doit
= nl80211_del_interface
,
9524 .policy
= nl80211_policy
,
9525 .flags
= GENL_ADMIN_PERM
,
9526 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9527 NL80211_FLAG_NEED_RTNL
,
9530 .cmd
= NL80211_CMD_GET_KEY
,
9531 .doit
= nl80211_get_key
,
9532 .policy
= nl80211_policy
,
9533 .flags
= GENL_ADMIN_PERM
,
9534 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9535 NL80211_FLAG_NEED_RTNL
,
9538 .cmd
= NL80211_CMD_SET_KEY
,
9539 .doit
= nl80211_set_key
,
9540 .policy
= nl80211_policy
,
9541 .flags
= GENL_ADMIN_PERM
,
9542 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9543 NL80211_FLAG_NEED_RTNL
,
9546 .cmd
= NL80211_CMD_NEW_KEY
,
9547 .doit
= nl80211_new_key
,
9548 .policy
= nl80211_policy
,
9549 .flags
= GENL_ADMIN_PERM
,
9550 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9551 NL80211_FLAG_NEED_RTNL
,
9554 .cmd
= NL80211_CMD_DEL_KEY
,
9555 .doit
= nl80211_del_key
,
9556 .policy
= nl80211_policy
,
9557 .flags
= GENL_ADMIN_PERM
,
9558 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9559 NL80211_FLAG_NEED_RTNL
,
9562 .cmd
= NL80211_CMD_SET_BEACON
,
9563 .policy
= nl80211_policy
,
9564 .flags
= GENL_ADMIN_PERM
,
9565 .doit
= nl80211_set_beacon
,
9566 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9567 NL80211_FLAG_NEED_RTNL
,
9570 .cmd
= NL80211_CMD_START_AP
,
9571 .policy
= nl80211_policy
,
9572 .flags
= GENL_ADMIN_PERM
,
9573 .doit
= nl80211_start_ap
,
9574 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9575 NL80211_FLAG_NEED_RTNL
,
9578 .cmd
= NL80211_CMD_STOP_AP
,
9579 .policy
= nl80211_policy
,
9580 .flags
= GENL_ADMIN_PERM
,
9581 .doit
= nl80211_stop_ap
,
9582 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9583 NL80211_FLAG_NEED_RTNL
,
9586 .cmd
= NL80211_CMD_GET_STATION
,
9587 .doit
= nl80211_get_station
,
9588 .dumpit
= nl80211_dump_station
,
9589 .policy
= nl80211_policy
,
9590 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9591 NL80211_FLAG_NEED_RTNL
,
9594 .cmd
= NL80211_CMD_SET_STATION
,
9595 .doit
= nl80211_set_station
,
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_NEW_STATION
,
9603 .doit
= nl80211_new_station
,
9604 .policy
= nl80211_policy
,
9605 .flags
= GENL_ADMIN_PERM
,
9606 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9607 NL80211_FLAG_NEED_RTNL
,
9610 .cmd
= NL80211_CMD_DEL_STATION
,
9611 .doit
= nl80211_del_station
,
9612 .policy
= nl80211_policy
,
9613 .flags
= GENL_ADMIN_PERM
,
9614 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9615 NL80211_FLAG_NEED_RTNL
,
9618 .cmd
= NL80211_CMD_GET_MPATH
,
9619 .doit
= nl80211_get_mpath
,
9620 .dumpit
= nl80211_dump_mpath
,
9621 .policy
= nl80211_policy
,
9622 .flags
= GENL_ADMIN_PERM
,
9623 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9624 NL80211_FLAG_NEED_RTNL
,
9627 .cmd
= NL80211_CMD_SET_MPATH
,
9628 .doit
= nl80211_set_mpath
,
9629 .policy
= nl80211_policy
,
9630 .flags
= GENL_ADMIN_PERM
,
9631 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9632 NL80211_FLAG_NEED_RTNL
,
9635 .cmd
= NL80211_CMD_NEW_MPATH
,
9636 .doit
= nl80211_new_mpath
,
9637 .policy
= nl80211_policy
,
9638 .flags
= GENL_ADMIN_PERM
,
9639 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9640 NL80211_FLAG_NEED_RTNL
,
9643 .cmd
= NL80211_CMD_DEL_MPATH
,
9644 .doit
= nl80211_del_mpath
,
9645 .policy
= nl80211_policy
,
9646 .flags
= GENL_ADMIN_PERM
,
9647 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9648 NL80211_FLAG_NEED_RTNL
,
9651 .cmd
= NL80211_CMD_SET_BSS
,
9652 .doit
= nl80211_set_bss
,
9653 .policy
= nl80211_policy
,
9654 .flags
= GENL_ADMIN_PERM
,
9655 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9656 NL80211_FLAG_NEED_RTNL
,
9659 .cmd
= NL80211_CMD_GET_REG
,
9660 .doit
= nl80211_get_reg
,
9661 .policy
= nl80211_policy
,
9662 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9663 /* can be retrieved by unprivileged users */
9666 .cmd
= NL80211_CMD_SET_REG
,
9667 .doit
= nl80211_set_reg
,
9668 .policy
= nl80211_policy
,
9669 .flags
= GENL_ADMIN_PERM
,
9670 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9673 .cmd
= NL80211_CMD_REQ_SET_REG
,
9674 .doit
= nl80211_req_set_reg
,
9675 .policy
= nl80211_policy
,
9676 .flags
= GENL_ADMIN_PERM
,
9679 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
9680 .doit
= nl80211_get_mesh_config
,
9681 .policy
= nl80211_policy
,
9682 /* can be retrieved by unprivileged users */
9683 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9684 NL80211_FLAG_NEED_RTNL
,
9687 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
9688 .doit
= nl80211_update_mesh_config
,
9689 .policy
= nl80211_policy
,
9690 .flags
= GENL_ADMIN_PERM
,
9691 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9692 NL80211_FLAG_NEED_RTNL
,
9695 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
9696 .doit
= nl80211_trigger_scan
,
9697 .policy
= nl80211_policy
,
9698 .flags
= GENL_ADMIN_PERM
,
9699 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9700 NL80211_FLAG_NEED_RTNL
,
9703 .cmd
= NL80211_CMD_GET_SCAN
,
9704 .policy
= nl80211_policy
,
9705 .dumpit
= nl80211_dump_scan
,
9708 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
9709 .doit
= nl80211_start_sched_scan
,
9710 .policy
= nl80211_policy
,
9711 .flags
= GENL_ADMIN_PERM
,
9712 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9713 NL80211_FLAG_NEED_RTNL
,
9716 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
9717 .doit
= nl80211_stop_sched_scan
,
9718 .policy
= nl80211_policy
,
9719 .flags
= GENL_ADMIN_PERM
,
9720 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9721 NL80211_FLAG_NEED_RTNL
,
9724 .cmd
= NL80211_CMD_AUTHENTICATE
,
9725 .doit
= nl80211_authenticate
,
9726 .policy
= nl80211_policy
,
9727 .flags
= GENL_ADMIN_PERM
,
9728 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9729 NL80211_FLAG_NEED_RTNL
,
9732 .cmd
= NL80211_CMD_ASSOCIATE
,
9733 .doit
= nl80211_associate
,
9734 .policy
= nl80211_policy
,
9735 .flags
= GENL_ADMIN_PERM
,
9736 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9737 NL80211_FLAG_NEED_RTNL
,
9740 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
9741 .doit
= nl80211_deauthenticate
,
9742 .policy
= nl80211_policy
,
9743 .flags
= GENL_ADMIN_PERM
,
9744 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9745 NL80211_FLAG_NEED_RTNL
,
9748 .cmd
= NL80211_CMD_DISASSOCIATE
,
9749 .doit
= nl80211_disassociate
,
9750 .policy
= nl80211_policy
,
9751 .flags
= GENL_ADMIN_PERM
,
9752 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9753 NL80211_FLAG_NEED_RTNL
,
9756 .cmd
= NL80211_CMD_JOIN_IBSS
,
9757 .doit
= nl80211_join_ibss
,
9758 .policy
= nl80211_policy
,
9759 .flags
= GENL_ADMIN_PERM
,
9760 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9761 NL80211_FLAG_NEED_RTNL
,
9764 .cmd
= NL80211_CMD_LEAVE_IBSS
,
9765 .doit
= nl80211_leave_ibss
,
9766 .policy
= nl80211_policy
,
9767 .flags
= GENL_ADMIN_PERM
,
9768 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9769 NL80211_FLAG_NEED_RTNL
,
9771 #ifdef CONFIG_NL80211_TESTMODE
9773 .cmd
= NL80211_CMD_TESTMODE
,
9774 .doit
= nl80211_testmode_do
,
9775 .dumpit
= nl80211_testmode_dump
,
9776 .policy
= nl80211_policy
,
9777 .flags
= GENL_ADMIN_PERM
,
9778 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9779 NL80211_FLAG_NEED_RTNL
,
9783 .cmd
= NL80211_CMD_CONNECT
,
9784 .doit
= nl80211_connect
,
9785 .policy
= nl80211_policy
,
9786 .flags
= GENL_ADMIN_PERM
,
9787 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9788 NL80211_FLAG_NEED_RTNL
,
9791 .cmd
= NL80211_CMD_DISCONNECT
,
9792 .doit
= nl80211_disconnect
,
9793 .policy
= nl80211_policy
,
9794 .flags
= GENL_ADMIN_PERM
,
9795 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9796 NL80211_FLAG_NEED_RTNL
,
9799 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
9800 .doit
= nl80211_wiphy_netns
,
9801 .policy
= nl80211_policy
,
9802 .flags
= GENL_ADMIN_PERM
,
9803 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9804 NL80211_FLAG_NEED_RTNL
,
9807 .cmd
= NL80211_CMD_GET_SURVEY
,
9808 .policy
= nl80211_policy
,
9809 .dumpit
= nl80211_dump_survey
,
9812 .cmd
= NL80211_CMD_SET_PMKSA
,
9813 .doit
= nl80211_setdel_pmksa
,
9814 .policy
= nl80211_policy
,
9815 .flags
= GENL_ADMIN_PERM
,
9816 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9817 NL80211_FLAG_NEED_RTNL
,
9820 .cmd
= NL80211_CMD_DEL_PMKSA
,
9821 .doit
= nl80211_setdel_pmksa
,
9822 .policy
= nl80211_policy
,
9823 .flags
= GENL_ADMIN_PERM
,
9824 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9825 NL80211_FLAG_NEED_RTNL
,
9828 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
9829 .doit
= nl80211_flush_pmksa
,
9830 .policy
= nl80211_policy
,
9831 .flags
= GENL_ADMIN_PERM
,
9832 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9833 NL80211_FLAG_NEED_RTNL
,
9836 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
9837 .doit
= nl80211_remain_on_channel
,
9838 .policy
= nl80211_policy
,
9839 .flags
= GENL_ADMIN_PERM
,
9840 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9841 NL80211_FLAG_NEED_RTNL
,
9844 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9845 .doit
= nl80211_cancel_remain_on_channel
,
9846 .policy
= nl80211_policy
,
9847 .flags
= GENL_ADMIN_PERM
,
9848 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9849 NL80211_FLAG_NEED_RTNL
,
9852 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
9853 .doit
= nl80211_set_tx_bitrate_mask
,
9854 .policy
= nl80211_policy
,
9855 .flags
= GENL_ADMIN_PERM
,
9856 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9857 NL80211_FLAG_NEED_RTNL
,
9860 .cmd
= NL80211_CMD_REGISTER_FRAME
,
9861 .doit
= nl80211_register_mgmt
,
9862 .policy
= nl80211_policy
,
9863 .flags
= GENL_ADMIN_PERM
,
9864 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9865 NL80211_FLAG_NEED_RTNL
,
9868 .cmd
= NL80211_CMD_FRAME
,
9869 .doit
= nl80211_tx_mgmt
,
9870 .policy
= nl80211_policy
,
9871 .flags
= GENL_ADMIN_PERM
,
9872 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9873 NL80211_FLAG_NEED_RTNL
,
9876 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
9877 .doit
= nl80211_tx_mgmt_cancel_wait
,
9878 .policy
= nl80211_policy
,
9879 .flags
= GENL_ADMIN_PERM
,
9880 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9881 NL80211_FLAG_NEED_RTNL
,
9884 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
9885 .doit
= nl80211_set_power_save
,
9886 .policy
= nl80211_policy
,
9887 .flags
= GENL_ADMIN_PERM
,
9888 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9889 NL80211_FLAG_NEED_RTNL
,
9892 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
9893 .doit
= nl80211_get_power_save
,
9894 .policy
= nl80211_policy
,
9895 /* can be retrieved by unprivileged users */
9896 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9897 NL80211_FLAG_NEED_RTNL
,
9900 .cmd
= NL80211_CMD_SET_CQM
,
9901 .doit
= nl80211_set_cqm
,
9902 .policy
= nl80211_policy
,
9903 .flags
= GENL_ADMIN_PERM
,
9904 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9905 NL80211_FLAG_NEED_RTNL
,
9908 .cmd
= NL80211_CMD_SET_CHANNEL
,
9909 .doit
= nl80211_set_channel
,
9910 .policy
= nl80211_policy
,
9911 .flags
= GENL_ADMIN_PERM
,
9912 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9913 NL80211_FLAG_NEED_RTNL
,
9916 .cmd
= NL80211_CMD_SET_WDS_PEER
,
9917 .doit
= nl80211_set_wds_peer
,
9918 .policy
= nl80211_policy
,
9919 .flags
= GENL_ADMIN_PERM
,
9920 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9921 NL80211_FLAG_NEED_RTNL
,
9924 .cmd
= NL80211_CMD_JOIN_MESH
,
9925 .doit
= nl80211_join_mesh
,
9926 .policy
= nl80211_policy
,
9927 .flags
= GENL_ADMIN_PERM
,
9928 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9929 NL80211_FLAG_NEED_RTNL
,
9932 .cmd
= NL80211_CMD_LEAVE_MESH
,
9933 .doit
= nl80211_leave_mesh
,
9934 .policy
= nl80211_policy
,
9935 .flags
= GENL_ADMIN_PERM
,
9936 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9937 NL80211_FLAG_NEED_RTNL
,
9941 .cmd
= NL80211_CMD_GET_WOWLAN
,
9942 .doit
= nl80211_get_wowlan
,
9943 .policy
= nl80211_policy
,
9944 /* can be retrieved by unprivileged users */
9945 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9946 NL80211_FLAG_NEED_RTNL
,
9949 .cmd
= NL80211_CMD_SET_WOWLAN
,
9950 .doit
= nl80211_set_wowlan
,
9951 .policy
= nl80211_policy
,
9952 .flags
= GENL_ADMIN_PERM
,
9953 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9954 NL80211_FLAG_NEED_RTNL
,
9958 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9959 .doit
= nl80211_set_rekey_data
,
9960 .policy
= nl80211_policy
,
9961 .flags
= GENL_ADMIN_PERM
,
9962 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9963 NL80211_FLAG_NEED_RTNL
,
9966 .cmd
= NL80211_CMD_TDLS_MGMT
,
9967 .doit
= nl80211_tdls_mgmt
,
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_TDLS_OPER
,
9975 .doit
= nl80211_tdls_oper
,
9976 .policy
= nl80211_policy
,
9977 .flags
= GENL_ADMIN_PERM
,
9978 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9979 NL80211_FLAG_NEED_RTNL
,
9982 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9983 .doit
= nl80211_register_unexpected_frame
,
9984 .policy
= nl80211_policy
,
9985 .flags
= GENL_ADMIN_PERM
,
9986 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9987 NL80211_FLAG_NEED_RTNL
,
9990 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9991 .doit
= nl80211_probe_client
,
9992 .policy
= nl80211_policy
,
9993 .flags
= GENL_ADMIN_PERM
,
9994 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9995 NL80211_FLAG_NEED_RTNL
,
9998 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9999 .doit
= nl80211_register_beacons
,
10000 .policy
= nl80211_policy
,
10001 .flags
= GENL_ADMIN_PERM
,
10002 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10003 NL80211_FLAG_NEED_RTNL
,
10006 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
10007 .doit
= nl80211_set_noack_map
,
10008 .policy
= nl80211_policy
,
10009 .flags
= GENL_ADMIN_PERM
,
10010 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10011 NL80211_FLAG_NEED_RTNL
,
10014 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
10015 .doit
= nl80211_start_p2p_device
,
10016 .policy
= nl80211_policy
,
10017 .flags
= GENL_ADMIN_PERM
,
10018 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
10019 NL80211_FLAG_NEED_RTNL
,
10022 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
10023 .doit
= nl80211_stop_p2p_device
,
10024 .policy
= nl80211_policy
,
10025 .flags
= GENL_ADMIN_PERM
,
10026 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
10027 NL80211_FLAG_NEED_RTNL
,
10030 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
10031 .doit
= nl80211_set_mcast_rate
,
10032 .policy
= nl80211_policy
,
10033 .flags
= GENL_ADMIN_PERM
,
10034 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10035 NL80211_FLAG_NEED_RTNL
,
10038 .cmd
= NL80211_CMD_SET_MAC_ACL
,
10039 .doit
= nl80211_set_mac_acl
,
10040 .policy
= nl80211_policy
,
10041 .flags
= GENL_ADMIN_PERM
,
10042 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10043 NL80211_FLAG_NEED_RTNL
,
10046 .cmd
= NL80211_CMD_RADAR_DETECT
,
10047 .doit
= nl80211_start_radar_detection
,
10048 .policy
= nl80211_policy
,
10049 .flags
= GENL_ADMIN_PERM
,
10050 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10051 NL80211_FLAG_NEED_RTNL
,
10054 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
10055 .doit
= nl80211_get_protocol_features
,
10056 .policy
= nl80211_policy
,
10059 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
10060 .doit
= nl80211_update_ft_ies
,
10061 .policy
= nl80211_policy
,
10062 .flags
= GENL_ADMIN_PERM
,
10063 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10064 NL80211_FLAG_NEED_RTNL
,
10067 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
10068 .doit
= nl80211_crit_protocol_start
,
10069 .policy
= nl80211_policy
,
10070 .flags
= GENL_ADMIN_PERM
,
10071 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
10072 NL80211_FLAG_NEED_RTNL
,
10075 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
10076 .doit
= nl80211_crit_protocol_stop
,
10077 .policy
= nl80211_policy
,
10078 .flags
= GENL_ADMIN_PERM
,
10079 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
10080 NL80211_FLAG_NEED_RTNL
,
10083 .cmd
= NL80211_CMD_GET_COALESCE
,
10084 .doit
= nl80211_get_coalesce
,
10085 .policy
= nl80211_policy
,
10086 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10087 NL80211_FLAG_NEED_RTNL
,
10090 .cmd
= NL80211_CMD_SET_COALESCE
,
10091 .doit
= nl80211_set_coalesce
,
10092 .policy
= nl80211_policy
,
10093 .flags
= GENL_ADMIN_PERM
,
10094 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10095 NL80211_FLAG_NEED_RTNL
,
10098 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
10099 .doit
= nl80211_channel_switch
,
10100 .policy
= nl80211_policy
,
10101 .flags
= GENL_ADMIN_PERM
,
10102 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10103 NL80211_FLAG_NEED_RTNL
,
10106 .cmd
= NL80211_CMD_VENDOR
,
10107 .doit
= nl80211_vendor_cmd
,
10108 .policy
= nl80211_policy
,
10109 .flags
= GENL_ADMIN_PERM
,
10110 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10111 NL80211_FLAG_NEED_RTNL
,
10114 .cmd
= NL80211_CMD_SET_QOS_MAP
,
10115 .doit
= nl80211_set_qos_map
,
10116 .policy
= nl80211_policy
,
10117 .flags
= GENL_ADMIN_PERM
,
10118 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10119 NL80211_FLAG_NEED_RTNL
,
10123 /* notification functions */
10125 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
10126 enum nl80211_commands cmd
)
10128 struct sk_buff
*msg
;
10129 struct nl80211_dump_wiphy_state state
= {};
10131 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
10132 cmd
!= NL80211_CMD_DEL_WIPHY
);
10134 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10138 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
10143 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10144 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
10147 static int nl80211_add_scan_req(struct sk_buff
*msg
,
10148 struct cfg80211_registered_device
*rdev
)
10150 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
10151 struct nlattr
*nest
;
10157 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
10159 goto nla_put_failure
;
10160 for (i
= 0; i
< req
->n_ssids
; i
++) {
10161 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
10162 goto nla_put_failure
;
10164 nla_nest_end(msg
, nest
);
10166 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
10168 goto nla_put_failure
;
10169 for (i
= 0; i
< req
->n_channels
; i
++) {
10170 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
10171 goto nla_put_failure
;
10173 nla_nest_end(msg
, nest
);
10176 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
10177 goto nla_put_failure
;
10180 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
10181 goto nla_put_failure
;
10188 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
10189 struct cfg80211_registered_device
*rdev
,
10190 struct wireless_dev
*wdev
,
10191 u32 portid
, u32 seq
, int flags
,
10196 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
10200 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10201 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10202 wdev
->netdev
->ifindex
)) ||
10203 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10204 goto nla_put_failure
;
10206 /* ignore errors and send incomplete event anyway */
10207 nl80211_add_scan_req(msg
, rdev
);
10209 return genlmsg_end(msg
, hdr
);
10212 genlmsg_cancel(msg
, hdr
);
10217 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
10218 struct cfg80211_registered_device
*rdev
,
10219 struct net_device
*netdev
,
10220 u32 portid
, u32 seq
, int flags
, u32 cmd
)
10224 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
10228 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10229 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10230 goto nla_put_failure
;
10232 return genlmsg_end(msg
, hdr
);
10235 genlmsg_cancel(msg
, hdr
);
10239 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
10240 struct wireless_dev
*wdev
)
10242 struct sk_buff
*msg
;
10244 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10248 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
10249 NL80211_CMD_TRIGGER_SCAN
) < 0) {
10254 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10255 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10258 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
10259 struct wireless_dev
*wdev
, bool aborted
)
10261 struct sk_buff
*msg
;
10263 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10267 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
10268 aborted
? NL80211_CMD_SCAN_ABORTED
:
10269 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
10277 void nl80211_send_scan_result(struct cfg80211_registered_device
*rdev
,
10278 struct sk_buff
*msg
)
10283 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10284 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10287 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
10288 struct net_device
*netdev
)
10290 struct sk_buff
*msg
;
10292 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10296 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
10297 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
10302 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10303 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10306 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
10307 struct net_device
*netdev
, u32 cmd
)
10309 struct sk_buff
*msg
;
10311 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10315 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
10320 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10321 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
10325 * This can happen on global regulatory changes or device specific settings
10326 * based on custom world regulatory domains.
10328 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
10330 struct sk_buff
*msg
;
10333 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10337 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
10343 /* Userspace can always count this one always being set */
10344 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
10345 goto nla_put_failure
;
10347 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
10348 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10349 NL80211_REGDOM_TYPE_WORLD
))
10350 goto nla_put_failure
;
10351 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
10352 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10353 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
10354 goto nla_put_failure
;
10355 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
10356 request
->intersect
) {
10357 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10358 NL80211_REGDOM_TYPE_INTERSECTION
))
10359 goto nla_put_failure
;
10361 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
10362 NL80211_REGDOM_TYPE_COUNTRY
) ||
10363 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
10365 goto nla_put_failure
;
10368 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
10369 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
10370 goto nla_put_failure
;
10372 genlmsg_end(msg
, hdr
);
10375 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
10376 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
10382 genlmsg_cancel(msg
, hdr
);
10386 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
10387 struct net_device
*netdev
,
10388 const u8
*buf
, size_t len
,
10389 enum nl80211_commands cmd
, gfp_t gfp
)
10391 struct sk_buff
*msg
;
10394 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10398 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10404 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10405 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10406 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10407 goto nla_put_failure
;
10409 genlmsg_end(msg
, hdr
);
10411 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10412 NL80211_MCGRP_MLME
, gfp
);
10416 genlmsg_cancel(msg
, hdr
);
10420 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
10421 struct net_device
*netdev
, const u8
*buf
,
10422 size_t len
, gfp_t gfp
)
10424 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10425 NL80211_CMD_AUTHENTICATE
, gfp
);
10428 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
10429 struct net_device
*netdev
, const u8
*buf
,
10430 size_t len
, gfp_t gfp
)
10432 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10433 NL80211_CMD_ASSOCIATE
, gfp
);
10436 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
10437 struct net_device
*netdev
, const u8
*buf
,
10438 size_t len
, gfp_t gfp
)
10440 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10441 NL80211_CMD_DEAUTHENTICATE
, gfp
);
10444 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
10445 struct net_device
*netdev
, const u8
*buf
,
10446 size_t len
, gfp_t gfp
)
10448 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
10449 NL80211_CMD_DISASSOCIATE
, gfp
);
10452 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
10455 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10456 struct wiphy
*wiphy
= wdev
->wiphy
;
10457 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10458 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
10461 if (WARN_ON(len
< 2))
10464 if (ieee80211_is_deauth(mgmt
->frame_control
))
10465 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
10467 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
10469 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
10470 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
);
10472 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
10474 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
10475 struct net_device
*netdev
, int cmd
,
10476 const u8
*addr
, gfp_t gfp
)
10478 struct sk_buff
*msg
;
10481 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10485 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10491 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10492 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10493 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
10494 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10495 goto nla_put_failure
;
10497 genlmsg_end(msg
, hdr
);
10499 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10500 NL80211_MCGRP_MLME
, gfp
);
10504 genlmsg_cancel(msg
, hdr
);
10508 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
10509 struct net_device
*netdev
, const u8
*addr
,
10512 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
10516 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
10517 struct net_device
*netdev
, const u8
*addr
,
10520 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
10524 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
10525 struct net_device
*netdev
, const u8
*bssid
,
10526 const u8
*req_ie
, size_t req_ie_len
,
10527 const u8
*resp_ie
, size_t resp_ie_len
,
10528 u16 status
, gfp_t gfp
)
10530 struct sk_buff
*msg
;
10533 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10537 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
10543 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10544 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10545 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
10546 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
10548 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
10550 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
10551 goto nla_put_failure
;
10553 genlmsg_end(msg
, hdr
);
10555 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10556 NL80211_MCGRP_MLME
, gfp
);
10560 genlmsg_cancel(msg
, hdr
);
10565 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
10566 struct net_device
*netdev
, const u8
*bssid
,
10567 const u8
*req_ie
, size_t req_ie_len
,
10568 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
10570 struct sk_buff
*msg
;
10573 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10577 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
10583 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10584 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10585 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
10587 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
10589 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
10590 goto nla_put_failure
;
10592 genlmsg_end(msg
, hdr
);
10594 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10595 NL80211_MCGRP_MLME
, gfp
);
10599 genlmsg_cancel(msg
, hdr
);
10604 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
10605 struct net_device
*netdev
, u16 reason
,
10606 const u8
*ie
, size_t ie_len
, bool from_ap
)
10608 struct sk_buff
*msg
;
10611 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10615 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
10621 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10622 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10623 (from_ap
&& reason
&&
10624 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
10626 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
10627 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
10628 goto nla_put_failure
;
10630 genlmsg_end(msg
, hdr
);
10632 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10633 NL80211_MCGRP_MLME
, GFP_KERNEL
);
10637 genlmsg_cancel(msg
, hdr
);
10642 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
10643 struct net_device
*netdev
, const u8
*bssid
,
10646 struct sk_buff
*msg
;
10649 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10653 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
10659 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10660 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10661 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10662 goto nla_put_failure
;
10664 genlmsg_end(msg
, hdr
);
10666 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10667 NL80211_MCGRP_MLME
, gfp
);
10671 genlmsg_cancel(msg
, hdr
);
10675 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
10676 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
10678 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10679 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
10680 struct sk_buff
*msg
;
10683 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
10686 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
10688 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10692 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
10698 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10699 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10700 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10702 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
10703 goto nla_put_failure
;
10705 genlmsg_end(msg
, hdr
);
10707 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10708 NL80211_MCGRP_MLME
, gfp
);
10712 genlmsg_cancel(msg
, hdr
);
10715 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
10717 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
10718 struct net_device
*netdev
, const u8
*addr
,
10719 enum nl80211_key_type key_type
, int key_id
,
10720 const u8
*tsc
, gfp_t gfp
)
10722 struct sk_buff
*msg
;
10725 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10729 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
10735 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10736 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10737 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
10738 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
10740 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
10741 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
10742 goto nla_put_failure
;
10744 genlmsg_end(msg
, hdr
);
10746 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10747 NL80211_MCGRP_MLME
, gfp
);
10751 genlmsg_cancel(msg
, hdr
);
10755 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
10756 struct ieee80211_channel
*channel_before
,
10757 struct ieee80211_channel
*channel_after
)
10759 struct sk_buff
*msg
;
10761 struct nlattr
*nl_freq
;
10763 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
10767 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
10774 * Since we are applying the beacon hint to a wiphy we know its
10775 * wiphy_idx is valid
10777 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
10778 goto nla_put_failure
;
10781 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
10783 goto nla_put_failure
;
10784 if (nl80211_msg_put_channel(msg
, channel_before
, false))
10785 goto nla_put_failure
;
10786 nla_nest_end(msg
, nl_freq
);
10789 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
10791 goto nla_put_failure
;
10792 if (nl80211_msg_put_channel(msg
, channel_after
, false))
10793 goto nla_put_failure
;
10794 nla_nest_end(msg
, nl_freq
);
10796 genlmsg_end(msg
, hdr
);
10799 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
10800 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
10806 genlmsg_cancel(msg
, hdr
);
10810 static void nl80211_send_remain_on_chan_event(
10811 int cmd
, struct cfg80211_registered_device
*rdev
,
10812 struct wireless_dev
*wdev
, u64 cookie
,
10813 struct ieee80211_channel
*chan
,
10814 unsigned int duration
, gfp_t gfp
)
10816 struct sk_buff
*msg
;
10819 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10823 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10829 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10830 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10831 wdev
->netdev
->ifindex
)) ||
10832 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10833 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
10834 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10835 NL80211_CHAN_NO_HT
) ||
10836 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
10837 goto nla_put_failure
;
10839 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
10840 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
10841 goto nla_put_failure
;
10843 genlmsg_end(msg
, hdr
);
10845 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10846 NL80211_MCGRP_MLME
, gfp
);
10850 genlmsg_cancel(msg
, hdr
);
10854 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
10855 struct ieee80211_channel
*chan
,
10856 unsigned int duration
, gfp_t gfp
)
10858 struct wiphy
*wiphy
= wdev
->wiphy
;
10859 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10861 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
10862 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
10863 rdev
, wdev
, cookie
, chan
,
10866 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
10868 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
10869 struct ieee80211_channel
*chan
,
10872 struct wiphy
*wiphy
= wdev
->wiphy
;
10873 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10875 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
10876 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
10877 rdev
, wdev
, cookie
, chan
, 0, gfp
);
10879 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
10881 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
10882 struct station_info
*sinfo
, gfp_t gfp
)
10884 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10885 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10886 struct sk_buff
*msg
;
10888 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
10890 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10894 if (nl80211_send_station(msg
, 0, 0, 0,
10895 rdev
, dev
, mac_addr
, sinfo
) < 0) {
10900 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10901 NL80211_MCGRP_MLME
, gfp
);
10903 EXPORT_SYMBOL(cfg80211_new_sta
);
10905 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
10907 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10908 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10909 struct sk_buff
*msg
;
10912 trace_cfg80211_del_sta(dev
, mac_addr
);
10914 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10918 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
10924 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10925 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
10926 goto nla_put_failure
;
10928 genlmsg_end(msg
, hdr
);
10930 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10931 NL80211_MCGRP_MLME
, gfp
);
10935 genlmsg_cancel(msg
, hdr
);
10938 EXPORT_SYMBOL(cfg80211_del_sta
);
10940 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10941 enum nl80211_connect_failed_reason reason
,
10944 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10945 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10946 struct sk_buff
*msg
;
10949 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10953 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10959 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10960 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10961 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10962 goto nla_put_failure
;
10964 genlmsg_end(msg
, hdr
);
10966 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
10967 NL80211_MCGRP_MLME
, gfp
);
10971 genlmsg_cancel(msg
, hdr
);
10974 EXPORT_SYMBOL(cfg80211_conn_failed
);
10976 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10977 const u8
*addr
, gfp_t gfp
)
10979 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10980 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
10981 struct sk_buff
*msg
;
10983 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10988 msg
= nlmsg_new(100, gfp
);
10992 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10998 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10999 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11000 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
11001 goto nla_put_failure
;
11003 genlmsg_end(msg
, hdr
);
11004 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
11008 genlmsg_cancel(msg
, hdr
);
11013 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
11014 const u8
*addr
, gfp_t gfp
)
11016 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11019 trace_cfg80211_rx_spurious_frame(dev
, addr
);
11021 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11022 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
11023 trace_cfg80211_return_bool(false);
11026 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
11028 trace_cfg80211_return_bool(ret
);
11031 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
11033 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
11034 const u8
*addr
, gfp_t gfp
)
11036 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11039 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
11041 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11042 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
11043 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
11044 trace_cfg80211_return_bool(false);
11047 ret
= __nl80211_unexpected_frame(dev
,
11048 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
11050 trace_cfg80211_return_bool(ret
);
11053 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
11055 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
11056 struct wireless_dev
*wdev
, u32 nlportid
,
11057 int freq
, int sig_dbm
,
11058 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
11060 struct net_device
*netdev
= wdev
->netdev
;
11061 struct sk_buff
*msg
;
11064 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11068 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
11074 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11075 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11076 netdev
->ifindex
)) ||
11077 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
11078 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
11080 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
11081 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
11083 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
11084 goto nla_put_failure
;
11086 genlmsg_end(msg
, hdr
);
11088 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
11091 genlmsg_cancel(msg
, hdr
);
11096 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
11097 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
11099 struct wiphy
*wiphy
= wdev
->wiphy
;
11100 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11101 struct net_device
*netdev
= wdev
->netdev
;
11102 struct sk_buff
*msg
;
11105 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
11107 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11111 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
11117 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11118 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11119 netdev
->ifindex
)) ||
11120 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
11121 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
11122 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
11123 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
11124 goto nla_put_failure
;
11126 genlmsg_end(msg
, hdr
);
11128 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11129 NL80211_MCGRP_MLME
, gfp
);
11133 genlmsg_cancel(msg
, hdr
);
11136 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
11138 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
11139 enum nl80211_cqm_rssi_threshold_event rssi_event
,
11142 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11143 struct wiphy
*wiphy
= wdev
->wiphy
;
11144 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11145 struct sk_buff
*msg
;
11146 struct nlattr
*pinfoattr
;
11149 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
11151 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11155 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
11161 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11162 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
11163 goto nla_put_failure
;
11165 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
11167 goto nla_put_failure
;
11169 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
11171 goto nla_put_failure
;
11173 nla_nest_end(msg
, pinfoattr
);
11175 genlmsg_end(msg
, hdr
);
11177 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11178 NL80211_MCGRP_MLME
, gfp
);
11182 genlmsg_cancel(msg
, hdr
);
11185 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
11187 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
11188 struct net_device
*netdev
, const u8
*bssid
,
11189 const u8
*replay_ctr
, gfp_t gfp
)
11191 struct sk_buff
*msg
;
11192 struct nlattr
*rekey_attr
;
11195 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11199 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
11205 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11206 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11207 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
11208 goto nla_put_failure
;
11210 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
11212 goto nla_put_failure
;
11214 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
11215 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
11216 goto nla_put_failure
;
11218 nla_nest_end(msg
, rekey_attr
);
11220 genlmsg_end(msg
, hdr
);
11222 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11223 NL80211_MCGRP_MLME
, gfp
);
11227 genlmsg_cancel(msg
, hdr
);
11231 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
11232 const u8
*replay_ctr
, gfp_t gfp
)
11234 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11235 struct wiphy
*wiphy
= wdev
->wiphy
;
11236 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11238 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
11239 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
11241 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
11244 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
11245 struct net_device
*netdev
, int index
,
11246 const u8
*bssid
, bool preauth
, gfp_t gfp
)
11248 struct sk_buff
*msg
;
11249 struct nlattr
*attr
;
11252 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11256 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
11262 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11263 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11264 goto nla_put_failure
;
11266 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
11268 goto nla_put_failure
;
11270 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
11271 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
11273 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
11274 goto nla_put_failure
;
11276 nla_nest_end(msg
, attr
);
11278 genlmsg_end(msg
, hdr
);
11280 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11281 NL80211_MCGRP_MLME
, gfp
);
11285 genlmsg_cancel(msg
, hdr
);
11289 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
11290 const u8
*bssid
, bool preauth
, gfp_t gfp
)
11292 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11293 struct wiphy
*wiphy
= wdev
->wiphy
;
11294 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11296 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
11297 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
11299 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
11301 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
11302 struct net_device
*netdev
,
11303 struct cfg80211_chan_def
*chandef
,
11306 struct sk_buff
*msg
;
11309 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11313 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
11319 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11320 goto nla_put_failure
;
11322 if (nl80211_send_chandef(msg
, chandef
))
11323 goto nla_put_failure
;
11325 genlmsg_end(msg
, hdr
);
11327 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11328 NL80211_MCGRP_MLME
, gfp
);
11332 genlmsg_cancel(msg
, hdr
);
11336 void cfg80211_ch_switch_notify(struct net_device
*dev
,
11337 struct cfg80211_chan_def
*chandef
)
11339 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11340 struct wiphy
*wiphy
= wdev
->wiphy
;
11341 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11343 ASSERT_WDEV_LOCK(wdev
);
11345 trace_cfg80211_ch_switch_notify(dev
, chandef
);
11347 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
11348 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
11349 wdev
->iftype
!= NL80211_IFTYPE_ADHOC
&&
11350 wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
11353 wdev
->chandef
= *chandef
;
11354 wdev
->preset_chandef
= *chandef
;
11355 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
11357 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
11359 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
11360 const u8
*peer
, u32 num_packets
,
11361 u32 rate
, u32 intvl
, gfp_t gfp
)
11363 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11364 struct wiphy
*wiphy
= wdev
->wiphy
;
11365 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11366 struct sk_buff
*msg
;
11367 struct nlattr
*pinfoattr
;
11370 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
11374 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
11380 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11381 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11382 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
11383 goto nla_put_failure
;
11385 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
11387 goto nla_put_failure
;
11389 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
11390 goto nla_put_failure
;
11392 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
11393 goto nla_put_failure
;
11395 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
11396 goto nla_put_failure
;
11398 nla_nest_end(msg
, pinfoattr
);
11400 genlmsg_end(msg
, hdr
);
11402 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11403 NL80211_MCGRP_MLME
, gfp
);
11407 genlmsg_cancel(msg
, hdr
);
11410 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
11413 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
11414 const struct cfg80211_chan_def
*chandef
,
11415 enum nl80211_radar_event event
,
11416 struct net_device
*netdev
, gfp_t gfp
)
11418 struct sk_buff
*msg
;
11421 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11425 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
11431 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
11432 goto nla_put_failure
;
11434 /* NOP and radar events don't need a netdev parameter */
11436 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
11438 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11439 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11440 goto nla_put_failure
;
11443 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
11444 goto nla_put_failure
;
11446 if (nl80211_send_chandef(msg
, chandef
))
11447 goto nla_put_failure
;
11449 genlmsg_end(msg
, hdr
);
11451 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11452 NL80211_MCGRP_MLME
, gfp
);
11456 genlmsg_cancel(msg
, hdr
);
11460 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
11461 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
11463 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11464 struct wiphy
*wiphy
= wdev
->wiphy
;
11465 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11466 struct sk_buff
*msg
;
11467 struct nlattr
*pinfoattr
;
11470 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
11472 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11476 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
11482 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11483 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11484 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
11485 goto nla_put_failure
;
11487 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
11489 goto nla_put_failure
;
11491 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
11492 goto nla_put_failure
;
11494 nla_nest_end(msg
, pinfoattr
);
11496 genlmsg_end(msg
, hdr
);
11498 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11499 NL80211_MCGRP_MLME
, gfp
);
11503 genlmsg_cancel(msg
, hdr
);
11506 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
11508 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
11509 u64 cookie
, bool acked
, gfp_t gfp
)
11511 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11512 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
11513 struct sk_buff
*msg
;
11516 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
11518 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11523 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
11529 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11530 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11531 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
11532 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
11533 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
11534 goto nla_put_failure
;
11536 genlmsg_end(msg
, hdr
);
11538 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11539 NL80211_MCGRP_MLME
, gfp
);
11543 genlmsg_cancel(msg
, hdr
);
11546 EXPORT_SYMBOL(cfg80211_probe_status
);
11548 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
11549 const u8
*frame
, size_t len
,
11550 int freq
, int sig_dbm
)
11552 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11553 struct sk_buff
*msg
;
11555 struct cfg80211_beacon_registration
*reg
;
11557 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
11559 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11560 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
11561 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
11563 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11567 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
11569 goto nla_put_failure
;
11571 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11573 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
11575 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
11576 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
11577 goto nla_put_failure
;
11579 genlmsg_end(msg
, hdr
);
11581 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
11583 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11587 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11589 genlmsg_cancel(msg
, hdr
);
11592 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
11595 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
11596 struct cfg80211_wowlan_wakeup
*wakeup
,
11599 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
11600 struct sk_buff
*msg
;
11604 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
11607 size
+= wakeup
->packet_present_len
;
11609 msg
= nlmsg_new(size
, gfp
);
11613 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
11617 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11618 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11621 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11622 wdev
->netdev
->ifindex
))
11626 struct nlattr
*reasons
;
11628 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
11632 if (wakeup
->disconnect
&&
11633 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
11635 if (wakeup
->magic_pkt
&&
11636 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
11638 if (wakeup
->gtk_rekey_failure
&&
11639 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
11641 if (wakeup
->eap_identity_req
&&
11642 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
11644 if (wakeup
->four_way_handshake
&&
11645 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
11647 if (wakeup
->rfkill_release
&&
11648 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
11651 if (wakeup
->pattern_idx
>= 0 &&
11652 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
11653 wakeup
->pattern_idx
))
11656 if (wakeup
->tcp_match
&&
11657 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
11660 if (wakeup
->tcp_connlost
&&
11661 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
11664 if (wakeup
->tcp_nomoretokens
&&
11666 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
11669 if (wakeup
->packet
) {
11670 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
11671 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
11673 if (!wakeup
->packet_80211
) {
11675 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
11677 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
11680 if (wakeup
->packet_len
&&
11681 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
11684 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
11689 nla_nest_end(msg
, reasons
);
11692 genlmsg_end(msg
, hdr
);
11694 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11695 NL80211_MCGRP_MLME
, gfp
);
11701 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
11704 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
11705 enum nl80211_tdls_operation oper
,
11706 u16 reason_code
, gfp_t gfp
)
11708 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11709 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
11710 struct sk_buff
*msg
;
11713 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
11716 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11720 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
11726 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11727 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11728 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
11729 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
11730 (reason_code
> 0 &&
11731 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
11732 goto nla_put_failure
;
11734 genlmsg_end(msg
, hdr
);
11736 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11737 NL80211_MCGRP_MLME
, gfp
);
11741 genlmsg_cancel(msg
, hdr
);
11744 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
11746 static int nl80211_netlink_notify(struct notifier_block
* nb
,
11747 unsigned long state
,
11750 struct netlink_notify
*notify
= _notify
;
11751 struct cfg80211_registered_device
*rdev
;
11752 struct wireless_dev
*wdev
;
11753 struct cfg80211_beacon_registration
*reg
, *tmp
;
11755 if (state
!= NETLINK_URELEASE
)
11756 return NOTIFY_DONE
;
11760 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
11761 bool schedule_destroy_work
= false;
11763 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
) {
11764 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
11766 if (wdev
->owner_nlportid
== notify
->portid
)
11767 schedule_destroy_work
= true;
11770 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11771 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
11773 if (reg
->nlportid
== notify
->portid
) {
11774 list_del(®
->list
);
11779 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11781 if (schedule_destroy_work
) {
11782 struct cfg80211_iface_destroy
*destroy
;
11784 destroy
= kzalloc(sizeof(*destroy
), GFP_ATOMIC
);
11786 destroy
->nlportid
= notify
->portid
;
11787 spin_lock(&rdev
->destroy_list_lock
);
11788 list_add(&destroy
->list
, &rdev
->destroy_list
);
11789 spin_unlock(&rdev
->destroy_list_lock
);
11790 schedule_work(&rdev
->destroy_work
);
11800 static struct notifier_block nl80211_netlink_notifier
= {
11801 .notifier_call
= nl80211_netlink_notify
,
11804 void cfg80211_ft_event(struct net_device
*netdev
,
11805 struct cfg80211_ft_event_params
*ft_event
)
11807 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
11808 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11809 struct sk_buff
*msg
;
11812 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
11814 if (!ft_event
->target_ap
)
11817 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11821 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
11825 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11826 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11827 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
11830 if (ft_event
->ies
&&
11831 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
11833 if (ft_event
->ric_ies
&&
11834 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
11835 ft_event
->ric_ies
))
11838 genlmsg_end(msg
, hdr
);
11840 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11841 NL80211_MCGRP_MLME
, GFP_KERNEL
);
11846 EXPORT_SYMBOL(cfg80211_ft_event
);
11848 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
11850 struct cfg80211_registered_device
*rdev
;
11851 struct sk_buff
*msg
;
11855 rdev
= wiphy_to_rdev(wdev
->wiphy
);
11856 if (!rdev
->crit_proto_nlportid
)
11859 nlportid
= rdev
->crit_proto_nlportid
;
11860 rdev
->crit_proto_nlportid
= 0;
11862 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11866 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
11868 goto nla_put_failure
;
11870 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11871 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11872 goto nla_put_failure
;
11874 genlmsg_end(msg
, hdr
);
11876 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
11881 genlmsg_cancel(msg
, hdr
);
11885 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
11887 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
11889 struct wiphy
*wiphy
= wdev
->wiphy
;
11890 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11891 struct sk_buff
*msg
;
11894 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11898 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
11902 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11903 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
11904 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11907 genlmsg_end(msg
, hdr
);
11909 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
11910 NL80211_MCGRP_MLME
, GFP_KERNEL
);
11916 /* initialisation/exit functions */
11918 int nl80211_init(void)
11922 err
= genl_register_family_with_ops_groups(&nl80211_fam
, nl80211_ops
,
11927 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
11933 genl_unregister_family(&nl80211_fam
);
11937 void nl80211_exit(void)
11939 netlink_unregister_notifier(&nl80211_netlink_notifier
);
11940 genl_unregister_family(&nl80211_fam
);