2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
22 #include <net/inet_connection_sock.h>
28 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
29 struct genl_info
*info
,
30 struct cfg80211_crypto_settings
*settings
,
33 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
34 struct genl_info
*info
);
35 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
38 /* the netlink family */
39 static struct genl_family nl80211_fam
= {
40 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
41 .name
= "nl80211", /* have users key off the name instead */
42 .hdrsize
= 0, /* no private header */
43 .version
= 1, /* no particular meaning now */
44 .maxattr
= NL80211_ATTR_MAX
,
46 .pre_doit
= nl80211_pre_doit
,
47 .post_doit
= nl80211_post_doit
,
50 /* returns ERR_PTR values */
51 static struct wireless_dev
*
52 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
54 struct cfg80211_registered_device
*rdev
;
55 struct wireless_dev
*result
= NULL
;
56 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
57 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
62 assert_cfg80211_lock();
64 if (!have_ifidx
&& !have_wdev_id
)
65 return ERR_PTR(-EINVAL
);
68 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
70 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
71 wiphy_idx
= wdev_id
>> 32;
74 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
75 struct wireless_dev
*wdev
;
77 if (wiphy_net(&rdev
->wiphy
) != netns
)
80 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
83 mutex_lock(&rdev
->devlist_mtx
);
84 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
85 if (have_ifidx
&& wdev
->netdev
&&
86 wdev
->netdev
->ifindex
== ifidx
) {
90 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
95 mutex_unlock(&rdev
->devlist_mtx
);
103 return ERR_PTR(-ENODEV
);
106 static struct cfg80211_registered_device
*
107 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
109 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
110 struct net_device
*netdev
;
112 assert_cfg80211_lock();
114 if (!attrs
[NL80211_ATTR_WIPHY
] &&
115 !attrs
[NL80211_ATTR_IFINDEX
] &&
116 !attrs
[NL80211_ATTR_WDEV
])
117 return ERR_PTR(-EINVAL
);
119 if (attrs
[NL80211_ATTR_WIPHY
])
120 rdev
= cfg80211_rdev_by_wiphy_idx(
121 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
123 if (attrs
[NL80211_ATTR_WDEV
]) {
124 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
125 struct wireless_dev
*wdev
;
128 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
130 /* make sure wdev exists */
131 mutex_lock(&tmp
->devlist_mtx
);
132 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
133 if (wdev
->identifier
!= (u32
)wdev_id
)
138 mutex_unlock(&tmp
->devlist_mtx
);
143 if (rdev
&& tmp
!= rdev
)
144 return ERR_PTR(-EINVAL
);
149 if (attrs
[NL80211_ATTR_IFINDEX
]) {
150 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
151 netdev
= dev_get_by_index(netns
, ifindex
);
153 if (netdev
->ieee80211_ptr
)
155 netdev
->ieee80211_ptr
->wiphy
);
161 /* not wireless device -- return error */
163 return ERR_PTR(-EINVAL
);
165 /* mismatch -- return error */
166 if (rdev
&& tmp
!= rdev
)
167 return ERR_PTR(-EINVAL
);
174 return ERR_PTR(-ENODEV
);
176 if (netns
!= wiphy_net(&rdev
->wiphy
))
177 return ERR_PTR(-ENODEV
);
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
202 static struct cfg80211_registered_device
*
203 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
205 struct cfg80211_registered_device
*rdev
;
207 mutex_lock(&cfg80211_mutex
);
208 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
214 mutex_lock(&rdev
->mtx
);
216 mutex_unlock(&cfg80211_mutex
);
221 /* policy for the attributes */
222 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
223 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
226 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
228 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
235 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
240 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
241 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
242 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
244 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
245 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
247 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
248 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
249 .len
= WLAN_MAX_KEY_LEN
},
250 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
251 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
253 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
254 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
256 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
258 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
259 .len
= IEEE80211_MAX_DATA_LEN
},
260 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
261 .len
= IEEE80211_MAX_DATA_LEN
},
262 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
263 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
264 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
265 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
266 .len
= NL80211_MAX_SUPP_RATES
},
267 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
268 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
269 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
270 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
271 .len
= IEEE80211_MAX_MESH_ID_LEN
},
272 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
274 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
275 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
277 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
280 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
281 .len
= NL80211_MAX_SUPP_RATES
},
282 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
284 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
285 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
287 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
289 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
290 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
291 .len
= IEEE80211_MAX_DATA_LEN
},
292 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
293 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
295 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
296 .len
= IEEE80211_MAX_SSID_LEN
},
297 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
298 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
299 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
302 [NL80211_ATTR_STA_FLAGS2
] = {
303 .len
= sizeof(struct nl80211_sta_flag_update
),
305 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
308 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
309 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
312 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
313 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
314 .len
= WLAN_PMKID_LEN
},
315 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
317 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
318 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
319 .len
= IEEE80211_MAX_DATA_LEN
},
320 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
321 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
323 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
324 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
327 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
328 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
331 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
332 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
333 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
334 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
335 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
336 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
337 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
338 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
339 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
340 .len
= IEEE80211_MAX_DATA_LEN
},
341 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
342 .len
= IEEE80211_MAX_DATA_LEN
},
343 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
345 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
351 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
352 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
353 .len
= IEEE80211_MAX_DATA_LEN
},
354 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
355 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
356 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
357 .len
= NL80211_HT_CAPABILITY_LEN
359 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
360 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
361 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
362 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
363 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
364 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
365 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
366 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
367 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
368 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
369 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
370 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
371 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
372 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
373 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
374 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
375 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
376 .len
= NL80211_VHT_CAPABILITY_LEN
,
378 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
379 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
380 .len
= IEEE80211_MAX_DATA_LEN
},
383 /* policy for the key attributes */
384 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
385 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
386 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
387 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
388 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
389 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
390 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
391 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
392 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
395 /* policy for the key default flags */
396 static const struct nla_policy
397 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
398 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
399 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
402 /* policy for WoWLAN attributes */
403 static const struct nla_policy
404 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
405 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
406 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
407 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
408 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
409 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
410 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
411 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
412 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
413 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
416 static const struct nla_policy
417 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
418 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
419 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
420 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
421 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
422 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
423 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
424 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
425 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
427 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
428 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
430 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
431 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
432 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
435 /* policy for GTK rekey offload attributes */
436 static const struct nla_policy
437 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
438 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
439 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
440 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
443 static const struct nla_policy
444 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
445 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
446 .len
= IEEE80211_MAX_SSID_LEN
},
447 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
450 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
451 struct netlink_callback
*cb
,
452 struct cfg80211_registered_device
**rdev
,
453 struct wireless_dev
**wdev
)
458 mutex_lock(&cfg80211_mutex
);
461 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
462 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
467 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
468 nl80211_fam
.attrbuf
);
470 err
= PTR_ERR(*wdev
);
473 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
474 cb
->args
[0] = (*rdev
)->wiphy_idx
;
475 cb
->args
[1] = (*wdev
)->identifier
;
477 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0]);
478 struct wireless_dev
*tmp
;
484 *rdev
= wiphy_to_dev(wiphy
);
487 mutex_lock(&(*rdev
)->devlist_mtx
);
488 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
489 if (tmp
->identifier
== cb
->args
[1]) {
494 mutex_unlock(&(*rdev
)->devlist_mtx
);
502 cfg80211_lock_rdev(*rdev
);
504 mutex_unlock(&cfg80211_mutex
);
507 mutex_unlock(&cfg80211_mutex
);
512 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
514 cfg80211_unlock_rdev(rdev
);
519 static bool is_valid_ie_attr(const struct nlattr
*attr
)
527 pos
= nla_data(attr
);
548 /* message building helper */
549 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
552 /* since there is no private header just add the generic one */
553 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
556 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
557 struct ieee80211_channel
*chan
,
560 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
562 goto nla_put_failure
;
564 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
565 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
566 goto nla_put_failure
;
567 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
568 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
569 goto nla_put_failure
;
570 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
571 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
572 goto nla_put_failure
;
573 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
574 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
575 goto nla_put_failure
;
579 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
581 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
583 goto nla_put_failure
;
584 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
586 goto nla_put_failure
;
591 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
592 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
593 goto nla_put_failure
;
594 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
595 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
596 goto nla_put_failure
;
597 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
598 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
599 goto nla_put_failure
;
600 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
601 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
602 goto nla_put_failure
;
605 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
606 DBM_TO_MBM(chan
->max_power
)))
607 goto nla_put_failure
;
615 /* netlink command implementations */
622 bool def_uni
, def_multi
;
625 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
627 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
628 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
633 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
634 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
643 if (tb
[NL80211_KEY_IDX
])
644 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
646 if (tb
[NL80211_KEY_DATA
]) {
647 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
648 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
651 if (tb
[NL80211_KEY_SEQ
]) {
652 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
653 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
656 if (tb
[NL80211_KEY_CIPHER
])
657 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
659 if (tb
[NL80211_KEY_TYPE
]) {
660 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
661 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
665 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
666 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
667 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
668 tb
[NL80211_KEY_DEFAULT_TYPES
],
669 nl80211_key_default_policy
);
673 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
674 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
680 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
682 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
683 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
684 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
687 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
688 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
689 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
692 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
693 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
695 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
696 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
698 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
699 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
708 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
709 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
710 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
714 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
715 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
716 int err
= nla_parse_nested(
717 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
718 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
719 nl80211_key_default_policy
);
723 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
724 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
730 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
734 memset(k
, 0, sizeof(*k
));
738 if (info
->attrs
[NL80211_ATTR_KEY
])
739 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
741 err
= nl80211_parse_key_old(info
, k
);
746 if (k
->def
&& k
->defmgmt
)
750 if (k
->def_uni
|| !k
->def_multi
)
756 if (k
->idx
< 4 || k
->idx
> 5)
759 if (k
->idx
< 0 || k
->idx
> 3)
762 if (k
->idx
< 0 || k
->idx
> 5)
770 static struct cfg80211_cached_keys
*
771 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
772 struct nlattr
*keys
, bool *no_ht
)
774 struct key_parse parse
;
776 struct cfg80211_cached_keys
*result
;
777 int rem
, err
, def
= 0;
779 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
781 return ERR_PTR(-ENOMEM
);
784 result
->defmgmt
= -1;
786 nla_for_each_nested(key
, keys
, rem
) {
787 memset(&parse
, 0, sizeof(parse
));
790 err
= nl80211_parse_key_new(key
, &parse
);
796 if (parse
.idx
< 0 || parse
.idx
> 4)
802 result
->def
= parse
.idx
;
803 if (!parse
.def_uni
|| !parse
.def_multi
)
805 } else if (parse
.defmgmt
)
807 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
808 parse
.idx
, false, NULL
);
811 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
812 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
813 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
814 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
816 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
817 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
829 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
831 ASSERT_WDEV_LOCK(wdev
);
833 switch (wdev
->iftype
) {
834 case NL80211_IFTYPE_AP
:
835 case NL80211_IFTYPE_AP_VLAN
:
836 case NL80211_IFTYPE_P2P_GO
:
837 case NL80211_IFTYPE_MESH_POINT
:
839 case NL80211_IFTYPE_ADHOC
:
840 if (!wdev
->current_bss
)
843 case NL80211_IFTYPE_STATION
:
844 case NL80211_IFTYPE_P2P_CLIENT
:
845 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
855 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
857 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
861 goto nla_put_failure
;
865 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
866 goto nla_put_failure
;
871 nla_nest_end(msg
, nl_modes
);
878 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
882 struct nlattr
*nl_combis
;
885 nl_combis
= nla_nest_start(msg
,
886 NL80211_ATTR_INTERFACE_COMBINATIONS
);
888 goto nla_put_failure
;
890 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
891 const struct ieee80211_iface_combination
*c
;
892 struct nlattr
*nl_combi
, *nl_limits
;
894 c
= &wiphy
->iface_combinations
[i
];
896 nl_combi
= nla_nest_start(msg
, i
+ 1);
898 goto nla_put_failure
;
900 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
902 goto nla_put_failure
;
904 for (j
= 0; j
< c
->n_limits
; j
++) {
905 struct nlattr
*nl_limit
;
907 nl_limit
= nla_nest_start(msg
, j
+ 1);
909 goto nla_put_failure
;
910 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
912 goto nla_put_failure
;
913 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
915 goto nla_put_failure
;
916 nla_nest_end(msg
, nl_limit
);
919 nla_nest_end(msg
, nl_limits
);
921 if (c
->beacon_int_infra_match
&&
922 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
923 goto nla_put_failure
;
924 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
925 c
->num_different_channels
) ||
926 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
928 goto nla_put_failure
;
930 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
931 c
->radar_detect_widths
))
932 goto nla_put_failure
;
934 nla_nest_end(msg
, nl_combi
);
937 nla_nest_end(msg
, nl_combis
);
945 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
948 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
.tcp
;
949 struct nlattr
*nl_tcp
;
954 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
958 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
959 tcp
->data_payload_max
))
962 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
963 tcp
->data_payload_max
))
966 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
969 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
970 sizeof(*tcp
->tok
), tcp
->tok
))
973 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
974 tcp
->data_interval_max
))
977 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
978 tcp
->wake_payload_max
))
981 nla_nest_end(msg
, nl_tcp
);
985 static int nl80211_send_wowlan(struct sk_buff
*msg
,
986 struct cfg80211_registered_device
*dev
,
989 struct nlattr
*nl_wowlan
;
991 if (!dev
->wiphy
.wowlan
.flags
&& !dev
->wiphy
.wowlan
.n_patterns
)
994 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
998 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
999 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1000 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1001 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1002 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1003 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1004 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1005 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1006 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1007 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1008 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1009 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1010 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1011 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1012 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1013 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1016 if (dev
->wiphy
.wowlan
.n_patterns
) {
1017 struct nl80211_wowlan_pattern_support pat
= {
1018 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1019 .min_pattern_len
= dev
->wiphy
.wowlan
.pattern_min_len
,
1020 .max_pattern_len
= dev
->wiphy
.wowlan
.pattern_max_len
,
1021 .max_pkt_offset
= dev
->wiphy
.wowlan
.max_pkt_offset
,
1024 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1029 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
1032 nla_nest_end(msg
, nl_wowlan
);
1038 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1039 struct ieee80211_supported_band
*sband
)
1041 struct nlattr
*nl_rates
, *nl_rate
;
1042 struct ieee80211_rate
*rate
;
1046 if (sband
->ht_cap
.ht_supported
&&
1047 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1048 sizeof(sband
->ht_cap
.mcs
),
1049 &sband
->ht_cap
.mcs
) ||
1050 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1051 sband
->ht_cap
.cap
) ||
1052 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1053 sband
->ht_cap
.ampdu_factor
) ||
1054 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1055 sband
->ht_cap
.ampdu_density
)))
1059 if (sband
->vht_cap
.vht_supported
&&
1060 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1061 sizeof(sband
->vht_cap
.vht_mcs
),
1062 &sband
->vht_cap
.vht_mcs
) ||
1063 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1064 sband
->vht_cap
.cap
)))
1068 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1072 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1073 nl_rate
= nla_nest_start(msg
, i
);
1077 rate
= &sband
->bitrates
[i
];
1078 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1081 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1083 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1086 nla_nest_end(msg
, nl_rate
);
1089 nla_nest_end(msg
, nl_rates
);
1095 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1096 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1099 struct nlattr
*nl_ftypes
, *nl_ifs
;
1100 enum nl80211_iftype ift
;
1106 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1110 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1111 nl_ftypes
= nla_nest_start(msg
, ift
);
1115 stypes
= mgmt_stypes
[ift
].tx
;
1118 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1119 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1124 nla_nest_end(msg
, nl_ftypes
);
1127 nla_nest_end(msg
, nl_ifs
);
1129 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1133 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1134 nl_ftypes
= nla_nest_start(msg
, ift
);
1138 stypes
= mgmt_stypes
[ift
].rx
;
1141 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1142 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1147 nla_nest_end(msg
, nl_ftypes
);
1149 nla_nest_end(msg
, nl_ifs
);
1154 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1155 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1156 int flags
, bool split
, long *split_start
,
1157 long *band_start
, long *chan_start
)
1160 struct nlattr
*nl_bands
, *nl_band
;
1161 struct nlattr
*nl_freqs
, *nl_freq
;
1162 struct nlattr
*nl_cmds
;
1163 enum ieee80211_band band
;
1164 struct ieee80211_channel
*chan
;
1166 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1167 dev
->wiphy
.mgmt_stypes
;
1168 long start
= 0, start_chan
= 0, start_band
= 0;
1171 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1175 /* allow always using the variables */
1177 split_start
= &start
;
1178 band_start
= &start_band
;
1179 chan_start
= &start_chan
;
1182 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1183 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1184 wiphy_name(&dev
->wiphy
)) ||
1185 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1186 cfg80211_rdev_list_generation
))
1187 goto nla_put_failure
;
1189 switch (*split_start
) {
1191 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1192 dev
->wiphy
.retry_short
) ||
1193 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1194 dev
->wiphy
.retry_long
) ||
1195 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1196 dev
->wiphy
.frag_threshold
) ||
1197 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1198 dev
->wiphy
.rts_threshold
) ||
1199 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1200 dev
->wiphy
.coverage_class
) ||
1201 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1202 dev
->wiphy
.max_scan_ssids
) ||
1203 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1204 dev
->wiphy
.max_sched_scan_ssids
) ||
1205 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1206 dev
->wiphy
.max_scan_ie_len
) ||
1207 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1208 dev
->wiphy
.max_sched_scan_ie_len
) ||
1209 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1210 dev
->wiphy
.max_match_sets
))
1211 goto nla_put_failure
;
1213 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1214 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1215 goto nla_put_failure
;
1216 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1217 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1218 goto nla_put_failure
;
1219 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1220 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1221 goto nla_put_failure
;
1222 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1223 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1224 goto nla_put_failure
;
1225 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1226 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1227 goto nla_put_failure
;
1228 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1229 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1230 goto nla_put_failure
;
1236 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1237 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1238 dev
->wiphy
.cipher_suites
))
1239 goto nla_put_failure
;
1241 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1242 dev
->wiphy
.max_num_pmkids
))
1243 goto nla_put_failure
;
1245 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1246 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1247 goto nla_put_failure
;
1249 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1250 dev
->wiphy
.available_antennas_tx
) ||
1251 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1252 dev
->wiphy
.available_antennas_rx
))
1253 goto nla_put_failure
;
1255 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1256 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1257 dev
->wiphy
.probe_resp_offload
))
1258 goto nla_put_failure
;
1260 if ((dev
->wiphy
.available_antennas_tx
||
1261 dev
->wiphy
.available_antennas_rx
) &&
1262 dev
->ops
->get_antenna
) {
1263 u32 tx_ant
= 0, rx_ant
= 0;
1265 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1267 if (nla_put_u32(msg
,
1268 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1271 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1273 goto nla_put_failure
;
1281 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1282 dev
->wiphy
.interface_modes
))
1283 goto nla_put_failure
;
1288 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1290 goto nla_put_failure
;
1292 for (band
= *band_start
; band
< IEEE80211_NUM_BANDS
; band
++) {
1293 struct ieee80211_supported_band
*sband
;
1295 sband
= dev
->wiphy
.bands
[band
];
1300 nl_band
= nla_nest_start(msg
, band
);
1302 goto nla_put_failure
;
1304 switch (*chan_start
) {
1306 if (nl80211_send_band_rateinfo(msg
, sband
))
1307 goto nla_put_failure
;
1312 /* add frequencies */
1313 nl_freqs
= nla_nest_start(
1314 msg
, NL80211_BAND_ATTR_FREQS
);
1316 goto nla_put_failure
;
1318 for (i
= *chan_start
- 1;
1319 i
< sband
->n_channels
;
1321 nl_freq
= nla_nest_start(msg
, i
);
1323 goto nla_put_failure
;
1325 chan
= &sband
->channels
[i
];
1327 if (nl80211_msg_put_channel(msg
, chan
,
1329 goto nla_put_failure
;
1331 nla_nest_end(msg
, nl_freq
);
1335 if (i
< sband
->n_channels
)
1336 *chan_start
= i
+ 2;
1339 nla_nest_end(msg
, nl_freqs
);
1342 nla_nest_end(msg
, nl_band
);
1345 /* start again here */
1351 nla_nest_end(msg
, nl_bands
);
1353 if (band
< IEEE80211_NUM_BANDS
)
1354 *band_start
= band
+ 1;
1358 /* if bands & channels are done, continue outside */
1359 if (*band_start
== 0 && *chan_start
== 0)
1364 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1366 goto nla_put_failure
;
1369 #define CMD(op, n) \
1371 if (dev->ops->op) { \
1373 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1374 goto nla_put_failure; \
1378 CMD(add_virtual_intf
, NEW_INTERFACE
);
1379 CMD(change_virtual_intf
, SET_INTERFACE
);
1380 CMD(add_key
, NEW_KEY
);
1381 CMD(start_ap
, START_AP
);
1382 CMD(add_station
, NEW_STATION
);
1383 CMD(add_mpath
, NEW_MPATH
);
1384 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1385 CMD(change_bss
, SET_BSS
);
1386 CMD(auth
, AUTHENTICATE
);
1387 CMD(assoc
, ASSOCIATE
);
1388 CMD(deauth
, DEAUTHENTICATE
);
1389 CMD(disassoc
, DISASSOCIATE
);
1390 CMD(join_ibss
, JOIN_IBSS
);
1391 CMD(join_mesh
, JOIN_MESH
);
1392 CMD(set_pmksa
, SET_PMKSA
);
1393 CMD(del_pmksa
, DEL_PMKSA
);
1394 CMD(flush_pmksa
, FLUSH_PMKSA
);
1395 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1396 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1397 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1398 CMD(mgmt_tx
, FRAME
);
1399 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1400 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1402 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1403 goto nla_put_failure
;
1405 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1406 dev
->ops
->join_mesh
) {
1408 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1409 goto nla_put_failure
;
1411 CMD(set_wds_peer
, SET_WDS_PEER
);
1412 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1413 CMD(tdls_mgmt
, TDLS_MGMT
);
1414 CMD(tdls_oper
, TDLS_OPER
);
1416 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1417 CMD(sched_scan_start
, START_SCHED_SCAN
);
1418 CMD(probe_client
, PROBE_CLIENT
);
1419 CMD(set_noack_map
, SET_NOACK_MAP
);
1420 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1422 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1423 goto nla_put_failure
;
1425 CMD(start_p2p_device
, START_P2P_DEVICE
);
1426 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1428 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1429 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1432 #ifdef CONFIG_NL80211_TESTMODE
1433 CMD(testmode_cmd
, TESTMODE
);
1438 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1440 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1441 goto nla_put_failure
;
1444 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1446 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1447 goto nla_put_failure
;
1450 nla_nest_end(msg
, nl_cmds
);
1455 if (dev
->ops
->remain_on_channel
&&
1456 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1458 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1459 dev
->wiphy
.max_remain_on_channel_duration
))
1460 goto nla_put_failure
;
1462 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1463 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1464 goto nla_put_failure
;
1466 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1467 goto nla_put_failure
;
1473 if (nl80211_send_wowlan(msg
, dev
, split
))
1474 goto nla_put_failure
;
1482 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1483 dev
->wiphy
.software_iftypes
))
1484 goto nla_put_failure
;
1486 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
, split
))
1487 goto nla_put_failure
;
1493 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1494 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1495 dev
->wiphy
.ap_sme_capa
))
1496 goto nla_put_failure
;
1498 features
= dev
->wiphy
.features
;
1500 * We can only add the per-channel limit information if the
1501 * dump is split, otherwise it makes it too big. Therefore
1502 * only advertise it in that case.
1505 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1506 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1507 goto nla_put_failure
;
1509 if (dev
->wiphy
.ht_capa_mod_mask
&&
1510 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1511 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1512 dev
->wiphy
.ht_capa_mod_mask
))
1513 goto nla_put_failure
;
1515 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1516 dev
->wiphy
.max_acl_mac_addrs
&&
1517 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1518 dev
->wiphy
.max_acl_mac_addrs
))
1519 goto nla_put_failure
;
1522 * Any information below this point is only available to
1523 * applications that can deal with it being split. This
1524 * helps ensure that newly added capabilities don't break
1525 * older tools by overrunning their buffers.
1527 * We still increment split_start so that in the split
1528 * case we'll continue with more data in the next round,
1529 * but break unconditionally so unsplit data stops here.
1534 if (dev
->wiphy
.extended_capabilities
&&
1535 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1536 dev
->wiphy
.extended_capabilities_len
,
1537 dev
->wiphy
.extended_capabilities
) ||
1538 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1539 dev
->wiphy
.extended_capabilities_len
,
1540 dev
->wiphy
.extended_capabilities_mask
)))
1541 goto nla_put_failure
;
1543 if (dev
->wiphy
.vht_capa_mod_mask
&&
1544 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1545 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1546 dev
->wiphy
.vht_capa_mod_mask
))
1547 goto nla_put_failure
;
1553 return genlmsg_end(msg
, hdr
);
1556 genlmsg_cancel(msg
, hdr
);
1560 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1563 int start
= cb
->args
[0];
1564 struct cfg80211_registered_device
*dev
;
1565 s64 filter_wiphy
= -1;
1567 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1570 mutex_lock(&cfg80211_mutex
);
1571 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1572 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1574 split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1575 if (tb
[NL80211_ATTR_WIPHY
])
1576 filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1577 if (tb
[NL80211_ATTR_WDEV
])
1578 filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1579 if (tb
[NL80211_ATTR_IFINDEX
]) {
1580 struct net_device
*netdev
;
1581 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1583 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1585 mutex_unlock(&cfg80211_mutex
);
1588 if (netdev
->ieee80211_ptr
) {
1590 netdev
->ieee80211_ptr
->wiphy
);
1591 filter_wiphy
= dev
->wiphy_idx
;
1597 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1598 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1602 if (filter_wiphy
!= -1 && dev
->wiphy_idx
!= filter_wiphy
)
1604 /* attempt to fit multiple wiphy data chunks into the skb */
1606 ret
= nl80211_send_wiphy(dev
, skb
,
1607 NETLINK_CB(cb
->skb
).portid
,
1610 split
, &cb
->args
[1],
1615 * If sending the wiphy data didn't fit (ENOBUFS
1616 * or EMSGSIZE returned), this SKB is still
1617 * empty (so it's not too big because another
1618 * wiphy dataset is already in the skb) and
1619 * we've not tried to adjust the dump allocation
1620 * yet ... then adjust the alloc size to be
1621 * bigger, and return 1 but with the empty skb.
1622 * This results in an empty message being RX'ed
1623 * in userspace, but that is ignored.
1625 * We can then retry with the larger buffer.
1627 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1629 cb
->min_dump_alloc
< 4096) {
1630 cb
->min_dump_alloc
= 4096;
1631 mutex_unlock(&cfg80211_mutex
);
1637 } while (cb
->args
[1] > 0);
1640 mutex_unlock(&cfg80211_mutex
);
1647 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1649 struct sk_buff
*msg
;
1650 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1652 msg
= nlmsg_new(4096, GFP_KERNEL
);
1656 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1657 false, NULL
, NULL
, NULL
) < 0) {
1662 return genlmsg_reply(msg
, info
);
1665 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1666 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1667 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1668 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1669 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1670 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1673 static int parse_txq_params(struct nlattr
*tb
[],
1674 struct ieee80211_txq_params
*txq_params
)
1676 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1677 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1678 !tb
[NL80211_TXQ_ATTR_AIFS
])
1681 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1682 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1683 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1684 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1685 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1687 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1693 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1696 * You can only set the channel explicitly for WDS interfaces,
1697 * all others have their channel managed via their respective
1698 * "establish a connection" command (connect, join, ...)
1700 * For AP/GO and mesh mode, the channel can be set with the
1701 * channel userspace API, but is only stored and passed to the
1702 * low-level driver when the AP starts or the mesh is joined.
1703 * This is for backward compatibility, userspace can also give
1704 * the channel in the start-ap or join-mesh commands instead.
1706 * Monitors are special as they are normally slaved to
1707 * whatever else is going on, so they have their own special
1708 * operation to set the monitor channel if possible.
1711 wdev
->iftype
== NL80211_IFTYPE_AP
||
1712 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1713 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1714 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1717 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1718 struct genl_info
*info
,
1719 struct cfg80211_chan_def
*chandef
)
1723 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1726 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1728 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1729 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1730 chandef
->center_freq1
= control_freq
;
1731 chandef
->center_freq2
= 0;
1733 /* Primary channel not allowed */
1734 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1737 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1738 enum nl80211_channel_type chantype
;
1740 chantype
= nla_get_u32(
1741 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1744 case NL80211_CHAN_NO_HT
:
1745 case NL80211_CHAN_HT20
:
1746 case NL80211_CHAN_HT40PLUS
:
1747 case NL80211_CHAN_HT40MINUS
:
1748 cfg80211_chandef_create(chandef
, chandef
->chan
,
1754 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1756 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1757 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1758 chandef
->center_freq1
=
1760 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1761 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1762 chandef
->center_freq2
=
1764 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1767 if (!cfg80211_chandef_valid(chandef
))
1770 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1771 IEEE80211_CHAN_DISABLED
))
1777 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1778 struct wireless_dev
*wdev
,
1779 struct genl_info
*info
)
1781 struct cfg80211_chan_def chandef
;
1783 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1786 iftype
= wdev
->iftype
;
1788 if (!nl80211_can_set_dev_channel(wdev
))
1791 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1795 mutex_lock(&rdev
->devlist_mtx
);
1797 case NL80211_IFTYPE_AP
:
1798 case NL80211_IFTYPE_P2P_GO
:
1799 if (wdev
->beacon_interval
) {
1803 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1807 wdev
->preset_chandef
= chandef
;
1810 case NL80211_IFTYPE_MESH_POINT
:
1811 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1813 case NL80211_IFTYPE_MONITOR
:
1814 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1819 mutex_unlock(&rdev
->devlist_mtx
);
1824 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1826 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1827 struct net_device
*netdev
= info
->user_ptr
[1];
1829 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1832 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1834 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1835 struct net_device
*dev
= info
->user_ptr
[1];
1836 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1839 if (!info
->attrs
[NL80211_ATTR_MAC
])
1842 if (netif_running(dev
))
1845 if (!rdev
->ops
->set_wds_peer
)
1848 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1851 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1852 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1856 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1858 struct cfg80211_registered_device
*rdev
;
1859 struct net_device
*netdev
= NULL
;
1860 struct wireless_dev
*wdev
;
1861 int result
= 0, rem_txq_params
= 0;
1862 struct nlattr
*nl_txq_params
;
1864 u8 retry_short
= 0, retry_long
= 0;
1865 u32 frag_threshold
= 0, rts_threshold
= 0;
1866 u8 coverage_class
= 0;
1869 * Try to find the wiphy and netdev. Normally this
1870 * function shouldn't need the netdev, but this is
1871 * done for backward compatibility -- previously
1872 * setting the channel was done per wiphy, but now
1873 * it is per netdev. Previous userland like hostapd
1874 * also passed a netdev to set_wiphy, so that it is
1875 * possible to let that go to the right netdev!
1877 mutex_lock(&cfg80211_mutex
);
1879 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1880 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1882 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1883 if (netdev
&& netdev
->ieee80211_ptr
) {
1884 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1885 mutex_lock(&rdev
->mtx
);
1891 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1894 mutex_unlock(&cfg80211_mutex
);
1895 return PTR_ERR(rdev
);
1901 mutex_lock(&rdev
->mtx
);
1903 wdev
= netdev
->ieee80211_ptr
;
1906 * end workaround code, by now the rdev is available
1907 * and locked, and wdev may or may not be NULL.
1910 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1911 result
= cfg80211_dev_rename(
1912 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1914 mutex_unlock(&cfg80211_mutex
);
1919 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1920 struct ieee80211_txq_params txq_params
;
1921 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1923 if (!rdev
->ops
->set_txq_params
) {
1924 result
= -EOPNOTSUPP
;
1933 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1934 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1939 if (!netif_running(netdev
)) {
1944 nla_for_each_nested(nl_txq_params
,
1945 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1947 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1948 nla_data(nl_txq_params
),
1949 nla_len(nl_txq_params
),
1951 result
= parse_txq_params(tb
, &txq_params
);
1955 result
= rdev_set_txq_params(rdev
, netdev
,
1962 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1963 result
= __nl80211_set_channel(rdev
,
1964 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1970 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1971 struct wireless_dev
*txp_wdev
= wdev
;
1972 enum nl80211_tx_power_setting type
;
1975 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
1978 if (!rdev
->ops
->set_tx_power
) {
1979 result
= -EOPNOTSUPP
;
1983 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1984 type
= nla_get_u32(info
->attrs
[idx
]);
1986 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1987 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1992 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1993 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1994 mbm
= nla_get_u32(info
->attrs
[idx
]);
1997 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2002 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2003 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2005 if ((!rdev
->wiphy
.available_antennas_tx
&&
2006 !rdev
->wiphy
.available_antennas_rx
) ||
2007 !rdev
->ops
->set_antenna
) {
2008 result
= -EOPNOTSUPP
;
2012 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2013 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2015 /* reject antenna configurations which don't match the
2016 * available antenna masks, except for the "all" mask */
2017 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2018 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2023 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2024 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2026 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2033 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2034 retry_short
= nla_get_u8(
2035 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2036 if (retry_short
== 0) {
2040 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2043 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2044 retry_long
= nla_get_u8(
2045 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2046 if (retry_long
== 0) {
2050 changed
|= WIPHY_PARAM_RETRY_LONG
;
2053 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2054 frag_threshold
= nla_get_u32(
2055 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2056 if (frag_threshold
< 256) {
2060 if (frag_threshold
!= (u32
) -1) {
2062 * Fragments (apart from the last one) are required to
2063 * have even length. Make the fragmentation code
2064 * simpler by stripping LSB should someone try to use
2065 * odd threshold value.
2067 frag_threshold
&= ~0x1;
2069 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2072 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2073 rts_threshold
= nla_get_u32(
2074 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2075 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2078 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2079 coverage_class
= nla_get_u8(
2080 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2081 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2085 u8 old_retry_short
, old_retry_long
;
2086 u32 old_frag_threshold
, old_rts_threshold
;
2087 u8 old_coverage_class
;
2089 if (!rdev
->ops
->set_wiphy_params
) {
2090 result
= -EOPNOTSUPP
;
2094 old_retry_short
= rdev
->wiphy
.retry_short
;
2095 old_retry_long
= rdev
->wiphy
.retry_long
;
2096 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2097 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2098 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2100 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2101 rdev
->wiphy
.retry_short
= retry_short
;
2102 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2103 rdev
->wiphy
.retry_long
= retry_long
;
2104 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2105 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2106 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2107 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2108 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2109 rdev
->wiphy
.coverage_class
= coverage_class
;
2111 result
= rdev_set_wiphy_params(rdev
, changed
);
2113 rdev
->wiphy
.retry_short
= old_retry_short
;
2114 rdev
->wiphy
.retry_long
= old_retry_long
;
2115 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2116 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2117 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2122 mutex_unlock(&rdev
->mtx
);
2128 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2130 return (u64
)wdev
->identifier
|
2131 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2134 static int nl80211_send_chandef(struct sk_buff
*msg
,
2135 struct cfg80211_chan_def
*chandef
)
2137 WARN_ON(!cfg80211_chandef_valid(chandef
));
2139 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2140 chandef
->chan
->center_freq
))
2142 switch (chandef
->width
) {
2143 case NL80211_CHAN_WIDTH_20_NOHT
:
2144 case NL80211_CHAN_WIDTH_20
:
2145 case NL80211_CHAN_WIDTH_40
:
2146 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2147 cfg80211_get_chandef_type(chandef
)))
2153 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2155 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2157 if (chandef
->center_freq2
&&
2158 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2163 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2164 struct cfg80211_registered_device
*rdev
,
2165 struct wireless_dev
*wdev
)
2167 struct net_device
*dev
= wdev
->netdev
;
2170 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2175 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2176 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2177 goto nla_put_failure
;
2179 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2180 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2181 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2182 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2183 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2184 rdev
->devlist_generation
^
2185 (cfg80211_rdev_list_generation
<< 2)))
2186 goto nla_put_failure
;
2188 if (rdev
->ops
->get_channel
) {
2190 struct cfg80211_chan_def chandef
;
2192 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2194 if (nl80211_send_chandef(msg
, &chandef
))
2195 goto nla_put_failure
;
2199 if (wdev
->ssid_len
) {
2200 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2201 goto nla_put_failure
;
2204 return genlmsg_end(msg
, hdr
);
2207 genlmsg_cancel(msg
, hdr
);
2211 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2215 int wp_start
= cb
->args
[0];
2216 int if_start
= cb
->args
[1];
2217 struct cfg80211_registered_device
*rdev
;
2218 struct wireless_dev
*wdev
;
2220 mutex_lock(&cfg80211_mutex
);
2221 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2222 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2224 if (wp_idx
< wp_start
) {
2230 mutex_lock(&rdev
->devlist_mtx
);
2231 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2232 if (if_idx
< if_start
) {
2236 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2237 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2239 mutex_unlock(&rdev
->devlist_mtx
);
2244 mutex_unlock(&rdev
->devlist_mtx
);
2249 mutex_unlock(&cfg80211_mutex
);
2251 cb
->args
[0] = wp_idx
;
2252 cb
->args
[1] = if_idx
;
2257 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2259 struct sk_buff
*msg
;
2260 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2261 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2263 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2267 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2273 return genlmsg_reply(msg
, info
);
2276 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2277 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2278 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2279 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2280 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2281 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2284 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2286 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2294 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2295 nla
, mntr_flags_policy
))
2298 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2300 *mntrflags
|= (1<<flag
);
2305 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2306 struct net_device
*netdev
, u8 use_4addr
,
2307 enum nl80211_iftype iftype
)
2310 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2316 case NL80211_IFTYPE_AP_VLAN
:
2317 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2320 case NL80211_IFTYPE_STATION
:
2321 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2331 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2333 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2334 struct vif_params params
;
2336 enum nl80211_iftype otype
, ntype
;
2337 struct net_device
*dev
= info
->user_ptr
[1];
2338 u32 _flags
, *flags
= NULL
;
2339 bool change
= false;
2341 memset(¶ms
, 0, sizeof(params
));
2343 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2345 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2346 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2349 if (ntype
> NL80211_IFTYPE_MAX
)
2353 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2354 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2356 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2358 if (netif_running(dev
))
2362 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2363 IEEE80211_MAX_MESH_ID_LEN
);
2364 wdev
->mesh_id_up_len
=
2365 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2366 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2367 wdev
->mesh_id_up_len
);
2371 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2372 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2374 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2378 params
.use_4addr
= -1;
2381 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2382 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2384 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2394 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2398 if (!err
&& params
.use_4addr
!= -1)
2399 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2404 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2406 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2407 struct vif_params params
;
2408 struct wireless_dev
*wdev
;
2409 struct sk_buff
*msg
;
2411 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2414 memset(¶ms
, 0, sizeof(params
));
2416 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2419 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2420 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2421 if (type
> NL80211_IFTYPE_MAX
)
2425 if (!rdev
->ops
->add_virtual_intf
||
2426 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2429 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2430 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2432 if (!is_valid_ether_addr(params
.macaddr
))
2433 return -EADDRNOTAVAIL
;
2436 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2437 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2438 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2443 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2447 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2448 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2450 wdev
= rdev_add_virtual_intf(rdev
,
2451 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2452 type
, err
? NULL
: &flags
, ¶ms
);
2455 return PTR_ERR(wdev
);
2459 case NL80211_IFTYPE_MESH_POINT
:
2460 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2463 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2464 IEEE80211_MAX_MESH_ID_LEN
);
2465 wdev
->mesh_id_up_len
=
2466 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2467 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2468 wdev
->mesh_id_up_len
);
2471 case NL80211_IFTYPE_P2P_DEVICE
:
2473 * P2P Device doesn't have a netdev, so doesn't go
2474 * through the netdev notifier and must be added here
2476 mutex_init(&wdev
->mtx
);
2477 INIT_LIST_HEAD(&wdev
->event_list
);
2478 spin_lock_init(&wdev
->event_lock
);
2479 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2480 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2482 mutex_lock(&rdev
->devlist_mtx
);
2483 wdev
->identifier
= ++rdev
->wdev_id
;
2484 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2485 rdev
->devlist_generation
++;
2486 mutex_unlock(&rdev
->devlist_mtx
);
2492 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2498 return genlmsg_reply(msg
, info
);
2501 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2503 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2504 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2506 if (!rdev
->ops
->del_virtual_intf
)
2510 * If we remove a wireless device without a netdev then clear
2511 * user_ptr[1] so that nl80211_post_doit won't dereference it
2512 * to check if it needs to do dev_put(). Otherwise it crashes
2513 * since the wdev has been freed, unlike with a netdev where
2514 * we need the dev_put() for the netdev to really be freed.
2517 info
->user_ptr
[1] = NULL
;
2519 return rdev_del_virtual_intf(rdev
, wdev
);
2522 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2524 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2525 struct net_device
*dev
= info
->user_ptr
[1];
2528 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2531 if (!rdev
->ops
->set_noack_map
)
2534 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2536 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2539 struct get_key_cookie
{
2540 struct sk_buff
*msg
;
2545 static void get_key_callback(void *c
, struct key_params
*params
)
2548 struct get_key_cookie
*cookie
= c
;
2551 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2552 params
->key_len
, params
->key
)) ||
2554 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2555 params
->seq_len
, params
->seq
)) ||
2557 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2559 goto nla_put_failure
;
2561 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2563 goto nla_put_failure
;
2566 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2567 params
->key_len
, params
->key
)) ||
2569 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2570 params
->seq_len
, params
->seq
)) ||
2572 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2574 goto nla_put_failure
;
2576 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2577 goto nla_put_failure
;
2579 nla_nest_end(cookie
->msg
, key
);
2586 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2588 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2590 struct net_device
*dev
= info
->user_ptr
[1];
2592 const u8
*mac_addr
= NULL
;
2594 struct get_key_cookie cookie
= {
2598 struct sk_buff
*msg
;
2600 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2601 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2606 if (info
->attrs
[NL80211_ATTR_MAC
])
2607 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2609 pairwise
= !!mac_addr
;
2610 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2611 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2612 if (kt
>= NUM_NL80211_KEYTYPES
)
2614 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2615 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2617 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2620 if (!rdev
->ops
->get_key
)
2623 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2627 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2628 NL80211_CMD_NEW_KEY
);
2630 return PTR_ERR(hdr
);
2633 cookie
.idx
= key_idx
;
2635 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2636 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2637 goto nla_put_failure
;
2639 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2640 goto nla_put_failure
;
2642 if (pairwise
&& mac_addr
&&
2643 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2646 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2653 goto nla_put_failure
;
2655 genlmsg_end(msg
, hdr
);
2656 return genlmsg_reply(msg
, info
);
2665 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2667 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2668 struct key_parse key
;
2670 struct net_device
*dev
= info
->user_ptr
[1];
2672 err
= nl80211_parse_key(info
, &key
);
2679 /* only support setting default key */
2680 if (!key
.def
&& !key
.defmgmt
)
2683 wdev_lock(dev
->ieee80211_ptr
);
2686 if (!rdev
->ops
->set_default_key
) {
2691 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2695 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2696 key
.def_uni
, key
.def_multi
);
2701 #ifdef CONFIG_CFG80211_WEXT
2702 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2705 if (key
.def_uni
|| !key
.def_multi
) {
2710 if (!rdev
->ops
->set_default_mgmt_key
) {
2715 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2719 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2723 #ifdef CONFIG_CFG80211_WEXT
2724 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2729 wdev_unlock(dev
->ieee80211_ptr
);
2734 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2736 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2738 struct net_device
*dev
= info
->user_ptr
[1];
2739 struct key_parse key
;
2740 const u8
*mac_addr
= NULL
;
2742 err
= nl80211_parse_key(info
, &key
);
2749 if (info
->attrs
[NL80211_ATTR_MAC
])
2750 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2752 if (key
.type
== -1) {
2754 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2756 key
.type
= NL80211_KEYTYPE_GROUP
;
2760 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2761 key
.type
!= NL80211_KEYTYPE_GROUP
)
2764 if (!rdev
->ops
->add_key
)
2767 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2768 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2772 wdev_lock(dev
->ieee80211_ptr
);
2773 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2775 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2776 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2778 wdev_unlock(dev
->ieee80211_ptr
);
2783 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2785 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2787 struct net_device
*dev
= info
->user_ptr
[1];
2788 u8
*mac_addr
= NULL
;
2789 struct key_parse key
;
2791 err
= nl80211_parse_key(info
, &key
);
2795 if (info
->attrs
[NL80211_ATTR_MAC
])
2796 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2798 if (key
.type
== -1) {
2800 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2802 key
.type
= NL80211_KEYTYPE_GROUP
;
2806 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2807 key
.type
!= NL80211_KEYTYPE_GROUP
)
2810 if (!rdev
->ops
->del_key
)
2813 wdev_lock(dev
->ieee80211_ptr
);
2814 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2816 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2817 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2821 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2822 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2825 #ifdef CONFIG_CFG80211_WEXT
2827 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2828 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2829 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2830 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2833 wdev_unlock(dev
->ieee80211_ptr
);
2838 /* This function returns an error or the number of nested attributes */
2839 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2841 struct nlattr
*attr
;
2842 int n_entries
= 0, tmp
;
2844 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2845 if (nla_len(attr
) != ETH_ALEN
)
2855 * This function parses ACL information and allocates memory for ACL data.
2856 * On successful return, the calling function is responsible to free the
2857 * ACL buffer returned by this function.
2859 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2860 struct genl_info
*info
)
2862 enum nl80211_acl_policy acl_policy
;
2863 struct nlattr
*attr
;
2864 struct cfg80211_acl_data
*acl
;
2865 int i
= 0, n_entries
, tmp
;
2867 if (!wiphy
->max_acl_mac_addrs
)
2868 return ERR_PTR(-EOPNOTSUPP
);
2870 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2871 return ERR_PTR(-EINVAL
);
2873 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2874 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2875 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2876 return ERR_PTR(-EINVAL
);
2878 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2879 return ERR_PTR(-EINVAL
);
2881 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2883 return ERR_PTR(n_entries
);
2885 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2886 return ERR_PTR(-ENOTSUPP
);
2888 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2891 return ERR_PTR(-ENOMEM
);
2893 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2894 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2898 acl
->n_acl_entries
= n_entries
;
2899 acl
->acl_policy
= acl_policy
;
2904 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2906 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2907 struct net_device
*dev
= info
->user_ptr
[1];
2908 struct cfg80211_acl_data
*acl
;
2911 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2912 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2915 if (!dev
->ieee80211_ptr
->beacon_interval
)
2918 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2920 return PTR_ERR(acl
);
2922 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2929 static int nl80211_parse_beacon(struct genl_info
*info
,
2930 struct cfg80211_beacon_data
*bcn
)
2932 bool haveinfo
= false;
2934 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2935 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2936 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2937 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2940 memset(bcn
, 0, sizeof(*bcn
));
2942 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2943 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2944 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2950 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2951 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2953 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2960 if (info
->attrs
[NL80211_ATTR_IE
]) {
2961 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2962 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2965 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2966 bcn
->proberesp_ies
=
2967 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2968 bcn
->proberesp_ies_len
=
2969 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2972 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2973 bcn
->assocresp_ies
=
2974 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2975 bcn
->assocresp_ies_len
=
2976 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2979 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2981 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2982 bcn
->probe_resp_len
=
2983 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2989 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2990 struct cfg80211_ap_settings
*params
)
2992 struct wireless_dev
*wdev
;
2995 mutex_lock(&rdev
->devlist_mtx
);
2997 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2998 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2999 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3002 if (!wdev
->preset_chandef
.chan
)
3005 params
->chandef
= wdev
->preset_chandef
;
3010 mutex_unlock(&rdev
->devlist_mtx
);
3015 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3016 enum nl80211_auth_type auth_type
,
3017 enum nl80211_commands cmd
)
3019 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3023 case NL80211_CMD_AUTHENTICATE
:
3024 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3025 auth_type
== NL80211_AUTHTYPE_SAE
)
3028 case NL80211_CMD_CONNECT
:
3029 case NL80211_CMD_START_AP
:
3030 /* SAE not supported yet */
3031 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3039 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3041 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3042 struct net_device
*dev
= info
->user_ptr
[1];
3043 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3044 struct cfg80211_ap_settings params
;
3046 u8 radar_detect_width
= 0;
3048 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3049 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3052 if (!rdev
->ops
->start_ap
)
3055 if (wdev
->beacon_interval
)
3058 memset(¶ms
, 0, sizeof(params
));
3060 /* these are required for START_AP */
3061 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3062 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3063 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3066 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
3070 params
.beacon_interval
=
3071 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3072 params
.dtim_period
=
3073 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3075 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3080 * In theory, some of these attributes should be required here
3081 * but since they were not used when the command was originally
3082 * added, keep them optional for old user space programs to let
3083 * them continue to work with drivers that do not need the
3084 * additional information -- drivers must check!
3086 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3087 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3089 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3090 if (params
.ssid_len
== 0 ||
3091 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3095 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3096 params
.hidden_ssid
= nla_get_u32(
3097 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3098 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3099 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3100 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3104 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3106 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3107 params
.auth_type
= nla_get_u32(
3108 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3109 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3110 NL80211_CMD_START_AP
))
3113 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3115 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3116 NL80211_MAX_NR_CIPHER_SUITES
);
3120 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3121 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3123 params
.inactivity_timeout
= nla_get_u16(
3124 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3127 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3128 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3130 params
.p2p_ctwindow
=
3131 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3132 if (params
.p2p_ctwindow
> 127)
3134 if (params
.p2p_ctwindow
!= 0 &&
3135 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3139 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3142 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3144 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3147 params
.p2p_opp_ps
= tmp
;
3148 if (params
.p2p_opp_ps
!= 0 &&
3149 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3153 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3154 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3157 } else if (wdev
->preset_chandef
.chan
) {
3158 params
.chandef
= wdev
->preset_chandef
;
3159 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3162 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3165 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3169 radar_detect_width
= BIT(params
.chandef
.width
);
3170 params
.radar_required
= true;
3173 mutex_lock(&rdev
->devlist_mtx
);
3174 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3175 params
.chandef
.chan
,
3177 radar_detect_width
);
3178 mutex_unlock(&rdev
->devlist_mtx
);
3183 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3184 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3185 if (IS_ERR(params
.acl
))
3186 return PTR_ERR(params
.acl
);
3189 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3191 wdev
->preset_chandef
= params
.chandef
;
3192 wdev
->beacon_interval
= params
.beacon_interval
;
3193 wdev
->channel
= params
.chandef
.chan
;
3194 wdev
->ssid_len
= params
.ssid_len
;
3195 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3203 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3205 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3206 struct net_device
*dev
= info
->user_ptr
[1];
3207 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3208 struct cfg80211_beacon_data params
;
3211 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3212 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3215 if (!rdev
->ops
->change_beacon
)
3218 if (!wdev
->beacon_interval
)
3221 err
= nl80211_parse_beacon(info
, ¶ms
);
3225 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3228 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3230 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3231 struct net_device
*dev
= info
->user_ptr
[1];
3233 return cfg80211_stop_ap(rdev
, dev
);
3236 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3237 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3238 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3239 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3240 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3241 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3242 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3245 static int parse_station_flags(struct genl_info
*info
,
3246 enum nl80211_iftype iftype
,
3247 struct station_parameters
*params
)
3249 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3254 * Try parsing the new attribute first so userspace
3255 * can specify both for older kernels.
3257 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3259 struct nl80211_sta_flag_update
*sta_flags
;
3261 sta_flags
= nla_data(nla
);
3262 params
->sta_flags_mask
= sta_flags
->mask
;
3263 params
->sta_flags_set
= sta_flags
->set
;
3264 params
->sta_flags_set
&= params
->sta_flags_mask
;
3265 if ((params
->sta_flags_mask
|
3266 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3271 /* if present, parse the old attribute */
3273 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3277 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3278 nla
, sta_flags_policy
))
3282 * Only allow certain flags for interface types so that
3283 * other attributes are silently ignored. Remember that
3284 * this is backward compatibility code with old userspace
3285 * and shouldn't be hit in other cases anyway.
3288 case NL80211_IFTYPE_AP
:
3289 case NL80211_IFTYPE_AP_VLAN
:
3290 case NL80211_IFTYPE_P2P_GO
:
3291 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3292 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3293 BIT(NL80211_STA_FLAG_WME
) |
3294 BIT(NL80211_STA_FLAG_MFP
);
3296 case NL80211_IFTYPE_P2P_CLIENT
:
3297 case NL80211_IFTYPE_STATION
:
3298 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3299 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3301 case NL80211_IFTYPE_MESH_POINT
:
3302 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3303 BIT(NL80211_STA_FLAG_MFP
) |
3304 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3309 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3311 params
->sta_flags_set
|= (1<<flag
);
3313 /* no longer support new API additions in old API */
3314 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3322 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3325 struct nlattr
*rate
;
3329 rate
= nla_nest_start(msg
, attr
);
3333 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3334 bitrate
= cfg80211_calculate_bitrate(info
);
3335 /* report 16-bit bitrate only if we can */
3336 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3338 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3340 if (bitrate_compat
> 0 &&
3341 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3344 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3345 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3347 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3348 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3350 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3351 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3353 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3354 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3356 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3358 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3359 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3361 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3362 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3364 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3365 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3367 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3368 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3370 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3371 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3375 nla_nest_end(msg
, rate
);
3379 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3381 struct cfg80211_registered_device
*rdev
,
3382 struct net_device
*dev
,
3383 const u8
*mac_addr
, struct station_info
*sinfo
)
3386 struct nlattr
*sinfoattr
, *bss_param
;
3388 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3392 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3393 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3394 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3395 goto nla_put_failure
;
3397 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3399 goto nla_put_failure
;
3400 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3401 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3402 sinfo
->connected_time
))
3403 goto nla_put_failure
;
3404 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3405 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3406 sinfo
->inactive_time
))
3407 goto nla_put_failure
;
3408 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3409 STATION_INFO_RX_BYTES64
)) &&
3410 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3411 (u32
)sinfo
->rx_bytes
))
3412 goto nla_put_failure
;
3413 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3414 NL80211_STA_INFO_TX_BYTES64
)) &&
3415 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3416 (u32
)sinfo
->tx_bytes
))
3417 goto nla_put_failure
;
3418 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3419 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3421 goto nla_put_failure
;
3422 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3423 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3425 goto nla_put_failure
;
3426 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3427 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3428 goto nla_put_failure
;
3429 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3430 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3431 goto nla_put_failure
;
3432 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3433 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3434 sinfo
->plink_state
))
3435 goto nla_put_failure
;
3436 switch (rdev
->wiphy
.signal_type
) {
3437 case CFG80211_SIGNAL_TYPE_MBM
:
3438 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3439 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3441 goto nla_put_failure
;
3442 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3443 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3445 goto nla_put_failure
;
3450 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3451 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3452 NL80211_STA_INFO_TX_BITRATE
))
3453 goto nla_put_failure
;
3455 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3456 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3457 NL80211_STA_INFO_RX_BITRATE
))
3458 goto nla_put_failure
;
3460 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3461 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3463 goto nla_put_failure
;
3464 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3465 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3467 goto nla_put_failure
;
3468 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3469 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3471 goto nla_put_failure
;
3472 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3473 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3475 goto nla_put_failure
;
3476 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3477 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3478 sinfo
->beacon_loss_count
))
3479 goto nla_put_failure
;
3480 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3481 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3483 goto nla_put_failure
;
3484 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3485 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3487 goto nla_put_failure
;
3488 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3489 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3491 goto nla_put_failure
;
3492 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3493 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3495 goto nla_put_failure
;
3497 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3498 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3499 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3500 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3501 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3502 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3503 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3504 sinfo
->bss_param
.dtim_period
) ||
3505 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3506 sinfo
->bss_param
.beacon_interval
))
3507 goto nla_put_failure
;
3509 nla_nest_end(msg
, bss_param
);
3511 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3512 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3513 sizeof(struct nl80211_sta_flag_update
),
3515 goto nla_put_failure
;
3516 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3517 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3519 goto nla_put_failure
;
3520 nla_nest_end(msg
, sinfoattr
);
3522 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3523 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3524 sinfo
->assoc_req_ies
))
3525 goto nla_put_failure
;
3527 return genlmsg_end(msg
, hdr
);
3530 genlmsg_cancel(msg
, hdr
);
3534 static int nl80211_dump_station(struct sk_buff
*skb
,
3535 struct netlink_callback
*cb
)
3537 struct station_info sinfo
;
3538 struct cfg80211_registered_device
*dev
;
3539 struct wireless_dev
*wdev
;
3540 u8 mac_addr
[ETH_ALEN
];
3541 int sta_idx
= cb
->args
[2];
3544 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3548 if (!wdev
->netdev
) {
3553 if (!dev
->ops
->dump_station
) {
3559 memset(&sinfo
, 0, sizeof(sinfo
));
3560 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3567 if (nl80211_send_station(skb
,
3568 NETLINK_CB(cb
->skb
).portid
,
3569 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3570 dev
, wdev
->netdev
, mac_addr
,
3579 cb
->args
[2] = sta_idx
;
3582 nl80211_finish_wdev_dump(dev
);
3587 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3589 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3590 struct net_device
*dev
= info
->user_ptr
[1];
3591 struct station_info sinfo
;
3592 struct sk_buff
*msg
;
3593 u8
*mac_addr
= NULL
;
3596 memset(&sinfo
, 0, sizeof(sinfo
));
3598 if (!info
->attrs
[NL80211_ATTR_MAC
])
3601 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3603 if (!rdev
->ops
->get_station
)
3606 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3610 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3614 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3615 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3620 return genlmsg_reply(msg
, info
);
3623 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3624 struct station_parameters
*params
,
3625 enum cfg80211_station_type statype
)
3627 if (params
->listen_interval
!= -1)
3632 /* When you run into this, adjust the code below for the new flag */
3633 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3636 case CFG80211_STA_MESH_PEER_KERNEL
:
3637 case CFG80211_STA_MESH_PEER_USER
:
3639 * No ignoring the TDLS flag here -- the userspace mesh
3640 * code doesn't have the bug of including TDLS in the
3643 if (params
->sta_flags_mask
&
3644 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3645 BIT(NL80211_STA_FLAG_MFP
) |
3646 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3649 case CFG80211_STA_TDLS_PEER_SETUP
:
3650 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3651 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3653 /* ignore since it can't change */
3654 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3657 /* disallow mesh-specific things */
3658 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3660 if (params
->local_pm
)
3662 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3666 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3667 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3668 /* TDLS can't be set, ... */
3669 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3672 * ... but don't bother the driver with it. This works around
3673 * a hostapd/wpa_supplicant issue -- it always includes the
3674 * TLDS_PEER flag in the mask even for AP mode.
3676 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3679 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3680 /* reject other things that can't change */
3681 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3683 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3685 if (params
->supported_rates
)
3687 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3691 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3697 case CFG80211_STA_AP_MLME_CLIENT
:
3698 /* Use this only for authorizing/unauthorizing a station */
3699 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3702 case CFG80211_STA_AP_CLIENT
:
3703 /* accept only the listed bits */
3704 if (params
->sta_flags_mask
&
3705 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3706 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3707 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3708 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3709 BIT(NL80211_STA_FLAG_WME
) |
3710 BIT(NL80211_STA_FLAG_MFP
)))
3713 /* but authenticated/associated only if driver handles it */
3714 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3715 params
->sta_flags_mask
&
3716 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3717 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3720 case CFG80211_STA_IBSS
:
3721 case CFG80211_STA_AP_STA
:
3722 /* reject any changes other than AUTHORIZED */
3723 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3726 case CFG80211_STA_TDLS_PEER_SETUP
:
3727 /* reject any changes other than AUTHORIZED or WME */
3728 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3729 BIT(NL80211_STA_FLAG_WME
)))
3731 /* force (at least) rates when authorizing */
3732 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3733 !params
->supported_rates
)
3736 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3737 /* reject any changes */
3739 case CFG80211_STA_MESH_PEER_KERNEL
:
3740 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3743 case CFG80211_STA_MESH_PEER_USER
:
3744 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3751 EXPORT_SYMBOL(cfg80211_check_station_change
);
3754 * Get vlan interface making sure it is running and on the right wiphy.
3756 static struct net_device
*get_vlan(struct genl_info
*info
,
3757 struct cfg80211_registered_device
*rdev
)
3759 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3760 struct net_device
*v
;
3766 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3768 return ERR_PTR(-ENODEV
);
3770 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3775 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3776 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3777 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3782 if (!netif_running(v
)) {
3790 return ERR_PTR(ret
);
3793 static struct nla_policy
3794 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3795 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3796 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3799 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3800 struct station_parameters
*params
)
3802 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3806 /* parse WME attributes if present */
3807 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3810 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3811 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3812 nl80211_sta_wme_policy
);
3816 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3817 params
->uapsd_queues
= nla_get_u8(
3818 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3819 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3822 if (tb
[NL80211_STA_WME_MAX_SP
])
3823 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3825 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3828 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3833 static int nl80211_set_station_tdls(struct genl_info
*info
,
3834 struct station_parameters
*params
)
3836 /* Dummy STA entry gets updated once the peer capabilities are known */
3837 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3839 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3840 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3842 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3844 return nl80211_parse_sta_wme(info
, params
);
3847 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3849 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3850 struct net_device
*dev
= info
->user_ptr
[1];
3851 struct station_parameters params
;
3855 memset(¶ms
, 0, sizeof(params
));
3857 params
.listen_interval
= -1;
3859 if (!rdev
->ops
->change_station
)
3862 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3865 if (!info
->attrs
[NL80211_ATTR_MAC
])
3868 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3870 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3871 params
.supported_rates
=
3872 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3873 params
.supported_rates_len
=
3874 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3877 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3879 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3880 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3883 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3885 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3886 params
.ext_capab_len
=
3887 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3890 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3893 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3896 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3897 params
.plink_action
=
3898 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3899 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3903 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3904 params
.plink_state
=
3905 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3906 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3908 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3911 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3912 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3913 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3915 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3916 pm
> NL80211_MESH_POWER_MAX
)
3919 params
.local_pm
= pm
;
3922 /* Include parameters for TDLS peer (will check later) */
3923 err
= nl80211_set_station_tdls(info
, ¶ms
);
3927 params
.vlan
= get_vlan(info
, rdev
);
3928 if (IS_ERR(params
.vlan
))
3929 return PTR_ERR(params
.vlan
);
3931 switch (dev
->ieee80211_ptr
->iftype
) {
3932 case NL80211_IFTYPE_AP
:
3933 case NL80211_IFTYPE_AP_VLAN
:
3934 case NL80211_IFTYPE_P2P_GO
:
3935 case NL80211_IFTYPE_P2P_CLIENT
:
3936 case NL80211_IFTYPE_STATION
:
3937 case NL80211_IFTYPE_ADHOC
:
3938 case NL80211_IFTYPE_MESH_POINT
:
3945 /* driver will call cfg80211_check_station_change() */
3946 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3950 dev_put(params
.vlan
);
3955 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3957 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3959 struct net_device
*dev
= info
->user_ptr
[1];
3960 struct station_parameters params
;
3961 u8
*mac_addr
= NULL
;
3963 memset(¶ms
, 0, sizeof(params
));
3965 if (!rdev
->ops
->add_station
)
3968 if (!info
->attrs
[NL80211_ATTR_MAC
])
3971 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3974 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3977 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3980 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3981 params
.supported_rates
=
3982 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3983 params
.supported_rates_len
=
3984 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3985 params
.listen_interval
=
3986 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3988 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3989 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3992 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3994 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3995 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3998 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4000 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4001 params
.ext_capab_len
=
4002 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4005 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4007 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4009 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4011 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4013 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4014 params
.plink_action
=
4015 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4016 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4020 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4024 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4027 /* When you run into this, adjust the code below for the new flag */
4028 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4030 switch (dev
->ieee80211_ptr
->iftype
) {
4031 case NL80211_IFTYPE_AP
:
4032 case NL80211_IFTYPE_AP_VLAN
:
4033 case NL80211_IFTYPE_P2P_GO
:
4034 /* ignore WME attributes if iface/sta is not capable */
4035 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4036 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4037 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4039 /* TDLS peers cannot be added */
4040 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4042 /* but don't bother the driver with it */
4043 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4045 /* allow authenticated/associated only if driver handles it */
4046 if (!(rdev
->wiphy
.features
&
4047 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4048 params
.sta_flags_mask
&
4049 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4050 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4053 /* must be last in here for error handling */
4054 params
.vlan
= get_vlan(info
, rdev
);
4055 if (IS_ERR(params
.vlan
))
4056 return PTR_ERR(params
.vlan
);
4058 case NL80211_IFTYPE_MESH_POINT
:
4059 /* ignore uAPSD data */
4060 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4062 /* associated is disallowed */
4063 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4065 /* TDLS peers cannot be added */
4066 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4069 case NL80211_IFTYPE_STATION
:
4070 case NL80211_IFTYPE_P2P_CLIENT
:
4071 /* ignore uAPSD data */
4072 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4074 /* these are disallowed */
4075 if (params
.sta_flags_mask
&
4076 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4077 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4079 /* Only TDLS peers can be added */
4080 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4082 /* Can only add if TDLS ... */
4083 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4085 /* ... with external setup is supported */
4086 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4089 * Older wpa_supplicant versions always mark the TDLS peer
4090 * as authorized, but it shouldn't yet be.
4092 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4098 /* be aware of params.vlan when changing code here */
4100 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4103 dev_put(params
.vlan
);
4107 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4109 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4110 struct net_device
*dev
= info
->user_ptr
[1];
4111 u8
*mac_addr
= NULL
;
4113 if (info
->attrs
[NL80211_ATTR_MAC
])
4114 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4116 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4117 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4118 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4119 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4122 if (!rdev
->ops
->del_station
)
4125 return rdev_del_station(rdev
, dev
, mac_addr
);
4128 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4129 int flags
, struct net_device
*dev
,
4130 u8
*dst
, u8
*next_hop
,
4131 struct mpath_info
*pinfo
)
4134 struct nlattr
*pinfoattr
;
4136 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4140 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4141 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4142 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4143 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4144 goto nla_put_failure
;
4146 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4148 goto nla_put_failure
;
4149 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4150 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4152 goto nla_put_failure
;
4153 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4154 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4155 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4156 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4158 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4159 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4161 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4162 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4164 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4165 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4166 pinfo
->discovery_timeout
)) ||
4167 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4168 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4169 pinfo
->discovery_retries
)))
4170 goto nla_put_failure
;
4172 nla_nest_end(msg
, pinfoattr
);
4174 return genlmsg_end(msg
, hdr
);
4177 genlmsg_cancel(msg
, hdr
);
4181 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4182 struct netlink_callback
*cb
)
4184 struct mpath_info pinfo
;
4185 struct cfg80211_registered_device
*dev
;
4186 struct wireless_dev
*wdev
;
4188 u8 next_hop
[ETH_ALEN
];
4189 int path_idx
= cb
->args
[2];
4192 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4196 if (!dev
->ops
->dump_mpath
) {
4201 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4207 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4214 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4215 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4216 wdev
->netdev
, dst
, next_hop
,
4225 cb
->args
[2] = path_idx
;
4228 nl80211_finish_wdev_dump(dev
);
4232 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4234 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4236 struct net_device
*dev
= info
->user_ptr
[1];
4237 struct mpath_info pinfo
;
4238 struct sk_buff
*msg
;
4240 u8 next_hop
[ETH_ALEN
];
4242 memset(&pinfo
, 0, sizeof(pinfo
));
4244 if (!info
->attrs
[NL80211_ATTR_MAC
])
4247 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4249 if (!rdev
->ops
->get_mpath
)
4252 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4255 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4259 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4263 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4264 dev
, dst
, next_hop
, &pinfo
) < 0) {
4269 return genlmsg_reply(msg
, info
);
4272 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4274 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4275 struct net_device
*dev
= info
->user_ptr
[1];
4277 u8
*next_hop
= NULL
;
4279 if (!info
->attrs
[NL80211_ATTR_MAC
])
4282 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4285 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4286 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4288 if (!rdev
->ops
->change_mpath
)
4291 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4294 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4297 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4299 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4300 struct net_device
*dev
= info
->user_ptr
[1];
4302 u8
*next_hop
= NULL
;
4304 if (!info
->attrs
[NL80211_ATTR_MAC
])
4307 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4310 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4311 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4313 if (!rdev
->ops
->add_mpath
)
4316 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4319 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4322 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4324 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4325 struct net_device
*dev
= info
->user_ptr
[1];
4328 if (info
->attrs
[NL80211_ATTR_MAC
])
4329 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4331 if (!rdev
->ops
->del_mpath
)
4334 return rdev_del_mpath(rdev
, dev
, dst
);
4337 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4339 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4340 struct net_device
*dev
= info
->user_ptr
[1];
4341 struct bss_parameters params
;
4343 memset(¶ms
, 0, sizeof(params
));
4344 /* default to not changing parameters */
4345 params
.use_cts_prot
= -1;
4346 params
.use_short_preamble
= -1;
4347 params
.use_short_slot_time
= -1;
4348 params
.ap_isolate
= -1;
4349 params
.ht_opmode
= -1;
4350 params
.p2p_ctwindow
= -1;
4351 params
.p2p_opp_ps
= -1;
4353 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4354 params
.use_cts_prot
=
4355 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4356 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4357 params
.use_short_preamble
=
4358 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4359 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4360 params
.use_short_slot_time
=
4361 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4362 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4363 params
.basic_rates
=
4364 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4365 params
.basic_rates_len
=
4366 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4368 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4369 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4370 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4372 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4374 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4375 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4377 params
.p2p_ctwindow
=
4378 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4379 if (params
.p2p_ctwindow
< 0)
4381 if (params
.p2p_ctwindow
!= 0 &&
4382 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4386 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4389 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4391 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4394 params
.p2p_opp_ps
= tmp
;
4395 if (params
.p2p_opp_ps
&&
4396 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4400 if (!rdev
->ops
->change_bss
)
4403 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4404 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4407 return rdev_change_bss(rdev
, dev
, ¶ms
);
4410 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4411 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4412 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4413 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4414 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4415 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4416 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4419 static int parse_reg_rule(struct nlattr
*tb
[],
4420 struct ieee80211_reg_rule
*reg_rule
)
4422 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4423 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4425 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4427 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4429 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4431 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4433 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4436 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4438 freq_range
->start_freq_khz
=
4439 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4440 freq_range
->end_freq_khz
=
4441 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4442 freq_range
->max_bandwidth_khz
=
4443 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4445 power_rule
->max_eirp
=
4446 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4448 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4449 power_rule
->max_antenna_gain
=
4450 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4455 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4459 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4462 * You should only get this when cfg80211 hasn't yet initialized
4463 * completely when built-in to the kernel right between the time
4464 * window between nl80211_init() and regulatory_init(), if that is
4467 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4468 return -EINPROGRESS
;
4470 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4473 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4475 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4476 user_reg_hint_type
=
4477 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4479 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4481 switch (user_reg_hint_type
) {
4482 case NL80211_USER_REG_HINT_USER
:
4483 case NL80211_USER_REG_HINT_CELL_BASE
:
4489 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4494 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4495 struct genl_info
*info
)
4497 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4498 struct net_device
*dev
= info
->user_ptr
[1];
4499 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4500 struct mesh_config cur_params
;
4503 struct nlattr
*pinfoattr
;
4504 struct sk_buff
*msg
;
4506 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4509 if (!rdev
->ops
->get_mesh_config
)
4513 /* If not connected, get default parameters */
4514 if (!wdev
->mesh_id_len
)
4515 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4517 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4523 /* Draw up a netlink message to send back */
4524 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4527 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4528 NL80211_CMD_GET_MESH_CONFIG
);
4531 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4533 goto nla_put_failure
;
4534 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4535 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4536 cur_params
.dot11MeshRetryTimeout
) ||
4537 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4538 cur_params
.dot11MeshConfirmTimeout
) ||
4539 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4540 cur_params
.dot11MeshHoldingTimeout
) ||
4541 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4542 cur_params
.dot11MeshMaxPeerLinks
) ||
4543 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4544 cur_params
.dot11MeshMaxRetries
) ||
4545 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4546 cur_params
.dot11MeshTTL
) ||
4547 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4548 cur_params
.element_ttl
) ||
4549 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4550 cur_params
.auto_open_plinks
) ||
4551 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4552 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4553 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4554 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4555 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4556 cur_params
.path_refresh_time
) ||
4557 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4558 cur_params
.min_discovery_timeout
) ||
4559 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4560 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4561 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4562 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4563 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4564 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4565 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4566 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4567 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4568 cur_params
.dot11MeshHWMPRootMode
) ||
4569 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4570 cur_params
.dot11MeshHWMPRannInterval
) ||
4571 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4572 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4573 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4574 cur_params
.dot11MeshForwarding
) ||
4575 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4576 cur_params
.rssi_threshold
) ||
4577 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4578 cur_params
.ht_opmode
) ||
4579 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4580 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4581 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4582 cur_params
.dot11MeshHWMProotInterval
) ||
4583 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4584 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4585 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4586 cur_params
.power_mode
) ||
4587 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4588 cur_params
.dot11MeshAwakeWindowDuration
))
4589 goto nla_put_failure
;
4590 nla_nest_end(msg
, pinfoattr
);
4591 genlmsg_end(msg
, hdr
);
4592 return genlmsg_reply(msg
, info
);
4595 genlmsg_cancel(msg
, hdr
);
4601 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4602 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4603 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4604 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4605 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4606 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4607 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4608 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4609 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4610 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4611 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4612 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4613 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4614 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4615 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4616 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4617 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4618 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4619 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4620 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4621 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4622 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4623 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4624 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4625 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4626 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4627 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4628 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4631 static const struct nla_policy
4632 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4633 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4634 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4635 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4636 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4637 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4638 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4639 .len
= IEEE80211_MAX_DATA_LEN
},
4640 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4643 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4644 struct mesh_config
*cfg
,
4647 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4650 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4653 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4655 cfg->param = fn(tb[attr]); \
4656 mask |= (1 << (attr - 1)); \
4661 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4663 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4664 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4665 nl80211_meshconf_params_policy
))
4668 /* This makes sure that there aren't more than 32 mesh config
4669 * parameters (otherwise our bitfield scheme would not work.) */
4670 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4672 /* Fill in the params struct */
4673 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4674 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4676 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4677 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4679 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4680 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4682 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4683 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4685 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4686 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4688 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4689 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4690 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4691 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4693 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4694 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4696 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4698 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4700 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4701 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4703 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4704 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4706 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4707 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4709 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4711 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4713 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4715 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4717 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4719 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4721 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4722 dot11MeshHWMPnetDiameterTraversalTime
,
4724 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4726 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4727 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4729 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4730 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4732 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4733 dot11MeshGateAnnouncementProtocol
, 0, 1,
4734 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4736 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4737 mask
, NL80211_MESHCONF_FORWARDING
,
4739 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4740 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4742 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4743 mask
, NL80211_MESHCONF_HT_OPMODE
,
4745 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4747 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4749 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4750 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4752 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4753 dot11MeshHWMPconfirmationInterval
,
4755 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4758 NL80211_MESH_POWER_ACTIVE
,
4759 NL80211_MESH_POWER_MAX
,
4760 mask
, NL80211_MESHCONF_POWER_MODE
,
4762 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4764 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4770 #undef FILL_IN_MESH_PARAM_IF_SET
4773 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4774 struct mesh_setup
*setup
)
4776 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4777 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4779 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4781 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4782 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4783 nl80211_mesh_setup_params_policy
))
4786 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4787 setup
->sync_method
=
4788 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4789 IEEE80211_SYNC_METHOD_VENDOR
:
4790 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4792 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4793 setup
->path_sel_proto
=
4794 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4795 IEEE80211_PATH_PROTOCOL_VENDOR
:
4796 IEEE80211_PATH_PROTOCOL_HWMP
;
4798 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4799 setup
->path_metric
=
4800 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4801 IEEE80211_PATH_METRIC_VENDOR
:
4802 IEEE80211_PATH_METRIC_AIRTIME
;
4805 if (tb
[NL80211_MESH_SETUP_IE
]) {
4806 struct nlattr
*ieattr
=
4807 tb
[NL80211_MESH_SETUP_IE
];
4808 if (!is_valid_ie_attr(ieattr
))
4810 setup
->ie
= nla_data(ieattr
);
4811 setup
->ie_len
= nla_len(ieattr
);
4813 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4814 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4816 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4817 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4818 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4819 if (setup
->is_secure
)
4820 setup
->user_mpm
= true;
4825 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4826 struct genl_info
*info
)
4828 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4829 struct net_device
*dev
= info
->user_ptr
[1];
4830 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4831 struct mesh_config cfg
;
4835 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4838 if (!rdev
->ops
->update_mesh_config
)
4841 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4846 if (!wdev
->mesh_id_len
)
4850 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4857 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4859 const struct ieee80211_regdomain
*regdom
;
4860 struct sk_buff
*msg
;
4862 struct nlattr
*nl_reg_rules
;
4866 mutex_lock(&cfg80211_mutex
);
4868 if (!cfg80211_regdomain
)
4871 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4877 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4878 NL80211_CMD_GET_REG
);
4882 if (reg_last_request_cell_base() &&
4883 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4884 NL80211_USER_REG_HINT_CELL_BASE
))
4885 goto nla_put_failure
;
4888 regdom
= rcu_dereference(cfg80211_regdomain
);
4890 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4891 (regdom
->dfs_region
&&
4892 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4893 goto nla_put_failure_rcu
;
4895 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4897 goto nla_put_failure_rcu
;
4899 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4900 struct nlattr
*nl_reg_rule
;
4901 const struct ieee80211_reg_rule
*reg_rule
;
4902 const struct ieee80211_freq_range
*freq_range
;
4903 const struct ieee80211_power_rule
*power_rule
;
4905 reg_rule
= ®dom
->reg_rules
[i
];
4906 freq_range
= ®_rule
->freq_range
;
4907 power_rule
= ®_rule
->power_rule
;
4909 nl_reg_rule
= nla_nest_start(msg
, i
);
4911 goto nla_put_failure_rcu
;
4913 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4915 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4916 freq_range
->start_freq_khz
) ||
4917 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4918 freq_range
->end_freq_khz
) ||
4919 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4920 freq_range
->max_bandwidth_khz
) ||
4921 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4922 power_rule
->max_antenna_gain
) ||
4923 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4924 power_rule
->max_eirp
))
4925 goto nla_put_failure_rcu
;
4927 nla_nest_end(msg
, nl_reg_rule
);
4931 nla_nest_end(msg
, nl_reg_rules
);
4933 genlmsg_end(msg
, hdr
);
4934 err
= genlmsg_reply(msg
, info
);
4937 nla_put_failure_rcu
:
4940 genlmsg_cancel(msg
, hdr
);
4945 mutex_unlock(&cfg80211_mutex
);
4949 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4951 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4952 struct nlattr
*nl_reg_rule
;
4953 char *alpha2
= NULL
;
4954 int rem_reg_rules
= 0, r
= 0;
4955 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4957 struct ieee80211_regdomain
*rd
= NULL
;
4959 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4962 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4965 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4967 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4968 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4970 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4973 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4977 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4978 num_rules
* sizeof(struct ieee80211_reg_rule
);
4980 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4984 rd
->n_reg_rules
= num_rules
;
4985 rd
->alpha2
[0] = alpha2
[0];
4986 rd
->alpha2
[1] = alpha2
[1];
4989 * Disable DFS master mode if the DFS region was
4990 * not supported or known on this kernel.
4992 if (reg_supported_dfs_region(dfs_region
))
4993 rd
->dfs_region
= dfs_region
;
4995 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4997 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4998 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5000 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5006 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5012 mutex_lock(&cfg80211_mutex
);
5015 /* set_regdom took ownership */
5017 mutex_unlock(&cfg80211_mutex
);
5024 static int validate_scan_freqs(struct nlattr
*freqs
)
5026 struct nlattr
*attr1
, *attr2
;
5027 int n_channels
= 0, tmp1
, tmp2
;
5029 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5032 * Some hardware has a limited channel list for
5033 * scanning, and it is pretty much nonsensical
5034 * to scan for a channel twice, so disallow that
5035 * and don't require drivers to check that the
5036 * channel list they get isn't longer than what
5037 * they can scan, as long as they can scan all
5038 * the channels they registered at once.
5040 nla_for_each_nested(attr2
, freqs
, tmp2
)
5041 if (attr1
!= attr2
&&
5042 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5049 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5051 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5052 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5053 struct cfg80211_scan_request
*request
;
5054 struct nlattr
*attr
;
5055 struct wiphy
*wiphy
;
5056 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5059 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5062 wiphy
= &rdev
->wiphy
;
5064 if (!rdev
->ops
->scan
)
5067 mutex_lock(&rdev
->sched_scan_mtx
);
5068 if (rdev
->scan_req
) {
5073 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5074 n_channels
= validate_scan_freqs(
5075 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5081 enum ieee80211_band band
;
5084 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5085 if (wiphy
->bands
[band
])
5086 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5089 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5090 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5093 if (n_ssids
> wiphy
->max_scan_ssids
) {
5098 if (info
->attrs
[NL80211_ATTR_IE
])
5099 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5103 if (ie_len
> wiphy
->max_scan_ie_len
) {
5108 request
= kzalloc(sizeof(*request
)
5109 + sizeof(*request
->ssids
) * n_ssids
5110 + sizeof(*request
->channels
) * n_channels
5111 + ie_len
, GFP_KERNEL
);
5118 request
->ssids
= (void *)&request
->channels
[n_channels
];
5119 request
->n_ssids
= n_ssids
;
5122 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5124 request
->ie
= (void *)(request
->channels
+ n_channels
);
5128 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5129 /* user specified, bail out if channel not found */
5130 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5131 struct ieee80211_channel
*chan
;
5133 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5140 /* ignore disabled channels */
5141 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5144 request
->channels
[i
] = chan
;
5148 enum ieee80211_band band
;
5151 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5153 if (!wiphy
->bands
[band
])
5155 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5156 struct ieee80211_channel
*chan
;
5158 chan
= &wiphy
->bands
[band
]->channels
[j
];
5160 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5163 request
->channels
[i
] = chan
;
5174 request
->n_channels
= i
;
5177 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5178 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5179 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5183 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5184 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5189 if (info
->attrs
[NL80211_ATTR_IE
]) {
5190 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5191 memcpy((void *)request
->ie
,
5192 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5196 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5197 if (wiphy
->bands
[i
])
5199 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5201 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5202 nla_for_each_nested(attr
,
5203 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5205 enum ieee80211_band band
= nla_type(attr
);
5207 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5211 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5214 &request
->rates
[band
]);
5220 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5221 request
->flags
= nla_get_u32(
5222 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5223 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5224 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5225 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5226 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5233 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5235 request
->wdev
= wdev
;
5236 request
->wiphy
= &rdev
->wiphy
;
5237 request
->scan_start
= jiffies
;
5239 rdev
->scan_req
= request
;
5240 err
= rdev_scan(rdev
, request
);
5243 nl80211_send_scan_start(rdev
, wdev
);
5245 dev_hold(wdev
->netdev
);
5248 rdev
->scan_req
= NULL
;
5253 mutex_unlock(&rdev
->sched_scan_mtx
);
5257 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5258 struct genl_info
*info
)
5260 struct cfg80211_sched_scan_request
*request
;
5261 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5262 struct net_device
*dev
= info
->user_ptr
[1];
5263 struct nlattr
*attr
;
5264 struct wiphy
*wiphy
;
5265 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5267 enum ieee80211_band band
;
5269 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5271 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5272 !rdev
->ops
->sched_scan_start
)
5275 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5278 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5281 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5285 wiphy
= &rdev
->wiphy
;
5287 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5288 n_channels
= validate_scan_freqs(
5289 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5295 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5296 if (wiphy
->bands
[band
])
5297 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5300 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5301 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5305 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5308 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5309 nla_for_each_nested(attr
,
5310 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5314 if (n_match_sets
> wiphy
->max_match_sets
)
5317 if (info
->attrs
[NL80211_ATTR_IE
])
5318 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5322 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5325 mutex_lock(&rdev
->sched_scan_mtx
);
5327 if (rdev
->sched_scan_req
) {
5332 request
= kzalloc(sizeof(*request
)
5333 + sizeof(*request
->ssids
) * n_ssids
5334 + sizeof(*request
->match_sets
) * n_match_sets
5335 + sizeof(*request
->channels
) * n_channels
5336 + ie_len
, GFP_KERNEL
);
5343 request
->ssids
= (void *)&request
->channels
[n_channels
];
5344 request
->n_ssids
= n_ssids
;
5347 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5349 request
->ie
= (void *)(request
->channels
+ n_channels
);
5354 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5355 else if (request
->ssids
)
5356 request
->match_sets
=
5357 (void *)(request
->ssids
+ n_ssids
);
5359 request
->match_sets
=
5360 (void *)(request
->channels
+ n_channels
);
5362 request
->n_match_sets
= n_match_sets
;
5365 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5366 /* user specified, bail out if channel not found */
5367 nla_for_each_nested(attr
,
5368 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5370 struct ieee80211_channel
*chan
;
5372 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5379 /* ignore disabled channels */
5380 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5383 request
->channels
[i
] = chan
;
5388 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5390 if (!wiphy
->bands
[band
])
5392 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5393 struct ieee80211_channel
*chan
;
5395 chan
= &wiphy
->bands
[band
]->channels
[j
];
5397 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5400 request
->channels
[i
] = chan
;
5411 request
->n_channels
= i
;
5414 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5415 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5417 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5421 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5422 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5429 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5430 nla_for_each_nested(attr
,
5431 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5433 struct nlattr
*ssid
, *rssi
;
5435 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5436 nla_data(attr
), nla_len(attr
),
5437 nl80211_match_policy
);
5438 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5440 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5444 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5445 nla_data(ssid
), nla_len(ssid
));
5446 request
->match_sets
[i
].ssid
.ssid_len
=
5449 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5451 request
->rssi_thold
= nla_get_u32(rssi
);
5453 request
->rssi_thold
=
5454 NL80211_SCAN_RSSI_THOLD_OFF
;
5459 if (info
->attrs
[NL80211_ATTR_IE
]) {
5460 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5461 memcpy((void *)request
->ie
,
5462 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5466 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5467 request
->flags
= nla_get_u32(
5468 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5469 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5470 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5471 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5472 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5479 request
->wiphy
= &rdev
->wiphy
;
5480 request
->interval
= interval
;
5481 request
->scan_start
= jiffies
;
5483 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5485 rdev
->sched_scan_req
= request
;
5486 nl80211_send_sched_scan(rdev
, dev
,
5487 NL80211_CMD_START_SCHED_SCAN
);
5494 mutex_unlock(&rdev
->sched_scan_mtx
);
5498 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5499 struct genl_info
*info
)
5501 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5504 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5505 !rdev
->ops
->sched_scan_stop
)
5508 mutex_lock(&rdev
->sched_scan_mtx
);
5509 err
= __cfg80211_stop_sched_scan(rdev
, false);
5510 mutex_unlock(&rdev
->sched_scan_mtx
);
5515 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5516 struct genl_info
*info
)
5518 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5519 struct net_device
*dev
= info
->user_ptr
[1];
5520 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5521 struct cfg80211_chan_def chandef
;
5524 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5528 if (wdev
->cac_started
)
5531 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5538 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5541 if (!rdev
->ops
->start_radar_detection
)
5544 mutex_lock(&rdev
->devlist_mtx
);
5545 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5546 chandef
.chan
, CHAN_MODE_SHARED
,
5547 BIT(chandef
.width
));
5551 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5553 wdev
->channel
= chandef
.chan
;
5554 wdev
->cac_started
= true;
5555 wdev
->cac_start_time
= jiffies
;
5558 mutex_unlock(&rdev
->devlist_mtx
);
5563 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5565 struct cfg80211_registered_device
*rdev
,
5566 struct wireless_dev
*wdev
,
5567 struct cfg80211_internal_bss
*intbss
)
5569 struct cfg80211_bss
*res
= &intbss
->pub
;
5570 const struct cfg80211_bss_ies
*ies
;
5575 ASSERT_WDEV_LOCK(wdev
);
5577 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5578 NL80211_CMD_NEW_SCAN_RESULTS
);
5582 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5584 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5585 goto nla_put_failure
;
5587 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5588 goto nla_put_failure
;
5589 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5590 goto nla_put_failure
;
5592 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5594 goto nla_put_failure
;
5595 if ((!is_zero_ether_addr(res
->bssid
) &&
5596 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5597 goto nla_put_failure
;
5600 ies
= rcu_dereference(res
->ies
);
5602 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5603 goto fail_unlock_rcu
;
5605 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5606 ies
->len
, ies
->data
))
5607 goto fail_unlock_rcu
;
5609 ies
= rcu_dereference(res
->beacon_ies
);
5611 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5612 goto fail_unlock_rcu
;
5613 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5614 ies
->len
, ies
->data
))
5615 goto fail_unlock_rcu
;
5619 if (res
->beacon_interval
&&
5620 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5621 goto nla_put_failure
;
5622 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5623 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5624 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5625 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5626 goto nla_put_failure
;
5628 switch (rdev
->wiphy
.signal_type
) {
5629 case CFG80211_SIGNAL_TYPE_MBM
:
5630 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5631 goto nla_put_failure
;
5633 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5634 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5635 goto nla_put_failure
;
5641 switch (wdev
->iftype
) {
5642 case NL80211_IFTYPE_P2P_CLIENT
:
5643 case NL80211_IFTYPE_STATION
:
5644 if (intbss
== wdev
->current_bss
&&
5645 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5646 NL80211_BSS_STATUS_ASSOCIATED
))
5647 goto nla_put_failure
;
5649 case NL80211_IFTYPE_ADHOC
:
5650 if (intbss
== wdev
->current_bss
&&
5651 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5652 NL80211_BSS_STATUS_IBSS_JOINED
))
5653 goto nla_put_failure
;
5659 nla_nest_end(msg
, bss
);
5661 return genlmsg_end(msg
, hdr
);
5666 genlmsg_cancel(msg
, hdr
);
5670 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5672 struct cfg80211_registered_device
*rdev
;
5673 struct cfg80211_internal_bss
*scan
;
5674 struct wireless_dev
*wdev
;
5675 int start
= cb
->args
[2], idx
= 0;
5678 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5683 spin_lock_bh(&rdev
->bss_lock
);
5684 cfg80211_bss_expire(rdev
);
5686 cb
->seq
= rdev
->bss_generation
;
5688 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5691 if (nl80211_send_bss(skb
, cb
,
5692 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5693 rdev
, wdev
, scan
) < 0) {
5699 spin_unlock_bh(&rdev
->bss_lock
);
5703 nl80211_finish_wdev_dump(rdev
);
5708 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5709 int flags
, struct net_device
*dev
,
5710 struct survey_info
*survey
)
5713 struct nlattr
*infoattr
;
5715 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5716 NL80211_CMD_NEW_SURVEY_RESULTS
);
5720 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5721 goto nla_put_failure
;
5723 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5725 goto nla_put_failure
;
5727 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5728 survey
->channel
->center_freq
))
5729 goto nla_put_failure
;
5731 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5732 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5733 goto nla_put_failure
;
5734 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5735 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5736 goto nla_put_failure
;
5737 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5738 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5739 survey
->channel_time
))
5740 goto nla_put_failure
;
5741 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5742 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5743 survey
->channel_time_busy
))
5744 goto nla_put_failure
;
5745 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5746 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5747 survey
->channel_time_ext_busy
))
5748 goto nla_put_failure
;
5749 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5750 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5751 survey
->channel_time_rx
))
5752 goto nla_put_failure
;
5753 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5754 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5755 survey
->channel_time_tx
))
5756 goto nla_put_failure
;
5758 nla_nest_end(msg
, infoattr
);
5760 return genlmsg_end(msg
, hdr
);
5763 genlmsg_cancel(msg
, hdr
);
5767 static int nl80211_dump_survey(struct sk_buff
*skb
,
5768 struct netlink_callback
*cb
)
5770 struct survey_info survey
;
5771 struct cfg80211_registered_device
*dev
;
5772 struct wireless_dev
*wdev
;
5773 int survey_idx
= cb
->args
[2];
5776 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5780 if (!wdev
->netdev
) {
5785 if (!dev
->ops
->dump_survey
) {
5791 struct ieee80211_channel
*chan
;
5793 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5799 /* Survey without a channel doesn't make sense */
5800 if (!survey
.channel
) {
5805 chan
= ieee80211_get_channel(&dev
->wiphy
,
5806 survey
.channel
->center_freq
);
5807 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5812 if (nl80211_send_survey(skb
,
5813 NETLINK_CB(cb
->skb
).portid
,
5814 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5815 wdev
->netdev
, &survey
) < 0)
5821 cb
->args
[2] = survey_idx
;
5824 nl80211_finish_wdev_dump(dev
);
5828 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5830 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5831 NL80211_WPA_VERSION_2
));
5834 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5836 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5837 struct net_device
*dev
= info
->user_ptr
[1];
5838 struct ieee80211_channel
*chan
;
5839 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5840 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5841 enum nl80211_auth_type auth_type
;
5842 struct key_parse key
;
5843 bool local_state_change
;
5845 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5848 if (!info
->attrs
[NL80211_ATTR_MAC
])
5851 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5854 if (!info
->attrs
[NL80211_ATTR_SSID
])
5857 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5860 err
= nl80211_parse_key(info
, &key
);
5865 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5867 if (!key
.p
.key
|| !key
.p
.key_len
)
5869 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5870 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5871 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5872 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5884 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5885 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5894 if (!rdev
->ops
->auth
)
5897 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5898 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5901 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5902 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5903 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5904 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5907 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5908 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5910 if (info
->attrs
[NL80211_ATTR_IE
]) {
5911 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5912 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5915 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5916 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5919 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5920 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5923 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5924 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5926 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5927 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5928 /* need to include at least Auth Transaction and Status Code */
5929 if (sae_data_len
< 4)
5933 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5936 * Since we no longer track auth state, ignore
5937 * requests to only change local state.
5939 if (local_state_change
)
5942 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5943 ssid
, ssid_len
, ie
, ie_len
,
5944 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5945 sae_data
, sae_data_len
);
5948 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5949 struct genl_info
*info
,
5950 struct cfg80211_crypto_settings
*settings
,
5953 memset(settings
, 0, sizeof(*settings
));
5955 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5957 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5959 proto
= nla_get_u16(
5960 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5961 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5962 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5965 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5966 settings
->control_port_no_encrypt
= true;
5968 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5970 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5974 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5975 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5976 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5978 if (len
% sizeof(u32
))
5981 if (settings
->n_ciphers_pairwise
> cipher_limit
)
5984 memcpy(settings
->ciphers_pairwise
, data
, len
);
5986 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
5987 if (!cfg80211_supported_cipher_suite(
5989 settings
->ciphers_pairwise
[i
]))
5993 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
5994 settings
->cipher_group
=
5995 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
5996 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
5997 settings
->cipher_group
))
6001 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6002 settings
->wpa_versions
=
6003 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6004 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6008 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6012 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6013 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6014 settings
->n_akm_suites
= len
/ sizeof(u32
);
6016 if (len
% sizeof(u32
))
6019 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6022 memcpy(settings
->akm_suites
, data
, len
);
6028 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6030 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6031 struct net_device
*dev
= info
->user_ptr
[1];
6032 struct ieee80211_channel
*chan
;
6033 struct cfg80211_assoc_request req
= {};
6034 const u8
*bssid
, *ssid
;
6035 int err
, ssid_len
= 0;
6037 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6040 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6041 !info
->attrs
[NL80211_ATTR_SSID
] ||
6042 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6045 if (!rdev
->ops
->assoc
)
6048 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6049 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6052 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6054 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6055 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6056 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6059 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6060 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6062 if (info
->attrs
[NL80211_ATTR_IE
]) {
6063 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6064 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6067 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6068 enum nl80211_mfp mfp
=
6069 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6070 if (mfp
== NL80211_MFP_REQUIRED
)
6072 else if (mfp
!= NL80211_MFP_NO
)
6076 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6077 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6079 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6080 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6082 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6083 memcpy(&req
.ht_capa_mask
,
6084 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6085 sizeof(req
.ht_capa_mask
));
6087 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6088 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6090 memcpy(&req
.ht_capa
,
6091 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6092 sizeof(req
.ht_capa
));
6095 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6096 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6098 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6099 memcpy(&req
.vht_capa_mask
,
6100 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6101 sizeof(req
.vht_capa_mask
));
6103 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6104 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6106 memcpy(&req
.vht_capa
,
6107 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6108 sizeof(req
.vht_capa
));
6111 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6113 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6114 ssid
, ssid_len
, &req
);
6119 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6121 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6122 struct net_device
*dev
= info
->user_ptr
[1];
6123 const u8
*ie
= NULL
, *bssid
;
6126 bool local_state_change
;
6128 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6131 if (!info
->attrs
[NL80211_ATTR_MAC
])
6134 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6137 if (!rdev
->ops
->deauth
)
6140 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6141 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6144 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6146 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6147 if (reason_code
== 0) {
6148 /* Reason Code 0 is reserved */
6152 if (info
->attrs
[NL80211_ATTR_IE
]) {
6153 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6154 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6157 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6159 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6160 local_state_change
);
6163 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6165 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6166 struct net_device
*dev
= info
->user_ptr
[1];
6167 const u8
*ie
= NULL
, *bssid
;
6170 bool local_state_change
;
6172 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6175 if (!info
->attrs
[NL80211_ATTR_MAC
])
6178 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6181 if (!rdev
->ops
->disassoc
)
6184 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6185 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6188 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6190 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6191 if (reason_code
== 0) {
6192 /* Reason Code 0 is reserved */
6196 if (info
->attrs
[NL80211_ATTR_IE
]) {
6197 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6198 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6201 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6203 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6204 local_state_change
);
6208 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6209 int mcast_rate
[IEEE80211_NUM_BANDS
],
6212 struct wiphy
*wiphy
= &rdev
->wiphy
;
6216 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6217 struct ieee80211_supported_band
*sband
;
6219 sband
= wiphy
->bands
[band
];
6223 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6224 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6225 mcast_rate
[band
] = i
+ 1;
6235 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6237 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6238 struct net_device
*dev
= info
->user_ptr
[1];
6239 struct cfg80211_ibss_params ibss
;
6240 struct wiphy
*wiphy
;
6241 struct cfg80211_cached_keys
*connkeys
= NULL
;
6244 memset(&ibss
, 0, sizeof(ibss
));
6246 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6249 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6250 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6253 ibss
.beacon_interval
= 100;
6255 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6256 ibss
.beacon_interval
=
6257 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6258 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6262 if (!rdev
->ops
->join_ibss
)
6265 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6268 wiphy
= &rdev
->wiphy
;
6270 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6271 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6273 if (!is_valid_ether_addr(ibss
.bssid
))
6276 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6277 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6279 if (info
->attrs
[NL80211_ATTR_IE
]) {
6280 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6281 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6284 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6288 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6291 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
6293 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
6294 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
6297 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6298 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6300 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6302 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6304 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6305 struct ieee80211_supported_band
*sband
=
6306 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6308 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6314 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6315 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6316 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6319 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6322 connkeys
= nl80211_parse_connkeys(rdev
,
6323 info
->attrs
[NL80211_ATTR_KEYS
],
6325 if (IS_ERR(connkeys
))
6326 return PTR_ERR(connkeys
);
6328 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6336 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6338 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6344 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6346 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6347 struct net_device
*dev
= info
->user_ptr
[1];
6349 if (!rdev
->ops
->leave_ibss
)
6352 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6355 return cfg80211_leave_ibss(rdev
, dev
, false);
6358 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6360 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6361 struct net_device
*dev
= info
->user_ptr
[1];
6362 int mcast_rate
[IEEE80211_NUM_BANDS
];
6366 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6367 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6370 if (!rdev
->ops
->set_mcast_rate
)
6373 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6375 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6378 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6379 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6382 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6388 #ifdef CONFIG_NL80211_TESTMODE
6389 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6393 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6395 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6398 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6402 if (rdev
->ops
->testmode_cmd
) {
6403 rdev
->testmode_info
= info
;
6404 err
= rdev_testmode_cmd(rdev
,
6405 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6406 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6407 rdev
->testmode_info
= NULL
;
6413 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6414 struct netlink_callback
*cb
)
6416 struct cfg80211_registered_device
*rdev
;
6424 * 0 is a valid index, but not valid for args[0],
6425 * so we need to offset by 1.
6427 phy_idx
= cb
->args
[0] - 1;
6429 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6430 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6435 mutex_lock(&cfg80211_mutex
);
6436 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6437 nl80211_fam
.attrbuf
);
6439 mutex_unlock(&cfg80211_mutex
);
6440 return PTR_ERR(rdev
);
6442 phy_idx
= rdev
->wiphy_idx
;
6444 mutex_unlock(&cfg80211_mutex
);
6446 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6448 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6452 data
= nla_data((void *)cb
->args
[1]);
6453 data_len
= nla_len((void *)cb
->args
[1]);
6456 mutex_lock(&cfg80211_mutex
);
6457 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6459 mutex_unlock(&cfg80211_mutex
);
6462 cfg80211_lock_rdev(rdev
);
6463 mutex_unlock(&cfg80211_mutex
);
6465 if (!rdev
->ops
->testmode_dump
) {
6471 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6472 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6473 NL80211_CMD_TESTMODE
);
6474 struct nlattr
*tmdata
;
6476 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6477 genlmsg_cancel(skb
, hdr
);
6481 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6483 genlmsg_cancel(skb
, hdr
);
6486 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6487 nla_nest_end(skb
, tmdata
);
6489 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6490 genlmsg_cancel(skb
, hdr
);
6493 genlmsg_cancel(skb
, hdr
);
6497 genlmsg_end(skb
, hdr
);
6502 cb
->args
[0] = phy_idx
+ 1;
6504 cfg80211_unlock_rdev(rdev
);
6508 static struct sk_buff
*
6509 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
6510 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
6512 struct sk_buff
*skb
;
6514 struct nlattr
*data
;
6516 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6520 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
6526 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6527 goto nla_put_failure
;
6528 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6530 ((void **)skb
->cb
)[0] = rdev
;
6531 ((void **)skb
->cb
)[1] = hdr
;
6532 ((void **)skb
->cb
)[2] = data
;
6541 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
6544 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6546 if (WARN_ON(!rdev
->testmode_info
))
6549 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
6550 rdev
->testmode_info
->snd_portid
,
6551 rdev
->testmode_info
->snd_seq
,
6554 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
6556 int cfg80211_testmode_reply(struct sk_buff
*skb
)
6558 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6559 void *hdr
= ((void **)skb
->cb
)[1];
6560 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6562 if (WARN_ON(!rdev
->testmode_info
)) {
6567 nla_nest_end(skb
, data
);
6568 genlmsg_end(skb
, hdr
);
6569 return genlmsg_reply(skb
, rdev
->testmode_info
);
6571 EXPORT_SYMBOL(cfg80211_testmode_reply
);
6573 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
6574 int approxlen
, gfp_t gfp
)
6576 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6578 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
6580 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
6582 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
6584 void *hdr
= ((void **)skb
->cb
)[1];
6585 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6587 nla_nest_end(skb
, data
);
6588 genlmsg_end(skb
, hdr
);
6589 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
6591 EXPORT_SYMBOL(cfg80211_testmode_event
);
6594 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6596 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6597 struct net_device
*dev
= info
->user_ptr
[1];
6598 struct cfg80211_connect_params connect
;
6599 struct wiphy
*wiphy
;
6600 struct cfg80211_cached_keys
*connkeys
= NULL
;
6603 memset(&connect
, 0, sizeof(connect
));
6605 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6608 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6609 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6612 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6614 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6615 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6616 NL80211_CMD_CONNECT
))
6619 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6621 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6623 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6624 NL80211_MAX_NR_CIPHER_SUITES
);
6628 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6629 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6632 wiphy
= &rdev
->wiphy
;
6634 connect
.bg_scan_period
= -1;
6635 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6636 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6637 connect
.bg_scan_period
=
6638 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6641 if (info
->attrs
[NL80211_ATTR_MAC
])
6642 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6643 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6644 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6646 if (info
->attrs
[NL80211_ATTR_IE
]) {
6647 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6648 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6651 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6652 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6653 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6654 connect
.mfp
!= NL80211_MFP_NO
)
6657 connect
.mfp
= NL80211_MFP_NO
;
6660 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6662 ieee80211_get_channel(wiphy
,
6663 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6664 if (!connect
.channel
||
6665 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6669 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6670 connkeys
= nl80211_parse_connkeys(rdev
,
6671 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6672 if (IS_ERR(connkeys
))
6673 return PTR_ERR(connkeys
);
6676 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6677 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6679 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6680 memcpy(&connect
.ht_capa_mask
,
6681 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6682 sizeof(connect
.ht_capa_mask
));
6684 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6685 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6689 memcpy(&connect
.ht_capa
,
6690 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6691 sizeof(connect
.ht_capa
));
6694 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6695 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6697 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6698 memcpy(&connect
.vht_capa_mask
,
6699 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6700 sizeof(connect
.vht_capa_mask
));
6702 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6703 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6707 memcpy(&connect
.vht_capa
,
6708 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6709 sizeof(connect
.vht_capa
));
6712 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
6718 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6720 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6721 struct net_device
*dev
= info
->user_ptr
[1];
6724 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6725 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6727 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6732 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6733 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6736 return cfg80211_disconnect(rdev
, dev
, reason
, true);
6739 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6741 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6746 if (!info
->attrs
[NL80211_ATTR_PID
])
6749 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6751 net
= get_net_ns_by_pid(pid
);
6753 return PTR_ERR(net
);
6757 /* check if anything to do */
6758 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6759 err
= cfg80211_switch_netns(rdev
, net
);
6765 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6767 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6768 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6769 struct cfg80211_pmksa
*pmksa
) = NULL
;
6770 struct net_device
*dev
= info
->user_ptr
[1];
6771 struct cfg80211_pmksa pmksa
;
6773 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6775 if (!info
->attrs
[NL80211_ATTR_MAC
])
6778 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6781 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6782 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6784 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6785 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6788 switch (info
->genlhdr
->cmd
) {
6789 case NL80211_CMD_SET_PMKSA
:
6790 rdev_ops
= rdev
->ops
->set_pmksa
;
6792 case NL80211_CMD_DEL_PMKSA
:
6793 rdev_ops
= rdev
->ops
->del_pmksa
;
6803 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6806 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6808 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6809 struct net_device
*dev
= info
->user_ptr
[1];
6811 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6812 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6815 if (!rdev
->ops
->flush_pmksa
)
6818 return rdev_flush_pmksa(rdev
, dev
);
6821 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6823 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6824 struct net_device
*dev
= info
->user_ptr
[1];
6825 u8 action_code
, dialog_token
;
6829 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6830 !rdev
->ops
->tdls_mgmt
)
6833 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6834 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6835 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6836 !info
->attrs
[NL80211_ATTR_IE
] ||
6837 !info
->attrs
[NL80211_ATTR_MAC
])
6840 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6841 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6842 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6843 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6845 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6846 dialog_token
, status_code
,
6847 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6848 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6851 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6853 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6854 struct net_device
*dev
= info
->user_ptr
[1];
6855 enum nl80211_tdls_operation operation
;
6858 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6859 !rdev
->ops
->tdls_oper
)
6862 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6863 !info
->attrs
[NL80211_ATTR_MAC
])
6866 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6867 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6869 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6872 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6873 struct genl_info
*info
)
6875 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6876 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6877 struct cfg80211_chan_def chandef
;
6878 struct sk_buff
*msg
;
6884 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6885 !info
->attrs
[NL80211_ATTR_DURATION
])
6888 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6890 if (!rdev
->ops
->remain_on_channel
||
6891 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6895 * We should be on that channel for at least a minimum amount of
6896 * time (10ms) but no longer than the driver supports.
6898 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6899 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6902 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6906 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6910 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6911 NL80211_CMD_REMAIN_ON_CHANNEL
);
6918 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6924 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6925 goto nla_put_failure
;
6927 genlmsg_end(msg
, hdr
);
6929 return genlmsg_reply(msg
, info
);
6938 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
6939 struct genl_info
*info
)
6941 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6942 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6945 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6948 if (!rdev
->ops
->cancel_remain_on_channel
)
6951 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6953 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
6956 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
6957 u8
*rates
, u8 rates_len
)
6962 for (i
= 0; i
< rates_len
; i
++) {
6963 int rate
= (rates
[i
] & 0x7f) * 5;
6965 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
6966 struct ieee80211_rate
*srate
=
6967 &sband
->bitrates
[ridx
];
6968 if (rate
== srate
->bitrate
) {
6973 if (ridx
== sband
->n_bitrates
)
6974 return 0; /* rate not found */
6980 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
6981 u8
*rates
, u8 rates_len
,
6982 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
6986 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
6988 for (i
= 0; i
< rates_len
; i
++) {
6991 ridx
= rates
[i
] / 8;
6992 rbit
= BIT(rates
[i
] % 8);
6994 /* check validity */
6995 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
6998 /* check availability */
6999 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7008 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7009 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7010 .len
= NL80211_MAX_SUPP_RATES
},
7011 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7012 .len
= NL80211_MAX_SUPP_HT_RATES
},
7015 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7016 struct genl_info
*info
)
7018 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7019 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7020 struct cfg80211_bitrate_mask mask
;
7022 struct net_device
*dev
= info
->user_ptr
[1];
7023 struct nlattr
*tx_rates
;
7024 struct ieee80211_supported_band
*sband
;
7026 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7029 if (!rdev
->ops
->set_bitrate_mask
)
7032 memset(&mask
, 0, sizeof(mask
));
7033 /* Default to all rates enabled */
7034 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7035 sband
= rdev
->wiphy
.bands
[i
];
7036 mask
.control
[i
].legacy
=
7037 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7039 memcpy(mask
.control
[i
].mcs
,
7040 sband
->ht_cap
.mcs
.rx_mask
,
7041 sizeof(mask
.control
[i
].mcs
));
7043 memset(mask
.control
[i
].mcs
, 0,
7044 sizeof(mask
.control
[i
].mcs
));
7048 * The nested attribute uses enum nl80211_band as the index. This maps
7049 * directly to the enum ieee80211_band values used in cfg80211.
7051 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7052 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7054 enum ieee80211_band band
= nla_type(tx_rates
);
7055 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7057 sband
= rdev
->wiphy
.bands
[band
];
7060 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7061 nla_len(tx_rates
), nl80211_txattr_policy
);
7062 if (tb
[NL80211_TXRATE_LEGACY
]) {
7063 mask
.control
[band
].legacy
= rateset_to_mask(
7065 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7066 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7067 if ((mask
.control
[band
].legacy
== 0) &&
7068 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7071 if (tb
[NL80211_TXRATE_MCS
]) {
7072 if (!ht_rateset_to_mask(
7074 nla_data(tb
[NL80211_TXRATE_MCS
]),
7075 nla_len(tb
[NL80211_TXRATE_MCS
]),
7076 mask
.control
[band
].mcs
))
7080 if (mask
.control
[band
].legacy
== 0) {
7081 /* don't allow empty legacy rates if HT
7082 * is not even supported. */
7083 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7086 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7087 if (mask
.control
[band
].mcs
[i
])
7090 /* legacy and mcs rates may not be both empty */
7091 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7096 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7099 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7101 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7102 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7103 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7105 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7108 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7109 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7111 switch (wdev
->iftype
) {
7112 case NL80211_IFTYPE_STATION
:
7113 case NL80211_IFTYPE_ADHOC
:
7114 case NL80211_IFTYPE_P2P_CLIENT
:
7115 case NL80211_IFTYPE_AP
:
7116 case NL80211_IFTYPE_AP_VLAN
:
7117 case NL80211_IFTYPE_MESH_POINT
:
7118 case NL80211_IFTYPE_P2P_GO
:
7119 case NL80211_IFTYPE_P2P_DEVICE
:
7125 /* not much point in registering if we can't reply */
7126 if (!rdev
->ops
->mgmt_tx
)
7129 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7130 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7131 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7134 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7136 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7137 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7138 struct cfg80211_chan_def chandef
;
7142 struct sk_buff
*msg
= NULL
;
7143 unsigned int wait
= 0;
7144 bool offchan
, no_cck
, dont_wait_for_ack
;
7146 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7148 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7151 if (!rdev
->ops
->mgmt_tx
)
7154 switch (wdev
->iftype
) {
7155 case NL80211_IFTYPE_STATION
:
7156 case NL80211_IFTYPE_ADHOC
:
7157 case NL80211_IFTYPE_P2P_CLIENT
:
7158 case NL80211_IFTYPE_AP
:
7159 case NL80211_IFTYPE_AP_VLAN
:
7160 case NL80211_IFTYPE_MESH_POINT
:
7161 case NL80211_IFTYPE_P2P_GO
:
7162 case NL80211_IFTYPE_P2P_DEVICE
:
7168 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7169 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7171 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7174 * We should wait on the channel for at least a minimum amount
7175 * of time (10ms) but no longer than the driver supports.
7177 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7178 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7183 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7185 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7188 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7190 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7194 if (!dont_wait_for_ack
) {
7195 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7199 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7208 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7209 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7210 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7211 no_cck
, dont_wait_for_ack
, &cookie
);
7216 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7217 goto nla_put_failure
;
7219 genlmsg_end(msg
, hdr
);
7220 return genlmsg_reply(msg
, info
);
7232 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7234 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7235 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7238 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7241 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7244 switch (wdev
->iftype
) {
7245 case NL80211_IFTYPE_STATION
:
7246 case NL80211_IFTYPE_ADHOC
:
7247 case NL80211_IFTYPE_P2P_CLIENT
:
7248 case NL80211_IFTYPE_AP
:
7249 case NL80211_IFTYPE_AP_VLAN
:
7250 case NL80211_IFTYPE_P2P_GO
:
7251 case NL80211_IFTYPE_P2P_DEVICE
:
7257 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7259 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7262 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7264 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7265 struct wireless_dev
*wdev
;
7266 struct net_device
*dev
= info
->user_ptr
[1];
7271 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7274 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7276 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7279 wdev
= dev
->ieee80211_ptr
;
7281 if (!rdev
->ops
->set_power_mgmt
)
7284 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7286 if (state
== wdev
->ps
)
7289 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7295 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7297 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7298 enum nl80211_ps_state ps_state
;
7299 struct wireless_dev
*wdev
;
7300 struct net_device
*dev
= info
->user_ptr
[1];
7301 struct sk_buff
*msg
;
7305 wdev
= dev
->ieee80211_ptr
;
7307 if (!rdev
->ops
->set_power_mgmt
)
7310 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7314 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7315 NL80211_CMD_GET_POWER_SAVE
);
7322 ps_state
= NL80211_PS_ENABLED
;
7324 ps_state
= NL80211_PS_DISABLED
;
7326 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7327 goto nla_put_failure
;
7329 genlmsg_end(msg
, hdr
);
7330 return genlmsg_reply(msg
, info
);
7339 static struct nla_policy
7340 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7341 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7342 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7343 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7344 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7345 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7346 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7349 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7350 u32 rate
, u32 pkts
, u32 intvl
)
7352 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7353 struct wireless_dev
*wdev
;
7354 struct net_device
*dev
= info
->user_ptr
[1];
7356 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7359 wdev
= dev
->ieee80211_ptr
;
7361 if (!rdev
->ops
->set_cqm_txe_config
)
7364 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7365 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7368 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7371 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7372 s32 threshold
, u32 hysteresis
)
7374 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7375 struct wireless_dev
*wdev
;
7376 struct net_device
*dev
= info
->user_ptr
[1];
7381 wdev
= dev
->ieee80211_ptr
;
7383 if (!rdev
->ops
->set_cqm_rssi_config
)
7386 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7387 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7390 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7393 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7395 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7399 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7405 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7406 nl80211_attr_cqm_policy
);
7410 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7411 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7414 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7415 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7416 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7417 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7418 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7419 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7420 u32 rate
, pkts
, intvl
;
7421 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7422 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7423 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7424 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7432 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7434 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7435 struct net_device
*dev
= info
->user_ptr
[1];
7436 struct mesh_config cfg
;
7437 struct mesh_setup setup
;
7440 /* start with default */
7441 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7442 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7444 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7445 /* and parse parameters if given */
7446 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7451 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7452 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7455 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7456 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7458 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7459 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7460 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7463 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7464 setup
.beacon_interval
=
7465 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7466 if (setup
.beacon_interval
< 10 ||
7467 setup
.beacon_interval
> 10000)
7471 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7473 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7474 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7478 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7479 /* parse additional setup parameters if given */
7480 err
= nl80211_parse_mesh_setup(info
, &setup
);
7486 cfg
.auto_open_plinks
= false;
7488 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7489 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7493 /* cfg80211_join_mesh() will sort it out */
7494 setup
.chandef
.chan
= NULL
;
7497 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7500 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7502 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7503 struct net_device
*dev
= info
->user_ptr
[1];
7505 return cfg80211_leave_mesh(rdev
, dev
);
7509 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7510 struct cfg80211_registered_device
*rdev
)
7512 struct nlattr
*nl_pats
, *nl_pat
;
7515 if (!rdev
->wowlan
->n_patterns
)
7518 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7522 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
7523 nl_pat
= nla_nest_start(msg
, i
+ 1);
7526 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
7527 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7528 DIV_ROUND_UP(pat_len
, 8),
7529 rdev
->wowlan
->patterns
[i
].mask
) ||
7530 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7531 pat_len
, rdev
->wowlan
->patterns
[i
].pattern
) ||
7532 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7533 rdev
->wowlan
->patterns
[i
].pkt_offset
))
7535 nla_nest_end(msg
, nl_pat
);
7537 nla_nest_end(msg
, nl_pats
);
7542 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7543 struct cfg80211_wowlan_tcp
*tcp
)
7545 struct nlattr
*nl_tcp
;
7550 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7554 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7555 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7556 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7557 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7558 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7559 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7560 tcp
->payload_len
, tcp
->payload
) ||
7561 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7562 tcp
->data_interval
) ||
7563 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7564 tcp
->wake_len
, tcp
->wake_data
) ||
7565 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7566 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7569 if (tcp
->payload_seq
.len
&&
7570 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7571 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7574 if (tcp
->payload_tok
.len
&&
7575 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7576 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7580 nla_nest_end(msg
, nl_tcp
);
7585 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7587 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7588 struct sk_buff
*msg
;
7590 u32 size
= NLMSG_DEFAULT_SIZE
;
7592 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7593 !rdev
->wiphy
.wowlan
.tcp
)
7596 if (rdev
->wowlan
&& rdev
->wowlan
->tcp
) {
7597 /* adjust size to have room for all the data */
7598 size
+= rdev
->wowlan
->tcp
->tokens_size
+
7599 rdev
->wowlan
->tcp
->payload_len
+
7600 rdev
->wowlan
->tcp
->wake_len
+
7601 rdev
->wowlan
->tcp
->wake_len
/ 8;
7604 msg
= nlmsg_new(size
, GFP_KERNEL
);
7608 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7609 NL80211_CMD_GET_WOWLAN
);
7611 goto nla_put_failure
;
7614 struct nlattr
*nl_wowlan
;
7616 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7618 goto nla_put_failure
;
7620 if ((rdev
->wowlan
->any
&&
7621 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7622 (rdev
->wowlan
->disconnect
&&
7623 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7624 (rdev
->wowlan
->magic_pkt
&&
7625 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7626 (rdev
->wowlan
->gtk_rekey_failure
&&
7627 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7628 (rdev
->wowlan
->eap_identity_req
&&
7629 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7630 (rdev
->wowlan
->four_way_handshake
&&
7631 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7632 (rdev
->wowlan
->rfkill_release
&&
7633 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7634 goto nla_put_failure
;
7636 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7637 goto nla_put_failure
;
7639 if (nl80211_send_wowlan_tcp(msg
, rdev
->wowlan
->tcp
))
7640 goto nla_put_failure
;
7642 nla_nest_end(msg
, nl_wowlan
);
7645 genlmsg_end(msg
, hdr
);
7646 return genlmsg_reply(msg
, info
);
7653 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7654 struct nlattr
*attr
,
7655 struct cfg80211_wowlan
*trig
)
7657 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7658 struct cfg80211_wowlan_tcp
*cfg
;
7659 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7660 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7662 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7665 if (!rdev
->wiphy
.wowlan
.tcp
)
7668 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7669 nla_data(attr
), nla_len(attr
),
7670 nl80211_wowlan_tcp_policy
);
7674 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7675 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7676 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7677 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7678 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7679 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7680 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7681 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7684 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7685 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7688 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7689 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
||
7690 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7693 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7694 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7697 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7698 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7701 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7702 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7704 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7705 tokens_size
= tokln
- sizeof(*tok
);
7707 if (!tok
->len
|| tokens_size
% tok
->len
)
7709 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7711 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7713 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7715 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7717 if (tok
->offset
+ tok
->len
> data_size
)
7721 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7722 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7723 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7725 if (seq
->len
== 0 || seq
->len
> 4)
7727 if (seq
->len
+ seq
->offset
> data_size
)
7731 size
= sizeof(*cfg
);
7733 size
+= wake_size
+ wake_mask_size
;
7734 size
+= tokens_size
;
7736 cfg
= kzalloc(size
, GFP_KERNEL
);
7739 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7740 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7741 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7743 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7744 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7748 /* allocate a socket and port for it and use it */
7749 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7750 IPPROTO_TCP
, &cfg
->sock
, 1);
7755 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7756 sock_release(cfg
->sock
);
7760 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7766 cfg
->src_port
= port
;
7769 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7770 cfg
->payload_len
= data_size
;
7771 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7772 memcpy((void *)cfg
->payload
,
7773 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7776 cfg
->payload_seq
= *seq
;
7777 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7778 cfg
->wake_len
= wake_size
;
7779 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7780 memcpy((void *)cfg
->wake_data
,
7781 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7783 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7784 data_size
+ wake_size
;
7785 memcpy((void *)cfg
->wake_mask
,
7786 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7789 cfg
->tokens_size
= tokens_size
;
7790 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7798 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7800 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7801 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7802 struct cfg80211_wowlan new_triggers
= {};
7803 struct cfg80211_wowlan
*ntrig
;
7804 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7806 bool prev_enabled
= rdev
->wowlan
;
7808 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7809 !rdev
->wiphy
.wowlan
.tcp
)
7812 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7813 cfg80211_rdev_free_wowlan(rdev
);
7814 rdev
->wowlan
= NULL
;
7818 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7819 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7820 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7821 nl80211_wowlan_policy
);
7825 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7826 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7828 new_triggers
.any
= true;
7831 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7832 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7834 new_triggers
.disconnect
= true;
7837 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7838 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7840 new_triggers
.magic_pkt
= true;
7843 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7846 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7847 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7849 new_triggers
.gtk_rekey_failure
= true;
7852 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7853 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7855 new_triggers
.eap_identity_req
= true;
7858 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7859 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7861 new_triggers
.four_way_handshake
= true;
7864 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7865 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7867 new_triggers
.rfkill_release
= true;
7870 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7873 int rem
, pat_len
, mask_len
, pkt_offset
;
7874 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7876 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7879 if (n_patterns
> wowlan
->n_patterns
)
7882 new_triggers
.patterns
= kcalloc(n_patterns
,
7883 sizeof(new_triggers
.patterns
[0]),
7885 if (!new_triggers
.patterns
)
7888 new_triggers
.n_patterns
= n_patterns
;
7891 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7893 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7894 nla_data(pat
), nla_len(pat
), NULL
);
7896 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7897 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7899 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7900 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7901 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7904 if (pat_len
> wowlan
->pattern_max_len
||
7905 pat_len
< wowlan
->pattern_min_len
)
7908 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7911 pkt_offset
= nla_get_u32(
7912 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7913 if (pkt_offset
> wowlan
->max_pkt_offset
)
7915 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7917 new_triggers
.patterns
[i
].mask
=
7918 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7919 if (!new_triggers
.patterns
[i
].mask
) {
7923 new_triggers
.patterns
[i
].pattern
=
7924 new_triggers
.patterns
[i
].mask
+ mask_len
;
7925 memcpy(new_triggers
.patterns
[i
].mask
,
7926 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7928 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7929 memcpy(new_triggers
.patterns
[i
].pattern
,
7930 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
7936 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
7937 err
= nl80211_parse_wowlan_tcp(
7938 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
7944 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
7949 cfg80211_rdev_free_wowlan(rdev
);
7950 rdev
->wowlan
= ntrig
;
7953 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
7954 rdev_set_wakeup(rdev
, rdev
->wowlan
);
7958 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
7959 kfree(new_triggers
.patterns
[i
].mask
);
7960 kfree(new_triggers
.patterns
);
7961 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
7962 sock_release(new_triggers
.tcp
->sock
);
7963 kfree(new_triggers
.tcp
);
7968 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
7970 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7971 struct net_device
*dev
= info
->user_ptr
[1];
7972 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7973 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
7974 struct cfg80211_gtk_rekey_data rekey_data
;
7977 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
7980 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
7981 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
7982 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
7983 nl80211_rekey_policy
);
7987 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
7989 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
7991 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
7994 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
7996 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
7998 memcpy(rekey_data
.replay_ctr
,
7999 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8000 NL80211_REPLAY_CTR_LEN
);
8003 if (!wdev
->current_bss
) {
8008 if (!rdev
->ops
->set_rekey_data
) {
8013 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8019 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8020 struct genl_info
*info
)
8022 struct net_device
*dev
= info
->user_ptr
[1];
8023 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8025 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8026 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8029 if (wdev
->ap_unexpected_nlportid
)
8032 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8036 static int nl80211_probe_client(struct sk_buff
*skb
,
8037 struct genl_info
*info
)
8039 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8040 struct net_device
*dev
= info
->user_ptr
[1];
8041 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8042 struct sk_buff
*msg
;
8048 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8049 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8052 if (!info
->attrs
[NL80211_ATTR_MAC
])
8055 if (!rdev
->ops
->probe_client
)
8058 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8062 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8063 NL80211_CMD_PROBE_CLIENT
);
8070 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8072 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8076 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8077 goto nla_put_failure
;
8079 genlmsg_end(msg
, hdr
);
8081 return genlmsg_reply(msg
, info
);
8090 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8092 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8093 struct cfg80211_beacon_registration
*reg
, *nreg
;
8096 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8099 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8103 /* First, check if already registered. */
8104 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8105 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8106 if (reg
->nlportid
== info
->snd_portid
) {
8111 /* Add it to the list */
8112 nreg
->nlportid
= info
->snd_portid
;
8113 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8115 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8119 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8124 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8126 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8127 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8130 if (!rdev
->ops
->start_p2p_device
)
8133 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8136 if (wdev
->p2p_started
)
8139 mutex_lock(&rdev
->devlist_mtx
);
8140 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8141 mutex_unlock(&rdev
->devlist_mtx
);
8145 err
= rdev_start_p2p_device(rdev
, wdev
);
8149 wdev
->p2p_started
= true;
8150 mutex_lock(&rdev
->devlist_mtx
);
8152 mutex_unlock(&rdev
->devlist_mtx
);
8157 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8159 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8160 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8162 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8165 if (!rdev
->ops
->stop_p2p_device
)
8168 mutex_lock(&rdev
->devlist_mtx
);
8169 mutex_lock(&rdev
->sched_scan_mtx
);
8170 cfg80211_stop_p2p_device(rdev
, wdev
);
8171 mutex_unlock(&rdev
->sched_scan_mtx
);
8172 mutex_unlock(&rdev
->devlist_mtx
);
8177 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8178 struct genl_info
*info
)
8181 struct sk_buff
*msg
;
8183 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8187 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8188 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8190 goto nla_put_failure
;
8192 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8193 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8194 goto nla_put_failure
;
8196 genlmsg_end(msg
, hdr
);
8197 return genlmsg_reply(msg
, info
);
8204 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8206 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8207 struct cfg80211_update_ft_ies_params ft_params
;
8208 struct net_device
*dev
= info
->user_ptr
[1];
8210 if (!rdev
->ops
->update_ft_ies
)
8213 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8214 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8217 memset(&ft_params
, 0, sizeof(ft_params
));
8218 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8219 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8220 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8222 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8225 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8226 struct genl_info
*info
)
8228 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8229 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8230 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8234 if (!rdev
->ops
->crit_proto_start
)
8237 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8240 if (rdev
->crit_proto_nlportid
)
8243 /* determine protocol if provided */
8244 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8245 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8247 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8250 /* timeout must be provided */
8251 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8255 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8257 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8260 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8262 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8267 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8268 struct genl_info
*info
)
8270 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8271 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8273 if (!rdev
->ops
->crit_proto_stop
)
8276 if (rdev
->crit_proto_nlportid
) {
8277 rdev
->crit_proto_nlportid
= 0;
8278 rdev_crit_proto_stop(rdev
, wdev
);
8283 #define NL80211_FLAG_NEED_WIPHY 0x01
8284 #define NL80211_FLAG_NEED_NETDEV 0x02
8285 #define NL80211_FLAG_NEED_RTNL 0x04
8286 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8287 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8288 NL80211_FLAG_CHECK_NETDEV_UP)
8289 #define NL80211_FLAG_NEED_WDEV 0x10
8290 /* If a netdev is associated, it must be UP, P2P must be started */
8291 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8292 NL80211_FLAG_CHECK_NETDEV_UP)
8294 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8295 struct genl_info
*info
)
8297 struct cfg80211_registered_device
*rdev
;
8298 struct wireless_dev
*wdev
;
8299 struct net_device
*dev
;
8300 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8305 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8306 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8310 return PTR_ERR(rdev
);
8312 info
->user_ptr
[0] = rdev
;
8313 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8314 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8315 mutex_lock(&cfg80211_mutex
);
8316 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8319 mutex_unlock(&cfg80211_mutex
);
8322 return PTR_ERR(wdev
);
8326 rdev
= wiphy_to_dev(wdev
->wiphy
);
8328 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8330 mutex_unlock(&cfg80211_mutex
);
8336 info
->user_ptr
[1] = dev
;
8338 info
->user_ptr
[1] = wdev
;
8342 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8343 !netif_running(dev
)) {
8344 mutex_unlock(&cfg80211_mutex
);
8351 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8352 if (!wdev
->p2p_started
) {
8353 mutex_unlock(&cfg80211_mutex
);
8360 cfg80211_lock_rdev(rdev
);
8362 mutex_unlock(&cfg80211_mutex
);
8364 info
->user_ptr
[0] = rdev
;
8370 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8371 struct genl_info
*info
)
8373 if (info
->user_ptr
[0])
8374 cfg80211_unlock_rdev(info
->user_ptr
[0]);
8375 if (info
->user_ptr
[1]) {
8376 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8377 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8380 dev_put(wdev
->netdev
);
8382 dev_put(info
->user_ptr
[1]);
8385 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8389 static struct genl_ops nl80211_ops
[] = {
8391 .cmd
= NL80211_CMD_GET_WIPHY
,
8392 .doit
= nl80211_get_wiphy
,
8393 .dumpit
= nl80211_dump_wiphy
,
8394 .policy
= nl80211_policy
,
8395 /* can be retrieved by unprivileged users */
8396 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
8399 .cmd
= NL80211_CMD_SET_WIPHY
,
8400 .doit
= nl80211_set_wiphy
,
8401 .policy
= nl80211_policy
,
8402 .flags
= GENL_ADMIN_PERM
,
8403 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8406 .cmd
= NL80211_CMD_GET_INTERFACE
,
8407 .doit
= nl80211_get_interface
,
8408 .dumpit
= nl80211_dump_interface
,
8409 .policy
= nl80211_policy
,
8410 /* can be retrieved by unprivileged users */
8411 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
8414 .cmd
= NL80211_CMD_SET_INTERFACE
,
8415 .doit
= nl80211_set_interface
,
8416 .policy
= nl80211_policy
,
8417 .flags
= GENL_ADMIN_PERM
,
8418 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8419 NL80211_FLAG_NEED_RTNL
,
8422 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8423 .doit
= nl80211_new_interface
,
8424 .policy
= nl80211_policy
,
8425 .flags
= GENL_ADMIN_PERM
,
8426 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8427 NL80211_FLAG_NEED_RTNL
,
8430 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8431 .doit
= nl80211_del_interface
,
8432 .policy
= nl80211_policy
,
8433 .flags
= GENL_ADMIN_PERM
,
8434 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8435 NL80211_FLAG_NEED_RTNL
,
8438 .cmd
= NL80211_CMD_GET_KEY
,
8439 .doit
= nl80211_get_key
,
8440 .policy
= nl80211_policy
,
8441 .flags
= GENL_ADMIN_PERM
,
8442 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8443 NL80211_FLAG_NEED_RTNL
,
8446 .cmd
= NL80211_CMD_SET_KEY
,
8447 .doit
= nl80211_set_key
,
8448 .policy
= nl80211_policy
,
8449 .flags
= GENL_ADMIN_PERM
,
8450 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8451 NL80211_FLAG_NEED_RTNL
,
8454 .cmd
= NL80211_CMD_NEW_KEY
,
8455 .doit
= nl80211_new_key
,
8456 .policy
= nl80211_policy
,
8457 .flags
= GENL_ADMIN_PERM
,
8458 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8459 NL80211_FLAG_NEED_RTNL
,
8462 .cmd
= NL80211_CMD_DEL_KEY
,
8463 .doit
= nl80211_del_key
,
8464 .policy
= nl80211_policy
,
8465 .flags
= GENL_ADMIN_PERM
,
8466 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8467 NL80211_FLAG_NEED_RTNL
,
8470 .cmd
= NL80211_CMD_SET_BEACON
,
8471 .policy
= nl80211_policy
,
8472 .flags
= GENL_ADMIN_PERM
,
8473 .doit
= nl80211_set_beacon
,
8474 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8475 NL80211_FLAG_NEED_RTNL
,
8478 .cmd
= NL80211_CMD_START_AP
,
8479 .policy
= nl80211_policy
,
8480 .flags
= GENL_ADMIN_PERM
,
8481 .doit
= nl80211_start_ap
,
8482 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8483 NL80211_FLAG_NEED_RTNL
,
8486 .cmd
= NL80211_CMD_STOP_AP
,
8487 .policy
= nl80211_policy
,
8488 .flags
= GENL_ADMIN_PERM
,
8489 .doit
= nl80211_stop_ap
,
8490 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8491 NL80211_FLAG_NEED_RTNL
,
8494 .cmd
= NL80211_CMD_GET_STATION
,
8495 .doit
= nl80211_get_station
,
8496 .dumpit
= nl80211_dump_station
,
8497 .policy
= nl80211_policy
,
8498 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8499 NL80211_FLAG_NEED_RTNL
,
8502 .cmd
= NL80211_CMD_SET_STATION
,
8503 .doit
= nl80211_set_station
,
8504 .policy
= nl80211_policy
,
8505 .flags
= GENL_ADMIN_PERM
,
8506 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8507 NL80211_FLAG_NEED_RTNL
,
8510 .cmd
= NL80211_CMD_NEW_STATION
,
8511 .doit
= nl80211_new_station
,
8512 .policy
= nl80211_policy
,
8513 .flags
= GENL_ADMIN_PERM
,
8514 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8515 NL80211_FLAG_NEED_RTNL
,
8518 .cmd
= NL80211_CMD_DEL_STATION
,
8519 .doit
= nl80211_del_station
,
8520 .policy
= nl80211_policy
,
8521 .flags
= GENL_ADMIN_PERM
,
8522 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8523 NL80211_FLAG_NEED_RTNL
,
8526 .cmd
= NL80211_CMD_GET_MPATH
,
8527 .doit
= nl80211_get_mpath
,
8528 .dumpit
= nl80211_dump_mpath
,
8529 .policy
= nl80211_policy
,
8530 .flags
= GENL_ADMIN_PERM
,
8531 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8532 NL80211_FLAG_NEED_RTNL
,
8535 .cmd
= NL80211_CMD_SET_MPATH
,
8536 .doit
= nl80211_set_mpath
,
8537 .policy
= nl80211_policy
,
8538 .flags
= GENL_ADMIN_PERM
,
8539 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8540 NL80211_FLAG_NEED_RTNL
,
8543 .cmd
= NL80211_CMD_NEW_MPATH
,
8544 .doit
= nl80211_new_mpath
,
8545 .policy
= nl80211_policy
,
8546 .flags
= GENL_ADMIN_PERM
,
8547 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8548 NL80211_FLAG_NEED_RTNL
,
8551 .cmd
= NL80211_CMD_DEL_MPATH
,
8552 .doit
= nl80211_del_mpath
,
8553 .policy
= nl80211_policy
,
8554 .flags
= GENL_ADMIN_PERM
,
8555 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8556 NL80211_FLAG_NEED_RTNL
,
8559 .cmd
= NL80211_CMD_SET_BSS
,
8560 .doit
= nl80211_set_bss
,
8561 .policy
= nl80211_policy
,
8562 .flags
= GENL_ADMIN_PERM
,
8563 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8564 NL80211_FLAG_NEED_RTNL
,
8567 .cmd
= NL80211_CMD_GET_REG
,
8568 .doit
= nl80211_get_reg
,
8569 .policy
= nl80211_policy
,
8570 /* can be retrieved by unprivileged users */
8573 .cmd
= NL80211_CMD_SET_REG
,
8574 .doit
= nl80211_set_reg
,
8575 .policy
= nl80211_policy
,
8576 .flags
= GENL_ADMIN_PERM
,
8579 .cmd
= NL80211_CMD_REQ_SET_REG
,
8580 .doit
= nl80211_req_set_reg
,
8581 .policy
= nl80211_policy
,
8582 .flags
= GENL_ADMIN_PERM
,
8585 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8586 .doit
= nl80211_get_mesh_config
,
8587 .policy
= nl80211_policy
,
8588 /* can be retrieved by unprivileged users */
8589 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8590 NL80211_FLAG_NEED_RTNL
,
8593 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8594 .doit
= nl80211_update_mesh_config
,
8595 .policy
= nl80211_policy
,
8596 .flags
= GENL_ADMIN_PERM
,
8597 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8598 NL80211_FLAG_NEED_RTNL
,
8601 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8602 .doit
= nl80211_trigger_scan
,
8603 .policy
= nl80211_policy
,
8604 .flags
= GENL_ADMIN_PERM
,
8605 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8606 NL80211_FLAG_NEED_RTNL
,
8609 .cmd
= NL80211_CMD_GET_SCAN
,
8610 .policy
= nl80211_policy
,
8611 .dumpit
= nl80211_dump_scan
,
8614 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8615 .doit
= nl80211_start_sched_scan
,
8616 .policy
= nl80211_policy
,
8617 .flags
= GENL_ADMIN_PERM
,
8618 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8619 NL80211_FLAG_NEED_RTNL
,
8622 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8623 .doit
= nl80211_stop_sched_scan
,
8624 .policy
= nl80211_policy
,
8625 .flags
= GENL_ADMIN_PERM
,
8626 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8627 NL80211_FLAG_NEED_RTNL
,
8630 .cmd
= NL80211_CMD_AUTHENTICATE
,
8631 .doit
= nl80211_authenticate
,
8632 .policy
= nl80211_policy
,
8633 .flags
= GENL_ADMIN_PERM
,
8634 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8635 NL80211_FLAG_NEED_RTNL
,
8638 .cmd
= NL80211_CMD_ASSOCIATE
,
8639 .doit
= nl80211_associate
,
8640 .policy
= nl80211_policy
,
8641 .flags
= GENL_ADMIN_PERM
,
8642 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8643 NL80211_FLAG_NEED_RTNL
,
8646 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8647 .doit
= nl80211_deauthenticate
,
8648 .policy
= nl80211_policy
,
8649 .flags
= GENL_ADMIN_PERM
,
8650 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8651 NL80211_FLAG_NEED_RTNL
,
8654 .cmd
= NL80211_CMD_DISASSOCIATE
,
8655 .doit
= nl80211_disassociate
,
8656 .policy
= nl80211_policy
,
8657 .flags
= GENL_ADMIN_PERM
,
8658 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8659 NL80211_FLAG_NEED_RTNL
,
8662 .cmd
= NL80211_CMD_JOIN_IBSS
,
8663 .doit
= nl80211_join_ibss
,
8664 .policy
= nl80211_policy
,
8665 .flags
= GENL_ADMIN_PERM
,
8666 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8667 NL80211_FLAG_NEED_RTNL
,
8670 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8671 .doit
= nl80211_leave_ibss
,
8672 .policy
= nl80211_policy
,
8673 .flags
= GENL_ADMIN_PERM
,
8674 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8675 NL80211_FLAG_NEED_RTNL
,
8677 #ifdef CONFIG_NL80211_TESTMODE
8679 .cmd
= NL80211_CMD_TESTMODE
,
8680 .doit
= nl80211_testmode_do
,
8681 .dumpit
= nl80211_testmode_dump
,
8682 .policy
= nl80211_policy
,
8683 .flags
= GENL_ADMIN_PERM
,
8684 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8685 NL80211_FLAG_NEED_RTNL
,
8689 .cmd
= NL80211_CMD_CONNECT
,
8690 .doit
= nl80211_connect
,
8691 .policy
= nl80211_policy
,
8692 .flags
= GENL_ADMIN_PERM
,
8693 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8694 NL80211_FLAG_NEED_RTNL
,
8697 .cmd
= NL80211_CMD_DISCONNECT
,
8698 .doit
= nl80211_disconnect
,
8699 .policy
= nl80211_policy
,
8700 .flags
= GENL_ADMIN_PERM
,
8701 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8702 NL80211_FLAG_NEED_RTNL
,
8705 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8706 .doit
= nl80211_wiphy_netns
,
8707 .policy
= nl80211_policy
,
8708 .flags
= GENL_ADMIN_PERM
,
8709 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8710 NL80211_FLAG_NEED_RTNL
,
8713 .cmd
= NL80211_CMD_GET_SURVEY
,
8714 .policy
= nl80211_policy
,
8715 .dumpit
= nl80211_dump_survey
,
8718 .cmd
= NL80211_CMD_SET_PMKSA
,
8719 .doit
= nl80211_setdel_pmksa
,
8720 .policy
= nl80211_policy
,
8721 .flags
= GENL_ADMIN_PERM
,
8722 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8723 NL80211_FLAG_NEED_RTNL
,
8726 .cmd
= NL80211_CMD_DEL_PMKSA
,
8727 .doit
= nl80211_setdel_pmksa
,
8728 .policy
= nl80211_policy
,
8729 .flags
= GENL_ADMIN_PERM
,
8730 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8731 NL80211_FLAG_NEED_RTNL
,
8734 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8735 .doit
= nl80211_flush_pmksa
,
8736 .policy
= nl80211_policy
,
8737 .flags
= GENL_ADMIN_PERM
,
8738 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8739 NL80211_FLAG_NEED_RTNL
,
8742 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8743 .doit
= nl80211_remain_on_channel
,
8744 .policy
= nl80211_policy
,
8745 .flags
= GENL_ADMIN_PERM
,
8746 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8747 NL80211_FLAG_NEED_RTNL
,
8750 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8751 .doit
= nl80211_cancel_remain_on_channel
,
8752 .policy
= nl80211_policy
,
8753 .flags
= GENL_ADMIN_PERM
,
8754 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8755 NL80211_FLAG_NEED_RTNL
,
8758 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8759 .doit
= nl80211_set_tx_bitrate_mask
,
8760 .policy
= nl80211_policy
,
8761 .flags
= GENL_ADMIN_PERM
,
8762 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8763 NL80211_FLAG_NEED_RTNL
,
8766 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8767 .doit
= nl80211_register_mgmt
,
8768 .policy
= nl80211_policy
,
8769 .flags
= GENL_ADMIN_PERM
,
8770 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8771 NL80211_FLAG_NEED_RTNL
,
8774 .cmd
= NL80211_CMD_FRAME
,
8775 .doit
= nl80211_tx_mgmt
,
8776 .policy
= nl80211_policy
,
8777 .flags
= GENL_ADMIN_PERM
,
8778 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8779 NL80211_FLAG_NEED_RTNL
,
8782 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8783 .doit
= nl80211_tx_mgmt_cancel_wait
,
8784 .policy
= nl80211_policy
,
8785 .flags
= GENL_ADMIN_PERM
,
8786 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8787 NL80211_FLAG_NEED_RTNL
,
8790 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8791 .doit
= nl80211_set_power_save
,
8792 .policy
= nl80211_policy
,
8793 .flags
= GENL_ADMIN_PERM
,
8794 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8795 NL80211_FLAG_NEED_RTNL
,
8798 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8799 .doit
= nl80211_get_power_save
,
8800 .policy
= nl80211_policy
,
8801 /* can be retrieved by unprivileged users */
8802 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8803 NL80211_FLAG_NEED_RTNL
,
8806 .cmd
= NL80211_CMD_SET_CQM
,
8807 .doit
= nl80211_set_cqm
,
8808 .policy
= nl80211_policy
,
8809 .flags
= GENL_ADMIN_PERM
,
8810 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8811 NL80211_FLAG_NEED_RTNL
,
8814 .cmd
= NL80211_CMD_SET_CHANNEL
,
8815 .doit
= nl80211_set_channel
,
8816 .policy
= nl80211_policy
,
8817 .flags
= GENL_ADMIN_PERM
,
8818 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8819 NL80211_FLAG_NEED_RTNL
,
8822 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8823 .doit
= nl80211_set_wds_peer
,
8824 .policy
= nl80211_policy
,
8825 .flags
= GENL_ADMIN_PERM
,
8826 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8827 NL80211_FLAG_NEED_RTNL
,
8830 .cmd
= NL80211_CMD_JOIN_MESH
,
8831 .doit
= nl80211_join_mesh
,
8832 .policy
= nl80211_policy
,
8833 .flags
= GENL_ADMIN_PERM
,
8834 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8835 NL80211_FLAG_NEED_RTNL
,
8838 .cmd
= NL80211_CMD_LEAVE_MESH
,
8839 .doit
= nl80211_leave_mesh
,
8840 .policy
= nl80211_policy
,
8841 .flags
= GENL_ADMIN_PERM
,
8842 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8843 NL80211_FLAG_NEED_RTNL
,
8847 .cmd
= NL80211_CMD_GET_WOWLAN
,
8848 .doit
= nl80211_get_wowlan
,
8849 .policy
= nl80211_policy
,
8850 /* can be retrieved by unprivileged users */
8851 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8852 NL80211_FLAG_NEED_RTNL
,
8855 .cmd
= NL80211_CMD_SET_WOWLAN
,
8856 .doit
= nl80211_set_wowlan
,
8857 .policy
= nl80211_policy
,
8858 .flags
= GENL_ADMIN_PERM
,
8859 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8860 NL80211_FLAG_NEED_RTNL
,
8864 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
8865 .doit
= nl80211_set_rekey_data
,
8866 .policy
= nl80211_policy
,
8867 .flags
= GENL_ADMIN_PERM
,
8868 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8869 NL80211_FLAG_NEED_RTNL
,
8872 .cmd
= NL80211_CMD_TDLS_MGMT
,
8873 .doit
= nl80211_tdls_mgmt
,
8874 .policy
= nl80211_policy
,
8875 .flags
= GENL_ADMIN_PERM
,
8876 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8877 NL80211_FLAG_NEED_RTNL
,
8880 .cmd
= NL80211_CMD_TDLS_OPER
,
8881 .doit
= nl80211_tdls_oper
,
8882 .policy
= nl80211_policy
,
8883 .flags
= GENL_ADMIN_PERM
,
8884 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8885 NL80211_FLAG_NEED_RTNL
,
8888 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
8889 .doit
= nl80211_register_unexpected_frame
,
8890 .policy
= nl80211_policy
,
8891 .flags
= GENL_ADMIN_PERM
,
8892 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8893 NL80211_FLAG_NEED_RTNL
,
8896 .cmd
= NL80211_CMD_PROBE_CLIENT
,
8897 .doit
= nl80211_probe_client
,
8898 .policy
= nl80211_policy
,
8899 .flags
= GENL_ADMIN_PERM
,
8900 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8901 NL80211_FLAG_NEED_RTNL
,
8904 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
8905 .doit
= nl80211_register_beacons
,
8906 .policy
= nl80211_policy
,
8907 .flags
= GENL_ADMIN_PERM
,
8908 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8909 NL80211_FLAG_NEED_RTNL
,
8912 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
8913 .doit
= nl80211_set_noack_map
,
8914 .policy
= nl80211_policy
,
8915 .flags
= GENL_ADMIN_PERM
,
8916 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8917 NL80211_FLAG_NEED_RTNL
,
8920 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
8921 .doit
= nl80211_start_p2p_device
,
8922 .policy
= nl80211_policy
,
8923 .flags
= GENL_ADMIN_PERM
,
8924 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8925 NL80211_FLAG_NEED_RTNL
,
8928 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
8929 .doit
= nl80211_stop_p2p_device
,
8930 .policy
= nl80211_policy
,
8931 .flags
= GENL_ADMIN_PERM
,
8932 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8933 NL80211_FLAG_NEED_RTNL
,
8936 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
8937 .doit
= nl80211_set_mcast_rate
,
8938 .policy
= nl80211_policy
,
8939 .flags
= GENL_ADMIN_PERM
,
8940 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8941 NL80211_FLAG_NEED_RTNL
,
8944 .cmd
= NL80211_CMD_SET_MAC_ACL
,
8945 .doit
= nl80211_set_mac_acl
,
8946 .policy
= nl80211_policy
,
8947 .flags
= GENL_ADMIN_PERM
,
8948 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8949 NL80211_FLAG_NEED_RTNL
,
8952 .cmd
= NL80211_CMD_RADAR_DETECT
,
8953 .doit
= nl80211_start_radar_detection
,
8954 .policy
= nl80211_policy
,
8955 .flags
= GENL_ADMIN_PERM
,
8956 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8957 NL80211_FLAG_NEED_RTNL
,
8960 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
8961 .doit
= nl80211_get_protocol_features
,
8962 .policy
= nl80211_policy
,
8965 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
8966 .doit
= nl80211_update_ft_ies
,
8967 .policy
= nl80211_policy
,
8968 .flags
= GENL_ADMIN_PERM
,
8969 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8970 NL80211_FLAG_NEED_RTNL
,
8973 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
8974 .doit
= nl80211_crit_protocol_start
,
8975 .policy
= nl80211_policy
,
8976 .flags
= GENL_ADMIN_PERM
,
8977 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8978 NL80211_FLAG_NEED_RTNL
,
8981 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
8982 .doit
= nl80211_crit_protocol_stop
,
8983 .policy
= nl80211_policy
,
8984 .flags
= GENL_ADMIN_PERM
,
8985 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8986 NL80211_FLAG_NEED_RTNL
,
8990 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
8994 /* multicast groups */
8995 static struct genl_multicast_group nl80211_config_mcgrp
= {
8998 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9001 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9002 .name
= "regulatory",
9005 /* notification functions */
9007 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9009 struct sk_buff
*msg
;
9011 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9015 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0,
9016 false, NULL
, NULL
, NULL
) < 0) {
9021 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9022 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9025 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9026 struct cfg80211_registered_device
*rdev
)
9028 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9029 struct nlattr
*nest
;
9032 lockdep_assert_held(&rdev
->sched_scan_mtx
);
9037 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9039 goto nla_put_failure
;
9040 for (i
= 0; i
< req
->n_ssids
; i
++) {
9041 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9042 goto nla_put_failure
;
9044 nla_nest_end(msg
, nest
);
9046 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9048 goto nla_put_failure
;
9049 for (i
= 0; i
< req
->n_channels
; i
++) {
9050 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9051 goto nla_put_failure
;
9053 nla_nest_end(msg
, nest
);
9056 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9057 goto nla_put_failure
;
9060 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9067 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9068 struct cfg80211_registered_device
*rdev
,
9069 struct wireless_dev
*wdev
,
9070 u32 portid
, u32 seq
, int flags
,
9075 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9079 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9080 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9081 wdev
->netdev
->ifindex
)) ||
9082 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9083 goto nla_put_failure
;
9085 /* ignore errors and send incomplete event anyway */
9086 nl80211_add_scan_req(msg
, rdev
);
9088 return genlmsg_end(msg
, hdr
);
9091 genlmsg_cancel(msg
, hdr
);
9096 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9097 struct cfg80211_registered_device
*rdev
,
9098 struct net_device
*netdev
,
9099 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9103 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9107 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9108 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9109 goto nla_put_failure
;
9111 return genlmsg_end(msg
, hdr
);
9114 genlmsg_cancel(msg
, hdr
);
9118 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9119 struct wireless_dev
*wdev
)
9121 struct sk_buff
*msg
;
9123 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9127 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9128 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9133 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9134 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9137 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9138 struct wireless_dev
*wdev
)
9140 struct sk_buff
*msg
;
9142 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9146 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9147 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9152 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9153 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9156 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9157 struct wireless_dev
*wdev
)
9159 struct sk_buff
*msg
;
9161 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9165 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9166 NL80211_CMD_SCAN_ABORTED
) < 0) {
9171 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9172 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9175 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9176 struct net_device
*netdev
)
9178 struct sk_buff
*msg
;
9180 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9184 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9185 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9190 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9191 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9194 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9195 struct net_device
*netdev
, u32 cmd
)
9197 struct sk_buff
*msg
;
9199 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9203 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9208 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9209 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9213 * This can happen on global regulatory changes or device specific settings
9214 * based on custom world regulatory domains.
9216 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9218 struct sk_buff
*msg
;
9221 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9225 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9231 /* Userspace can always count this one always being set */
9232 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9233 goto nla_put_failure
;
9235 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9236 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9237 NL80211_REGDOM_TYPE_WORLD
))
9238 goto nla_put_failure
;
9239 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9240 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9241 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9242 goto nla_put_failure
;
9243 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9244 request
->intersect
) {
9245 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9246 NL80211_REGDOM_TYPE_INTERSECTION
))
9247 goto nla_put_failure
;
9249 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9250 NL80211_REGDOM_TYPE_COUNTRY
) ||
9251 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9253 goto nla_put_failure
;
9256 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9257 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9258 goto nla_put_failure
;
9260 genlmsg_end(msg
, hdr
);
9263 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9270 genlmsg_cancel(msg
, hdr
);
9274 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9275 struct net_device
*netdev
,
9276 const u8
*buf
, size_t len
,
9277 enum nl80211_commands cmd
, gfp_t gfp
)
9279 struct sk_buff
*msg
;
9282 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9286 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9292 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9293 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9294 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9295 goto nla_put_failure
;
9297 genlmsg_end(msg
, hdr
);
9299 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9300 nl80211_mlme_mcgrp
.id
, gfp
);
9304 genlmsg_cancel(msg
, hdr
);
9308 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9309 struct net_device
*netdev
, const u8
*buf
,
9310 size_t len
, gfp_t gfp
)
9312 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9313 NL80211_CMD_AUTHENTICATE
, gfp
);
9316 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9317 struct net_device
*netdev
, const u8
*buf
,
9318 size_t len
, gfp_t gfp
)
9320 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9321 NL80211_CMD_ASSOCIATE
, gfp
);
9324 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9325 struct net_device
*netdev
, const u8
*buf
,
9326 size_t len
, gfp_t gfp
)
9328 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9329 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9332 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9333 struct net_device
*netdev
, const u8
*buf
,
9334 size_t len
, gfp_t gfp
)
9336 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9337 NL80211_CMD_DISASSOCIATE
, gfp
);
9340 void cfg80211_send_unprot_deauth(struct net_device
*dev
, const u8
*buf
,
9343 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9344 struct wiphy
*wiphy
= wdev
->wiphy
;
9345 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9347 trace_cfg80211_send_unprot_deauth(dev
);
9348 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9349 NL80211_CMD_UNPROT_DEAUTHENTICATE
, GFP_ATOMIC
);
9351 EXPORT_SYMBOL(cfg80211_send_unprot_deauth
);
9353 void cfg80211_send_unprot_disassoc(struct net_device
*dev
, const u8
*buf
,
9356 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9357 struct wiphy
*wiphy
= wdev
->wiphy
;
9358 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9360 trace_cfg80211_send_unprot_disassoc(dev
);
9361 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9362 NL80211_CMD_UNPROT_DISASSOCIATE
, GFP_ATOMIC
);
9364 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc
);
9366 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9367 struct net_device
*netdev
, int cmd
,
9368 const u8
*addr
, gfp_t gfp
)
9370 struct sk_buff
*msg
;
9373 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9377 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9383 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9384 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9385 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9386 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9387 goto nla_put_failure
;
9389 genlmsg_end(msg
, hdr
);
9391 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9392 nl80211_mlme_mcgrp
.id
, gfp
);
9396 genlmsg_cancel(msg
, hdr
);
9400 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9401 struct net_device
*netdev
, const u8
*addr
,
9404 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9408 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9409 struct net_device
*netdev
, const u8
*addr
,
9412 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9416 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9417 struct net_device
*netdev
, const u8
*bssid
,
9418 const u8
*req_ie
, size_t req_ie_len
,
9419 const u8
*resp_ie
, size_t resp_ie_len
,
9420 u16 status
, gfp_t gfp
)
9422 struct sk_buff
*msg
;
9425 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9429 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9435 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9436 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9437 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9438 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9440 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9442 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9443 goto nla_put_failure
;
9445 genlmsg_end(msg
, hdr
);
9447 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9448 nl80211_mlme_mcgrp
.id
, gfp
);
9452 genlmsg_cancel(msg
, hdr
);
9457 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9458 struct net_device
*netdev
, const u8
*bssid
,
9459 const u8
*req_ie
, size_t req_ie_len
,
9460 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9462 struct sk_buff
*msg
;
9465 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9469 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9475 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9476 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9477 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9479 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9481 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9482 goto nla_put_failure
;
9484 genlmsg_end(msg
, hdr
);
9486 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9487 nl80211_mlme_mcgrp
.id
, gfp
);
9491 genlmsg_cancel(msg
, hdr
);
9496 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9497 struct net_device
*netdev
, u16 reason
,
9498 const u8
*ie
, size_t ie_len
, bool from_ap
)
9500 struct sk_buff
*msg
;
9503 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9507 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9513 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9514 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9515 (from_ap
&& reason
&&
9516 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9518 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9519 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9520 goto nla_put_failure
;
9522 genlmsg_end(msg
, hdr
);
9524 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9525 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9529 genlmsg_cancel(msg
, hdr
);
9534 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9535 struct net_device
*netdev
, const u8
*bssid
,
9538 struct sk_buff
*msg
;
9541 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9545 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9551 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9552 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9553 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9554 goto nla_put_failure
;
9556 genlmsg_end(msg
, hdr
);
9558 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9559 nl80211_mlme_mcgrp
.id
, gfp
);
9563 genlmsg_cancel(msg
, hdr
);
9567 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9568 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9570 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9571 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9572 struct sk_buff
*msg
;
9575 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9578 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9580 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9584 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9590 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9591 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9592 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9594 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9595 goto nla_put_failure
;
9597 genlmsg_end(msg
, hdr
);
9599 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9600 nl80211_mlme_mcgrp
.id
, gfp
);
9604 genlmsg_cancel(msg
, hdr
);
9607 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9609 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9610 struct net_device
*netdev
, const u8
*addr
,
9611 enum nl80211_key_type key_type
, int key_id
,
9612 const u8
*tsc
, gfp_t gfp
)
9614 struct sk_buff
*msg
;
9617 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9621 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9627 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9628 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9629 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9630 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9632 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9633 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9634 goto nla_put_failure
;
9636 genlmsg_end(msg
, hdr
);
9638 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9639 nl80211_mlme_mcgrp
.id
, gfp
);
9643 genlmsg_cancel(msg
, hdr
);
9647 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9648 struct ieee80211_channel
*channel_before
,
9649 struct ieee80211_channel
*channel_after
)
9651 struct sk_buff
*msg
;
9653 struct nlattr
*nl_freq
;
9655 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9659 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9666 * Since we are applying the beacon hint to a wiphy we know its
9667 * wiphy_idx is valid
9669 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9670 goto nla_put_failure
;
9673 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9675 goto nla_put_failure
;
9676 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9677 goto nla_put_failure
;
9678 nla_nest_end(msg
, nl_freq
);
9681 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9683 goto nla_put_failure
;
9684 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9685 goto nla_put_failure
;
9686 nla_nest_end(msg
, nl_freq
);
9688 genlmsg_end(msg
, hdr
);
9691 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9698 genlmsg_cancel(msg
, hdr
);
9702 static void nl80211_send_remain_on_chan_event(
9703 int cmd
, struct cfg80211_registered_device
*rdev
,
9704 struct wireless_dev
*wdev
, u64 cookie
,
9705 struct ieee80211_channel
*chan
,
9706 unsigned int duration
, gfp_t gfp
)
9708 struct sk_buff
*msg
;
9711 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9715 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9721 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9722 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9723 wdev
->netdev
->ifindex
)) ||
9724 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9725 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9726 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9727 NL80211_CHAN_NO_HT
) ||
9728 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9729 goto nla_put_failure
;
9731 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9732 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9733 goto nla_put_failure
;
9735 genlmsg_end(msg
, hdr
);
9737 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9738 nl80211_mlme_mcgrp
.id
, gfp
);
9742 genlmsg_cancel(msg
, hdr
);
9746 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9747 struct ieee80211_channel
*chan
,
9748 unsigned int duration
, gfp_t gfp
)
9750 struct wiphy
*wiphy
= wdev
->wiphy
;
9751 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9753 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9754 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9755 rdev
, wdev
, cookie
, chan
,
9758 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9760 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9761 struct ieee80211_channel
*chan
,
9764 struct wiphy
*wiphy
= wdev
->wiphy
;
9765 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9767 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9768 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9769 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9771 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9773 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9774 struct station_info
*sinfo
, gfp_t gfp
)
9776 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9777 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9778 struct sk_buff
*msg
;
9780 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9782 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9786 if (nl80211_send_station(msg
, 0, 0, 0,
9787 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9792 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9793 nl80211_mlme_mcgrp
.id
, gfp
);
9795 EXPORT_SYMBOL(cfg80211_new_sta
);
9797 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9799 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9800 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9801 struct sk_buff
*msg
;
9804 trace_cfg80211_del_sta(dev
, mac_addr
);
9806 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9810 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9816 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9817 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9818 goto nla_put_failure
;
9820 genlmsg_end(msg
, hdr
);
9822 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9823 nl80211_mlme_mcgrp
.id
, gfp
);
9827 genlmsg_cancel(msg
, hdr
);
9830 EXPORT_SYMBOL(cfg80211_del_sta
);
9832 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
9833 enum nl80211_connect_failed_reason reason
,
9836 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9837 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9838 struct sk_buff
*msg
;
9841 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
9845 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
9851 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9852 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
9853 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
9854 goto nla_put_failure
;
9856 genlmsg_end(msg
, hdr
);
9858 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9859 nl80211_mlme_mcgrp
.id
, gfp
);
9863 genlmsg_cancel(msg
, hdr
);
9866 EXPORT_SYMBOL(cfg80211_conn_failed
);
9868 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
9869 const u8
*addr
, gfp_t gfp
)
9871 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9872 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9873 struct sk_buff
*msg
;
9876 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
9881 msg
= nlmsg_new(100, gfp
);
9885 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9891 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9892 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9893 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9894 goto nla_put_failure
;
9896 err
= genlmsg_end(msg
, hdr
);
9902 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9906 genlmsg_cancel(msg
, hdr
);
9911 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
9912 const u8
*addr
, gfp_t gfp
)
9914 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9917 trace_cfg80211_rx_spurious_frame(dev
, addr
);
9919 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9920 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
9921 trace_cfg80211_return_bool(false);
9924 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
9926 trace_cfg80211_return_bool(ret
);
9929 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
9931 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
9932 const u8
*addr
, gfp_t gfp
)
9934 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9937 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
9939 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9940 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
9941 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
9942 trace_cfg80211_return_bool(false);
9945 ret
= __nl80211_unexpected_frame(dev
,
9946 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
9948 trace_cfg80211_return_bool(ret
);
9951 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
9953 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
9954 struct wireless_dev
*wdev
, u32 nlportid
,
9955 int freq
, int sig_dbm
,
9956 const u8
*buf
, size_t len
, gfp_t gfp
)
9958 struct net_device
*netdev
= wdev
->netdev
;
9959 struct sk_buff
*msg
;
9962 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9966 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
9972 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9973 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9974 netdev
->ifindex
)) ||
9975 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9976 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
9978 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
9979 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9980 goto nla_put_failure
;
9982 genlmsg_end(msg
, hdr
);
9984 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9987 genlmsg_cancel(msg
, hdr
);
9992 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
9993 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
9995 struct wiphy
*wiphy
= wdev
->wiphy
;
9996 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9997 struct net_device
*netdev
= wdev
->netdev
;
9998 struct sk_buff
*msg
;
10001 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10003 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10007 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10013 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10014 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10015 netdev
->ifindex
)) ||
10016 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10017 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10018 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10019 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10020 goto nla_put_failure
;
10022 genlmsg_end(msg
, hdr
);
10024 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
10028 genlmsg_cancel(msg
, hdr
);
10031 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10033 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10034 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10037 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10038 struct wiphy
*wiphy
= wdev
->wiphy
;
10039 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10040 struct sk_buff
*msg
;
10041 struct nlattr
*pinfoattr
;
10044 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10046 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10050 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10056 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10057 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10058 goto nla_put_failure
;
10060 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10062 goto nla_put_failure
;
10064 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10066 goto nla_put_failure
;
10068 nla_nest_end(msg
, pinfoattr
);
10070 genlmsg_end(msg
, hdr
);
10072 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10073 nl80211_mlme_mcgrp
.id
, gfp
);
10077 genlmsg_cancel(msg
, hdr
);
10080 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10082 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10083 struct net_device
*netdev
, const u8
*bssid
,
10084 const u8
*replay_ctr
, gfp_t gfp
)
10086 struct sk_buff
*msg
;
10087 struct nlattr
*rekey_attr
;
10090 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10094 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10100 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10101 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10102 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10103 goto nla_put_failure
;
10105 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10107 goto nla_put_failure
;
10109 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10110 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10111 goto nla_put_failure
;
10113 nla_nest_end(msg
, rekey_attr
);
10115 genlmsg_end(msg
, hdr
);
10117 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10118 nl80211_mlme_mcgrp
.id
, gfp
);
10122 genlmsg_cancel(msg
, hdr
);
10126 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10127 const u8
*replay_ctr
, gfp_t gfp
)
10129 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10130 struct wiphy
*wiphy
= wdev
->wiphy
;
10131 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10133 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10134 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10136 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10139 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10140 struct net_device
*netdev
, int index
,
10141 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10143 struct sk_buff
*msg
;
10144 struct nlattr
*attr
;
10147 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10151 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10157 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10158 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10159 goto nla_put_failure
;
10161 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10163 goto nla_put_failure
;
10165 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10166 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10168 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10169 goto nla_put_failure
;
10171 nla_nest_end(msg
, attr
);
10173 genlmsg_end(msg
, hdr
);
10175 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10176 nl80211_mlme_mcgrp
.id
, gfp
);
10180 genlmsg_cancel(msg
, hdr
);
10184 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10185 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10187 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10188 struct wiphy
*wiphy
= wdev
->wiphy
;
10189 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10191 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10192 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10194 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10196 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10197 struct net_device
*netdev
,
10198 struct cfg80211_chan_def
*chandef
,
10201 struct sk_buff
*msg
;
10204 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10208 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10214 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10215 goto nla_put_failure
;
10217 if (nl80211_send_chandef(msg
, chandef
))
10218 goto nla_put_failure
;
10220 genlmsg_end(msg
, hdr
);
10222 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10223 nl80211_mlme_mcgrp
.id
, gfp
);
10227 genlmsg_cancel(msg
, hdr
);
10231 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10232 struct cfg80211_chan_def
*chandef
)
10234 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10235 struct wiphy
*wiphy
= wdev
->wiphy
;
10236 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10238 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10242 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10243 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10246 wdev
->channel
= chandef
->chan
;
10247 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10252 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10254 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10255 const u8
*peer
, u32 num_packets
,
10256 u32 rate
, u32 intvl
, gfp_t gfp
)
10258 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10259 struct wiphy
*wiphy
= wdev
->wiphy
;
10260 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10261 struct sk_buff
*msg
;
10262 struct nlattr
*pinfoattr
;
10265 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10269 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10275 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10276 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10277 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10278 goto nla_put_failure
;
10280 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10282 goto nla_put_failure
;
10284 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10285 goto nla_put_failure
;
10287 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10288 goto nla_put_failure
;
10290 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10291 goto nla_put_failure
;
10293 nla_nest_end(msg
, pinfoattr
);
10295 genlmsg_end(msg
, hdr
);
10297 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10298 nl80211_mlme_mcgrp
.id
, gfp
);
10302 genlmsg_cancel(msg
, hdr
);
10305 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10308 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10309 struct cfg80211_chan_def
*chandef
,
10310 enum nl80211_radar_event event
,
10311 struct net_device
*netdev
, gfp_t gfp
)
10313 struct sk_buff
*msg
;
10316 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10320 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10326 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10327 goto nla_put_failure
;
10329 /* NOP and radar events don't need a netdev parameter */
10331 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10333 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10334 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10335 goto nla_put_failure
;
10338 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10339 goto nla_put_failure
;
10341 if (nl80211_send_chandef(msg
, chandef
))
10342 goto nla_put_failure
;
10344 if (genlmsg_end(msg
, hdr
) < 0) {
10349 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10350 nl80211_mlme_mcgrp
.id
, gfp
);
10354 genlmsg_cancel(msg
, hdr
);
10358 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10359 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10361 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10362 struct wiphy
*wiphy
= wdev
->wiphy
;
10363 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10364 struct sk_buff
*msg
;
10365 struct nlattr
*pinfoattr
;
10368 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10370 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10374 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10380 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10381 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10382 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10383 goto nla_put_failure
;
10385 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10387 goto nla_put_failure
;
10389 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10390 goto nla_put_failure
;
10392 nla_nest_end(msg
, pinfoattr
);
10394 genlmsg_end(msg
, hdr
);
10396 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10397 nl80211_mlme_mcgrp
.id
, gfp
);
10401 genlmsg_cancel(msg
, hdr
);
10404 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10406 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10407 u64 cookie
, bool acked
, gfp_t gfp
)
10409 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10410 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10411 struct sk_buff
*msg
;
10415 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10417 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10422 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10428 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10429 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10430 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10431 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10432 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10433 goto nla_put_failure
;
10435 err
= genlmsg_end(msg
, hdr
);
10441 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10442 nl80211_mlme_mcgrp
.id
, gfp
);
10446 genlmsg_cancel(msg
, hdr
);
10449 EXPORT_SYMBOL(cfg80211_probe_status
);
10451 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10452 const u8
*frame
, size_t len
,
10453 int freq
, int sig_dbm
)
10455 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10456 struct sk_buff
*msg
;
10458 struct cfg80211_beacon_registration
*reg
;
10460 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10462 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10463 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10464 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10466 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10470 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10472 goto nla_put_failure
;
10474 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10476 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10478 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10479 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10480 goto nla_put_failure
;
10482 genlmsg_end(msg
, hdr
);
10484 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10486 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10490 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10492 genlmsg_cancel(msg
, hdr
);
10495 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10498 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10499 struct cfg80211_wowlan_wakeup
*wakeup
,
10502 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10503 struct sk_buff
*msg
;
10505 int err
, size
= 200;
10507 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10510 size
+= wakeup
->packet_present_len
;
10512 msg
= nlmsg_new(size
, gfp
);
10516 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10520 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10521 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10524 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10525 wdev
->netdev
->ifindex
))
10529 struct nlattr
*reasons
;
10531 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10533 if (wakeup
->disconnect
&&
10534 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10536 if (wakeup
->magic_pkt
&&
10537 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10539 if (wakeup
->gtk_rekey_failure
&&
10540 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10542 if (wakeup
->eap_identity_req
&&
10543 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10545 if (wakeup
->four_way_handshake
&&
10546 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10548 if (wakeup
->rfkill_release
&&
10549 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10552 if (wakeup
->pattern_idx
>= 0 &&
10553 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10554 wakeup
->pattern_idx
))
10557 if (wakeup
->tcp_match
)
10558 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10560 if (wakeup
->tcp_connlost
)
10562 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10564 if (wakeup
->tcp_nomoretokens
)
10566 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10568 if (wakeup
->packet
) {
10569 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10570 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10572 if (!wakeup
->packet_80211
) {
10574 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10576 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10579 if (wakeup
->packet_len
&&
10580 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10583 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10588 nla_nest_end(msg
, reasons
);
10591 err
= genlmsg_end(msg
, hdr
);
10595 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10596 nl80211_mlme_mcgrp
.id
, gfp
);
10602 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10605 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10606 enum nl80211_tdls_operation oper
,
10607 u16 reason_code
, gfp_t gfp
)
10609 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10610 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10611 struct sk_buff
*msg
;
10615 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10618 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10622 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10628 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10629 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10630 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10631 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10632 (reason_code
> 0 &&
10633 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10634 goto nla_put_failure
;
10636 err
= genlmsg_end(msg
, hdr
);
10642 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10643 nl80211_mlme_mcgrp
.id
, gfp
);
10647 genlmsg_cancel(msg
, hdr
);
10650 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10652 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10653 unsigned long state
,
10656 struct netlink_notify
*notify
= _notify
;
10657 struct cfg80211_registered_device
*rdev
;
10658 struct wireless_dev
*wdev
;
10659 struct cfg80211_beacon_registration
*reg
, *tmp
;
10661 if (state
!= NETLINK_URELEASE
)
10662 return NOTIFY_DONE
;
10666 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10667 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10668 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10670 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10671 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10673 if (reg
->nlportid
== notify
->portid
) {
10674 list_del(®
->list
);
10679 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10684 return NOTIFY_DONE
;
10687 static struct notifier_block nl80211_netlink_notifier
= {
10688 .notifier_call
= nl80211_netlink_notify
,
10691 void cfg80211_ft_event(struct net_device
*netdev
,
10692 struct cfg80211_ft_event_params
*ft_event
)
10694 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10695 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10696 struct sk_buff
*msg
;
10700 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10702 if (!ft_event
->target_ap
)
10705 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10709 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10715 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10716 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10717 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10719 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10720 if (ft_event
->ric_ies
)
10721 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10722 ft_event
->ric_ies
);
10724 err
= genlmsg_end(msg
, hdr
);
10730 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10731 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10733 EXPORT_SYMBOL(cfg80211_ft_event
);
10735 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10737 struct cfg80211_registered_device
*rdev
;
10738 struct sk_buff
*msg
;
10742 rdev
= wiphy_to_dev(wdev
->wiphy
);
10743 if (!rdev
->crit_proto_nlportid
)
10746 nlportid
= rdev
->crit_proto_nlportid
;
10747 rdev
->crit_proto_nlportid
= 0;
10749 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10753 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10755 goto nla_put_failure
;
10757 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10758 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10759 goto nla_put_failure
;
10761 genlmsg_end(msg
, hdr
);
10763 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10768 genlmsg_cancel(msg
, hdr
);
10772 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10774 /* initialisation/exit functions */
10776 int nl80211_init(void)
10780 err
= genl_register_family_with_ops(&nl80211_fam
,
10781 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10785 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10789 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10793 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10797 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10801 #ifdef CONFIG_NL80211_TESTMODE
10802 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10807 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10813 genl_unregister_family(&nl80211_fam
);
10817 void nl80211_exit(void)
10819 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10820 genl_unregister_family(&nl80211_fam
);