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/nospec.h>
20 #include <linux/etherdevice.h>
21 #include <net/net_namespace.h>
22 #include <net/genetlink.h>
23 #include <net/cfg80211.h>
25 #include <net/inet_connection_sock.h>
31 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
32 struct genl_info
*info
,
33 struct cfg80211_crypto_settings
*settings
,
36 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
37 struct genl_info
*info
);
38 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
39 struct genl_info
*info
);
41 /* the netlink family */
42 static struct genl_family nl80211_fam
= {
43 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
44 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
45 .hdrsize
= 0, /* no private header */
46 .version
= 1, /* no particular meaning now */
47 .maxattr
= NL80211_ATTR_MAX
,
49 .pre_doit
= nl80211_pre_doit
,
50 .post_doit
= nl80211_post_doit
,
53 /* multicast groups */
54 enum nl80211_multicast_groups
{
57 NL80211_MCGRP_REGULATORY
,
60 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
63 static const struct genl_multicast_group nl80211_mcgrps
[] = {
64 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
65 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
66 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
67 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
68 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
69 #ifdef CONFIG_NL80211_TESTMODE
70 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
74 /* returns ERR_PTR values */
75 static struct wireless_dev
*
76 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
78 struct cfg80211_registered_device
*rdev
;
79 struct wireless_dev
*result
= NULL
;
80 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
81 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
88 if (!have_ifidx
&& !have_wdev_id
)
89 return ERR_PTR(-EINVAL
);
92 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
94 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
95 wiphy_idx
= wdev_id
>> 32;
98 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
99 struct wireless_dev
*wdev
;
101 if (wiphy_net(&rdev
->wiphy
) != netns
)
104 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
107 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
108 if (have_ifidx
&& wdev
->netdev
&&
109 wdev
->netdev
->ifindex
== ifidx
) {
113 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
125 return ERR_PTR(-ENODEV
);
128 static struct cfg80211_registered_device
*
129 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
131 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
132 struct net_device
*netdev
;
136 if (!attrs
[NL80211_ATTR_WIPHY
] &&
137 !attrs
[NL80211_ATTR_IFINDEX
] &&
138 !attrs
[NL80211_ATTR_WDEV
])
139 return ERR_PTR(-EINVAL
);
141 if (attrs
[NL80211_ATTR_WIPHY
])
142 rdev
= cfg80211_rdev_by_wiphy_idx(
143 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
145 if (attrs
[NL80211_ATTR_WDEV
]) {
146 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
147 struct wireless_dev
*wdev
;
150 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
152 /* make sure wdev exists */
153 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
154 if (wdev
->identifier
!= (u32
)wdev_id
)
163 if (rdev
&& tmp
!= rdev
)
164 return ERR_PTR(-EINVAL
);
169 if (attrs
[NL80211_ATTR_IFINDEX
]) {
170 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
171 netdev
= __dev_get_by_index(netns
, ifindex
);
173 if (netdev
->ieee80211_ptr
)
175 netdev
->ieee80211_ptr
->wiphy
);
179 /* not wireless device -- return error */
181 return ERR_PTR(-EINVAL
);
183 /* mismatch -- return error */
184 if (rdev
&& tmp
!= rdev
)
185 return ERR_PTR(-EINVAL
);
192 return ERR_PTR(-ENODEV
);
194 if (netns
!= wiphy_net(&rdev
->wiphy
))
195 return ERR_PTR(-ENODEV
);
201 * This function returns a pointer to the driver
202 * that the genl_info item that is passed refers to.
204 * The result of this can be a PTR_ERR and hence must
205 * be checked with IS_ERR() for errors.
207 static struct cfg80211_registered_device
*
208 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
210 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
213 /* policy for the attributes */
214 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
215 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
216 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
218 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
220 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
221 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
222 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
226 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
227 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
228 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
231 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
233 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
235 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
237 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
238 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
240 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
241 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
242 .len
= WLAN_MAX_KEY_LEN
},
243 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
244 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
245 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
246 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
247 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
249 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
252 .len
= IEEE80211_MAX_DATA_LEN
},
253 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
254 .len
= IEEE80211_MAX_DATA_LEN
},
255 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
256 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
257 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
258 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
259 .len
= NL80211_MAX_SUPP_RATES
},
260 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
261 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
262 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
263 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
264 .len
= IEEE80211_MAX_MESH_ID_LEN
},
265 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
267 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
268 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
270 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
271 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
274 .len
= NL80211_MAX_SUPP_RATES
},
275 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
277 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
278 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
280 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
282 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
283 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
284 .len
= IEEE80211_MAX_DATA_LEN
},
285 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
286 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
288 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
289 .len
= IEEE80211_MAX_SSID_LEN
},
290 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
291 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
292 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
293 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
295 [NL80211_ATTR_STA_FLAGS2
] = {
296 .len
= sizeof(struct nl80211_sta_flag_update
),
298 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
299 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
300 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
303 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
306 [NL80211_ATTR_PMKID
] = { .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_LOCAL_MESH_POWER_MODE
] = {. type
= NLA_U32
},
363 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
364 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
365 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
366 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
367 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
368 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
369 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
370 .len
= NL80211_VHT_CAPABILITY_LEN
,
372 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
373 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
374 .len
= IEEE80211_MAX_DATA_LEN
},
375 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
376 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
377 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
378 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
379 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
380 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
381 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
382 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
384 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
385 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
386 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
387 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
388 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
389 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
390 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
391 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
392 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
393 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
394 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
395 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
396 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
397 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
398 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
399 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
400 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
401 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
402 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
403 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
404 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
407 /* policy for the key attributes */
408 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
409 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
410 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
411 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
412 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
413 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
414 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
415 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
416 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
419 /* policy for the key default flags */
420 static const struct nla_policy
421 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
422 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
423 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
426 /* policy for WoWLAN attributes */
427 static const struct nla_policy
428 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
429 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
430 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
431 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
432 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
433 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
434 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
435 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
436 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
437 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
438 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
441 static const struct nla_policy
442 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
443 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
444 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
445 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
446 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
447 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
448 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
449 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
450 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
452 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
453 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
455 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
456 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
457 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
460 /* policy for coalesce rule attributes */
461 static const struct nla_policy
462 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
463 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
464 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
465 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
468 /* policy for GTK rekey offload attributes */
469 static const struct nla_policy
470 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
471 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
472 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
473 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
476 static const struct nla_policy
477 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
478 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
479 .len
= IEEE80211_MAX_SSID_LEN
},
480 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
483 static const struct nla_policy
484 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
485 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
486 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
489 /* policy for packet pattern attributes */
490 static const struct nla_policy
491 nl80211_packet_pattern_policy
[MAX_NL80211_PKTPAT
+ 1] = {
492 [NL80211_PKTPAT_MASK
] = { .type
= NLA_BINARY
, },
493 [NL80211_PKTPAT_PATTERN
] = { .type
= NLA_BINARY
, },
494 [NL80211_PKTPAT_OFFSET
] = { .type
= NLA_U32
},
497 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
498 struct netlink_callback
*cb
,
499 struct cfg80211_registered_device
**rdev
,
500 struct wireless_dev
**wdev
)
505 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
506 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
511 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
512 nl80211_fam
.attrbuf
);
514 return PTR_ERR(*wdev
);
515 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
516 /* 0 is the first index - add 1 to parse only once */
517 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
518 cb
->args
[1] = (*wdev
)->identifier
;
520 /* subtract the 1 again here */
521 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
522 struct wireless_dev
*tmp
;
526 *rdev
= wiphy_to_rdev(wiphy
);
529 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
530 if (tmp
->identifier
== cb
->args
[1]) {
544 static bool is_valid_ie_attr(const struct nlattr
*attr
)
552 pos
= nla_data(attr
);
573 /* message building helper */
574 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
577 /* since there is no private header just add the generic one */
578 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
581 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
582 struct ieee80211_channel
*chan
,
585 /* Some channels must be completely excluded from the
586 * list to protect old user-space tools from breaking
588 if (!large
&& chan
->flags
&
589 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
592 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
594 goto nla_put_failure
;
596 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
597 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
598 goto nla_put_failure
;
599 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
600 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
601 goto nla_put_failure
;
602 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
603 goto nla_put_failure
;
605 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
606 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
607 goto nla_put_failure
;
611 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
613 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
615 goto nla_put_failure
;
616 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
618 goto nla_put_failure
;
620 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
622 goto nla_put_failure
;
627 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
628 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
629 goto nla_put_failure
;
630 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
631 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
632 goto nla_put_failure
;
633 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
634 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
635 goto nla_put_failure
;
636 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
637 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
638 goto nla_put_failure
;
639 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
640 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
641 goto nla_put_failure
;
642 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
643 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
644 goto nla_put_failure
;
645 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
646 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
647 goto nla_put_failure
;
648 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
649 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
650 goto nla_put_failure
;
653 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
654 DBM_TO_MBM(chan
->max_power
)))
655 goto nla_put_failure
;
663 /* netlink command implementations */
670 bool def_uni
, def_multi
;
673 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
675 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
676 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
681 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
682 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
691 if (tb
[NL80211_KEY_IDX
])
692 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
694 if (tb
[NL80211_KEY_DATA
]) {
695 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
696 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
699 if (tb
[NL80211_KEY_SEQ
]) {
700 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
701 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
704 if (tb
[NL80211_KEY_CIPHER
])
705 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
707 if (tb
[NL80211_KEY_TYPE
]) {
708 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
709 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
713 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
714 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
715 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
716 tb
[NL80211_KEY_DEFAULT_TYPES
],
717 nl80211_key_default_policy
);
721 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
722 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
728 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
730 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
731 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
732 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
735 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
736 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
737 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
740 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
741 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
743 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
744 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
746 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
747 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
756 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
757 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
758 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
762 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
763 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
764 int err
= nla_parse_nested(
765 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
766 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
767 nl80211_key_default_policy
);
771 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
772 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
778 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
782 memset(k
, 0, sizeof(*k
));
786 if (info
->attrs
[NL80211_ATTR_KEY
])
787 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
789 err
= nl80211_parse_key_old(info
, k
);
794 if (k
->def
&& k
->defmgmt
)
798 if (k
->def_uni
|| !k
->def_multi
)
804 if (k
->idx
< 4 || k
->idx
> 5)
807 if (k
->idx
< 0 || k
->idx
> 3)
810 if (k
->idx
< 0 || k
->idx
> 5)
818 static struct cfg80211_cached_keys
*
819 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
820 struct nlattr
*keys
, bool *no_ht
)
822 struct key_parse parse
;
824 struct cfg80211_cached_keys
*result
;
825 int rem
, err
, def
= 0;
827 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
829 return ERR_PTR(-ENOMEM
);
832 result
->defmgmt
= -1;
834 nla_for_each_nested(key
, keys
, rem
) {
835 memset(&parse
, 0, sizeof(parse
));
838 err
= nl80211_parse_key_new(key
, &parse
);
844 if (parse
.idx
< 0 || parse
.idx
> 4)
850 result
->def
= parse
.idx
;
851 if (!parse
.def_uni
|| !parse
.def_multi
)
853 } else if (parse
.defmgmt
)
855 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
856 parse
.idx
, false, NULL
);
859 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
860 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
861 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
862 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
864 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
865 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
877 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
879 ASSERT_WDEV_LOCK(wdev
);
881 switch (wdev
->iftype
) {
882 case NL80211_IFTYPE_AP
:
883 case NL80211_IFTYPE_AP_VLAN
:
884 case NL80211_IFTYPE_P2P_GO
:
885 case NL80211_IFTYPE_MESH_POINT
:
887 case NL80211_IFTYPE_ADHOC
:
888 case NL80211_IFTYPE_STATION
:
889 case NL80211_IFTYPE_P2P_CLIENT
:
890 if (!wdev
->current_bss
)
893 case NL80211_IFTYPE_UNSPECIFIED
:
894 case NL80211_IFTYPE_OCB
:
895 case NL80211_IFTYPE_MONITOR
:
896 case NL80211_IFTYPE_P2P_DEVICE
:
897 case NL80211_IFTYPE_WDS
:
898 case NUM_NL80211_IFTYPES
:
905 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
908 struct ieee80211_channel
*chan
;
912 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
913 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
918 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
920 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
924 goto nla_put_failure
;
928 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
929 goto nla_put_failure
;
934 nla_nest_end(msg
, nl_modes
);
941 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
945 struct nlattr
*nl_combis
;
948 nl_combis
= nla_nest_start(msg
,
949 NL80211_ATTR_INTERFACE_COMBINATIONS
);
951 goto nla_put_failure
;
953 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
954 const struct ieee80211_iface_combination
*c
;
955 struct nlattr
*nl_combi
, *nl_limits
;
957 c
= &wiphy
->iface_combinations
[i
];
959 nl_combi
= nla_nest_start(msg
, i
+ 1);
961 goto nla_put_failure
;
963 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
965 goto nla_put_failure
;
967 for (j
= 0; j
< c
->n_limits
; j
++) {
968 struct nlattr
*nl_limit
;
970 nl_limit
= nla_nest_start(msg
, j
+ 1);
972 goto nla_put_failure
;
973 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
975 goto nla_put_failure
;
976 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
978 goto nla_put_failure
;
979 nla_nest_end(msg
, nl_limit
);
982 nla_nest_end(msg
, nl_limits
);
984 if (c
->beacon_int_infra_match
&&
985 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
986 goto nla_put_failure
;
987 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
988 c
->num_different_channels
) ||
989 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
991 goto nla_put_failure
;
993 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
994 c
->radar_detect_widths
) ||
995 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
996 c
->radar_detect_regions
)))
997 goto nla_put_failure
;
999 nla_nest_end(msg
, nl_combi
);
1002 nla_nest_end(msg
, nl_combis
);
1010 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1011 struct sk_buff
*msg
)
1013 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1014 struct nlattr
*nl_tcp
;
1019 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1023 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1024 tcp
->data_payload_max
))
1027 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1028 tcp
->data_payload_max
))
1031 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1034 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1035 sizeof(*tcp
->tok
), tcp
->tok
))
1038 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1039 tcp
->data_interval_max
))
1042 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1043 tcp
->wake_payload_max
))
1046 nla_nest_end(msg
, nl_tcp
);
1050 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1051 struct cfg80211_registered_device
*rdev
,
1054 struct nlattr
*nl_wowlan
;
1056 if (!rdev
->wiphy
.wowlan
)
1059 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1063 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1064 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1065 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1066 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1067 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1068 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1069 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1070 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1071 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1072 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1073 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1074 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1075 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1076 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1077 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1078 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1081 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1082 struct nl80211_pattern_support pat
= {
1083 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1084 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1085 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1086 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1089 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1094 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1095 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1096 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1099 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1102 nla_nest_end(msg
, nl_wowlan
);
1108 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1109 struct cfg80211_registered_device
*rdev
)
1111 struct nl80211_coalesce_rule_support rule
;
1113 if (!rdev
->wiphy
.coalesce
)
1116 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1117 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1118 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1119 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1120 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1121 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1123 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1129 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1130 struct ieee80211_supported_band
*sband
)
1132 struct nlattr
*nl_rates
, *nl_rate
;
1133 struct ieee80211_rate
*rate
;
1137 if (sband
->ht_cap
.ht_supported
&&
1138 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1139 sizeof(sband
->ht_cap
.mcs
),
1140 &sband
->ht_cap
.mcs
) ||
1141 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1142 sband
->ht_cap
.cap
) ||
1143 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1144 sband
->ht_cap
.ampdu_factor
) ||
1145 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1146 sband
->ht_cap
.ampdu_density
)))
1150 if (sband
->vht_cap
.vht_supported
&&
1151 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1152 sizeof(sband
->vht_cap
.vht_mcs
),
1153 &sband
->vht_cap
.vht_mcs
) ||
1154 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1155 sband
->vht_cap
.cap
)))
1159 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1163 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1164 nl_rate
= nla_nest_start(msg
, i
);
1168 rate
= &sband
->bitrates
[i
];
1169 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1172 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1174 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1177 nla_nest_end(msg
, nl_rate
);
1180 nla_nest_end(msg
, nl_rates
);
1186 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1187 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1190 struct nlattr
*nl_ftypes
, *nl_ifs
;
1191 enum nl80211_iftype ift
;
1197 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1201 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1202 nl_ftypes
= nla_nest_start(msg
, ift
);
1206 stypes
= mgmt_stypes
[ift
].tx
;
1209 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1210 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1215 nla_nest_end(msg
, nl_ftypes
);
1218 nla_nest_end(msg
, nl_ifs
);
1220 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1224 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1225 nl_ftypes
= nla_nest_start(msg
, ift
);
1229 stypes
= mgmt_stypes
[ift
].rx
;
1232 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1233 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1238 nla_nest_end(msg
, nl_ftypes
);
1240 nla_nest_end(msg
, nl_ifs
);
1245 struct nl80211_dump_wiphy_state
{
1248 long split_start
, band_start
, chan_start
;
1252 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1253 enum nl80211_commands cmd
,
1254 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1255 int flags
, struct nl80211_dump_wiphy_state
*state
)
1258 struct nlattr
*nl_bands
, *nl_band
;
1259 struct nlattr
*nl_freqs
, *nl_freq
;
1260 struct nlattr
*nl_cmds
;
1261 enum ieee80211_band band
;
1262 struct ieee80211_channel
*chan
;
1264 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1265 rdev
->wiphy
.mgmt_stypes
;
1268 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1272 if (WARN_ON(!state
))
1275 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1276 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1277 wiphy_name(&rdev
->wiphy
)) ||
1278 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1279 cfg80211_rdev_list_generation
))
1280 goto nla_put_failure
;
1282 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1285 switch (state
->split_start
) {
1287 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1288 rdev
->wiphy
.retry_short
) ||
1289 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1290 rdev
->wiphy
.retry_long
) ||
1291 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1292 rdev
->wiphy
.frag_threshold
) ||
1293 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1294 rdev
->wiphy
.rts_threshold
) ||
1295 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1296 rdev
->wiphy
.coverage_class
) ||
1297 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1298 rdev
->wiphy
.max_scan_ssids
) ||
1299 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1300 rdev
->wiphy
.max_sched_scan_ssids
) ||
1301 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1302 rdev
->wiphy
.max_scan_ie_len
) ||
1303 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1304 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1305 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1306 rdev
->wiphy
.max_match_sets
) ||
1307 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1308 rdev
->wiphy
.max_sched_scan_plans
) ||
1309 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1310 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1311 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1312 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1313 goto nla_put_failure
;
1315 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1316 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1317 goto nla_put_failure
;
1318 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1319 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1320 goto nla_put_failure
;
1321 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1322 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1323 goto nla_put_failure
;
1324 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1325 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1326 goto nla_put_failure
;
1327 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1328 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1329 goto nla_put_failure
;
1330 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1331 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1332 goto nla_put_failure
;
1333 state
->split_start
++;
1337 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1338 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1339 rdev
->wiphy
.cipher_suites
))
1340 goto nla_put_failure
;
1342 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1343 rdev
->wiphy
.max_num_pmkids
))
1344 goto nla_put_failure
;
1346 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1347 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1348 goto nla_put_failure
;
1350 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1351 rdev
->wiphy
.available_antennas_tx
) ||
1352 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1353 rdev
->wiphy
.available_antennas_rx
))
1354 goto nla_put_failure
;
1356 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1357 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1358 rdev
->wiphy
.probe_resp_offload
))
1359 goto nla_put_failure
;
1361 if ((rdev
->wiphy
.available_antennas_tx
||
1362 rdev
->wiphy
.available_antennas_rx
) &&
1363 rdev
->ops
->get_antenna
) {
1364 u32 tx_ant
= 0, rx_ant
= 0;
1366 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1368 if (nla_put_u32(msg
,
1369 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1372 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1374 goto nla_put_failure
;
1378 state
->split_start
++;
1382 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1383 rdev
->wiphy
.interface_modes
))
1384 goto nla_put_failure
;
1385 state
->split_start
++;
1389 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1391 goto nla_put_failure
;
1393 for (band
= state
->band_start
;
1394 band
< IEEE80211_NUM_BANDS
; band
++) {
1395 struct ieee80211_supported_band
*sband
;
1397 sband
= rdev
->wiphy
.bands
[band
];
1402 nl_band
= nla_nest_start(msg
, band
);
1404 goto nla_put_failure
;
1406 switch (state
->chan_start
) {
1408 if (nl80211_send_band_rateinfo(msg
, sband
))
1409 goto nla_put_failure
;
1410 state
->chan_start
++;
1414 /* add frequencies */
1415 nl_freqs
= nla_nest_start(
1416 msg
, NL80211_BAND_ATTR_FREQS
);
1418 goto nla_put_failure
;
1420 for (i
= state
->chan_start
- 1;
1421 i
< sband
->n_channels
;
1423 nl_freq
= nla_nest_start(msg
, i
);
1425 goto nla_put_failure
;
1427 chan
= &sband
->channels
[i
];
1429 if (nl80211_msg_put_channel(
1432 goto nla_put_failure
;
1434 nla_nest_end(msg
, nl_freq
);
1438 if (i
< sband
->n_channels
)
1439 state
->chan_start
= i
+ 2;
1441 state
->chan_start
= 0;
1442 nla_nest_end(msg
, nl_freqs
);
1445 nla_nest_end(msg
, nl_band
);
1448 /* start again here */
1449 if (state
->chan_start
)
1454 nla_nest_end(msg
, nl_bands
);
1456 if (band
< IEEE80211_NUM_BANDS
)
1457 state
->band_start
= band
+ 1;
1459 state
->band_start
= 0;
1461 /* if bands & channels are done, continue outside */
1462 if (state
->band_start
== 0 && state
->chan_start
== 0)
1463 state
->split_start
++;
1467 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1469 goto nla_put_failure
;
1472 #define CMD(op, n) \
1474 if (rdev->ops->op) { \
1476 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1477 goto nla_put_failure; \
1481 CMD(add_virtual_intf
, NEW_INTERFACE
);
1482 CMD(change_virtual_intf
, SET_INTERFACE
);
1483 CMD(add_key
, NEW_KEY
);
1484 CMD(start_ap
, START_AP
);
1485 CMD(add_station
, NEW_STATION
);
1486 CMD(add_mpath
, NEW_MPATH
);
1487 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1488 CMD(change_bss
, SET_BSS
);
1489 CMD(auth
, AUTHENTICATE
);
1490 CMD(assoc
, ASSOCIATE
);
1491 CMD(deauth
, DEAUTHENTICATE
);
1492 CMD(disassoc
, DISASSOCIATE
);
1493 CMD(join_ibss
, JOIN_IBSS
);
1494 CMD(join_mesh
, JOIN_MESH
);
1495 CMD(set_pmksa
, SET_PMKSA
);
1496 CMD(del_pmksa
, DEL_PMKSA
);
1497 CMD(flush_pmksa
, FLUSH_PMKSA
);
1498 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1499 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1500 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1501 CMD(mgmt_tx
, FRAME
);
1502 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1503 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1505 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1506 goto nla_put_failure
;
1508 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1509 rdev
->ops
->join_mesh
) {
1511 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1512 goto nla_put_failure
;
1514 CMD(set_wds_peer
, SET_WDS_PEER
);
1515 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1516 CMD(tdls_mgmt
, TDLS_MGMT
);
1517 CMD(tdls_oper
, TDLS_OPER
);
1519 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1520 CMD(sched_scan_start
, START_SCHED_SCAN
);
1521 CMD(probe_client
, PROBE_CLIENT
);
1522 CMD(set_noack_map
, SET_NOACK_MAP
);
1523 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1525 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1526 goto nla_put_failure
;
1528 CMD(start_p2p_device
, START_P2P_DEVICE
);
1529 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1530 #ifdef CONFIG_NL80211_TESTMODE
1531 CMD(testmode_cmd
, TESTMODE
);
1534 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1535 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1536 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1537 CMD(channel_switch
, CHANNEL_SWITCH
);
1538 CMD(set_qos_map
, SET_QOS_MAP
);
1539 if (rdev
->wiphy
.features
&
1540 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1541 CMD(add_tx_ts
, ADD_TX_TS
);
1543 /* add into the if now */
1546 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1548 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1549 goto nla_put_failure
;
1552 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1554 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1555 goto nla_put_failure
;
1558 nla_nest_end(msg
, nl_cmds
);
1559 state
->split_start
++;
1563 if (rdev
->ops
->remain_on_channel
&&
1564 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1566 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1567 rdev
->wiphy
.max_remain_on_channel_duration
))
1568 goto nla_put_failure
;
1570 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1571 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1572 goto nla_put_failure
;
1574 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1575 goto nla_put_failure
;
1576 state
->split_start
++;
1581 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1582 goto nla_put_failure
;
1583 state
->split_start
++;
1587 state
->split_start
++;
1590 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1591 rdev
->wiphy
.software_iftypes
))
1592 goto nla_put_failure
;
1594 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1596 goto nla_put_failure
;
1598 state
->split_start
++;
1602 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1603 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1604 rdev
->wiphy
.ap_sme_capa
))
1605 goto nla_put_failure
;
1607 features
= rdev
->wiphy
.features
;
1609 * We can only add the per-channel limit information if the
1610 * dump is split, otherwise it makes it too big. Therefore
1611 * only advertise it in that case.
1614 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1615 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1616 goto nla_put_failure
;
1618 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1619 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1620 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1621 rdev
->wiphy
.ht_capa_mod_mask
))
1622 goto nla_put_failure
;
1624 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1625 rdev
->wiphy
.max_acl_mac_addrs
&&
1626 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1627 rdev
->wiphy
.max_acl_mac_addrs
))
1628 goto nla_put_failure
;
1631 * Any information below this point is only available to
1632 * applications that can deal with it being split. This
1633 * helps ensure that newly added capabilities don't break
1634 * older tools by overrunning their buffers.
1636 * We still increment split_start so that in the split
1637 * case we'll continue with more data in the next round,
1638 * but break unconditionally so unsplit data stops here.
1640 state
->split_start
++;
1643 if (rdev
->wiphy
.extended_capabilities
&&
1644 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1645 rdev
->wiphy
.extended_capabilities_len
,
1646 rdev
->wiphy
.extended_capabilities
) ||
1647 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1648 rdev
->wiphy
.extended_capabilities_len
,
1649 rdev
->wiphy
.extended_capabilities_mask
)))
1650 goto nla_put_failure
;
1652 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1653 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1654 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1655 rdev
->wiphy
.vht_capa_mod_mask
))
1656 goto nla_put_failure
;
1658 state
->split_start
++;
1661 if (nl80211_send_coalesce(msg
, rdev
))
1662 goto nla_put_failure
;
1664 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1665 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1666 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1667 goto nla_put_failure
;
1669 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1670 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1671 rdev
->wiphy
.max_ap_assoc_sta
))
1672 goto nla_put_failure
;
1674 state
->split_start
++;
1677 if (rdev
->wiphy
.n_vendor_commands
) {
1678 const struct nl80211_vendor_cmd_info
*info
;
1679 struct nlattr
*nested
;
1681 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1683 goto nla_put_failure
;
1685 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1686 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1687 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1688 goto nla_put_failure
;
1690 nla_nest_end(msg
, nested
);
1693 if (rdev
->wiphy
.n_vendor_events
) {
1694 const struct nl80211_vendor_cmd_info
*info
;
1695 struct nlattr
*nested
;
1697 nested
= nla_nest_start(msg
,
1698 NL80211_ATTR_VENDOR_EVENTS
);
1700 goto nla_put_failure
;
1702 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1703 info
= &rdev
->wiphy
.vendor_events
[i
];
1704 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1705 goto nla_put_failure
;
1707 nla_nest_end(msg
, nested
);
1709 state
->split_start
++;
1712 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1713 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1714 rdev
->wiphy
.max_num_csa_counters
))
1715 goto nla_put_failure
;
1717 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1718 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1719 goto nla_put_failure
;
1721 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1722 sizeof(rdev
->wiphy
.ext_features
),
1723 rdev
->wiphy
.ext_features
))
1724 goto nla_put_failure
;
1727 state
->split_start
= 0;
1731 genlmsg_end(msg
, hdr
);
1735 genlmsg_cancel(msg
, hdr
);
1739 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1740 struct netlink_callback
*cb
,
1741 struct nl80211_dump_wiphy_state
*state
)
1743 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1744 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1745 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1746 /* ignore parse errors for backward compatibility */
1750 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1751 if (tb
[NL80211_ATTR_WIPHY
])
1752 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1753 if (tb
[NL80211_ATTR_WDEV
])
1754 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1755 if (tb
[NL80211_ATTR_IFINDEX
]) {
1756 struct net_device
*netdev
;
1757 struct cfg80211_registered_device
*rdev
;
1758 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1760 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1763 if (netdev
->ieee80211_ptr
) {
1764 rdev
= wiphy_to_rdev(
1765 netdev
->ieee80211_ptr
->wiphy
);
1766 state
->filter_wiphy
= rdev
->wiphy_idx
;
1773 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1776 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1777 struct cfg80211_registered_device
*rdev
;
1781 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1786 state
->filter_wiphy
= -1;
1787 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1793 cb
->args
[0] = (long)state
;
1796 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1797 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1799 if (++idx
<= state
->start
)
1801 if (state
->filter_wiphy
!= -1 &&
1802 state
->filter_wiphy
!= rdev
->wiphy_idx
)
1804 /* attempt to fit multiple wiphy data chunks into the skb */
1806 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
1808 NETLINK_CB(cb
->skb
).portid
,
1810 NLM_F_MULTI
, state
);
1813 * If sending the wiphy data didn't fit (ENOBUFS
1814 * or EMSGSIZE returned), this SKB is still
1815 * empty (so it's not too big because another
1816 * wiphy dataset is already in the skb) and
1817 * we've not tried to adjust the dump allocation
1818 * yet ... then adjust the alloc size to be
1819 * bigger, and return 1 but with the empty skb.
1820 * This results in an empty message being RX'ed
1821 * in userspace, but that is ignored.
1823 * We can then retry with the larger buffer.
1825 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1826 !skb
->len
&& !state
->split
&&
1827 cb
->min_dump_alloc
< 4096) {
1828 cb
->min_dump_alloc
= 4096;
1829 state
->split_start
= 0;
1836 } while (state
->split_start
> 0);
1846 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1848 kfree((void *)cb
->args
[0]);
1852 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1854 struct sk_buff
*msg
;
1855 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1856 struct nl80211_dump_wiphy_state state
= {};
1858 msg
= nlmsg_new(4096, GFP_KERNEL
);
1862 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
1863 info
->snd_portid
, info
->snd_seq
, 0,
1869 return genlmsg_reply(msg
, info
);
1872 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1873 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1874 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1875 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1876 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1877 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1880 static int parse_txq_params(struct nlattr
*tb
[],
1881 struct ieee80211_txq_params
*txq_params
)
1885 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1886 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1887 !tb
[NL80211_TXQ_ATTR_AIFS
])
1890 ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1891 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1892 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1893 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1894 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1896 if (ac
>= NL80211_NUM_ACS
)
1898 txq_params
->ac
= array_index_nospec(ac
, NL80211_NUM_ACS
);
1902 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1905 * You can only set the channel explicitly for WDS interfaces,
1906 * all others have their channel managed via their respective
1907 * "establish a connection" command (connect, join, ...)
1909 * For AP/GO and mesh mode, the channel can be set with the
1910 * channel userspace API, but is only stored and passed to the
1911 * low-level driver when the AP starts or the mesh is joined.
1912 * This is for backward compatibility, userspace can also give
1913 * the channel in the start-ap or join-mesh commands instead.
1915 * Monitors are special as they are normally slaved to
1916 * whatever else is going on, so they have their own special
1917 * operation to set the monitor channel if possible.
1920 wdev
->iftype
== NL80211_IFTYPE_AP
||
1921 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1922 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1923 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1926 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1927 struct genl_info
*info
,
1928 struct cfg80211_chan_def
*chandef
)
1932 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1935 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1937 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1938 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1939 chandef
->center_freq1
= control_freq
;
1940 chandef
->center_freq2
= 0;
1942 /* Primary channel not allowed */
1943 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1946 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1947 enum nl80211_channel_type chantype
;
1949 chantype
= nla_get_u32(
1950 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1953 case NL80211_CHAN_NO_HT
:
1954 case NL80211_CHAN_HT20
:
1955 case NL80211_CHAN_HT40PLUS
:
1956 case NL80211_CHAN_HT40MINUS
:
1957 cfg80211_chandef_create(chandef
, chandef
->chan
,
1963 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1965 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1966 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1967 chandef
->center_freq1
=
1969 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1970 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1971 chandef
->center_freq2
=
1973 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1976 if (!cfg80211_chandef_valid(chandef
))
1979 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1980 IEEE80211_CHAN_DISABLED
))
1983 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1984 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1985 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1991 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1992 struct net_device
*dev
,
1993 struct genl_info
*info
)
1995 struct cfg80211_chan_def chandef
;
1997 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1998 struct wireless_dev
*wdev
= NULL
;
2001 wdev
= dev
->ieee80211_ptr
;
2002 if (!nl80211_can_set_dev_channel(wdev
))
2005 iftype
= wdev
->iftype
;
2007 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2012 case NL80211_IFTYPE_AP
:
2013 case NL80211_IFTYPE_P2P_GO
:
2014 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2019 if (wdev
->beacon_interval
) {
2020 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2021 !(rdev
->wiphy
.features
&
2022 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2027 /* Only allow dynamic channel width changes */
2028 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2032 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2036 wdev
->preset_chandef
= chandef
;
2039 case NL80211_IFTYPE_MESH_POINT
:
2040 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2042 case NL80211_IFTYPE_MONITOR
:
2043 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2052 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2054 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2055 struct net_device
*netdev
= info
->user_ptr
[1];
2057 return __nl80211_set_channel(rdev
, netdev
, info
);
2060 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2062 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2063 struct net_device
*dev
= info
->user_ptr
[1];
2064 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2067 if (!info
->attrs
[NL80211_ATTR_MAC
])
2070 if (netif_running(dev
))
2073 if (!rdev
->ops
->set_wds_peer
)
2076 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2079 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2080 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2084 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2086 struct cfg80211_registered_device
*rdev
;
2087 struct net_device
*netdev
= NULL
;
2088 struct wireless_dev
*wdev
;
2089 int result
= 0, rem_txq_params
= 0;
2090 struct nlattr
*nl_txq_params
;
2092 u8 retry_short
= 0, retry_long
= 0;
2093 u32 frag_threshold
= 0, rts_threshold
= 0;
2094 u8 coverage_class
= 0;
2099 * Try to find the wiphy and netdev. Normally this
2100 * function shouldn't need the netdev, but this is
2101 * done for backward compatibility -- previously
2102 * setting the channel was done per wiphy, but now
2103 * it is per netdev. Previous userland like hostapd
2104 * also passed a netdev to set_wiphy, so that it is
2105 * possible to let that go to the right netdev!
2108 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2109 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2111 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2112 if (netdev
&& netdev
->ieee80211_ptr
)
2113 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2119 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2122 return PTR_ERR(rdev
);
2127 wdev
= netdev
->ieee80211_ptr
;
2130 * end workaround code, by now the rdev is available
2131 * and locked, and wdev may or may not be NULL.
2134 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2135 result
= cfg80211_dev_rename(
2136 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2141 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2142 struct ieee80211_txq_params txq_params
;
2143 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2145 if (!rdev
->ops
->set_txq_params
)
2151 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2152 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2155 if (!netif_running(netdev
))
2158 nla_for_each_nested(nl_txq_params
,
2159 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2161 result
= nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
2162 nla_data(nl_txq_params
),
2163 nla_len(nl_txq_params
),
2167 result
= parse_txq_params(tb
, &txq_params
);
2171 result
= rdev_set_txq_params(rdev
, netdev
,
2178 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2179 result
= __nl80211_set_channel(
2181 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2187 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2188 struct wireless_dev
*txp_wdev
= wdev
;
2189 enum nl80211_tx_power_setting type
;
2192 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2195 if (!rdev
->ops
->set_tx_power
)
2198 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2199 type
= nla_get_u32(info
->attrs
[idx
]);
2201 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2202 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2205 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2206 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2207 mbm
= nla_get_u32(info
->attrs
[idx
]);
2210 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2215 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2216 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2218 if ((!rdev
->wiphy
.available_antennas_tx
&&
2219 !rdev
->wiphy
.available_antennas_rx
) ||
2220 !rdev
->ops
->set_antenna
)
2223 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2224 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2226 /* reject antenna configurations which don't match the
2227 * available antenna masks, except for the "all" mask */
2228 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2229 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2232 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2233 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2235 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2242 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2243 retry_short
= nla_get_u8(
2244 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2245 if (retry_short
== 0)
2248 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2251 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2252 retry_long
= nla_get_u8(
2253 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2254 if (retry_long
== 0)
2257 changed
|= WIPHY_PARAM_RETRY_LONG
;
2260 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2261 frag_threshold
= nla_get_u32(
2262 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2263 if (frag_threshold
< 256)
2266 if (frag_threshold
!= (u32
) -1) {
2268 * Fragments (apart from the last one) are required to
2269 * have even length. Make the fragmentation code
2270 * simpler by stripping LSB should someone try to use
2271 * odd threshold value.
2273 frag_threshold
&= ~0x1;
2275 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2278 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2279 rts_threshold
= nla_get_u32(
2280 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2281 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2284 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2285 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2288 coverage_class
= nla_get_u8(
2289 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2290 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2293 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2294 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2297 changed
|= WIPHY_PARAM_DYN_ACK
;
2301 u8 old_retry_short
, old_retry_long
;
2302 u32 old_frag_threshold
, old_rts_threshold
;
2303 u8 old_coverage_class
;
2305 if (!rdev
->ops
->set_wiphy_params
)
2308 old_retry_short
= rdev
->wiphy
.retry_short
;
2309 old_retry_long
= rdev
->wiphy
.retry_long
;
2310 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2311 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2312 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2314 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2315 rdev
->wiphy
.retry_short
= retry_short
;
2316 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2317 rdev
->wiphy
.retry_long
= retry_long
;
2318 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2319 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2320 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2321 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2322 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2323 rdev
->wiphy
.coverage_class
= coverage_class
;
2325 result
= rdev_set_wiphy_params(rdev
, changed
);
2327 rdev
->wiphy
.retry_short
= old_retry_short
;
2328 rdev
->wiphy
.retry_long
= old_retry_long
;
2329 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2330 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2331 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2338 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2340 return (u64
)wdev
->identifier
|
2341 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2344 static int nl80211_send_chandef(struct sk_buff
*msg
,
2345 const struct cfg80211_chan_def
*chandef
)
2347 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2350 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2351 chandef
->chan
->center_freq
))
2353 switch (chandef
->width
) {
2354 case NL80211_CHAN_WIDTH_20_NOHT
:
2355 case NL80211_CHAN_WIDTH_20
:
2356 case NL80211_CHAN_WIDTH_40
:
2357 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2358 cfg80211_get_chandef_type(chandef
)))
2364 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2366 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2368 if (chandef
->center_freq2
&&
2369 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2374 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2375 struct cfg80211_registered_device
*rdev
,
2376 struct wireless_dev
*wdev
, bool removal
)
2378 struct net_device
*dev
= wdev
->netdev
;
2379 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2383 cmd
= NL80211_CMD_DEL_INTERFACE
;
2385 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2390 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2391 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2392 goto nla_put_failure
;
2394 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2395 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2396 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2397 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2398 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2399 rdev
->devlist_generation
^
2400 (cfg80211_rdev_list_generation
<< 2)))
2401 goto nla_put_failure
;
2403 if (rdev
->ops
->get_channel
) {
2405 struct cfg80211_chan_def chandef
;
2407 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2409 if (nl80211_send_chandef(msg
, &chandef
))
2410 goto nla_put_failure
;
2414 if (rdev
->ops
->get_tx_power
) {
2417 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2419 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2421 goto nla_put_failure
;
2424 if (wdev
->ssid_len
) {
2425 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2426 goto nla_put_failure
;
2429 genlmsg_end(msg
, hdr
);
2433 genlmsg_cancel(msg
, hdr
);
2437 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2441 int wp_start
= cb
->args
[0];
2442 int if_start
= cb
->args
[1];
2443 struct cfg80211_registered_device
*rdev
;
2444 struct wireless_dev
*wdev
;
2447 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2448 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2450 if (wp_idx
< wp_start
) {
2456 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2457 if (if_idx
< if_start
) {
2461 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2462 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2463 rdev
, wdev
, false) < 0) {
2474 cb
->args
[0] = wp_idx
;
2475 cb
->args
[1] = if_idx
;
2480 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2482 struct sk_buff
*msg
;
2483 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2484 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2486 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2490 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2491 rdev
, wdev
, false) < 0) {
2496 return genlmsg_reply(msg
, info
);
2499 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2500 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2501 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2502 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2503 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2504 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2505 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2508 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2510 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2518 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2519 nla
, mntr_flags_policy
))
2522 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2524 *mntrflags
|= (1<<flag
);
2529 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2530 struct net_device
*netdev
, u8 use_4addr
,
2531 enum nl80211_iftype iftype
)
2534 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2540 case NL80211_IFTYPE_AP_VLAN
:
2541 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2544 case NL80211_IFTYPE_STATION
:
2545 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2555 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2557 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2558 struct vif_params params
;
2560 enum nl80211_iftype otype
, ntype
;
2561 struct net_device
*dev
= info
->user_ptr
[1];
2562 u32 _flags
, *flags
= NULL
;
2563 bool change
= false;
2565 memset(¶ms
, 0, sizeof(params
));
2567 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2569 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2570 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2573 if (ntype
> NL80211_IFTYPE_MAX
)
2577 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2578 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2580 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2582 if (netif_running(dev
))
2586 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2587 IEEE80211_MAX_MESH_ID_LEN
);
2588 wdev
->mesh_id_up_len
=
2589 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2590 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2591 wdev
->mesh_id_up_len
);
2595 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2596 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2598 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2602 params
.use_4addr
= -1;
2605 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2606 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2608 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2617 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2618 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2622 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2626 if (!err
&& params
.use_4addr
!= -1)
2627 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2632 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2634 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2635 struct vif_params params
;
2636 struct wireless_dev
*wdev
;
2637 struct sk_buff
*msg
, *event
;
2639 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2642 /* to avoid failing a new interface creation due to pending removal */
2643 cfg80211_destroy_ifaces(rdev
);
2645 memset(¶ms
, 0, sizeof(params
));
2647 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2650 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2651 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2652 if (type
> NL80211_IFTYPE_MAX
)
2656 if (!rdev
->ops
->add_virtual_intf
||
2657 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2660 if ((type
== NL80211_IFTYPE_P2P_DEVICE
||
2661 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
2662 info
->attrs
[NL80211_ATTR_MAC
]) {
2663 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2665 if (!is_valid_ether_addr(params
.macaddr
))
2666 return -EADDRNOTAVAIL
;
2669 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2670 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2671 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2676 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2677 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2680 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2681 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2684 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2688 wdev
= rdev_add_virtual_intf(rdev
,
2689 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2690 NET_NAME_USER
, type
, err
? NULL
: &flags
,
2692 if (WARN_ON(!wdev
)) {
2695 } else if (IS_ERR(wdev
)) {
2697 return PTR_ERR(wdev
);
2700 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
2701 wdev
->owner_nlportid
= info
->snd_portid
;
2704 case NL80211_IFTYPE_MESH_POINT
:
2705 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2708 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2709 IEEE80211_MAX_MESH_ID_LEN
);
2710 wdev
->mesh_id_up_len
=
2711 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2712 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2713 wdev
->mesh_id_up_len
);
2716 case NL80211_IFTYPE_P2P_DEVICE
:
2718 * P2P Device doesn't have a netdev, so doesn't go
2719 * through the netdev notifier and must be added here
2721 mutex_init(&wdev
->mtx
);
2722 INIT_LIST_HEAD(&wdev
->event_list
);
2723 spin_lock_init(&wdev
->event_lock
);
2724 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2725 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2727 wdev
->identifier
= ++rdev
->wdev_id
;
2728 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2729 rdev
->devlist_generation
++;
2735 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2736 rdev
, wdev
, false) < 0) {
2741 event
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2743 if (nl80211_send_iface(event
, 0, 0, 0,
2744 rdev
, wdev
, false) < 0) {
2749 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2750 event
, 0, NL80211_MCGRP_CONFIG
,
2755 return genlmsg_reply(msg
, info
);
2758 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2760 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2761 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2762 struct sk_buff
*msg
;
2765 if (!rdev
->ops
->del_virtual_intf
)
2768 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2769 if (msg
&& nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
, true) < 0) {
2775 * If we remove a wireless device without a netdev then clear
2776 * user_ptr[1] so that nl80211_post_doit won't dereference it
2777 * to check if it needs to do dev_put(). Otherwise it crashes
2778 * since the wdev has been freed, unlike with a netdev where
2779 * we need the dev_put() for the netdev to really be freed.
2782 info
->user_ptr
[1] = NULL
;
2784 status
= rdev_del_virtual_intf(rdev
, wdev
);
2785 if (status
>= 0 && msg
)
2786 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2787 msg
, 0, NL80211_MCGRP_CONFIG
,
2795 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2797 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2798 struct net_device
*dev
= info
->user_ptr
[1];
2801 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2804 if (!rdev
->ops
->set_noack_map
)
2807 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2809 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2812 struct get_key_cookie
{
2813 struct sk_buff
*msg
;
2818 static void get_key_callback(void *c
, struct key_params
*params
)
2821 struct get_key_cookie
*cookie
= c
;
2824 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2825 params
->key_len
, params
->key
)) ||
2827 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2828 params
->seq_len
, params
->seq
)) ||
2830 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2832 goto nla_put_failure
;
2834 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2836 goto nla_put_failure
;
2839 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2840 params
->key_len
, params
->key
)) ||
2842 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2843 params
->seq_len
, params
->seq
)) ||
2845 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2847 goto nla_put_failure
;
2849 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2850 goto nla_put_failure
;
2852 nla_nest_end(cookie
->msg
, key
);
2859 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2863 struct net_device
*dev
= info
->user_ptr
[1];
2865 const u8
*mac_addr
= NULL
;
2867 struct get_key_cookie cookie
= {
2871 struct sk_buff
*msg
;
2873 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2874 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2879 if (info
->attrs
[NL80211_ATTR_MAC
])
2880 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2882 pairwise
= !!mac_addr
;
2883 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2884 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2885 if (kt
>= NUM_NL80211_KEYTYPES
)
2887 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2888 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2890 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2893 if (!rdev
->ops
->get_key
)
2896 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2899 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2903 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2904 NL80211_CMD_NEW_KEY
);
2906 goto nla_put_failure
;
2909 cookie
.idx
= key_idx
;
2911 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2912 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2913 goto nla_put_failure
;
2915 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2916 goto nla_put_failure
;
2918 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2925 goto nla_put_failure
;
2927 genlmsg_end(msg
, hdr
);
2928 return genlmsg_reply(msg
, info
);
2937 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2939 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2940 struct key_parse key
;
2942 struct net_device
*dev
= info
->user_ptr
[1];
2944 err
= nl80211_parse_key(info
, &key
);
2951 /* only support setting default key */
2952 if (!key
.def
&& !key
.defmgmt
)
2955 wdev_lock(dev
->ieee80211_ptr
);
2958 if (!rdev
->ops
->set_default_key
) {
2963 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2967 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2968 key
.def_uni
, key
.def_multi
);
2973 #ifdef CONFIG_CFG80211_WEXT
2974 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2977 if (key
.def_uni
|| !key
.def_multi
) {
2982 if (!rdev
->ops
->set_default_mgmt_key
) {
2987 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2991 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2995 #ifdef CONFIG_CFG80211_WEXT
2996 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
3001 wdev_unlock(dev
->ieee80211_ptr
);
3006 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3008 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3010 struct net_device
*dev
= info
->user_ptr
[1];
3011 struct key_parse key
;
3012 const u8
*mac_addr
= NULL
;
3014 err
= nl80211_parse_key(info
, &key
);
3021 if (info
->attrs
[NL80211_ATTR_MAC
])
3022 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3024 if (key
.type
== -1) {
3026 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3028 key
.type
= NL80211_KEYTYPE_GROUP
;
3032 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3033 key
.type
!= NL80211_KEYTYPE_GROUP
)
3036 if (!rdev
->ops
->add_key
)
3039 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3040 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3044 wdev_lock(dev
->ieee80211_ptr
);
3045 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3047 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3048 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3050 wdev_unlock(dev
->ieee80211_ptr
);
3055 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3057 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3059 struct net_device
*dev
= info
->user_ptr
[1];
3060 u8
*mac_addr
= NULL
;
3061 struct key_parse key
;
3063 err
= nl80211_parse_key(info
, &key
);
3067 if (info
->attrs
[NL80211_ATTR_MAC
])
3068 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3070 if (key
.type
== -1) {
3072 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3074 key
.type
= NL80211_KEYTYPE_GROUP
;
3078 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3079 key
.type
!= NL80211_KEYTYPE_GROUP
)
3082 if (!rdev
->ops
->del_key
)
3085 wdev_lock(dev
->ieee80211_ptr
);
3086 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3088 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3089 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3093 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3094 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3097 #ifdef CONFIG_CFG80211_WEXT
3099 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3100 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3101 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3102 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3105 wdev_unlock(dev
->ieee80211_ptr
);
3110 /* This function returns an error or the number of nested attributes */
3111 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3113 struct nlattr
*attr
;
3114 int n_entries
= 0, tmp
;
3116 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3117 if (nla_len(attr
) != ETH_ALEN
)
3127 * This function parses ACL information and allocates memory for ACL data.
3128 * On successful return, the calling function is responsible to free the
3129 * ACL buffer returned by this function.
3131 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3132 struct genl_info
*info
)
3134 enum nl80211_acl_policy acl_policy
;
3135 struct nlattr
*attr
;
3136 struct cfg80211_acl_data
*acl
;
3137 int i
= 0, n_entries
, tmp
;
3139 if (!wiphy
->max_acl_mac_addrs
)
3140 return ERR_PTR(-EOPNOTSUPP
);
3142 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3143 return ERR_PTR(-EINVAL
);
3145 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3146 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3147 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3148 return ERR_PTR(-EINVAL
);
3150 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3151 return ERR_PTR(-EINVAL
);
3153 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3155 return ERR_PTR(n_entries
);
3157 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3158 return ERR_PTR(-ENOTSUPP
);
3160 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3163 return ERR_PTR(-ENOMEM
);
3165 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3166 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3170 acl
->n_acl_entries
= n_entries
;
3171 acl
->acl_policy
= acl_policy
;
3176 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3178 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3179 struct net_device
*dev
= info
->user_ptr
[1];
3180 struct cfg80211_acl_data
*acl
;
3183 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3184 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3187 if (!dev
->ieee80211_ptr
->beacon_interval
)
3190 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3192 return PTR_ERR(acl
);
3194 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3201 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3202 struct cfg80211_beacon_data
*bcn
)
3204 bool haveinfo
= false;
3206 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3207 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3208 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3209 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3212 memset(bcn
, 0, sizeof(*bcn
));
3214 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3215 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3216 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3222 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3223 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3224 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3231 if (attrs
[NL80211_ATTR_IE
]) {
3232 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3233 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3236 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3237 bcn
->proberesp_ies
=
3238 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3239 bcn
->proberesp_ies_len
=
3240 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3243 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3244 bcn
->assocresp_ies
=
3245 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3246 bcn
->assocresp_ies_len
=
3247 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3250 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3251 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3252 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3258 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3259 struct cfg80211_ap_settings
*params
)
3261 struct wireless_dev
*wdev
;
3264 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3265 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3266 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3269 if (!wdev
->preset_chandef
.chan
)
3272 params
->chandef
= wdev
->preset_chandef
;
3280 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3281 enum nl80211_auth_type auth_type
,
3282 enum nl80211_commands cmd
)
3284 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3288 case NL80211_CMD_AUTHENTICATE
:
3289 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3290 auth_type
== NL80211_AUTHTYPE_SAE
)
3293 case NL80211_CMD_CONNECT
:
3294 case NL80211_CMD_START_AP
:
3295 /* SAE not supported yet */
3296 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3304 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3306 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3307 struct net_device
*dev
= info
->user_ptr
[1];
3308 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3309 struct cfg80211_ap_settings params
;
3312 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3313 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3316 if (!rdev
->ops
->start_ap
)
3319 if (wdev
->beacon_interval
)
3322 memset(¶ms
, 0, sizeof(params
));
3324 /* these are required for START_AP */
3325 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3326 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3327 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3330 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3334 params
.beacon_interval
=
3335 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3336 params
.dtim_period
=
3337 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3339 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3344 * In theory, some of these attributes should be required here
3345 * but since they were not used when the command was originally
3346 * added, keep them optional for old user space programs to let
3347 * them continue to work with drivers that do not need the
3348 * additional information -- drivers must check!
3350 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3351 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3353 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3354 if (params
.ssid_len
== 0 ||
3355 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3359 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3360 params
.hidden_ssid
= nla_get_u32(
3361 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3362 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3363 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3364 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3368 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3370 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3371 params
.auth_type
= nla_get_u32(
3372 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3373 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3374 NL80211_CMD_START_AP
))
3377 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3379 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3380 NL80211_MAX_NR_CIPHER_SUITES
);
3384 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3385 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3387 params
.inactivity_timeout
= nla_get_u16(
3388 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3391 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3392 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3394 params
.p2p_ctwindow
=
3395 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3396 if (params
.p2p_ctwindow
> 127)
3398 if (params
.p2p_ctwindow
!= 0 &&
3399 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3403 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3406 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3408 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3411 params
.p2p_opp_ps
= tmp
;
3412 if (params
.p2p_opp_ps
!= 0 &&
3413 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3417 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3418 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3421 } else if (wdev
->preset_chandef
.chan
) {
3422 params
.chandef
= wdev
->preset_chandef
;
3423 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3426 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
3430 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
3432 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
3433 switch (params
.smps_mode
) {
3434 case NL80211_SMPS_OFF
:
3436 case NL80211_SMPS_STATIC
:
3437 if (!(rdev
->wiphy
.features
&
3438 NL80211_FEATURE_STATIC_SMPS
))
3441 case NL80211_SMPS_DYNAMIC
:
3442 if (!(rdev
->wiphy
.features
&
3443 NL80211_FEATURE_DYNAMIC_SMPS
))
3450 params
.smps_mode
= NL80211_SMPS_OFF
;
3453 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3454 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3455 if (IS_ERR(params
.acl
))
3456 return PTR_ERR(params
.acl
);
3460 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3462 wdev
->preset_chandef
= params
.chandef
;
3463 wdev
->beacon_interval
= params
.beacon_interval
;
3464 wdev
->chandef
= params
.chandef
;
3465 wdev
->ssid_len
= params
.ssid_len
;
3466 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3475 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3477 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3478 struct net_device
*dev
= info
->user_ptr
[1];
3479 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3480 struct cfg80211_beacon_data params
;
3483 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3484 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3487 if (!rdev
->ops
->change_beacon
)
3490 if (!wdev
->beacon_interval
)
3493 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3498 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
3504 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3506 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3507 struct net_device
*dev
= info
->user_ptr
[1];
3509 return cfg80211_stop_ap(rdev
, dev
, false);
3512 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3513 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3514 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3515 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3516 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3517 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3518 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3521 static int parse_station_flags(struct genl_info
*info
,
3522 enum nl80211_iftype iftype
,
3523 struct station_parameters
*params
)
3525 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3530 * Try parsing the new attribute first so userspace
3531 * can specify both for older kernels.
3533 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3535 struct nl80211_sta_flag_update
*sta_flags
;
3537 sta_flags
= nla_data(nla
);
3538 params
->sta_flags_mask
= sta_flags
->mask
;
3539 params
->sta_flags_set
= sta_flags
->set
;
3540 params
->sta_flags_set
&= params
->sta_flags_mask
;
3541 if ((params
->sta_flags_mask
|
3542 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3547 /* if present, parse the old attribute */
3549 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3553 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3554 nla
, sta_flags_policy
))
3558 * Only allow certain flags for interface types so that
3559 * other attributes are silently ignored. Remember that
3560 * this is backward compatibility code with old userspace
3561 * and shouldn't be hit in other cases anyway.
3564 case NL80211_IFTYPE_AP
:
3565 case NL80211_IFTYPE_AP_VLAN
:
3566 case NL80211_IFTYPE_P2P_GO
:
3567 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3568 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3569 BIT(NL80211_STA_FLAG_WME
) |
3570 BIT(NL80211_STA_FLAG_MFP
);
3572 case NL80211_IFTYPE_P2P_CLIENT
:
3573 case NL80211_IFTYPE_STATION
:
3574 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3575 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3577 case NL80211_IFTYPE_MESH_POINT
:
3578 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3579 BIT(NL80211_STA_FLAG_MFP
) |
3580 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3586 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3588 params
->sta_flags_set
|= (1<<flag
);
3590 /* no longer support new API additions in old API */
3591 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3599 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3602 struct nlattr
*rate
;
3605 enum nl80211_attrs rate_flg
;
3607 rate
= nla_nest_start(msg
, attr
);
3611 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3612 bitrate
= cfg80211_calculate_bitrate(info
);
3613 /* report 16-bit bitrate only if we can */
3614 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3616 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3618 if (bitrate_compat
> 0 &&
3619 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3623 case RATE_INFO_BW_5
:
3624 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
3626 case RATE_INFO_BW_10
:
3627 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
3632 case RATE_INFO_BW_20
:
3635 case RATE_INFO_BW_40
:
3636 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
3638 case RATE_INFO_BW_80
:
3639 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
3641 case RATE_INFO_BW_160
:
3642 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
3646 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
3649 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3650 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3652 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3653 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3655 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3656 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3658 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3660 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3661 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3665 nla_nest_end(msg
, rate
);
3669 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3678 attr
= nla_nest_start(msg
, id
);
3682 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3683 if (!(mask
& BIT(i
)))
3686 if (nla_put_u8(msg
, i
, signal
[i
]))
3690 nla_nest_end(msg
, attr
);
3695 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
3697 struct cfg80211_registered_device
*rdev
,
3698 struct net_device
*dev
,
3699 const u8
*mac_addr
, struct station_info
*sinfo
)
3702 struct nlattr
*sinfoattr
, *bss_param
;
3704 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
3708 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3709 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3710 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3711 goto nla_put_failure
;
3713 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3715 goto nla_put_failure
;
3717 #define PUT_SINFO(attr, memb, type) do { \
3718 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3719 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3721 goto nla_put_failure; \
3724 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
3725 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
3727 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
3728 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
3729 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3730 (u32
)sinfo
->rx_bytes
))
3731 goto nla_put_failure
;
3733 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
3734 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
3735 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3736 (u32
)sinfo
->tx_bytes
))
3737 goto nla_put_failure
;
3739 PUT_SINFO(RX_BYTES64
, rx_bytes
, u64
);
3740 PUT_SINFO(TX_BYTES64
, tx_bytes
, u64
);
3741 PUT_SINFO(LLID
, llid
, u16
);
3742 PUT_SINFO(PLID
, plid
, u16
);
3743 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
3745 switch (rdev
->wiphy
.signal_type
) {
3746 case CFG80211_SIGNAL_TYPE_MBM
:
3747 PUT_SINFO(SIGNAL
, signal
, u8
);
3748 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
3753 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
3754 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3755 sinfo
->chain_signal
,
3756 NL80211_STA_INFO_CHAIN_SIGNAL
))
3757 goto nla_put_failure
;
3759 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
3760 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3761 sinfo
->chain_signal_avg
,
3762 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3763 goto nla_put_failure
;
3765 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
3766 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3767 NL80211_STA_INFO_TX_BITRATE
))
3768 goto nla_put_failure
;
3770 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
3771 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3772 NL80211_STA_INFO_RX_BITRATE
))
3773 goto nla_put_failure
;
3776 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
3777 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
3778 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
3779 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
3780 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
3781 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
3782 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
3783 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
3784 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
3786 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
3787 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3789 goto nla_put_failure
;
3791 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3792 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3793 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3794 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3795 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3796 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3797 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3798 sinfo
->bss_param
.dtim_period
) ||
3799 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3800 sinfo
->bss_param
.beacon_interval
))
3801 goto nla_put_failure
;
3803 nla_nest_end(msg
, bss_param
);
3805 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
3806 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3807 sizeof(struct nl80211_sta_flag_update
),
3809 goto nla_put_failure
;
3811 PUT_SINFO(T_OFFSET
, t_offset
, u64
);
3812 PUT_SINFO(RX_DROP_MISC
, rx_dropped_misc
, u64
);
3813 PUT_SINFO(BEACON_RX
, rx_beacon
, u64
);
3814 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
3818 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TID_STATS
)) {
3819 struct nlattr
*tidsattr
;
3822 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
3824 goto nla_put_failure
;
3826 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
3827 struct cfg80211_tid_stats
*tidstats
;
3828 struct nlattr
*tidattr
;
3830 tidstats
= &sinfo
->pertid
[tid
];
3832 if (!tidstats
->filled
)
3835 tidattr
= nla_nest_start(msg
, tid
+ 1);
3837 goto nla_put_failure
;
3839 #define PUT_TIDVAL(attr, memb, type) do { \
3840 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3841 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3843 goto nla_put_failure; \
3846 PUT_TIDVAL(RX_MSDU
, rx_msdu
, u64
);
3847 PUT_TIDVAL(TX_MSDU
, tx_msdu
, u64
);
3848 PUT_TIDVAL(TX_MSDU_RETRIES
, tx_msdu_retries
, u64
);
3849 PUT_TIDVAL(TX_MSDU_FAILED
, tx_msdu_failed
, u64
);
3852 nla_nest_end(msg
, tidattr
);
3855 nla_nest_end(msg
, tidsattr
);
3858 nla_nest_end(msg
, sinfoattr
);
3860 if (sinfo
->assoc_req_ies_len
&&
3861 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3862 sinfo
->assoc_req_ies
))
3863 goto nla_put_failure
;
3865 genlmsg_end(msg
, hdr
);
3869 genlmsg_cancel(msg
, hdr
);
3873 static int nl80211_dump_station(struct sk_buff
*skb
,
3874 struct netlink_callback
*cb
)
3876 struct station_info sinfo
;
3877 struct cfg80211_registered_device
*rdev
;
3878 struct wireless_dev
*wdev
;
3879 u8 mac_addr
[ETH_ALEN
];
3880 int sta_idx
= cb
->args
[2];
3884 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
3888 if (!wdev
->netdev
) {
3893 if (!rdev
->ops
->dump_station
) {
3899 memset(&sinfo
, 0, sizeof(sinfo
));
3900 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
3907 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
3908 NETLINK_CB(cb
->skb
).portid
,
3909 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3910 rdev
, wdev
->netdev
, mac_addr
,
3919 cb
->args
[2] = sta_idx
;
3927 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3929 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3930 struct net_device
*dev
= info
->user_ptr
[1];
3931 struct station_info sinfo
;
3932 struct sk_buff
*msg
;
3933 u8
*mac_addr
= NULL
;
3936 memset(&sinfo
, 0, sizeof(sinfo
));
3938 if (!info
->attrs
[NL80211_ATTR_MAC
])
3941 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3943 if (!rdev
->ops
->get_station
)
3946 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3950 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3954 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
3955 info
->snd_portid
, info
->snd_seq
, 0,
3956 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3961 return genlmsg_reply(msg
, info
);
3964 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3965 struct station_parameters
*params
,
3966 enum cfg80211_station_type statype
)
3968 if (params
->listen_interval
!= -1 &&
3969 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
3973 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
3974 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
3977 /* When you run into this, adjust the code below for the new flag */
3978 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3981 case CFG80211_STA_MESH_PEER_KERNEL
:
3982 case CFG80211_STA_MESH_PEER_USER
:
3984 * No ignoring the TDLS flag here -- the userspace mesh
3985 * code doesn't have the bug of including TDLS in the
3988 if (params
->sta_flags_mask
&
3989 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3990 BIT(NL80211_STA_FLAG_MFP
) |
3991 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3994 case CFG80211_STA_TDLS_PEER_SETUP
:
3995 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3996 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3998 /* ignore since it can't change */
3999 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4002 /* disallow mesh-specific things */
4003 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4005 if (params
->local_pm
)
4007 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4011 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4012 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4013 /* TDLS can't be set, ... */
4014 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4017 * ... but don't bother the driver with it. This works around
4018 * a hostapd/wpa_supplicant issue -- it always includes the
4019 * TLDS_PEER flag in the mask even for AP mode.
4021 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4024 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4025 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4026 /* reject other things that can't change */
4027 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4029 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4031 if (params
->supported_rates
)
4033 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4037 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4038 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4044 case CFG80211_STA_AP_MLME_CLIENT
:
4045 /* Use this only for authorizing/unauthorizing a station */
4046 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4049 case CFG80211_STA_AP_CLIENT
:
4050 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4051 /* accept only the listed bits */
4052 if (params
->sta_flags_mask
&
4053 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4054 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4055 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4056 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4057 BIT(NL80211_STA_FLAG_WME
) |
4058 BIT(NL80211_STA_FLAG_MFP
)))
4061 /* but authenticated/associated only if driver handles it */
4062 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4063 params
->sta_flags_mask
&
4064 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4065 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4068 case CFG80211_STA_IBSS
:
4069 case CFG80211_STA_AP_STA
:
4070 /* reject any changes other than AUTHORIZED */
4071 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4074 case CFG80211_STA_TDLS_PEER_SETUP
:
4075 /* reject any changes other than AUTHORIZED or WME */
4076 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4077 BIT(NL80211_STA_FLAG_WME
)))
4079 /* force (at least) rates when authorizing */
4080 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4081 !params
->supported_rates
)
4084 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4085 /* reject any changes */
4087 case CFG80211_STA_MESH_PEER_KERNEL
:
4088 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4091 case CFG80211_STA_MESH_PEER_USER
:
4092 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4093 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4100 EXPORT_SYMBOL(cfg80211_check_station_change
);
4103 * Get vlan interface making sure it is running and on the right wiphy.
4105 static struct net_device
*get_vlan(struct genl_info
*info
,
4106 struct cfg80211_registered_device
*rdev
)
4108 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4109 struct net_device
*v
;
4115 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4117 return ERR_PTR(-ENODEV
);
4119 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4124 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4125 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4126 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4131 if (!netif_running(v
)) {
4139 return ERR_PTR(ret
);
4142 static const struct nla_policy
4143 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
4144 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
4145 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
4148 static int nl80211_parse_sta_wme(struct genl_info
*info
,
4149 struct station_parameters
*params
)
4151 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
4155 /* parse WME attributes if present */
4156 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
4159 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
4160 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
4161 nl80211_sta_wme_policy
);
4165 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4166 params
->uapsd_queues
= nla_get_u8(
4167 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4168 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4171 if (tb
[NL80211_STA_WME_MAX_SP
])
4172 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4174 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4177 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4182 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4183 struct station_parameters
*params
)
4185 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4186 params
->supported_channels
=
4187 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4188 params
->supported_channels_len
=
4189 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4191 * Need to include at least one (first channel, number of
4192 * channels) tuple for each subband, and must have proper
4193 * tuples for the rest of the data as well.
4195 if (params
->supported_channels_len
< 2)
4197 if (params
->supported_channels_len
% 2)
4201 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4202 params
->supported_oper_classes
=
4203 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4204 params
->supported_oper_classes_len
=
4205 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4207 * The value of the Length field of the Supported Operating
4208 * Classes element is between 2 and 253.
4210 if (params
->supported_oper_classes_len
< 2 ||
4211 params
->supported_oper_classes_len
> 253)
4217 static int nl80211_set_station_tdls(struct genl_info
*info
,
4218 struct station_parameters
*params
)
4221 /* Dummy STA entry gets updated once the peer capabilities are known */
4222 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4223 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4224 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4226 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4227 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4229 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4231 err
= nl80211_parse_sta_channel_info(info
, params
);
4235 return nl80211_parse_sta_wme(info
, params
);
4238 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4240 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4241 struct net_device
*dev
= info
->user_ptr
[1];
4242 struct station_parameters params
;
4246 memset(¶ms
, 0, sizeof(params
));
4248 if (!rdev
->ops
->change_station
)
4252 * AID and listen_interval properties can be set only for unassociated
4253 * station. Include these parameters here and will check them in
4254 * cfg80211_check_station_change().
4256 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4257 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4259 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4260 params
.listen_interval
=
4261 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4263 params
.listen_interval
= -1;
4265 if (!info
->attrs
[NL80211_ATTR_MAC
])
4268 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4270 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4271 params
.supported_rates
=
4272 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4273 params
.supported_rates_len
=
4274 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4277 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4279 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4280 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4283 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4285 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4286 params
.ext_capab_len
=
4287 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4290 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4293 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4294 params
.plink_action
=
4295 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4296 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4300 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4301 params
.plink_state
=
4302 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4303 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4305 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4308 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4309 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4310 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4312 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4313 pm
> NL80211_MESH_POWER_MAX
)
4316 params
.local_pm
= pm
;
4319 /* Include parameters for TDLS peer (will check later) */
4320 err
= nl80211_set_station_tdls(info
, ¶ms
);
4324 params
.vlan
= get_vlan(info
, rdev
);
4325 if (IS_ERR(params
.vlan
))
4326 return PTR_ERR(params
.vlan
);
4328 switch (dev
->ieee80211_ptr
->iftype
) {
4329 case NL80211_IFTYPE_AP
:
4330 case NL80211_IFTYPE_AP_VLAN
:
4331 case NL80211_IFTYPE_P2P_GO
:
4332 case NL80211_IFTYPE_P2P_CLIENT
:
4333 case NL80211_IFTYPE_STATION
:
4334 case NL80211_IFTYPE_ADHOC
:
4335 case NL80211_IFTYPE_MESH_POINT
:
4342 /* driver will call cfg80211_check_station_change() */
4343 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4347 dev_put(params
.vlan
);
4352 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4354 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4356 struct net_device
*dev
= info
->user_ptr
[1];
4357 struct station_parameters params
;
4358 u8
*mac_addr
= NULL
;
4360 memset(¶ms
, 0, sizeof(params
));
4362 if (!rdev
->ops
->add_station
)
4365 if (!info
->attrs
[NL80211_ATTR_MAC
])
4368 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4371 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4374 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4375 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4378 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4379 params
.supported_rates
=
4380 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4381 params
.supported_rates_len
=
4382 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4383 params
.listen_interval
=
4384 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4386 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4387 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4389 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4390 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4393 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4395 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4396 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4399 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4401 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4402 params
.ext_capab_len
=
4403 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4406 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4408 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4410 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4412 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4414 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4415 params
.opmode_notif_used
= true;
4416 params
.opmode_notif
=
4417 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4420 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4421 params
.plink_action
=
4422 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4423 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4427 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
4431 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4435 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4438 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4439 * as userspace might just pass through the capabilities from the IEs
4440 * directly, rather than enforcing this restriction and returning an
4441 * error in this case.
4443 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4444 params
.ht_capa
= NULL
;
4445 params
.vht_capa
= NULL
;
4448 /* When you run into this, adjust the code below for the new flag */
4449 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4451 switch (dev
->ieee80211_ptr
->iftype
) {
4452 case NL80211_IFTYPE_AP
:
4453 case NL80211_IFTYPE_AP_VLAN
:
4454 case NL80211_IFTYPE_P2P_GO
:
4455 /* ignore WME attributes if iface/sta is not capable */
4456 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4457 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4458 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4460 /* TDLS peers cannot be added */
4461 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4462 info
->attrs
[NL80211_ATTR_PEER_AID
])
4464 /* but don't bother the driver with it */
4465 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4467 /* allow authenticated/associated only if driver handles it */
4468 if (!(rdev
->wiphy
.features
&
4469 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4470 params
.sta_flags_mask
&
4471 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4472 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4475 /* must be last in here for error handling */
4476 params
.vlan
= get_vlan(info
, rdev
);
4477 if (IS_ERR(params
.vlan
))
4478 return PTR_ERR(params
.vlan
);
4480 case NL80211_IFTYPE_MESH_POINT
:
4481 /* ignore uAPSD data */
4482 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4484 /* associated is disallowed */
4485 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4487 /* TDLS peers cannot be added */
4488 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4489 info
->attrs
[NL80211_ATTR_PEER_AID
])
4492 case NL80211_IFTYPE_STATION
:
4493 case NL80211_IFTYPE_P2P_CLIENT
:
4494 /* ignore uAPSD data */
4495 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4497 /* these are disallowed */
4498 if (params
.sta_flags_mask
&
4499 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4500 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4502 /* Only TDLS peers can be added */
4503 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4505 /* Can only add if TDLS ... */
4506 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4508 /* ... with external setup is supported */
4509 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4512 * Older wpa_supplicant versions always mark the TDLS peer
4513 * as authorized, but it shouldn't yet be.
4515 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4521 /* be aware of params.vlan when changing code here */
4523 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4526 dev_put(params
.vlan
);
4530 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4532 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4533 struct net_device
*dev
= info
->user_ptr
[1];
4534 struct station_del_parameters params
;
4536 memset(¶ms
, 0, sizeof(params
));
4538 if (info
->attrs
[NL80211_ATTR_MAC
])
4539 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4541 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4542 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4543 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4544 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4547 if (!rdev
->ops
->del_station
)
4550 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
4552 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
4553 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
4554 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
4557 /* Default to Deauthentication frame */
4558 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
4561 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
4562 params
.reason_code
=
4563 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4564 if (params
.reason_code
== 0)
4565 return -EINVAL
; /* 0 is reserved */
4567 /* Default to reason code 2 */
4568 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
4571 return rdev_del_station(rdev
, dev
, ¶ms
);
4574 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4575 int flags
, struct net_device
*dev
,
4576 u8
*dst
, u8
*next_hop
,
4577 struct mpath_info
*pinfo
)
4580 struct nlattr
*pinfoattr
;
4582 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
4586 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4587 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4588 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4589 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4590 goto nla_put_failure
;
4592 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4594 goto nla_put_failure
;
4595 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4596 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4598 goto nla_put_failure
;
4599 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4600 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4601 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4602 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4604 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4605 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4607 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4608 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4610 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4611 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4612 pinfo
->discovery_timeout
)) ||
4613 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4614 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4615 pinfo
->discovery_retries
)))
4616 goto nla_put_failure
;
4618 nla_nest_end(msg
, pinfoattr
);
4620 genlmsg_end(msg
, hdr
);
4624 genlmsg_cancel(msg
, hdr
);
4628 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4629 struct netlink_callback
*cb
)
4631 struct mpath_info pinfo
;
4632 struct cfg80211_registered_device
*rdev
;
4633 struct wireless_dev
*wdev
;
4635 u8 next_hop
[ETH_ALEN
];
4636 int path_idx
= cb
->args
[2];
4640 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4644 if (!rdev
->ops
->dump_mpath
) {
4649 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4655 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
4662 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4663 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4664 wdev
->netdev
, dst
, next_hop
,
4673 cb
->args
[2] = path_idx
;
4680 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4682 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4684 struct net_device
*dev
= info
->user_ptr
[1];
4685 struct mpath_info pinfo
;
4686 struct sk_buff
*msg
;
4688 u8 next_hop
[ETH_ALEN
];
4690 memset(&pinfo
, 0, sizeof(pinfo
));
4692 if (!info
->attrs
[NL80211_ATTR_MAC
])
4695 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4697 if (!rdev
->ops
->get_mpath
)
4700 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4703 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4707 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4711 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4712 dev
, dst
, next_hop
, &pinfo
) < 0) {
4717 return genlmsg_reply(msg
, info
);
4720 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4722 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4723 struct net_device
*dev
= info
->user_ptr
[1];
4725 u8
*next_hop
= NULL
;
4727 if (!info
->attrs
[NL80211_ATTR_MAC
])
4730 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4733 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4734 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4736 if (!rdev
->ops
->change_mpath
)
4739 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4742 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4745 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4747 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4748 struct net_device
*dev
= info
->user_ptr
[1];
4750 u8
*next_hop
= NULL
;
4752 if (!info
->attrs
[NL80211_ATTR_MAC
])
4755 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4758 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4759 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4761 if (!rdev
->ops
->add_mpath
)
4764 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4767 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4770 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4772 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4773 struct net_device
*dev
= info
->user_ptr
[1];
4776 if (info
->attrs
[NL80211_ATTR_MAC
])
4777 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4779 if (!rdev
->ops
->del_mpath
)
4782 return rdev_del_mpath(rdev
, dev
, dst
);
4785 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
4787 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4789 struct net_device
*dev
= info
->user_ptr
[1];
4790 struct mpath_info pinfo
;
4791 struct sk_buff
*msg
;
4795 memset(&pinfo
, 0, sizeof(pinfo
));
4797 if (!info
->attrs
[NL80211_ATTR_MAC
])
4800 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4802 if (!rdev
->ops
->get_mpp
)
4805 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4808 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
4812 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4816 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4817 dev
, dst
, mpp
, &pinfo
) < 0) {
4822 return genlmsg_reply(msg
, info
);
4825 static int nl80211_dump_mpp(struct sk_buff
*skb
,
4826 struct netlink_callback
*cb
)
4828 struct mpath_info pinfo
;
4829 struct cfg80211_registered_device
*rdev
;
4830 struct wireless_dev
*wdev
;
4833 int path_idx
= cb
->args
[2];
4837 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4841 if (!rdev
->ops
->dump_mpp
) {
4846 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4852 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
4859 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4860 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4861 wdev
->netdev
, dst
, mpp
,
4869 cb
->args
[2] = path_idx
;
4876 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4878 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4879 struct net_device
*dev
= info
->user_ptr
[1];
4880 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4881 struct bss_parameters params
;
4884 memset(¶ms
, 0, sizeof(params
));
4885 /* default to not changing parameters */
4886 params
.use_cts_prot
= -1;
4887 params
.use_short_preamble
= -1;
4888 params
.use_short_slot_time
= -1;
4889 params
.ap_isolate
= -1;
4890 params
.ht_opmode
= -1;
4891 params
.p2p_ctwindow
= -1;
4892 params
.p2p_opp_ps
= -1;
4894 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4895 params
.use_cts_prot
=
4896 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4897 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4898 params
.use_short_preamble
=
4899 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4900 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4901 params
.use_short_slot_time
=
4902 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4903 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4904 params
.basic_rates
=
4905 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4906 params
.basic_rates_len
=
4907 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4909 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4910 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4911 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4913 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4915 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4916 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4918 params
.p2p_ctwindow
=
4919 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4920 if (params
.p2p_ctwindow
< 0)
4922 if (params
.p2p_ctwindow
!= 0 &&
4923 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4927 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4930 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4932 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4935 params
.p2p_opp_ps
= tmp
;
4936 if (params
.p2p_opp_ps
&&
4937 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4941 if (!rdev
->ops
->change_bss
)
4944 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4945 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4949 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
4955 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4959 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4964 * You should only get this when cfg80211 hasn't yet initialized
4965 * completely when built-in to the kernel right between the time
4966 * window between nl80211_init() and regulatory_init(), if that is
4969 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4970 return -EINPROGRESS
;
4972 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4973 user_reg_hint_type
=
4974 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4976 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4978 switch (user_reg_hint_type
) {
4979 case NL80211_USER_REG_HINT_USER
:
4980 case NL80211_USER_REG_HINT_CELL_BASE
:
4981 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4984 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4985 return regulatory_hint_user(data
, user_reg_hint_type
);
4986 case NL80211_USER_REG_HINT_INDOOR
:
4987 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
4988 owner_nlportid
= info
->snd_portid
;
4989 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
4995 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
5001 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
5002 struct genl_info
*info
)
5004 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5005 struct net_device
*dev
= info
->user_ptr
[1];
5006 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5007 struct mesh_config cur_params
;
5010 struct nlattr
*pinfoattr
;
5011 struct sk_buff
*msg
;
5013 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5016 if (!rdev
->ops
->get_mesh_config
)
5020 /* If not connected, get default parameters */
5021 if (!wdev
->mesh_id_len
)
5022 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5024 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5030 /* Draw up a netlink message to send back */
5031 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5034 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5035 NL80211_CMD_GET_MESH_CONFIG
);
5038 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5040 goto nla_put_failure
;
5041 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5042 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5043 cur_params
.dot11MeshRetryTimeout
) ||
5044 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5045 cur_params
.dot11MeshConfirmTimeout
) ||
5046 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5047 cur_params
.dot11MeshHoldingTimeout
) ||
5048 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5049 cur_params
.dot11MeshMaxPeerLinks
) ||
5050 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5051 cur_params
.dot11MeshMaxRetries
) ||
5052 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5053 cur_params
.dot11MeshTTL
) ||
5054 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5055 cur_params
.element_ttl
) ||
5056 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5057 cur_params
.auto_open_plinks
) ||
5058 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5059 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5060 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5061 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5062 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5063 cur_params
.path_refresh_time
) ||
5064 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5065 cur_params
.min_discovery_timeout
) ||
5066 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5067 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5068 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5069 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5070 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5071 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5072 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5073 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5074 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5075 cur_params
.dot11MeshHWMPRootMode
) ||
5076 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5077 cur_params
.dot11MeshHWMPRannInterval
) ||
5078 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5079 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
5080 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
5081 cur_params
.dot11MeshForwarding
) ||
5082 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5083 cur_params
.rssi_threshold
) ||
5084 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
5085 cur_params
.ht_opmode
) ||
5086 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5087 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
5088 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5089 cur_params
.dot11MeshHWMProotInterval
) ||
5090 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5091 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
5092 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
5093 cur_params
.power_mode
) ||
5094 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
5095 cur_params
.dot11MeshAwakeWindowDuration
) ||
5096 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5097 cur_params
.plink_timeout
))
5098 goto nla_put_failure
;
5099 nla_nest_end(msg
, pinfoattr
);
5100 genlmsg_end(msg
, hdr
);
5101 return genlmsg_reply(msg
, info
);
5104 genlmsg_cancel(msg
, hdr
);
5110 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
5111 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
5112 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
5113 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
5114 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
5115 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
5116 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
5117 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
5118 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
5119 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
5120 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
5121 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
5122 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
5123 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
5124 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
5125 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
5126 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
5127 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
5128 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
5129 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
5130 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
5131 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
5132 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
5133 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
5134 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
5135 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
5136 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
5137 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
5138 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
5141 static const struct nla_policy
5142 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
5143 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
5144 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
5145 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
5146 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
5147 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
5148 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
5149 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
5150 .len
= IEEE80211_MAX_DATA_LEN
},
5151 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
5154 static int nl80211_parse_mesh_config(struct genl_info
*info
,
5155 struct mesh_config
*cfg
,
5158 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
5161 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5164 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5166 cfg->param = fn(tb[attr]); \
5167 mask |= (1 << (attr - 1)); \
5172 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
5174 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
5175 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
5176 nl80211_meshconf_params_policy
))
5179 /* This makes sure that there aren't more than 32 mesh config
5180 * parameters (otherwise our bitfield scheme would not work.) */
5181 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
5183 /* Fill in the params struct */
5184 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
5185 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5187 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
5188 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5190 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
5191 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5193 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
5194 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5196 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
5197 mask
, NL80211_MESHCONF_MAX_RETRIES
,
5199 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
5200 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
5201 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
5202 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
5204 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
5205 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5207 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
5209 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5211 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
5212 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5214 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
5215 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5217 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
5218 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5220 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
5222 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5224 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
5226 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5228 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
5230 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5232 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5233 dot11MeshHWMPnetDiameterTraversalTime
,
5235 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5237 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
5238 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5240 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
5241 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5243 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5244 dot11MeshGateAnnouncementProtocol
, 0, 1,
5245 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5247 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
5248 mask
, NL80211_MESHCONF_FORWARDING
,
5250 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
5251 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5253 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
5254 mask
, NL80211_MESHCONF_HT_OPMODE
,
5256 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
5258 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5260 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
5261 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5263 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5264 dot11MeshHWMPconfirmationInterval
,
5266 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5268 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
5269 NL80211_MESH_POWER_ACTIVE
,
5270 NL80211_MESH_POWER_MAX
,
5271 mask
, NL80211_MESHCONF_POWER_MODE
,
5273 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
5275 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
5276 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
5277 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5284 #undef FILL_IN_MESH_PARAM_IF_SET
5287 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
5288 struct mesh_setup
*setup
)
5290 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5291 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
5293 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
5295 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
5296 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
5297 nl80211_mesh_setup_params_policy
))
5300 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
5301 setup
->sync_method
=
5302 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
5303 IEEE80211_SYNC_METHOD_VENDOR
:
5304 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
5306 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
5307 setup
->path_sel_proto
=
5308 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
5309 IEEE80211_PATH_PROTOCOL_VENDOR
:
5310 IEEE80211_PATH_PROTOCOL_HWMP
;
5312 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
5313 setup
->path_metric
=
5314 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
5315 IEEE80211_PATH_METRIC_VENDOR
:
5316 IEEE80211_PATH_METRIC_AIRTIME
;
5319 if (tb
[NL80211_MESH_SETUP_IE
]) {
5320 struct nlattr
*ieattr
=
5321 tb
[NL80211_MESH_SETUP_IE
];
5322 if (!is_valid_ie_attr(ieattr
))
5324 setup
->ie
= nla_data(ieattr
);
5325 setup
->ie_len
= nla_len(ieattr
);
5327 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
5328 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
5330 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
5331 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
5332 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
5333 if (setup
->is_secure
)
5334 setup
->user_mpm
= true;
5336 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
5337 if (!setup
->user_mpm
)
5340 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
5346 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
5347 struct genl_info
*info
)
5349 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5350 struct net_device
*dev
= info
->user_ptr
[1];
5351 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5352 struct mesh_config cfg
;
5356 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5359 if (!rdev
->ops
->update_mesh_config
)
5362 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
5367 if (!wdev
->mesh_id_len
)
5371 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
5378 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
5379 struct sk_buff
*msg
)
5381 struct nlattr
*nl_reg_rules
;
5384 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
5385 (regdom
->dfs_region
&&
5386 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
5387 goto nla_put_failure
;
5389 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
5391 goto nla_put_failure
;
5393 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
5394 struct nlattr
*nl_reg_rule
;
5395 const struct ieee80211_reg_rule
*reg_rule
;
5396 const struct ieee80211_freq_range
*freq_range
;
5397 const struct ieee80211_power_rule
*power_rule
;
5398 unsigned int max_bandwidth_khz
;
5400 reg_rule
= ®dom
->reg_rules
[i
];
5401 freq_range
= ®_rule
->freq_range
;
5402 power_rule
= ®_rule
->power_rule
;
5404 nl_reg_rule
= nla_nest_start(msg
, i
);
5406 goto nla_put_failure
;
5408 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
5409 if (!max_bandwidth_khz
)
5410 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
5413 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
5415 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
5416 freq_range
->start_freq_khz
) ||
5417 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
5418 freq_range
->end_freq_khz
) ||
5419 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
5420 max_bandwidth_khz
) ||
5421 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
5422 power_rule
->max_antenna_gain
) ||
5423 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
5424 power_rule
->max_eirp
) ||
5425 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
5426 reg_rule
->dfs_cac_ms
))
5427 goto nla_put_failure
;
5429 nla_nest_end(msg
, nl_reg_rule
);
5432 nla_nest_end(msg
, nl_reg_rules
);
5439 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
5441 const struct ieee80211_regdomain
*regdom
= NULL
;
5442 struct cfg80211_registered_device
*rdev
;
5443 struct wiphy
*wiphy
= NULL
;
5444 struct sk_buff
*msg
;
5447 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5451 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5452 NL80211_CMD_GET_REG
);
5456 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
5459 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
5462 return PTR_ERR(rdev
);
5465 wiphy
= &rdev
->wiphy
;
5466 self_managed
= wiphy
->regulatory_flags
&
5467 REGULATORY_WIPHY_SELF_MANAGED
;
5468 regdom
= get_wiphy_regdom(wiphy
);
5470 /* a self-managed-reg device must have a private regdom */
5471 if (WARN_ON(!regdom
&& self_managed
)) {
5477 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5478 goto nla_put_failure
;
5481 if (!wiphy
&& reg_last_request_cell_base() &&
5482 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5483 NL80211_USER_REG_HINT_CELL_BASE
))
5484 goto nla_put_failure
;
5489 regdom
= rcu_dereference(cfg80211_regdomain
);
5491 if (nl80211_put_regdom(regdom
, msg
))
5492 goto nla_put_failure_rcu
;
5496 genlmsg_end(msg
, hdr
);
5497 return genlmsg_reply(msg
, info
);
5499 nla_put_failure_rcu
:
5502 genlmsg_cancel(msg
, hdr
);
5508 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5509 u32 seq
, int flags
, struct wiphy
*wiphy
,
5510 const struct ieee80211_regdomain
*regdom
)
5512 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5513 NL80211_CMD_GET_REG
);
5518 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5520 if (nl80211_put_regdom(regdom
, msg
))
5521 goto nla_put_failure
;
5523 if (!wiphy
&& reg_last_request_cell_base() &&
5524 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5525 NL80211_USER_REG_HINT_CELL_BASE
))
5526 goto nla_put_failure
;
5529 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5530 goto nla_put_failure
;
5532 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
5533 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
5534 goto nla_put_failure
;
5536 genlmsg_end(msg
, hdr
);
5540 genlmsg_cancel(msg
, hdr
);
5544 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
5545 struct netlink_callback
*cb
)
5547 const struct ieee80211_regdomain
*regdom
= NULL
;
5548 struct cfg80211_registered_device
*rdev
;
5549 int err
, reg_idx
, start
= cb
->args
[2];
5553 if (cfg80211_regdomain
&& start
== 0) {
5554 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5556 rtnl_dereference(cfg80211_regdomain
));
5561 /* the global regdom is idx 0 */
5563 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
5564 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
5568 if (++reg_idx
<= start
)
5571 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5572 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
5579 cb
->args
[2] = reg_idx
;
5586 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
5587 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
5588 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
5589 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
5590 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
5591 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
5592 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
5593 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
5594 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
5597 static int parse_reg_rule(struct nlattr
*tb
[],
5598 struct ieee80211_reg_rule
*reg_rule
)
5600 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
5601 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
5603 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
5605 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
5607 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
5609 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
5611 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
5614 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
5616 freq_range
->start_freq_khz
=
5617 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
5618 freq_range
->end_freq_khz
=
5619 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
5620 freq_range
->max_bandwidth_khz
=
5621 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
5623 power_rule
->max_eirp
=
5624 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
5626 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
5627 power_rule
->max_antenna_gain
=
5628 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
5630 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
5631 reg_rule
->dfs_cac_ms
=
5632 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
5637 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5639 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5640 struct nlattr
*nl_reg_rule
;
5642 int rem_reg_rules
, r
;
5643 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5644 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
5645 struct ieee80211_regdomain
*rd
;
5647 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5650 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5653 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5655 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5656 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5658 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5661 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5665 if (!reg_is_valid_request(alpha2
))
5668 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5669 num_rules
* sizeof(struct ieee80211_reg_rule
);
5671 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5675 rd
->n_reg_rules
= num_rules
;
5676 rd
->alpha2
[0] = alpha2
[0];
5677 rd
->alpha2
[1] = alpha2
[1];
5680 * Disable DFS master mode if the DFS region was
5681 * not supported or known on this kernel.
5683 if (reg_supported_dfs_region(dfs_region
))
5684 rd
->dfs_region
= dfs_region
;
5686 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5688 r
= nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5689 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5693 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5699 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5705 r
= set_regdom(rd
, REGD_SOURCE_CRDA
);
5706 /* set_regdom took ownership */
5713 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
5715 static int validate_scan_freqs(struct nlattr
*freqs
)
5717 struct nlattr
*attr1
, *attr2
;
5718 int n_channels
= 0, tmp1
, tmp2
;
5720 nla_for_each_nested(attr1
, freqs
, tmp1
)
5721 if (nla_len(attr1
) != sizeof(u32
))
5724 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5727 * Some hardware has a limited channel list for
5728 * scanning, and it is pretty much nonsensical
5729 * to scan for a channel twice, so disallow that
5730 * and don't require drivers to check that the
5731 * channel list they get isn't longer than what
5732 * they can scan, as long as they can scan all
5733 * the channels they registered at once.
5735 nla_for_each_nested(attr2
, freqs
, tmp2
)
5736 if (attr1
!= attr2
&&
5737 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5744 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
5745 u8
*mac_addr
, u8
*mac_addr_mask
)
5749 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
5750 eth_zero_addr(mac_addr
);
5751 eth_zero_addr(mac_addr_mask
);
5753 mac_addr_mask
[0] = 0x3;
5758 /* need both or none */
5759 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
5762 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
5763 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
5765 /* don't allow or configure an mcast address */
5766 if (!is_multicast_ether_addr(mac_addr_mask
) ||
5767 is_multicast_ether_addr(mac_addr
))
5771 * allow users to pass a MAC address that has bits set outside
5772 * of the mask, but don't bother drivers with having to deal
5775 for (i
= 0; i
< ETH_ALEN
; i
++)
5776 mac_addr
[i
] &= mac_addr_mask
[i
];
5781 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5783 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5784 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5785 struct cfg80211_scan_request
*request
;
5786 struct nlattr
*attr
;
5787 struct wiphy
*wiphy
;
5788 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5791 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5794 wiphy
= &rdev
->wiphy
;
5796 if (!rdev
->ops
->scan
)
5799 if (rdev
->scan_req
|| rdev
->scan_msg
) {
5804 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5805 n_channels
= validate_scan_freqs(
5806 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5812 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
5815 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5816 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5819 if (n_ssids
> wiphy
->max_scan_ssids
) {
5824 if (info
->attrs
[NL80211_ATTR_IE
])
5825 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5829 if (ie_len
> wiphy
->max_scan_ie_len
) {
5834 request
= kzalloc(sizeof(*request
)
5835 + sizeof(*request
->ssids
) * n_ssids
5836 + sizeof(*request
->channels
) * n_channels
5837 + ie_len
, GFP_KERNEL
);
5844 request
->ssids
= (void *)&request
->channels
[n_channels
];
5845 request
->n_ssids
= n_ssids
;
5848 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5850 request
->ie
= (void *)(request
->channels
+ n_channels
);
5854 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5855 /* user specified, bail out if channel not found */
5856 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5857 struct ieee80211_channel
*chan
;
5859 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5866 /* ignore disabled channels */
5867 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5870 request
->channels
[i
] = chan
;
5874 enum ieee80211_band band
;
5877 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5879 if (!wiphy
->bands
[band
])
5881 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5882 struct ieee80211_channel
*chan
;
5884 chan
= &wiphy
->bands
[band
]->channels
[j
];
5886 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5889 request
->channels
[i
] = chan
;
5900 request
->n_channels
= i
;
5904 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5905 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5909 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5910 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5915 if (info
->attrs
[NL80211_ATTR_IE
]) {
5916 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5917 memcpy((void *)request
->ie
,
5918 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5922 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5923 if (wiphy
->bands
[i
])
5925 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5927 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5928 nla_for_each_nested(attr
,
5929 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5931 enum ieee80211_band band
= nla_type(attr
);
5933 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5938 if (!wiphy
->bands
[band
])
5941 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5944 &request
->rates
[band
]);
5950 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5951 request
->flags
= nla_get_u32(
5952 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5953 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5954 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
5959 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
5960 if (!(wiphy
->features
&
5961 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
)) {
5966 if (wdev
->current_bss
) {
5971 err
= nl80211_parse_random_mac(info
->attrs
,
5973 request
->mac_addr_mask
);
5980 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5982 request
->wdev
= wdev
;
5983 request
->wiphy
= &rdev
->wiphy
;
5984 request
->scan_start
= jiffies
;
5986 rdev
->scan_req
= request
;
5987 err
= rdev_scan(rdev
, request
);
5990 nl80211_send_scan_start(rdev
, wdev
);
5992 dev_hold(wdev
->netdev
);
5995 rdev
->scan_req
= NULL
;
6004 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
6005 struct cfg80211_sched_scan_request
*request
,
6006 struct nlattr
**attrs
)
6008 int tmp
, err
, i
= 0;
6009 struct nlattr
*attr
;
6011 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6015 * If scan plans are not specified,
6016 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6017 * case one scan plan will be set with the specified scan
6018 * interval and infinite number of iterations.
6020 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6023 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
6027 request
->scan_plans
[0].interval
=
6028 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
6029 if (!request
->scan_plans
[0].interval
)
6032 if (request
->scan_plans
[0].interval
>
6033 wiphy
->max_sched_scan_plan_interval
)
6034 request
->scan_plans
[0].interval
=
6035 wiphy
->max_sched_scan_plan_interval
;
6040 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
6041 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
6043 if (WARN_ON(i
>= n_plans
))
6046 err
= nla_parse(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
6047 nla_data(attr
), nla_len(attr
),
6048 nl80211_plan_policy
);
6052 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
6055 request
->scan_plans
[i
].interval
=
6056 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
6057 if (!request
->scan_plans
[i
].interval
||
6058 request
->scan_plans
[i
].interval
>
6059 wiphy
->max_sched_scan_plan_interval
)
6062 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
6063 request
->scan_plans
[i
].iterations
=
6064 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
6065 if (!request
->scan_plans
[i
].iterations
||
6066 (request
->scan_plans
[i
].iterations
>
6067 wiphy
->max_sched_scan_plan_iterations
))
6069 } else if (i
< n_plans
- 1) {
6071 * All scan plans but the last one must specify
6072 * a finite number of iterations
6081 * The last scan plan must not specify the number of
6082 * iterations, it is supposed to run infinitely
6084 if (request
->scan_plans
[n_plans
- 1].iterations
)
6090 static struct cfg80211_sched_scan_request
*
6091 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6092 struct nlattr
**attrs
)
6094 struct cfg80211_sched_scan_request
*request
;
6095 struct nlattr
*attr
;
6096 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
6097 enum ieee80211_band band
;
6099 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
6100 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
6102 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
6103 return ERR_PTR(-EINVAL
);
6105 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6106 n_channels
= validate_scan_freqs(
6107 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6109 return ERR_PTR(-EINVAL
);
6111 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6114 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
6115 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6119 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
6120 return ERR_PTR(-EINVAL
);
6123 * First, count the number of 'real' matchsets. Due to an issue with
6124 * the old implementation, matchsets containing only the RSSI attribute
6125 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6126 * RSSI for all matchsets, rather than their own matchset for reporting
6127 * all APs with a strong RSSI. This is needed to be compatible with
6128 * older userspace that treated a matchset with only the RSSI as the
6129 * global RSSI for all other matchsets - if there are other matchsets.
6131 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6132 nla_for_each_nested(attr
,
6133 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6135 struct nlattr
*rssi
;
6137 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6138 nla_data(attr
), nla_len(attr
),
6139 nl80211_match_policy
);
6141 return ERR_PTR(err
);
6142 /* add other standalone attributes here */
6143 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
]) {
6147 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6149 default_match_rssi
= nla_get_s32(rssi
);
6153 /* However, if there's no other matchset, add the RSSI one */
6154 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
6157 if (n_match_sets
> wiphy
->max_match_sets
)
6158 return ERR_PTR(-EINVAL
);
6160 if (attrs
[NL80211_ATTR_IE
])
6161 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
6165 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
6166 return ERR_PTR(-EINVAL
);
6168 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6170 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6171 * each scan plan already specifies its own interval
6173 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6174 return ERR_PTR(-EINVAL
);
6176 nla_for_each_nested(attr
,
6177 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
6181 * The scan interval attribute is kept for backward
6182 * compatibility. If no scan plans are specified and sched scan
6183 * interval is specified, one scan plan will be set with this
6184 * scan interval and infinite number of iterations.
6186 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6187 return ERR_PTR(-EINVAL
);
6192 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
6193 return ERR_PTR(-EINVAL
);
6195 request
= kzalloc(sizeof(*request
)
6196 + sizeof(*request
->ssids
) * n_ssids
6197 + sizeof(*request
->match_sets
) * n_match_sets
6198 + sizeof(*request
->scan_plans
) * n_plans
6199 + sizeof(*request
->channels
) * n_channels
6200 + ie_len
, GFP_KERNEL
);
6202 return ERR_PTR(-ENOMEM
);
6205 request
->ssids
= (void *)&request
->channels
[n_channels
];
6206 request
->n_ssids
= n_ssids
;
6209 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6211 request
->ie
= (void *)(request
->channels
+ n_channels
);
6216 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
6218 request
->match_sets
=
6219 (void *)(request
->ssids
+ n_ssids
);
6221 request
->match_sets
=
6222 (void *)(request
->channels
+ n_channels
);
6224 request
->n_match_sets
= n_match_sets
;
6227 request
->scan_plans
= (void *)(request
->match_sets
+
6229 else if (request
->ie
)
6230 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
6232 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
6234 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
6236 request
->n_scan_plans
= n_plans
;
6239 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6240 /* user specified, bail out if channel not found */
6241 nla_for_each_nested(attr
,
6242 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
6244 struct ieee80211_channel
*chan
;
6246 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6253 /* ignore disabled channels */
6254 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6257 request
->channels
[i
] = chan
;
6262 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6264 if (!wiphy
->bands
[band
])
6266 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6267 struct ieee80211_channel
*chan
;
6269 chan
= &wiphy
->bands
[band
]->channels
[j
];
6271 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6274 request
->channels
[i
] = chan
;
6285 request
->n_channels
= i
;
6289 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6291 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6295 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6296 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
6303 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6304 nla_for_each_nested(attr
,
6305 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6307 struct nlattr
*ssid
, *rssi
;
6309 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6310 nla_data(attr
), nla_len(attr
),
6311 nl80211_match_policy
);
6314 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
6316 if (WARN_ON(i
>= n_match_sets
)) {
6317 /* this indicates a programming error,
6318 * the loop above should have verified
6325 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
6329 memcpy(request
->match_sets
[i
].ssid
.ssid
,
6330 nla_data(ssid
), nla_len(ssid
));
6331 request
->match_sets
[i
].ssid
.ssid_len
=
6333 /* special attribute - old implemenation w/a */
6334 request
->match_sets
[i
].rssi_thold
=
6336 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6338 request
->match_sets
[i
].rssi_thold
=
6344 /* there was no other matchset, so the RSSI one is alone */
6345 if (i
== 0 && n_match_sets
)
6346 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
6348 request
->min_rssi_thold
= INT_MAX
;
6349 for (i
= 0; i
< n_match_sets
; i
++)
6350 request
->min_rssi_thold
=
6351 min(request
->match_sets
[i
].rssi_thold
,
6352 request
->min_rssi_thold
);
6354 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
6358 request
->ie_len
= ie_len
;
6359 memcpy((void *)request
->ie
,
6360 nla_data(attrs
[NL80211_ATTR_IE
]),
6364 if (attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
6365 request
->flags
= nla_get_u32(
6366 attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6367 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6368 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
6373 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6374 u32 flg
= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
;
6376 if (!wdev
) /* must be net-detect */
6377 flg
= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
6379 if (!(wiphy
->features
& flg
)) {
6384 if (wdev
&& wdev
->current_bss
) {
6389 err
= nl80211_parse_random_mac(attrs
, request
->mac_addr
,
6390 request
->mac_addr_mask
);
6396 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
6398 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
6400 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
6404 request
->scan_start
= jiffies
;
6410 return ERR_PTR(err
);
6413 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
6414 struct genl_info
*info
)
6416 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6417 struct net_device
*dev
= info
->user_ptr
[1];
6418 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6419 struct cfg80211_sched_scan_request
*sched_scan_req
;
6422 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6423 !rdev
->ops
->sched_scan_start
)
6426 if (rdev
->sched_scan_req
)
6427 return -EINPROGRESS
;
6429 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
6432 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
6436 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
6440 sched_scan_req
->dev
= dev
;
6441 sched_scan_req
->wiphy
= &rdev
->wiphy
;
6443 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
6444 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
6446 rcu_assign_pointer(rdev
->sched_scan_req
, sched_scan_req
);
6448 nl80211_send_sched_scan(rdev
, dev
,
6449 NL80211_CMD_START_SCHED_SCAN
);
6453 kfree(sched_scan_req
);
6458 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
6459 struct genl_info
*info
)
6461 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6463 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6464 !rdev
->ops
->sched_scan_stop
)
6467 return __cfg80211_stop_sched_scan(rdev
, false);
6470 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
6471 struct genl_info
*info
)
6473 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6474 struct net_device
*dev
= info
->user_ptr
[1];
6475 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6476 struct cfg80211_chan_def chandef
;
6477 enum nl80211_dfs_regions dfs_region
;
6478 unsigned int cac_time_ms
;
6481 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
6482 if (dfs_region
== NL80211_DFS_UNSET
)
6485 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6489 if (netif_carrier_ok(dev
))
6492 if (wdev
->cac_started
)
6495 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
6503 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
6506 if (!rdev
->ops
->start_radar_detection
)
6509 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
6510 if (WARN_ON(!cac_time_ms
))
6511 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
6513 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
,
6516 wdev
->chandef
= chandef
;
6517 wdev
->cac_started
= true;
6518 wdev
->cac_start_time
= jiffies
;
6519 wdev
->cac_time_ms
= cac_time_ms
;
6524 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
6526 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6527 struct net_device
*dev
= info
->user_ptr
[1];
6528 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6529 struct cfg80211_csa_settings params
;
6530 /* csa_attrs is defined static to avoid waste of stack size - this
6531 * function is called under RTNL lock, so this should not be a problem.
6533 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
6535 bool need_new_beacon
= false;
6539 if (!rdev
->ops
->channel_switch
||
6540 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
6543 switch (dev
->ieee80211_ptr
->iftype
) {
6544 case NL80211_IFTYPE_AP
:
6545 case NL80211_IFTYPE_P2P_GO
:
6546 need_new_beacon
= true;
6548 /* useless if AP is not running */
6549 if (!wdev
->beacon_interval
)
6552 case NL80211_IFTYPE_ADHOC
:
6553 if (!wdev
->ssid_len
)
6556 case NL80211_IFTYPE_MESH_POINT
:
6557 if (!wdev
->mesh_id_len
)
6564 memset(¶ms
, 0, sizeof(params
));
6566 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6567 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
6570 /* only important for AP, IBSS and mesh create IEs internally */
6571 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
6574 /* Even though the attribute is u32, the specification says
6575 * u8, so let's make sure we don't overflow.
6577 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
6581 params
.count
= cs_count
;
6583 if (!need_new_beacon
)
6586 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
6590 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
6591 info
->attrs
[NL80211_ATTR_CSA_IES
],
6596 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
6600 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
6603 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6604 if (!len
|| (len
% sizeof(u16
)))
6607 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
6608 if (rdev
->wiphy
.max_num_csa_counters
&&
6609 (params
.n_counter_offsets_beacon
>
6610 rdev
->wiphy
.max_num_csa_counters
))
6613 params
.counter_offsets_beacon
=
6614 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6616 /* sanity checks - counters should fit and be the same */
6617 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
6618 u16 offset
= params
.counter_offsets_beacon
[i
];
6620 if (offset
>= params
.beacon_csa
.tail_len
)
6623 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
6627 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
6628 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6629 if (!len
|| (len
% sizeof(u16
)))
6632 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
6633 if (rdev
->wiphy
.max_num_csa_counters
&&
6634 (params
.n_counter_offsets_presp
>
6635 rdev
->wiphy
.max_num_csa_counters
))
6638 params
.counter_offsets_presp
=
6639 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6641 /* sanity checks - counters should fit and be the same */
6642 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
6643 u16 offset
= params
.counter_offsets_presp
[i
];
6645 if (offset
>= params
.beacon_csa
.probe_resp_len
)
6648 if (params
.beacon_csa
.probe_resp
[offset
] !=
6655 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
6659 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
6663 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
6670 params
.radar_required
= true;
6672 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
6673 params
.block_tx
= true;
6676 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
6682 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6684 struct cfg80211_registered_device
*rdev
,
6685 struct wireless_dev
*wdev
,
6686 struct cfg80211_internal_bss
*intbss
)
6688 struct cfg80211_bss
*res
= &intbss
->pub
;
6689 const struct cfg80211_bss_ies
*ies
;
6693 ASSERT_WDEV_LOCK(wdev
);
6695 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6696 NL80211_CMD_NEW_SCAN_RESULTS
);
6700 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
6702 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
6703 goto nla_put_failure
;
6705 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
6706 goto nla_put_failure
;
6707 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
6708 goto nla_put_failure
;
6710 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
6712 goto nla_put_failure
;
6713 if ((!is_zero_ether_addr(res
->bssid
) &&
6714 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
6715 goto nla_put_failure
;
6718 /* indicate whether we have probe response data or not */
6719 if (rcu_access_pointer(res
->proberesp_ies
) &&
6720 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
6721 goto fail_unlock_rcu
;
6723 /* this pointer prefers to be pointed to probe response data
6724 * but is always valid
6726 ies
= rcu_dereference(res
->ies
);
6728 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
6729 goto fail_unlock_rcu
;
6730 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
6731 ies
->len
, ies
->data
))
6732 goto fail_unlock_rcu
;
6735 /* and this pointer is always (unless driver didn't know) beacon data */
6736 ies
= rcu_dereference(res
->beacon_ies
);
6737 if (ies
&& ies
->from_beacon
) {
6738 if (nla_put_u64(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
))
6739 goto fail_unlock_rcu
;
6740 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
6741 ies
->len
, ies
->data
))
6742 goto fail_unlock_rcu
;
6746 if (res
->beacon_interval
&&
6747 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
6748 goto nla_put_failure
;
6749 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
6750 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
6751 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
6752 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
6753 jiffies_to_msecs(jiffies
- intbss
->ts
)))
6754 goto nla_put_failure
;
6756 if (intbss
->ts_boottime
&&
6757 nla_put_u64(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
6758 intbss
->ts_boottime
))
6759 goto nla_put_failure
;
6761 switch (rdev
->wiphy
.signal_type
) {
6762 case CFG80211_SIGNAL_TYPE_MBM
:
6763 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
6764 goto nla_put_failure
;
6766 case CFG80211_SIGNAL_TYPE_UNSPEC
:
6767 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
6768 goto nla_put_failure
;
6774 switch (wdev
->iftype
) {
6775 case NL80211_IFTYPE_P2P_CLIENT
:
6776 case NL80211_IFTYPE_STATION
:
6777 if (intbss
== wdev
->current_bss
&&
6778 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6779 NL80211_BSS_STATUS_ASSOCIATED
))
6780 goto nla_put_failure
;
6782 case NL80211_IFTYPE_ADHOC
:
6783 if (intbss
== wdev
->current_bss
&&
6784 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6785 NL80211_BSS_STATUS_IBSS_JOINED
))
6786 goto nla_put_failure
;
6792 nla_nest_end(msg
, bss
);
6794 genlmsg_end(msg
, hdr
);
6800 genlmsg_cancel(msg
, hdr
);
6804 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6806 struct cfg80211_registered_device
*rdev
;
6807 struct cfg80211_internal_bss
*scan
;
6808 struct wireless_dev
*wdev
;
6809 int start
= cb
->args
[2], idx
= 0;
6813 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6820 spin_lock_bh(&rdev
->bss_lock
);
6821 cfg80211_bss_expire(rdev
);
6823 cb
->seq
= rdev
->bss_generation
;
6825 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
6828 if (nl80211_send_bss(skb
, cb
,
6829 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6830 rdev
, wdev
, scan
) < 0) {
6836 spin_unlock_bh(&rdev
->bss_lock
);
6845 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
6846 int flags
, struct net_device
*dev
,
6847 bool allow_radio_stats
,
6848 struct survey_info
*survey
)
6851 struct nlattr
*infoattr
;
6853 /* skip radio stats if userspace didn't request them */
6854 if (!survey
->channel
&& !allow_radio_stats
)
6857 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
6858 NL80211_CMD_NEW_SURVEY_RESULTS
);
6862 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
6863 goto nla_put_failure
;
6865 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
6867 goto nla_put_failure
;
6869 if (survey
->channel
&&
6870 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
6871 survey
->channel
->center_freq
))
6872 goto nla_put_failure
;
6874 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
6875 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
6876 goto nla_put_failure
;
6877 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
6878 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
6879 goto nla_put_failure
;
6880 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
6881 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME
,
6883 goto nla_put_failure
;
6884 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
6885 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
6887 goto nla_put_failure
;
6888 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
6889 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
6890 survey
->time_ext_busy
))
6891 goto nla_put_failure
;
6892 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
6893 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_RX
,
6895 goto nla_put_failure
;
6896 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
6897 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_TX
,
6899 goto nla_put_failure
;
6900 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
6901 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
6903 goto nla_put_failure
;
6905 nla_nest_end(msg
, infoattr
);
6907 genlmsg_end(msg
, hdr
);
6911 genlmsg_cancel(msg
, hdr
);
6915 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6917 struct survey_info survey
;
6918 struct cfg80211_registered_device
*rdev
;
6919 struct wireless_dev
*wdev
;
6920 int survey_idx
= cb
->args
[2];
6925 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6929 /* prepare_wdev_dump parsed the attributes */
6930 radio_stats
= nl80211_fam
.attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
6932 if (!wdev
->netdev
) {
6937 if (!rdev
->ops
->dump_survey
) {
6943 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
6949 /* don't send disabled channels, but do send non-channel data */
6950 if (survey
.channel
&&
6951 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
6956 if (nl80211_send_survey(skb
,
6957 NETLINK_CB(cb
->skb
).portid
,
6958 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6959 wdev
->netdev
, radio_stats
, &survey
) < 0)
6965 cb
->args
[2] = survey_idx
;
6972 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
6974 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
6975 NL80211_WPA_VERSION_2
));
6978 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6980 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6981 struct net_device
*dev
= info
->user_ptr
[1];
6982 struct ieee80211_channel
*chan
;
6983 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
6984 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
6985 enum nl80211_auth_type auth_type
;
6986 struct key_parse key
;
6987 bool local_state_change
;
6989 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6992 if (!info
->attrs
[NL80211_ATTR_MAC
])
6995 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
6998 if (!info
->attrs
[NL80211_ATTR_SSID
])
7001 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7004 err
= nl80211_parse_key(info
, &key
);
7009 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
7011 if (!key
.p
.key
|| !key
.p
.key_len
)
7013 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
7014 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
7015 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
7016 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
7028 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
7029 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
7038 if (!rdev
->ops
->auth
)
7041 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7042 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7045 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7046 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7047 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7051 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7052 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7054 if (info
->attrs
[NL80211_ATTR_IE
]) {
7055 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7056 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7059 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7060 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
7063 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
7064 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
7067 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
7068 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
7070 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7071 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7072 /* need to include at least Auth Transaction and Status Code */
7073 if (sae_data_len
< 4)
7077 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7080 * Since we no longer track auth state, ignore
7081 * requests to only change local state.
7083 if (local_state_change
)
7086 wdev_lock(dev
->ieee80211_ptr
);
7087 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
7088 ssid
, ssid_len
, ie
, ie_len
,
7089 key
.p
.key
, key
.p
.key_len
, key
.idx
,
7090 sae_data
, sae_data_len
);
7091 wdev_unlock(dev
->ieee80211_ptr
);
7095 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
7096 struct genl_info
*info
,
7097 struct cfg80211_crypto_settings
*settings
,
7100 memset(settings
, 0, sizeof(*settings
));
7102 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
7104 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
7106 proto
= nla_get_u16(
7107 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
7108 settings
->control_port_ethertype
= cpu_to_be16(proto
);
7109 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
7112 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
7113 settings
->control_port_no_encrypt
= true;
7115 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
7117 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
7121 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7122 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7123 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
7125 if (len
% sizeof(u32
))
7128 if (settings
->n_ciphers_pairwise
> cipher_limit
)
7131 memcpy(settings
->ciphers_pairwise
, data
, len
);
7133 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
7134 if (!cfg80211_supported_cipher_suite(
7136 settings
->ciphers_pairwise
[i
]))
7140 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
7141 settings
->cipher_group
=
7142 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
7143 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
7144 settings
->cipher_group
))
7148 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
7149 settings
->wpa_versions
=
7150 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
7151 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
7155 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
7159 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7160 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7161 settings
->n_akm_suites
= len
/ sizeof(u32
);
7163 if (len
% sizeof(u32
))
7166 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
7169 memcpy(settings
->akm_suites
, data
, len
);
7175 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
7177 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7178 struct net_device
*dev
= info
->user_ptr
[1];
7179 struct ieee80211_channel
*chan
;
7180 struct cfg80211_assoc_request req
= {};
7181 const u8
*bssid
, *ssid
;
7182 int err
, ssid_len
= 0;
7184 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7187 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
7188 !info
->attrs
[NL80211_ATTR_SSID
] ||
7189 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7192 if (!rdev
->ops
->assoc
)
7195 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7196 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7199 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7201 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7202 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7206 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7207 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7209 if (info
->attrs
[NL80211_ATTR_IE
]) {
7210 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7211 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7214 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7215 enum nl80211_mfp mfp
=
7216 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7217 if (mfp
== NL80211_MFP_REQUIRED
)
7219 else if (mfp
!= NL80211_MFP_NO
)
7223 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
7224 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
7226 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7227 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
7229 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7230 memcpy(&req
.ht_capa_mask
,
7231 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7232 sizeof(req
.ht_capa_mask
));
7234 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7235 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7237 memcpy(&req
.ht_capa
,
7238 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7239 sizeof(req
.ht_capa
));
7242 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7243 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7245 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7246 memcpy(&req
.vht_capa_mask
,
7247 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7248 sizeof(req
.vht_capa_mask
));
7250 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7251 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7253 memcpy(&req
.vht_capa
,
7254 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7255 sizeof(req
.vht_capa
));
7258 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7259 if (!(rdev
->wiphy
.features
&
7260 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) ||
7261 !(rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
))
7263 req
.flags
|= ASSOC_REQ_USE_RRM
;
7266 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
7268 wdev_lock(dev
->ieee80211_ptr
);
7269 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
7270 ssid
, ssid_len
, &req
);
7271 wdev_unlock(dev
->ieee80211_ptr
);
7277 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
7279 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7280 struct net_device
*dev
= info
->user_ptr
[1];
7281 const u8
*ie
= NULL
, *bssid
;
7282 int ie_len
= 0, err
;
7284 bool local_state_change
;
7286 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7289 if (!info
->attrs
[NL80211_ATTR_MAC
])
7292 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7295 if (!rdev
->ops
->deauth
)
7298 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7299 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7302 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7304 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7305 if (reason_code
== 0) {
7306 /* Reason Code 0 is reserved */
7310 if (info
->attrs
[NL80211_ATTR_IE
]) {
7311 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7312 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7315 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7317 wdev_lock(dev
->ieee80211_ptr
);
7318 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7319 local_state_change
);
7320 wdev_unlock(dev
->ieee80211_ptr
);
7324 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
7326 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7327 struct net_device
*dev
= info
->user_ptr
[1];
7328 const u8
*ie
= NULL
, *bssid
;
7329 int ie_len
= 0, err
;
7331 bool local_state_change
;
7333 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7336 if (!info
->attrs
[NL80211_ATTR_MAC
])
7339 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7342 if (!rdev
->ops
->disassoc
)
7345 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7346 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7349 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7351 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7352 if (reason_code
== 0) {
7353 /* Reason Code 0 is reserved */
7357 if (info
->attrs
[NL80211_ATTR_IE
]) {
7358 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7359 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7362 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7364 wdev_lock(dev
->ieee80211_ptr
);
7365 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7366 local_state_change
);
7367 wdev_unlock(dev
->ieee80211_ptr
);
7372 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
7373 int mcast_rate
[IEEE80211_NUM_BANDS
],
7376 struct wiphy
*wiphy
= &rdev
->wiphy
;
7380 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
7381 struct ieee80211_supported_band
*sband
;
7383 sband
= wiphy
->bands
[band
];
7387 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
7388 if (sband
->bitrates
[i
].bitrate
== rateval
) {
7389 mcast_rate
[band
] = i
+ 1;
7399 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7401 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7402 struct net_device
*dev
= info
->user_ptr
[1];
7403 struct cfg80211_ibss_params ibss
;
7404 struct wiphy
*wiphy
;
7405 struct cfg80211_cached_keys
*connkeys
= NULL
;
7408 memset(&ibss
, 0, sizeof(ibss
));
7410 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7413 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7414 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7417 ibss
.beacon_interval
= 100;
7419 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7420 ibss
.beacon_interval
=
7421 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7422 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
7426 if (!rdev
->ops
->join_ibss
)
7429 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7432 wiphy
= &rdev
->wiphy
;
7434 if (info
->attrs
[NL80211_ATTR_MAC
]) {
7435 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7437 if (!is_valid_ether_addr(ibss
.bssid
))
7440 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7441 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7443 if (info
->attrs
[NL80211_ATTR_IE
]) {
7444 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7445 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7448 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
7452 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
7453 NL80211_IFTYPE_ADHOC
))
7456 switch (ibss
.chandef
.width
) {
7457 case NL80211_CHAN_WIDTH_5
:
7458 case NL80211_CHAN_WIDTH_10
:
7459 case NL80211_CHAN_WIDTH_20_NOHT
:
7461 case NL80211_CHAN_WIDTH_20
:
7462 case NL80211_CHAN_WIDTH_40
:
7463 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7466 case NL80211_CHAN_WIDTH_80
:
7467 case NL80211_CHAN_WIDTH_80P80
:
7468 case NL80211_CHAN_WIDTH_160
:
7469 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7471 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
7472 NL80211_EXT_FEATURE_VHT_IBSS
))
7479 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
7480 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
7482 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7484 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7486 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7487 struct ieee80211_supported_band
*sband
=
7488 wiphy
->bands
[ibss
.chandef
.chan
->band
];
7490 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7496 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7497 memcpy(&ibss
.ht_capa_mask
,
7498 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7499 sizeof(ibss
.ht_capa_mask
));
7501 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7502 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7504 memcpy(&ibss
.ht_capa
,
7505 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7506 sizeof(ibss
.ht_capa
));
7509 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7510 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
7511 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7514 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7517 connkeys
= nl80211_parse_connkeys(rdev
,
7518 info
->attrs
[NL80211_ATTR_KEYS
],
7520 if (IS_ERR(connkeys
))
7521 return PTR_ERR(connkeys
);
7523 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
7531 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
7533 ibss
.userspace_handles_dfs
=
7534 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
7536 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
7542 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7544 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7545 struct net_device
*dev
= info
->user_ptr
[1];
7547 if (!rdev
->ops
->leave_ibss
)
7550 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7553 return cfg80211_leave_ibss(rdev
, dev
, false);
7556 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
7558 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7559 struct net_device
*dev
= info
->user_ptr
[1];
7560 int mcast_rate
[IEEE80211_NUM_BANDS
];
7564 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
7565 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
7566 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
7569 if (!rdev
->ops
->set_mcast_rate
)
7572 memset(mcast_rate
, 0, sizeof(mcast_rate
));
7574 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
7577 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
7578 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
7581 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
7586 static struct sk_buff
*
7587 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
7588 struct wireless_dev
*wdev
, int approxlen
,
7589 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
7590 enum nl80211_attrs attr
,
7591 const struct nl80211_vendor_cmd_info
*info
,
7594 struct sk_buff
*skb
;
7596 struct nlattr
*data
;
7598 skb
= nlmsg_new(approxlen
+ 100, gfp
);
7602 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
7608 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
7609 goto nla_put_failure
;
7612 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
7614 goto nla_put_failure
;
7615 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
7617 goto nla_put_failure
;
7621 if (nla_put_u64(skb
, NL80211_ATTR_WDEV
,
7623 goto nla_put_failure
;
7625 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
7626 wdev
->netdev
->ifindex
))
7627 goto nla_put_failure
;
7630 data
= nla_nest_start(skb
, attr
);
7632 ((void **)skb
->cb
)[0] = rdev
;
7633 ((void **)skb
->cb
)[1] = hdr
;
7634 ((void **)skb
->cb
)[2] = data
;
7643 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
7644 struct wireless_dev
*wdev
,
7645 enum nl80211_commands cmd
,
7646 enum nl80211_attrs attr
,
7647 int vendor_event_idx
,
7648 int approxlen
, gfp_t gfp
)
7650 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
7651 const struct nl80211_vendor_cmd_info
*info
;
7654 case NL80211_CMD_TESTMODE
:
7655 if (WARN_ON(vendor_event_idx
!= -1))
7659 case NL80211_CMD_VENDOR
:
7660 if (WARN_ON(vendor_event_idx
< 0 ||
7661 vendor_event_idx
>= wiphy
->n_vendor_events
))
7663 info
= &wiphy
->vendor_events
[vendor_event_idx
];
7670 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
7671 cmd
, attr
, info
, gfp
);
7673 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
7675 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
7677 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
7678 void *hdr
= ((void **)skb
->cb
)[1];
7679 struct nlattr
*data
= ((void **)skb
->cb
)[2];
7680 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
7682 /* clear CB data for netlink core to own from now on */
7683 memset(skb
->cb
, 0, sizeof(skb
->cb
));
7685 nla_nest_end(skb
, data
);
7686 genlmsg_end(skb
, hdr
);
7688 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
7689 mcgrp
= NL80211_MCGRP_VENDOR
;
7691 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
7694 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
7696 #ifdef CONFIG_NL80211_TESTMODE
7697 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
7699 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7700 struct wireless_dev
*wdev
=
7701 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
7704 if (!rdev
->ops
->testmode_cmd
)
7708 err
= PTR_ERR(wdev
);
7712 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
7716 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
7719 rdev
->cur_cmd_info
= info
;
7720 err
= rdev_testmode_cmd(rdev
, wdev
,
7721 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
7722 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
7723 rdev
->cur_cmd_info
= NULL
;
7728 static int nl80211_testmode_dump(struct sk_buff
*skb
,
7729 struct netlink_callback
*cb
)
7731 struct cfg80211_registered_device
*rdev
;
7741 * 0 is a valid index, but not valid for args[0],
7742 * so we need to offset by 1.
7744 phy_idx
= cb
->args
[0] - 1;
7746 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
7747 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
7752 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
7753 nl80211_fam
.attrbuf
);
7755 err
= PTR_ERR(rdev
);
7758 phy_idx
= rdev
->wiphy_idx
;
7761 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
7763 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
7767 data
= nla_data((void *)cb
->args
[1]);
7768 data_len
= nla_len((void *)cb
->args
[1]);
7771 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
7777 if (!rdev
->ops
->testmode_dump
) {
7783 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
7784 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7785 NL80211_CMD_TESTMODE
);
7786 struct nlattr
*tmdata
;
7791 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
7792 genlmsg_cancel(skb
, hdr
);
7796 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
7798 genlmsg_cancel(skb
, hdr
);
7801 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
7802 nla_nest_end(skb
, tmdata
);
7804 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
7805 genlmsg_cancel(skb
, hdr
);
7808 genlmsg_cancel(skb
, hdr
);
7812 genlmsg_end(skb
, hdr
);
7817 cb
->args
[0] = phy_idx
+ 1;
7824 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
7826 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7827 struct net_device
*dev
= info
->user_ptr
[1];
7828 struct cfg80211_connect_params connect
;
7829 struct wiphy
*wiphy
;
7830 struct cfg80211_cached_keys
*connkeys
= NULL
;
7833 memset(&connect
, 0, sizeof(connect
));
7835 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7838 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7839 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7842 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
7844 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7845 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
7846 NL80211_CMD_CONNECT
))
7849 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
7851 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
7853 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
7854 NL80211_MAX_NR_CIPHER_SUITES
);
7858 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7859 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7862 wiphy
= &rdev
->wiphy
;
7864 connect
.bg_scan_period
= -1;
7865 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
7866 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
7867 connect
.bg_scan_period
=
7868 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
7871 if (info
->attrs
[NL80211_ATTR_MAC
])
7872 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7873 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
7874 connect
.bssid_hint
=
7875 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
7876 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7877 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7879 if (info
->attrs
[NL80211_ATTR_IE
]) {
7880 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7881 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7884 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7885 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7886 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
7887 connect
.mfp
!= NL80211_MFP_NO
)
7890 connect
.mfp
= NL80211_MFP_NO
;
7893 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7894 connect
.channel
= nl80211_get_valid_chan(
7895 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7896 if (!connect
.channel
)
7898 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
7899 connect
.channel_hint
= nl80211_get_valid_chan(
7900 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
7901 if (!connect
.channel_hint
)
7905 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7906 connkeys
= nl80211_parse_connkeys(rdev
,
7907 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
7908 if (IS_ERR(connkeys
))
7909 return PTR_ERR(connkeys
);
7912 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7913 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
7915 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7916 memcpy(&connect
.ht_capa_mask
,
7917 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7918 sizeof(connect
.ht_capa_mask
));
7920 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7921 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
7925 memcpy(&connect
.ht_capa
,
7926 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7927 sizeof(connect
.ht_capa
));
7930 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7931 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7933 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7934 memcpy(&connect
.vht_capa_mask
,
7935 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7936 sizeof(connect
.vht_capa_mask
));
7938 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7939 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
7943 memcpy(&connect
.vht_capa
,
7944 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7945 sizeof(connect
.vht_capa
));
7948 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7949 if (!(rdev
->wiphy
.features
&
7950 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) ||
7951 !(rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) {
7955 connect
.flags
|= ASSOC_REQ_USE_RRM
;
7958 wdev_lock(dev
->ieee80211_ptr
);
7959 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
7960 wdev_unlock(dev
->ieee80211_ptr
);
7966 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
7968 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7969 struct net_device
*dev
= info
->user_ptr
[1];
7973 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7974 reason
= WLAN_REASON_DEAUTH_LEAVING
;
7976 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7981 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7982 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7985 wdev_lock(dev
->ieee80211_ptr
);
7986 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
7987 wdev_unlock(dev
->ieee80211_ptr
);
7991 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
7993 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7997 if (info
->attrs
[NL80211_ATTR_PID
]) {
7998 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
8000 net
= get_net_ns_by_pid(pid
);
8001 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
8002 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
8004 net
= get_net_ns_by_fd(fd
);
8010 return PTR_ERR(net
);
8014 /* check if anything to do */
8015 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
8016 err
= cfg80211_switch_netns(rdev
, net
);
8022 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8024 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8025 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
8026 struct cfg80211_pmksa
*pmksa
) = NULL
;
8027 struct net_device
*dev
= info
->user_ptr
[1];
8028 struct cfg80211_pmksa pmksa
;
8030 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
8032 if (!info
->attrs
[NL80211_ATTR_MAC
])
8035 if (!info
->attrs
[NL80211_ATTR_PMKID
])
8038 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
8039 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8041 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8042 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8045 switch (info
->genlhdr
->cmd
) {
8046 case NL80211_CMD_SET_PMKSA
:
8047 rdev_ops
= rdev
->ops
->set_pmksa
;
8049 case NL80211_CMD_DEL_PMKSA
:
8050 rdev_ops
= rdev
->ops
->del_pmksa
;
8060 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
8063 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8065 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8066 struct net_device
*dev
= info
->user_ptr
[1];
8068 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8069 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8072 if (!rdev
->ops
->flush_pmksa
)
8075 return rdev_flush_pmksa(rdev
, dev
);
8078 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8080 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8081 struct net_device
*dev
= info
->user_ptr
[1];
8082 u8 action_code
, dialog_token
;
8083 u32 peer_capability
= 0;
8088 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8089 !rdev
->ops
->tdls_mgmt
)
8092 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
8093 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
8094 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
8095 !info
->attrs
[NL80211_ATTR_IE
] ||
8096 !info
->attrs
[NL80211_ATTR_MAC
])
8099 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8100 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
8101 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
8102 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
8103 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
8104 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
8106 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
8108 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
8109 dialog_token
, status_code
, peer_capability
,
8111 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
8112 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
8115 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
8117 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8118 struct net_device
*dev
= info
->user_ptr
[1];
8119 enum nl80211_tdls_operation operation
;
8122 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8123 !rdev
->ops
->tdls_oper
)
8126 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
8127 !info
->attrs
[NL80211_ATTR_MAC
])
8130 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
8131 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8133 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
8136 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
8137 struct genl_info
*info
)
8139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8140 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8141 struct cfg80211_chan_def chandef
;
8142 struct sk_buff
*msg
;
8148 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
8149 !info
->attrs
[NL80211_ATTR_DURATION
])
8152 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8154 if (!rdev
->ops
->remain_on_channel
||
8155 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
8159 * We should be on that channel for at least a minimum amount of
8160 * time (10ms) but no longer than the driver supports.
8162 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8163 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
8166 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8170 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8174 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8175 NL80211_CMD_REMAIN_ON_CHANNEL
);
8181 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
8187 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8188 goto nla_put_failure
;
8190 genlmsg_end(msg
, hdr
);
8192 return genlmsg_reply(msg
, info
);
8201 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
8202 struct genl_info
*info
)
8204 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8205 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8208 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8211 if (!rdev
->ops
->cancel_remain_on_channel
)
8214 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8216 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
8219 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
8220 u8
*rates
, u8 rates_len
)
8225 for (i
= 0; i
< rates_len
; i
++) {
8226 int rate
= (rates
[i
] & 0x7f) * 5;
8228 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
8229 struct ieee80211_rate
*srate
=
8230 &sband
->bitrates
[ridx
];
8231 if (rate
== srate
->bitrate
) {
8236 if (ridx
== sband
->n_bitrates
)
8237 return 0; /* rate not found */
8243 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
8244 u8
*rates
, u8 rates_len
,
8245 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
8249 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
8251 for (i
= 0; i
< rates_len
; i
++) {
8254 ridx
= rates
[i
] / 8;
8255 rbit
= BIT(rates
[i
] % 8);
8257 /* check validity */
8258 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
8261 /* check availability */
8262 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
8271 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
8275 switch (vht_mcs_map
) {
8276 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
8278 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
8281 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
8284 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
8294 static void vht_build_mcs_mask(u16 vht_mcs_map
,
8295 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
8299 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
8300 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
8305 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
8306 struct nl80211_txrate_vht
*txrate
,
8307 u16 mcs
[NL80211_VHT_NSS_MAX
])
8309 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8310 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
8313 if (!sband
->vht_cap
.vht_supported
)
8316 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
8318 /* Build vht_mcs_mask from VHT capabilities */
8319 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
8321 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
8322 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
8323 mcs
[i
] = txrate
->mcs
[i
];
8331 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
8332 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
8333 .len
= NL80211_MAX_SUPP_RATES
},
8334 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
8335 .len
= NL80211_MAX_SUPP_HT_RATES
},
8336 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
8337 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
8340 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
8341 struct genl_info
*info
)
8343 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
8344 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8345 struct cfg80211_bitrate_mask mask
;
8347 struct net_device
*dev
= info
->user_ptr
[1];
8348 struct nlattr
*tx_rates
;
8349 struct ieee80211_supported_band
*sband
;
8352 if (!rdev
->ops
->set_bitrate_mask
)
8355 memset(&mask
, 0, sizeof(mask
));
8356 /* Default to all rates enabled */
8357 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
8358 sband
= rdev
->wiphy
.bands
[i
];
8363 mask
.control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
8364 memcpy(mask
.control
[i
].ht_mcs
,
8365 sband
->ht_cap
.mcs
.rx_mask
,
8366 sizeof(mask
.control
[i
].ht_mcs
));
8368 if (!sband
->vht_cap
.vht_supported
)
8371 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8372 vht_build_mcs_mask(vht_tx_mcs_map
, mask
.control
[i
].vht_mcs
);
8375 /* if no rates are given set it back to the defaults */
8376 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
8380 * The nested attribute uses enum nl80211_band as the index. This maps
8381 * directly to the enum ieee80211_band values used in cfg80211.
8383 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
8384 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
8385 enum ieee80211_band band
= nla_type(tx_rates
);
8388 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
8390 sband
= rdev
->wiphy
.bands
[band
];
8393 err
= nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
8394 nla_len(tx_rates
), nl80211_txattr_policy
);
8397 if (tb
[NL80211_TXRATE_LEGACY
]) {
8398 mask
.control
[band
].legacy
= rateset_to_mask(
8400 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
8401 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
8402 if ((mask
.control
[band
].legacy
== 0) &&
8403 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
8406 if (tb
[NL80211_TXRATE_HT
]) {
8407 if (!ht_rateset_to_mask(
8409 nla_data(tb
[NL80211_TXRATE_HT
]),
8410 nla_len(tb
[NL80211_TXRATE_HT
]),
8411 mask
.control
[band
].ht_mcs
))
8414 if (tb
[NL80211_TXRATE_VHT
]) {
8415 if (!vht_set_mcs_mask(
8417 nla_data(tb
[NL80211_TXRATE_VHT
]),
8418 mask
.control
[band
].vht_mcs
))
8421 if (tb
[NL80211_TXRATE_GI
]) {
8422 mask
.control
[band
].gi
=
8423 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
8424 if (mask
.control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
8428 if (mask
.control
[band
].legacy
== 0) {
8429 /* don't allow empty legacy rates if HT or VHT
8430 * are not even supported.
8432 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
8433 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
8436 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
8437 if (mask
.control
[band
].ht_mcs
[i
])
8440 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
8441 if (mask
.control
[band
].vht_mcs
[i
])
8444 /* legacy and mcs rates may not be both empty */
8450 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
8453 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8455 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8456 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8457 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
8459 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
8462 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
8463 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
8465 switch (wdev
->iftype
) {
8466 case NL80211_IFTYPE_STATION
:
8467 case NL80211_IFTYPE_ADHOC
:
8468 case NL80211_IFTYPE_P2P_CLIENT
:
8469 case NL80211_IFTYPE_AP
:
8470 case NL80211_IFTYPE_AP_VLAN
:
8471 case NL80211_IFTYPE_MESH_POINT
:
8472 case NL80211_IFTYPE_P2P_GO
:
8473 case NL80211_IFTYPE_P2P_DEVICE
:
8479 /* not much point in registering if we can't reply */
8480 if (!rdev
->ops
->mgmt_tx
)
8483 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
8484 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
8485 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
8488 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8490 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8491 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8492 struct cfg80211_chan_def chandef
;
8496 struct sk_buff
*msg
= NULL
;
8497 struct cfg80211_mgmt_tx_params params
= {
8498 .dont_wait_for_ack
=
8499 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
8502 if (!info
->attrs
[NL80211_ATTR_FRAME
])
8505 if (!rdev
->ops
->mgmt_tx
)
8508 switch (wdev
->iftype
) {
8509 case NL80211_IFTYPE_P2P_DEVICE
:
8510 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8512 case NL80211_IFTYPE_STATION
:
8513 case NL80211_IFTYPE_ADHOC
:
8514 case NL80211_IFTYPE_P2P_CLIENT
:
8515 case NL80211_IFTYPE_AP
:
8516 case NL80211_IFTYPE_AP_VLAN
:
8517 case NL80211_IFTYPE_MESH_POINT
:
8518 case NL80211_IFTYPE_P2P_GO
:
8524 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
8525 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8527 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8530 * We should wait on the channel for at least a minimum amount
8531 * of time (10ms) but no longer than the driver supports.
8533 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8534 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
8539 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
8541 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8544 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
8546 /* get the channel if any has been specified, otherwise pass NULL to
8547 * the driver. The latter will use the current one
8549 chandef
.chan
= NULL
;
8550 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8551 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8556 if (!chandef
.chan
&& params
.offchan
)
8559 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
8560 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
8562 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
8563 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8566 if (len
% sizeof(u16
))
8569 params
.n_csa_offsets
= len
/ sizeof(u16
);
8570 params
.csa_offsets
=
8571 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8573 /* check that all the offsets fit the frame */
8574 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
8575 if (params
.csa_offsets
[i
] >= params
.len
)
8580 if (!params
.dont_wait_for_ack
) {
8581 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8585 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8593 params
.chan
= chandef
.chan
;
8594 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
8599 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8600 goto nla_put_failure
;
8602 genlmsg_end(msg
, hdr
);
8603 return genlmsg_reply(msg
, info
);
8615 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
8617 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8618 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8621 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8624 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
8627 switch (wdev
->iftype
) {
8628 case NL80211_IFTYPE_STATION
:
8629 case NL80211_IFTYPE_ADHOC
:
8630 case NL80211_IFTYPE_P2P_CLIENT
:
8631 case NL80211_IFTYPE_AP
:
8632 case NL80211_IFTYPE_AP_VLAN
:
8633 case NL80211_IFTYPE_P2P_GO
:
8634 case NL80211_IFTYPE_P2P_DEVICE
:
8640 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8642 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
8645 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
8647 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8648 struct wireless_dev
*wdev
;
8649 struct net_device
*dev
= info
->user_ptr
[1];
8654 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
8657 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
8659 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
8662 wdev
= dev
->ieee80211_ptr
;
8664 if (!rdev
->ops
->set_power_mgmt
)
8667 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
8669 if (state
== wdev
->ps
)
8672 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
8678 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
8680 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8681 enum nl80211_ps_state ps_state
;
8682 struct wireless_dev
*wdev
;
8683 struct net_device
*dev
= info
->user_ptr
[1];
8684 struct sk_buff
*msg
;
8688 wdev
= dev
->ieee80211_ptr
;
8690 if (!rdev
->ops
->set_power_mgmt
)
8693 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8697 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8698 NL80211_CMD_GET_POWER_SAVE
);
8705 ps_state
= NL80211_PS_ENABLED
;
8707 ps_state
= NL80211_PS_DISABLED
;
8709 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
8710 goto nla_put_failure
;
8712 genlmsg_end(msg
, hdr
);
8713 return genlmsg_reply(msg
, info
);
8722 static const struct nla_policy
8723 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
8724 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
8725 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
8726 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
8727 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
8728 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
8729 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
8732 static int nl80211_set_cqm_txe(struct genl_info
*info
,
8733 u32 rate
, u32 pkts
, u32 intvl
)
8735 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8736 struct net_device
*dev
= info
->user_ptr
[1];
8737 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8739 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
8742 if (!rdev
->ops
->set_cqm_txe_config
)
8745 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8746 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8749 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
8752 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
8753 s32 threshold
, u32 hysteresis
)
8755 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8756 struct net_device
*dev
= info
->user_ptr
[1];
8757 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8762 /* disabling - hysteresis should also be zero then */
8766 if (!rdev
->ops
->set_cqm_rssi_config
)
8769 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8770 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8773 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
8776 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
8778 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
8782 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
8786 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
8787 nl80211_attr_cqm_policy
);
8791 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
8792 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
8793 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
8794 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
8796 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
8799 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
8800 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
8801 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
8802 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
8803 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
8804 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
8806 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
8812 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
8814 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8815 struct net_device
*dev
= info
->user_ptr
[1];
8816 struct ocb_setup setup
= {};
8819 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8823 return cfg80211_join_ocb(rdev
, dev
, &setup
);
8826 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
8828 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8829 struct net_device
*dev
= info
->user_ptr
[1];
8831 return cfg80211_leave_ocb(rdev
, dev
);
8834 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8836 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8837 struct net_device
*dev
= info
->user_ptr
[1];
8838 struct mesh_config cfg
;
8839 struct mesh_setup setup
;
8842 /* start with default */
8843 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
8844 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
8846 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
8847 /* and parse parameters if given */
8848 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
8853 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
8854 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
8857 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8858 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8860 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8861 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
8862 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8865 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
8866 setup
.beacon_interval
=
8867 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8868 if (setup
.beacon_interval
< 10 ||
8869 setup
.beacon_interval
> 10000)
8873 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
8875 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
8876 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
8880 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
8881 /* parse additional setup parameters if given */
8882 err
= nl80211_parse_mesh_setup(info
, &setup
);
8888 cfg
.auto_open_plinks
= false;
8890 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8891 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8895 /* cfg80211_join_mesh() will sort it out */
8896 setup
.chandef
.chan
= NULL
;
8899 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8900 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8902 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8903 struct ieee80211_supported_band
*sband
;
8905 if (!setup
.chandef
.chan
)
8908 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
8910 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8911 &setup
.basic_rates
);
8916 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
8919 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8921 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8922 struct net_device
*dev
= info
->user_ptr
[1];
8924 return cfg80211_leave_mesh(rdev
, dev
);
8928 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
8929 struct cfg80211_registered_device
*rdev
)
8931 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
8932 struct nlattr
*nl_pats
, *nl_pat
;
8935 if (!wowlan
->n_patterns
)
8938 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
8942 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
8943 nl_pat
= nla_nest_start(msg
, i
+ 1);
8946 pat_len
= wowlan
->patterns
[i
].pattern_len
;
8947 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
8948 wowlan
->patterns
[i
].mask
) ||
8949 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8950 wowlan
->patterns
[i
].pattern
) ||
8951 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8952 wowlan
->patterns
[i
].pkt_offset
))
8954 nla_nest_end(msg
, nl_pat
);
8956 nla_nest_end(msg
, nl_pats
);
8961 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
8962 struct cfg80211_wowlan_tcp
*tcp
)
8964 struct nlattr
*nl_tcp
;
8969 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
8973 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
8974 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
8975 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
8976 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
8977 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
8978 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
8979 tcp
->payload_len
, tcp
->payload
) ||
8980 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
8981 tcp
->data_interval
) ||
8982 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
8983 tcp
->wake_len
, tcp
->wake_data
) ||
8984 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
8985 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
8988 if (tcp
->payload_seq
.len
&&
8989 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
8990 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
8993 if (tcp
->payload_tok
.len
&&
8994 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
8995 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
8999 nla_nest_end(msg
, nl_tcp
);
9004 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
9005 struct cfg80211_sched_scan_request
*req
)
9007 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
9013 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
9017 if (req
->n_scan_plans
== 1 &&
9018 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
9019 req
->scan_plans
[0].interval
* 1000))
9022 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
9025 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9029 for (i
= 0; i
< req
->n_channels
; i
++)
9030 nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
);
9032 nla_nest_end(msg
, freqs
);
9034 if (req
->n_match_sets
) {
9035 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
9036 for (i
= 0; i
< req
->n_match_sets
; i
++) {
9037 match
= nla_nest_start(msg
, i
);
9038 nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
9039 req
->match_sets
[i
].ssid
.ssid_len
,
9040 req
->match_sets
[i
].ssid
.ssid
);
9041 nla_nest_end(msg
, match
);
9043 nla_nest_end(msg
, matches
);
9046 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
9050 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
9051 scan_plan
= nla_nest_start(msg
, i
+ 1);
9053 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
9054 req
->scan_plans
[i
].interval
) ||
9055 (req
->scan_plans
[i
].iterations
&&
9056 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
9057 req
->scan_plans
[i
].iterations
)))
9059 nla_nest_end(msg
, scan_plan
);
9061 nla_nest_end(msg
, scan_plans
);
9063 nla_nest_end(msg
, nd
);
9068 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9070 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9071 struct sk_buff
*msg
;
9073 u32 size
= NLMSG_DEFAULT_SIZE
;
9075 if (!rdev
->wiphy
.wowlan
)
9078 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
9079 /* adjust size to have room for all the data */
9080 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
9081 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
9082 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
9083 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
9086 msg
= nlmsg_new(size
, GFP_KERNEL
);
9090 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9091 NL80211_CMD_GET_WOWLAN
);
9093 goto nla_put_failure
;
9095 if (rdev
->wiphy
.wowlan_config
) {
9096 struct nlattr
*nl_wowlan
;
9098 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
9100 goto nla_put_failure
;
9102 if ((rdev
->wiphy
.wowlan_config
->any
&&
9103 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
9104 (rdev
->wiphy
.wowlan_config
->disconnect
&&
9105 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
9106 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
9107 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
9108 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
9109 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
9110 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
9111 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
9112 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
9113 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
9114 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
9115 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
9116 goto nla_put_failure
;
9118 if (nl80211_send_wowlan_patterns(msg
, rdev
))
9119 goto nla_put_failure
;
9121 if (nl80211_send_wowlan_tcp(msg
,
9122 rdev
->wiphy
.wowlan_config
->tcp
))
9123 goto nla_put_failure
;
9125 if (nl80211_send_wowlan_nd(
9127 rdev
->wiphy
.wowlan_config
->nd_config
))
9128 goto nla_put_failure
;
9130 nla_nest_end(msg
, nl_wowlan
);
9133 genlmsg_end(msg
, hdr
);
9134 return genlmsg_reply(msg
, info
);
9141 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
9142 struct nlattr
*attr
,
9143 struct cfg80211_wowlan
*trig
)
9145 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
9146 struct cfg80211_wowlan_tcp
*cfg
;
9147 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
9148 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
9150 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
9153 if (!rdev
->wiphy
.wowlan
->tcp
)
9156 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
9157 nla_data(attr
), nla_len(attr
),
9158 nl80211_wowlan_tcp_policy
);
9162 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
9163 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
9164 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
9165 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
9166 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
9167 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
9168 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
9169 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
9172 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
9173 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
9176 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
9177 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
9178 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
9181 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
9182 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
9185 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
9186 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
9189 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
9190 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9192 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9193 tokens_size
= tokln
- sizeof(*tok
);
9195 if (!tok
->len
|| tokens_size
% tok
->len
)
9197 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
9199 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
9201 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
9203 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
9205 if (tok
->offset
+ tok
->len
> data_size
)
9209 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
9210 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
9211 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
9213 if (seq
->len
== 0 || seq
->len
> 4)
9215 if (seq
->len
+ seq
->offset
> data_size
)
9219 size
= sizeof(*cfg
);
9221 size
+= wake_size
+ wake_mask_size
;
9222 size
+= tokens_size
;
9224 cfg
= kzalloc(size
, GFP_KERNEL
);
9227 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
9228 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
9229 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
9231 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
9232 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
9236 /* allocate a socket and port for it and use it */
9237 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
9238 IPPROTO_TCP
, &cfg
->sock
, 1);
9243 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
9244 sock_release(cfg
->sock
);
9248 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
9254 cfg
->src_port
= port
;
9257 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
9258 cfg
->payload_len
= data_size
;
9259 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
9260 memcpy((void *)cfg
->payload
,
9261 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
9264 cfg
->payload_seq
= *seq
;
9265 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
9266 cfg
->wake_len
= wake_size
;
9267 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
9268 memcpy((void *)cfg
->wake_data
,
9269 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
9271 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
9272 data_size
+ wake_size
;
9273 memcpy((void *)cfg
->wake_mask
,
9274 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
9277 cfg
->tokens_size
= tokens_size
;
9278 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
9286 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
9287 const struct wiphy_wowlan_support
*wowlan
,
9288 struct nlattr
*attr
,
9289 struct cfg80211_wowlan
*trig
)
9294 tb
= kzalloc(NUM_NL80211_ATTR
* sizeof(*tb
), GFP_KERNEL
);
9298 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
9303 err
= nla_parse(tb
, NL80211_ATTR_MAX
,
9304 nla_data(attr
), nla_len(attr
),
9309 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
);
9310 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
9312 trig
->nd_config
= NULL
;
9319 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9321 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9322 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
9323 struct cfg80211_wowlan new_triggers
= {};
9324 struct cfg80211_wowlan
*ntrig
;
9325 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
9327 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
9328 bool regular
= false;
9333 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
9334 cfg80211_rdev_free_wowlan(rdev
);
9335 rdev
->wiphy
.wowlan_config
= NULL
;
9339 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
9340 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9341 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9342 nl80211_wowlan_policy
);
9346 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
9347 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
9349 new_triggers
.any
= true;
9352 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
9353 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
9355 new_triggers
.disconnect
= true;
9359 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
9360 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
9362 new_triggers
.magic_pkt
= true;
9366 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
9369 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
9370 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
9372 new_triggers
.gtk_rekey_failure
= true;
9376 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
9377 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
9379 new_triggers
.eap_identity_req
= true;
9383 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
9384 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
9386 new_triggers
.four_way_handshake
= true;
9390 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
9391 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
9393 new_triggers
.rfkill_release
= true;
9397 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
9400 int rem
, pat_len
, mask_len
, pkt_offset
;
9401 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9405 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9408 if (n_patterns
> wowlan
->n_patterns
)
9411 new_triggers
.patterns
= kcalloc(n_patterns
,
9412 sizeof(new_triggers
.patterns
[0]),
9414 if (!new_triggers
.patterns
)
9417 new_triggers
.n_patterns
= n_patterns
;
9420 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9424 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
9425 nla_len(pat
), nl80211_packet_pattern_policy
);
9427 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
9428 !pat_tb
[NL80211_PKTPAT_PATTERN
])
9430 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
9431 mask_len
= DIV_ROUND_UP(pat_len
, 8);
9432 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
9434 if (pat_len
> wowlan
->pattern_max_len
||
9435 pat_len
< wowlan
->pattern_min_len
)
9438 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
9441 pkt_offset
= nla_get_u32(
9442 pat_tb
[NL80211_PKTPAT_OFFSET
]);
9443 if (pkt_offset
> wowlan
->max_pkt_offset
)
9445 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
9447 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
9452 new_triggers
.patterns
[i
].mask
= mask_pat
;
9453 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
9455 mask_pat
+= mask_len
;
9456 new_triggers
.patterns
[i
].pattern
= mask_pat
;
9457 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
9459 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
9465 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
9467 err
= nl80211_parse_wowlan_tcp(
9468 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
9474 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
9476 err
= nl80211_parse_wowlan_nd(
9477 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
9483 /* The 'any' trigger means the device continues operating more or less
9484 * as in its normal operation mode and wakes up the host on most of the
9485 * normal interrupts (like packet RX, ...)
9486 * It therefore makes little sense to combine with the more constrained
9487 * wakeup trigger modes.
9489 if (new_triggers
.any
&& regular
) {
9494 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
9499 cfg80211_rdev_free_wowlan(rdev
);
9500 rdev
->wiphy
.wowlan_config
= ntrig
;
9503 if (rdev
->ops
->set_wakeup
&&
9504 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
9505 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
9509 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
9510 kfree(new_triggers
.patterns
[i
].mask
);
9511 kfree(new_triggers
.patterns
);
9512 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
9513 sock_release(new_triggers
.tcp
->sock
);
9514 kfree(new_triggers
.tcp
);
9515 kfree(new_triggers
.nd_config
);
9520 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
9521 struct cfg80211_registered_device
*rdev
)
9523 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
9525 struct cfg80211_coalesce_rules
*rule
;
9527 if (!rdev
->coalesce
->n_rules
)
9530 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
9534 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
9535 nl_rule
= nla_nest_start(msg
, i
+ 1);
9539 rule
= &rdev
->coalesce
->rules
[i
];
9540 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
9544 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
9548 nl_pats
= nla_nest_start(msg
,
9549 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
9553 for (j
= 0; j
< rule
->n_patterns
; j
++) {
9554 nl_pat
= nla_nest_start(msg
, j
+ 1);
9557 pat_len
= rule
->patterns
[j
].pattern_len
;
9558 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
9559 DIV_ROUND_UP(pat_len
, 8),
9560 rule
->patterns
[j
].mask
) ||
9561 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
9562 rule
->patterns
[j
].pattern
) ||
9563 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
9564 rule
->patterns
[j
].pkt_offset
))
9566 nla_nest_end(msg
, nl_pat
);
9568 nla_nest_end(msg
, nl_pats
);
9569 nla_nest_end(msg
, nl_rule
);
9571 nla_nest_end(msg
, nl_rules
);
9576 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
9578 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9579 struct sk_buff
*msg
;
9582 if (!rdev
->wiphy
.coalesce
)
9585 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9589 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9590 NL80211_CMD_GET_COALESCE
);
9592 goto nla_put_failure
;
9594 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
9595 goto nla_put_failure
;
9597 genlmsg_end(msg
, hdr
);
9598 return genlmsg_reply(msg
, info
);
9605 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
9607 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
9609 struct cfg80211_coalesce_rules
*rule
;
9614 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
9615 rule
= &coalesce
->rules
[i
];
9616 for (j
= 0; j
< rule
->n_patterns
; j
++)
9617 kfree(rule
->patterns
[j
].mask
);
9618 kfree(rule
->patterns
);
9620 kfree(coalesce
->rules
);
9622 rdev
->coalesce
= NULL
;
9625 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
9626 struct nlattr
*rule
,
9627 struct cfg80211_coalesce_rules
*new_rule
)
9630 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
9631 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
9632 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
9633 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9635 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
9636 nla_len(rule
), nl80211_coalesce_policy
);
9640 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
9642 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
9643 if (new_rule
->delay
> coalesce
->max_delay
)
9646 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
9647 new_rule
->condition
=
9648 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
9649 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
9650 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
9653 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
9656 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
9659 if (n_patterns
> coalesce
->n_patterns
)
9662 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
9664 if (!new_rule
->patterns
)
9667 new_rule
->n_patterns
= n_patterns
;
9670 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
9674 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
9675 nla_len(pat
), nl80211_packet_pattern_policy
);
9676 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
9677 !pat_tb
[NL80211_PKTPAT_PATTERN
])
9679 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
9680 mask_len
= DIV_ROUND_UP(pat_len
, 8);
9681 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
9683 if (pat_len
> coalesce
->pattern_max_len
||
9684 pat_len
< coalesce
->pattern_min_len
)
9687 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
9690 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
9691 if (pkt_offset
> coalesce
->max_pkt_offset
)
9693 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
9695 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
9699 new_rule
->patterns
[i
].mask
= mask_pat
;
9700 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
9703 mask_pat
+= mask_len
;
9704 new_rule
->patterns
[i
].pattern
= mask_pat
;
9705 new_rule
->patterns
[i
].pattern_len
= pat_len
;
9706 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
9714 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
9716 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9717 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
9718 struct cfg80211_coalesce new_coalesce
= {};
9719 struct cfg80211_coalesce
*n_coalesce
;
9720 int err
, rem_rule
, n_rules
= 0, i
, j
;
9721 struct nlattr
*rule
;
9722 struct cfg80211_coalesce_rules
*tmp_rule
;
9724 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
9727 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
9728 cfg80211_rdev_free_coalesce(rdev
);
9729 rdev
->ops
->set_coalesce(&rdev
->wiphy
, NULL
);
9733 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
9736 if (n_rules
> coalesce
->n_rules
)
9739 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
9741 if (!new_coalesce
.rules
)
9744 new_coalesce
.n_rules
= n_rules
;
9747 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
9749 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
9750 &new_coalesce
.rules
[i
]);
9757 err
= rdev
->ops
->set_coalesce(&rdev
->wiphy
, &new_coalesce
);
9761 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
9766 cfg80211_rdev_free_coalesce(rdev
);
9767 rdev
->coalesce
= n_coalesce
;
9771 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
9772 tmp_rule
= &new_coalesce
.rules
[i
];
9773 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
9774 kfree(tmp_rule
->patterns
[j
].mask
);
9775 kfree(tmp_rule
->patterns
);
9777 kfree(new_coalesce
.rules
);
9782 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
9784 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9785 struct net_device
*dev
= info
->user_ptr
[1];
9786 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9787 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
9788 struct cfg80211_gtk_rekey_data rekey_data
;
9791 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
9794 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
9795 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
9796 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
9797 nl80211_rekey_policy
);
9801 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
9802 !tb
[NL80211_REKEY_DATA_KCK
])
9804 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
9806 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
9808 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
9811 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
9812 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
9813 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
9816 if (!wdev
->current_bss
) {
9821 if (!rdev
->ops
->set_rekey_data
) {
9826 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
9832 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
9833 struct genl_info
*info
)
9835 struct net_device
*dev
= info
->user_ptr
[1];
9836 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9838 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9839 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
9842 if (wdev
->ap_unexpected_nlportid
)
9845 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
9849 static int nl80211_probe_client(struct sk_buff
*skb
,
9850 struct genl_info
*info
)
9852 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9853 struct net_device
*dev
= info
->user_ptr
[1];
9854 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9855 struct sk_buff
*msg
;
9861 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9862 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
9865 if (!info
->attrs
[NL80211_ATTR_MAC
])
9868 if (!rdev
->ops
->probe_client
)
9871 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9875 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9876 NL80211_CMD_PROBE_CLIENT
);
9882 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9884 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
9888 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9889 goto nla_put_failure
;
9891 genlmsg_end(msg
, hdr
);
9893 return genlmsg_reply(msg
, info
);
9902 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
9904 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9905 struct cfg80211_beacon_registration
*reg
, *nreg
;
9908 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
9911 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
9915 /* First, check if already registered. */
9916 spin_lock_bh(&rdev
->beacon_registrations_lock
);
9917 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
9918 if (reg
->nlportid
== info
->snd_portid
) {
9923 /* Add it to the list */
9924 nreg
->nlportid
= info
->snd_portid
;
9925 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
9927 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9931 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9936 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9938 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9939 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9942 if (!rdev
->ops
->start_p2p_device
)
9945 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9948 if (wdev
->p2p_started
)
9951 if (rfkill_blocked(rdev
->rfkill
))
9954 err
= rdev_start_p2p_device(rdev
, wdev
);
9958 wdev
->p2p_started
= true;
9964 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9966 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9967 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9969 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9972 if (!rdev
->ops
->stop_p2p_device
)
9975 cfg80211_stop_p2p_device(rdev
, wdev
);
9980 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
9981 struct genl_info
*info
)
9984 struct sk_buff
*msg
;
9986 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9990 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9991 NL80211_CMD_GET_PROTOCOL_FEATURES
);
9993 goto nla_put_failure
;
9995 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
9996 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
9997 goto nla_put_failure
;
9999 genlmsg_end(msg
, hdr
);
10000 return genlmsg_reply(msg
, info
);
10007 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
10009 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10010 struct cfg80211_update_ft_ies_params ft_params
;
10011 struct net_device
*dev
= info
->user_ptr
[1];
10013 if (!rdev
->ops
->update_ft_ies
)
10014 return -EOPNOTSUPP
;
10016 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
10017 !info
->attrs
[NL80211_ATTR_IE
] ||
10018 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
10021 memset(&ft_params
, 0, sizeof(ft_params
));
10022 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
10023 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10024 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10026 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
10029 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
10030 struct genl_info
*info
)
10032 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10033 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10034 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
10038 if (!rdev
->ops
->crit_proto_start
)
10039 return -EOPNOTSUPP
;
10041 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
10044 if (rdev
->crit_proto_nlportid
)
10047 /* determine protocol if provided */
10048 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
10049 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
10051 if (proto
>= NUM_NL80211_CRIT_PROTO
)
10054 /* timeout must be provided */
10055 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
10059 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
10061 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
10064 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
10066 rdev
->crit_proto_nlportid
= info
->snd_portid
;
10071 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
10072 struct genl_info
*info
)
10074 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10075 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10077 if (!rdev
->ops
->crit_proto_stop
)
10078 return -EOPNOTSUPP
;
10080 if (rdev
->crit_proto_nlportid
) {
10081 rdev
->crit_proto_nlportid
= 0;
10082 rdev_crit_proto_stop(rdev
, wdev
);
10087 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
10089 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10090 struct wireless_dev
*wdev
=
10091 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
10095 if (!rdev
->wiphy
.vendor_commands
)
10096 return -EOPNOTSUPP
;
10098 if (IS_ERR(wdev
)) {
10099 err
= PTR_ERR(wdev
);
10100 if (err
!= -EINVAL
)
10103 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
10107 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
10108 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
10111 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
10112 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
10113 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
10114 const struct wiphy_vendor_command
*vcmd
;
10118 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
10120 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10123 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
10124 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
10127 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10131 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10132 if (wdev
->netdev
&&
10133 !netif_running(wdev
->netdev
))
10135 if (!wdev
->netdev
&& !wdev
->p2p_started
)
10140 return -EOPNOTSUPP
;
10145 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
10146 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10147 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10150 rdev
->cur_cmd_info
= info
;
10151 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
10153 rdev
->cur_cmd_info
= NULL
;
10157 return -EOPNOTSUPP
;
10160 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
10161 struct netlink_callback
*cb
,
10162 struct cfg80211_registered_device
**rdev
,
10163 struct wireless_dev
**wdev
)
10170 unsigned int data_len
= 0;
10173 /* subtract the 1 again here */
10174 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
10175 struct wireless_dev
*tmp
;
10179 *rdev
= wiphy_to_rdev(wiphy
);
10183 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
10184 if (tmp
->identifier
== cb
->args
[1] - 1) {
10191 /* keep rtnl locked in successful case */
10195 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
10196 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
10201 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
10202 !nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
])
10205 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
10206 nl80211_fam
.attrbuf
);
10210 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
10211 nl80211_fam
.attrbuf
);
10213 return PTR_ERR(*rdev
);
10215 vid
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
]);
10216 subcmd
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
10218 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
10219 const struct wiphy_vendor_command
*vcmd
;
10221 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
10223 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10227 return -EOPNOTSUPP
;
10234 return -EOPNOTSUPP
;
10236 if (nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
10237 data
= nla_data(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10238 data_len
= nla_len(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10241 /* 0 is the first index - add 1 to parse only once */
10242 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
10243 /* add 1 to know if it was NULL */
10244 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
10245 cb
->args
[2] = vcmd_idx
;
10246 cb
->args
[3] = (unsigned long)data
;
10247 cb
->args
[4] = data_len
;
10249 /* keep rtnl locked in successful case */
10253 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
10254 struct netlink_callback
*cb
)
10256 struct cfg80211_registered_device
*rdev
;
10257 struct wireless_dev
*wdev
;
10258 unsigned int vcmd_idx
;
10259 const struct wiphy_vendor_command
*vcmd
;
10263 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
)) {
10281 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10287 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10288 if (wdev
->netdev
&&
10289 !netif_running(wdev
->netdev
)) {
10293 if (!wdev
->netdev
&& !wdev
->p2p_started
) {
10301 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
10302 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
10303 NL80211_CMD_VENDOR
);
10307 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10308 (wdev
&& nla_put_u64(skb
, NL80211_ATTR_WDEV
,
10310 genlmsg_cancel(skb
, hdr
);
10314 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
10315 if (!vendor_data
) {
10316 genlmsg_cancel(skb
, hdr
);
10320 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
10321 (unsigned long *)&cb
->args
[5]);
10322 nla_nest_end(skb
, vendor_data
);
10324 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
10325 genlmsg_cancel(skb
, hdr
);
10328 genlmsg_cancel(skb
, hdr
);
10332 genlmsg_end(skb
, hdr
);
10341 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
10342 enum nl80211_commands cmd
,
10343 enum nl80211_attrs attr
,
10346 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10348 if (WARN_ON(!rdev
->cur_cmd_info
))
10351 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
10352 rdev
->cur_cmd_info
->snd_portid
,
10353 rdev
->cur_cmd_info
->snd_seq
,
10354 cmd
, attr
, NULL
, GFP_KERNEL
);
10356 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
10358 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
10360 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
10361 void *hdr
= ((void **)skb
->cb
)[1];
10362 struct nlattr
*data
= ((void **)skb
->cb
)[2];
10364 /* clear CB data for netlink core to own from now on */
10365 memset(skb
->cb
, 0, sizeof(skb
->cb
));
10367 if (WARN_ON(!rdev
->cur_cmd_info
)) {
10372 nla_nest_end(skb
, data
);
10373 genlmsg_end(skb
, hdr
);
10374 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
10376 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
10379 static int nl80211_set_qos_map(struct sk_buff
*skb
,
10380 struct genl_info
*info
)
10382 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10383 struct cfg80211_qos_map
*qos_map
= NULL
;
10384 struct net_device
*dev
= info
->user_ptr
[1];
10385 u8
*pos
, len
, num_des
, des_len
, des
;
10388 if (!rdev
->ops
->set_qos_map
)
10389 return -EOPNOTSUPP
;
10391 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
10392 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10393 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10395 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
10396 len
> IEEE80211_QOS_MAP_LEN_MAX
)
10399 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
10403 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
10405 des_len
= num_des
*
10406 sizeof(struct cfg80211_dscp_exception
);
10407 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
10408 qos_map
->num_des
= num_des
;
10409 for (des
= 0; des
< num_des
; des
++) {
10410 if (qos_map
->dscp_exception
[des
].up
> 7) {
10417 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
10420 wdev_lock(dev
->ieee80211_ptr
);
10421 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
10423 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
10424 wdev_unlock(dev
->ieee80211_ptr
);
10430 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10432 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10433 struct net_device
*dev
= info
->user_ptr
[1];
10434 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10437 u16 admitted_time
= 0;
10440 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
10441 return -EOPNOTSUPP
;
10443 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
10444 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
10447 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10448 if (tsid
>= IEEE80211_NUM_TIDS
)
10451 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
10452 if (up
>= IEEE80211_NUM_UPS
)
10455 /* WMM uses TIDs 0-7 even for TSPEC */
10456 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
10457 /* TODO: handle 802.11 TSPEC/admission control
10458 * need more attributes for that (e.g. BA session requirement);
10459 * change the WMM adminssion test above to allow both then
10464 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10466 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
10468 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
10469 if (!admitted_time
)
10474 switch (wdev
->iftype
) {
10475 case NL80211_IFTYPE_STATION
:
10476 case NL80211_IFTYPE_P2P_CLIENT
:
10477 if (wdev
->current_bss
)
10486 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
10493 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10495 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10496 struct net_device
*dev
= info
->user_ptr
[1];
10497 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10502 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
10505 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10506 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10509 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
10515 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
10516 struct genl_info
*info
)
10518 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10519 struct net_device
*dev
= info
->user_ptr
[1];
10520 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10521 struct cfg80211_chan_def chandef
= {};
10526 if (!rdev
->ops
->tdls_channel_switch
||
10527 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10528 return -EOPNOTSUPP
;
10530 switch (dev
->ieee80211_ptr
->iftype
) {
10531 case NL80211_IFTYPE_STATION
:
10532 case NL80211_IFTYPE_P2P_CLIENT
:
10535 return -EOPNOTSUPP
;
10538 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
10539 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
10542 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
10547 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10548 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10549 * specification is not defined for them.
10551 if (chandef
.chan
->band
== IEEE80211_BAND_2GHZ
&&
10552 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
10553 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
10556 /* we will be active on the TDLS link */
10557 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
10561 /* don't allow switching to DFS channels */
10562 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
10565 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10566 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
10569 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
10575 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
10576 struct genl_info
*info
)
10578 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10579 struct net_device
*dev
= info
->user_ptr
[1];
10580 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10583 if (!rdev
->ops
->tdls_channel_switch
||
10584 !rdev
->ops
->tdls_cancel_channel_switch
||
10585 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10586 return -EOPNOTSUPP
;
10588 switch (dev
->ieee80211_ptr
->iftype
) {
10589 case NL80211_IFTYPE_STATION
:
10590 case NL80211_IFTYPE_P2P_CLIENT
:
10593 return -EOPNOTSUPP
;
10596 if (!info
->attrs
[NL80211_ATTR_MAC
])
10599 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10602 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
10608 #define NL80211_FLAG_NEED_WIPHY 0x01
10609 #define NL80211_FLAG_NEED_NETDEV 0x02
10610 #define NL80211_FLAG_NEED_RTNL 0x04
10611 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10612 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10613 NL80211_FLAG_CHECK_NETDEV_UP)
10614 #define NL80211_FLAG_NEED_WDEV 0x10
10615 /* If a netdev is associated, it must be UP, P2P must be started */
10616 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10617 NL80211_FLAG_CHECK_NETDEV_UP)
10618 #define NL80211_FLAG_CLEAR_SKB 0x20
10620 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
10621 struct genl_info
*info
)
10623 struct cfg80211_registered_device
*rdev
;
10624 struct wireless_dev
*wdev
;
10625 struct net_device
*dev
;
10626 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
10631 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
10632 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
10633 if (IS_ERR(rdev
)) {
10636 return PTR_ERR(rdev
);
10638 info
->user_ptr
[0] = rdev
;
10639 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
10640 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
10643 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
10645 if (IS_ERR(wdev
)) {
10648 return PTR_ERR(wdev
);
10651 dev
= wdev
->netdev
;
10652 rdev
= wiphy_to_rdev(wdev
->wiphy
);
10654 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
10661 info
->user_ptr
[1] = dev
;
10663 info
->user_ptr
[1] = wdev
;
10667 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
10668 !netif_running(dev
)) {
10675 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
10676 if (!wdev
->p2p_started
) {
10683 info
->user_ptr
[0] = rdev
;
10689 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
10690 struct genl_info
*info
)
10692 if (info
->user_ptr
[1]) {
10693 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
10694 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10697 dev_put(wdev
->netdev
);
10699 dev_put(info
->user_ptr
[1]);
10703 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
10706 /* If needed, clear the netlink message payload from the SKB
10707 * as it might contain key data that shouldn't stick around on
10708 * the heap after the SKB is freed. The netlink message header
10709 * is still needed for further processing, so leave it intact.
10711 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
10712 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
10714 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
10718 static const struct genl_ops nl80211_ops
[] = {
10720 .cmd
= NL80211_CMD_GET_WIPHY
,
10721 .doit
= nl80211_get_wiphy
,
10722 .dumpit
= nl80211_dump_wiphy
,
10723 .done
= nl80211_dump_wiphy_done
,
10724 .policy
= nl80211_policy
,
10725 /* can be retrieved by unprivileged users */
10726 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10727 NL80211_FLAG_NEED_RTNL
,
10730 .cmd
= NL80211_CMD_SET_WIPHY
,
10731 .doit
= nl80211_set_wiphy
,
10732 .policy
= nl80211_policy
,
10733 .flags
= GENL_ADMIN_PERM
,
10734 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10737 .cmd
= NL80211_CMD_GET_INTERFACE
,
10738 .doit
= nl80211_get_interface
,
10739 .dumpit
= nl80211_dump_interface
,
10740 .policy
= nl80211_policy
,
10741 /* can be retrieved by unprivileged users */
10742 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
10743 NL80211_FLAG_NEED_RTNL
,
10746 .cmd
= NL80211_CMD_SET_INTERFACE
,
10747 .doit
= nl80211_set_interface
,
10748 .policy
= nl80211_policy
,
10749 .flags
= GENL_ADMIN_PERM
,
10750 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10751 NL80211_FLAG_NEED_RTNL
,
10754 .cmd
= NL80211_CMD_NEW_INTERFACE
,
10755 .doit
= nl80211_new_interface
,
10756 .policy
= nl80211_policy
,
10757 .flags
= GENL_ADMIN_PERM
,
10758 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10759 NL80211_FLAG_NEED_RTNL
,
10762 .cmd
= NL80211_CMD_DEL_INTERFACE
,
10763 .doit
= nl80211_del_interface
,
10764 .policy
= nl80211_policy
,
10765 .flags
= GENL_ADMIN_PERM
,
10766 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
10767 NL80211_FLAG_NEED_RTNL
,
10770 .cmd
= NL80211_CMD_GET_KEY
,
10771 .doit
= nl80211_get_key
,
10772 .policy
= nl80211_policy
,
10773 .flags
= GENL_ADMIN_PERM
,
10774 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10775 NL80211_FLAG_NEED_RTNL
,
10778 .cmd
= NL80211_CMD_SET_KEY
,
10779 .doit
= nl80211_set_key
,
10780 .policy
= nl80211_policy
,
10781 .flags
= GENL_ADMIN_PERM
,
10782 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10783 NL80211_FLAG_NEED_RTNL
|
10784 NL80211_FLAG_CLEAR_SKB
,
10787 .cmd
= NL80211_CMD_NEW_KEY
,
10788 .doit
= nl80211_new_key
,
10789 .policy
= nl80211_policy
,
10790 .flags
= GENL_ADMIN_PERM
,
10791 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10792 NL80211_FLAG_NEED_RTNL
|
10793 NL80211_FLAG_CLEAR_SKB
,
10796 .cmd
= NL80211_CMD_DEL_KEY
,
10797 .doit
= nl80211_del_key
,
10798 .policy
= nl80211_policy
,
10799 .flags
= GENL_ADMIN_PERM
,
10800 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10801 NL80211_FLAG_NEED_RTNL
,
10804 .cmd
= NL80211_CMD_SET_BEACON
,
10805 .policy
= nl80211_policy
,
10806 .flags
= GENL_ADMIN_PERM
,
10807 .doit
= nl80211_set_beacon
,
10808 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10809 NL80211_FLAG_NEED_RTNL
,
10812 .cmd
= NL80211_CMD_START_AP
,
10813 .policy
= nl80211_policy
,
10814 .flags
= GENL_ADMIN_PERM
,
10815 .doit
= nl80211_start_ap
,
10816 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10817 NL80211_FLAG_NEED_RTNL
,
10820 .cmd
= NL80211_CMD_STOP_AP
,
10821 .policy
= nl80211_policy
,
10822 .flags
= GENL_ADMIN_PERM
,
10823 .doit
= nl80211_stop_ap
,
10824 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10825 NL80211_FLAG_NEED_RTNL
,
10828 .cmd
= NL80211_CMD_GET_STATION
,
10829 .doit
= nl80211_get_station
,
10830 .dumpit
= nl80211_dump_station
,
10831 .policy
= nl80211_policy
,
10832 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10833 NL80211_FLAG_NEED_RTNL
,
10836 .cmd
= NL80211_CMD_SET_STATION
,
10837 .doit
= nl80211_set_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_NEW_STATION
,
10845 .doit
= nl80211_new_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_DEL_STATION
,
10853 .doit
= nl80211_del_station
,
10854 .policy
= nl80211_policy
,
10855 .flags
= GENL_ADMIN_PERM
,
10856 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10857 NL80211_FLAG_NEED_RTNL
,
10860 .cmd
= NL80211_CMD_GET_MPATH
,
10861 .doit
= nl80211_get_mpath
,
10862 .dumpit
= nl80211_dump_mpath
,
10863 .policy
= nl80211_policy
,
10864 .flags
= GENL_ADMIN_PERM
,
10865 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10866 NL80211_FLAG_NEED_RTNL
,
10869 .cmd
= NL80211_CMD_GET_MPP
,
10870 .doit
= nl80211_get_mpp
,
10871 .dumpit
= nl80211_dump_mpp
,
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_SET_MPATH
,
10879 .doit
= nl80211_set_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_NEW_MPATH
,
10887 .doit
= nl80211_new_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_DEL_MPATH
,
10895 .doit
= nl80211_del_mpath
,
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_SET_BSS
,
10903 .doit
= nl80211_set_bss
,
10904 .policy
= nl80211_policy
,
10905 .flags
= GENL_ADMIN_PERM
,
10906 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10907 NL80211_FLAG_NEED_RTNL
,
10910 .cmd
= NL80211_CMD_GET_REG
,
10911 .doit
= nl80211_get_reg_do
,
10912 .dumpit
= nl80211_get_reg_dump
,
10913 .policy
= nl80211_policy
,
10914 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10915 /* can be retrieved by unprivileged users */
10917 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
10919 .cmd
= NL80211_CMD_SET_REG
,
10920 .doit
= nl80211_set_reg
,
10921 .policy
= nl80211_policy
,
10922 .flags
= GENL_ADMIN_PERM
,
10923 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10927 .cmd
= NL80211_CMD_REQ_SET_REG
,
10928 .doit
= nl80211_req_set_reg
,
10929 .policy
= nl80211_policy
,
10930 .flags
= GENL_ADMIN_PERM
,
10933 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
10934 .doit
= nl80211_get_mesh_config
,
10935 .policy
= nl80211_policy
,
10936 /* can be retrieved by unprivileged users */
10937 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10938 NL80211_FLAG_NEED_RTNL
,
10941 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
10942 .doit
= nl80211_update_mesh_config
,
10943 .policy
= nl80211_policy
,
10944 .flags
= GENL_ADMIN_PERM
,
10945 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10946 NL80211_FLAG_NEED_RTNL
,
10949 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
10950 .doit
= nl80211_trigger_scan
,
10951 .policy
= nl80211_policy
,
10952 .flags
= GENL_ADMIN_PERM
,
10953 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
10954 NL80211_FLAG_NEED_RTNL
,
10957 .cmd
= NL80211_CMD_GET_SCAN
,
10958 .policy
= nl80211_policy
,
10959 .dumpit
= nl80211_dump_scan
,
10962 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
10963 .doit
= nl80211_start_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_STOP_SCHED_SCAN
,
10971 .doit
= nl80211_stop_sched_scan
,
10972 .policy
= nl80211_policy
,
10973 .flags
= GENL_ADMIN_PERM
,
10974 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10975 NL80211_FLAG_NEED_RTNL
,
10978 .cmd
= NL80211_CMD_AUTHENTICATE
,
10979 .doit
= nl80211_authenticate
,
10980 .policy
= nl80211_policy
,
10981 .flags
= GENL_ADMIN_PERM
,
10982 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10983 NL80211_FLAG_NEED_RTNL
|
10984 NL80211_FLAG_CLEAR_SKB
,
10987 .cmd
= NL80211_CMD_ASSOCIATE
,
10988 .doit
= nl80211_associate
,
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_DEAUTHENTICATE
,
10996 .doit
= nl80211_deauthenticate
,
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_DISASSOCIATE
,
11004 .doit
= nl80211_disassociate
,
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_JOIN_IBSS
,
11012 .doit
= nl80211_join_ibss
,
11013 .policy
= nl80211_policy
,
11014 .flags
= GENL_ADMIN_PERM
,
11015 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11016 NL80211_FLAG_NEED_RTNL
,
11019 .cmd
= NL80211_CMD_LEAVE_IBSS
,
11020 .doit
= nl80211_leave_ibss
,
11021 .policy
= nl80211_policy
,
11022 .flags
= GENL_ADMIN_PERM
,
11023 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11024 NL80211_FLAG_NEED_RTNL
,
11026 #ifdef CONFIG_NL80211_TESTMODE
11028 .cmd
= NL80211_CMD_TESTMODE
,
11029 .doit
= nl80211_testmode_do
,
11030 .dumpit
= nl80211_testmode_dump
,
11031 .policy
= nl80211_policy
,
11032 .flags
= GENL_ADMIN_PERM
,
11033 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11034 NL80211_FLAG_NEED_RTNL
,
11038 .cmd
= NL80211_CMD_CONNECT
,
11039 .doit
= nl80211_connect
,
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_DISCONNECT
,
11047 .doit
= nl80211_disconnect
,
11048 .policy
= nl80211_policy
,
11049 .flags
= GENL_ADMIN_PERM
,
11050 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11051 NL80211_FLAG_NEED_RTNL
,
11054 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
11055 .doit
= nl80211_wiphy_netns
,
11056 .policy
= nl80211_policy
,
11057 .flags
= GENL_ADMIN_PERM
,
11058 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11059 NL80211_FLAG_NEED_RTNL
,
11062 .cmd
= NL80211_CMD_GET_SURVEY
,
11063 .policy
= nl80211_policy
,
11064 .dumpit
= nl80211_dump_survey
,
11067 .cmd
= NL80211_CMD_SET_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_DEL_PMKSA
,
11076 .doit
= nl80211_setdel_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_FLUSH_PMKSA
,
11084 .doit
= nl80211_flush_pmksa
,
11085 .policy
= nl80211_policy
,
11086 .flags
= GENL_ADMIN_PERM
,
11087 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11088 NL80211_FLAG_NEED_RTNL
,
11091 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
11092 .doit
= nl80211_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_CANCEL_REMAIN_ON_CHANNEL
,
11100 .doit
= nl80211_cancel_remain_on_channel
,
11101 .policy
= nl80211_policy
,
11102 .flags
= GENL_ADMIN_PERM
,
11103 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11104 NL80211_FLAG_NEED_RTNL
,
11107 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
11108 .doit
= nl80211_set_tx_bitrate_mask
,
11109 .policy
= nl80211_policy
,
11110 .flags
= GENL_ADMIN_PERM
,
11111 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11112 NL80211_FLAG_NEED_RTNL
,
11115 .cmd
= NL80211_CMD_REGISTER_FRAME
,
11116 .doit
= nl80211_register_mgmt
,
11117 .policy
= nl80211_policy
,
11118 .flags
= GENL_ADMIN_PERM
,
11119 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11120 NL80211_FLAG_NEED_RTNL
,
11123 .cmd
= NL80211_CMD_FRAME
,
11124 .doit
= nl80211_tx_mgmt
,
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_FRAME_WAIT_CANCEL
,
11132 .doit
= nl80211_tx_mgmt_cancel_wait
,
11133 .policy
= nl80211_policy
,
11134 .flags
= GENL_ADMIN_PERM
,
11135 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11136 NL80211_FLAG_NEED_RTNL
,
11139 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
11140 .doit
= nl80211_set_power_save
,
11141 .policy
= nl80211_policy
,
11142 .flags
= GENL_ADMIN_PERM
,
11143 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11144 NL80211_FLAG_NEED_RTNL
,
11147 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
11148 .doit
= nl80211_get_power_save
,
11149 .policy
= nl80211_policy
,
11150 /* can be retrieved by unprivileged users */
11151 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11152 NL80211_FLAG_NEED_RTNL
,
11155 .cmd
= NL80211_CMD_SET_CQM
,
11156 .doit
= nl80211_set_cqm
,
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_CHANNEL
,
11164 .doit
= nl80211_set_channel
,
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_SET_WDS_PEER
,
11172 .doit
= nl80211_set_wds_peer
,
11173 .policy
= nl80211_policy
,
11174 .flags
= GENL_ADMIN_PERM
,
11175 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11176 NL80211_FLAG_NEED_RTNL
,
11179 .cmd
= NL80211_CMD_JOIN_MESH
,
11180 .doit
= nl80211_join_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_LEAVE_MESH
,
11188 .doit
= nl80211_leave_mesh
,
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_JOIN_OCB
,
11196 .doit
= nl80211_join_ocb
,
11197 .policy
= nl80211_policy
,
11198 .flags
= GENL_ADMIN_PERM
,
11199 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11200 NL80211_FLAG_NEED_RTNL
,
11203 .cmd
= NL80211_CMD_LEAVE_OCB
,
11204 .doit
= nl80211_leave_ocb
,
11205 .policy
= nl80211_policy
,
11206 .flags
= GENL_ADMIN_PERM
,
11207 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11208 NL80211_FLAG_NEED_RTNL
,
11212 .cmd
= NL80211_CMD_GET_WOWLAN
,
11213 .doit
= nl80211_get_wowlan
,
11214 .policy
= nl80211_policy
,
11215 /* can be retrieved by unprivileged users */
11216 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11217 NL80211_FLAG_NEED_RTNL
,
11220 .cmd
= NL80211_CMD_SET_WOWLAN
,
11221 .doit
= nl80211_set_wowlan
,
11222 .policy
= nl80211_policy
,
11223 .flags
= GENL_ADMIN_PERM
,
11224 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11225 NL80211_FLAG_NEED_RTNL
,
11229 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
11230 .doit
= nl80211_set_rekey_data
,
11231 .policy
= nl80211_policy
,
11232 .flags
= GENL_ADMIN_PERM
,
11233 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11234 NL80211_FLAG_NEED_RTNL
|
11235 NL80211_FLAG_CLEAR_SKB
,
11238 .cmd
= NL80211_CMD_TDLS_MGMT
,
11239 .doit
= nl80211_tdls_mgmt
,
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_TDLS_OPER
,
11247 .doit
= nl80211_tdls_oper
,
11248 .policy
= nl80211_policy
,
11249 .flags
= GENL_ADMIN_PERM
,
11250 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11251 NL80211_FLAG_NEED_RTNL
,
11254 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
11255 .doit
= nl80211_register_unexpected_frame
,
11256 .policy
= nl80211_policy
,
11257 .flags
= GENL_ADMIN_PERM
,
11258 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11259 NL80211_FLAG_NEED_RTNL
,
11262 .cmd
= NL80211_CMD_PROBE_CLIENT
,
11263 .doit
= nl80211_probe_client
,
11264 .policy
= nl80211_policy
,
11265 .flags
= GENL_ADMIN_PERM
,
11266 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11267 NL80211_FLAG_NEED_RTNL
,
11270 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
11271 .doit
= nl80211_register_beacons
,
11272 .policy
= nl80211_policy
,
11273 .flags
= GENL_ADMIN_PERM
,
11274 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11275 NL80211_FLAG_NEED_RTNL
,
11278 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
11279 .doit
= nl80211_set_noack_map
,
11280 .policy
= nl80211_policy
,
11281 .flags
= GENL_ADMIN_PERM
,
11282 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11283 NL80211_FLAG_NEED_RTNL
,
11286 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
11287 .doit
= nl80211_start_p2p_device
,
11288 .policy
= nl80211_policy
,
11289 .flags
= GENL_ADMIN_PERM
,
11290 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11291 NL80211_FLAG_NEED_RTNL
,
11294 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
11295 .doit
= nl80211_stop_p2p_device
,
11296 .policy
= nl80211_policy
,
11297 .flags
= GENL_ADMIN_PERM
,
11298 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11299 NL80211_FLAG_NEED_RTNL
,
11302 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
11303 .doit
= nl80211_set_mcast_rate
,
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_SET_MAC_ACL
,
11311 .doit
= nl80211_set_mac_acl
,
11312 .policy
= nl80211_policy
,
11313 .flags
= GENL_ADMIN_PERM
,
11314 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11315 NL80211_FLAG_NEED_RTNL
,
11318 .cmd
= NL80211_CMD_RADAR_DETECT
,
11319 .doit
= nl80211_start_radar_detection
,
11320 .policy
= nl80211_policy
,
11321 .flags
= GENL_ADMIN_PERM
,
11322 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11323 NL80211_FLAG_NEED_RTNL
,
11326 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
11327 .doit
= nl80211_get_protocol_features
,
11328 .policy
= nl80211_policy
,
11331 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
11332 .doit
= nl80211_update_ft_ies
,
11333 .policy
= nl80211_policy
,
11334 .flags
= GENL_ADMIN_PERM
,
11335 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11336 NL80211_FLAG_NEED_RTNL
,
11339 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
11340 .doit
= nl80211_crit_protocol_start
,
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_CRIT_PROTOCOL_STOP
,
11348 .doit
= nl80211_crit_protocol_stop
,
11349 .policy
= nl80211_policy
,
11350 .flags
= GENL_ADMIN_PERM
,
11351 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11352 NL80211_FLAG_NEED_RTNL
,
11355 .cmd
= NL80211_CMD_GET_COALESCE
,
11356 .doit
= nl80211_get_coalesce
,
11357 .policy
= nl80211_policy
,
11358 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11359 NL80211_FLAG_NEED_RTNL
,
11362 .cmd
= NL80211_CMD_SET_COALESCE
,
11363 .doit
= nl80211_set_coalesce
,
11364 .policy
= nl80211_policy
,
11365 .flags
= GENL_ADMIN_PERM
,
11366 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11367 NL80211_FLAG_NEED_RTNL
,
11370 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
11371 .doit
= nl80211_channel_switch
,
11372 .policy
= nl80211_policy
,
11373 .flags
= GENL_ADMIN_PERM
,
11374 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11375 NL80211_FLAG_NEED_RTNL
,
11378 .cmd
= NL80211_CMD_VENDOR
,
11379 .doit
= nl80211_vendor_cmd
,
11380 .dumpit
= nl80211_vendor_cmd_dump
,
11381 .policy
= nl80211_policy
,
11382 .flags
= GENL_ADMIN_PERM
,
11383 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11384 NL80211_FLAG_NEED_RTNL
,
11387 .cmd
= NL80211_CMD_SET_QOS_MAP
,
11388 .doit
= nl80211_set_qos_map
,
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_ADD_TX_TS
,
11396 .doit
= nl80211_add_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_DEL_TX_TS
,
11404 .doit
= nl80211_del_tx_ts
,
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_CHANNEL_SWITCH
,
11412 .doit
= nl80211_tdls_channel_switch
,
11413 .policy
= nl80211_policy
,
11414 .flags
= GENL_ADMIN_PERM
,
11415 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11416 NL80211_FLAG_NEED_RTNL
,
11419 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
11420 .doit
= nl80211_tdls_cancel_channel_switch
,
11421 .policy
= nl80211_policy
,
11422 .flags
= GENL_ADMIN_PERM
,
11423 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11424 NL80211_FLAG_NEED_RTNL
,
11428 /* notification functions */
11430 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
11431 enum nl80211_commands cmd
)
11433 struct sk_buff
*msg
;
11434 struct nl80211_dump_wiphy_state state
= {};
11436 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
11437 cmd
!= NL80211_CMD_DEL_WIPHY
);
11439 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11443 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
11448 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11449 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
11452 static int nl80211_add_scan_req(struct sk_buff
*msg
,
11453 struct cfg80211_registered_device
*rdev
)
11455 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
11456 struct nlattr
*nest
;
11462 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
11464 goto nla_put_failure
;
11465 for (i
= 0; i
< req
->n_ssids
; i
++) {
11466 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
11467 goto nla_put_failure
;
11469 nla_nest_end(msg
, nest
);
11471 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
11473 goto nla_put_failure
;
11474 for (i
= 0; i
< req
->n_channels
; i
++) {
11475 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
11476 goto nla_put_failure
;
11478 nla_nest_end(msg
, nest
);
11481 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
11482 goto nla_put_failure
;
11485 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
11486 goto nla_put_failure
;
11493 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
11494 struct cfg80211_registered_device
*rdev
,
11495 struct wireless_dev
*wdev
,
11496 u32 portid
, u32 seq
, int flags
,
11501 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11505 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11506 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11507 wdev
->netdev
->ifindex
)) ||
11508 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11509 goto nla_put_failure
;
11511 /* ignore errors and send incomplete event anyway */
11512 nl80211_add_scan_req(msg
, rdev
);
11514 genlmsg_end(msg
, hdr
);
11518 genlmsg_cancel(msg
, hdr
);
11523 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
11524 struct cfg80211_registered_device
*rdev
,
11525 struct net_device
*netdev
,
11526 u32 portid
, u32 seq
, int flags
, u32 cmd
)
11530 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11534 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11535 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11536 goto nla_put_failure
;
11538 genlmsg_end(msg
, hdr
);
11542 genlmsg_cancel(msg
, hdr
);
11546 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
11547 struct wireless_dev
*wdev
)
11549 struct sk_buff
*msg
;
11551 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11555 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11556 NL80211_CMD_TRIGGER_SCAN
) < 0) {
11561 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11562 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11565 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
11566 struct wireless_dev
*wdev
, bool aborted
)
11568 struct sk_buff
*msg
;
11570 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11574 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11575 aborted
? NL80211_CMD_SCAN_ABORTED
:
11576 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
11584 void nl80211_send_scan_result(struct cfg80211_registered_device
*rdev
,
11585 struct sk_buff
*msg
)
11590 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11591 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11594 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
11595 struct net_device
*netdev
)
11597 struct sk_buff
*msg
;
11599 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11603 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
11604 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
11609 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11610 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11613 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
11614 struct net_device
*netdev
, u32 cmd
)
11616 struct sk_buff
*msg
;
11618 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11622 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
11627 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11628 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11631 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
11632 struct regulatory_request
*request
)
11634 /* Userspace can always count this one always being set */
11635 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
11636 goto nla_put_failure
;
11638 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
11639 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11640 NL80211_REGDOM_TYPE_WORLD
))
11641 goto nla_put_failure
;
11642 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
11643 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11644 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
11645 goto nla_put_failure
;
11646 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
11647 request
->intersect
) {
11648 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11649 NL80211_REGDOM_TYPE_INTERSECTION
))
11650 goto nla_put_failure
;
11652 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11653 NL80211_REGDOM_TYPE_COUNTRY
) ||
11654 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
11656 goto nla_put_failure
;
11659 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
11660 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
11663 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
11664 goto nla_put_failure
;
11667 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
11668 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
11669 goto nla_put_failure
;
11679 * This can happen on global regulatory changes or device specific settings
11680 * based on custom regulatory domains.
11682 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
11683 struct regulatory_request
*request
)
11685 struct sk_buff
*msg
;
11688 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11692 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
11698 if (nl80211_reg_change_event_fill(msg
, request
) == false)
11699 goto nla_put_failure
;
11701 genlmsg_end(msg
, hdr
);
11704 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
11705 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
11711 genlmsg_cancel(msg
, hdr
);
11715 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
11716 struct net_device
*netdev
,
11717 const u8
*buf
, size_t len
,
11718 enum nl80211_commands cmd
, gfp_t gfp
,
11721 struct sk_buff
*msg
;
11724 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11728 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
11734 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11735 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11736 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
11737 goto nla_put_failure
;
11739 if (uapsd_queues
>= 0) {
11740 struct nlattr
*nla_wmm
=
11741 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
11743 goto nla_put_failure
;
11745 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
11747 goto nla_put_failure
;
11749 nla_nest_end(msg
, nla_wmm
);
11752 genlmsg_end(msg
, hdr
);
11754 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11755 NL80211_MCGRP_MLME
, gfp
);
11759 genlmsg_cancel(msg
, hdr
);
11763 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
11764 struct net_device
*netdev
, const u8
*buf
,
11765 size_t len
, gfp_t gfp
)
11767 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11768 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
11771 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
11772 struct net_device
*netdev
, const u8
*buf
,
11773 size_t len
, gfp_t gfp
, int uapsd_queues
)
11775 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11776 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
11779 void nl80211_send_deauth(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_DEAUTHENTICATE
, gfp
, -1);
11787 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
11788 struct net_device
*netdev
, const u8
*buf
,
11789 size_t len
, gfp_t gfp
)
11791 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11792 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
11795 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
11798 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11799 struct wiphy
*wiphy
= wdev
->wiphy
;
11800 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11801 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
11804 if (WARN_ON(len
< 2))
11807 if (ieee80211_is_deauth(mgmt
->frame_control
))
11808 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
11810 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
11812 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
11813 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
11815 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
11817 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
11818 struct net_device
*netdev
, int cmd
,
11819 const u8
*addr
, gfp_t gfp
)
11821 struct sk_buff
*msg
;
11824 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11828 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
11834 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11835 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11836 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
11837 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
11838 goto nla_put_failure
;
11840 genlmsg_end(msg
, hdr
);
11842 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11843 NL80211_MCGRP_MLME
, gfp
);
11847 genlmsg_cancel(msg
, hdr
);
11851 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
11852 struct net_device
*netdev
, const u8
*addr
,
11855 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
11859 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
11860 struct net_device
*netdev
, const u8
*addr
,
11863 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
11867 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
11868 struct net_device
*netdev
, const u8
*bssid
,
11869 const u8
*req_ie
, size_t req_ie_len
,
11870 const u8
*resp_ie
, size_t resp_ie_len
,
11871 u16 status
, gfp_t gfp
)
11873 struct sk_buff
*msg
;
11876 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11880 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
11886 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11887 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11888 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
11889 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
11891 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
11893 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
11894 goto nla_put_failure
;
11896 genlmsg_end(msg
, hdr
);
11898 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11899 NL80211_MCGRP_MLME
, gfp
);
11903 genlmsg_cancel(msg
, hdr
);
11908 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
11909 struct net_device
*netdev
, const u8
*bssid
,
11910 const u8
*req_ie
, size_t req_ie_len
,
11911 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
11913 struct sk_buff
*msg
;
11916 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11920 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
11926 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11927 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11928 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
11930 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
11932 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
11933 goto nla_put_failure
;
11935 genlmsg_end(msg
, hdr
);
11937 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11938 NL80211_MCGRP_MLME
, gfp
);
11942 genlmsg_cancel(msg
, hdr
);
11947 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
11948 struct net_device
*netdev
, u16 reason
,
11949 const u8
*ie
, size_t ie_len
, bool from_ap
)
11951 struct sk_buff
*msg
;
11954 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11958 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
11964 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11965 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11966 (from_ap
&& reason
&&
11967 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
11969 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
11970 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
11971 goto nla_put_failure
;
11973 genlmsg_end(msg
, hdr
);
11975 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11976 NL80211_MCGRP_MLME
, GFP_KERNEL
);
11980 genlmsg_cancel(msg
, hdr
);
11985 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
11986 struct net_device
*netdev
, const u8
*bssid
,
11989 struct sk_buff
*msg
;
11992 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11996 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
12002 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12003 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12004 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
12005 goto nla_put_failure
;
12007 genlmsg_end(msg
, hdr
);
12009 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12010 NL80211_MCGRP_MLME
, gfp
);
12014 genlmsg_cancel(msg
, hdr
);
12018 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
12019 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
12021 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12022 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12023 struct sk_buff
*msg
;
12026 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
12029 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
12031 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12035 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
12041 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12042 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12043 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
12045 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
12046 goto nla_put_failure
;
12048 genlmsg_end(msg
, hdr
);
12050 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12051 NL80211_MCGRP_MLME
, gfp
);
12055 genlmsg_cancel(msg
, hdr
);
12058 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
12060 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
12061 struct net_device
*netdev
, const u8
*addr
,
12062 enum nl80211_key_type key_type
, int key_id
,
12063 const u8
*tsc
, gfp_t gfp
)
12065 struct sk_buff
*msg
;
12068 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12072 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
12078 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12079 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12080 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
12081 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
12083 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
12084 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
12085 goto nla_put_failure
;
12087 genlmsg_end(msg
, hdr
);
12089 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12090 NL80211_MCGRP_MLME
, gfp
);
12094 genlmsg_cancel(msg
, hdr
);
12098 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
12099 struct ieee80211_channel
*channel_before
,
12100 struct ieee80211_channel
*channel_after
)
12102 struct sk_buff
*msg
;
12104 struct nlattr
*nl_freq
;
12106 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
12110 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
12117 * Since we are applying the beacon hint to a wiphy we know its
12118 * wiphy_idx is valid
12120 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
12121 goto nla_put_failure
;
12124 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
12126 goto nla_put_failure
;
12127 if (nl80211_msg_put_channel(msg
, channel_before
, false))
12128 goto nla_put_failure
;
12129 nla_nest_end(msg
, nl_freq
);
12132 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
12134 goto nla_put_failure
;
12135 if (nl80211_msg_put_channel(msg
, channel_after
, false))
12136 goto nla_put_failure
;
12137 nla_nest_end(msg
, nl_freq
);
12139 genlmsg_end(msg
, hdr
);
12142 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
12143 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
12149 genlmsg_cancel(msg
, hdr
);
12153 static void nl80211_send_remain_on_chan_event(
12154 int cmd
, struct cfg80211_registered_device
*rdev
,
12155 struct wireless_dev
*wdev
, u64 cookie
,
12156 struct ieee80211_channel
*chan
,
12157 unsigned int duration
, gfp_t gfp
)
12159 struct sk_buff
*msg
;
12162 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12166 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12172 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12173 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12174 wdev
->netdev
->ifindex
)) ||
12175 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12176 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
12177 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
12178 NL80211_CHAN_NO_HT
) ||
12179 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
12180 goto nla_put_failure
;
12182 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
12183 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
12184 goto nla_put_failure
;
12186 genlmsg_end(msg
, hdr
);
12188 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12189 NL80211_MCGRP_MLME
, gfp
);
12193 genlmsg_cancel(msg
, hdr
);
12197 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
12198 struct ieee80211_channel
*chan
,
12199 unsigned int duration
, gfp_t gfp
)
12201 struct wiphy
*wiphy
= wdev
->wiphy
;
12202 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12204 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
12205 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
12206 rdev
, wdev
, cookie
, chan
,
12209 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
12211 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
12212 struct ieee80211_channel
*chan
,
12215 struct wiphy
*wiphy
= wdev
->wiphy
;
12216 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12218 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
12219 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
12220 rdev
, wdev
, cookie
, chan
, 0, gfp
);
12222 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
12224 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
12225 struct station_info
*sinfo
, gfp_t gfp
)
12227 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12228 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12229 struct sk_buff
*msg
;
12231 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
12233 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12237 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
12238 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12243 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12244 NL80211_MCGRP_MLME
, gfp
);
12246 EXPORT_SYMBOL(cfg80211_new_sta
);
12248 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
12249 struct station_info
*sinfo
, gfp_t gfp
)
12251 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12252 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12253 struct sk_buff
*msg
;
12254 struct station_info empty_sinfo
= {};
12257 sinfo
= &empty_sinfo
;
12259 trace_cfg80211_del_sta(dev
, mac_addr
);
12261 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12265 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
12266 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12271 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12272 NL80211_MCGRP_MLME
, gfp
);
12274 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
12276 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
12277 enum nl80211_connect_failed_reason reason
,
12280 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12281 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12282 struct sk_buff
*msg
;
12285 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
12289 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
12295 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12296 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
12297 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
12298 goto nla_put_failure
;
12300 genlmsg_end(msg
, hdr
);
12302 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12303 NL80211_MCGRP_MLME
, gfp
);
12307 genlmsg_cancel(msg
, hdr
);
12310 EXPORT_SYMBOL(cfg80211_conn_failed
);
12312 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
12313 const u8
*addr
, gfp_t gfp
)
12315 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12316 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12317 struct sk_buff
*msg
;
12319 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
12324 msg
= nlmsg_new(100, gfp
);
12328 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12334 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12335 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12336 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
12337 goto nla_put_failure
;
12339 genlmsg_end(msg
, hdr
);
12340 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12344 genlmsg_cancel(msg
, hdr
);
12349 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
12350 const u8
*addr
, gfp_t gfp
)
12352 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12355 trace_cfg80211_rx_spurious_frame(dev
, addr
);
12357 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12358 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
12359 trace_cfg80211_return_bool(false);
12362 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
12364 trace_cfg80211_return_bool(ret
);
12367 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
12369 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
12370 const u8
*addr
, gfp_t gfp
)
12372 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12375 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
12377 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12378 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
12379 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
12380 trace_cfg80211_return_bool(false);
12383 ret
= __nl80211_unexpected_frame(dev
,
12384 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
12386 trace_cfg80211_return_bool(ret
);
12389 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
12391 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
12392 struct wireless_dev
*wdev
, u32 nlportid
,
12393 int freq
, int sig_dbm
,
12394 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
12396 struct net_device
*netdev
= wdev
->netdev
;
12397 struct sk_buff
*msg
;
12400 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12404 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
12410 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12411 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12412 netdev
->ifindex
)) ||
12413 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12414 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
12416 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
12417 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12419 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
12420 goto nla_put_failure
;
12422 genlmsg_end(msg
, hdr
);
12424 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12427 genlmsg_cancel(msg
, hdr
);
12432 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
12433 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
12435 struct wiphy
*wiphy
= wdev
->wiphy
;
12436 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12437 struct net_device
*netdev
= wdev
->netdev
;
12438 struct sk_buff
*msg
;
12441 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
12443 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12447 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
12453 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12454 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12455 netdev
->ifindex
)) ||
12456 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12457 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12458 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
12459 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
12460 goto nla_put_failure
;
12462 genlmsg_end(msg
, hdr
);
12464 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12465 NL80211_MCGRP_MLME
, gfp
);
12469 genlmsg_cancel(msg
, hdr
);
12472 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
12474 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
12475 const char *mac
, gfp_t gfp
)
12477 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12478 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12479 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12485 cb
= (void **)msg
->cb
;
12487 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
12493 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12494 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
12495 goto nla_put_failure
;
12497 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
12498 goto nla_put_failure
;
12500 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
12502 goto nla_put_failure
;
12512 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
12514 void **cb
= (void **)msg
->cb
;
12515 struct cfg80211_registered_device
*rdev
= cb
[2];
12517 nla_nest_end(msg
, cb
[1]);
12518 genlmsg_end(msg
, cb
[0]);
12520 memset(msg
->cb
, 0, sizeof(msg
->cb
));
12522 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12523 NL80211_MCGRP_MLME
, gfp
);
12526 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
12527 enum nl80211_cqm_rssi_threshold_event rssi_event
,
12530 struct sk_buff
*msg
;
12532 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
12534 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
12535 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
12538 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
12542 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
12544 goto nla_put_failure
;
12546 cfg80211_send_cqm(msg
, gfp
);
12553 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
12555 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
12556 const u8
*peer
, u32 num_packets
,
12557 u32 rate
, u32 intvl
, gfp_t gfp
)
12559 struct sk_buff
*msg
;
12561 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
12565 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
12566 goto nla_put_failure
;
12568 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
12569 goto nla_put_failure
;
12571 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
12572 goto nla_put_failure
;
12574 cfg80211_send_cqm(msg
, gfp
);
12580 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
12582 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
12583 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
12585 struct sk_buff
*msg
;
12587 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
12589 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
12593 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
12594 goto nla_put_failure
;
12596 cfg80211_send_cqm(msg
, gfp
);
12602 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
12604 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
12606 struct sk_buff
*msg
;
12608 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
12612 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
12613 goto nla_put_failure
;
12615 cfg80211_send_cqm(msg
, gfp
);
12621 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
12623 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
12624 struct net_device
*netdev
, const u8
*bssid
,
12625 const u8
*replay_ctr
, gfp_t gfp
)
12627 struct sk_buff
*msg
;
12628 struct nlattr
*rekey_attr
;
12631 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12635 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
12641 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12642 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12643 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
12644 goto nla_put_failure
;
12646 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
12648 goto nla_put_failure
;
12650 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
12651 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
12652 goto nla_put_failure
;
12654 nla_nest_end(msg
, rekey_attr
);
12656 genlmsg_end(msg
, hdr
);
12658 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12659 NL80211_MCGRP_MLME
, gfp
);
12663 genlmsg_cancel(msg
, hdr
);
12667 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
12668 const u8
*replay_ctr
, gfp_t gfp
)
12670 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12671 struct wiphy
*wiphy
= wdev
->wiphy
;
12672 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12674 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
12675 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
12677 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
12680 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
12681 struct net_device
*netdev
, int index
,
12682 const u8
*bssid
, bool preauth
, gfp_t gfp
)
12684 struct sk_buff
*msg
;
12685 struct nlattr
*attr
;
12688 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12692 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
12698 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12699 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
12700 goto nla_put_failure
;
12702 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
12704 goto nla_put_failure
;
12706 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
12707 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
12709 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
12710 goto nla_put_failure
;
12712 nla_nest_end(msg
, attr
);
12714 genlmsg_end(msg
, hdr
);
12716 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12717 NL80211_MCGRP_MLME
, gfp
);
12721 genlmsg_cancel(msg
, hdr
);
12725 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
12726 const u8
*bssid
, bool preauth
, gfp_t gfp
)
12728 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12729 struct wiphy
*wiphy
= wdev
->wiphy
;
12730 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12732 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
12733 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
12735 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
12737 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
12738 struct net_device
*netdev
,
12739 struct cfg80211_chan_def
*chandef
,
12741 enum nl80211_commands notif
,
12744 struct sk_buff
*msg
;
12747 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12751 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
12757 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
12758 goto nla_put_failure
;
12760 if (nl80211_send_chandef(msg
, chandef
))
12761 goto nla_put_failure
;
12763 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
12764 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
12765 goto nla_put_failure
;
12767 genlmsg_end(msg
, hdr
);
12769 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12770 NL80211_MCGRP_MLME
, gfp
);
12774 genlmsg_cancel(msg
, hdr
);
12778 void cfg80211_ch_switch_notify(struct net_device
*dev
,
12779 struct cfg80211_chan_def
*chandef
)
12781 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12782 struct wiphy
*wiphy
= wdev
->wiphy
;
12783 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12785 ASSERT_WDEV_LOCK(wdev
);
12787 trace_cfg80211_ch_switch_notify(dev
, chandef
);
12789 wdev
->chandef
= *chandef
;
12790 wdev
->preset_chandef
= *chandef
;
12791 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
12792 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
12794 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
12796 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
12797 struct cfg80211_chan_def
*chandef
,
12800 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12801 struct wiphy
*wiphy
= wdev
->wiphy
;
12802 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12804 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
12806 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
12807 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
12809 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
12812 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
12813 const struct cfg80211_chan_def
*chandef
,
12814 enum nl80211_radar_event event
,
12815 struct net_device
*netdev
, gfp_t gfp
)
12817 struct sk_buff
*msg
;
12820 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12824 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
12830 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
12831 goto nla_put_failure
;
12833 /* NOP and radar events don't need a netdev parameter */
12835 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
12837 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12838 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
12839 goto nla_put_failure
;
12842 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
12843 goto nla_put_failure
;
12845 if (nl80211_send_chandef(msg
, chandef
))
12846 goto nla_put_failure
;
12848 genlmsg_end(msg
, hdr
);
12850 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12851 NL80211_MCGRP_MLME
, gfp
);
12855 genlmsg_cancel(msg
, hdr
);
12859 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
12860 u64 cookie
, bool acked
, gfp_t gfp
)
12862 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12863 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12864 struct sk_buff
*msg
;
12867 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
12869 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12874 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
12880 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12881 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12882 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
12883 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
12884 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
12885 goto nla_put_failure
;
12887 genlmsg_end(msg
, hdr
);
12889 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12890 NL80211_MCGRP_MLME
, gfp
);
12894 genlmsg_cancel(msg
, hdr
);
12897 EXPORT_SYMBOL(cfg80211_probe_status
);
12899 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
12900 const u8
*frame
, size_t len
,
12901 int freq
, int sig_dbm
)
12903 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12904 struct sk_buff
*msg
;
12906 struct cfg80211_beacon_registration
*reg
;
12908 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
12910 spin_lock_bh(&rdev
->beacon_registrations_lock
);
12911 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
12912 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
12914 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12918 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
12920 goto nla_put_failure
;
12922 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12924 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
12926 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
12927 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
12928 goto nla_put_failure
;
12930 genlmsg_end(msg
, hdr
);
12932 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
12934 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12938 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12940 genlmsg_cancel(msg
, hdr
);
12943 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
12946 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
12947 struct cfg80211_wowlan_wakeup
*wakeup
)
12949 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
12950 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
12953 nl_results
= nla_nest_start(
12954 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
12958 for (i
= 0; i
< nd
->n_matches
; i
++) {
12959 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
12961 nl_match
= nla_nest_start(msg
, i
);
12965 /* The SSID attribute is optional in nl80211, but for
12966 * simplicity reasons it's always present in the
12967 * cfg80211 structure. If a driver can't pass the
12968 * SSID, that needs to be changed. A zero length SSID
12969 * is still a valid SSID (wildcard), so it cannot be
12970 * used for this purpose.
12972 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
12973 match
->ssid
.ssid
)) {
12974 nla_nest_cancel(msg
, nl_match
);
12978 if (match
->n_channels
) {
12979 nl_freqs
= nla_nest_start(
12980 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
12982 nla_nest_cancel(msg
, nl_match
);
12986 for (j
= 0; j
< match
->n_channels
; j
++) {
12987 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
12988 nla_nest_cancel(msg
, nl_freqs
);
12989 nla_nest_cancel(msg
, nl_match
);
12994 nla_nest_end(msg
, nl_freqs
);
12997 nla_nest_end(msg
, nl_match
);
13001 nla_nest_end(msg
, nl_results
);
13005 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
13006 struct cfg80211_wowlan_wakeup
*wakeup
,
13009 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13010 struct sk_buff
*msg
;
13014 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
13017 size
+= wakeup
->packet_present_len
;
13019 msg
= nlmsg_new(size
, gfp
);
13023 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
13027 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13028 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13031 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13032 wdev
->netdev
->ifindex
))
13036 struct nlattr
*reasons
;
13038 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
13042 if (wakeup
->disconnect
&&
13043 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
13045 if (wakeup
->magic_pkt
&&
13046 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
13048 if (wakeup
->gtk_rekey_failure
&&
13049 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
13051 if (wakeup
->eap_identity_req
&&
13052 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
13054 if (wakeup
->four_way_handshake
&&
13055 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
13057 if (wakeup
->rfkill_release
&&
13058 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
13061 if (wakeup
->pattern_idx
>= 0 &&
13062 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
13063 wakeup
->pattern_idx
))
13066 if (wakeup
->tcp_match
&&
13067 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
13070 if (wakeup
->tcp_connlost
&&
13071 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
13074 if (wakeup
->tcp_nomoretokens
&&
13076 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
13079 if (wakeup
->packet
) {
13080 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
13081 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
13083 if (!wakeup
->packet_80211
) {
13085 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
13087 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
13090 if (wakeup
->packet_len
&&
13091 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
13094 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
13099 if (wakeup
->net_detect
&&
13100 cfg80211_net_detect_results(msg
, wakeup
))
13103 nla_nest_end(msg
, reasons
);
13106 genlmsg_end(msg
, hdr
);
13108 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13109 NL80211_MCGRP_MLME
, gfp
);
13115 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
13118 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
13119 enum nl80211_tdls_operation oper
,
13120 u16 reason_code
, gfp_t gfp
)
13122 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13123 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13124 struct sk_buff
*msg
;
13127 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
13130 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13134 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
13140 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13141 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13142 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
13143 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
13144 (reason_code
> 0 &&
13145 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
13146 goto nla_put_failure
;
13148 genlmsg_end(msg
, hdr
);
13150 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13151 NL80211_MCGRP_MLME
, gfp
);
13155 genlmsg_cancel(msg
, hdr
);
13158 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
13160 static int nl80211_netlink_notify(struct notifier_block
* nb
,
13161 unsigned long state
,
13164 struct netlink_notify
*notify
= _notify
;
13165 struct cfg80211_registered_device
*rdev
;
13166 struct wireless_dev
*wdev
;
13167 struct cfg80211_beacon_registration
*reg
, *tmp
;
13169 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
13170 return NOTIFY_DONE
;
13174 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
13175 bool schedule_destroy_work
= false;
13176 struct cfg80211_sched_scan_request
*sched_scan_req
=
13177 rcu_dereference(rdev
->sched_scan_req
);
13179 if (sched_scan_req
&& notify
->portid
&&
13180 sched_scan_req
->owner_nlportid
== notify
->portid
) {
13181 sched_scan_req
->owner_nlportid
= 0;
13183 if (rdev
->ops
->sched_scan_stop
&&
13184 rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
13185 schedule_work(&rdev
->sched_scan_stop_wk
);
13188 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
) {
13189 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
13191 if (wdev
->owner_nlportid
== notify
->portid
)
13192 schedule_destroy_work
= true;
13195 spin_lock_bh(&rdev
->beacon_registrations_lock
);
13196 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
13198 if (reg
->nlportid
== notify
->portid
) {
13199 list_del(®
->list
);
13204 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
13206 if (schedule_destroy_work
) {
13207 struct cfg80211_iface_destroy
*destroy
;
13209 destroy
= kzalloc(sizeof(*destroy
), GFP_ATOMIC
);
13211 destroy
->nlportid
= notify
->portid
;
13212 spin_lock(&rdev
->destroy_list_lock
);
13213 list_add(&destroy
->list
, &rdev
->destroy_list
);
13214 spin_unlock(&rdev
->destroy_list_lock
);
13215 schedule_work(&rdev
->destroy_work
);
13223 * It is possible that the user space process that is controlling the
13224 * indoor setting disappeared, so notify the regulatory core.
13226 regulatory_netlink_notify(notify
->portid
);
13230 static struct notifier_block nl80211_netlink_notifier
= {
13231 .notifier_call
= nl80211_netlink_notify
,
13234 void cfg80211_ft_event(struct net_device
*netdev
,
13235 struct cfg80211_ft_event_params
*ft_event
)
13237 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
13238 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13239 struct sk_buff
*msg
;
13242 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
13244 if (!ft_event
->target_ap
)
13247 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13251 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
13255 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13256 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13257 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
13260 if (ft_event
->ies
&&
13261 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
13263 if (ft_event
->ric_ies
&&
13264 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
13265 ft_event
->ric_ies
))
13268 genlmsg_end(msg
, hdr
);
13270 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13271 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13276 EXPORT_SYMBOL(cfg80211_ft_event
);
13278 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
13280 struct cfg80211_registered_device
*rdev
;
13281 struct sk_buff
*msg
;
13285 rdev
= wiphy_to_rdev(wdev
->wiphy
);
13286 if (!rdev
->crit_proto_nlportid
)
13289 nlportid
= rdev
->crit_proto_nlportid
;
13290 rdev
->crit_proto_nlportid
= 0;
13292 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13296 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
13298 goto nla_put_failure
;
13300 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13301 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13302 goto nla_put_failure
;
13304 genlmsg_end(msg
, hdr
);
13306 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
13311 genlmsg_cancel(msg
, hdr
);
13315 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
13317 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
13319 struct wiphy
*wiphy
= wdev
->wiphy
;
13320 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13321 struct sk_buff
*msg
;
13324 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13328 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
13332 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13333 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
13334 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13337 genlmsg_end(msg
, hdr
);
13339 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
13340 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13346 /* initialisation/exit functions */
13348 int nl80211_init(void)
13352 err
= genl_register_family_with_ops_groups(&nl80211_fam
, nl80211_ops
,
13357 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
13363 genl_unregister_family(&nl80211_fam
);
13367 void nl80211_exit(void)
13369 netlink_unregister_notifier(&nl80211_netlink_notifier
);
13370 genl_unregister_family(&nl80211_fam
);