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 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2674 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2678 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2679 NL80211_CMD_NEW_KEY
);
2681 goto nla_put_failure
;
2684 cookie
.idx
= key_idx
;
2686 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2687 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2688 goto nla_put_failure
;
2690 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2691 goto nla_put_failure
;
2693 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2700 goto nla_put_failure
;
2702 genlmsg_end(msg
, hdr
);
2703 return genlmsg_reply(msg
, info
);
2712 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2714 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2715 struct key_parse key
;
2717 struct net_device
*dev
= info
->user_ptr
[1];
2719 err
= nl80211_parse_key(info
, &key
);
2726 /* only support setting default key */
2727 if (!key
.def
&& !key
.defmgmt
)
2730 wdev_lock(dev
->ieee80211_ptr
);
2733 if (!rdev
->ops
->set_default_key
) {
2738 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2742 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2743 key
.def_uni
, key
.def_multi
);
2748 #ifdef CONFIG_CFG80211_WEXT
2749 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2752 if (key
.def_uni
|| !key
.def_multi
) {
2757 if (!rdev
->ops
->set_default_mgmt_key
) {
2762 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2766 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2770 #ifdef CONFIG_CFG80211_WEXT
2771 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2776 wdev_unlock(dev
->ieee80211_ptr
);
2781 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2783 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2785 struct net_device
*dev
= info
->user_ptr
[1];
2786 struct key_parse key
;
2787 const u8
*mac_addr
= NULL
;
2789 err
= nl80211_parse_key(info
, &key
);
2796 if (info
->attrs
[NL80211_ATTR_MAC
])
2797 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2799 if (key
.type
== -1) {
2801 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2803 key
.type
= NL80211_KEYTYPE_GROUP
;
2807 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2808 key
.type
!= NL80211_KEYTYPE_GROUP
)
2811 if (!rdev
->ops
->add_key
)
2814 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2815 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2819 wdev_lock(dev
->ieee80211_ptr
);
2820 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2822 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2823 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2825 wdev_unlock(dev
->ieee80211_ptr
);
2830 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2832 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2834 struct net_device
*dev
= info
->user_ptr
[1];
2835 u8
*mac_addr
= NULL
;
2836 struct key_parse key
;
2838 err
= nl80211_parse_key(info
, &key
);
2842 if (info
->attrs
[NL80211_ATTR_MAC
])
2843 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2845 if (key
.type
== -1) {
2847 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2849 key
.type
= NL80211_KEYTYPE_GROUP
;
2853 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2854 key
.type
!= NL80211_KEYTYPE_GROUP
)
2857 if (!rdev
->ops
->del_key
)
2860 wdev_lock(dev
->ieee80211_ptr
);
2861 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2863 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
2864 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2868 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2869 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2872 #ifdef CONFIG_CFG80211_WEXT
2874 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2875 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2876 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2877 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2880 wdev_unlock(dev
->ieee80211_ptr
);
2885 /* This function returns an error or the number of nested attributes */
2886 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2888 struct nlattr
*attr
;
2889 int n_entries
= 0, tmp
;
2891 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2892 if (nla_len(attr
) != ETH_ALEN
)
2902 * This function parses ACL information and allocates memory for ACL data.
2903 * On successful return, the calling function is responsible to free the
2904 * ACL buffer returned by this function.
2906 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2907 struct genl_info
*info
)
2909 enum nl80211_acl_policy acl_policy
;
2910 struct nlattr
*attr
;
2911 struct cfg80211_acl_data
*acl
;
2912 int i
= 0, n_entries
, tmp
;
2914 if (!wiphy
->max_acl_mac_addrs
)
2915 return ERR_PTR(-EOPNOTSUPP
);
2917 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2918 return ERR_PTR(-EINVAL
);
2920 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2921 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2922 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2923 return ERR_PTR(-EINVAL
);
2925 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2926 return ERR_PTR(-EINVAL
);
2928 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2930 return ERR_PTR(n_entries
);
2932 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2933 return ERR_PTR(-ENOTSUPP
);
2935 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2938 return ERR_PTR(-ENOMEM
);
2940 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2941 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2945 acl
->n_acl_entries
= n_entries
;
2946 acl
->acl_policy
= acl_policy
;
2951 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2953 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2954 struct net_device
*dev
= info
->user_ptr
[1];
2955 struct cfg80211_acl_data
*acl
;
2958 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2959 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2962 if (!dev
->ieee80211_ptr
->beacon_interval
)
2965 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2967 return PTR_ERR(acl
);
2969 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2976 static int nl80211_parse_beacon(struct genl_info
*info
,
2977 struct cfg80211_beacon_data
*bcn
)
2979 bool haveinfo
= false;
2981 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2982 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2983 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2984 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2987 memset(bcn
, 0, sizeof(*bcn
));
2989 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2990 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2991 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2997 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2998 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3000 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3007 if (info
->attrs
[NL80211_ATTR_IE
]) {
3008 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3009 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3012 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3013 bcn
->proberesp_ies
=
3014 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3015 bcn
->proberesp_ies_len
=
3016 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3019 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3020 bcn
->assocresp_ies
=
3021 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3022 bcn
->assocresp_ies_len
=
3023 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3026 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
3028 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3029 bcn
->probe_resp_len
=
3030 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3036 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3037 struct cfg80211_ap_settings
*params
)
3039 struct wireless_dev
*wdev
;
3042 mutex_lock(&rdev
->devlist_mtx
);
3044 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3045 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3046 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3049 if (!wdev
->preset_chandef
.chan
)
3052 params
->chandef
= wdev
->preset_chandef
;
3057 mutex_unlock(&rdev
->devlist_mtx
);
3062 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3063 enum nl80211_auth_type auth_type
,
3064 enum nl80211_commands cmd
)
3066 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3070 case NL80211_CMD_AUTHENTICATE
:
3071 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3072 auth_type
== NL80211_AUTHTYPE_SAE
)
3075 case NL80211_CMD_CONNECT
:
3076 case NL80211_CMD_START_AP
:
3077 /* SAE not supported yet */
3078 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3086 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3088 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3089 struct net_device
*dev
= info
->user_ptr
[1];
3090 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3091 struct cfg80211_ap_settings params
;
3093 u8 radar_detect_width
= 0;
3095 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3096 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3099 if (!rdev
->ops
->start_ap
)
3102 if (wdev
->beacon_interval
)
3105 memset(¶ms
, 0, sizeof(params
));
3107 /* these are required for START_AP */
3108 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3109 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3110 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3113 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
3117 params
.beacon_interval
=
3118 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3119 params
.dtim_period
=
3120 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3122 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3127 * In theory, some of these attributes should be required here
3128 * but since they were not used when the command was originally
3129 * added, keep them optional for old user space programs to let
3130 * them continue to work with drivers that do not need the
3131 * additional information -- drivers must check!
3133 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3134 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3136 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3137 if (params
.ssid_len
== 0 ||
3138 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3142 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3143 params
.hidden_ssid
= nla_get_u32(
3144 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3145 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3146 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3147 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3151 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3153 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3154 params
.auth_type
= nla_get_u32(
3155 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3156 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3157 NL80211_CMD_START_AP
))
3160 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3162 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3163 NL80211_MAX_NR_CIPHER_SUITES
);
3167 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3168 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3170 params
.inactivity_timeout
= nla_get_u16(
3171 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3174 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3175 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3177 params
.p2p_ctwindow
=
3178 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3179 if (params
.p2p_ctwindow
> 127)
3181 if (params
.p2p_ctwindow
!= 0 &&
3182 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3186 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3189 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3191 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3194 params
.p2p_opp_ps
= tmp
;
3195 if (params
.p2p_opp_ps
!= 0 &&
3196 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3200 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3201 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3204 } else if (wdev
->preset_chandef
.chan
) {
3205 params
.chandef
= wdev
->preset_chandef
;
3206 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3209 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3212 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3216 radar_detect_width
= BIT(params
.chandef
.width
);
3217 params
.radar_required
= true;
3220 mutex_lock(&rdev
->devlist_mtx
);
3221 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3222 params
.chandef
.chan
,
3224 radar_detect_width
);
3225 mutex_unlock(&rdev
->devlist_mtx
);
3230 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3231 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3232 if (IS_ERR(params
.acl
))
3233 return PTR_ERR(params
.acl
);
3236 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3238 wdev
->preset_chandef
= params
.chandef
;
3239 wdev
->beacon_interval
= params
.beacon_interval
;
3240 wdev
->channel
= params
.chandef
.chan
;
3241 wdev
->ssid_len
= params
.ssid_len
;
3242 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3250 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3252 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3253 struct net_device
*dev
= info
->user_ptr
[1];
3254 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3255 struct cfg80211_beacon_data params
;
3258 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3259 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3262 if (!rdev
->ops
->change_beacon
)
3265 if (!wdev
->beacon_interval
)
3268 err
= nl80211_parse_beacon(info
, ¶ms
);
3272 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3275 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3277 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3278 struct net_device
*dev
= info
->user_ptr
[1];
3280 return cfg80211_stop_ap(rdev
, dev
);
3283 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3284 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3285 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3286 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3287 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3288 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3289 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3292 static int parse_station_flags(struct genl_info
*info
,
3293 enum nl80211_iftype iftype
,
3294 struct station_parameters
*params
)
3296 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3301 * Try parsing the new attribute first so userspace
3302 * can specify both for older kernels.
3304 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3306 struct nl80211_sta_flag_update
*sta_flags
;
3308 sta_flags
= nla_data(nla
);
3309 params
->sta_flags_mask
= sta_flags
->mask
;
3310 params
->sta_flags_set
= sta_flags
->set
;
3311 params
->sta_flags_set
&= params
->sta_flags_mask
;
3312 if ((params
->sta_flags_mask
|
3313 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3318 /* if present, parse the old attribute */
3320 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3324 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3325 nla
, sta_flags_policy
))
3329 * Only allow certain flags for interface types so that
3330 * other attributes are silently ignored. Remember that
3331 * this is backward compatibility code with old userspace
3332 * and shouldn't be hit in other cases anyway.
3335 case NL80211_IFTYPE_AP
:
3336 case NL80211_IFTYPE_AP_VLAN
:
3337 case NL80211_IFTYPE_P2P_GO
:
3338 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3339 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3340 BIT(NL80211_STA_FLAG_WME
) |
3341 BIT(NL80211_STA_FLAG_MFP
);
3343 case NL80211_IFTYPE_P2P_CLIENT
:
3344 case NL80211_IFTYPE_STATION
:
3345 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3346 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3348 case NL80211_IFTYPE_MESH_POINT
:
3349 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3350 BIT(NL80211_STA_FLAG_MFP
) |
3351 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3356 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3358 params
->sta_flags_set
|= (1<<flag
);
3360 /* no longer support new API additions in old API */
3361 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3369 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3372 struct nlattr
*rate
;
3376 rate
= nla_nest_start(msg
, attr
);
3380 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3381 bitrate
= cfg80211_calculate_bitrate(info
);
3382 /* report 16-bit bitrate only if we can */
3383 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3385 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3387 if (bitrate_compat
> 0 &&
3388 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3391 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3392 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3394 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3395 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3397 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3398 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3400 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3401 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3403 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3405 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3406 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3408 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3409 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3411 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3412 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3414 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3415 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3417 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3418 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3422 nla_nest_end(msg
, rate
);
3426 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3428 struct cfg80211_registered_device
*rdev
,
3429 struct net_device
*dev
,
3430 const u8
*mac_addr
, struct station_info
*sinfo
)
3433 struct nlattr
*sinfoattr
, *bss_param
;
3435 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3439 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3440 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3441 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3442 goto nla_put_failure
;
3444 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3446 goto nla_put_failure
;
3447 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3448 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3449 sinfo
->connected_time
))
3450 goto nla_put_failure
;
3451 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3452 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3453 sinfo
->inactive_time
))
3454 goto nla_put_failure
;
3455 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3456 STATION_INFO_RX_BYTES64
)) &&
3457 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3458 (u32
)sinfo
->rx_bytes
))
3459 goto nla_put_failure
;
3460 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3461 STATION_INFO_TX_BYTES64
)) &&
3462 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3463 (u32
)sinfo
->tx_bytes
))
3464 goto nla_put_failure
;
3465 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3466 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3468 goto nla_put_failure
;
3469 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3470 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3472 goto nla_put_failure
;
3473 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3474 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3475 goto nla_put_failure
;
3476 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3477 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3478 goto nla_put_failure
;
3479 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3480 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3481 sinfo
->plink_state
))
3482 goto nla_put_failure
;
3483 switch (rdev
->wiphy
.signal_type
) {
3484 case CFG80211_SIGNAL_TYPE_MBM
:
3485 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3486 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3488 goto nla_put_failure
;
3489 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3490 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3492 goto nla_put_failure
;
3497 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3498 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3499 NL80211_STA_INFO_TX_BITRATE
))
3500 goto nla_put_failure
;
3502 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3503 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3504 NL80211_STA_INFO_RX_BITRATE
))
3505 goto nla_put_failure
;
3507 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3508 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3510 goto nla_put_failure
;
3511 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3512 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3514 goto nla_put_failure
;
3515 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3516 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3518 goto nla_put_failure
;
3519 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3520 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3522 goto nla_put_failure
;
3523 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3524 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3525 sinfo
->beacon_loss_count
))
3526 goto nla_put_failure
;
3527 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3528 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3530 goto nla_put_failure
;
3531 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3532 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3534 goto nla_put_failure
;
3535 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3536 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3538 goto nla_put_failure
;
3539 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3540 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3542 goto nla_put_failure
;
3544 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3545 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3546 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3547 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3548 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3549 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3550 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3551 sinfo
->bss_param
.dtim_period
) ||
3552 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3553 sinfo
->bss_param
.beacon_interval
))
3554 goto nla_put_failure
;
3556 nla_nest_end(msg
, bss_param
);
3558 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3559 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3560 sizeof(struct nl80211_sta_flag_update
),
3562 goto nla_put_failure
;
3563 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3564 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3566 goto nla_put_failure
;
3567 nla_nest_end(msg
, sinfoattr
);
3569 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3570 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3571 sinfo
->assoc_req_ies
))
3572 goto nla_put_failure
;
3574 return genlmsg_end(msg
, hdr
);
3577 genlmsg_cancel(msg
, hdr
);
3581 static int nl80211_dump_station(struct sk_buff
*skb
,
3582 struct netlink_callback
*cb
)
3584 struct station_info sinfo
;
3585 struct cfg80211_registered_device
*dev
;
3586 struct wireless_dev
*wdev
;
3587 u8 mac_addr
[ETH_ALEN
];
3588 int sta_idx
= cb
->args
[2];
3591 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3595 if (!wdev
->netdev
) {
3600 if (!dev
->ops
->dump_station
) {
3606 memset(&sinfo
, 0, sizeof(sinfo
));
3607 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3614 if (nl80211_send_station(skb
,
3615 NETLINK_CB(cb
->skb
).portid
,
3616 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3617 dev
, wdev
->netdev
, mac_addr
,
3626 cb
->args
[2] = sta_idx
;
3629 nl80211_finish_wdev_dump(dev
);
3634 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3637 struct net_device
*dev
= info
->user_ptr
[1];
3638 struct station_info sinfo
;
3639 struct sk_buff
*msg
;
3640 u8
*mac_addr
= NULL
;
3643 memset(&sinfo
, 0, sizeof(sinfo
));
3645 if (!info
->attrs
[NL80211_ATTR_MAC
])
3648 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3650 if (!rdev
->ops
->get_station
)
3653 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3657 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3661 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3662 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3667 return genlmsg_reply(msg
, info
);
3670 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3671 struct station_parameters
*params
,
3672 enum cfg80211_station_type statype
)
3674 if (params
->listen_interval
!= -1)
3679 /* When you run into this, adjust the code below for the new flag */
3680 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3683 case CFG80211_STA_MESH_PEER_KERNEL
:
3684 case CFG80211_STA_MESH_PEER_USER
:
3686 * No ignoring the TDLS flag here -- the userspace mesh
3687 * code doesn't have the bug of including TDLS in the
3690 if (params
->sta_flags_mask
&
3691 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3692 BIT(NL80211_STA_FLAG_MFP
) |
3693 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3696 case CFG80211_STA_TDLS_PEER_SETUP
:
3697 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3698 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3700 /* ignore since it can't change */
3701 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3704 /* disallow mesh-specific things */
3705 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3707 if (params
->local_pm
)
3709 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3713 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3714 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3715 /* TDLS can't be set, ... */
3716 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3719 * ... but don't bother the driver with it. This works around
3720 * a hostapd/wpa_supplicant issue -- it always includes the
3721 * TLDS_PEER flag in the mask even for AP mode.
3723 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3726 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3727 /* reject other things that can't change */
3728 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3730 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3732 if (params
->supported_rates
)
3734 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3738 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3744 case CFG80211_STA_AP_MLME_CLIENT
:
3745 /* Use this only for authorizing/unauthorizing a station */
3746 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3749 case CFG80211_STA_AP_CLIENT
:
3750 /* accept only the listed bits */
3751 if (params
->sta_flags_mask
&
3752 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3753 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3754 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3755 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3756 BIT(NL80211_STA_FLAG_WME
) |
3757 BIT(NL80211_STA_FLAG_MFP
)))
3760 /* but authenticated/associated only if driver handles it */
3761 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3762 params
->sta_flags_mask
&
3763 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3764 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3767 case CFG80211_STA_IBSS
:
3768 case CFG80211_STA_AP_STA
:
3769 /* reject any changes other than AUTHORIZED */
3770 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3773 case CFG80211_STA_TDLS_PEER_SETUP
:
3774 /* reject any changes other than AUTHORIZED or WME */
3775 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3776 BIT(NL80211_STA_FLAG_WME
)))
3778 /* force (at least) rates when authorizing */
3779 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3780 !params
->supported_rates
)
3783 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3784 /* reject any changes */
3786 case CFG80211_STA_MESH_PEER_KERNEL
:
3787 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3790 case CFG80211_STA_MESH_PEER_USER
:
3791 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3798 EXPORT_SYMBOL(cfg80211_check_station_change
);
3801 * Get vlan interface making sure it is running and on the right wiphy.
3803 static struct net_device
*get_vlan(struct genl_info
*info
,
3804 struct cfg80211_registered_device
*rdev
)
3806 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3807 struct net_device
*v
;
3813 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3815 return ERR_PTR(-ENODEV
);
3817 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3822 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3823 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3824 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3829 if (!netif_running(v
)) {
3837 return ERR_PTR(ret
);
3840 static struct nla_policy
3841 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3842 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3843 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3846 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3847 struct station_parameters
*params
)
3849 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3853 /* parse WME attributes if present */
3854 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3857 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3858 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3859 nl80211_sta_wme_policy
);
3863 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3864 params
->uapsd_queues
= nla_get_u8(
3865 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3866 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3869 if (tb
[NL80211_STA_WME_MAX_SP
])
3870 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3872 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3875 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3880 static int nl80211_set_station_tdls(struct genl_info
*info
,
3881 struct station_parameters
*params
)
3883 /* Dummy STA entry gets updated once the peer capabilities are known */
3884 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3886 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3887 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3889 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3891 return nl80211_parse_sta_wme(info
, params
);
3894 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3896 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3897 struct net_device
*dev
= info
->user_ptr
[1];
3898 struct station_parameters params
;
3902 memset(¶ms
, 0, sizeof(params
));
3904 params
.listen_interval
= -1;
3906 if (!rdev
->ops
->change_station
)
3909 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3912 if (!info
->attrs
[NL80211_ATTR_MAC
])
3915 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3917 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3918 params
.supported_rates
=
3919 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3920 params
.supported_rates_len
=
3921 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3924 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3926 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3927 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3930 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3932 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3933 params
.ext_capab_len
=
3934 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3937 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3940 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3943 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3944 params
.plink_action
=
3945 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3946 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3950 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3951 params
.plink_state
=
3952 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3953 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3955 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3958 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3959 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3960 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3962 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3963 pm
> NL80211_MESH_POWER_MAX
)
3966 params
.local_pm
= pm
;
3969 /* Include parameters for TDLS peer (will check later) */
3970 err
= nl80211_set_station_tdls(info
, ¶ms
);
3974 params
.vlan
= get_vlan(info
, rdev
);
3975 if (IS_ERR(params
.vlan
))
3976 return PTR_ERR(params
.vlan
);
3978 switch (dev
->ieee80211_ptr
->iftype
) {
3979 case NL80211_IFTYPE_AP
:
3980 case NL80211_IFTYPE_AP_VLAN
:
3981 case NL80211_IFTYPE_P2P_GO
:
3982 case NL80211_IFTYPE_P2P_CLIENT
:
3983 case NL80211_IFTYPE_STATION
:
3984 case NL80211_IFTYPE_ADHOC
:
3985 case NL80211_IFTYPE_MESH_POINT
:
3992 /* driver will call cfg80211_check_station_change() */
3993 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3997 dev_put(params
.vlan
);
4002 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4004 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4006 struct net_device
*dev
= info
->user_ptr
[1];
4007 struct station_parameters params
;
4008 u8
*mac_addr
= NULL
;
4010 memset(¶ms
, 0, sizeof(params
));
4012 if (!rdev
->ops
->add_station
)
4015 if (!info
->attrs
[NL80211_ATTR_MAC
])
4018 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4021 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4024 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
4027 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4028 params
.supported_rates
=
4029 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4030 params
.supported_rates_len
=
4031 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4032 params
.listen_interval
=
4033 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4035 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4036 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4039 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4041 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4042 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4045 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4047 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4048 params
.ext_capab_len
=
4049 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4052 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4054 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4056 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4058 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4060 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4061 params
.plink_action
=
4062 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4063 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4067 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4071 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4074 /* When you run into this, adjust the code below for the new flag */
4075 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4077 switch (dev
->ieee80211_ptr
->iftype
) {
4078 case NL80211_IFTYPE_AP
:
4079 case NL80211_IFTYPE_AP_VLAN
:
4080 case NL80211_IFTYPE_P2P_GO
:
4081 /* ignore WME attributes if iface/sta is not capable */
4082 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4083 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4084 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4086 /* TDLS peers cannot be added */
4087 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4089 /* but don't bother the driver with it */
4090 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4092 /* allow authenticated/associated only if driver handles it */
4093 if (!(rdev
->wiphy
.features
&
4094 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4095 params
.sta_flags_mask
&
4096 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4097 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4100 /* must be last in here for error handling */
4101 params
.vlan
= get_vlan(info
, rdev
);
4102 if (IS_ERR(params
.vlan
))
4103 return PTR_ERR(params
.vlan
);
4105 case NL80211_IFTYPE_MESH_POINT
:
4106 /* ignore uAPSD data */
4107 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4109 /* associated is disallowed */
4110 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4112 /* TDLS peers cannot be added */
4113 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4116 case NL80211_IFTYPE_STATION
:
4117 case NL80211_IFTYPE_P2P_CLIENT
:
4118 /* ignore uAPSD data */
4119 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4121 /* these are disallowed */
4122 if (params
.sta_flags_mask
&
4123 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4124 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4126 /* Only TDLS peers can be added */
4127 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4129 /* Can only add if TDLS ... */
4130 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4132 /* ... with external setup is supported */
4133 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4136 * Older wpa_supplicant versions always mark the TDLS peer
4137 * as authorized, but it shouldn't yet be.
4139 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4145 /* be aware of params.vlan when changing code here */
4147 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4150 dev_put(params
.vlan
);
4154 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4156 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4157 struct net_device
*dev
= info
->user_ptr
[1];
4158 u8
*mac_addr
= NULL
;
4160 if (info
->attrs
[NL80211_ATTR_MAC
])
4161 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4163 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4164 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4165 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4166 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4169 if (!rdev
->ops
->del_station
)
4172 return rdev_del_station(rdev
, dev
, mac_addr
);
4175 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4176 int flags
, struct net_device
*dev
,
4177 u8
*dst
, u8
*next_hop
,
4178 struct mpath_info
*pinfo
)
4181 struct nlattr
*pinfoattr
;
4183 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4187 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4188 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4189 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4190 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4191 goto nla_put_failure
;
4193 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4195 goto nla_put_failure
;
4196 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4197 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4199 goto nla_put_failure
;
4200 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4201 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4202 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4203 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4205 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4206 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4208 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4209 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4211 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4212 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4213 pinfo
->discovery_timeout
)) ||
4214 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4215 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4216 pinfo
->discovery_retries
)))
4217 goto nla_put_failure
;
4219 nla_nest_end(msg
, pinfoattr
);
4221 return genlmsg_end(msg
, hdr
);
4224 genlmsg_cancel(msg
, hdr
);
4228 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4229 struct netlink_callback
*cb
)
4231 struct mpath_info pinfo
;
4232 struct cfg80211_registered_device
*dev
;
4233 struct wireless_dev
*wdev
;
4235 u8 next_hop
[ETH_ALEN
];
4236 int path_idx
= cb
->args
[2];
4239 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4243 if (!dev
->ops
->dump_mpath
) {
4248 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4254 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4261 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4262 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4263 wdev
->netdev
, dst
, next_hop
,
4272 cb
->args
[2] = path_idx
;
4275 nl80211_finish_wdev_dump(dev
);
4279 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4281 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4283 struct net_device
*dev
= info
->user_ptr
[1];
4284 struct mpath_info pinfo
;
4285 struct sk_buff
*msg
;
4287 u8 next_hop
[ETH_ALEN
];
4289 memset(&pinfo
, 0, sizeof(pinfo
));
4291 if (!info
->attrs
[NL80211_ATTR_MAC
])
4294 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4296 if (!rdev
->ops
->get_mpath
)
4299 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4302 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4306 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4310 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4311 dev
, dst
, next_hop
, &pinfo
) < 0) {
4316 return genlmsg_reply(msg
, info
);
4319 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4321 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4322 struct net_device
*dev
= info
->user_ptr
[1];
4324 u8
*next_hop
= NULL
;
4326 if (!info
->attrs
[NL80211_ATTR_MAC
])
4329 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4332 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4333 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4335 if (!rdev
->ops
->change_mpath
)
4338 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4341 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4344 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4346 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4347 struct net_device
*dev
= info
->user_ptr
[1];
4349 u8
*next_hop
= NULL
;
4351 if (!info
->attrs
[NL80211_ATTR_MAC
])
4354 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4357 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4358 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4360 if (!rdev
->ops
->add_mpath
)
4363 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4366 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4369 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4371 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4372 struct net_device
*dev
= info
->user_ptr
[1];
4375 if (info
->attrs
[NL80211_ATTR_MAC
])
4376 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4378 if (!rdev
->ops
->del_mpath
)
4381 return rdev_del_mpath(rdev
, dev
, dst
);
4384 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4386 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4387 struct net_device
*dev
= info
->user_ptr
[1];
4388 struct bss_parameters params
;
4390 memset(¶ms
, 0, sizeof(params
));
4391 /* default to not changing parameters */
4392 params
.use_cts_prot
= -1;
4393 params
.use_short_preamble
= -1;
4394 params
.use_short_slot_time
= -1;
4395 params
.ap_isolate
= -1;
4396 params
.ht_opmode
= -1;
4397 params
.p2p_ctwindow
= -1;
4398 params
.p2p_opp_ps
= -1;
4400 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4401 params
.use_cts_prot
=
4402 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4403 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4404 params
.use_short_preamble
=
4405 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4406 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4407 params
.use_short_slot_time
=
4408 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4409 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4410 params
.basic_rates
=
4411 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4412 params
.basic_rates_len
=
4413 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4415 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4416 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4417 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4419 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4421 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4422 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4424 params
.p2p_ctwindow
=
4425 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4426 if (params
.p2p_ctwindow
< 0)
4428 if (params
.p2p_ctwindow
!= 0 &&
4429 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4433 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4436 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4438 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4441 params
.p2p_opp_ps
= tmp
;
4442 if (params
.p2p_opp_ps
&&
4443 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4447 if (!rdev
->ops
->change_bss
)
4450 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4451 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4454 return rdev_change_bss(rdev
, dev
, ¶ms
);
4457 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4458 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4459 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4460 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4461 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4462 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4463 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4466 static int parse_reg_rule(struct nlattr
*tb
[],
4467 struct ieee80211_reg_rule
*reg_rule
)
4469 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4470 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4472 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4474 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4476 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4478 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4480 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4483 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4485 freq_range
->start_freq_khz
=
4486 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4487 freq_range
->end_freq_khz
=
4488 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4489 freq_range
->max_bandwidth_khz
=
4490 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4492 power_rule
->max_eirp
=
4493 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4495 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4496 power_rule
->max_antenna_gain
=
4497 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4502 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4506 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4509 * You should only get this when cfg80211 hasn't yet initialized
4510 * completely when built-in to the kernel right between the time
4511 * window between nl80211_init() and regulatory_init(), if that is
4514 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4515 return -EINPROGRESS
;
4517 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4520 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4522 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4523 user_reg_hint_type
=
4524 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4526 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4528 switch (user_reg_hint_type
) {
4529 case NL80211_USER_REG_HINT_USER
:
4530 case NL80211_USER_REG_HINT_CELL_BASE
:
4536 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4541 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4542 struct genl_info
*info
)
4544 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4545 struct net_device
*dev
= info
->user_ptr
[1];
4546 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4547 struct mesh_config cur_params
;
4550 struct nlattr
*pinfoattr
;
4551 struct sk_buff
*msg
;
4553 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4556 if (!rdev
->ops
->get_mesh_config
)
4560 /* If not connected, get default parameters */
4561 if (!wdev
->mesh_id_len
)
4562 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4564 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4570 /* Draw up a netlink message to send back */
4571 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4574 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4575 NL80211_CMD_GET_MESH_CONFIG
);
4578 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4580 goto nla_put_failure
;
4581 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4582 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4583 cur_params
.dot11MeshRetryTimeout
) ||
4584 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4585 cur_params
.dot11MeshConfirmTimeout
) ||
4586 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4587 cur_params
.dot11MeshHoldingTimeout
) ||
4588 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4589 cur_params
.dot11MeshMaxPeerLinks
) ||
4590 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4591 cur_params
.dot11MeshMaxRetries
) ||
4592 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4593 cur_params
.dot11MeshTTL
) ||
4594 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4595 cur_params
.element_ttl
) ||
4596 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4597 cur_params
.auto_open_plinks
) ||
4598 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4599 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4600 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4601 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4602 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4603 cur_params
.path_refresh_time
) ||
4604 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4605 cur_params
.min_discovery_timeout
) ||
4606 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4607 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4608 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4609 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4610 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4611 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4612 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4613 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4614 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4615 cur_params
.dot11MeshHWMPRootMode
) ||
4616 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4617 cur_params
.dot11MeshHWMPRannInterval
) ||
4618 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4619 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4620 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4621 cur_params
.dot11MeshForwarding
) ||
4622 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4623 cur_params
.rssi_threshold
) ||
4624 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4625 cur_params
.ht_opmode
) ||
4626 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4627 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4628 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4629 cur_params
.dot11MeshHWMProotInterval
) ||
4630 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4631 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4632 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4633 cur_params
.power_mode
) ||
4634 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4635 cur_params
.dot11MeshAwakeWindowDuration
))
4636 goto nla_put_failure
;
4637 nla_nest_end(msg
, pinfoattr
);
4638 genlmsg_end(msg
, hdr
);
4639 return genlmsg_reply(msg
, info
);
4642 genlmsg_cancel(msg
, hdr
);
4648 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4649 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4650 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4651 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4652 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4653 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4654 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4655 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4656 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4657 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4658 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4659 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4660 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4661 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4662 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4663 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4664 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4665 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4666 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4667 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4668 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4669 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4670 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4671 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4672 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4673 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4674 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4675 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4678 static const struct nla_policy
4679 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4680 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4681 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4682 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4683 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4684 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4685 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4686 .len
= IEEE80211_MAX_DATA_LEN
},
4687 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4690 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4691 struct mesh_config
*cfg
,
4694 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4697 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4700 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4702 cfg->param = fn(tb[attr]); \
4703 mask |= (1 << (attr - 1)); \
4708 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4710 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4711 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4712 nl80211_meshconf_params_policy
))
4715 /* This makes sure that there aren't more than 32 mesh config
4716 * parameters (otherwise our bitfield scheme would not work.) */
4717 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4719 /* Fill in the params struct */
4720 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4721 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4723 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4724 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4726 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4727 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4729 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4730 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4732 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4733 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4735 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4736 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4737 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4738 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4740 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4741 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4743 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4745 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4747 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4748 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4750 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4751 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4753 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4754 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4756 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4758 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4760 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4762 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4764 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4766 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4768 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4769 dot11MeshHWMPnetDiameterTraversalTime
,
4771 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4773 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4774 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4776 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4777 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4779 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4780 dot11MeshGateAnnouncementProtocol
, 0, 1,
4781 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4783 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4784 mask
, NL80211_MESHCONF_FORWARDING
,
4786 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4787 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4789 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4790 mask
, NL80211_MESHCONF_HT_OPMODE
,
4792 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4794 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4796 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4797 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4799 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4800 dot11MeshHWMPconfirmationInterval
,
4802 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4804 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4805 NL80211_MESH_POWER_ACTIVE
,
4806 NL80211_MESH_POWER_MAX
,
4807 mask
, NL80211_MESHCONF_POWER_MODE
,
4809 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4811 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4817 #undef FILL_IN_MESH_PARAM_IF_SET
4820 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4821 struct mesh_setup
*setup
)
4823 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4824 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4826 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4828 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4829 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4830 nl80211_mesh_setup_params_policy
))
4833 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4834 setup
->sync_method
=
4835 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4836 IEEE80211_SYNC_METHOD_VENDOR
:
4837 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4839 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4840 setup
->path_sel_proto
=
4841 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4842 IEEE80211_PATH_PROTOCOL_VENDOR
:
4843 IEEE80211_PATH_PROTOCOL_HWMP
;
4845 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4846 setup
->path_metric
=
4847 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4848 IEEE80211_PATH_METRIC_VENDOR
:
4849 IEEE80211_PATH_METRIC_AIRTIME
;
4852 if (tb
[NL80211_MESH_SETUP_IE
]) {
4853 struct nlattr
*ieattr
=
4854 tb
[NL80211_MESH_SETUP_IE
];
4855 if (!is_valid_ie_attr(ieattr
))
4857 setup
->ie
= nla_data(ieattr
);
4858 setup
->ie_len
= nla_len(ieattr
);
4860 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4861 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4863 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4864 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4865 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4866 if (setup
->is_secure
)
4867 setup
->user_mpm
= true;
4872 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4873 struct genl_info
*info
)
4875 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4876 struct net_device
*dev
= info
->user_ptr
[1];
4877 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4878 struct mesh_config cfg
;
4882 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4885 if (!rdev
->ops
->update_mesh_config
)
4888 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4893 if (!wdev
->mesh_id_len
)
4897 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4904 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4906 const struct ieee80211_regdomain
*regdom
;
4907 struct sk_buff
*msg
;
4909 struct nlattr
*nl_reg_rules
;
4913 mutex_lock(&cfg80211_mutex
);
4915 if (!cfg80211_regdomain
)
4918 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4924 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4925 NL80211_CMD_GET_REG
);
4929 if (reg_last_request_cell_base() &&
4930 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4931 NL80211_USER_REG_HINT_CELL_BASE
))
4932 goto nla_put_failure
;
4935 regdom
= rcu_dereference(cfg80211_regdomain
);
4937 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4938 (regdom
->dfs_region
&&
4939 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4940 goto nla_put_failure_rcu
;
4942 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4944 goto nla_put_failure_rcu
;
4946 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4947 struct nlattr
*nl_reg_rule
;
4948 const struct ieee80211_reg_rule
*reg_rule
;
4949 const struct ieee80211_freq_range
*freq_range
;
4950 const struct ieee80211_power_rule
*power_rule
;
4952 reg_rule
= ®dom
->reg_rules
[i
];
4953 freq_range
= ®_rule
->freq_range
;
4954 power_rule
= ®_rule
->power_rule
;
4956 nl_reg_rule
= nla_nest_start(msg
, i
);
4958 goto nla_put_failure_rcu
;
4960 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4962 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4963 freq_range
->start_freq_khz
) ||
4964 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4965 freq_range
->end_freq_khz
) ||
4966 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4967 freq_range
->max_bandwidth_khz
) ||
4968 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4969 power_rule
->max_antenna_gain
) ||
4970 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4971 power_rule
->max_eirp
))
4972 goto nla_put_failure_rcu
;
4974 nla_nest_end(msg
, nl_reg_rule
);
4978 nla_nest_end(msg
, nl_reg_rules
);
4980 genlmsg_end(msg
, hdr
);
4981 err
= genlmsg_reply(msg
, info
);
4984 nla_put_failure_rcu
:
4987 genlmsg_cancel(msg
, hdr
);
4992 mutex_unlock(&cfg80211_mutex
);
4996 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4998 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4999 struct nlattr
*nl_reg_rule
;
5000 char *alpha2
= NULL
;
5001 int rem_reg_rules
= 0, r
= 0;
5002 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5004 struct ieee80211_regdomain
*rd
= NULL
;
5006 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5009 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5012 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5014 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5015 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5017 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5020 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5024 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5025 num_rules
* sizeof(struct ieee80211_reg_rule
);
5027 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5031 rd
->n_reg_rules
= num_rules
;
5032 rd
->alpha2
[0] = alpha2
[0];
5033 rd
->alpha2
[1] = alpha2
[1];
5036 * Disable DFS master mode if the DFS region was
5037 * not supported or known on this kernel.
5039 if (reg_supported_dfs_region(dfs_region
))
5040 rd
->dfs_region
= dfs_region
;
5042 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5044 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5045 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5047 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5053 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5059 mutex_lock(&cfg80211_mutex
);
5062 /* set_regdom took ownership */
5064 mutex_unlock(&cfg80211_mutex
);
5071 static int validate_scan_freqs(struct nlattr
*freqs
)
5073 struct nlattr
*attr1
, *attr2
;
5074 int n_channels
= 0, tmp1
, tmp2
;
5076 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5079 * Some hardware has a limited channel list for
5080 * scanning, and it is pretty much nonsensical
5081 * to scan for a channel twice, so disallow that
5082 * and don't require drivers to check that the
5083 * channel list they get isn't longer than what
5084 * they can scan, as long as they can scan all
5085 * the channels they registered at once.
5087 nla_for_each_nested(attr2
, freqs
, tmp2
)
5088 if (attr1
!= attr2
&&
5089 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5096 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5098 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5099 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5100 struct cfg80211_scan_request
*request
;
5101 struct nlattr
*attr
;
5102 struct wiphy
*wiphy
;
5103 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5106 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5109 wiphy
= &rdev
->wiphy
;
5111 if (!rdev
->ops
->scan
)
5114 mutex_lock(&rdev
->sched_scan_mtx
);
5115 if (rdev
->scan_req
) {
5120 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5121 n_channels
= validate_scan_freqs(
5122 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5128 enum ieee80211_band band
;
5131 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5132 if (wiphy
->bands
[band
])
5133 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5136 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5137 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5140 if (n_ssids
> wiphy
->max_scan_ssids
) {
5145 if (info
->attrs
[NL80211_ATTR_IE
])
5146 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5150 if (ie_len
> wiphy
->max_scan_ie_len
) {
5155 request
= kzalloc(sizeof(*request
)
5156 + sizeof(*request
->ssids
) * n_ssids
5157 + sizeof(*request
->channels
) * n_channels
5158 + ie_len
, GFP_KERNEL
);
5165 request
->ssids
= (void *)&request
->channels
[n_channels
];
5166 request
->n_ssids
= n_ssids
;
5169 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5171 request
->ie
= (void *)(request
->channels
+ n_channels
);
5175 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5176 /* user specified, bail out if channel not found */
5177 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5178 struct ieee80211_channel
*chan
;
5180 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5187 /* ignore disabled channels */
5188 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5191 request
->channels
[i
] = chan
;
5195 enum ieee80211_band band
;
5198 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5200 if (!wiphy
->bands
[band
])
5202 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5203 struct ieee80211_channel
*chan
;
5205 chan
= &wiphy
->bands
[band
]->channels
[j
];
5207 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5210 request
->channels
[i
] = chan
;
5221 request
->n_channels
= i
;
5224 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5225 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5226 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5230 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5231 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5236 if (info
->attrs
[NL80211_ATTR_IE
]) {
5237 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5238 memcpy((void *)request
->ie
,
5239 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5243 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5244 if (wiphy
->bands
[i
])
5246 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5248 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5249 nla_for_each_nested(attr
,
5250 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5252 enum ieee80211_band band
= nla_type(attr
);
5254 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5258 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5261 &request
->rates
[band
]);
5267 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5268 request
->flags
= nla_get_u32(
5269 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5270 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5271 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5272 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5273 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5280 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5282 request
->wdev
= wdev
;
5283 request
->wiphy
= &rdev
->wiphy
;
5284 request
->scan_start
= jiffies
;
5286 rdev
->scan_req
= request
;
5287 err
= rdev_scan(rdev
, request
);
5290 nl80211_send_scan_start(rdev
, wdev
);
5292 dev_hold(wdev
->netdev
);
5295 rdev
->scan_req
= NULL
;
5300 mutex_unlock(&rdev
->sched_scan_mtx
);
5304 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5305 struct genl_info
*info
)
5307 struct cfg80211_sched_scan_request
*request
;
5308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5309 struct net_device
*dev
= info
->user_ptr
[1];
5310 struct nlattr
*attr
;
5311 struct wiphy
*wiphy
;
5312 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5314 enum ieee80211_band band
;
5316 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5318 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5319 !rdev
->ops
->sched_scan_start
)
5322 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5325 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5328 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5332 wiphy
= &rdev
->wiphy
;
5334 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5335 n_channels
= validate_scan_freqs(
5336 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5342 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5343 if (wiphy
->bands
[band
])
5344 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5347 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5348 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5352 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5355 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5356 nla_for_each_nested(attr
,
5357 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5361 if (n_match_sets
> wiphy
->max_match_sets
)
5364 if (info
->attrs
[NL80211_ATTR_IE
])
5365 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5369 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5372 mutex_lock(&rdev
->sched_scan_mtx
);
5374 if (rdev
->sched_scan_req
) {
5379 request
= kzalloc(sizeof(*request
)
5380 + sizeof(*request
->ssids
) * n_ssids
5381 + sizeof(*request
->match_sets
) * n_match_sets
5382 + sizeof(*request
->channels
) * n_channels
5383 + ie_len
, GFP_KERNEL
);
5390 request
->ssids
= (void *)&request
->channels
[n_channels
];
5391 request
->n_ssids
= n_ssids
;
5394 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5396 request
->ie
= (void *)(request
->channels
+ n_channels
);
5401 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5402 else if (request
->ssids
)
5403 request
->match_sets
=
5404 (void *)(request
->ssids
+ n_ssids
);
5406 request
->match_sets
=
5407 (void *)(request
->channels
+ n_channels
);
5409 request
->n_match_sets
= n_match_sets
;
5412 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5413 /* user specified, bail out if channel not found */
5414 nla_for_each_nested(attr
,
5415 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5417 struct ieee80211_channel
*chan
;
5419 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5426 /* ignore disabled channels */
5427 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5430 request
->channels
[i
] = chan
;
5435 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5437 if (!wiphy
->bands
[band
])
5439 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5440 struct ieee80211_channel
*chan
;
5442 chan
= &wiphy
->bands
[band
]->channels
[j
];
5444 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5447 request
->channels
[i
] = chan
;
5458 request
->n_channels
= i
;
5461 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5462 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5464 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5468 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5469 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5476 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5477 nla_for_each_nested(attr
,
5478 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5480 struct nlattr
*ssid
, *rssi
;
5482 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5483 nla_data(attr
), nla_len(attr
),
5484 nl80211_match_policy
);
5485 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5487 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5491 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5492 nla_data(ssid
), nla_len(ssid
));
5493 request
->match_sets
[i
].ssid
.ssid_len
=
5496 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5498 request
->rssi_thold
= nla_get_u32(rssi
);
5500 request
->rssi_thold
=
5501 NL80211_SCAN_RSSI_THOLD_OFF
;
5506 if (info
->attrs
[NL80211_ATTR_IE
]) {
5507 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5508 memcpy((void *)request
->ie
,
5509 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5513 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5514 request
->flags
= nla_get_u32(
5515 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5516 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5517 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5518 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5519 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5526 request
->wiphy
= &rdev
->wiphy
;
5527 request
->interval
= interval
;
5528 request
->scan_start
= jiffies
;
5530 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5532 rdev
->sched_scan_req
= request
;
5533 nl80211_send_sched_scan(rdev
, dev
,
5534 NL80211_CMD_START_SCHED_SCAN
);
5541 mutex_unlock(&rdev
->sched_scan_mtx
);
5545 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5546 struct genl_info
*info
)
5548 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5551 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5552 !rdev
->ops
->sched_scan_stop
)
5555 mutex_lock(&rdev
->sched_scan_mtx
);
5556 err
= __cfg80211_stop_sched_scan(rdev
, false);
5557 mutex_unlock(&rdev
->sched_scan_mtx
);
5562 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5563 struct genl_info
*info
)
5565 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5566 struct net_device
*dev
= info
->user_ptr
[1];
5567 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5568 struct cfg80211_chan_def chandef
;
5571 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5575 if (wdev
->cac_started
)
5578 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5585 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5588 if (!rdev
->ops
->start_radar_detection
)
5591 mutex_lock(&rdev
->devlist_mtx
);
5592 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5593 chandef
.chan
, CHAN_MODE_SHARED
,
5594 BIT(chandef
.width
));
5598 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5600 wdev
->channel
= chandef
.chan
;
5601 wdev
->cac_started
= true;
5602 wdev
->cac_start_time
= jiffies
;
5605 mutex_unlock(&rdev
->devlist_mtx
);
5610 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5612 struct cfg80211_registered_device
*rdev
,
5613 struct wireless_dev
*wdev
,
5614 struct cfg80211_internal_bss
*intbss
)
5616 struct cfg80211_bss
*res
= &intbss
->pub
;
5617 const struct cfg80211_bss_ies
*ies
;
5622 ASSERT_WDEV_LOCK(wdev
);
5624 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5625 NL80211_CMD_NEW_SCAN_RESULTS
);
5629 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5631 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5632 goto nla_put_failure
;
5634 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5635 goto nla_put_failure
;
5636 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5637 goto nla_put_failure
;
5639 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5641 goto nla_put_failure
;
5642 if ((!is_zero_ether_addr(res
->bssid
) &&
5643 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5644 goto nla_put_failure
;
5647 ies
= rcu_dereference(res
->ies
);
5649 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5650 goto fail_unlock_rcu
;
5652 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5653 ies
->len
, ies
->data
))
5654 goto fail_unlock_rcu
;
5656 ies
= rcu_dereference(res
->beacon_ies
);
5658 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5659 goto fail_unlock_rcu
;
5660 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5661 ies
->len
, ies
->data
))
5662 goto fail_unlock_rcu
;
5666 if (res
->beacon_interval
&&
5667 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5668 goto nla_put_failure
;
5669 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5670 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5671 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5672 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5673 goto nla_put_failure
;
5675 switch (rdev
->wiphy
.signal_type
) {
5676 case CFG80211_SIGNAL_TYPE_MBM
:
5677 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5678 goto nla_put_failure
;
5680 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5681 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5682 goto nla_put_failure
;
5688 switch (wdev
->iftype
) {
5689 case NL80211_IFTYPE_P2P_CLIENT
:
5690 case NL80211_IFTYPE_STATION
:
5691 if (intbss
== wdev
->current_bss
&&
5692 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5693 NL80211_BSS_STATUS_ASSOCIATED
))
5694 goto nla_put_failure
;
5696 case NL80211_IFTYPE_ADHOC
:
5697 if (intbss
== wdev
->current_bss
&&
5698 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5699 NL80211_BSS_STATUS_IBSS_JOINED
))
5700 goto nla_put_failure
;
5706 nla_nest_end(msg
, bss
);
5708 return genlmsg_end(msg
, hdr
);
5713 genlmsg_cancel(msg
, hdr
);
5717 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5719 struct cfg80211_registered_device
*rdev
;
5720 struct cfg80211_internal_bss
*scan
;
5721 struct wireless_dev
*wdev
;
5722 int start
= cb
->args
[2], idx
= 0;
5725 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5730 spin_lock_bh(&rdev
->bss_lock
);
5731 cfg80211_bss_expire(rdev
);
5733 cb
->seq
= rdev
->bss_generation
;
5735 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5738 if (nl80211_send_bss(skb
, cb
,
5739 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5740 rdev
, wdev
, scan
) < 0) {
5746 spin_unlock_bh(&rdev
->bss_lock
);
5750 nl80211_finish_wdev_dump(rdev
);
5755 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5756 int flags
, struct net_device
*dev
,
5757 struct survey_info
*survey
)
5760 struct nlattr
*infoattr
;
5762 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5763 NL80211_CMD_NEW_SURVEY_RESULTS
);
5767 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5768 goto nla_put_failure
;
5770 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5772 goto nla_put_failure
;
5774 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5775 survey
->channel
->center_freq
))
5776 goto nla_put_failure
;
5778 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5779 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5780 goto nla_put_failure
;
5781 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5782 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5783 goto nla_put_failure
;
5784 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5785 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5786 survey
->channel_time
))
5787 goto nla_put_failure
;
5788 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5789 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5790 survey
->channel_time_busy
))
5791 goto nla_put_failure
;
5792 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5793 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5794 survey
->channel_time_ext_busy
))
5795 goto nla_put_failure
;
5796 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5797 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5798 survey
->channel_time_rx
))
5799 goto nla_put_failure
;
5800 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5801 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5802 survey
->channel_time_tx
))
5803 goto nla_put_failure
;
5805 nla_nest_end(msg
, infoattr
);
5807 return genlmsg_end(msg
, hdr
);
5810 genlmsg_cancel(msg
, hdr
);
5814 static int nl80211_dump_survey(struct sk_buff
*skb
,
5815 struct netlink_callback
*cb
)
5817 struct survey_info survey
;
5818 struct cfg80211_registered_device
*dev
;
5819 struct wireless_dev
*wdev
;
5820 int survey_idx
= cb
->args
[2];
5823 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5827 if (!wdev
->netdev
) {
5832 if (!dev
->ops
->dump_survey
) {
5838 struct ieee80211_channel
*chan
;
5840 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5846 /* Survey without a channel doesn't make sense */
5847 if (!survey
.channel
) {
5852 chan
= ieee80211_get_channel(&dev
->wiphy
,
5853 survey
.channel
->center_freq
);
5854 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5859 if (nl80211_send_survey(skb
,
5860 NETLINK_CB(cb
->skb
).portid
,
5861 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5862 wdev
->netdev
, &survey
) < 0)
5868 cb
->args
[2] = survey_idx
;
5871 nl80211_finish_wdev_dump(dev
);
5875 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5877 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5878 NL80211_WPA_VERSION_2
));
5881 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5883 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5884 struct net_device
*dev
= info
->user_ptr
[1];
5885 struct ieee80211_channel
*chan
;
5886 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5887 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5888 enum nl80211_auth_type auth_type
;
5889 struct key_parse key
;
5890 bool local_state_change
;
5892 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5895 if (!info
->attrs
[NL80211_ATTR_MAC
])
5898 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5901 if (!info
->attrs
[NL80211_ATTR_SSID
])
5904 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5907 err
= nl80211_parse_key(info
, &key
);
5912 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5914 if (!key
.p
.key
|| !key
.p
.key_len
)
5916 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5917 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5918 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5919 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5931 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5932 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5941 if (!rdev
->ops
->auth
)
5944 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5945 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5948 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5949 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5950 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5951 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5954 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5955 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5957 if (info
->attrs
[NL80211_ATTR_IE
]) {
5958 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5959 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5962 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5963 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5966 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5967 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5970 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5971 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5973 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5974 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5975 /* need to include at least Auth Transaction and Status Code */
5976 if (sae_data_len
< 4)
5980 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5983 * Since we no longer track auth state, ignore
5984 * requests to only change local state.
5986 if (local_state_change
)
5989 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5990 ssid
, ssid_len
, ie
, ie_len
,
5991 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5992 sae_data
, sae_data_len
);
5995 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5996 struct genl_info
*info
,
5997 struct cfg80211_crypto_settings
*settings
,
6000 memset(settings
, 0, sizeof(*settings
));
6002 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6004 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6006 proto
= nla_get_u16(
6007 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6008 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6009 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6012 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6013 settings
->control_port_no_encrypt
= true;
6015 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6017 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6021 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6022 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6023 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6025 if (len
% sizeof(u32
))
6028 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6031 memcpy(settings
->ciphers_pairwise
, data
, len
);
6033 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6034 if (!cfg80211_supported_cipher_suite(
6036 settings
->ciphers_pairwise
[i
]))
6040 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6041 settings
->cipher_group
=
6042 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6043 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6044 settings
->cipher_group
))
6048 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6049 settings
->wpa_versions
=
6050 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6051 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6055 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6059 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6060 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6061 settings
->n_akm_suites
= len
/ sizeof(u32
);
6063 if (len
% sizeof(u32
))
6066 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6069 memcpy(settings
->akm_suites
, data
, len
);
6075 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6077 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6078 struct net_device
*dev
= info
->user_ptr
[1];
6079 struct ieee80211_channel
*chan
;
6080 struct cfg80211_assoc_request req
= {};
6081 const u8
*bssid
, *ssid
;
6082 int err
, ssid_len
= 0;
6084 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6087 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6088 !info
->attrs
[NL80211_ATTR_SSID
] ||
6089 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6092 if (!rdev
->ops
->assoc
)
6095 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6096 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6099 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6101 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6102 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6103 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6106 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6107 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6109 if (info
->attrs
[NL80211_ATTR_IE
]) {
6110 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6111 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6114 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6115 enum nl80211_mfp mfp
=
6116 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6117 if (mfp
== NL80211_MFP_REQUIRED
)
6119 else if (mfp
!= NL80211_MFP_NO
)
6123 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6124 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6126 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6127 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6129 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6130 memcpy(&req
.ht_capa_mask
,
6131 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6132 sizeof(req
.ht_capa_mask
));
6134 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6135 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6137 memcpy(&req
.ht_capa
,
6138 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6139 sizeof(req
.ht_capa
));
6142 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6143 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6145 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6146 memcpy(&req
.vht_capa_mask
,
6147 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6148 sizeof(req
.vht_capa_mask
));
6150 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6151 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6153 memcpy(&req
.vht_capa
,
6154 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6155 sizeof(req
.vht_capa
));
6158 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6160 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6161 ssid
, ssid_len
, &req
);
6166 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6168 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6169 struct net_device
*dev
= info
->user_ptr
[1];
6170 const u8
*ie
= NULL
, *bssid
;
6173 bool local_state_change
;
6175 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6178 if (!info
->attrs
[NL80211_ATTR_MAC
])
6181 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6184 if (!rdev
->ops
->deauth
)
6187 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6188 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6191 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6193 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6194 if (reason_code
== 0) {
6195 /* Reason Code 0 is reserved */
6199 if (info
->attrs
[NL80211_ATTR_IE
]) {
6200 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6201 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6204 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6206 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6207 local_state_change
);
6210 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6212 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6213 struct net_device
*dev
= info
->user_ptr
[1];
6214 const u8
*ie
= NULL
, *bssid
;
6217 bool local_state_change
;
6219 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6222 if (!info
->attrs
[NL80211_ATTR_MAC
])
6225 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6228 if (!rdev
->ops
->disassoc
)
6231 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6232 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6235 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6237 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6238 if (reason_code
== 0) {
6239 /* Reason Code 0 is reserved */
6243 if (info
->attrs
[NL80211_ATTR_IE
]) {
6244 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6245 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6248 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6250 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6251 local_state_change
);
6255 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6256 int mcast_rate
[IEEE80211_NUM_BANDS
],
6259 struct wiphy
*wiphy
= &rdev
->wiphy
;
6263 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6264 struct ieee80211_supported_band
*sband
;
6266 sband
= wiphy
->bands
[band
];
6270 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6271 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6272 mcast_rate
[band
] = i
+ 1;
6282 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6284 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6285 struct net_device
*dev
= info
->user_ptr
[1];
6286 struct cfg80211_ibss_params ibss
;
6287 struct wiphy
*wiphy
;
6288 struct cfg80211_cached_keys
*connkeys
= NULL
;
6291 memset(&ibss
, 0, sizeof(ibss
));
6293 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6296 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6297 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6300 ibss
.beacon_interval
= 100;
6302 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6303 ibss
.beacon_interval
=
6304 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6305 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6309 if (!rdev
->ops
->join_ibss
)
6312 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6315 wiphy
= &rdev
->wiphy
;
6317 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6318 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6320 if (!is_valid_ether_addr(ibss
.bssid
))
6323 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6324 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6326 if (info
->attrs
[NL80211_ATTR_IE
]) {
6327 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6328 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6331 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6335 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6338 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
6340 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
6341 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
6344 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6345 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6347 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6349 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6351 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6352 struct ieee80211_supported_band
*sband
=
6353 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6355 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6361 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6362 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6363 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6366 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6369 connkeys
= nl80211_parse_connkeys(rdev
,
6370 info
->attrs
[NL80211_ATTR_KEYS
],
6372 if (IS_ERR(connkeys
))
6373 return PTR_ERR(connkeys
);
6375 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6383 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6385 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6391 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6393 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6394 struct net_device
*dev
= info
->user_ptr
[1];
6396 if (!rdev
->ops
->leave_ibss
)
6399 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6402 return cfg80211_leave_ibss(rdev
, dev
, false);
6405 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6407 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6408 struct net_device
*dev
= info
->user_ptr
[1];
6409 int mcast_rate
[IEEE80211_NUM_BANDS
];
6413 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6414 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6417 if (!rdev
->ops
->set_mcast_rate
)
6420 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6422 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6425 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6426 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6429 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6434 static struct sk_buff
*
6435 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
6436 int approxlen
, u32 portid
, u32 seq
,
6437 enum nl80211_commands cmd
,
6438 enum nl80211_attrs attr
,
6439 const struct nl80211_vendor_cmd_info
*info
,
6442 struct sk_buff
*skb
;
6444 struct nlattr
*data
;
6446 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6450 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
6456 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6457 goto nla_put_failure
;
6460 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
6462 goto nla_put_failure
;
6463 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
6465 goto nla_put_failure
;
6468 data
= nla_nest_start(skb
, attr
);
6470 ((void **)skb
->cb
)[0] = rdev
;
6471 ((void **)skb
->cb
)[1] = hdr
;
6472 ((void **)skb
->cb
)[2] = data
;
6481 #ifdef CONFIG_NL80211_TESTMODE
6482 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6486 static struct genl_multicast_group nl80211_vendor_mcgrp
= {
6490 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6492 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6495 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6499 if (rdev
->ops
->testmode_cmd
) {
6500 rdev
->cur_cmd_info
= info
;
6501 err
= rdev_testmode_cmd(rdev
,
6502 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6503 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6504 rdev
->cur_cmd_info
= NULL
;
6510 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6511 struct netlink_callback
*cb
)
6513 struct cfg80211_registered_device
*rdev
;
6521 * 0 is a valid index, but not valid for args[0],
6522 * so we need to offset by 1.
6524 phy_idx
= cb
->args
[0] - 1;
6526 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6527 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6532 mutex_lock(&cfg80211_mutex
);
6533 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6534 nl80211_fam
.attrbuf
);
6536 mutex_unlock(&cfg80211_mutex
);
6537 return PTR_ERR(rdev
);
6539 phy_idx
= rdev
->wiphy_idx
;
6541 mutex_unlock(&cfg80211_mutex
);
6543 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6545 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6549 data
= nla_data((void *)cb
->args
[1]);
6550 data_len
= nla_len((void *)cb
->args
[1]);
6553 mutex_lock(&cfg80211_mutex
);
6554 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6556 mutex_unlock(&cfg80211_mutex
);
6559 cfg80211_lock_rdev(rdev
);
6560 mutex_unlock(&cfg80211_mutex
);
6562 if (!rdev
->ops
->testmode_dump
) {
6568 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6569 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6570 NL80211_CMD_TESTMODE
);
6571 struct nlattr
*tmdata
;
6576 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6577 genlmsg_cancel(skb
, hdr
);
6581 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6583 genlmsg_cancel(skb
, hdr
);
6586 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6587 nla_nest_end(skb
, tmdata
);
6589 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6590 genlmsg_cancel(skb
, hdr
);
6593 genlmsg_cancel(skb
, hdr
);
6597 genlmsg_end(skb
, hdr
);
6602 cb
->args
[0] = phy_idx
+ 1;
6604 cfg80211_unlock_rdev(rdev
);
6608 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
6609 enum nl80211_commands cmd
,
6610 enum nl80211_attrs attr
,
6611 int vendor_event_idx
,
6612 int approxlen
, gfp_t gfp
)
6614 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6615 const struct nl80211_vendor_cmd_info
*info
;
6618 case NL80211_CMD_TESTMODE
:
6619 if (WARN_ON(vendor_event_idx
!= -1))
6623 case NL80211_CMD_VENDOR
:
6624 if (WARN_ON(vendor_event_idx
< 0 ||
6625 vendor_event_idx
>= wiphy
->n_vendor_events
))
6627 info
= &wiphy
->vendor_events
[vendor_event_idx
];
6633 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
, 0, 0,
6634 cmd
, attr
, info
, gfp
);
6636 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
6638 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
6640 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6641 void *hdr
= ((void **)skb
->cb
)[1];
6642 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6644 /* clear CB data for netlink core to own from now on */
6645 memset(skb
->cb
, 0, sizeof(skb
->cb
));
6647 nla_nest_end(skb
, data
);
6648 genlmsg_end(skb
, hdr
);
6650 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
6651 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6652 nl80211_vendor_mcgrp
.id
, gfp
);
6654 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6655 nl80211_testmode_mcgrp
.id
, gfp
);
6657 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
6660 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6662 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6663 struct net_device
*dev
= info
->user_ptr
[1];
6664 struct cfg80211_connect_params connect
;
6665 struct wiphy
*wiphy
;
6666 struct cfg80211_cached_keys
*connkeys
= NULL
;
6669 memset(&connect
, 0, sizeof(connect
));
6671 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6674 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6675 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6678 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6680 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6681 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6682 NL80211_CMD_CONNECT
))
6685 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6687 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6689 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6690 NL80211_MAX_NR_CIPHER_SUITES
);
6694 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6695 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6698 wiphy
= &rdev
->wiphy
;
6700 connect
.bg_scan_period
= -1;
6701 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6702 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6703 connect
.bg_scan_period
=
6704 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6707 if (info
->attrs
[NL80211_ATTR_MAC
])
6708 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6709 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6710 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6712 if (info
->attrs
[NL80211_ATTR_IE
]) {
6713 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6714 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6717 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6718 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6719 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6720 connect
.mfp
!= NL80211_MFP_NO
)
6723 connect
.mfp
= NL80211_MFP_NO
;
6726 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6728 ieee80211_get_channel(wiphy
,
6729 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6730 if (!connect
.channel
||
6731 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6735 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6736 connkeys
= nl80211_parse_connkeys(rdev
,
6737 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6738 if (IS_ERR(connkeys
))
6739 return PTR_ERR(connkeys
);
6742 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6743 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6745 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6746 memcpy(&connect
.ht_capa_mask
,
6747 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6748 sizeof(connect
.ht_capa_mask
));
6750 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6751 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6755 memcpy(&connect
.ht_capa
,
6756 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6757 sizeof(connect
.ht_capa
));
6760 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6761 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6763 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6764 memcpy(&connect
.vht_capa_mask
,
6765 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6766 sizeof(connect
.vht_capa_mask
));
6768 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6769 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6773 memcpy(&connect
.vht_capa
,
6774 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6775 sizeof(connect
.vht_capa
));
6778 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
6784 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6786 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6787 struct net_device
*dev
= info
->user_ptr
[1];
6790 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6791 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6793 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6798 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6799 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6802 return cfg80211_disconnect(rdev
, dev
, reason
, true);
6805 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6807 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6812 if (!info
->attrs
[NL80211_ATTR_PID
])
6815 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6817 net
= get_net_ns_by_pid(pid
);
6819 return PTR_ERR(net
);
6823 /* check if anything to do */
6824 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6825 err
= cfg80211_switch_netns(rdev
, net
);
6831 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6833 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6834 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6835 struct cfg80211_pmksa
*pmksa
) = NULL
;
6836 struct net_device
*dev
= info
->user_ptr
[1];
6837 struct cfg80211_pmksa pmksa
;
6839 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6841 if (!info
->attrs
[NL80211_ATTR_MAC
])
6844 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6847 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6848 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6850 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6851 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6854 switch (info
->genlhdr
->cmd
) {
6855 case NL80211_CMD_SET_PMKSA
:
6856 rdev_ops
= rdev
->ops
->set_pmksa
;
6858 case NL80211_CMD_DEL_PMKSA
:
6859 rdev_ops
= rdev
->ops
->del_pmksa
;
6869 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6872 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6875 struct net_device
*dev
= info
->user_ptr
[1];
6877 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6878 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6881 if (!rdev
->ops
->flush_pmksa
)
6884 return rdev_flush_pmksa(rdev
, dev
);
6887 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6889 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6890 struct net_device
*dev
= info
->user_ptr
[1];
6891 u8 action_code
, dialog_token
;
6895 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6896 !rdev
->ops
->tdls_mgmt
)
6899 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6900 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6901 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6902 !info
->attrs
[NL80211_ATTR_IE
] ||
6903 !info
->attrs
[NL80211_ATTR_MAC
])
6906 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6907 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6908 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6909 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6911 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6912 dialog_token
, status_code
,
6913 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6914 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6917 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6919 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6920 struct net_device
*dev
= info
->user_ptr
[1];
6921 enum nl80211_tdls_operation operation
;
6924 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6925 !rdev
->ops
->tdls_oper
)
6928 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6929 !info
->attrs
[NL80211_ATTR_MAC
])
6932 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6933 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6935 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6938 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6939 struct genl_info
*info
)
6941 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6942 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6943 struct cfg80211_chan_def chandef
;
6944 struct sk_buff
*msg
;
6950 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6951 !info
->attrs
[NL80211_ATTR_DURATION
])
6954 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6956 if (!rdev
->ops
->remain_on_channel
||
6957 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6961 * We should be on that channel for at least a minimum amount of
6962 * time (10ms) but no longer than the driver supports.
6964 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6965 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6968 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6972 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6976 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6977 NL80211_CMD_REMAIN_ON_CHANNEL
);
6983 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6989 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6990 goto nla_put_failure
;
6992 genlmsg_end(msg
, hdr
);
6994 return genlmsg_reply(msg
, info
);
7003 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7004 struct genl_info
*info
)
7006 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7007 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7010 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7013 if (!rdev
->ops
->cancel_remain_on_channel
)
7016 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7018 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7021 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7022 u8
*rates
, u8 rates_len
)
7027 for (i
= 0; i
< rates_len
; i
++) {
7028 int rate
= (rates
[i
] & 0x7f) * 5;
7030 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7031 struct ieee80211_rate
*srate
=
7032 &sband
->bitrates
[ridx
];
7033 if (rate
== srate
->bitrate
) {
7038 if (ridx
== sband
->n_bitrates
)
7039 return 0; /* rate not found */
7045 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7046 u8
*rates
, u8 rates_len
,
7047 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7051 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7053 for (i
= 0; i
< rates_len
; i
++) {
7056 ridx
= rates
[i
] / 8;
7057 rbit
= BIT(rates
[i
] % 8);
7059 /* check validity */
7060 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7063 /* check availability */
7064 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7073 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7074 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7075 .len
= NL80211_MAX_SUPP_RATES
},
7076 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7077 .len
= NL80211_MAX_SUPP_HT_RATES
},
7080 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7081 struct genl_info
*info
)
7083 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7084 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7085 struct cfg80211_bitrate_mask mask
;
7087 struct net_device
*dev
= info
->user_ptr
[1];
7088 struct nlattr
*tx_rates
;
7089 struct ieee80211_supported_band
*sband
;
7091 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7094 if (!rdev
->ops
->set_bitrate_mask
)
7097 memset(&mask
, 0, sizeof(mask
));
7098 /* Default to all rates enabled */
7099 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7100 sband
= rdev
->wiphy
.bands
[i
];
7101 mask
.control
[i
].legacy
=
7102 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7104 memcpy(mask
.control
[i
].mcs
,
7105 sband
->ht_cap
.mcs
.rx_mask
,
7106 sizeof(mask
.control
[i
].mcs
));
7108 memset(mask
.control
[i
].mcs
, 0,
7109 sizeof(mask
.control
[i
].mcs
));
7113 * The nested attribute uses enum nl80211_band as the index. This maps
7114 * directly to the enum ieee80211_band values used in cfg80211.
7116 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7117 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7119 enum ieee80211_band band
= nla_type(tx_rates
);
7120 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7122 sband
= rdev
->wiphy
.bands
[band
];
7125 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7126 nla_len(tx_rates
), nl80211_txattr_policy
);
7127 if (tb
[NL80211_TXRATE_LEGACY
]) {
7128 mask
.control
[band
].legacy
= rateset_to_mask(
7130 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7131 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7132 if ((mask
.control
[band
].legacy
== 0) &&
7133 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7136 if (tb
[NL80211_TXRATE_MCS
]) {
7137 if (!ht_rateset_to_mask(
7139 nla_data(tb
[NL80211_TXRATE_MCS
]),
7140 nla_len(tb
[NL80211_TXRATE_MCS
]),
7141 mask
.control
[band
].mcs
))
7145 if (mask
.control
[band
].legacy
== 0) {
7146 /* don't allow empty legacy rates if HT
7147 * is not even supported. */
7148 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7151 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7152 if (mask
.control
[band
].mcs
[i
])
7155 /* legacy and mcs rates may not be both empty */
7156 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7161 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7164 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7166 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7167 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7168 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7170 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7173 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7174 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7176 switch (wdev
->iftype
) {
7177 case NL80211_IFTYPE_STATION
:
7178 case NL80211_IFTYPE_ADHOC
:
7179 case NL80211_IFTYPE_P2P_CLIENT
:
7180 case NL80211_IFTYPE_AP
:
7181 case NL80211_IFTYPE_AP_VLAN
:
7182 case NL80211_IFTYPE_MESH_POINT
:
7183 case NL80211_IFTYPE_P2P_GO
:
7184 case NL80211_IFTYPE_P2P_DEVICE
:
7190 /* not much point in registering if we can't reply */
7191 if (!rdev
->ops
->mgmt_tx
)
7194 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7195 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7196 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7199 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7201 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7202 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7203 struct cfg80211_chan_def chandef
;
7207 struct sk_buff
*msg
= NULL
;
7208 unsigned int wait
= 0;
7209 bool offchan
, no_cck
, dont_wait_for_ack
;
7211 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7213 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7216 if (!rdev
->ops
->mgmt_tx
)
7219 switch (wdev
->iftype
) {
7220 case NL80211_IFTYPE_STATION
:
7221 case NL80211_IFTYPE_ADHOC
:
7222 case NL80211_IFTYPE_P2P_CLIENT
:
7223 case NL80211_IFTYPE_AP
:
7224 case NL80211_IFTYPE_AP_VLAN
:
7225 case NL80211_IFTYPE_MESH_POINT
:
7226 case NL80211_IFTYPE_P2P_GO
:
7227 case NL80211_IFTYPE_P2P_DEVICE
:
7233 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7234 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7236 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7239 * We should wait on the channel for at least a minimum amount
7240 * of time (10ms) but no longer than the driver supports.
7242 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7243 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7248 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7250 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7253 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7255 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7259 if (!dont_wait_for_ack
) {
7260 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7264 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7272 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7273 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7274 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7275 no_cck
, dont_wait_for_ack
, &cookie
);
7280 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7281 goto nla_put_failure
;
7283 genlmsg_end(msg
, hdr
);
7284 return genlmsg_reply(msg
, info
);
7296 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7298 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7299 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7302 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7305 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7308 switch (wdev
->iftype
) {
7309 case NL80211_IFTYPE_STATION
:
7310 case NL80211_IFTYPE_ADHOC
:
7311 case NL80211_IFTYPE_P2P_CLIENT
:
7312 case NL80211_IFTYPE_AP
:
7313 case NL80211_IFTYPE_AP_VLAN
:
7314 case NL80211_IFTYPE_P2P_GO
:
7315 case NL80211_IFTYPE_P2P_DEVICE
:
7321 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7323 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7326 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7328 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7329 struct wireless_dev
*wdev
;
7330 struct net_device
*dev
= info
->user_ptr
[1];
7335 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7338 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7340 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7343 wdev
= dev
->ieee80211_ptr
;
7345 if (!rdev
->ops
->set_power_mgmt
)
7348 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7350 if (state
== wdev
->ps
)
7353 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7359 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7361 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7362 enum nl80211_ps_state ps_state
;
7363 struct wireless_dev
*wdev
;
7364 struct net_device
*dev
= info
->user_ptr
[1];
7365 struct sk_buff
*msg
;
7369 wdev
= dev
->ieee80211_ptr
;
7371 if (!rdev
->ops
->set_power_mgmt
)
7374 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7378 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7379 NL80211_CMD_GET_POWER_SAVE
);
7386 ps_state
= NL80211_PS_ENABLED
;
7388 ps_state
= NL80211_PS_DISABLED
;
7390 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7391 goto nla_put_failure
;
7393 genlmsg_end(msg
, hdr
);
7394 return genlmsg_reply(msg
, info
);
7403 static struct nla_policy
7404 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7405 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7406 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7407 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7408 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7409 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7410 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7413 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7414 u32 rate
, u32 pkts
, u32 intvl
)
7416 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7417 struct wireless_dev
*wdev
;
7418 struct net_device
*dev
= info
->user_ptr
[1];
7420 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7423 wdev
= dev
->ieee80211_ptr
;
7425 if (!rdev
->ops
->set_cqm_txe_config
)
7428 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7429 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7432 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7435 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7436 s32 threshold
, u32 hysteresis
)
7438 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7439 struct wireless_dev
*wdev
;
7440 struct net_device
*dev
= info
->user_ptr
[1];
7445 wdev
= dev
->ieee80211_ptr
;
7447 if (!rdev
->ops
->set_cqm_rssi_config
)
7450 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7451 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7454 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7457 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7459 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7463 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7469 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7470 nl80211_attr_cqm_policy
);
7474 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7475 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7478 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7479 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7480 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7481 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7482 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7483 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7484 u32 rate
, pkts
, intvl
;
7485 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7486 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7487 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7488 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7496 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7498 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7499 struct net_device
*dev
= info
->user_ptr
[1];
7500 struct mesh_config cfg
;
7501 struct mesh_setup setup
;
7504 /* start with default */
7505 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7506 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7508 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7509 /* and parse parameters if given */
7510 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7515 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7516 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7519 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7520 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7522 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7523 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7524 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7527 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7528 setup
.beacon_interval
=
7529 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7530 if (setup
.beacon_interval
< 10 ||
7531 setup
.beacon_interval
> 10000)
7535 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7537 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7538 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7542 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7543 /* parse additional setup parameters if given */
7544 err
= nl80211_parse_mesh_setup(info
, &setup
);
7550 cfg
.auto_open_plinks
= false;
7552 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7553 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7557 /* cfg80211_join_mesh() will sort it out */
7558 setup
.chandef
.chan
= NULL
;
7561 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7564 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7566 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7567 struct net_device
*dev
= info
->user_ptr
[1];
7569 return cfg80211_leave_mesh(rdev
, dev
);
7573 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7574 struct cfg80211_registered_device
*rdev
)
7576 struct nlattr
*nl_pats
, *nl_pat
;
7579 if (!rdev
->wowlan
->n_patterns
)
7582 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7586 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
7587 nl_pat
= nla_nest_start(msg
, i
+ 1);
7590 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
7591 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7592 DIV_ROUND_UP(pat_len
, 8),
7593 rdev
->wowlan
->patterns
[i
].mask
) ||
7594 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7595 pat_len
, rdev
->wowlan
->patterns
[i
].pattern
) ||
7596 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7597 rdev
->wowlan
->patterns
[i
].pkt_offset
))
7599 nla_nest_end(msg
, nl_pat
);
7601 nla_nest_end(msg
, nl_pats
);
7606 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7607 struct cfg80211_wowlan_tcp
*tcp
)
7609 struct nlattr
*nl_tcp
;
7614 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7618 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7619 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7620 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7621 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7622 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7623 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7624 tcp
->payload_len
, tcp
->payload
) ||
7625 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7626 tcp
->data_interval
) ||
7627 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7628 tcp
->wake_len
, tcp
->wake_data
) ||
7629 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7630 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7633 if (tcp
->payload_seq
.len
&&
7634 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7635 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7638 if (tcp
->payload_tok
.len
&&
7639 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7640 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7644 nla_nest_end(msg
, nl_tcp
);
7649 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7651 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7652 struct sk_buff
*msg
;
7654 u32 size
= NLMSG_DEFAULT_SIZE
;
7656 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7657 !rdev
->wiphy
.wowlan
.tcp
)
7660 if (rdev
->wowlan
&& rdev
->wowlan
->tcp
) {
7661 /* adjust size to have room for all the data */
7662 size
+= rdev
->wowlan
->tcp
->tokens_size
+
7663 rdev
->wowlan
->tcp
->payload_len
+
7664 rdev
->wowlan
->tcp
->wake_len
+
7665 rdev
->wowlan
->tcp
->wake_len
/ 8;
7668 msg
= nlmsg_new(size
, GFP_KERNEL
);
7672 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7673 NL80211_CMD_GET_WOWLAN
);
7675 goto nla_put_failure
;
7678 struct nlattr
*nl_wowlan
;
7680 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7682 goto nla_put_failure
;
7684 if ((rdev
->wowlan
->any
&&
7685 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7686 (rdev
->wowlan
->disconnect
&&
7687 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7688 (rdev
->wowlan
->magic_pkt
&&
7689 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7690 (rdev
->wowlan
->gtk_rekey_failure
&&
7691 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7692 (rdev
->wowlan
->eap_identity_req
&&
7693 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7694 (rdev
->wowlan
->four_way_handshake
&&
7695 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7696 (rdev
->wowlan
->rfkill_release
&&
7697 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7698 goto nla_put_failure
;
7700 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7701 goto nla_put_failure
;
7703 if (nl80211_send_wowlan_tcp(msg
, rdev
->wowlan
->tcp
))
7704 goto nla_put_failure
;
7706 nla_nest_end(msg
, nl_wowlan
);
7709 genlmsg_end(msg
, hdr
);
7710 return genlmsg_reply(msg
, info
);
7717 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7718 struct nlattr
*attr
,
7719 struct cfg80211_wowlan
*trig
)
7721 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7722 struct cfg80211_wowlan_tcp
*cfg
;
7723 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7724 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7726 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7729 if (!rdev
->wiphy
.wowlan
.tcp
)
7732 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7733 nla_data(attr
), nla_len(attr
),
7734 nl80211_wowlan_tcp_policy
);
7738 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7739 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7740 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7741 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7742 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7743 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7744 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7745 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7748 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7749 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7752 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7753 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
||
7754 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7757 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7758 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7761 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7762 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7765 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7766 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7768 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7769 tokens_size
= tokln
- sizeof(*tok
);
7771 if (!tok
->len
|| tokens_size
% tok
->len
)
7773 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7775 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7777 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7779 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7781 if (tok
->offset
+ tok
->len
> data_size
)
7785 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7786 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7787 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7789 if (seq
->len
== 0 || seq
->len
> 4)
7791 if (seq
->len
+ seq
->offset
> data_size
)
7795 size
= sizeof(*cfg
);
7797 size
+= wake_size
+ wake_mask_size
;
7798 size
+= tokens_size
;
7800 cfg
= kzalloc(size
, GFP_KERNEL
);
7803 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7804 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7805 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7807 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7808 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7812 /* allocate a socket and port for it and use it */
7813 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7814 IPPROTO_TCP
, &cfg
->sock
, 1);
7819 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7820 sock_release(cfg
->sock
);
7824 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7830 cfg
->src_port
= port
;
7833 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7834 cfg
->payload_len
= data_size
;
7835 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7836 memcpy((void *)cfg
->payload
,
7837 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7840 cfg
->payload_seq
= *seq
;
7841 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7842 cfg
->wake_len
= wake_size
;
7843 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7844 memcpy((void *)cfg
->wake_data
,
7845 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7847 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7848 data_size
+ wake_size
;
7849 memcpy((void *)cfg
->wake_mask
,
7850 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7853 cfg
->tokens_size
= tokens_size
;
7854 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7862 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7864 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7865 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7866 struct cfg80211_wowlan new_triggers
= {};
7867 struct cfg80211_wowlan
*ntrig
;
7868 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7870 bool prev_enabled
= rdev
->wowlan
;
7872 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7873 !rdev
->wiphy
.wowlan
.tcp
)
7876 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7877 cfg80211_rdev_free_wowlan(rdev
);
7878 rdev
->wowlan
= NULL
;
7882 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7883 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7884 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7885 nl80211_wowlan_policy
);
7889 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7890 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7892 new_triggers
.any
= true;
7895 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7896 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7898 new_triggers
.disconnect
= true;
7901 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7902 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7904 new_triggers
.magic_pkt
= true;
7907 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7910 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7911 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7913 new_triggers
.gtk_rekey_failure
= true;
7916 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7917 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7919 new_triggers
.eap_identity_req
= true;
7922 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7923 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7925 new_triggers
.four_way_handshake
= true;
7928 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7929 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7931 new_triggers
.rfkill_release
= true;
7934 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7937 int rem
, pat_len
, mask_len
, pkt_offset
;
7938 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7940 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7943 if (n_patterns
> wowlan
->n_patterns
)
7946 new_triggers
.patterns
= kcalloc(n_patterns
,
7947 sizeof(new_triggers
.patterns
[0]),
7949 if (!new_triggers
.patterns
)
7952 new_triggers
.n_patterns
= n_patterns
;
7955 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7957 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7958 nla_data(pat
), nla_len(pat
), NULL
);
7960 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7961 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7963 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7964 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7965 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7968 if (pat_len
> wowlan
->pattern_max_len
||
7969 pat_len
< wowlan
->pattern_min_len
)
7972 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7975 pkt_offset
= nla_get_u32(
7976 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7977 if (pkt_offset
> wowlan
->max_pkt_offset
)
7979 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7981 new_triggers
.patterns
[i
].mask
=
7982 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7983 if (!new_triggers
.patterns
[i
].mask
) {
7987 new_triggers
.patterns
[i
].pattern
=
7988 new_triggers
.patterns
[i
].mask
+ mask_len
;
7989 memcpy(new_triggers
.patterns
[i
].mask
,
7990 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7992 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7993 memcpy(new_triggers
.patterns
[i
].pattern
,
7994 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
8000 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8001 err
= nl80211_parse_wowlan_tcp(
8002 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8008 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8013 cfg80211_rdev_free_wowlan(rdev
);
8014 rdev
->wowlan
= ntrig
;
8017 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
8018 rdev_set_wakeup(rdev
, rdev
->wowlan
);
8022 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8023 kfree(new_triggers
.patterns
[i
].mask
);
8024 kfree(new_triggers
.patterns
);
8025 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8026 sock_release(new_triggers
.tcp
->sock
);
8027 kfree(new_triggers
.tcp
);
8032 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8034 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8035 struct net_device
*dev
= info
->user_ptr
[1];
8036 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8037 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8038 struct cfg80211_gtk_rekey_data rekey_data
;
8041 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8044 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8045 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8046 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8047 nl80211_rekey_policy
);
8051 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8053 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8055 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8058 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8060 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8062 memcpy(rekey_data
.replay_ctr
,
8063 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8064 NL80211_REPLAY_CTR_LEN
);
8067 if (!wdev
->current_bss
) {
8072 if (!rdev
->ops
->set_rekey_data
) {
8077 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8083 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8084 struct genl_info
*info
)
8086 struct net_device
*dev
= info
->user_ptr
[1];
8087 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8089 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8090 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8093 if (wdev
->ap_unexpected_nlportid
)
8096 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8100 static int nl80211_probe_client(struct sk_buff
*skb
,
8101 struct genl_info
*info
)
8103 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8104 struct net_device
*dev
= info
->user_ptr
[1];
8105 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8106 struct sk_buff
*msg
;
8112 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8113 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8116 if (!info
->attrs
[NL80211_ATTR_MAC
])
8119 if (!rdev
->ops
->probe_client
)
8122 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8126 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8127 NL80211_CMD_PROBE_CLIENT
);
8133 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8135 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8139 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8140 goto nla_put_failure
;
8142 genlmsg_end(msg
, hdr
);
8144 return genlmsg_reply(msg
, info
);
8153 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8155 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8156 struct cfg80211_beacon_registration
*reg
, *nreg
;
8159 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8162 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8166 /* First, check if already registered. */
8167 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8168 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8169 if (reg
->nlportid
== info
->snd_portid
) {
8174 /* Add it to the list */
8175 nreg
->nlportid
= info
->snd_portid
;
8176 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8178 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8182 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8187 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8190 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8193 if (!rdev
->ops
->start_p2p_device
)
8196 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8199 if (wdev
->p2p_started
)
8202 mutex_lock(&rdev
->devlist_mtx
);
8203 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8204 mutex_unlock(&rdev
->devlist_mtx
);
8208 err
= rdev_start_p2p_device(rdev
, wdev
);
8212 wdev
->p2p_started
= true;
8213 mutex_lock(&rdev
->devlist_mtx
);
8215 mutex_unlock(&rdev
->devlist_mtx
);
8220 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8222 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8223 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8225 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8228 if (!rdev
->ops
->stop_p2p_device
)
8231 mutex_lock(&rdev
->devlist_mtx
);
8232 mutex_lock(&rdev
->sched_scan_mtx
);
8233 cfg80211_stop_p2p_device(rdev
, wdev
);
8234 mutex_unlock(&rdev
->sched_scan_mtx
);
8235 mutex_unlock(&rdev
->devlist_mtx
);
8240 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8241 struct genl_info
*info
)
8244 struct sk_buff
*msg
;
8246 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8250 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8251 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8253 goto nla_put_failure
;
8255 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8256 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8257 goto nla_put_failure
;
8259 genlmsg_end(msg
, hdr
);
8260 return genlmsg_reply(msg
, info
);
8267 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8269 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8270 struct cfg80211_update_ft_ies_params ft_params
;
8271 struct net_device
*dev
= info
->user_ptr
[1];
8273 if (!rdev
->ops
->update_ft_ies
)
8276 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8277 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8280 memset(&ft_params
, 0, sizeof(ft_params
));
8281 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8282 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8283 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8285 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8288 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8289 struct genl_info
*info
)
8291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8292 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8293 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8297 if (!rdev
->ops
->crit_proto_start
)
8300 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8303 if (rdev
->crit_proto_nlportid
)
8306 /* determine protocol if provided */
8307 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8308 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8310 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8313 /* timeout must be provided */
8314 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8318 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8320 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8323 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8325 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8330 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8331 struct genl_info
*info
)
8333 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8334 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8336 if (!rdev
->ops
->crit_proto_stop
)
8339 if (rdev
->crit_proto_nlportid
) {
8340 rdev
->crit_proto_nlportid
= 0;
8341 rdev_crit_proto_stop(rdev
, wdev
);
8346 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
8348 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8349 struct wireless_dev
*wdev
=
8350 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8354 if (!rdev
|| !rdev
->wiphy
.vendor_commands
)
8358 err
= PTR_ERR(wdev
);
8362 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8366 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
8367 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
8370 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
8371 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
8372 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
8373 const struct wiphy_vendor_command
*vcmd
;
8377 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
8379 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
8382 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
8383 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
8386 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
8390 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
8391 if (!wdev
->netdev
||
8392 !netif_running(wdev
->netdev
))
8399 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
8400 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8401 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8404 rdev
->cur_cmd_info
= info
;
8405 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
8407 rdev
->cur_cmd_info
= NULL
;
8414 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
8415 enum nl80211_commands cmd
,
8416 enum nl80211_attrs attr
,
8419 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8421 if (WARN_ON(!rdev
->cur_cmd_info
))
8424 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
,
8427 cmd
, attr
, NULL
, GFP_KERNEL
);
8429 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
8431 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
8433 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8434 void *hdr
= ((void **)skb
->cb
)[1];
8435 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8437 if (WARN_ON(!rdev
->cur_cmd_info
)) {
8442 nla_nest_end(skb
, data
);
8443 genlmsg_end(skb
, hdr
);
8444 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
8446 EXPORT_SYMBOL(cfg80211_vendor_cmd_reply
);
8448 #define NL80211_FLAG_NEED_WIPHY 0x01
8449 #define NL80211_FLAG_NEED_NETDEV 0x02
8450 #define NL80211_FLAG_NEED_RTNL 0x04
8451 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8452 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8453 NL80211_FLAG_CHECK_NETDEV_UP)
8454 #define NL80211_FLAG_NEED_WDEV 0x10
8455 /* If a netdev is associated, it must be UP, P2P must be started */
8456 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8457 NL80211_FLAG_CHECK_NETDEV_UP)
8459 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8460 struct genl_info
*info
)
8462 struct cfg80211_registered_device
*rdev
;
8463 struct wireless_dev
*wdev
;
8464 struct net_device
*dev
;
8465 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8470 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8471 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8475 return PTR_ERR(rdev
);
8477 info
->user_ptr
[0] = rdev
;
8478 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8479 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8480 mutex_lock(&cfg80211_mutex
);
8481 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8484 mutex_unlock(&cfg80211_mutex
);
8487 return PTR_ERR(wdev
);
8491 rdev
= wiphy_to_dev(wdev
->wiphy
);
8493 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8495 mutex_unlock(&cfg80211_mutex
);
8501 info
->user_ptr
[1] = dev
;
8503 info
->user_ptr
[1] = wdev
;
8507 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8508 !netif_running(dev
)) {
8509 mutex_unlock(&cfg80211_mutex
);
8516 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8517 if (!wdev
->p2p_started
) {
8518 mutex_unlock(&cfg80211_mutex
);
8525 cfg80211_lock_rdev(rdev
);
8527 mutex_unlock(&cfg80211_mutex
);
8529 info
->user_ptr
[0] = rdev
;
8535 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8536 struct genl_info
*info
)
8538 if (info
->user_ptr
[0])
8539 cfg80211_unlock_rdev(info
->user_ptr
[0]);
8540 if (info
->user_ptr
[1]) {
8541 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8542 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8545 dev_put(wdev
->netdev
);
8547 dev_put(info
->user_ptr
[1]);
8550 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8554 static struct genl_ops nl80211_ops
[] = {
8556 .cmd
= NL80211_CMD_GET_WIPHY
,
8557 .doit
= nl80211_get_wiphy
,
8558 .dumpit
= nl80211_dump_wiphy
,
8559 .policy
= nl80211_policy
,
8560 /* can be retrieved by unprivileged users */
8561 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
8564 .cmd
= NL80211_CMD_SET_WIPHY
,
8565 .doit
= nl80211_set_wiphy
,
8566 .policy
= nl80211_policy
,
8567 .flags
= GENL_ADMIN_PERM
,
8568 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8571 .cmd
= NL80211_CMD_GET_INTERFACE
,
8572 .doit
= nl80211_get_interface
,
8573 .dumpit
= nl80211_dump_interface
,
8574 .policy
= nl80211_policy
,
8575 /* can be retrieved by unprivileged users */
8576 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
8579 .cmd
= NL80211_CMD_SET_INTERFACE
,
8580 .doit
= nl80211_set_interface
,
8581 .policy
= nl80211_policy
,
8582 .flags
= GENL_ADMIN_PERM
,
8583 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8584 NL80211_FLAG_NEED_RTNL
,
8587 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8588 .doit
= nl80211_new_interface
,
8589 .policy
= nl80211_policy
,
8590 .flags
= GENL_ADMIN_PERM
,
8591 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8592 NL80211_FLAG_NEED_RTNL
,
8595 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8596 .doit
= nl80211_del_interface
,
8597 .policy
= nl80211_policy
,
8598 .flags
= GENL_ADMIN_PERM
,
8599 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8600 NL80211_FLAG_NEED_RTNL
,
8603 .cmd
= NL80211_CMD_GET_KEY
,
8604 .doit
= nl80211_get_key
,
8605 .policy
= nl80211_policy
,
8606 .flags
= GENL_ADMIN_PERM
,
8607 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8608 NL80211_FLAG_NEED_RTNL
,
8611 .cmd
= NL80211_CMD_SET_KEY
,
8612 .doit
= nl80211_set_key
,
8613 .policy
= nl80211_policy
,
8614 .flags
= GENL_ADMIN_PERM
,
8615 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8616 NL80211_FLAG_NEED_RTNL
,
8619 .cmd
= NL80211_CMD_NEW_KEY
,
8620 .doit
= nl80211_new_key
,
8621 .policy
= nl80211_policy
,
8622 .flags
= GENL_ADMIN_PERM
,
8623 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8624 NL80211_FLAG_NEED_RTNL
,
8627 .cmd
= NL80211_CMD_DEL_KEY
,
8628 .doit
= nl80211_del_key
,
8629 .policy
= nl80211_policy
,
8630 .flags
= GENL_ADMIN_PERM
,
8631 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8632 NL80211_FLAG_NEED_RTNL
,
8635 .cmd
= NL80211_CMD_SET_BEACON
,
8636 .policy
= nl80211_policy
,
8637 .flags
= GENL_ADMIN_PERM
,
8638 .doit
= nl80211_set_beacon
,
8639 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8640 NL80211_FLAG_NEED_RTNL
,
8643 .cmd
= NL80211_CMD_START_AP
,
8644 .policy
= nl80211_policy
,
8645 .flags
= GENL_ADMIN_PERM
,
8646 .doit
= nl80211_start_ap
,
8647 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8648 NL80211_FLAG_NEED_RTNL
,
8651 .cmd
= NL80211_CMD_STOP_AP
,
8652 .policy
= nl80211_policy
,
8653 .flags
= GENL_ADMIN_PERM
,
8654 .doit
= nl80211_stop_ap
,
8655 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8656 NL80211_FLAG_NEED_RTNL
,
8659 .cmd
= NL80211_CMD_GET_STATION
,
8660 .doit
= nl80211_get_station
,
8661 .dumpit
= nl80211_dump_station
,
8662 .policy
= nl80211_policy
,
8663 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8664 NL80211_FLAG_NEED_RTNL
,
8667 .cmd
= NL80211_CMD_SET_STATION
,
8668 .doit
= nl80211_set_station
,
8669 .policy
= nl80211_policy
,
8670 .flags
= GENL_ADMIN_PERM
,
8671 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8672 NL80211_FLAG_NEED_RTNL
,
8675 .cmd
= NL80211_CMD_NEW_STATION
,
8676 .doit
= nl80211_new_station
,
8677 .policy
= nl80211_policy
,
8678 .flags
= GENL_ADMIN_PERM
,
8679 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8680 NL80211_FLAG_NEED_RTNL
,
8683 .cmd
= NL80211_CMD_DEL_STATION
,
8684 .doit
= nl80211_del_station
,
8685 .policy
= nl80211_policy
,
8686 .flags
= GENL_ADMIN_PERM
,
8687 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8688 NL80211_FLAG_NEED_RTNL
,
8691 .cmd
= NL80211_CMD_GET_MPATH
,
8692 .doit
= nl80211_get_mpath
,
8693 .dumpit
= nl80211_dump_mpath
,
8694 .policy
= nl80211_policy
,
8695 .flags
= GENL_ADMIN_PERM
,
8696 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8697 NL80211_FLAG_NEED_RTNL
,
8700 .cmd
= NL80211_CMD_SET_MPATH
,
8701 .doit
= nl80211_set_mpath
,
8702 .policy
= nl80211_policy
,
8703 .flags
= GENL_ADMIN_PERM
,
8704 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8705 NL80211_FLAG_NEED_RTNL
,
8708 .cmd
= NL80211_CMD_NEW_MPATH
,
8709 .doit
= nl80211_new_mpath
,
8710 .policy
= nl80211_policy
,
8711 .flags
= GENL_ADMIN_PERM
,
8712 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8713 NL80211_FLAG_NEED_RTNL
,
8716 .cmd
= NL80211_CMD_DEL_MPATH
,
8717 .doit
= nl80211_del_mpath
,
8718 .policy
= nl80211_policy
,
8719 .flags
= GENL_ADMIN_PERM
,
8720 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8721 NL80211_FLAG_NEED_RTNL
,
8724 .cmd
= NL80211_CMD_SET_BSS
,
8725 .doit
= nl80211_set_bss
,
8726 .policy
= nl80211_policy
,
8727 .flags
= GENL_ADMIN_PERM
,
8728 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8729 NL80211_FLAG_NEED_RTNL
,
8732 .cmd
= NL80211_CMD_GET_REG
,
8733 .doit
= nl80211_get_reg
,
8734 .policy
= nl80211_policy
,
8735 /* can be retrieved by unprivileged users */
8738 .cmd
= NL80211_CMD_SET_REG
,
8739 .doit
= nl80211_set_reg
,
8740 .policy
= nl80211_policy
,
8741 .flags
= GENL_ADMIN_PERM
,
8744 .cmd
= NL80211_CMD_REQ_SET_REG
,
8745 .doit
= nl80211_req_set_reg
,
8746 .policy
= nl80211_policy
,
8747 .flags
= GENL_ADMIN_PERM
,
8750 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8751 .doit
= nl80211_get_mesh_config
,
8752 .policy
= nl80211_policy
,
8753 /* can be retrieved by unprivileged users */
8754 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8755 NL80211_FLAG_NEED_RTNL
,
8758 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8759 .doit
= nl80211_update_mesh_config
,
8760 .policy
= nl80211_policy
,
8761 .flags
= GENL_ADMIN_PERM
,
8762 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8763 NL80211_FLAG_NEED_RTNL
,
8766 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8767 .doit
= nl80211_trigger_scan
,
8768 .policy
= nl80211_policy
,
8769 .flags
= GENL_ADMIN_PERM
,
8770 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8771 NL80211_FLAG_NEED_RTNL
,
8774 .cmd
= NL80211_CMD_GET_SCAN
,
8775 .policy
= nl80211_policy
,
8776 .dumpit
= nl80211_dump_scan
,
8779 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8780 .doit
= nl80211_start_sched_scan
,
8781 .policy
= nl80211_policy
,
8782 .flags
= GENL_ADMIN_PERM
,
8783 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8784 NL80211_FLAG_NEED_RTNL
,
8787 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8788 .doit
= nl80211_stop_sched_scan
,
8789 .policy
= nl80211_policy
,
8790 .flags
= GENL_ADMIN_PERM
,
8791 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8792 NL80211_FLAG_NEED_RTNL
,
8795 .cmd
= NL80211_CMD_AUTHENTICATE
,
8796 .doit
= nl80211_authenticate
,
8797 .policy
= nl80211_policy
,
8798 .flags
= GENL_ADMIN_PERM
,
8799 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8800 NL80211_FLAG_NEED_RTNL
,
8803 .cmd
= NL80211_CMD_ASSOCIATE
,
8804 .doit
= nl80211_associate
,
8805 .policy
= nl80211_policy
,
8806 .flags
= GENL_ADMIN_PERM
,
8807 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8808 NL80211_FLAG_NEED_RTNL
,
8811 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8812 .doit
= nl80211_deauthenticate
,
8813 .policy
= nl80211_policy
,
8814 .flags
= GENL_ADMIN_PERM
,
8815 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8816 NL80211_FLAG_NEED_RTNL
,
8819 .cmd
= NL80211_CMD_DISASSOCIATE
,
8820 .doit
= nl80211_disassociate
,
8821 .policy
= nl80211_policy
,
8822 .flags
= GENL_ADMIN_PERM
,
8823 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8824 NL80211_FLAG_NEED_RTNL
,
8827 .cmd
= NL80211_CMD_JOIN_IBSS
,
8828 .doit
= nl80211_join_ibss
,
8829 .policy
= nl80211_policy
,
8830 .flags
= GENL_ADMIN_PERM
,
8831 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8832 NL80211_FLAG_NEED_RTNL
,
8835 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8836 .doit
= nl80211_leave_ibss
,
8837 .policy
= nl80211_policy
,
8838 .flags
= GENL_ADMIN_PERM
,
8839 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8840 NL80211_FLAG_NEED_RTNL
,
8842 #ifdef CONFIG_NL80211_TESTMODE
8844 .cmd
= NL80211_CMD_TESTMODE
,
8845 .doit
= nl80211_testmode_do
,
8846 .dumpit
= nl80211_testmode_dump
,
8847 .policy
= nl80211_policy
,
8848 .flags
= GENL_ADMIN_PERM
,
8849 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8850 NL80211_FLAG_NEED_RTNL
,
8854 .cmd
= NL80211_CMD_CONNECT
,
8855 .doit
= nl80211_connect
,
8856 .policy
= nl80211_policy
,
8857 .flags
= GENL_ADMIN_PERM
,
8858 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8859 NL80211_FLAG_NEED_RTNL
,
8862 .cmd
= NL80211_CMD_DISCONNECT
,
8863 .doit
= nl80211_disconnect
,
8864 .policy
= nl80211_policy
,
8865 .flags
= GENL_ADMIN_PERM
,
8866 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8867 NL80211_FLAG_NEED_RTNL
,
8870 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8871 .doit
= nl80211_wiphy_netns
,
8872 .policy
= nl80211_policy
,
8873 .flags
= GENL_ADMIN_PERM
,
8874 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8875 NL80211_FLAG_NEED_RTNL
,
8878 .cmd
= NL80211_CMD_GET_SURVEY
,
8879 .policy
= nl80211_policy
,
8880 .dumpit
= nl80211_dump_survey
,
8883 .cmd
= NL80211_CMD_SET_PMKSA
,
8884 .doit
= nl80211_setdel_pmksa
,
8885 .policy
= nl80211_policy
,
8886 .flags
= GENL_ADMIN_PERM
,
8887 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8888 NL80211_FLAG_NEED_RTNL
,
8891 .cmd
= NL80211_CMD_DEL_PMKSA
,
8892 .doit
= nl80211_setdel_pmksa
,
8893 .policy
= nl80211_policy
,
8894 .flags
= GENL_ADMIN_PERM
,
8895 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8896 NL80211_FLAG_NEED_RTNL
,
8899 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8900 .doit
= nl80211_flush_pmksa
,
8901 .policy
= nl80211_policy
,
8902 .flags
= GENL_ADMIN_PERM
,
8903 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8904 NL80211_FLAG_NEED_RTNL
,
8907 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8908 .doit
= nl80211_remain_on_channel
,
8909 .policy
= nl80211_policy
,
8910 .flags
= GENL_ADMIN_PERM
,
8911 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8912 NL80211_FLAG_NEED_RTNL
,
8915 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8916 .doit
= nl80211_cancel_remain_on_channel
,
8917 .policy
= nl80211_policy
,
8918 .flags
= GENL_ADMIN_PERM
,
8919 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8920 NL80211_FLAG_NEED_RTNL
,
8923 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8924 .doit
= nl80211_set_tx_bitrate_mask
,
8925 .policy
= nl80211_policy
,
8926 .flags
= GENL_ADMIN_PERM
,
8927 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8928 NL80211_FLAG_NEED_RTNL
,
8931 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8932 .doit
= nl80211_register_mgmt
,
8933 .policy
= nl80211_policy
,
8934 .flags
= GENL_ADMIN_PERM
,
8935 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8936 NL80211_FLAG_NEED_RTNL
,
8939 .cmd
= NL80211_CMD_FRAME
,
8940 .doit
= nl80211_tx_mgmt
,
8941 .policy
= nl80211_policy
,
8942 .flags
= GENL_ADMIN_PERM
,
8943 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8944 NL80211_FLAG_NEED_RTNL
,
8947 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8948 .doit
= nl80211_tx_mgmt_cancel_wait
,
8949 .policy
= nl80211_policy
,
8950 .flags
= GENL_ADMIN_PERM
,
8951 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8952 NL80211_FLAG_NEED_RTNL
,
8955 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8956 .doit
= nl80211_set_power_save
,
8957 .policy
= nl80211_policy
,
8958 .flags
= GENL_ADMIN_PERM
,
8959 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8960 NL80211_FLAG_NEED_RTNL
,
8963 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8964 .doit
= nl80211_get_power_save
,
8965 .policy
= nl80211_policy
,
8966 /* can be retrieved by unprivileged users */
8967 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8968 NL80211_FLAG_NEED_RTNL
,
8971 .cmd
= NL80211_CMD_SET_CQM
,
8972 .doit
= nl80211_set_cqm
,
8973 .policy
= nl80211_policy
,
8974 .flags
= GENL_ADMIN_PERM
,
8975 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8976 NL80211_FLAG_NEED_RTNL
,
8979 .cmd
= NL80211_CMD_SET_CHANNEL
,
8980 .doit
= nl80211_set_channel
,
8981 .policy
= nl80211_policy
,
8982 .flags
= GENL_ADMIN_PERM
,
8983 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8984 NL80211_FLAG_NEED_RTNL
,
8987 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8988 .doit
= nl80211_set_wds_peer
,
8989 .policy
= nl80211_policy
,
8990 .flags
= GENL_ADMIN_PERM
,
8991 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8992 NL80211_FLAG_NEED_RTNL
,
8995 .cmd
= NL80211_CMD_JOIN_MESH
,
8996 .doit
= nl80211_join_mesh
,
8997 .policy
= nl80211_policy
,
8998 .flags
= GENL_ADMIN_PERM
,
8999 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9000 NL80211_FLAG_NEED_RTNL
,
9003 .cmd
= NL80211_CMD_LEAVE_MESH
,
9004 .doit
= nl80211_leave_mesh
,
9005 .policy
= nl80211_policy
,
9006 .flags
= GENL_ADMIN_PERM
,
9007 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9008 NL80211_FLAG_NEED_RTNL
,
9012 .cmd
= NL80211_CMD_GET_WOWLAN
,
9013 .doit
= nl80211_get_wowlan
,
9014 .policy
= nl80211_policy
,
9015 /* can be retrieved by unprivileged users */
9016 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9017 NL80211_FLAG_NEED_RTNL
,
9020 .cmd
= NL80211_CMD_SET_WOWLAN
,
9021 .doit
= nl80211_set_wowlan
,
9022 .policy
= nl80211_policy
,
9023 .flags
= GENL_ADMIN_PERM
,
9024 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9025 NL80211_FLAG_NEED_RTNL
,
9029 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9030 .doit
= nl80211_set_rekey_data
,
9031 .policy
= nl80211_policy
,
9032 .flags
= GENL_ADMIN_PERM
,
9033 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9034 NL80211_FLAG_NEED_RTNL
,
9037 .cmd
= NL80211_CMD_TDLS_MGMT
,
9038 .doit
= nl80211_tdls_mgmt
,
9039 .policy
= nl80211_policy
,
9040 .flags
= GENL_ADMIN_PERM
,
9041 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9042 NL80211_FLAG_NEED_RTNL
,
9045 .cmd
= NL80211_CMD_TDLS_OPER
,
9046 .doit
= nl80211_tdls_oper
,
9047 .policy
= nl80211_policy
,
9048 .flags
= GENL_ADMIN_PERM
,
9049 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9050 NL80211_FLAG_NEED_RTNL
,
9053 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9054 .doit
= nl80211_register_unexpected_frame
,
9055 .policy
= nl80211_policy
,
9056 .flags
= GENL_ADMIN_PERM
,
9057 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9058 NL80211_FLAG_NEED_RTNL
,
9061 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9062 .doit
= nl80211_probe_client
,
9063 .policy
= nl80211_policy
,
9064 .flags
= GENL_ADMIN_PERM
,
9065 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9066 NL80211_FLAG_NEED_RTNL
,
9069 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9070 .doit
= nl80211_register_beacons
,
9071 .policy
= nl80211_policy
,
9072 .flags
= GENL_ADMIN_PERM
,
9073 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9074 NL80211_FLAG_NEED_RTNL
,
9077 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
9078 .doit
= nl80211_set_noack_map
,
9079 .policy
= nl80211_policy
,
9080 .flags
= GENL_ADMIN_PERM
,
9081 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9082 NL80211_FLAG_NEED_RTNL
,
9085 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
9086 .doit
= nl80211_start_p2p_device
,
9087 .policy
= nl80211_policy
,
9088 .flags
= GENL_ADMIN_PERM
,
9089 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9090 NL80211_FLAG_NEED_RTNL
,
9093 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
9094 .doit
= nl80211_stop_p2p_device
,
9095 .policy
= nl80211_policy
,
9096 .flags
= GENL_ADMIN_PERM
,
9097 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9098 NL80211_FLAG_NEED_RTNL
,
9101 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
9102 .doit
= nl80211_set_mcast_rate
,
9103 .policy
= nl80211_policy
,
9104 .flags
= GENL_ADMIN_PERM
,
9105 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9106 NL80211_FLAG_NEED_RTNL
,
9109 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9110 .doit
= nl80211_set_mac_acl
,
9111 .policy
= nl80211_policy
,
9112 .flags
= GENL_ADMIN_PERM
,
9113 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9114 NL80211_FLAG_NEED_RTNL
,
9117 .cmd
= NL80211_CMD_RADAR_DETECT
,
9118 .doit
= nl80211_start_radar_detection
,
9119 .policy
= nl80211_policy
,
9120 .flags
= GENL_ADMIN_PERM
,
9121 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9122 NL80211_FLAG_NEED_RTNL
,
9125 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9126 .doit
= nl80211_get_protocol_features
,
9127 .policy
= nl80211_policy
,
9130 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9131 .doit
= nl80211_update_ft_ies
,
9132 .policy
= nl80211_policy
,
9133 .flags
= GENL_ADMIN_PERM
,
9134 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9135 NL80211_FLAG_NEED_RTNL
,
9138 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9139 .doit
= nl80211_crit_protocol_start
,
9140 .policy
= nl80211_policy
,
9141 .flags
= GENL_ADMIN_PERM
,
9142 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9143 NL80211_FLAG_NEED_RTNL
,
9146 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9147 .doit
= nl80211_crit_protocol_stop
,
9148 .policy
= nl80211_policy
,
9149 .flags
= GENL_ADMIN_PERM
,
9150 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9151 NL80211_FLAG_NEED_RTNL
,
9154 .cmd
= NL80211_CMD_VENDOR
,
9155 .doit
= nl80211_vendor_cmd
,
9156 .policy
= nl80211_policy
,
9157 .flags
= GENL_ADMIN_PERM
,
9158 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9159 NL80211_FLAG_NEED_RTNL
,
9163 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9167 /* multicast groups */
9168 static struct genl_multicast_group nl80211_config_mcgrp
= {
9171 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9174 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9175 .name
= "regulatory",
9178 /* notification functions */
9180 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9182 struct sk_buff
*msg
;
9184 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9188 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0,
9189 false, NULL
, NULL
, NULL
) < 0) {
9194 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9195 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9198 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9199 struct cfg80211_registered_device
*rdev
)
9201 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9202 struct nlattr
*nest
;
9205 lockdep_assert_held(&rdev
->sched_scan_mtx
);
9210 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9212 goto nla_put_failure
;
9213 for (i
= 0; i
< req
->n_ssids
; i
++) {
9214 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9215 goto nla_put_failure
;
9217 nla_nest_end(msg
, nest
);
9219 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9221 goto nla_put_failure
;
9222 for (i
= 0; i
< req
->n_channels
; i
++) {
9223 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9224 goto nla_put_failure
;
9226 nla_nest_end(msg
, nest
);
9229 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9230 goto nla_put_failure
;
9233 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9240 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9241 struct cfg80211_registered_device
*rdev
,
9242 struct wireless_dev
*wdev
,
9243 u32 portid
, u32 seq
, int flags
,
9248 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9252 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9253 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9254 wdev
->netdev
->ifindex
)) ||
9255 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9256 goto nla_put_failure
;
9258 /* ignore errors and send incomplete event anyway */
9259 nl80211_add_scan_req(msg
, rdev
);
9261 return genlmsg_end(msg
, hdr
);
9264 genlmsg_cancel(msg
, hdr
);
9269 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9270 struct cfg80211_registered_device
*rdev
,
9271 struct net_device
*netdev
,
9272 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9276 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9280 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9281 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9282 goto nla_put_failure
;
9284 return genlmsg_end(msg
, hdr
);
9287 genlmsg_cancel(msg
, hdr
);
9291 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9292 struct wireless_dev
*wdev
)
9294 struct sk_buff
*msg
;
9296 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9300 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9301 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9306 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9307 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9310 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9311 struct wireless_dev
*wdev
)
9313 struct sk_buff
*msg
;
9315 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9319 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9320 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9325 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9326 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9329 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9330 struct wireless_dev
*wdev
)
9332 struct sk_buff
*msg
;
9334 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9338 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9339 NL80211_CMD_SCAN_ABORTED
) < 0) {
9344 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9345 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9348 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9349 struct net_device
*netdev
)
9351 struct sk_buff
*msg
;
9353 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9357 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9358 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9363 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9364 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9367 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9368 struct net_device
*netdev
, u32 cmd
)
9370 struct sk_buff
*msg
;
9372 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9376 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9381 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9382 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9386 * This can happen on global regulatory changes or device specific settings
9387 * based on custom world regulatory domains.
9389 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9391 struct sk_buff
*msg
;
9394 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9398 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9404 /* Userspace can always count this one always being set */
9405 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9406 goto nla_put_failure
;
9408 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9409 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9410 NL80211_REGDOM_TYPE_WORLD
))
9411 goto nla_put_failure
;
9412 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9413 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9414 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9415 goto nla_put_failure
;
9416 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9417 request
->intersect
) {
9418 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9419 NL80211_REGDOM_TYPE_INTERSECTION
))
9420 goto nla_put_failure
;
9422 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9423 NL80211_REGDOM_TYPE_COUNTRY
) ||
9424 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9426 goto nla_put_failure
;
9429 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9430 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9431 goto nla_put_failure
;
9433 genlmsg_end(msg
, hdr
);
9436 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9443 genlmsg_cancel(msg
, hdr
);
9447 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9448 struct net_device
*netdev
,
9449 const u8
*buf
, size_t len
,
9450 enum nl80211_commands cmd
, gfp_t gfp
)
9452 struct sk_buff
*msg
;
9455 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9459 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9465 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9466 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9467 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9468 goto nla_put_failure
;
9470 genlmsg_end(msg
, hdr
);
9472 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9473 nl80211_mlme_mcgrp
.id
, gfp
);
9477 genlmsg_cancel(msg
, hdr
);
9481 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9482 struct net_device
*netdev
, const u8
*buf
,
9483 size_t len
, gfp_t gfp
)
9485 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9486 NL80211_CMD_AUTHENTICATE
, gfp
);
9489 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9490 struct net_device
*netdev
, const u8
*buf
,
9491 size_t len
, gfp_t gfp
)
9493 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9494 NL80211_CMD_ASSOCIATE
, gfp
);
9497 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9498 struct net_device
*netdev
, const u8
*buf
,
9499 size_t len
, gfp_t gfp
)
9501 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9502 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9505 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9506 struct net_device
*netdev
, const u8
*buf
,
9507 size_t len
, gfp_t gfp
)
9509 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9510 NL80211_CMD_DISASSOCIATE
, gfp
);
9513 void cfg80211_send_unprot_deauth(struct net_device
*dev
, const u8
*buf
,
9516 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9517 struct wiphy
*wiphy
= wdev
->wiphy
;
9518 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9520 trace_cfg80211_send_unprot_deauth(dev
);
9521 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9522 NL80211_CMD_UNPROT_DEAUTHENTICATE
, GFP_ATOMIC
);
9524 EXPORT_SYMBOL(cfg80211_send_unprot_deauth
);
9526 void cfg80211_send_unprot_disassoc(struct net_device
*dev
, const u8
*buf
,
9529 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9530 struct wiphy
*wiphy
= wdev
->wiphy
;
9531 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9533 trace_cfg80211_send_unprot_disassoc(dev
);
9534 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9535 NL80211_CMD_UNPROT_DISASSOCIATE
, GFP_ATOMIC
);
9537 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc
);
9539 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9540 struct net_device
*netdev
, int cmd
,
9541 const u8
*addr
, gfp_t gfp
)
9543 struct sk_buff
*msg
;
9546 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9550 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9556 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9557 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9558 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9559 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9560 goto nla_put_failure
;
9562 genlmsg_end(msg
, hdr
);
9564 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9565 nl80211_mlme_mcgrp
.id
, gfp
);
9569 genlmsg_cancel(msg
, hdr
);
9573 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9574 struct net_device
*netdev
, const u8
*addr
,
9577 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9581 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9582 struct net_device
*netdev
, const u8
*addr
,
9585 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9589 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9590 struct net_device
*netdev
, const u8
*bssid
,
9591 const u8
*req_ie
, size_t req_ie_len
,
9592 const u8
*resp_ie
, size_t resp_ie_len
,
9593 u16 status
, gfp_t gfp
)
9595 struct sk_buff
*msg
;
9598 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9602 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9608 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9609 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9610 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9611 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9613 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9615 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9616 goto nla_put_failure
;
9618 genlmsg_end(msg
, hdr
);
9620 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9621 nl80211_mlme_mcgrp
.id
, gfp
);
9625 genlmsg_cancel(msg
, hdr
);
9630 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9631 struct net_device
*netdev
, const u8
*bssid
,
9632 const u8
*req_ie
, size_t req_ie_len
,
9633 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9635 struct sk_buff
*msg
;
9638 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9642 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9648 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9649 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9650 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9652 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9654 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9655 goto nla_put_failure
;
9657 genlmsg_end(msg
, hdr
);
9659 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9660 nl80211_mlme_mcgrp
.id
, gfp
);
9664 genlmsg_cancel(msg
, hdr
);
9669 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9670 struct net_device
*netdev
, u16 reason
,
9671 const u8
*ie
, size_t ie_len
, bool from_ap
)
9673 struct sk_buff
*msg
;
9676 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9680 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9686 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9687 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9688 (from_ap
&& reason
&&
9689 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9691 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9692 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9693 goto nla_put_failure
;
9695 genlmsg_end(msg
, hdr
);
9697 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9698 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9702 genlmsg_cancel(msg
, hdr
);
9707 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9708 struct net_device
*netdev
, const u8
*bssid
,
9711 struct sk_buff
*msg
;
9714 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9718 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9724 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9725 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9726 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9727 goto nla_put_failure
;
9729 genlmsg_end(msg
, hdr
);
9731 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9732 nl80211_mlme_mcgrp
.id
, gfp
);
9736 genlmsg_cancel(msg
, hdr
);
9740 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9741 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9743 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9744 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9745 struct sk_buff
*msg
;
9748 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9751 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9753 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9757 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9763 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9764 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9765 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9767 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9768 goto nla_put_failure
;
9770 genlmsg_end(msg
, hdr
);
9772 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9773 nl80211_mlme_mcgrp
.id
, gfp
);
9777 genlmsg_cancel(msg
, hdr
);
9780 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9782 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9783 struct net_device
*netdev
, const u8
*addr
,
9784 enum nl80211_key_type key_type
, int key_id
,
9785 const u8
*tsc
, gfp_t gfp
)
9787 struct sk_buff
*msg
;
9790 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9794 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9800 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9801 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9802 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9803 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9805 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9806 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9807 goto nla_put_failure
;
9809 genlmsg_end(msg
, hdr
);
9811 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9812 nl80211_mlme_mcgrp
.id
, gfp
);
9816 genlmsg_cancel(msg
, hdr
);
9820 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9821 struct ieee80211_channel
*channel_before
,
9822 struct ieee80211_channel
*channel_after
)
9824 struct sk_buff
*msg
;
9826 struct nlattr
*nl_freq
;
9828 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9832 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9839 * Since we are applying the beacon hint to a wiphy we know its
9840 * wiphy_idx is valid
9842 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9843 goto nla_put_failure
;
9846 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9848 goto nla_put_failure
;
9849 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9850 goto nla_put_failure
;
9851 nla_nest_end(msg
, nl_freq
);
9854 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9856 goto nla_put_failure
;
9857 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9858 goto nla_put_failure
;
9859 nla_nest_end(msg
, nl_freq
);
9861 genlmsg_end(msg
, hdr
);
9864 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9871 genlmsg_cancel(msg
, hdr
);
9875 static void nl80211_send_remain_on_chan_event(
9876 int cmd
, struct cfg80211_registered_device
*rdev
,
9877 struct wireless_dev
*wdev
, u64 cookie
,
9878 struct ieee80211_channel
*chan
,
9879 unsigned int duration
, gfp_t gfp
)
9881 struct sk_buff
*msg
;
9884 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9888 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9894 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9895 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9896 wdev
->netdev
->ifindex
)) ||
9897 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9898 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9899 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9900 NL80211_CHAN_NO_HT
) ||
9901 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9902 goto nla_put_failure
;
9904 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9905 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9906 goto nla_put_failure
;
9908 genlmsg_end(msg
, hdr
);
9910 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9911 nl80211_mlme_mcgrp
.id
, gfp
);
9915 genlmsg_cancel(msg
, hdr
);
9919 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9920 struct ieee80211_channel
*chan
,
9921 unsigned int duration
, gfp_t gfp
)
9923 struct wiphy
*wiphy
= wdev
->wiphy
;
9924 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9926 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9927 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9928 rdev
, wdev
, cookie
, chan
,
9931 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9933 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9934 struct ieee80211_channel
*chan
,
9937 struct wiphy
*wiphy
= wdev
->wiphy
;
9938 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9940 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9941 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9942 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9944 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9946 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9947 struct station_info
*sinfo
, gfp_t gfp
)
9949 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9950 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9951 struct sk_buff
*msg
;
9953 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9955 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9959 if (nl80211_send_station(msg
, 0, 0, 0,
9960 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9965 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9966 nl80211_mlme_mcgrp
.id
, gfp
);
9968 EXPORT_SYMBOL(cfg80211_new_sta
);
9970 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9972 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9973 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9974 struct sk_buff
*msg
;
9977 trace_cfg80211_del_sta(dev
, mac_addr
);
9979 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9983 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9989 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9990 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9991 goto nla_put_failure
;
9993 genlmsg_end(msg
, hdr
);
9995 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9996 nl80211_mlme_mcgrp
.id
, gfp
);
10000 genlmsg_cancel(msg
, hdr
);
10003 EXPORT_SYMBOL(cfg80211_del_sta
);
10005 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10006 enum nl80211_connect_failed_reason reason
,
10009 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10010 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10011 struct sk_buff
*msg
;
10014 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10018 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10024 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10025 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10026 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10027 goto nla_put_failure
;
10029 genlmsg_end(msg
, hdr
);
10031 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10032 nl80211_mlme_mcgrp
.id
, gfp
);
10036 genlmsg_cancel(msg
, hdr
);
10039 EXPORT_SYMBOL(cfg80211_conn_failed
);
10041 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10042 const u8
*addr
, gfp_t gfp
)
10044 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10045 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10046 struct sk_buff
*msg
;
10049 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10054 msg
= nlmsg_new(100, gfp
);
10058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10064 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10065 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10066 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10067 goto nla_put_failure
;
10069 err
= genlmsg_end(msg
, hdr
);
10075 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10079 genlmsg_cancel(msg
, hdr
);
10084 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
10085 const u8
*addr
, gfp_t gfp
)
10087 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10090 trace_cfg80211_rx_spurious_frame(dev
, addr
);
10092 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10093 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
10094 trace_cfg80211_return_bool(false);
10097 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
10099 trace_cfg80211_return_bool(ret
);
10102 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
10104 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
10105 const u8
*addr
, gfp_t gfp
)
10107 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10110 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
10112 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10113 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10114 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
10115 trace_cfg80211_return_bool(false);
10118 ret
= __nl80211_unexpected_frame(dev
,
10119 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
10121 trace_cfg80211_return_bool(ret
);
10124 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10126 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10127 struct wireless_dev
*wdev
, u32 nlportid
,
10128 int freq
, int sig_dbm
,
10129 const u8
*buf
, size_t len
, gfp_t gfp
)
10131 struct net_device
*netdev
= wdev
->netdev
;
10132 struct sk_buff
*msg
;
10135 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10139 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10145 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10146 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10147 netdev
->ifindex
)) ||
10148 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10149 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10151 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10152 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10153 goto nla_put_failure
;
10155 genlmsg_end(msg
, hdr
);
10157 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10160 genlmsg_cancel(msg
, hdr
);
10165 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10166 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10168 struct wiphy
*wiphy
= wdev
->wiphy
;
10169 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10170 struct net_device
*netdev
= wdev
->netdev
;
10171 struct sk_buff
*msg
;
10174 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10176 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10180 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10186 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10187 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10188 netdev
->ifindex
)) ||
10189 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10190 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10191 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10192 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10193 goto nla_put_failure
;
10195 genlmsg_end(msg
, hdr
);
10197 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10198 nl80211_mlme_mcgrp
.id
, gfp
);
10202 genlmsg_cancel(msg
, hdr
);
10205 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10207 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10208 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10211 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10212 struct wiphy
*wiphy
= wdev
->wiphy
;
10213 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10214 struct sk_buff
*msg
;
10215 struct nlattr
*pinfoattr
;
10218 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10220 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10224 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10230 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10231 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10232 goto nla_put_failure
;
10234 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10236 goto nla_put_failure
;
10238 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10240 goto nla_put_failure
;
10242 nla_nest_end(msg
, pinfoattr
);
10244 genlmsg_end(msg
, hdr
);
10246 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10247 nl80211_mlme_mcgrp
.id
, gfp
);
10251 genlmsg_cancel(msg
, hdr
);
10254 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10256 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10257 struct net_device
*netdev
, const u8
*bssid
,
10258 const u8
*replay_ctr
, gfp_t gfp
)
10260 struct sk_buff
*msg
;
10261 struct nlattr
*rekey_attr
;
10264 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10268 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10274 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10275 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10276 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10277 goto nla_put_failure
;
10279 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10281 goto nla_put_failure
;
10283 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10284 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10285 goto nla_put_failure
;
10287 nla_nest_end(msg
, rekey_attr
);
10289 genlmsg_end(msg
, hdr
);
10291 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10292 nl80211_mlme_mcgrp
.id
, gfp
);
10296 genlmsg_cancel(msg
, hdr
);
10300 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10301 const u8
*replay_ctr
, gfp_t gfp
)
10303 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10304 struct wiphy
*wiphy
= wdev
->wiphy
;
10305 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10307 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10308 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10310 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10313 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10314 struct net_device
*netdev
, int index
,
10315 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10317 struct sk_buff
*msg
;
10318 struct nlattr
*attr
;
10321 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10325 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10331 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10332 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10333 goto nla_put_failure
;
10335 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10337 goto nla_put_failure
;
10339 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10340 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10342 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10343 goto nla_put_failure
;
10345 nla_nest_end(msg
, attr
);
10347 genlmsg_end(msg
, hdr
);
10349 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10350 nl80211_mlme_mcgrp
.id
, gfp
);
10354 genlmsg_cancel(msg
, hdr
);
10358 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10359 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10361 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10362 struct wiphy
*wiphy
= wdev
->wiphy
;
10363 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10365 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10366 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10368 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10370 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10371 struct net_device
*netdev
,
10372 struct cfg80211_chan_def
*chandef
,
10375 struct sk_buff
*msg
;
10378 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10382 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10388 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10389 goto nla_put_failure
;
10391 if (nl80211_send_chandef(msg
, chandef
))
10392 goto nla_put_failure
;
10394 genlmsg_end(msg
, hdr
);
10396 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10397 nl80211_mlme_mcgrp
.id
, gfp
);
10401 genlmsg_cancel(msg
, hdr
);
10405 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10406 struct cfg80211_chan_def
*chandef
)
10408 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10409 struct wiphy
*wiphy
= wdev
->wiphy
;
10410 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10412 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10416 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10417 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10420 wdev
->channel
= chandef
->chan
;
10421 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10426 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10428 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10429 const u8
*peer
, u32 num_packets
,
10430 u32 rate
, u32 intvl
, gfp_t gfp
)
10432 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10433 struct wiphy
*wiphy
= wdev
->wiphy
;
10434 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10435 struct sk_buff
*msg
;
10436 struct nlattr
*pinfoattr
;
10439 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10443 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10449 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10450 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10451 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10452 goto nla_put_failure
;
10454 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10456 goto nla_put_failure
;
10458 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10459 goto nla_put_failure
;
10461 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10462 goto nla_put_failure
;
10464 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10465 goto nla_put_failure
;
10467 nla_nest_end(msg
, pinfoattr
);
10469 genlmsg_end(msg
, hdr
);
10471 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10472 nl80211_mlme_mcgrp
.id
, gfp
);
10476 genlmsg_cancel(msg
, hdr
);
10479 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10482 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10483 struct cfg80211_chan_def
*chandef
,
10484 enum nl80211_radar_event event
,
10485 struct net_device
*netdev
, gfp_t gfp
)
10487 struct sk_buff
*msg
;
10490 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10494 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10500 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10501 goto nla_put_failure
;
10503 /* NOP and radar events don't need a netdev parameter */
10505 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10507 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10508 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10509 goto nla_put_failure
;
10512 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10513 goto nla_put_failure
;
10515 if (nl80211_send_chandef(msg
, chandef
))
10516 goto nla_put_failure
;
10518 if (genlmsg_end(msg
, hdr
) < 0) {
10523 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10524 nl80211_mlme_mcgrp
.id
, gfp
);
10528 genlmsg_cancel(msg
, hdr
);
10532 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10533 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10535 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10536 struct wiphy
*wiphy
= wdev
->wiphy
;
10537 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10538 struct sk_buff
*msg
;
10539 struct nlattr
*pinfoattr
;
10542 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10544 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10548 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10554 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10555 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10556 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10557 goto nla_put_failure
;
10559 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10561 goto nla_put_failure
;
10563 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10564 goto nla_put_failure
;
10566 nla_nest_end(msg
, pinfoattr
);
10568 genlmsg_end(msg
, hdr
);
10570 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10571 nl80211_mlme_mcgrp
.id
, gfp
);
10575 genlmsg_cancel(msg
, hdr
);
10578 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10580 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10581 u64 cookie
, bool acked
, gfp_t gfp
)
10583 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10584 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10585 struct sk_buff
*msg
;
10589 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10591 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10596 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10602 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10603 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10604 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10605 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10606 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10607 goto nla_put_failure
;
10609 err
= genlmsg_end(msg
, hdr
);
10615 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10616 nl80211_mlme_mcgrp
.id
, gfp
);
10620 genlmsg_cancel(msg
, hdr
);
10623 EXPORT_SYMBOL(cfg80211_probe_status
);
10625 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10626 const u8
*frame
, size_t len
,
10627 int freq
, int sig_dbm
)
10629 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10630 struct sk_buff
*msg
;
10632 struct cfg80211_beacon_registration
*reg
;
10634 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10636 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10637 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10638 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10640 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10644 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10646 goto nla_put_failure
;
10648 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10650 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10652 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10653 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10654 goto nla_put_failure
;
10656 genlmsg_end(msg
, hdr
);
10658 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10660 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10664 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10666 genlmsg_cancel(msg
, hdr
);
10669 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10672 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10673 struct cfg80211_wowlan_wakeup
*wakeup
,
10676 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10677 struct sk_buff
*msg
;
10679 int err
, size
= 200;
10681 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10684 size
+= wakeup
->packet_present_len
;
10686 msg
= nlmsg_new(size
, gfp
);
10690 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10694 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10695 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10698 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10699 wdev
->netdev
->ifindex
))
10703 struct nlattr
*reasons
;
10705 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10707 if (wakeup
->disconnect
&&
10708 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10710 if (wakeup
->magic_pkt
&&
10711 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10713 if (wakeup
->gtk_rekey_failure
&&
10714 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10716 if (wakeup
->eap_identity_req
&&
10717 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10719 if (wakeup
->four_way_handshake
&&
10720 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10722 if (wakeup
->rfkill_release
&&
10723 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10726 if (wakeup
->pattern_idx
>= 0 &&
10727 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10728 wakeup
->pattern_idx
))
10731 if (wakeup
->tcp_match
)
10732 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10734 if (wakeup
->tcp_connlost
)
10736 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10738 if (wakeup
->tcp_nomoretokens
)
10740 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10742 if (wakeup
->packet
) {
10743 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10744 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10746 if (!wakeup
->packet_80211
) {
10748 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10750 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10753 if (wakeup
->packet_len
&&
10754 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10757 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10762 nla_nest_end(msg
, reasons
);
10765 err
= genlmsg_end(msg
, hdr
);
10769 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10770 nl80211_mlme_mcgrp
.id
, gfp
);
10776 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10779 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10780 enum nl80211_tdls_operation oper
,
10781 u16 reason_code
, gfp_t gfp
)
10783 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10784 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10785 struct sk_buff
*msg
;
10789 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10792 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10796 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10802 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10803 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10804 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10805 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10806 (reason_code
> 0 &&
10807 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10808 goto nla_put_failure
;
10810 err
= genlmsg_end(msg
, hdr
);
10816 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10817 nl80211_mlme_mcgrp
.id
, gfp
);
10821 genlmsg_cancel(msg
, hdr
);
10824 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10826 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10827 unsigned long state
,
10830 struct netlink_notify
*notify
= _notify
;
10831 struct cfg80211_registered_device
*rdev
;
10832 struct wireless_dev
*wdev
;
10833 struct cfg80211_beacon_registration
*reg
, *tmp
;
10835 if (state
!= NETLINK_URELEASE
)
10836 return NOTIFY_DONE
;
10840 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10841 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10842 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10844 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10845 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10847 if (reg
->nlportid
== notify
->portid
) {
10848 list_del(®
->list
);
10853 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10858 return NOTIFY_DONE
;
10861 static struct notifier_block nl80211_netlink_notifier
= {
10862 .notifier_call
= nl80211_netlink_notify
,
10865 void cfg80211_ft_event(struct net_device
*netdev
,
10866 struct cfg80211_ft_event_params
*ft_event
)
10868 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10869 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10870 struct sk_buff
*msg
;
10874 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10876 if (!ft_event
->target_ap
)
10879 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10883 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10889 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10890 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10891 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10893 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10894 if (ft_event
->ric_ies
)
10895 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10896 ft_event
->ric_ies
);
10898 err
= genlmsg_end(msg
, hdr
);
10904 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10905 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10907 EXPORT_SYMBOL(cfg80211_ft_event
);
10909 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10911 struct cfg80211_registered_device
*rdev
;
10912 struct sk_buff
*msg
;
10916 rdev
= wiphy_to_dev(wdev
->wiphy
);
10917 if (!rdev
->crit_proto_nlportid
)
10920 nlportid
= rdev
->crit_proto_nlportid
;
10921 rdev
->crit_proto_nlportid
= 0;
10923 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10927 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10929 goto nla_put_failure
;
10931 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10932 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10933 goto nla_put_failure
;
10935 genlmsg_end(msg
, hdr
);
10937 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10942 genlmsg_cancel(msg
, hdr
);
10946 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10948 /* initialisation/exit functions */
10950 int nl80211_init(void)
10954 err
= genl_register_family_with_ops(&nl80211_fam
,
10955 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10959 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10963 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10967 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10971 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10975 #ifdef CONFIG_NL80211_TESTMODE
10976 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10980 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_vendor_mcgrp
);
10985 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10991 genl_unregister_family(&nl80211_fam
);
10995 void nl80211_exit(void)
10997 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10998 genl_unregister_family(&nl80211_fam
);