2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright 2015 Intel Deutschland GmbH
10 #include <linux/module.h>
11 #include <linux/err.h>
12 #include <linux/slab.h>
13 #include <linux/list.h>
14 #include <linux/if_ether.h>
15 #include <linux/ieee80211.h>
16 #include <linux/nl80211.h>
17 #include <linux/rtnetlink.h>
18 #include <linux/netlink.h>
19 #include <linux/etherdevice.h>
20 #include <net/net_namespace.h>
21 #include <net/genetlink.h>
22 #include <net/cfg80211.h>
24 #include <net/inet_connection_sock.h>
30 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
31 struct genl_info
*info
,
32 struct cfg80211_crypto_settings
*settings
,
35 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
37 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
38 struct genl_info
*info
);
40 /* the netlink family */
41 static struct genl_family nl80211_fam
= {
42 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
43 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
44 .hdrsize
= 0, /* no private header */
45 .version
= 1, /* no particular meaning now */
46 .maxattr
= NL80211_ATTR_MAX
,
48 .pre_doit
= nl80211_pre_doit
,
49 .post_doit
= nl80211_post_doit
,
52 /* multicast groups */
53 enum nl80211_multicast_groups
{
56 NL80211_MCGRP_REGULATORY
,
59 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
62 static const struct genl_multicast_group nl80211_mcgrps
[] = {
63 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
64 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
65 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
66 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
67 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
68 #ifdef CONFIG_NL80211_TESTMODE
69 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
73 /* returns ERR_PTR values */
74 static struct wireless_dev
*
75 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
77 struct cfg80211_registered_device
*rdev
;
78 struct wireless_dev
*result
= NULL
;
79 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
80 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
87 if (!have_ifidx
&& !have_wdev_id
)
88 return ERR_PTR(-EINVAL
);
91 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
93 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
94 wiphy_idx
= wdev_id
>> 32;
97 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
98 struct wireless_dev
*wdev
;
100 if (wiphy_net(&rdev
->wiphy
) != netns
)
103 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
106 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
107 if (have_ifidx
&& wdev
->netdev
&&
108 wdev
->netdev
->ifindex
== ifidx
) {
112 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
124 return ERR_PTR(-ENODEV
);
127 static struct cfg80211_registered_device
*
128 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
130 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
131 struct net_device
*netdev
;
135 if (!attrs
[NL80211_ATTR_WIPHY
] &&
136 !attrs
[NL80211_ATTR_IFINDEX
] &&
137 !attrs
[NL80211_ATTR_WDEV
])
138 return ERR_PTR(-EINVAL
);
140 if (attrs
[NL80211_ATTR_WIPHY
])
141 rdev
= cfg80211_rdev_by_wiphy_idx(
142 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
144 if (attrs
[NL80211_ATTR_WDEV
]) {
145 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
146 struct wireless_dev
*wdev
;
149 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
151 /* make sure wdev exists */
152 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
153 if (wdev
->identifier
!= (u32
)wdev_id
)
162 if (rdev
&& tmp
!= rdev
)
163 return ERR_PTR(-EINVAL
);
168 if (attrs
[NL80211_ATTR_IFINDEX
]) {
169 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
170 netdev
= __dev_get_by_index(netns
, ifindex
);
172 if (netdev
->ieee80211_ptr
)
174 netdev
->ieee80211_ptr
->wiphy
);
178 /* not wireless device -- return error */
180 return ERR_PTR(-EINVAL
);
182 /* mismatch -- return error */
183 if (rdev
&& tmp
!= rdev
)
184 return ERR_PTR(-EINVAL
);
191 return ERR_PTR(-ENODEV
);
193 if (netns
!= wiphy_net(&rdev
->wiphy
))
194 return ERR_PTR(-ENODEV
);
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
206 static struct cfg80211_registered_device
*
207 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
209 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
212 /* policy for the attributes */
213 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
214 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
215 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
217 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
219 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
221 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
222 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
225 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
226 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
230 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
232 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
233 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
236 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
237 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
239 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
240 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
241 .len
= WLAN_MAX_KEY_LEN
},
242 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
243 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
244 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
245 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
246 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
248 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
249 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
251 .len
= IEEE80211_MAX_DATA_LEN
},
252 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
253 .len
= IEEE80211_MAX_DATA_LEN
},
254 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
255 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
256 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
257 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
258 .len
= NL80211_MAX_SUPP_RATES
},
259 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
260 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
261 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
262 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
263 .len
= IEEE80211_MAX_MESH_ID_LEN
},
264 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
266 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
267 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
269 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
273 .len
= NL80211_MAX_SUPP_RATES
},
274 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
276 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
277 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
279 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
281 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
282 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
283 .len
= IEEE80211_MAX_DATA_LEN
},
284 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
285 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
287 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
288 .len
= IEEE80211_MAX_SSID_LEN
},
289 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
290 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
291 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
292 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
293 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
294 [NL80211_ATTR_STA_FLAGS2
] = {
295 .len
= sizeof(struct nl80211_sta_flag_update
),
297 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
302 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
303 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
305 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
306 .len
= WLAN_PMKID_LEN
},
307 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
308 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
309 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
310 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
311 .len
= IEEE80211_MAX_DATA_LEN
},
312 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
313 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
314 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
315 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
316 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
317 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
318 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
319 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
320 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
323 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
324 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
325 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
326 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
327 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
328 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
329 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
330 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
331 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
332 .len
= IEEE80211_MAX_DATA_LEN
},
333 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
334 .len
= IEEE80211_MAX_DATA_LEN
},
335 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
336 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
337 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
338 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
339 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
340 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
341 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
342 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
343 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
346 .len
= IEEE80211_MAX_DATA_LEN
},
347 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
349 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
350 .len
= NL80211_HT_CAPABILITY_LEN
352 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
353 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
354 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
355 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
356 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
357 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
358 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
359 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
360 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
361 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
362 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
363 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
364 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
365 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
366 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
367 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
368 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
369 .len
= NL80211_VHT_CAPABILITY_LEN
,
371 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
372 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
373 .len
= IEEE80211_MAX_DATA_LEN
},
374 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
375 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
377 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
378 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
379 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
382 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
383 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
384 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
385 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
386 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
387 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
388 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
389 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
390 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
391 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
392 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
393 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
394 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
395 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
396 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
397 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
398 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
399 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
401 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
402 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
403 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
406 /* policy for the key attributes */
407 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
408 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
409 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
410 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
411 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
412 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
413 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
414 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
415 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
418 /* policy for the key default flags */
419 static const struct nla_policy
420 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
421 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
422 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
425 /* policy for WoWLAN attributes */
426 static const struct nla_policy
427 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
428 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
429 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
430 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
431 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
432 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
433 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
434 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
435 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
436 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
437 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
440 static const struct nla_policy
441 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
442 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
443 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
444 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
445 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
446 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
448 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
449 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
451 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
452 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
454 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
455 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
456 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
459 /* policy for coalesce rule attributes */
460 static const struct nla_policy
461 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
462 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
463 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
464 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
467 /* policy for GTK rekey offload attributes */
468 static const struct nla_policy
469 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
470 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
471 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
472 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
475 static const struct nla_policy
476 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
477 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
478 .len
= IEEE80211_MAX_SSID_LEN
},
479 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
482 static const struct nla_policy
483 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
484 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
485 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
488 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
489 struct netlink_callback
*cb
,
490 struct cfg80211_registered_device
**rdev
,
491 struct wireless_dev
**wdev
)
498 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
499 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
504 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
505 nl80211_fam
.attrbuf
);
507 err
= PTR_ERR(*wdev
);
510 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
511 /* 0 is the first index - add 1 to parse only once */
512 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
513 cb
->args
[1] = (*wdev
)->identifier
;
515 /* subtract the 1 again here */
516 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
517 struct wireless_dev
*tmp
;
523 *rdev
= wiphy_to_rdev(wiphy
);
526 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
527 if (tmp
->identifier
== cb
->args
[1]) {
545 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
551 static bool is_valid_ie_attr(const struct nlattr
*attr
)
559 pos
= nla_data(attr
);
580 /* message building helper */
581 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
584 /* since there is no private header just add the generic one */
585 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
588 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
589 struct ieee80211_channel
*chan
,
592 /* Some channels must be completely excluded from the
593 * list to protect old user-space tools from breaking
595 if (!large
&& chan
->flags
&
596 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
599 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
601 goto nla_put_failure
;
603 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
604 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
605 goto nla_put_failure
;
606 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
607 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
608 goto nla_put_failure
;
609 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
610 goto nla_put_failure
;
612 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
613 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
614 goto nla_put_failure
;
618 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
620 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
622 goto nla_put_failure
;
623 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
625 goto nla_put_failure
;
627 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
629 goto nla_put_failure
;
634 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
635 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
636 goto nla_put_failure
;
637 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
638 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
639 goto nla_put_failure
;
640 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
641 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
642 goto nla_put_failure
;
643 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
644 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
645 goto nla_put_failure
;
646 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
647 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
648 goto nla_put_failure
;
649 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
650 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
651 goto nla_put_failure
;
652 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
653 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
654 goto nla_put_failure
;
655 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
656 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
657 goto nla_put_failure
;
660 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
661 DBM_TO_MBM(chan
->max_power
)))
662 goto nla_put_failure
;
670 /* netlink command implementations */
677 bool def_uni
, def_multi
;
680 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
682 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
683 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
688 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
689 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
698 if (tb
[NL80211_KEY_IDX
])
699 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
701 if (tb
[NL80211_KEY_DATA
]) {
702 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
703 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
706 if (tb
[NL80211_KEY_SEQ
]) {
707 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
708 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
711 if (tb
[NL80211_KEY_CIPHER
])
712 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
714 if (tb
[NL80211_KEY_TYPE
]) {
715 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
716 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
720 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
721 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
722 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
723 tb
[NL80211_KEY_DEFAULT_TYPES
],
724 nl80211_key_default_policy
);
728 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
729 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
735 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
737 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
738 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
739 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
742 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
743 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
744 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
747 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
748 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
750 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
751 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
753 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
754 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
763 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
764 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
765 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
769 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
770 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
771 int err
= nla_parse_nested(
772 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
773 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
774 nl80211_key_default_policy
);
778 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
779 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
785 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
789 memset(k
, 0, sizeof(*k
));
793 if (info
->attrs
[NL80211_ATTR_KEY
])
794 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
796 err
= nl80211_parse_key_old(info
, k
);
801 if (k
->def
&& k
->defmgmt
)
805 if (k
->def_uni
|| !k
->def_multi
)
811 if (k
->idx
< 4 || k
->idx
> 5)
814 if (k
->idx
< 0 || k
->idx
> 3)
817 if (k
->idx
< 0 || k
->idx
> 5)
825 static struct cfg80211_cached_keys
*
826 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
827 struct nlattr
*keys
, bool *no_ht
)
829 struct key_parse parse
;
831 struct cfg80211_cached_keys
*result
;
832 int rem
, err
, def
= 0;
834 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
836 return ERR_PTR(-ENOMEM
);
839 result
->defmgmt
= -1;
841 nla_for_each_nested(key
, keys
, rem
) {
842 memset(&parse
, 0, sizeof(parse
));
845 err
= nl80211_parse_key_new(key
, &parse
);
851 if (parse
.idx
< 0 || parse
.idx
> 4)
857 result
->def
= parse
.idx
;
858 if (!parse
.def_uni
|| !parse
.def_multi
)
860 } else if (parse
.defmgmt
)
862 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
863 parse
.idx
, false, NULL
);
866 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
867 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
868 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
869 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
871 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
872 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
884 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
886 ASSERT_WDEV_LOCK(wdev
);
888 switch (wdev
->iftype
) {
889 case NL80211_IFTYPE_AP
:
890 case NL80211_IFTYPE_AP_VLAN
:
891 case NL80211_IFTYPE_P2P_GO
:
892 case NL80211_IFTYPE_MESH_POINT
:
894 case NL80211_IFTYPE_ADHOC
:
895 case NL80211_IFTYPE_STATION
:
896 case NL80211_IFTYPE_P2P_CLIENT
:
897 if (!wdev
->current_bss
)
900 case NL80211_IFTYPE_UNSPECIFIED
:
901 case NL80211_IFTYPE_OCB
:
902 case NL80211_IFTYPE_MONITOR
:
903 case NL80211_IFTYPE_P2P_DEVICE
:
904 case NL80211_IFTYPE_WDS
:
905 case NUM_NL80211_IFTYPES
:
912 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
915 struct ieee80211_channel
*chan
;
919 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
920 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
925 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
927 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
931 goto nla_put_failure
;
935 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
936 goto nla_put_failure
;
941 nla_nest_end(msg
, nl_modes
);
948 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
952 struct nlattr
*nl_combis
;
955 nl_combis
= nla_nest_start(msg
,
956 NL80211_ATTR_INTERFACE_COMBINATIONS
);
958 goto nla_put_failure
;
960 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
961 const struct ieee80211_iface_combination
*c
;
962 struct nlattr
*nl_combi
, *nl_limits
;
964 c
= &wiphy
->iface_combinations
[i
];
966 nl_combi
= nla_nest_start(msg
, i
+ 1);
968 goto nla_put_failure
;
970 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
972 goto nla_put_failure
;
974 for (j
= 0; j
< c
->n_limits
; j
++) {
975 struct nlattr
*nl_limit
;
977 nl_limit
= nla_nest_start(msg
, j
+ 1);
979 goto nla_put_failure
;
980 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
982 goto nla_put_failure
;
983 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
985 goto nla_put_failure
;
986 nla_nest_end(msg
, nl_limit
);
989 nla_nest_end(msg
, nl_limits
);
991 if (c
->beacon_int_infra_match
&&
992 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
993 goto nla_put_failure
;
994 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
995 c
->num_different_channels
) ||
996 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
998 goto nla_put_failure
;
1000 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
1001 c
->radar_detect_widths
) ||
1002 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
1003 c
->radar_detect_regions
)))
1004 goto nla_put_failure
;
1006 nla_nest_end(msg
, nl_combi
);
1009 nla_nest_end(msg
, nl_combis
);
1017 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1018 struct sk_buff
*msg
)
1020 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1021 struct nlattr
*nl_tcp
;
1026 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1030 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1031 tcp
->data_payload_max
))
1034 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1035 tcp
->data_payload_max
))
1038 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1041 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1042 sizeof(*tcp
->tok
), tcp
->tok
))
1045 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1046 tcp
->data_interval_max
))
1049 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1050 tcp
->wake_payload_max
))
1053 nla_nest_end(msg
, nl_tcp
);
1057 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1058 struct cfg80211_registered_device
*rdev
,
1061 struct nlattr
*nl_wowlan
;
1063 if (!rdev
->wiphy
.wowlan
)
1066 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1070 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1071 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1072 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1073 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1074 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1075 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1076 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1077 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1078 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1079 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1080 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1081 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1082 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1083 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1084 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1085 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1088 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1089 struct nl80211_pattern_support pat
= {
1090 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1091 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1092 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1093 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1096 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1101 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1102 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1103 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1106 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1109 nla_nest_end(msg
, nl_wowlan
);
1115 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1116 struct cfg80211_registered_device
*rdev
)
1118 struct nl80211_coalesce_rule_support rule
;
1120 if (!rdev
->wiphy
.coalesce
)
1123 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1124 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1125 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1126 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1127 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1128 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1130 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1136 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1137 struct ieee80211_supported_band
*sband
)
1139 struct nlattr
*nl_rates
, *nl_rate
;
1140 struct ieee80211_rate
*rate
;
1144 if (sband
->ht_cap
.ht_supported
&&
1145 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1146 sizeof(sband
->ht_cap
.mcs
),
1147 &sband
->ht_cap
.mcs
) ||
1148 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1149 sband
->ht_cap
.cap
) ||
1150 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1151 sband
->ht_cap
.ampdu_factor
) ||
1152 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1153 sband
->ht_cap
.ampdu_density
)))
1157 if (sband
->vht_cap
.vht_supported
&&
1158 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1159 sizeof(sband
->vht_cap
.vht_mcs
),
1160 &sband
->vht_cap
.vht_mcs
) ||
1161 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1162 sband
->vht_cap
.cap
)))
1166 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1170 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1171 nl_rate
= nla_nest_start(msg
, i
);
1175 rate
= &sband
->bitrates
[i
];
1176 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1179 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1181 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1184 nla_nest_end(msg
, nl_rate
);
1187 nla_nest_end(msg
, nl_rates
);
1193 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1194 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1197 struct nlattr
*nl_ftypes
, *nl_ifs
;
1198 enum nl80211_iftype ift
;
1204 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1208 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1209 nl_ftypes
= nla_nest_start(msg
, ift
);
1213 stypes
= mgmt_stypes
[ift
].tx
;
1216 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1217 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1222 nla_nest_end(msg
, nl_ftypes
);
1225 nla_nest_end(msg
, nl_ifs
);
1227 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1231 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1232 nl_ftypes
= nla_nest_start(msg
, ift
);
1236 stypes
= mgmt_stypes
[ift
].rx
;
1239 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1240 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1245 nla_nest_end(msg
, nl_ftypes
);
1247 nla_nest_end(msg
, nl_ifs
);
1252 struct nl80211_dump_wiphy_state
{
1255 long split_start
, band_start
, chan_start
;
1259 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1260 enum nl80211_commands cmd
,
1261 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1262 int flags
, struct nl80211_dump_wiphy_state
*state
)
1265 struct nlattr
*nl_bands
, *nl_band
;
1266 struct nlattr
*nl_freqs
, *nl_freq
;
1267 struct nlattr
*nl_cmds
;
1268 enum ieee80211_band band
;
1269 struct ieee80211_channel
*chan
;
1271 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1272 rdev
->wiphy
.mgmt_stypes
;
1275 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1279 if (WARN_ON(!state
))
1282 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1283 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1284 wiphy_name(&rdev
->wiphy
)) ||
1285 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1286 cfg80211_rdev_list_generation
))
1287 goto nla_put_failure
;
1289 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1292 switch (state
->split_start
) {
1294 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1295 rdev
->wiphy
.retry_short
) ||
1296 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1297 rdev
->wiphy
.retry_long
) ||
1298 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1299 rdev
->wiphy
.frag_threshold
) ||
1300 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1301 rdev
->wiphy
.rts_threshold
) ||
1302 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1303 rdev
->wiphy
.coverage_class
) ||
1304 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1305 rdev
->wiphy
.max_scan_ssids
) ||
1306 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1307 rdev
->wiphy
.max_sched_scan_ssids
) ||
1308 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1309 rdev
->wiphy
.max_scan_ie_len
) ||
1310 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1311 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1312 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1313 rdev
->wiphy
.max_match_sets
) ||
1314 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1315 rdev
->wiphy
.max_sched_scan_plans
) ||
1316 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1317 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1318 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1319 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1320 goto nla_put_failure
;
1322 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1323 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1324 goto nla_put_failure
;
1325 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1326 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1327 goto nla_put_failure
;
1328 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1329 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1330 goto nla_put_failure
;
1331 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1332 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1333 goto nla_put_failure
;
1334 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1335 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1336 goto nla_put_failure
;
1337 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1338 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1339 goto nla_put_failure
;
1340 state
->split_start
++;
1344 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1345 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1346 rdev
->wiphy
.cipher_suites
))
1347 goto nla_put_failure
;
1349 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1350 rdev
->wiphy
.max_num_pmkids
))
1351 goto nla_put_failure
;
1353 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1354 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1355 goto nla_put_failure
;
1357 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1358 rdev
->wiphy
.available_antennas_tx
) ||
1359 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1360 rdev
->wiphy
.available_antennas_rx
))
1361 goto nla_put_failure
;
1363 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1364 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1365 rdev
->wiphy
.probe_resp_offload
))
1366 goto nla_put_failure
;
1368 if ((rdev
->wiphy
.available_antennas_tx
||
1369 rdev
->wiphy
.available_antennas_rx
) &&
1370 rdev
->ops
->get_antenna
) {
1371 u32 tx_ant
= 0, rx_ant
= 0;
1373 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1375 if (nla_put_u32(msg
,
1376 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1379 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1381 goto nla_put_failure
;
1385 state
->split_start
++;
1389 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1390 rdev
->wiphy
.interface_modes
))
1391 goto nla_put_failure
;
1392 state
->split_start
++;
1396 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1398 goto nla_put_failure
;
1400 for (band
= state
->band_start
;
1401 band
< IEEE80211_NUM_BANDS
; band
++) {
1402 struct ieee80211_supported_band
*sband
;
1404 sband
= rdev
->wiphy
.bands
[band
];
1409 nl_band
= nla_nest_start(msg
, band
);
1411 goto nla_put_failure
;
1413 switch (state
->chan_start
) {
1415 if (nl80211_send_band_rateinfo(msg
, sband
))
1416 goto nla_put_failure
;
1417 state
->chan_start
++;
1421 /* add frequencies */
1422 nl_freqs
= nla_nest_start(
1423 msg
, NL80211_BAND_ATTR_FREQS
);
1425 goto nla_put_failure
;
1427 for (i
= state
->chan_start
- 1;
1428 i
< sband
->n_channels
;
1430 nl_freq
= nla_nest_start(msg
, i
);
1432 goto nla_put_failure
;
1434 chan
= &sband
->channels
[i
];
1436 if (nl80211_msg_put_channel(
1439 goto nla_put_failure
;
1441 nla_nest_end(msg
, nl_freq
);
1445 if (i
< sband
->n_channels
)
1446 state
->chan_start
= i
+ 2;
1448 state
->chan_start
= 0;
1449 nla_nest_end(msg
, nl_freqs
);
1452 nla_nest_end(msg
, nl_band
);
1455 /* start again here */
1456 if (state
->chan_start
)
1461 nla_nest_end(msg
, nl_bands
);
1463 if (band
< IEEE80211_NUM_BANDS
)
1464 state
->band_start
= band
+ 1;
1466 state
->band_start
= 0;
1468 /* if bands & channels are done, continue outside */
1469 if (state
->band_start
== 0 && state
->chan_start
== 0)
1470 state
->split_start
++;
1474 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1476 goto nla_put_failure
;
1479 #define CMD(op, n) \
1481 if (rdev->ops->op) { \
1483 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1484 goto nla_put_failure; \
1488 CMD(add_virtual_intf
, NEW_INTERFACE
);
1489 CMD(change_virtual_intf
, SET_INTERFACE
);
1490 CMD(add_key
, NEW_KEY
);
1491 CMD(start_ap
, START_AP
);
1492 CMD(add_station
, NEW_STATION
);
1493 CMD(add_mpath
, NEW_MPATH
);
1494 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1495 CMD(change_bss
, SET_BSS
);
1496 CMD(auth
, AUTHENTICATE
);
1497 CMD(assoc
, ASSOCIATE
);
1498 CMD(deauth
, DEAUTHENTICATE
);
1499 CMD(disassoc
, DISASSOCIATE
);
1500 CMD(join_ibss
, JOIN_IBSS
);
1501 CMD(join_mesh
, JOIN_MESH
);
1502 CMD(set_pmksa
, SET_PMKSA
);
1503 CMD(del_pmksa
, DEL_PMKSA
);
1504 CMD(flush_pmksa
, FLUSH_PMKSA
);
1505 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1506 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1507 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1508 CMD(mgmt_tx
, FRAME
);
1509 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1510 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1512 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1513 goto nla_put_failure
;
1515 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1516 rdev
->ops
->join_mesh
) {
1518 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1519 goto nla_put_failure
;
1521 CMD(set_wds_peer
, SET_WDS_PEER
);
1522 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1523 CMD(tdls_mgmt
, TDLS_MGMT
);
1524 CMD(tdls_oper
, TDLS_OPER
);
1526 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1527 CMD(sched_scan_start
, START_SCHED_SCAN
);
1528 CMD(probe_client
, PROBE_CLIENT
);
1529 CMD(set_noack_map
, SET_NOACK_MAP
);
1530 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1532 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1533 goto nla_put_failure
;
1535 CMD(start_p2p_device
, START_P2P_DEVICE
);
1536 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1537 #ifdef CONFIG_NL80211_TESTMODE
1538 CMD(testmode_cmd
, TESTMODE
);
1541 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1542 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1543 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1544 CMD(channel_switch
, CHANNEL_SWITCH
);
1545 CMD(set_qos_map
, SET_QOS_MAP
);
1546 if (rdev
->wiphy
.features
&
1547 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1548 CMD(add_tx_ts
, ADD_TX_TS
);
1550 /* add into the if now */
1553 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1555 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1556 goto nla_put_failure
;
1559 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1561 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1562 goto nla_put_failure
;
1565 nla_nest_end(msg
, nl_cmds
);
1566 state
->split_start
++;
1570 if (rdev
->ops
->remain_on_channel
&&
1571 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1573 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1574 rdev
->wiphy
.max_remain_on_channel_duration
))
1575 goto nla_put_failure
;
1577 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1578 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1579 goto nla_put_failure
;
1581 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1582 goto nla_put_failure
;
1583 state
->split_start
++;
1588 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1589 goto nla_put_failure
;
1590 state
->split_start
++;
1594 state
->split_start
++;
1597 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1598 rdev
->wiphy
.software_iftypes
))
1599 goto nla_put_failure
;
1601 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1603 goto nla_put_failure
;
1605 state
->split_start
++;
1609 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1610 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1611 rdev
->wiphy
.ap_sme_capa
))
1612 goto nla_put_failure
;
1614 features
= rdev
->wiphy
.features
;
1616 * We can only add the per-channel limit information if the
1617 * dump is split, otherwise it makes it too big. Therefore
1618 * only advertise it in that case.
1621 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1622 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1623 goto nla_put_failure
;
1625 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1626 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1627 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1628 rdev
->wiphy
.ht_capa_mod_mask
))
1629 goto nla_put_failure
;
1631 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1632 rdev
->wiphy
.max_acl_mac_addrs
&&
1633 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1634 rdev
->wiphy
.max_acl_mac_addrs
))
1635 goto nla_put_failure
;
1638 * Any information below this point is only available to
1639 * applications that can deal with it being split. This
1640 * helps ensure that newly added capabilities don't break
1641 * older tools by overrunning their buffers.
1643 * We still increment split_start so that in the split
1644 * case we'll continue with more data in the next round,
1645 * but break unconditionally so unsplit data stops here.
1647 state
->split_start
++;
1650 if (rdev
->wiphy
.extended_capabilities
&&
1651 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1652 rdev
->wiphy
.extended_capabilities_len
,
1653 rdev
->wiphy
.extended_capabilities
) ||
1654 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1655 rdev
->wiphy
.extended_capabilities_len
,
1656 rdev
->wiphy
.extended_capabilities_mask
)))
1657 goto nla_put_failure
;
1659 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1660 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1661 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1662 rdev
->wiphy
.vht_capa_mod_mask
))
1663 goto nla_put_failure
;
1665 state
->split_start
++;
1668 if (nl80211_send_coalesce(msg
, rdev
))
1669 goto nla_put_failure
;
1671 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1672 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1673 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1674 goto nla_put_failure
;
1676 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1677 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1678 rdev
->wiphy
.max_ap_assoc_sta
))
1679 goto nla_put_failure
;
1681 state
->split_start
++;
1684 if (rdev
->wiphy
.n_vendor_commands
) {
1685 const struct nl80211_vendor_cmd_info
*info
;
1686 struct nlattr
*nested
;
1688 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1690 goto nla_put_failure
;
1692 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1693 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1694 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1695 goto nla_put_failure
;
1697 nla_nest_end(msg
, nested
);
1700 if (rdev
->wiphy
.n_vendor_events
) {
1701 const struct nl80211_vendor_cmd_info
*info
;
1702 struct nlattr
*nested
;
1704 nested
= nla_nest_start(msg
,
1705 NL80211_ATTR_VENDOR_EVENTS
);
1707 goto nla_put_failure
;
1709 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1710 info
= &rdev
->wiphy
.vendor_events
[i
];
1711 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1712 goto nla_put_failure
;
1714 nla_nest_end(msg
, nested
);
1716 state
->split_start
++;
1719 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1720 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1721 rdev
->wiphy
.max_num_csa_counters
))
1722 goto nla_put_failure
;
1724 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1725 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1726 goto nla_put_failure
;
1728 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1729 sizeof(rdev
->wiphy
.ext_features
),
1730 rdev
->wiphy
.ext_features
))
1731 goto nla_put_failure
;
1734 state
->split_start
= 0;
1738 genlmsg_end(msg
, hdr
);
1742 genlmsg_cancel(msg
, hdr
);
1746 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1747 struct netlink_callback
*cb
,
1748 struct nl80211_dump_wiphy_state
*state
)
1750 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1751 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1752 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1753 /* ignore parse errors for backward compatibility */
1757 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1758 if (tb
[NL80211_ATTR_WIPHY
])
1759 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1760 if (tb
[NL80211_ATTR_WDEV
])
1761 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1762 if (tb
[NL80211_ATTR_IFINDEX
]) {
1763 struct net_device
*netdev
;
1764 struct cfg80211_registered_device
*rdev
;
1765 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1767 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1770 if (netdev
->ieee80211_ptr
) {
1771 rdev
= wiphy_to_rdev(
1772 netdev
->ieee80211_ptr
->wiphy
);
1773 state
->filter_wiphy
= rdev
->wiphy_idx
;
1780 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1783 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1784 struct cfg80211_registered_device
*rdev
;
1788 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1793 state
->filter_wiphy
= -1;
1794 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1800 cb
->args
[0] = (long)state
;
1803 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1804 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1806 if (++idx
<= state
->start
)
1808 if (state
->filter_wiphy
!= -1 &&
1809 state
->filter_wiphy
!= rdev
->wiphy_idx
)
1811 /* attempt to fit multiple wiphy data chunks into the skb */
1813 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
1815 NETLINK_CB(cb
->skb
).portid
,
1817 NLM_F_MULTI
, state
);
1820 * If sending the wiphy data didn't fit (ENOBUFS
1821 * or EMSGSIZE returned), this SKB is still
1822 * empty (so it's not too big because another
1823 * wiphy dataset is already in the skb) and
1824 * we've not tried to adjust the dump allocation
1825 * yet ... then adjust the alloc size to be
1826 * bigger, and return 1 but with the empty skb.
1827 * This results in an empty message being RX'ed
1828 * in userspace, but that is ignored.
1830 * We can then retry with the larger buffer.
1832 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1833 !skb
->len
&& !state
->split
&&
1834 cb
->min_dump_alloc
< 4096) {
1835 cb
->min_dump_alloc
= 4096;
1836 state
->split_start
= 0;
1843 } while (state
->split_start
> 0);
1853 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1855 kfree((void *)cb
->args
[0]);
1859 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1861 struct sk_buff
*msg
;
1862 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1863 struct nl80211_dump_wiphy_state state
= {};
1865 msg
= nlmsg_new(4096, GFP_KERNEL
);
1869 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
1870 info
->snd_portid
, info
->snd_seq
, 0,
1876 return genlmsg_reply(msg
, info
);
1879 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1880 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1881 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1882 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1883 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1884 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1887 static int parse_txq_params(struct nlattr
*tb
[],
1888 struct ieee80211_txq_params
*txq_params
)
1890 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1891 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1892 !tb
[NL80211_TXQ_ATTR_AIFS
])
1895 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1896 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1897 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1898 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1899 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1901 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1907 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1910 * You can only set the channel explicitly for WDS interfaces,
1911 * all others have their channel managed via their respective
1912 * "establish a connection" command (connect, join, ...)
1914 * For AP/GO and mesh mode, the channel can be set with the
1915 * channel userspace API, but is only stored and passed to the
1916 * low-level driver when the AP starts or the mesh is joined.
1917 * This is for backward compatibility, userspace can also give
1918 * the channel in the start-ap or join-mesh commands instead.
1920 * Monitors are special as they are normally slaved to
1921 * whatever else is going on, so they have their own special
1922 * operation to set the monitor channel if possible.
1925 wdev
->iftype
== NL80211_IFTYPE_AP
||
1926 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1927 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1928 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1931 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1932 struct genl_info
*info
,
1933 struct cfg80211_chan_def
*chandef
)
1937 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1940 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1942 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1943 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1944 chandef
->center_freq1
= control_freq
;
1945 chandef
->center_freq2
= 0;
1947 /* Primary channel not allowed */
1948 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1951 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1952 enum nl80211_channel_type chantype
;
1954 chantype
= nla_get_u32(
1955 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1958 case NL80211_CHAN_NO_HT
:
1959 case NL80211_CHAN_HT20
:
1960 case NL80211_CHAN_HT40PLUS
:
1961 case NL80211_CHAN_HT40MINUS
:
1962 cfg80211_chandef_create(chandef
, chandef
->chan
,
1968 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1970 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1971 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1972 chandef
->center_freq1
=
1974 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1975 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1976 chandef
->center_freq2
=
1978 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1981 if (!cfg80211_chandef_valid(chandef
))
1984 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1985 IEEE80211_CHAN_DISABLED
))
1988 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1989 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1990 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1996 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1997 struct net_device
*dev
,
1998 struct genl_info
*info
)
2000 struct cfg80211_chan_def chandef
;
2002 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
2003 struct wireless_dev
*wdev
= NULL
;
2006 wdev
= dev
->ieee80211_ptr
;
2007 if (!nl80211_can_set_dev_channel(wdev
))
2010 iftype
= wdev
->iftype
;
2012 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2017 case NL80211_IFTYPE_AP
:
2018 case NL80211_IFTYPE_P2P_GO
:
2019 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2024 if (wdev
->beacon_interval
) {
2025 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2026 !(rdev
->wiphy
.features
&
2027 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2032 /* Only allow dynamic channel width changes */
2033 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2037 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2041 wdev
->preset_chandef
= chandef
;
2044 case NL80211_IFTYPE_MESH_POINT
:
2045 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2047 case NL80211_IFTYPE_MONITOR
:
2048 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2057 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2059 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2060 struct net_device
*netdev
= info
->user_ptr
[1];
2062 return __nl80211_set_channel(rdev
, netdev
, info
);
2065 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2067 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2068 struct net_device
*dev
= info
->user_ptr
[1];
2069 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2072 if (!info
->attrs
[NL80211_ATTR_MAC
])
2075 if (netif_running(dev
))
2078 if (!rdev
->ops
->set_wds_peer
)
2081 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2084 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2085 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2089 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2091 struct cfg80211_registered_device
*rdev
;
2092 struct net_device
*netdev
= NULL
;
2093 struct wireless_dev
*wdev
;
2094 int result
= 0, rem_txq_params
= 0;
2095 struct nlattr
*nl_txq_params
;
2097 u8 retry_short
= 0, retry_long
= 0;
2098 u32 frag_threshold
= 0, rts_threshold
= 0;
2099 u8 coverage_class
= 0;
2104 * Try to find the wiphy and netdev. Normally this
2105 * function shouldn't need the netdev, but this is
2106 * done for backward compatibility -- previously
2107 * setting the channel was done per wiphy, but now
2108 * it is per netdev. Previous userland like hostapd
2109 * also passed a netdev to set_wiphy, so that it is
2110 * possible to let that go to the right netdev!
2113 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2114 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2116 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2117 if (netdev
&& netdev
->ieee80211_ptr
)
2118 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2124 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2127 return PTR_ERR(rdev
);
2132 wdev
= netdev
->ieee80211_ptr
;
2135 * end workaround code, by now the rdev is available
2136 * and locked, and wdev may or may not be NULL.
2139 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2140 result
= cfg80211_dev_rename(
2141 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2146 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2147 struct ieee80211_txq_params txq_params
;
2148 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2150 if (!rdev
->ops
->set_txq_params
)
2156 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2157 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2160 if (!netif_running(netdev
))
2163 nla_for_each_nested(nl_txq_params
,
2164 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2166 result
= nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
2167 nla_data(nl_txq_params
),
2168 nla_len(nl_txq_params
),
2172 result
= parse_txq_params(tb
, &txq_params
);
2176 result
= rdev_set_txq_params(rdev
, netdev
,
2183 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2184 result
= __nl80211_set_channel(
2186 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2192 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2193 struct wireless_dev
*txp_wdev
= wdev
;
2194 enum nl80211_tx_power_setting type
;
2197 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2200 if (!rdev
->ops
->set_tx_power
)
2203 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2204 type
= nla_get_u32(info
->attrs
[idx
]);
2206 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2207 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2210 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2211 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2212 mbm
= nla_get_u32(info
->attrs
[idx
]);
2215 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2220 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2221 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2223 if ((!rdev
->wiphy
.available_antennas_tx
&&
2224 !rdev
->wiphy
.available_antennas_rx
) ||
2225 !rdev
->ops
->set_antenna
)
2228 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2229 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2231 /* reject antenna configurations which don't match the
2232 * available antenna masks, except for the "all" mask */
2233 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2234 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2237 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2238 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2240 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2247 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2248 retry_short
= nla_get_u8(
2249 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2250 if (retry_short
== 0)
2253 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2256 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2257 retry_long
= nla_get_u8(
2258 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2259 if (retry_long
== 0)
2262 changed
|= WIPHY_PARAM_RETRY_LONG
;
2265 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2266 frag_threshold
= nla_get_u32(
2267 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2268 if (frag_threshold
< 256)
2271 if (frag_threshold
!= (u32
) -1) {
2273 * Fragments (apart from the last one) are required to
2274 * have even length. Make the fragmentation code
2275 * simpler by stripping LSB should someone try to use
2276 * odd threshold value.
2278 frag_threshold
&= ~0x1;
2280 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2283 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2284 rts_threshold
= nla_get_u32(
2285 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2286 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2289 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2290 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2293 coverage_class
= nla_get_u8(
2294 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2295 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2298 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2299 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2302 changed
|= WIPHY_PARAM_DYN_ACK
;
2306 u8 old_retry_short
, old_retry_long
;
2307 u32 old_frag_threshold
, old_rts_threshold
;
2308 u8 old_coverage_class
;
2310 if (!rdev
->ops
->set_wiphy_params
)
2313 old_retry_short
= rdev
->wiphy
.retry_short
;
2314 old_retry_long
= rdev
->wiphy
.retry_long
;
2315 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2316 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2317 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2319 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2320 rdev
->wiphy
.retry_short
= retry_short
;
2321 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2322 rdev
->wiphy
.retry_long
= retry_long
;
2323 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2324 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2325 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2326 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2327 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2328 rdev
->wiphy
.coverage_class
= coverage_class
;
2330 result
= rdev_set_wiphy_params(rdev
, changed
);
2332 rdev
->wiphy
.retry_short
= old_retry_short
;
2333 rdev
->wiphy
.retry_long
= old_retry_long
;
2334 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2335 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2336 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2343 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2345 return (u64
)wdev
->identifier
|
2346 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2349 static int nl80211_send_chandef(struct sk_buff
*msg
,
2350 const struct cfg80211_chan_def
*chandef
)
2352 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2355 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2356 chandef
->chan
->center_freq
))
2358 switch (chandef
->width
) {
2359 case NL80211_CHAN_WIDTH_20_NOHT
:
2360 case NL80211_CHAN_WIDTH_20
:
2361 case NL80211_CHAN_WIDTH_40
:
2362 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2363 cfg80211_get_chandef_type(chandef
)))
2369 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2371 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2373 if (chandef
->center_freq2
&&
2374 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2379 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2380 struct cfg80211_registered_device
*rdev
,
2381 struct wireless_dev
*wdev
, bool removal
)
2383 struct net_device
*dev
= wdev
->netdev
;
2384 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2388 cmd
= NL80211_CMD_DEL_INTERFACE
;
2390 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2395 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2396 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2397 goto nla_put_failure
;
2399 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2400 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2401 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2402 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2403 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2404 rdev
->devlist_generation
^
2405 (cfg80211_rdev_list_generation
<< 2)))
2406 goto nla_put_failure
;
2408 if (rdev
->ops
->get_channel
) {
2410 struct cfg80211_chan_def chandef
;
2412 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2414 if (nl80211_send_chandef(msg
, &chandef
))
2415 goto nla_put_failure
;
2419 if (rdev
->ops
->get_tx_power
) {
2422 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2424 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2426 goto nla_put_failure
;
2429 if (wdev
->ssid_len
) {
2430 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2431 goto nla_put_failure
;
2434 genlmsg_end(msg
, hdr
);
2438 genlmsg_cancel(msg
, hdr
);
2442 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2446 int wp_start
= cb
->args
[0];
2447 int if_start
= cb
->args
[1];
2448 struct cfg80211_registered_device
*rdev
;
2449 struct wireless_dev
*wdev
;
2452 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2453 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2455 if (wp_idx
< wp_start
) {
2461 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2462 if (if_idx
< if_start
) {
2466 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2467 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2468 rdev
, wdev
, false) < 0) {
2479 cb
->args
[0] = wp_idx
;
2480 cb
->args
[1] = if_idx
;
2485 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2487 struct sk_buff
*msg
;
2488 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2489 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2491 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2495 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2496 rdev
, wdev
, false) < 0) {
2501 return genlmsg_reply(msg
, info
);
2504 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2505 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2506 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2507 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2508 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2509 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2510 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2513 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2515 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2523 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2524 nla
, mntr_flags_policy
))
2527 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2529 *mntrflags
|= (1<<flag
);
2534 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2535 struct net_device
*netdev
, u8 use_4addr
,
2536 enum nl80211_iftype iftype
)
2539 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2545 case NL80211_IFTYPE_AP_VLAN
:
2546 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2549 case NL80211_IFTYPE_STATION
:
2550 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2560 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2562 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2563 struct vif_params params
;
2565 enum nl80211_iftype otype
, ntype
;
2566 struct net_device
*dev
= info
->user_ptr
[1];
2567 u32 _flags
, *flags
= NULL
;
2568 bool change
= false;
2570 memset(¶ms
, 0, sizeof(params
));
2572 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2574 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2575 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2578 if (ntype
> NL80211_IFTYPE_MAX
)
2582 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2583 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2585 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2587 if (netif_running(dev
))
2591 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2592 IEEE80211_MAX_MESH_ID_LEN
);
2593 wdev
->mesh_id_up_len
=
2594 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2595 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2596 wdev
->mesh_id_up_len
);
2600 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2601 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2603 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2607 params
.use_4addr
= -1;
2610 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2611 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2613 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2622 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2623 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2627 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2631 if (!err
&& params
.use_4addr
!= -1)
2632 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2637 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2639 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2640 struct vif_params params
;
2641 struct wireless_dev
*wdev
;
2642 struct sk_buff
*msg
, *event
;
2644 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2647 /* to avoid failing a new interface creation due to pending removal */
2648 cfg80211_destroy_ifaces(rdev
);
2650 memset(¶ms
, 0, sizeof(params
));
2652 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2655 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2656 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2657 if (type
> NL80211_IFTYPE_MAX
)
2661 if (!rdev
->ops
->add_virtual_intf
||
2662 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2665 if ((type
== NL80211_IFTYPE_P2P_DEVICE
||
2666 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
2667 info
->attrs
[NL80211_ATTR_MAC
]) {
2668 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2670 if (!is_valid_ether_addr(params
.macaddr
))
2671 return -EADDRNOTAVAIL
;
2674 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2675 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2676 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2681 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2682 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2685 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2686 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2689 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2693 wdev
= rdev_add_virtual_intf(rdev
,
2694 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2695 NET_NAME_USER
, type
, err
? NULL
: &flags
,
2697 if (WARN_ON(!wdev
)) {
2700 } else if (IS_ERR(wdev
)) {
2702 return PTR_ERR(wdev
);
2705 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
2706 wdev
->owner_nlportid
= info
->snd_portid
;
2709 case NL80211_IFTYPE_MESH_POINT
:
2710 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2713 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2714 IEEE80211_MAX_MESH_ID_LEN
);
2715 wdev
->mesh_id_up_len
=
2716 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2717 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2718 wdev
->mesh_id_up_len
);
2721 case NL80211_IFTYPE_P2P_DEVICE
:
2723 * P2P Device doesn't have a netdev, so doesn't go
2724 * through the netdev notifier and must be added here
2726 mutex_init(&wdev
->mtx
);
2727 INIT_LIST_HEAD(&wdev
->event_list
);
2728 spin_lock_init(&wdev
->event_lock
);
2729 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2730 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2732 wdev
->identifier
= ++rdev
->wdev_id
;
2733 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2734 rdev
->devlist_generation
++;
2740 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2741 rdev
, wdev
, false) < 0) {
2746 event
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2748 if (nl80211_send_iface(event
, 0, 0, 0,
2749 rdev
, wdev
, false) < 0) {
2754 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2755 event
, 0, NL80211_MCGRP_CONFIG
,
2760 return genlmsg_reply(msg
, info
);
2763 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2765 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2766 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2767 struct sk_buff
*msg
;
2770 if (!rdev
->ops
->del_virtual_intf
)
2773 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2774 if (msg
&& nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
, true) < 0) {
2780 * If we remove a wireless device without a netdev then clear
2781 * user_ptr[1] so that nl80211_post_doit won't dereference it
2782 * to check if it needs to do dev_put(). Otherwise it crashes
2783 * since the wdev has been freed, unlike with a netdev where
2784 * we need the dev_put() for the netdev to really be freed.
2787 info
->user_ptr
[1] = NULL
;
2789 status
= rdev_del_virtual_intf(rdev
, wdev
);
2790 if (status
>= 0 && msg
)
2791 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2792 msg
, 0, NL80211_MCGRP_CONFIG
,
2800 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2802 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2803 struct net_device
*dev
= info
->user_ptr
[1];
2806 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2809 if (!rdev
->ops
->set_noack_map
)
2812 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2814 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2817 struct get_key_cookie
{
2818 struct sk_buff
*msg
;
2823 static void get_key_callback(void *c
, struct key_params
*params
)
2826 struct get_key_cookie
*cookie
= c
;
2829 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2830 params
->key_len
, params
->key
)) ||
2832 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2833 params
->seq_len
, params
->seq
)) ||
2835 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2837 goto nla_put_failure
;
2839 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2841 goto nla_put_failure
;
2844 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2845 params
->key_len
, params
->key
)) ||
2847 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2848 params
->seq_len
, params
->seq
)) ||
2850 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2852 goto nla_put_failure
;
2854 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2855 goto nla_put_failure
;
2857 nla_nest_end(cookie
->msg
, key
);
2864 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2866 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2868 struct net_device
*dev
= info
->user_ptr
[1];
2870 const u8
*mac_addr
= NULL
;
2872 struct get_key_cookie cookie
= {
2876 struct sk_buff
*msg
;
2878 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2879 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2884 if (info
->attrs
[NL80211_ATTR_MAC
])
2885 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2887 pairwise
= !!mac_addr
;
2888 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2889 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2890 if (kt
>= NUM_NL80211_KEYTYPES
)
2892 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2893 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2895 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2898 if (!rdev
->ops
->get_key
)
2901 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2904 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2908 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2909 NL80211_CMD_NEW_KEY
);
2911 goto nla_put_failure
;
2914 cookie
.idx
= key_idx
;
2916 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2917 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2918 goto nla_put_failure
;
2920 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2921 goto nla_put_failure
;
2923 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2930 goto nla_put_failure
;
2932 genlmsg_end(msg
, hdr
);
2933 return genlmsg_reply(msg
, info
);
2942 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2944 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2945 struct key_parse key
;
2947 struct net_device
*dev
= info
->user_ptr
[1];
2949 err
= nl80211_parse_key(info
, &key
);
2956 /* only support setting default key */
2957 if (!key
.def
&& !key
.defmgmt
)
2960 wdev_lock(dev
->ieee80211_ptr
);
2963 if (!rdev
->ops
->set_default_key
) {
2968 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2972 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2973 key
.def_uni
, key
.def_multi
);
2978 #ifdef CONFIG_CFG80211_WEXT
2979 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2982 if (key
.def_uni
|| !key
.def_multi
) {
2987 if (!rdev
->ops
->set_default_mgmt_key
) {
2992 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2996 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
3000 #ifdef CONFIG_CFG80211_WEXT
3001 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3006 wdev_unlock(dev
->ieee80211_ptr
);
3011 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3013 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3015 struct net_device
*dev
= info
->user_ptr
[1];
3016 struct key_parse key
;
3017 const u8
*mac_addr
= NULL
;
3019 err
= nl80211_parse_key(info
, &key
);
3026 if (info
->attrs
[NL80211_ATTR_MAC
])
3027 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3029 if (key
.type
== -1) {
3031 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3033 key
.type
= NL80211_KEYTYPE_GROUP
;
3037 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3038 key
.type
!= NL80211_KEYTYPE_GROUP
)
3041 if (!rdev
->ops
->add_key
)
3044 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3045 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3049 wdev_lock(dev
->ieee80211_ptr
);
3050 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3052 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3053 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3055 wdev_unlock(dev
->ieee80211_ptr
);
3060 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3062 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3064 struct net_device
*dev
= info
->user_ptr
[1];
3065 u8
*mac_addr
= NULL
;
3066 struct key_parse key
;
3068 err
= nl80211_parse_key(info
, &key
);
3072 if (info
->attrs
[NL80211_ATTR_MAC
])
3073 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3075 if (key
.type
== -1) {
3077 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3079 key
.type
= NL80211_KEYTYPE_GROUP
;
3083 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3084 key
.type
!= NL80211_KEYTYPE_GROUP
)
3087 if (!rdev
->ops
->del_key
)
3090 wdev_lock(dev
->ieee80211_ptr
);
3091 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3093 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3094 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3098 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3099 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3102 #ifdef CONFIG_CFG80211_WEXT
3104 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3105 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3106 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3107 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3110 wdev_unlock(dev
->ieee80211_ptr
);
3115 /* This function returns an error or the number of nested attributes */
3116 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3118 struct nlattr
*attr
;
3119 int n_entries
= 0, tmp
;
3121 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3122 if (nla_len(attr
) != ETH_ALEN
)
3132 * This function parses ACL information and allocates memory for ACL data.
3133 * On successful return, the calling function is responsible to free the
3134 * ACL buffer returned by this function.
3136 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3137 struct genl_info
*info
)
3139 enum nl80211_acl_policy acl_policy
;
3140 struct nlattr
*attr
;
3141 struct cfg80211_acl_data
*acl
;
3142 int i
= 0, n_entries
, tmp
;
3144 if (!wiphy
->max_acl_mac_addrs
)
3145 return ERR_PTR(-EOPNOTSUPP
);
3147 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3148 return ERR_PTR(-EINVAL
);
3150 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3151 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3152 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3153 return ERR_PTR(-EINVAL
);
3155 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3156 return ERR_PTR(-EINVAL
);
3158 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3160 return ERR_PTR(n_entries
);
3162 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3163 return ERR_PTR(-ENOTSUPP
);
3165 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3168 return ERR_PTR(-ENOMEM
);
3170 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3171 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3175 acl
->n_acl_entries
= n_entries
;
3176 acl
->acl_policy
= acl_policy
;
3181 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3183 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3184 struct net_device
*dev
= info
->user_ptr
[1];
3185 struct cfg80211_acl_data
*acl
;
3188 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3189 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3192 if (!dev
->ieee80211_ptr
->beacon_interval
)
3195 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3197 return PTR_ERR(acl
);
3199 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3206 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3207 struct cfg80211_beacon_data
*bcn
)
3209 bool haveinfo
= false;
3211 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3212 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3213 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3214 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3217 memset(bcn
, 0, sizeof(*bcn
));
3219 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3220 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3221 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3227 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3228 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3229 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3236 if (attrs
[NL80211_ATTR_IE
]) {
3237 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3238 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3241 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3242 bcn
->proberesp_ies
=
3243 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3244 bcn
->proberesp_ies_len
=
3245 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3248 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3249 bcn
->assocresp_ies
=
3250 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3251 bcn
->assocresp_ies_len
=
3252 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3255 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3256 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3257 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3263 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3264 struct cfg80211_ap_settings
*params
)
3266 struct wireless_dev
*wdev
;
3269 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3270 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3271 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3274 if (!wdev
->preset_chandef
.chan
)
3277 params
->chandef
= wdev
->preset_chandef
;
3285 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3286 enum nl80211_auth_type auth_type
,
3287 enum nl80211_commands cmd
)
3289 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3293 case NL80211_CMD_AUTHENTICATE
:
3294 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3295 auth_type
== NL80211_AUTHTYPE_SAE
)
3298 case NL80211_CMD_CONNECT
:
3299 case NL80211_CMD_START_AP
:
3300 /* SAE not supported yet */
3301 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3309 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3311 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3312 struct net_device
*dev
= info
->user_ptr
[1];
3313 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3314 struct cfg80211_ap_settings params
;
3317 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3318 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3321 if (!rdev
->ops
->start_ap
)
3324 if (wdev
->beacon_interval
)
3327 memset(¶ms
, 0, sizeof(params
));
3329 /* these are required for START_AP */
3330 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3331 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3332 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3335 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3339 params
.beacon_interval
=
3340 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3341 params
.dtim_period
=
3342 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3344 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3349 * In theory, some of these attributes should be required here
3350 * but since they were not used when the command was originally
3351 * added, keep them optional for old user space programs to let
3352 * them continue to work with drivers that do not need the
3353 * additional information -- drivers must check!
3355 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3356 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3358 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3359 if (params
.ssid_len
== 0 ||
3360 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3364 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3365 params
.hidden_ssid
= nla_get_u32(
3366 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3367 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3368 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3369 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3373 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3375 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3376 params
.auth_type
= nla_get_u32(
3377 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3378 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3379 NL80211_CMD_START_AP
))
3382 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3384 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3385 NL80211_MAX_NR_CIPHER_SUITES
);
3389 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3390 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3392 params
.inactivity_timeout
= nla_get_u16(
3393 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3396 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3397 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3399 params
.p2p_ctwindow
=
3400 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3401 if (params
.p2p_ctwindow
> 127)
3403 if (params
.p2p_ctwindow
!= 0 &&
3404 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3408 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3411 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3413 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3416 params
.p2p_opp_ps
= tmp
;
3417 if (params
.p2p_opp_ps
!= 0 &&
3418 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3422 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3423 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3426 } else if (wdev
->preset_chandef
.chan
) {
3427 params
.chandef
= wdev
->preset_chandef
;
3428 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3431 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
3435 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
3437 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
3438 switch (params
.smps_mode
) {
3439 case NL80211_SMPS_OFF
:
3441 case NL80211_SMPS_STATIC
:
3442 if (!(rdev
->wiphy
.features
&
3443 NL80211_FEATURE_STATIC_SMPS
))
3446 case NL80211_SMPS_DYNAMIC
:
3447 if (!(rdev
->wiphy
.features
&
3448 NL80211_FEATURE_DYNAMIC_SMPS
))
3455 params
.smps_mode
= NL80211_SMPS_OFF
;
3458 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3459 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3460 if (IS_ERR(params
.acl
))
3461 return PTR_ERR(params
.acl
);
3465 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3467 wdev
->preset_chandef
= params
.chandef
;
3468 wdev
->beacon_interval
= params
.beacon_interval
;
3469 wdev
->chandef
= params
.chandef
;
3470 wdev
->ssid_len
= params
.ssid_len
;
3471 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3480 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3482 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3483 struct net_device
*dev
= info
->user_ptr
[1];
3484 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3485 struct cfg80211_beacon_data params
;
3488 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3489 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3492 if (!rdev
->ops
->change_beacon
)
3495 if (!wdev
->beacon_interval
)
3498 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3503 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
3509 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3511 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3512 struct net_device
*dev
= info
->user_ptr
[1];
3514 return cfg80211_stop_ap(rdev
, dev
, false);
3517 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3518 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3519 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3520 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3521 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3522 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3523 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3526 static int parse_station_flags(struct genl_info
*info
,
3527 enum nl80211_iftype iftype
,
3528 struct station_parameters
*params
)
3530 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3535 * Try parsing the new attribute first so userspace
3536 * can specify both for older kernels.
3538 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3540 struct nl80211_sta_flag_update
*sta_flags
;
3542 sta_flags
= nla_data(nla
);
3543 params
->sta_flags_mask
= sta_flags
->mask
;
3544 params
->sta_flags_set
= sta_flags
->set
;
3545 params
->sta_flags_set
&= params
->sta_flags_mask
;
3546 if ((params
->sta_flags_mask
|
3547 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3552 /* if present, parse the old attribute */
3554 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3558 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3559 nla
, sta_flags_policy
))
3563 * Only allow certain flags for interface types so that
3564 * other attributes are silently ignored. Remember that
3565 * this is backward compatibility code with old userspace
3566 * and shouldn't be hit in other cases anyway.
3569 case NL80211_IFTYPE_AP
:
3570 case NL80211_IFTYPE_AP_VLAN
:
3571 case NL80211_IFTYPE_P2P_GO
:
3572 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3573 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3574 BIT(NL80211_STA_FLAG_WME
) |
3575 BIT(NL80211_STA_FLAG_MFP
);
3577 case NL80211_IFTYPE_P2P_CLIENT
:
3578 case NL80211_IFTYPE_STATION
:
3579 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3580 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3582 case NL80211_IFTYPE_MESH_POINT
:
3583 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3584 BIT(NL80211_STA_FLAG_MFP
) |
3585 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3590 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3592 params
->sta_flags_set
|= (1<<flag
);
3594 /* no longer support new API additions in old API */
3595 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3603 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3606 struct nlattr
*rate
;
3609 enum nl80211_attrs rate_flg
;
3611 rate
= nla_nest_start(msg
, attr
);
3615 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3616 bitrate
= cfg80211_calculate_bitrate(info
);
3617 /* report 16-bit bitrate only if we can */
3618 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3620 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3622 if (bitrate_compat
> 0 &&
3623 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3627 case RATE_INFO_BW_5
:
3628 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
3630 case RATE_INFO_BW_10
:
3631 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
3636 case RATE_INFO_BW_20
:
3639 case RATE_INFO_BW_40
:
3640 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
3642 case RATE_INFO_BW_80
:
3643 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
3645 case RATE_INFO_BW_160
:
3646 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
3650 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
3653 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3654 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3656 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3657 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3659 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3660 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3662 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3664 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3665 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3669 nla_nest_end(msg
, rate
);
3673 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3682 attr
= nla_nest_start(msg
, id
);
3686 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3687 if (!(mask
& BIT(i
)))
3690 if (nla_put_u8(msg
, i
, signal
[i
]))
3694 nla_nest_end(msg
, attr
);
3699 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
3701 struct cfg80211_registered_device
*rdev
,
3702 struct net_device
*dev
,
3703 const u8
*mac_addr
, struct station_info
*sinfo
)
3706 struct nlattr
*sinfoattr
, *bss_param
;
3708 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
3712 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3713 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3714 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3715 goto nla_put_failure
;
3717 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3719 goto nla_put_failure
;
3721 #define PUT_SINFO(attr, memb, type) do { \
3722 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3723 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3725 goto nla_put_failure; \
3728 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
3729 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
3731 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
3732 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
3733 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3734 (u32
)sinfo
->rx_bytes
))
3735 goto nla_put_failure
;
3737 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
3738 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
3739 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3740 (u32
)sinfo
->tx_bytes
))
3741 goto nla_put_failure
;
3743 PUT_SINFO(RX_BYTES64
, rx_bytes
, u64
);
3744 PUT_SINFO(TX_BYTES64
, tx_bytes
, u64
);
3745 PUT_SINFO(LLID
, llid
, u16
);
3746 PUT_SINFO(PLID
, plid
, u16
);
3747 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
3749 switch (rdev
->wiphy
.signal_type
) {
3750 case CFG80211_SIGNAL_TYPE_MBM
:
3751 PUT_SINFO(SIGNAL
, signal
, u8
);
3752 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
3757 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
3758 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3759 sinfo
->chain_signal
,
3760 NL80211_STA_INFO_CHAIN_SIGNAL
))
3761 goto nla_put_failure
;
3763 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
3764 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3765 sinfo
->chain_signal_avg
,
3766 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3767 goto nla_put_failure
;
3769 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
3770 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3771 NL80211_STA_INFO_TX_BITRATE
))
3772 goto nla_put_failure
;
3774 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
3775 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3776 NL80211_STA_INFO_RX_BITRATE
))
3777 goto nla_put_failure
;
3780 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
3781 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
3782 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
3783 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
3784 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
3785 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
3786 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
3787 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
3788 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
3790 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
3791 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3793 goto nla_put_failure
;
3795 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3796 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3797 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3798 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3799 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3800 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3801 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3802 sinfo
->bss_param
.dtim_period
) ||
3803 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3804 sinfo
->bss_param
.beacon_interval
))
3805 goto nla_put_failure
;
3807 nla_nest_end(msg
, bss_param
);
3809 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
3810 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3811 sizeof(struct nl80211_sta_flag_update
),
3813 goto nla_put_failure
;
3815 PUT_SINFO(T_OFFSET
, t_offset
, u64
);
3816 PUT_SINFO(RX_DROP_MISC
, rx_dropped_misc
, u64
);
3817 PUT_SINFO(BEACON_RX
, rx_beacon
, u64
);
3818 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
3822 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TID_STATS
)) {
3823 struct nlattr
*tidsattr
;
3826 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
3828 goto nla_put_failure
;
3830 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
3831 struct cfg80211_tid_stats
*tidstats
;
3832 struct nlattr
*tidattr
;
3834 tidstats
= &sinfo
->pertid
[tid
];
3836 if (!tidstats
->filled
)
3839 tidattr
= nla_nest_start(msg
, tid
+ 1);
3841 goto nla_put_failure
;
3843 #define PUT_TIDVAL(attr, memb, type) do { \
3844 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3845 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3847 goto nla_put_failure; \
3850 PUT_TIDVAL(RX_MSDU
, rx_msdu
, u64
);
3851 PUT_TIDVAL(TX_MSDU
, tx_msdu
, u64
);
3852 PUT_TIDVAL(TX_MSDU_RETRIES
, tx_msdu_retries
, u64
);
3853 PUT_TIDVAL(TX_MSDU_FAILED
, tx_msdu_failed
, u64
);
3856 nla_nest_end(msg
, tidattr
);
3859 nla_nest_end(msg
, tidsattr
);
3862 nla_nest_end(msg
, sinfoattr
);
3864 if (sinfo
->assoc_req_ies_len
&&
3865 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3866 sinfo
->assoc_req_ies
))
3867 goto nla_put_failure
;
3869 genlmsg_end(msg
, hdr
);
3873 genlmsg_cancel(msg
, hdr
);
3877 static int nl80211_dump_station(struct sk_buff
*skb
,
3878 struct netlink_callback
*cb
)
3880 struct station_info sinfo
;
3881 struct cfg80211_registered_device
*rdev
;
3882 struct wireless_dev
*wdev
;
3883 u8 mac_addr
[ETH_ALEN
];
3884 int sta_idx
= cb
->args
[2];
3887 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
3891 if (!wdev
->netdev
) {
3896 if (!rdev
->ops
->dump_station
) {
3902 memset(&sinfo
, 0, sizeof(sinfo
));
3903 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
3910 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
3911 NETLINK_CB(cb
->skb
).portid
,
3912 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3913 rdev
, wdev
->netdev
, mac_addr
,
3922 cb
->args
[2] = sta_idx
;
3925 nl80211_finish_wdev_dump(rdev
);
3930 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3932 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3933 struct net_device
*dev
= info
->user_ptr
[1];
3934 struct station_info sinfo
;
3935 struct sk_buff
*msg
;
3936 u8
*mac_addr
= NULL
;
3939 memset(&sinfo
, 0, sizeof(sinfo
));
3941 if (!info
->attrs
[NL80211_ATTR_MAC
])
3944 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3946 if (!rdev
->ops
->get_station
)
3949 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3953 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3957 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
3958 info
->snd_portid
, info
->snd_seq
, 0,
3959 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3964 return genlmsg_reply(msg
, info
);
3967 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3968 struct station_parameters
*params
,
3969 enum cfg80211_station_type statype
)
3971 if (params
->listen_interval
!= -1 &&
3972 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
3976 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
3977 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
3980 /* When you run into this, adjust the code below for the new flag */
3981 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3984 case CFG80211_STA_MESH_PEER_KERNEL
:
3985 case CFG80211_STA_MESH_PEER_USER
:
3987 * No ignoring the TDLS flag here -- the userspace mesh
3988 * code doesn't have the bug of including TDLS in the
3991 if (params
->sta_flags_mask
&
3992 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3993 BIT(NL80211_STA_FLAG_MFP
) |
3994 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3997 case CFG80211_STA_TDLS_PEER_SETUP
:
3998 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3999 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4001 /* ignore since it can't change */
4002 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4005 /* disallow mesh-specific things */
4006 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4008 if (params
->local_pm
)
4010 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4014 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4015 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4016 /* TDLS can't be set, ... */
4017 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4020 * ... but don't bother the driver with it. This works around
4021 * a hostapd/wpa_supplicant issue -- it always includes the
4022 * TLDS_PEER flag in the mask even for AP mode.
4024 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4027 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4028 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4029 /* reject other things that can't change */
4030 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4032 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4034 if (params
->supported_rates
)
4036 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4040 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4041 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4047 case CFG80211_STA_AP_MLME_CLIENT
:
4048 /* Use this only for authorizing/unauthorizing a station */
4049 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4052 case CFG80211_STA_AP_CLIENT
:
4053 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4054 /* accept only the listed bits */
4055 if (params
->sta_flags_mask
&
4056 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4057 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4058 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4059 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4060 BIT(NL80211_STA_FLAG_WME
) |
4061 BIT(NL80211_STA_FLAG_MFP
)))
4064 /* but authenticated/associated only if driver handles it */
4065 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4066 params
->sta_flags_mask
&
4067 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4068 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4071 case CFG80211_STA_IBSS
:
4072 case CFG80211_STA_AP_STA
:
4073 /* reject any changes other than AUTHORIZED */
4074 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4077 case CFG80211_STA_TDLS_PEER_SETUP
:
4078 /* reject any changes other than AUTHORIZED or WME */
4079 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4080 BIT(NL80211_STA_FLAG_WME
)))
4082 /* force (at least) rates when authorizing */
4083 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4084 !params
->supported_rates
)
4087 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4088 /* reject any changes */
4090 case CFG80211_STA_MESH_PEER_KERNEL
:
4091 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4094 case CFG80211_STA_MESH_PEER_USER
:
4095 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4096 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4103 EXPORT_SYMBOL(cfg80211_check_station_change
);
4106 * Get vlan interface making sure it is running and on the right wiphy.
4108 static struct net_device
*get_vlan(struct genl_info
*info
,
4109 struct cfg80211_registered_device
*rdev
)
4111 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4112 struct net_device
*v
;
4118 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4120 return ERR_PTR(-ENODEV
);
4122 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4127 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4128 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4129 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4134 if (!netif_running(v
)) {
4142 return ERR_PTR(ret
);
4145 static const struct nla_policy
4146 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
4147 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
4148 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
4151 static int nl80211_parse_sta_wme(struct genl_info
*info
,
4152 struct station_parameters
*params
)
4154 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
4158 /* parse WME attributes if present */
4159 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
4162 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
4163 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
4164 nl80211_sta_wme_policy
);
4168 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4169 params
->uapsd_queues
= nla_get_u8(
4170 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4171 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4174 if (tb
[NL80211_STA_WME_MAX_SP
])
4175 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4177 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4180 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4185 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4186 struct station_parameters
*params
)
4188 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4189 params
->supported_channels
=
4190 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4191 params
->supported_channels_len
=
4192 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4194 * Need to include at least one (first channel, number of
4195 * channels) tuple for each subband, and must have proper
4196 * tuples for the rest of the data as well.
4198 if (params
->supported_channels_len
< 2)
4200 if (params
->supported_channels_len
% 2)
4204 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4205 params
->supported_oper_classes
=
4206 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4207 params
->supported_oper_classes_len
=
4208 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4210 * The value of the Length field of the Supported Operating
4211 * Classes element is between 2 and 253.
4213 if (params
->supported_oper_classes_len
< 2 ||
4214 params
->supported_oper_classes_len
> 253)
4220 static int nl80211_set_station_tdls(struct genl_info
*info
,
4221 struct station_parameters
*params
)
4224 /* Dummy STA entry gets updated once the peer capabilities are known */
4225 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4226 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4227 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4229 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4230 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4232 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4234 err
= nl80211_parse_sta_channel_info(info
, params
);
4238 return nl80211_parse_sta_wme(info
, params
);
4241 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4243 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4244 struct net_device
*dev
= info
->user_ptr
[1];
4245 struct station_parameters params
;
4249 memset(¶ms
, 0, sizeof(params
));
4251 if (!rdev
->ops
->change_station
)
4255 * AID and listen_interval properties can be set only for unassociated
4256 * station. Include these parameters here and will check them in
4257 * cfg80211_check_station_change().
4259 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4260 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4262 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4263 params
.listen_interval
=
4264 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4266 params
.listen_interval
= -1;
4268 if (!info
->attrs
[NL80211_ATTR_MAC
])
4271 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4273 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4274 params
.supported_rates
=
4275 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4276 params
.supported_rates_len
=
4277 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4280 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4282 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4283 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4286 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4288 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4289 params
.ext_capab_len
=
4290 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4293 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4296 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4297 params
.plink_action
=
4298 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4299 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4303 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4304 params
.plink_state
=
4305 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4306 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4308 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4311 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4312 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4313 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4315 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4316 pm
> NL80211_MESH_POWER_MAX
)
4319 params
.local_pm
= pm
;
4322 /* Include parameters for TDLS peer (will check later) */
4323 err
= nl80211_set_station_tdls(info
, ¶ms
);
4327 params
.vlan
= get_vlan(info
, rdev
);
4328 if (IS_ERR(params
.vlan
))
4329 return PTR_ERR(params
.vlan
);
4331 switch (dev
->ieee80211_ptr
->iftype
) {
4332 case NL80211_IFTYPE_AP
:
4333 case NL80211_IFTYPE_AP_VLAN
:
4334 case NL80211_IFTYPE_P2P_GO
:
4335 case NL80211_IFTYPE_P2P_CLIENT
:
4336 case NL80211_IFTYPE_STATION
:
4337 case NL80211_IFTYPE_ADHOC
:
4338 case NL80211_IFTYPE_MESH_POINT
:
4345 /* driver will call cfg80211_check_station_change() */
4346 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4350 dev_put(params
.vlan
);
4355 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4357 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4359 struct net_device
*dev
= info
->user_ptr
[1];
4360 struct station_parameters params
;
4361 u8
*mac_addr
= NULL
;
4363 memset(¶ms
, 0, sizeof(params
));
4365 if (!rdev
->ops
->add_station
)
4368 if (!info
->attrs
[NL80211_ATTR_MAC
])
4371 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4374 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4377 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4378 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4381 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4382 params
.supported_rates
=
4383 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4384 params
.supported_rates_len
=
4385 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4386 params
.listen_interval
=
4387 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4389 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4390 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4392 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4393 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4396 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4398 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4399 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4402 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4404 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4405 params
.ext_capab_len
=
4406 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4409 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4411 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4413 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4415 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4417 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4418 params
.opmode_notif_used
= true;
4419 params
.opmode_notif
=
4420 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4423 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4424 params
.plink_action
=
4425 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4426 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4430 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
4434 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4438 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4441 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4442 * as userspace might just pass through the capabilities from the IEs
4443 * directly, rather than enforcing this restriction and returning an
4444 * error in this case.
4446 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4447 params
.ht_capa
= NULL
;
4448 params
.vht_capa
= NULL
;
4451 /* When you run into this, adjust the code below for the new flag */
4452 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4454 switch (dev
->ieee80211_ptr
->iftype
) {
4455 case NL80211_IFTYPE_AP
:
4456 case NL80211_IFTYPE_AP_VLAN
:
4457 case NL80211_IFTYPE_P2P_GO
:
4458 /* ignore WME attributes if iface/sta is not capable */
4459 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4460 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4461 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4463 /* TDLS peers cannot be added */
4464 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4465 info
->attrs
[NL80211_ATTR_PEER_AID
])
4467 /* but don't bother the driver with it */
4468 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4470 /* allow authenticated/associated only if driver handles it */
4471 if (!(rdev
->wiphy
.features
&
4472 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4473 params
.sta_flags_mask
&
4474 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4475 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4478 /* must be last in here for error handling */
4479 params
.vlan
= get_vlan(info
, rdev
);
4480 if (IS_ERR(params
.vlan
))
4481 return PTR_ERR(params
.vlan
);
4483 case NL80211_IFTYPE_MESH_POINT
:
4484 /* ignore uAPSD data */
4485 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4487 /* associated is disallowed */
4488 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4490 /* TDLS peers cannot be added */
4491 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4492 info
->attrs
[NL80211_ATTR_PEER_AID
])
4495 case NL80211_IFTYPE_STATION
:
4496 case NL80211_IFTYPE_P2P_CLIENT
:
4497 /* ignore uAPSD data */
4498 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4500 /* these are disallowed */
4501 if (params
.sta_flags_mask
&
4502 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4503 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4505 /* Only TDLS peers can be added */
4506 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4508 /* Can only add if TDLS ... */
4509 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4511 /* ... with external setup is supported */
4512 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4515 * Older wpa_supplicant versions always mark the TDLS peer
4516 * as authorized, but it shouldn't yet be.
4518 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4524 /* be aware of params.vlan when changing code here */
4526 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4529 dev_put(params
.vlan
);
4533 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4535 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4536 struct net_device
*dev
= info
->user_ptr
[1];
4537 struct station_del_parameters params
;
4539 memset(¶ms
, 0, sizeof(params
));
4541 if (info
->attrs
[NL80211_ATTR_MAC
])
4542 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4544 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4545 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4546 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4547 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4550 if (!rdev
->ops
->del_station
)
4553 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
4555 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
4556 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
4557 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
4560 /* Default to Deauthentication frame */
4561 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
4564 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
4565 params
.reason_code
=
4566 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4567 if (params
.reason_code
== 0)
4568 return -EINVAL
; /* 0 is reserved */
4570 /* Default to reason code 2 */
4571 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
4574 return rdev_del_station(rdev
, dev
, ¶ms
);
4577 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4578 int flags
, struct net_device
*dev
,
4579 u8
*dst
, u8
*next_hop
,
4580 struct mpath_info
*pinfo
)
4583 struct nlattr
*pinfoattr
;
4585 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
4589 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4590 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4591 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4592 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4593 goto nla_put_failure
;
4595 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4597 goto nla_put_failure
;
4598 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4599 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4601 goto nla_put_failure
;
4602 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4603 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4604 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4605 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4607 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4608 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4610 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4611 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4613 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4614 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4615 pinfo
->discovery_timeout
)) ||
4616 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4617 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4618 pinfo
->discovery_retries
)))
4619 goto nla_put_failure
;
4621 nla_nest_end(msg
, pinfoattr
);
4623 genlmsg_end(msg
, hdr
);
4627 genlmsg_cancel(msg
, hdr
);
4631 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4632 struct netlink_callback
*cb
)
4634 struct mpath_info pinfo
;
4635 struct cfg80211_registered_device
*rdev
;
4636 struct wireless_dev
*wdev
;
4638 u8 next_hop
[ETH_ALEN
];
4639 int path_idx
= cb
->args
[2];
4642 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4646 if (!rdev
->ops
->dump_mpath
) {
4651 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4657 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
4664 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4665 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4666 wdev
->netdev
, dst
, next_hop
,
4675 cb
->args
[2] = path_idx
;
4678 nl80211_finish_wdev_dump(rdev
);
4682 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4684 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4686 struct net_device
*dev
= info
->user_ptr
[1];
4687 struct mpath_info pinfo
;
4688 struct sk_buff
*msg
;
4690 u8 next_hop
[ETH_ALEN
];
4692 memset(&pinfo
, 0, sizeof(pinfo
));
4694 if (!info
->attrs
[NL80211_ATTR_MAC
])
4697 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4699 if (!rdev
->ops
->get_mpath
)
4702 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4705 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4709 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4713 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4714 dev
, dst
, next_hop
, &pinfo
) < 0) {
4719 return genlmsg_reply(msg
, info
);
4722 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4724 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4725 struct net_device
*dev
= info
->user_ptr
[1];
4727 u8
*next_hop
= NULL
;
4729 if (!info
->attrs
[NL80211_ATTR_MAC
])
4732 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4735 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4736 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4738 if (!rdev
->ops
->change_mpath
)
4741 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4744 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4747 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4749 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4750 struct net_device
*dev
= info
->user_ptr
[1];
4752 u8
*next_hop
= NULL
;
4754 if (!info
->attrs
[NL80211_ATTR_MAC
])
4757 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4760 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4761 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4763 if (!rdev
->ops
->add_mpath
)
4766 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4769 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4772 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4774 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4775 struct net_device
*dev
= info
->user_ptr
[1];
4778 if (info
->attrs
[NL80211_ATTR_MAC
])
4779 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4781 if (!rdev
->ops
->del_mpath
)
4784 return rdev_del_mpath(rdev
, dev
, dst
);
4787 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
4789 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4791 struct net_device
*dev
= info
->user_ptr
[1];
4792 struct mpath_info pinfo
;
4793 struct sk_buff
*msg
;
4797 memset(&pinfo
, 0, sizeof(pinfo
));
4799 if (!info
->attrs
[NL80211_ATTR_MAC
])
4802 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4804 if (!rdev
->ops
->get_mpp
)
4807 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4810 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
4814 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4818 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4819 dev
, dst
, mpp
, &pinfo
) < 0) {
4824 return genlmsg_reply(msg
, info
);
4827 static int nl80211_dump_mpp(struct sk_buff
*skb
,
4828 struct netlink_callback
*cb
)
4830 struct mpath_info pinfo
;
4831 struct cfg80211_registered_device
*rdev
;
4832 struct wireless_dev
*wdev
;
4835 int path_idx
= cb
->args
[2];
4838 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4842 if (!rdev
->ops
->dump_mpp
) {
4847 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4853 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
4860 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4861 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4862 wdev
->netdev
, dst
, mpp
,
4870 cb
->args
[2] = path_idx
;
4873 nl80211_finish_wdev_dump(rdev
);
4877 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4879 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4880 struct net_device
*dev
= info
->user_ptr
[1];
4881 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4882 struct bss_parameters params
;
4885 memset(¶ms
, 0, sizeof(params
));
4886 /* default to not changing parameters */
4887 params
.use_cts_prot
= -1;
4888 params
.use_short_preamble
= -1;
4889 params
.use_short_slot_time
= -1;
4890 params
.ap_isolate
= -1;
4891 params
.ht_opmode
= -1;
4892 params
.p2p_ctwindow
= -1;
4893 params
.p2p_opp_ps
= -1;
4895 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4896 params
.use_cts_prot
=
4897 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4898 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4899 params
.use_short_preamble
=
4900 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4901 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4902 params
.use_short_slot_time
=
4903 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4904 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4905 params
.basic_rates
=
4906 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4907 params
.basic_rates_len
=
4908 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4910 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4911 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4912 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4914 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4916 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4917 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4919 params
.p2p_ctwindow
=
4920 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4921 if (params
.p2p_ctwindow
< 0)
4923 if (params
.p2p_ctwindow
!= 0 &&
4924 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4928 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4931 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4933 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4936 params
.p2p_opp_ps
= tmp
;
4937 if (params
.p2p_opp_ps
&&
4938 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4942 if (!rdev
->ops
->change_bss
)
4945 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4946 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4950 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
4956 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4960 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4965 * You should only get this when cfg80211 hasn't yet initialized
4966 * completely when built-in to the kernel right between the time
4967 * window between nl80211_init() and regulatory_init(), if that is
4970 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4971 return -EINPROGRESS
;
4973 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4974 user_reg_hint_type
=
4975 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4977 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4979 switch (user_reg_hint_type
) {
4980 case NL80211_USER_REG_HINT_USER
:
4981 case NL80211_USER_REG_HINT_CELL_BASE
:
4982 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4985 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4986 return regulatory_hint_user(data
, user_reg_hint_type
);
4987 case NL80211_USER_REG_HINT_INDOOR
:
4988 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
4989 owner_nlportid
= info
->snd_portid
;
4990 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
4996 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
5002 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
5003 struct genl_info
*info
)
5005 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5006 struct net_device
*dev
= info
->user_ptr
[1];
5007 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5008 struct mesh_config cur_params
;
5011 struct nlattr
*pinfoattr
;
5012 struct sk_buff
*msg
;
5014 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5017 if (!rdev
->ops
->get_mesh_config
)
5021 /* If not connected, get default parameters */
5022 if (!wdev
->mesh_id_len
)
5023 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5025 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5031 /* Draw up a netlink message to send back */
5032 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5035 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5036 NL80211_CMD_GET_MESH_CONFIG
);
5039 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5041 goto nla_put_failure
;
5042 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5043 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5044 cur_params
.dot11MeshRetryTimeout
) ||
5045 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5046 cur_params
.dot11MeshConfirmTimeout
) ||
5047 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5048 cur_params
.dot11MeshHoldingTimeout
) ||
5049 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5050 cur_params
.dot11MeshMaxPeerLinks
) ||
5051 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5052 cur_params
.dot11MeshMaxRetries
) ||
5053 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5054 cur_params
.dot11MeshTTL
) ||
5055 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5056 cur_params
.element_ttl
) ||
5057 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5058 cur_params
.auto_open_plinks
) ||
5059 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5060 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5061 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5062 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5063 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5064 cur_params
.path_refresh_time
) ||
5065 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5066 cur_params
.min_discovery_timeout
) ||
5067 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5068 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5069 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5070 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5071 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5072 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5073 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5074 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5075 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5076 cur_params
.dot11MeshHWMPRootMode
) ||
5077 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5078 cur_params
.dot11MeshHWMPRannInterval
) ||
5079 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5080 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
5081 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
5082 cur_params
.dot11MeshForwarding
) ||
5083 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5084 cur_params
.rssi_threshold
) ||
5085 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
5086 cur_params
.ht_opmode
) ||
5087 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5088 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
5089 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5090 cur_params
.dot11MeshHWMProotInterval
) ||
5091 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5092 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
5093 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
5094 cur_params
.power_mode
) ||
5095 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
5096 cur_params
.dot11MeshAwakeWindowDuration
) ||
5097 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5098 cur_params
.plink_timeout
))
5099 goto nla_put_failure
;
5100 nla_nest_end(msg
, pinfoattr
);
5101 genlmsg_end(msg
, hdr
);
5102 return genlmsg_reply(msg
, info
);
5105 genlmsg_cancel(msg
, hdr
);
5111 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
5112 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
5113 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
5114 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
5115 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
5116 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
5117 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
5118 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
5119 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
5120 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
5121 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
5122 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
5123 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
5124 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
5125 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
5126 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
5127 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
5128 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
5129 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
5130 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
5131 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
5132 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
5133 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
5134 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
5135 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
5136 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
5137 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
5138 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
5139 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
5142 static const struct nla_policy
5143 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
5144 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
5145 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
5146 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
5147 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
5148 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
5149 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
5150 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
5151 .len
= IEEE80211_MAX_DATA_LEN
},
5152 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
5155 static int nl80211_parse_mesh_config(struct genl_info
*info
,
5156 struct mesh_config
*cfg
,
5159 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
5162 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5165 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5167 cfg->param = fn(tb[attr]); \
5168 mask |= (1 << (attr - 1)); \
5173 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
5175 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
5176 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
5177 nl80211_meshconf_params_policy
))
5180 /* This makes sure that there aren't more than 32 mesh config
5181 * parameters (otherwise our bitfield scheme would not work.) */
5182 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
5184 /* Fill in the params struct */
5185 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
5186 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5188 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
5189 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5191 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
5192 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5194 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
5195 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5197 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
5198 mask
, NL80211_MESHCONF_MAX_RETRIES
,
5200 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
5201 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
5202 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
5203 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
5205 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
5206 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5208 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
5210 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5212 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
5213 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5215 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
5216 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5218 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
5219 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5221 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
5223 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5225 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
5227 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5229 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
5231 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5233 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5234 dot11MeshHWMPnetDiameterTraversalTime
,
5236 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5238 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
5239 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5241 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
5242 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5244 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5245 dot11MeshGateAnnouncementProtocol
, 0, 1,
5246 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5248 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
5249 mask
, NL80211_MESHCONF_FORWARDING
,
5251 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
5252 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5254 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
5255 mask
, NL80211_MESHCONF_HT_OPMODE
,
5257 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
5259 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5261 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
5262 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5264 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5265 dot11MeshHWMPconfirmationInterval
,
5267 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5269 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
5270 NL80211_MESH_POWER_ACTIVE
,
5271 NL80211_MESH_POWER_MAX
,
5272 mask
, NL80211_MESHCONF_POWER_MODE
,
5274 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
5276 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
5277 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
5278 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5285 #undef FILL_IN_MESH_PARAM_IF_SET
5288 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
5289 struct mesh_setup
*setup
)
5291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5292 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
5294 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
5296 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
5297 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
5298 nl80211_mesh_setup_params_policy
))
5301 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
5302 setup
->sync_method
=
5303 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
5304 IEEE80211_SYNC_METHOD_VENDOR
:
5305 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
5307 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
5308 setup
->path_sel_proto
=
5309 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
5310 IEEE80211_PATH_PROTOCOL_VENDOR
:
5311 IEEE80211_PATH_PROTOCOL_HWMP
;
5313 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
5314 setup
->path_metric
=
5315 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
5316 IEEE80211_PATH_METRIC_VENDOR
:
5317 IEEE80211_PATH_METRIC_AIRTIME
;
5320 if (tb
[NL80211_MESH_SETUP_IE
]) {
5321 struct nlattr
*ieattr
=
5322 tb
[NL80211_MESH_SETUP_IE
];
5323 if (!is_valid_ie_attr(ieattr
))
5325 setup
->ie
= nla_data(ieattr
);
5326 setup
->ie_len
= nla_len(ieattr
);
5328 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
5329 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
5331 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
5332 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
5333 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
5334 if (setup
->is_secure
)
5335 setup
->user_mpm
= true;
5337 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
5338 if (!setup
->user_mpm
)
5341 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
5347 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
5348 struct genl_info
*info
)
5350 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5351 struct net_device
*dev
= info
->user_ptr
[1];
5352 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5353 struct mesh_config cfg
;
5357 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5360 if (!rdev
->ops
->update_mesh_config
)
5363 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
5368 if (!wdev
->mesh_id_len
)
5372 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
5379 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
5380 struct sk_buff
*msg
)
5382 struct nlattr
*nl_reg_rules
;
5385 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
5386 (regdom
->dfs_region
&&
5387 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
5388 goto nla_put_failure
;
5390 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
5392 goto nla_put_failure
;
5394 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
5395 struct nlattr
*nl_reg_rule
;
5396 const struct ieee80211_reg_rule
*reg_rule
;
5397 const struct ieee80211_freq_range
*freq_range
;
5398 const struct ieee80211_power_rule
*power_rule
;
5399 unsigned int max_bandwidth_khz
;
5401 reg_rule
= ®dom
->reg_rules
[i
];
5402 freq_range
= ®_rule
->freq_range
;
5403 power_rule
= ®_rule
->power_rule
;
5405 nl_reg_rule
= nla_nest_start(msg
, i
);
5407 goto nla_put_failure
;
5409 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
5410 if (!max_bandwidth_khz
)
5411 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
5414 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
5416 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
5417 freq_range
->start_freq_khz
) ||
5418 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
5419 freq_range
->end_freq_khz
) ||
5420 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
5421 max_bandwidth_khz
) ||
5422 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
5423 power_rule
->max_antenna_gain
) ||
5424 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
5425 power_rule
->max_eirp
) ||
5426 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
5427 reg_rule
->dfs_cac_ms
))
5428 goto nla_put_failure
;
5430 nla_nest_end(msg
, nl_reg_rule
);
5433 nla_nest_end(msg
, nl_reg_rules
);
5440 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
5442 const struct ieee80211_regdomain
*regdom
= NULL
;
5443 struct cfg80211_registered_device
*rdev
;
5444 struct wiphy
*wiphy
= NULL
;
5445 struct sk_buff
*msg
;
5448 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5452 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5453 NL80211_CMD_GET_REG
);
5457 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
5460 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
5463 return PTR_ERR(rdev
);
5466 wiphy
= &rdev
->wiphy
;
5467 self_managed
= wiphy
->regulatory_flags
&
5468 REGULATORY_WIPHY_SELF_MANAGED
;
5469 regdom
= get_wiphy_regdom(wiphy
);
5471 /* a self-managed-reg device must have a private regdom */
5472 if (WARN_ON(!regdom
&& self_managed
)) {
5478 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5479 goto nla_put_failure
;
5482 if (!wiphy
&& reg_last_request_cell_base() &&
5483 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5484 NL80211_USER_REG_HINT_CELL_BASE
))
5485 goto nla_put_failure
;
5490 regdom
= rcu_dereference(cfg80211_regdomain
);
5492 if (nl80211_put_regdom(regdom
, msg
))
5493 goto nla_put_failure_rcu
;
5497 genlmsg_end(msg
, hdr
);
5498 return genlmsg_reply(msg
, info
);
5500 nla_put_failure_rcu
:
5503 genlmsg_cancel(msg
, hdr
);
5509 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5510 u32 seq
, int flags
, struct wiphy
*wiphy
,
5511 const struct ieee80211_regdomain
*regdom
)
5513 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5514 NL80211_CMD_GET_REG
);
5519 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5521 if (nl80211_put_regdom(regdom
, msg
))
5522 goto nla_put_failure
;
5524 if (!wiphy
&& reg_last_request_cell_base() &&
5525 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5526 NL80211_USER_REG_HINT_CELL_BASE
))
5527 goto nla_put_failure
;
5530 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5531 goto nla_put_failure
;
5533 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
5534 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
5535 goto nla_put_failure
;
5537 genlmsg_end(msg
, hdr
);
5541 genlmsg_cancel(msg
, hdr
);
5545 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
5546 struct netlink_callback
*cb
)
5548 const struct ieee80211_regdomain
*regdom
= NULL
;
5549 struct cfg80211_registered_device
*rdev
;
5550 int err
, reg_idx
, start
= cb
->args
[2];
5554 if (cfg80211_regdomain
&& start
== 0) {
5555 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5557 rtnl_dereference(cfg80211_regdomain
));
5562 /* the global regdom is idx 0 */
5564 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
5565 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
5569 if (++reg_idx
<= start
)
5572 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5573 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
5580 cb
->args
[2] = reg_idx
;
5587 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
5588 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
5589 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
5590 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
5591 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
5592 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
5593 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
5594 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
5595 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
5598 static int parse_reg_rule(struct nlattr
*tb
[],
5599 struct ieee80211_reg_rule
*reg_rule
)
5601 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
5602 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
5604 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
5606 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
5608 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
5610 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
5612 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
5615 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
5617 freq_range
->start_freq_khz
=
5618 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
5619 freq_range
->end_freq_khz
=
5620 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
5621 freq_range
->max_bandwidth_khz
=
5622 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
5624 power_rule
->max_eirp
=
5625 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
5627 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
5628 power_rule
->max_antenna_gain
=
5629 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
5631 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
5632 reg_rule
->dfs_cac_ms
=
5633 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
5638 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5640 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5641 struct nlattr
*nl_reg_rule
;
5643 int rem_reg_rules
, r
;
5644 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5645 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
5646 struct ieee80211_regdomain
*rd
;
5648 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5651 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5654 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5656 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5657 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5659 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5662 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5666 if (!reg_is_valid_request(alpha2
))
5669 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5670 num_rules
* sizeof(struct ieee80211_reg_rule
);
5672 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5676 rd
->n_reg_rules
= num_rules
;
5677 rd
->alpha2
[0] = alpha2
[0];
5678 rd
->alpha2
[1] = alpha2
[1];
5681 * Disable DFS master mode if the DFS region was
5682 * not supported or known on this kernel.
5684 if (reg_supported_dfs_region(dfs_region
))
5685 rd
->dfs_region
= dfs_region
;
5687 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5689 r
= nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5690 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5694 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5700 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5706 r
= set_regdom(rd
, REGD_SOURCE_CRDA
);
5707 /* set_regdom took ownership */
5714 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
5716 static int validate_scan_freqs(struct nlattr
*freqs
)
5718 struct nlattr
*attr1
, *attr2
;
5719 int n_channels
= 0, tmp1
, tmp2
;
5721 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5724 * Some hardware has a limited channel list for
5725 * scanning, and it is pretty much nonsensical
5726 * to scan for a channel twice, so disallow that
5727 * and don't require drivers to check that the
5728 * channel list they get isn't longer than what
5729 * they can scan, as long as they can scan all
5730 * the channels they registered at once.
5732 nla_for_each_nested(attr2
, freqs
, tmp2
)
5733 if (attr1
!= attr2
&&
5734 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5741 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
5742 u8
*mac_addr
, u8
*mac_addr_mask
)
5746 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
5747 eth_zero_addr(mac_addr
);
5748 eth_zero_addr(mac_addr_mask
);
5750 mac_addr_mask
[0] = 0x3;
5755 /* need both or none */
5756 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
5759 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
5760 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
5762 /* don't allow or configure an mcast address */
5763 if (!is_multicast_ether_addr(mac_addr_mask
) ||
5764 is_multicast_ether_addr(mac_addr
))
5768 * allow users to pass a MAC address that has bits set outside
5769 * of the mask, but don't bother drivers with having to deal
5772 for (i
= 0; i
< ETH_ALEN
; i
++)
5773 mac_addr
[i
] &= mac_addr_mask
[i
];
5778 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5780 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5781 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5782 struct cfg80211_scan_request
*request
;
5783 struct nlattr
*attr
;
5784 struct wiphy
*wiphy
;
5785 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5788 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5791 wiphy
= &rdev
->wiphy
;
5793 if (!rdev
->ops
->scan
)
5796 if (rdev
->scan_req
|| rdev
->scan_msg
) {
5801 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5802 n_channels
= validate_scan_freqs(
5803 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5809 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
5812 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5813 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5816 if (n_ssids
> wiphy
->max_scan_ssids
) {
5821 if (info
->attrs
[NL80211_ATTR_IE
])
5822 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5826 if (ie_len
> wiphy
->max_scan_ie_len
) {
5831 request
= kzalloc(sizeof(*request
)
5832 + sizeof(*request
->ssids
) * n_ssids
5833 + sizeof(*request
->channels
) * n_channels
5834 + ie_len
, GFP_KERNEL
);
5841 request
->ssids
= (void *)&request
->channels
[n_channels
];
5842 request
->n_ssids
= n_ssids
;
5845 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5847 request
->ie
= (void *)(request
->channels
+ n_channels
);
5851 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5852 /* user specified, bail out if channel not found */
5853 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5854 struct ieee80211_channel
*chan
;
5856 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5863 /* ignore disabled channels */
5864 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5867 request
->channels
[i
] = chan
;
5871 enum ieee80211_band band
;
5874 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5876 if (!wiphy
->bands
[band
])
5878 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5879 struct ieee80211_channel
*chan
;
5881 chan
= &wiphy
->bands
[band
]->channels
[j
];
5883 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5886 request
->channels
[i
] = chan
;
5897 request
->n_channels
= i
;
5901 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5902 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5906 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5907 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5912 if (info
->attrs
[NL80211_ATTR_IE
]) {
5913 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5914 memcpy((void *)request
->ie
,
5915 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5919 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5920 if (wiphy
->bands
[i
])
5922 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5924 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5925 nla_for_each_nested(attr
,
5926 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5928 enum ieee80211_band band
= nla_type(attr
);
5930 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5935 if (!wiphy
->bands
[band
])
5938 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5941 &request
->rates
[band
]);
5947 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5948 request
->flags
= nla_get_u32(
5949 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5950 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5951 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
5956 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
5957 if (!(wiphy
->features
&
5958 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
)) {
5963 if (wdev
->current_bss
) {
5968 err
= nl80211_parse_random_mac(info
->attrs
,
5970 request
->mac_addr_mask
);
5977 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5979 request
->wdev
= wdev
;
5980 request
->wiphy
= &rdev
->wiphy
;
5981 request
->scan_start
= jiffies
;
5983 rdev
->scan_req
= request
;
5984 err
= rdev_scan(rdev
, request
);
5987 nl80211_send_scan_start(rdev
, wdev
);
5989 dev_hold(wdev
->netdev
);
5992 rdev
->scan_req
= NULL
;
6001 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
6002 struct cfg80211_sched_scan_request
*request
,
6003 struct nlattr
**attrs
)
6005 int tmp
, err
, i
= 0;
6006 struct nlattr
*attr
;
6008 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6012 * If scan plans are not specified,
6013 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6014 * case one scan plan will be set with the specified scan
6015 * interval and infinite number of iterations.
6017 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6020 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
6024 request
->scan_plans
[0].interval
=
6025 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
6026 if (!request
->scan_plans
[0].interval
)
6029 if (request
->scan_plans
[0].interval
>
6030 wiphy
->max_sched_scan_plan_interval
)
6031 request
->scan_plans
[0].interval
=
6032 wiphy
->max_sched_scan_plan_interval
;
6037 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
6038 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
6040 if (WARN_ON(i
>= n_plans
))
6043 err
= nla_parse(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
6044 nla_data(attr
), nla_len(attr
),
6045 nl80211_plan_policy
);
6049 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
6052 request
->scan_plans
[i
].interval
=
6053 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
6054 if (!request
->scan_plans
[i
].interval
||
6055 request
->scan_plans
[i
].interval
>
6056 wiphy
->max_sched_scan_plan_interval
)
6059 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
6060 request
->scan_plans
[i
].iterations
=
6061 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
6062 if (!request
->scan_plans
[i
].iterations
||
6063 (request
->scan_plans
[i
].iterations
>
6064 wiphy
->max_sched_scan_plan_iterations
))
6066 } else if (i
< n_plans
- 1) {
6068 * All scan plans but the last one must specify
6069 * a finite number of iterations
6078 * The last scan plan must not specify the number of
6079 * iterations, it is supposed to run infinitely
6081 if (request
->scan_plans
[n_plans
- 1].iterations
)
6087 static struct cfg80211_sched_scan_request
*
6088 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6089 struct nlattr
**attrs
)
6091 struct cfg80211_sched_scan_request
*request
;
6092 struct nlattr
*attr
;
6093 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
6094 enum ieee80211_band band
;
6096 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
6097 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
6099 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
6100 return ERR_PTR(-EINVAL
);
6102 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6103 n_channels
= validate_scan_freqs(
6104 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6106 return ERR_PTR(-EINVAL
);
6108 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6111 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
6112 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6116 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
6117 return ERR_PTR(-EINVAL
);
6120 * First, count the number of 'real' matchsets. Due to an issue with
6121 * the old implementation, matchsets containing only the RSSI attribute
6122 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6123 * RSSI for all matchsets, rather than their own matchset for reporting
6124 * all APs with a strong RSSI. This is needed to be compatible with
6125 * older userspace that treated a matchset with only the RSSI as the
6126 * global RSSI for all other matchsets - if there are other matchsets.
6128 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6129 nla_for_each_nested(attr
,
6130 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6132 struct nlattr
*rssi
;
6134 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6135 nla_data(attr
), nla_len(attr
),
6136 nl80211_match_policy
);
6138 return ERR_PTR(err
);
6139 /* add other standalone attributes here */
6140 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
]) {
6144 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6146 default_match_rssi
= nla_get_s32(rssi
);
6150 /* However, if there's no other matchset, add the RSSI one */
6151 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
6154 if (n_match_sets
> wiphy
->max_match_sets
)
6155 return ERR_PTR(-EINVAL
);
6157 if (attrs
[NL80211_ATTR_IE
])
6158 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
6162 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
6163 return ERR_PTR(-EINVAL
);
6165 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6167 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6168 * each scan plan already specifies its own interval
6170 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6171 return ERR_PTR(-EINVAL
);
6173 nla_for_each_nested(attr
,
6174 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
6178 * The scan interval attribute is kept for backward
6179 * compatibility. If no scan plans are specified and sched scan
6180 * interval is specified, one scan plan will be set with this
6181 * scan interval and infinite number of iterations.
6183 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6184 return ERR_PTR(-EINVAL
);
6189 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
6190 return ERR_PTR(-EINVAL
);
6192 request
= kzalloc(sizeof(*request
)
6193 + sizeof(*request
->ssids
) * n_ssids
6194 + sizeof(*request
->match_sets
) * n_match_sets
6195 + sizeof(*request
->scan_plans
) * n_plans
6196 + sizeof(*request
->channels
) * n_channels
6197 + ie_len
, GFP_KERNEL
);
6199 return ERR_PTR(-ENOMEM
);
6202 request
->ssids
= (void *)&request
->channels
[n_channels
];
6203 request
->n_ssids
= n_ssids
;
6206 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6208 request
->ie
= (void *)(request
->channels
+ n_channels
);
6213 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
6215 request
->match_sets
=
6216 (void *)(request
->ssids
+ n_ssids
);
6218 request
->match_sets
=
6219 (void *)(request
->channels
+ n_channels
);
6221 request
->n_match_sets
= n_match_sets
;
6224 request
->scan_plans
= (void *)(request
->match_sets
+
6226 else if (request
->ie
)
6227 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
6229 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
6231 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
6233 request
->n_scan_plans
= n_plans
;
6236 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6237 /* user specified, bail out if channel not found */
6238 nla_for_each_nested(attr
,
6239 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
6241 struct ieee80211_channel
*chan
;
6243 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6250 /* ignore disabled channels */
6251 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6254 request
->channels
[i
] = chan
;
6259 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6261 if (!wiphy
->bands
[band
])
6263 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6264 struct ieee80211_channel
*chan
;
6266 chan
= &wiphy
->bands
[band
]->channels
[j
];
6268 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6271 request
->channels
[i
] = chan
;
6282 request
->n_channels
= i
;
6286 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6288 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6292 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6293 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
6300 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6301 nla_for_each_nested(attr
,
6302 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6304 struct nlattr
*ssid
, *rssi
;
6306 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6307 nla_data(attr
), nla_len(attr
),
6308 nl80211_match_policy
);
6311 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
6313 if (WARN_ON(i
>= n_match_sets
)) {
6314 /* this indicates a programming error,
6315 * the loop above should have verified
6322 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
6326 memcpy(request
->match_sets
[i
].ssid
.ssid
,
6327 nla_data(ssid
), nla_len(ssid
));
6328 request
->match_sets
[i
].ssid
.ssid_len
=
6330 /* special attribute - old implemenation w/a */
6331 request
->match_sets
[i
].rssi_thold
=
6333 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6335 request
->match_sets
[i
].rssi_thold
=
6341 /* there was no other matchset, so the RSSI one is alone */
6342 if (i
== 0 && n_match_sets
)
6343 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
6345 request
->min_rssi_thold
= INT_MAX
;
6346 for (i
= 0; i
< n_match_sets
; i
++)
6347 request
->min_rssi_thold
=
6348 min(request
->match_sets
[i
].rssi_thold
,
6349 request
->min_rssi_thold
);
6351 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
6355 request
->ie_len
= ie_len
;
6356 memcpy((void *)request
->ie
,
6357 nla_data(attrs
[NL80211_ATTR_IE
]),
6361 if (attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
6362 request
->flags
= nla_get_u32(
6363 attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6364 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6365 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
6370 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6371 u32 flg
= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
;
6373 if (!wdev
) /* must be net-detect */
6374 flg
= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
6376 if (!(wiphy
->features
& flg
)) {
6381 if (wdev
&& wdev
->current_bss
) {
6386 err
= nl80211_parse_random_mac(attrs
, request
->mac_addr
,
6387 request
->mac_addr_mask
);
6393 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
6395 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
6397 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
6401 request
->scan_start
= jiffies
;
6407 return ERR_PTR(err
);
6410 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
6411 struct genl_info
*info
)
6413 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6414 struct net_device
*dev
= info
->user_ptr
[1];
6415 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6416 struct cfg80211_sched_scan_request
*sched_scan_req
;
6419 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6420 !rdev
->ops
->sched_scan_start
)
6423 if (rdev
->sched_scan_req
)
6424 return -EINPROGRESS
;
6426 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
6429 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
6433 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
6437 sched_scan_req
->dev
= dev
;
6438 sched_scan_req
->wiphy
= &rdev
->wiphy
;
6440 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
6441 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
6443 rcu_assign_pointer(rdev
->sched_scan_req
, sched_scan_req
);
6445 nl80211_send_sched_scan(rdev
, dev
,
6446 NL80211_CMD_START_SCHED_SCAN
);
6450 kfree(sched_scan_req
);
6455 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
6456 struct genl_info
*info
)
6458 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6460 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6461 !rdev
->ops
->sched_scan_stop
)
6464 return __cfg80211_stop_sched_scan(rdev
, false);
6467 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
6468 struct genl_info
*info
)
6470 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6471 struct net_device
*dev
= info
->user_ptr
[1];
6472 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6473 struct cfg80211_chan_def chandef
;
6474 enum nl80211_dfs_regions dfs_region
;
6475 unsigned int cac_time_ms
;
6478 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
6479 if (dfs_region
== NL80211_DFS_UNSET
)
6482 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6486 if (netif_carrier_ok(dev
))
6489 if (wdev
->cac_started
)
6492 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
6500 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
6503 if (!rdev
->ops
->start_radar_detection
)
6506 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
6507 if (WARN_ON(!cac_time_ms
))
6508 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
6510 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
,
6513 wdev
->chandef
= chandef
;
6514 wdev
->cac_started
= true;
6515 wdev
->cac_start_time
= jiffies
;
6516 wdev
->cac_time_ms
= cac_time_ms
;
6521 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
6523 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6524 struct net_device
*dev
= info
->user_ptr
[1];
6525 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6526 struct cfg80211_csa_settings params
;
6527 /* csa_attrs is defined static to avoid waste of stack size - this
6528 * function is called under RTNL lock, so this should not be a problem.
6530 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
6532 bool need_new_beacon
= false;
6536 if (!rdev
->ops
->channel_switch
||
6537 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
6540 switch (dev
->ieee80211_ptr
->iftype
) {
6541 case NL80211_IFTYPE_AP
:
6542 case NL80211_IFTYPE_P2P_GO
:
6543 need_new_beacon
= true;
6545 /* useless if AP is not running */
6546 if (!wdev
->beacon_interval
)
6549 case NL80211_IFTYPE_ADHOC
:
6550 if (!wdev
->ssid_len
)
6553 case NL80211_IFTYPE_MESH_POINT
:
6554 if (!wdev
->mesh_id_len
)
6561 memset(¶ms
, 0, sizeof(params
));
6563 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6564 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
6567 /* only important for AP, IBSS and mesh create IEs internally */
6568 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
6571 /* Even though the attribute is u32, the specification says
6572 * u8, so let's make sure we don't overflow.
6574 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
6578 params
.count
= cs_count
;
6580 if (!need_new_beacon
)
6583 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
6587 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
6588 info
->attrs
[NL80211_ATTR_CSA_IES
],
6593 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
6597 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
6600 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6601 if (!len
|| (len
% sizeof(u16
)))
6604 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
6605 if (rdev
->wiphy
.max_num_csa_counters
&&
6606 (params
.n_counter_offsets_beacon
>
6607 rdev
->wiphy
.max_num_csa_counters
))
6610 params
.counter_offsets_beacon
=
6611 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6613 /* sanity checks - counters should fit and be the same */
6614 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
6615 u16 offset
= params
.counter_offsets_beacon
[i
];
6617 if (offset
>= params
.beacon_csa
.tail_len
)
6620 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
6624 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
6625 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6626 if (!len
|| (len
% sizeof(u16
)))
6629 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
6630 if (rdev
->wiphy
.max_num_csa_counters
&&
6631 (params
.n_counter_offsets_beacon
>
6632 rdev
->wiphy
.max_num_csa_counters
))
6635 params
.counter_offsets_presp
=
6636 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6638 /* sanity checks - counters should fit and be the same */
6639 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
6640 u16 offset
= params
.counter_offsets_presp
[i
];
6642 if (offset
>= params
.beacon_csa
.probe_resp_len
)
6645 if (params
.beacon_csa
.probe_resp
[offset
] !=
6652 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
6656 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
6660 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
6667 params
.radar_required
= true;
6669 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
6670 params
.block_tx
= true;
6673 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
6679 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6681 struct cfg80211_registered_device
*rdev
,
6682 struct wireless_dev
*wdev
,
6683 struct cfg80211_internal_bss
*intbss
)
6685 struct cfg80211_bss
*res
= &intbss
->pub
;
6686 const struct cfg80211_bss_ies
*ies
;
6690 ASSERT_WDEV_LOCK(wdev
);
6692 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6693 NL80211_CMD_NEW_SCAN_RESULTS
);
6697 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
6699 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
6700 goto nla_put_failure
;
6702 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
6703 goto nla_put_failure
;
6704 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
6705 goto nla_put_failure
;
6707 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
6709 goto nla_put_failure
;
6710 if ((!is_zero_ether_addr(res
->bssid
) &&
6711 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
6712 goto nla_put_failure
;
6715 /* indicate whether we have probe response data or not */
6716 if (rcu_access_pointer(res
->proberesp_ies
) &&
6717 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
6718 goto fail_unlock_rcu
;
6720 /* this pointer prefers to be pointed to probe response data
6721 * but is always valid
6723 ies
= rcu_dereference(res
->ies
);
6725 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
6726 goto fail_unlock_rcu
;
6727 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
6728 ies
->len
, ies
->data
))
6729 goto fail_unlock_rcu
;
6732 /* and this pointer is always (unless driver didn't know) beacon data */
6733 ies
= rcu_dereference(res
->beacon_ies
);
6734 if (ies
&& ies
->from_beacon
) {
6735 if (nla_put_u64(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
))
6736 goto fail_unlock_rcu
;
6737 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
6738 ies
->len
, ies
->data
))
6739 goto fail_unlock_rcu
;
6743 if (res
->beacon_interval
&&
6744 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
6745 goto nla_put_failure
;
6746 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
6747 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
6748 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
6749 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
6750 jiffies_to_msecs(jiffies
- intbss
->ts
)))
6751 goto nla_put_failure
;
6753 if (intbss
->ts_boottime
&&
6754 nla_put_u64(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
6755 intbss
->ts_boottime
))
6756 goto nla_put_failure
;
6758 switch (rdev
->wiphy
.signal_type
) {
6759 case CFG80211_SIGNAL_TYPE_MBM
:
6760 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
6761 goto nla_put_failure
;
6763 case CFG80211_SIGNAL_TYPE_UNSPEC
:
6764 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
6765 goto nla_put_failure
;
6771 switch (wdev
->iftype
) {
6772 case NL80211_IFTYPE_P2P_CLIENT
:
6773 case NL80211_IFTYPE_STATION
:
6774 if (intbss
== wdev
->current_bss
&&
6775 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6776 NL80211_BSS_STATUS_ASSOCIATED
))
6777 goto nla_put_failure
;
6779 case NL80211_IFTYPE_ADHOC
:
6780 if (intbss
== wdev
->current_bss
&&
6781 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6782 NL80211_BSS_STATUS_IBSS_JOINED
))
6783 goto nla_put_failure
;
6789 nla_nest_end(msg
, bss
);
6791 genlmsg_end(msg
, hdr
);
6797 genlmsg_cancel(msg
, hdr
);
6801 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6803 struct cfg80211_registered_device
*rdev
;
6804 struct cfg80211_internal_bss
*scan
;
6805 struct wireless_dev
*wdev
;
6806 int start
= cb
->args
[2], idx
= 0;
6809 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6814 spin_lock_bh(&rdev
->bss_lock
);
6815 cfg80211_bss_expire(rdev
);
6817 cb
->seq
= rdev
->bss_generation
;
6819 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
6822 if (nl80211_send_bss(skb
, cb
,
6823 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6824 rdev
, wdev
, scan
) < 0) {
6830 spin_unlock_bh(&rdev
->bss_lock
);
6834 nl80211_finish_wdev_dump(rdev
);
6839 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
6840 int flags
, struct net_device
*dev
,
6841 bool allow_radio_stats
,
6842 struct survey_info
*survey
)
6845 struct nlattr
*infoattr
;
6847 /* skip radio stats if userspace didn't request them */
6848 if (!survey
->channel
&& !allow_radio_stats
)
6851 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
6852 NL80211_CMD_NEW_SURVEY_RESULTS
);
6856 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
6857 goto nla_put_failure
;
6859 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
6861 goto nla_put_failure
;
6863 if (survey
->channel
&&
6864 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
6865 survey
->channel
->center_freq
))
6866 goto nla_put_failure
;
6868 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
6869 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
6870 goto nla_put_failure
;
6871 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
6872 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
6873 goto nla_put_failure
;
6874 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
6875 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME
,
6877 goto nla_put_failure
;
6878 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
6879 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
6881 goto nla_put_failure
;
6882 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
6883 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
6884 survey
->time_ext_busy
))
6885 goto nla_put_failure
;
6886 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
6887 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_RX
,
6889 goto nla_put_failure
;
6890 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
6891 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_TX
,
6893 goto nla_put_failure
;
6894 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
6895 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
6897 goto nla_put_failure
;
6899 nla_nest_end(msg
, infoattr
);
6901 genlmsg_end(msg
, hdr
);
6905 genlmsg_cancel(msg
, hdr
);
6909 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6911 struct survey_info survey
;
6912 struct cfg80211_registered_device
*rdev
;
6913 struct wireless_dev
*wdev
;
6914 int survey_idx
= cb
->args
[2];
6918 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6922 /* prepare_wdev_dump parsed the attributes */
6923 radio_stats
= nl80211_fam
.attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
6925 if (!wdev
->netdev
) {
6930 if (!rdev
->ops
->dump_survey
) {
6936 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
6942 /* don't send disabled channels, but do send non-channel data */
6943 if (survey
.channel
&&
6944 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
6949 if (nl80211_send_survey(skb
,
6950 NETLINK_CB(cb
->skb
).portid
,
6951 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6952 wdev
->netdev
, radio_stats
, &survey
) < 0)
6958 cb
->args
[2] = survey_idx
;
6961 nl80211_finish_wdev_dump(rdev
);
6965 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
6967 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
6968 NL80211_WPA_VERSION_2
));
6971 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6973 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6974 struct net_device
*dev
= info
->user_ptr
[1];
6975 struct ieee80211_channel
*chan
;
6976 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
6977 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
6978 enum nl80211_auth_type auth_type
;
6979 struct key_parse key
;
6980 bool local_state_change
;
6982 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6985 if (!info
->attrs
[NL80211_ATTR_MAC
])
6988 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
6991 if (!info
->attrs
[NL80211_ATTR_SSID
])
6994 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6997 err
= nl80211_parse_key(info
, &key
);
7002 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
7004 if (!key
.p
.key
|| !key
.p
.key_len
)
7006 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
7007 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
7008 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
7009 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
7021 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
7022 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
7031 if (!rdev
->ops
->auth
)
7034 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7035 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7038 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7039 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7040 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7044 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7045 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7047 if (info
->attrs
[NL80211_ATTR_IE
]) {
7048 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7049 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7052 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7053 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
7056 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
7057 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
7060 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
7061 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
7063 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7064 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7065 /* need to include at least Auth Transaction and Status Code */
7066 if (sae_data_len
< 4)
7070 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7073 * Since we no longer track auth state, ignore
7074 * requests to only change local state.
7076 if (local_state_change
)
7079 wdev_lock(dev
->ieee80211_ptr
);
7080 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
7081 ssid
, ssid_len
, ie
, ie_len
,
7082 key
.p
.key
, key
.p
.key_len
, key
.idx
,
7083 sae_data
, sae_data_len
);
7084 wdev_unlock(dev
->ieee80211_ptr
);
7088 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
7089 struct genl_info
*info
,
7090 struct cfg80211_crypto_settings
*settings
,
7093 memset(settings
, 0, sizeof(*settings
));
7095 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
7097 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
7099 proto
= nla_get_u16(
7100 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
7101 settings
->control_port_ethertype
= cpu_to_be16(proto
);
7102 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
7105 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
7106 settings
->control_port_no_encrypt
= true;
7108 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
7110 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
7114 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7115 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7116 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
7118 if (len
% sizeof(u32
))
7121 if (settings
->n_ciphers_pairwise
> cipher_limit
)
7124 memcpy(settings
->ciphers_pairwise
, data
, len
);
7126 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
7127 if (!cfg80211_supported_cipher_suite(
7129 settings
->ciphers_pairwise
[i
]))
7133 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
7134 settings
->cipher_group
=
7135 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
7136 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
7137 settings
->cipher_group
))
7141 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
7142 settings
->wpa_versions
=
7143 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
7144 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
7148 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
7152 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7153 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7154 settings
->n_akm_suites
= len
/ sizeof(u32
);
7156 if (len
% sizeof(u32
))
7159 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
7162 memcpy(settings
->akm_suites
, data
, len
);
7168 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
7170 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7171 struct net_device
*dev
= info
->user_ptr
[1];
7172 struct ieee80211_channel
*chan
;
7173 struct cfg80211_assoc_request req
= {};
7174 const u8
*bssid
, *ssid
;
7175 int err
, ssid_len
= 0;
7177 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7180 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
7181 !info
->attrs
[NL80211_ATTR_SSID
] ||
7182 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7185 if (!rdev
->ops
->assoc
)
7188 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7189 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7192 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7194 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7195 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7199 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7200 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7202 if (info
->attrs
[NL80211_ATTR_IE
]) {
7203 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7204 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7207 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7208 enum nl80211_mfp mfp
=
7209 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7210 if (mfp
== NL80211_MFP_REQUIRED
)
7212 else if (mfp
!= NL80211_MFP_NO
)
7216 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
7217 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
7219 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7220 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
7222 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7223 memcpy(&req
.ht_capa_mask
,
7224 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7225 sizeof(req
.ht_capa_mask
));
7227 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7228 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7230 memcpy(&req
.ht_capa
,
7231 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7232 sizeof(req
.ht_capa
));
7235 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7236 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7238 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7239 memcpy(&req
.vht_capa_mask
,
7240 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7241 sizeof(req
.vht_capa_mask
));
7243 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7244 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7246 memcpy(&req
.vht_capa
,
7247 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7248 sizeof(req
.vht_capa
));
7251 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7252 if (!(rdev
->wiphy
.features
&
7253 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) ||
7254 !(rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
))
7256 req
.flags
|= ASSOC_REQ_USE_RRM
;
7259 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
7261 wdev_lock(dev
->ieee80211_ptr
);
7262 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
7263 ssid
, ssid_len
, &req
);
7264 wdev_unlock(dev
->ieee80211_ptr
);
7270 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
7272 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7273 struct net_device
*dev
= info
->user_ptr
[1];
7274 const u8
*ie
= NULL
, *bssid
;
7275 int ie_len
= 0, err
;
7277 bool local_state_change
;
7279 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7282 if (!info
->attrs
[NL80211_ATTR_MAC
])
7285 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7288 if (!rdev
->ops
->deauth
)
7291 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7292 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7295 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7297 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7298 if (reason_code
== 0) {
7299 /* Reason Code 0 is reserved */
7303 if (info
->attrs
[NL80211_ATTR_IE
]) {
7304 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7305 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7308 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7310 wdev_lock(dev
->ieee80211_ptr
);
7311 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7312 local_state_change
);
7313 wdev_unlock(dev
->ieee80211_ptr
);
7317 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
7319 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7320 struct net_device
*dev
= info
->user_ptr
[1];
7321 const u8
*ie
= NULL
, *bssid
;
7322 int ie_len
= 0, err
;
7324 bool local_state_change
;
7326 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7329 if (!info
->attrs
[NL80211_ATTR_MAC
])
7332 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7335 if (!rdev
->ops
->disassoc
)
7338 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7339 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7342 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7344 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7345 if (reason_code
== 0) {
7346 /* Reason Code 0 is reserved */
7350 if (info
->attrs
[NL80211_ATTR_IE
]) {
7351 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7352 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7355 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7357 wdev_lock(dev
->ieee80211_ptr
);
7358 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7359 local_state_change
);
7360 wdev_unlock(dev
->ieee80211_ptr
);
7365 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
7366 int mcast_rate
[IEEE80211_NUM_BANDS
],
7369 struct wiphy
*wiphy
= &rdev
->wiphy
;
7373 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
7374 struct ieee80211_supported_band
*sband
;
7376 sband
= wiphy
->bands
[band
];
7380 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
7381 if (sband
->bitrates
[i
].bitrate
== rateval
) {
7382 mcast_rate
[band
] = i
+ 1;
7392 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7394 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7395 struct net_device
*dev
= info
->user_ptr
[1];
7396 struct cfg80211_ibss_params ibss
;
7397 struct wiphy
*wiphy
;
7398 struct cfg80211_cached_keys
*connkeys
= NULL
;
7401 memset(&ibss
, 0, sizeof(ibss
));
7403 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7406 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7407 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7410 ibss
.beacon_interval
= 100;
7412 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7413 ibss
.beacon_interval
=
7414 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7415 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
7419 if (!rdev
->ops
->join_ibss
)
7422 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7425 wiphy
= &rdev
->wiphy
;
7427 if (info
->attrs
[NL80211_ATTR_MAC
]) {
7428 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7430 if (!is_valid_ether_addr(ibss
.bssid
))
7433 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7434 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7436 if (info
->attrs
[NL80211_ATTR_IE
]) {
7437 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7438 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7441 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
7445 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
7446 NL80211_IFTYPE_ADHOC
))
7449 switch (ibss
.chandef
.width
) {
7450 case NL80211_CHAN_WIDTH_5
:
7451 case NL80211_CHAN_WIDTH_10
:
7452 case NL80211_CHAN_WIDTH_20_NOHT
:
7454 case NL80211_CHAN_WIDTH_20
:
7455 case NL80211_CHAN_WIDTH_40
:
7456 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7459 case NL80211_CHAN_WIDTH_80
:
7460 case NL80211_CHAN_WIDTH_80P80
:
7461 case NL80211_CHAN_WIDTH_160
:
7462 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7464 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
7465 NL80211_EXT_FEATURE_VHT_IBSS
))
7472 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
7473 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
7475 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7477 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7479 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7480 struct ieee80211_supported_band
*sband
=
7481 wiphy
->bands
[ibss
.chandef
.chan
->band
];
7483 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7489 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7490 memcpy(&ibss
.ht_capa_mask
,
7491 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7492 sizeof(ibss
.ht_capa_mask
));
7494 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7495 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7497 memcpy(&ibss
.ht_capa
,
7498 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7499 sizeof(ibss
.ht_capa
));
7502 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7503 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
7504 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7507 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7510 connkeys
= nl80211_parse_connkeys(rdev
,
7511 info
->attrs
[NL80211_ATTR_KEYS
],
7513 if (IS_ERR(connkeys
))
7514 return PTR_ERR(connkeys
);
7516 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
7524 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
7526 ibss
.userspace_handles_dfs
=
7527 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
7529 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
7535 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7537 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7538 struct net_device
*dev
= info
->user_ptr
[1];
7540 if (!rdev
->ops
->leave_ibss
)
7543 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7546 return cfg80211_leave_ibss(rdev
, dev
, false);
7549 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
7551 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7552 struct net_device
*dev
= info
->user_ptr
[1];
7553 int mcast_rate
[IEEE80211_NUM_BANDS
];
7557 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
7558 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
7559 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
7562 if (!rdev
->ops
->set_mcast_rate
)
7565 memset(mcast_rate
, 0, sizeof(mcast_rate
));
7567 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
7570 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
7571 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
7574 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
7579 static struct sk_buff
*
7580 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
7581 struct wireless_dev
*wdev
, int approxlen
,
7582 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
7583 enum nl80211_attrs attr
,
7584 const struct nl80211_vendor_cmd_info
*info
,
7587 struct sk_buff
*skb
;
7589 struct nlattr
*data
;
7591 skb
= nlmsg_new(approxlen
+ 100, gfp
);
7595 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
7601 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
7602 goto nla_put_failure
;
7605 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
7607 goto nla_put_failure
;
7608 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
7610 goto nla_put_failure
;
7614 if (nla_put_u64(skb
, NL80211_ATTR_WDEV
,
7616 goto nla_put_failure
;
7618 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
7619 wdev
->netdev
->ifindex
))
7620 goto nla_put_failure
;
7623 data
= nla_nest_start(skb
, attr
);
7625 ((void **)skb
->cb
)[0] = rdev
;
7626 ((void **)skb
->cb
)[1] = hdr
;
7627 ((void **)skb
->cb
)[2] = data
;
7636 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
7637 struct wireless_dev
*wdev
,
7638 enum nl80211_commands cmd
,
7639 enum nl80211_attrs attr
,
7640 int vendor_event_idx
,
7641 int approxlen
, gfp_t gfp
)
7643 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
7644 const struct nl80211_vendor_cmd_info
*info
;
7647 case NL80211_CMD_TESTMODE
:
7648 if (WARN_ON(vendor_event_idx
!= -1))
7652 case NL80211_CMD_VENDOR
:
7653 if (WARN_ON(vendor_event_idx
< 0 ||
7654 vendor_event_idx
>= wiphy
->n_vendor_events
))
7656 info
= &wiphy
->vendor_events
[vendor_event_idx
];
7663 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
7664 cmd
, attr
, info
, gfp
);
7666 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
7668 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
7670 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
7671 void *hdr
= ((void **)skb
->cb
)[1];
7672 struct nlattr
*data
= ((void **)skb
->cb
)[2];
7673 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
7675 /* clear CB data for netlink core to own from now on */
7676 memset(skb
->cb
, 0, sizeof(skb
->cb
));
7678 nla_nest_end(skb
, data
);
7679 genlmsg_end(skb
, hdr
);
7681 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
7682 mcgrp
= NL80211_MCGRP_VENDOR
;
7684 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
7687 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
7689 #ifdef CONFIG_NL80211_TESTMODE
7690 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
7692 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7693 struct wireless_dev
*wdev
=
7694 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
7697 if (!rdev
->ops
->testmode_cmd
)
7701 err
= PTR_ERR(wdev
);
7705 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
7709 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
7712 rdev
->cur_cmd_info
= info
;
7713 err
= rdev_testmode_cmd(rdev
, wdev
,
7714 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
7715 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
7716 rdev
->cur_cmd_info
= NULL
;
7721 static int nl80211_testmode_dump(struct sk_buff
*skb
,
7722 struct netlink_callback
*cb
)
7724 struct cfg80211_registered_device
*rdev
;
7734 * 0 is a valid index, but not valid for args[0],
7735 * so we need to offset by 1.
7737 phy_idx
= cb
->args
[0] - 1;
7739 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
7740 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
7745 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
7746 nl80211_fam
.attrbuf
);
7748 err
= PTR_ERR(rdev
);
7751 phy_idx
= rdev
->wiphy_idx
;
7754 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
7756 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
7760 data
= nla_data((void *)cb
->args
[1]);
7761 data_len
= nla_len((void *)cb
->args
[1]);
7764 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
7770 if (!rdev
->ops
->testmode_dump
) {
7776 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
7777 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7778 NL80211_CMD_TESTMODE
);
7779 struct nlattr
*tmdata
;
7784 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
7785 genlmsg_cancel(skb
, hdr
);
7789 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
7791 genlmsg_cancel(skb
, hdr
);
7794 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
7795 nla_nest_end(skb
, tmdata
);
7797 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
7798 genlmsg_cancel(skb
, hdr
);
7801 genlmsg_cancel(skb
, hdr
);
7805 genlmsg_end(skb
, hdr
);
7810 cb
->args
[0] = phy_idx
+ 1;
7817 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
7819 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7820 struct net_device
*dev
= info
->user_ptr
[1];
7821 struct cfg80211_connect_params connect
;
7822 struct wiphy
*wiphy
;
7823 struct cfg80211_cached_keys
*connkeys
= NULL
;
7826 memset(&connect
, 0, sizeof(connect
));
7828 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7831 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7832 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7835 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
7837 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7838 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
7839 NL80211_CMD_CONNECT
))
7842 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
7844 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
7846 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
7847 NL80211_MAX_NR_CIPHER_SUITES
);
7851 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7852 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7855 wiphy
= &rdev
->wiphy
;
7857 connect
.bg_scan_period
= -1;
7858 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
7859 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
7860 connect
.bg_scan_period
=
7861 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
7864 if (info
->attrs
[NL80211_ATTR_MAC
])
7865 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7866 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
7867 connect
.bssid_hint
=
7868 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
7869 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7870 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7872 if (info
->attrs
[NL80211_ATTR_IE
]) {
7873 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7874 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7877 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7878 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7879 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
7880 connect
.mfp
!= NL80211_MFP_NO
)
7883 connect
.mfp
= NL80211_MFP_NO
;
7886 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7887 connect
.channel
= nl80211_get_valid_chan(
7888 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7889 if (!connect
.channel
)
7891 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
7892 connect
.channel_hint
= nl80211_get_valid_chan(
7893 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
7894 if (!connect
.channel_hint
)
7898 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7899 connkeys
= nl80211_parse_connkeys(rdev
,
7900 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
7901 if (IS_ERR(connkeys
))
7902 return PTR_ERR(connkeys
);
7905 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7906 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
7908 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7909 memcpy(&connect
.ht_capa_mask
,
7910 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7911 sizeof(connect
.ht_capa_mask
));
7913 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7914 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
7918 memcpy(&connect
.ht_capa
,
7919 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7920 sizeof(connect
.ht_capa
));
7923 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7924 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7926 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7927 memcpy(&connect
.vht_capa_mask
,
7928 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7929 sizeof(connect
.vht_capa_mask
));
7931 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7932 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
7936 memcpy(&connect
.vht_capa
,
7937 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7938 sizeof(connect
.vht_capa
));
7941 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7942 if (!(rdev
->wiphy
.features
&
7943 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) ||
7944 !(rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
))
7946 connect
.flags
|= ASSOC_REQ_USE_RRM
;
7949 wdev_lock(dev
->ieee80211_ptr
);
7950 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
7951 wdev_unlock(dev
->ieee80211_ptr
);
7957 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
7959 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7960 struct net_device
*dev
= info
->user_ptr
[1];
7964 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7965 reason
= WLAN_REASON_DEAUTH_LEAVING
;
7967 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7972 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7973 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7976 wdev_lock(dev
->ieee80211_ptr
);
7977 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
7978 wdev_unlock(dev
->ieee80211_ptr
);
7982 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
7984 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7988 if (info
->attrs
[NL80211_ATTR_PID
]) {
7989 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
7991 net
= get_net_ns_by_pid(pid
);
7992 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
7993 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
7995 net
= get_net_ns_by_fd(fd
);
8001 return PTR_ERR(net
);
8005 /* check if anything to do */
8006 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
8007 err
= cfg80211_switch_netns(rdev
, net
);
8013 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8015 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8016 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
8017 struct cfg80211_pmksa
*pmksa
) = NULL
;
8018 struct net_device
*dev
= info
->user_ptr
[1];
8019 struct cfg80211_pmksa pmksa
;
8021 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
8023 if (!info
->attrs
[NL80211_ATTR_MAC
])
8026 if (!info
->attrs
[NL80211_ATTR_PMKID
])
8029 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
8030 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8032 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8033 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8036 switch (info
->genlhdr
->cmd
) {
8037 case NL80211_CMD_SET_PMKSA
:
8038 rdev_ops
= rdev
->ops
->set_pmksa
;
8040 case NL80211_CMD_DEL_PMKSA
:
8041 rdev_ops
= rdev
->ops
->del_pmksa
;
8051 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
8054 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8056 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8057 struct net_device
*dev
= info
->user_ptr
[1];
8059 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8060 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8063 if (!rdev
->ops
->flush_pmksa
)
8066 return rdev_flush_pmksa(rdev
, dev
);
8069 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8071 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8072 struct net_device
*dev
= info
->user_ptr
[1];
8073 u8 action_code
, dialog_token
;
8074 u32 peer_capability
= 0;
8079 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8080 !rdev
->ops
->tdls_mgmt
)
8083 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
8084 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
8085 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
8086 !info
->attrs
[NL80211_ATTR_IE
] ||
8087 !info
->attrs
[NL80211_ATTR_MAC
])
8090 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8091 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
8092 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
8093 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
8094 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
8095 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
8097 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
8099 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
8100 dialog_token
, status_code
, peer_capability
,
8102 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
8103 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
8106 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
8108 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8109 struct net_device
*dev
= info
->user_ptr
[1];
8110 enum nl80211_tdls_operation operation
;
8113 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8114 !rdev
->ops
->tdls_oper
)
8117 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
8118 !info
->attrs
[NL80211_ATTR_MAC
])
8121 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
8122 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8124 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
8127 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
8128 struct genl_info
*info
)
8130 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8131 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8132 struct cfg80211_chan_def chandef
;
8133 struct sk_buff
*msg
;
8139 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
8140 !info
->attrs
[NL80211_ATTR_DURATION
])
8143 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8145 if (!rdev
->ops
->remain_on_channel
||
8146 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
8150 * We should be on that channel for at least a minimum amount of
8151 * time (10ms) but no longer than the driver supports.
8153 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8154 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
8157 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8161 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8165 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8166 NL80211_CMD_REMAIN_ON_CHANNEL
);
8172 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
8178 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8179 goto nla_put_failure
;
8181 genlmsg_end(msg
, hdr
);
8183 return genlmsg_reply(msg
, info
);
8192 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
8193 struct genl_info
*info
)
8195 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8196 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8199 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8202 if (!rdev
->ops
->cancel_remain_on_channel
)
8205 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8207 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
8210 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
8211 u8
*rates
, u8 rates_len
)
8216 for (i
= 0; i
< rates_len
; i
++) {
8217 int rate
= (rates
[i
] & 0x7f) * 5;
8219 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
8220 struct ieee80211_rate
*srate
=
8221 &sband
->bitrates
[ridx
];
8222 if (rate
== srate
->bitrate
) {
8227 if (ridx
== sband
->n_bitrates
)
8228 return 0; /* rate not found */
8234 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
8235 u8
*rates
, u8 rates_len
,
8236 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
8240 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
8242 for (i
= 0; i
< rates_len
; i
++) {
8245 ridx
= rates
[i
] / 8;
8246 rbit
= BIT(rates
[i
] % 8);
8248 /* check validity */
8249 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
8252 /* check availability */
8253 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
8262 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
8266 switch (vht_mcs_map
) {
8267 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
8269 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
8272 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
8275 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
8285 static void vht_build_mcs_mask(u16 vht_mcs_map
,
8286 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
8290 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
8291 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
8296 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
8297 struct nl80211_txrate_vht
*txrate
,
8298 u16 mcs
[NL80211_VHT_NSS_MAX
])
8300 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8301 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
8304 if (!sband
->vht_cap
.vht_supported
)
8307 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
8309 /* Build vht_mcs_mask from VHT capabilities */
8310 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
8312 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
8313 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
8314 mcs
[i
] = txrate
->mcs
[i
];
8322 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
8323 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
8324 .len
= NL80211_MAX_SUPP_RATES
},
8325 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
8326 .len
= NL80211_MAX_SUPP_HT_RATES
},
8327 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
8328 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
8331 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
8332 struct genl_info
*info
)
8334 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
8335 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8336 struct cfg80211_bitrate_mask mask
;
8338 struct net_device
*dev
= info
->user_ptr
[1];
8339 struct nlattr
*tx_rates
;
8340 struct ieee80211_supported_band
*sband
;
8343 if (!rdev
->ops
->set_bitrate_mask
)
8346 memset(&mask
, 0, sizeof(mask
));
8347 /* Default to all rates enabled */
8348 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
8349 sband
= rdev
->wiphy
.bands
[i
];
8354 mask
.control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
8355 memcpy(mask
.control
[i
].ht_mcs
,
8356 sband
->ht_cap
.mcs
.rx_mask
,
8357 sizeof(mask
.control
[i
].ht_mcs
));
8359 if (!sband
->vht_cap
.vht_supported
)
8362 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8363 vht_build_mcs_mask(vht_tx_mcs_map
, mask
.control
[i
].vht_mcs
);
8366 /* if no rates are given set it back to the defaults */
8367 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
8371 * The nested attribute uses enum nl80211_band as the index. This maps
8372 * directly to the enum ieee80211_band values used in cfg80211.
8374 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
8375 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
8376 enum ieee80211_band band
= nla_type(tx_rates
);
8379 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
8381 sband
= rdev
->wiphy
.bands
[band
];
8384 err
= nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
8385 nla_len(tx_rates
), nl80211_txattr_policy
);
8388 if (tb
[NL80211_TXRATE_LEGACY
]) {
8389 mask
.control
[band
].legacy
= rateset_to_mask(
8391 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
8392 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
8393 if ((mask
.control
[band
].legacy
== 0) &&
8394 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
8397 if (tb
[NL80211_TXRATE_HT
]) {
8398 if (!ht_rateset_to_mask(
8400 nla_data(tb
[NL80211_TXRATE_HT
]),
8401 nla_len(tb
[NL80211_TXRATE_HT
]),
8402 mask
.control
[band
].ht_mcs
))
8405 if (tb
[NL80211_TXRATE_VHT
]) {
8406 if (!vht_set_mcs_mask(
8408 nla_data(tb
[NL80211_TXRATE_VHT
]),
8409 mask
.control
[band
].vht_mcs
))
8412 if (tb
[NL80211_TXRATE_GI
]) {
8413 mask
.control
[band
].gi
=
8414 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
8415 if (mask
.control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
8419 if (mask
.control
[band
].legacy
== 0) {
8420 /* don't allow empty legacy rates if HT or VHT
8421 * are not even supported.
8423 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
8424 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
8427 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
8428 if (mask
.control
[band
].ht_mcs
[i
])
8431 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
8432 if (mask
.control
[band
].vht_mcs
[i
])
8435 /* legacy and mcs rates may not be both empty */
8441 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
8444 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8446 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8447 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8448 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
8450 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
8453 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
8454 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
8456 switch (wdev
->iftype
) {
8457 case NL80211_IFTYPE_STATION
:
8458 case NL80211_IFTYPE_ADHOC
:
8459 case NL80211_IFTYPE_P2P_CLIENT
:
8460 case NL80211_IFTYPE_AP
:
8461 case NL80211_IFTYPE_AP_VLAN
:
8462 case NL80211_IFTYPE_MESH_POINT
:
8463 case NL80211_IFTYPE_P2P_GO
:
8464 case NL80211_IFTYPE_P2P_DEVICE
:
8470 /* not much point in registering if we can't reply */
8471 if (!rdev
->ops
->mgmt_tx
)
8474 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
8475 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
8476 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
8479 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8481 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8482 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8483 struct cfg80211_chan_def chandef
;
8487 struct sk_buff
*msg
= NULL
;
8488 struct cfg80211_mgmt_tx_params params
= {
8489 .dont_wait_for_ack
=
8490 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
8493 if (!info
->attrs
[NL80211_ATTR_FRAME
])
8496 if (!rdev
->ops
->mgmt_tx
)
8499 switch (wdev
->iftype
) {
8500 case NL80211_IFTYPE_P2P_DEVICE
:
8501 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8503 case NL80211_IFTYPE_STATION
:
8504 case NL80211_IFTYPE_ADHOC
:
8505 case NL80211_IFTYPE_P2P_CLIENT
:
8506 case NL80211_IFTYPE_AP
:
8507 case NL80211_IFTYPE_AP_VLAN
:
8508 case NL80211_IFTYPE_MESH_POINT
:
8509 case NL80211_IFTYPE_P2P_GO
:
8515 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
8516 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8518 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8521 * We should wait on the channel for at least a minimum amount
8522 * of time (10ms) but no longer than the driver supports.
8524 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8525 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
8530 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
8532 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8535 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
8537 /* get the channel if any has been specified, otherwise pass NULL to
8538 * the driver. The latter will use the current one
8540 chandef
.chan
= NULL
;
8541 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8542 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8547 if (!chandef
.chan
&& params
.offchan
)
8550 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
8551 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
8553 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
8554 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8557 if (len
% sizeof(u16
))
8560 params
.n_csa_offsets
= len
/ sizeof(u16
);
8561 params
.csa_offsets
=
8562 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8564 /* check that all the offsets fit the frame */
8565 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
8566 if (params
.csa_offsets
[i
] >= params
.len
)
8571 if (!params
.dont_wait_for_ack
) {
8572 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8576 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8584 params
.chan
= chandef
.chan
;
8585 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
8590 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8591 goto nla_put_failure
;
8593 genlmsg_end(msg
, hdr
);
8594 return genlmsg_reply(msg
, info
);
8606 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
8608 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8609 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8612 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8615 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
8618 switch (wdev
->iftype
) {
8619 case NL80211_IFTYPE_STATION
:
8620 case NL80211_IFTYPE_ADHOC
:
8621 case NL80211_IFTYPE_P2P_CLIENT
:
8622 case NL80211_IFTYPE_AP
:
8623 case NL80211_IFTYPE_AP_VLAN
:
8624 case NL80211_IFTYPE_P2P_GO
:
8625 case NL80211_IFTYPE_P2P_DEVICE
:
8631 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8633 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
8636 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
8638 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8639 struct wireless_dev
*wdev
;
8640 struct net_device
*dev
= info
->user_ptr
[1];
8645 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
8648 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
8650 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
8653 wdev
= dev
->ieee80211_ptr
;
8655 if (!rdev
->ops
->set_power_mgmt
)
8658 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
8660 if (state
== wdev
->ps
)
8663 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
8669 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
8671 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8672 enum nl80211_ps_state ps_state
;
8673 struct wireless_dev
*wdev
;
8674 struct net_device
*dev
= info
->user_ptr
[1];
8675 struct sk_buff
*msg
;
8679 wdev
= dev
->ieee80211_ptr
;
8681 if (!rdev
->ops
->set_power_mgmt
)
8684 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8688 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8689 NL80211_CMD_GET_POWER_SAVE
);
8696 ps_state
= NL80211_PS_ENABLED
;
8698 ps_state
= NL80211_PS_DISABLED
;
8700 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
8701 goto nla_put_failure
;
8703 genlmsg_end(msg
, hdr
);
8704 return genlmsg_reply(msg
, info
);
8713 static const struct nla_policy
8714 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
8715 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
8716 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
8717 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
8718 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
8719 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
8720 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
8723 static int nl80211_set_cqm_txe(struct genl_info
*info
,
8724 u32 rate
, u32 pkts
, u32 intvl
)
8726 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8727 struct net_device
*dev
= info
->user_ptr
[1];
8728 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8730 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
8733 if (!rdev
->ops
->set_cqm_txe_config
)
8736 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8737 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8740 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
8743 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
8744 s32 threshold
, u32 hysteresis
)
8746 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8747 struct net_device
*dev
= info
->user_ptr
[1];
8748 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8753 /* disabling - hysteresis should also be zero then */
8757 if (!rdev
->ops
->set_cqm_rssi_config
)
8760 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8761 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8764 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
8767 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
8769 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
8773 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
8777 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
8778 nl80211_attr_cqm_policy
);
8782 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
8783 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
8784 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
8785 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
8787 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
8790 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
8791 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
8792 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
8793 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
8794 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
8795 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
8797 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
8803 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
8805 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8806 struct net_device
*dev
= info
->user_ptr
[1];
8807 struct ocb_setup setup
= {};
8810 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8814 return cfg80211_join_ocb(rdev
, dev
, &setup
);
8817 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
8819 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8820 struct net_device
*dev
= info
->user_ptr
[1];
8822 return cfg80211_leave_ocb(rdev
, dev
);
8825 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8827 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8828 struct net_device
*dev
= info
->user_ptr
[1];
8829 struct mesh_config cfg
;
8830 struct mesh_setup setup
;
8833 /* start with default */
8834 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
8835 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
8837 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
8838 /* and parse parameters if given */
8839 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
8844 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
8845 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
8848 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8849 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8851 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8852 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
8853 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8856 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
8857 setup
.beacon_interval
=
8858 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8859 if (setup
.beacon_interval
< 10 ||
8860 setup
.beacon_interval
> 10000)
8864 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
8866 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
8867 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
8871 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
8872 /* parse additional setup parameters if given */
8873 err
= nl80211_parse_mesh_setup(info
, &setup
);
8879 cfg
.auto_open_plinks
= false;
8881 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8882 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8886 /* cfg80211_join_mesh() will sort it out */
8887 setup
.chandef
.chan
= NULL
;
8890 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8891 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8893 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8894 struct ieee80211_supported_band
*sband
;
8896 if (!setup
.chandef
.chan
)
8899 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
8901 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8902 &setup
.basic_rates
);
8907 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
8910 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8912 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8913 struct net_device
*dev
= info
->user_ptr
[1];
8915 return cfg80211_leave_mesh(rdev
, dev
);
8919 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
8920 struct cfg80211_registered_device
*rdev
)
8922 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
8923 struct nlattr
*nl_pats
, *nl_pat
;
8926 if (!wowlan
->n_patterns
)
8929 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
8933 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
8934 nl_pat
= nla_nest_start(msg
, i
+ 1);
8937 pat_len
= wowlan
->patterns
[i
].pattern_len
;
8938 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
8939 wowlan
->patterns
[i
].mask
) ||
8940 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8941 wowlan
->patterns
[i
].pattern
) ||
8942 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8943 wowlan
->patterns
[i
].pkt_offset
))
8945 nla_nest_end(msg
, nl_pat
);
8947 nla_nest_end(msg
, nl_pats
);
8952 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
8953 struct cfg80211_wowlan_tcp
*tcp
)
8955 struct nlattr
*nl_tcp
;
8960 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
8964 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
8965 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
8966 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
8967 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
8968 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
8969 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
8970 tcp
->payload_len
, tcp
->payload
) ||
8971 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
8972 tcp
->data_interval
) ||
8973 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
8974 tcp
->wake_len
, tcp
->wake_data
) ||
8975 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
8976 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
8979 if (tcp
->payload_seq
.len
&&
8980 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
8981 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
8984 if (tcp
->payload_tok
.len
&&
8985 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
8986 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
8990 nla_nest_end(msg
, nl_tcp
);
8995 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
8996 struct cfg80211_sched_scan_request
*req
)
8998 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
9004 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
9008 if (req
->n_scan_plans
== 1 &&
9009 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
9010 req
->scan_plans
[0].interval
* 1000))
9013 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
9016 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9020 for (i
= 0; i
< req
->n_channels
; i
++)
9021 nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
);
9023 nla_nest_end(msg
, freqs
);
9025 if (req
->n_match_sets
) {
9026 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
9027 for (i
= 0; i
< req
->n_match_sets
; i
++) {
9028 match
= nla_nest_start(msg
, i
);
9029 nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
9030 req
->match_sets
[i
].ssid
.ssid_len
,
9031 req
->match_sets
[i
].ssid
.ssid
);
9032 nla_nest_end(msg
, match
);
9034 nla_nest_end(msg
, matches
);
9037 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
9041 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
9042 scan_plan
= nla_nest_start(msg
, i
+ 1);
9044 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
9045 req
->scan_plans
[i
].interval
) ||
9046 (req
->scan_plans
[i
].iterations
&&
9047 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
9048 req
->scan_plans
[i
].iterations
)))
9050 nla_nest_end(msg
, scan_plan
);
9052 nla_nest_end(msg
, scan_plans
);
9054 nla_nest_end(msg
, nd
);
9059 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9061 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9062 struct sk_buff
*msg
;
9064 u32 size
= NLMSG_DEFAULT_SIZE
;
9066 if (!rdev
->wiphy
.wowlan
)
9069 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
9070 /* adjust size to have room for all the data */
9071 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
9072 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
9073 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
9074 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
9077 msg
= nlmsg_new(size
, GFP_KERNEL
);
9081 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9082 NL80211_CMD_GET_WOWLAN
);
9084 goto nla_put_failure
;
9086 if (rdev
->wiphy
.wowlan_config
) {
9087 struct nlattr
*nl_wowlan
;
9089 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
9091 goto nla_put_failure
;
9093 if ((rdev
->wiphy
.wowlan_config
->any
&&
9094 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
9095 (rdev
->wiphy
.wowlan_config
->disconnect
&&
9096 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
9097 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
9098 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
9099 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
9100 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
9101 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
9102 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
9103 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
9104 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
9105 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
9106 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
9107 goto nla_put_failure
;
9109 if (nl80211_send_wowlan_patterns(msg
, rdev
))
9110 goto nla_put_failure
;
9112 if (nl80211_send_wowlan_tcp(msg
,
9113 rdev
->wiphy
.wowlan_config
->tcp
))
9114 goto nla_put_failure
;
9116 if (nl80211_send_wowlan_nd(
9118 rdev
->wiphy
.wowlan_config
->nd_config
))
9119 goto nla_put_failure
;
9121 nla_nest_end(msg
, nl_wowlan
);
9124 genlmsg_end(msg
, hdr
);
9125 return genlmsg_reply(msg
, info
);
9132 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
9133 struct nlattr
*attr
,
9134 struct cfg80211_wowlan
*trig
)
9136 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
9137 struct cfg80211_wowlan_tcp
*cfg
;
9138 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
9139 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
9141 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
9144 if (!rdev
->wiphy
.wowlan
->tcp
)
9147 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
9148 nla_data(attr
), nla_len(attr
),
9149 nl80211_wowlan_tcp_policy
);
9153 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
9154 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
9155 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
9156 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
9157 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
9158 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
9159 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
9160 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
9163 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
9164 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
9167 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
9168 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
9169 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
9172 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
9173 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
9176 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
9177 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
9180 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
9181 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9183 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9184 tokens_size
= tokln
- sizeof(*tok
);
9186 if (!tok
->len
|| tokens_size
% tok
->len
)
9188 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
9190 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
9192 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
9194 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
9196 if (tok
->offset
+ tok
->len
> data_size
)
9200 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
9201 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
9202 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
9204 if (seq
->len
== 0 || seq
->len
> 4)
9206 if (seq
->len
+ seq
->offset
> data_size
)
9210 size
= sizeof(*cfg
);
9212 size
+= wake_size
+ wake_mask_size
;
9213 size
+= tokens_size
;
9215 cfg
= kzalloc(size
, GFP_KERNEL
);
9218 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
9219 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
9220 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
9222 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
9223 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
9227 /* allocate a socket and port for it and use it */
9228 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
9229 IPPROTO_TCP
, &cfg
->sock
, 1);
9234 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
9235 sock_release(cfg
->sock
);
9239 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
9245 cfg
->src_port
= port
;
9248 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
9249 cfg
->payload_len
= data_size
;
9250 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
9251 memcpy((void *)cfg
->payload
,
9252 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
9255 cfg
->payload_seq
= *seq
;
9256 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
9257 cfg
->wake_len
= wake_size
;
9258 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
9259 memcpy((void *)cfg
->wake_data
,
9260 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
9262 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
9263 data_size
+ wake_size
;
9264 memcpy((void *)cfg
->wake_mask
,
9265 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
9268 cfg
->tokens_size
= tokens_size
;
9269 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
9277 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
9278 const struct wiphy_wowlan_support
*wowlan
,
9279 struct nlattr
*attr
,
9280 struct cfg80211_wowlan
*trig
)
9285 tb
= kzalloc(NUM_NL80211_ATTR
* sizeof(*tb
), GFP_KERNEL
);
9289 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
9294 err
= nla_parse(tb
, NL80211_ATTR_MAX
,
9295 nla_data(attr
), nla_len(attr
),
9300 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
);
9301 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
9303 trig
->nd_config
= NULL
;
9310 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9312 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9313 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
9314 struct cfg80211_wowlan new_triggers
= {};
9315 struct cfg80211_wowlan
*ntrig
;
9316 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
9318 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
9319 bool regular
= false;
9324 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
9325 cfg80211_rdev_free_wowlan(rdev
);
9326 rdev
->wiphy
.wowlan_config
= NULL
;
9330 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
9331 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9332 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9333 nl80211_wowlan_policy
);
9337 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
9338 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
9340 new_triggers
.any
= true;
9343 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
9344 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
9346 new_triggers
.disconnect
= true;
9350 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
9351 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
9353 new_triggers
.magic_pkt
= true;
9357 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
9360 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
9361 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
9363 new_triggers
.gtk_rekey_failure
= true;
9367 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
9368 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
9370 new_triggers
.eap_identity_req
= true;
9374 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
9375 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
9377 new_triggers
.four_way_handshake
= true;
9381 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
9382 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
9384 new_triggers
.rfkill_release
= true;
9388 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
9391 int rem
, pat_len
, mask_len
, pkt_offset
;
9392 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9396 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9399 if (n_patterns
> wowlan
->n_patterns
)
9402 new_triggers
.patterns
= kcalloc(n_patterns
,
9403 sizeof(new_triggers
.patterns
[0]),
9405 if (!new_triggers
.patterns
)
9408 new_triggers
.n_patterns
= n_patterns
;
9411 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9415 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
9416 nla_len(pat
), NULL
);
9418 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
9419 !pat_tb
[NL80211_PKTPAT_PATTERN
])
9421 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
9422 mask_len
= DIV_ROUND_UP(pat_len
, 8);
9423 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
9425 if (pat_len
> wowlan
->pattern_max_len
||
9426 pat_len
< wowlan
->pattern_min_len
)
9429 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
9432 pkt_offset
= nla_get_u32(
9433 pat_tb
[NL80211_PKTPAT_OFFSET
]);
9434 if (pkt_offset
> wowlan
->max_pkt_offset
)
9436 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
9438 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
9443 new_triggers
.patterns
[i
].mask
= mask_pat
;
9444 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
9446 mask_pat
+= mask_len
;
9447 new_triggers
.patterns
[i
].pattern
= mask_pat
;
9448 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
9450 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
9456 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
9458 err
= nl80211_parse_wowlan_tcp(
9459 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
9465 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
9467 err
= nl80211_parse_wowlan_nd(
9468 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
9474 /* The 'any' trigger means the device continues operating more or less
9475 * as in its normal operation mode and wakes up the host on most of the
9476 * normal interrupts (like packet RX, ...)
9477 * It therefore makes little sense to combine with the more constrained
9478 * wakeup trigger modes.
9480 if (new_triggers
.any
&& regular
) {
9485 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
9490 cfg80211_rdev_free_wowlan(rdev
);
9491 rdev
->wiphy
.wowlan_config
= ntrig
;
9494 if (rdev
->ops
->set_wakeup
&&
9495 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
9496 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
9500 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
9501 kfree(new_triggers
.patterns
[i
].mask
);
9502 kfree(new_triggers
.patterns
);
9503 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
9504 sock_release(new_triggers
.tcp
->sock
);
9505 kfree(new_triggers
.tcp
);
9510 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
9511 struct cfg80211_registered_device
*rdev
)
9513 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
9515 struct cfg80211_coalesce_rules
*rule
;
9517 if (!rdev
->coalesce
->n_rules
)
9520 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
9524 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
9525 nl_rule
= nla_nest_start(msg
, i
+ 1);
9529 rule
= &rdev
->coalesce
->rules
[i
];
9530 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
9534 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
9538 nl_pats
= nla_nest_start(msg
,
9539 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
9543 for (j
= 0; j
< rule
->n_patterns
; j
++) {
9544 nl_pat
= nla_nest_start(msg
, j
+ 1);
9547 pat_len
= rule
->patterns
[j
].pattern_len
;
9548 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
9549 DIV_ROUND_UP(pat_len
, 8),
9550 rule
->patterns
[j
].mask
) ||
9551 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
9552 rule
->patterns
[j
].pattern
) ||
9553 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
9554 rule
->patterns
[j
].pkt_offset
))
9556 nla_nest_end(msg
, nl_pat
);
9558 nla_nest_end(msg
, nl_pats
);
9559 nla_nest_end(msg
, nl_rule
);
9561 nla_nest_end(msg
, nl_rules
);
9566 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
9568 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9569 struct sk_buff
*msg
;
9572 if (!rdev
->wiphy
.coalesce
)
9575 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9579 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9580 NL80211_CMD_GET_COALESCE
);
9582 goto nla_put_failure
;
9584 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
9585 goto nla_put_failure
;
9587 genlmsg_end(msg
, hdr
);
9588 return genlmsg_reply(msg
, info
);
9595 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
9597 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
9599 struct cfg80211_coalesce_rules
*rule
;
9604 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
9605 rule
= &coalesce
->rules
[i
];
9606 for (j
= 0; j
< rule
->n_patterns
; j
++)
9607 kfree(rule
->patterns
[j
].mask
);
9608 kfree(rule
->patterns
);
9610 kfree(coalesce
->rules
);
9612 rdev
->coalesce
= NULL
;
9615 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
9616 struct nlattr
*rule
,
9617 struct cfg80211_coalesce_rules
*new_rule
)
9620 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
9621 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
9622 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
9623 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9625 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
9626 nla_len(rule
), nl80211_coalesce_policy
);
9630 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
9632 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
9633 if (new_rule
->delay
> coalesce
->max_delay
)
9636 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
9637 new_rule
->condition
=
9638 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
9639 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
9640 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
9643 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
9646 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
9649 if (n_patterns
> coalesce
->n_patterns
)
9652 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
9654 if (!new_rule
->patterns
)
9657 new_rule
->n_patterns
= n_patterns
;
9660 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
9664 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
9665 nla_len(pat
), NULL
);
9666 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
9667 !pat_tb
[NL80211_PKTPAT_PATTERN
])
9669 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
9670 mask_len
= DIV_ROUND_UP(pat_len
, 8);
9671 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
9673 if (pat_len
> coalesce
->pattern_max_len
||
9674 pat_len
< coalesce
->pattern_min_len
)
9677 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
9680 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
9681 if (pkt_offset
> coalesce
->max_pkt_offset
)
9683 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
9685 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
9689 new_rule
->patterns
[i
].mask
= mask_pat
;
9690 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
9693 mask_pat
+= mask_len
;
9694 new_rule
->patterns
[i
].pattern
= mask_pat
;
9695 new_rule
->patterns
[i
].pattern_len
= pat_len
;
9696 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
9704 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
9706 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9707 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
9708 struct cfg80211_coalesce new_coalesce
= {};
9709 struct cfg80211_coalesce
*n_coalesce
;
9710 int err
, rem_rule
, n_rules
= 0, i
, j
;
9711 struct nlattr
*rule
;
9712 struct cfg80211_coalesce_rules
*tmp_rule
;
9714 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
9717 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
9718 cfg80211_rdev_free_coalesce(rdev
);
9719 rdev
->ops
->set_coalesce(&rdev
->wiphy
, NULL
);
9723 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
9726 if (n_rules
> coalesce
->n_rules
)
9729 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
9731 if (!new_coalesce
.rules
)
9734 new_coalesce
.n_rules
= n_rules
;
9737 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
9739 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
9740 &new_coalesce
.rules
[i
]);
9747 err
= rdev
->ops
->set_coalesce(&rdev
->wiphy
, &new_coalesce
);
9751 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
9756 cfg80211_rdev_free_coalesce(rdev
);
9757 rdev
->coalesce
= n_coalesce
;
9761 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
9762 tmp_rule
= &new_coalesce
.rules
[i
];
9763 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
9764 kfree(tmp_rule
->patterns
[j
].mask
);
9765 kfree(tmp_rule
->patterns
);
9767 kfree(new_coalesce
.rules
);
9772 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
9774 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9775 struct net_device
*dev
= info
->user_ptr
[1];
9776 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9777 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
9778 struct cfg80211_gtk_rekey_data rekey_data
;
9781 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
9784 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
9785 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
9786 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
9787 nl80211_rekey_policy
);
9791 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
9793 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
9795 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
9798 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
9799 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
9800 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
9803 if (!wdev
->current_bss
) {
9808 if (!rdev
->ops
->set_rekey_data
) {
9813 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
9819 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
9820 struct genl_info
*info
)
9822 struct net_device
*dev
= info
->user_ptr
[1];
9823 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9825 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9826 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
9829 if (wdev
->ap_unexpected_nlportid
)
9832 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
9836 static int nl80211_probe_client(struct sk_buff
*skb
,
9837 struct genl_info
*info
)
9839 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9840 struct net_device
*dev
= info
->user_ptr
[1];
9841 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9842 struct sk_buff
*msg
;
9848 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9849 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
9852 if (!info
->attrs
[NL80211_ATTR_MAC
])
9855 if (!rdev
->ops
->probe_client
)
9858 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9862 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9863 NL80211_CMD_PROBE_CLIENT
);
9869 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9871 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
9875 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9876 goto nla_put_failure
;
9878 genlmsg_end(msg
, hdr
);
9880 return genlmsg_reply(msg
, info
);
9889 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
9891 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9892 struct cfg80211_beacon_registration
*reg
, *nreg
;
9895 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
9898 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
9902 /* First, check if already registered. */
9903 spin_lock_bh(&rdev
->beacon_registrations_lock
);
9904 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
9905 if (reg
->nlportid
== info
->snd_portid
) {
9910 /* Add it to the list */
9911 nreg
->nlportid
= info
->snd_portid
;
9912 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
9914 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9918 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9923 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9925 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9926 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9929 if (!rdev
->ops
->start_p2p_device
)
9932 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9935 if (wdev
->p2p_started
)
9938 if (rfkill_blocked(rdev
->rfkill
))
9941 err
= rdev_start_p2p_device(rdev
, wdev
);
9945 wdev
->p2p_started
= true;
9951 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9953 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9954 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9956 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9959 if (!rdev
->ops
->stop_p2p_device
)
9962 cfg80211_stop_p2p_device(rdev
, wdev
);
9967 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
9968 struct genl_info
*info
)
9971 struct sk_buff
*msg
;
9973 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9977 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9978 NL80211_CMD_GET_PROTOCOL_FEATURES
);
9980 goto nla_put_failure
;
9982 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
9983 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
9984 goto nla_put_failure
;
9986 genlmsg_end(msg
, hdr
);
9987 return genlmsg_reply(msg
, info
);
9994 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
9996 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9997 struct cfg80211_update_ft_ies_params ft_params
;
9998 struct net_device
*dev
= info
->user_ptr
[1];
10000 if (!rdev
->ops
->update_ft_ies
)
10001 return -EOPNOTSUPP
;
10003 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
10004 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
10007 memset(&ft_params
, 0, sizeof(ft_params
));
10008 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
10009 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10010 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10012 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
10015 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
10016 struct genl_info
*info
)
10018 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10019 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10020 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
10024 if (!rdev
->ops
->crit_proto_start
)
10025 return -EOPNOTSUPP
;
10027 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
10030 if (rdev
->crit_proto_nlportid
)
10033 /* determine protocol if provided */
10034 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
10035 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
10037 if (proto
>= NUM_NL80211_CRIT_PROTO
)
10040 /* timeout must be provided */
10041 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
10045 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
10047 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
10050 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
10052 rdev
->crit_proto_nlportid
= info
->snd_portid
;
10057 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
10058 struct genl_info
*info
)
10060 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10061 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10063 if (!rdev
->ops
->crit_proto_stop
)
10064 return -EOPNOTSUPP
;
10066 if (rdev
->crit_proto_nlportid
) {
10067 rdev
->crit_proto_nlportid
= 0;
10068 rdev_crit_proto_stop(rdev
, wdev
);
10073 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
10075 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10076 struct wireless_dev
*wdev
=
10077 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
10081 if (!rdev
->wiphy
.vendor_commands
)
10082 return -EOPNOTSUPP
;
10084 if (IS_ERR(wdev
)) {
10085 err
= PTR_ERR(wdev
);
10086 if (err
!= -EINVAL
)
10089 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
10093 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
10094 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
10097 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
10098 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
10099 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
10100 const struct wiphy_vendor_command
*vcmd
;
10104 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
10106 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10109 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
10110 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
10113 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10117 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10118 if (wdev
->netdev
&&
10119 !netif_running(wdev
->netdev
))
10121 if (!wdev
->netdev
&& !wdev
->p2p_started
)
10126 return -EOPNOTSUPP
;
10131 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
10132 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10133 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10136 rdev
->cur_cmd_info
= info
;
10137 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
10139 rdev
->cur_cmd_info
= NULL
;
10143 return -EOPNOTSUPP
;
10146 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
10147 struct netlink_callback
*cb
,
10148 struct cfg80211_registered_device
**rdev
,
10149 struct wireless_dev
**wdev
)
10156 unsigned int data_len
= 0;
10161 /* subtract the 1 again here */
10162 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
10163 struct wireless_dev
*tmp
;
10169 *rdev
= wiphy_to_rdev(wiphy
);
10173 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
10174 if (tmp
->identifier
== cb
->args
[1] - 1) {
10181 /* keep rtnl locked in successful case */
10185 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
10186 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
10191 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
10192 !nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]) {
10197 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
10198 nl80211_fam
.attrbuf
);
10202 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
10203 nl80211_fam
.attrbuf
);
10204 if (IS_ERR(*rdev
)) {
10205 err
= PTR_ERR(*rdev
);
10209 vid
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
]);
10210 subcmd
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
10212 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
10213 const struct wiphy_vendor_command
*vcmd
;
10215 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
10217 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10220 if (!vcmd
->dumpit
) {
10229 if (vcmd_idx
< 0) {
10234 if (nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
10235 data
= nla_data(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10236 data_len
= nla_len(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10239 /* 0 is the first index - add 1 to parse only once */
10240 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
10241 /* add 1 to know if it was NULL */
10242 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
10243 cb
->args
[2] = vcmd_idx
;
10244 cb
->args
[3] = (unsigned long)data
;
10245 cb
->args
[4] = data_len
;
10247 /* keep rtnl locked in successful case */
10254 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
10255 struct netlink_callback
*cb
)
10257 struct cfg80211_registered_device
*rdev
;
10258 struct wireless_dev
*wdev
;
10259 unsigned int vcmd_idx
;
10260 const struct wiphy_vendor_command
*vcmd
;
10264 struct nlattr
*vendor_data
;
10266 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
10270 vcmd_idx
= cb
->args
[2];
10271 data
= (void *)cb
->args
[3];
10272 data_len
= cb
->args
[4];
10273 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
10275 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
10276 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
10279 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10283 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10284 if (wdev
->netdev
&&
10285 !netif_running(wdev
->netdev
))
10287 if (!wdev
->netdev
&& !wdev
->p2p_started
)
10293 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
10294 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
10295 NL80211_CMD_VENDOR
);
10299 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10300 (wdev
&& nla_put_u64(skb
, NL80211_ATTR_WDEV
,
10302 genlmsg_cancel(skb
, hdr
);
10306 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
10307 if (!vendor_data
) {
10308 genlmsg_cancel(skb
, hdr
);
10312 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
10313 (unsigned long *)&cb
->args
[5]);
10314 nla_nest_end(skb
, vendor_data
);
10316 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
10317 genlmsg_cancel(skb
, hdr
);
10320 genlmsg_cancel(skb
, hdr
);
10324 genlmsg_end(skb
, hdr
);
10333 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
10334 enum nl80211_commands cmd
,
10335 enum nl80211_attrs attr
,
10338 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10340 if (WARN_ON(!rdev
->cur_cmd_info
))
10343 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
10344 rdev
->cur_cmd_info
->snd_portid
,
10345 rdev
->cur_cmd_info
->snd_seq
,
10346 cmd
, attr
, NULL
, GFP_KERNEL
);
10348 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
10350 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
10352 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
10353 void *hdr
= ((void **)skb
->cb
)[1];
10354 struct nlattr
*data
= ((void **)skb
->cb
)[2];
10356 /* clear CB data for netlink core to own from now on */
10357 memset(skb
->cb
, 0, sizeof(skb
->cb
));
10359 if (WARN_ON(!rdev
->cur_cmd_info
)) {
10364 nla_nest_end(skb
, data
);
10365 genlmsg_end(skb
, hdr
);
10366 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
10368 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
10371 static int nl80211_set_qos_map(struct sk_buff
*skb
,
10372 struct genl_info
*info
)
10374 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10375 struct cfg80211_qos_map
*qos_map
= NULL
;
10376 struct net_device
*dev
= info
->user_ptr
[1];
10377 u8
*pos
, len
, num_des
, des_len
, des
;
10380 if (!rdev
->ops
->set_qos_map
)
10381 return -EOPNOTSUPP
;
10383 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
10384 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10385 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10387 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
10388 len
> IEEE80211_QOS_MAP_LEN_MAX
)
10391 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
10395 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
10397 des_len
= num_des
*
10398 sizeof(struct cfg80211_dscp_exception
);
10399 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
10400 qos_map
->num_des
= num_des
;
10401 for (des
= 0; des
< num_des
; des
++) {
10402 if (qos_map
->dscp_exception
[des
].up
> 7) {
10409 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
10412 wdev_lock(dev
->ieee80211_ptr
);
10413 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
10415 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
10416 wdev_unlock(dev
->ieee80211_ptr
);
10422 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10424 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10425 struct net_device
*dev
= info
->user_ptr
[1];
10426 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10429 u16 admitted_time
= 0;
10432 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
10433 return -EOPNOTSUPP
;
10435 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
10436 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
10439 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10440 if (tsid
>= IEEE80211_NUM_TIDS
)
10443 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
10444 if (up
>= IEEE80211_NUM_UPS
)
10447 /* WMM uses TIDs 0-7 even for TSPEC */
10448 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
10449 /* TODO: handle 802.11 TSPEC/admission control
10450 * need more attributes for that (e.g. BA session requirement);
10451 * change the WMM adminssion test above to allow both then
10456 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10458 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
10460 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
10461 if (!admitted_time
)
10466 switch (wdev
->iftype
) {
10467 case NL80211_IFTYPE_STATION
:
10468 case NL80211_IFTYPE_P2P_CLIENT
:
10469 if (wdev
->current_bss
)
10478 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
10485 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10487 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10488 struct net_device
*dev
= info
->user_ptr
[1];
10489 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10494 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
10497 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10498 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10501 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
10507 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
10508 struct genl_info
*info
)
10510 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10511 struct net_device
*dev
= info
->user_ptr
[1];
10512 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10513 struct cfg80211_chan_def chandef
= {};
10518 if (!rdev
->ops
->tdls_channel_switch
||
10519 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10520 return -EOPNOTSUPP
;
10522 switch (dev
->ieee80211_ptr
->iftype
) {
10523 case NL80211_IFTYPE_STATION
:
10524 case NL80211_IFTYPE_P2P_CLIENT
:
10527 return -EOPNOTSUPP
;
10530 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
10531 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
10534 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
10539 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10540 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10541 * specification is not defined for them.
10543 if (chandef
.chan
->band
== IEEE80211_BAND_2GHZ
&&
10544 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
10545 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
10548 /* we will be active on the TDLS link */
10549 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
10553 /* don't allow switching to DFS channels */
10554 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
10557 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10558 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
10561 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
10567 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
10568 struct genl_info
*info
)
10570 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10571 struct net_device
*dev
= info
->user_ptr
[1];
10572 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10575 if (!rdev
->ops
->tdls_channel_switch
||
10576 !rdev
->ops
->tdls_cancel_channel_switch
||
10577 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10578 return -EOPNOTSUPP
;
10580 switch (dev
->ieee80211_ptr
->iftype
) {
10581 case NL80211_IFTYPE_STATION
:
10582 case NL80211_IFTYPE_P2P_CLIENT
:
10585 return -EOPNOTSUPP
;
10588 if (!info
->attrs
[NL80211_ATTR_MAC
])
10591 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10594 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
10600 #define NL80211_FLAG_NEED_WIPHY 0x01
10601 #define NL80211_FLAG_NEED_NETDEV 0x02
10602 #define NL80211_FLAG_NEED_RTNL 0x04
10603 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10604 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10605 NL80211_FLAG_CHECK_NETDEV_UP)
10606 #define NL80211_FLAG_NEED_WDEV 0x10
10607 /* If a netdev is associated, it must be UP, P2P must be started */
10608 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10609 NL80211_FLAG_CHECK_NETDEV_UP)
10610 #define NL80211_FLAG_CLEAR_SKB 0x20
10612 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
10613 struct genl_info
*info
)
10615 struct cfg80211_registered_device
*rdev
;
10616 struct wireless_dev
*wdev
;
10617 struct net_device
*dev
;
10618 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
10623 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
10624 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
10625 if (IS_ERR(rdev
)) {
10628 return PTR_ERR(rdev
);
10630 info
->user_ptr
[0] = rdev
;
10631 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
10632 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
10635 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
10637 if (IS_ERR(wdev
)) {
10640 return PTR_ERR(wdev
);
10643 dev
= wdev
->netdev
;
10644 rdev
= wiphy_to_rdev(wdev
->wiphy
);
10646 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
10653 info
->user_ptr
[1] = dev
;
10655 info
->user_ptr
[1] = wdev
;
10659 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
10660 !netif_running(dev
)) {
10667 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
10668 if (!wdev
->p2p_started
) {
10675 info
->user_ptr
[0] = rdev
;
10681 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
10682 struct genl_info
*info
)
10684 if (info
->user_ptr
[1]) {
10685 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
10686 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10689 dev_put(wdev
->netdev
);
10691 dev_put(info
->user_ptr
[1]);
10695 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
10698 /* If needed, clear the netlink message payload from the SKB
10699 * as it might contain key data that shouldn't stick around on
10700 * the heap after the SKB is freed. The netlink message header
10701 * is still needed for further processing, so leave it intact.
10703 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
10704 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
10706 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
10710 static const struct genl_ops nl80211_ops
[] = {
10712 .cmd
= NL80211_CMD_GET_WIPHY
,
10713 .doit
= nl80211_get_wiphy
,
10714 .dumpit
= nl80211_dump_wiphy
,
10715 .done
= nl80211_dump_wiphy_done
,
10716 .policy
= nl80211_policy
,
10717 /* can be retrieved by unprivileged users */
10718 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10719 NL80211_FLAG_NEED_RTNL
,
10722 .cmd
= NL80211_CMD_SET_WIPHY
,
10723 .doit
= nl80211_set_wiphy
,
10724 .policy
= nl80211_policy
,
10725 .flags
= GENL_ADMIN_PERM
,
10726 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10729 .cmd
= NL80211_CMD_GET_INTERFACE
,
10730 .doit
= nl80211_get_interface
,
10731 .dumpit
= nl80211_dump_interface
,
10732 .policy
= nl80211_policy
,
10733 /* can be retrieved by unprivileged users */
10734 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
10735 NL80211_FLAG_NEED_RTNL
,
10738 .cmd
= NL80211_CMD_SET_INTERFACE
,
10739 .doit
= nl80211_set_interface
,
10740 .policy
= nl80211_policy
,
10741 .flags
= GENL_ADMIN_PERM
,
10742 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10743 NL80211_FLAG_NEED_RTNL
,
10746 .cmd
= NL80211_CMD_NEW_INTERFACE
,
10747 .doit
= nl80211_new_interface
,
10748 .policy
= nl80211_policy
,
10749 .flags
= GENL_ADMIN_PERM
,
10750 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10751 NL80211_FLAG_NEED_RTNL
,
10754 .cmd
= NL80211_CMD_DEL_INTERFACE
,
10755 .doit
= nl80211_del_interface
,
10756 .policy
= nl80211_policy
,
10757 .flags
= GENL_ADMIN_PERM
,
10758 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
10759 NL80211_FLAG_NEED_RTNL
,
10762 .cmd
= NL80211_CMD_GET_KEY
,
10763 .doit
= nl80211_get_key
,
10764 .policy
= nl80211_policy
,
10765 .flags
= GENL_ADMIN_PERM
,
10766 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10767 NL80211_FLAG_NEED_RTNL
,
10770 .cmd
= NL80211_CMD_SET_KEY
,
10771 .doit
= nl80211_set_key
,
10772 .policy
= nl80211_policy
,
10773 .flags
= GENL_ADMIN_PERM
,
10774 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10775 NL80211_FLAG_NEED_RTNL
|
10776 NL80211_FLAG_CLEAR_SKB
,
10779 .cmd
= NL80211_CMD_NEW_KEY
,
10780 .doit
= nl80211_new_key
,
10781 .policy
= nl80211_policy
,
10782 .flags
= GENL_ADMIN_PERM
,
10783 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10784 NL80211_FLAG_NEED_RTNL
|
10785 NL80211_FLAG_CLEAR_SKB
,
10788 .cmd
= NL80211_CMD_DEL_KEY
,
10789 .doit
= nl80211_del_key
,
10790 .policy
= nl80211_policy
,
10791 .flags
= GENL_ADMIN_PERM
,
10792 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10793 NL80211_FLAG_NEED_RTNL
,
10796 .cmd
= NL80211_CMD_SET_BEACON
,
10797 .policy
= nl80211_policy
,
10798 .flags
= GENL_ADMIN_PERM
,
10799 .doit
= nl80211_set_beacon
,
10800 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10801 NL80211_FLAG_NEED_RTNL
,
10804 .cmd
= NL80211_CMD_START_AP
,
10805 .policy
= nl80211_policy
,
10806 .flags
= GENL_ADMIN_PERM
,
10807 .doit
= nl80211_start_ap
,
10808 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10809 NL80211_FLAG_NEED_RTNL
,
10812 .cmd
= NL80211_CMD_STOP_AP
,
10813 .policy
= nl80211_policy
,
10814 .flags
= GENL_ADMIN_PERM
,
10815 .doit
= nl80211_stop_ap
,
10816 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10817 NL80211_FLAG_NEED_RTNL
,
10820 .cmd
= NL80211_CMD_GET_STATION
,
10821 .doit
= nl80211_get_station
,
10822 .dumpit
= nl80211_dump_station
,
10823 .policy
= nl80211_policy
,
10824 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10825 NL80211_FLAG_NEED_RTNL
,
10828 .cmd
= NL80211_CMD_SET_STATION
,
10829 .doit
= nl80211_set_station
,
10830 .policy
= nl80211_policy
,
10831 .flags
= GENL_ADMIN_PERM
,
10832 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10833 NL80211_FLAG_NEED_RTNL
,
10836 .cmd
= NL80211_CMD_NEW_STATION
,
10837 .doit
= nl80211_new_station
,
10838 .policy
= nl80211_policy
,
10839 .flags
= GENL_ADMIN_PERM
,
10840 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10841 NL80211_FLAG_NEED_RTNL
,
10844 .cmd
= NL80211_CMD_DEL_STATION
,
10845 .doit
= nl80211_del_station
,
10846 .policy
= nl80211_policy
,
10847 .flags
= GENL_ADMIN_PERM
,
10848 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10849 NL80211_FLAG_NEED_RTNL
,
10852 .cmd
= NL80211_CMD_GET_MPATH
,
10853 .doit
= nl80211_get_mpath
,
10854 .dumpit
= nl80211_dump_mpath
,
10855 .policy
= nl80211_policy
,
10856 .flags
= GENL_ADMIN_PERM
,
10857 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10858 NL80211_FLAG_NEED_RTNL
,
10861 .cmd
= NL80211_CMD_GET_MPP
,
10862 .doit
= nl80211_get_mpp
,
10863 .dumpit
= nl80211_dump_mpp
,
10864 .policy
= nl80211_policy
,
10865 .flags
= GENL_ADMIN_PERM
,
10866 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10867 NL80211_FLAG_NEED_RTNL
,
10870 .cmd
= NL80211_CMD_SET_MPATH
,
10871 .doit
= nl80211_set_mpath
,
10872 .policy
= nl80211_policy
,
10873 .flags
= GENL_ADMIN_PERM
,
10874 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10875 NL80211_FLAG_NEED_RTNL
,
10878 .cmd
= NL80211_CMD_NEW_MPATH
,
10879 .doit
= nl80211_new_mpath
,
10880 .policy
= nl80211_policy
,
10881 .flags
= GENL_ADMIN_PERM
,
10882 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10883 NL80211_FLAG_NEED_RTNL
,
10886 .cmd
= NL80211_CMD_DEL_MPATH
,
10887 .doit
= nl80211_del_mpath
,
10888 .policy
= nl80211_policy
,
10889 .flags
= GENL_ADMIN_PERM
,
10890 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10891 NL80211_FLAG_NEED_RTNL
,
10894 .cmd
= NL80211_CMD_SET_BSS
,
10895 .doit
= nl80211_set_bss
,
10896 .policy
= nl80211_policy
,
10897 .flags
= GENL_ADMIN_PERM
,
10898 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10899 NL80211_FLAG_NEED_RTNL
,
10902 .cmd
= NL80211_CMD_GET_REG
,
10903 .doit
= nl80211_get_reg_do
,
10904 .dumpit
= nl80211_get_reg_dump
,
10905 .policy
= nl80211_policy
,
10906 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10907 /* can be retrieved by unprivileged users */
10909 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
10911 .cmd
= NL80211_CMD_SET_REG
,
10912 .doit
= nl80211_set_reg
,
10913 .policy
= nl80211_policy
,
10914 .flags
= GENL_ADMIN_PERM
,
10915 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10919 .cmd
= NL80211_CMD_REQ_SET_REG
,
10920 .doit
= nl80211_req_set_reg
,
10921 .policy
= nl80211_policy
,
10922 .flags
= GENL_ADMIN_PERM
,
10925 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
10926 .doit
= nl80211_get_mesh_config
,
10927 .policy
= nl80211_policy
,
10928 /* can be retrieved by unprivileged users */
10929 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10930 NL80211_FLAG_NEED_RTNL
,
10933 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
10934 .doit
= nl80211_update_mesh_config
,
10935 .policy
= nl80211_policy
,
10936 .flags
= GENL_ADMIN_PERM
,
10937 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10938 NL80211_FLAG_NEED_RTNL
,
10941 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
10942 .doit
= nl80211_trigger_scan
,
10943 .policy
= nl80211_policy
,
10944 .flags
= GENL_ADMIN_PERM
,
10945 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
10946 NL80211_FLAG_NEED_RTNL
,
10949 .cmd
= NL80211_CMD_GET_SCAN
,
10950 .policy
= nl80211_policy
,
10951 .dumpit
= nl80211_dump_scan
,
10954 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
10955 .doit
= nl80211_start_sched_scan
,
10956 .policy
= nl80211_policy
,
10957 .flags
= GENL_ADMIN_PERM
,
10958 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10959 NL80211_FLAG_NEED_RTNL
,
10962 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
10963 .doit
= nl80211_stop_sched_scan
,
10964 .policy
= nl80211_policy
,
10965 .flags
= GENL_ADMIN_PERM
,
10966 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10967 NL80211_FLAG_NEED_RTNL
,
10970 .cmd
= NL80211_CMD_AUTHENTICATE
,
10971 .doit
= nl80211_authenticate
,
10972 .policy
= nl80211_policy
,
10973 .flags
= GENL_ADMIN_PERM
,
10974 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10975 NL80211_FLAG_NEED_RTNL
|
10976 NL80211_FLAG_CLEAR_SKB
,
10979 .cmd
= NL80211_CMD_ASSOCIATE
,
10980 .doit
= nl80211_associate
,
10981 .policy
= nl80211_policy
,
10982 .flags
= GENL_ADMIN_PERM
,
10983 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10984 NL80211_FLAG_NEED_RTNL
,
10987 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
10988 .doit
= nl80211_deauthenticate
,
10989 .policy
= nl80211_policy
,
10990 .flags
= GENL_ADMIN_PERM
,
10991 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10992 NL80211_FLAG_NEED_RTNL
,
10995 .cmd
= NL80211_CMD_DISASSOCIATE
,
10996 .doit
= nl80211_disassociate
,
10997 .policy
= nl80211_policy
,
10998 .flags
= GENL_ADMIN_PERM
,
10999 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11000 NL80211_FLAG_NEED_RTNL
,
11003 .cmd
= NL80211_CMD_JOIN_IBSS
,
11004 .doit
= nl80211_join_ibss
,
11005 .policy
= nl80211_policy
,
11006 .flags
= GENL_ADMIN_PERM
,
11007 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11008 NL80211_FLAG_NEED_RTNL
,
11011 .cmd
= NL80211_CMD_LEAVE_IBSS
,
11012 .doit
= nl80211_leave_ibss
,
11013 .policy
= nl80211_policy
,
11014 .flags
= GENL_ADMIN_PERM
,
11015 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11016 NL80211_FLAG_NEED_RTNL
,
11018 #ifdef CONFIG_NL80211_TESTMODE
11020 .cmd
= NL80211_CMD_TESTMODE
,
11021 .doit
= nl80211_testmode_do
,
11022 .dumpit
= nl80211_testmode_dump
,
11023 .policy
= nl80211_policy
,
11024 .flags
= GENL_ADMIN_PERM
,
11025 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11026 NL80211_FLAG_NEED_RTNL
,
11030 .cmd
= NL80211_CMD_CONNECT
,
11031 .doit
= nl80211_connect
,
11032 .policy
= nl80211_policy
,
11033 .flags
= GENL_ADMIN_PERM
,
11034 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11035 NL80211_FLAG_NEED_RTNL
,
11038 .cmd
= NL80211_CMD_DISCONNECT
,
11039 .doit
= nl80211_disconnect
,
11040 .policy
= nl80211_policy
,
11041 .flags
= GENL_ADMIN_PERM
,
11042 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11043 NL80211_FLAG_NEED_RTNL
,
11046 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
11047 .doit
= nl80211_wiphy_netns
,
11048 .policy
= nl80211_policy
,
11049 .flags
= GENL_ADMIN_PERM
,
11050 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11051 NL80211_FLAG_NEED_RTNL
,
11054 .cmd
= NL80211_CMD_GET_SURVEY
,
11055 .policy
= nl80211_policy
,
11056 .dumpit
= nl80211_dump_survey
,
11059 .cmd
= NL80211_CMD_SET_PMKSA
,
11060 .doit
= nl80211_setdel_pmksa
,
11061 .policy
= nl80211_policy
,
11062 .flags
= GENL_ADMIN_PERM
,
11063 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11064 NL80211_FLAG_NEED_RTNL
,
11067 .cmd
= NL80211_CMD_DEL_PMKSA
,
11068 .doit
= nl80211_setdel_pmksa
,
11069 .policy
= nl80211_policy
,
11070 .flags
= GENL_ADMIN_PERM
,
11071 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11072 NL80211_FLAG_NEED_RTNL
,
11075 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
11076 .doit
= nl80211_flush_pmksa
,
11077 .policy
= nl80211_policy
,
11078 .flags
= GENL_ADMIN_PERM
,
11079 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11080 NL80211_FLAG_NEED_RTNL
,
11083 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
11084 .doit
= nl80211_remain_on_channel
,
11085 .policy
= nl80211_policy
,
11086 .flags
= GENL_ADMIN_PERM
,
11087 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11088 NL80211_FLAG_NEED_RTNL
,
11091 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
11092 .doit
= nl80211_cancel_remain_on_channel
,
11093 .policy
= nl80211_policy
,
11094 .flags
= GENL_ADMIN_PERM
,
11095 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11096 NL80211_FLAG_NEED_RTNL
,
11099 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
11100 .doit
= nl80211_set_tx_bitrate_mask
,
11101 .policy
= nl80211_policy
,
11102 .flags
= GENL_ADMIN_PERM
,
11103 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11104 NL80211_FLAG_NEED_RTNL
,
11107 .cmd
= NL80211_CMD_REGISTER_FRAME
,
11108 .doit
= nl80211_register_mgmt
,
11109 .policy
= nl80211_policy
,
11110 .flags
= GENL_ADMIN_PERM
,
11111 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11112 NL80211_FLAG_NEED_RTNL
,
11115 .cmd
= NL80211_CMD_FRAME
,
11116 .doit
= nl80211_tx_mgmt
,
11117 .policy
= nl80211_policy
,
11118 .flags
= GENL_ADMIN_PERM
,
11119 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11120 NL80211_FLAG_NEED_RTNL
,
11123 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
11124 .doit
= nl80211_tx_mgmt_cancel_wait
,
11125 .policy
= nl80211_policy
,
11126 .flags
= GENL_ADMIN_PERM
,
11127 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11128 NL80211_FLAG_NEED_RTNL
,
11131 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
11132 .doit
= nl80211_set_power_save
,
11133 .policy
= nl80211_policy
,
11134 .flags
= GENL_ADMIN_PERM
,
11135 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11136 NL80211_FLAG_NEED_RTNL
,
11139 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
11140 .doit
= nl80211_get_power_save
,
11141 .policy
= nl80211_policy
,
11142 /* can be retrieved by unprivileged users */
11143 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11144 NL80211_FLAG_NEED_RTNL
,
11147 .cmd
= NL80211_CMD_SET_CQM
,
11148 .doit
= nl80211_set_cqm
,
11149 .policy
= nl80211_policy
,
11150 .flags
= GENL_ADMIN_PERM
,
11151 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11152 NL80211_FLAG_NEED_RTNL
,
11155 .cmd
= NL80211_CMD_SET_CHANNEL
,
11156 .doit
= nl80211_set_channel
,
11157 .policy
= nl80211_policy
,
11158 .flags
= GENL_ADMIN_PERM
,
11159 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11160 NL80211_FLAG_NEED_RTNL
,
11163 .cmd
= NL80211_CMD_SET_WDS_PEER
,
11164 .doit
= nl80211_set_wds_peer
,
11165 .policy
= nl80211_policy
,
11166 .flags
= GENL_ADMIN_PERM
,
11167 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11168 NL80211_FLAG_NEED_RTNL
,
11171 .cmd
= NL80211_CMD_JOIN_MESH
,
11172 .doit
= nl80211_join_mesh
,
11173 .policy
= nl80211_policy
,
11174 .flags
= GENL_ADMIN_PERM
,
11175 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11176 NL80211_FLAG_NEED_RTNL
,
11179 .cmd
= NL80211_CMD_LEAVE_MESH
,
11180 .doit
= nl80211_leave_mesh
,
11181 .policy
= nl80211_policy
,
11182 .flags
= GENL_ADMIN_PERM
,
11183 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11184 NL80211_FLAG_NEED_RTNL
,
11187 .cmd
= NL80211_CMD_JOIN_OCB
,
11188 .doit
= nl80211_join_ocb
,
11189 .policy
= nl80211_policy
,
11190 .flags
= GENL_ADMIN_PERM
,
11191 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11192 NL80211_FLAG_NEED_RTNL
,
11195 .cmd
= NL80211_CMD_LEAVE_OCB
,
11196 .doit
= nl80211_leave_ocb
,
11197 .policy
= nl80211_policy
,
11198 .flags
= GENL_ADMIN_PERM
,
11199 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11200 NL80211_FLAG_NEED_RTNL
,
11204 .cmd
= NL80211_CMD_GET_WOWLAN
,
11205 .doit
= nl80211_get_wowlan
,
11206 .policy
= nl80211_policy
,
11207 /* can be retrieved by unprivileged users */
11208 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11209 NL80211_FLAG_NEED_RTNL
,
11212 .cmd
= NL80211_CMD_SET_WOWLAN
,
11213 .doit
= nl80211_set_wowlan
,
11214 .policy
= nl80211_policy
,
11215 .flags
= GENL_ADMIN_PERM
,
11216 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11217 NL80211_FLAG_NEED_RTNL
,
11221 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
11222 .doit
= nl80211_set_rekey_data
,
11223 .policy
= nl80211_policy
,
11224 .flags
= GENL_ADMIN_PERM
,
11225 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11226 NL80211_FLAG_NEED_RTNL
|
11227 NL80211_FLAG_CLEAR_SKB
,
11230 .cmd
= NL80211_CMD_TDLS_MGMT
,
11231 .doit
= nl80211_tdls_mgmt
,
11232 .policy
= nl80211_policy
,
11233 .flags
= GENL_ADMIN_PERM
,
11234 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11235 NL80211_FLAG_NEED_RTNL
,
11238 .cmd
= NL80211_CMD_TDLS_OPER
,
11239 .doit
= nl80211_tdls_oper
,
11240 .policy
= nl80211_policy
,
11241 .flags
= GENL_ADMIN_PERM
,
11242 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11243 NL80211_FLAG_NEED_RTNL
,
11246 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
11247 .doit
= nl80211_register_unexpected_frame
,
11248 .policy
= nl80211_policy
,
11249 .flags
= GENL_ADMIN_PERM
,
11250 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11251 NL80211_FLAG_NEED_RTNL
,
11254 .cmd
= NL80211_CMD_PROBE_CLIENT
,
11255 .doit
= nl80211_probe_client
,
11256 .policy
= nl80211_policy
,
11257 .flags
= GENL_ADMIN_PERM
,
11258 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11259 NL80211_FLAG_NEED_RTNL
,
11262 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
11263 .doit
= nl80211_register_beacons
,
11264 .policy
= nl80211_policy
,
11265 .flags
= GENL_ADMIN_PERM
,
11266 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11267 NL80211_FLAG_NEED_RTNL
,
11270 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
11271 .doit
= nl80211_set_noack_map
,
11272 .policy
= nl80211_policy
,
11273 .flags
= GENL_ADMIN_PERM
,
11274 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11275 NL80211_FLAG_NEED_RTNL
,
11278 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
11279 .doit
= nl80211_start_p2p_device
,
11280 .policy
= nl80211_policy
,
11281 .flags
= GENL_ADMIN_PERM
,
11282 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11283 NL80211_FLAG_NEED_RTNL
,
11286 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
11287 .doit
= nl80211_stop_p2p_device
,
11288 .policy
= nl80211_policy
,
11289 .flags
= GENL_ADMIN_PERM
,
11290 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11291 NL80211_FLAG_NEED_RTNL
,
11294 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
11295 .doit
= nl80211_set_mcast_rate
,
11296 .policy
= nl80211_policy
,
11297 .flags
= GENL_ADMIN_PERM
,
11298 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11299 NL80211_FLAG_NEED_RTNL
,
11302 .cmd
= NL80211_CMD_SET_MAC_ACL
,
11303 .doit
= nl80211_set_mac_acl
,
11304 .policy
= nl80211_policy
,
11305 .flags
= GENL_ADMIN_PERM
,
11306 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11307 NL80211_FLAG_NEED_RTNL
,
11310 .cmd
= NL80211_CMD_RADAR_DETECT
,
11311 .doit
= nl80211_start_radar_detection
,
11312 .policy
= nl80211_policy
,
11313 .flags
= GENL_ADMIN_PERM
,
11314 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11315 NL80211_FLAG_NEED_RTNL
,
11318 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
11319 .doit
= nl80211_get_protocol_features
,
11320 .policy
= nl80211_policy
,
11323 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
11324 .doit
= nl80211_update_ft_ies
,
11325 .policy
= nl80211_policy
,
11326 .flags
= GENL_ADMIN_PERM
,
11327 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11328 NL80211_FLAG_NEED_RTNL
,
11331 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
11332 .doit
= nl80211_crit_protocol_start
,
11333 .policy
= nl80211_policy
,
11334 .flags
= GENL_ADMIN_PERM
,
11335 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11336 NL80211_FLAG_NEED_RTNL
,
11339 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
11340 .doit
= nl80211_crit_protocol_stop
,
11341 .policy
= nl80211_policy
,
11342 .flags
= GENL_ADMIN_PERM
,
11343 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11344 NL80211_FLAG_NEED_RTNL
,
11347 .cmd
= NL80211_CMD_GET_COALESCE
,
11348 .doit
= nl80211_get_coalesce
,
11349 .policy
= nl80211_policy
,
11350 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11351 NL80211_FLAG_NEED_RTNL
,
11354 .cmd
= NL80211_CMD_SET_COALESCE
,
11355 .doit
= nl80211_set_coalesce
,
11356 .policy
= nl80211_policy
,
11357 .flags
= GENL_ADMIN_PERM
,
11358 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11359 NL80211_FLAG_NEED_RTNL
,
11362 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
11363 .doit
= nl80211_channel_switch
,
11364 .policy
= nl80211_policy
,
11365 .flags
= GENL_ADMIN_PERM
,
11366 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11367 NL80211_FLAG_NEED_RTNL
,
11370 .cmd
= NL80211_CMD_VENDOR
,
11371 .doit
= nl80211_vendor_cmd
,
11372 .dumpit
= nl80211_vendor_cmd_dump
,
11373 .policy
= nl80211_policy
,
11374 .flags
= GENL_ADMIN_PERM
,
11375 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11376 NL80211_FLAG_NEED_RTNL
,
11379 .cmd
= NL80211_CMD_SET_QOS_MAP
,
11380 .doit
= nl80211_set_qos_map
,
11381 .policy
= nl80211_policy
,
11382 .flags
= GENL_ADMIN_PERM
,
11383 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11384 NL80211_FLAG_NEED_RTNL
,
11387 .cmd
= NL80211_CMD_ADD_TX_TS
,
11388 .doit
= nl80211_add_tx_ts
,
11389 .policy
= nl80211_policy
,
11390 .flags
= GENL_ADMIN_PERM
,
11391 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11392 NL80211_FLAG_NEED_RTNL
,
11395 .cmd
= NL80211_CMD_DEL_TX_TS
,
11396 .doit
= nl80211_del_tx_ts
,
11397 .policy
= nl80211_policy
,
11398 .flags
= GENL_ADMIN_PERM
,
11399 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11400 NL80211_FLAG_NEED_RTNL
,
11403 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
11404 .doit
= nl80211_tdls_channel_switch
,
11405 .policy
= nl80211_policy
,
11406 .flags
= GENL_ADMIN_PERM
,
11407 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11408 NL80211_FLAG_NEED_RTNL
,
11411 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
11412 .doit
= nl80211_tdls_cancel_channel_switch
,
11413 .policy
= nl80211_policy
,
11414 .flags
= GENL_ADMIN_PERM
,
11415 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11416 NL80211_FLAG_NEED_RTNL
,
11420 /* notification functions */
11422 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
11423 enum nl80211_commands cmd
)
11425 struct sk_buff
*msg
;
11426 struct nl80211_dump_wiphy_state state
= {};
11428 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
11429 cmd
!= NL80211_CMD_DEL_WIPHY
);
11431 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11435 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
11440 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11441 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
11444 static int nl80211_add_scan_req(struct sk_buff
*msg
,
11445 struct cfg80211_registered_device
*rdev
)
11447 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
11448 struct nlattr
*nest
;
11454 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
11456 goto nla_put_failure
;
11457 for (i
= 0; i
< req
->n_ssids
; i
++) {
11458 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
11459 goto nla_put_failure
;
11461 nla_nest_end(msg
, nest
);
11463 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
11465 goto nla_put_failure
;
11466 for (i
= 0; i
< req
->n_channels
; i
++) {
11467 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
11468 goto nla_put_failure
;
11470 nla_nest_end(msg
, nest
);
11473 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
11474 goto nla_put_failure
;
11477 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
11478 goto nla_put_failure
;
11485 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
11486 struct cfg80211_registered_device
*rdev
,
11487 struct wireless_dev
*wdev
,
11488 u32 portid
, u32 seq
, int flags
,
11493 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11497 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11498 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11499 wdev
->netdev
->ifindex
)) ||
11500 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11501 goto nla_put_failure
;
11503 /* ignore errors and send incomplete event anyway */
11504 nl80211_add_scan_req(msg
, rdev
);
11506 genlmsg_end(msg
, hdr
);
11510 genlmsg_cancel(msg
, hdr
);
11515 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
11516 struct cfg80211_registered_device
*rdev
,
11517 struct net_device
*netdev
,
11518 u32 portid
, u32 seq
, int flags
, u32 cmd
)
11522 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11526 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11527 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11528 goto nla_put_failure
;
11530 genlmsg_end(msg
, hdr
);
11534 genlmsg_cancel(msg
, hdr
);
11538 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
11539 struct wireless_dev
*wdev
)
11541 struct sk_buff
*msg
;
11543 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11547 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11548 NL80211_CMD_TRIGGER_SCAN
) < 0) {
11553 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11554 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11557 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
11558 struct wireless_dev
*wdev
, bool aborted
)
11560 struct sk_buff
*msg
;
11562 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11566 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11567 aborted
? NL80211_CMD_SCAN_ABORTED
:
11568 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
11576 void nl80211_send_scan_result(struct cfg80211_registered_device
*rdev
,
11577 struct sk_buff
*msg
)
11582 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11583 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11586 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
11587 struct net_device
*netdev
)
11589 struct sk_buff
*msg
;
11591 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11595 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
11596 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
11601 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11602 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11605 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
11606 struct net_device
*netdev
, u32 cmd
)
11608 struct sk_buff
*msg
;
11610 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11614 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
11619 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11620 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11623 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
11624 struct regulatory_request
*request
)
11626 /* Userspace can always count this one always being set */
11627 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
11628 goto nla_put_failure
;
11630 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
11631 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11632 NL80211_REGDOM_TYPE_WORLD
))
11633 goto nla_put_failure
;
11634 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
11635 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11636 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
11637 goto nla_put_failure
;
11638 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
11639 request
->intersect
) {
11640 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11641 NL80211_REGDOM_TYPE_INTERSECTION
))
11642 goto nla_put_failure
;
11644 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11645 NL80211_REGDOM_TYPE_COUNTRY
) ||
11646 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
11648 goto nla_put_failure
;
11651 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
11652 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
11655 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
11656 goto nla_put_failure
;
11659 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
11660 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
11661 goto nla_put_failure
;
11671 * This can happen on global regulatory changes or device specific settings
11672 * based on custom regulatory domains.
11674 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
11675 struct regulatory_request
*request
)
11677 struct sk_buff
*msg
;
11680 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11684 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
11690 if (nl80211_reg_change_event_fill(msg
, request
) == false)
11691 goto nla_put_failure
;
11693 genlmsg_end(msg
, hdr
);
11696 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
11697 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
11703 genlmsg_cancel(msg
, hdr
);
11707 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
11708 struct net_device
*netdev
,
11709 const u8
*buf
, size_t len
,
11710 enum nl80211_commands cmd
, gfp_t gfp
,
11713 struct sk_buff
*msg
;
11716 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11720 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
11726 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11727 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11728 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
11729 goto nla_put_failure
;
11731 if (uapsd_queues
>= 0) {
11732 struct nlattr
*nla_wmm
=
11733 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
11735 goto nla_put_failure
;
11737 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
11739 goto nla_put_failure
;
11741 nla_nest_end(msg
, nla_wmm
);
11744 genlmsg_end(msg
, hdr
);
11746 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11747 NL80211_MCGRP_MLME
, gfp
);
11751 genlmsg_cancel(msg
, hdr
);
11755 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
11756 struct net_device
*netdev
, const u8
*buf
,
11757 size_t len
, gfp_t gfp
)
11759 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11760 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
11763 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
11764 struct net_device
*netdev
, const u8
*buf
,
11765 size_t len
, gfp_t gfp
, int uapsd_queues
)
11767 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11768 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
11771 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
11772 struct net_device
*netdev
, const u8
*buf
,
11773 size_t len
, gfp_t gfp
)
11775 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11776 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
11779 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
11780 struct net_device
*netdev
, const u8
*buf
,
11781 size_t len
, gfp_t gfp
)
11783 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11784 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
11787 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
11790 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11791 struct wiphy
*wiphy
= wdev
->wiphy
;
11792 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11793 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
11796 if (WARN_ON(len
< 2))
11799 if (ieee80211_is_deauth(mgmt
->frame_control
))
11800 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
11802 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
11804 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
11805 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
11807 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
11809 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
11810 struct net_device
*netdev
, int cmd
,
11811 const u8
*addr
, gfp_t gfp
)
11813 struct sk_buff
*msg
;
11816 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11820 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
11826 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11827 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11828 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
11829 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
11830 goto nla_put_failure
;
11832 genlmsg_end(msg
, hdr
);
11834 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11835 NL80211_MCGRP_MLME
, gfp
);
11839 genlmsg_cancel(msg
, hdr
);
11843 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
11844 struct net_device
*netdev
, const u8
*addr
,
11847 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
11851 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
11852 struct net_device
*netdev
, const u8
*addr
,
11855 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
11859 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
11860 struct net_device
*netdev
, const u8
*bssid
,
11861 const u8
*req_ie
, size_t req_ie_len
,
11862 const u8
*resp_ie
, size_t resp_ie_len
,
11863 u16 status
, gfp_t gfp
)
11865 struct sk_buff
*msg
;
11868 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11872 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
11878 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11879 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11880 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
11881 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
11883 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
11885 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
11886 goto nla_put_failure
;
11888 genlmsg_end(msg
, hdr
);
11890 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11891 NL80211_MCGRP_MLME
, gfp
);
11895 genlmsg_cancel(msg
, hdr
);
11900 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
11901 struct net_device
*netdev
, const u8
*bssid
,
11902 const u8
*req_ie
, size_t req_ie_len
,
11903 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
11905 struct sk_buff
*msg
;
11908 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11912 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
11918 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11919 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11920 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
11922 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
11924 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
11925 goto nla_put_failure
;
11927 genlmsg_end(msg
, hdr
);
11929 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11930 NL80211_MCGRP_MLME
, gfp
);
11934 genlmsg_cancel(msg
, hdr
);
11939 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
11940 struct net_device
*netdev
, u16 reason
,
11941 const u8
*ie
, size_t ie_len
, bool from_ap
)
11943 struct sk_buff
*msg
;
11946 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11950 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
11956 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11957 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11958 (from_ap
&& reason
&&
11959 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
11961 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
11962 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
11963 goto nla_put_failure
;
11965 genlmsg_end(msg
, hdr
);
11967 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11968 NL80211_MCGRP_MLME
, GFP_KERNEL
);
11972 genlmsg_cancel(msg
, hdr
);
11977 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
11978 struct net_device
*netdev
, const u8
*bssid
,
11981 struct sk_buff
*msg
;
11984 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11988 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
11994 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11995 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11996 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
11997 goto nla_put_failure
;
11999 genlmsg_end(msg
, hdr
);
12001 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12002 NL80211_MCGRP_MLME
, gfp
);
12006 genlmsg_cancel(msg
, hdr
);
12010 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
12011 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
12013 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12014 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12015 struct sk_buff
*msg
;
12018 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
12021 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
12023 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12027 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
12033 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12034 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12035 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
12037 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
12038 goto nla_put_failure
;
12040 genlmsg_end(msg
, hdr
);
12042 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12043 NL80211_MCGRP_MLME
, gfp
);
12047 genlmsg_cancel(msg
, hdr
);
12050 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
12052 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
12053 struct net_device
*netdev
, const u8
*addr
,
12054 enum nl80211_key_type key_type
, int key_id
,
12055 const u8
*tsc
, gfp_t gfp
)
12057 struct sk_buff
*msg
;
12060 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12064 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
12070 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12071 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12072 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
12073 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
12075 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
12076 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
12077 goto nla_put_failure
;
12079 genlmsg_end(msg
, hdr
);
12081 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12082 NL80211_MCGRP_MLME
, gfp
);
12086 genlmsg_cancel(msg
, hdr
);
12090 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
12091 struct ieee80211_channel
*channel_before
,
12092 struct ieee80211_channel
*channel_after
)
12094 struct sk_buff
*msg
;
12096 struct nlattr
*nl_freq
;
12098 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
12102 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
12109 * Since we are applying the beacon hint to a wiphy we know its
12110 * wiphy_idx is valid
12112 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
12113 goto nla_put_failure
;
12116 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
12118 goto nla_put_failure
;
12119 if (nl80211_msg_put_channel(msg
, channel_before
, false))
12120 goto nla_put_failure
;
12121 nla_nest_end(msg
, nl_freq
);
12124 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
12126 goto nla_put_failure
;
12127 if (nl80211_msg_put_channel(msg
, channel_after
, false))
12128 goto nla_put_failure
;
12129 nla_nest_end(msg
, nl_freq
);
12131 genlmsg_end(msg
, hdr
);
12134 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
12135 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
12141 genlmsg_cancel(msg
, hdr
);
12145 static void nl80211_send_remain_on_chan_event(
12146 int cmd
, struct cfg80211_registered_device
*rdev
,
12147 struct wireless_dev
*wdev
, u64 cookie
,
12148 struct ieee80211_channel
*chan
,
12149 unsigned int duration
, gfp_t gfp
)
12151 struct sk_buff
*msg
;
12154 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12158 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12164 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12165 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12166 wdev
->netdev
->ifindex
)) ||
12167 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12168 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
12169 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
12170 NL80211_CHAN_NO_HT
) ||
12171 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
12172 goto nla_put_failure
;
12174 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
12175 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
12176 goto nla_put_failure
;
12178 genlmsg_end(msg
, hdr
);
12180 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12181 NL80211_MCGRP_MLME
, gfp
);
12185 genlmsg_cancel(msg
, hdr
);
12189 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
12190 struct ieee80211_channel
*chan
,
12191 unsigned int duration
, gfp_t gfp
)
12193 struct wiphy
*wiphy
= wdev
->wiphy
;
12194 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12196 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
12197 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
12198 rdev
, wdev
, cookie
, chan
,
12201 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
12203 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
12204 struct ieee80211_channel
*chan
,
12207 struct wiphy
*wiphy
= wdev
->wiphy
;
12208 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12210 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
12211 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
12212 rdev
, wdev
, cookie
, chan
, 0, gfp
);
12214 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
12216 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
12217 struct station_info
*sinfo
, gfp_t gfp
)
12219 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12220 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12221 struct sk_buff
*msg
;
12223 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
12225 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12229 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
12230 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12235 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12236 NL80211_MCGRP_MLME
, gfp
);
12238 EXPORT_SYMBOL(cfg80211_new_sta
);
12240 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
12241 struct station_info
*sinfo
, gfp_t gfp
)
12243 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12244 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12245 struct sk_buff
*msg
;
12246 struct station_info empty_sinfo
= {};
12249 sinfo
= &empty_sinfo
;
12251 trace_cfg80211_del_sta(dev
, mac_addr
);
12253 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12257 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
12258 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12263 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12264 NL80211_MCGRP_MLME
, gfp
);
12266 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
12268 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
12269 enum nl80211_connect_failed_reason reason
,
12272 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12273 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12274 struct sk_buff
*msg
;
12277 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
12281 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
12287 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12288 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
12289 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
12290 goto nla_put_failure
;
12292 genlmsg_end(msg
, hdr
);
12294 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12295 NL80211_MCGRP_MLME
, gfp
);
12299 genlmsg_cancel(msg
, hdr
);
12302 EXPORT_SYMBOL(cfg80211_conn_failed
);
12304 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
12305 const u8
*addr
, gfp_t gfp
)
12307 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12308 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12309 struct sk_buff
*msg
;
12311 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
12316 msg
= nlmsg_new(100, gfp
);
12320 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12326 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12327 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12328 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
12329 goto nla_put_failure
;
12331 genlmsg_end(msg
, hdr
);
12332 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12336 genlmsg_cancel(msg
, hdr
);
12341 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
12342 const u8
*addr
, gfp_t gfp
)
12344 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12347 trace_cfg80211_rx_spurious_frame(dev
, addr
);
12349 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12350 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
12351 trace_cfg80211_return_bool(false);
12354 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
12356 trace_cfg80211_return_bool(ret
);
12359 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
12361 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
12362 const u8
*addr
, gfp_t gfp
)
12364 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12367 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
12369 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12370 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
12371 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
12372 trace_cfg80211_return_bool(false);
12375 ret
= __nl80211_unexpected_frame(dev
,
12376 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
12378 trace_cfg80211_return_bool(ret
);
12381 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
12383 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
12384 struct wireless_dev
*wdev
, u32 nlportid
,
12385 int freq
, int sig_dbm
,
12386 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
12388 struct net_device
*netdev
= wdev
->netdev
;
12389 struct sk_buff
*msg
;
12392 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12396 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
12402 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12403 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12404 netdev
->ifindex
)) ||
12405 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12406 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
12408 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
12409 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12411 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
12412 goto nla_put_failure
;
12414 genlmsg_end(msg
, hdr
);
12416 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12419 genlmsg_cancel(msg
, hdr
);
12424 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
12425 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
12427 struct wiphy
*wiphy
= wdev
->wiphy
;
12428 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12429 struct net_device
*netdev
= wdev
->netdev
;
12430 struct sk_buff
*msg
;
12433 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
12435 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12439 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
12445 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12446 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12447 netdev
->ifindex
)) ||
12448 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12449 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12450 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
12451 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
12452 goto nla_put_failure
;
12454 genlmsg_end(msg
, hdr
);
12456 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12457 NL80211_MCGRP_MLME
, gfp
);
12461 genlmsg_cancel(msg
, hdr
);
12464 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
12466 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
12467 const char *mac
, gfp_t gfp
)
12469 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12470 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12471 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12477 cb
= (void **)msg
->cb
;
12479 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
12485 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12486 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
12487 goto nla_put_failure
;
12489 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
12490 goto nla_put_failure
;
12492 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
12494 goto nla_put_failure
;
12504 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
12506 void **cb
= (void **)msg
->cb
;
12507 struct cfg80211_registered_device
*rdev
= cb
[2];
12509 nla_nest_end(msg
, cb
[1]);
12510 genlmsg_end(msg
, cb
[0]);
12512 memset(msg
->cb
, 0, sizeof(msg
->cb
));
12514 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12515 NL80211_MCGRP_MLME
, gfp
);
12518 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
12519 enum nl80211_cqm_rssi_threshold_event rssi_event
,
12522 struct sk_buff
*msg
;
12524 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
12526 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
12527 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
12530 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
12534 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
12536 goto nla_put_failure
;
12538 cfg80211_send_cqm(msg
, gfp
);
12545 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
12547 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
12548 const u8
*peer
, u32 num_packets
,
12549 u32 rate
, u32 intvl
, gfp_t gfp
)
12551 struct sk_buff
*msg
;
12553 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
12557 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
12558 goto nla_put_failure
;
12560 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
12561 goto nla_put_failure
;
12563 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
12564 goto nla_put_failure
;
12566 cfg80211_send_cqm(msg
, gfp
);
12572 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
12574 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
12575 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
12577 struct sk_buff
*msg
;
12579 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
12581 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
12585 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
12586 goto nla_put_failure
;
12588 cfg80211_send_cqm(msg
, gfp
);
12594 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
12596 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
12598 struct sk_buff
*msg
;
12600 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
12604 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
12605 goto nla_put_failure
;
12607 cfg80211_send_cqm(msg
, gfp
);
12613 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
12615 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
12616 struct net_device
*netdev
, const u8
*bssid
,
12617 const u8
*replay_ctr
, gfp_t gfp
)
12619 struct sk_buff
*msg
;
12620 struct nlattr
*rekey_attr
;
12623 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12627 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
12633 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12634 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12635 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
12636 goto nla_put_failure
;
12638 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
12640 goto nla_put_failure
;
12642 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
12643 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
12644 goto nla_put_failure
;
12646 nla_nest_end(msg
, rekey_attr
);
12648 genlmsg_end(msg
, hdr
);
12650 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12651 NL80211_MCGRP_MLME
, gfp
);
12655 genlmsg_cancel(msg
, hdr
);
12659 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
12660 const u8
*replay_ctr
, gfp_t gfp
)
12662 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12663 struct wiphy
*wiphy
= wdev
->wiphy
;
12664 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12666 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
12667 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
12669 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
12672 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
12673 struct net_device
*netdev
, int index
,
12674 const u8
*bssid
, bool preauth
, gfp_t gfp
)
12676 struct sk_buff
*msg
;
12677 struct nlattr
*attr
;
12680 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12684 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
12690 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12691 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
12692 goto nla_put_failure
;
12694 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
12696 goto nla_put_failure
;
12698 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
12699 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
12701 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
12702 goto nla_put_failure
;
12704 nla_nest_end(msg
, attr
);
12706 genlmsg_end(msg
, hdr
);
12708 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12709 NL80211_MCGRP_MLME
, gfp
);
12713 genlmsg_cancel(msg
, hdr
);
12717 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
12718 const u8
*bssid
, bool preauth
, gfp_t gfp
)
12720 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12721 struct wiphy
*wiphy
= wdev
->wiphy
;
12722 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12724 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
12725 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
12727 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
12729 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
12730 struct net_device
*netdev
,
12731 struct cfg80211_chan_def
*chandef
,
12733 enum nl80211_commands notif
,
12736 struct sk_buff
*msg
;
12739 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12743 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
12749 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
12750 goto nla_put_failure
;
12752 if (nl80211_send_chandef(msg
, chandef
))
12753 goto nla_put_failure
;
12755 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
12756 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
12757 goto nla_put_failure
;
12759 genlmsg_end(msg
, hdr
);
12761 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12762 NL80211_MCGRP_MLME
, gfp
);
12766 genlmsg_cancel(msg
, hdr
);
12770 void cfg80211_ch_switch_notify(struct net_device
*dev
,
12771 struct cfg80211_chan_def
*chandef
)
12773 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12774 struct wiphy
*wiphy
= wdev
->wiphy
;
12775 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12777 ASSERT_WDEV_LOCK(wdev
);
12779 trace_cfg80211_ch_switch_notify(dev
, chandef
);
12781 wdev
->chandef
= *chandef
;
12782 wdev
->preset_chandef
= *chandef
;
12783 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
12784 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
12786 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
12788 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
12789 struct cfg80211_chan_def
*chandef
,
12792 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12793 struct wiphy
*wiphy
= wdev
->wiphy
;
12794 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12796 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
12798 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
12799 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
12801 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
12804 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
12805 const struct cfg80211_chan_def
*chandef
,
12806 enum nl80211_radar_event event
,
12807 struct net_device
*netdev
, gfp_t gfp
)
12809 struct sk_buff
*msg
;
12812 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12816 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
12822 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
12823 goto nla_put_failure
;
12825 /* NOP and radar events don't need a netdev parameter */
12827 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
12829 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12830 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
12831 goto nla_put_failure
;
12834 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
12835 goto nla_put_failure
;
12837 if (nl80211_send_chandef(msg
, chandef
))
12838 goto nla_put_failure
;
12840 genlmsg_end(msg
, hdr
);
12842 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12843 NL80211_MCGRP_MLME
, gfp
);
12847 genlmsg_cancel(msg
, hdr
);
12851 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
12852 u64 cookie
, bool acked
, gfp_t gfp
)
12854 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12855 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12856 struct sk_buff
*msg
;
12859 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
12861 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12866 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
12872 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12873 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12874 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
12875 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
12876 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
12877 goto nla_put_failure
;
12879 genlmsg_end(msg
, hdr
);
12881 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12882 NL80211_MCGRP_MLME
, gfp
);
12886 genlmsg_cancel(msg
, hdr
);
12889 EXPORT_SYMBOL(cfg80211_probe_status
);
12891 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
12892 const u8
*frame
, size_t len
,
12893 int freq
, int sig_dbm
)
12895 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12896 struct sk_buff
*msg
;
12898 struct cfg80211_beacon_registration
*reg
;
12900 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
12902 spin_lock_bh(&rdev
->beacon_registrations_lock
);
12903 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
12904 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
12906 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12910 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
12912 goto nla_put_failure
;
12914 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12916 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
12918 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
12919 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
12920 goto nla_put_failure
;
12922 genlmsg_end(msg
, hdr
);
12924 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
12926 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12930 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12932 genlmsg_cancel(msg
, hdr
);
12935 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
12938 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
12939 struct cfg80211_wowlan_wakeup
*wakeup
)
12941 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
12942 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
12945 nl_results
= nla_nest_start(
12946 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
12950 for (i
= 0; i
< nd
->n_matches
; i
++) {
12951 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
12953 nl_match
= nla_nest_start(msg
, i
);
12957 /* The SSID attribute is optional in nl80211, but for
12958 * simplicity reasons it's always present in the
12959 * cfg80211 structure. If a driver can't pass the
12960 * SSID, that needs to be changed. A zero length SSID
12961 * is still a valid SSID (wildcard), so it cannot be
12962 * used for this purpose.
12964 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
12965 match
->ssid
.ssid
)) {
12966 nla_nest_cancel(msg
, nl_match
);
12970 if (match
->n_channels
) {
12971 nl_freqs
= nla_nest_start(
12972 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
12974 nla_nest_cancel(msg
, nl_match
);
12978 for (j
= 0; j
< match
->n_channels
; j
++) {
12979 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
12980 nla_nest_cancel(msg
, nl_freqs
);
12981 nla_nest_cancel(msg
, nl_match
);
12986 nla_nest_end(msg
, nl_freqs
);
12989 nla_nest_end(msg
, nl_match
);
12993 nla_nest_end(msg
, nl_results
);
12997 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
12998 struct cfg80211_wowlan_wakeup
*wakeup
,
13001 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13002 struct sk_buff
*msg
;
13006 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
13009 size
+= wakeup
->packet_present_len
;
13011 msg
= nlmsg_new(size
, gfp
);
13015 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
13019 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13020 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13023 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13024 wdev
->netdev
->ifindex
))
13028 struct nlattr
*reasons
;
13030 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
13034 if (wakeup
->disconnect
&&
13035 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
13037 if (wakeup
->magic_pkt
&&
13038 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
13040 if (wakeup
->gtk_rekey_failure
&&
13041 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
13043 if (wakeup
->eap_identity_req
&&
13044 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
13046 if (wakeup
->four_way_handshake
&&
13047 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
13049 if (wakeup
->rfkill_release
&&
13050 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
13053 if (wakeup
->pattern_idx
>= 0 &&
13054 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
13055 wakeup
->pattern_idx
))
13058 if (wakeup
->tcp_match
&&
13059 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
13062 if (wakeup
->tcp_connlost
&&
13063 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
13066 if (wakeup
->tcp_nomoretokens
&&
13068 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
13071 if (wakeup
->packet
) {
13072 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
13073 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
13075 if (!wakeup
->packet_80211
) {
13077 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
13079 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
13082 if (wakeup
->packet_len
&&
13083 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
13086 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
13091 if (wakeup
->net_detect
&&
13092 cfg80211_net_detect_results(msg
, wakeup
))
13095 nla_nest_end(msg
, reasons
);
13098 genlmsg_end(msg
, hdr
);
13100 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13101 NL80211_MCGRP_MLME
, gfp
);
13107 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
13110 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
13111 enum nl80211_tdls_operation oper
,
13112 u16 reason_code
, gfp_t gfp
)
13114 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13115 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13116 struct sk_buff
*msg
;
13119 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
13122 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13126 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
13132 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13133 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13134 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
13135 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
13136 (reason_code
> 0 &&
13137 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
13138 goto nla_put_failure
;
13140 genlmsg_end(msg
, hdr
);
13142 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13143 NL80211_MCGRP_MLME
, gfp
);
13147 genlmsg_cancel(msg
, hdr
);
13150 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
13152 static int nl80211_netlink_notify(struct notifier_block
* nb
,
13153 unsigned long state
,
13156 struct netlink_notify
*notify
= _notify
;
13157 struct cfg80211_registered_device
*rdev
;
13158 struct wireless_dev
*wdev
;
13159 struct cfg80211_beacon_registration
*reg
, *tmp
;
13161 if (state
!= NETLINK_URELEASE
)
13162 return NOTIFY_DONE
;
13166 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
13167 bool schedule_destroy_work
= false;
13168 bool schedule_scan_stop
= false;
13169 struct cfg80211_sched_scan_request
*sched_scan_req
=
13170 rcu_dereference(rdev
->sched_scan_req
);
13172 if (sched_scan_req
&& notify
->portid
&&
13173 sched_scan_req
->owner_nlportid
== notify
->portid
)
13174 schedule_scan_stop
= true;
13176 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
) {
13177 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
13179 if (wdev
->owner_nlportid
== notify
->portid
)
13180 schedule_destroy_work
= true;
13183 spin_lock_bh(&rdev
->beacon_registrations_lock
);
13184 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
13186 if (reg
->nlportid
== notify
->portid
) {
13187 list_del(®
->list
);
13192 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
13194 if (schedule_destroy_work
) {
13195 struct cfg80211_iface_destroy
*destroy
;
13197 destroy
= kzalloc(sizeof(*destroy
), GFP_ATOMIC
);
13199 destroy
->nlportid
= notify
->portid
;
13200 spin_lock(&rdev
->destroy_list_lock
);
13201 list_add(&destroy
->list
, &rdev
->destroy_list
);
13202 spin_unlock(&rdev
->destroy_list_lock
);
13203 schedule_work(&rdev
->destroy_work
);
13205 } else if (schedule_scan_stop
) {
13206 sched_scan_req
->owner_nlportid
= 0;
13208 if (rdev
->ops
->sched_scan_stop
&&
13209 rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
13210 schedule_work(&rdev
->sched_scan_stop_wk
);
13217 * It is possible that the user space process that is controlling the
13218 * indoor setting disappeared, so notify the regulatory core.
13220 regulatory_netlink_notify(notify
->portid
);
13224 static struct notifier_block nl80211_netlink_notifier
= {
13225 .notifier_call
= nl80211_netlink_notify
,
13228 void cfg80211_ft_event(struct net_device
*netdev
,
13229 struct cfg80211_ft_event_params
*ft_event
)
13231 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
13232 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13233 struct sk_buff
*msg
;
13236 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
13238 if (!ft_event
->target_ap
)
13241 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13245 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
13249 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13250 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13251 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
13254 if (ft_event
->ies
&&
13255 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
13257 if (ft_event
->ric_ies
&&
13258 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
13259 ft_event
->ric_ies
))
13262 genlmsg_end(msg
, hdr
);
13264 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13265 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13270 EXPORT_SYMBOL(cfg80211_ft_event
);
13272 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
13274 struct cfg80211_registered_device
*rdev
;
13275 struct sk_buff
*msg
;
13279 rdev
= wiphy_to_rdev(wdev
->wiphy
);
13280 if (!rdev
->crit_proto_nlportid
)
13283 nlportid
= rdev
->crit_proto_nlportid
;
13284 rdev
->crit_proto_nlportid
= 0;
13286 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13290 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
13292 goto nla_put_failure
;
13294 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13295 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13296 goto nla_put_failure
;
13298 genlmsg_end(msg
, hdr
);
13300 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
13305 genlmsg_cancel(msg
, hdr
);
13309 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
13311 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
13313 struct wiphy
*wiphy
= wdev
->wiphy
;
13314 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13315 struct sk_buff
*msg
;
13318 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13322 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
13326 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13327 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
13328 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13331 genlmsg_end(msg
, hdr
);
13333 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
13334 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13340 /* initialisation/exit functions */
13342 int nl80211_init(void)
13346 err
= genl_register_family_with_ops_groups(&nl80211_fam
, nl80211_ops
,
13351 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
13357 genl_unregister_family(&nl80211_fam
);
13361 void nl80211_exit(void)
13363 netlink_unregister_notifier(&nl80211_netlink_notifier
);
13364 genl_unregister_family(&nl80211_fam
);