2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright 2015 Intel Deutschland GmbH
10 #include <linux/module.h>
11 #include <linux/err.h>
12 #include <linux/slab.h>
13 #include <linux/list.h>
14 #include <linux/if_ether.h>
15 #include <linux/ieee80211.h>
16 #include <linux/nl80211.h>
17 #include <linux/rtnetlink.h>
18 #include <linux/netlink.h>
19 #include <linux/etherdevice.h>
20 #include <net/net_namespace.h>
21 #include <net/genetlink.h>
22 #include <net/cfg80211.h>
24 #include <net/inet_connection_sock.h>
30 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
31 struct genl_info
*info
,
32 struct cfg80211_crypto_settings
*settings
,
35 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
37 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
38 struct genl_info
*info
);
40 /* the netlink family */
41 static struct genl_family nl80211_fam
= {
42 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
43 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
44 .hdrsize
= 0, /* no private header */
45 .version
= 1, /* no particular meaning now */
46 .maxattr
= NL80211_ATTR_MAX
,
48 .pre_doit
= nl80211_pre_doit
,
49 .post_doit
= nl80211_post_doit
,
52 /* multicast groups */
53 enum nl80211_multicast_groups
{
56 NL80211_MCGRP_REGULATORY
,
59 NL80211_MCGRP_TESTMODE
/* keep last - ifdef! */
62 static const struct genl_multicast_group nl80211_mcgrps
[] = {
63 [NL80211_MCGRP_CONFIG
] = { .name
= NL80211_MULTICAST_GROUP_CONFIG
},
64 [NL80211_MCGRP_SCAN
] = { .name
= NL80211_MULTICAST_GROUP_SCAN
},
65 [NL80211_MCGRP_REGULATORY
] = { .name
= NL80211_MULTICAST_GROUP_REG
},
66 [NL80211_MCGRP_MLME
] = { .name
= NL80211_MULTICAST_GROUP_MLME
},
67 [NL80211_MCGRP_VENDOR
] = { .name
= NL80211_MULTICAST_GROUP_VENDOR
},
68 #ifdef CONFIG_NL80211_TESTMODE
69 [NL80211_MCGRP_TESTMODE
] = { .name
= NL80211_MULTICAST_GROUP_TESTMODE
}
73 /* returns ERR_PTR values */
74 static struct wireless_dev
*
75 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
77 struct cfg80211_registered_device
*rdev
;
78 struct wireless_dev
*result
= NULL
;
79 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
80 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
87 if (!have_ifidx
&& !have_wdev_id
)
88 return ERR_PTR(-EINVAL
);
91 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
93 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
94 wiphy_idx
= wdev_id
>> 32;
97 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
98 struct wireless_dev
*wdev
;
100 if (wiphy_net(&rdev
->wiphy
) != netns
)
103 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
106 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
107 if (have_ifidx
&& wdev
->netdev
&&
108 wdev
->netdev
->ifindex
== ifidx
) {
112 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
124 return ERR_PTR(-ENODEV
);
127 static struct cfg80211_registered_device
*
128 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
130 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
131 struct net_device
*netdev
;
135 if (!attrs
[NL80211_ATTR_WIPHY
] &&
136 !attrs
[NL80211_ATTR_IFINDEX
] &&
137 !attrs
[NL80211_ATTR_WDEV
])
138 return ERR_PTR(-EINVAL
);
140 if (attrs
[NL80211_ATTR_WIPHY
])
141 rdev
= cfg80211_rdev_by_wiphy_idx(
142 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
144 if (attrs
[NL80211_ATTR_WDEV
]) {
145 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
146 struct wireless_dev
*wdev
;
149 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
151 /* make sure wdev exists */
152 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
153 if (wdev
->identifier
!= (u32
)wdev_id
)
162 if (rdev
&& tmp
!= rdev
)
163 return ERR_PTR(-EINVAL
);
168 if (attrs
[NL80211_ATTR_IFINDEX
]) {
169 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
170 netdev
= __dev_get_by_index(netns
, ifindex
);
172 if (netdev
->ieee80211_ptr
)
174 netdev
->ieee80211_ptr
->wiphy
);
178 /* not wireless device -- return error */
180 return ERR_PTR(-EINVAL
);
182 /* mismatch -- return error */
183 if (rdev
&& tmp
!= rdev
)
184 return ERR_PTR(-EINVAL
);
191 return ERR_PTR(-ENODEV
);
193 if (netns
!= wiphy_net(&rdev
->wiphy
))
194 return ERR_PTR(-ENODEV
);
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
206 static struct cfg80211_registered_device
*
207 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
209 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
212 /* policy for the attributes */
213 static const struct nla_policy nl80211_policy
[NUM_NL80211_ATTR
] = {
214 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
215 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
217 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
219 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
221 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
222 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
225 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
226 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
230 [NL80211_ATTR_WIPHY_DYN_ACK
] = { .type
= NLA_FLAG
},
232 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
233 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
236 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
237 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
239 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
240 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
241 .len
= WLAN_MAX_KEY_LEN
},
242 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
243 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
244 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
245 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
246 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
248 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
249 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
251 .len
= IEEE80211_MAX_DATA_LEN
},
252 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
253 .len
= IEEE80211_MAX_DATA_LEN
},
254 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
255 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
256 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
257 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
258 .len
= NL80211_MAX_SUPP_RATES
},
259 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
260 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
261 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
262 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
263 .len
= IEEE80211_MAX_MESH_ID_LEN
},
264 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
266 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
267 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
269 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
273 .len
= NL80211_MAX_SUPP_RATES
},
274 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
276 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
277 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
279 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
281 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
282 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
283 .len
= IEEE80211_MAX_DATA_LEN
},
284 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
285 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
287 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
288 .len
= IEEE80211_MAX_SSID_LEN
},
289 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
290 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
291 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
292 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
293 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
294 [NL80211_ATTR_STA_FLAGS2
] = {
295 .len
= sizeof(struct nl80211_sta_flag_update
),
297 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
302 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
303 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
305 [NL80211_ATTR_PMKID
] = { .len
= WLAN_PMKID_LEN
},
306 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
307 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
308 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
309 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
310 .len
= IEEE80211_MAX_DATA_LEN
},
311 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
312 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
313 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
314 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
315 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
318 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
319 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
323 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
324 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
325 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
326 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
327 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
328 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
329 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
331 .len
= IEEE80211_MAX_DATA_LEN
},
332 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
333 .len
= IEEE80211_MAX_DATA_LEN
},
334 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
335 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
336 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
337 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
339 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
340 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
342 [NL80211_ATTR_TDLS_INITIATOR
] = { .type
= NLA_FLAG
},
343 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
345 .len
= IEEE80211_MAX_DATA_LEN
},
346 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
347 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
348 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
349 .len
= NL80211_HT_CAPABILITY_LEN
351 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
352 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
353 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
354 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
355 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
356 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
357 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
358 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
359 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
360 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
361 [NL80211_ATTR_LOCAL_MESH_POWER_MODE
] = {. type
= NLA_U32
},
362 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
363 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
364 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
365 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
366 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
367 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
368 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
369 .len
= NL80211_VHT_CAPABILITY_LEN
,
371 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
372 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
373 .len
= IEEE80211_MAX_DATA_LEN
},
374 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
375 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
377 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
378 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_BINARY
},
379 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_BINARY
},
380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
382 [NL80211_ATTR_HANDLE_DFS
] = { .type
= NLA_FLAG
},
383 [NL80211_ATTR_OPMODE_NOTIF
] = { .type
= NLA_U8
},
384 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
385 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
386 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
387 [NL80211_ATTR_QOS_MAP
] = { .type
= NLA_BINARY
,
388 .len
= IEEE80211_QOS_MAP_LEN_MAX
},
389 [NL80211_ATTR_MAC_HINT
] = { .len
= ETH_ALEN
},
390 [NL80211_ATTR_WIPHY_FREQ_HINT
] = { .type
= NLA_U32
},
391 [NL80211_ATTR_TDLS_PEER_CAPABILITY
] = { .type
= NLA_U32
},
392 [NL80211_ATTR_SOCKET_OWNER
] = { .type
= NLA_FLAG
},
393 [NL80211_ATTR_CSA_C_OFFSETS_TX
] = { .type
= NLA_BINARY
},
394 [NL80211_ATTR_USE_RRM
] = { .type
= NLA_FLAG
},
395 [NL80211_ATTR_TSID
] = { .type
= NLA_U8
},
396 [NL80211_ATTR_USER_PRIO
] = { .type
= NLA_U8
},
397 [NL80211_ATTR_ADMITTED_TIME
] = { .type
= NLA_U16
},
398 [NL80211_ATTR_SMPS_MODE
] = { .type
= NLA_U8
},
399 [NL80211_ATTR_MAC_MASK
] = { .len
= ETH_ALEN
},
400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG
] = { .type
= NLA_FLAG
},
401 [NL80211_ATTR_NETNS_FD
] = { .type
= NLA_U32
},
402 [NL80211_ATTR_SCHED_SCAN_DELAY
] = { .type
= NLA_U32
},
403 [NL80211_ATTR_REG_INDOOR
] = { .type
= NLA_FLAG
},
406 /* policy for the key attributes */
407 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
408 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
409 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
410 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
411 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
412 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
413 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
414 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
415 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
418 /* policy for the key default flags */
419 static const struct nla_policy
420 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
421 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
422 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
425 /* policy for WoWLAN attributes */
426 static const struct nla_policy
427 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
428 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
429 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
430 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
431 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
432 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
433 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
434 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
435 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
436 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
437 [NL80211_WOWLAN_TRIG_NET_DETECT
] = { .type
= NLA_NESTED
},
440 static const struct nla_policy
441 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
442 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
443 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
444 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
445 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
446 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
448 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
449 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
451 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
452 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
454 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
455 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
456 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
459 /* policy for coalesce rule attributes */
460 static const struct nla_policy
461 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
462 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
463 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
464 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
467 /* policy for GTK rekey offload attributes */
468 static const struct nla_policy
469 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
470 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
471 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
472 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
475 static const struct nla_policy
476 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
477 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
478 .len
= IEEE80211_MAX_SSID_LEN
},
479 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
482 static const struct nla_policy
483 nl80211_plan_policy
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1] = {
484 [NL80211_SCHED_SCAN_PLAN_INTERVAL
] = { .type
= NLA_U32
},
485 [NL80211_SCHED_SCAN_PLAN_ITERATIONS
] = { .type
= NLA_U32
},
488 /* policy for packet pattern attributes */
489 static const struct nla_policy
490 nl80211_packet_pattern_policy
[MAX_NL80211_PKTPAT
+ 1] = {
491 [NL80211_PKTPAT_MASK
] = { .type
= NLA_BINARY
, },
492 [NL80211_PKTPAT_PATTERN
] = { .type
= NLA_BINARY
, },
493 [NL80211_PKTPAT_OFFSET
] = { .type
= NLA_U32
},
496 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
497 struct netlink_callback
*cb
,
498 struct cfg80211_registered_device
**rdev
,
499 struct wireless_dev
**wdev
)
504 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
505 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
510 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
511 nl80211_fam
.attrbuf
);
513 return PTR_ERR(*wdev
);
514 *rdev
= wiphy_to_rdev((*wdev
)->wiphy
);
515 /* 0 is the first index - add 1 to parse only once */
516 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
517 cb
->args
[1] = (*wdev
)->identifier
;
519 /* subtract the 1 again here */
520 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
521 struct wireless_dev
*tmp
;
525 *rdev
= wiphy_to_rdev(wiphy
);
528 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
529 if (tmp
->identifier
== cb
->args
[1]) {
543 static bool is_valid_ie_attr(const struct nlattr
*attr
)
551 pos
= nla_data(attr
);
572 /* message building helper */
573 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
576 /* since there is no private header just add the generic one */
577 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
580 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
581 struct ieee80211_channel
*chan
,
584 /* Some channels must be completely excluded from the
585 * list to protect old user-space tools from breaking
587 if (!large
&& chan
->flags
&
588 (IEEE80211_CHAN_NO_10MHZ
| IEEE80211_CHAN_NO_20MHZ
))
591 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
593 goto nla_put_failure
;
595 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
596 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
597 goto nla_put_failure
;
598 if (chan
->flags
& IEEE80211_CHAN_NO_IR
) {
599 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IR
))
600 goto nla_put_failure
;
601 if (nla_put_flag(msg
, __NL80211_FREQUENCY_ATTR_NO_IBSS
))
602 goto nla_put_failure
;
604 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
605 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
606 goto nla_put_failure
;
610 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
612 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
614 goto nla_put_failure
;
615 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
617 goto nla_put_failure
;
619 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME
,
621 goto nla_put_failure
;
626 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
627 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
628 goto nla_put_failure
;
629 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
630 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
631 goto nla_put_failure
;
632 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
633 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
634 goto nla_put_failure
;
635 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
636 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
637 goto nla_put_failure
;
638 if ((chan
->flags
& IEEE80211_CHAN_INDOOR_ONLY
) &&
639 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_INDOOR_ONLY
))
640 goto nla_put_failure
;
641 if ((chan
->flags
& IEEE80211_CHAN_IR_CONCURRENT
) &&
642 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_IR_CONCURRENT
))
643 goto nla_put_failure
;
644 if ((chan
->flags
& IEEE80211_CHAN_NO_20MHZ
) &&
645 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_20MHZ
))
646 goto nla_put_failure
;
647 if ((chan
->flags
& IEEE80211_CHAN_NO_10MHZ
) &&
648 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_10MHZ
))
649 goto nla_put_failure
;
652 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
653 DBM_TO_MBM(chan
->max_power
)))
654 goto nla_put_failure
;
662 /* netlink command implementations */
669 bool def_uni
, def_multi
;
672 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
674 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
675 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
680 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
681 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
690 if (tb
[NL80211_KEY_IDX
])
691 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
693 if (tb
[NL80211_KEY_DATA
]) {
694 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
695 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
698 if (tb
[NL80211_KEY_SEQ
]) {
699 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
700 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
703 if (tb
[NL80211_KEY_CIPHER
])
704 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
706 if (tb
[NL80211_KEY_TYPE
]) {
707 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
708 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
712 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
713 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
714 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
715 tb
[NL80211_KEY_DEFAULT_TYPES
],
716 nl80211_key_default_policy
);
720 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
721 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
727 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
729 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
730 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
731 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
734 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
735 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
736 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
739 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
740 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
742 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
743 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
745 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
746 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
755 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
756 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
757 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
761 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
762 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
763 int err
= nla_parse_nested(
764 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
765 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
766 nl80211_key_default_policy
);
770 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
771 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
777 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
781 memset(k
, 0, sizeof(*k
));
785 if (info
->attrs
[NL80211_ATTR_KEY
])
786 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
788 err
= nl80211_parse_key_old(info
, k
);
793 if (k
->def
&& k
->defmgmt
)
797 if (k
->def_uni
|| !k
->def_multi
)
803 if (k
->idx
< 4 || k
->idx
> 5)
806 if (k
->idx
< 0 || k
->idx
> 3)
809 if (k
->idx
< 0 || k
->idx
> 5)
817 static struct cfg80211_cached_keys
*
818 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
819 struct nlattr
*keys
, bool *no_ht
)
821 struct key_parse parse
;
823 struct cfg80211_cached_keys
*result
;
824 int rem
, err
, def
= 0;
826 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
828 return ERR_PTR(-ENOMEM
);
831 result
->defmgmt
= -1;
833 nla_for_each_nested(key
, keys
, rem
) {
834 memset(&parse
, 0, sizeof(parse
));
837 err
= nl80211_parse_key_new(key
, &parse
);
843 if (parse
.idx
< 0 || parse
.idx
> 4)
849 result
->def
= parse
.idx
;
850 if (!parse
.def_uni
|| !parse
.def_multi
)
852 } else if (parse
.defmgmt
)
854 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
855 parse
.idx
, false, NULL
);
858 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
859 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
860 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
861 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
863 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
864 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
876 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
878 ASSERT_WDEV_LOCK(wdev
);
880 switch (wdev
->iftype
) {
881 case NL80211_IFTYPE_AP
:
882 case NL80211_IFTYPE_AP_VLAN
:
883 case NL80211_IFTYPE_P2P_GO
:
884 case NL80211_IFTYPE_MESH_POINT
:
886 case NL80211_IFTYPE_ADHOC
:
887 case NL80211_IFTYPE_STATION
:
888 case NL80211_IFTYPE_P2P_CLIENT
:
889 if (!wdev
->current_bss
)
892 case NL80211_IFTYPE_UNSPECIFIED
:
893 case NL80211_IFTYPE_OCB
:
894 case NL80211_IFTYPE_MONITOR
:
895 case NL80211_IFTYPE_P2P_DEVICE
:
896 case NL80211_IFTYPE_WDS
:
897 case NUM_NL80211_IFTYPES
:
904 static struct ieee80211_channel
*nl80211_get_valid_chan(struct wiphy
*wiphy
,
907 struct ieee80211_channel
*chan
;
911 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(tb
));
912 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
917 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
919 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
923 goto nla_put_failure
;
927 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
928 goto nla_put_failure
;
933 nla_nest_end(msg
, nl_modes
);
940 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
944 struct nlattr
*nl_combis
;
947 nl_combis
= nla_nest_start(msg
,
948 NL80211_ATTR_INTERFACE_COMBINATIONS
);
950 goto nla_put_failure
;
952 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
953 const struct ieee80211_iface_combination
*c
;
954 struct nlattr
*nl_combi
, *nl_limits
;
956 c
= &wiphy
->iface_combinations
[i
];
958 nl_combi
= nla_nest_start(msg
, i
+ 1);
960 goto nla_put_failure
;
962 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
964 goto nla_put_failure
;
966 for (j
= 0; j
< c
->n_limits
; j
++) {
967 struct nlattr
*nl_limit
;
969 nl_limit
= nla_nest_start(msg
, j
+ 1);
971 goto nla_put_failure
;
972 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
974 goto nla_put_failure
;
975 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
977 goto nla_put_failure
;
978 nla_nest_end(msg
, nl_limit
);
981 nla_nest_end(msg
, nl_limits
);
983 if (c
->beacon_int_infra_match
&&
984 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
985 goto nla_put_failure
;
986 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
987 c
->num_different_channels
) ||
988 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
990 goto nla_put_failure
;
992 (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
993 c
->radar_detect_widths
) ||
994 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS
,
995 c
->radar_detect_regions
)))
996 goto nla_put_failure
;
998 nla_nest_end(msg
, nl_combi
);
1001 nla_nest_end(msg
, nl_combis
);
1009 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
1010 struct sk_buff
*msg
)
1012 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
1013 struct nlattr
*nl_tcp
;
1018 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
1022 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1023 tcp
->data_payload_max
))
1026 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
1027 tcp
->data_payload_max
))
1030 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
1033 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
1034 sizeof(*tcp
->tok
), tcp
->tok
))
1037 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
1038 tcp
->data_interval_max
))
1041 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
1042 tcp
->wake_payload_max
))
1045 nla_nest_end(msg
, nl_tcp
);
1049 static int nl80211_send_wowlan(struct sk_buff
*msg
,
1050 struct cfg80211_registered_device
*rdev
,
1053 struct nlattr
*nl_wowlan
;
1055 if (!rdev
->wiphy
.wowlan
)
1058 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1062 if (((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
1063 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1064 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1065 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1066 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1067 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1068 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1069 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1070 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1071 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1072 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1073 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1074 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1075 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1076 ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1077 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1080 if (rdev
->wiphy
.wowlan
->n_patterns
) {
1081 struct nl80211_pattern_support pat
= {
1082 .max_patterns
= rdev
->wiphy
.wowlan
->n_patterns
,
1083 .min_pattern_len
= rdev
->wiphy
.wowlan
->pattern_min_len
,
1084 .max_pattern_len
= rdev
->wiphy
.wowlan
->pattern_max_len
,
1085 .max_pkt_offset
= rdev
->wiphy
.wowlan
->max_pkt_offset
,
1088 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1093 if ((rdev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
) &&
1094 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
,
1095 rdev
->wiphy
.wowlan
->max_nd_match_sets
))
1098 if (large
&& nl80211_send_wowlan_tcp_caps(rdev
, msg
))
1101 nla_nest_end(msg
, nl_wowlan
);
1107 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1108 struct cfg80211_registered_device
*rdev
)
1110 struct nl80211_coalesce_rule_support rule
;
1112 if (!rdev
->wiphy
.coalesce
)
1115 rule
.max_rules
= rdev
->wiphy
.coalesce
->n_rules
;
1116 rule
.max_delay
= rdev
->wiphy
.coalesce
->max_delay
;
1117 rule
.pat
.max_patterns
= rdev
->wiphy
.coalesce
->n_patterns
;
1118 rule
.pat
.min_pattern_len
= rdev
->wiphy
.coalesce
->pattern_min_len
;
1119 rule
.pat
.max_pattern_len
= rdev
->wiphy
.coalesce
->pattern_max_len
;
1120 rule
.pat
.max_pkt_offset
= rdev
->wiphy
.coalesce
->max_pkt_offset
;
1122 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1128 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1129 struct ieee80211_supported_band
*sband
)
1131 struct nlattr
*nl_rates
, *nl_rate
;
1132 struct ieee80211_rate
*rate
;
1136 if (sband
->ht_cap
.ht_supported
&&
1137 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1138 sizeof(sband
->ht_cap
.mcs
),
1139 &sband
->ht_cap
.mcs
) ||
1140 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1141 sband
->ht_cap
.cap
) ||
1142 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1143 sband
->ht_cap
.ampdu_factor
) ||
1144 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1145 sband
->ht_cap
.ampdu_density
)))
1149 if (sband
->vht_cap
.vht_supported
&&
1150 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1151 sizeof(sband
->vht_cap
.vht_mcs
),
1152 &sband
->vht_cap
.vht_mcs
) ||
1153 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1154 sband
->vht_cap
.cap
)))
1158 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1162 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1163 nl_rate
= nla_nest_start(msg
, i
);
1167 rate
= &sband
->bitrates
[i
];
1168 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1171 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1173 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1176 nla_nest_end(msg
, nl_rate
);
1179 nla_nest_end(msg
, nl_rates
);
1185 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1186 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1189 struct nlattr
*nl_ftypes
, *nl_ifs
;
1190 enum nl80211_iftype ift
;
1196 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1200 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1201 nl_ftypes
= nla_nest_start(msg
, ift
);
1205 stypes
= mgmt_stypes
[ift
].tx
;
1208 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1209 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1214 nla_nest_end(msg
, nl_ftypes
);
1217 nla_nest_end(msg
, nl_ifs
);
1219 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1223 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1224 nl_ftypes
= nla_nest_start(msg
, ift
);
1228 stypes
= mgmt_stypes
[ift
].rx
;
1231 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1232 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1237 nla_nest_end(msg
, nl_ftypes
);
1239 nla_nest_end(msg
, nl_ifs
);
1244 struct nl80211_dump_wiphy_state
{
1247 long split_start
, band_start
, chan_start
;
1251 static int nl80211_send_wiphy(struct cfg80211_registered_device
*rdev
,
1252 enum nl80211_commands cmd
,
1253 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1254 int flags
, struct nl80211_dump_wiphy_state
*state
)
1257 struct nlattr
*nl_bands
, *nl_band
;
1258 struct nlattr
*nl_freqs
, *nl_freq
;
1259 struct nlattr
*nl_cmds
;
1260 enum nl80211_band band
;
1261 struct ieee80211_channel
*chan
;
1263 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1264 rdev
->wiphy
.mgmt_stypes
;
1267 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
1271 if (WARN_ON(!state
))
1274 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1275 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1276 wiphy_name(&rdev
->wiphy
)) ||
1277 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1278 cfg80211_rdev_list_generation
))
1279 goto nla_put_failure
;
1281 if (cmd
!= NL80211_CMD_NEW_WIPHY
)
1284 switch (state
->split_start
) {
1286 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1287 rdev
->wiphy
.retry_short
) ||
1288 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1289 rdev
->wiphy
.retry_long
) ||
1290 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1291 rdev
->wiphy
.frag_threshold
) ||
1292 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1293 rdev
->wiphy
.rts_threshold
) ||
1294 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1295 rdev
->wiphy
.coverage_class
) ||
1296 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1297 rdev
->wiphy
.max_scan_ssids
) ||
1298 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1299 rdev
->wiphy
.max_sched_scan_ssids
) ||
1300 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1301 rdev
->wiphy
.max_scan_ie_len
) ||
1302 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1303 rdev
->wiphy
.max_sched_scan_ie_len
) ||
1304 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1305 rdev
->wiphy
.max_match_sets
) ||
1306 nla_put_u32(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS
,
1307 rdev
->wiphy
.max_sched_scan_plans
) ||
1308 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL
,
1309 rdev
->wiphy
.max_sched_scan_plan_interval
) ||
1310 nla_put_u32(msg
, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS
,
1311 rdev
->wiphy
.max_sched_scan_plan_iterations
))
1312 goto nla_put_failure
;
1314 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1315 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1316 goto nla_put_failure
;
1317 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1318 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1319 goto nla_put_failure
;
1320 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1321 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1322 goto nla_put_failure
;
1323 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1324 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1325 goto nla_put_failure
;
1326 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1327 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1328 goto nla_put_failure
;
1329 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1330 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1331 goto nla_put_failure
;
1332 state
->split_start
++;
1336 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1337 sizeof(u32
) * rdev
->wiphy
.n_cipher_suites
,
1338 rdev
->wiphy
.cipher_suites
))
1339 goto nla_put_failure
;
1341 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1342 rdev
->wiphy
.max_num_pmkids
))
1343 goto nla_put_failure
;
1345 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1346 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1347 goto nla_put_failure
;
1349 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1350 rdev
->wiphy
.available_antennas_tx
) ||
1351 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1352 rdev
->wiphy
.available_antennas_rx
))
1353 goto nla_put_failure
;
1355 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1356 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1357 rdev
->wiphy
.probe_resp_offload
))
1358 goto nla_put_failure
;
1360 if ((rdev
->wiphy
.available_antennas_tx
||
1361 rdev
->wiphy
.available_antennas_rx
) &&
1362 rdev
->ops
->get_antenna
) {
1363 u32 tx_ant
= 0, rx_ant
= 0;
1365 res
= rdev_get_antenna(rdev
, &tx_ant
, &rx_ant
);
1367 if (nla_put_u32(msg
,
1368 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1371 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1373 goto nla_put_failure
;
1377 state
->split_start
++;
1381 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1382 rdev
->wiphy
.interface_modes
))
1383 goto nla_put_failure
;
1384 state
->split_start
++;
1388 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1390 goto nla_put_failure
;
1392 for (band
= state
->band_start
;
1393 band
< NUM_NL80211_BANDS
; band
++) {
1394 struct ieee80211_supported_band
*sband
;
1396 sband
= rdev
->wiphy
.bands
[band
];
1401 nl_band
= nla_nest_start(msg
, band
);
1403 goto nla_put_failure
;
1405 switch (state
->chan_start
) {
1407 if (nl80211_send_band_rateinfo(msg
, sband
))
1408 goto nla_put_failure
;
1409 state
->chan_start
++;
1413 /* add frequencies */
1414 nl_freqs
= nla_nest_start(
1415 msg
, NL80211_BAND_ATTR_FREQS
);
1417 goto nla_put_failure
;
1419 for (i
= state
->chan_start
- 1;
1420 i
< sband
->n_channels
;
1422 nl_freq
= nla_nest_start(msg
, i
);
1424 goto nla_put_failure
;
1426 chan
= &sband
->channels
[i
];
1428 if (nl80211_msg_put_channel(
1431 goto nla_put_failure
;
1433 nla_nest_end(msg
, nl_freq
);
1437 if (i
< sband
->n_channels
)
1438 state
->chan_start
= i
+ 2;
1440 state
->chan_start
= 0;
1441 nla_nest_end(msg
, nl_freqs
);
1444 nla_nest_end(msg
, nl_band
);
1447 /* start again here */
1448 if (state
->chan_start
)
1453 nla_nest_end(msg
, nl_bands
);
1455 if (band
< NUM_NL80211_BANDS
)
1456 state
->band_start
= band
+ 1;
1458 state
->band_start
= 0;
1460 /* if bands & channels are done, continue outside */
1461 if (state
->band_start
== 0 && state
->chan_start
== 0)
1462 state
->split_start
++;
1466 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1468 goto nla_put_failure
;
1471 #define CMD(op, n) \
1473 if (rdev->ops->op) { \
1475 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1476 goto nla_put_failure; \
1480 CMD(add_virtual_intf
, NEW_INTERFACE
);
1481 CMD(change_virtual_intf
, SET_INTERFACE
);
1482 CMD(add_key
, NEW_KEY
);
1483 CMD(start_ap
, START_AP
);
1484 CMD(add_station
, NEW_STATION
);
1485 CMD(add_mpath
, NEW_MPATH
);
1486 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1487 CMD(change_bss
, SET_BSS
);
1488 CMD(auth
, AUTHENTICATE
);
1489 CMD(assoc
, ASSOCIATE
);
1490 CMD(deauth
, DEAUTHENTICATE
);
1491 CMD(disassoc
, DISASSOCIATE
);
1492 CMD(join_ibss
, JOIN_IBSS
);
1493 CMD(join_mesh
, JOIN_MESH
);
1494 CMD(set_pmksa
, SET_PMKSA
);
1495 CMD(del_pmksa
, DEL_PMKSA
);
1496 CMD(flush_pmksa
, FLUSH_PMKSA
);
1497 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1498 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1499 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1500 CMD(mgmt_tx
, FRAME
);
1501 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1502 if (rdev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1504 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1505 goto nla_put_failure
;
1507 if (rdev
->ops
->set_monitor_channel
|| rdev
->ops
->start_ap
||
1508 rdev
->ops
->join_mesh
) {
1510 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1511 goto nla_put_failure
;
1513 CMD(set_wds_peer
, SET_WDS_PEER
);
1514 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1515 CMD(tdls_mgmt
, TDLS_MGMT
);
1516 CMD(tdls_oper
, TDLS_OPER
);
1518 if (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1519 CMD(sched_scan_start
, START_SCHED_SCAN
);
1520 CMD(probe_client
, PROBE_CLIENT
);
1521 CMD(set_noack_map
, SET_NOACK_MAP
);
1522 if (rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1524 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1525 goto nla_put_failure
;
1527 CMD(start_p2p_device
, START_P2P_DEVICE
);
1528 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1529 #ifdef CONFIG_NL80211_TESTMODE
1530 CMD(testmode_cmd
, TESTMODE
);
1533 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1534 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1535 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1536 CMD(channel_switch
, CHANNEL_SWITCH
);
1537 CMD(set_qos_map
, SET_QOS_MAP
);
1538 if (rdev
->wiphy
.features
&
1539 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
)
1540 CMD(add_tx_ts
, ADD_TX_TS
);
1542 /* add into the if now */
1545 if (rdev
->ops
->connect
|| rdev
->ops
->auth
) {
1547 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1548 goto nla_put_failure
;
1551 if (rdev
->ops
->disconnect
|| rdev
->ops
->deauth
) {
1553 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1554 goto nla_put_failure
;
1557 nla_nest_end(msg
, nl_cmds
);
1558 state
->split_start
++;
1562 if (rdev
->ops
->remain_on_channel
&&
1563 (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1565 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1566 rdev
->wiphy
.max_remain_on_channel_duration
))
1567 goto nla_put_failure
;
1569 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1570 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1571 goto nla_put_failure
;
1573 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1574 goto nla_put_failure
;
1575 state
->split_start
++;
1580 if (nl80211_send_wowlan(msg
, rdev
, state
->split
))
1581 goto nla_put_failure
;
1582 state
->split_start
++;
1586 state
->split_start
++;
1589 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1590 rdev
->wiphy
.software_iftypes
))
1591 goto nla_put_failure
;
1593 if (nl80211_put_iface_combinations(&rdev
->wiphy
, msg
,
1595 goto nla_put_failure
;
1597 state
->split_start
++;
1601 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1602 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1603 rdev
->wiphy
.ap_sme_capa
))
1604 goto nla_put_failure
;
1606 features
= rdev
->wiphy
.features
;
1608 * We can only add the per-channel limit information if the
1609 * dump is split, otherwise it makes it too big. Therefore
1610 * only advertise it in that case.
1613 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1614 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1615 goto nla_put_failure
;
1617 if (rdev
->wiphy
.ht_capa_mod_mask
&&
1618 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1619 sizeof(*rdev
->wiphy
.ht_capa_mod_mask
),
1620 rdev
->wiphy
.ht_capa_mod_mask
))
1621 goto nla_put_failure
;
1623 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1624 rdev
->wiphy
.max_acl_mac_addrs
&&
1625 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1626 rdev
->wiphy
.max_acl_mac_addrs
))
1627 goto nla_put_failure
;
1630 * Any information below this point is only available to
1631 * applications that can deal with it being split. This
1632 * helps ensure that newly added capabilities don't break
1633 * older tools by overrunning their buffers.
1635 * We still increment split_start so that in the split
1636 * case we'll continue with more data in the next round,
1637 * but break unconditionally so unsplit data stops here.
1639 state
->split_start
++;
1642 if (rdev
->wiphy
.extended_capabilities
&&
1643 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1644 rdev
->wiphy
.extended_capabilities_len
,
1645 rdev
->wiphy
.extended_capabilities
) ||
1646 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1647 rdev
->wiphy
.extended_capabilities_len
,
1648 rdev
->wiphy
.extended_capabilities_mask
)))
1649 goto nla_put_failure
;
1651 if (rdev
->wiphy
.vht_capa_mod_mask
&&
1652 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1653 sizeof(*rdev
->wiphy
.vht_capa_mod_mask
),
1654 rdev
->wiphy
.vht_capa_mod_mask
))
1655 goto nla_put_failure
;
1657 state
->split_start
++;
1660 if (nl80211_send_coalesce(msg
, rdev
))
1661 goto nla_put_failure
;
1663 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1664 (nla_put_flag(msg
, NL80211_ATTR_SUPPORT_5_MHZ
) ||
1665 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_10_MHZ
)))
1666 goto nla_put_failure
;
1668 if (rdev
->wiphy
.max_ap_assoc_sta
&&
1669 nla_put_u32(msg
, NL80211_ATTR_MAX_AP_ASSOC_STA
,
1670 rdev
->wiphy
.max_ap_assoc_sta
))
1671 goto nla_put_failure
;
1673 state
->split_start
++;
1676 if (rdev
->wiphy
.n_vendor_commands
) {
1677 const struct nl80211_vendor_cmd_info
*info
;
1678 struct nlattr
*nested
;
1680 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1682 goto nla_put_failure
;
1684 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
1685 info
= &rdev
->wiphy
.vendor_commands
[i
].info
;
1686 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1687 goto nla_put_failure
;
1689 nla_nest_end(msg
, nested
);
1692 if (rdev
->wiphy
.n_vendor_events
) {
1693 const struct nl80211_vendor_cmd_info
*info
;
1694 struct nlattr
*nested
;
1696 nested
= nla_nest_start(msg
,
1697 NL80211_ATTR_VENDOR_EVENTS
);
1699 goto nla_put_failure
;
1701 for (i
= 0; i
< rdev
->wiphy
.n_vendor_events
; i
++) {
1702 info
= &rdev
->wiphy
.vendor_events
[i
];
1703 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1704 goto nla_put_failure
;
1706 nla_nest_end(msg
, nested
);
1708 state
->split_start
++;
1711 if (rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
&&
1712 nla_put_u8(msg
, NL80211_ATTR_MAX_CSA_COUNTERS
,
1713 rdev
->wiphy
.max_num_csa_counters
))
1714 goto nla_put_failure
;
1716 if (rdev
->wiphy
.regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
1717 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
1718 goto nla_put_failure
;
1720 if (nla_put(msg
, NL80211_ATTR_EXT_FEATURES
,
1721 sizeof(rdev
->wiphy
.ext_features
),
1722 rdev
->wiphy
.ext_features
))
1723 goto nla_put_failure
;
1726 state
->split_start
= 0;
1730 genlmsg_end(msg
, hdr
);
1734 genlmsg_cancel(msg
, hdr
);
1738 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1739 struct netlink_callback
*cb
,
1740 struct nl80211_dump_wiphy_state
*state
)
1742 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1743 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1744 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1745 /* ignore parse errors for backward compatibility */
1749 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1750 if (tb
[NL80211_ATTR_WIPHY
])
1751 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1752 if (tb
[NL80211_ATTR_WDEV
])
1753 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1754 if (tb
[NL80211_ATTR_IFINDEX
]) {
1755 struct net_device
*netdev
;
1756 struct cfg80211_registered_device
*rdev
;
1757 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1759 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1762 if (netdev
->ieee80211_ptr
) {
1763 rdev
= wiphy_to_rdev(
1764 netdev
->ieee80211_ptr
->wiphy
);
1765 state
->filter_wiphy
= rdev
->wiphy_idx
;
1772 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1775 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1776 struct cfg80211_registered_device
*rdev
;
1780 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1785 state
->filter_wiphy
= -1;
1786 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1792 cb
->args
[0] = (long)state
;
1795 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1796 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1798 if (++idx
<= state
->start
)
1800 if (state
->filter_wiphy
!= -1 &&
1801 state
->filter_wiphy
!= rdev
->wiphy_idx
)
1803 /* attempt to fit multiple wiphy data chunks into the skb */
1805 ret
= nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
,
1807 NETLINK_CB(cb
->skb
).portid
,
1809 NLM_F_MULTI
, state
);
1812 * If sending the wiphy data didn't fit (ENOBUFS
1813 * or EMSGSIZE returned), this SKB is still
1814 * empty (so it's not too big because another
1815 * wiphy dataset is already in the skb) and
1816 * we've not tried to adjust the dump allocation
1817 * yet ... then adjust the alloc size to be
1818 * bigger, and return 1 but with the empty skb.
1819 * This results in an empty message being RX'ed
1820 * in userspace, but that is ignored.
1822 * We can then retry with the larger buffer.
1824 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1825 !skb
->len
&& !state
->split
&&
1826 cb
->min_dump_alloc
< 4096) {
1827 cb
->min_dump_alloc
= 4096;
1828 state
->split_start
= 0;
1835 } while (state
->split_start
> 0);
1845 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1847 kfree((void *)cb
->args
[0]);
1851 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1853 struct sk_buff
*msg
;
1854 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1855 struct nl80211_dump_wiphy_state state
= {};
1857 msg
= nlmsg_new(4096, GFP_KERNEL
);
1861 if (nl80211_send_wiphy(rdev
, NL80211_CMD_NEW_WIPHY
, msg
,
1862 info
->snd_portid
, info
->snd_seq
, 0,
1868 return genlmsg_reply(msg
, info
);
1871 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1872 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1873 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1874 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1875 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1876 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1879 static int parse_txq_params(struct nlattr
*tb
[],
1880 struct ieee80211_txq_params
*txq_params
)
1882 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1883 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1884 !tb
[NL80211_TXQ_ATTR_AIFS
])
1887 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1888 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1889 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1890 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1891 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1893 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1899 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1902 * You can only set the channel explicitly for WDS interfaces,
1903 * all others have their channel managed via their respective
1904 * "establish a connection" command (connect, join, ...)
1906 * For AP/GO and mesh mode, the channel can be set with the
1907 * channel userspace API, but is only stored and passed to the
1908 * low-level driver when the AP starts or the mesh is joined.
1909 * This is for backward compatibility, userspace can also give
1910 * the channel in the start-ap or join-mesh commands instead.
1912 * Monitors are special as they are normally slaved to
1913 * whatever else is going on, so they have their own special
1914 * operation to set the monitor channel if possible.
1917 wdev
->iftype
== NL80211_IFTYPE_AP
||
1918 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1919 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1920 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1923 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1924 struct genl_info
*info
,
1925 struct cfg80211_chan_def
*chandef
)
1929 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1932 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1934 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1935 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1936 chandef
->center_freq1
= control_freq
;
1937 chandef
->center_freq2
= 0;
1939 /* Primary channel not allowed */
1940 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1943 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1944 enum nl80211_channel_type chantype
;
1946 chantype
= nla_get_u32(
1947 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1950 case NL80211_CHAN_NO_HT
:
1951 case NL80211_CHAN_HT20
:
1952 case NL80211_CHAN_HT40PLUS
:
1953 case NL80211_CHAN_HT40MINUS
:
1954 cfg80211_chandef_create(chandef
, chandef
->chan
,
1960 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1962 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1963 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1964 chandef
->center_freq1
=
1966 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1967 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1968 chandef
->center_freq2
=
1970 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1973 if (!cfg80211_chandef_valid(chandef
))
1976 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1977 IEEE80211_CHAN_DISABLED
))
1980 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1981 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1982 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1988 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1989 struct net_device
*dev
,
1990 struct genl_info
*info
)
1992 struct cfg80211_chan_def chandef
;
1994 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1995 struct wireless_dev
*wdev
= NULL
;
1998 wdev
= dev
->ieee80211_ptr
;
1999 if (!nl80211_can_set_dev_channel(wdev
))
2002 iftype
= wdev
->iftype
;
2004 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
2009 case NL80211_IFTYPE_AP
:
2010 case NL80211_IFTYPE_P2P_GO
:
2011 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
2016 if (wdev
->beacon_interval
) {
2017 if (!dev
|| !rdev
->ops
->set_ap_chanwidth
||
2018 !(rdev
->wiphy
.features
&
2019 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
)) {
2024 /* Only allow dynamic channel width changes */
2025 if (chandef
.chan
!= wdev
->preset_chandef
.chan
) {
2029 result
= rdev_set_ap_chanwidth(rdev
, dev
, &chandef
);
2033 wdev
->preset_chandef
= chandef
;
2036 case NL80211_IFTYPE_MESH_POINT
:
2037 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
2039 case NL80211_IFTYPE_MONITOR
:
2040 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
2049 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
2051 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2052 struct net_device
*netdev
= info
->user_ptr
[1];
2054 return __nl80211_set_channel(rdev
, netdev
, info
);
2057 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
2059 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2060 struct net_device
*dev
= info
->user_ptr
[1];
2061 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2064 if (!info
->attrs
[NL80211_ATTR_MAC
])
2067 if (netif_running(dev
))
2070 if (!rdev
->ops
->set_wds_peer
)
2073 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
2076 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2077 return rdev_set_wds_peer(rdev
, dev
, bssid
);
2081 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
2083 struct cfg80211_registered_device
*rdev
;
2084 struct net_device
*netdev
= NULL
;
2085 struct wireless_dev
*wdev
;
2086 int result
= 0, rem_txq_params
= 0;
2087 struct nlattr
*nl_txq_params
;
2089 u8 retry_short
= 0, retry_long
= 0;
2090 u32 frag_threshold
= 0, rts_threshold
= 0;
2091 u8 coverage_class
= 0;
2096 * Try to find the wiphy and netdev. Normally this
2097 * function shouldn't need the netdev, but this is
2098 * done for backward compatibility -- previously
2099 * setting the channel was done per wiphy, but now
2100 * it is per netdev. Previous userland like hostapd
2101 * also passed a netdev to set_wiphy, so that it is
2102 * possible to let that go to the right netdev!
2105 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
2106 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
2108 netdev
= __dev_get_by_index(genl_info_net(info
), ifindex
);
2109 if (netdev
&& netdev
->ieee80211_ptr
)
2110 rdev
= wiphy_to_rdev(netdev
->ieee80211_ptr
->wiphy
);
2116 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
2119 return PTR_ERR(rdev
);
2124 wdev
= netdev
->ieee80211_ptr
;
2127 * end workaround code, by now the rdev is available
2128 * and locked, and wdev may or may not be NULL.
2131 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
2132 result
= cfg80211_dev_rename(
2133 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
2138 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
2139 struct ieee80211_txq_params txq_params
;
2140 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
2142 if (!rdev
->ops
->set_txq_params
)
2148 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2149 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2152 if (!netif_running(netdev
))
2155 nla_for_each_nested(nl_txq_params
,
2156 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
2158 result
= nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
2159 nla_data(nl_txq_params
),
2160 nla_len(nl_txq_params
),
2164 result
= parse_txq_params(tb
, &txq_params
);
2168 result
= rdev_set_txq_params(rdev
, netdev
,
2175 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2176 result
= __nl80211_set_channel(
2178 nl80211_can_set_dev_channel(wdev
) ? netdev
: NULL
,
2184 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2185 struct wireless_dev
*txp_wdev
= wdev
;
2186 enum nl80211_tx_power_setting type
;
2189 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2192 if (!rdev
->ops
->set_tx_power
)
2195 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2196 type
= nla_get_u32(info
->attrs
[idx
]);
2198 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2199 (type
!= NL80211_TX_POWER_AUTOMATIC
))
2202 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2203 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2204 mbm
= nla_get_u32(info
->attrs
[idx
]);
2207 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2212 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2213 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2215 if ((!rdev
->wiphy
.available_antennas_tx
&&
2216 !rdev
->wiphy
.available_antennas_rx
) ||
2217 !rdev
->ops
->set_antenna
)
2220 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2221 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2223 /* reject antenna configurations which don't match the
2224 * available antenna masks, except for the "all" mask */
2225 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2226 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
)))
2229 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2230 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2232 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2239 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2240 retry_short
= nla_get_u8(
2241 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2242 if (retry_short
== 0)
2245 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2248 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2249 retry_long
= nla_get_u8(
2250 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2251 if (retry_long
== 0)
2254 changed
|= WIPHY_PARAM_RETRY_LONG
;
2257 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2258 frag_threshold
= nla_get_u32(
2259 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2260 if (frag_threshold
< 256)
2263 if (frag_threshold
!= (u32
) -1) {
2265 * Fragments (apart from the last one) are required to
2266 * have even length. Make the fragmentation code
2267 * simpler by stripping LSB should someone try to use
2268 * odd threshold value.
2270 frag_threshold
&= ~0x1;
2272 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2275 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2276 rts_threshold
= nla_get_u32(
2277 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2278 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2281 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2282 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
])
2285 coverage_class
= nla_get_u8(
2286 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2287 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2290 if (info
->attrs
[NL80211_ATTR_WIPHY_DYN_ACK
]) {
2291 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_ACKTO_ESTIMATION
))
2294 changed
|= WIPHY_PARAM_DYN_ACK
;
2298 u8 old_retry_short
, old_retry_long
;
2299 u32 old_frag_threshold
, old_rts_threshold
;
2300 u8 old_coverage_class
;
2302 if (!rdev
->ops
->set_wiphy_params
)
2305 old_retry_short
= rdev
->wiphy
.retry_short
;
2306 old_retry_long
= rdev
->wiphy
.retry_long
;
2307 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2308 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2309 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2311 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2312 rdev
->wiphy
.retry_short
= retry_short
;
2313 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2314 rdev
->wiphy
.retry_long
= retry_long
;
2315 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2316 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2317 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2318 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2319 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2320 rdev
->wiphy
.coverage_class
= coverage_class
;
2322 result
= rdev_set_wiphy_params(rdev
, changed
);
2324 rdev
->wiphy
.retry_short
= old_retry_short
;
2325 rdev
->wiphy
.retry_long
= old_retry_long
;
2326 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2327 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2328 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2335 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2337 return (u64
)wdev
->identifier
|
2338 ((u64
)wiphy_to_rdev(wdev
->wiphy
)->wiphy_idx
<< 32);
2341 static int nl80211_send_chandef(struct sk_buff
*msg
,
2342 const struct cfg80211_chan_def
*chandef
)
2344 if (WARN_ON(!cfg80211_chandef_valid(chandef
)))
2347 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2348 chandef
->chan
->center_freq
))
2350 switch (chandef
->width
) {
2351 case NL80211_CHAN_WIDTH_20_NOHT
:
2352 case NL80211_CHAN_WIDTH_20
:
2353 case NL80211_CHAN_WIDTH_40
:
2354 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2355 cfg80211_get_chandef_type(chandef
)))
2361 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2363 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2365 if (chandef
->center_freq2
&&
2366 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2371 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2372 struct cfg80211_registered_device
*rdev
,
2373 struct wireless_dev
*wdev
, bool removal
)
2375 struct net_device
*dev
= wdev
->netdev
;
2376 u8 cmd
= NL80211_CMD_NEW_INTERFACE
;
2380 cmd
= NL80211_CMD_DEL_INTERFACE
;
2382 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
2387 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2388 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2389 goto nla_put_failure
;
2391 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2392 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2393 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2394 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2395 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2396 rdev
->devlist_generation
^
2397 (cfg80211_rdev_list_generation
<< 2)))
2398 goto nla_put_failure
;
2400 if (rdev
->ops
->get_channel
) {
2402 struct cfg80211_chan_def chandef
;
2404 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2406 if (nl80211_send_chandef(msg
, &chandef
))
2407 goto nla_put_failure
;
2411 if (rdev
->ops
->get_tx_power
) {
2414 ret
= rdev_get_tx_power(rdev
, wdev
, &dbm
);
2416 nla_put_u32(msg
, NL80211_ATTR_WIPHY_TX_POWER_LEVEL
,
2418 goto nla_put_failure
;
2421 if (wdev
->ssid_len
) {
2422 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2423 goto nla_put_failure
;
2426 genlmsg_end(msg
, hdr
);
2430 genlmsg_cancel(msg
, hdr
);
2434 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2438 int wp_start
= cb
->args
[0];
2439 int if_start
= cb
->args
[1];
2440 struct cfg80211_registered_device
*rdev
;
2441 struct wireless_dev
*wdev
;
2444 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2445 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2447 if (wp_idx
< wp_start
) {
2453 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2454 if (if_idx
< if_start
) {
2458 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2459 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2460 rdev
, wdev
, false) < 0) {
2471 cb
->args
[0] = wp_idx
;
2472 cb
->args
[1] = if_idx
;
2477 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2479 struct sk_buff
*msg
;
2480 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2481 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2483 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2487 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2488 rdev
, wdev
, false) < 0) {
2493 return genlmsg_reply(msg
, info
);
2496 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2497 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2498 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2499 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2500 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2501 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2502 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2505 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2507 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2515 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2516 nla
, mntr_flags_policy
))
2519 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2521 *mntrflags
|= (1<<flag
);
2526 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2527 struct net_device
*netdev
, u8 use_4addr
,
2528 enum nl80211_iftype iftype
)
2531 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2537 case NL80211_IFTYPE_AP_VLAN
:
2538 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2541 case NL80211_IFTYPE_STATION
:
2542 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2552 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2554 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2555 struct vif_params params
;
2557 enum nl80211_iftype otype
, ntype
;
2558 struct net_device
*dev
= info
->user_ptr
[1];
2559 u32 _flags
, *flags
= NULL
;
2560 bool change
= false;
2562 memset(¶ms
, 0, sizeof(params
));
2564 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2566 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2567 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2570 if (ntype
> NL80211_IFTYPE_MAX
)
2574 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2575 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2577 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2579 if (netif_running(dev
))
2583 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2584 IEEE80211_MAX_MESH_ID_LEN
);
2585 wdev
->mesh_id_up_len
=
2586 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2587 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2588 wdev
->mesh_id_up_len
);
2592 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2593 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2595 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2599 params
.use_4addr
= -1;
2602 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2603 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2605 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2614 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2615 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2619 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2623 if (!err
&& params
.use_4addr
!= -1)
2624 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2629 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2631 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2632 struct vif_params params
;
2633 struct wireless_dev
*wdev
;
2634 struct sk_buff
*msg
, *event
;
2636 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2639 /* to avoid failing a new interface creation due to pending removal */
2640 cfg80211_destroy_ifaces(rdev
);
2642 memset(¶ms
, 0, sizeof(params
));
2644 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2647 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2648 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2649 if (type
> NL80211_IFTYPE_MAX
)
2653 if (!rdev
->ops
->add_virtual_intf
||
2654 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2657 if ((type
== NL80211_IFTYPE_P2P_DEVICE
||
2658 rdev
->wiphy
.features
& NL80211_FEATURE_MAC_ON_CREATE
) &&
2659 info
->attrs
[NL80211_ATTR_MAC
]) {
2660 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2662 if (!is_valid_ether_addr(params
.macaddr
))
2663 return -EADDRNOTAVAIL
;
2666 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2667 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2668 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2673 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2674 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2677 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2678 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2681 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2685 wdev
= rdev_add_virtual_intf(rdev
,
2686 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2687 NET_NAME_USER
, type
, err
? NULL
: &flags
,
2689 if (WARN_ON(!wdev
)) {
2692 } else if (IS_ERR(wdev
)) {
2694 return PTR_ERR(wdev
);
2697 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
2698 wdev
->owner_nlportid
= info
->snd_portid
;
2701 case NL80211_IFTYPE_MESH_POINT
:
2702 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2705 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2706 IEEE80211_MAX_MESH_ID_LEN
);
2707 wdev
->mesh_id_up_len
=
2708 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2709 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2710 wdev
->mesh_id_up_len
);
2713 case NL80211_IFTYPE_P2P_DEVICE
:
2715 * P2P Device doesn't have a netdev, so doesn't go
2716 * through the netdev notifier and must be added here
2718 mutex_init(&wdev
->mtx
);
2719 INIT_LIST_HEAD(&wdev
->event_list
);
2720 spin_lock_init(&wdev
->event_lock
);
2721 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2722 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2724 wdev
->identifier
= ++rdev
->wdev_id
;
2725 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2726 rdev
->devlist_generation
++;
2732 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2733 rdev
, wdev
, false) < 0) {
2738 event
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2740 if (nl80211_send_iface(event
, 0, 0, 0,
2741 rdev
, wdev
, false) < 0) {
2746 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2747 event
, 0, NL80211_MCGRP_CONFIG
,
2752 return genlmsg_reply(msg
, info
);
2755 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2757 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2758 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2759 struct sk_buff
*msg
;
2762 if (!rdev
->ops
->del_virtual_intf
)
2765 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2766 if (msg
&& nl80211_send_iface(msg
, 0, 0, 0, rdev
, wdev
, true) < 0) {
2772 * If we remove a wireless device without a netdev then clear
2773 * user_ptr[1] so that nl80211_post_doit won't dereference it
2774 * to check if it needs to do dev_put(). Otherwise it crashes
2775 * since the wdev has been freed, unlike with a netdev where
2776 * we need the dev_put() for the netdev to really be freed.
2779 info
->user_ptr
[1] = NULL
;
2781 status
= rdev_del_virtual_intf(rdev
, wdev
);
2782 if (status
>= 0 && msg
)
2783 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
),
2784 msg
, 0, NL80211_MCGRP_CONFIG
,
2792 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2794 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2795 struct net_device
*dev
= info
->user_ptr
[1];
2798 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2801 if (!rdev
->ops
->set_noack_map
)
2804 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2806 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2809 struct get_key_cookie
{
2810 struct sk_buff
*msg
;
2815 static void get_key_callback(void *c
, struct key_params
*params
)
2818 struct get_key_cookie
*cookie
= c
;
2821 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2822 params
->key_len
, params
->key
)) ||
2824 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2825 params
->seq_len
, params
->seq
)) ||
2827 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2829 goto nla_put_failure
;
2831 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2833 goto nla_put_failure
;
2836 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2837 params
->key_len
, params
->key
)) ||
2839 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2840 params
->seq_len
, params
->seq
)) ||
2842 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2844 goto nla_put_failure
;
2846 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2847 goto nla_put_failure
;
2849 nla_nest_end(cookie
->msg
, key
);
2856 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2858 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2860 struct net_device
*dev
= info
->user_ptr
[1];
2862 const u8
*mac_addr
= NULL
;
2864 struct get_key_cookie cookie
= {
2868 struct sk_buff
*msg
;
2870 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2871 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2876 if (info
->attrs
[NL80211_ATTR_MAC
])
2877 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2879 pairwise
= !!mac_addr
;
2880 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2881 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2882 if (kt
>= NUM_NL80211_KEYTYPES
)
2884 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2885 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2887 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2890 if (!rdev
->ops
->get_key
)
2893 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2896 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2900 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2901 NL80211_CMD_NEW_KEY
);
2903 goto nla_put_failure
;
2906 cookie
.idx
= key_idx
;
2908 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2909 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2910 goto nla_put_failure
;
2912 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2913 goto nla_put_failure
;
2915 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2922 goto nla_put_failure
;
2924 genlmsg_end(msg
, hdr
);
2925 return genlmsg_reply(msg
, info
);
2934 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2936 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2937 struct key_parse key
;
2939 struct net_device
*dev
= info
->user_ptr
[1];
2941 err
= nl80211_parse_key(info
, &key
);
2948 /* only support setting default key */
2949 if (!key
.def
&& !key
.defmgmt
)
2952 wdev_lock(dev
->ieee80211_ptr
);
2955 if (!rdev
->ops
->set_default_key
) {
2960 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2964 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2965 key
.def_uni
, key
.def_multi
);
2970 #ifdef CONFIG_CFG80211_WEXT
2971 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2974 if (key
.def_uni
|| !key
.def_multi
) {
2979 if (!rdev
->ops
->set_default_mgmt_key
) {
2984 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2988 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2992 #ifdef CONFIG_CFG80211_WEXT
2993 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2998 wdev_unlock(dev
->ieee80211_ptr
);
3003 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
3005 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3007 struct net_device
*dev
= info
->user_ptr
[1];
3008 struct key_parse key
;
3009 const u8
*mac_addr
= NULL
;
3011 err
= nl80211_parse_key(info
, &key
);
3018 if (info
->attrs
[NL80211_ATTR_MAC
])
3019 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3021 if (key
.type
== -1) {
3023 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3025 key
.type
= NL80211_KEYTYPE_GROUP
;
3029 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3030 key
.type
!= NL80211_KEYTYPE_GROUP
)
3033 if (!rdev
->ops
->add_key
)
3036 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
3037 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3041 wdev_lock(dev
->ieee80211_ptr
);
3042 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3044 err
= rdev_add_key(rdev
, dev
, key
.idx
,
3045 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3047 wdev_unlock(dev
->ieee80211_ptr
);
3052 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
3054 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3056 struct net_device
*dev
= info
->user_ptr
[1];
3057 u8
*mac_addr
= NULL
;
3058 struct key_parse key
;
3060 err
= nl80211_parse_key(info
, &key
);
3064 if (info
->attrs
[NL80211_ATTR_MAC
])
3065 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3067 if (key
.type
== -1) {
3069 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
3071 key
.type
= NL80211_KEYTYPE_GROUP
;
3075 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
3076 key
.type
!= NL80211_KEYTYPE_GROUP
)
3079 if (!rdev
->ops
->del_key
)
3082 wdev_lock(dev
->ieee80211_ptr
);
3083 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
3085 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
3086 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
3090 err
= rdev_del_key(rdev
, dev
, key
.idx
,
3091 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
3094 #ifdef CONFIG_CFG80211_WEXT
3096 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
3097 dev
->ieee80211_ptr
->wext
.default_key
= -1;
3098 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
3099 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
3102 wdev_unlock(dev
->ieee80211_ptr
);
3107 /* This function returns an error or the number of nested attributes */
3108 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
3110 struct nlattr
*attr
;
3111 int n_entries
= 0, tmp
;
3113 nla_for_each_nested(attr
, nl_attr
, tmp
) {
3114 if (nla_len(attr
) != ETH_ALEN
)
3124 * This function parses ACL information and allocates memory for ACL data.
3125 * On successful return, the calling function is responsible to free the
3126 * ACL buffer returned by this function.
3128 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
3129 struct genl_info
*info
)
3131 enum nl80211_acl_policy acl_policy
;
3132 struct nlattr
*attr
;
3133 struct cfg80211_acl_data
*acl
;
3134 int i
= 0, n_entries
, tmp
;
3136 if (!wiphy
->max_acl_mac_addrs
)
3137 return ERR_PTR(-EOPNOTSUPP
);
3139 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
3140 return ERR_PTR(-EINVAL
);
3142 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
3143 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
3144 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
3145 return ERR_PTR(-EINVAL
);
3147 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
3148 return ERR_PTR(-EINVAL
);
3150 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
3152 return ERR_PTR(n_entries
);
3154 if (n_entries
> wiphy
->max_acl_mac_addrs
)
3155 return ERR_PTR(-ENOTSUPP
);
3157 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
3160 return ERR_PTR(-ENOMEM
);
3162 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
3163 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
3167 acl
->n_acl_entries
= n_entries
;
3168 acl
->acl_policy
= acl_policy
;
3173 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
3175 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3176 struct net_device
*dev
= info
->user_ptr
[1];
3177 struct cfg80211_acl_data
*acl
;
3180 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3181 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3184 if (!dev
->ieee80211_ptr
->beacon_interval
)
3187 acl
= parse_acl_data(&rdev
->wiphy
, info
);
3189 return PTR_ERR(acl
);
3191 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
3198 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
3199 struct cfg80211_beacon_data
*bcn
)
3201 bool haveinfo
= false;
3203 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
3204 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
3205 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
3206 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
3209 memset(bcn
, 0, sizeof(*bcn
));
3211 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
3212 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3213 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
3219 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
3220 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3221 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
3228 if (attrs
[NL80211_ATTR_IE
]) {
3229 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
3230 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3233 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3234 bcn
->proberesp_ies
=
3235 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3236 bcn
->proberesp_ies_len
=
3237 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3240 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3241 bcn
->assocresp_ies
=
3242 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3243 bcn
->assocresp_ies_len
=
3244 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3247 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3248 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3249 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3255 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3256 struct cfg80211_ap_settings
*params
)
3258 struct wireless_dev
*wdev
;
3261 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3262 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3263 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3266 if (!wdev
->preset_chandef
.chan
)
3269 params
->chandef
= wdev
->preset_chandef
;
3277 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3278 enum nl80211_auth_type auth_type
,
3279 enum nl80211_commands cmd
)
3281 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3285 case NL80211_CMD_AUTHENTICATE
:
3286 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3287 auth_type
== NL80211_AUTHTYPE_SAE
)
3290 case NL80211_CMD_CONNECT
:
3291 case NL80211_CMD_START_AP
:
3292 /* SAE not supported yet */
3293 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3301 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3303 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3304 struct net_device
*dev
= info
->user_ptr
[1];
3305 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3306 struct cfg80211_ap_settings params
;
3309 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3310 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3313 if (!rdev
->ops
->start_ap
)
3316 if (wdev
->beacon_interval
)
3319 memset(¶ms
, 0, sizeof(params
));
3321 /* these are required for START_AP */
3322 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3323 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3324 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3327 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3331 params
.beacon_interval
=
3332 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3333 params
.dtim_period
=
3334 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3336 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3341 * In theory, some of these attributes should be required here
3342 * but since they were not used when the command was originally
3343 * added, keep them optional for old user space programs to let
3344 * them continue to work with drivers that do not need the
3345 * additional information -- drivers must check!
3347 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3348 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3350 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3351 if (params
.ssid_len
== 0 ||
3352 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3356 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3357 params
.hidden_ssid
= nla_get_u32(
3358 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3359 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3360 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3361 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3365 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3367 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3368 params
.auth_type
= nla_get_u32(
3369 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3370 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3371 NL80211_CMD_START_AP
))
3374 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3376 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3377 NL80211_MAX_NR_CIPHER_SUITES
);
3381 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3382 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3384 params
.inactivity_timeout
= nla_get_u16(
3385 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3388 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3389 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3391 params
.p2p_ctwindow
=
3392 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3393 if (params
.p2p_ctwindow
> 127)
3395 if (params
.p2p_ctwindow
!= 0 &&
3396 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3400 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3403 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3405 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3408 params
.p2p_opp_ps
= tmp
;
3409 if (params
.p2p_opp_ps
!= 0 &&
3410 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3414 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3415 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3418 } else if (wdev
->preset_chandef
.chan
) {
3419 params
.chandef
= wdev
->preset_chandef
;
3420 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3423 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
3427 if (info
->attrs
[NL80211_ATTR_SMPS_MODE
]) {
3429 nla_get_u8(info
->attrs
[NL80211_ATTR_SMPS_MODE
]);
3430 switch (params
.smps_mode
) {
3431 case NL80211_SMPS_OFF
:
3433 case NL80211_SMPS_STATIC
:
3434 if (!(rdev
->wiphy
.features
&
3435 NL80211_FEATURE_STATIC_SMPS
))
3438 case NL80211_SMPS_DYNAMIC
:
3439 if (!(rdev
->wiphy
.features
&
3440 NL80211_FEATURE_DYNAMIC_SMPS
))
3447 params
.smps_mode
= NL80211_SMPS_OFF
;
3450 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3451 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3452 if (IS_ERR(params
.acl
))
3453 return PTR_ERR(params
.acl
);
3457 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3459 wdev
->preset_chandef
= params
.chandef
;
3460 wdev
->beacon_interval
= params
.beacon_interval
;
3461 wdev
->chandef
= params
.chandef
;
3462 wdev
->ssid_len
= params
.ssid_len
;
3463 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3472 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3474 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3475 struct net_device
*dev
= info
->user_ptr
[1];
3476 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3477 struct cfg80211_beacon_data params
;
3480 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3481 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3484 if (!rdev
->ops
->change_beacon
)
3487 if (!wdev
->beacon_interval
)
3490 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3495 err
= rdev_change_beacon(rdev
, dev
, ¶ms
);
3501 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3503 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3504 struct net_device
*dev
= info
->user_ptr
[1];
3506 return cfg80211_stop_ap(rdev
, dev
, false);
3509 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3510 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3511 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3512 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3513 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3514 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3515 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3518 static int parse_station_flags(struct genl_info
*info
,
3519 enum nl80211_iftype iftype
,
3520 struct station_parameters
*params
)
3522 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3527 * Try parsing the new attribute first so userspace
3528 * can specify both for older kernels.
3530 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3532 struct nl80211_sta_flag_update
*sta_flags
;
3534 sta_flags
= nla_data(nla
);
3535 params
->sta_flags_mask
= sta_flags
->mask
;
3536 params
->sta_flags_set
= sta_flags
->set
;
3537 params
->sta_flags_set
&= params
->sta_flags_mask
;
3538 if ((params
->sta_flags_mask
|
3539 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3544 /* if present, parse the old attribute */
3546 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3550 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3551 nla
, sta_flags_policy
))
3555 * Only allow certain flags for interface types so that
3556 * other attributes are silently ignored. Remember that
3557 * this is backward compatibility code with old userspace
3558 * and shouldn't be hit in other cases anyway.
3561 case NL80211_IFTYPE_AP
:
3562 case NL80211_IFTYPE_AP_VLAN
:
3563 case NL80211_IFTYPE_P2P_GO
:
3564 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3565 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3566 BIT(NL80211_STA_FLAG_WME
) |
3567 BIT(NL80211_STA_FLAG_MFP
);
3569 case NL80211_IFTYPE_P2P_CLIENT
:
3570 case NL80211_IFTYPE_STATION
:
3571 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3572 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3574 case NL80211_IFTYPE_MESH_POINT
:
3575 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3576 BIT(NL80211_STA_FLAG_MFP
) |
3577 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3582 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3584 params
->sta_flags_set
|= (1<<flag
);
3586 /* no longer support new API additions in old API */
3587 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3595 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3598 struct nlattr
*rate
;
3601 enum nl80211_rate_info rate_flg
;
3603 rate
= nla_nest_start(msg
, attr
);
3607 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3608 bitrate
= cfg80211_calculate_bitrate(info
);
3609 /* report 16-bit bitrate only if we can */
3610 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3612 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3614 if (bitrate_compat
> 0 &&
3615 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3619 case RATE_INFO_BW_5
:
3620 rate_flg
= NL80211_RATE_INFO_5_MHZ_WIDTH
;
3622 case RATE_INFO_BW_10
:
3623 rate_flg
= NL80211_RATE_INFO_10_MHZ_WIDTH
;
3628 case RATE_INFO_BW_20
:
3631 case RATE_INFO_BW_40
:
3632 rate_flg
= NL80211_RATE_INFO_40_MHZ_WIDTH
;
3634 case RATE_INFO_BW_80
:
3635 rate_flg
= NL80211_RATE_INFO_80_MHZ_WIDTH
;
3637 case RATE_INFO_BW_160
:
3638 rate_flg
= NL80211_RATE_INFO_160_MHZ_WIDTH
;
3642 if (rate_flg
&& nla_put_flag(msg
, rate_flg
))
3645 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3646 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3648 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3649 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3651 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3652 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3654 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3656 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3657 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3661 nla_nest_end(msg
, rate
);
3665 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3674 attr
= nla_nest_start(msg
, id
);
3678 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3679 if (!(mask
& BIT(i
)))
3682 if (nla_put_u8(msg
, i
, signal
[i
]))
3686 nla_nest_end(msg
, attr
);
3691 static int nl80211_send_station(struct sk_buff
*msg
, u32 cmd
, u32 portid
,
3693 struct cfg80211_registered_device
*rdev
,
3694 struct net_device
*dev
,
3695 const u8
*mac_addr
, struct station_info
*sinfo
)
3698 struct nlattr
*sinfoattr
, *bss_param
;
3700 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
3704 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3705 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3706 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3707 goto nla_put_failure
;
3709 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3711 goto nla_put_failure
;
3713 #define PUT_SINFO(attr, memb, type) do { \
3714 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3715 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3717 goto nla_put_failure; \
3720 PUT_SINFO(CONNECTED_TIME
, connected_time
, u32
);
3721 PUT_SINFO(INACTIVE_TIME
, inactive_time
, u32
);
3723 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_RX_BYTES
) |
3724 BIT(NL80211_STA_INFO_RX_BYTES64
)) &&
3725 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3726 (u32
)sinfo
->rx_bytes
))
3727 goto nla_put_failure
;
3729 if (sinfo
->filled
& (BIT(NL80211_STA_INFO_TX_BYTES
) |
3730 BIT(NL80211_STA_INFO_TX_BYTES64
)) &&
3731 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3732 (u32
)sinfo
->tx_bytes
))
3733 goto nla_put_failure
;
3735 PUT_SINFO(RX_BYTES64
, rx_bytes
, u64
);
3736 PUT_SINFO(TX_BYTES64
, tx_bytes
, u64
);
3737 PUT_SINFO(LLID
, llid
, u16
);
3738 PUT_SINFO(PLID
, plid
, u16
);
3739 PUT_SINFO(PLINK_STATE
, plink_state
, u8
);
3741 switch (rdev
->wiphy
.signal_type
) {
3742 case CFG80211_SIGNAL_TYPE_MBM
:
3743 PUT_SINFO(SIGNAL
, signal
, u8
);
3744 PUT_SINFO(SIGNAL_AVG
, signal_avg
, u8
);
3749 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL
)) {
3750 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3751 sinfo
->chain_signal
,
3752 NL80211_STA_INFO_CHAIN_SIGNAL
))
3753 goto nla_put_failure
;
3755 if (sinfo
->filled
& BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG
)) {
3756 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3757 sinfo
->chain_signal_avg
,
3758 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3759 goto nla_put_failure
;
3761 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TX_BITRATE
)) {
3762 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3763 NL80211_STA_INFO_TX_BITRATE
))
3764 goto nla_put_failure
;
3766 if (sinfo
->filled
& BIT(NL80211_STA_INFO_RX_BITRATE
)) {
3767 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3768 NL80211_STA_INFO_RX_BITRATE
))
3769 goto nla_put_failure
;
3772 PUT_SINFO(RX_PACKETS
, rx_packets
, u32
);
3773 PUT_SINFO(TX_PACKETS
, tx_packets
, u32
);
3774 PUT_SINFO(TX_RETRIES
, tx_retries
, u32
);
3775 PUT_SINFO(TX_FAILED
, tx_failed
, u32
);
3776 PUT_SINFO(EXPECTED_THROUGHPUT
, expected_throughput
, u32
);
3777 PUT_SINFO(BEACON_LOSS
, beacon_loss_count
, u32
);
3778 PUT_SINFO(LOCAL_PM
, local_pm
, u32
);
3779 PUT_SINFO(PEER_PM
, peer_pm
, u32
);
3780 PUT_SINFO(NONPEER_PM
, nonpeer_pm
, u32
);
3782 if (sinfo
->filled
& BIT(NL80211_STA_INFO_BSS_PARAM
)) {
3783 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3785 goto nla_put_failure
;
3787 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3788 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3789 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3790 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3791 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3792 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3793 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3794 sinfo
->bss_param
.dtim_period
) ||
3795 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3796 sinfo
->bss_param
.beacon_interval
))
3797 goto nla_put_failure
;
3799 nla_nest_end(msg
, bss_param
);
3801 if ((sinfo
->filled
& BIT(NL80211_STA_INFO_STA_FLAGS
)) &&
3802 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3803 sizeof(struct nl80211_sta_flag_update
),
3805 goto nla_put_failure
;
3807 PUT_SINFO(T_OFFSET
, t_offset
, u64
);
3808 PUT_SINFO(RX_DROP_MISC
, rx_dropped_misc
, u64
);
3809 PUT_SINFO(BEACON_RX
, rx_beacon
, u64
);
3810 PUT_SINFO(BEACON_SIGNAL_AVG
, rx_beacon_signal_avg
, u8
);
3814 if (sinfo
->filled
& BIT(NL80211_STA_INFO_TID_STATS
)) {
3815 struct nlattr
*tidsattr
;
3818 tidsattr
= nla_nest_start(msg
, NL80211_STA_INFO_TID_STATS
);
3820 goto nla_put_failure
;
3822 for (tid
= 0; tid
< IEEE80211_NUM_TIDS
+ 1; tid
++) {
3823 struct cfg80211_tid_stats
*tidstats
;
3824 struct nlattr
*tidattr
;
3826 tidstats
= &sinfo
->pertid
[tid
];
3828 if (!tidstats
->filled
)
3831 tidattr
= nla_nest_start(msg
, tid
+ 1);
3833 goto nla_put_failure
;
3835 #define PUT_TIDVAL(attr, memb, type) do { \
3836 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3837 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3839 goto nla_put_failure; \
3842 PUT_TIDVAL(RX_MSDU
, rx_msdu
, u64
);
3843 PUT_TIDVAL(TX_MSDU
, tx_msdu
, u64
);
3844 PUT_TIDVAL(TX_MSDU_RETRIES
, tx_msdu_retries
, u64
);
3845 PUT_TIDVAL(TX_MSDU_FAILED
, tx_msdu_failed
, u64
);
3848 nla_nest_end(msg
, tidattr
);
3851 nla_nest_end(msg
, tidsattr
);
3854 nla_nest_end(msg
, sinfoattr
);
3856 if (sinfo
->assoc_req_ies_len
&&
3857 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3858 sinfo
->assoc_req_ies
))
3859 goto nla_put_failure
;
3861 genlmsg_end(msg
, hdr
);
3865 genlmsg_cancel(msg
, hdr
);
3869 static int nl80211_dump_station(struct sk_buff
*skb
,
3870 struct netlink_callback
*cb
)
3872 struct station_info sinfo
;
3873 struct cfg80211_registered_device
*rdev
;
3874 struct wireless_dev
*wdev
;
3875 u8 mac_addr
[ETH_ALEN
];
3876 int sta_idx
= cb
->args
[2];
3880 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
3884 if (!wdev
->netdev
) {
3889 if (!rdev
->ops
->dump_station
) {
3895 memset(&sinfo
, 0, sizeof(sinfo
));
3896 err
= rdev_dump_station(rdev
, wdev
->netdev
, sta_idx
,
3903 if (nl80211_send_station(skb
, NL80211_CMD_NEW_STATION
,
3904 NETLINK_CB(cb
->skb
).portid
,
3905 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3906 rdev
, wdev
->netdev
, mac_addr
,
3915 cb
->args
[2] = sta_idx
;
3923 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3925 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3926 struct net_device
*dev
= info
->user_ptr
[1];
3927 struct station_info sinfo
;
3928 struct sk_buff
*msg
;
3929 u8
*mac_addr
= NULL
;
3932 memset(&sinfo
, 0, sizeof(sinfo
));
3934 if (!info
->attrs
[NL80211_ATTR_MAC
])
3937 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3939 if (!rdev
->ops
->get_station
)
3942 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3946 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3950 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
,
3951 info
->snd_portid
, info
->snd_seq
, 0,
3952 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3957 return genlmsg_reply(msg
, info
);
3960 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3961 struct station_parameters
*params
,
3962 enum cfg80211_station_type statype
)
3964 if (params
->listen_interval
!= -1 &&
3965 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
3969 !(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
3970 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
)
3973 /* When you run into this, adjust the code below for the new flag */
3974 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3977 case CFG80211_STA_MESH_PEER_KERNEL
:
3978 case CFG80211_STA_MESH_PEER_USER
:
3980 * No ignoring the TDLS flag here -- the userspace mesh
3981 * code doesn't have the bug of including TDLS in the
3984 if (params
->sta_flags_mask
&
3985 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3986 BIT(NL80211_STA_FLAG_MFP
) |
3987 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3990 case CFG80211_STA_TDLS_PEER_SETUP
:
3991 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3992 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3994 /* ignore since it can't change */
3995 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3998 /* disallow mesh-specific things */
3999 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
4001 if (params
->local_pm
)
4003 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4007 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4008 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
4009 /* TDLS can't be set, ... */
4010 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4013 * ... but don't bother the driver with it. This works around
4014 * a hostapd/wpa_supplicant issue -- it always includes the
4015 * TLDS_PEER flag in the mask even for AP mode.
4017 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4020 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
4021 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4022 /* reject other things that can't change */
4023 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
4025 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
4027 if (params
->supported_rates
)
4029 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
4033 if (statype
!= CFG80211_STA_AP_CLIENT
&&
4034 statype
!= CFG80211_STA_AP_CLIENT_UNASSOC
) {
4040 case CFG80211_STA_AP_MLME_CLIENT
:
4041 /* Use this only for authorizing/unauthorizing a station */
4042 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
4045 case CFG80211_STA_AP_CLIENT
:
4046 case CFG80211_STA_AP_CLIENT_UNASSOC
:
4047 /* accept only the listed bits */
4048 if (params
->sta_flags_mask
&
4049 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4050 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4051 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4052 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
4053 BIT(NL80211_STA_FLAG_WME
) |
4054 BIT(NL80211_STA_FLAG_MFP
)))
4057 /* but authenticated/associated only if driver handles it */
4058 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4059 params
->sta_flags_mask
&
4060 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4061 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4064 case CFG80211_STA_IBSS
:
4065 case CFG80211_STA_AP_STA
:
4066 /* reject any changes other than AUTHORIZED */
4067 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
4070 case CFG80211_STA_TDLS_PEER_SETUP
:
4071 /* reject any changes other than AUTHORIZED or WME */
4072 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
4073 BIT(NL80211_STA_FLAG_WME
)))
4075 /* force (at least) rates when authorizing */
4076 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
4077 !params
->supported_rates
)
4080 case CFG80211_STA_TDLS_PEER_ACTIVE
:
4081 /* reject any changes */
4083 case CFG80211_STA_MESH_PEER_KERNEL
:
4084 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
4087 case CFG80211_STA_MESH_PEER_USER
:
4088 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
&&
4089 params
->plink_action
!= NL80211_PLINK_ACTION_BLOCK
)
4096 EXPORT_SYMBOL(cfg80211_check_station_change
);
4099 * Get vlan interface making sure it is running and on the right wiphy.
4101 static struct net_device
*get_vlan(struct genl_info
*info
,
4102 struct cfg80211_registered_device
*rdev
)
4104 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
4105 struct net_device
*v
;
4111 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
4113 return ERR_PTR(-ENODEV
);
4115 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
4120 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4121 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4122 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
4127 if (!netif_running(v
)) {
4135 return ERR_PTR(ret
);
4138 static const struct nla_policy
4139 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] = {
4140 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
4141 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
4144 static int nl80211_parse_sta_wme(struct genl_info
*info
,
4145 struct station_parameters
*params
)
4147 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
4151 /* parse WME attributes if present */
4152 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
4155 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
4156 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
4157 nl80211_sta_wme_policy
);
4161 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
4162 params
->uapsd_queues
= nla_get_u8(
4163 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
4164 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
4167 if (tb
[NL80211_STA_WME_MAX_SP
])
4168 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
4170 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
4173 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
4178 static int nl80211_parse_sta_channel_info(struct genl_info
*info
,
4179 struct station_parameters
*params
)
4181 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]) {
4182 params
->supported_channels
=
4183 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4184 params
->supported_channels_len
=
4185 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_CHANNELS
]);
4187 * Need to include at least one (first channel, number of
4188 * channels) tuple for each subband, and must have proper
4189 * tuples for the rest of the data as well.
4191 if (params
->supported_channels_len
< 2)
4193 if (params
->supported_channels_len
% 2)
4197 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]) {
4198 params
->supported_oper_classes
=
4199 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4200 params
->supported_oper_classes_len
=
4201 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
]);
4203 * The value of the Length field of the Supported Operating
4204 * Classes element is between 2 and 253.
4206 if (params
->supported_oper_classes_len
< 2 ||
4207 params
->supported_oper_classes_len
> 253)
4213 static int nl80211_set_station_tdls(struct genl_info
*info
,
4214 struct station_parameters
*params
)
4217 /* Dummy STA entry gets updated once the peer capabilities are known */
4218 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4219 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4220 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4222 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4223 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4225 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4227 err
= nl80211_parse_sta_channel_info(info
, params
);
4231 return nl80211_parse_sta_wme(info
, params
);
4234 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
4236 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4237 struct net_device
*dev
= info
->user_ptr
[1];
4238 struct station_parameters params
;
4242 memset(¶ms
, 0, sizeof(params
));
4244 if (!rdev
->ops
->change_station
)
4248 * AID and listen_interval properties can be set only for unassociated
4249 * station. Include these parameters here and will check them in
4250 * cfg80211_check_station_change().
4252 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4253 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4255 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4256 params
.listen_interval
=
4257 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4259 params
.listen_interval
= -1;
4261 if (!info
->attrs
[NL80211_ATTR_MAC
])
4264 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4266 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
4267 params
.supported_rates
=
4268 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4269 params
.supported_rates_len
=
4270 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4273 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4275 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4276 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4279 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4281 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4282 params
.ext_capab_len
=
4283 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4286 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4289 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4290 params
.plink_action
=
4291 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4292 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4296 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
4297 params
.plink_state
=
4298 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
4299 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
4301 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
4304 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
4305 enum nl80211_mesh_power_mode pm
= nla_get_u32(
4306 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
4308 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
4309 pm
> NL80211_MESH_POWER_MAX
)
4312 params
.local_pm
= pm
;
4315 /* Include parameters for TDLS peer (will check later) */
4316 err
= nl80211_set_station_tdls(info
, ¶ms
);
4320 params
.vlan
= get_vlan(info
, rdev
);
4321 if (IS_ERR(params
.vlan
))
4322 return PTR_ERR(params
.vlan
);
4324 switch (dev
->ieee80211_ptr
->iftype
) {
4325 case NL80211_IFTYPE_AP
:
4326 case NL80211_IFTYPE_AP_VLAN
:
4327 case NL80211_IFTYPE_P2P_GO
:
4328 case NL80211_IFTYPE_P2P_CLIENT
:
4329 case NL80211_IFTYPE_STATION
:
4330 case NL80211_IFTYPE_ADHOC
:
4331 case NL80211_IFTYPE_MESH_POINT
:
4338 /* driver will call cfg80211_check_station_change() */
4339 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4343 dev_put(params
.vlan
);
4348 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4350 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4352 struct net_device
*dev
= info
->user_ptr
[1];
4353 struct station_parameters params
;
4354 u8
*mac_addr
= NULL
;
4356 memset(¶ms
, 0, sizeof(params
));
4358 if (!rdev
->ops
->add_station
)
4361 if (!info
->attrs
[NL80211_ATTR_MAC
])
4364 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4367 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4370 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4371 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4374 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4375 params
.supported_rates
=
4376 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4377 params
.supported_rates_len
=
4378 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4379 params
.listen_interval
=
4380 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4382 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4383 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4385 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4386 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4389 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4391 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4392 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4395 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4397 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4398 params
.ext_capab_len
=
4399 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4402 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4404 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4406 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4408 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4410 if (info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]) {
4411 params
.opmode_notif_used
= true;
4412 params
.opmode_notif
=
4413 nla_get_u8(info
->attrs
[NL80211_ATTR_OPMODE_NOTIF
]);
4416 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4417 params
.plink_action
=
4418 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4419 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4423 err
= nl80211_parse_sta_channel_info(info
, ¶ms
);
4427 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4431 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4434 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4435 * as userspace might just pass through the capabilities from the IEs
4436 * directly, rather than enforcing this restriction and returning an
4437 * error in this case.
4439 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4440 params
.ht_capa
= NULL
;
4441 params
.vht_capa
= NULL
;
4444 /* When you run into this, adjust the code below for the new flag */
4445 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4447 switch (dev
->ieee80211_ptr
->iftype
) {
4448 case NL80211_IFTYPE_AP
:
4449 case NL80211_IFTYPE_AP_VLAN
:
4450 case NL80211_IFTYPE_P2P_GO
:
4451 /* ignore WME attributes if iface/sta is not capable */
4452 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4453 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4454 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4456 /* TDLS peers cannot be added */
4457 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4458 info
->attrs
[NL80211_ATTR_PEER_AID
])
4460 /* but don't bother the driver with it */
4461 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4463 /* allow authenticated/associated only if driver handles it */
4464 if (!(rdev
->wiphy
.features
&
4465 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4466 params
.sta_flags_mask
&
4467 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4468 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4471 /* must be last in here for error handling */
4472 params
.vlan
= get_vlan(info
, rdev
);
4473 if (IS_ERR(params
.vlan
))
4474 return PTR_ERR(params
.vlan
);
4476 case NL80211_IFTYPE_MESH_POINT
:
4477 /* ignore uAPSD data */
4478 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4480 /* associated is disallowed */
4481 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4483 /* TDLS peers cannot be added */
4484 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4485 info
->attrs
[NL80211_ATTR_PEER_AID
])
4488 case NL80211_IFTYPE_STATION
:
4489 case NL80211_IFTYPE_P2P_CLIENT
:
4490 /* ignore uAPSD data */
4491 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4493 /* these are disallowed */
4494 if (params
.sta_flags_mask
&
4495 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4496 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4498 /* Only TDLS peers can be added */
4499 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4501 /* Can only add if TDLS ... */
4502 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4504 /* ... with external setup is supported */
4505 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4508 * Older wpa_supplicant versions always mark the TDLS peer
4509 * as authorized, but it shouldn't yet be.
4511 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4517 /* be aware of params.vlan when changing code here */
4519 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4522 dev_put(params
.vlan
);
4526 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4528 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4529 struct net_device
*dev
= info
->user_ptr
[1];
4530 struct station_del_parameters params
;
4532 memset(¶ms
, 0, sizeof(params
));
4534 if (info
->attrs
[NL80211_ATTR_MAC
])
4535 params
.mac
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4537 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4538 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4539 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4540 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4543 if (!rdev
->ops
->del_station
)
4546 if (info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]) {
4548 nla_get_u8(info
->attrs
[NL80211_ATTR_MGMT_SUBTYPE
]);
4549 if (params
.subtype
!= IEEE80211_STYPE_DISASSOC
>> 4 &&
4550 params
.subtype
!= IEEE80211_STYPE_DEAUTH
>> 4)
4553 /* Default to Deauthentication frame */
4554 params
.subtype
= IEEE80211_STYPE_DEAUTH
>> 4;
4557 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
4558 params
.reason_code
=
4559 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4560 if (params
.reason_code
== 0)
4561 return -EINVAL
; /* 0 is reserved */
4563 /* Default to reason code 2 */
4564 params
.reason_code
= WLAN_REASON_PREV_AUTH_NOT_VALID
;
4567 return rdev_del_station(rdev
, dev
, ¶ms
);
4570 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4571 int flags
, struct net_device
*dev
,
4572 u8
*dst
, u8
*next_hop
,
4573 struct mpath_info
*pinfo
)
4576 struct nlattr
*pinfoattr
;
4578 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_MPATH
);
4582 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4583 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4584 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4585 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4586 goto nla_put_failure
;
4588 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4590 goto nla_put_failure
;
4591 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4592 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4594 goto nla_put_failure
;
4595 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4596 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4597 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4598 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4600 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4601 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4603 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4604 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4606 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4607 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4608 pinfo
->discovery_timeout
)) ||
4609 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4610 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4611 pinfo
->discovery_retries
)))
4612 goto nla_put_failure
;
4614 nla_nest_end(msg
, pinfoattr
);
4616 genlmsg_end(msg
, hdr
);
4620 genlmsg_cancel(msg
, hdr
);
4624 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4625 struct netlink_callback
*cb
)
4627 struct mpath_info pinfo
;
4628 struct cfg80211_registered_device
*rdev
;
4629 struct wireless_dev
*wdev
;
4631 u8 next_hop
[ETH_ALEN
];
4632 int path_idx
= cb
->args
[2];
4636 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4640 if (!rdev
->ops
->dump_mpath
) {
4645 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4651 err
= rdev_dump_mpath(rdev
, wdev
->netdev
, path_idx
, dst
,
4658 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4659 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4660 wdev
->netdev
, dst
, next_hop
,
4669 cb
->args
[2] = path_idx
;
4676 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4678 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4680 struct net_device
*dev
= info
->user_ptr
[1];
4681 struct mpath_info pinfo
;
4682 struct sk_buff
*msg
;
4684 u8 next_hop
[ETH_ALEN
];
4686 memset(&pinfo
, 0, sizeof(pinfo
));
4688 if (!info
->attrs
[NL80211_ATTR_MAC
])
4691 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4693 if (!rdev
->ops
->get_mpath
)
4696 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4699 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4703 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4707 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4708 dev
, dst
, next_hop
, &pinfo
) < 0) {
4713 return genlmsg_reply(msg
, info
);
4716 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4718 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4719 struct net_device
*dev
= info
->user_ptr
[1];
4721 u8
*next_hop
= NULL
;
4723 if (!info
->attrs
[NL80211_ATTR_MAC
])
4726 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4729 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4730 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4732 if (!rdev
->ops
->change_mpath
)
4735 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4738 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4741 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4743 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4744 struct net_device
*dev
= info
->user_ptr
[1];
4746 u8
*next_hop
= NULL
;
4748 if (!info
->attrs
[NL80211_ATTR_MAC
])
4751 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4754 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4755 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4757 if (!rdev
->ops
->add_mpath
)
4760 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4763 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4766 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4768 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4769 struct net_device
*dev
= info
->user_ptr
[1];
4772 if (info
->attrs
[NL80211_ATTR_MAC
])
4773 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4775 if (!rdev
->ops
->del_mpath
)
4778 return rdev_del_mpath(rdev
, dev
, dst
);
4781 static int nl80211_get_mpp(struct sk_buff
*skb
, struct genl_info
*info
)
4783 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4785 struct net_device
*dev
= info
->user_ptr
[1];
4786 struct mpath_info pinfo
;
4787 struct sk_buff
*msg
;
4791 memset(&pinfo
, 0, sizeof(pinfo
));
4793 if (!info
->attrs
[NL80211_ATTR_MAC
])
4796 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4798 if (!rdev
->ops
->get_mpp
)
4801 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4804 err
= rdev_get_mpp(rdev
, dev
, dst
, mpp
, &pinfo
);
4808 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4812 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4813 dev
, dst
, mpp
, &pinfo
) < 0) {
4818 return genlmsg_reply(msg
, info
);
4821 static int nl80211_dump_mpp(struct sk_buff
*skb
,
4822 struct netlink_callback
*cb
)
4824 struct mpath_info pinfo
;
4825 struct cfg80211_registered_device
*rdev
;
4826 struct wireless_dev
*wdev
;
4829 int path_idx
= cb
->args
[2];
4833 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
4837 if (!rdev
->ops
->dump_mpp
) {
4842 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4848 err
= rdev_dump_mpp(rdev
, wdev
->netdev
, path_idx
, dst
,
4855 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4856 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4857 wdev
->netdev
, dst
, mpp
,
4865 cb
->args
[2] = path_idx
;
4872 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4875 struct net_device
*dev
= info
->user_ptr
[1];
4876 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4877 struct bss_parameters params
;
4880 memset(¶ms
, 0, sizeof(params
));
4881 /* default to not changing parameters */
4882 params
.use_cts_prot
= -1;
4883 params
.use_short_preamble
= -1;
4884 params
.use_short_slot_time
= -1;
4885 params
.ap_isolate
= -1;
4886 params
.ht_opmode
= -1;
4887 params
.p2p_ctwindow
= -1;
4888 params
.p2p_opp_ps
= -1;
4890 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4891 params
.use_cts_prot
=
4892 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4893 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4894 params
.use_short_preamble
=
4895 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4896 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4897 params
.use_short_slot_time
=
4898 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4899 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4900 params
.basic_rates
=
4901 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4902 params
.basic_rates_len
=
4903 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4905 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4906 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4907 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4909 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4911 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4912 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4914 params
.p2p_ctwindow
=
4915 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4916 if (params
.p2p_ctwindow
< 0)
4918 if (params
.p2p_ctwindow
!= 0 &&
4919 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4923 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4926 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4928 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4931 params
.p2p_opp_ps
= tmp
;
4932 if (params
.p2p_opp_ps
&&
4933 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4937 if (!rdev
->ops
->change_bss
)
4940 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4941 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4945 err
= rdev_change_bss(rdev
, dev
, ¶ms
);
4951 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4955 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4960 * You should only get this when cfg80211 hasn't yet initialized
4961 * completely when built-in to the kernel right between the time
4962 * window between nl80211_init() and regulatory_init(), if that is
4965 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4966 return -EINPROGRESS
;
4968 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4969 user_reg_hint_type
=
4970 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4972 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4974 switch (user_reg_hint_type
) {
4975 case NL80211_USER_REG_HINT_USER
:
4976 case NL80211_USER_REG_HINT_CELL_BASE
:
4977 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4980 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4981 return regulatory_hint_user(data
, user_reg_hint_type
);
4982 case NL80211_USER_REG_HINT_INDOOR
:
4983 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
]) {
4984 owner_nlportid
= info
->snd_portid
;
4985 is_indoor
= !!info
->attrs
[NL80211_ATTR_REG_INDOOR
];
4991 return regulatory_hint_indoor(is_indoor
, owner_nlportid
);
4997 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4998 struct genl_info
*info
)
5000 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5001 struct net_device
*dev
= info
->user_ptr
[1];
5002 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5003 struct mesh_config cur_params
;
5006 struct nlattr
*pinfoattr
;
5007 struct sk_buff
*msg
;
5009 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5012 if (!rdev
->ops
->get_mesh_config
)
5016 /* If not connected, get default parameters */
5017 if (!wdev
->mesh_id_len
)
5018 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
5020 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
5026 /* Draw up a netlink message to send back */
5027 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5030 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5031 NL80211_CMD_GET_MESH_CONFIG
);
5034 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
5036 goto nla_put_failure
;
5037 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
5038 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5039 cur_params
.dot11MeshRetryTimeout
) ||
5040 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5041 cur_params
.dot11MeshConfirmTimeout
) ||
5042 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5043 cur_params
.dot11MeshHoldingTimeout
) ||
5044 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5045 cur_params
.dot11MeshMaxPeerLinks
) ||
5046 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
5047 cur_params
.dot11MeshMaxRetries
) ||
5048 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
5049 cur_params
.dot11MeshTTL
) ||
5050 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
5051 cur_params
.element_ttl
) ||
5052 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5053 cur_params
.auto_open_plinks
) ||
5054 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5055 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
5056 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5057 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
5058 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5059 cur_params
.path_refresh_time
) ||
5060 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5061 cur_params
.min_discovery_timeout
) ||
5062 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5063 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
5064 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5065 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
5066 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5067 cur_params
.dot11MeshHWMPperrMinInterval
) ||
5068 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5069 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
5070 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5071 cur_params
.dot11MeshHWMPRootMode
) ||
5072 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5073 cur_params
.dot11MeshHWMPRannInterval
) ||
5074 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5075 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
5076 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
5077 cur_params
.dot11MeshForwarding
) ||
5078 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5079 cur_params
.rssi_threshold
) ||
5080 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
5081 cur_params
.ht_opmode
) ||
5082 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5083 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
5084 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5085 cur_params
.dot11MeshHWMProotInterval
) ||
5086 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5087 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
5088 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
5089 cur_params
.power_mode
) ||
5090 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
5091 cur_params
.dot11MeshAwakeWindowDuration
) ||
5092 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5093 cur_params
.plink_timeout
))
5094 goto nla_put_failure
;
5095 nla_nest_end(msg
, pinfoattr
);
5096 genlmsg_end(msg
, hdr
);
5097 return genlmsg_reply(msg
, info
);
5100 genlmsg_cancel(msg
, hdr
);
5106 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
5107 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
5108 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
5109 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
5110 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
5111 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
5112 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
5113 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
5114 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
5115 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
5116 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
5117 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
5118 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
5119 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
5120 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
5121 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
5122 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
5123 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
5124 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
5125 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
5126 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
5127 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
5128 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
5129 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
5130 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
5131 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
5132 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
5133 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
5134 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
5137 static const struct nla_policy
5138 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
5139 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
5140 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
5141 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
5142 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
5143 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
5144 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
5145 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
5146 .len
= IEEE80211_MAX_DATA_LEN
},
5147 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
5150 static int nl80211_parse_mesh_config(struct genl_info
*info
,
5151 struct mesh_config
*cfg
,
5154 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
5157 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5160 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5162 cfg->param = fn(tb[attr]); \
5163 mask |= (1 << (attr - 1)); \
5168 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
5170 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
5171 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
5172 nl80211_meshconf_params_policy
))
5175 /* This makes sure that there aren't more than 32 mesh config
5176 * parameters (otherwise our bitfield scheme would not work.) */
5177 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
5179 /* Fill in the params struct */
5180 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
5181 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
5183 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
5184 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
5186 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
5187 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
5189 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
5190 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
5192 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
5193 mask
, NL80211_MESHCONF_MAX_RETRIES
,
5195 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
5196 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
5197 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
5198 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
5200 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
5201 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
5203 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
5205 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
5207 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
5208 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
5210 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
5211 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
5213 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
5214 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
5216 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
5218 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
5220 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
5222 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
5224 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
5226 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
5228 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5229 dot11MeshHWMPnetDiameterTraversalTime
,
5231 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
5233 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
5234 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
5236 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
5237 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
5239 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5240 dot11MeshGateAnnouncementProtocol
, 0, 1,
5241 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
5243 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
5244 mask
, NL80211_MESHCONF_FORWARDING
,
5246 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
5247 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
5249 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
5250 mask
, NL80211_MESHCONF_HT_OPMODE
,
5252 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
5254 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
5256 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
5257 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
5259 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
5260 dot11MeshHWMPconfirmationInterval
,
5262 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
5264 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
5265 NL80211_MESH_POWER_ACTIVE
,
5266 NL80211_MESH_POWER_MAX
,
5267 mask
, NL80211_MESHCONF_POWER_MODE
,
5269 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
5271 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
5272 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 0, 0xffffffff,
5273 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
5280 #undef FILL_IN_MESH_PARAM_IF_SET
5283 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
5284 struct mesh_setup
*setup
)
5286 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5287 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
5289 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
5291 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
5292 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
5293 nl80211_mesh_setup_params_policy
))
5296 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
5297 setup
->sync_method
=
5298 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
5299 IEEE80211_SYNC_METHOD_VENDOR
:
5300 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
5302 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
5303 setup
->path_sel_proto
=
5304 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
5305 IEEE80211_PATH_PROTOCOL_VENDOR
:
5306 IEEE80211_PATH_PROTOCOL_HWMP
;
5308 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
5309 setup
->path_metric
=
5310 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
5311 IEEE80211_PATH_METRIC_VENDOR
:
5312 IEEE80211_PATH_METRIC_AIRTIME
;
5315 if (tb
[NL80211_MESH_SETUP_IE
]) {
5316 struct nlattr
*ieattr
=
5317 tb
[NL80211_MESH_SETUP_IE
];
5318 if (!is_valid_ie_attr(ieattr
))
5320 setup
->ie
= nla_data(ieattr
);
5321 setup
->ie_len
= nla_len(ieattr
);
5323 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
5324 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
5326 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
5327 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
5328 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
5329 if (setup
->is_secure
)
5330 setup
->user_mpm
= true;
5332 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
5333 if (!setup
->user_mpm
)
5336 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
5342 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
5343 struct genl_info
*info
)
5345 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5346 struct net_device
*dev
= info
->user_ptr
[1];
5347 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5348 struct mesh_config cfg
;
5352 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
5355 if (!rdev
->ops
->update_mesh_config
)
5358 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
5363 if (!wdev
->mesh_id_len
)
5367 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
5374 static int nl80211_put_regdom(const struct ieee80211_regdomain
*regdom
,
5375 struct sk_buff
*msg
)
5377 struct nlattr
*nl_reg_rules
;
5380 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
5381 (regdom
->dfs_region
&&
5382 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
5383 goto nla_put_failure
;
5385 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
5387 goto nla_put_failure
;
5389 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
5390 struct nlattr
*nl_reg_rule
;
5391 const struct ieee80211_reg_rule
*reg_rule
;
5392 const struct ieee80211_freq_range
*freq_range
;
5393 const struct ieee80211_power_rule
*power_rule
;
5394 unsigned int max_bandwidth_khz
;
5396 reg_rule
= ®dom
->reg_rules
[i
];
5397 freq_range
= ®_rule
->freq_range
;
5398 power_rule
= ®_rule
->power_rule
;
5400 nl_reg_rule
= nla_nest_start(msg
, i
);
5402 goto nla_put_failure
;
5404 max_bandwidth_khz
= freq_range
->max_bandwidth_khz
;
5405 if (!max_bandwidth_khz
)
5406 max_bandwidth_khz
= reg_get_max_bandwidth(regdom
,
5409 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
5411 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
5412 freq_range
->start_freq_khz
) ||
5413 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
5414 freq_range
->end_freq_khz
) ||
5415 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
5416 max_bandwidth_khz
) ||
5417 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
5418 power_rule
->max_antenna_gain
) ||
5419 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
5420 power_rule
->max_eirp
) ||
5421 nla_put_u32(msg
, NL80211_ATTR_DFS_CAC_TIME
,
5422 reg_rule
->dfs_cac_ms
))
5423 goto nla_put_failure
;
5425 nla_nest_end(msg
, nl_reg_rule
);
5428 nla_nest_end(msg
, nl_reg_rules
);
5435 static int nl80211_get_reg_do(struct sk_buff
*skb
, struct genl_info
*info
)
5437 const struct ieee80211_regdomain
*regdom
= NULL
;
5438 struct cfg80211_registered_device
*rdev
;
5439 struct wiphy
*wiphy
= NULL
;
5440 struct sk_buff
*msg
;
5443 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5447 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5448 NL80211_CMD_GET_REG
);
5452 if (info
->attrs
[NL80211_ATTR_WIPHY
]) {
5455 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
5458 return PTR_ERR(rdev
);
5461 wiphy
= &rdev
->wiphy
;
5462 self_managed
= wiphy
->regulatory_flags
&
5463 REGULATORY_WIPHY_SELF_MANAGED
;
5464 regdom
= get_wiphy_regdom(wiphy
);
5466 /* a self-managed-reg device must have a private regdom */
5467 if (WARN_ON(!regdom
&& self_managed
)) {
5473 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5474 goto nla_put_failure
;
5477 if (!wiphy
&& reg_last_request_cell_base() &&
5478 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5479 NL80211_USER_REG_HINT_CELL_BASE
))
5480 goto nla_put_failure
;
5485 regdom
= rcu_dereference(cfg80211_regdomain
);
5487 if (nl80211_put_regdom(regdom
, msg
))
5488 goto nla_put_failure_rcu
;
5492 genlmsg_end(msg
, hdr
);
5493 return genlmsg_reply(msg
, info
);
5495 nla_put_failure_rcu
:
5498 genlmsg_cancel(msg
, hdr
);
5504 static int nl80211_send_regdom(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5505 u32 seq
, int flags
, struct wiphy
*wiphy
,
5506 const struct ieee80211_regdomain
*regdom
)
5508 void *hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5509 NL80211_CMD_GET_REG
);
5514 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5516 if (nl80211_put_regdom(regdom
, msg
))
5517 goto nla_put_failure
;
5519 if (!wiphy
&& reg_last_request_cell_base() &&
5520 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
5521 NL80211_USER_REG_HINT_CELL_BASE
))
5522 goto nla_put_failure
;
5525 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
5526 goto nla_put_failure
;
5528 if (wiphy
&& wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
5529 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
5530 goto nla_put_failure
;
5532 genlmsg_end(msg
, hdr
);
5536 genlmsg_cancel(msg
, hdr
);
5540 static int nl80211_get_reg_dump(struct sk_buff
*skb
,
5541 struct netlink_callback
*cb
)
5543 const struct ieee80211_regdomain
*regdom
= NULL
;
5544 struct cfg80211_registered_device
*rdev
;
5545 int err
, reg_idx
, start
= cb
->args
[2];
5549 if (cfg80211_regdomain
&& start
== 0) {
5550 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5552 rtnl_dereference(cfg80211_regdomain
));
5557 /* the global regdom is idx 0 */
5559 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
5560 regdom
= get_wiphy_regdom(&rdev
->wiphy
);
5564 if (++reg_idx
<= start
)
5567 err
= nl80211_send_regdom(skb
, cb
, cb
->nlh
->nlmsg_seq
,
5568 NLM_F_MULTI
, &rdev
->wiphy
, regdom
);
5575 cb
->args
[2] = reg_idx
;
5582 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
5583 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
5584 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
5585 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
5586 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
5587 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
5588 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
5589 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
5590 [NL80211_ATTR_DFS_CAC_TIME
] = { .type
= NLA_U32
},
5593 static int parse_reg_rule(struct nlattr
*tb
[],
5594 struct ieee80211_reg_rule
*reg_rule
)
5596 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
5597 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
5599 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
5601 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
5603 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
5605 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
5607 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
5610 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
5612 freq_range
->start_freq_khz
=
5613 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
5614 freq_range
->end_freq_khz
=
5615 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
5616 freq_range
->max_bandwidth_khz
=
5617 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
5619 power_rule
->max_eirp
=
5620 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
5622 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
5623 power_rule
->max_antenna_gain
=
5624 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
5626 if (tb
[NL80211_ATTR_DFS_CAC_TIME
])
5627 reg_rule
->dfs_cac_ms
=
5628 nla_get_u32(tb
[NL80211_ATTR_DFS_CAC_TIME
]);
5633 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5635 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5636 struct nlattr
*nl_reg_rule
;
5638 int rem_reg_rules
, r
;
5639 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5640 enum nl80211_dfs_regions dfs_region
= NL80211_DFS_UNSET
;
5641 struct ieee80211_regdomain
*rd
;
5643 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5646 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5649 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5651 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5652 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5654 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5657 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5661 if (!reg_is_valid_request(alpha2
))
5664 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5665 num_rules
* sizeof(struct ieee80211_reg_rule
);
5667 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5671 rd
->n_reg_rules
= num_rules
;
5672 rd
->alpha2
[0] = alpha2
[0];
5673 rd
->alpha2
[1] = alpha2
[1];
5676 * Disable DFS master mode if the DFS region was
5677 * not supported or known on this kernel.
5679 if (reg_supported_dfs_region(dfs_region
))
5680 rd
->dfs_region
= dfs_region
;
5682 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5684 r
= nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5685 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5689 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5695 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5701 r
= set_regdom(rd
, REGD_SOURCE_CRDA
);
5702 /* set_regdom took ownership */
5709 #endif /* CONFIG_CFG80211_CRDA_SUPPORT */
5711 static int validate_scan_freqs(struct nlattr
*freqs
)
5713 struct nlattr
*attr1
, *attr2
;
5714 int n_channels
= 0, tmp1
, tmp2
;
5716 nla_for_each_nested(attr1
, freqs
, tmp1
)
5717 if (nla_len(attr1
) != sizeof(u32
))
5720 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5723 * Some hardware has a limited channel list for
5724 * scanning, and it is pretty much nonsensical
5725 * to scan for a channel twice, so disallow that
5726 * and don't require drivers to check that the
5727 * channel list they get isn't longer than what
5728 * they can scan, as long as they can scan all
5729 * the channels they registered at once.
5731 nla_for_each_nested(attr2
, freqs
, tmp2
)
5732 if (attr1
!= attr2
&&
5733 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5740 static int nl80211_parse_random_mac(struct nlattr
**attrs
,
5741 u8
*mac_addr
, u8
*mac_addr_mask
)
5745 if (!attrs
[NL80211_ATTR_MAC
] && !attrs
[NL80211_ATTR_MAC_MASK
]) {
5746 eth_zero_addr(mac_addr
);
5747 eth_zero_addr(mac_addr_mask
);
5749 mac_addr_mask
[0] = 0x3;
5754 /* need both or none */
5755 if (!attrs
[NL80211_ATTR_MAC
] || !attrs
[NL80211_ATTR_MAC_MASK
])
5758 memcpy(mac_addr
, nla_data(attrs
[NL80211_ATTR_MAC
]), ETH_ALEN
);
5759 memcpy(mac_addr_mask
, nla_data(attrs
[NL80211_ATTR_MAC_MASK
]), ETH_ALEN
);
5761 /* don't allow or configure an mcast address */
5762 if (!is_multicast_ether_addr(mac_addr_mask
) ||
5763 is_multicast_ether_addr(mac_addr
))
5767 * allow users to pass a MAC address that has bits set outside
5768 * of the mask, but don't bother drivers with having to deal
5771 for (i
= 0; i
< ETH_ALEN
; i
++)
5772 mac_addr
[i
] &= mac_addr_mask
[i
];
5777 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5779 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5780 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5781 struct cfg80211_scan_request
*request
;
5782 struct nlattr
*attr
;
5783 struct wiphy
*wiphy
;
5784 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5787 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5790 wiphy
= &rdev
->wiphy
;
5792 if (!rdev
->ops
->scan
)
5795 if (rdev
->scan_req
|| rdev
->scan_msg
) {
5800 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5801 n_channels
= validate_scan_freqs(
5802 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5808 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
5811 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5812 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5815 if (n_ssids
> wiphy
->max_scan_ssids
) {
5820 if (info
->attrs
[NL80211_ATTR_IE
])
5821 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5825 if (ie_len
> wiphy
->max_scan_ie_len
) {
5830 request
= kzalloc(sizeof(*request
)
5831 + sizeof(*request
->ssids
) * n_ssids
5832 + sizeof(*request
->channels
) * n_channels
5833 + ie_len
, GFP_KERNEL
);
5840 request
->ssids
= (void *)&request
->channels
[n_channels
];
5841 request
->n_ssids
= n_ssids
;
5844 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5846 request
->ie
= (void *)(request
->channels
+ n_channels
);
5850 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5851 /* user specified, bail out if channel not found */
5852 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5853 struct ieee80211_channel
*chan
;
5855 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5862 /* ignore disabled channels */
5863 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5866 request
->channels
[i
] = chan
;
5870 enum nl80211_band band
;
5873 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
5875 if (!wiphy
->bands
[band
])
5877 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5878 struct ieee80211_channel
*chan
;
5880 chan
= &wiphy
->bands
[band
]->channels
[j
];
5882 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5885 request
->channels
[i
] = chan
;
5896 request
->n_channels
= i
;
5900 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5901 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5905 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5906 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5911 if (info
->attrs
[NL80211_ATTR_IE
]) {
5912 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5913 memcpy((void *)request
->ie
,
5914 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5918 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++)
5919 if (wiphy
->bands
[i
])
5921 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5923 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5924 nla_for_each_nested(attr
,
5925 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5927 enum nl80211_band band
= nla_type(attr
);
5929 if (band
< 0 || band
>= NUM_NL80211_BANDS
) {
5934 if (!wiphy
->bands
[band
])
5937 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5940 &request
->rates
[band
]);
5946 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5947 request
->flags
= nla_get_u32(
5948 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5949 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5950 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
5955 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
5956 if (!(wiphy
->features
&
5957 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
)) {
5962 if (wdev
->current_bss
) {
5967 err
= nl80211_parse_random_mac(info
->attrs
,
5969 request
->mac_addr_mask
);
5976 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5978 request
->wdev
= wdev
;
5979 request
->wiphy
= &rdev
->wiphy
;
5980 request
->scan_start
= jiffies
;
5982 rdev
->scan_req
= request
;
5983 err
= rdev_scan(rdev
, request
);
5986 nl80211_send_scan_start(rdev
, wdev
);
5988 dev_hold(wdev
->netdev
);
5991 rdev
->scan_req
= NULL
;
6000 nl80211_parse_sched_scan_plans(struct wiphy
*wiphy
, int n_plans
,
6001 struct cfg80211_sched_scan_request
*request
,
6002 struct nlattr
**attrs
)
6004 int tmp
, err
, i
= 0;
6005 struct nlattr
*attr
;
6007 if (!attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6011 * If scan plans are not specified,
6012 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6013 * case one scan plan will be set with the specified scan
6014 * interval and infinite number of iterations.
6016 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6019 interval
= nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
6023 request
->scan_plans
[0].interval
=
6024 DIV_ROUND_UP(interval
, MSEC_PER_SEC
);
6025 if (!request
->scan_plans
[0].interval
)
6028 if (request
->scan_plans
[0].interval
>
6029 wiphy
->max_sched_scan_plan_interval
)
6030 request
->scan_plans
[0].interval
=
6031 wiphy
->max_sched_scan_plan_interval
;
6036 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
) {
6037 struct nlattr
*plan
[NL80211_SCHED_SCAN_PLAN_MAX
+ 1];
6039 if (WARN_ON(i
>= n_plans
))
6042 err
= nla_parse(plan
, NL80211_SCHED_SCAN_PLAN_MAX
,
6043 nla_data(attr
), nla_len(attr
),
6044 nl80211_plan_policy
);
6048 if (!plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
])
6051 request
->scan_plans
[i
].interval
=
6052 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_INTERVAL
]);
6053 if (!request
->scan_plans
[i
].interval
||
6054 request
->scan_plans
[i
].interval
>
6055 wiphy
->max_sched_scan_plan_interval
)
6058 if (plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]) {
6059 request
->scan_plans
[i
].iterations
=
6060 nla_get_u32(plan
[NL80211_SCHED_SCAN_PLAN_ITERATIONS
]);
6061 if (!request
->scan_plans
[i
].iterations
||
6062 (request
->scan_plans
[i
].iterations
>
6063 wiphy
->max_sched_scan_plan_iterations
))
6065 } else if (i
< n_plans
- 1) {
6067 * All scan plans but the last one must specify
6068 * a finite number of iterations
6077 * The last scan plan must not specify the number of
6078 * iterations, it is supposed to run infinitely
6080 if (request
->scan_plans
[n_plans
- 1].iterations
)
6086 static struct cfg80211_sched_scan_request
*
6087 nl80211_parse_sched_scan(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
6088 struct nlattr
**attrs
)
6090 struct cfg80211_sched_scan_request
*request
;
6091 struct nlattr
*attr
;
6092 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
, n_plans
= 0;
6093 enum nl80211_band band
;
6095 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
6096 s32 default_match_rssi
= NL80211_SCAN_RSSI_THOLD_OFF
;
6098 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]))
6099 return ERR_PTR(-EINVAL
);
6101 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6102 n_channels
= validate_scan_freqs(
6103 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
6105 return ERR_PTR(-EINVAL
);
6107 n_channels
= ieee80211_get_num_supported_channels(wiphy
);
6110 if (attrs
[NL80211_ATTR_SCAN_SSIDS
])
6111 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6115 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
6116 return ERR_PTR(-EINVAL
);
6119 * First, count the number of 'real' matchsets. Due to an issue with
6120 * the old implementation, matchsets containing only the RSSI attribute
6121 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6122 * RSSI for all matchsets, rather than their own matchset for reporting
6123 * all APs with a strong RSSI. This is needed to be compatible with
6124 * older userspace that treated a matchset with only the RSSI as the
6125 * global RSSI for all other matchsets - if there are other matchsets.
6127 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6128 nla_for_each_nested(attr
,
6129 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6131 struct nlattr
*rssi
;
6133 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6134 nla_data(attr
), nla_len(attr
),
6135 nl80211_match_policy
);
6137 return ERR_PTR(err
);
6138 /* add other standalone attributes here */
6139 if (tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
]) {
6143 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6145 default_match_rssi
= nla_get_s32(rssi
);
6149 /* However, if there's no other matchset, add the RSSI one */
6150 if (!n_match_sets
&& default_match_rssi
!= NL80211_SCAN_RSSI_THOLD_OFF
)
6153 if (n_match_sets
> wiphy
->max_match_sets
)
6154 return ERR_PTR(-EINVAL
);
6156 if (attrs
[NL80211_ATTR_IE
])
6157 ie_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
6161 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
6162 return ERR_PTR(-EINVAL
);
6164 if (attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
]) {
6166 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6167 * each scan plan already specifies its own interval
6169 if (attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6170 return ERR_PTR(-EINVAL
);
6172 nla_for_each_nested(attr
,
6173 attrs
[NL80211_ATTR_SCHED_SCAN_PLANS
], tmp
)
6177 * The scan interval attribute is kept for backward
6178 * compatibility. If no scan plans are specified and sched scan
6179 * interval is specified, one scan plan will be set with this
6180 * scan interval and infinite number of iterations.
6182 if (!attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
6183 return ERR_PTR(-EINVAL
);
6188 if (!n_plans
|| n_plans
> wiphy
->max_sched_scan_plans
)
6189 return ERR_PTR(-EINVAL
);
6191 request
= kzalloc(sizeof(*request
)
6192 + sizeof(*request
->ssids
) * n_ssids
6193 + sizeof(*request
->match_sets
) * n_match_sets
6194 + sizeof(*request
->scan_plans
) * n_plans
6195 + sizeof(*request
->channels
) * n_channels
6196 + ie_len
, GFP_KERNEL
);
6198 return ERR_PTR(-ENOMEM
);
6201 request
->ssids
= (void *)&request
->channels
[n_channels
];
6202 request
->n_ssids
= n_ssids
;
6205 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
6207 request
->ie
= (void *)(request
->channels
+ n_channels
);
6212 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
6214 request
->match_sets
=
6215 (void *)(request
->ssids
+ n_ssids
);
6217 request
->match_sets
=
6218 (void *)(request
->channels
+ n_channels
);
6220 request
->n_match_sets
= n_match_sets
;
6223 request
->scan_plans
= (void *)(request
->match_sets
+
6225 else if (request
->ie
)
6226 request
->scan_plans
= (void *)(request
->ie
+ ie_len
);
6228 request
->scan_plans
= (void *)(request
->ssids
+ n_ssids
);
6230 request
->scan_plans
= (void *)(request
->channels
+ n_channels
);
6232 request
->n_scan_plans
= n_plans
;
6235 if (attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
6236 /* user specified, bail out if channel not found */
6237 nla_for_each_nested(attr
,
6238 attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
6240 struct ieee80211_channel
*chan
;
6242 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
6249 /* ignore disabled channels */
6250 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6253 request
->channels
[i
] = chan
;
6258 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
6260 if (!wiphy
->bands
[band
])
6262 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
6263 struct ieee80211_channel
*chan
;
6265 chan
= &wiphy
->bands
[band
]->channels
[j
];
6267 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
6270 request
->channels
[i
] = chan
;
6281 request
->n_channels
= i
;
6285 nla_for_each_nested(attr
, attrs
[NL80211_ATTR_SCAN_SSIDS
],
6287 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
6291 request
->ssids
[i
].ssid_len
= nla_len(attr
);
6292 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
6299 if (attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
6300 nla_for_each_nested(attr
,
6301 attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
6303 struct nlattr
*ssid
, *rssi
;
6305 err
= nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
6306 nla_data(attr
), nla_len(attr
),
6307 nl80211_match_policy
);
6310 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
6312 if (WARN_ON(i
>= n_match_sets
)) {
6313 /* this indicates a programming error,
6314 * the loop above should have verified
6321 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
6325 memcpy(request
->match_sets
[i
].ssid
.ssid
,
6326 nla_data(ssid
), nla_len(ssid
));
6327 request
->match_sets
[i
].ssid
.ssid_len
=
6329 /* special attribute - old implemenation w/a */
6330 request
->match_sets
[i
].rssi_thold
=
6332 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
6334 request
->match_sets
[i
].rssi_thold
=
6340 /* there was no other matchset, so the RSSI one is alone */
6341 if (i
== 0 && n_match_sets
)
6342 request
->match_sets
[0].rssi_thold
= default_match_rssi
;
6344 request
->min_rssi_thold
= INT_MAX
;
6345 for (i
= 0; i
< n_match_sets
; i
++)
6346 request
->min_rssi_thold
=
6347 min(request
->match_sets
[i
].rssi_thold
,
6348 request
->min_rssi_thold
);
6350 request
->min_rssi_thold
= NL80211_SCAN_RSSI_THOLD_OFF
;
6354 request
->ie_len
= ie_len
;
6355 memcpy((void *)request
->ie
,
6356 nla_data(attrs
[NL80211_ATTR_IE
]),
6360 if (attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
6361 request
->flags
= nla_get_u32(
6362 attrs
[NL80211_ATTR_SCAN_FLAGS
]);
6363 if ((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
6364 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) {
6369 if (request
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
) {
6370 u32 flg
= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
;
6372 if (!wdev
) /* must be net-detect */
6373 flg
= NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
6375 if (!(wiphy
->features
& flg
)) {
6380 if (wdev
&& wdev
->current_bss
) {
6385 err
= nl80211_parse_random_mac(attrs
, request
->mac_addr
,
6386 request
->mac_addr_mask
);
6392 if (attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
])
6394 nla_get_u32(attrs
[NL80211_ATTR_SCHED_SCAN_DELAY
]);
6396 err
= nl80211_parse_sched_scan_plans(wiphy
, n_plans
, request
, attrs
);
6400 request
->scan_start
= jiffies
;
6406 return ERR_PTR(err
);
6409 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
6410 struct genl_info
*info
)
6412 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6413 struct net_device
*dev
= info
->user_ptr
[1];
6414 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6415 struct cfg80211_sched_scan_request
*sched_scan_req
;
6418 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6419 !rdev
->ops
->sched_scan_start
)
6422 if (rdev
->sched_scan_req
)
6423 return -EINPROGRESS
;
6425 sched_scan_req
= nl80211_parse_sched_scan(&rdev
->wiphy
, wdev
,
6428 err
= PTR_ERR_OR_ZERO(sched_scan_req
);
6432 err
= rdev_sched_scan_start(rdev
, dev
, sched_scan_req
);
6436 sched_scan_req
->dev
= dev
;
6437 sched_scan_req
->wiphy
= &rdev
->wiphy
;
6439 if (info
->attrs
[NL80211_ATTR_SOCKET_OWNER
])
6440 sched_scan_req
->owner_nlportid
= info
->snd_portid
;
6442 rcu_assign_pointer(rdev
->sched_scan_req
, sched_scan_req
);
6444 nl80211_send_sched_scan(rdev
, dev
,
6445 NL80211_CMD_START_SCHED_SCAN
);
6449 kfree(sched_scan_req
);
6454 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
6455 struct genl_info
*info
)
6457 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6459 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
6460 !rdev
->ops
->sched_scan_stop
)
6463 return __cfg80211_stop_sched_scan(rdev
, false);
6466 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
6467 struct genl_info
*info
)
6469 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6470 struct net_device
*dev
= info
->user_ptr
[1];
6471 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6472 struct cfg80211_chan_def chandef
;
6473 enum nl80211_dfs_regions dfs_region
;
6474 unsigned int cac_time_ms
;
6477 dfs_region
= reg_get_dfs_region(wdev
->wiphy
);
6478 if (dfs_region
== NL80211_DFS_UNSET
)
6481 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6485 if (netif_carrier_ok(dev
))
6488 if (wdev
->cac_started
)
6491 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
,
6499 if (!cfg80211_chandef_dfs_usable(wdev
->wiphy
, &chandef
))
6502 if (!rdev
->ops
->start_radar_detection
)
6505 cac_time_ms
= cfg80211_chandef_dfs_cac_time(&rdev
->wiphy
, &chandef
);
6506 if (WARN_ON(!cac_time_ms
))
6507 cac_time_ms
= IEEE80211_DFS_MIN_CAC_TIME_MS
;
6509 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
,
6512 wdev
->chandef
= chandef
;
6513 wdev
->cac_started
= true;
6514 wdev
->cac_start_time
= jiffies
;
6515 wdev
->cac_time_ms
= cac_time_ms
;
6520 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
6522 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6523 struct net_device
*dev
= info
->user_ptr
[1];
6524 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6525 struct cfg80211_csa_settings params
;
6526 /* csa_attrs is defined static to avoid waste of stack size - this
6527 * function is called under RTNL lock, so this should not be a problem.
6529 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
6531 bool need_new_beacon
= false;
6535 if (!rdev
->ops
->channel_switch
||
6536 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
6539 switch (dev
->ieee80211_ptr
->iftype
) {
6540 case NL80211_IFTYPE_AP
:
6541 case NL80211_IFTYPE_P2P_GO
:
6542 need_new_beacon
= true;
6544 /* useless if AP is not running */
6545 if (!wdev
->beacon_interval
)
6548 case NL80211_IFTYPE_ADHOC
:
6549 if (!wdev
->ssid_len
)
6552 case NL80211_IFTYPE_MESH_POINT
:
6553 if (!wdev
->mesh_id_len
)
6560 memset(¶ms
, 0, sizeof(params
));
6562 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6563 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
6566 /* only important for AP, IBSS and mesh create IEs internally */
6567 if (need_new_beacon
&& !info
->attrs
[NL80211_ATTR_CSA_IES
])
6570 /* Even though the attribute is u32, the specification says
6571 * u8, so let's make sure we don't overflow.
6573 cs_count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
6577 params
.count
= cs_count
;
6579 if (!need_new_beacon
)
6582 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
6586 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
6587 info
->attrs
[NL80211_ATTR_CSA_IES
],
6592 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
6596 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
6599 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6600 if (!len
|| (len
% sizeof(u16
)))
6603 params
.n_counter_offsets_beacon
= len
/ sizeof(u16
);
6604 if (rdev
->wiphy
.max_num_csa_counters
&&
6605 (params
.n_counter_offsets_beacon
>
6606 rdev
->wiphy
.max_num_csa_counters
))
6609 params
.counter_offsets_beacon
=
6610 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
6612 /* sanity checks - counters should fit and be the same */
6613 for (i
= 0; i
< params
.n_counter_offsets_beacon
; i
++) {
6614 u16 offset
= params
.counter_offsets_beacon
[i
];
6616 if (offset
>= params
.beacon_csa
.tail_len
)
6619 if (params
.beacon_csa
.tail
[offset
] != params
.count
)
6623 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
6624 len
= nla_len(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6625 if (!len
|| (len
% sizeof(u16
)))
6628 params
.n_counter_offsets_presp
= len
/ sizeof(u16
);
6629 if (rdev
->wiphy
.max_num_csa_counters
&&
6630 (params
.n_counter_offsets_presp
>
6631 rdev
->wiphy
.max_num_csa_counters
))
6634 params
.counter_offsets_presp
=
6635 nla_data(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
6637 /* sanity checks - counters should fit and be the same */
6638 for (i
= 0; i
< params
.n_counter_offsets_presp
; i
++) {
6639 u16 offset
= params
.counter_offsets_presp
[i
];
6641 if (offset
>= params
.beacon_csa
.probe_resp_len
)
6644 if (params
.beacon_csa
.probe_resp
[offset
] !=
6651 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
6655 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, ¶ms
.chandef
,
6659 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
6666 params
.radar_required
= true;
6668 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
6669 params
.block_tx
= true;
6672 err
= rdev_channel_switch(rdev
, dev
, ¶ms
);
6678 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
6680 struct cfg80211_registered_device
*rdev
,
6681 struct wireless_dev
*wdev
,
6682 struct cfg80211_internal_bss
*intbss
)
6684 struct cfg80211_bss
*res
= &intbss
->pub
;
6685 const struct cfg80211_bss_ies
*ies
;
6689 ASSERT_WDEV_LOCK(wdev
);
6691 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
6692 NL80211_CMD_NEW_SCAN_RESULTS
);
6696 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
6698 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
6699 goto nla_put_failure
;
6701 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
6702 goto nla_put_failure
;
6703 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
6704 goto nla_put_failure
;
6706 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
6708 goto nla_put_failure
;
6709 if ((!is_zero_ether_addr(res
->bssid
) &&
6710 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
6711 goto nla_put_failure
;
6714 /* indicate whether we have probe response data or not */
6715 if (rcu_access_pointer(res
->proberesp_ies
) &&
6716 nla_put_flag(msg
, NL80211_BSS_PRESP_DATA
))
6717 goto fail_unlock_rcu
;
6719 /* this pointer prefers to be pointed to probe response data
6720 * but is always valid
6722 ies
= rcu_dereference(res
->ies
);
6724 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
6725 goto fail_unlock_rcu
;
6726 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
6727 ies
->len
, ies
->data
))
6728 goto fail_unlock_rcu
;
6731 /* and this pointer is always (unless driver didn't know) beacon data */
6732 ies
= rcu_dereference(res
->beacon_ies
);
6733 if (ies
&& ies
->from_beacon
) {
6734 if (nla_put_u64(msg
, NL80211_BSS_BEACON_TSF
, ies
->tsf
))
6735 goto fail_unlock_rcu
;
6736 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
6737 ies
->len
, ies
->data
))
6738 goto fail_unlock_rcu
;
6742 if (res
->beacon_interval
&&
6743 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
6744 goto nla_put_failure
;
6745 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
6746 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
6747 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
6748 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
6749 jiffies_to_msecs(jiffies
- intbss
->ts
)))
6750 goto nla_put_failure
;
6752 if (intbss
->ts_boottime
&&
6753 nla_put_u64(msg
, NL80211_BSS_LAST_SEEN_BOOTTIME
,
6754 intbss
->ts_boottime
))
6755 goto nla_put_failure
;
6757 switch (rdev
->wiphy
.signal_type
) {
6758 case CFG80211_SIGNAL_TYPE_MBM
:
6759 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
6760 goto nla_put_failure
;
6762 case CFG80211_SIGNAL_TYPE_UNSPEC
:
6763 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
6764 goto nla_put_failure
;
6770 switch (wdev
->iftype
) {
6771 case NL80211_IFTYPE_P2P_CLIENT
:
6772 case NL80211_IFTYPE_STATION
:
6773 if (intbss
== wdev
->current_bss
&&
6774 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6775 NL80211_BSS_STATUS_ASSOCIATED
))
6776 goto nla_put_failure
;
6778 case NL80211_IFTYPE_ADHOC
:
6779 if (intbss
== wdev
->current_bss
&&
6780 nla_put_u32(msg
, NL80211_BSS_STATUS
,
6781 NL80211_BSS_STATUS_IBSS_JOINED
))
6782 goto nla_put_failure
;
6788 nla_nest_end(msg
, bss
);
6790 genlmsg_end(msg
, hdr
);
6796 genlmsg_cancel(msg
, hdr
);
6800 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6802 struct cfg80211_registered_device
*rdev
;
6803 struct cfg80211_internal_bss
*scan
;
6804 struct wireless_dev
*wdev
;
6805 int start
= cb
->args
[2], idx
= 0;
6809 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6816 spin_lock_bh(&rdev
->bss_lock
);
6817 cfg80211_bss_expire(rdev
);
6819 cb
->seq
= rdev
->bss_generation
;
6821 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
6824 if (nl80211_send_bss(skb
, cb
,
6825 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6826 rdev
, wdev
, scan
) < 0) {
6832 spin_unlock_bh(&rdev
->bss_lock
);
6841 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
6842 int flags
, struct net_device
*dev
,
6843 bool allow_radio_stats
,
6844 struct survey_info
*survey
)
6847 struct nlattr
*infoattr
;
6849 /* skip radio stats if userspace didn't request them */
6850 if (!survey
->channel
&& !allow_radio_stats
)
6853 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
6854 NL80211_CMD_NEW_SURVEY_RESULTS
);
6858 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
6859 goto nla_put_failure
;
6861 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
6863 goto nla_put_failure
;
6865 if (survey
->channel
&&
6866 nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
6867 survey
->channel
->center_freq
))
6868 goto nla_put_failure
;
6870 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
6871 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
6872 goto nla_put_failure
;
6873 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
6874 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
6875 goto nla_put_failure
;
6876 if ((survey
->filled
& SURVEY_INFO_TIME
) &&
6877 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME
,
6879 goto nla_put_failure
;
6880 if ((survey
->filled
& SURVEY_INFO_TIME_BUSY
) &&
6881 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_BUSY
,
6883 goto nla_put_failure
;
6884 if ((survey
->filled
& SURVEY_INFO_TIME_EXT_BUSY
) &&
6885 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_EXT_BUSY
,
6886 survey
->time_ext_busy
))
6887 goto nla_put_failure
;
6888 if ((survey
->filled
& SURVEY_INFO_TIME_RX
) &&
6889 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_RX
,
6891 goto nla_put_failure
;
6892 if ((survey
->filled
& SURVEY_INFO_TIME_TX
) &&
6893 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_TX
,
6895 goto nla_put_failure
;
6896 if ((survey
->filled
& SURVEY_INFO_TIME_SCAN
) &&
6897 nla_put_u64(msg
, NL80211_SURVEY_INFO_TIME_SCAN
,
6899 goto nla_put_failure
;
6901 nla_nest_end(msg
, infoattr
);
6903 genlmsg_end(msg
, hdr
);
6907 genlmsg_cancel(msg
, hdr
);
6911 static int nl80211_dump_survey(struct sk_buff
*skb
, struct netlink_callback
*cb
)
6913 struct survey_info survey
;
6914 struct cfg80211_registered_device
*rdev
;
6915 struct wireless_dev
*wdev
;
6916 int survey_idx
= cb
->args
[2];
6921 res
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
6925 /* prepare_wdev_dump parsed the attributes */
6926 radio_stats
= nl80211_fam
.attrbuf
[NL80211_ATTR_SURVEY_RADIO_STATS
];
6928 if (!wdev
->netdev
) {
6933 if (!rdev
->ops
->dump_survey
) {
6939 res
= rdev_dump_survey(rdev
, wdev
->netdev
, survey_idx
, &survey
);
6945 /* don't send disabled channels, but do send non-channel data */
6946 if (survey
.channel
&&
6947 survey
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
6952 if (nl80211_send_survey(skb
,
6953 NETLINK_CB(cb
->skb
).portid
,
6954 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6955 wdev
->netdev
, radio_stats
, &survey
) < 0)
6961 cb
->args
[2] = survey_idx
;
6968 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
6970 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
6971 NL80211_WPA_VERSION_2
|
6973 NL80211_WAPI_VERSION_1
));
6976 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6978 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6979 struct net_device
*dev
= info
->user_ptr
[1];
6980 struct ieee80211_channel
*chan
;
6981 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
6982 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
6983 enum nl80211_auth_type auth_type
;
6984 struct key_parse key
;
6985 bool local_state_change
;
6987 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6990 if (!info
->attrs
[NL80211_ATTR_MAC
])
6993 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
6996 if (!info
->attrs
[NL80211_ATTR_SSID
])
6999 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7002 err
= nl80211_parse_key(info
, &key
);
7007 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
7009 if (!key
.p
.key
|| !key
.p
.key_len
)
7011 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
7012 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
7013 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
7014 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
7026 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
7027 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
7036 if (!rdev
->ops
->auth
)
7039 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7040 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7043 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7044 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7045 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7049 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7050 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7052 if (info
->attrs
[NL80211_ATTR_IE
]) {
7053 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7054 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7057 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7058 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
7061 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
7062 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
7065 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
7066 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
7068 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7069 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
7070 /* need to include at least Auth Transaction and Status Code */
7071 if (sae_data_len
< 4)
7075 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7078 * Since we no longer track auth state, ignore
7079 * requests to only change local state.
7081 if (local_state_change
)
7084 wdev_lock(dev
->ieee80211_ptr
);
7085 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
7086 ssid
, ssid_len
, ie
, ie_len
,
7087 key
.p
.key
, key
.p
.key_len
, key
.idx
,
7088 sae_data
, sae_data_len
);
7089 wdev_unlock(dev
->ieee80211_ptr
);
7093 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
7094 struct genl_info
*info
,
7095 struct cfg80211_crypto_settings
*settings
,
7098 memset(settings
, 0, sizeof(*settings
));
7100 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
7102 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
7104 proto
= nla_get_u16(
7105 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
7106 settings
->control_port_ethertype
= cpu_to_be16(proto
);
7107 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
7110 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
7111 settings
->control_port_no_encrypt
= true;
7113 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
7115 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
7119 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7120 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
7121 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
7123 if (len
% sizeof(u32
))
7126 if (settings
->n_ciphers_pairwise
> cipher_limit
)
7129 memcpy(settings
->ciphers_pairwise
, data
, len
);
7131 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
7132 if (!cfg80211_supported_cipher_suite(
7134 settings
->ciphers_pairwise
[i
]))
7138 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
7139 settings
->cipher_group
=
7140 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
7141 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
7142 settings
->cipher_group
))
7146 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
7147 settings
->wpa_versions
=
7148 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
7149 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
7153 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
7157 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7158 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
7159 settings
->n_akm_suites
= len
/ sizeof(u32
);
7161 if (len
% sizeof(u32
))
7164 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
7167 memcpy(settings
->akm_suites
, data
, len
);
7173 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
7175 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7176 struct net_device
*dev
= info
->user_ptr
[1];
7177 struct ieee80211_channel
*chan
;
7178 struct cfg80211_assoc_request req
= {};
7179 const u8
*bssid
, *ssid
;
7180 int err
, ssid_len
= 0;
7182 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7185 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
7186 !info
->attrs
[NL80211_ATTR_SSID
] ||
7187 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7190 if (!rdev
->ops
->assoc
)
7193 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7194 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7197 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7199 chan
= nl80211_get_valid_chan(&rdev
->wiphy
,
7200 info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7204 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7205 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7207 if (info
->attrs
[NL80211_ATTR_IE
]) {
7208 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7209 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7212 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7213 enum nl80211_mfp mfp
=
7214 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7215 if (mfp
== NL80211_MFP_REQUIRED
)
7217 else if (mfp
!= NL80211_MFP_NO
)
7221 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
7222 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
7224 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7225 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
7227 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7228 memcpy(&req
.ht_capa_mask
,
7229 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7230 sizeof(req
.ht_capa_mask
));
7232 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7233 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7235 memcpy(&req
.ht_capa
,
7236 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7237 sizeof(req
.ht_capa
));
7240 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7241 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7243 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7244 memcpy(&req
.vht_capa_mask
,
7245 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7246 sizeof(req
.vht_capa_mask
));
7248 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7249 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7251 memcpy(&req
.vht_capa
,
7252 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7253 sizeof(req
.vht_capa
));
7256 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7257 if (!(rdev
->wiphy
.features
&
7258 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) ||
7259 !(rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
))
7261 req
.flags
|= ASSOC_REQ_USE_RRM
;
7264 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
7266 wdev_lock(dev
->ieee80211_ptr
);
7267 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
7268 ssid
, ssid_len
, &req
);
7269 wdev_unlock(dev
->ieee80211_ptr
);
7275 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
7277 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7278 struct net_device
*dev
= info
->user_ptr
[1];
7279 const u8
*ie
= NULL
, *bssid
;
7280 int ie_len
= 0, err
;
7282 bool local_state_change
;
7284 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7287 if (!info
->attrs
[NL80211_ATTR_MAC
])
7290 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7293 if (!rdev
->ops
->deauth
)
7296 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7297 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7300 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7302 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7303 if (reason_code
== 0) {
7304 /* Reason Code 0 is reserved */
7308 if (info
->attrs
[NL80211_ATTR_IE
]) {
7309 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7310 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7313 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7315 wdev_lock(dev
->ieee80211_ptr
);
7316 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7317 local_state_change
);
7318 wdev_unlock(dev
->ieee80211_ptr
);
7322 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
7324 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7325 struct net_device
*dev
= info
->user_ptr
[1];
7326 const u8
*ie
= NULL
, *bssid
;
7327 int ie_len
= 0, err
;
7329 bool local_state_change
;
7331 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7334 if (!info
->attrs
[NL80211_ATTR_MAC
])
7337 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7340 if (!rdev
->ops
->disassoc
)
7343 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7344 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7347 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7349 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7350 if (reason_code
== 0) {
7351 /* Reason Code 0 is reserved */
7355 if (info
->attrs
[NL80211_ATTR_IE
]) {
7356 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7357 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7360 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
7362 wdev_lock(dev
->ieee80211_ptr
);
7363 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
7364 local_state_change
);
7365 wdev_unlock(dev
->ieee80211_ptr
);
7370 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
7371 int mcast_rate
[NUM_NL80211_BANDS
],
7374 struct wiphy
*wiphy
= &rdev
->wiphy
;
7378 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
7379 struct ieee80211_supported_band
*sband
;
7381 sband
= wiphy
->bands
[band
];
7385 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
7386 if (sband
->bitrates
[i
].bitrate
== rateval
) {
7387 mcast_rate
[band
] = i
+ 1;
7397 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7399 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7400 struct net_device
*dev
= info
->user_ptr
[1];
7401 struct cfg80211_ibss_params ibss
;
7402 struct wiphy
*wiphy
;
7403 struct cfg80211_cached_keys
*connkeys
= NULL
;
7406 memset(&ibss
, 0, sizeof(ibss
));
7408 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7411 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7412 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7415 ibss
.beacon_interval
= 100;
7417 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7418 ibss
.beacon_interval
=
7419 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7420 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
7424 if (!rdev
->ops
->join_ibss
)
7427 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7430 wiphy
= &rdev
->wiphy
;
7432 if (info
->attrs
[NL80211_ATTR_MAC
]) {
7433 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7435 if (!is_valid_ether_addr(ibss
.bssid
))
7438 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7439 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7441 if (info
->attrs
[NL80211_ATTR_IE
]) {
7442 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7443 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7446 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
7450 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
,
7451 NL80211_IFTYPE_ADHOC
))
7454 switch (ibss
.chandef
.width
) {
7455 case NL80211_CHAN_WIDTH_5
:
7456 case NL80211_CHAN_WIDTH_10
:
7457 case NL80211_CHAN_WIDTH_20_NOHT
:
7459 case NL80211_CHAN_WIDTH_20
:
7460 case NL80211_CHAN_WIDTH_40
:
7461 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7464 case NL80211_CHAN_WIDTH_80
:
7465 case NL80211_CHAN_WIDTH_80P80
:
7466 case NL80211_CHAN_WIDTH_160
:
7467 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
7469 if (!wiphy_ext_feature_isset(&rdev
->wiphy
,
7470 NL80211_EXT_FEATURE_VHT_IBSS
))
7477 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
7478 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
7480 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7482 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7484 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7485 struct ieee80211_supported_band
*sband
=
7486 wiphy
->bands
[ibss
.chandef
.chan
->band
];
7488 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7494 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7495 memcpy(&ibss
.ht_capa_mask
,
7496 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7497 sizeof(ibss
.ht_capa_mask
));
7499 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7500 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7502 memcpy(&ibss
.ht_capa
,
7503 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7504 sizeof(ibss
.ht_capa
));
7507 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7508 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
7509 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7512 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7515 connkeys
= nl80211_parse_connkeys(rdev
,
7516 info
->attrs
[NL80211_ATTR_KEYS
],
7518 if (IS_ERR(connkeys
))
7519 return PTR_ERR(connkeys
);
7521 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
7529 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
7531 ibss
.userspace_handles_dfs
=
7532 nla_get_flag(info
->attrs
[NL80211_ATTR_HANDLE_DFS
]);
7534 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
7540 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
7542 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7543 struct net_device
*dev
= info
->user_ptr
[1];
7545 if (!rdev
->ops
->leave_ibss
)
7548 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
7551 return cfg80211_leave_ibss(rdev
, dev
, false);
7554 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
7556 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7557 struct net_device
*dev
= info
->user_ptr
[1];
7558 int mcast_rate
[NUM_NL80211_BANDS
];
7562 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
7563 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
7564 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_OCB
)
7567 if (!rdev
->ops
->set_mcast_rate
)
7570 memset(mcast_rate
, 0, sizeof(mcast_rate
));
7572 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
7575 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
7576 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
7579 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
7584 static struct sk_buff
*
7585 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
7586 struct wireless_dev
*wdev
, int approxlen
,
7587 u32 portid
, u32 seq
, enum nl80211_commands cmd
,
7588 enum nl80211_attrs attr
,
7589 const struct nl80211_vendor_cmd_info
*info
,
7592 struct sk_buff
*skb
;
7594 struct nlattr
*data
;
7596 skb
= nlmsg_new(approxlen
+ 100, gfp
);
7600 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
7606 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
7607 goto nla_put_failure
;
7610 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
7612 goto nla_put_failure
;
7613 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
7615 goto nla_put_failure
;
7619 if (nla_put_u64(skb
, NL80211_ATTR_WDEV
,
7621 goto nla_put_failure
;
7623 nla_put_u32(skb
, NL80211_ATTR_IFINDEX
,
7624 wdev
->netdev
->ifindex
))
7625 goto nla_put_failure
;
7628 data
= nla_nest_start(skb
, attr
);
7630 ((void **)skb
->cb
)[0] = rdev
;
7631 ((void **)skb
->cb
)[1] = hdr
;
7632 ((void **)skb
->cb
)[2] = data
;
7641 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
7642 struct wireless_dev
*wdev
,
7643 enum nl80211_commands cmd
,
7644 enum nl80211_attrs attr
,
7645 int vendor_event_idx
,
7646 int approxlen
, gfp_t gfp
)
7648 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
7649 const struct nl80211_vendor_cmd_info
*info
;
7652 case NL80211_CMD_TESTMODE
:
7653 if (WARN_ON(vendor_event_idx
!= -1))
7657 case NL80211_CMD_VENDOR
:
7658 if (WARN_ON(vendor_event_idx
< 0 ||
7659 vendor_event_idx
>= wiphy
->n_vendor_events
))
7661 info
= &wiphy
->vendor_events
[vendor_event_idx
];
7668 return __cfg80211_alloc_vendor_skb(rdev
, wdev
, approxlen
, 0, 0,
7669 cmd
, attr
, info
, gfp
);
7671 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
7673 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
7675 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
7676 void *hdr
= ((void **)skb
->cb
)[1];
7677 struct nlattr
*data
= ((void **)skb
->cb
)[2];
7678 enum nl80211_multicast_groups mcgrp
= NL80211_MCGRP_TESTMODE
;
7680 /* clear CB data for netlink core to own from now on */
7681 memset(skb
->cb
, 0, sizeof(skb
->cb
));
7683 nla_nest_end(skb
, data
);
7684 genlmsg_end(skb
, hdr
);
7686 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
7687 mcgrp
= NL80211_MCGRP_VENDOR
;
7689 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), skb
, 0,
7692 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
7694 #ifdef CONFIG_NL80211_TESTMODE
7695 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
7697 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7698 struct wireless_dev
*wdev
=
7699 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
7702 if (!rdev
->ops
->testmode_cmd
)
7706 err
= PTR_ERR(wdev
);
7710 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
7714 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
7717 rdev
->cur_cmd_info
= info
;
7718 err
= rdev_testmode_cmd(rdev
, wdev
,
7719 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
7720 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
7721 rdev
->cur_cmd_info
= NULL
;
7726 static int nl80211_testmode_dump(struct sk_buff
*skb
,
7727 struct netlink_callback
*cb
)
7729 struct cfg80211_registered_device
*rdev
;
7739 * 0 is a valid index, but not valid for args[0],
7740 * so we need to offset by 1.
7742 phy_idx
= cb
->args
[0] - 1;
7744 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
7745 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
7750 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
7751 nl80211_fam
.attrbuf
);
7753 err
= PTR_ERR(rdev
);
7756 phy_idx
= rdev
->wiphy_idx
;
7759 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
7761 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
7765 data
= nla_data((void *)cb
->args
[1]);
7766 data_len
= nla_len((void *)cb
->args
[1]);
7769 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
7775 if (!rdev
->ops
->testmode_dump
) {
7781 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
7782 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
7783 NL80211_CMD_TESTMODE
);
7784 struct nlattr
*tmdata
;
7789 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
7790 genlmsg_cancel(skb
, hdr
);
7794 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
7796 genlmsg_cancel(skb
, hdr
);
7799 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
7800 nla_nest_end(skb
, tmdata
);
7802 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
7803 genlmsg_cancel(skb
, hdr
);
7806 genlmsg_cancel(skb
, hdr
);
7810 genlmsg_end(skb
, hdr
);
7815 cb
->args
[0] = phy_idx
+ 1;
7822 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
7824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7825 struct net_device
*dev
= info
->user_ptr
[1];
7826 struct cfg80211_connect_params connect
;
7827 struct wiphy
*wiphy
;
7828 struct cfg80211_cached_keys
*connkeys
= NULL
;
7831 memset(&connect
, 0, sizeof(connect
));
7833 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
7836 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
7837 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
7840 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
7842 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
7843 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
7844 NL80211_CMD_CONNECT
))
7847 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
7849 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
7851 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
7852 NL80211_MAX_NR_CIPHER_SUITES
);
7856 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7857 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7860 wiphy
= &rdev
->wiphy
;
7862 connect
.bg_scan_period
= -1;
7863 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
7864 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
7865 connect
.bg_scan_period
=
7866 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
7869 if (info
->attrs
[NL80211_ATTR_MAC
])
7870 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7871 else if (info
->attrs
[NL80211_ATTR_MAC_HINT
])
7872 connect
.bssid_hint
=
7873 nla_data(info
->attrs
[NL80211_ATTR_MAC_HINT
]);
7874 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
7875 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
7877 if (info
->attrs
[NL80211_ATTR_IE
]) {
7878 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
7879 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
7882 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
7883 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
7884 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
7885 connect
.mfp
!= NL80211_MFP_NO
)
7888 connect
.mfp
= NL80211_MFP_NO
;
7891 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7892 connect
.channel
= nl80211_get_valid_chan(
7893 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
7894 if (!connect
.channel
)
7896 } else if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]) {
7897 connect
.channel_hint
= nl80211_get_valid_chan(
7898 wiphy
, info
->attrs
[NL80211_ATTR_WIPHY_FREQ_HINT
]);
7899 if (!connect
.channel_hint
)
7903 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
7904 connkeys
= nl80211_parse_connkeys(rdev
,
7905 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
7906 if (IS_ERR(connkeys
))
7907 return PTR_ERR(connkeys
);
7910 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
7911 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
7913 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
7914 memcpy(&connect
.ht_capa_mask
,
7915 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
7916 sizeof(connect
.ht_capa_mask
));
7918 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
7919 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
7923 memcpy(&connect
.ht_capa
,
7924 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
7925 sizeof(connect
.ht_capa
));
7928 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
7929 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
7931 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
7932 memcpy(&connect
.vht_capa_mask
,
7933 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
7934 sizeof(connect
.vht_capa_mask
));
7936 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
7937 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
7941 memcpy(&connect
.vht_capa
,
7942 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
7943 sizeof(connect
.vht_capa
));
7946 if (nla_get_flag(info
->attrs
[NL80211_ATTR_USE_RRM
])) {
7947 if (!(rdev
->wiphy
.features
&
7948 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
) ||
7949 !(rdev
->wiphy
.features
& NL80211_FEATURE_QUIET
)) {
7953 connect
.flags
|= ASSOC_REQ_USE_RRM
;
7956 wdev_lock(dev
->ieee80211_ptr
);
7957 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
7958 wdev_unlock(dev
->ieee80211_ptr
);
7964 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
7966 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7967 struct net_device
*dev
= info
->user_ptr
[1];
7971 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
7972 reason
= WLAN_REASON_DEAUTH_LEAVING
;
7974 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
7979 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7980 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7983 wdev_lock(dev
->ieee80211_ptr
);
7984 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
7985 wdev_unlock(dev
->ieee80211_ptr
);
7989 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
7991 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7995 if (info
->attrs
[NL80211_ATTR_PID
]) {
7996 u32 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
7998 net
= get_net_ns_by_pid(pid
);
7999 } else if (info
->attrs
[NL80211_ATTR_NETNS_FD
]) {
8000 u32 fd
= nla_get_u32(info
->attrs
[NL80211_ATTR_NETNS_FD
]);
8002 net
= get_net_ns_by_fd(fd
);
8008 return PTR_ERR(net
);
8012 /* check if anything to do */
8013 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
8014 err
= cfg80211_switch_netns(rdev
, net
);
8020 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8022 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8023 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
8024 struct cfg80211_pmksa
*pmksa
) = NULL
;
8025 struct net_device
*dev
= info
->user_ptr
[1];
8026 struct cfg80211_pmksa pmksa
;
8028 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
8030 if (!info
->attrs
[NL80211_ATTR_MAC
])
8033 if (!info
->attrs
[NL80211_ATTR_PMKID
])
8036 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
8037 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8039 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8040 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8043 switch (info
->genlhdr
->cmd
) {
8044 case NL80211_CMD_SET_PMKSA
:
8045 rdev_ops
= rdev
->ops
->set_pmksa
;
8047 case NL80211_CMD_DEL_PMKSA
:
8048 rdev_ops
= rdev
->ops
->del_pmksa
;
8058 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
8061 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
8063 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8064 struct net_device
*dev
= info
->user_ptr
[1];
8066 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
8067 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8070 if (!rdev
->ops
->flush_pmksa
)
8073 return rdev_flush_pmksa(rdev
, dev
);
8076 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8078 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8079 struct net_device
*dev
= info
->user_ptr
[1];
8080 u8 action_code
, dialog_token
;
8081 u32 peer_capability
= 0;
8086 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8087 !rdev
->ops
->tdls_mgmt
)
8090 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
8091 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
8092 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
8093 !info
->attrs
[NL80211_ATTR_IE
] ||
8094 !info
->attrs
[NL80211_ATTR_MAC
])
8097 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8098 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
8099 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
8100 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
8101 initiator
= nla_get_flag(info
->attrs
[NL80211_ATTR_TDLS_INITIATOR
]);
8102 if (info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
])
8104 nla_get_u32(info
->attrs
[NL80211_ATTR_TDLS_PEER_CAPABILITY
]);
8106 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
8107 dialog_token
, status_code
, peer_capability
,
8109 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
8110 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
8113 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
8115 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8116 struct net_device
*dev
= info
->user_ptr
[1];
8117 enum nl80211_tdls_operation operation
;
8120 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
8121 !rdev
->ops
->tdls_oper
)
8124 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
8125 !info
->attrs
[NL80211_ATTR_MAC
])
8128 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
8129 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8131 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
8134 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
8135 struct genl_info
*info
)
8137 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8138 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8139 struct cfg80211_chan_def chandef
;
8140 struct sk_buff
*msg
;
8146 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
8147 !info
->attrs
[NL80211_ATTR_DURATION
])
8150 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8152 if (!rdev
->ops
->remain_on_channel
||
8153 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
8157 * We should be on that channel for at least a minimum amount of
8158 * time (10ms) but no longer than the driver supports.
8160 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8161 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
8164 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8168 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8172 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8173 NL80211_CMD_REMAIN_ON_CHANNEL
);
8179 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
8185 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8186 goto nla_put_failure
;
8188 genlmsg_end(msg
, hdr
);
8190 return genlmsg_reply(msg
, info
);
8199 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
8200 struct genl_info
*info
)
8202 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8203 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8206 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8209 if (!rdev
->ops
->cancel_remain_on_channel
)
8212 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8214 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
8217 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
8218 u8
*rates
, u8 rates_len
)
8223 for (i
= 0; i
< rates_len
; i
++) {
8224 int rate
= (rates
[i
] & 0x7f) * 5;
8226 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
8227 struct ieee80211_rate
*srate
=
8228 &sband
->bitrates
[ridx
];
8229 if (rate
== srate
->bitrate
) {
8234 if (ridx
== sband
->n_bitrates
)
8235 return 0; /* rate not found */
8241 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
8242 u8
*rates
, u8 rates_len
,
8243 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
8247 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
8249 for (i
= 0; i
< rates_len
; i
++) {
8252 ridx
= rates
[i
] / 8;
8253 rbit
= BIT(rates
[i
] % 8);
8255 /* check validity */
8256 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
8259 /* check availability */
8260 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
8269 static u16
vht_mcs_map_to_mcs_mask(u8 vht_mcs_map
)
8273 switch (vht_mcs_map
) {
8274 case IEEE80211_VHT_MCS_NOT_SUPPORTED
:
8276 case IEEE80211_VHT_MCS_SUPPORT_0_7
:
8279 case IEEE80211_VHT_MCS_SUPPORT_0_8
:
8282 case IEEE80211_VHT_MCS_SUPPORT_0_9
:
8292 static void vht_build_mcs_mask(u16 vht_mcs_map
,
8293 u16 vht_mcs_mask
[NL80211_VHT_NSS_MAX
])
8297 for (nss
= 0; nss
< NL80211_VHT_NSS_MAX
; nss
++) {
8298 vht_mcs_mask
[nss
] = vht_mcs_map_to_mcs_mask(vht_mcs_map
& 0x03);
8303 static bool vht_set_mcs_mask(struct ieee80211_supported_band
*sband
,
8304 struct nl80211_txrate_vht
*txrate
,
8305 u16 mcs
[NL80211_VHT_NSS_MAX
])
8307 u16 tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8308 u16 tx_mcs_mask
[NL80211_VHT_NSS_MAX
] = {};
8311 if (!sband
->vht_cap
.vht_supported
)
8314 memset(mcs
, 0, sizeof(u16
) * NL80211_VHT_NSS_MAX
);
8316 /* Build vht_mcs_mask from VHT capabilities */
8317 vht_build_mcs_mask(tx_mcs_map
, tx_mcs_mask
);
8319 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
8320 if ((tx_mcs_mask
[i
] & txrate
->mcs
[i
]) == txrate
->mcs
[i
])
8321 mcs
[i
] = txrate
->mcs
[i
];
8329 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
8330 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
8331 .len
= NL80211_MAX_SUPP_RATES
},
8332 [NL80211_TXRATE_HT
] = { .type
= NLA_BINARY
,
8333 .len
= NL80211_MAX_SUPP_HT_RATES
},
8334 [NL80211_TXRATE_VHT
] = { .len
= sizeof(struct nl80211_txrate_vht
)},
8335 [NL80211_TXRATE_GI
] = { .type
= NLA_U8
},
8338 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
8339 struct genl_info
*info
)
8341 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
8342 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8343 struct cfg80211_bitrate_mask mask
;
8345 struct net_device
*dev
= info
->user_ptr
[1];
8346 struct nlattr
*tx_rates
;
8347 struct ieee80211_supported_band
*sband
;
8350 if (!rdev
->ops
->set_bitrate_mask
)
8353 memset(&mask
, 0, sizeof(mask
));
8354 /* Default to all rates enabled */
8355 for (i
= 0; i
< NUM_NL80211_BANDS
; i
++) {
8356 sband
= rdev
->wiphy
.bands
[i
];
8361 mask
.control
[i
].legacy
= (1 << sband
->n_bitrates
) - 1;
8362 memcpy(mask
.control
[i
].ht_mcs
,
8363 sband
->ht_cap
.mcs
.rx_mask
,
8364 sizeof(mask
.control
[i
].ht_mcs
));
8366 if (!sband
->vht_cap
.vht_supported
)
8369 vht_tx_mcs_map
= le16_to_cpu(sband
->vht_cap
.vht_mcs
.tx_mcs_map
);
8370 vht_build_mcs_mask(vht_tx_mcs_map
, mask
.control
[i
].vht_mcs
);
8373 /* if no rates are given set it back to the defaults */
8374 if (!info
->attrs
[NL80211_ATTR_TX_RATES
])
8378 * The nested attribute uses enum nl80211_band as the index. This maps
8379 * directly to the enum ieee80211_band values used in cfg80211.
8381 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
8382 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
) {
8383 enum nl80211_band band
= nla_type(tx_rates
);
8386 if (band
< 0 || band
>= NUM_NL80211_BANDS
)
8388 sband
= rdev
->wiphy
.bands
[band
];
8391 err
= nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
8392 nla_len(tx_rates
), nl80211_txattr_policy
);
8395 if (tb
[NL80211_TXRATE_LEGACY
]) {
8396 mask
.control
[band
].legacy
= rateset_to_mask(
8398 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
8399 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
8400 if ((mask
.control
[band
].legacy
== 0) &&
8401 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
8404 if (tb
[NL80211_TXRATE_HT
]) {
8405 if (!ht_rateset_to_mask(
8407 nla_data(tb
[NL80211_TXRATE_HT
]),
8408 nla_len(tb
[NL80211_TXRATE_HT
]),
8409 mask
.control
[band
].ht_mcs
))
8412 if (tb
[NL80211_TXRATE_VHT
]) {
8413 if (!vht_set_mcs_mask(
8415 nla_data(tb
[NL80211_TXRATE_VHT
]),
8416 mask
.control
[band
].vht_mcs
))
8419 if (tb
[NL80211_TXRATE_GI
]) {
8420 mask
.control
[band
].gi
=
8421 nla_get_u8(tb
[NL80211_TXRATE_GI
]);
8422 if (mask
.control
[band
].gi
> NL80211_TXRATE_FORCE_LGI
)
8426 if (mask
.control
[band
].legacy
== 0) {
8427 /* don't allow empty legacy rates if HT or VHT
8428 * are not even supported.
8430 if (!(rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
||
8431 rdev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
))
8434 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
8435 if (mask
.control
[band
].ht_mcs
[i
])
8438 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
8439 if (mask
.control
[band
].vht_mcs
[i
])
8442 /* legacy and mcs rates may not be both empty */
8448 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
8451 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8453 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8454 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8455 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
8457 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
8460 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
8461 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
8463 switch (wdev
->iftype
) {
8464 case NL80211_IFTYPE_STATION
:
8465 case NL80211_IFTYPE_ADHOC
:
8466 case NL80211_IFTYPE_P2P_CLIENT
:
8467 case NL80211_IFTYPE_AP
:
8468 case NL80211_IFTYPE_AP_VLAN
:
8469 case NL80211_IFTYPE_MESH_POINT
:
8470 case NL80211_IFTYPE_P2P_GO
:
8471 case NL80211_IFTYPE_P2P_DEVICE
:
8477 /* not much point in registering if we can't reply */
8478 if (!rdev
->ops
->mgmt_tx
)
8481 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
8482 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
8483 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
8486 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
8488 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8489 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8490 struct cfg80211_chan_def chandef
;
8494 struct sk_buff
*msg
= NULL
;
8495 struct cfg80211_mgmt_tx_params params
= {
8496 .dont_wait_for_ack
=
8497 info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
],
8500 if (!info
->attrs
[NL80211_ATTR_FRAME
])
8503 if (!rdev
->ops
->mgmt_tx
)
8506 switch (wdev
->iftype
) {
8507 case NL80211_IFTYPE_P2P_DEVICE
:
8508 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
8510 case NL80211_IFTYPE_STATION
:
8511 case NL80211_IFTYPE_ADHOC
:
8512 case NL80211_IFTYPE_P2P_CLIENT
:
8513 case NL80211_IFTYPE_AP
:
8514 case NL80211_IFTYPE_AP_VLAN
:
8515 case NL80211_IFTYPE_MESH_POINT
:
8516 case NL80211_IFTYPE_P2P_GO
:
8522 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
8523 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8525 params
.wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
8528 * We should wait on the channel for at least a minimum amount
8529 * of time (10ms) but no longer than the driver supports.
8531 if (params
.wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
8532 params
.wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
8537 params
.offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
8539 if (params
.offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
8542 params
.no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
8544 /* get the channel if any has been specified, otherwise pass NULL to
8545 * the driver. The latter will use the current one
8547 chandef
.chan
= NULL
;
8548 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8549 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
8554 if (!chandef
.chan
&& params
.offchan
)
8557 params
.buf
= nla_data(info
->attrs
[NL80211_ATTR_FRAME
]);
8558 params
.len
= nla_len(info
->attrs
[NL80211_ATTR_FRAME
]);
8560 if (info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]) {
8561 int len
= nla_len(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8564 if (len
% sizeof(u16
))
8567 params
.n_csa_offsets
= len
/ sizeof(u16
);
8568 params
.csa_offsets
=
8569 nla_data(info
->attrs
[NL80211_ATTR_CSA_C_OFFSETS_TX
]);
8571 /* check that all the offsets fit the frame */
8572 for (i
= 0; i
< params
.n_csa_offsets
; i
++) {
8573 if (params
.csa_offsets
[i
] >= params
.len
)
8578 if (!params
.dont_wait_for_ack
) {
8579 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8583 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8591 params
.chan
= chandef
.chan
;
8592 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, ¶ms
, &cookie
);
8597 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8598 goto nla_put_failure
;
8600 genlmsg_end(msg
, hdr
);
8601 return genlmsg_reply(msg
, info
);
8613 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
8615 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8616 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8619 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
8622 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
8625 switch (wdev
->iftype
) {
8626 case NL80211_IFTYPE_STATION
:
8627 case NL80211_IFTYPE_ADHOC
:
8628 case NL80211_IFTYPE_P2P_CLIENT
:
8629 case NL80211_IFTYPE_AP
:
8630 case NL80211_IFTYPE_AP_VLAN
:
8631 case NL80211_IFTYPE_P2P_GO
:
8632 case NL80211_IFTYPE_P2P_DEVICE
:
8638 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
8640 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
8643 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
8645 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8646 struct wireless_dev
*wdev
;
8647 struct net_device
*dev
= info
->user_ptr
[1];
8652 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
8655 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
8657 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
8660 wdev
= dev
->ieee80211_ptr
;
8662 if (!rdev
->ops
->set_power_mgmt
)
8665 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
8667 if (state
== wdev
->ps
)
8670 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
8676 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
8678 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8679 enum nl80211_ps_state ps_state
;
8680 struct wireless_dev
*wdev
;
8681 struct net_device
*dev
= info
->user_ptr
[1];
8682 struct sk_buff
*msg
;
8686 wdev
= dev
->ieee80211_ptr
;
8688 if (!rdev
->ops
->set_power_mgmt
)
8691 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8695 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8696 NL80211_CMD_GET_POWER_SAVE
);
8703 ps_state
= NL80211_PS_ENABLED
;
8705 ps_state
= NL80211_PS_DISABLED
;
8707 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
8708 goto nla_put_failure
;
8710 genlmsg_end(msg
, hdr
);
8711 return genlmsg_reply(msg
, info
);
8720 static const struct nla_policy
8721 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
8722 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
8723 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
8724 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
8725 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
8726 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
8727 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
8730 static int nl80211_set_cqm_txe(struct genl_info
*info
,
8731 u32 rate
, u32 pkts
, u32 intvl
)
8733 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8734 struct net_device
*dev
= info
->user_ptr
[1];
8735 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8737 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
8740 if (!rdev
->ops
->set_cqm_txe_config
)
8743 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8744 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8747 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
8750 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
8751 s32 threshold
, u32 hysteresis
)
8753 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8754 struct net_device
*dev
= info
->user_ptr
[1];
8755 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8760 /* disabling - hysteresis should also be zero then */
8764 if (!rdev
->ops
->set_cqm_rssi_config
)
8767 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
8768 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
8771 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
8774 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
8776 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
8780 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
8784 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
8785 nl80211_attr_cqm_policy
);
8789 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
8790 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
8791 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
8792 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
8794 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
8797 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
8798 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
8799 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
8800 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
8801 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
8802 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
8804 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
8810 static int nl80211_join_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
8812 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8813 struct net_device
*dev
= info
->user_ptr
[1];
8814 struct ocb_setup setup
= {};
8817 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8821 return cfg80211_join_ocb(rdev
, dev
, &setup
);
8824 static int nl80211_leave_ocb(struct sk_buff
*skb
, struct genl_info
*info
)
8826 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8827 struct net_device
*dev
= info
->user_ptr
[1];
8829 return cfg80211_leave_ocb(rdev
, dev
);
8832 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8834 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8835 struct net_device
*dev
= info
->user_ptr
[1];
8836 struct mesh_config cfg
;
8837 struct mesh_setup setup
;
8840 /* start with default */
8841 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
8842 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
8844 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
8845 /* and parse parameters if given */
8846 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
8851 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
8852 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
8855 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8856 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
8858 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
8859 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
8860 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
8863 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
8864 setup
.beacon_interval
=
8865 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
8866 if (setup
.beacon_interval
< 10 ||
8867 setup
.beacon_interval
> 10000)
8871 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
8873 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
8874 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
8878 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
8879 /* parse additional setup parameters if given */
8880 err
= nl80211_parse_mesh_setup(info
, &setup
);
8886 cfg
.auto_open_plinks
= false;
8888 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
8889 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
8893 /* cfg80211_join_mesh() will sort it out */
8894 setup
.chandef
.chan
= NULL
;
8897 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
8898 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8900 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
8901 struct ieee80211_supported_band
*sband
;
8903 if (!setup
.chandef
.chan
)
8906 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
8908 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
8909 &setup
.basic_rates
);
8914 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
8917 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
8919 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8920 struct net_device
*dev
= info
->user_ptr
[1];
8922 return cfg80211_leave_mesh(rdev
, dev
);
8926 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
8927 struct cfg80211_registered_device
*rdev
)
8929 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
8930 struct nlattr
*nl_pats
, *nl_pat
;
8933 if (!wowlan
->n_patterns
)
8936 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
8940 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
8941 nl_pat
= nla_nest_start(msg
, i
+ 1);
8944 pat_len
= wowlan
->patterns
[i
].pattern_len
;
8945 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
8946 wowlan
->patterns
[i
].mask
) ||
8947 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8948 wowlan
->patterns
[i
].pattern
) ||
8949 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8950 wowlan
->patterns
[i
].pkt_offset
))
8952 nla_nest_end(msg
, nl_pat
);
8954 nla_nest_end(msg
, nl_pats
);
8959 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
8960 struct cfg80211_wowlan_tcp
*tcp
)
8962 struct nlattr
*nl_tcp
;
8967 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
8971 if (nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
8972 nla_put_in_addr(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
8973 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
8974 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
8975 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
8976 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
8977 tcp
->payload_len
, tcp
->payload
) ||
8978 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
8979 tcp
->data_interval
) ||
8980 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
8981 tcp
->wake_len
, tcp
->wake_data
) ||
8982 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
8983 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
8986 if (tcp
->payload_seq
.len
&&
8987 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
8988 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
8991 if (tcp
->payload_tok
.len
&&
8992 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
8993 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
8997 nla_nest_end(msg
, nl_tcp
);
9002 static int nl80211_send_wowlan_nd(struct sk_buff
*msg
,
9003 struct cfg80211_sched_scan_request
*req
)
9005 struct nlattr
*nd
, *freqs
, *matches
, *match
, *scan_plans
, *scan_plan
;
9011 nd
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_NET_DETECT
);
9015 if (req
->n_scan_plans
== 1 &&
9016 nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
,
9017 req
->scan_plans
[0].interval
* 1000))
9020 if (nla_put_u32(msg
, NL80211_ATTR_SCHED_SCAN_DELAY
, req
->delay
))
9023 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9027 for (i
= 0; i
< req
->n_channels
; i
++)
9028 nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
);
9030 nla_nest_end(msg
, freqs
);
9032 if (req
->n_match_sets
) {
9033 matches
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
9034 for (i
= 0; i
< req
->n_match_sets
; i
++) {
9035 match
= nla_nest_start(msg
, i
);
9036 nla_put(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_SSID
,
9037 req
->match_sets
[i
].ssid
.ssid_len
,
9038 req
->match_sets
[i
].ssid
.ssid
);
9039 nla_nest_end(msg
, match
);
9041 nla_nest_end(msg
, matches
);
9044 scan_plans
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_PLANS
);
9048 for (i
= 0; i
< req
->n_scan_plans
; i
++) {
9049 scan_plan
= nla_nest_start(msg
, i
+ 1);
9051 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_INTERVAL
,
9052 req
->scan_plans
[i
].interval
) ||
9053 (req
->scan_plans
[i
].iterations
&&
9054 nla_put_u32(msg
, NL80211_SCHED_SCAN_PLAN_ITERATIONS
,
9055 req
->scan_plans
[i
].iterations
)))
9057 nla_nest_end(msg
, scan_plan
);
9059 nla_nest_end(msg
, scan_plans
);
9061 nla_nest_end(msg
, nd
);
9066 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9068 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9069 struct sk_buff
*msg
;
9071 u32 size
= NLMSG_DEFAULT_SIZE
;
9073 if (!rdev
->wiphy
.wowlan
)
9076 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
9077 /* adjust size to have room for all the data */
9078 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
9079 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
9080 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
9081 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
9084 msg
= nlmsg_new(size
, GFP_KERNEL
);
9088 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9089 NL80211_CMD_GET_WOWLAN
);
9091 goto nla_put_failure
;
9093 if (rdev
->wiphy
.wowlan_config
) {
9094 struct nlattr
*nl_wowlan
;
9096 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
9098 goto nla_put_failure
;
9100 if ((rdev
->wiphy
.wowlan_config
->any
&&
9101 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
9102 (rdev
->wiphy
.wowlan_config
->disconnect
&&
9103 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
9104 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
9105 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
9106 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
9107 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
9108 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
9109 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
9110 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
9111 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
9112 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
9113 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
9114 goto nla_put_failure
;
9116 if (nl80211_send_wowlan_patterns(msg
, rdev
))
9117 goto nla_put_failure
;
9119 if (nl80211_send_wowlan_tcp(msg
,
9120 rdev
->wiphy
.wowlan_config
->tcp
))
9121 goto nla_put_failure
;
9123 if (nl80211_send_wowlan_nd(
9125 rdev
->wiphy
.wowlan_config
->nd_config
))
9126 goto nla_put_failure
;
9128 nla_nest_end(msg
, nl_wowlan
);
9131 genlmsg_end(msg
, hdr
);
9132 return genlmsg_reply(msg
, info
);
9139 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
9140 struct nlattr
*attr
,
9141 struct cfg80211_wowlan
*trig
)
9143 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
9144 struct cfg80211_wowlan_tcp
*cfg
;
9145 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
9146 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
9148 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
9151 if (!rdev
->wiphy
.wowlan
->tcp
)
9154 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
9155 nla_data(attr
), nla_len(attr
),
9156 nl80211_wowlan_tcp_policy
);
9160 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
9161 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
9162 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
9163 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
9164 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
9165 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
9166 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
9167 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
9170 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
9171 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
9174 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
9175 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
9176 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
9179 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
9180 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
9183 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
9184 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
9187 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
9188 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9190 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
9191 tokens_size
= tokln
- sizeof(*tok
);
9193 if (!tok
->len
|| tokens_size
% tok
->len
)
9195 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
9197 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
9199 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
9201 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
9203 if (tok
->offset
+ tok
->len
> data_size
)
9207 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
9208 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
9209 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
9211 if (seq
->len
== 0 || seq
->len
> 4)
9213 if (seq
->len
+ seq
->offset
> data_size
)
9217 size
= sizeof(*cfg
);
9219 size
+= wake_size
+ wake_mask_size
;
9220 size
+= tokens_size
;
9222 cfg
= kzalloc(size
, GFP_KERNEL
);
9225 cfg
->src
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
9226 cfg
->dst
= nla_get_in_addr(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
9227 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
9229 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
9230 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
9234 /* allocate a socket and port for it and use it */
9235 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
9236 IPPROTO_TCP
, &cfg
->sock
, 1);
9241 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
9242 sock_release(cfg
->sock
);
9246 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
9252 cfg
->src_port
= port
;
9255 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
9256 cfg
->payload_len
= data_size
;
9257 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
9258 memcpy((void *)cfg
->payload
,
9259 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
9262 cfg
->payload_seq
= *seq
;
9263 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
9264 cfg
->wake_len
= wake_size
;
9265 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
9266 memcpy((void *)cfg
->wake_data
,
9267 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
9269 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
9270 data_size
+ wake_size
;
9271 memcpy((void *)cfg
->wake_mask
,
9272 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
9275 cfg
->tokens_size
= tokens_size
;
9276 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
9284 static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device
*rdev
,
9285 const struct wiphy_wowlan_support
*wowlan
,
9286 struct nlattr
*attr
,
9287 struct cfg80211_wowlan
*trig
)
9292 tb
= kzalloc(NUM_NL80211_ATTR
* sizeof(*tb
), GFP_KERNEL
);
9296 if (!(wowlan
->flags
& WIPHY_WOWLAN_NET_DETECT
)) {
9301 err
= nla_parse(tb
, NL80211_ATTR_MAX
,
9302 nla_data(attr
), nla_len(attr
),
9307 trig
->nd_config
= nl80211_parse_sched_scan(&rdev
->wiphy
, NULL
, tb
);
9308 err
= PTR_ERR_OR_ZERO(trig
->nd_config
);
9310 trig
->nd_config
= NULL
;
9317 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
9319 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9320 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
9321 struct cfg80211_wowlan new_triggers
= {};
9322 struct cfg80211_wowlan
*ntrig
;
9323 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
9325 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
9326 bool regular
= false;
9331 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
9332 cfg80211_rdev_free_wowlan(rdev
);
9333 rdev
->wiphy
.wowlan_config
= NULL
;
9337 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
9338 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9339 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
9340 nl80211_wowlan_policy
);
9344 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
9345 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
9347 new_triggers
.any
= true;
9350 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
9351 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
9353 new_triggers
.disconnect
= true;
9357 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
9358 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
9360 new_triggers
.magic_pkt
= true;
9364 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
9367 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
9368 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
9370 new_triggers
.gtk_rekey_failure
= true;
9374 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
9375 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
9377 new_triggers
.eap_identity_req
= true;
9381 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
9382 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
9384 new_triggers
.four_way_handshake
= true;
9388 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
9389 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
9391 new_triggers
.rfkill_release
= true;
9395 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
9398 int rem
, pat_len
, mask_len
, pkt_offset
;
9399 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9403 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9406 if (n_patterns
> wowlan
->n_patterns
)
9409 new_triggers
.patterns
= kcalloc(n_patterns
,
9410 sizeof(new_triggers
.patterns
[0]),
9412 if (!new_triggers
.patterns
)
9415 new_triggers
.n_patterns
= n_patterns
;
9418 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
9422 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
9423 nla_len(pat
), nl80211_packet_pattern_policy
);
9425 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
9426 !pat_tb
[NL80211_PKTPAT_PATTERN
])
9428 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
9429 mask_len
= DIV_ROUND_UP(pat_len
, 8);
9430 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
9432 if (pat_len
> wowlan
->pattern_max_len
||
9433 pat_len
< wowlan
->pattern_min_len
)
9436 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
9439 pkt_offset
= nla_get_u32(
9440 pat_tb
[NL80211_PKTPAT_OFFSET
]);
9441 if (pkt_offset
> wowlan
->max_pkt_offset
)
9443 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
9445 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
9450 new_triggers
.patterns
[i
].mask
= mask_pat
;
9451 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
9453 mask_pat
+= mask_len
;
9454 new_triggers
.patterns
[i
].pattern
= mask_pat
;
9455 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
9457 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
9463 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
9465 err
= nl80211_parse_wowlan_tcp(
9466 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
9472 if (tb
[NL80211_WOWLAN_TRIG_NET_DETECT
]) {
9474 err
= nl80211_parse_wowlan_nd(
9475 rdev
, wowlan
, tb
[NL80211_WOWLAN_TRIG_NET_DETECT
],
9481 /* The 'any' trigger means the device continues operating more or less
9482 * as in its normal operation mode and wakes up the host on most of the
9483 * normal interrupts (like packet RX, ...)
9484 * It therefore makes little sense to combine with the more constrained
9485 * wakeup trigger modes.
9487 if (new_triggers
.any
&& regular
) {
9492 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
9497 cfg80211_rdev_free_wowlan(rdev
);
9498 rdev
->wiphy
.wowlan_config
= ntrig
;
9501 if (rdev
->ops
->set_wakeup
&&
9502 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
9503 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
9507 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
9508 kfree(new_triggers
.patterns
[i
].mask
);
9509 kfree(new_triggers
.patterns
);
9510 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
9511 sock_release(new_triggers
.tcp
->sock
);
9512 kfree(new_triggers
.tcp
);
9513 kfree(new_triggers
.nd_config
);
9518 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
9519 struct cfg80211_registered_device
*rdev
)
9521 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
9523 struct cfg80211_coalesce_rules
*rule
;
9525 if (!rdev
->coalesce
->n_rules
)
9528 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
9532 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
9533 nl_rule
= nla_nest_start(msg
, i
+ 1);
9537 rule
= &rdev
->coalesce
->rules
[i
];
9538 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
9542 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
9546 nl_pats
= nla_nest_start(msg
,
9547 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
9551 for (j
= 0; j
< rule
->n_patterns
; j
++) {
9552 nl_pat
= nla_nest_start(msg
, j
+ 1);
9555 pat_len
= rule
->patterns
[j
].pattern_len
;
9556 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
9557 DIV_ROUND_UP(pat_len
, 8),
9558 rule
->patterns
[j
].mask
) ||
9559 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
9560 rule
->patterns
[j
].pattern
) ||
9561 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
9562 rule
->patterns
[j
].pkt_offset
))
9564 nla_nest_end(msg
, nl_pat
);
9566 nla_nest_end(msg
, nl_pats
);
9567 nla_nest_end(msg
, nl_rule
);
9569 nla_nest_end(msg
, nl_rules
);
9574 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
9576 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9577 struct sk_buff
*msg
;
9580 if (!rdev
->wiphy
.coalesce
)
9583 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9587 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9588 NL80211_CMD_GET_COALESCE
);
9590 goto nla_put_failure
;
9592 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
9593 goto nla_put_failure
;
9595 genlmsg_end(msg
, hdr
);
9596 return genlmsg_reply(msg
, info
);
9603 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
9605 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
9607 struct cfg80211_coalesce_rules
*rule
;
9612 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
9613 rule
= &coalesce
->rules
[i
];
9614 for (j
= 0; j
< rule
->n_patterns
; j
++)
9615 kfree(rule
->patterns
[j
].mask
);
9616 kfree(rule
->patterns
);
9618 kfree(coalesce
->rules
);
9620 rdev
->coalesce
= NULL
;
9623 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
9624 struct nlattr
*rule
,
9625 struct cfg80211_coalesce_rules
*new_rule
)
9628 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
9629 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
9630 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
9631 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
9633 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
9634 nla_len(rule
), nl80211_coalesce_policy
);
9638 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
9640 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
9641 if (new_rule
->delay
> coalesce
->max_delay
)
9644 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
9645 new_rule
->condition
=
9646 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
9647 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
9648 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
9651 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
9654 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
9657 if (n_patterns
> coalesce
->n_patterns
)
9660 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
9662 if (!new_rule
->patterns
)
9665 new_rule
->n_patterns
= n_patterns
;
9668 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
9672 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
9673 nla_len(pat
), nl80211_packet_pattern_policy
);
9674 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
9675 !pat_tb
[NL80211_PKTPAT_PATTERN
])
9677 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
9678 mask_len
= DIV_ROUND_UP(pat_len
, 8);
9679 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
9681 if (pat_len
> coalesce
->pattern_max_len
||
9682 pat_len
< coalesce
->pattern_min_len
)
9685 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
9688 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
9689 if (pkt_offset
> coalesce
->max_pkt_offset
)
9691 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
9693 mask_pat
= kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
9697 new_rule
->patterns
[i
].mask
= mask_pat
;
9698 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
9701 mask_pat
+= mask_len
;
9702 new_rule
->patterns
[i
].pattern
= mask_pat
;
9703 new_rule
->patterns
[i
].pattern_len
= pat_len
;
9704 memcpy(mask_pat
, nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
9712 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
9714 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9715 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
9716 struct cfg80211_coalesce new_coalesce
= {};
9717 struct cfg80211_coalesce
*n_coalesce
;
9718 int err
, rem_rule
, n_rules
= 0, i
, j
;
9719 struct nlattr
*rule
;
9720 struct cfg80211_coalesce_rules
*tmp_rule
;
9722 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
9725 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
9726 cfg80211_rdev_free_coalesce(rdev
);
9727 rdev
->ops
->set_coalesce(&rdev
->wiphy
, NULL
);
9731 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
9734 if (n_rules
> coalesce
->n_rules
)
9737 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
9739 if (!new_coalesce
.rules
)
9742 new_coalesce
.n_rules
= n_rules
;
9745 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
9747 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
9748 &new_coalesce
.rules
[i
]);
9755 err
= rdev
->ops
->set_coalesce(&rdev
->wiphy
, &new_coalesce
);
9759 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
9764 cfg80211_rdev_free_coalesce(rdev
);
9765 rdev
->coalesce
= n_coalesce
;
9769 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
9770 tmp_rule
= &new_coalesce
.rules
[i
];
9771 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
9772 kfree(tmp_rule
->patterns
[j
].mask
);
9773 kfree(tmp_rule
->patterns
);
9775 kfree(new_coalesce
.rules
);
9780 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
9782 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9783 struct net_device
*dev
= info
->user_ptr
[1];
9784 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9785 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
9786 struct cfg80211_gtk_rekey_data rekey_data
;
9789 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
9792 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
9793 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
9794 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
9795 nl80211_rekey_policy
);
9799 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
9800 !tb
[NL80211_REKEY_DATA_KCK
])
9802 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
9804 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
9806 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
9809 rekey_data
.kek
= nla_data(tb
[NL80211_REKEY_DATA_KEK
]);
9810 rekey_data
.kck
= nla_data(tb
[NL80211_REKEY_DATA_KCK
]);
9811 rekey_data
.replay_ctr
= nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]);
9814 if (!wdev
->current_bss
) {
9819 if (!rdev
->ops
->set_rekey_data
) {
9824 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
9830 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
9831 struct genl_info
*info
)
9833 struct net_device
*dev
= info
->user_ptr
[1];
9834 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9836 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9837 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
9840 if (wdev
->ap_unexpected_nlportid
)
9843 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
9847 static int nl80211_probe_client(struct sk_buff
*skb
,
9848 struct genl_info
*info
)
9850 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9851 struct net_device
*dev
= info
->user_ptr
[1];
9852 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9853 struct sk_buff
*msg
;
9859 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9860 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
9863 if (!info
->attrs
[NL80211_ATTR_MAC
])
9866 if (!rdev
->ops
->probe_client
)
9869 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9873 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9874 NL80211_CMD_PROBE_CLIENT
);
9880 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
9882 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
9886 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9887 goto nla_put_failure
;
9889 genlmsg_end(msg
, hdr
);
9891 return genlmsg_reply(msg
, info
);
9900 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
9902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9903 struct cfg80211_beacon_registration
*reg
, *nreg
;
9906 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
9909 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
9913 /* First, check if already registered. */
9914 spin_lock_bh(&rdev
->beacon_registrations_lock
);
9915 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
9916 if (reg
->nlportid
== info
->snd_portid
) {
9921 /* Add it to the list */
9922 nreg
->nlportid
= info
->snd_portid
;
9923 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
9925 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9929 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9934 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9936 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9937 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9940 if (!rdev
->ops
->start_p2p_device
)
9943 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9946 if (wdev
->p2p_started
)
9949 if (rfkill_blocked(rdev
->rfkill
))
9952 err
= rdev_start_p2p_device(rdev
, wdev
);
9956 wdev
->p2p_started
= true;
9962 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
9964 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
9965 struct wireless_dev
*wdev
= info
->user_ptr
[1];
9967 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
9970 if (!rdev
->ops
->stop_p2p_device
)
9973 cfg80211_stop_p2p_device(rdev
, wdev
);
9978 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
9979 struct genl_info
*info
)
9982 struct sk_buff
*msg
;
9984 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9988 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
9989 NL80211_CMD_GET_PROTOCOL_FEATURES
);
9991 goto nla_put_failure
;
9993 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
9994 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
9995 goto nla_put_failure
;
9997 genlmsg_end(msg
, hdr
);
9998 return genlmsg_reply(msg
, info
);
10005 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
10007 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10008 struct cfg80211_update_ft_ies_params ft_params
;
10009 struct net_device
*dev
= info
->user_ptr
[1];
10011 if (!rdev
->ops
->update_ft_ies
)
10012 return -EOPNOTSUPP
;
10014 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
10015 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
10018 memset(&ft_params
, 0, sizeof(ft_params
));
10019 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
10020 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
10021 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
10023 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
10026 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
10027 struct genl_info
*info
)
10029 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10030 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10031 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
10035 if (!rdev
->ops
->crit_proto_start
)
10036 return -EOPNOTSUPP
;
10038 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
10041 if (rdev
->crit_proto_nlportid
)
10044 /* determine protocol if provided */
10045 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
10046 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
10048 if (proto
>= NUM_NL80211_CRIT_PROTO
)
10051 /* timeout must be provided */
10052 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
10056 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
10058 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
10061 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
10063 rdev
->crit_proto_nlportid
= info
->snd_portid
;
10068 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
10069 struct genl_info
*info
)
10071 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10072 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10074 if (!rdev
->ops
->crit_proto_stop
)
10075 return -EOPNOTSUPP
;
10077 if (rdev
->crit_proto_nlportid
) {
10078 rdev
->crit_proto_nlportid
= 0;
10079 rdev_crit_proto_stop(rdev
, wdev
);
10084 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
10086 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10087 struct wireless_dev
*wdev
=
10088 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
10092 if (!rdev
->wiphy
.vendor_commands
)
10093 return -EOPNOTSUPP
;
10095 if (IS_ERR(wdev
)) {
10096 err
= PTR_ERR(wdev
);
10097 if (err
!= -EINVAL
)
10100 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
10104 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
10105 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
10108 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
10109 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
10110 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
10111 const struct wiphy_vendor_command
*vcmd
;
10115 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
10117 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10120 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
10121 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
10124 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10128 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10129 if (wdev
->netdev
&&
10130 !netif_running(wdev
->netdev
))
10132 if (!wdev
->netdev
&& !wdev
->p2p_started
)
10137 return -EOPNOTSUPP
;
10142 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
10143 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10144 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
10147 rdev
->cur_cmd_info
= info
;
10148 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
10150 rdev
->cur_cmd_info
= NULL
;
10154 return -EOPNOTSUPP
;
10157 static int nl80211_prepare_vendor_dump(struct sk_buff
*skb
,
10158 struct netlink_callback
*cb
,
10159 struct cfg80211_registered_device
**rdev
,
10160 struct wireless_dev
**wdev
)
10167 unsigned int data_len
= 0;
10170 /* subtract the 1 again here */
10171 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
10172 struct wireless_dev
*tmp
;
10176 *rdev
= wiphy_to_rdev(wiphy
);
10180 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
10181 if (tmp
->identifier
== cb
->args
[1] - 1) {
10188 /* keep rtnl locked in successful case */
10192 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
10193 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
10198 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
] ||
10199 !nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
])
10202 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
10203 nl80211_fam
.attrbuf
);
10207 *rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
10208 nl80211_fam
.attrbuf
);
10210 return PTR_ERR(*rdev
);
10212 vid
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_ID
]);
10213 subcmd
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_SUBCMD
]);
10215 for (i
= 0; i
< (*rdev
)->wiphy
.n_vendor_commands
; i
++) {
10216 const struct wiphy_vendor_command
*vcmd
;
10218 vcmd
= &(*rdev
)->wiphy
.vendor_commands
[i
];
10220 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
10224 return -EOPNOTSUPP
;
10231 return -EOPNOTSUPP
;
10233 if (nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]) {
10234 data
= nla_data(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10235 data_len
= nla_len(nl80211_fam
.attrbuf
[NL80211_ATTR_VENDOR_DATA
]);
10238 /* 0 is the first index - add 1 to parse only once */
10239 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
10240 /* add 1 to know if it was NULL */
10241 cb
->args
[1] = *wdev
? (*wdev
)->identifier
+ 1 : 0;
10242 cb
->args
[2] = vcmd_idx
;
10243 cb
->args
[3] = (unsigned long)data
;
10244 cb
->args
[4] = data_len
;
10246 /* keep rtnl locked in successful case */
10250 static int nl80211_vendor_cmd_dump(struct sk_buff
*skb
,
10251 struct netlink_callback
*cb
)
10253 struct cfg80211_registered_device
*rdev
;
10254 struct wireless_dev
*wdev
;
10255 unsigned int vcmd_idx
;
10256 const struct wiphy_vendor_command
*vcmd
;
10260 struct nlattr
*vendor_data
;
10263 err
= nl80211_prepare_vendor_dump(skb
, cb
, &rdev
, &wdev
);
10267 vcmd_idx
= cb
->args
[2];
10268 data
= (void *)cb
->args
[3];
10269 data_len
= cb
->args
[4];
10270 vcmd
= &rdev
->wiphy
.vendor_commands
[vcmd_idx
];
10272 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
10273 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
10278 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
10284 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
10285 if (wdev
->netdev
&&
10286 !netif_running(wdev
->netdev
)) {
10290 if (!wdev
->netdev
&& !wdev
->p2p_started
) {
10298 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
10299 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
10300 NL80211_CMD_VENDOR
);
10304 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10305 (wdev
&& nla_put_u64(skb
, NL80211_ATTR_WDEV
,
10307 genlmsg_cancel(skb
, hdr
);
10311 vendor_data
= nla_nest_start(skb
, NL80211_ATTR_VENDOR_DATA
);
10312 if (!vendor_data
) {
10313 genlmsg_cancel(skb
, hdr
);
10317 err
= vcmd
->dumpit(&rdev
->wiphy
, wdev
, skb
, data
, data_len
,
10318 (unsigned long *)&cb
->args
[5]);
10319 nla_nest_end(skb
, vendor_data
);
10321 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
10322 genlmsg_cancel(skb
, hdr
);
10325 genlmsg_cancel(skb
, hdr
);
10329 genlmsg_end(skb
, hdr
);
10338 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
10339 enum nl80211_commands cmd
,
10340 enum nl80211_attrs attr
,
10343 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
10345 if (WARN_ON(!rdev
->cur_cmd_info
))
10348 return __cfg80211_alloc_vendor_skb(rdev
, NULL
, approxlen
,
10349 rdev
->cur_cmd_info
->snd_portid
,
10350 rdev
->cur_cmd_info
->snd_seq
,
10351 cmd
, attr
, NULL
, GFP_KERNEL
);
10353 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
10355 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
10357 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
10358 void *hdr
= ((void **)skb
->cb
)[1];
10359 struct nlattr
*data
= ((void **)skb
->cb
)[2];
10361 /* clear CB data for netlink core to own from now on */
10362 memset(skb
->cb
, 0, sizeof(skb
->cb
));
10364 if (WARN_ON(!rdev
->cur_cmd_info
)) {
10369 nla_nest_end(skb
, data
);
10370 genlmsg_end(skb
, hdr
);
10371 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
10373 EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply
);
10376 static int nl80211_set_qos_map(struct sk_buff
*skb
,
10377 struct genl_info
*info
)
10379 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10380 struct cfg80211_qos_map
*qos_map
= NULL
;
10381 struct net_device
*dev
= info
->user_ptr
[1];
10382 u8
*pos
, len
, num_des
, des_len
, des
;
10385 if (!rdev
->ops
->set_qos_map
)
10386 return -EOPNOTSUPP
;
10388 if (info
->attrs
[NL80211_ATTR_QOS_MAP
]) {
10389 pos
= nla_data(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10390 len
= nla_len(info
->attrs
[NL80211_ATTR_QOS_MAP
]);
10392 if (len
% 2 || len
< IEEE80211_QOS_MAP_LEN_MIN
||
10393 len
> IEEE80211_QOS_MAP_LEN_MAX
)
10396 qos_map
= kzalloc(sizeof(struct cfg80211_qos_map
), GFP_KERNEL
);
10400 num_des
= (len
- IEEE80211_QOS_MAP_LEN_MIN
) >> 1;
10402 des_len
= num_des
*
10403 sizeof(struct cfg80211_dscp_exception
);
10404 memcpy(qos_map
->dscp_exception
, pos
, des_len
);
10405 qos_map
->num_des
= num_des
;
10406 for (des
= 0; des
< num_des
; des
++) {
10407 if (qos_map
->dscp_exception
[des
].up
> 7) {
10414 memcpy(qos_map
->up
, pos
, IEEE80211_QOS_MAP_LEN_MIN
);
10417 wdev_lock(dev
->ieee80211_ptr
);
10418 ret
= nl80211_key_allowed(dev
->ieee80211_ptr
);
10420 ret
= rdev_set_qos_map(rdev
, dev
, qos_map
);
10421 wdev_unlock(dev
->ieee80211_ptr
);
10427 static int nl80211_add_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10429 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10430 struct net_device
*dev
= info
->user_ptr
[1];
10431 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10434 u16 admitted_time
= 0;
10437 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
))
10438 return -EOPNOTSUPP
;
10440 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
] ||
10441 !info
->attrs
[NL80211_ATTR_USER_PRIO
])
10444 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10445 if (tsid
>= IEEE80211_NUM_TIDS
)
10448 up
= nla_get_u8(info
->attrs
[NL80211_ATTR_USER_PRIO
]);
10449 if (up
>= IEEE80211_NUM_UPS
)
10452 /* WMM uses TIDs 0-7 even for TSPEC */
10453 if (tsid
>= IEEE80211_FIRST_TSPEC_TSID
) {
10454 /* TODO: handle 802.11 TSPEC/admission control
10455 * need more attributes for that (e.g. BA session requirement);
10456 * change the WMM adminssion test above to allow both then
10461 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10463 if (info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]) {
10465 nla_get_u16(info
->attrs
[NL80211_ATTR_ADMITTED_TIME
]);
10466 if (!admitted_time
)
10471 switch (wdev
->iftype
) {
10472 case NL80211_IFTYPE_STATION
:
10473 case NL80211_IFTYPE_P2P_CLIENT
:
10474 if (wdev
->current_bss
)
10483 err
= rdev_add_tx_ts(rdev
, dev
, tsid
, peer
, up
, admitted_time
);
10490 static int nl80211_del_tx_ts(struct sk_buff
*skb
, struct genl_info
*info
)
10492 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10493 struct net_device
*dev
= info
->user_ptr
[1];
10494 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10499 if (!info
->attrs
[NL80211_ATTR_TSID
] || !info
->attrs
[NL80211_ATTR_MAC
])
10502 tsid
= nla_get_u8(info
->attrs
[NL80211_ATTR_TSID
]);
10503 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10506 err
= rdev_del_tx_ts(rdev
, dev
, tsid
, peer
);
10512 static int nl80211_tdls_channel_switch(struct sk_buff
*skb
,
10513 struct genl_info
*info
)
10515 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10516 struct net_device
*dev
= info
->user_ptr
[1];
10517 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10518 struct cfg80211_chan_def chandef
= {};
10523 if (!rdev
->ops
->tdls_channel_switch
||
10524 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10525 return -EOPNOTSUPP
;
10527 switch (dev
->ieee80211_ptr
->iftype
) {
10528 case NL80211_IFTYPE_STATION
:
10529 case NL80211_IFTYPE_P2P_CLIENT
:
10532 return -EOPNOTSUPP
;
10535 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
10536 !info
->attrs
[NL80211_ATTR_OPER_CLASS
])
10539 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
10544 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10545 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10546 * specification is not defined for them.
10548 if (chandef
.chan
->band
== NL80211_BAND_2GHZ
&&
10549 chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
10550 chandef
.width
!= NL80211_CHAN_WIDTH_20
)
10553 /* we will be active on the TDLS link */
10554 if (!cfg80211_reg_can_beacon_relax(&rdev
->wiphy
, &chandef
,
10558 /* don't allow switching to DFS channels */
10559 if (cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
, wdev
->iftype
))
10562 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10563 oper_class
= nla_get_u8(info
->attrs
[NL80211_ATTR_OPER_CLASS
]);
10566 err
= rdev_tdls_channel_switch(rdev
, dev
, addr
, oper_class
, &chandef
);
10572 static int nl80211_tdls_cancel_channel_switch(struct sk_buff
*skb
,
10573 struct genl_info
*info
)
10575 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
10576 struct net_device
*dev
= info
->user_ptr
[1];
10577 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10580 if (!rdev
->ops
->tdls_channel_switch
||
10581 !rdev
->ops
->tdls_cancel_channel_switch
||
10582 !(rdev
->wiphy
.features
& NL80211_FEATURE_TDLS_CHANNEL_SWITCH
))
10583 return -EOPNOTSUPP
;
10585 switch (dev
->ieee80211_ptr
->iftype
) {
10586 case NL80211_IFTYPE_STATION
:
10587 case NL80211_IFTYPE_P2P_CLIENT
:
10590 return -EOPNOTSUPP
;
10593 if (!info
->attrs
[NL80211_ATTR_MAC
])
10596 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
10599 rdev_tdls_cancel_channel_switch(rdev
, dev
, addr
);
10605 #define NL80211_FLAG_NEED_WIPHY 0x01
10606 #define NL80211_FLAG_NEED_NETDEV 0x02
10607 #define NL80211_FLAG_NEED_RTNL 0x04
10608 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10609 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10610 NL80211_FLAG_CHECK_NETDEV_UP)
10611 #define NL80211_FLAG_NEED_WDEV 0x10
10612 /* If a netdev is associated, it must be UP, P2P must be started */
10613 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10614 NL80211_FLAG_CHECK_NETDEV_UP)
10615 #define NL80211_FLAG_CLEAR_SKB 0x20
10617 static int nl80211_pre_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
10618 struct genl_info
*info
)
10620 struct cfg80211_registered_device
*rdev
;
10621 struct wireless_dev
*wdev
;
10622 struct net_device
*dev
;
10623 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
10628 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
10629 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
10630 if (IS_ERR(rdev
)) {
10633 return PTR_ERR(rdev
);
10635 info
->user_ptr
[0] = rdev
;
10636 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
10637 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
10640 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
10642 if (IS_ERR(wdev
)) {
10645 return PTR_ERR(wdev
);
10648 dev
= wdev
->netdev
;
10649 rdev
= wiphy_to_rdev(wdev
->wiphy
);
10651 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
10658 info
->user_ptr
[1] = dev
;
10660 info
->user_ptr
[1] = wdev
;
10664 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
10665 !netif_running(dev
)) {
10672 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
10673 if (!wdev
->p2p_started
) {
10680 info
->user_ptr
[0] = rdev
;
10686 static void nl80211_post_doit(const struct genl_ops
*ops
, struct sk_buff
*skb
,
10687 struct genl_info
*info
)
10689 if (info
->user_ptr
[1]) {
10690 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
10691 struct wireless_dev
*wdev
= info
->user_ptr
[1];
10694 dev_put(wdev
->netdev
);
10696 dev_put(info
->user_ptr
[1]);
10700 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
10703 /* If needed, clear the netlink message payload from the SKB
10704 * as it might contain key data that shouldn't stick around on
10705 * the heap after the SKB is freed. The netlink message header
10706 * is still needed for further processing, so leave it intact.
10708 if (ops
->internal_flags
& NL80211_FLAG_CLEAR_SKB
) {
10709 struct nlmsghdr
*nlh
= nlmsg_hdr(skb
);
10711 memset(nlmsg_data(nlh
), 0, nlmsg_len(nlh
));
10715 static const struct genl_ops nl80211_ops
[] = {
10717 .cmd
= NL80211_CMD_GET_WIPHY
,
10718 .doit
= nl80211_get_wiphy
,
10719 .dumpit
= nl80211_dump_wiphy
,
10720 .done
= nl80211_dump_wiphy_done
,
10721 .policy
= nl80211_policy
,
10722 /* can be retrieved by unprivileged users */
10723 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10724 NL80211_FLAG_NEED_RTNL
,
10727 .cmd
= NL80211_CMD_SET_WIPHY
,
10728 .doit
= nl80211_set_wiphy
,
10729 .policy
= nl80211_policy
,
10730 .flags
= GENL_ADMIN_PERM
,
10731 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10734 .cmd
= NL80211_CMD_GET_INTERFACE
,
10735 .doit
= nl80211_get_interface
,
10736 .dumpit
= nl80211_dump_interface
,
10737 .policy
= nl80211_policy
,
10738 /* can be retrieved by unprivileged users */
10739 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
10740 NL80211_FLAG_NEED_RTNL
,
10743 .cmd
= NL80211_CMD_SET_INTERFACE
,
10744 .doit
= nl80211_set_interface
,
10745 .policy
= nl80211_policy
,
10746 .flags
= GENL_ADMIN_PERM
,
10747 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10748 NL80211_FLAG_NEED_RTNL
,
10751 .cmd
= NL80211_CMD_NEW_INTERFACE
,
10752 .doit
= nl80211_new_interface
,
10753 .policy
= nl80211_policy
,
10754 .flags
= GENL_ADMIN_PERM
,
10755 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
10756 NL80211_FLAG_NEED_RTNL
,
10759 .cmd
= NL80211_CMD_DEL_INTERFACE
,
10760 .doit
= nl80211_del_interface
,
10761 .policy
= nl80211_policy
,
10762 .flags
= GENL_ADMIN_PERM
,
10763 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
10764 NL80211_FLAG_NEED_RTNL
,
10767 .cmd
= NL80211_CMD_GET_KEY
,
10768 .doit
= nl80211_get_key
,
10769 .policy
= nl80211_policy
,
10770 .flags
= GENL_ADMIN_PERM
,
10771 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10772 NL80211_FLAG_NEED_RTNL
,
10775 .cmd
= NL80211_CMD_SET_KEY
,
10776 .doit
= nl80211_set_key
,
10777 .policy
= nl80211_policy
,
10778 .flags
= GENL_ADMIN_PERM
,
10779 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10780 NL80211_FLAG_NEED_RTNL
|
10781 NL80211_FLAG_CLEAR_SKB
,
10784 .cmd
= NL80211_CMD_NEW_KEY
,
10785 .doit
= nl80211_new_key
,
10786 .policy
= nl80211_policy
,
10787 .flags
= GENL_ADMIN_PERM
,
10788 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10789 NL80211_FLAG_NEED_RTNL
|
10790 NL80211_FLAG_CLEAR_SKB
,
10793 .cmd
= NL80211_CMD_DEL_KEY
,
10794 .doit
= nl80211_del_key
,
10795 .policy
= nl80211_policy
,
10796 .flags
= GENL_ADMIN_PERM
,
10797 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10798 NL80211_FLAG_NEED_RTNL
,
10801 .cmd
= NL80211_CMD_SET_BEACON
,
10802 .policy
= nl80211_policy
,
10803 .flags
= GENL_ADMIN_PERM
,
10804 .doit
= nl80211_set_beacon
,
10805 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10806 NL80211_FLAG_NEED_RTNL
,
10809 .cmd
= NL80211_CMD_START_AP
,
10810 .policy
= nl80211_policy
,
10811 .flags
= GENL_ADMIN_PERM
,
10812 .doit
= nl80211_start_ap
,
10813 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10814 NL80211_FLAG_NEED_RTNL
,
10817 .cmd
= NL80211_CMD_STOP_AP
,
10818 .policy
= nl80211_policy
,
10819 .flags
= GENL_ADMIN_PERM
,
10820 .doit
= nl80211_stop_ap
,
10821 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10822 NL80211_FLAG_NEED_RTNL
,
10825 .cmd
= NL80211_CMD_GET_STATION
,
10826 .doit
= nl80211_get_station
,
10827 .dumpit
= nl80211_dump_station
,
10828 .policy
= nl80211_policy
,
10829 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
10830 NL80211_FLAG_NEED_RTNL
,
10833 .cmd
= NL80211_CMD_SET_STATION
,
10834 .doit
= nl80211_set_station
,
10835 .policy
= nl80211_policy
,
10836 .flags
= GENL_ADMIN_PERM
,
10837 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10838 NL80211_FLAG_NEED_RTNL
,
10841 .cmd
= NL80211_CMD_NEW_STATION
,
10842 .doit
= nl80211_new_station
,
10843 .policy
= nl80211_policy
,
10844 .flags
= GENL_ADMIN_PERM
,
10845 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10846 NL80211_FLAG_NEED_RTNL
,
10849 .cmd
= NL80211_CMD_DEL_STATION
,
10850 .doit
= nl80211_del_station
,
10851 .policy
= nl80211_policy
,
10852 .flags
= GENL_ADMIN_PERM
,
10853 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10854 NL80211_FLAG_NEED_RTNL
,
10857 .cmd
= NL80211_CMD_GET_MPATH
,
10858 .doit
= nl80211_get_mpath
,
10859 .dumpit
= nl80211_dump_mpath
,
10860 .policy
= nl80211_policy
,
10861 .flags
= GENL_ADMIN_PERM
,
10862 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10863 NL80211_FLAG_NEED_RTNL
,
10866 .cmd
= NL80211_CMD_GET_MPP
,
10867 .doit
= nl80211_get_mpp
,
10868 .dumpit
= nl80211_dump_mpp
,
10869 .policy
= nl80211_policy
,
10870 .flags
= GENL_ADMIN_PERM
,
10871 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10872 NL80211_FLAG_NEED_RTNL
,
10875 .cmd
= NL80211_CMD_SET_MPATH
,
10876 .doit
= nl80211_set_mpath
,
10877 .policy
= nl80211_policy
,
10878 .flags
= GENL_ADMIN_PERM
,
10879 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10880 NL80211_FLAG_NEED_RTNL
,
10883 .cmd
= NL80211_CMD_NEW_MPATH
,
10884 .doit
= nl80211_new_mpath
,
10885 .policy
= nl80211_policy
,
10886 .flags
= GENL_ADMIN_PERM
,
10887 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10888 NL80211_FLAG_NEED_RTNL
,
10891 .cmd
= NL80211_CMD_DEL_MPATH
,
10892 .doit
= nl80211_del_mpath
,
10893 .policy
= nl80211_policy
,
10894 .flags
= GENL_ADMIN_PERM
,
10895 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10896 NL80211_FLAG_NEED_RTNL
,
10899 .cmd
= NL80211_CMD_SET_BSS
,
10900 .doit
= nl80211_set_bss
,
10901 .policy
= nl80211_policy
,
10902 .flags
= GENL_ADMIN_PERM
,
10903 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10904 NL80211_FLAG_NEED_RTNL
,
10907 .cmd
= NL80211_CMD_GET_REG
,
10908 .doit
= nl80211_get_reg_do
,
10909 .dumpit
= nl80211_get_reg_dump
,
10910 .policy
= nl80211_policy
,
10911 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10912 /* can be retrieved by unprivileged users */
10914 #ifdef CONFIG_CFG80211_CRDA_SUPPORT
10916 .cmd
= NL80211_CMD_SET_REG
,
10917 .doit
= nl80211_set_reg
,
10918 .policy
= nl80211_policy
,
10919 .flags
= GENL_ADMIN_PERM
,
10920 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
10924 .cmd
= NL80211_CMD_REQ_SET_REG
,
10925 .doit
= nl80211_req_set_reg
,
10926 .policy
= nl80211_policy
,
10927 .flags
= GENL_ADMIN_PERM
,
10930 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
10931 .doit
= nl80211_get_mesh_config
,
10932 .policy
= nl80211_policy
,
10933 /* can be retrieved by unprivileged users */
10934 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10935 NL80211_FLAG_NEED_RTNL
,
10938 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
10939 .doit
= nl80211_update_mesh_config
,
10940 .policy
= nl80211_policy
,
10941 .flags
= GENL_ADMIN_PERM
,
10942 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10943 NL80211_FLAG_NEED_RTNL
,
10946 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
10947 .doit
= nl80211_trigger_scan
,
10948 .policy
= nl80211_policy
,
10949 .flags
= GENL_ADMIN_PERM
,
10950 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
10951 NL80211_FLAG_NEED_RTNL
,
10954 .cmd
= NL80211_CMD_GET_SCAN
,
10955 .policy
= nl80211_policy
,
10956 .dumpit
= nl80211_dump_scan
,
10959 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
10960 .doit
= nl80211_start_sched_scan
,
10961 .policy
= nl80211_policy
,
10962 .flags
= GENL_ADMIN_PERM
,
10963 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10964 NL80211_FLAG_NEED_RTNL
,
10967 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
10968 .doit
= nl80211_stop_sched_scan
,
10969 .policy
= nl80211_policy
,
10970 .flags
= GENL_ADMIN_PERM
,
10971 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10972 NL80211_FLAG_NEED_RTNL
,
10975 .cmd
= NL80211_CMD_AUTHENTICATE
,
10976 .doit
= nl80211_authenticate
,
10977 .policy
= nl80211_policy
,
10978 .flags
= GENL_ADMIN_PERM
,
10979 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10980 NL80211_FLAG_NEED_RTNL
|
10981 NL80211_FLAG_CLEAR_SKB
,
10984 .cmd
= NL80211_CMD_ASSOCIATE
,
10985 .doit
= nl80211_associate
,
10986 .policy
= nl80211_policy
,
10987 .flags
= GENL_ADMIN_PERM
,
10988 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10989 NL80211_FLAG_NEED_RTNL
,
10992 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
10993 .doit
= nl80211_deauthenticate
,
10994 .policy
= nl80211_policy
,
10995 .flags
= GENL_ADMIN_PERM
,
10996 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
10997 NL80211_FLAG_NEED_RTNL
,
11000 .cmd
= NL80211_CMD_DISASSOCIATE
,
11001 .doit
= nl80211_disassociate
,
11002 .policy
= nl80211_policy
,
11003 .flags
= GENL_ADMIN_PERM
,
11004 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11005 NL80211_FLAG_NEED_RTNL
,
11008 .cmd
= NL80211_CMD_JOIN_IBSS
,
11009 .doit
= nl80211_join_ibss
,
11010 .policy
= nl80211_policy
,
11011 .flags
= GENL_ADMIN_PERM
,
11012 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11013 NL80211_FLAG_NEED_RTNL
,
11016 .cmd
= NL80211_CMD_LEAVE_IBSS
,
11017 .doit
= nl80211_leave_ibss
,
11018 .policy
= nl80211_policy
,
11019 .flags
= GENL_ADMIN_PERM
,
11020 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11021 NL80211_FLAG_NEED_RTNL
,
11023 #ifdef CONFIG_NL80211_TESTMODE
11025 .cmd
= NL80211_CMD_TESTMODE
,
11026 .doit
= nl80211_testmode_do
,
11027 .dumpit
= nl80211_testmode_dump
,
11028 .policy
= nl80211_policy
,
11029 .flags
= GENL_ADMIN_PERM
,
11030 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11031 NL80211_FLAG_NEED_RTNL
,
11035 .cmd
= NL80211_CMD_CONNECT
,
11036 .doit
= nl80211_connect
,
11037 .policy
= nl80211_policy
,
11038 .flags
= GENL_ADMIN_PERM
,
11039 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11040 NL80211_FLAG_NEED_RTNL
,
11043 .cmd
= NL80211_CMD_DISCONNECT
,
11044 .doit
= nl80211_disconnect
,
11045 .policy
= nl80211_policy
,
11046 .flags
= GENL_ADMIN_PERM
,
11047 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11048 NL80211_FLAG_NEED_RTNL
,
11051 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
11052 .doit
= nl80211_wiphy_netns
,
11053 .policy
= nl80211_policy
,
11054 .flags
= GENL_ADMIN_PERM
,
11055 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11056 NL80211_FLAG_NEED_RTNL
,
11059 .cmd
= NL80211_CMD_GET_SURVEY
,
11060 .policy
= nl80211_policy
,
11061 .dumpit
= nl80211_dump_survey
,
11064 .cmd
= NL80211_CMD_SET_PMKSA
,
11065 .doit
= nl80211_setdel_pmksa
,
11066 .policy
= nl80211_policy
,
11067 .flags
= GENL_ADMIN_PERM
,
11068 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11069 NL80211_FLAG_NEED_RTNL
,
11072 .cmd
= NL80211_CMD_DEL_PMKSA
,
11073 .doit
= nl80211_setdel_pmksa
,
11074 .policy
= nl80211_policy
,
11075 .flags
= GENL_ADMIN_PERM
,
11076 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11077 NL80211_FLAG_NEED_RTNL
,
11080 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
11081 .doit
= nl80211_flush_pmksa
,
11082 .policy
= nl80211_policy
,
11083 .flags
= GENL_ADMIN_PERM
,
11084 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11085 NL80211_FLAG_NEED_RTNL
,
11088 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
11089 .doit
= nl80211_remain_on_channel
,
11090 .policy
= nl80211_policy
,
11091 .flags
= GENL_ADMIN_PERM
,
11092 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11093 NL80211_FLAG_NEED_RTNL
,
11096 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
11097 .doit
= nl80211_cancel_remain_on_channel
,
11098 .policy
= nl80211_policy
,
11099 .flags
= GENL_ADMIN_PERM
,
11100 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11101 NL80211_FLAG_NEED_RTNL
,
11104 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
11105 .doit
= nl80211_set_tx_bitrate_mask
,
11106 .policy
= nl80211_policy
,
11107 .flags
= GENL_ADMIN_PERM
,
11108 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11109 NL80211_FLAG_NEED_RTNL
,
11112 .cmd
= NL80211_CMD_REGISTER_FRAME
,
11113 .doit
= nl80211_register_mgmt
,
11114 .policy
= nl80211_policy
,
11115 .flags
= GENL_ADMIN_PERM
,
11116 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11117 NL80211_FLAG_NEED_RTNL
,
11120 .cmd
= NL80211_CMD_FRAME
,
11121 .doit
= nl80211_tx_mgmt
,
11122 .policy
= nl80211_policy
,
11123 .flags
= GENL_ADMIN_PERM
,
11124 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11125 NL80211_FLAG_NEED_RTNL
,
11128 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
11129 .doit
= nl80211_tx_mgmt_cancel_wait
,
11130 .policy
= nl80211_policy
,
11131 .flags
= GENL_ADMIN_PERM
,
11132 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11133 NL80211_FLAG_NEED_RTNL
,
11136 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
11137 .doit
= nl80211_set_power_save
,
11138 .policy
= nl80211_policy
,
11139 .flags
= GENL_ADMIN_PERM
,
11140 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11141 NL80211_FLAG_NEED_RTNL
,
11144 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
11145 .doit
= nl80211_get_power_save
,
11146 .policy
= nl80211_policy
,
11147 /* can be retrieved by unprivileged users */
11148 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11149 NL80211_FLAG_NEED_RTNL
,
11152 .cmd
= NL80211_CMD_SET_CQM
,
11153 .doit
= nl80211_set_cqm
,
11154 .policy
= nl80211_policy
,
11155 .flags
= GENL_ADMIN_PERM
,
11156 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11157 NL80211_FLAG_NEED_RTNL
,
11160 .cmd
= NL80211_CMD_SET_CHANNEL
,
11161 .doit
= nl80211_set_channel
,
11162 .policy
= nl80211_policy
,
11163 .flags
= GENL_ADMIN_PERM
,
11164 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11165 NL80211_FLAG_NEED_RTNL
,
11168 .cmd
= NL80211_CMD_SET_WDS_PEER
,
11169 .doit
= nl80211_set_wds_peer
,
11170 .policy
= nl80211_policy
,
11171 .flags
= GENL_ADMIN_PERM
,
11172 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11173 NL80211_FLAG_NEED_RTNL
,
11176 .cmd
= NL80211_CMD_JOIN_MESH
,
11177 .doit
= nl80211_join_mesh
,
11178 .policy
= nl80211_policy
,
11179 .flags
= GENL_ADMIN_PERM
,
11180 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11181 NL80211_FLAG_NEED_RTNL
,
11184 .cmd
= NL80211_CMD_LEAVE_MESH
,
11185 .doit
= nl80211_leave_mesh
,
11186 .policy
= nl80211_policy
,
11187 .flags
= GENL_ADMIN_PERM
,
11188 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11189 NL80211_FLAG_NEED_RTNL
,
11192 .cmd
= NL80211_CMD_JOIN_OCB
,
11193 .doit
= nl80211_join_ocb
,
11194 .policy
= nl80211_policy
,
11195 .flags
= GENL_ADMIN_PERM
,
11196 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11197 NL80211_FLAG_NEED_RTNL
,
11200 .cmd
= NL80211_CMD_LEAVE_OCB
,
11201 .doit
= nl80211_leave_ocb
,
11202 .policy
= nl80211_policy
,
11203 .flags
= GENL_ADMIN_PERM
,
11204 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11205 NL80211_FLAG_NEED_RTNL
,
11209 .cmd
= NL80211_CMD_GET_WOWLAN
,
11210 .doit
= nl80211_get_wowlan
,
11211 .policy
= nl80211_policy
,
11212 /* can be retrieved by unprivileged users */
11213 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11214 NL80211_FLAG_NEED_RTNL
,
11217 .cmd
= NL80211_CMD_SET_WOWLAN
,
11218 .doit
= nl80211_set_wowlan
,
11219 .policy
= nl80211_policy
,
11220 .flags
= GENL_ADMIN_PERM
,
11221 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11222 NL80211_FLAG_NEED_RTNL
,
11226 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
11227 .doit
= nl80211_set_rekey_data
,
11228 .policy
= nl80211_policy
,
11229 .flags
= GENL_ADMIN_PERM
,
11230 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11231 NL80211_FLAG_NEED_RTNL
|
11232 NL80211_FLAG_CLEAR_SKB
,
11235 .cmd
= NL80211_CMD_TDLS_MGMT
,
11236 .doit
= nl80211_tdls_mgmt
,
11237 .policy
= nl80211_policy
,
11238 .flags
= GENL_ADMIN_PERM
,
11239 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11240 NL80211_FLAG_NEED_RTNL
,
11243 .cmd
= NL80211_CMD_TDLS_OPER
,
11244 .doit
= nl80211_tdls_oper
,
11245 .policy
= nl80211_policy
,
11246 .flags
= GENL_ADMIN_PERM
,
11247 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11248 NL80211_FLAG_NEED_RTNL
,
11251 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
11252 .doit
= nl80211_register_unexpected_frame
,
11253 .policy
= nl80211_policy
,
11254 .flags
= GENL_ADMIN_PERM
,
11255 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11256 NL80211_FLAG_NEED_RTNL
,
11259 .cmd
= NL80211_CMD_PROBE_CLIENT
,
11260 .doit
= nl80211_probe_client
,
11261 .policy
= nl80211_policy
,
11262 .flags
= GENL_ADMIN_PERM
,
11263 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11264 NL80211_FLAG_NEED_RTNL
,
11267 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
11268 .doit
= nl80211_register_beacons
,
11269 .policy
= nl80211_policy
,
11270 .flags
= GENL_ADMIN_PERM
,
11271 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11272 NL80211_FLAG_NEED_RTNL
,
11275 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
11276 .doit
= nl80211_set_noack_map
,
11277 .policy
= nl80211_policy
,
11278 .flags
= GENL_ADMIN_PERM
,
11279 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11280 NL80211_FLAG_NEED_RTNL
,
11283 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
11284 .doit
= nl80211_start_p2p_device
,
11285 .policy
= nl80211_policy
,
11286 .flags
= GENL_ADMIN_PERM
,
11287 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
11288 NL80211_FLAG_NEED_RTNL
,
11291 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
11292 .doit
= nl80211_stop_p2p_device
,
11293 .policy
= nl80211_policy
,
11294 .flags
= GENL_ADMIN_PERM
,
11295 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11296 NL80211_FLAG_NEED_RTNL
,
11299 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
11300 .doit
= nl80211_set_mcast_rate
,
11301 .policy
= nl80211_policy
,
11302 .flags
= GENL_ADMIN_PERM
,
11303 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11304 NL80211_FLAG_NEED_RTNL
,
11307 .cmd
= NL80211_CMD_SET_MAC_ACL
,
11308 .doit
= nl80211_set_mac_acl
,
11309 .policy
= nl80211_policy
,
11310 .flags
= GENL_ADMIN_PERM
,
11311 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
11312 NL80211_FLAG_NEED_RTNL
,
11315 .cmd
= NL80211_CMD_RADAR_DETECT
,
11316 .doit
= nl80211_start_radar_detection
,
11317 .policy
= nl80211_policy
,
11318 .flags
= GENL_ADMIN_PERM
,
11319 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11320 NL80211_FLAG_NEED_RTNL
,
11323 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
11324 .doit
= nl80211_get_protocol_features
,
11325 .policy
= nl80211_policy
,
11328 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
11329 .doit
= nl80211_update_ft_ies
,
11330 .policy
= nl80211_policy
,
11331 .flags
= GENL_ADMIN_PERM
,
11332 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11333 NL80211_FLAG_NEED_RTNL
,
11336 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
11337 .doit
= nl80211_crit_protocol_start
,
11338 .policy
= nl80211_policy
,
11339 .flags
= GENL_ADMIN_PERM
,
11340 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11341 NL80211_FLAG_NEED_RTNL
,
11344 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
11345 .doit
= nl80211_crit_protocol_stop
,
11346 .policy
= nl80211_policy
,
11347 .flags
= GENL_ADMIN_PERM
,
11348 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
11349 NL80211_FLAG_NEED_RTNL
,
11352 .cmd
= NL80211_CMD_GET_COALESCE
,
11353 .doit
= nl80211_get_coalesce
,
11354 .policy
= nl80211_policy
,
11355 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11356 NL80211_FLAG_NEED_RTNL
,
11359 .cmd
= NL80211_CMD_SET_COALESCE
,
11360 .doit
= nl80211_set_coalesce
,
11361 .policy
= nl80211_policy
,
11362 .flags
= GENL_ADMIN_PERM
,
11363 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11364 NL80211_FLAG_NEED_RTNL
,
11367 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
11368 .doit
= nl80211_channel_switch
,
11369 .policy
= nl80211_policy
,
11370 .flags
= GENL_ADMIN_PERM
,
11371 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11372 NL80211_FLAG_NEED_RTNL
,
11375 .cmd
= NL80211_CMD_VENDOR
,
11376 .doit
= nl80211_vendor_cmd
,
11377 .dumpit
= nl80211_vendor_cmd_dump
,
11378 .policy
= nl80211_policy
,
11379 .flags
= GENL_ADMIN_PERM
,
11380 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
11381 NL80211_FLAG_NEED_RTNL
,
11384 .cmd
= NL80211_CMD_SET_QOS_MAP
,
11385 .doit
= nl80211_set_qos_map
,
11386 .policy
= nl80211_policy
,
11387 .flags
= GENL_ADMIN_PERM
,
11388 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11389 NL80211_FLAG_NEED_RTNL
,
11392 .cmd
= NL80211_CMD_ADD_TX_TS
,
11393 .doit
= nl80211_add_tx_ts
,
11394 .policy
= nl80211_policy
,
11395 .flags
= GENL_ADMIN_PERM
,
11396 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11397 NL80211_FLAG_NEED_RTNL
,
11400 .cmd
= NL80211_CMD_DEL_TX_TS
,
11401 .doit
= nl80211_del_tx_ts
,
11402 .policy
= nl80211_policy
,
11403 .flags
= GENL_ADMIN_PERM
,
11404 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11405 NL80211_FLAG_NEED_RTNL
,
11408 .cmd
= NL80211_CMD_TDLS_CHANNEL_SWITCH
,
11409 .doit
= nl80211_tdls_channel_switch
,
11410 .policy
= nl80211_policy
,
11411 .flags
= GENL_ADMIN_PERM
,
11412 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11413 NL80211_FLAG_NEED_RTNL
,
11416 .cmd
= NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
,
11417 .doit
= nl80211_tdls_cancel_channel_switch
,
11418 .policy
= nl80211_policy
,
11419 .flags
= GENL_ADMIN_PERM
,
11420 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
11421 NL80211_FLAG_NEED_RTNL
,
11425 /* notification functions */
11427 void nl80211_notify_wiphy(struct cfg80211_registered_device
*rdev
,
11428 enum nl80211_commands cmd
)
11430 struct sk_buff
*msg
;
11431 struct nl80211_dump_wiphy_state state
= {};
11433 WARN_ON(cmd
!= NL80211_CMD_NEW_WIPHY
&&
11434 cmd
!= NL80211_CMD_DEL_WIPHY
);
11436 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11440 if (nl80211_send_wiphy(rdev
, cmd
, msg
, 0, 0, 0, &state
) < 0) {
11445 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11446 NL80211_MCGRP_CONFIG
, GFP_KERNEL
);
11449 static int nl80211_add_scan_req(struct sk_buff
*msg
,
11450 struct cfg80211_registered_device
*rdev
)
11452 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
11453 struct nlattr
*nest
;
11459 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
11461 goto nla_put_failure
;
11462 for (i
= 0; i
< req
->n_ssids
; i
++) {
11463 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
11464 goto nla_put_failure
;
11466 nla_nest_end(msg
, nest
);
11468 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
11470 goto nla_put_failure
;
11471 for (i
= 0; i
< req
->n_channels
; i
++) {
11472 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
11473 goto nla_put_failure
;
11475 nla_nest_end(msg
, nest
);
11478 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
11479 goto nla_put_failure
;
11482 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
))
11483 goto nla_put_failure
;
11490 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
11491 struct cfg80211_registered_device
*rdev
,
11492 struct wireless_dev
*wdev
,
11493 u32 portid
, u32 seq
, int flags
,
11498 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11502 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11503 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11504 wdev
->netdev
->ifindex
)) ||
11505 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11506 goto nla_put_failure
;
11508 /* ignore errors and send incomplete event anyway */
11509 nl80211_add_scan_req(msg
, rdev
);
11511 genlmsg_end(msg
, hdr
);
11515 genlmsg_cancel(msg
, hdr
);
11520 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
11521 struct cfg80211_registered_device
*rdev
,
11522 struct net_device
*netdev
,
11523 u32 portid
, u32 seq
, int flags
, u32 cmd
)
11527 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
11531 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11532 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
11533 goto nla_put_failure
;
11535 genlmsg_end(msg
, hdr
);
11539 genlmsg_cancel(msg
, hdr
);
11543 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
11544 struct wireless_dev
*wdev
)
11546 struct sk_buff
*msg
;
11548 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11552 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11553 NL80211_CMD_TRIGGER_SCAN
) < 0) {
11558 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11559 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11562 struct sk_buff
*nl80211_build_scan_msg(struct cfg80211_registered_device
*rdev
,
11563 struct wireless_dev
*wdev
, bool aborted
)
11565 struct sk_buff
*msg
;
11567 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11571 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
11572 aborted
? NL80211_CMD_SCAN_ABORTED
:
11573 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
11581 void nl80211_send_scan_result(struct cfg80211_registered_device
*rdev
,
11582 struct sk_buff
*msg
)
11587 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11588 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11591 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
11592 struct net_device
*netdev
)
11594 struct sk_buff
*msg
;
11596 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11600 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
11601 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
11606 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11607 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11610 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
11611 struct net_device
*netdev
, u32 cmd
)
11613 struct sk_buff
*msg
;
11615 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11619 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
11624 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11625 NL80211_MCGRP_SCAN
, GFP_KERNEL
);
11628 static bool nl80211_reg_change_event_fill(struct sk_buff
*msg
,
11629 struct regulatory_request
*request
)
11631 /* Userspace can always count this one always being set */
11632 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
11633 goto nla_put_failure
;
11635 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
11636 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11637 NL80211_REGDOM_TYPE_WORLD
))
11638 goto nla_put_failure
;
11639 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
11640 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11641 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
11642 goto nla_put_failure
;
11643 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
11644 request
->intersect
) {
11645 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11646 NL80211_REGDOM_TYPE_INTERSECTION
))
11647 goto nla_put_failure
;
11649 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
11650 NL80211_REGDOM_TYPE_COUNTRY
) ||
11651 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
11653 goto nla_put_failure
;
11656 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
) {
11657 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(request
->wiphy_idx
);
11660 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
11661 goto nla_put_failure
;
11664 wiphy
->regulatory_flags
& REGULATORY_WIPHY_SELF_MANAGED
&&
11665 nla_put_flag(msg
, NL80211_ATTR_WIPHY_SELF_MANAGED_REG
))
11666 goto nla_put_failure
;
11676 * This can happen on global regulatory changes or device specific settings
11677 * based on custom regulatory domains.
11679 void nl80211_common_reg_change_event(enum nl80211_commands cmd_id
,
11680 struct regulatory_request
*request
)
11682 struct sk_buff
*msg
;
11685 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11689 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd_id
);
11695 if (nl80211_reg_change_event_fill(msg
, request
) == false)
11696 goto nla_put_failure
;
11698 genlmsg_end(msg
, hdr
);
11701 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
11702 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
11708 genlmsg_cancel(msg
, hdr
);
11712 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
11713 struct net_device
*netdev
,
11714 const u8
*buf
, size_t len
,
11715 enum nl80211_commands cmd
, gfp_t gfp
,
11718 struct sk_buff
*msg
;
11721 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11725 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
11731 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11732 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11733 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
11734 goto nla_put_failure
;
11736 if (uapsd_queues
>= 0) {
11737 struct nlattr
*nla_wmm
=
11738 nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
11740 goto nla_put_failure
;
11742 if (nla_put_u8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
11744 goto nla_put_failure
;
11746 nla_nest_end(msg
, nla_wmm
);
11749 genlmsg_end(msg
, hdr
);
11751 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11752 NL80211_MCGRP_MLME
, gfp
);
11756 genlmsg_cancel(msg
, hdr
);
11760 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
11761 struct net_device
*netdev
, const u8
*buf
,
11762 size_t len
, gfp_t gfp
)
11764 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11765 NL80211_CMD_AUTHENTICATE
, gfp
, -1);
11768 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
11769 struct net_device
*netdev
, const u8
*buf
,
11770 size_t len
, gfp_t gfp
, int uapsd_queues
)
11772 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11773 NL80211_CMD_ASSOCIATE
, gfp
, uapsd_queues
);
11776 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
11777 struct net_device
*netdev
, const u8
*buf
,
11778 size_t len
, gfp_t gfp
)
11780 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11781 NL80211_CMD_DEAUTHENTICATE
, gfp
, -1);
11784 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
11785 struct net_device
*netdev
, const u8
*buf
,
11786 size_t len
, gfp_t gfp
)
11788 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
11789 NL80211_CMD_DISASSOCIATE
, gfp
, -1);
11792 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
11795 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11796 struct wiphy
*wiphy
= wdev
->wiphy
;
11797 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
11798 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
11801 if (WARN_ON(len
< 2))
11804 if (ieee80211_is_deauth(mgmt
->frame_control
))
11805 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
11807 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
11809 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
11810 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
, -1);
11812 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
11814 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
11815 struct net_device
*netdev
, int cmd
,
11816 const u8
*addr
, gfp_t gfp
)
11818 struct sk_buff
*msg
;
11821 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11825 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
11831 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11832 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11833 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
11834 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
11835 goto nla_put_failure
;
11837 genlmsg_end(msg
, hdr
);
11839 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11840 NL80211_MCGRP_MLME
, gfp
);
11844 genlmsg_cancel(msg
, hdr
);
11848 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
11849 struct net_device
*netdev
, const u8
*addr
,
11852 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
11856 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
11857 struct net_device
*netdev
, const u8
*addr
,
11860 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
11864 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
11865 struct net_device
*netdev
, const u8
*bssid
,
11866 const u8
*req_ie
, size_t req_ie_len
,
11867 const u8
*resp_ie
, size_t resp_ie_len
,
11868 u16 status
, gfp_t gfp
)
11870 struct sk_buff
*msg
;
11873 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11877 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
11883 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11884 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11885 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
11886 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
11888 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
11890 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
11891 goto nla_put_failure
;
11893 genlmsg_end(msg
, hdr
);
11895 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11896 NL80211_MCGRP_MLME
, gfp
);
11900 genlmsg_cancel(msg
, hdr
);
11905 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
11906 struct net_device
*netdev
, const u8
*bssid
,
11907 const u8
*req_ie
, size_t req_ie_len
,
11908 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
11910 struct sk_buff
*msg
;
11913 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11917 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
11923 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11924 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11925 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
11927 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
11929 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
11930 goto nla_put_failure
;
11932 genlmsg_end(msg
, hdr
);
11934 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11935 NL80211_MCGRP_MLME
, gfp
);
11939 genlmsg_cancel(msg
, hdr
);
11944 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
11945 struct net_device
*netdev
, u16 reason
,
11946 const u8
*ie
, size_t ie_len
, bool from_ap
)
11948 struct sk_buff
*msg
;
11951 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11955 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
11961 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11962 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
11963 (from_ap
&& reason
&&
11964 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
11966 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
11967 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
11968 goto nla_put_failure
;
11970 genlmsg_end(msg
, hdr
);
11972 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
11973 NL80211_MCGRP_MLME
, GFP_KERNEL
);
11977 genlmsg_cancel(msg
, hdr
);
11982 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
11983 struct net_device
*netdev
, const u8
*bssid
,
11986 struct sk_buff
*msg
;
11989 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11993 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
11999 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12000 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12001 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
12002 goto nla_put_failure
;
12004 genlmsg_end(msg
, hdr
);
12006 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12007 NL80211_MCGRP_MLME
, gfp
);
12011 genlmsg_cancel(msg
, hdr
);
12015 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
12016 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
12018 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12019 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12020 struct sk_buff
*msg
;
12023 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
12026 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
12028 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12032 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
12038 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12039 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12040 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
12042 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
12043 goto nla_put_failure
;
12045 genlmsg_end(msg
, hdr
);
12047 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12048 NL80211_MCGRP_MLME
, gfp
);
12052 genlmsg_cancel(msg
, hdr
);
12055 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
12057 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
12058 struct net_device
*netdev
, const u8
*addr
,
12059 enum nl80211_key_type key_type
, int key_id
,
12060 const u8
*tsc
, gfp_t gfp
)
12062 struct sk_buff
*msg
;
12065 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12069 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
12075 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12076 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12077 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
12078 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
12080 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
12081 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
12082 goto nla_put_failure
;
12084 genlmsg_end(msg
, hdr
);
12086 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12087 NL80211_MCGRP_MLME
, gfp
);
12091 genlmsg_cancel(msg
, hdr
);
12095 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
12096 struct ieee80211_channel
*channel_before
,
12097 struct ieee80211_channel
*channel_after
)
12099 struct sk_buff
*msg
;
12101 struct nlattr
*nl_freq
;
12103 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
12107 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
12114 * Since we are applying the beacon hint to a wiphy we know its
12115 * wiphy_idx is valid
12117 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
12118 goto nla_put_failure
;
12121 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
12123 goto nla_put_failure
;
12124 if (nl80211_msg_put_channel(msg
, channel_before
, false))
12125 goto nla_put_failure
;
12126 nla_nest_end(msg
, nl_freq
);
12129 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
12131 goto nla_put_failure
;
12132 if (nl80211_msg_put_channel(msg
, channel_after
, false))
12133 goto nla_put_failure
;
12134 nla_nest_end(msg
, nl_freq
);
12136 genlmsg_end(msg
, hdr
);
12139 genlmsg_multicast_allns(&nl80211_fam
, msg
, 0,
12140 NL80211_MCGRP_REGULATORY
, GFP_ATOMIC
);
12146 genlmsg_cancel(msg
, hdr
);
12150 static void nl80211_send_remain_on_chan_event(
12151 int cmd
, struct cfg80211_registered_device
*rdev
,
12152 struct wireless_dev
*wdev
, u64 cookie
,
12153 struct ieee80211_channel
*chan
,
12154 unsigned int duration
, gfp_t gfp
)
12156 struct sk_buff
*msg
;
12159 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12163 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12169 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12170 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12171 wdev
->netdev
->ifindex
)) ||
12172 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12173 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
12174 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
12175 NL80211_CHAN_NO_HT
) ||
12176 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
12177 goto nla_put_failure
;
12179 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
12180 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
12181 goto nla_put_failure
;
12183 genlmsg_end(msg
, hdr
);
12185 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12186 NL80211_MCGRP_MLME
, gfp
);
12190 genlmsg_cancel(msg
, hdr
);
12194 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
12195 struct ieee80211_channel
*chan
,
12196 unsigned int duration
, gfp_t gfp
)
12198 struct wiphy
*wiphy
= wdev
->wiphy
;
12199 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12201 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
12202 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
12203 rdev
, wdev
, cookie
, chan
,
12206 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
12208 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
12209 struct ieee80211_channel
*chan
,
12212 struct wiphy
*wiphy
= wdev
->wiphy
;
12213 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12215 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
12216 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
12217 rdev
, wdev
, cookie
, chan
, 0, gfp
);
12219 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
12221 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
12222 struct station_info
*sinfo
, gfp_t gfp
)
12224 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12225 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12226 struct sk_buff
*msg
;
12228 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
12230 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12234 if (nl80211_send_station(msg
, NL80211_CMD_NEW_STATION
, 0, 0, 0,
12235 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12240 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12241 NL80211_MCGRP_MLME
, gfp
);
12243 EXPORT_SYMBOL(cfg80211_new_sta
);
12245 void cfg80211_del_sta_sinfo(struct net_device
*dev
, const u8
*mac_addr
,
12246 struct station_info
*sinfo
, gfp_t gfp
)
12248 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12249 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12250 struct sk_buff
*msg
;
12251 struct station_info empty_sinfo
= {};
12254 sinfo
= &empty_sinfo
;
12256 trace_cfg80211_del_sta(dev
, mac_addr
);
12258 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12262 if (nl80211_send_station(msg
, NL80211_CMD_DEL_STATION
, 0, 0, 0,
12263 rdev
, dev
, mac_addr
, sinfo
) < 0) {
12268 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12269 NL80211_MCGRP_MLME
, gfp
);
12271 EXPORT_SYMBOL(cfg80211_del_sta_sinfo
);
12273 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
12274 enum nl80211_connect_failed_reason reason
,
12277 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
12278 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12279 struct sk_buff
*msg
;
12282 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
12286 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
12292 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12293 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
12294 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
12295 goto nla_put_failure
;
12297 genlmsg_end(msg
, hdr
);
12299 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12300 NL80211_MCGRP_MLME
, gfp
);
12304 genlmsg_cancel(msg
, hdr
);
12307 EXPORT_SYMBOL(cfg80211_conn_failed
);
12309 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
12310 const u8
*addr
, gfp_t gfp
)
12312 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12313 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12314 struct sk_buff
*msg
;
12316 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
12321 msg
= nlmsg_new(100, gfp
);
12325 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
12331 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12332 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12333 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
12334 goto nla_put_failure
;
12336 genlmsg_end(msg
, hdr
);
12337 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12341 genlmsg_cancel(msg
, hdr
);
12346 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
12347 const u8
*addr
, gfp_t gfp
)
12349 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12352 trace_cfg80211_rx_spurious_frame(dev
, addr
);
12354 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12355 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
12356 trace_cfg80211_return_bool(false);
12359 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
12361 trace_cfg80211_return_bool(ret
);
12364 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
12366 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
12367 const u8
*addr
, gfp_t gfp
)
12369 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12372 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
12374 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
12375 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
12376 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
12377 trace_cfg80211_return_bool(false);
12380 ret
= __nl80211_unexpected_frame(dev
,
12381 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
12383 trace_cfg80211_return_bool(ret
);
12386 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
12388 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
12389 struct wireless_dev
*wdev
, u32 nlportid
,
12390 int freq
, int sig_dbm
,
12391 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
12393 struct net_device
*netdev
= wdev
->netdev
;
12394 struct sk_buff
*msg
;
12397 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12401 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
12407 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12408 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12409 netdev
->ifindex
)) ||
12410 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12411 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
12413 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
12414 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12416 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
12417 goto nla_put_failure
;
12419 genlmsg_end(msg
, hdr
);
12421 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
12424 genlmsg_cancel(msg
, hdr
);
12429 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
12430 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
12432 struct wiphy
*wiphy
= wdev
->wiphy
;
12433 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12434 struct net_device
*netdev
= wdev
->netdev
;
12435 struct sk_buff
*msg
;
12438 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
12440 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12444 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
12450 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12451 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
12452 netdev
->ifindex
)) ||
12453 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
12454 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
12455 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
12456 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
12457 goto nla_put_failure
;
12459 genlmsg_end(msg
, hdr
);
12461 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12462 NL80211_MCGRP_MLME
, gfp
);
12466 genlmsg_cancel(msg
, hdr
);
12469 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
12471 static struct sk_buff
*cfg80211_prepare_cqm(struct net_device
*dev
,
12472 const char *mac
, gfp_t gfp
)
12474 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12475 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12476 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12482 cb
= (void **)msg
->cb
;
12484 cb
[0] = nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
12490 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12491 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
12492 goto nla_put_failure
;
12494 if (mac
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac
))
12495 goto nla_put_failure
;
12497 cb
[1] = nla_nest_start(msg
, NL80211_ATTR_CQM
);
12499 goto nla_put_failure
;
12509 static void cfg80211_send_cqm(struct sk_buff
*msg
, gfp_t gfp
)
12511 void **cb
= (void **)msg
->cb
;
12512 struct cfg80211_registered_device
*rdev
= cb
[2];
12514 nla_nest_end(msg
, cb
[1]);
12515 genlmsg_end(msg
, cb
[0]);
12517 memset(msg
->cb
, 0, sizeof(msg
->cb
));
12519 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12520 NL80211_MCGRP_MLME
, gfp
);
12523 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
12524 enum nl80211_cqm_rssi_threshold_event rssi_event
,
12527 struct sk_buff
*msg
;
12529 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
12531 if (WARN_ON(rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
&&
12532 rssi_event
!= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
))
12535 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
12539 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
12541 goto nla_put_failure
;
12543 cfg80211_send_cqm(msg
, gfp
);
12550 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
12552 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
12553 const u8
*peer
, u32 num_packets
,
12554 u32 rate
, u32 intvl
, gfp_t gfp
)
12556 struct sk_buff
*msg
;
12558 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
12562 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
12563 goto nla_put_failure
;
12565 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
12566 goto nla_put_failure
;
12568 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
12569 goto nla_put_failure
;
12571 cfg80211_send_cqm(msg
, gfp
);
12577 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
12579 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
12580 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
12582 struct sk_buff
*msg
;
12584 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
12586 msg
= cfg80211_prepare_cqm(dev
, peer
, gfp
);
12590 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
12591 goto nla_put_failure
;
12593 cfg80211_send_cqm(msg
, gfp
);
12599 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
12601 void cfg80211_cqm_beacon_loss_notify(struct net_device
*dev
, gfp_t gfp
)
12603 struct sk_buff
*msg
;
12605 msg
= cfg80211_prepare_cqm(dev
, NULL
, gfp
);
12609 if (nla_put_flag(msg
, NL80211_ATTR_CQM_BEACON_LOSS_EVENT
))
12610 goto nla_put_failure
;
12612 cfg80211_send_cqm(msg
, gfp
);
12618 EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify
);
12620 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
12621 struct net_device
*netdev
, const u8
*bssid
,
12622 const u8
*replay_ctr
, gfp_t gfp
)
12624 struct sk_buff
*msg
;
12625 struct nlattr
*rekey_attr
;
12628 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12632 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
12638 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12639 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12640 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
12641 goto nla_put_failure
;
12643 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
12645 goto nla_put_failure
;
12647 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
12648 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
12649 goto nla_put_failure
;
12651 nla_nest_end(msg
, rekey_attr
);
12653 genlmsg_end(msg
, hdr
);
12655 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12656 NL80211_MCGRP_MLME
, gfp
);
12660 genlmsg_cancel(msg
, hdr
);
12664 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
12665 const u8
*replay_ctr
, gfp_t gfp
)
12667 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12668 struct wiphy
*wiphy
= wdev
->wiphy
;
12669 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12671 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
12672 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
12674 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
12677 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
12678 struct net_device
*netdev
, int index
,
12679 const u8
*bssid
, bool preauth
, gfp_t gfp
)
12681 struct sk_buff
*msg
;
12682 struct nlattr
*attr
;
12685 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12689 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
12695 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12696 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
12697 goto nla_put_failure
;
12699 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
12701 goto nla_put_failure
;
12703 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
12704 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
12706 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
12707 goto nla_put_failure
;
12709 nla_nest_end(msg
, attr
);
12711 genlmsg_end(msg
, hdr
);
12713 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12714 NL80211_MCGRP_MLME
, gfp
);
12718 genlmsg_cancel(msg
, hdr
);
12722 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
12723 const u8
*bssid
, bool preauth
, gfp_t gfp
)
12725 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12726 struct wiphy
*wiphy
= wdev
->wiphy
;
12727 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12729 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
12730 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
12732 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
12734 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
12735 struct net_device
*netdev
,
12736 struct cfg80211_chan_def
*chandef
,
12738 enum nl80211_commands notif
,
12741 struct sk_buff
*msg
;
12744 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12748 hdr
= nl80211hdr_put(msg
, 0, 0, 0, notif
);
12754 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
12755 goto nla_put_failure
;
12757 if (nl80211_send_chandef(msg
, chandef
))
12758 goto nla_put_failure
;
12760 if ((notif
== NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
) &&
12761 (nla_put_u32(msg
, NL80211_ATTR_CH_SWITCH_COUNT
, count
)))
12762 goto nla_put_failure
;
12764 genlmsg_end(msg
, hdr
);
12766 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12767 NL80211_MCGRP_MLME
, gfp
);
12771 genlmsg_cancel(msg
, hdr
);
12775 void cfg80211_ch_switch_notify(struct net_device
*dev
,
12776 struct cfg80211_chan_def
*chandef
)
12778 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12779 struct wiphy
*wiphy
= wdev
->wiphy
;
12780 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12782 ASSERT_WDEV_LOCK(wdev
);
12784 trace_cfg80211_ch_switch_notify(dev
, chandef
);
12786 wdev
->chandef
= *chandef
;
12787 wdev
->preset_chandef
= *chandef
;
12788 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
12789 NL80211_CMD_CH_SWITCH_NOTIFY
, 0);
12791 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
12793 void cfg80211_ch_switch_started_notify(struct net_device
*dev
,
12794 struct cfg80211_chan_def
*chandef
,
12797 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12798 struct wiphy
*wiphy
= wdev
->wiphy
;
12799 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12801 trace_cfg80211_ch_switch_started_notify(dev
, chandef
);
12803 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
,
12804 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
, count
);
12806 EXPORT_SYMBOL(cfg80211_ch_switch_started_notify
);
12809 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
12810 const struct cfg80211_chan_def
*chandef
,
12811 enum nl80211_radar_event event
,
12812 struct net_device
*netdev
, gfp_t gfp
)
12814 struct sk_buff
*msg
;
12817 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12821 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
12827 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
12828 goto nla_put_failure
;
12830 /* NOP and radar events don't need a netdev parameter */
12832 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
12834 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
12835 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
12836 goto nla_put_failure
;
12839 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
12840 goto nla_put_failure
;
12842 if (nl80211_send_chandef(msg
, chandef
))
12843 goto nla_put_failure
;
12845 genlmsg_end(msg
, hdr
);
12847 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12848 NL80211_MCGRP_MLME
, gfp
);
12852 genlmsg_cancel(msg
, hdr
);
12856 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
12857 u64 cookie
, bool acked
, gfp_t gfp
)
12859 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
12860 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
12861 struct sk_buff
*msg
;
12864 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
12866 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
12871 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
12877 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12878 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
12879 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
12880 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
12881 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
12882 goto nla_put_failure
;
12884 genlmsg_end(msg
, hdr
);
12886 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
12887 NL80211_MCGRP_MLME
, gfp
);
12891 genlmsg_cancel(msg
, hdr
);
12894 EXPORT_SYMBOL(cfg80211_probe_status
);
12896 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
12897 const u8
*frame
, size_t len
,
12898 int freq
, int sig_dbm
)
12900 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
12901 struct sk_buff
*msg
;
12903 struct cfg80211_beacon_registration
*reg
;
12905 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
12907 spin_lock_bh(&rdev
->beacon_registrations_lock
);
12908 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
12909 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
12911 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12915 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
12917 goto nla_put_failure
;
12919 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
12921 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
12923 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
12924 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
12925 goto nla_put_failure
;
12927 genlmsg_end(msg
, hdr
);
12929 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
12931 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12935 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
12937 genlmsg_cancel(msg
, hdr
);
12940 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
12943 static int cfg80211_net_detect_results(struct sk_buff
*msg
,
12944 struct cfg80211_wowlan_wakeup
*wakeup
)
12946 struct cfg80211_wowlan_nd_info
*nd
= wakeup
->net_detect
;
12947 struct nlattr
*nl_results
, *nl_match
, *nl_freqs
;
12950 nl_results
= nla_nest_start(
12951 msg
, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS
);
12955 for (i
= 0; i
< nd
->n_matches
; i
++) {
12956 struct cfg80211_wowlan_nd_match
*match
= nd
->matches
[i
];
12958 nl_match
= nla_nest_start(msg
, i
);
12962 /* The SSID attribute is optional in nl80211, but for
12963 * simplicity reasons it's always present in the
12964 * cfg80211 structure. If a driver can't pass the
12965 * SSID, that needs to be changed. A zero length SSID
12966 * is still a valid SSID (wildcard), so it cannot be
12967 * used for this purpose.
12969 if (nla_put(msg
, NL80211_ATTR_SSID
, match
->ssid
.ssid_len
,
12970 match
->ssid
.ssid
)) {
12971 nla_nest_cancel(msg
, nl_match
);
12975 if (match
->n_channels
) {
12976 nl_freqs
= nla_nest_start(
12977 msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
12979 nla_nest_cancel(msg
, nl_match
);
12983 for (j
= 0; j
< match
->n_channels
; j
++) {
12984 if (nla_put_u32(msg
, j
, match
->channels
[j
])) {
12985 nla_nest_cancel(msg
, nl_freqs
);
12986 nla_nest_cancel(msg
, nl_match
);
12991 nla_nest_end(msg
, nl_freqs
);
12994 nla_nest_end(msg
, nl_match
);
12998 nla_nest_end(msg
, nl_results
);
13002 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
13003 struct cfg80211_wowlan_wakeup
*wakeup
,
13006 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13007 struct sk_buff
*msg
;
13011 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
13014 size
+= wakeup
->packet_present_len
;
13016 msg
= nlmsg_new(size
, gfp
);
13020 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
13024 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13025 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13028 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
13029 wdev
->netdev
->ifindex
))
13033 struct nlattr
*reasons
;
13035 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
13039 if (wakeup
->disconnect
&&
13040 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
13042 if (wakeup
->magic_pkt
&&
13043 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
13045 if (wakeup
->gtk_rekey_failure
&&
13046 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
13048 if (wakeup
->eap_identity_req
&&
13049 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
13051 if (wakeup
->four_way_handshake
&&
13052 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
13054 if (wakeup
->rfkill_release
&&
13055 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
13058 if (wakeup
->pattern_idx
>= 0 &&
13059 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
13060 wakeup
->pattern_idx
))
13063 if (wakeup
->tcp_match
&&
13064 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
))
13067 if (wakeup
->tcp_connlost
&&
13068 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
))
13071 if (wakeup
->tcp_nomoretokens
&&
13073 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
))
13076 if (wakeup
->packet
) {
13077 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
13078 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
13080 if (!wakeup
->packet_80211
) {
13082 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
13084 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
13087 if (wakeup
->packet_len
&&
13088 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
13091 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
13096 if (wakeup
->net_detect
&&
13097 cfg80211_net_detect_results(msg
, wakeup
))
13100 nla_nest_end(msg
, reasons
);
13103 genlmsg_end(msg
, hdr
);
13105 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13106 NL80211_MCGRP_MLME
, gfp
);
13112 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
13115 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
13116 enum nl80211_tdls_operation oper
,
13117 u16 reason_code
, gfp_t gfp
)
13119 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
13120 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wdev
->wiphy
);
13121 struct sk_buff
*msg
;
13124 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
13127 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13131 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
13137 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13138 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
13139 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
13140 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
13141 (reason_code
> 0 &&
13142 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
13143 goto nla_put_failure
;
13145 genlmsg_end(msg
, hdr
);
13147 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13148 NL80211_MCGRP_MLME
, gfp
);
13152 genlmsg_cancel(msg
, hdr
);
13155 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
13157 static int nl80211_netlink_notify(struct notifier_block
* nb
,
13158 unsigned long state
,
13161 struct netlink_notify
*notify
= _notify
;
13162 struct cfg80211_registered_device
*rdev
;
13163 struct wireless_dev
*wdev
;
13164 struct cfg80211_beacon_registration
*reg
, *tmp
;
13166 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
13167 return NOTIFY_DONE
;
13171 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
13172 bool schedule_destroy_work
= false;
13173 struct cfg80211_sched_scan_request
*sched_scan_req
=
13174 rcu_dereference(rdev
->sched_scan_req
);
13176 if (sched_scan_req
&& notify
->portid
&&
13177 sched_scan_req
->owner_nlportid
== notify
->portid
) {
13178 sched_scan_req
->owner_nlportid
= 0;
13180 if (rdev
->ops
->sched_scan_stop
&&
13181 rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
13182 schedule_work(&rdev
->sched_scan_stop_wk
);
13185 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
) {
13186 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
13188 if (wdev
->owner_nlportid
== notify
->portid
)
13189 schedule_destroy_work
= true;
13192 spin_lock_bh(&rdev
->beacon_registrations_lock
);
13193 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
13195 if (reg
->nlportid
== notify
->portid
) {
13196 list_del(®
->list
);
13201 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
13203 if (schedule_destroy_work
) {
13204 struct cfg80211_iface_destroy
*destroy
;
13206 destroy
= kzalloc(sizeof(*destroy
), GFP_ATOMIC
);
13208 destroy
->nlportid
= notify
->portid
;
13209 spin_lock(&rdev
->destroy_list_lock
);
13210 list_add(&destroy
->list
, &rdev
->destroy_list
);
13211 spin_unlock(&rdev
->destroy_list_lock
);
13212 schedule_work(&rdev
->destroy_work
);
13220 * It is possible that the user space process that is controlling the
13221 * indoor setting disappeared, so notify the regulatory core.
13223 regulatory_netlink_notify(notify
->portid
);
13227 static struct notifier_block nl80211_netlink_notifier
= {
13228 .notifier_call
= nl80211_netlink_notify
,
13231 void cfg80211_ft_event(struct net_device
*netdev
,
13232 struct cfg80211_ft_event_params
*ft_event
)
13234 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
13235 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13236 struct sk_buff
*msg
;
13239 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
13241 if (!ft_event
->target_ap
)
13244 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13248 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
13252 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13253 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
13254 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
))
13257 if (ft_event
->ies
&&
13258 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
))
13260 if (ft_event
->ric_ies
&&
13261 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
13262 ft_event
->ric_ies
))
13265 genlmsg_end(msg
, hdr
);
13267 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(&rdev
->wiphy
), msg
, 0,
13268 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13273 EXPORT_SYMBOL(cfg80211_ft_event
);
13275 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
13277 struct cfg80211_registered_device
*rdev
;
13278 struct sk_buff
*msg
;
13282 rdev
= wiphy_to_rdev(wdev
->wiphy
);
13283 if (!rdev
->crit_proto_nlportid
)
13286 nlportid
= rdev
->crit_proto_nlportid
;
13287 rdev
->crit_proto_nlportid
= 0;
13289 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
13293 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
13295 goto nla_put_failure
;
13297 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13298 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13299 goto nla_put_failure
;
13301 genlmsg_end(msg
, hdr
);
13303 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
13308 genlmsg_cancel(msg
, hdr
);
13312 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
13314 void nl80211_send_ap_stopped(struct wireless_dev
*wdev
)
13316 struct wiphy
*wiphy
= wdev
->wiphy
;
13317 struct cfg80211_registered_device
*rdev
= wiphy_to_rdev(wiphy
);
13318 struct sk_buff
*msg
;
13321 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
13325 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_STOP_AP
);
13329 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
13330 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
) ||
13331 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
13334 genlmsg_end(msg
, hdr
);
13336 genlmsg_multicast_netns(&nl80211_fam
, wiphy_net(wiphy
), msg
, 0,
13337 NL80211_MCGRP_MLME
, GFP_KERNEL
);
13343 /* initialisation/exit functions */
13345 int nl80211_init(void)
13349 err
= genl_register_family_with_ops_groups(&nl80211_fam
, nl80211_ops
,
13354 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
13360 genl_unregister_family(&nl80211_fam
);
13364 void nl80211_exit(void)
13366 netlink_unregister_notifier(&nl80211_netlink_notifier
);
13367 genl_unregister_family(&nl80211_fam
);