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
},
381 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
382 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
384 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
385 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
386 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
389 /* policy for the key attributes */
390 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
391 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
392 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
393 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
394 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
395 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
396 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
397 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
398 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
401 /* policy for the key default flags */
402 static const struct nla_policy
403 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
404 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
405 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
408 /* policy for WoWLAN attributes */
409 static const struct nla_policy
410 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
411 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
412 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
413 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
414 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
415 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
416 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
417 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
418 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
419 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
422 static const struct nla_policy
423 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
424 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
425 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
426 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
427 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
428 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
430 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
431 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
434 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
436 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
437 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
438 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
441 /* policy for GTK rekey offload attributes */
442 static const struct nla_policy
443 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
444 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
445 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
446 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
449 static const struct nla_policy
450 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
451 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
452 .len
= IEEE80211_MAX_SSID_LEN
},
453 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
456 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
457 struct netlink_callback
*cb
,
458 struct cfg80211_registered_device
**rdev
,
459 struct wireless_dev
**wdev
)
464 mutex_lock(&cfg80211_mutex
);
467 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
468 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
473 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
474 nl80211_fam
.attrbuf
);
476 err
= PTR_ERR(*wdev
);
479 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
480 /* 0 is the first index - add 1 to parse only once */
481 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
482 cb
->args
[1] = (*wdev
)->identifier
;
484 /* subtract the 1 again here */
485 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
486 struct wireless_dev
*tmp
;
492 *rdev
= wiphy_to_dev(wiphy
);
495 mutex_lock(&(*rdev
)->devlist_mtx
);
496 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
497 if (tmp
->identifier
== cb
->args
[1]) {
502 mutex_unlock(&(*rdev
)->devlist_mtx
);
510 cfg80211_lock_rdev(*rdev
);
512 mutex_unlock(&cfg80211_mutex
);
515 mutex_unlock(&cfg80211_mutex
);
520 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
522 cfg80211_unlock_rdev(rdev
);
527 static bool is_valid_ie_attr(const struct nlattr
*attr
)
535 pos
= nla_data(attr
);
556 /* message building helper */
557 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
560 /* since there is no private header just add the generic one */
561 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
564 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
565 struct ieee80211_channel
*chan
,
568 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
570 goto nla_put_failure
;
572 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
573 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
574 goto nla_put_failure
;
575 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
576 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
577 goto nla_put_failure
;
578 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
579 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
580 goto nla_put_failure
;
581 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
582 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
583 goto nla_put_failure
;
587 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
589 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
591 goto nla_put_failure
;
592 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
594 goto nla_put_failure
;
599 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
600 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
601 goto nla_put_failure
;
602 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
603 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
604 goto nla_put_failure
;
605 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
606 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
607 goto nla_put_failure
;
608 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
609 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
610 goto nla_put_failure
;
613 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
614 DBM_TO_MBM(chan
->max_power
)))
615 goto nla_put_failure
;
623 /* netlink command implementations */
630 bool def_uni
, def_multi
;
633 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
635 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
636 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
641 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
642 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
651 if (tb
[NL80211_KEY_IDX
])
652 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
654 if (tb
[NL80211_KEY_DATA
]) {
655 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
656 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
659 if (tb
[NL80211_KEY_SEQ
]) {
660 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
661 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
664 if (tb
[NL80211_KEY_CIPHER
])
665 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
667 if (tb
[NL80211_KEY_TYPE
]) {
668 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
669 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
673 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
674 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
675 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
676 tb
[NL80211_KEY_DEFAULT_TYPES
],
677 nl80211_key_default_policy
);
681 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
682 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
688 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
690 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
691 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
692 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
695 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
696 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
697 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
700 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
701 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
703 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
704 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
706 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
707 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
716 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
717 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
718 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
722 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
723 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
724 int err
= nla_parse_nested(
725 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
726 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
727 nl80211_key_default_policy
);
731 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
732 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
738 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
742 memset(k
, 0, sizeof(*k
));
746 if (info
->attrs
[NL80211_ATTR_KEY
])
747 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
749 err
= nl80211_parse_key_old(info
, k
);
754 if (k
->def
&& k
->defmgmt
)
758 if (k
->def_uni
|| !k
->def_multi
)
764 if (k
->idx
< 4 || k
->idx
> 5)
767 if (k
->idx
< 0 || k
->idx
> 3)
770 if (k
->idx
< 0 || k
->idx
> 5)
778 static struct cfg80211_cached_keys
*
779 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
780 struct nlattr
*keys
, bool *no_ht
)
782 struct key_parse parse
;
784 struct cfg80211_cached_keys
*result
;
785 int rem
, err
, def
= 0;
787 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
789 return ERR_PTR(-ENOMEM
);
792 result
->defmgmt
= -1;
794 nla_for_each_nested(key
, keys
, rem
) {
795 memset(&parse
, 0, sizeof(parse
));
798 err
= nl80211_parse_key_new(key
, &parse
);
804 if (parse
.idx
< 0 || parse
.idx
> 4)
810 result
->def
= parse
.idx
;
811 if (!parse
.def_uni
|| !parse
.def_multi
)
813 } else if (parse
.defmgmt
)
815 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
816 parse
.idx
, false, NULL
);
819 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
820 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
821 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
822 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
824 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
825 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
837 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
839 ASSERT_WDEV_LOCK(wdev
);
841 switch (wdev
->iftype
) {
842 case NL80211_IFTYPE_AP
:
843 case NL80211_IFTYPE_AP_VLAN
:
844 case NL80211_IFTYPE_P2P_GO
:
845 case NL80211_IFTYPE_MESH_POINT
:
847 case NL80211_IFTYPE_ADHOC
:
848 if (!wdev
->current_bss
)
851 case NL80211_IFTYPE_STATION
:
852 case NL80211_IFTYPE_P2P_CLIENT
:
853 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
863 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
865 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
869 goto nla_put_failure
;
873 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
874 goto nla_put_failure
;
879 nla_nest_end(msg
, nl_modes
);
886 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
890 struct nlattr
*nl_combis
;
893 nl_combis
= nla_nest_start(msg
,
894 NL80211_ATTR_INTERFACE_COMBINATIONS
);
896 goto nla_put_failure
;
898 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
899 const struct ieee80211_iface_combination
*c
;
900 struct nlattr
*nl_combi
, *nl_limits
;
902 c
= &wiphy
->iface_combinations
[i
];
904 nl_combi
= nla_nest_start(msg
, i
+ 1);
906 goto nla_put_failure
;
908 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
910 goto nla_put_failure
;
912 for (j
= 0; j
< c
->n_limits
; j
++) {
913 struct nlattr
*nl_limit
;
915 nl_limit
= nla_nest_start(msg
, j
+ 1);
917 goto nla_put_failure
;
918 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
920 goto nla_put_failure
;
921 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
923 goto nla_put_failure
;
924 nla_nest_end(msg
, nl_limit
);
927 nla_nest_end(msg
, nl_limits
);
929 if (c
->beacon_int_infra_match
&&
930 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
931 goto nla_put_failure
;
932 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
933 c
->num_different_channels
) ||
934 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
936 goto nla_put_failure
;
938 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
939 c
->radar_detect_widths
))
940 goto nla_put_failure
;
942 nla_nest_end(msg
, nl_combi
);
945 nla_nest_end(msg
, nl_combis
);
953 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
956 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
.tcp
;
957 struct nlattr
*nl_tcp
;
962 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
966 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
967 tcp
->data_payload_max
))
970 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
971 tcp
->data_payload_max
))
974 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
977 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
978 sizeof(*tcp
->tok
), tcp
->tok
))
981 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
982 tcp
->data_interval_max
))
985 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
986 tcp
->wake_payload_max
))
989 nla_nest_end(msg
, nl_tcp
);
993 static int nl80211_send_wowlan(struct sk_buff
*msg
,
994 struct cfg80211_registered_device
*dev
,
997 struct nlattr
*nl_wowlan
;
999 if (!dev
->wiphy
.wowlan
.flags
&& !dev
->wiphy
.wowlan
.n_patterns
)
1002 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1006 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1007 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1008 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1009 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1010 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1011 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1012 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1013 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1014 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1015 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1016 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1017 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1018 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1019 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1020 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1021 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1024 if (dev
->wiphy
.wowlan
.n_patterns
) {
1025 struct nl80211_wowlan_pattern_support pat
= {
1026 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1027 .min_pattern_len
= dev
->wiphy
.wowlan
.pattern_min_len
,
1028 .max_pattern_len
= dev
->wiphy
.wowlan
.pattern_max_len
,
1029 .max_pkt_offset
= dev
->wiphy
.wowlan
.max_pkt_offset
,
1032 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1037 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
1040 nla_nest_end(msg
, nl_wowlan
);
1046 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1047 struct ieee80211_supported_band
*sband
)
1049 struct nlattr
*nl_rates
, *nl_rate
;
1050 struct ieee80211_rate
*rate
;
1054 if (sband
->ht_cap
.ht_supported
&&
1055 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1056 sizeof(sband
->ht_cap
.mcs
),
1057 &sband
->ht_cap
.mcs
) ||
1058 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1059 sband
->ht_cap
.cap
) ||
1060 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1061 sband
->ht_cap
.ampdu_factor
) ||
1062 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1063 sband
->ht_cap
.ampdu_density
)))
1067 if (sband
->vht_cap
.vht_supported
&&
1068 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1069 sizeof(sband
->vht_cap
.vht_mcs
),
1070 &sband
->vht_cap
.vht_mcs
) ||
1071 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1072 sband
->vht_cap
.cap
)))
1076 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1080 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1081 nl_rate
= nla_nest_start(msg
, i
);
1085 rate
= &sband
->bitrates
[i
];
1086 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1089 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1091 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1094 nla_nest_end(msg
, nl_rate
);
1097 nla_nest_end(msg
, nl_rates
);
1103 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1104 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1107 struct nlattr
*nl_ftypes
, *nl_ifs
;
1108 enum nl80211_iftype ift
;
1114 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1118 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1119 nl_ftypes
= nla_nest_start(msg
, ift
);
1123 stypes
= mgmt_stypes
[ift
].tx
;
1126 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1127 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1132 nla_nest_end(msg
, nl_ftypes
);
1135 nla_nest_end(msg
, nl_ifs
);
1137 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1141 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1142 nl_ftypes
= nla_nest_start(msg
, ift
);
1146 stypes
= mgmt_stypes
[ift
].rx
;
1149 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1150 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1155 nla_nest_end(msg
, nl_ftypes
);
1157 nla_nest_end(msg
, nl_ifs
);
1162 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1163 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1164 int flags
, bool split
, long *split_start
,
1165 long *band_start
, long *chan_start
)
1168 struct nlattr
*nl_bands
, *nl_band
;
1169 struct nlattr
*nl_freqs
, *nl_freq
;
1170 struct nlattr
*nl_cmds
;
1171 enum ieee80211_band band
;
1172 struct ieee80211_channel
*chan
;
1174 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1175 dev
->wiphy
.mgmt_stypes
;
1176 long start
= 0, start_chan
= 0, start_band
= 0;
1179 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1183 /* allow always using the variables */
1185 split_start
= &start
;
1186 band_start
= &start_band
;
1187 chan_start
= &start_chan
;
1190 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1191 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1192 wiphy_name(&dev
->wiphy
)) ||
1193 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1194 cfg80211_rdev_list_generation
))
1195 goto nla_put_failure
;
1197 switch (*split_start
) {
1199 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1200 dev
->wiphy
.retry_short
) ||
1201 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1202 dev
->wiphy
.retry_long
) ||
1203 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1204 dev
->wiphy
.frag_threshold
) ||
1205 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1206 dev
->wiphy
.rts_threshold
) ||
1207 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1208 dev
->wiphy
.coverage_class
) ||
1209 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1210 dev
->wiphy
.max_scan_ssids
) ||
1211 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1212 dev
->wiphy
.max_sched_scan_ssids
) ||
1213 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1214 dev
->wiphy
.max_scan_ie_len
) ||
1215 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1216 dev
->wiphy
.max_sched_scan_ie_len
) ||
1217 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1218 dev
->wiphy
.max_match_sets
))
1219 goto nla_put_failure
;
1221 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1222 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1223 goto nla_put_failure
;
1224 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1225 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1226 goto nla_put_failure
;
1227 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1228 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1229 goto nla_put_failure
;
1230 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1231 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1232 goto nla_put_failure
;
1233 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1234 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1235 goto nla_put_failure
;
1236 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1237 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1238 goto nla_put_failure
;
1244 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1245 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1246 dev
->wiphy
.cipher_suites
))
1247 goto nla_put_failure
;
1249 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1250 dev
->wiphy
.max_num_pmkids
))
1251 goto nla_put_failure
;
1253 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1254 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1255 goto nla_put_failure
;
1257 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1258 dev
->wiphy
.available_antennas_tx
) ||
1259 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1260 dev
->wiphy
.available_antennas_rx
))
1261 goto nla_put_failure
;
1263 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1264 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1265 dev
->wiphy
.probe_resp_offload
))
1266 goto nla_put_failure
;
1268 if ((dev
->wiphy
.available_antennas_tx
||
1269 dev
->wiphy
.available_antennas_rx
) &&
1270 dev
->ops
->get_antenna
) {
1271 u32 tx_ant
= 0, rx_ant
= 0;
1273 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1275 if (nla_put_u32(msg
,
1276 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1279 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1281 goto nla_put_failure
;
1289 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1290 dev
->wiphy
.interface_modes
))
1291 goto nla_put_failure
;
1296 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1298 goto nla_put_failure
;
1300 for (band
= *band_start
; band
< IEEE80211_NUM_BANDS
; band
++) {
1301 struct ieee80211_supported_band
*sband
;
1303 sband
= dev
->wiphy
.bands
[band
];
1308 nl_band
= nla_nest_start(msg
, band
);
1310 goto nla_put_failure
;
1312 switch (*chan_start
) {
1314 if (nl80211_send_band_rateinfo(msg
, sband
))
1315 goto nla_put_failure
;
1320 /* add frequencies */
1321 nl_freqs
= nla_nest_start(
1322 msg
, NL80211_BAND_ATTR_FREQS
);
1324 goto nla_put_failure
;
1326 for (i
= *chan_start
- 1;
1327 i
< sband
->n_channels
;
1329 nl_freq
= nla_nest_start(msg
, i
);
1331 goto nla_put_failure
;
1333 chan
= &sband
->channels
[i
];
1335 if (nl80211_msg_put_channel(msg
, chan
,
1337 goto nla_put_failure
;
1339 nla_nest_end(msg
, nl_freq
);
1343 if (i
< sband
->n_channels
)
1344 *chan_start
= i
+ 2;
1347 nla_nest_end(msg
, nl_freqs
);
1350 nla_nest_end(msg
, nl_band
);
1353 /* start again here */
1359 nla_nest_end(msg
, nl_bands
);
1361 if (band
< IEEE80211_NUM_BANDS
)
1362 *band_start
= band
+ 1;
1366 /* if bands & channels are done, continue outside */
1367 if (*band_start
== 0 && *chan_start
== 0)
1372 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1374 goto nla_put_failure
;
1377 #define CMD(op, n) \
1379 if (dev->ops->op) { \
1381 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1382 goto nla_put_failure; \
1386 CMD(add_virtual_intf
, NEW_INTERFACE
);
1387 CMD(change_virtual_intf
, SET_INTERFACE
);
1388 CMD(add_key
, NEW_KEY
);
1389 CMD(start_ap
, START_AP
);
1390 CMD(add_station
, NEW_STATION
);
1391 CMD(add_mpath
, NEW_MPATH
);
1392 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1393 CMD(change_bss
, SET_BSS
);
1394 CMD(auth
, AUTHENTICATE
);
1395 CMD(assoc
, ASSOCIATE
);
1396 CMD(deauth
, DEAUTHENTICATE
);
1397 CMD(disassoc
, DISASSOCIATE
);
1398 CMD(join_ibss
, JOIN_IBSS
);
1399 CMD(join_mesh
, JOIN_MESH
);
1400 CMD(set_pmksa
, SET_PMKSA
);
1401 CMD(del_pmksa
, DEL_PMKSA
);
1402 CMD(flush_pmksa
, FLUSH_PMKSA
);
1403 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1404 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1405 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1406 CMD(mgmt_tx
, FRAME
);
1407 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1408 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1410 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1411 goto nla_put_failure
;
1413 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1414 dev
->ops
->join_mesh
) {
1416 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1417 goto nla_put_failure
;
1419 CMD(set_wds_peer
, SET_WDS_PEER
);
1420 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1421 CMD(tdls_mgmt
, TDLS_MGMT
);
1422 CMD(tdls_oper
, TDLS_OPER
);
1424 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1425 CMD(sched_scan_start
, START_SCHED_SCAN
);
1426 CMD(probe_client
, PROBE_CLIENT
);
1427 CMD(set_noack_map
, SET_NOACK_MAP
);
1428 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1430 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1431 goto nla_put_failure
;
1433 CMD(start_p2p_device
, START_P2P_DEVICE
);
1434 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1436 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1437 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1440 #ifdef CONFIG_NL80211_TESTMODE
1441 CMD(testmode_cmd
, TESTMODE
);
1446 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1448 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1449 goto nla_put_failure
;
1452 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1454 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1455 goto nla_put_failure
;
1458 nla_nest_end(msg
, nl_cmds
);
1463 if (dev
->ops
->remain_on_channel
&&
1464 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1466 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1467 dev
->wiphy
.max_remain_on_channel_duration
))
1468 goto nla_put_failure
;
1470 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1471 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1472 goto nla_put_failure
;
1474 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1475 goto nla_put_failure
;
1481 if (nl80211_send_wowlan(msg
, dev
, split
))
1482 goto nla_put_failure
;
1490 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1491 dev
->wiphy
.software_iftypes
))
1492 goto nla_put_failure
;
1494 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
, split
))
1495 goto nla_put_failure
;
1501 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1502 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1503 dev
->wiphy
.ap_sme_capa
))
1504 goto nla_put_failure
;
1506 features
= dev
->wiphy
.features
;
1508 * We can only add the per-channel limit information if the
1509 * dump is split, otherwise it makes it too big. Therefore
1510 * only advertise it in that case.
1513 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1514 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1515 goto nla_put_failure
;
1517 if (dev
->wiphy
.ht_capa_mod_mask
&&
1518 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1519 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1520 dev
->wiphy
.ht_capa_mod_mask
))
1521 goto nla_put_failure
;
1523 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1524 dev
->wiphy
.max_acl_mac_addrs
&&
1525 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1526 dev
->wiphy
.max_acl_mac_addrs
))
1527 goto nla_put_failure
;
1529 if (dev
->wiphy
.n_vendor_commands
) {
1530 const struct nl80211_vendor_cmd_info
*info
;
1531 struct nlattr
*nested
;
1533 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1535 goto nla_put_failure
;
1537 for (i
= 0; i
< dev
->wiphy
.n_vendor_commands
; i
++) {
1538 info
= &dev
->wiphy
.vendor_commands
[i
].info
;
1539 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1540 goto nla_put_failure
;
1542 nla_nest_end(msg
, nested
);
1545 if (dev
->wiphy
.n_vendor_events
) {
1546 const struct nl80211_vendor_cmd_info
*info
;
1547 struct nlattr
*nested
;
1549 nested
= nla_nest_start(msg
,
1550 NL80211_ATTR_VENDOR_EVENTS
);
1552 goto nla_put_failure
;
1554 for (i
= 0; i
< dev
->wiphy
.n_vendor_events
; i
++) {
1555 info
= &dev
->wiphy
.vendor_events
[i
];
1556 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1557 goto nla_put_failure
;
1559 nla_nest_end(msg
, nested
);
1563 * Any information below this point is only available to
1564 * applications that can deal with it being split. This
1565 * helps ensure that newly added capabilities don't break
1566 * older tools by overrunning their buffers.
1568 * We still increment split_start so that in the split
1569 * case we'll continue with more data in the next round,
1570 * but break unconditionally so unsplit data stops here.
1575 if (dev
->wiphy
.extended_capabilities
&&
1576 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1577 dev
->wiphy
.extended_capabilities_len
,
1578 dev
->wiphy
.extended_capabilities
) ||
1579 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1580 dev
->wiphy
.extended_capabilities_len
,
1581 dev
->wiphy
.extended_capabilities_mask
)))
1582 goto nla_put_failure
;
1584 if (dev
->wiphy
.vht_capa_mod_mask
&&
1585 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1586 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1587 dev
->wiphy
.vht_capa_mod_mask
))
1588 goto nla_put_failure
;
1594 return genlmsg_end(msg
, hdr
);
1597 genlmsg_cancel(msg
, hdr
);
1601 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1604 int start
= cb
->args
[0];
1605 struct cfg80211_registered_device
*dev
;
1606 s64 filter_wiphy
= -1;
1611 /* will be zeroed in nlmsg_parse() */
1612 tb
= kmalloc(sizeof(*tb
) * (NL80211_ATTR_MAX
+ 1), GFP_KERNEL
);
1616 mutex_lock(&cfg80211_mutex
);
1617 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1618 tb
, NL80211_ATTR_MAX
, nl80211_policy
);
1620 split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1621 if (tb
[NL80211_ATTR_WIPHY
])
1622 filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1623 if (tb
[NL80211_ATTR_WDEV
])
1624 filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1625 if (tb
[NL80211_ATTR_IFINDEX
]) {
1626 struct net_device
*netdev
;
1627 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1629 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1631 mutex_unlock(&cfg80211_mutex
);
1635 if (netdev
->ieee80211_ptr
) {
1637 netdev
->ieee80211_ptr
->wiphy
);
1638 filter_wiphy
= dev
->wiphy_idx
;
1645 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1646 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1650 if (filter_wiphy
!= -1 && dev
->wiphy_idx
!= filter_wiphy
)
1652 /* attempt to fit multiple wiphy data chunks into the skb */
1654 ret
= nl80211_send_wiphy(dev
, skb
,
1655 NETLINK_CB(cb
->skb
).portid
,
1658 split
, &cb
->args
[1],
1663 * If sending the wiphy data didn't fit (ENOBUFS
1664 * or EMSGSIZE returned), this SKB is still
1665 * empty (so it's not too big because another
1666 * wiphy dataset is already in the skb) and
1667 * we've not tried to adjust the dump allocation
1668 * yet ... then adjust the alloc size to be
1669 * bigger, and return 1 but with the empty skb.
1670 * This results in an empty message being RX'ed
1671 * in userspace, but that is ignored.
1673 * We can then retry with the larger buffer.
1675 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1677 cb
->min_dump_alloc
< 4096) {
1678 cb
->min_dump_alloc
= 4096;
1679 mutex_unlock(&cfg80211_mutex
);
1685 } while (cb
->args
[1] > 0);
1688 mutex_unlock(&cfg80211_mutex
);
1695 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1697 struct sk_buff
*msg
;
1698 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1700 msg
= nlmsg_new(4096, GFP_KERNEL
);
1704 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1705 false, NULL
, NULL
, NULL
) < 0) {
1710 return genlmsg_reply(msg
, info
);
1713 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1714 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1715 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1716 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1717 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1718 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1721 static int parse_txq_params(struct nlattr
*tb
[],
1722 struct ieee80211_txq_params
*txq_params
)
1724 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1725 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1726 !tb
[NL80211_TXQ_ATTR_AIFS
])
1729 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1730 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1731 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1732 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1733 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1735 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1741 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1744 * You can only set the channel explicitly for WDS interfaces,
1745 * all others have their channel managed via their respective
1746 * "establish a connection" command (connect, join, ...)
1748 * For AP/GO and mesh mode, the channel can be set with the
1749 * channel userspace API, but is only stored and passed to the
1750 * low-level driver when the AP starts or the mesh is joined.
1751 * This is for backward compatibility, userspace can also give
1752 * the channel in the start-ap or join-mesh commands instead.
1754 * Monitors are special as they are normally slaved to
1755 * whatever else is going on, so they have their own special
1756 * operation to set the monitor channel if possible.
1759 wdev
->iftype
== NL80211_IFTYPE_AP
||
1760 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1761 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1762 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1765 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1766 struct genl_info
*info
,
1767 struct cfg80211_chan_def
*chandef
)
1771 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1774 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1776 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1777 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1778 chandef
->center_freq1
= control_freq
;
1779 chandef
->center_freq2
= 0;
1781 /* Primary channel not allowed */
1782 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1785 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1786 enum nl80211_channel_type chantype
;
1788 chantype
= nla_get_u32(
1789 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1792 case NL80211_CHAN_NO_HT
:
1793 case NL80211_CHAN_HT20
:
1794 case NL80211_CHAN_HT40PLUS
:
1795 case NL80211_CHAN_HT40MINUS
:
1796 cfg80211_chandef_create(chandef
, chandef
->chan
,
1802 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1804 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1805 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1806 chandef
->center_freq1
=
1808 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1809 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1810 chandef
->center_freq2
=
1812 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1815 if (!cfg80211_chandef_valid(chandef
))
1818 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1819 IEEE80211_CHAN_DISABLED
))
1825 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1826 struct wireless_dev
*wdev
,
1827 struct genl_info
*info
)
1829 struct cfg80211_chan_def chandef
;
1831 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1834 iftype
= wdev
->iftype
;
1836 if (!nl80211_can_set_dev_channel(wdev
))
1839 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1843 mutex_lock(&rdev
->devlist_mtx
);
1845 case NL80211_IFTYPE_AP
:
1846 case NL80211_IFTYPE_P2P_GO
:
1847 if (wdev
->beacon_interval
) {
1851 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1855 wdev
->preset_chandef
= chandef
;
1858 case NL80211_IFTYPE_MESH_POINT
:
1859 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1861 case NL80211_IFTYPE_MONITOR
:
1862 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1867 mutex_unlock(&rdev
->devlist_mtx
);
1872 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1875 struct net_device
*netdev
= info
->user_ptr
[1];
1877 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1880 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1882 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1883 struct net_device
*dev
= info
->user_ptr
[1];
1884 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1887 if (!info
->attrs
[NL80211_ATTR_MAC
])
1890 if (netif_running(dev
))
1893 if (!rdev
->ops
->set_wds_peer
)
1896 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1899 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1900 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1904 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1906 struct cfg80211_registered_device
*rdev
;
1907 struct net_device
*netdev
= NULL
;
1908 struct wireless_dev
*wdev
;
1909 int result
= 0, rem_txq_params
= 0;
1910 struct nlattr
*nl_txq_params
;
1912 u8 retry_short
= 0, retry_long
= 0;
1913 u32 frag_threshold
= 0, rts_threshold
= 0;
1914 u8 coverage_class
= 0;
1917 * Try to find the wiphy and netdev. Normally this
1918 * function shouldn't need the netdev, but this is
1919 * done for backward compatibility -- previously
1920 * setting the channel was done per wiphy, but now
1921 * it is per netdev. Previous userland like hostapd
1922 * also passed a netdev to set_wiphy, so that it is
1923 * possible to let that go to the right netdev!
1925 mutex_lock(&cfg80211_mutex
);
1927 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1928 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1930 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1931 if (netdev
&& netdev
->ieee80211_ptr
) {
1932 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1933 mutex_lock(&rdev
->mtx
);
1939 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1942 mutex_unlock(&cfg80211_mutex
);
1943 return PTR_ERR(rdev
);
1949 mutex_lock(&rdev
->mtx
);
1951 wdev
= netdev
->ieee80211_ptr
;
1954 * end workaround code, by now the rdev is available
1955 * and locked, and wdev may or may not be NULL.
1958 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1959 result
= cfg80211_dev_rename(
1960 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1962 mutex_unlock(&cfg80211_mutex
);
1967 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1968 struct ieee80211_txq_params txq_params
;
1969 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1971 if (!rdev
->ops
->set_txq_params
) {
1972 result
= -EOPNOTSUPP
;
1981 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1982 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1987 if (!netif_running(netdev
)) {
1992 nla_for_each_nested(nl_txq_params
,
1993 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1995 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1996 nla_data(nl_txq_params
),
1997 nla_len(nl_txq_params
),
1999 result
= parse_txq_params(tb
, &txq_params
);
2003 result
= rdev_set_txq_params(rdev
, netdev
,
2010 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2011 result
= __nl80211_set_channel(rdev
,
2012 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
2018 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2019 struct wireless_dev
*txp_wdev
= wdev
;
2020 enum nl80211_tx_power_setting type
;
2023 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2026 if (!rdev
->ops
->set_tx_power
) {
2027 result
= -EOPNOTSUPP
;
2031 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2032 type
= nla_get_u32(info
->attrs
[idx
]);
2034 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2035 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
2040 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2041 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2042 mbm
= nla_get_u32(info
->attrs
[idx
]);
2045 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2050 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2051 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2053 if ((!rdev
->wiphy
.available_antennas_tx
&&
2054 !rdev
->wiphy
.available_antennas_rx
) ||
2055 !rdev
->ops
->set_antenna
) {
2056 result
= -EOPNOTSUPP
;
2060 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2061 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2063 /* reject antenna configurations which don't match the
2064 * available antenna masks, except for the "all" mask */
2065 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2066 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2071 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2072 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2074 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2081 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2082 retry_short
= nla_get_u8(
2083 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2084 if (retry_short
== 0) {
2088 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2091 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2092 retry_long
= nla_get_u8(
2093 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2094 if (retry_long
== 0) {
2098 changed
|= WIPHY_PARAM_RETRY_LONG
;
2101 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2102 frag_threshold
= nla_get_u32(
2103 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2104 if (frag_threshold
< 256) {
2108 if (frag_threshold
!= (u32
) -1) {
2110 * Fragments (apart from the last one) are required to
2111 * have even length. Make the fragmentation code
2112 * simpler by stripping LSB should someone try to use
2113 * odd threshold value.
2115 frag_threshold
&= ~0x1;
2117 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2120 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2121 rts_threshold
= nla_get_u32(
2122 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2123 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2126 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2127 coverage_class
= nla_get_u8(
2128 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2129 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2133 u8 old_retry_short
, old_retry_long
;
2134 u32 old_frag_threshold
, old_rts_threshold
;
2135 u8 old_coverage_class
;
2137 if (!rdev
->ops
->set_wiphy_params
) {
2138 result
= -EOPNOTSUPP
;
2142 old_retry_short
= rdev
->wiphy
.retry_short
;
2143 old_retry_long
= rdev
->wiphy
.retry_long
;
2144 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2145 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2146 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2148 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2149 rdev
->wiphy
.retry_short
= retry_short
;
2150 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2151 rdev
->wiphy
.retry_long
= retry_long
;
2152 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2153 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2154 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2155 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2156 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2157 rdev
->wiphy
.coverage_class
= coverage_class
;
2159 result
= rdev_set_wiphy_params(rdev
, changed
);
2161 rdev
->wiphy
.retry_short
= old_retry_short
;
2162 rdev
->wiphy
.retry_long
= old_retry_long
;
2163 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2164 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2165 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2170 mutex_unlock(&rdev
->mtx
);
2176 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2178 return (u64
)wdev
->identifier
|
2179 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2182 static int nl80211_send_chandef(struct sk_buff
*msg
,
2183 struct cfg80211_chan_def
*chandef
)
2185 WARN_ON(!cfg80211_chandef_valid(chandef
));
2187 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2188 chandef
->chan
->center_freq
))
2190 switch (chandef
->width
) {
2191 case NL80211_CHAN_WIDTH_20_NOHT
:
2192 case NL80211_CHAN_WIDTH_20
:
2193 case NL80211_CHAN_WIDTH_40
:
2194 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2195 cfg80211_get_chandef_type(chandef
)))
2201 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2203 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2205 if (chandef
->center_freq2
&&
2206 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2211 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2212 struct cfg80211_registered_device
*rdev
,
2213 struct wireless_dev
*wdev
)
2215 struct net_device
*dev
= wdev
->netdev
;
2218 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2223 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2224 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2225 goto nla_put_failure
;
2227 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2228 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2229 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2230 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2231 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2232 rdev
->devlist_generation
^
2233 (cfg80211_rdev_list_generation
<< 2)))
2234 goto nla_put_failure
;
2236 if (rdev
->ops
->get_channel
) {
2238 struct cfg80211_chan_def chandef
;
2240 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2242 if (nl80211_send_chandef(msg
, &chandef
))
2243 goto nla_put_failure
;
2247 if (wdev
->ssid_len
) {
2248 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2249 goto nla_put_failure
;
2252 return genlmsg_end(msg
, hdr
);
2255 genlmsg_cancel(msg
, hdr
);
2259 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2263 int wp_start
= cb
->args
[0];
2264 int if_start
= cb
->args
[1];
2265 struct cfg80211_registered_device
*rdev
;
2266 struct wireless_dev
*wdev
;
2268 mutex_lock(&cfg80211_mutex
);
2269 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2270 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2272 if (wp_idx
< wp_start
) {
2278 mutex_lock(&rdev
->devlist_mtx
);
2279 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2280 if (if_idx
< if_start
) {
2284 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2285 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2287 mutex_unlock(&rdev
->devlist_mtx
);
2292 mutex_unlock(&rdev
->devlist_mtx
);
2297 mutex_unlock(&cfg80211_mutex
);
2299 cb
->args
[0] = wp_idx
;
2300 cb
->args
[1] = if_idx
;
2305 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2307 struct sk_buff
*msg
;
2308 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2309 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2311 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2315 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2321 return genlmsg_reply(msg
, info
);
2324 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2325 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2326 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2327 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2328 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2329 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2332 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2334 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2342 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2343 nla
, mntr_flags_policy
))
2346 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2348 *mntrflags
|= (1<<flag
);
2353 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2354 struct net_device
*netdev
, u8 use_4addr
,
2355 enum nl80211_iftype iftype
)
2358 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2364 case NL80211_IFTYPE_AP_VLAN
:
2365 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2368 case NL80211_IFTYPE_STATION
:
2369 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2379 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2381 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2382 struct vif_params params
;
2384 enum nl80211_iftype otype
, ntype
;
2385 struct net_device
*dev
= info
->user_ptr
[1];
2386 u32 _flags
, *flags
= NULL
;
2387 bool change
= false;
2389 memset(¶ms
, 0, sizeof(params
));
2391 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2393 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2394 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2397 if (ntype
> NL80211_IFTYPE_MAX
)
2401 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2402 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2404 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2406 if (netif_running(dev
))
2410 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2411 IEEE80211_MAX_MESH_ID_LEN
);
2412 wdev
->mesh_id_up_len
=
2413 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2414 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2415 wdev
->mesh_id_up_len
);
2419 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2420 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2422 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2426 params
.use_4addr
= -1;
2429 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2430 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2432 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2442 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2446 if (!err
&& params
.use_4addr
!= -1)
2447 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2452 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2454 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2455 struct vif_params params
;
2456 struct wireless_dev
*wdev
;
2457 struct sk_buff
*msg
;
2459 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2462 memset(¶ms
, 0, sizeof(params
));
2464 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2467 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2468 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2469 if (type
> NL80211_IFTYPE_MAX
)
2473 if (!rdev
->ops
->add_virtual_intf
||
2474 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2477 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2478 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2480 if (!is_valid_ether_addr(params
.macaddr
))
2481 return -EADDRNOTAVAIL
;
2484 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2485 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2486 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2491 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2495 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2496 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2498 wdev
= rdev_add_virtual_intf(rdev
,
2499 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2500 type
, err
? NULL
: &flags
, ¶ms
);
2503 return PTR_ERR(wdev
);
2507 case NL80211_IFTYPE_MESH_POINT
:
2508 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2511 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2512 IEEE80211_MAX_MESH_ID_LEN
);
2513 wdev
->mesh_id_up_len
=
2514 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2515 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2516 wdev
->mesh_id_up_len
);
2519 case NL80211_IFTYPE_P2P_DEVICE
:
2521 * P2P Device doesn't have a netdev, so doesn't go
2522 * through the netdev notifier and must be added here
2524 mutex_init(&wdev
->mtx
);
2525 INIT_LIST_HEAD(&wdev
->event_list
);
2526 spin_lock_init(&wdev
->event_lock
);
2527 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2528 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2530 mutex_lock(&rdev
->devlist_mtx
);
2531 wdev
->identifier
= ++rdev
->wdev_id
;
2532 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2533 rdev
->devlist_generation
++;
2534 mutex_unlock(&rdev
->devlist_mtx
);
2540 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2546 return genlmsg_reply(msg
, info
);
2549 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2551 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2552 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2554 if (!rdev
->ops
->del_virtual_intf
)
2558 * If we remove a wireless device without a netdev then clear
2559 * user_ptr[1] so that nl80211_post_doit won't dereference it
2560 * to check if it needs to do dev_put(). Otherwise it crashes
2561 * since the wdev has been freed, unlike with a netdev where
2562 * we need the dev_put() for the netdev to really be freed.
2565 info
->user_ptr
[1] = NULL
;
2567 return rdev_del_virtual_intf(rdev
, wdev
);
2570 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2572 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2573 struct net_device
*dev
= info
->user_ptr
[1];
2576 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2579 if (!rdev
->ops
->set_noack_map
)
2582 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2584 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2587 struct get_key_cookie
{
2588 struct sk_buff
*msg
;
2593 static void get_key_callback(void *c
, struct key_params
*params
)
2596 struct get_key_cookie
*cookie
= c
;
2599 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2600 params
->key_len
, params
->key
)) ||
2602 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2603 params
->seq_len
, params
->seq
)) ||
2605 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2607 goto nla_put_failure
;
2609 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2611 goto nla_put_failure
;
2614 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2615 params
->key_len
, params
->key
)) ||
2617 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2618 params
->seq_len
, params
->seq
)) ||
2620 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2622 goto nla_put_failure
;
2624 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2625 goto nla_put_failure
;
2627 nla_nest_end(cookie
->msg
, key
);
2634 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2638 struct net_device
*dev
= info
->user_ptr
[1];
2640 const u8
*mac_addr
= NULL
;
2642 struct get_key_cookie cookie
= {
2646 struct sk_buff
*msg
;
2648 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2649 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2654 if (info
->attrs
[NL80211_ATTR_MAC
])
2655 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2657 pairwise
= !!mac_addr
;
2658 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2659 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2660 if (kt
>= NUM_NL80211_KEYTYPES
)
2662 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2663 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2665 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2668 if (!rdev
->ops
->get_key
)
2671 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2675 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2676 NL80211_CMD_NEW_KEY
);
2678 goto nla_put_failure
;
2681 cookie
.idx
= key_idx
;
2683 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2684 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2685 goto nla_put_failure
;
2687 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2688 goto nla_put_failure
;
2690 if (pairwise
&& mac_addr
&&
2691 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2694 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2701 goto nla_put_failure
;
2703 genlmsg_end(msg
, hdr
);
2704 return genlmsg_reply(msg
, info
);
2713 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2715 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2716 struct key_parse key
;
2718 struct net_device
*dev
= info
->user_ptr
[1];
2720 err
= nl80211_parse_key(info
, &key
);
2727 /* only support setting default key */
2728 if (!key
.def
&& !key
.defmgmt
)
2731 wdev_lock(dev
->ieee80211_ptr
);
2734 if (!rdev
->ops
->set_default_key
) {
2739 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2743 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2744 key
.def_uni
, key
.def_multi
);
2749 #ifdef CONFIG_CFG80211_WEXT
2750 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2753 if (key
.def_uni
|| !key
.def_multi
) {
2758 if (!rdev
->ops
->set_default_mgmt_key
) {
2763 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2767 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2771 #ifdef CONFIG_CFG80211_WEXT
2772 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2777 wdev_unlock(dev
->ieee80211_ptr
);
2782 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2784 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2786 struct net_device
*dev
= info
->user_ptr
[1];
2787 struct key_parse key
;
2788 const u8
*mac_addr
= NULL
;
2790 err
= nl80211_parse_key(info
, &key
);
2797 if (info
->attrs
[NL80211_ATTR_MAC
])
2798 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2800 if (key
.type
== -1) {
2802 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2804 key
.type
= NL80211_KEYTYPE_GROUP
;
2808 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2809 key
.type
!= NL80211_KEYTYPE_GROUP
)
2812 if (!rdev
->ops
->add_key
)
2815 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2816 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2820 wdev_lock(dev
->ieee80211_ptr
);
2821 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2823 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2824 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2826 wdev_unlock(dev
->ieee80211_ptr
);
2831 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2833 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2835 struct net_device
*dev
= info
->user_ptr
[1];
2836 u8
*mac_addr
= NULL
;
2837 struct key_parse key
;
2839 err
= nl80211_parse_key(info
, &key
);
2843 if (info
->attrs
[NL80211_ATTR_MAC
])
2844 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2846 if (key
.type
== -1) {
2848 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2850 key
.type
= NL80211_KEYTYPE_GROUP
;
2854 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2855 key
.type
!= NL80211_KEYTYPE_GROUP
)
2858 if (!rdev
->ops
->del_key
)
2861 wdev_lock(dev
->ieee80211_ptr
);
2862 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2864 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2865 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2869 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2870 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2873 #ifdef CONFIG_CFG80211_WEXT
2875 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2876 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2877 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2878 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2881 wdev_unlock(dev
->ieee80211_ptr
);
2886 /* This function returns an error or the number of nested attributes */
2887 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2889 struct nlattr
*attr
;
2890 int n_entries
= 0, tmp
;
2892 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2893 if (nla_len(attr
) != ETH_ALEN
)
2903 * This function parses ACL information and allocates memory for ACL data.
2904 * On successful return, the calling function is responsible to free the
2905 * ACL buffer returned by this function.
2907 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2908 struct genl_info
*info
)
2910 enum nl80211_acl_policy acl_policy
;
2911 struct nlattr
*attr
;
2912 struct cfg80211_acl_data
*acl
;
2913 int i
= 0, n_entries
, tmp
;
2915 if (!wiphy
->max_acl_mac_addrs
)
2916 return ERR_PTR(-EOPNOTSUPP
);
2918 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2919 return ERR_PTR(-EINVAL
);
2921 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2922 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2923 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2924 return ERR_PTR(-EINVAL
);
2926 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2927 return ERR_PTR(-EINVAL
);
2929 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2931 return ERR_PTR(n_entries
);
2933 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2934 return ERR_PTR(-ENOTSUPP
);
2936 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2939 return ERR_PTR(-ENOMEM
);
2941 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2942 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2946 acl
->n_acl_entries
= n_entries
;
2947 acl
->acl_policy
= acl_policy
;
2952 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2954 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2955 struct net_device
*dev
= info
->user_ptr
[1];
2956 struct cfg80211_acl_data
*acl
;
2959 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2960 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2963 if (!dev
->ieee80211_ptr
->beacon_interval
)
2966 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2968 return PTR_ERR(acl
);
2970 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2977 static int nl80211_parse_beacon(struct genl_info
*info
,
2978 struct cfg80211_beacon_data
*bcn
)
2980 bool haveinfo
= false;
2982 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2983 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2984 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2985 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2988 memset(bcn
, 0, sizeof(*bcn
));
2990 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2991 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2992 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2998 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2999 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3001 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3008 if (info
->attrs
[NL80211_ATTR_IE
]) {
3009 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3010 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3013 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3014 bcn
->proberesp_ies
=
3015 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3016 bcn
->proberesp_ies_len
=
3017 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3020 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3021 bcn
->assocresp_ies
=
3022 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3023 bcn
->assocresp_ies_len
=
3024 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3027 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
3029 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3030 bcn
->probe_resp_len
=
3031 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3037 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3038 struct cfg80211_ap_settings
*params
)
3040 struct wireless_dev
*wdev
;
3043 mutex_lock(&rdev
->devlist_mtx
);
3045 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3046 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3047 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3050 if (!wdev
->preset_chandef
.chan
)
3053 params
->chandef
= wdev
->preset_chandef
;
3058 mutex_unlock(&rdev
->devlist_mtx
);
3063 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3064 enum nl80211_auth_type auth_type
,
3065 enum nl80211_commands cmd
)
3067 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3071 case NL80211_CMD_AUTHENTICATE
:
3072 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3073 auth_type
== NL80211_AUTHTYPE_SAE
)
3076 case NL80211_CMD_CONNECT
:
3077 case NL80211_CMD_START_AP
:
3078 /* SAE not supported yet */
3079 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3087 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3089 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3090 struct net_device
*dev
= info
->user_ptr
[1];
3091 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3092 struct cfg80211_ap_settings params
;
3094 u8 radar_detect_width
= 0;
3096 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3097 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3100 if (!rdev
->ops
->start_ap
)
3103 if (wdev
->beacon_interval
)
3106 memset(¶ms
, 0, sizeof(params
));
3108 /* these are required for START_AP */
3109 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3110 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3111 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3114 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
3118 params
.beacon_interval
=
3119 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3120 params
.dtim_period
=
3121 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3123 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3128 * In theory, some of these attributes should be required here
3129 * but since they were not used when the command was originally
3130 * added, keep them optional for old user space programs to let
3131 * them continue to work with drivers that do not need the
3132 * additional information -- drivers must check!
3134 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3135 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3137 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3138 if (params
.ssid_len
== 0 ||
3139 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3143 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3144 params
.hidden_ssid
= nla_get_u32(
3145 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3146 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3147 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3148 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3152 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3154 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3155 params
.auth_type
= nla_get_u32(
3156 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3157 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3158 NL80211_CMD_START_AP
))
3161 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3163 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3164 NL80211_MAX_NR_CIPHER_SUITES
);
3168 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3169 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3171 params
.inactivity_timeout
= nla_get_u16(
3172 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3175 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3176 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3178 params
.p2p_ctwindow
=
3179 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3180 if (params
.p2p_ctwindow
> 127)
3182 if (params
.p2p_ctwindow
!= 0 &&
3183 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3187 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3190 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3192 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3195 params
.p2p_opp_ps
= tmp
;
3196 if (params
.p2p_opp_ps
!= 0 &&
3197 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3201 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3202 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3205 } else if (wdev
->preset_chandef
.chan
) {
3206 params
.chandef
= wdev
->preset_chandef
;
3207 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3210 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3213 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3217 radar_detect_width
= BIT(params
.chandef
.width
);
3218 params
.radar_required
= true;
3221 mutex_lock(&rdev
->devlist_mtx
);
3222 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3223 params
.chandef
.chan
,
3225 radar_detect_width
);
3226 mutex_unlock(&rdev
->devlist_mtx
);
3231 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3232 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3233 if (IS_ERR(params
.acl
))
3234 return PTR_ERR(params
.acl
);
3237 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3239 wdev
->preset_chandef
= params
.chandef
;
3240 wdev
->beacon_interval
= params
.beacon_interval
;
3241 wdev
->channel
= params
.chandef
.chan
;
3242 wdev
->ssid_len
= params
.ssid_len
;
3243 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3251 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3253 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3254 struct net_device
*dev
= info
->user_ptr
[1];
3255 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3256 struct cfg80211_beacon_data params
;
3259 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3260 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3263 if (!rdev
->ops
->change_beacon
)
3266 if (!wdev
->beacon_interval
)
3269 err
= nl80211_parse_beacon(info
, ¶ms
);
3273 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3276 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3278 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3279 struct net_device
*dev
= info
->user_ptr
[1];
3281 return cfg80211_stop_ap(rdev
, dev
);
3284 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3285 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3286 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3287 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3288 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3289 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3290 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3293 static int parse_station_flags(struct genl_info
*info
,
3294 enum nl80211_iftype iftype
,
3295 struct station_parameters
*params
)
3297 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3302 * Try parsing the new attribute first so userspace
3303 * can specify both for older kernels.
3305 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3307 struct nl80211_sta_flag_update
*sta_flags
;
3309 sta_flags
= nla_data(nla
);
3310 params
->sta_flags_mask
= sta_flags
->mask
;
3311 params
->sta_flags_set
= sta_flags
->set
;
3312 params
->sta_flags_set
&= params
->sta_flags_mask
;
3313 if ((params
->sta_flags_mask
|
3314 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3319 /* if present, parse the old attribute */
3321 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3325 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3326 nla
, sta_flags_policy
))
3330 * Only allow certain flags for interface types so that
3331 * other attributes are silently ignored. Remember that
3332 * this is backward compatibility code with old userspace
3333 * and shouldn't be hit in other cases anyway.
3336 case NL80211_IFTYPE_AP
:
3337 case NL80211_IFTYPE_AP_VLAN
:
3338 case NL80211_IFTYPE_P2P_GO
:
3339 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3340 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3341 BIT(NL80211_STA_FLAG_WME
) |
3342 BIT(NL80211_STA_FLAG_MFP
);
3344 case NL80211_IFTYPE_P2P_CLIENT
:
3345 case NL80211_IFTYPE_STATION
:
3346 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3347 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3349 case NL80211_IFTYPE_MESH_POINT
:
3350 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3351 BIT(NL80211_STA_FLAG_MFP
) |
3352 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3357 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3359 params
->sta_flags_set
|= (1<<flag
);
3361 /* no longer support new API additions in old API */
3362 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3370 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3373 struct nlattr
*rate
;
3377 rate
= nla_nest_start(msg
, attr
);
3381 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3382 bitrate
= cfg80211_calculate_bitrate(info
);
3383 /* report 16-bit bitrate only if we can */
3384 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3386 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3388 if (bitrate_compat
> 0 &&
3389 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3392 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3393 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3395 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3396 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3398 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3399 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3401 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3402 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3404 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3406 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3407 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3409 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3410 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3412 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3413 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3415 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3416 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3418 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3419 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3423 nla_nest_end(msg
, rate
);
3427 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3429 struct cfg80211_registered_device
*rdev
,
3430 struct net_device
*dev
,
3431 const u8
*mac_addr
, struct station_info
*sinfo
)
3434 struct nlattr
*sinfoattr
, *bss_param
;
3436 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3440 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3441 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3442 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3443 goto nla_put_failure
;
3445 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3447 goto nla_put_failure
;
3448 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3449 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3450 sinfo
->connected_time
))
3451 goto nla_put_failure
;
3452 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3453 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3454 sinfo
->inactive_time
))
3455 goto nla_put_failure
;
3456 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3457 STATION_INFO_RX_BYTES64
)) &&
3458 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3459 (u32
)sinfo
->rx_bytes
))
3460 goto nla_put_failure
;
3461 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3462 STATION_INFO_TX_BYTES64
)) &&
3463 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3464 (u32
)sinfo
->tx_bytes
))
3465 goto nla_put_failure
;
3466 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3467 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3469 goto nla_put_failure
;
3470 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3471 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3473 goto nla_put_failure
;
3474 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3475 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3476 goto nla_put_failure
;
3477 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3478 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3479 goto nla_put_failure
;
3480 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3481 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3482 sinfo
->plink_state
))
3483 goto nla_put_failure
;
3484 switch (rdev
->wiphy
.signal_type
) {
3485 case CFG80211_SIGNAL_TYPE_MBM
:
3486 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3487 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3489 goto nla_put_failure
;
3490 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3491 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3493 goto nla_put_failure
;
3498 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3499 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3500 NL80211_STA_INFO_TX_BITRATE
))
3501 goto nla_put_failure
;
3503 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3504 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3505 NL80211_STA_INFO_RX_BITRATE
))
3506 goto nla_put_failure
;
3508 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3509 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3511 goto nla_put_failure
;
3512 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3513 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3515 goto nla_put_failure
;
3516 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3517 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3519 goto nla_put_failure
;
3520 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3521 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3523 goto nla_put_failure
;
3524 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3525 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3526 sinfo
->beacon_loss_count
))
3527 goto nla_put_failure
;
3528 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3529 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3531 goto nla_put_failure
;
3532 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3533 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3535 goto nla_put_failure
;
3536 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3537 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3539 goto nla_put_failure
;
3540 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3541 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3543 goto nla_put_failure
;
3545 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3546 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3547 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3548 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3549 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3550 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3551 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3552 sinfo
->bss_param
.dtim_period
) ||
3553 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3554 sinfo
->bss_param
.beacon_interval
))
3555 goto nla_put_failure
;
3557 nla_nest_end(msg
, bss_param
);
3559 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3560 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3561 sizeof(struct nl80211_sta_flag_update
),
3563 goto nla_put_failure
;
3564 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3565 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3567 goto nla_put_failure
;
3568 nla_nest_end(msg
, sinfoattr
);
3570 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3571 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3572 sinfo
->assoc_req_ies
))
3573 goto nla_put_failure
;
3575 return genlmsg_end(msg
, hdr
);
3578 genlmsg_cancel(msg
, hdr
);
3582 static int nl80211_dump_station(struct sk_buff
*skb
,
3583 struct netlink_callback
*cb
)
3585 struct station_info sinfo
;
3586 struct cfg80211_registered_device
*dev
;
3587 struct wireless_dev
*wdev
;
3588 u8 mac_addr
[ETH_ALEN
];
3589 int sta_idx
= cb
->args
[2];
3592 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3596 if (!wdev
->netdev
) {
3601 if (!dev
->ops
->dump_station
) {
3607 memset(&sinfo
, 0, sizeof(sinfo
));
3608 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3615 if (nl80211_send_station(skb
,
3616 NETLINK_CB(cb
->skb
).portid
,
3617 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3618 dev
, wdev
->netdev
, mac_addr
,
3627 cb
->args
[2] = sta_idx
;
3630 nl80211_finish_wdev_dump(dev
);
3635 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3637 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3638 struct net_device
*dev
= info
->user_ptr
[1];
3639 struct station_info sinfo
;
3640 struct sk_buff
*msg
;
3641 u8
*mac_addr
= NULL
;
3644 memset(&sinfo
, 0, sizeof(sinfo
));
3646 if (!info
->attrs
[NL80211_ATTR_MAC
])
3649 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3651 if (!rdev
->ops
->get_station
)
3654 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3658 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3662 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3663 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3668 return genlmsg_reply(msg
, info
);
3671 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3672 struct station_parameters
*params
,
3673 enum cfg80211_station_type statype
)
3675 if (params
->listen_interval
!= -1)
3680 /* When you run into this, adjust the code below for the new flag */
3681 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3684 case CFG80211_STA_MESH_PEER_KERNEL
:
3685 case CFG80211_STA_MESH_PEER_USER
:
3687 * No ignoring the TDLS flag here -- the userspace mesh
3688 * code doesn't have the bug of including TDLS in the
3691 if (params
->sta_flags_mask
&
3692 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3693 BIT(NL80211_STA_FLAG_MFP
) |
3694 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3697 case CFG80211_STA_TDLS_PEER_SETUP
:
3698 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3699 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3701 /* ignore since it can't change */
3702 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3705 /* disallow mesh-specific things */
3706 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3708 if (params
->local_pm
)
3710 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3714 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3715 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3716 /* TDLS can't be set, ... */
3717 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3720 * ... but don't bother the driver with it. This works around
3721 * a hostapd/wpa_supplicant issue -- it always includes the
3722 * TLDS_PEER flag in the mask even for AP mode.
3724 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3727 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3728 /* reject other things that can't change */
3729 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3731 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3733 if (params
->supported_rates
)
3735 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3739 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3745 case CFG80211_STA_AP_MLME_CLIENT
:
3746 /* Use this only for authorizing/unauthorizing a station */
3747 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3750 case CFG80211_STA_AP_CLIENT
:
3751 /* accept only the listed bits */
3752 if (params
->sta_flags_mask
&
3753 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3754 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3755 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3756 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3757 BIT(NL80211_STA_FLAG_WME
) |
3758 BIT(NL80211_STA_FLAG_MFP
)))
3761 /* but authenticated/associated only if driver handles it */
3762 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3763 params
->sta_flags_mask
&
3764 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3765 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3768 case CFG80211_STA_IBSS
:
3769 case CFG80211_STA_AP_STA
:
3770 /* reject any changes other than AUTHORIZED */
3771 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3774 case CFG80211_STA_TDLS_PEER_SETUP
:
3775 /* reject any changes other than AUTHORIZED or WME */
3776 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3777 BIT(NL80211_STA_FLAG_WME
)))
3779 /* force (at least) rates when authorizing */
3780 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3781 !params
->supported_rates
)
3784 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3785 /* reject any changes */
3787 case CFG80211_STA_MESH_PEER_KERNEL
:
3788 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3791 case CFG80211_STA_MESH_PEER_USER
:
3792 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3799 EXPORT_SYMBOL(cfg80211_check_station_change
);
3802 * Get vlan interface making sure it is running and on the right wiphy.
3804 static struct net_device
*get_vlan(struct genl_info
*info
,
3805 struct cfg80211_registered_device
*rdev
)
3807 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3808 struct net_device
*v
;
3814 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3816 return ERR_PTR(-ENODEV
);
3818 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3823 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3824 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3825 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3830 if (!netif_running(v
)) {
3838 return ERR_PTR(ret
);
3841 static struct nla_policy
3842 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3843 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3844 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3847 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3848 struct station_parameters
*params
)
3850 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3854 /* parse WME attributes if present */
3855 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3858 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3859 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3860 nl80211_sta_wme_policy
);
3864 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3865 params
->uapsd_queues
= nla_get_u8(
3866 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3867 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3870 if (tb
[NL80211_STA_WME_MAX_SP
])
3871 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3873 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3876 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3881 static int nl80211_set_station_tdls(struct genl_info
*info
,
3882 struct station_parameters
*params
)
3884 /* Dummy STA entry gets updated once the peer capabilities are known */
3885 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3887 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3888 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3890 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3892 return nl80211_parse_sta_wme(info
, params
);
3895 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3897 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3898 struct net_device
*dev
= info
->user_ptr
[1];
3899 struct station_parameters params
;
3903 memset(¶ms
, 0, sizeof(params
));
3905 params
.listen_interval
= -1;
3907 if (!rdev
->ops
->change_station
)
3910 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3913 if (!info
->attrs
[NL80211_ATTR_MAC
])
3916 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3918 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3919 params
.supported_rates
=
3920 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3921 params
.supported_rates_len
=
3922 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3925 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3927 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3928 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3931 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3933 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3934 params
.ext_capab_len
=
3935 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3938 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3941 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3944 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3945 params
.plink_action
=
3946 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3947 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3951 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3952 params
.plink_state
=
3953 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3954 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3956 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3959 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3960 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3961 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3963 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3964 pm
> NL80211_MESH_POWER_MAX
)
3967 params
.local_pm
= pm
;
3970 /* Include parameters for TDLS peer (will check later) */
3971 err
= nl80211_set_station_tdls(info
, ¶ms
);
3975 params
.vlan
= get_vlan(info
, rdev
);
3976 if (IS_ERR(params
.vlan
))
3977 return PTR_ERR(params
.vlan
);
3979 switch (dev
->ieee80211_ptr
->iftype
) {
3980 case NL80211_IFTYPE_AP
:
3981 case NL80211_IFTYPE_AP_VLAN
:
3982 case NL80211_IFTYPE_P2P_GO
:
3983 case NL80211_IFTYPE_P2P_CLIENT
:
3984 case NL80211_IFTYPE_STATION
:
3985 case NL80211_IFTYPE_ADHOC
:
3986 case NL80211_IFTYPE_MESH_POINT
:
3993 /* driver will call cfg80211_check_station_change() */
3994 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3998 dev_put(params
.vlan
);
4003 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4005 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4007 struct net_device
*dev
= info
->user_ptr
[1];
4008 struct station_parameters params
;
4009 u8
*mac_addr
= NULL
;
4011 memset(¶ms
, 0, sizeof(params
));
4013 if (!rdev
->ops
->add_station
)
4016 if (!info
->attrs
[NL80211_ATTR_MAC
])
4019 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4022 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4025 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
4028 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4029 params
.supported_rates
=
4030 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4031 params
.supported_rates_len
=
4032 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4033 params
.listen_interval
=
4034 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4036 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4037 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4040 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4042 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4043 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4046 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4048 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4049 params
.ext_capab_len
=
4050 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4053 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4055 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4057 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4059 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4061 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4062 params
.plink_action
=
4063 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4064 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4068 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4072 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4075 /* When you run into this, adjust the code below for the new flag */
4076 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4078 switch (dev
->ieee80211_ptr
->iftype
) {
4079 case NL80211_IFTYPE_AP
:
4080 case NL80211_IFTYPE_AP_VLAN
:
4081 case NL80211_IFTYPE_P2P_GO
:
4082 /* ignore WME attributes if iface/sta is not capable */
4083 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4084 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4085 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4087 /* TDLS peers cannot be added */
4088 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4090 /* but don't bother the driver with it */
4091 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4093 /* allow authenticated/associated only if driver handles it */
4094 if (!(rdev
->wiphy
.features
&
4095 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4096 params
.sta_flags_mask
&
4097 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4098 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4101 /* must be last in here for error handling */
4102 params
.vlan
= get_vlan(info
, rdev
);
4103 if (IS_ERR(params
.vlan
))
4104 return PTR_ERR(params
.vlan
);
4106 case NL80211_IFTYPE_MESH_POINT
:
4107 /* ignore uAPSD data */
4108 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4110 /* associated is disallowed */
4111 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4113 /* TDLS peers cannot be added */
4114 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4117 case NL80211_IFTYPE_STATION
:
4118 case NL80211_IFTYPE_P2P_CLIENT
:
4119 /* ignore uAPSD data */
4120 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4122 /* these are disallowed */
4123 if (params
.sta_flags_mask
&
4124 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4125 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4127 /* Only TDLS peers can be added */
4128 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4130 /* Can only add if TDLS ... */
4131 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4133 /* ... with external setup is supported */
4134 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4137 * Older wpa_supplicant versions always mark the TDLS peer
4138 * as authorized, but it shouldn't yet be.
4140 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4146 /* be aware of params.vlan when changing code here */
4148 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4151 dev_put(params
.vlan
);
4155 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4157 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4158 struct net_device
*dev
= info
->user_ptr
[1];
4159 u8
*mac_addr
= NULL
;
4161 if (info
->attrs
[NL80211_ATTR_MAC
])
4162 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4164 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4165 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4166 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4167 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4170 if (!rdev
->ops
->del_station
)
4173 return rdev_del_station(rdev
, dev
, mac_addr
);
4176 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4177 int flags
, struct net_device
*dev
,
4178 u8
*dst
, u8
*next_hop
,
4179 struct mpath_info
*pinfo
)
4182 struct nlattr
*pinfoattr
;
4184 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4188 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4189 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4190 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4191 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4192 goto nla_put_failure
;
4194 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4196 goto nla_put_failure
;
4197 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4198 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4200 goto nla_put_failure
;
4201 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4202 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4203 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4204 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4206 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4207 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4209 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4210 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4212 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4213 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4214 pinfo
->discovery_timeout
)) ||
4215 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4216 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4217 pinfo
->discovery_retries
)))
4218 goto nla_put_failure
;
4220 nla_nest_end(msg
, pinfoattr
);
4222 return genlmsg_end(msg
, hdr
);
4225 genlmsg_cancel(msg
, hdr
);
4229 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4230 struct netlink_callback
*cb
)
4232 struct mpath_info pinfo
;
4233 struct cfg80211_registered_device
*dev
;
4234 struct wireless_dev
*wdev
;
4236 u8 next_hop
[ETH_ALEN
];
4237 int path_idx
= cb
->args
[2];
4240 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4244 if (!dev
->ops
->dump_mpath
) {
4249 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4255 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4262 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4263 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4264 wdev
->netdev
, dst
, next_hop
,
4273 cb
->args
[2] = path_idx
;
4276 nl80211_finish_wdev_dump(dev
);
4280 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4282 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4284 struct net_device
*dev
= info
->user_ptr
[1];
4285 struct mpath_info pinfo
;
4286 struct sk_buff
*msg
;
4288 u8 next_hop
[ETH_ALEN
];
4290 memset(&pinfo
, 0, sizeof(pinfo
));
4292 if (!info
->attrs
[NL80211_ATTR_MAC
])
4295 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4297 if (!rdev
->ops
->get_mpath
)
4300 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4303 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4307 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4311 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4312 dev
, dst
, next_hop
, &pinfo
) < 0) {
4317 return genlmsg_reply(msg
, info
);
4320 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4322 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4323 struct net_device
*dev
= info
->user_ptr
[1];
4325 u8
*next_hop
= NULL
;
4327 if (!info
->attrs
[NL80211_ATTR_MAC
])
4330 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4333 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4334 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4336 if (!rdev
->ops
->change_mpath
)
4339 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4342 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4345 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4347 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4348 struct net_device
*dev
= info
->user_ptr
[1];
4350 u8
*next_hop
= NULL
;
4352 if (!info
->attrs
[NL80211_ATTR_MAC
])
4355 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4358 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4359 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4361 if (!rdev
->ops
->add_mpath
)
4364 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4367 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4370 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4372 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4373 struct net_device
*dev
= info
->user_ptr
[1];
4376 if (info
->attrs
[NL80211_ATTR_MAC
])
4377 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4379 if (!rdev
->ops
->del_mpath
)
4382 return rdev_del_mpath(rdev
, dev
, dst
);
4385 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4387 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4388 struct net_device
*dev
= info
->user_ptr
[1];
4389 struct bss_parameters params
;
4391 memset(¶ms
, 0, sizeof(params
));
4392 /* default to not changing parameters */
4393 params
.use_cts_prot
= -1;
4394 params
.use_short_preamble
= -1;
4395 params
.use_short_slot_time
= -1;
4396 params
.ap_isolate
= -1;
4397 params
.ht_opmode
= -1;
4398 params
.p2p_ctwindow
= -1;
4399 params
.p2p_opp_ps
= -1;
4401 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4402 params
.use_cts_prot
=
4403 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4404 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4405 params
.use_short_preamble
=
4406 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4407 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4408 params
.use_short_slot_time
=
4409 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4410 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4411 params
.basic_rates
=
4412 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4413 params
.basic_rates_len
=
4414 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4416 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4417 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4418 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4420 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4422 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4423 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4425 params
.p2p_ctwindow
=
4426 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4427 if (params
.p2p_ctwindow
< 0)
4429 if (params
.p2p_ctwindow
!= 0 &&
4430 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4434 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4437 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4439 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4442 params
.p2p_opp_ps
= tmp
;
4443 if (params
.p2p_opp_ps
&&
4444 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4448 if (!rdev
->ops
->change_bss
)
4451 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4452 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4455 return rdev_change_bss(rdev
, dev
, ¶ms
);
4458 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4459 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4460 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4461 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4462 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4463 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4464 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4467 static int parse_reg_rule(struct nlattr
*tb
[],
4468 struct ieee80211_reg_rule
*reg_rule
)
4470 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4471 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4473 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4475 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4477 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4479 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4481 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4484 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4486 freq_range
->start_freq_khz
=
4487 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4488 freq_range
->end_freq_khz
=
4489 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4490 freq_range
->max_bandwidth_khz
=
4491 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4493 power_rule
->max_eirp
=
4494 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4496 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4497 power_rule
->max_antenna_gain
=
4498 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4503 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4507 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4510 * You should only get this when cfg80211 hasn't yet initialized
4511 * completely when built-in to the kernel right between the time
4512 * window between nl80211_init() and regulatory_init(), if that is
4515 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4516 return -EINPROGRESS
;
4518 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4521 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4523 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4524 user_reg_hint_type
=
4525 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4527 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4529 switch (user_reg_hint_type
) {
4530 case NL80211_USER_REG_HINT_USER
:
4531 case NL80211_USER_REG_HINT_CELL_BASE
:
4537 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4542 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4543 struct genl_info
*info
)
4545 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4546 struct net_device
*dev
= info
->user_ptr
[1];
4547 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4548 struct mesh_config cur_params
;
4551 struct nlattr
*pinfoattr
;
4552 struct sk_buff
*msg
;
4554 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4557 if (!rdev
->ops
->get_mesh_config
)
4561 /* If not connected, get default parameters */
4562 if (!wdev
->mesh_id_len
)
4563 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4565 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4571 /* Draw up a netlink message to send back */
4572 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4575 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4576 NL80211_CMD_GET_MESH_CONFIG
);
4579 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4581 goto nla_put_failure
;
4582 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4583 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4584 cur_params
.dot11MeshRetryTimeout
) ||
4585 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4586 cur_params
.dot11MeshConfirmTimeout
) ||
4587 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4588 cur_params
.dot11MeshHoldingTimeout
) ||
4589 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4590 cur_params
.dot11MeshMaxPeerLinks
) ||
4591 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4592 cur_params
.dot11MeshMaxRetries
) ||
4593 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4594 cur_params
.dot11MeshTTL
) ||
4595 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4596 cur_params
.element_ttl
) ||
4597 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4598 cur_params
.auto_open_plinks
) ||
4599 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4600 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4601 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4602 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4603 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4604 cur_params
.path_refresh_time
) ||
4605 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4606 cur_params
.min_discovery_timeout
) ||
4607 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4608 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4609 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4610 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4611 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4612 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4613 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4614 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4615 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4616 cur_params
.dot11MeshHWMPRootMode
) ||
4617 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4618 cur_params
.dot11MeshHWMPRannInterval
) ||
4619 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4620 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4621 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4622 cur_params
.dot11MeshForwarding
) ||
4623 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4624 cur_params
.rssi_threshold
) ||
4625 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4626 cur_params
.ht_opmode
) ||
4627 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4628 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4629 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4630 cur_params
.dot11MeshHWMProotInterval
) ||
4631 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4632 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4633 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4634 cur_params
.power_mode
) ||
4635 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4636 cur_params
.dot11MeshAwakeWindowDuration
))
4637 goto nla_put_failure
;
4638 nla_nest_end(msg
, pinfoattr
);
4639 genlmsg_end(msg
, hdr
);
4640 return genlmsg_reply(msg
, info
);
4643 genlmsg_cancel(msg
, hdr
);
4649 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4650 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4651 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4652 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4653 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4654 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4655 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4656 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4657 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4658 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4659 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4660 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4661 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4662 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4663 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4664 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4665 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4666 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4667 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4668 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4669 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4670 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4671 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4672 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4673 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4674 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4675 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4676 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4679 static const struct nla_policy
4680 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4681 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4682 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4683 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4684 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4685 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4686 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4687 .len
= IEEE80211_MAX_DATA_LEN
},
4688 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4691 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4692 struct mesh_config
*cfg
,
4695 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4698 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4701 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4703 cfg->param = fn(tb[attr]); \
4704 mask |= (1 << (attr - 1)); \
4709 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4711 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4712 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4713 nl80211_meshconf_params_policy
))
4716 /* This makes sure that there aren't more than 32 mesh config
4717 * parameters (otherwise our bitfield scheme would not work.) */
4718 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4720 /* Fill in the params struct */
4721 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4722 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4724 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4725 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4727 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4728 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4730 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4731 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4733 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4734 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4736 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4737 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4738 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4739 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4741 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4742 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4744 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4746 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4748 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4749 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4751 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4752 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4754 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4755 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4759 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4761 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4763 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4765 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4767 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4769 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4770 dot11MeshHWMPnetDiameterTraversalTime
,
4772 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4774 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4775 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4777 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4778 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4780 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4781 dot11MeshGateAnnouncementProtocol
, 0, 1,
4782 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4784 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4785 mask
, NL80211_MESHCONF_FORWARDING
,
4787 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4788 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4790 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4791 mask
, NL80211_MESHCONF_HT_OPMODE
,
4793 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4795 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4797 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4798 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4800 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4801 dot11MeshHWMPconfirmationInterval
,
4803 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4805 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4806 NL80211_MESH_POWER_ACTIVE
,
4807 NL80211_MESH_POWER_MAX
,
4808 mask
, NL80211_MESHCONF_POWER_MODE
,
4810 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4812 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4818 #undef FILL_IN_MESH_PARAM_IF_SET
4821 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4822 struct mesh_setup
*setup
)
4824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4825 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4827 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4829 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4830 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4831 nl80211_mesh_setup_params_policy
))
4834 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4835 setup
->sync_method
=
4836 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4837 IEEE80211_SYNC_METHOD_VENDOR
:
4838 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4840 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4841 setup
->path_sel_proto
=
4842 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4843 IEEE80211_PATH_PROTOCOL_VENDOR
:
4844 IEEE80211_PATH_PROTOCOL_HWMP
;
4846 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4847 setup
->path_metric
=
4848 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4849 IEEE80211_PATH_METRIC_VENDOR
:
4850 IEEE80211_PATH_METRIC_AIRTIME
;
4853 if (tb
[NL80211_MESH_SETUP_IE
]) {
4854 struct nlattr
*ieattr
=
4855 tb
[NL80211_MESH_SETUP_IE
];
4856 if (!is_valid_ie_attr(ieattr
))
4858 setup
->ie
= nla_data(ieattr
);
4859 setup
->ie_len
= nla_len(ieattr
);
4861 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4862 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4864 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4865 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4866 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4867 if (setup
->is_secure
)
4868 setup
->user_mpm
= true;
4873 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4874 struct genl_info
*info
)
4876 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4877 struct net_device
*dev
= info
->user_ptr
[1];
4878 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4879 struct mesh_config cfg
;
4883 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4886 if (!rdev
->ops
->update_mesh_config
)
4889 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4894 if (!wdev
->mesh_id_len
)
4898 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4905 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4907 const struct ieee80211_regdomain
*regdom
;
4908 struct sk_buff
*msg
;
4910 struct nlattr
*nl_reg_rules
;
4914 mutex_lock(&cfg80211_mutex
);
4916 if (!cfg80211_regdomain
)
4919 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4925 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4926 NL80211_CMD_GET_REG
);
4930 if (reg_last_request_cell_base() &&
4931 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4932 NL80211_USER_REG_HINT_CELL_BASE
))
4933 goto nla_put_failure
;
4936 regdom
= rcu_dereference(cfg80211_regdomain
);
4938 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4939 (regdom
->dfs_region
&&
4940 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4941 goto nla_put_failure_rcu
;
4943 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4945 goto nla_put_failure_rcu
;
4947 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4948 struct nlattr
*nl_reg_rule
;
4949 const struct ieee80211_reg_rule
*reg_rule
;
4950 const struct ieee80211_freq_range
*freq_range
;
4951 const struct ieee80211_power_rule
*power_rule
;
4953 reg_rule
= ®dom
->reg_rules
[i
];
4954 freq_range
= ®_rule
->freq_range
;
4955 power_rule
= ®_rule
->power_rule
;
4957 nl_reg_rule
= nla_nest_start(msg
, i
);
4959 goto nla_put_failure_rcu
;
4961 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4963 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4964 freq_range
->start_freq_khz
) ||
4965 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4966 freq_range
->end_freq_khz
) ||
4967 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4968 freq_range
->max_bandwidth_khz
) ||
4969 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4970 power_rule
->max_antenna_gain
) ||
4971 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4972 power_rule
->max_eirp
))
4973 goto nla_put_failure_rcu
;
4975 nla_nest_end(msg
, nl_reg_rule
);
4979 nla_nest_end(msg
, nl_reg_rules
);
4981 genlmsg_end(msg
, hdr
);
4982 err
= genlmsg_reply(msg
, info
);
4985 nla_put_failure_rcu
:
4988 genlmsg_cancel(msg
, hdr
);
4993 mutex_unlock(&cfg80211_mutex
);
4997 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4999 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5000 struct nlattr
*nl_reg_rule
;
5001 char *alpha2
= NULL
;
5002 int rem_reg_rules
= 0, r
= 0;
5003 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5005 struct ieee80211_regdomain
*rd
= NULL
;
5007 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5010 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5013 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5015 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5016 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5018 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5021 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5025 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5026 num_rules
* sizeof(struct ieee80211_reg_rule
);
5028 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5032 rd
->n_reg_rules
= num_rules
;
5033 rd
->alpha2
[0] = alpha2
[0];
5034 rd
->alpha2
[1] = alpha2
[1];
5037 * Disable DFS master mode if the DFS region was
5038 * not supported or known on this kernel.
5040 if (reg_supported_dfs_region(dfs_region
))
5041 rd
->dfs_region
= dfs_region
;
5043 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5045 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5046 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5048 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5054 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5060 mutex_lock(&cfg80211_mutex
);
5063 /* set_regdom took ownership */
5065 mutex_unlock(&cfg80211_mutex
);
5072 static int validate_scan_freqs(struct nlattr
*freqs
)
5074 struct nlattr
*attr1
, *attr2
;
5075 int n_channels
= 0, tmp1
, tmp2
;
5077 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5080 * Some hardware has a limited channel list for
5081 * scanning, and it is pretty much nonsensical
5082 * to scan for a channel twice, so disallow that
5083 * and don't require drivers to check that the
5084 * channel list they get isn't longer than what
5085 * they can scan, as long as they can scan all
5086 * the channels they registered at once.
5088 nla_for_each_nested(attr2
, freqs
, tmp2
)
5089 if (attr1
!= attr2
&&
5090 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5097 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5099 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5100 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5101 struct cfg80211_scan_request
*request
;
5102 struct nlattr
*attr
;
5103 struct wiphy
*wiphy
;
5104 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5107 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5110 wiphy
= &rdev
->wiphy
;
5112 if (!rdev
->ops
->scan
)
5115 mutex_lock(&rdev
->sched_scan_mtx
);
5116 if (rdev
->scan_req
) {
5121 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5122 n_channels
= validate_scan_freqs(
5123 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5129 enum ieee80211_band band
;
5132 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5133 if (wiphy
->bands
[band
])
5134 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5137 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5138 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5141 if (n_ssids
> wiphy
->max_scan_ssids
) {
5146 if (info
->attrs
[NL80211_ATTR_IE
])
5147 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5151 if (ie_len
> wiphy
->max_scan_ie_len
) {
5156 request
= kzalloc(sizeof(*request
)
5157 + sizeof(*request
->ssids
) * n_ssids
5158 + sizeof(*request
->channels
) * n_channels
5159 + ie_len
, GFP_KERNEL
);
5166 request
->ssids
= (void *)&request
->channels
[n_channels
];
5167 request
->n_ssids
= n_ssids
;
5170 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5172 request
->ie
= (void *)(request
->channels
+ n_channels
);
5176 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5177 /* user specified, bail out if channel not found */
5178 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5179 struct ieee80211_channel
*chan
;
5181 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5188 /* ignore disabled channels */
5189 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5192 request
->channels
[i
] = chan
;
5196 enum ieee80211_band band
;
5199 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5201 if (!wiphy
->bands
[band
])
5203 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5204 struct ieee80211_channel
*chan
;
5206 chan
= &wiphy
->bands
[band
]->channels
[j
];
5208 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5211 request
->channels
[i
] = chan
;
5222 request
->n_channels
= i
;
5225 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5226 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5227 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5231 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5232 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5237 if (info
->attrs
[NL80211_ATTR_IE
]) {
5238 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5239 memcpy((void *)request
->ie
,
5240 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5244 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5245 if (wiphy
->bands
[i
])
5247 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5249 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5250 nla_for_each_nested(attr
,
5251 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5253 enum ieee80211_band band
= nla_type(attr
);
5255 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5259 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5262 &request
->rates
[band
]);
5268 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5269 request
->flags
= nla_get_u32(
5270 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5271 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5272 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5273 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5274 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5281 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5283 request
->wdev
= wdev
;
5284 request
->wiphy
= &rdev
->wiphy
;
5285 request
->scan_start
= jiffies
;
5287 rdev
->scan_req
= request
;
5288 err
= rdev_scan(rdev
, request
);
5291 nl80211_send_scan_start(rdev
, wdev
);
5293 dev_hold(wdev
->netdev
);
5296 rdev
->scan_req
= NULL
;
5301 mutex_unlock(&rdev
->sched_scan_mtx
);
5305 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5306 struct genl_info
*info
)
5308 struct cfg80211_sched_scan_request
*request
;
5309 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5310 struct net_device
*dev
= info
->user_ptr
[1];
5311 struct nlattr
*attr
;
5312 struct wiphy
*wiphy
;
5313 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5315 enum ieee80211_band band
;
5317 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5319 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5320 !rdev
->ops
->sched_scan_start
)
5323 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5326 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5329 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5333 wiphy
= &rdev
->wiphy
;
5335 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5336 n_channels
= validate_scan_freqs(
5337 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5343 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5344 if (wiphy
->bands
[band
])
5345 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5348 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5349 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5353 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5356 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5357 nla_for_each_nested(attr
,
5358 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5362 if (n_match_sets
> wiphy
->max_match_sets
)
5365 if (info
->attrs
[NL80211_ATTR_IE
])
5366 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5370 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5373 mutex_lock(&rdev
->sched_scan_mtx
);
5375 if (rdev
->sched_scan_req
) {
5380 request
= kzalloc(sizeof(*request
)
5381 + sizeof(*request
->ssids
) * n_ssids
5382 + sizeof(*request
->match_sets
) * n_match_sets
5383 + sizeof(*request
->channels
) * n_channels
5384 + ie_len
, GFP_KERNEL
);
5391 request
->ssids
= (void *)&request
->channels
[n_channels
];
5392 request
->n_ssids
= n_ssids
;
5395 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5397 request
->ie
= (void *)(request
->channels
+ n_channels
);
5402 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5403 else if (request
->ssids
)
5404 request
->match_sets
=
5405 (void *)(request
->ssids
+ n_ssids
);
5407 request
->match_sets
=
5408 (void *)(request
->channels
+ n_channels
);
5410 request
->n_match_sets
= n_match_sets
;
5413 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5414 /* user specified, bail out if channel not found */
5415 nla_for_each_nested(attr
,
5416 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5418 struct ieee80211_channel
*chan
;
5420 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5427 /* ignore disabled channels */
5428 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5431 request
->channels
[i
] = chan
;
5436 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5438 if (!wiphy
->bands
[band
])
5440 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5441 struct ieee80211_channel
*chan
;
5443 chan
= &wiphy
->bands
[band
]->channels
[j
];
5445 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5448 request
->channels
[i
] = chan
;
5459 request
->n_channels
= i
;
5462 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5463 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5465 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5469 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5470 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5477 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5478 nla_for_each_nested(attr
,
5479 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5481 struct nlattr
*ssid
, *rssi
;
5483 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5484 nla_data(attr
), nla_len(attr
),
5485 nl80211_match_policy
);
5486 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5488 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5492 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5493 nla_data(ssid
), nla_len(ssid
));
5494 request
->match_sets
[i
].ssid
.ssid_len
=
5497 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5499 request
->rssi_thold
= nla_get_u32(rssi
);
5501 request
->rssi_thold
=
5502 NL80211_SCAN_RSSI_THOLD_OFF
;
5507 if (info
->attrs
[NL80211_ATTR_IE
]) {
5508 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5509 memcpy((void *)request
->ie
,
5510 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5514 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5515 request
->flags
= nla_get_u32(
5516 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5517 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5518 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5519 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5520 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5527 request
->wiphy
= &rdev
->wiphy
;
5528 request
->interval
= interval
;
5529 request
->scan_start
= jiffies
;
5531 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5533 rdev
->sched_scan_req
= request
;
5534 nl80211_send_sched_scan(rdev
, dev
,
5535 NL80211_CMD_START_SCHED_SCAN
);
5542 mutex_unlock(&rdev
->sched_scan_mtx
);
5546 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5547 struct genl_info
*info
)
5549 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5552 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5553 !rdev
->ops
->sched_scan_stop
)
5556 mutex_lock(&rdev
->sched_scan_mtx
);
5557 err
= __cfg80211_stop_sched_scan(rdev
, false);
5558 mutex_unlock(&rdev
->sched_scan_mtx
);
5563 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5564 struct genl_info
*info
)
5566 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5567 struct net_device
*dev
= info
->user_ptr
[1];
5568 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5569 struct cfg80211_chan_def chandef
;
5572 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5576 if (wdev
->cac_started
)
5579 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5586 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5589 if (!rdev
->ops
->start_radar_detection
)
5592 mutex_lock(&rdev
->devlist_mtx
);
5593 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5594 chandef
.chan
, CHAN_MODE_SHARED
,
5595 BIT(chandef
.width
));
5599 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5601 wdev
->channel
= chandef
.chan
;
5602 wdev
->cac_started
= true;
5603 wdev
->cac_start_time
= jiffies
;
5606 mutex_unlock(&rdev
->devlist_mtx
);
5611 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5613 struct cfg80211_registered_device
*rdev
,
5614 struct wireless_dev
*wdev
,
5615 struct cfg80211_internal_bss
*intbss
)
5617 struct cfg80211_bss
*res
= &intbss
->pub
;
5618 const struct cfg80211_bss_ies
*ies
;
5623 ASSERT_WDEV_LOCK(wdev
);
5625 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5626 NL80211_CMD_NEW_SCAN_RESULTS
);
5630 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5632 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5633 goto nla_put_failure
;
5635 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5636 goto nla_put_failure
;
5637 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5638 goto nla_put_failure
;
5640 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5642 goto nla_put_failure
;
5643 if ((!is_zero_ether_addr(res
->bssid
) &&
5644 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5645 goto nla_put_failure
;
5648 ies
= rcu_dereference(res
->ies
);
5650 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5651 goto fail_unlock_rcu
;
5653 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5654 ies
->len
, ies
->data
))
5655 goto fail_unlock_rcu
;
5657 ies
= rcu_dereference(res
->beacon_ies
);
5659 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5660 goto fail_unlock_rcu
;
5661 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5662 ies
->len
, ies
->data
))
5663 goto fail_unlock_rcu
;
5667 if (res
->beacon_interval
&&
5668 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5669 goto nla_put_failure
;
5670 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5671 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5672 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5673 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5674 goto nla_put_failure
;
5676 switch (rdev
->wiphy
.signal_type
) {
5677 case CFG80211_SIGNAL_TYPE_MBM
:
5678 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5679 goto nla_put_failure
;
5681 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5682 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5683 goto nla_put_failure
;
5689 switch (wdev
->iftype
) {
5690 case NL80211_IFTYPE_P2P_CLIENT
:
5691 case NL80211_IFTYPE_STATION
:
5692 if (intbss
== wdev
->current_bss
&&
5693 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5694 NL80211_BSS_STATUS_ASSOCIATED
))
5695 goto nla_put_failure
;
5697 case NL80211_IFTYPE_ADHOC
:
5698 if (intbss
== wdev
->current_bss
&&
5699 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5700 NL80211_BSS_STATUS_IBSS_JOINED
))
5701 goto nla_put_failure
;
5707 nla_nest_end(msg
, bss
);
5709 return genlmsg_end(msg
, hdr
);
5714 genlmsg_cancel(msg
, hdr
);
5718 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5720 struct cfg80211_registered_device
*rdev
;
5721 struct cfg80211_internal_bss
*scan
;
5722 struct wireless_dev
*wdev
;
5723 int start
= cb
->args
[2], idx
= 0;
5726 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5731 spin_lock_bh(&rdev
->bss_lock
);
5732 cfg80211_bss_expire(rdev
);
5734 cb
->seq
= rdev
->bss_generation
;
5736 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5739 if (nl80211_send_bss(skb
, cb
,
5740 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5741 rdev
, wdev
, scan
) < 0) {
5747 spin_unlock_bh(&rdev
->bss_lock
);
5751 nl80211_finish_wdev_dump(rdev
);
5756 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5757 int flags
, struct net_device
*dev
,
5758 struct survey_info
*survey
)
5761 struct nlattr
*infoattr
;
5763 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5764 NL80211_CMD_NEW_SURVEY_RESULTS
);
5768 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5769 goto nla_put_failure
;
5771 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5773 goto nla_put_failure
;
5775 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5776 survey
->channel
->center_freq
))
5777 goto nla_put_failure
;
5779 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5780 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5781 goto nla_put_failure
;
5782 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5783 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5784 goto nla_put_failure
;
5785 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5786 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5787 survey
->channel_time
))
5788 goto nla_put_failure
;
5789 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5790 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5791 survey
->channel_time_busy
))
5792 goto nla_put_failure
;
5793 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5794 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5795 survey
->channel_time_ext_busy
))
5796 goto nla_put_failure
;
5797 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5798 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5799 survey
->channel_time_rx
))
5800 goto nla_put_failure
;
5801 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5802 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5803 survey
->channel_time_tx
))
5804 goto nla_put_failure
;
5806 nla_nest_end(msg
, infoattr
);
5808 return genlmsg_end(msg
, hdr
);
5811 genlmsg_cancel(msg
, hdr
);
5815 static int nl80211_dump_survey(struct sk_buff
*skb
,
5816 struct netlink_callback
*cb
)
5818 struct survey_info survey
;
5819 struct cfg80211_registered_device
*dev
;
5820 struct wireless_dev
*wdev
;
5821 int survey_idx
= cb
->args
[2];
5824 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5828 if (!wdev
->netdev
) {
5833 if (!dev
->ops
->dump_survey
) {
5839 struct ieee80211_channel
*chan
;
5841 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5847 /* Survey without a channel doesn't make sense */
5848 if (!survey
.channel
) {
5853 chan
= ieee80211_get_channel(&dev
->wiphy
,
5854 survey
.channel
->center_freq
);
5855 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5860 if (nl80211_send_survey(skb
,
5861 NETLINK_CB(cb
->skb
).portid
,
5862 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5863 wdev
->netdev
, &survey
) < 0)
5869 cb
->args
[2] = survey_idx
;
5872 nl80211_finish_wdev_dump(dev
);
5876 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5878 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5879 NL80211_WPA_VERSION_2
));
5882 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5884 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5885 struct net_device
*dev
= info
->user_ptr
[1];
5886 struct ieee80211_channel
*chan
;
5887 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5888 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5889 enum nl80211_auth_type auth_type
;
5890 struct key_parse key
;
5891 bool local_state_change
;
5893 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5896 if (!info
->attrs
[NL80211_ATTR_MAC
])
5899 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5902 if (!info
->attrs
[NL80211_ATTR_SSID
])
5905 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5908 err
= nl80211_parse_key(info
, &key
);
5913 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5915 if (!key
.p
.key
|| !key
.p
.key_len
)
5917 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5918 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5919 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5920 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5932 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5933 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5942 if (!rdev
->ops
->auth
)
5945 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5946 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5949 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5950 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5951 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5952 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5955 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5956 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5958 if (info
->attrs
[NL80211_ATTR_IE
]) {
5959 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5960 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5963 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5964 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5967 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5968 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5971 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5972 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5974 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5975 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5976 /* need to include at least Auth Transaction and Status Code */
5977 if (sae_data_len
< 4)
5981 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5984 * Since we no longer track auth state, ignore
5985 * requests to only change local state.
5987 if (local_state_change
)
5990 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5991 ssid
, ssid_len
, ie
, ie_len
,
5992 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5993 sae_data
, sae_data_len
);
5996 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5997 struct genl_info
*info
,
5998 struct cfg80211_crypto_settings
*settings
,
6001 memset(settings
, 0, sizeof(*settings
));
6003 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6005 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6007 proto
= nla_get_u16(
6008 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6009 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6010 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6013 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6014 settings
->control_port_no_encrypt
= true;
6016 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6018 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6022 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6023 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6024 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6026 if (len
% sizeof(u32
))
6029 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6032 memcpy(settings
->ciphers_pairwise
, data
, len
);
6034 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6035 if (!cfg80211_supported_cipher_suite(
6037 settings
->ciphers_pairwise
[i
]))
6041 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6042 settings
->cipher_group
=
6043 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6044 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6045 settings
->cipher_group
))
6049 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6050 settings
->wpa_versions
=
6051 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6052 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6056 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6060 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6061 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6062 settings
->n_akm_suites
= len
/ sizeof(u32
);
6064 if (len
% sizeof(u32
))
6067 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6070 memcpy(settings
->akm_suites
, data
, len
);
6076 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6078 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6079 struct net_device
*dev
= info
->user_ptr
[1];
6080 struct ieee80211_channel
*chan
;
6081 struct cfg80211_assoc_request req
= {};
6082 const u8
*bssid
, *ssid
;
6083 int err
, ssid_len
= 0;
6085 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6088 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6089 !info
->attrs
[NL80211_ATTR_SSID
] ||
6090 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6093 if (!rdev
->ops
->assoc
)
6096 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6097 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6100 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6102 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6103 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6104 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6107 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6108 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6110 if (info
->attrs
[NL80211_ATTR_IE
]) {
6111 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6112 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6115 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6116 enum nl80211_mfp mfp
=
6117 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6118 if (mfp
== NL80211_MFP_REQUIRED
)
6120 else if (mfp
!= NL80211_MFP_NO
)
6124 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6125 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6127 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6128 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6130 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6131 memcpy(&req
.ht_capa_mask
,
6132 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6133 sizeof(req
.ht_capa_mask
));
6135 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6136 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6138 memcpy(&req
.ht_capa
,
6139 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6140 sizeof(req
.ht_capa
));
6143 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6144 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6146 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6147 memcpy(&req
.vht_capa_mask
,
6148 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6149 sizeof(req
.vht_capa_mask
));
6151 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6152 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6154 memcpy(&req
.vht_capa
,
6155 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6156 sizeof(req
.vht_capa
));
6159 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6161 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6162 ssid
, ssid_len
, &req
);
6167 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6169 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6170 struct net_device
*dev
= info
->user_ptr
[1];
6171 const u8
*ie
= NULL
, *bssid
;
6174 bool local_state_change
;
6176 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6179 if (!info
->attrs
[NL80211_ATTR_MAC
])
6182 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6185 if (!rdev
->ops
->deauth
)
6188 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6189 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6192 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6194 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6195 if (reason_code
== 0) {
6196 /* Reason Code 0 is reserved */
6200 if (info
->attrs
[NL80211_ATTR_IE
]) {
6201 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6202 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6205 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6207 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6208 local_state_change
);
6211 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6213 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6214 struct net_device
*dev
= info
->user_ptr
[1];
6215 const u8
*ie
= NULL
, *bssid
;
6218 bool local_state_change
;
6220 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6223 if (!info
->attrs
[NL80211_ATTR_MAC
])
6226 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6229 if (!rdev
->ops
->disassoc
)
6232 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6233 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6236 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6238 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6239 if (reason_code
== 0) {
6240 /* Reason Code 0 is reserved */
6244 if (info
->attrs
[NL80211_ATTR_IE
]) {
6245 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6246 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6249 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6251 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6252 local_state_change
);
6256 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6257 int mcast_rate
[IEEE80211_NUM_BANDS
],
6260 struct wiphy
*wiphy
= &rdev
->wiphy
;
6264 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6265 struct ieee80211_supported_band
*sband
;
6267 sband
= wiphy
->bands
[band
];
6271 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6272 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6273 mcast_rate
[band
] = i
+ 1;
6283 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6285 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6286 struct net_device
*dev
= info
->user_ptr
[1];
6287 struct cfg80211_ibss_params ibss
;
6288 struct wiphy
*wiphy
;
6289 struct cfg80211_cached_keys
*connkeys
= NULL
;
6292 memset(&ibss
, 0, sizeof(ibss
));
6294 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6297 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6298 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6301 ibss
.beacon_interval
= 100;
6303 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6304 ibss
.beacon_interval
=
6305 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6306 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6310 if (!rdev
->ops
->join_ibss
)
6313 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6316 wiphy
= &rdev
->wiphy
;
6318 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6319 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6321 if (!is_valid_ether_addr(ibss
.bssid
))
6324 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6325 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6327 if (info
->attrs
[NL80211_ATTR_IE
]) {
6328 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6329 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6332 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6336 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6339 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
6341 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
6342 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
6345 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6346 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6348 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6350 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6352 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6353 struct ieee80211_supported_band
*sband
=
6354 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6356 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6362 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6363 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6364 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6367 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6370 connkeys
= nl80211_parse_connkeys(rdev
,
6371 info
->attrs
[NL80211_ATTR_KEYS
],
6373 if (IS_ERR(connkeys
))
6374 return PTR_ERR(connkeys
);
6376 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6384 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6386 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6392 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6394 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6395 struct net_device
*dev
= info
->user_ptr
[1];
6397 if (!rdev
->ops
->leave_ibss
)
6400 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6403 return cfg80211_leave_ibss(rdev
, dev
, false);
6406 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6408 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6409 struct net_device
*dev
= info
->user_ptr
[1];
6410 int mcast_rate
[IEEE80211_NUM_BANDS
];
6414 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6415 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6418 if (!rdev
->ops
->set_mcast_rate
)
6421 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6423 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6426 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6427 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6430 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6435 static struct sk_buff
*
6436 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
6437 int approxlen
, u32 portid
, u32 seq
,
6438 enum nl80211_commands cmd
,
6439 enum nl80211_attrs attr
,
6440 const struct nl80211_vendor_cmd_info
*info
,
6443 struct sk_buff
*skb
;
6445 struct nlattr
*data
;
6447 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6451 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
6457 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6458 goto nla_put_failure
;
6461 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
6463 goto nla_put_failure
;
6464 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
6466 goto nla_put_failure
;
6469 data
= nla_nest_start(skb
, attr
);
6471 ((void **)skb
->cb
)[0] = rdev
;
6472 ((void **)skb
->cb
)[1] = hdr
;
6473 ((void **)skb
->cb
)[2] = data
;
6482 #ifdef CONFIG_NL80211_TESTMODE
6483 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6487 static struct genl_multicast_group nl80211_vendor_mcgrp
= {
6491 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6493 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6496 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6500 if (rdev
->ops
->testmode_cmd
) {
6501 rdev
->cur_cmd_info
= info
;
6502 err
= rdev_testmode_cmd(rdev
,
6503 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6504 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6505 rdev
->cur_cmd_info
= NULL
;
6511 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6512 struct netlink_callback
*cb
)
6514 struct cfg80211_registered_device
*rdev
;
6522 * 0 is a valid index, but not valid for args[0],
6523 * so we need to offset by 1.
6525 phy_idx
= cb
->args
[0] - 1;
6527 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6528 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6533 mutex_lock(&cfg80211_mutex
);
6534 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6535 nl80211_fam
.attrbuf
);
6537 mutex_unlock(&cfg80211_mutex
);
6538 return PTR_ERR(rdev
);
6540 phy_idx
= rdev
->wiphy_idx
;
6542 mutex_unlock(&cfg80211_mutex
);
6544 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6546 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6550 data
= nla_data((void *)cb
->args
[1]);
6551 data_len
= nla_len((void *)cb
->args
[1]);
6554 mutex_lock(&cfg80211_mutex
);
6555 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6557 mutex_unlock(&cfg80211_mutex
);
6560 cfg80211_lock_rdev(rdev
);
6561 mutex_unlock(&cfg80211_mutex
);
6563 if (!rdev
->ops
->testmode_dump
) {
6569 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6570 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6571 NL80211_CMD_TESTMODE
);
6572 struct nlattr
*tmdata
;
6577 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6578 genlmsg_cancel(skb
, hdr
);
6582 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6584 genlmsg_cancel(skb
, hdr
);
6587 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6588 nla_nest_end(skb
, tmdata
);
6590 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6591 genlmsg_cancel(skb
, hdr
);
6594 genlmsg_cancel(skb
, hdr
);
6598 genlmsg_end(skb
, hdr
);
6603 cb
->args
[0] = phy_idx
+ 1;
6605 cfg80211_unlock_rdev(rdev
);
6609 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
6610 enum nl80211_commands cmd
,
6611 enum nl80211_attrs attr
,
6612 int vendor_event_idx
,
6613 int approxlen
, gfp_t gfp
)
6615 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6616 const struct nl80211_vendor_cmd_info
*info
;
6619 case NL80211_CMD_TESTMODE
:
6620 if (WARN_ON(vendor_event_idx
!= -1))
6624 case NL80211_CMD_VENDOR
:
6625 if (WARN_ON(vendor_event_idx
< 0 ||
6626 vendor_event_idx
>= wiphy
->n_vendor_events
))
6628 info
= &wiphy
->vendor_events
[vendor_event_idx
];
6634 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
, 0, 0,
6635 cmd
, attr
, info
, gfp
);
6637 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
6639 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
6641 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6642 void *hdr
= ((void **)skb
->cb
)[1];
6643 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6645 nla_nest_end(skb
, data
);
6646 genlmsg_end(skb
, hdr
);
6648 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
6649 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6650 nl80211_vendor_mcgrp
.id
, gfp
);
6652 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6653 nl80211_testmode_mcgrp
.id
, gfp
);
6655 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
6658 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6660 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6661 struct net_device
*dev
= info
->user_ptr
[1];
6662 struct cfg80211_connect_params connect
;
6663 struct wiphy
*wiphy
;
6664 struct cfg80211_cached_keys
*connkeys
= NULL
;
6667 memset(&connect
, 0, sizeof(connect
));
6669 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6672 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6673 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6676 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6678 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6679 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6680 NL80211_CMD_CONNECT
))
6683 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6685 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6687 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6688 NL80211_MAX_NR_CIPHER_SUITES
);
6692 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6693 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6696 wiphy
= &rdev
->wiphy
;
6698 connect
.bg_scan_period
= -1;
6699 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6700 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6701 connect
.bg_scan_period
=
6702 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6705 if (info
->attrs
[NL80211_ATTR_MAC
])
6706 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6707 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6708 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6710 if (info
->attrs
[NL80211_ATTR_IE
]) {
6711 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6712 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6715 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6716 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6717 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6718 connect
.mfp
!= NL80211_MFP_NO
)
6721 connect
.mfp
= NL80211_MFP_NO
;
6724 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6726 ieee80211_get_channel(wiphy
,
6727 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6728 if (!connect
.channel
||
6729 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6733 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6734 connkeys
= nl80211_parse_connkeys(rdev
,
6735 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6736 if (IS_ERR(connkeys
))
6737 return PTR_ERR(connkeys
);
6740 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6741 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6743 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6744 memcpy(&connect
.ht_capa_mask
,
6745 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6746 sizeof(connect
.ht_capa_mask
));
6748 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6749 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6753 memcpy(&connect
.ht_capa
,
6754 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6755 sizeof(connect
.ht_capa
));
6758 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6759 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6761 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6762 memcpy(&connect
.vht_capa_mask
,
6763 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6764 sizeof(connect
.vht_capa_mask
));
6766 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6767 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6771 memcpy(&connect
.vht_capa
,
6772 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6773 sizeof(connect
.vht_capa
));
6776 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
6782 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6784 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6785 struct net_device
*dev
= info
->user_ptr
[1];
6788 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6789 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6791 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6796 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6797 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6800 return cfg80211_disconnect(rdev
, dev
, reason
, true);
6803 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6805 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6810 if (!info
->attrs
[NL80211_ATTR_PID
])
6813 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6815 net
= get_net_ns_by_pid(pid
);
6817 return PTR_ERR(net
);
6821 /* check if anything to do */
6822 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6823 err
= cfg80211_switch_netns(rdev
, net
);
6829 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6831 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6832 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6833 struct cfg80211_pmksa
*pmksa
) = NULL
;
6834 struct net_device
*dev
= info
->user_ptr
[1];
6835 struct cfg80211_pmksa pmksa
;
6837 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6839 if (!info
->attrs
[NL80211_ATTR_MAC
])
6842 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6845 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6846 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6848 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6849 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6852 switch (info
->genlhdr
->cmd
) {
6853 case NL80211_CMD_SET_PMKSA
:
6854 rdev_ops
= rdev
->ops
->set_pmksa
;
6856 case NL80211_CMD_DEL_PMKSA
:
6857 rdev_ops
= rdev
->ops
->del_pmksa
;
6867 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6870 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6872 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6873 struct net_device
*dev
= info
->user_ptr
[1];
6875 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6876 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6879 if (!rdev
->ops
->flush_pmksa
)
6882 return rdev_flush_pmksa(rdev
, dev
);
6885 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6887 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6888 struct net_device
*dev
= info
->user_ptr
[1];
6889 u8 action_code
, dialog_token
;
6893 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6894 !rdev
->ops
->tdls_mgmt
)
6897 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6898 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6899 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6900 !info
->attrs
[NL80211_ATTR_IE
] ||
6901 !info
->attrs
[NL80211_ATTR_MAC
])
6904 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6905 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6906 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6907 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6909 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6910 dialog_token
, status_code
,
6911 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6912 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6915 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6917 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6918 struct net_device
*dev
= info
->user_ptr
[1];
6919 enum nl80211_tdls_operation operation
;
6922 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6923 !rdev
->ops
->tdls_oper
)
6926 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6927 !info
->attrs
[NL80211_ATTR_MAC
])
6930 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6931 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6933 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6936 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6937 struct genl_info
*info
)
6939 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6940 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6941 struct cfg80211_chan_def chandef
;
6942 struct sk_buff
*msg
;
6948 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6949 !info
->attrs
[NL80211_ATTR_DURATION
])
6952 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6954 if (!rdev
->ops
->remain_on_channel
||
6955 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6959 * We should be on that channel for at least a minimum amount of
6960 * time (10ms) but no longer than the driver supports.
6962 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6963 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6966 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6970 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6974 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6975 NL80211_CMD_REMAIN_ON_CHANNEL
);
6981 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6987 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6988 goto nla_put_failure
;
6990 genlmsg_end(msg
, hdr
);
6992 return genlmsg_reply(msg
, info
);
7001 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7002 struct genl_info
*info
)
7004 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7005 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7008 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7011 if (!rdev
->ops
->cancel_remain_on_channel
)
7014 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7016 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7019 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7020 u8
*rates
, u8 rates_len
)
7025 for (i
= 0; i
< rates_len
; i
++) {
7026 int rate
= (rates
[i
] & 0x7f) * 5;
7028 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7029 struct ieee80211_rate
*srate
=
7030 &sband
->bitrates
[ridx
];
7031 if (rate
== srate
->bitrate
) {
7036 if (ridx
== sband
->n_bitrates
)
7037 return 0; /* rate not found */
7043 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7044 u8
*rates
, u8 rates_len
,
7045 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7049 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7051 for (i
= 0; i
< rates_len
; i
++) {
7054 ridx
= rates
[i
] / 8;
7055 rbit
= BIT(rates
[i
] % 8);
7057 /* check validity */
7058 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7061 /* check availability */
7062 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7071 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7072 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7073 .len
= NL80211_MAX_SUPP_RATES
},
7074 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7075 .len
= NL80211_MAX_SUPP_HT_RATES
},
7078 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7079 struct genl_info
*info
)
7081 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7082 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7083 struct cfg80211_bitrate_mask mask
;
7085 struct net_device
*dev
= info
->user_ptr
[1];
7086 struct nlattr
*tx_rates
;
7087 struct ieee80211_supported_band
*sband
;
7089 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7092 if (!rdev
->ops
->set_bitrate_mask
)
7095 memset(&mask
, 0, sizeof(mask
));
7096 /* Default to all rates enabled */
7097 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7098 sband
= rdev
->wiphy
.bands
[i
];
7099 mask
.control
[i
].legacy
=
7100 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7102 memcpy(mask
.control
[i
].mcs
,
7103 sband
->ht_cap
.mcs
.rx_mask
,
7104 sizeof(mask
.control
[i
].mcs
));
7106 memset(mask
.control
[i
].mcs
, 0,
7107 sizeof(mask
.control
[i
].mcs
));
7111 * The nested attribute uses enum nl80211_band as the index. This maps
7112 * directly to the enum ieee80211_band values used in cfg80211.
7114 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7115 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7117 enum ieee80211_band band
= nla_type(tx_rates
);
7118 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7120 sband
= rdev
->wiphy
.bands
[band
];
7123 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7124 nla_len(tx_rates
), nl80211_txattr_policy
);
7125 if (tb
[NL80211_TXRATE_LEGACY
]) {
7126 mask
.control
[band
].legacy
= rateset_to_mask(
7128 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7129 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7130 if ((mask
.control
[band
].legacy
== 0) &&
7131 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7134 if (tb
[NL80211_TXRATE_MCS
]) {
7135 if (!ht_rateset_to_mask(
7137 nla_data(tb
[NL80211_TXRATE_MCS
]),
7138 nla_len(tb
[NL80211_TXRATE_MCS
]),
7139 mask
.control
[band
].mcs
))
7143 if (mask
.control
[band
].legacy
== 0) {
7144 /* don't allow empty legacy rates if HT
7145 * is not even supported. */
7146 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7149 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7150 if (mask
.control
[band
].mcs
[i
])
7153 /* legacy and mcs rates may not be both empty */
7154 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7159 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7162 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7164 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7165 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7166 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7168 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7171 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7172 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7174 switch (wdev
->iftype
) {
7175 case NL80211_IFTYPE_STATION
:
7176 case NL80211_IFTYPE_ADHOC
:
7177 case NL80211_IFTYPE_P2P_CLIENT
:
7178 case NL80211_IFTYPE_AP
:
7179 case NL80211_IFTYPE_AP_VLAN
:
7180 case NL80211_IFTYPE_MESH_POINT
:
7181 case NL80211_IFTYPE_P2P_GO
:
7182 case NL80211_IFTYPE_P2P_DEVICE
:
7188 /* not much point in registering if we can't reply */
7189 if (!rdev
->ops
->mgmt_tx
)
7192 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7193 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7194 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7197 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7199 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7200 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7201 struct cfg80211_chan_def chandef
;
7205 struct sk_buff
*msg
= NULL
;
7206 unsigned int wait
= 0;
7207 bool offchan
, no_cck
, dont_wait_for_ack
;
7209 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7211 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7214 if (!rdev
->ops
->mgmt_tx
)
7217 switch (wdev
->iftype
) {
7218 case NL80211_IFTYPE_STATION
:
7219 case NL80211_IFTYPE_ADHOC
:
7220 case NL80211_IFTYPE_P2P_CLIENT
:
7221 case NL80211_IFTYPE_AP
:
7222 case NL80211_IFTYPE_AP_VLAN
:
7223 case NL80211_IFTYPE_MESH_POINT
:
7224 case NL80211_IFTYPE_P2P_GO
:
7225 case NL80211_IFTYPE_P2P_DEVICE
:
7231 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7232 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7234 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7237 * We should wait on the channel for at least a minimum amount
7238 * of time (10ms) but no longer than the driver supports.
7240 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7241 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7246 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7248 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7251 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7253 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7257 if (!dont_wait_for_ack
) {
7258 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7262 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7270 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7271 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7272 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7273 no_cck
, dont_wait_for_ack
, &cookie
);
7278 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7279 goto nla_put_failure
;
7281 genlmsg_end(msg
, hdr
);
7282 return genlmsg_reply(msg
, info
);
7294 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7296 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7297 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7300 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7303 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7306 switch (wdev
->iftype
) {
7307 case NL80211_IFTYPE_STATION
:
7308 case NL80211_IFTYPE_ADHOC
:
7309 case NL80211_IFTYPE_P2P_CLIENT
:
7310 case NL80211_IFTYPE_AP
:
7311 case NL80211_IFTYPE_AP_VLAN
:
7312 case NL80211_IFTYPE_P2P_GO
:
7313 case NL80211_IFTYPE_P2P_DEVICE
:
7319 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7321 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7324 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7326 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7327 struct wireless_dev
*wdev
;
7328 struct net_device
*dev
= info
->user_ptr
[1];
7333 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7336 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7338 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7341 wdev
= dev
->ieee80211_ptr
;
7343 if (!rdev
->ops
->set_power_mgmt
)
7346 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7348 if (state
== wdev
->ps
)
7351 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7357 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7359 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7360 enum nl80211_ps_state ps_state
;
7361 struct wireless_dev
*wdev
;
7362 struct net_device
*dev
= info
->user_ptr
[1];
7363 struct sk_buff
*msg
;
7367 wdev
= dev
->ieee80211_ptr
;
7369 if (!rdev
->ops
->set_power_mgmt
)
7372 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7376 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7377 NL80211_CMD_GET_POWER_SAVE
);
7384 ps_state
= NL80211_PS_ENABLED
;
7386 ps_state
= NL80211_PS_DISABLED
;
7388 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7389 goto nla_put_failure
;
7391 genlmsg_end(msg
, hdr
);
7392 return genlmsg_reply(msg
, info
);
7401 static struct nla_policy
7402 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7403 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7404 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7405 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7406 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7407 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7408 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7411 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7412 u32 rate
, u32 pkts
, u32 intvl
)
7414 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7415 struct wireless_dev
*wdev
;
7416 struct net_device
*dev
= info
->user_ptr
[1];
7418 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7421 wdev
= dev
->ieee80211_ptr
;
7423 if (!rdev
->ops
->set_cqm_txe_config
)
7426 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7427 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7430 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7433 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7434 s32 threshold
, u32 hysteresis
)
7436 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7437 struct wireless_dev
*wdev
;
7438 struct net_device
*dev
= info
->user_ptr
[1];
7443 wdev
= dev
->ieee80211_ptr
;
7445 if (!rdev
->ops
->set_cqm_rssi_config
)
7448 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7449 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7452 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7455 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7457 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7461 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7467 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7468 nl80211_attr_cqm_policy
);
7472 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7473 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7476 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7477 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7478 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7479 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7480 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7481 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7482 u32 rate
, pkts
, intvl
;
7483 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7484 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7485 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7486 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7494 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7496 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7497 struct net_device
*dev
= info
->user_ptr
[1];
7498 struct mesh_config cfg
;
7499 struct mesh_setup setup
;
7502 /* start with default */
7503 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7504 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7506 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7507 /* and parse parameters if given */
7508 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7513 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7514 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7517 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7518 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7520 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7521 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7522 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7525 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7526 setup
.beacon_interval
=
7527 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7528 if (setup
.beacon_interval
< 10 ||
7529 setup
.beacon_interval
> 10000)
7533 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7535 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7536 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7540 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7541 /* parse additional setup parameters if given */
7542 err
= nl80211_parse_mesh_setup(info
, &setup
);
7548 cfg
.auto_open_plinks
= false;
7550 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7551 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7555 /* cfg80211_join_mesh() will sort it out */
7556 setup
.chandef
.chan
= NULL
;
7559 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7562 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7564 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7565 struct net_device
*dev
= info
->user_ptr
[1];
7567 return cfg80211_leave_mesh(rdev
, dev
);
7571 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7572 struct cfg80211_registered_device
*rdev
)
7574 struct nlattr
*nl_pats
, *nl_pat
;
7577 if (!rdev
->wowlan
->n_patterns
)
7580 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7584 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
7585 nl_pat
= nla_nest_start(msg
, i
+ 1);
7588 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
7589 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7590 DIV_ROUND_UP(pat_len
, 8),
7591 rdev
->wowlan
->patterns
[i
].mask
) ||
7592 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7593 pat_len
, rdev
->wowlan
->patterns
[i
].pattern
) ||
7594 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7595 rdev
->wowlan
->patterns
[i
].pkt_offset
))
7597 nla_nest_end(msg
, nl_pat
);
7599 nla_nest_end(msg
, nl_pats
);
7604 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7605 struct cfg80211_wowlan_tcp
*tcp
)
7607 struct nlattr
*nl_tcp
;
7612 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7616 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7617 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7618 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7619 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7620 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7621 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7622 tcp
->payload_len
, tcp
->payload
) ||
7623 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7624 tcp
->data_interval
) ||
7625 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7626 tcp
->wake_len
, tcp
->wake_data
) ||
7627 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7628 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7631 if (tcp
->payload_seq
.len
&&
7632 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7633 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7636 if (tcp
->payload_tok
.len
&&
7637 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7638 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7642 nla_nest_end(msg
, nl_tcp
);
7647 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7649 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7650 struct sk_buff
*msg
;
7652 u32 size
= NLMSG_DEFAULT_SIZE
;
7654 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7655 !rdev
->wiphy
.wowlan
.tcp
)
7658 if (rdev
->wowlan
&& rdev
->wowlan
->tcp
) {
7659 /* adjust size to have room for all the data */
7660 size
+= rdev
->wowlan
->tcp
->tokens_size
+
7661 rdev
->wowlan
->tcp
->payload_len
+
7662 rdev
->wowlan
->tcp
->wake_len
+
7663 rdev
->wowlan
->tcp
->wake_len
/ 8;
7666 msg
= nlmsg_new(size
, GFP_KERNEL
);
7670 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7671 NL80211_CMD_GET_WOWLAN
);
7673 goto nla_put_failure
;
7676 struct nlattr
*nl_wowlan
;
7678 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7680 goto nla_put_failure
;
7682 if ((rdev
->wowlan
->any
&&
7683 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7684 (rdev
->wowlan
->disconnect
&&
7685 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7686 (rdev
->wowlan
->magic_pkt
&&
7687 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7688 (rdev
->wowlan
->gtk_rekey_failure
&&
7689 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7690 (rdev
->wowlan
->eap_identity_req
&&
7691 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7692 (rdev
->wowlan
->four_way_handshake
&&
7693 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7694 (rdev
->wowlan
->rfkill_release
&&
7695 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7696 goto nla_put_failure
;
7698 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7699 goto nla_put_failure
;
7701 if (nl80211_send_wowlan_tcp(msg
, rdev
->wowlan
->tcp
))
7702 goto nla_put_failure
;
7704 nla_nest_end(msg
, nl_wowlan
);
7707 genlmsg_end(msg
, hdr
);
7708 return genlmsg_reply(msg
, info
);
7715 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7716 struct nlattr
*attr
,
7717 struct cfg80211_wowlan
*trig
)
7719 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7720 struct cfg80211_wowlan_tcp
*cfg
;
7721 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7722 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7724 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7727 if (!rdev
->wiphy
.wowlan
.tcp
)
7730 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7731 nla_data(attr
), nla_len(attr
),
7732 nl80211_wowlan_tcp_policy
);
7736 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7737 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7738 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7739 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7740 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7741 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7742 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7743 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7746 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7747 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7750 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7751 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
||
7752 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7755 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7756 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7759 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7760 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7763 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7764 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7766 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7767 tokens_size
= tokln
- sizeof(*tok
);
7769 if (!tok
->len
|| tokens_size
% tok
->len
)
7771 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7773 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7775 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7777 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7779 if (tok
->offset
+ tok
->len
> data_size
)
7783 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7784 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7785 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7787 if (seq
->len
== 0 || seq
->len
> 4)
7789 if (seq
->len
+ seq
->offset
> data_size
)
7793 size
= sizeof(*cfg
);
7795 size
+= wake_size
+ wake_mask_size
;
7796 size
+= tokens_size
;
7798 cfg
= kzalloc(size
, GFP_KERNEL
);
7801 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7802 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7803 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7805 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7806 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7810 /* allocate a socket and port for it and use it */
7811 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7812 IPPROTO_TCP
, &cfg
->sock
, 1);
7817 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7818 sock_release(cfg
->sock
);
7822 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7828 cfg
->src_port
= port
;
7831 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7832 cfg
->payload_len
= data_size
;
7833 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7834 memcpy((void *)cfg
->payload
,
7835 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7838 cfg
->payload_seq
= *seq
;
7839 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7840 cfg
->wake_len
= wake_size
;
7841 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7842 memcpy((void *)cfg
->wake_data
,
7843 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7845 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7846 data_size
+ wake_size
;
7847 memcpy((void *)cfg
->wake_mask
,
7848 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7851 cfg
->tokens_size
= tokens_size
;
7852 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7860 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7862 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7863 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7864 struct cfg80211_wowlan new_triggers
= {};
7865 struct cfg80211_wowlan
*ntrig
;
7866 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7868 bool prev_enabled
= rdev
->wowlan
;
7870 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7871 !rdev
->wiphy
.wowlan
.tcp
)
7874 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7875 cfg80211_rdev_free_wowlan(rdev
);
7876 rdev
->wowlan
= NULL
;
7880 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7881 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7882 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7883 nl80211_wowlan_policy
);
7887 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7888 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7890 new_triggers
.any
= true;
7893 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7894 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7896 new_triggers
.disconnect
= true;
7899 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7900 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7902 new_triggers
.magic_pkt
= true;
7905 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7908 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7909 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7911 new_triggers
.gtk_rekey_failure
= true;
7914 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7915 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7917 new_triggers
.eap_identity_req
= true;
7920 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7921 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7923 new_triggers
.four_way_handshake
= true;
7926 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7927 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7929 new_triggers
.rfkill_release
= true;
7932 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7935 int rem
, pat_len
, mask_len
, pkt_offset
;
7936 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7938 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7941 if (n_patterns
> wowlan
->n_patterns
)
7944 new_triggers
.patterns
= kcalloc(n_patterns
,
7945 sizeof(new_triggers
.patterns
[0]),
7947 if (!new_triggers
.patterns
)
7950 new_triggers
.n_patterns
= n_patterns
;
7953 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7955 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7956 nla_data(pat
), nla_len(pat
), NULL
);
7958 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7959 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7961 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7962 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7963 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7966 if (pat_len
> wowlan
->pattern_max_len
||
7967 pat_len
< wowlan
->pattern_min_len
)
7970 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7973 pkt_offset
= nla_get_u32(
7974 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7975 if (pkt_offset
> wowlan
->max_pkt_offset
)
7977 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7979 new_triggers
.patterns
[i
].mask
=
7980 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7981 if (!new_triggers
.patterns
[i
].mask
) {
7985 new_triggers
.patterns
[i
].pattern
=
7986 new_triggers
.patterns
[i
].mask
+ mask_len
;
7987 memcpy(new_triggers
.patterns
[i
].mask
,
7988 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7990 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7991 memcpy(new_triggers
.patterns
[i
].pattern
,
7992 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
7998 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
7999 err
= nl80211_parse_wowlan_tcp(
8000 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8006 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8011 cfg80211_rdev_free_wowlan(rdev
);
8012 rdev
->wowlan
= ntrig
;
8015 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
8016 rdev_set_wakeup(rdev
, rdev
->wowlan
);
8020 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8021 kfree(new_triggers
.patterns
[i
].mask
);
8022 kfree(new_triggers
.patterns
);
8023 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8024 sock_release(new_triggers
.tcp
->sock
);
8025 kfree(new_triggers
.tcp
);
8030 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8032 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8033 struct net_device
*dev
= info
->user_ptr
[1];
8034 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8035 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8036 struct cfg80211_gtk_rekey_data rekey_data
;
8039 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8042 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8043 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8044 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8045 nl80211_rekey_policy
);
8049 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8051 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8053 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8056 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8058 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8060 memcpy(rekey_data
.replay_ctr
,
8061 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8062 NL80211_REPLAY_CTR_LEN
);
8065 if (!wdev
->current_bss
) {
8070 if (!rdev
->ops
->set_rekey_data
) {
8075 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8081 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8082 struct genl_info
*info
)
8084 struct net_device
*dev
= info
->user_ptr
[1];
8085 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8087 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8088 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8091 if (wdev
->ap_unexpected_nlportid
)
8094 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8098 static int nl80211_probe_client(struct sk_buff
*skb
,
8099 struct genl_info
*info
)
8101 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8102 struct net_device
*dev
= info
->user_ptr
[1];
8103 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8104 struct sk_buff
*msg
;
8110 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8111 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8114 if (!info
->attrs
[NL80211_ATTR_MAC
])
8117 if (!rdev
->ops
->probe_client
)
8120 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8124 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8125 NL80211_CMD_PROBE_CLIENT
);
8131 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8133 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8137 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8138 goto nla_put_failure
;
8140 genlmsg_end(msg
, hdr
);
8142 return genlmsg_reply(msg
, info
);
8151 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8153 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8154 struct cfg80211_beacon_registration
*reg
, *nreg
;
8157 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8160 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8164 /* First, check if already registered. */
8165 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8166 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8167 if (reg
->nlportid
== info
->snd_portid
) {
8172 /* Add it to the list */
8173 nreg
->nlportid
= info
->snd_portid
;
8174 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8176 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8180 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8185 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8187 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8188 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8191 if (!rdev
->ops
->start_p2p_device
)
8194 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8197 if (wdev
->p2p_started
)
8200 mutex_lock(&rdev
->devlist_mtx
);
8201 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8202 mutex_unlock(&rdev
->devlist_mtx
);
8206 err
= rdev_start_p2p_device(rdev
, wdev
);
8210 wdev
->p2p_started
= true;
8211 mutex_lock(&rdev
->devlist_mtx
);
8213 mutex_unlock(&rdev
->devlist_mtx
);
8218 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8220 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8221 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8223 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8226 if (!rdev
->ops
->stop_p2p_device
)
8229 mutex_lock(&rdev
->devlist_mtx
);
8230 mutex_lock(&rdev
->sched_scan_mtx
);
8231 cfg80211_stop_p2p_device(rdev
, wdev
);
8232 mutex_unlock(&rdev
->sched_scan_mtx
);
8233 mutex_unlock(&rdev
->devlist_mtx
);
8238 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8239 struct genl_info
*info
)
8242 struct sk_buff
*msg
;
8244 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8248 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8249 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8251 goto nla_put_failure
;
8253 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8254 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8255 goto nla_put_failure
;
8257 genlmsg_end(msg
, hdr
);
8258 return genlmsg_reply(msg
, info
);
8265 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8268 struct cfg80211_update_ft_ies_params ft_params
;
8269 struct net_device
*dev
= info
->user_ptr
[1];
8271 if (!rdev
->ops
->update_ft_ies
)
8274 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8275 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8278 memset(&ft_params
, 0, sizeof(ft_params
));
8279 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8280 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8281 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8283 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8286 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8287 struct genl_info
*info
)
8289 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8290 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8291 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8295 if (!rdev
->ops
->crit_proto_start
)
8298 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8301 if (rdev
->crit_proto_nlportid
)
8304 /* determine protocol if provided */
8305 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8306 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8308 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8311 /* timeout must be provided */
8312 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8316 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8318 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8321 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8323 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8328 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8329 struct genl_info
*info
)
8331 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8332 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8334 if (!rdev
->ops
->crit_proto_stop
)
8337 if (rdev
->crit_proto_nlportid
) {
8338 rdev
->crit_proto_nlportid
= 0;
8339 rdev_crit_proto_stop(rdev
, wdev
);
8344 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
8346 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8347 struct wireless_dev
*wdev
=
8348 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8352 if (!rdev
|| !rdev
->wiphy
.vendor_commands
)
8356 err
= PTR_ERR(wdev
);
8360 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8364 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
8365 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
8368 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
8369 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
8370 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
8371 const struct wiphy_vendor_command
*vcmd
;
8375 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
8377 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
8380 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
8381 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
8384 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
8388 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
8389 if (!wdev
->netdev
||
8390 !netif_running(wdev
->netdev
))
8397 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
8398 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8399 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8402 rdev
->cur_cmd_info
= info
;
8403 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
8405 rdev
->cur_cmd_info
= NULL
;
8412 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
8413 enum nl80211_commands cmd
,
8414 enum nl80211_attrs attr
,
8417 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8419 if (WARN_ON(!rdev
->cur_cmd_info
))
8422 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
,
8425 cmd
, attr
, NULL
, GFP_KERNEL
);
8427 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
8429 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
8431 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8432 void *hdr
= ((void **)skb
->cb
)[1];
8433 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8435 if (WARN_ON(!rdev
->cur_cmd_info
)) {
8440 nla_nest_end(skb
, data
);
8441 genlmsg_end(skb
, hdr
);
8442 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
8444 EXPORT_SYMBOL(cfg80211_vendor_cmd_reply
);
8446 #define NL80211_FLAG_NEED_WIPHY 0x01
8447 #define NL80211_FLAG_NEED_NETDEV 0x02
8448 #define NL80211_FLAG_NEED_RTNL 0x04
8449 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8450 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8451 NL80211_FLAG_CHECK_NETDEV_UP)
8452 #define NL80211_FLAG_NEED_WDEV 0x10
8453 /* If a netdev is associated, it must be UP, P2P must be started */
8454 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8455 NL80211_FLAG_CHECK_NETDEV_UP)
8457 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8458 struct genl_info
*info
)
8460 struct cfg80211_registered_device
*rdev
;
8461 struct wireless_dev
*wdev
;
8462 struct net_device
*dev
;
8463 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8468 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8469 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8473 return PTR_ERR(rdev
);
8475 info
->user_ptr
[0] = rdev
;
8476 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8477 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8478 mutex_lock(&cfg80211_mutex
);
8479 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8482 mutex_unlock(&cfg80211_mutex
);
8485 return PTR_ERR(wdev
);
8489 rdev
= wiphy_to_dev(wdev
->wiphy
);
8491 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8493 mutex_unlock(&cfg80211_mutex
);
8499 info
->user_ptr
[1] = dev
;
8501 info
->user_ptr
[1] = wdev
;
8505 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8506 !netif_running(dev
)) {
8507 mutex_unlock(&cfg80211_mutex
);
8514 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8515 if (!wdev
->p2p_started
) {
8516 mutex_unlock(&cfg80211_mutex
);
8523 cfg80211_lock_rdev(rdev
);
8525 mutex_unlock(&cfg80211_mutex
);
8527 info
->user_ptr
[0] = rdev
;
8533 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8534 struct genl_info
*info
)
8536 if (info
->user_ptr
[0])
8537 cfg80211_unlock_rdev(info
->user_ptr
[0]);
8538 if (info
->user_ptr
[1]) {
8539 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8540 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8543 dev_put(wdev
->netdev
);
8545 dev_put(info
->user_ptr
[1]);
8548 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8552 static struct genl_ops nl80211_ops
[] = {
8554 .cmd
= NL80211_CMD_GET_WIPHY
,
8555 .doit
= nl80211_get_wiphy
,
8556 .dumpit
= nl80211_dump_wiphy
,
8557 .policy
= nl80211_policy
,
8558 /* can be retrieved by unprivileged users */
8559 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
8562 .cmd
= NL80211_CMD_SET_WIPHY
,
8563 .doit
= nl80211_set_wiphy
,
8564 .policy
= nl80211_policy
,
8565 .flags
= GENL_ADMIN_PERM
,
8566 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8569 .cmd
= NL80211_CMD_GET_INTERFACE
,
8570 .doit
= nl80211_get_interface
,
8571 .dumpit
= nl80211_dump_interface
,
8572 .policy
= nl80211_policy
,
8573 /* can be retrieved by unprivileged users */
8574 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
8577 .cmd
= NL80211_CMD_SET_INTERFACE
,
8578 .doit
= nl80211_set_interface
,
8579 .policy
= nl80211_policy
,
8580 .flags
= GENL_ADMIN_PERM
,
8581 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8582 NL80211_FLAG_NEED_RTNL
,
8585 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8586 .doit
= nl80211_new_interface
,
8587 .policy
= nl80211_policy
,
8588 .flags
= GENL_ADMIN_PERM
,
8589 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8590 NL80211_FLAG_NEED_RTNL
,
8593 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8594 .doit
= nl80211_del_interface
,
8595 .policy
= nl80211_policy
,
8596 .flags
= GENL_ADMIN_PERM
,
8597 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8598 NL80211_FLAG_NEED_RTNL
,
8601 .cmd
= NL80211_CMD_GET_KEY
,
8602 .doit
= nl80211_get_key
,
8603 .policy
= nl80211_policy
,
8604 .flags
= GENL_ADMIN_PERM
,
8605 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8606 NL80211_FLAG_NEED_RTNL
,
8609 .cmd
= NL80211_CMD_SET_KEY
,
8610 .doit
= nl80211_set_key
,
8611 .policy
= nl80211_policy
,
8612 .flags
= GENL_ADMIN_PERM
,
8613 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8614 NL80211_FLAG_NEED_RTNL
,
8617 .cmd
= NL80211_CMD_NEW_KEY
,
8618 .doit
= nl80211_new_key
,
8619 .policy
= nl80211_policy
,
8620 .flags
= GENL_ADMIN_PERM
,
8621 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8622 NL80211_FLAG_NEED_RTNL
,
8625 .cmd
= NL80211_CMD_DEL_KEY
,
8626 .doit
= nl80211_del_key
,
8627 .policy
= nl80211_policy
,
8628 .flags
= GENL_ADMIN_PERM
,
8629 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8630 NL80211_FLAG_NEED_RTNL
,
8633 .cmd
= NL80211_CMD_SET_BEACON
,
8634 .policy
= nl80211_policy
,
8635 .flags
= GENL_ADMIN_PERM
,
8636 .doit
= nl80211_set_beacon
,
8637 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8638 NL80211_FLAG_NEED_RTNL
,
8641 .cmd
= NL80211_CMD_START_AP
,
8642 .policy
= nl80211_policy
,
8643 .flags
= GENL_ADMIN_PERM
,
8644 .doit
= nl80211_start_ap
,
8645 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8646 NL80211_FLAG_NEED_RTNL
,
8649 .cmd
= NL80211_CMD_STOP_AP
,
8650 .policy
= nl80211_policy
,
8651 .flags
= GENL_ADMIN_PERM
,
8652 .doit
= nl80211_stop_ap
,
8653 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8654 NL80211_FLAG_NEED_RTNL
,
8657 .cmd
= NL80211_CMD_GET_STATION
,
8658 .doit
= nl80211_get_station
,
8659 .dumpit
= nl80211_dump_station
,
8660 .policy
= nl80211_policy
,
8661 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8662 NL80211_FLAG_NEED_RTNL
,
8665 .cmd
= NL80211_CMD_SET_STATION
,
8666 .doit
= nl80211_set_station
,
8667 .policy
= nl80211_policy
,
8668 .flags
= GENL_ADMIN_PERM
,
8669 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8670 NL80211_FLAG_NEED_RTNL
,
8673 .cmd
= NL80211_CMD_NEW_STATION
,
8674 .doit
= nl80211_new_station
,
8675 .policy
= nl80211_policy
,
8676 .flags
= GENL_ADMIN_PERM
,
8677 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8678 NL80211_FLAG_NEED_RTNL
,
8681 .cmd
= NL80211_CMD_DEL_STATION
,
8682 .doit
= nl80211_del_station
,
8683 .policy
= nl80211_policy
,
8684 .flags
= GENL_ADMIN_PERM
,
8685 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8686 NL80211_FLAG_NEED_RTNL
,
8689 .cmd
= NL80211_CMD_GET_MPATH
,
8690 .doit
= nl80211_get_mpath
,
8691 .dumpit
= nl80211_dump_mpath
,
8692 .policy
= nl80211_policy
,
8693 .flags
= GENL_ADMIN_PERM
,
8694 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8695 NL80211_FLAG_NEED_RTNL
,
8698 .cmd
= NL80211_CMD_SET_MPATH
,
8699 .doit
= nl80211_set_mpath
,
8700 .policy
= nl80211_policy
,
8701 .flags
= GENL_ADMIN_PERM
,
8702 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8703 NL80211_FLAG_NEED_RTNL
,
8706 .cmd
= NL80211_CMD_NEW_MPATH
,
8707 .doit
= nl80211_new_mpath
,
8708 .policy
= nl80211_policy
,
8709 .flags
= GENL_ADMIN_PERM
,
8710 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8711 NL80211_FLAG_NEED_RTNL
,
8714 .cmd
= NL80211_CMD_DEL_MPATH
,
8715 .doit
= nl80211_del_mpath
,
8716 .policy
= nl80211_policy
,
8717 .flags
= GENL_ADMIN_PERM
,
8718 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8719 NL80211_FLAG_NEED_RTNL
,
8722 .cmd
= NL80211_CMD_SET_BSS
,
8723 .doit
= nl80211_set_bss
,
8724 .policy
= nl80211_policy
,
8725 .flags
= GENL_ADMIN_PERM
,
8726 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8727 NL80211_FLAG_NEED_RTNL
,
8730 .cmd
= NL80211_CMD_GET_REG
,
8731 .doit
= nl80211_get_reg
,
8732 .policy
= nl80211_policy
,
8733 /* can be retrieved by unprivileged users */
8736 .cmd
= NL80211_CMD_SET_REG
,
8737 .doit
= nl80211_set_reg
,
8738 .policy
= nl80211_policy
,
8739 .flags
= GENL_ADMIN_PERM
,
8742 .cmd
= NL80211_CMD_REQ_SET_REG
,
8743 .doit
= nl80211_req_set_reg
,
8744 .policy
= nl80211_policy
,
8745 .flags
= GENL_ADMIN_PERM
,
8748 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8749 .doit
= nl80211_get_mesh_config
,
8750 .policy
= nl80211_policy
,
8751 /* can be retrieved by unprivileged users */
8752 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8753 NL80211_FLAG_NEED_RTNL
,
8756 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8757 .doit
= nl80211_update_mesh_config
,
8758 .policy
= nl80211_policy
,
8759 .flags
= GENL_ADMIN_PERM
,
8760 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8761 NL80211_FLAG_NEED_RTNL
,
8764 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8765 .doit
= nl80211_trigger_scan
,
8766 .policy
= nl80211_policy
,
8767 .flags
= GENL_ADMIN_PERM
,
8768 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8769 NL80211_FLAG_NEED_RTNL
,
8772 .cmd
= NL80211_CMD_GET_SCAN
,
8773 .policy
= nl80211_policy
,
8774 .dumpit
= nl80211_dump_scan
,
8777 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8778 .doit
= nl80211_start_sched_scan
,
8779 .policy
= nl80211_policy
,
8780 .flags
= GENL_ADMIN_PERM
,
8781 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8782 NL80211_FLAG_NEED_RTNL
,
8785 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8786 .doit
= nl80211_stop_sched_scan
,
8787 .policy
= nl80211_policy
,
8788 .flags
= GENL_ADMIN_PERM
,
8789 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8790 NL80211_FLAG_NEED_RTNL
,
8793 .cmd
= NL80211_CMD_AUTHENTICATE
,
8794 .doit
= nl80211_authenticate
,
8795 .policy
= nl80211_policy
,
8796 .flags
= GENL_ADMIN_PERM
,
8797 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8798 NL80211_FLAG_NEED_RTNL
,
8801 .cmd
= NL80211_CMD_ASSOCIATE
,
8802 .doit
= nl80211_associate
,
8803 .policy
= nl80211_policy
,
8804 .flags
= GENL_ADMIN_PERM
,
8805 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8806 NL80211_FLAG_NEED_RTNL
,
8809 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8810 .doit
= nl80211_deauthenticate
,
8811 .policy
= nl80211_policy
,
8812 .flags
= GENL_ADMIN_PERM
,
8813 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8814 NL80211_FLAG_NEED_RTNL
,
8817 .cmd
= NL80211_CMD_DISASSOCIATE
,
8818 .doit
= nl80211_disassociate
,
8819 .policy
= nl80211_policy
,
8820 .flags
= GENL_ADMIN_PERM
,
8821 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8822 NL80211_FLAG_NEED_RTNL
,
8825 .cmd
= NL80211_CMD_JOIN_IBSS
,
8826 .doit
= nl80211_join_ibss
,
8827 .policy
= nl80211_policy
,
8828 .flags
= GENL_ADMIN_PERM
,
8829 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8830 NL80211_FLAG_NEED_RTNL
,
8833 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8834 .doit
= nl80211_leave_ibss
,
8835 .policy
= nl80211_policy
,
8836 .flags
= GENL_ADMIN_PERM
,
8837 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8838 NL80211_FLAG_NEED_RTNL
,
8840 #ifdef CONFIG_NL80211_TESTMODE
8842 .cmd
= NL80211_CMD_TESTMODE
,
8843 .doit
= nl80211_testmode_do
,
8844 .dumpit
= nl80211_testmode_dump
,
8845 .policy
= nl80211_policy
,
8846 .flags
= GENL_ADMIN_PERM
,
8847 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8848 NL80211_FLAG_NEED_RTNL
,
8852 .cmd
= NL80211_CMD_CONNECT
,
8853 .doit
= nl80211_connect
,
8854 .policy
= nl80211_policy
,
8855 .flags
= GENL_ADMIN_PERM
,
8856 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8857 NL80211_FLAG_NEED_RTNL
,
8860 .cmd
= NL80211_CMD_DISCONNECT
,
8861 .doit
= nl80211_disconnect
,
8862 .policy
= nl80211_policy
,
8863 .flags
= GENL_ADMIN_PERM
,
8864 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8865 NL80211_FLAG_NEED_RTNL
,
8868 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8869 .doit
= nl80211_wiphy_netns
,
8870 .policy
= nl80211_policy
,
8871 .flags
= GENL_ADMIN_PERM
,
8872 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8873 NL80211_FLAG_NEED_RTNL
,
8876 .cmd
= NL80211_CMD_GET_SURVEY
,
8877 .policy
= nl80211_policy
,
8878 .dumpit
= nl80211_dump_survey
,
8881 .cmd
= NL80211_CMD_SET_PMKSA
,
8882 .doit
= nl80211_setdel_pmksa
,
8883 .policy
= nl80211_policy
,
8884 .flags
= GENL_ADMIN_PERM
,
8885 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8886 NL80211_FLAG_NEED_RTNL
,
8889 .cmd
= NL80211_CMD_DEL_PMKSA
,
8890 .doit
= nl80211_setdel_pmksa
,
8891 .policy
= nl80211_policy
,
8892 .flags
= GENL_ADMIN_PERM
,
8893 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8894 NL80211_FLAG_NEED_RTNL
,
8897 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8898 .doit
= nl80211_flush_pmksa
,
8899 .policy
= nl80211_policy
,
8900 .flags
= GENL_ADMIN_PERM
,
8901 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8902 NL80211_FLAG_NEED_RTNL
,
8905 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8906 .doit
= nl80211_remain_on_channel
,
8907 .policy
= nl80211_policy
,
8908 .flags
= GENL_ADMIN_PERM
,
8909 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8910 NL80211_FLAG_NEED_RTNL
,
8913 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8914 .doit
= nl80211_cancel_remain_on_channel
,
8915 .policy
= nl80211_policy
,
8916 .flags
= GENL_ADMIN_PERM
,
8917 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8918 NL80211_FLAG_NEED_RTNL
,
8921 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8922 .doit
= nl80211_set_tx_bitrate_mask
,
8923 .policy
= nl80211_policy
,
8924 .flags
= GENL_ADMIN_PERM
,
8925 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8926 NL80211_FLAG_NEED_RTNL
,
8929 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8930 .doit
= nl80211_register_mgmt
,
8931 .policy
= nl80211_policy
,
8932 .flags
= GENL_ADMIN_PERM
,
8933 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8934 NL80211_FLAG_NEED_RTNL
,
8937 .cmd
= NL80211_CMD_FRAME
,
8938 .doit
= nl80211_tx_mgmt
,
8939 .policy
= nl80211_policy
,
8940 .flags
= GENL_ADMIN_PERM
,
8941 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8942 NL80211_FLAG_NEED_RTNL
,
8945 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8946 .doit
= nl80211_tx_mgmt_cancel_wait
,
8947 .policy
= nl80211_policy
,
8948 .flags
= GENL_ADMIN_PERM
,
8949 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8950 NL80211_FLAG_NEED_RTNL
,
8953 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8954 .doit
= nl80211_set_power_save
,
8955 .policy
= nl80211_policy
,
8956 .flags
= GENL_ADMIN_PERM
,
8957 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8958 NL80211_FLAG_NEED_RTNL
,
8961 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8962 .doit
= nl80211_get_power_save
,
8963 .policy
= nl80211_policy
,
8964 /* can be retrieved by unprivileged users */
8965 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8966 NL80211_FLAG_NEED_RTNL
,
8969 .cmd
= NL80211_CMD_SET_CQM
,
8970 .doit
= nl80211_set_cqm
,
8971 .policy
= nl80211_policy
,
8972 .flags
= GENL_ADMIN_PERM
,
8973 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8974 NL80211_FLAG_NEED_RTNL
,
8977 .cmd
= NL80211_CMD_SET_CHANNEL
,
8978 .doit
= nl80211_set_channel
,
8979 .policy
= nl80211_policy
,
8980 .flags
= GENL_ADMIN_PERM
,
8981 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8982 NL80211_FLAG_NEED_RTNL
,
8985 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8986 .doit
= nl80211_set_wds_peer
,
8987 .policy
= nl80211_policy
,
8988 .flags
= GENL_ADMIN_PERM
,
8989 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8990 NL80211_FLAG_NEED_RTNL
,
8993 .cmd
= NL80211_CMD_JOIN_MESH
,
8994 .doit
= nl80211_join_mesh
,
8995 .policy
= nl80211_policy
,
8996 .flags
= GENL_ADMIN_PERM
,
8997 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8998 NL80211_FLAG_NEED_RTNL
,
9001 .cmd
= NL80211_CMD_LEAVE_MESH
,
9002 .doit
= nl80211_leave_mesh
,
9003 .policy
= nl80211_policy
,
9004 .flags
= GENL_ADMIN_PERM
,
9005 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9006 NL80211_FLAG_NEED_RTNL
,
9010 .cmd
= NL80211_CMD_GET_WOWLAN
,
9011 .doit
= nl80211_get_wowlan
,
9012 .policy
= nl80211_policy
,
9013 /* can be retrieved by unprivileged users */
9014 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9015 NL80211_FLAG_NEED_RTNL
,
9018 .cmd
= NL80211_CMD_SET_WOWLAN
,
9019 .doit
= nl80211_set_wowlan
,
9020 .policy
= nl80211_policy
,
9021 .flags
= GENL_ADMIN_PERM
,
9022 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9023 NL80211_FLAG_NEED_RTNL
,
9027 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9028 .doit
= nl80211_set_rekey_data
,
9029 .policy
= nl80211_policy
,
9030 .flags
= GENL_ADMIN_PERM
,
9031 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9032 NL80211_FLAG_NEED_RTNL
,
9035 .cmd
= NL80211_CMD_TDLS_MGMT
,
9036 .doit
= nl80211_tdls_mgmt
,
9037 .policy
= nl80211_policy
,
9038 .flags
= GENL_ADMIN_PERM
,
9039 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9040 NL80211_FLAG_NEED_RTNL
,
9043 .cmd
= NL80211_CMD_TDLS_OPER
,
9044 .doit
= nl80211_tdls_oper
,
9045 .policy
= nl80211_policy
,
9046 .flags
= GENL_ADMIN_PERM
,
9047 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9048 NL80211_FLAG_NEED_RTNL
,
9051 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9052 .doit
= nl80211_register_unexpected_frame
,
9053 .policy
= nl80211_policy
,
9054 .flags
= GENL_ADMIN_PERM
,
9055 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9056 NL80211_FLAG_NEED_RTNL
,
9059 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9060 .doit
= nl80211_probe_client
,
9061 .policy
= nl80211_policy
,
9062 .flags
= GENL_ADMIN_PERM
,
9063 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9064 NL80211_FLAG_NEED_RTNL
,
9067 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9068 .doit
= nl80211_register_beacons
,
9069 .policy
= nl80211_policy
,
9070 .flags
= GENL_ADMIN_PERM
,
9071 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9072 NL80211_FLAG_NEED_RTNL
,
9075 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
9076 .doit
= nl80211_set_noack_map
,
9077 .policy
= nl80211_policy
,
9078 .flags
= GENL_ADMIN_PERM
,
9079 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9080 NL80211_FLAG_NEED_RTNL
,
9083 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
9084 .doit
= nl80211_start_p2p_device
,
9085 .policy
= nl80211_policy
,
9086 .flags
= GENL_ADMIN_PERM
,
9087 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9088 NL80211_FLAG_NEED_RTNL
,
9091 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
9092 .doit
= nl80211_stop_p2p_device
,
9093 .policy
= nl80211_policy
,
9094 .flags
= GENL_ADMIN_PERM
,
9095 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9096 NL80211_FLAG_NEED_RTNL
,
9099 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
9100 .doit
= nl80211_set_mcast_rate
,
9101 .policy
= nl80211_policy
,
9102 .flags
= GENL_ADMIN_PERM
,
9103 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9104 NL80211_FLAG_NEED_RTNL
,
9107 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9108 .doit
= nl80211_set_mac_acl
,
9109 .policy
= nl80211_policy
,
9110 .flags
= GENL_ADMIN_PERM
,
9111 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9112 NL80211_FLAG_NEED_RTNL
,
9115 .cmd
= NL80211_CMD_RADAR_DETECT
,
9116 .doit
= nl80211_start_radar_detection
,
9117 .policy
= nl80211_policy
,
9118 .flags
= GENL_ADMIN_PERM
,
9119 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9120 NL80211_FLAG_NEED_RTNL
,
9123 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9124 .doit
= nl80211_get_protocol_features
,
9125 .policy
= nl80211_policy
,
9128 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9129 .doit
= nl80211_update_ft_ies
,
9130 .policy
= nl80211_policy
,
9131 .flags
= GENL_ADMIN_PERM
,
9132 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9133 NL80211_FLAG_NEED_RTNL
,
9136 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9137 .doit
= nl80211_crit_protocol_start
,
9138 .policy
= nl80211_policy
,
9139 .flags
= GENL_ADMIN_PERM
,
9140 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9141 NL80211_FLAG_NEED_RTNL
,
9144 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9145 .doit
= nl80211_crit_protocol_stop
,
9146 .policy
= nl80211_policy
,
9147 .flags
= GENL_ADMIN_PERM
,
9148 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9149 NL80211_FLAG_NEED_RTNL
,
9152 .cmd
= NL80211_CMD_VENDOR
,
9153 .doit
= nl80211_vendor_cmd
,
9154 .policy
= nl80211_policy
,
9155 .flags
= GENL_ADMIN_PERM
,
9156 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9157 NL80211_FLAG_NEED_RTNL
,
9161 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9165 /* multicast groups */
9166 static struct genl_multicast_group nl80211_config_mcgrp
= {
9169 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9172 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9173 .name
= "regulatory",
9176 /* notification functions */
9178 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9180 struct sk_buff
*msg
;
9182 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9186 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0,
9187 false, NULL
, NULL
, NULL
) < 0) {
9192 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9193 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9196 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9197 struct cfg80211_registered_device
*rdev
)
9199 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9200 struct nlattr
*nest
;
9203 lockdep_assert_held(&rdev
->sched_scan_mtx
);
9208 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9210 goto nla_put_failure
;
9211 for (i
= 0; i
< req
->n_ssids
; i
++) {
9212 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9213 goto nla_put_failure
;
9215 nla_nest_end(msg
, nest
);
9217 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9219 goto nla_put_failure
;
9220 for (i
= 0; i
< req
->n_channels
; i
++) {
9221 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9222 goto nla_put_failure
;
9224 nla_nest_end(msg
, nest
);
9227 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9228 goto nla_put_failure
;
9231 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9238 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9239 struct cfg80211_registered_device
*rdev
,
9240 struct wireless_dev
*wdev
,
9241 u32 portid
, u32 seq
, int flags
,
9246 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9250 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9251 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9252 wdev
->netdev
->ifindex
)) ||
9253 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9254 goto nla_put_failure
;
9256 /* ignore errors and send incomplete event anyway */
9257 nl80211_add_scan_req(msg
, rdev
);
9259 return genlmsg_end(msg
, hdr
);
9262 genlmsg_cancel(msg
, hdr
);
9267 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9268 struct cfg80211_registered_device
*rdev
,
9269 struct net_device
*netdev
,
9270 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9274 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9278 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9279 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9280 goto nla_put_failure
;
9282 return genlmsg_end(msg
, hdr
);
9285 genlmsg_cancel(msg
, hdr
);
9289 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9290 struct wireless_dev
*wdev
)
9292 struct sk_buff
*msg
;
9294 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9298 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9299 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9304 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9305 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9308 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9309 struct wireless_dev
*wdev
)
9311 struct sk_buff
*msg
;
9313 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9317 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9318 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9323 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9324 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9327 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9328 struct wireless_dev
*wdev
)
9330 struct sk_buff
*msg
;
9332 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9336 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9337 NL80211_CMD_SCAN_ABORTED
) < 0) {
9342 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9343 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9346 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9347 struct net_device
*netdev
)
9349 struct sk_buff
*msg
;
9351 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9355 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9356 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9361 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9362 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9365 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9366 struct net_device
*netdev
, u32 cmd
)
9368 struct sk_buff
*msg
;
9370 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9374 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9379 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9380 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9384 * This can happen on global regulatory changes or device specific settings
9385 * based on custom world regulatory domains.
9387 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9389 struct sk_buff
*msg
;
9392 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9396 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9402 /* Userspace can always count this one always being set */
9403 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9404 goto nla_put_failure
;
9406 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9407 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9408 NL80211_REGDOM_TYPE_WORLD
))
9409 goto nla_put_failure
;
9410 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9411 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9412 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9413 goto nla_put_failure
;
9414 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9415 request
->intersect
) {
9416 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9417 NL80211_REGDOM_TYPE_INTERSECTION
))
9418 goto nla_put_failure
;
9420 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9421 NL80211_REGDOM_TYPE_COUNTRY
) ||
9422 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9424 goto nla_put_failure
;
9427 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9428 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9429 goto nla_put_failure
;
9431 genlmsg_end(msg
, hdr
);
9434 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9441 genlmsg_cancel(msg
, hdr
);
9445 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9446 struct net_device
*netdev
,
9447 const u8
*buf
, size_t len
,
9448 enum nl80211_commands cmd
, gfp_t gfp
)
9450 struct sk_buff
*msg
;
9453 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9457 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9463 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9464 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9465 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9466 goto nla_put_failure
;
9468 genlmsg_end(msg
, hdr
);
9470 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9471 nl80211_mlme_mcgrp
.id
, gfp
);
9475 genlmsg_cancel(msg
, hdr
);
9479 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9480 struct net_device
*netdev
, const u8
*buf
,
9481 size_t len
, gfp_t gfp
)
9483 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9484 NL80211_CMD_AUTHENTICATE
, gfp
);
9487 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9488 struct net_device
*netdev
, const u8
*buf
,
9489 size_t len
, gfp_t gfp
)
9491 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9492 NL80211_CMD_ASSOCIATE
, gfp
);
9495 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9496 struct net_device
*netdev
, const u8
*buf
,
9497 size_t len
, gfp_t gfp
)
9499 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9500 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9503 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9504 struct net_device
*netdev
, const u8
*buf
,
9505 size_t len
, gfp_t gfp
)
9507 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9508 NL80211_CMD_DISASSOCIATE
, gfp
);
9511 void cfg80211_send_unprot_deauth(struct net_device
*dev
, const u8
*buf
,
9514 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9515 struct wiphy
*wiphy
= wdev
->wiphy
;
9516 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9518 trace_cfg80211_send_unprot_deauth(dev
);
9519 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9520 NL80211_CMD_UNPROT_DEAUTHENTICATE
, GFP_ATOMIC
);
9522 EXPORT_SYMBOL(cfg80211_send_unprot_deauth
);
9524 void cfg80211_send_unprot_disassoc(struct net_device
*dev
, const u8
*buf
,
9527 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9528 struct wiphy
*wiphy
= wdev
->wiphy
;
9529 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9531 trace_cfg80211_send_unprot_disassoc(dev
);
9532 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9533 NL80211_CMD_UNPROT_DISASSOCIATE
, GFP_ATOMIC
);
9535 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc
);
9537 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9538 struct net_device
*netdev
, int cmd
,
9539 const u8
*addr
, gfp_t gfp
)
9541 struct sk_buff
*msg
;
9544 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9548 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9554 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9555 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9556 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9557 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9558 goto nla_put_failure
;
9560 genlmsg_end(msg
, hdr
);
9562 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9563 nl80211_mlme_mcgrp
.id
, gfp
);
9567 genlmsg_cancel(msg
, hdr
);
9571 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9572 struct net_device
*netdev
, const u8
*addr
,
9575 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9579 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9580 struct net_device
*netdev
, const u8
*addr
,
9583 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9587 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9588 struct net_device
*netdev
, const u8
*bssid
,
9589 const u8
*req_ie
, size_t req_ie_len
,
9590 const u8
*resp_ie
, size_t resp_ie_len
,
9591 u16 status
, gfp_t gfp
)
9593 struct sk_buff
*msg
;
9596 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9600 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9606 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9607 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9608 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9609 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9611 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9613 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9614 goto nla_put_failure
;
9616 genlmsg_end(msg
, hdr
);
9618 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9619 nl80211_mlme_mcgrp
.id
, gfp
);
9623 genlmsg_cancel(msg
, hdr
);
9628 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9629 struct net_device
*netdev
, const u8
*bssid
,
9630 const u8
*req_ie
, size_t req_ie_len
,
9631 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9633 struct sk_buff
*msg
;
9636 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9640 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9646 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9647 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9648 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9650 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9652 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9653 goto nla_put_failure
;
9655 genlmsg_end(msg
, hdr
);
9657 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9658 nl80211_mlme_mcgrp
.id
, gfp
);
9662 genlmsg_cancel(msg
, hdr
);
9667 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9668 struct net_device
*netdev
, u16 reason
,
9669 const u8
*ie
, size_t ie_len
, bool from_ap
)
9671 struct sk_buff
*msg
;
9674 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9678 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9684 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9685 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9686 (from_ap
&& reason
&&
9687 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9689 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9690 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9691 goto nla_put_failure
;
9693 genlmsg_end(msg
, hdr
);
9695 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9696 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9700 genlmsg_cancel(msg
, hdr
);
9705 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9706 struct net_device
*netdev
, const u8
*bssid
,
9709 struct sk_buff
*msg
;
9712 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9716 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9722 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9723 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9724 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9725 goto nla_put_failure
;
9727 genlmsg_end(msg
, hdr
);
9729 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9730 nl80211_mlme_mcgrp
.id
, gfp
);
9734 genlmsg_cancel(msg
, hdr
);
9738 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9739 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9741 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9742 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9743 struct sk_buff
*msg
;
9746 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9749 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9751 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9755 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9761 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9762 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9763 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9765 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9766 goto nla_put_failure
;
9768 genlmsg_end(msg
, hdr
);
9770 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9771 nl80211_mlme_mcgrp
.id
, gfp
);
9775 genlmsg_cancel(msg
, hdr
);
9778 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9780 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9781 struct net_device
*netdev
, const u8
*addr
,
9782 enum nl80211_key_type key_type
, int key_id
,
9783 const u8
*tsc
, gfp_t gfp
)
9785 struct sk_buff
*msg
;
9788 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9792 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9798 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9799 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9800 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9801 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9803 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9804 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9805 goto nla_put_failure
;
9807 genlmsg_end(msg
, hdr
);
9809 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9810 nl80211_mlme_mcgrp
.id
, gfp
);
9814 genlmsg_cancel(msg
, hdr
);
9818 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9819 struct ieee80211_channel
*channel_before
,
9820 struct ieee80211_channel
*channel_after
)
9822 struct sk_buff
*msg
;
9824 struct nlattr
*nl_freq
;
9826 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9830 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9837 * Since we are applying the beacon hint to a wiphy we know its
9838 * wiphy_idx is valid
9840 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9841 goto nla_put_failure
;
9844 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9846 goto nla_put_failure
;
9847 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9848 goto nla_put_failure
;
9849 nla_nest_end(msg
, nl_freq
);
9852 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9854 goto nla_put_failure
;
9855 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9856 goto nla_put_failure
;
9857 nla_nest_end(msg
, nl_freq
);
9859 genlmsg_end(msg
, hdr
);
9862 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9869 genlmsg_cancel(msg
, hdr
);
9873 static void nl80211_send_remain_on_chan_event(
9874 int cmd
, struct cfg80211_registered_device
*rdev
,
9875 struct wireless_dev
*wdev
, u64 cookie
,
9876 struct ieee80211_channel
*chan
,
9877 unsigned int duration
, gfp_t gfp
)
9879 struct sk_buff
*msg
;
9882 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9886 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9892 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9893 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9894 wdev
->netdev
->ifindex
)) ||
9895 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9896 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9897 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9898 NL80211_CHAN_NO_HT
) ||
9899 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9900 goto nla_put_failure
;
9902 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9903 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9904 goto nla_put_failure
;
9906 genlmsg_end(msg
, hdr
);
9908 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9909 nl80211_mlme_mcgrp
.id
, gfp
);
9913 genlmsg_cancel(msg
, hdr
);
9917 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9918 struct ieee80211_channel
*chan
,
9919 unsigned int duration
, gfp_t gfp
)
9921 struct wiphy
*wiphy
= wdev
->wiphy
;
9922 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9924 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9925 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9926 rdev
, wdev
, cookie
, chan
,
9929 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9931 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9932 struct ieee80211_channel
*chan
,
9935 struct wiphy
*wiphy
= wdev
->wiphy
;
9936 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9938 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9939 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9940 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9942 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9944 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9945 struct station_info
*sinfo
, gfp_t gfp
)
9947 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9948 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9949 struct sk_buff
*msg
;
9951 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9953 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9957 if (nl80211_send_station(msg
, 0, 0, 0,
9958 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9963 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9964 nl80211_mlme_mcgrp
.id
, gfp
);
9966 EXPORT_SYMBOL(cfg80211_new_sta
);
9968 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9970 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9971 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9972 struct sk_buff
*msg
;
9975 trace_cfg80211_del_sta(dev
, mac_addr
);
9977 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9981 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9987 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9988 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9989 goto nla_put_failure
;
9991 genlmsg_end(msg
, hdr
);
9993 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9994 nl80211_mlme_mcgrp
.id
, gfp
);
9998 genlmsg_cancel(msg
, hdr
);
10001 EXPORT_SYMBOL(cfg80211_del_sta
);
10003 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10004 enum nl80211_connect_failed_reason reason
,
10007 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10008 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10009 struct sk_buff
*msg
;
10012 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10016 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10022 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10023 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10024 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10025 goto nla_put_failure
;
10027 genlmsg_end(msg
, hdr
);
10029 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10030 nl80211_mlme_mcgrp
.id
, gfp
);
10034 genlmsg_cancel(msg
, hdr
);
10037 EXPORT_SYMBOL(cfg80211_conn_failed
);
10039 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10040 const u8
*addr
, gfp_t gfp
)
10042 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10043 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10044 struct sk_buff
*msg
;
10047 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10052 msg
= nlmsg_new(100, gfp
);
10056 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10062 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10063 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10064 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10065 goto nla_put_failure
;
10067 err
= genlmsg_end(msg
, hdr
);
10073 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10077 genlmsg_cancel(msg
, hdr
);
10082 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
10083 const u8
*addr
, gfp_t gfp
)
10085 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10088 trace_cfg80211_rx_spurious_frame(dev
, addr
);
10090 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10091 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
10092 trace_cfg80211_return_bool(false);
10095 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
10097 trace_cfg80211_return_bool(ret
);
10100 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
10102 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
10103 const u8
*addr
, gfp_t gfp
)
10105 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10108 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
10110 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10111 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10112 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
10113 trace_cfg80211_return_bool(false);
10116 ret
= __nl80211_unexpected_frame(dev
,
10117 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
10119 trace_cfg80211_return_bool(ret
);
10122 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10124 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10125 struct wireless_dev
*wdev
, u32 nlportid
,
10126 int freq
, int sig_dbm
,
10127 const u8
*buf
, size_t len
, gfp_t gfp
)
10129 struct net_device
*netdev
= wdev
->netdev
;
10130 struct sk_buff
*msg
;
10133 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10137 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10143 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10144 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10145 netdev
->ifindex
)) ||
10146 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10147 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10149 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10150 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10151 goto nla_put_failure
;
10153 genlmsg_end(msg
, hdr
);
10155 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10158 genlmsg_cancel(msg
, hdr
);
10163 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10164 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10166 struct wiphy
*wiphy
= wdev
->wiphy
;
10167 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10168 struct net_device
*netdev
= wdev
->netdev
;
10169 struct sk_buff
*msg
;
10172 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10174 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10178 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10184 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10185 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10186 netdev
->ifindex
)) ||
10187 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10188 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10189 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10190 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10191 goto nla_put_failure
;
10193 genlmsg_end(msg
, hdr
);
10195 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10196 nl80211_mlme_mcgrp
.id
, gfp
);
10200 genlmsg_cancel(msg
, hdr
);
10203 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10205 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10206 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10209 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10210 struct wiphy
*wiphy
= wdev
->wiphy
;
10211 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10212 struct sk_buff
*msg
;
10213 struct nlattr
*pinfoattr
;
10216 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10218 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10222 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10228 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10229 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10230 goto nla_put_failure
;
10232 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10234 goto nla_put_failure
;
10236 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10238 goto nla_put_failure
;
10240 nla_nest_end(msg
, pinfoattr
);
10242 genlmsg_end(msg
, hdr
);
10244 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10245 nl80211_mlme_mcgrp
.id
, gfp
);
10249 genlmsg_cancel(msg
, hdr
);
10252 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10254 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10255 struct net_device
*netdev
, const u8
*bssid
,
10256 const u8
*replay_ctr
, gfp_t gfp
)
10258 struct sk_buff
*msg
;
10259 struct nlattr
*rekey_attr
;
10262 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10266 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10272 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10273 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10274 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10275 goto nla_put_failure
;
10277 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10279 goto nla_put_failure
;
10281 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10282 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10283 goto nla_put_failure
;
10285 nla_nest_end(msg
, rekey_attr
);
10287 genlmsg_end(msg
, hdr
);
10289 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10290 nl80211_mlme_mcgrp
.id
, gfp
);
10294 genlmsg_cancel(msg
, hdr
);
10298 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10299 const u8
*replay_ctr
, gfp_t gfp
)
10301 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10302 struct wiphy
*wiphy
= wdev
->wiphy
;
10303 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10305 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10306 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10308 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10311 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10312 struct net_device
*netdev
, int index
,
10313 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10315 struct sk_buff
*msg
;
10316 struct nlattr
*attr
;
10319 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10323 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10329 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10330 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10331 goto nla_put_failure
;
10333 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10335 goto nla_put_failure
;
10337 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10338 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10340 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10341 goto nla_put_failure
;
10343 nla_nest_end(msg
, attr
);
10345 genlmsg_end(msg
, hdr
);
10347 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10348 nl80211_mlme_mcgrp
.id
, gfp
);
10352 genlmsg_cancel(msg
, hdr
);
10356 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10357 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10359 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10360 struct wiphy
*wiphy
= wdev
->wiphy
;
10361 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10363 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10364 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10366 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10368 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10369 struct net_device
*netdev
,
10370 struct cfg80211_chan_def
*chandef
,
10373 struct sk_buff
*msg
;
10376 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10380 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10386 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10387 goto nla_put_failure
;
10389 if (nl80211_send_chandef(msg
, chandef
))
10390 goto nla_put_failure
;
10392 genlmsg_end(msg
, hdr
);
10394 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10395 nl80211_mlme_mcgrp
.id
, gfp
);
10399 genlmsg_cancel(msg
, hdr
);
10403 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10404 struct cfg80211_chan_def
*chandef
)
10406 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10407 struct wiphy
*wiphy
= wdev
->wiphy
;
10408 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10410 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10414 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10415 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10418 wdev
->channel
= chandef
->chan
;
10419 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10424 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10426 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10427 const u8
*peer
, u32 num_packets
,
10428 u32 rate
, u32 intvl
, gfp_t gfp
)
10430 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10431 struct wiphy
*wiphy
= wdev
->wiphy
;
10432 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10433 struct sk_buff
*msg
;
10434 struct nlattr
*pinfoattr
;
10437 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10441 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10447 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10448 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10449 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10450 goto nla_put_failure
;
10452 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10454 goto nla_put_failure
;
10456 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10457 goto nla_put_failure
;
10459 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10460 goto nla_put_failure
;
10462 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10463 goto nla_put_failure
;
10465 nla_nest_end(msg
, pinfoattr
);
10467 genlmsg_end(msg
, hdr
);
10469 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10470 nl80211_mlme_mcgrp
.id
, gfp
);
10474 genlmsg_cancel(msg
, hdr
);
10477 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10480 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10481 struct cfg80211_chan_def
*chandef
,
10482 enum nl80211_radar_event event
,
10483 struct net_device
*netdev
, gfp_t gfp
)
10485 struct sk_buff
*msg
;
10488 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10492 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10498 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10499 goto nla_put_failure
;
10501 /* NOP and radar events don't need a netdev parameter */
10503 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10505 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10506 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10507 goto nla_put_failure
;
10510 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10511 goto nla_put_failure
;
10513 if (nl80211_send_chandef(msg
, chandef
))
10514 goto nla_put_failure
;
10516 if (genlmsg_end(msg
, hdr
) < 0) {
10521 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10522 nl80211_mlme_mcgrp
.id
, gfp
);
10526 genlmsg_cancel(msg
, hdr
);
10530 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10531 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10533 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10534 struct wiphy
*wiphy
= wdev
->wiphy
;
10535 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10536 struct sk_buff
*msg
;
10537 struct nlattr
*pinfoattr
;
10540 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10542 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10546 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10552 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10553 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10554 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10555 goto nla_put_failure
;
10557 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10559 goto nla_put_failure
;
10561 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10562 goto nla_put_failure
;
10564 nla_nest_end(msg
, pinfoattr
);
10566 genlmsg_end(msg
, hdr
);
10568 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10569 nl80211_mlme_mcgrp
.id
, gfp
);
10573 genlmsg_cancel(msg
, hdr
);
10576 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10578 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10579 u64 cookie
, bool acked
, gfp_t gfp
)
10581 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10582 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10583 struct sk_buff
*msg
;
10587 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10589 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10594 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10600 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10601 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10602 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10603 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10604 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10605 goto nla_put_failure
;
10607 err
= genlmsg_end(msg
, hdr
);
10613 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10614 nl80211_mlme_mcgrp
.id
, gfp
);
10618 genlmsg_cancel(msg
, hdr
);
10621 EXPORT_SYMBOL(cfg80211_probe_status
);
10623 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10624 const u8
*frame
, size_t len
,
10625 int freq
, int sig_dbm
)
10627 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10628 struct sk_buff
*msg
;
10630 struct cfg80211_beacon_registration
*reg
;
10632 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10634 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10635 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10636 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10638 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10642 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10644 goto nla_put_failure
;
10646 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10648 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10650 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10651 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10652 goto nla_put_failure
;
10654 genlmsg_end(msg
, hdr
);
10656 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10658 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10662 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10664 genlmsg_cancel(msg
, hdr
);
10667 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10670 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10671 struct cfg80211_wowlan_wakeup
*wakeup
,
10674 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10675 struct sk_buff
*msg
;
10677 int err
, size
= 200;
10679 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10682 size
+= wakeup
->packet_present_len
;
10684 msg
= nlmsg_new(size
, gfp
);
10688 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10692 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10693 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10696 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10697 wdev
->netdev
->ifindex
))
10701 struct nlattr
*reasons
;
10703 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10705 if (wakeup
->disconnect
&&
10706 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10708 if (wakeup
->magic_pkt
&&
10709 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10711 if (wakeup
->gtk_rekey_failure
&&
10712 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10714 if (wakeup
->eap_identity_req
&&
10715 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10717 if (wakeup
->four_way_handshake
&&
10718 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10720 if (wakeup
->rfkill_release
&&
10721 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10724 if (wakeup
->pattern_idx
>= 0 &&
10725 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10726 wakeup
->pattern_idx
))
10729 if (wakeup
->tcp_match
)
10730 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10732 if (wakeup
->tcp_connlost
)
10734 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10736 if (wakeup
->tcp_nomoretokens
)
10738 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10740 if (wakeup
->packet
) {
10741 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10742 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10744 if (!wakeup
->packet_80211
) {
10746 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10748 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10751 if (wakeup
->packet_len
&&
10752 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10755 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10760 nla_nest_end(msg
, reasons
);
10763 err
= genlmsg_end(msg
, hdr
);
10767 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10768 nl80211_mlme_mcgrp
.id
, gfp
);
10774 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10777 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10778 enum nl80211_tdls_operation oper
,
10779 u16 reason_code
, gfp_t gfp
)
10781 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10782 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10783 struct sk_buff
*msg
;
10787 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10790 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10794 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10800 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10801 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10802 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10803 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10804 (reason_code
> 0 &&
10805 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10806 goto nla_put_failure
;
10808 err
= genlmsg_end(msg
, hdr
);
10814 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10815 nl80211_mlme_mcgrp
.id
, gfp
);
10819 genlmsg_cancel(msg
, hdr
);
10822 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10824 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10825 unsigned long state
,
10828 struct netlink_notify
*notify
= _notify
;
10829 struct cfg80211_registered_device
*rdev
;
10830 struct wireless_dev
*wdev
;
10831 struct cfg80211_beacon_registration
*reg
, *tmp
;
10833 if (state
!= NETLINK_URELEASE
)
10834 return NOTIFY_DONE
;
10838 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10839 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10840 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10842 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10843 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10845 if (reg
->nlportid
== notify
->portid
) {
10846 list_del(®
->list
);
10851 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10856 return NOTIFY_DONE
;
10859 static struct notifier_block nl80211_netlink_notifier
= {
10860 .notifier_call
= nl80211_netlink_notify
,
10863 void cfg80211_ft_event(struct net_device
*netdev
,
10864 struct cfg80211_ft_event_params
*ft_event
)
10866 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10867 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10868 struct sk_buff
*msg
;
10872 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10874 if (!ft_event
->target_ap
)
10877 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10881 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10887 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10888 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10889 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10891 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10892 if (ft_event
->ric_ies
)
10893 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10894 ft_event
->ric_ies
);
10896 err
= genlmsg_end(msg
, hdr
);
10902 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10903 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10905 EXPORT_SYMBOL(cfg80211_ft_event
);
10907 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10909 struct cfg80211_registered_device
*rdev
;
10910 struct sk_buff
*msg
;
10914 rdev
= wiphy_to_dev(wdev
->wiphy
);
10915 if (!rdev
->crit_proto_nlportid
)
10918 nlportid
= rdev
->crit_proto_nlportid
;
10919 rdev
->crit_proto_nlportid
= 0;
10921 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10925 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10927 goto nla_put_failure
;
10929 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10930 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10931 goto nla_put_failure
;
10933 genlmsg_end(msg
, hdr
);
10935 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10940 genlmsg_cancel(msg
, hdr
);
10944 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10946 /* initialisation/exit functions */
10948 int nl80211_init(void)
10952 err
= genl_register_family_with_ops(&nl80211_fam
,
10953 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10957 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10961 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10965 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10969 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10973 #ifdef CONFIG_NL80211_TESTMODE
10974 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10978 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_vendor_mcgrp
);
10983 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10989 genl_unregister_family(&nl80211_fam
);
10993 void nl80211_exit(void)
10995 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10996 genl_unregister_family(&nl80211_fam
);