2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
22 #include <net/inet_connection_sock.h>
28 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
29 struct genl_info
*info
,
30 struct cfg80211_crypto_settings
*settings
,
33 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
34 struct genl_info
*info
);
35 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
38 /* the netlink family */
39 static struct genl_family nl80211_fam
= {
40 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
41 .name
= "nl80211", /* have users key off the name instead */
42 .hdrsize
= 0, /* no private header */
43 .version
= 1, /* no particular meaning now */
44 .maxattr
= NL80211_ATTR_MAX
,
46 .pre_doit
= nl80211_pre_doit
,
47 .post_doit
= nl80211_post_doit
,
50 /* returns ERR_PTR values */
51 static struct wireless_dev
*
52 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
54 struct cfg80211_registered_device
*rdev
;
55 struct wireless_dev
*result
= NULL
;
56 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
57 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
62 assert_cfg80211_lock();
64 if (!have_ifidx
&& !have_wdev_id
)
65 return ERR_PTR(-EINVAL
);
68 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
70 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
71 wiphy_idx
= wdev_id
>> 32;
74 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
75 struct wireless_dev
*wdev
;
77 if (wiphy_net(&rdev
->wiphy
) != netns
)
80 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
83 mutex_lock(&rdev
->devlist_mtx
);
84 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
85 if (have_ifidx
&& wdev
->netdev
&&
86 wdev
->netdev
->ifindex
== ifidx
) {
90 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
95 mutex_unlock(&rdev
->devlist_mtx
);
103 return ERR_PTR(-ENODEV
);
106 static struct cfg80211_registered_device
*
107 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
109 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
110 struct net_device
*netdev
;
112 assert_cfg80211_lock();
114 if (!attrs
[NL80211_ATTR_WIPHY
] &&
115 !attrs
[NL80211_ATTR_IFINDEX
] &&
116 !attrs
[NL80211_ATTR_WDEV
])
117 return ERR_PTR(-EINVAL
);
119 if (attrs
[NL80211_ATTR_WIPHY
])
120 rdev
= cfg80211_rdev_by_wiphy_idx(
121 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
123 if (attrs
[NL80211_ATTR_WDEV
]) {
124 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
125 struct wireless_dev
*wdev
;
128 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
130 /* make sure wdev exists */
131 mutex_lock(&tmp
->devlist_mtx
);
132 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
133 if (wdev
->identifier
!= (u32
)wdev_id
)
138 mutex_unlock(&tmp
->devlist_mtx
);
143 if (rdev
&& tmp
!= rdev
)
144 return ERR_PTR(-EINVAL
);
149 if (attrs
[NL80211_ATTR_IFINDEX
]) {
150 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
151 netdev
= dev_get_by_index(netns
, ifindex
);
153 if (netdev
->ieee80211_ptr
)
155 netdev
->ieee80211_ptr
->wiphy
);
161 /* not wireless device -- return error */
163 return ERR_PTR(-EINVAL
);
165 /* mismatch -- return error */
166 if (rdev
&& tmp
!= rdev
)
167 return ERR_PTR(-EINVAL
);
174 return ERR_PTR(-ENODEV
);
176 if (netns
!= wiphy_net(&rdev
->wiphy
))
177 return ERR_PTR(-ENODEV
);
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
202 static struct cfg80211_registered_device
*
203 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
205 struct cfg80211_registered_device
*rdev
;
207 mutex_lock(&cfg80211_mutex
);
208 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
214 mutex_lock(&rdev
->mtx
);
216 mutex_unlock(&cfg80211_mutex
);
221 /* policy for the attributes */
222 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
223 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
226 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
228 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
235 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
240 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
241 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
242 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
244 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
245 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
247 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
248 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
249 .len
= WLAN_MAX_KEY_LEN
},
250 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
251 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
253 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
254 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
256 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
258 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
259 .len
= IEEE80211_MAX_DATA_LEN
},
260 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
261 .len
= IEEE80211_MAX_DATA_LEN
},
262 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
263 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
264 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
265 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
266 .len
= NL80211_MAX_SUPP_RATES
},
267 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
268 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
269 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
270 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
271 .len
= IEEE80211_MAX_MESH_ID_LEN
},
272 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
274 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
275 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
277 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
280 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
281 .len
= NL80211_MAX_SUPP_RATES
},
282 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
284 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
285 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
287 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
289 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
290 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
291 .len
= IEEE80211_MAX_DATA_LEN
},
292 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
293 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
295 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
296 .len
= IEEE80211_MAX_SSID_LEN
},
297 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
298 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
299 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
302 [NL80211_ATTR_STA_FLAGS2
] = {
303 .len
= sizeof(struct nl80211_sta_flag_update
),
305 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
308 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
309 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
312 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
313 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
314 .len
= WLAN_PMKID_LEN
},
315 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
317 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
318 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
319 .len
= IEEE80211_MAX_DATA_LEN
},
320 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
321 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
323 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
324 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
327 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
328 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
331 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
332 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
333 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
334 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
335 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
336 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
337 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
338 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
339 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
340 .len
= IEEE80211_MAX_DATA_LEN
},
341 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
342 .len
= IEEE80211_MAX_DATA_LEN
},
343 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
345 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
351 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
352 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
353 .len
= IEEE80211_MAX_DATA_LEN
},
354 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
355 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
356 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
357 .len
= NL80211_HT_CAPABILITY_LEN
359 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
360 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
361 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
362 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
363 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
364 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
365 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
366 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
367 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
368 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
369 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
370 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
371 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
372 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
373 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
374 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
375 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
376 .len
= NL80211_VHT_CAPABILITY_LEN
,
378 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
379 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
380 .len
= IEEE80211_MAX_DATA_LEN
},
381 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
382 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
384 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
385 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
386 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
389 /* policy for the key attributes */
390 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
391 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
392 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
393 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
394 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
395 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
396 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
397 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
398 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
401 /* policy for the key default flags */
402 static const struct nla_policy
403 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
404 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
405 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
408 /* policy for WoWLAN attributes */
409 static const struct nla_policy
410 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
411 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
412 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
413 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
414 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
415 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
416 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
417 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
418 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
419 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
422 static const struct nla_policy
423 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
424 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
425 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
426 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
427 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
428 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
430 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
431 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
434 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
436 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
437 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
438 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
441 /* policy for GTK rekey offload attributes */
442 static const struct nla_policy
443 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
444 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
445 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
446 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
449 static const struct nla_policy
450 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
451 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
452 .len
= IEEE80211_MAX_SSID_LEN
},
453 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
456 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
457 struct netlink_callback
*cb
,
458 struct cfg80211_registered_device
**rdev
,
459 struct wireless_dev
**wdev
)
464 mutex_lock(&cfg80211_mutex
);
467 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
468 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
473 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
474 nl80211_fam
.attrbuf
);
476 err
= PTR_ERR(*wdev
);
479 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
480 /* 0 is the first index - add 1 to parse only once */
481 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
482 cb
->args
[1] = (*wdev
)->identifier
;
484 /* subtract the 1 again here */
485 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
486 struct wireless_dev
*tmp
;
492 *rdev
= wiphy_to_dev(wiphy
);
495 mutex_lock(&(*rdev
)->devlist_mtx
);
496 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
497 if (tmp
->identifier
== cb
->args
[1]) {
502 mutex_unlock(&(*rdev
)->devlist_mtx
);
510 cfg80211_lock_rdev(*rdev
);
512 mutex_unlock(&cfg80211_mutex
);
515 mutex_unlock(&cfg80211_mutex
);
520 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
522 cfg80211_unlock_rdev(rdev
);
527 static bool is_valid_ie_attr(const struct nlattr
*attr
)
535 pos
= nla_data(attr
);
556 /* message building helper */
557 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
560 /* since there is no private header just add the generic one */
561 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
564 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
565 struct ieee80211_channel
*chan
,
568 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
570 goto nla_put_failure
;
572 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
573 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
574 goto nla_put_failure
;
575 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
576 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
577 goto nla_put_failure
;
578 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
579 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
580 goto nla_put_failure
;
581 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
582 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
583 goto nla_put_failure
;
587 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
589 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
591 goto nla_put_failure
;
592 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
594 goto nla_put_failure
;
599 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
600 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
601 goto nla_put_failure
;
602 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
603 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
604 goto nla_put_failure
;
605 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
606 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
607 goto nla_put_failure
;
608 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
609 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
610 goto nla_put_failure
;
613 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
614 DBM_TO_MBM(chan
->max_power
)))
615 goto nla_put_failure
;
623 /* netlink command implementations */
630 bool def_uni
, def_multi
;
633 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
635 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
636 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
641 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
642 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
651 if (tb
[NL80211_KEY_IDX
])
652 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
654 if (tb
[NL80211_KEY_DATA
]) {
655 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
656 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
659 if (tb
[NL80211_KEY_SEQ
]) {
660 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
661 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
664 if (tb
[NL80211_KEY_CIPHER
])
665 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
667 if (tb
[NL80211_KEY_TYPE
]) {
668 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
669 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
673 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
674 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
675 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
676 tb
[NL80211_KEY_DEFAULT_TYPES
],
677 nl80211_key_default_policy
);
681 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
682 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
688 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
690 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
691 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
692 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
695 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
696 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
697 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
700 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
701 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
703 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
704 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
706 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
707 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
716 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
717 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
718 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
722 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
723 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
724 int err
= nla_parse_nested(
725 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
726 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
727 nl80211_key_default_policy
);
731 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
732 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
738 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
742 memset(k
, 0, sizeof(*k
));
746 if (info
->attrs
[NL80211_ATTR_KEY
])
747 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
749 err
= nl80211_parse_key_old(info
, k
);
754 if (k
->def
&& k
->defmgmt
)
758 if (k
->def_uni
|| !k
->def_multi
)
764 if (k
->idx
< 4 || k
->idx
> 5)
767 if (k
->idx
< 0 || k
->idx
> 3)
770 if (k
->idx
< 0 || k
->idx
> 5)
778 static struct cfg80211_cached_keys
*
779 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
780 struct nlattr
*keys
, bool *no_ht
)
782 struct key_parse parse
;
784 struct cfg80211_cached_keys
*result
;
785 int rem
, err
, def
= 0;
787 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
789 return ERR_PTR(-ENOMEM
);
792 result
->defmgmt
= -1;
794 nla_for_each_nested(key
, keys
, rem
) {
795 memset(&parse
, 0, sizeof(parse
));
798 err
= nl80211_parse_key_new(key
, &parse
);
804 if (parse
.idx
< 0 || parse
.idx
> 4)
810 result
->def
= parse
.idx
;
811 if (!parse
.def_uni
|| !parse
.def_multi
)
813 } else if (parse
.defmgmt
)
815 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
816 parse
.idx
, false, NULL
);
819 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
820 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
821 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
822 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
824 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
825 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
837 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
839 ASSERT_WDEV_LOCK(wdev
);
841 switch (wdev
->iftype
) {
842 case NL80211_IFTYPE_AP
:
843 case NL80211_IFTYPE_AP_VLAN
:
844 case NL80211_IFTYPE_P2P_GO
:
845 case NL80211_IFTYPE_MESH_POINT
:
847 case NL80211_IFTYPE_ADHOC
:
848 if (!wdev
->current_bss
)
851 case NL80211_IFTYPE_STATION
:
852 case NL80211_IFTYPE_P2P_CLIENT
:
853 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
863 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
865 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
869 goto nla_put_failure
;
873 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
874 goto nla_put_failure
;
879 nla_nest_end(msg
, nl_modes
);
886 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
890 struct nlattr
*nl_combis
;
893 nl_combis
= nla_nest_start(msg
,
894 NL80211_ATTR_INTERFACE_COMBINATIONS
);
896 goto nla_put_failure
;
898 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
899 const struct ieee80211_iface_combination
*c
;
900 struct nlattr
*nl_combi
, *nl_limits
;
902 c
= &wiphy
->iface_combinations
[i
];
904 nl_combi
= nla_nest_start(msg
, i
+ 1);
906 goto nla_put_failure
;
908 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
910 goto nla_put_failure
;
912 for (j
= 0; j
< c
->n_limits
; j
++) {
913 struct nlattr
*nl_limit
;
915 nl_limit
= nla_nest_start(msg
, j
+ 1);
917 goto nla_put_failure
;
918 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
920 goto nla_put_failure
;
921 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
923 goto nla_put_failure
;
924 nla_nest_end(msg
, nl_limit
);
927 nla_nest_end(msg
, nl_limits
);
929 if (c
->beacon_int_infra_match
&&
930 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
931 goto nla_put_failure
;
932 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
933 c
->num_different_channels
) ||
934 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
936 goto nla_put_failure
;
938 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
939 c
->radar_detect_widths
))
940 goto nla_put_failure
;
942 nla_nest_end(msg
, nl_combi
);
945 nla_nest_end(msg
, nl_combis
);
953 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
956 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
.tcp
;
957 struct nlattr
*nl_tcp
;
962 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
966 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
967 tcp
->data_payload_max
))
970 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
971 tcp
->data_payload_max
))
974 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
977 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
978 sizeof(*tcp
->tok
), tcp
->tok
))
981 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
982 tcp
->data_interval_max
))
985 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
986 tcp
->wake_payload_max
))
989 nla_nest_end(msg
, nl_tcp
);
993 static int nl80211_send_wowlan(struct sk_buff
*msg
,
994 struct cfg80211_registered_device
*dev
,
997 struct nlattr
*nl_wowlan
;
999 if (!dev
->wiphy
.wowlan
.flags
&& !dev
->wiphy
.wowlan
.n_patterns
)
1002 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1006 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1007 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1008 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1009 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1010 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1011 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1012 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1013 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1014 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1015 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1016 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1017 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1018 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1019 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1020 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1021 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1024 if (dev
->wiphy
.wowlan
.n_patterns
) {
1025 struct nl80211_wowlan_pattern_support pat
= {
1026 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1027 .min_pattern_len
= dev
->wiphy
.wowlan
.pattern_min_len
,
1028 .max_pattern_len
= dev
->wiphy
.wowlan
.pattern_max_len
,
1029 .max_pkt_offset
= dev
->wiphy
.wowlan
.max_pkt_offset
,
1032 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1037 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
1040 nla_nest_end(msg
, nl_wowlan
);
1046 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1047 struct ieee80211_supported_band
*sband
)
1049 struct nlattr
*nl_rates
, *nl_rate
;
1050 struct ieee80211_rate
*rate
;
1054 if (sband
->ht_cap
.ht_supported
&&
1055 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1056 sizeof(sband
->ht_cap
.mcs
),
1057 &sband
->ht_cap
.mcs
) ||
1058 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1059 sband
->ht_cap
.cap
) ||
1060 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1061 sband
->ht_cap
.ampdu_factor
) ||
1062 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1063 sband
->ht_cap
.ampdu_density
)))
1067 if (sband
->vht_cap
.vht_supported
&&
1068 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1069 sizeof(sband
->vht_cap
.vht_mcs
),
1070 &sband
->vht_cap
.vht_mcs
) ||
1071 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1072 sband
->vht_cap
.cap
)))
1076 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1080 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1081 nl_rate
= nla_nest_start(msg
, i
);
1085 rate
= &sband
->bitrates
[i
];
1086 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1089 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1091 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1094 nla_nest_end(msg
, nl_rate
);
1097 nla_nest_end(msg
, nl_rates
);
1103 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1104 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1107 struct nlattr
*nl_ftypes
, *nl_ifs
;
1108 enum nl80211_iftype ift
;
1114 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1118 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1119 nl_ftypes
= nla_nest_start(msg
, ift
);
1123 stypes
= mgmt_stypes
[ift
].tx
;
1126 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1127 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1132 nla_nest_end(msg
, nl_ftypes
);
1135 nla_nest_end(msg
, nl_ifs
);
1137 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1141 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1142 nl_ftypes
= nla_nest_start(msg
, ift
);
1146 stypes
= mgmt_stypes
[ift
].rx
;
1149 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1150 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1155 nla_nest_end(msg
, nl_ftypes
);
1157 nla_nest_end(msg
, nl_ifs
);
1162 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1163 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1164 int flags
, bool split
, long *split_start
,
1165 long *band_start
, long *chan_start
)
1168 struct nlattr
*nl_bands
, *nl_band
;
1169 struct nlattr
*nl_freqs
, *nl_freq
;
1170 struct nlattr
*nl_cmds
;
1171 enum ieee80211_band band
;
1172 struct ieee80211_channel
*chan
;
1174 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1175 dev
->wiphy
.mgmt_stypes
;
1176 long start
= 0, start_chan
= 0, start_band
= 0;
1179 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1183 /* allow always using the variables */
1185 split_start
= &start
;
1186 band_start
= &start_band
;
1187 chan_start
= &start_chan
;
1190 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1191 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1192 wiphy_name(&dev
->wiphy
)) ||
1193 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1194 cfg80211_rdev_list_generation
))
1195 goto nla_put_failure
;
1197 switch (*split_start
) {
1199 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1200 dev
->wiphy
.retry_short
) ||
1201 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1202 dev
->wiphy
.retry_long
) ||
1203 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1204 dev
->wiphy
.frag_threshold
) ||
1205 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1206 dev
->wiphy
.rts_threshold
) ||
1207 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1208 dev
->wiphy
.coverage_class
) ||
1209 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1210 dev
->wiphy
.max_scan_ssids
) ||
1211 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1212 dev
->wiphy
.max_sched_scan_ssids
) ||
1213 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1214 dev
->wiphy
.max_scan_ie_len
) ||
1215 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1216 dev
->wiphy
.max_sched_scan_ie_len
) ||
1217 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1218 dev
->wiphy
.max_match_sets
))
1219 goto nla_put_failure
;
1221 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1222 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1223 goto nla_put_failure
;
1224 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1225 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1226 goto nla_put_failure
;
1227 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1228 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1229 goto nla_put_failure
;
1230 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1231 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1232 goto nla_put_failure
;
1233 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1234 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1235 goto nla_put_failure
;
1236 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1237 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1238 goto nla_put_failure
;
1244 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1245 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1246 dev
->wiphy
.cipher_suites
))
1247 goto nla_put_failure
;
1249 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1250 dev
->wiphy
.max_num_pmkids
))
1251 goto nla_put_failure
;
1253 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1254 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1255 goto nla_put_failure
;
1257 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1258 dev
->wiphy
.available_antennas_tx
) ||
1259 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1260 dev
->wiphy
.available_antennas_rx
))
1261 goto nla_put_failure
;
1263 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1264 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1265 dev
->wiphy
.probe_resp_offload
))
1266 goto nla_put_failure
;
1268 if ((dev
->wiphy
.available_antennas_tx
||
1269 dev
->wiphy
.available_antennas_rx
) &&
1270 dev
->ops
->get_antenna
) {
1271 u32 tx_ant
= 0, rx_ant
= 0;
1273 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1275 if (nla_put_u32(msg
,
1276 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1279 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1281 goto nla_put_failure
;
1289 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1290 dev
->wiphy
.interface_modes
))
1291 goto nla_put_failure
;
1296 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1298 goto nla_put_failure
;
1300 for (band
= *band_start
; band
< IEEE80211_NUM_BANDS
; band
++) {
1301 struct ieee80211_supported_band
*sband
;
1303 sband
= dev
->wiphy
.bands
[band
];
1308 nl_band
= nla_nest_start(msg
, band
);
1310 goto nla_put_failure
;
1312 switch (*chan_start
) {
1314 if (nl80211_send_band_rateinfo(msg
, sband
))
1315 goto nla_put_failure
;
1320 /* add frequencies */
1321 nl_freqs
= nla_nest_start(
1322 msg
, NL80211_BAND_ATTR_FREQS
);
1324 goto nla_put_failure
;
1326 for (i
= *chan_start
- 1;
1327 i
< sband
->n_channels
;
1329 nl_freq
= nla_nest_start(msg
, i
);
1331 goto nla_put_failure
;
1333 chan
= &sband
->channels
[i
];
1335 if (nl80211_msg_put_channel(msg
, chan
,
1337 goto nla_put_failure
;
1339 nla_nest_end(msg
, nl_freq
);
1343 if (i
< sband
->n_channels
)
1344 *chan_start
= i
+ 2;
1347 nla_nest_end(msg
, nl_freqs
);
1350 nla_nest_end(msg
, nl_band
);
1353 /* start again here */
1359 nla_nest_end(msg
, nl_bands
);
1361 if (band
< IEEE80211_NUM_BANDS
)
1362 *band_start
= band
+ 1;
1366 /* if bands & channels are done, continue outside */
1367 if (*band_start
== 0 && *chan_start
== 0)
1372 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1374 goto nla_put_failure
;
1377 #define CMD(op, n) \
1379 if (dev->ops->op) { \
1381 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1382 goto nla_put_failure; \
1386 CMD(add_virtual_intf
, NEW_INTERFACE
);
1387 CMD(change_virtual_intf
, SET_INTERFACE
);
1388 CMD(add_key
, NEW_KEY
);
1389 CMD(start_ap
, START_AP
);
1390 CMD(add_station
, NEW_STATION
);
1391 CMD(add_mpath
, NEW_MPATH
);
1392 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1393 CMD(change_bss
, SET_BSS
);
1394 CMD(auth
, AUTHENTICATE
);
1395 CMD(assoc
, ASSOCIATE
);
1396 CMD(deauth
, DEAUTHENTICATE
);
1397 CMD(disassoc
, DISASSOCIATE
);
1398 CMD(join_ibss
, JOIN_IBSS
);
1399 CMD(join_mesh
, JOIN_MESH
);
1400 CMD(set_pmksa
, SET_PMKSA
);
1401 CMD(del_pmksa
, DEL_PMKSA
);
1402 CMD(flush_pmksa
, FLUSH_PMKSA
);
1403 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1404 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1405 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1406 CMD(mgmt_tx
, FRAME
);
1407 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1408 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1410 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1411 goto nla_put_failure
;
1413 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1414 dev
->ops
->join_mesh
) {
1416 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1417 goto nla_put_failure
;
1419 CMD(set_wds_peer
, SET_WDS_PEER
);
1420 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1421 CMD(tdls_mgmt
, TDLS_MGMT
);
1422 CMD(tdls_oper
, TDLS_OPER
);
1424 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1425 CMD(sched_scan_start
, START_SCHED_SCAN
);
1426 CMD(probe_client
, PROBE_CLIENT
);
1427 CMD(set_noack_map
, SET_NOACK_MAP
);
1428 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1430 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1431 goto nla_put_failure
;
1433 CMD(start_p2p_device
, START_P2P_DEVICE
);
1434 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1436 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1437 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1440 #ifdef CONFIG_NL80211_TESTMODE
1441 CMD(testmode_cmd
, TESTMODE
);
1446 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1448 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1449 goto nla_put_failure
;
1452 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1454 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1455 goto nla_put_failure
;
1458 nla_nest_end(msg
, nl_cmds
);
1463 if (dev
->ops
->remain_on_channel
&&
1464 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1466 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1467 dev
->wiphy
.max_remain_on_channel_duration
))
1468 goto nla_put_failure
;
1470 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1471 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1472 goto nla_put_failure
;
1474 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1475 goto nla_put_failure
;
1481 if (nl80211_send_wowlan(msg
, dev
, split
))
1482 goto nla_put_failure
;
1490 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1491 dev
->wiphy
.software_iftypes
))
1492 goto nla_put_failure
;
1494 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
, split
))
1495 goto nla_put_failure
;
1501 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1502 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1503 dev
->wiphy
.ap_sme_capa
))
1504 goto nla_put_failure
;
1506 features
= dev
->wiphy
.features
;
1508 * We can only add the per-channel limit information if the
1509 * dump is split, otherwise it makes it too big. Therefore
1510 * only advertise it in that case.
1513 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1514 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1515 goto nla_put_failure
;
1517 if (dev
->wiphy
.ht_capa_mod_mask
&&
1518 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1519 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1520 dev
->wiphy
.ht_capa_mod_mask
))
1521 goto nla_put_failure
;
1523 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1524 dev
->wiphy
.max_acl_mac_addrs
&&
1525 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1526 dev
->wiphy
.max_acl_mac_addrs
))
1527 goto nla_put_failure
;
1529 if (dev
->wiphy
.n_vendor_commands
) {
1530 const struct nl80211_vendor_cmd_info
*info
;
1531 struct nlattr
*nested
;
1533 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1535 goto nla_put_failure
;
1537 for (i
= 0; i
< dev
->wiphy
.n_vendor_commands
; i
++) {
1538 info
= &dev
->wiphy
.vendor_commands
[i
].info
;
1539 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1540 goto nla_put_failure
;
1542 nla_nest_end(msg
, nested
);
1545 if (dev
->wiphy
.n_vendor_events
) {
1546 const struct nl80211_vendor_cmd_info
*info
;
1547 struct nlattr
*nested
;
1549 nested
= nla_nest_start(msg
,
1550 NL80211_ATTR_VENDOR_EVENTS
);
1552 goto nla_put_failure
;
1554 for (i
= 0; i
< dev
->wiphy
.n_vendor_events
; i
++) {
1555 info
= &dev
->wiphy
.vendor_events
[i
];
1556 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1557 goto nla_put_failure
;
1559 nla_nest_end(msg
, nested
);
1563 * Any information below this point is only available to
1564 * applications that can deal with it being split. This
1565 * helps ensure that newly added capabilities don't break
1566 * older tools by overrunning their buffers.
1568 * We still increment split_start so that in the split
1569 * case we'll continue with more data in the next round,
1570 * but break unconditionally so unsplit data stops here.
1575 if (dev
->wiphy
.extended_capabilities
&&
1576 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1577 dev
->wiphy
.extended_capabilities_len
,
1578 dev
->wiphy
.extended_capabilities
) ||
1579 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1580 dev
->wiphy
.extended_capabilities_len
,
1581 dev
->wiphy
.extended_capabilities_mask
)))
1582 goto nla_put_failure
;
1584 if (dev
->wiphy
.vht_capa_mod_mask
&&
1585 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1586 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1587 dev
->wiphy
.vht_capa_mod_mask
))
1588 goto nla_put_failure
;
1594 return genlmsg_end(msg
, hdr
);
1597 genlmsg_cancel(msg
, hdr
);
1601 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1604 int start
= cb
->args
[0];
1605 struct cfg80211_registered_device
*dev
;
1606 s64 filter_wiphy
= -1;
1611 /* will be zeroed in nlmsg_parse() */
1612 tb
= kmalloc(sizeof(*tb
) * (NL80211_ATTR_MAX
+ 1), GFP_KERNEL
);
1616 mutex_lock(&cfg80211_mutex
);
1617 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1618 tb
, NL80211_ATTR_MAX
, nl80211_policy
);
1620 split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1621 if (tb
[NL80211_ATTR_WIPHY
])
1622 filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1623 if (tb
[NL80211_ATTR_WDEV
])
1624 filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1625 if (tb
[NL80211_ATTR_IFINDEX
]) {
1626 struct net_device
*netdev
;
1627 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1629 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1631 mutex_unlock(&cfg80211_mutex
);
1635 if (netdev
->ieee80211_ptr
) {
1637 netdev
->ieee80211_ptr
->wiphy
);
1638 filter_wiphy
= dev
->wiphy_idx
;
1645 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1646 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1650 if (filter_wiphy
!= -1 && dev
->wiphy_idx
!= filter_wiphy
)
1652 /* attempt to fit multiple wiphy data chunks into the skb */
1654 ret
= nl80211_send_wiphy(dev
, skb
,
1655 NETLINK_CB(cb
->skb
).portid
,
1658 split
, &cb
->args
[1],
1663 * If sending the wiphy data didn't fit (ENOBUFS
1664 * or EMSGSIZE returned), this SKB is still
1665 * empty (so it's not too big because another
1666 * wiphy dataset is already in the skb) and
1667 * we've not tried to adjust the dump allocation
1668 * yet ... then adjust the alloc size to be
1669 * bigger, and return 1 but with the empty skb.
1670 * This results in an empty message being RX'ed
1671 * in userspace, but that is ignored.
1673 * We can then retry with the larger buffer.
1675 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1677 cb
->min_dump_alloc
< 4096) {
1678 cb
->min_dump_alloc
= 4096;
1679 mutex_unlock(&cfg80211_mutex
);
1685 } while (cb
->args
[1] > 0);
1688 mutex_unlock(&cfg80211_mutex
);
1695 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1697 struct sk_buff
*msg
;
1698 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1700 msg
= nlmsg_new(4096, GFP_KERNEL
);
1704 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1705 false, NULL
, NULL
, NULL
) < 0) {
1710 return genlmsg_reply(msg
, info
);
1713 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1714 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1715 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1716 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1717 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1718 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1721 static int parse_txq_params(struct nlattr
*tb
[],
1722 struct ieee80211_txq_params
*txq_params
)
1724 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1725 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1726 !tb
[NL80211_TXQ_ATTR_AIFS
])
1729 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1730 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1731 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1732 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1733 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1735 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1741 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1744 * You can only set the channel explicitly for WDS interfaces,
1745 * all others have their channel managed via their respective
1746 * "establish a connection" command (connect, join, ...)
1748 * For AP/GO and mesh mode, the channel can be set with the
1749 * channel userspace API, but is only stored and passed to the
1750 * low-level driver when the AP starts or the mesh is joined.
1751 * This is for backward compatibility, userspace can also give
1752 * the channel in the start-ap or join-mesh commands instead.
1754 * Monitors are special as they are normally slaved to
1755 * whatever else is going on, so they have their own special
1756 * operation to set the monitor channel if possible.
1759 wdev
->iftype
== NL80211_IFTYPE_AP
||
1760 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1761 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1762 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1765 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1766 struct genl_info
*info
,
1767 struct cfg80211_chan_def
*chandef
)
1771 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1774 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1776 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1777 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1778 chandef
->center_freq1
= control_freq
;
1779 chandef
->center_freq2
= 0;
1781 /* Primary channel not allowed */
1782 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1785 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1786 enum nl80211_channel_type chantype
;
1788 chantype
= nla_get_u32(
1789 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1792 case NL80211_CHAN_NO_HT
:
1793 case NL80211_CHAN_HT20
:
1794 case NL80211_CHAN_HT40PLUS
:
1795 case NL80211_CHAN_HT40MINUS
:
1796 cfg80211_chandef_create(chandef
, chandef
->chan
,
1802 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1804 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1805 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1806 chandef
->center_freq1
=
1808 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1809 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1810 chandef
->center_freq2
=
1812 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1815 if (!cfg80211_chandef_valid(chandef
))
1818 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1819 IEEE80211_CHAN_DISABLED
))
1825 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1826 struct wireless_dev
*wdev
,
1827 struct genl_info
*info
)
1829 struct cfg80211_chan_def chandef
;
1831 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1834 iftype
= wdev
->iftype
;
1836 if (!nl80211_can_set_dev_channel(wdev
))
1839 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1843 mutex_lock(&rdev
->devlist_mtx
);
1845 case NL80211_IFTYPE_AP
:
1846 case NL80211_IFTYPE_P2P_GO
:
1847 if (wdev
->beacon_interval
) {
1851 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1855 wdev
->preset_chandef
= chandef
;
1858 case NL80211_IFTYPE_MESH_POINT
:
1859 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1861 case NL80211_IFTYPE_MONITOR
:
1862 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1867 mutex_unlock(&rdev
->devlist_mtx
);
1872 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1875 struct net_device
*netdev
= info
->user_ptr
[1];
1877 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1880 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1882 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1883 struct net_device
*dev
= info
->user_ptr
[1];
1884 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1887 if (!info
->attrs
[NL80211_ATTR_MAC
])
1890 if (netif_running(dev
))
1893 if (!rdev
->ops
->set_wds_peer
)
1896 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1899 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1900 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1904 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1906 struct cfg80211_registered_device
*rdev
;
1907 struct net_device
*netdev
= NULL
;
1908 struct wireless_dev
*wdev
;
1909 int result
= 0, rem_txq_params
= 0;
1910 struct nlattr
*nl_txq_params
;
1912 u8 retry_short
= 0, retry_long
= 0;
1913 u32 frag_threshold
= 0, rts_threshold
= 0;
1914 u8 coverage_class
= 0;
1917 * Try to find the wiphy and netdev. Normally this
1918 * function shouldn't need the netdev, but this is
1919 * done for backward compatibility -- previously
1920 * setting the channel was done per wiphy, but now
1921 * it is per netdev. Previous userland like hostapd
1922 * also passed a netdev to set_wiphy, so that it is
1923 * possible to let that go to the right netdev!
1925 mutex_lock(&cfg80211_mutex
);
1927 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1928 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1930 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1931 if (netdev
&& netdev
->ieee80211_ptr
) {
1932 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1933 mutex_lock(&rdev
->mtx
);
1939 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1942 mutex_unlock(&cfg80211_mutex
);
1943 return PTR_ERR(rdev
);
1949 mutex_lock(&rdev
->mtx
);
1951 wdev
= netdev
->ieee80211_ptr
;
1954 * end workaround code, by now the rdev is available
1955 * and locked, and wdev may or may not be NULL.
1958 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1959 result
= cfg80211_dev_rename(
1960 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1962 mutex_unlock(&cfg80211_mutex
);
1967 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1968 struct ieee80211_txq_params txq_params
;
1969 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1971 if (!rdev
->ops
->set_txq_params
) {
1972 result
= -EOPNOTSUPP
;
1981 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1982 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1987 if (!netif_running(netdev
)) {
1992 nla_for_each_nested(nl_txq_params
,
1993 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1995 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1996 nla_data(nl_txq_params
),
1997 nla_len(nl_txq_params
),
1999 result
= parse_txq_params(tb
, &txq_params
);
2003 result
= rdev_set_txq_params(rdev
, netdev
,
2010 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2011 result
= __nl80211_set_channel(rdev
,
2012 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
2018 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2019 struct wireless_dev
*txp_wdev
= wdev
;
2020 enum nl80211_tx_power_setting type
;
2023 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2026 if (!rdev
->ops
->set_tx_power
) {
2027 result
= -EOPNOTSUPP
;
2031 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2032 type
= nla_get_u32(info
->attrs
[idx
]);
2034 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2035 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
2040 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2041 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2042 mbm
= nla_get_u32(info
->attrs
[idx
]);
2045 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2050 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2051 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2053 if ((!rdev
->wiphy
.available_antennas_tx
&&
2054 !rdev
->wiphy
.available_antennas_rx
) ||
2055 !rdev
->ops
->set_antenna
) {
2056 result
= -EOPNOTSUPP
;
2060 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2061 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2063 /* reject antenna configurations which don't match the
2064 * available antenna masks, except for the "all" mask */
2065 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2066 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2071 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2072 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2074 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2081 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2082 retry_short
= nla_get_u8(
2083 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2084 if (retry_short
== 0) {
2088 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2091 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2092 retry_long
= nla_get_u8(
2093 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2094 if (retry_long
== 0) {
2098 changed
|= WIPHY_PARAM_RETRY_LONG
;
2101 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2102 frag_threshold
= nla_get_u32(
2103 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2104 if (frag_threshold
< 256) {
2108 if (frag_threshold
!= (u32
) -1) {
2110 * Fragments (apart from the last one) are required to
2111 * have even length. Make the fragmentation code
2112 * simpler by stripping LSB should someone try to use
2113 * odd threshold value.
2115 frag_threshold
&= ~0x1;
2117 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2120 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2121 rts_threshold
= nla_get_u32(
2122 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2123 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2126 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2127 coverage_class
= nla_get_u8(
2128 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2129 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2133 u8 old_retry_short
, old_retry_long
;
2134 u32 old_frag_threshold
, old_rts_threshold
;
2135 u8 old_coverage_class
;
2137 if (!rdev
->ops
->set_wiphy_params
) {
2138 result
= -EOPNOTSUPP
;
2142 old_retry_short
= rdev
->wiphy
.retry_short
;
2143 old_retry_long
= rdev
->wiphy
.retry_long
;
2144 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2145 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2146 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2148 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2149 rdev
->wiphy
.retry_short
= retry_short
;
2150 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2151 rdev
->wiphy
.retry_long
= retry_long
;
2152 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2153 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2154 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2155 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2156 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2157 rdev
->wiphy
.coverage_class
= coverage_class
;
2159 result
= rdev_set_wiphy_params(rdev
, changed
);
2161 rdev
->wiphy
.retry_short
= old_retry_short
;
2162 rdev
->wiphy
.retry_long
= old_retry_long
;
2163 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2164 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2165 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2170 mutex_unlock(&rdev
->mtx
);
2176 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2178 return (u64
)wdev
->identifier
|
2179 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2182 static int nl80211_send_chandef(struct sk_buff
*msg
,
2183 struct cfg80211_chan_def
*chandef
)
2185 WARN_ON(!cfg80211_chandef_valid(chandef
));
2187 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2188 chandef
->chan
->center_freq
))
2190 switch (chandef
->width
) {
2191 case NL80211_CHAN_WIDTH_20_NOHT
:
2192 case NL80211_CHAN_WIDTH_20
:
2193 case NL80211_CHAN_WIDTH_40
:
2194 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2195 cfg80211_get_chandef_type(chandef
)))
2201 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2203 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2205 if (chandef
->center_freq2
&&
2206 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2211 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2212 struct cfg80211_registered_device
*rdev
,
2213 struct wireless_dev
*wdev
)
2215 struct net_device
*dev
= wdev
->netdev
;
2218 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2223 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2224 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2225 goto nla_put_failure
;
2227 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2228 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2229 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2230 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2231 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2232 rdev
->devlist_generation
^
2233 (cfg80211_rdev_list_generation
<< 2)))
2234 goto nla_put_failure
;
2236 if (rdev
->ops
->get_channel
) {
2238 struct cfg80211_chan_def chandef
;
2240 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2242 if (nl80211_send_chandef(msg
, &chandef
))
2243 goto nla_put_failure
;
2247 if (wdev
->ssid_len
) {
2248 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2249 goto nla_put_failure
;
2252 return genlmsg_end(msg
, hdr
);
2255 genlmsg_cancel(msg
, hdr
);
2259 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2263 int wp_start
= cb
->args
[0];
2264 int if_start
= cb
->args
[1];
2265 struct cfg80211_registered_device
*rdev
;
2266 struct wireless_dev
*wdev
;
2268 mutex_lock(&cfg80211_mutex
);
2269 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2270 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2272 if (wp_idx
< wp_start
) {
2278 mutex_lock(&rdev
->devlist_mtx
);
2279 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2280 if (if_idx
< if_start
) {
2284 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2285 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2287 mutex_unlock(&rdev
->devlist_mtx
);
2292 mutex_unlock(&rdev
->devlist_mtx
);
2297 mutex_unlock(&cfg80211_mutex
);
2299 cb
->args
[0] = wp_idx
;
2300 cb
->args
[1] = if_idx
;
2305 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2307 struct sk_buff
*msg
;
2308 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2309 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2311 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2315 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2321 return genlmsg_reply(msg
, info
);
2324 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2325 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2326 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2327 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2328 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2329 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2332 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2334 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2342 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2343 nla
, mntr_flags_policy
))
2346 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2348 *mntrflags
|= (1<<flag
);
2353 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2354 struct net_device
*netdev
, u8 use_4addr
,
2355 enum nl80211_iftype iftype
)
2358 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2364 case NL80211_IFTYPE_AP_VLAN
:
2365 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2368 case NL80211_IFTYPE_STATION
:
2369 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2379 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2381 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2382 struct vif_params params
;
2384 enum nl80211_iftype otype
, ntype
;
2385 struct net_device
*dev
= info
->user_ptr
[1];
2386 u32 _flags
, *flags
= NULL
;
2387 bool change
= false;
2389 memset(¶ms
, 0, sizeof(params
));
2391 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2393 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2394 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2397 if (ntype
> NL80211_IFTYPE_MAX
)
2401 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2402 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2404 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2406 if (netif_running(dev
))
2410 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2411 IEEE80211_MAX_MESH_ID_LEN
);
2412 wdev
->mesh_id_up_len
=
2413 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2414 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2415 wdev
->mesh_id_up_len
);
2419 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2420 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2422 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2426 params
.use_4addr
= -1;
2429 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2430 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2432 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2442 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2446 if (!err
&& params
.use_4addr
!= -1)
2447 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2452 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2454 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2455 struct vif_params params
;
2456 struct wireless_dev
*wdev
;
2457 struct sk_buff
*msg
;
2459 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2462 memset(¶ms
, 0, sizeof(params
));
2464 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2467 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2468 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2469 if (type
> NL80211_IFTYPE_MAX
)
2473 if (!rdev
->ops
->add_virtual_intf
||
2474 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2477 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2478 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2480 if (!is_valid_ether_addr(params
.macaddr
))
2481 return -EADDRNOTAVAIL
;
2484 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2485 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2486 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2491 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2495 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2496 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2498 wdev
= rdev_add_virtual_intf(rdev
,
2499 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2500 type
, err
? NULL
: &flags
, ¶ms
);
2503 return PTR_ERR(wdev
);
2507 case NL80211_IFTYPE_MESH_POINT
:
2508 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2511 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2512 IEEE80211_MAX_MESH_ID_LEN
);
2513 wdev
->mesh_id_up_len
=
2514 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2515 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2516 wdev
->mesh_id_up_len
);
2519 case NL80211_IFTYPE_P2P_DEVICE
:
2521 * P2P Device doesn't have a netdev, so doesn't go
2522 * through the netdev notifier and must be added here
2524 mutex_init(&wdev
->mtx
);
2525 INIT_LIST_HEAD(&wdev
->event_list
);
2526 spin_lock_init(&wdev
->event_lock
);
2527 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2528 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2530 mutex_lock(&rdev
->devlist_mtx
);
2531 wdev
->identifier
= ++rdev
->wdev_id
;
2532 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2533 rdev
->devlist_generation
++;
2534 mutex_unlock(&rdev
->devlist_mtx
);
2540 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2546 return genlmsg_reply(msg
, info
);
2549 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2551 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2552 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2554 if (!rdev
->ops
->del_virtual_intf
)
2558 * If we remove a wireless device without a netdev then clear
2559 * user_ptr[1] so that nl80211_post_doit won't dereference it
2560 * to check if it needs to do dev_put(). Otherwise it crashes
2561 * since the wdev has been freed, unlike with a netdev where
2562 * we need the dev_put() for the netdev to really be freed.
2565 info
->user_ptr
[1] = NULL
;
2567 return rdev_del_virtual_intf(rdev
, wdev
);
2570 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2572 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2573 struct net_device
*dev
= info
->user_ptr
[1];
2576 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2579 if (!rdev
->ops
->set_noack_map
)
2582 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2584 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2587 struct get_key_cookie
{
2588 struct sk_buff
*msg
;
2593 static void get_key_callback(void *c
, struct key_params
*params
)
2596 struct get_key_cookie
*cookie
= c
;
2599 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2600 params
->key_len
, params
->key
)) ||
2602 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2603 params
->seq_len
, params
->seq
)) ||
2605 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2607 goto nla_put_failure
;
2609 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2611 goto nla_put_failure
;
2614 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2615 params
->key_len
, params
->key
)) ||
2617 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2618 params
->seq_len
, params
->seq
)) ||
2620 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2622 goto nla_put_failure
;
2624 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2625 goto nla_put_failure
;
2627 nla_nest_end(cookie
->msg
, key
);
2634 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2638 struct net_device
*dev
= info
->user_ptr
[1];
2640 const u8
*mac_addr
= NULL
;
2642 struct get_key_cookie cookie
= {
2646 struct sk_buff
*msg
;
2648 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2649 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2654 if (info
->attrs
[NL80211_ATTR_MAC
])
2655 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2657 pairwise
= !!mac_addr
;
2658 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2659 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2660 if (kt
>= NUM_NL80211_KEYTYPES
)
2662 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2663 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2665 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2668 if (!rdev
->ops
->get_key
)
2671 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2675 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2676 NL80211_CMD_NEW_KEY
);
2678 goto nla_put_failure
;
2681 cookie
.idx
= key_idx
;
2683 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2684 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2685 goto nla_put_failure
;
2687 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2688 goto nla_put_failure
;
2690 if (pairwise
&& mac_addr
&&
2691 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2694 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2701 goto nla_put_failure
;
2703 genlmsg_end(msg
, hdr
);
2704 return genlmsg_reply(msg
, info
);
2713 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2715 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2716 struct key_parse key
;
2718 struct net_device
*dev
= info
->user_ptr
[1];
2720 err
= nl80211_parse_key(info
, &key
);
2727 /* only support setting default key */
2728 if (!key
.def
&& !key
.defmgmt
)
2731 wdev_lock(dev
->ieee80211_ptr
);
2734 if (!rdev
->ops
->set_default_key
) {
2739 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2743 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2744 key
.def_uni
, key
.def_multi
);
2749 #ifdef CONFIG_CFG80211_WEXT
2750 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2753 if (key
.def_uni
|| !key
.def_multi
) {
2758 if (!rdev
->ops
->set_default_mgmt_key
) {
2763 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2767 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2771 #ifdef CONFIG_CFG80211_WEXT
2772 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2777 wdev_unlock(dev
->ieee80211_ptr
);
2782 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2784 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2786 struct net_device
*dev
= info
->user_ptr
[1];
2787 struct key_parse key
;
2788 const u8
*mac_addr
= NULL
;
2790 err
= nl80211_parse_key(info
, &key
);
2797 if (info
->attrs
[NL80211_ATTR_MAC
])
2798 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2800 if (key
.type
== -1) {
2802 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2804 key
.type
= NL80211_KEYTYPE_GROUP
;
2808 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2809 key
.type
!= NL80211_KEYTYPE_GROUP
)
2812 if (!rdev
->ops
->add_key
)
2815 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2816 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2820 wdev_lock(dev
->ieee80211_ptr
);
2821 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2823 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2824 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2826 wdev_unlock(dev
->ieee80211_ptr
);
2831 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2833 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2835 struct net_device
*dev
= info
->user_ptr
[1];
2836 u8
*mac_addr
= NULL
;
2837 struct key_parse key
;
2839 err
= nl80211_parse_key(info
, &key
);
2843 if (info
->attrs
[NL80211_ATTR_MAC
])
2844 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2846 if (key
.type
== -1) {
2848 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2850 key
.type
= NL80211_KEYTYPE_GROUP
;
2854 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2855 key
.type
!= NL80211_KEYTYPE_GROUP
)
2858 if (!rdev
->ops
->del_key
)
2861 wdev_lock(dev
->ieee80211_ptr
);
2862 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2864 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2865 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2869 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2870 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2873 #ifdef CONFIG_CFG80211_WEXT
2875 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2876 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2877 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2878 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2881 wdev_unlock(dev
->ieee80211_ptr
);
2886 /* This function returns an error or the number of nested attributes */
2887 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2889 struct nlattr
*attr
;
2890 int n_entries
= 0, tmp
;
2892 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2893 if (nla_len(attr
) != ETH_ALEN
)
2903 * This function parses ACL information and allocates memory for ACL data.
2904 * On successful return, the calling function is responsible to free the
2905 * ACL buffer returned by this function.
2907 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2908 struct genl_info
*info
)
2910 enum nl80211_acl_policy acl_policy
;
2911 struct nlattr
*attr
;
2912 struct cfg80211_acl_data
*acl
;
2913 int i
= 0, n_entries
, tmp
;
2915 if (!wiphy
->max_acl_mac_addrs
)
2916 return ERR_PTR(-EOPNOTSUPP
);
2918 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2919 return ERR_PTR(-EINVAL
);
2921 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2922 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2923 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2924 return ERR_PTR(-EINVAL
);
2926 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2927 return ERR_PTR(-EINVAL
);
2929 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2931 return ERR_PTR(n_entries
);
2933 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2934 return ERR_PTR(-ENOTSUPP
);
2936 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2939 return ERR_PTR(-ENOMEM
);
2941 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2942 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2946 acl
->n_acl_entries
= n_entries
;
2947 acl
->acl_policy
= acl_policy
;
2952 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2954 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2955 struct net_device
*dev
= info
->user_ptr
[1];
2956 struct cfg80211_acl_data
*acl
;
2959 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2960 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2963 if (!dev
->ieee80211_ptr
->beacon_interval
)
2966 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2968 return PTR_ERR(acl
);
2970 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2977 static int nl80211_parse_beacon(struct genl_info
*info
,
2978 struct cfg80211_beacon_data
*bcn
)
2980 bool haveinfo
= false;
2982 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2983 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2984 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2985 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2988 memset(bcn
, 0, sizeof(*bcn
));
2990 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2991 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2992 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2998 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2999 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3001 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3008 if (info
->attrs
[NL80211_ATTR_IE
]) {
3009 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3010 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3013 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3014 bcn
->proberesp_ies
=
3015 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3016 bcn
->proberesp_ies_len
=
3017 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3020 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3021 bcn
->assocresp_ies
=
3022 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3023 bcn
->assocresp_ies_len
=
3024 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3027 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
3029 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3030 bcn
->probe_resp_len
=
3031 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3037 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3038 struct cfg80211_ap_settings
*params
)
3040 struct wireless_dev
*wdev
;
3043 mutex_lock(&rdev
->devlist_mtx
);
3045 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3046 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3047 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3050 if (!wdev
->preset_chandef
.chan
)
3053 params
->chandef
= wdev
->preset_chandef
;
3058 mutex_unlock(&rdev
->devlist_mtx
);
3063 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3064 enum nl80211_auth_type auth_type
,
3065 enum nl80211_commands cmd
)
3067 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3071 case NL80211_CMD_AUTHENTICATE
:
3072 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3073 auth_type
== NL80211_AUTHTYPE_SAE
)
3076 case NL80211_CMD_CONNECT
:
3077 case NL80211_CMD_START_AP
:
3078 /* SAE not supported yet */
3079 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3087 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3089 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3090 struct net_device
*dev
= info
->user_ptr
[1];
3091 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3092 struct cfg80211_ap_settings params
;
3094 u8 radar_detect_width
= 0;
3096 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3097 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3100 if (!rdev
->ops
->start_ap
)
3103 if (wdev
->beacon_interval
)
3106 memset(¶ms
, 0, sizeof(params
));
3108 /* these are required for START_AP */
3109 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3110 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3111 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3114 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
3118 params
.beacon_interval
=
3119 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3120 params
.dtim_period
=
3121 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3123 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3128 * In theory, some of these attributes should be required here
3129 * but since they were not used when the command was originally
3130 * added, keep them optional for old user space programs to let
3131 * them continue to work with drivers that do not need the
3132 * additional information -- drivers must check!
3134 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3135 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3137 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3138 if (params
.ssid_len
== 0 ||
3139 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3143 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3144 params
.hidden_ssid
= nla_get_u32(
3145 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3146 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3147 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3148 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3152 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3154 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3155 params
.auth_type
= nla_get_u32(
3156 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3157 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3158 NL80211_CMD_START_AP
))
3161 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3163 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3164 NL80211_MAX_NR_CIPHER_SUITES
);
3168 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3169 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3171 params
.inactivity_timeout
= nla_get_u16(
3172 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3175 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3176 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3178 params
.p2p_ctwindow
=
3179 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3180 if (params
.p2p_ctwindow
> 127)
3182 if (params
.p2p_ctwindow
!= 0 &&
3183 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3187 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3190 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3192 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3195 params
.p2p_opp_ps
= tmp
;
3196 if (params
.p2p_opp_ps
!= 0 &&
3197 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3201 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3202 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3205 } else if (wdev
->preset_chandef
.chan
) {
3206 params
.chandef
= wdev
->preset_chandef
;
3207 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3210 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3213 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3217 radar_detect_width
= BIT(params
.chandef
.width
);
3218 params
.radar_required
= true;
3221 mutex_lock(&rdev
->devlist_mtx
);
3222 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3223 params
.chandef
.chan
,
3225 radar_detect_width
);
3226 mutex_unlock(&rdev
->devlist_mtx
);
3231 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3232 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3233 if (IS_ERR(params
.acl
))
3234 return PTR_ERR(params
.acl
);
3237 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3239 wdev
->preset_chandef
= params
.chandef
;
3240 wdev
->beacon_interval
= params
.beacon_interval
;
3241 wdev
->channel
= params
.chandef
.chan
;
3242 wdev
->ssid_len
= params
.ssid_len
;
3243 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3251 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3253 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3254 struct net_device
*dev
= info
->user_ptr
[1];
3255 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3256 struct cfg80211_beacon_data params
;
3259 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3260 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3263 if (!rdev
->ops
->change_beacon
)
3266 if (!wdev
->beacon_interval
)
3269 err
= nl80211_parse_beacon(info
, ¶ms
);
3273 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3276 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3278 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3279 struct net_device
*dev
= info
->user_ptr
[1];
3281 return cfg80211_stop_ap(rdev
, dev
);
3284 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3285 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3286 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3287 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3288 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3289 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3290 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3293 static int parse_station_flags(struct genl_info
*info
,
3294 enum nl80211_iftype iftype
,
3295 struct station_parameters
*params
)
3297 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3302 * Try parsing the new attribute first so userspace
3303 * can specify both for older kernels.
3305 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3307 struct nl80211_sta_flag_update
*sta_flags
;
3309 sta_flags
= nla_data(nla
);
3310 params
->sta_flags_mask
= sta_flags
->mask
;
3311 params
->sta_flags_set
= sta_flags
->set
;
3312 params
->sta_flags_set
&= params
->sta_flags_mask
;
3313 if ((params
->sta_flags_mask
|
3314 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3319 /* if present, parse the old attribute */
3321 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3325 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3326 nla
, sta_flags_policy
))
3330 * Only allow certain flags for interface types so that
3331 * other attributes are silently ignored. Remember that
3332 * this is backward compatibility code with old userspace
3333 * and shouldn't be hit in other cases anyway.
3336 case NL80211_IFTYPE_AP
:
3337 case NL80211_IFTYPE_AP_VLAN
:
3338 case NL80211_IFTYPE_P2P_GO
:
3339 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3340 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3341 BIT(NL80211_STA_FLAG_WME
) |
3342 BIT(NL80211_STA_FLAG_MFP
);
3344 case NL80211_IFTYPE_P2P_CLIENT
:
3345 case NL80211_IFTYPE_STATION
:
3346 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3347 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3349 case NL80211_IFTYPE_MESH_POINT
:
3350 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3351 BIT(NL80211_STA_FLAG_MFP
) |
3352 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3357 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3359 params
->sta_flags_set
|= (1<<flag
);
3361 /* no longer support new API additions in old API */
3362 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3370 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3373 struct nlattr
*rate
;
3377 rate
= nla_nest_start(msg
, attr
);
3381 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3382 bitrate
= cfg80211_calculate_bitrate(info
);
3383 /* report 16-bit bitrate only if we can */
3384 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3386 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3388 if (bitrate_compat
> 0 &&
3389 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3392 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3393 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3395 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3396 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3398 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3399 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3401 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3402 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3404 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3406 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3407 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3409 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3410 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3412 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3413 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3415 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3416 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3418 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3419 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3423 nla_nest_end(msg
, rate
);
3427 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3429 struct cfg80211_registered_device
*rdev
,
3430 struct net_device
*dev
,
3431 const u8
*mac_addr
, struct station_info
*sinfo
)
3434 struct nlattr
*sinfoattr
, *bss_param
;
3436 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3440 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3441 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3442 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3443 goto nla_put_failure
;
3445 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3447 goto nla_put_failure
;
3448 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3449 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3450 sinfo
->connected_time
))
3451 goto nla_put_failure
;
3452 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3453 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3454 sinfo
->inactive_time
))
3455 goto nla_put_failure
;
3456 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3457 STATION_INFO_RX_BYTES64
)) &&
3458 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3459 (u32
)sinfo
->rx_bytes
))
3460 goto nla_put_failure
;
3461 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3462 STATION_INFO_TX_BYTES64
)) &&
3463 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3464 (u32
)sinfo
->tx_bytes
))
3465 goto nla_put_failure
;
3466 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3467 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3469 goto nla_put_failure
;
3470 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3471 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3473 goto nla_put_failure
;
3474 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3475 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3476 goto nla_put_failure
;
3477 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3478 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3479 goto nla_put_failure
;
3480 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3481 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3482 sinfo
->plink_state
))
3483 goto nla_put_failure
;
3484 switch (rdev
->wiphy
.signal_type
) {
3485 case CFG80211_SIGNAL_TYPE_MBM
:
3486 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3487 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3489 goto nla_put_failure
;
3490 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3491 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3493 goto nla_put_failure
;
3498 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3499 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3500 NL80211_STA_INFO_TX_BITRATE
))
3501 goto nla_put_failure
;
3503 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3504 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3505 NL80211_STA_INFO_RX_BITRATE
))
3506 goto nla_put_failure
;
3508 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3509 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3511 goto nla_put_failure
;
3512 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3513 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3515 goto nla_put_failure
;
3516 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3517 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3519 goto nla_put_failure
;
3520 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3521 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3523 goto nla_put_failure
;
3524 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3525 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3526 sinfo
->beacon_loss_count
))
3527 goto nla_put_failure
;
3528 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3529 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3531 goto nla_put_failure
;
3532 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3533 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3535 goto nla_put_failure
;
3536 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3537 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3539 goto nla_put_failure
;
3540 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3541 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3543 goto nla_put_failure
;
3545 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3546 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3547 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3548 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3549 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3550 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3551 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3552 sinfo
->bss_param
.dtim_period
) ||
3553 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3554 sinfo
->bss_param
.beacon_interval
))
3555 goto nla_put_failure
;
3557 nla_nest_end(msg
, bss_param
);
3559 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3560 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3561 sizeof(struct nl80211_sta_flag_update
),
3563 goto nla_put_failure
;
3564 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3565 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3567 goto nla_put_failure
;
3568 nla_nest_end(msg
, sinfoattr
);
3570 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3571 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3572 sinfo
->assoc_req_ies
))
3573 goto nla_put_failure
;
3575 return genlmsg_end(msg
, hdr
);
3578 genlmsg_cancel(msg
, hdr
);
3582 static int nl80211_dump_station(struct sk_buff
*skb
,
3583 struct netlink_callback
*cb
)
3585 struct station_info sinfo
;
3586 struct cfg80211_registered_device
*dev
;
3587 struct wireless_dev
*wdev
;
3588 u8 mac_addr
[ETH_ALEN
];
3589 int sta_idx
= cb
->args
[2];
3592 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3596 if (!wdev
->netdev
) {
3601 if (!dev
->ops
->dump_station
) {
3607 memset(&sinfo
, 0, sizeof(sinfo
));
3608 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3615 if (nl80211_send_station(skb
,
3616 NETLINK_CB(cb
->skb
).portid
,
3617 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3618 dev
, wdev
->netdev
, mac_addr
,
3627 cb
->args
[2] = sta_idx
;
3630 nl80211_finish_wdev_dump(dev
);
3635 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3637 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3638 struct net_device
*dev
= info
->user_ptr
[1];
3639 struct station_info sinfo
;
3640 struct sk_buff
*msg
;
3641 u8
*mac_addr
= NULL
;
3644 memset(&sinfo
, 0, sizeof(sinfo
));
3646 if (!info
->attrs
[NL80211_ATTR_MAC
])
3649 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3651 if (!rdev
->ops
->get_station
)
3654 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3658 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3662 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3663 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3668 return genlmsg_reply(msg
, info
);
3671 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3672 struct station_parameters
*params
,
3673 enum cfg80211_station_type statype
)
3675 if (params
->listen_interval
!= -1)
3680 /* When you run into this, adjust the code below for the new flag */
3681 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3684 case CFG80211_STA_MESH_PEER_KERNEL
:
3685 case CFG80211_STA_MESH_PEER_USER
:
3687 * No ignoring the TDLS flag here -- the userspace mesh
3688 * code doesn't have the bug of including TDLS in the
3691 if (params
->sta_flags_mask
&
3692 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3693 BIT(NL80211_STA_FLAG_MFP
) |
3694 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3697 case CFG80211_STA_TDLS_PEER_SETUP
:
3698 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3699 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3701 /* ignore since it can't change */
3702 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3705 /* disallow mesh-specific things */
3706 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3708 if (params
->local_pm
)
3710 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3714 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3715 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3716 /* TDLS can't be set, ... */
3717 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3720 * ... but don't bother the driver with it. This works around
3721 * a hostapd/wpa_supplicant issue -- it always includes the
3722 * TLDS_PEER flag in the mask even for AP mode.
3724 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3727 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3728 /* reject other things that can't change */
3729 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3731 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3733 if (params
->supported_rates
)
3735 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3739 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3745 case CFG80211_STA_AP_MLME_CLIENT
:
3746 /* Use this only for authorizing/unauthorizing a station */
3747 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3750 case CFG80211_STA_AP_CLIENT
:
3751 /* accept only the listed bits */
3752 if (params
->sta_flags_mask
&
3753 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3754 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3755 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3756 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3757 BIT(NL80211_STA_FLAG_WME
) |
3758 BIT(NL80211_STA_FLAG_MFP
)))
3761 /* but authenticated/associated only if driver handles it */
3762 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3763 params
->sta_flags_mask
&
3764 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3765 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3768 case CFG80211_STA_IBSS
:
3769 case CFG80211_STA_AP_STA
:
3770 /* reject any changes other than AUTHORIZED */
3771 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3774 case CFG80211_STA_TDLS_PEER_SETUP
:
3775 /* reject any changes other than AUTHORIZED or WME */
3776 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3777 BIT(NL80211_STA_FLAG_WME
)))
3779 /* force (at least) rates when authorizing */
3780 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3781 !params
->supported_rates
)
3784 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3785 /* reject any changes */
3787 case CFG80211_STA_MESH_PEER_KERNEL
:
3788 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3791 case CFG80211_STA_MESH_PEER_USER
:
3792 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3799 EXPORT_SYMBOL(cfg80211_check_station_change
);
3802 * Get vlan interface making sure it is running and on the right wiphy.
3804 static struct net_device
*get_vlan(struct genl_info
*info
,
3805 struct cfg80211_registered_device
*rdev
)
3807 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3808 struct net_device
*v
;
3814 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3816 return ERR_PTR(-ENODEV
);
3818 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3823 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3824 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3825 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3830 if (!netif_running(v
)) {
3838 return ERR_PTR(ret
);
3841 static struct nla_policy
3842 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3843 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3844 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3847 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3848 struct station_parameters
*params
)
3850 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3854 /* parse WME attributes if present */
3855 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3858 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3859 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3860 nl80211_sta_wme_policy
);
3864 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3865 params
->uapsd_queues
= nla_get_u8(
3866 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3867 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3870 if (tb
[NL80211_STA_WME_MAX_SP
])
3871 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3873 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3876 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3881 static int nl80211_set_station_tdls(struct genl_info
*info
,
3882 struct station_parameters
*params
)
3884 /* Dummy STA entry gets updated once the peer capabilities are known */
3885 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3887 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3888 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3890 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3892 return nl80211_parse_sta_wme(info
, params
);
3895 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3897 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3898 struct net_device
*dev
= info
->user_ptr
[1];
3899 struct station_parameters params
;
3903 memset(¶ms
, 0, sizeof(params
));
3905 params
.listen_interval
= -1;
3907 if (!rdev
->ops
->change_station
)
3910 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3913 if (!info
->attrs
[NL80211_ATTR_MAC
])
3916 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3918 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3919 params
.supported_rates
=
3920 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3921 params
.supported_rates_len
=
3922 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3925 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3927 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3928 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3931 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3933 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3934 params
.ext_capab_len
=
3935 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3938 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3941 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3944 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3945 params
.plink_action
=
3946 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3947 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3951 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3952 params
.plink_state
=
3953 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3954 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3956 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3959 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3960 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3961 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3963 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3964 pm
> NL80211_MESH_POWER_MAX
)
3967 params
.local_pm
= pm
;
3970 /* Include parameters for TDLS peer (will check later) */
3971 err
= nl80211_set_station_tdls(info
, ¶ms
);
3975 params
.vlan
= get_vlan(info
, rdev
);
3976 if (IS_ERR(params
.vlan
))
3977 return PTR_ERR(params
.vlan
);
3979 switch (dev
->ieee80211_ptr
->iftype
) {
3980 case NL80211_IFTYPE_AP
:
3981 case NL80211_IFTYPE_AP_VLAN
:
3982 case NL80211_IFTYPE_P2P_GO
:
3983 case NL80211_IFTYPE_P2P_CLIENT
:
3984 case NL80211_IFTYPE_STATION
:
3985 case NL80211_IFTYPE_ADHOC
:
3986 case NL80211_IFTYPE_MESH_POINT
:
3993 /* driver will call cfg80211_check_station_change() */
3994 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3998 dev_put(params
.vlan
);
4003 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4005 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4007 struct net_device
*dev
= info
->user_ptr
[1];
4008 struct station_parameters params
;
4009 u8
*mac_addr
= NULL
;
4011 memset(¶ms
, 0, sizeof(params
));
4013 if (!rdev
->ops
->add_station
)
4016 if (!info
->attrs
[NL80211_ATTR_MAC
])
4019 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4022 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4025 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
4028 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4029 params
.supported_rates
=
4030 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4031 params
.supported_rates_len
=
4032 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4033 params
.listen_interval
=
4034 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4036 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4037 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4040 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4042 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4043 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4046 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4048 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4049 params
.ext_capab_len
=
4050 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4053 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4055 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4057 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4059 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4061 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4062 params
.plink_action
=
4063 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4064 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4068 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4072 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4075 /* When you run into this, adjust the code below for the new flag */
4076 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4078 switch (dev
->ieee80211_ptr
->iftype
) {
4079 case NL80211_IFTYPE_AP
:
4080 case NL80211_IFTYPE_AP_VLAN
:
4081 case NL80211_IFTYPE_P2P_GO
:
4082 /* ignore WME attributes if iface/sta is not capable */
4083 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4084 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4085 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4087 /* TDLS peers cannot be added */
4088 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4090 /* but don't bother the driver with it */
4091 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4093 /* allow authenticated/associated only if driver handles it */
4094 if (!(rdev
->wiphy
.features
&
4095 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4096 params
.sta_flags_mask
&
4097 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4098 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4101 /* must be last in here for error handling */
4102 params
.vlan
= get_vlan(info
, rdev
);
4103 if (IS_ERR(params
.vlan
))
4104 return PTR_ERR(params
.vlan
);
4106 case NL80211_IFTYPE_MESH_POINT
:
4107 /* ignore uAPSD data */
4108 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4110 /* associated is disallowed */
4111 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4113 /* TDLS peers cannot be added */
4114 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4117 case NL80211_IFTYPE_STATION
:
4118 case NL80211_IFTYPE_P2P_CLIENT
:
4119 /* ignore uAPSD data */
4120 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4122 /* these are disallowed */
4123 if (params
.sta_flags_mask
&
4124 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4125 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4127 /* Only TDLS peers can be added */
4128 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4130 /* Can only add if TDLS ... */
4131 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4133 /* ... with external setup is supported */
4134 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4137 * Older wpa_supplicant versions always mark the TDLS peer
4138 * as authorized, but it shouldn't yet be.
4140 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4146 /* be aware of params.vlan when changing code here */
4148 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4151 dev_put(params
.vlan
);
4155 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4157 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4158 struct net_device
*dev
= info
->user_ptr
[1];
4159 u8
*mac_addr
= NULL
;
4161 if (info
->attrs
[NL80211_ATTR_MAC
])
4162 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4164 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4165 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4166 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4167 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4170 if (!rdev
->ops
->del_station
)
4173 return rdev_del_station(rdev
, dev
, mac_addr
);
4176 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4177 int flags
, struct net_device
*dev
,
4178 u8
*dst
, u8
*next_hop
,
4179 struct mpath_info
*pinfo
)
4182 struct nlattr
*pinfoattr
;
4184 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4188 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4189 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4190 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4191 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4192 goto nla_put_failure
;
4194 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4196 goto nla_put_failure
;
4197 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4198 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4200 goto nla_put_failure
;
4201 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4202 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4203 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4204 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4206 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4207 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4209 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4210 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4212 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4213 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4214 pinfo
->discovery_timeout
)) ||
4215 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4216 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4217 pinfo
->discovery_retries
)))
4218 goto nla_put_failure
;
4220 nla_nest_end(msg
, pinfoattr
);
4222 return genlmsg_end(msg
, hdr
);
4225 genlmsg_cancel(msg
, hdr
);
4229 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4230 struct netlink_callback
*cb
)
4232 struct mpath_info pinfo
;
4233 struct cfg80211_registered_device
*dev
;
4234 struct wireless_dev
*wdev
;
4236 u8 next_hop
[ETH_ALEN
];
4237 int path_idx
= cb
->args
[2];
4240 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4244 if (!dev
->ops
->dump_mpath
) {
4249 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4255 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4262 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4263 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4264 wdev
->netdev
, dst
, next_hop
,
4273 cb
->args
[2] = path_idx
;
4276 nl80211_finish_wdev_dump(dev
);
4280 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4282 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4284 struct net_device
*dev
= info
->user_ptr
[1];
4285 struct mpath_info pinfo
;
4286 struct sk_buff
*msg
;
4288 u8 next_hop
[ETH_ALEN
];
4290 memset(&pinfo
, 0, sizeof(pinfo
));
4292 if (!info
->attrs
[NL80211_ATTR_MAC
])
4295 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4297 if (!rdev
->ops
->get_mpath
)
4300 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4303 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4307 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4311 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4312 dev
, dst
, next_hop
, &pinfo
) < 0) {
4317 return genlmsg_reply(msg
, info
);
4320 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4322 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4323 struct net_device
*dev
= info
->user_ptr
[1];
4325 u8
*next_hop
= NULL
;
4327 if (!info
->attrs
[NL80211_ATTR_MAC
])
4330 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4333 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4334 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4336 if (!rdev
->ops
->change_mpath
)
4339 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4342 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4345 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4347 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4348 struct net_device
*dev
= info
->user_ptr
[1];
4350 u8
*next_hop
= NULL
;
4352 if (!info
->attrs
[NL80211_ATTR_MAC
])
4355 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4358 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4359 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4361 if (!rdev
->ops
->add_mpath
)
4364 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4367 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4370 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4372 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4373 struct net_device
*dev
= info
->user_ptr
[1];
4376 if (info
->attrs
[NL80211_ATTR_MAC
])
4377 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4379 if (!rdev
->ops
->del_mpath
)
4382 return rdev_del_mpath(rdev
, dev
, dst
);
4385 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4387 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4388 struct net_device
*dev
= info
->user_ptr
[1];
4389 struct bss_parameters params
;
4391 memset(¶ms
, 0, sizeof(params
));
4392 /* default to not changing parameters */
4393 params
.use_cts_prot
= -1;
4394 params
.use_short_preamble
= -1;
4395 params
.use_short_slot_time
= -1;
4396 params
.ap_isolate
= -1;
4397 params
.ht_opmode
= -1;
4398 params
.p2p_ctwindow
= -1;
4399 params
.p2p_opp_ps
= -1;
4401 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4402 params
.use_cts_prot
=
4403 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4404 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4405 params
.use_short_preamble
=
4406 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4407 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4408 params
.use_short_slot_time
=
4409 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4410 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4411 params
.basic_rates
=
4412 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4413 params
.basic_rates_len
=
4414 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4416 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4417 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4418 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4420 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4422 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4423 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4425 params
.p2p_ctwindow
=
4426 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4427 if (params
.p2p_ctwindow
< 0)
4429 if (params
.p2p_ctwindow
!= 0 &&
4430 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4434 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4437 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4439 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4442 params
.p2p_opp_ps
= tmp
;
4443 if (params
.p2p_opp_ps
&&
4444 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4448 if (!rdev
->ops
->change_bss
)
4451 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4452 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4455 return rdev_change_bss(rdev
, dev
, ¶ms
);
4458 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4459 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4460 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4461 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4462 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4463 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4464 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4467 static int parse_reg_rule(struct nlattr
*tb
[],
4468 struct ieee80211_reg_rule
*reg_rule
)
4470 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4471 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4473 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4475 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4477 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4479 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4481 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4484 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4486 freq_range
->start_freq_khz
=
4487 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4488 freq_range
->end_freq_khz
=
4489 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4490 freq_range
->max_bandwidth_khz
=
4491 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4493 power_rule
->max_eirp
=
4494 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4496 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4497 power_rule
->max_antenna_gain
=
4498 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4503 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4507 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4510 * You should only get this when cfg80211 hasn't yet initialized
4511 * completely when built-in to the kernel right between the time
4512 * window between nl80211_init() and regulatory_init(), if that is
4515 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4516 return -EINPROGRESS
;
4518 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4521 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4523 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4524 user_reg_hint_type
=
4525 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4527 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4529 switch (user_reg_hint_type
) {
4530 case NL80211_USER_REG_HINT_USER
:
4531 case NL80211_USER_REG_HINT_CELL_BASE
:
4537 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4542 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4543 struct genl_info
*info
)
4545 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4546 struct net_device
*dev
= info
->user_ptr
[1];
4547 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4548 struct mesh_config cur_params
;
4551 struct nlattr
*pinfoattr
;
4552 struct sk_buff
*msg
;
4554 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4557 if (!rdev
->ops
->get_mesh_config
)
4561 /* If not connected, get default parameters */
4562 if (!wdev
->mesh_id_len
)
4563 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4565 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4571 /* Draw up a netlink message to send back */
4572 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4575 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4576 NL80211_CMD_GET_MESH_CONFIG
);
4579 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4581 goto nla_put_failure
;
4582 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4583 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4584 cur_params
.dot11MeshRetryTimeout
) ||
4585 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4586 cur_params
.dot11MeshConfirmTimeout
) ||
4587 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4588 cur_params
.dot11MeshHoldingTimeout
) ||
4589 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4590 cur_params
.dot11MeshMaxPeerLinks
) ||
4591 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4592 cur_params
.dot11MeshMaxRetries
) ||
4593 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4594 cur_params
.dot11MeshTTL
) ||
4595 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4596 cur_params
.element_ttl
) ||
4597 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4598 cur_params
.auto_open_plinks
) ||
4599 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4600 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4601 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4602 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4603 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4604 cur_params
.path_refresh_time
) ||
4605 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4606 cur_params
.min_discovery_timeout
) ||
4607 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4608 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4609 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4610 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4611 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4612 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4613 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4614 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4615 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4616 cur_params
.dot11MeshHWMPRootMode
) ||
4617 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4618 cur_params
.dot11MeshHWMPRannInterval
) ||
4619 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4620 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4621 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4622 cur_params
.dot11MeshForwarding
) ||
4623 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4624 cur_params
.rssi_threshold
) ||
4625 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4626 cur_params
.ht_opmode
) ||
4627 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4628 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4629 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4630 cur_params
.dot11MeshHWMProotInterval
) ||
4631 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4632 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4633 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4634 cur_params
.power_mode
) ||
4635 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4636 cur_params
.dot11MeshAwakeWindowDuration
))
4637 goto nla_put_failure
;
4638 nla_nest_end(msg
, pinfoattr
);
4639 genlmsg_end(msg
, hdr
);
4640 return genlmsg_reply(msg
, info
);
4643 genlmsg_cancel(msg
, hdr
);
4649 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4650 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4651 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4652 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4653 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4654 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4655 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4656 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4657 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4658 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4659 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4660 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4661 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4662 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4663 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4664 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4665 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4666 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4667 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4668 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4669 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4670 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4671 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4672 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4673 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4674 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4675 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4676 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4679 static const struct nla_policy
4680 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4681 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4682 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4683 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4684 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4685 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4686 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4687 .len
= IEEE80211_MAX_DATA_LEN
},
4688 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4691 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4692 struct mesh_config
*cfg
,
4695 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4698 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4701 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4703 cfg->param = fn(tb[attr]); \
4704 mask |= (1 << (attr - 1)); \
4709 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4711 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4712 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4713 nl80211_meshconf_params_policy
))
4716 /* This makes sure that there aren't more than 32 mesh config
4717 * parameters (otherwise our bitfield scheme would not work.) */
4718 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4720 /* Fill in the params struct */
4721 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4722 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4724 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4725 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4727 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4728 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4730 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4731 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4733 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4734 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4736 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4737 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4738 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4739 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4741 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4742 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4744 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4746 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4748 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4749 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4751 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4752 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4754 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4755 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4759 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4761 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4763 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4765 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4767 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4769 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4770 dot11MeshHWMPnetDiameterTraversalTime
,
4772 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4774 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4775 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4777 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4778 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4780 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4781 dot11MeshGateAnnouncementProtocol
, 0, 1,
4782 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4784 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4785 mask
, NL80211_MESHCONF_FORWARDING
,
4787 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4788 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4790 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4791 mask
, NL80211_MESHCONF_HT_OPMODE
,
4793 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4795 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4797 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4798 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4800 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4801 dot11MeshHWMPconfirmationInterval
,
4803 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4805 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4806 NL80211_MESH_POWER_ACTIVE
,
4807 NL80211_MESH_POWER_MAX
,
4808 mask
, NL80211_MESHCONF_POWER_MODE
,
4810 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4812 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4818 #undef FILL_IN_MESH_PARAM_IF_SET
4821 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4822 struct mesh_setup
*setup
)
4824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4825 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4827 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4829 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4830 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4831 nl80211_mesh_setup_params_policy
))
4834 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4835 setup
->sync_method
=
4836 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4837 IEEE80211_SYNC_METHOD_VENDOR
:
4838 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4840 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4841 setup
->path_sel_proto
=
4842 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4843 IEEE80211_PATH_PROTOCOL_VENDOR
:
4844 IEEE80211_PATH_PROTOCOL_HWMP
;
4846 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4847 setup
->path_metric
=
4848 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4849 IEEE80211_PATH_METRIC_VENDOR
:
4850 IEEE80211_PATH_METRIC_AIRTIME
;
4853 if (tb
[NL80211_MESH_SETUP_IE
]) {
4854 struct nlattr
*ieattr
=
4855 tb
[NL80211_MESH_SETUP_IE
];
4856 if (!is_valid_ie_attr(ieattr
))
4858 setup
->ie
= nla_data(ieattr
);
4859 setup
->ie_len
= nla_len(ieattr
);
4861 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4862 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4864 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4865 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4866 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4867 if (setup
->is_secure
)
4868 setup
->user_mpm
= true;
4873 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4874 struct genl_info
*info
)
4876 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4877 struct net_device
*dev
= info
->user_ptr
[1];
4878 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4879 struct mesh_config cfg
;
4883 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4886 if (!rdev
->ops
->update_mesh_config
)
4889 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4894 if (!wdev
->mesh_id_len
)
4898 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4905 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4907 const struct ieee80211_regdomain
*regdom
;
4908 struct sk_buff
*msg
;
4910 struct nlattr
*nl_reg_rules
;
4914 mutex_lock(&cfg80211_mutex
);
4916 if (!cfg80211_regdomain
)
4919 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4925 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4926 NL80211_CMD_GET_REG
);
4930 if (reg_last_request_cell_base() &&
4931 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4932 NL80211_USER_REG_HINT_CELL_BASE
))
4933 goto nla_put_failure
;
4936 regdom
= rcu_dereference(cfg80211_regdomain
);
4938 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4939 (regdom
->dfs_region
&&
4940 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4941 goto nla_put_failure_rcu
;
4943 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4945 goto nla_put_failure_rcu
;
4947 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4948 struct nlattr
*nl_reg_rule
;
4949 const struct ieee80211_reg_rule
*reg_rule
;
4950 const struct ieee80211_freq_range
*freq_range
;
4951 const struct ieee80211_power_rule
*power_rule
;
4953 reg_rule
= ®dom
->reg_rules
[i
];
4954 freq_range
= ®_rule
->freq_range
;
4955 power_rule
= ®_rule
->power_rule
;
4957 nl_reg_rule
= nla_nest_start(msg
, i
);
4959 goto nla_put_failure_rcu
;
4961 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4963 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4964 freq_range
->start_freq_khz
) ||
4965 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4966 freq_range
->end_freq_khz
) ||
4967 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4968 freq_range
->max_bandwidth_khz
) ||
4969 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4970 power_rule
->max_antenna_gain
) ||
4971 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4972 power_rule
->max_eirp
))
4973 goto nla_put_failure_rcu
;
4975 nla_nest_end(msg
, nl_reg_rule
);
4979 nla_nest_end(msg
, nl_reg_rules
);
4981 genlmsg_end(msg
, hdr
);
4982 err
= genlmsg_reply(msg
, info
);
4985 nla_put_failure_rcu
:
4988 genlmsg_cancel(msg
, hdr
);
4993 mutex_unlock(&cfg80211_mutex
);
4997 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4999 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5000 struct nlattr
*nl_reg_rule
;
5001 char *alpha2
= NULL
;
5002 int rem_reg_rules
= 0, r
= 0;
5003 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5005 struct ieee80211_regdomain
*rd
= NULL
;
5007 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5010 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5013 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5015 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5016 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5018 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5021 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5025 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5026 num_rules
* sizeof(struct ieee80211_reg_rule
);
5028 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5032 rd
->n_reg_rules
= num_rules
;
5033 rd
->alpha2
[0] = alpha2
[0];
5034 rd
->alpha2
[1] = alpha2
[1];
5037 * Disable DFS master mode if the DFS region was
5038 * not supported or known on this kernel.
5040 if (reg_supported_dfs_region(dfs_region
))
5041 rd
->dfs_region
= dfs_region
;
5043 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5045 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5046 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5048 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5054 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5060 mutex_lock(&cfg80211_mutex
);
5063 /* set_regdom took ownership */
5065 mutex_unlock(&cfg80211_mutex
);
5072 static int validate_scan_freqs(struct nlattr
*freqs
)
5074 struct nlattr
*attr1
, *attr2
;
5075 int n_channels
= 0, tmp1
, tmp2
;
5077 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5080 * Some hardware has a limited channel list for
5081 * scanning, and it is pretty much nonsensical
5082 * to scan for a channel twice, so disallow that
5083 * and don't require drivers to check that the
5084 * channel list they get isn't longer than what
5085 * they can scan, as long as they can scan all
5086 * the channels they registered at once.
5088 nla_for_each_nested(attr2
, freqs
, tmp2
)
5089 if (attr1
!= attr2
&&
5090 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5097 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5099 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5100 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5101 struct cfg80211_scan_request
*request
;
5102 struct nlattr
*attr
;
5103 struct wiphy
*wiphy
;
5104 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5107 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5110 wiphy
= &rdev
->wiphy
;
5112 if (!rdev
->ops
->scan
)
5115 mutex_lock(&rdev
->sched_scan_mtx
);
5116 if (rdev
->scan_req
) {
5121 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5122 n_channels
= validate_scan_freqs(
5123 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5129 enum ieee80211_band band
;
5132 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5133 if (wiphy
->bands
[band
])
5134 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5137 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5138 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5141 if (n_ssids
> wiphy
->max_scan_ssids
) {
5146 if (info
->attrs
[NL80211_ATTR_IE
])
5147 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5151 if (ie_len
> wiphy
->max_scan_ie_len
) {
5156 request
= kzalloc(sizeof(*request
)
5157 + sizeof(*request
->ssids
) * n_ssids
5158 + sizeof(*request
->channels
) * n_channels
5159 + ie_len
, GFP_KERNEL
);
5166 request
->ssids
= (void *)&request
->channels
[n_channels
];
5167 request
->n_ssids
= n_ssids
;
5170 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5172 request
->ie
= (void *)(request
->channels
+ n_channels
);
5176 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5177 /* user specified, bail out if channel not found */
5178 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5179 struct ieee80211_channel
*chan
;
5181 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5188 /* ignore disabled channels */
5189 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5192 request
->channels
[i
] = chan
;
5196 enum ieee80211_band band
;
5199 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5201 if (!wiphy
->bands
[band
])
5203 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5204 struct ieee80211_channel
*chan
;
5206 chan
= &wiphy
->bands
[band
]->channels
[j
];
5208 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5211 request
->channels
[i
] = chan
;
5222 request
->n_channels
= i
;
5225 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5226 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5227 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5231 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5232 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5237 if (info
->attrs
[NL80211_ATTR_IE
]) {
5238 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5239 memcpy((void *)request
->ie
,
5240 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5244 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5245 if (wiphy
->bands
[i
])
5247 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5249 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5250 nla_for_each_nested(attr
,
5251 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5253 enum ieee80211_band band
= nla_type(attr
);
5255 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5259 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5262 &request
->rates
[band
]);
5268 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5269 request
->flags
= nla_get_u32(
5270 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5271 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5272 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5273 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5274 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5281 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5283 request
->wdev
= wdev
;
5284 request
->wiphy
= &rdev
->wiphy
;
5285 request
->scan_start
= jiffies
;
5287 rdev
->scan_req
= request
;
5288 err
= rdev_scan(rdev
, request
);
5291 nl80211_send_scan_start(rdev
, wdev
);
5293 dev_hold(wdev
->netdev
);
5296 rdev
->scan_req
= NULL
;
5301 mutex_unlock(&rdev
->sched_scan_mtx
);
5305 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5306 struct genl_info
*info
)
5308 struct cfg80211_sched_scan_request
*request
;
5309 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5310 struct net_device
*dev
= info
->user_ptr
[1];
5311 struct nlattr
*attr
;
5312 struct wiphy
*wiphy
;
5313 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5315 enum ieee80211_band band
;
5317 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5319 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5320 !rdev
->ops
->sched_scan_start
)
5323 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5326 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5329 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5333 wiphy
= &rdev
->wiphy
;
5335 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5336 n_channels
= validate_scan_freqs(
5337 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5343 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5344 if (wiphy
->bands
[band
])
5345 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5348 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5349 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5353 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5356 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5357 nla_for_each_nested(attr
,
5358 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5362 if (n_match_sets
> wiphy
->max_match_sets
)
5365 if (info
->attrs
[NL80211_ATTR_IE
])
5366 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5370 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5373 mutex_lock(&rdev
->sched_scan_mtx
);
5375 if (rdev
->sched_scan_req
) {
5380 request
= kzalloc(sizeof(*request
)
5381 + sizeof(*request
->ssids
) * n_ssids
5382 + sizeof(*request
->match_sets
) * n_match_sets
5383 + sizeof(*request
->channels
) * n_channels
5384 + ie_len
, GFP_KERNEL
);
5391 request
->ssids
= (void *)&request
->channels
[n_channels
];
5392 request
->n_ssids
= n_ssids
;
5395 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5397 request
->ie
= (void *)(request
->channels
+ n_channels
);
5402 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5403 else if (request
->ssids
)
5404 request
->match_sets
=
5405 (void *)(request
->ssids
+ n_ssids
);
5407 request
->match_sets
=
5408 (void *)(request
->channels
+ n_channels
);
5410 request
->n_match_sets
= n_match_sets
;
5413 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5414 /* user specified, bail out if channel not found */
5415 nla_for_each_nested(attr
,
5416 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5418 struct ieee80211_channel
*chan
;
5420 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5427 /* ignore disabled channels */
5428 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5431 request
->channels
[i
] = chan
;
5436 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5438 if (!wiphy
->bands
[band
])
5440 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5441 struct ieee80211_channel
*chan
;
5443 chan
= &wiphy
->bands
[band
]->channels
[j
];
5445 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5448 request
->channels
[i
] = chan
;
5459 request
->n_channels
= i
;
5462 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5463 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5465 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5469 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5470 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5477 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5478 nla_for_each_nested(attr
,
5479 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5481 struct nlattr
*ssid
, *rssi
;
5483 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5484 nla_data(attr
), nla_len(attr
),
5485 nl80211_match_policy
);
5486 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5488 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5492 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5493 nla_data(ssid
), nla_len(ssid
));
5494 request
->match_sets
[i
].ssid
.ssid_len
=
5497 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5499 request
->rssi_thold
= nla_get_u32(rssi
);
5501 request
->rssi_thold
=
5502 NL80211_SCAN_RSSI_THOLD_OFF
;
5507 if (info
->attrs
[NL80211_ATTR_IE
]) {
5508 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5509 memcpy((void *)request
->ie
,
5510 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5514 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5515 request
->flags
= nla_get_u32(
5516 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5517 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5518 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5519 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5520 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5527 request
->wiphy
= &rdev
->wiphy
;
5528 request
->interval
= interval
;
5529 request
->scan_start
= jiffies
;
5531 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5533 rdev
->sched_scan_req
= request
;
5534 nl80211_send_sched_scan(rdev
, dev
,
5535 NL80211_CMD_START_SCHED_SCAN
);
5542 mutex_unlock(&rdev
->sched_scan_mtx
);
5546 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5547 struct genl_info
*info
)
5549 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5552 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5553 !rdev
->ops
->sched_scan_stop
)
5556 mutex_lock(&rdev
->sched_scan_mtx
);
5557 err
= __cfg80211_stop_sched_scan(rdev
, false);
5558 mutex_unlock(&rdev
->sched_scan_mtx
);
5563 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5564 struct genl_info
*info
)
5566 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5567 struct net_device
*dev
= info
->user_ptr
[1];
5568 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5569 struct cfg80211_chan_def chandef
;
5572 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5576 if (wdev
->cac_started
)
5579 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5586 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5589 if (!rdev
->ops
->start_radar_detection
)
5592 mutex_lock(&rdev
->devlist_mtx
);
5593 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5594 chandef
.chan
, CHAN_MODE_SHARED
,
5595 BIT(chandef
.width
));
5599 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5601 wdev
->channel
= chandef
.chan
;
5602 wdev
->cac_started
= true;
5603 wdev
->cac_start_time
= jiffies
;
5606 mutex_unlock(&rdev
->devlist_mtx
);
5611 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5613 struct cfg80211_registered_device
*rdev
,
5614 struct wireless_dev
*wdev
,
5615 struct cfg80211_internal_bss
*intbss
)
5617 struct cfg80211_bss
*res
= &intbss
->pub
;
5618 const struct cfg80211_bss_ies
*ies
;
5623 ASSERT_WDEV_LOCK(wdev
);
5625 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5626 NL80211_CMD_NEW_SCAN_RESULTS
);
5630 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5632 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5633 goto nla_put_failure
;
5635 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5636 goto nla_put_failure
;
5637 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5638 goto nla_put_failure
;
5640 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5642 goto nla_put_failure
;
5643 if ((!is_zero_ether_addr(res
->bssid
) &&
5644 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5645 goto nla_put_failure
;
5648 ies
= rcu_dereference(res
->ies
);
5650 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5651 goto fail_unlock_rcu
;
5653 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5654 ies
->len
, ies
->data
))
5655 goto fail_unlock_rcu
;
5657 ies
= rcu_dereference(res
->beacon_ies
);
5659 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5660 goto fail_unlock_rcu
;
5661 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5662 ies
->len
, ies
->data
))
5663 goto fail_unlock_rcu
;
5667 if (res
->beacon_interval
&&
5668 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5669 goto nla_put_failure
;
5670 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5671 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5672 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5673 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5674 goto nla_put_failure
;
5676 switch (rdev
->wiphy
.signal_type
) {
5677 case CFG80211_SIGNAL_TYPE_MBM
:
5678 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5679 goto nla_put_failure
;
5681 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5682 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5683 goto nla_put_failure
;
5689 switch (wdev
->iftype
) {
5690 case NL80211_IFTYPE_P2P_CLIENT
:
5691 case NL80211_IFTYPE_STATION
:
5692 if (intbss
== wdev
->current_bss
&&
5693 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5694 NL80211_BSS_STATUS_ASSOCIATED
))
5695 goto nla_put_failure
;
5697 case NL80211_IFTYPE_ADHOC
:
5698 if (intbss
== wdev
->current_bss
&&
5699 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5700 NL80211_BSS_STATUS_IBSS_JOINED
))
5701 goto nla_put_failure
;
5707 nla_nest_end(msg
, bss
);
5709 return genlmsg_end(msg
, hdr
);
5714 genlmsg_cancel(msg
, hdr
);
5718 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5720 struct cfg80211_registered_device
*rdev
;
5721 struct cfg80211_internal_bss
*scan
;
5722 struct wireless_dev
*wdev
;
5723 int start
= cb
->args
[2], idx
= 0;
5726 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5731 spin_lock_bh(&rdev
->bss_lock
);
5732 cfg80211_bss_expire(rdev
);
5734 cb
->seq
= rdev
->bss_generation
;
5736 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5739 if (nl80211_send_bss(skb
, cb
,
5740 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5741 rdev
, wdev
, scan
) < 0) {
5747 spin_unlock_bh(&rdev
->bss_lock
);
5751 nl80211_finish_wdev_dump(rdev
);
5756 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5757 int flags
, struct net_device
*dev
,
5758 struct survey_info
*survey
)
5761 struct nlattr
*infoattr
;
5763 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5764 NL80211_CMD_NEW_SURVEY_RESULTS
);
5768 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5769 goto nla_put_failure
;
5771 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5773 goto nla_put_failure
;
5775 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5776 survey
->channel
->center_freq
))
5777 goto nla_put_failure
;
5779 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5780 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5781 goto nla_put_failure
;
5782 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5783 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5784 goto nla_put_failure
;
5785 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5786 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5787 survey
->channel_time
))
5788 goto nla_put_failure
;
5789 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5790 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5791 survey
->channel_time_busy
))
5792 goto nla_put_failure
;
5793 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5794 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5795 survey
->channel_time_ext_busy
))
5796 goto nla_put_failure
;
5797 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5798 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5799 survey
->channel_time_rx
))
5800 goto nla_put_failure
;
5801 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5802 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5803 survey
->channel_time_tx
))
5804 goto nla_put_failure
;
5806 nla_nest_end(msg
, infoattr
);
5808 return genlmsg_end(msg
, hdr
);
5811 genlmsg_cancel(msg
, hdr
);
5815 static int nl80211_dump_survey(struct sk_buff
*skb
,
5816 struct netlink_callback
*cb
)
5818 struct survey_info survey
;
5819 struct cfg80211_registered_device
*dev
;
5820 struct wireless_dev
*wdev
;
5821 int survey_idx
= cb
->args
[2];
5824 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5828 if (!wdev
->netdev
) {
5833 if (!dev
->ops
->dump_survey
) {
5839 struct ieee80211_channel
*chan
;
5841 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5847 /* Survey without a channel doesn't make sense */
5848 if (!survey
.channel
) {
5853 chan
= ieee80211_get_channel(&dev
->wiphy
,
5854 survey
.channel
->center_freq
);
5855 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5860 if (nl80211_send_survey(skb
,
5861 NETLINK_CB(cb
->skb
).portid
,
5862 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5863 wdev
->netdev
, &survey
) < 0)
5869 cb
->args
[2] = survey_idx
;
5872 nl80211_finish_wdev_dump(dev
);
5876 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5878 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5879 NL80211_WPA_VERSION_2
));
5882 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5884 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5885 struct net_device
*dev
= info
->user_ptr
[1];
5886 struct ieee80211_channel
*chan
;
5887 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5888 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5889 enum nl80211_auth_type auth_type
;
5890 struct key_parse key
;
5891 bool local_state_change
;
5893 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5896 if (!info
->attrs
[NL80211_ATTR_MAC
])
5899 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5902 if (!info
->attrs
[NL80211_ATTR_SSID
])
5905 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5908 err
= nl80211_parse_key(info
, &key
);
5913 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5915 if (!key
.p
.key
|| !key
.p
.key_len
)
5917 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5918 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5919 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5920 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5932 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5933 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5942 if (!rdev
->ops
->auth
)
5945 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5946 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5949 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5950 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5951 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5952 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5955 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5956 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5958 if (info
->attrs
[NL80211_ATTR_IE
]) {
5959 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5960 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5963 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5964 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5967 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5968 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5971 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5972 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5974 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5975 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5976 /* need to include at least Auth Transaction and Status Code */
5977 if (sae_data_len
< 4)
5981 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5984 * Since we no longer track auth state, ignore
5985 * requests to only change local state.
5987 if (local_state_change
)
5990 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5991 ssid
, ssid_len
, ie
, ie_len
,
5992 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5993 sae_data
, sae_data_len
);
5996 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5997 struct genl_info
*info
,
5998 struct cfg80211_crypto_settings
*settings
,
6001 memset(settings
, 0, sizeof(*settings
));
6003 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6005 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6007 proto
= nla_get_u16(
6008 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6009 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6010 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6013 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6014 settings
->control_port_no_encrypt
= true;
6016 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6018 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6022 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6023 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6024 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6026 if (len
% sizeof(u32
))
6029 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6032 memcpy(settings
->ciphers_pairwise
, data
, len
);
6034 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6035 if (!cfg80211_supported_cipher_suite(
6037 settings
->ciphers_pairwise
[i
]))
6041 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6042 settings
->cipher_group
=
6043 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6044 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6045 settings
->cipher_group
))
6049 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6050 settings
->wpa_versions
=
6051 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6052 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6056 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6060 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6061 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6062 settings
->n_akm_suites
= len
/ sizeof(u32
);
6064 if (len
% sizeof(u32
))
6067 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6070 memcpy(settings
->akm_suites
, data
, len
);
6076 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6078 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6079 struct net_device
*dev
= info
->user_ptr
[1];
6080 struct ieee80211_channel
*chan
;
6081 struct cfg80211_assoc_request req
= {};
6082 const u8
*bssid
, *ssid
;
6083 int err
, ssid_len
= 0;
6085 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6088 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6089 !info
->attrs
[NL80211_ATTR_SSID
] ||
6090 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6093 if (!rdev
->ops
->assoc
)
6096 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6097 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6100 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6102 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6103 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6104 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6107 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6108 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6110 if (info
->attrs
[NL80211_ATTR_IE
]) {
6111 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6112 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6115 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6116 enum nl80211_mfp mfp
=
6117 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6118 if (mfp
== NL80211_MFP_REQUIRED
)
6120 else if (mfp
!= NL80211_MFP_NO
)
6124 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6125 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6127 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6128 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6130 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6131 memcpy(&req
.ht_capa_mask
,
6132 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6133 sizeof(req
.ht_capa_mask
));
6135 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6136 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6138 memcpy(&req
.ht_capa
,
6139 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6140 sizeof(req
.ht_capa
));
6143 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6144 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6146 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6147 memcpy(&req
.vht_capa_mask
,
6148 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6149 sizeof(req
.vht_capa_mask
));
6151 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6152 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6154 memcpy(&req
.vht_capa
,
6155 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6156 sizeof(req
.vht_capa
));
6159 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6161 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6162 ssid
, ssid_len
, &req
);
6167 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6169 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6170 struct net_device
*dev
= info
->user_ptr
[1];
6171 const u8
*ie
= NULL
, *bssid
;
6174 bool local_state_change
;
6176 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6179 if (!info
->attrs
[NL80211_ATTR_MAC
])
6182 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6185 if (!rdev
->ops
->deauth
)
6188 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6189 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6192 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6194 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6195 if (reason_code
== 0) {
6196 /* Reason Code 0 is reserved */
6200 if (info
->attrs
[NL80211_ATTR_IE
]) {
6201 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6202 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6205 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6207 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6208 local_state_change
);
6211 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6213 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6214 struct net_device
*dev
= info
->user_ptr
[1];
6215 const u8
*ie
= NULL
, *bssid
;
6218 bool local_state_change
;
6220 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6223 if (!info
->attrs
[NL80211_ATTR_MAC
])
6226 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6229 if (!rdev
->ops
->disassoc
)
6232 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6233 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6236 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6238 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6239 if (reason_code
== 0) {
6240 /* Reason Code 0 is reserved */
6244 if (info
->attrs
[NL80211_ATTR_IE
]) {
6245 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6246 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6249 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6251 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6252 local_state_change
);
6256 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6257 int mcast_rate
[IEEE80211_NUM_BANDS
],
6260 struct wiphy
*wiphy
= &rdev
->wiphy
;
6264 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6265 struct ieee80211_supported_band
*sband
;
6267 sband
= wiphy
->bands
[band
];
6271 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6272 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6273 mcast_rate
[band
] = i
+ 1;
6283 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6285 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6286 struct net_device
*dev
= info
->user_ptr
[1];
6287 struct cfg80211_ibss_params ibss
;
6288 struct wiphy
*wiphy
;
6289 struct cfg80211_cached_keys
*connkeys
= NULL
;
6292 memset(&ibss
, 0, sizeof(ibss
));
6294 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6297 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6298 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6301 ibss
.beacon_interval
= 100;
6303 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6304 ibss
.beacon_interval
=
6305 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6306 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6310 if (!rdev
->ops
->join_ibss
)
6313 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6316 wiphy
= &rdev
->wiphy
;
6318 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6319 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6321 if (!is_valid_ether_addr(ibss
.bssid
))
6324 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6325 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6327 if (info
->attrs
[NL80211_ATTR_IE
]) {
6328 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6329 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6332 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6336 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6339 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
6341 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
6342 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
6345 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6346 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6348 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6350 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6352 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6353 struct ieee80211_supported_band
*sband
=
6354 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6356 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6362 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6363 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6364 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6367 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6370 connkeys
= nl80211_parse_connkeys(rdev
,
6371 info
->attrs
[NL80211_ATTR_KEYS
],
6373 if (IS_ERR(connkeys
))
6374 return PTR_ERR(connkeys
);
6376 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6384 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6386 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6392 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6394 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6395 struct net_device
*dev
= info
->user_ptr
[1];
6397 if (!rdev
->ops
->leave_ibss
)
6400 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6403 return cfg80211_leave_ibss(rdev
, dev
, false);
6406 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6408 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6409 struct net_device
*dev
= info
->user_ptr
[1];
6410 int mcast_rate
[IEEE80211_NUM_BANDS
];
6414 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6415 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6418 if (!rdev
->ops
->set_mcast_rate
)
6421 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6423 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6426 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6427 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6430 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6435 static struct sk_buff
*
6436 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
6437 int approxlen
, u32 portid
, u32 seq
,
6438 enum nl80211_commands cmd
,
6439 enum nl80211_attrs attr
,
6440 const struct nl80211_vendor_cmd_info
*info
,
6443 struct sk_buff
*skb
;
6445 struct nlattr
*data
;
6447 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6451 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
6457 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6458 goto nla_put_failure
;
6461 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
6463 goto nla_put_failure
;
6464 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
6466 goto nla_put_failure
;
6469 data
= nla_nest_start(skb
, attr
);
6471 ((void **)skb
->cb
)[0] = rdev
;
6472 ((void **)skb
->cb
)[1] = hdr
;
6473 ((void **)skb
->cb
)[2] = data
;
6482 #ifdef CONFIG_NL80211_TESTMODE
6483 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6487 static struct genl_multicast_group nl80211_vendor_mcgrp
= {
6491 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6493 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6496 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6500 if (rdev
->ops
->testmode_cmd
) {
6501 rdev
->cur_cmd_info
= info
;
6502 err
= rdev_testmode_cmd(rdev
,
6503 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6504 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6505 rdev
->cur_cmd_info
= NULL
;
6511 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6512 struct netlink_callback
*cb
)
6514 struct cfg80211_registered_device
*rdev
;
6522 * 0 is a valid index, but not valid for args[0],
6523 * so we need to offset by 1.
6525 phy_idx
= cb
->args
[0] - 1;
6527 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6528 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6533 mutex_lock(&cfg80211_mutex
);
6534 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6535 nl80211_fam
.attrbuf
);
6537 mutex_unlock(&cfg80211_mutex
);
6538 return PTR_ERR(rdev
);
6540 phy_idx
= rdev
->wiphy_idx
;
6542 mutex_unlock(&cfg80211_mutex
);
6544 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6546 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6550 data
= nla_data((void *)cb
->args
[1]);
6551 data_len
= nla_len((void *)cb
->args
[1]);
6554 mutex_lock(&cfg80211_mutex
);
6555 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6557 mutex_unlock(&cfg80211_mutex
);
6560 cfg80211_lock_rdev(rdev
);
6561 mutex_unlock(&cfg80211_mutex
);
6563 if (!rdev
->ops
->testmode_dump
) {
6569 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6570 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6571 NL80211_CMD_TESTMODE
);
6572 struct nlattr
*tmdata
;
6577 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6578 genlmsg_cancel(skb
, hdr
);
6582 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6584 genlmsg_cancel(skb
, hdr
);
6587 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6588 nla_nest_end(skb
, tmdata
);
6590 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6591 genlmsg_cancel(skb
, hdr
);
6594 genlmsg_cancel(skb
, hdr
);
6598 genlmsg_end(skb
, hdr
);
6603 cb
->args
[0] = phy_idx
+ 1;
6605 cfg80211_unlock_rdev(rdev
);
6609 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
6610 enum nl80211_commands cmd
,
6611 enum nl80211_attrs attr
,
6612 int vendor_event_idx
,
6613 int approxlen
, gfp_t gfp
)
6615 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6616 const struct nl80211_vendor_cmd_info
*info
;
6619 case NL80211_CMD_TESTMODE
:
6620 if (WARN_ON(vendor_event_idx
!= -1))
6624 case NL80211_CMD_VENDOR
:
6625 if (WARN_ON(vendor_event_idx
< 0 ||
6626 vendor_event_idx
>= wiphy
->n_vendor_events
))
6628 info
= &wiphy
->vendor_events
[vendor_event_idx
];
6634 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
, 0, 0,
6635 cmd
, attr
, info
, gfp
);
6637 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
6639 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
6641 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6642 void *hdr
= ((void **)skb
->cb
)[1];
6643 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6645 /* clear CB data for netlink core to own from now on */
6646 memset(skb
->cb
, 0, sizeof(skb
->cb
));
6648 nla_nest_end(skb
, data
);
6649 genlmsg_end(skb
, hdr
);
6651 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
6652 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6653 nl80211_vendor_mcgrp
.id
, gfp
);
6655 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6656 nl80211_testmode_mcgrp
.id
, gfp
);
6658 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
6661 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6663 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6664 struct net_device
*dev
= info
->user_ptr
[1];
6665 struct cfg80211_connect_params connect
;
6666 struct wiphy
*wiphy
;
6667 struct cfg80211_cached_keys
*connkeys
= NULL
;
6670 memset(&connect
, 0, sizeof(connect
));
6672 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6675 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6676 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6679 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6681 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6682 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6683 NL80211_CMD_CONNECT
))
6686 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6688 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6690 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6691 NL80211_MAX_NR_CIPHER_SUITES
);
6695 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6696 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6699 wiphy
= &rdev
->wiphy
;
6701 connect
.bg_scan_period
= -1;
6702 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6703 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6704 connect
.bg_scan_period
=
6705 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6708 if (info
->attrs
[NL80211_ATTR_MAC
])
6709 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6710 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6711 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6713 if (info
->attrs
[NL80211_ATTR_IE
]) {
6714 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6715 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6718 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6719 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6720 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6721 connect
.mfp
!= NL80211_MFP_NO
)
6724 connect
.mfp
= NL80211_MFP_NO
;
6727 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6729 ieee80211_get_channel(wiphy
,
6730 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6731 if (!connect
.channel
||
6732 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6736 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6737 connkeys
= nl80211_parse_connkeys(rdev
,
6738 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6739 if (IS_ERR(connkeys
))
6740 return PTR_ERR(connkeys
);
6743 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6744 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6746 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6747 memcpy(&connect
.ht_capa_mask
,
6748 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6749 sizeof(connect
.ht_capa_mask
));
6751 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6752 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6756 memcpy(&connect
.ht_capa
,
6757 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6758 sizeof(connect
.ht_capa
));
6761 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6762 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6764 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6765 memcpy(&connect
.vht_capa_mask
,
6766 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6767 sizeof(connect
.vht_capa_mask
));
6769 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6770 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6774 memcpy(&connect
.vht_capa
,
6775 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6776 sizeof(connect
.vht_capa
));
6779 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
6785 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6787 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6788 struct net_device
*dev
= info
->user_ptr
[1];
6791 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6792 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6794 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6799 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6800 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6803 return cfg80211_disconnect(rdev
, dev
, reason
, true);
6806 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6808 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6813 if (!info
->attrs
[NL80211_ATTR_PID
])
6816 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6818 net
= get_net_ns_by_pid(pid
);
6820 return PTR_ERR(net
);
6824 /* check if anything to do */
6825 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6826 err
= cfg80211_switch_netns(rdev
, net
);
6832 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6834 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6835 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6836 struct cfg80211_pmksa
*pmksa
) = NULL
;
6837 struct net_device
*dev
= info
->user_ptr
[1];
6838 struct cfg80211_pmksa pmksa
;
6840 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6842 if (!info
->attrs
[NL80211_ATTR_MAC
])
6845 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6848 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6849 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6851 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6852 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6855 switch (info
->genlhdr
->cmd
) {
6856 case NL80211_CMD_SET_PMKSA
:
6857 rdev_ops
= rdev
->ops
->set_pmksa
;
6859 case NL80211_CMD_DEL_PMKSA
:
6860 rdev_ops
= rdev
->ops
->del_pmksa
;
6870 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6873 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6875 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6876 struct net_device
*dev
= info
->user_ptr
[1];
6878 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6879 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6882 if (!rdev
->ops
->flush_pmksa
)
6885 return rdev_flush_pmksa(rdev
, dev
);
6888 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6890 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6891 struct net_device
*dev
= info
->user_ptr
[1];
6892 u8 action_code
, dialog_token
;
6896 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6897 !rdev
->ops
->tdls_mgmt
)
6900 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6901 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6902 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6903 !info
->attrs
[NL80211_ATTR_IE
] ||
6904 !info
->attrs
[NL80211_ATTR_MAC
])
6907 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6908 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6909 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6910 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6912 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6913 dialog_token
, status_code
,
6914 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6915 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6918 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6920 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6921 struct net_device
*dev
= info
->user_ptr
[1];
6922 enum nl80211_tdls_operation operation
;
6925 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6926 !rdev
->ops
->tdls_oper
)
6929 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6930 !info
->attrs
[NL80211_ATTR_MAC
])
6933 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6934 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6936 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6939 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6940 struct genl_info
*info
)
6942 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6943 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6944 struct cfg80211_chan_def chandef
;
6945 struct sk_buff
*msg
;
6951 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6952 !info
->attrs
[NL80211_ATTR_DURATION
])
6955 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6957 if (!rdev
->ops
->remain_on_channel
||
6958 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6962 * We should be on that channel for at least a minimum amount of
6963 * time (10ms) but no longer than the driver supports.
6965 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6966 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6969 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6973 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6977 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6978 NL80211_CMD_REMAIN_ON_CHANNEL
);
6984 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6990 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6991 goto nla_put_failure
;
6993 genlmsg_end(msg
, hdr
);
6995 return genlmsg_reply(msg
, info
);
7004 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7005 struct genl_info
*info
)
7007 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7008 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7011 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7014 if (!rdev
->ops
->cancel_remain_on_channel
)
7017 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7019 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7022 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7023 u8
*rates
, u8 rates_len
)
7028 for (i
= 0; i
< rates_len
; i
++) {
7029 int rate
= (rates
[i
] & 0x7f) * 5;
7031 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7032 struct ieee80211_rate
*srate
=
7033 &sband
->bitrates
[ridx
];
7034 if (rate
== srate
->bitrate
) {
7039 if (ridx
== sband
->n_bitrates
)
7040 return 0; /* rate not found */
7046 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7047 u8
*rates
, u8 rates_len
,
7048 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7052 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7054 for (i
= 0; i
< rates_len
; i
++) {
7057 ridx
= rates
[i
] / 8;
7058 rbit
= BIT(rates
[i
] % 8);
7060 /* check validity */
7061 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7064 /* check availability */
7065 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7074 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7075 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7076 .len
= NL80211_MAX_SUPP_RATES
},
7077 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7078 .len
= NL80211_MAX_SUPP_HT_RATES
},
7081 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7082 struct genl_info
*info
)
7084 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7085 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7086 struct cfg80211_bitrate_mask mask
;
7088 struct net_device
*dev
= info
->user_ptr
[1];
7089 struct nlattr
*tx_rates
;
7090 struct ieee80211_supported_band
*sband
;
7092 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7095 if (!rdev
->ops
->set_bitrate_mask
)
7098 memset(&mask
, 0, sizeof(mask
));
7099 /* Default to all rates enabled */
7100 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7101 sband
= rdev
->wiphy
.bands
[i
];
7102 mask
.control
[i
].legacy
=
7103 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7105 memcpy(mask
.control
[i
].mcs
,
7106 sband
->ht_cap
.mcs
.rx_mask
,
7107 sizeof(mask
.control
[i
].mcs
));
7109 memset(mask
.control
[i
].mcs
, 0,
7110 sizeof(mask
.control
[i
].mcs
));
7114 * The nested attribute uses enum nl80211_band as the index. This maps
7115 * directly to the enum ieee80211_band values used in cfg80211.
7117 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7118 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7120 enum ieee80211_band band
= nla_type(tx_rates
);
7121 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7123 sband
= rdev
->wiphy
.bands
[band
];
7126 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7127 nla_len(tx_rates
), nl80211_txattr_policy
);
7128 if (tb
[NL80211_TXRATE_LEGACY
]) {
7129 mask
.control
[band
].legacy
= rateset_to_mask(
7131 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7132 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7133 if ((mask
.control
[band
].legacy
== 0) &&
7134 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7137 if (tb
[NL80211_TXRATE_MCS
]) {
7138 if (!ht_rateset_to_mask(
7140 nla_data(tb
[NL80211_TXRATE_MCS
]),
7141 nla_len(tb
[NL80211_TXRATE_MCS
]),
7142 mask
.control
[band
].mcs
))
7146 if (mask
.control
[band
].legacy
== 0) {
7147 /* don't allow empty legacy rates if HT
7148 * is not even supported. */
7149 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7152 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7153 if (mask
.control
[band
].mcs
[i
])
7156 /* legacy and mcs rates may not be both empty */
7157 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7162 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7165 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7167 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7168 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7169 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7171 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7174 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7175 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7177 switch (wdev
->iftype
) {
7178 case NL80211_IFTYPE_STATION
:
7179 case NL80211_IFTYPE_ADHOC
:
7180 case NL80211_IFTYPE_P2P_CLIENT
:
7181 case NL80211_IFTYPE_AP
:
7182 case NL80211_IFTYPE_AP_VLAN
:
7183 case NL80211_IFTYPE_MESH_POINT
:
7184 case NL80211_IFTYPE_P2P_GO
:
7185 case NL80211_IFTYPE_P2P_DEVICE
:
7191 /* not much point in registering if we can't reply */
7192 if (!rdev
->ops
->mgmt_tx
)
7195 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7196 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7197 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7200 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7202 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7203 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7204 struct cfg80211_chan_def chandef
;
7208 struct sk_buff
*msg
= NULL
;
7209 unsigned int wait
= 0;
7210 bool offchan
, no_cck
, dont_wait_for_ack
;
7212 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7214 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7217 if (!rdev
->ops
->mgmt_tx
)
7220 switch (wdev
->iftype
) {
7221 case NL80211_IFTYPE_STATION
:
7222 case NL80211_IFTYPE_ADHOC
:
7223 case NL80211_IFTYPE_P2P_CLIENT
:
7224 case NL80211_IFTYPE_AP
:
7225 case NL80211_IFTYPE_AP_VLAN
:
7226 case NL80211_IFTYPE_MESH_POINT
:
7227 case NL80211_IFTYPE_P2P_GO
:
7228 case NL80211_IFTYPE_P2P_DEVICE
:
7234 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7235 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7237 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7240 * We should wait on the channel for at least a minimum amount
7241 * of time (10ms) but no longer than the driver supports.
7243 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7244 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7249 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7251 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7254 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7256 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7260 if (!dont_wait_for_ack
) {
7261 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7265 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7273 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7274 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7275 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7276 no_cck
, dont_wait_for_ack
, &cookie
);
7281 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7282 goto nla_put_failure
;
7284 genlmsg_end(msg
, hdr
);
7285 return genlmsg_reply(msg
, info
);
7297 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7299 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7300 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7303 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7306 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7309 switch (wdev
->iftype
) {
7310 case NL80211_IFTYPE_STATION
:
7311 case NL80211_IFTYPE_ADHOC
:
7312 case NL80211_IFTYPE_P2P_CLIENT
:
7313 case NL80211_IFTYPE_AP
:
7314 case NL80211_IFTYPE_AP_VLAN
:
7315 case NL80211_IFTYPE_P2P_GO
:
7316 case NL80211_IFTYPE_P2P_DEVICE
:
7322 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7324 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7327 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7329 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7330 struct wireless_dev
*wdev
;
7331 struct net_device
*dev
= info
->user_ptr
[1];
7336 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7339 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7341 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7344 wdev
= dev
->ieee80211_ptr
;
7346 if (!rdev
->ops
->set_power_mgmt
)
7349 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7351 if (state
== wdev
->ps
)
7354 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7360 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7362 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7363 enum nl80211_ps_state ps_state
;
7364 struct wireless_dev
*wdev
;
7365 struct net_device
*dev
= info
->user_ptr
[1];
7366 struct sk_buff
*msg
;
7370 wdev
= dev
->ieee80211_ptr
;
7372 if (!rdev
->ops
->set_power_mgmt
)
7375 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7379 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7380 NL80211_CMD_GET_POWER_SAVE
);
7387 ps_state
= NL80211_PS_ENABLED
;
7389 ps_state
= NL80211_PS_DISABLED
;
7391 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7392 goto nla_put_failure
;
7394 genlmsg_end(msg
, hdr
);
7395 return genlmsg_reply(msg
, info
);
7404 static struct nla_policy
7405 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7406 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7407 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7408 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7409 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7410 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7411 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7414 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7415 u32 rate
, u32 pkts
, u32 intvl
)
7417 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7418 struct wireless_dev
*wdev
;
7419 struct net_device
*dev
= info
->user_ptr
[1];
7421 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7424 wdev
= dev
->ieee80211_ptr
;
7426 if (!rdev
->ops
->set_cqm_txe_config
)
7429 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7430 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7433 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7436 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7437 s32 threshold
, u32 hysteresis
)
7439 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7440 struct wireless_dev
*wdev
;
7441 struct net_device
*dev
= info
->user_ptr
[1];
7446 wdev
= dev
->ieee80211_ptr
;
7448 if (!rdev
->ops
->set_cqm_rssi_config
)
7451 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7452 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7455 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7458 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7460 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7464 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7470 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7471 nl80211_attr_cqm_policy
);
7475 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7476 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7479 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7480 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7481 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7482 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7483 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7484 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7485 u32 rate
, pkts
, intvl
;
7486 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7487 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7488 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7489 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7497 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7499 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7500 struct net_device
*dev
= info
->user_ptr
[1];
7501 struct mesh_config cfg
;
7502 struct mesh_setup setup
;
7505 /* start with default */
7506 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7507 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7509 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7510 /* and parse parameters if given */
7511 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7516 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7517 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7520 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7521 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7523 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7524 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7525 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7528 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7529 setup
.beacon_interval
=
7530 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7531 if (setup
.beacon_interval
< 10 ||
7532 setup
.beacon_interval
> 10000)
7536 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7538 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7539 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7543 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7544 /* parse additional setup parameters if given */
7545 err
= nl80211_parse_mesh_setup(info
, &setup
);
7551 cfg
.auto_open_plinks
= false;
7553 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7554 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7558 /* cfg80211_join_mesh() will sort it out */
7559 setup
.chandef
.chan
= NULL
;
7562 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7565 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7567 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7568 struct net_device
*dev
= info
->user_ptr
[1];
7570 return cfg80211_leave_mesh(rdev
, dev
);
7574 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7575 struct cfg80211_registered_device
*rdev
)
7577 struct nlattr
*nl_pats
, *nl_pat
;
7580 if (!rdev
->wowlan
->n_patterns
)
7583 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7587 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
7588 nl_pat
= nla_nest_start(msg
, i
+ 1);
7591 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
7592 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7593 DIV_ROUND_UP(pat_len
, 8),
7594 rdev
->wowlan
->patterns
[i
].mask
) ||
7595 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7596 pat_len
, rdev
->wowlan
->patterns
[i
].pattern
) ||
7597 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7598 rdev
->wowlan
->patterns
[i
].pkt_offset
))
7600 nla_nest_end(msg
, nl_pat
);
7602 nla_nest_end(msg
, nl_pats
);
7607 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7608 struct cfg80211_wowlan_tcp
*tcp
)
7610 struct nlattr
*nl_tcp
;
7615 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7619 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7620 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7621 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7622 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7623 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7624 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7625 tcp
->payload_len
, tcp
->payload
) ||
7626 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7627 tcp
->data_interval
) ||
7628 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7629 tcp
->wake_len
, tcp
->wake_data
) ||
7630 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7631 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7634 if (tcp
->payload_seq
.len
&&
7635 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7636 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7639 if (tcp
->payload_tok
.len
&&
7640 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7641 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7645 nla_nest_end(msg
, nl_tcp
);
7650 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7652 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7653 struct sk_buff
*msg
;
7655 u32 size
= NLMSG_DEFAULT_SIZE
;
7657 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7658 !rdev
->wiphy
.wowlan
.tcp
)
7661 if (rdev
->wowlan
&& rdev
->wowlan
->tcp
) {
7662 /* adjust size to have room for all the data */
7663 size
+= rdev
->wowlan
->tcp
->tokens_size
+
7664 rdev
->wowlan
->tcp
->payload_len
+
7665 rdev
->wowlan
->tcp
->wake_len
+
7666 rdev
->wowlan
->tcp
->wake_len
/ 8;
7669 msg
= nlmsg_new(size
, GFP_KERNEL
);
7673 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7674 NL80211_CMD_GET_WOWLAN
);
7676 goto nla_put_failure
;
7679 struct nlattr
*nl_wowlan
;
7681 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7683 goto nla_put_failure
;
7685 if ((rdev
->wowlan
->any
&&
7686 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7687 (rdev
->wowlan
->disconnect
&&
7688 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7689 (rdev
->wowlan
->magic_pkt
&&
7690 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7691 (rdev
->wowlan
->gtk_rekey_failure
&&
7692 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7693 (rdev
->wowlan
->eap_identity_req
&&
7694 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7695 (rdev
->wowlan
->four_way_handshake
&&
7696 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7697 (rdev
->wowlan
->rfkill_release
&&
7698 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7699 goto nla_put_failure
;
7701 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7702 goto nla_put_failure
;
7704 if (nl80211_send_wowlan_tcp(msg
, rdev
->wowlan
->tcp
))
7705 goto nla_put_failure
;
7707 nla_nest_end(msg
, nl_wowlan
);
7710 genlmsg_end(msg
, hdr
);
7711 return genlmsg_reply(msg
, info
);
7718 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7719 struct nlattr
*attr
,
7720 struct cfg80211_wowlan
*trig
)
7722 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7723 struct cfg80211_wowlan_tcp
*cfg
;
7724 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7725 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7727 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7730 if (!rdev
->wiphy
.wowlan
.tcp
)
7733 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7734 nla_data(attr
), nla_len(attr
),
7735 nl80211_wowlan_tcp_policy
);
7739 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7740 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7741 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7742 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7743 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7744 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7745 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7746 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7749 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7750 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7753 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7754 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
||
7755 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7758 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7759 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7762 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7763 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7766 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7767 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7769 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7770 tokens_size
= tokln
- sizeof(*tok
);
7772 if (!tok
->len
|| tokens_size
% tok
->len
)
7774 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7776 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7778 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7780 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7782 if (tok
->offset
+ tok
->len
> data_size
)
7786 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7787 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7788 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7790 if (seq
->len
== 0 || seq
->len
> 4)
7792 if (seq
->len
+ seq
->offset
> data_size
)
7796 size
= sizeof(*cfg
);
7798 size
+= wake_size
+ wake_mask_size
;
7799 size
+= tokens_size
;
7801 cfg
= kzalloc(size
, GFP_KERNEL
);
7804 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7805 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7806 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7808 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7809 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7813 /* allocate a socket and port for it and use it */
7814 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7815 IPPROTO_TCP
, &cfg
->sock
, 1);
7820 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7821 sock_release(cfg
->sock
);
7825 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7831 cfg
->src_port
= port
;
7834 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7835 cfg
->payload_len
= data_size
;
7836 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7837 memcpy((void *)cfg
->payload
,
7838 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7841 cfg
->payload_seq
= *seq
;
7842 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7843 cfg
->wake_len
= wake_size
;
7844 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7845 memcpy((void *)cfg
->wake_data
,
7846 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7848 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7849 data_size
+ wake_size
;
7850 memcpy((void *)cfg
->wake_mask
,
7851 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7854 cfg
->tokens_size
= tokens_size
;
7855 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7863 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7865 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7866 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7867 struct cfg80211_wowlan new_triggers
= {};
7868 struct cfg80211_wowlan
*ntrig
;
7869 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7871 bool prev_enabled
= rdev
->wowlan
;
7873 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7874 !rdev
->wiphy
.wowlan
.tcp
)
7877 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7878 cfg80211_rdev_free_wowlan(rdev
);
7879 rdev
->wowlan
= NULL
;
7883 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7884 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7885 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7886 nl80211_wowlan_policy
);
7890 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7891 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7893 new_triggers
.any
= true;
7896 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7897 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7899 new_triggers
.disconnect
= true;
7902 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7903 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7905 new_triggers
.magic_pkt
= true;
7908 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7911 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7912 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7914 new_triggers
.gtk_rekey_failure
= true;
7917 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7918 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7920 new_triggers
.eap_identity_req
= true;
7923 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7924 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7926 new_triggers
.four_way_handshake
= true;
7929 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7930 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7932 new_triggers
.rfkill_release
= true;
7935 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7938 int rem
, pat_len
, mask_len
, pkt_offset
;
7939 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7941 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7944 if (n_patterns
> wowlan
->n_patterns
)
7947 new_triggers
.patterns
= kcalloc(n_patterns
,
7948 sizeof(new_triggers
.patterns
[0]),
7950 if (!new_triggers
.patterns
)
7953 new_triggers
.n_patterns
= n_patterns
;
7956 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7958 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7959 nla_data(pat
), nla_len(pat
), NULL
);
7961 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7962 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7964 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7965 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7966 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7969 if (pat_len
> wowlan
->pattern_max_len
||
7970 pat_len
< wowlan
->pattern_min_len
)
7973 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7976 pkt_offset
= nla_get_u32(
7977 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7978 if (pkt_offset
> wowlan
->max_pkt_offset
)
7980 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7982 new_triggers
.patterns
[i
].mask
=
7983 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7984 if (!new_triggers
.patterns
[i
].mask
) {
7988 new_triggers
.patterns
[i
].pattern
=
7989 new_triggers
.patterns
[i
].mask
+ mask_len
;
7990 memcpy(new_triggers
.patterns
[i
].mask
,
7991 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7993 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7994 memcpy(new_triggers
.patterns
[i
].pattern
,
7995 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
8001 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8002 err
= nl80211_parse_wowlan_tcp(
8003 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8009 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8014 cfg80211_rdev_free_wowlan(rdev
);
8015 rdev
->wowlan
= ntrig
;
8018 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
8019 rdev_set_wakeup(rdev
, rdev
->wowlan
);
8023 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8024 kfree(new_triggers
.patterns
[i
].mask
);
8025 kfree(new_triggers
.patterns
);
8026 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8027 sock_release(new_triggers
.tcp
->sock
);
8028 kfree(new_triggers
.tcp
);
8033 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8035 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8036 struct net_device
*dev
= info
->user_ptr
[1];
8037 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8038 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8039 struct cfg80211_gtk_rekey_data rekey_data
;
8042 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8045 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8046 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8047 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8048 nl80211_rekey_policy
);
8052 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8054 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8056 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8059 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8061 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8063 memcpy(rekey_data
.replay_ctr
,
8064 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8065 NL80211_REPLAY_CTR_LEN
);
8068 if (!wdev
->current_bss
) {
8073 if (!rdev
->ops
->set_rekey_data
) {
8078 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8084 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8085 struct genl_info
*info
)
8087 struct net_device
*dev
= info
->user_ptr
[1];
8088 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8090 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8091 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8094 if (wdev
->ap_unexpected_nlportid
)
8097 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8101 static int nl80211_probe_client(struct sk_buff
*skb
,
8102 struct genl_info
*info
)
8104 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8105 struct net_device
*dev
= info
->user_ptr
[1];
8106 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8107 struct sk_buff
*msg
;
8113 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8114 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8117 if (!info
->attrs
[NL80211_ATTR_MAC
])
8120 if (!rdev
->ops
->probe_client
)
8123 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8127 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8128 NL80211_CMD_PROBE_CLIENT
);
8134 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8136 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8140 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8141 goto nla_put_failure
;
8143 genlmsg_end(msg
, hdr
);
8145 return genlmsg_reply(msg
, info
);
8154 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8156 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8157 struct cfg80211_beacon_registration
*reg
, *nreg
;
8160 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8163 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8167 /* First, check if already registered. */
8168 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8169 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8170 if (reg
->nlportid
== info
->snd_portid
) {
8175 /* Add it to the list */
8176 nreg
->nlportid
= info
->snd_portid
;
8177 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8179 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8183 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8188 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8190 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8191 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8194 if (!rdev
->ops
->start_p2p_device
)
8197 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8200 if (wdev
->p2p_started
)
8203 mutex_lock(&rdev
->devlist_mtx
);
8204 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8205 mutex_unlock(&rdev
->devlist_mtx
);
8209 err
= rdev_start_p2p_device(rdev
, wdev
);
8213 wdev
->p2p_started
= true;
8214 mutex_lock(&rdev
->devlist_mtx
);
8216 mutex_unlock(&rdev
->devlist_mtx
);
8221 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8223 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8224 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8226 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8229 if (!rdev
->ops
->stop_p2p_device
)
8232 mutex_lock(&rdev
->devlist_mtx
);
8233 mutex_lock(&rdev
->sched_scan_mtx
);
8234 cfg80211_stop_p2p_device(rdev
, wdev
);
8235 mutex_unlock(&rdev
->sched_scan_mtx
);
8236 mutex_unlock(&rdev
->devlist_mtx
);
8241 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8242 struct genl_info
*info
)
8245 struct sk_buff
*msg
;
8247 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8251 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8252 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8254 goto nla_put_failure
;
8256 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8257 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8258 goto nla_put_failure
;
8260 genlmsg_end(msg
, hdr
);
8261 return genlmsg_reply(msg
, info
);
8268 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8270 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8271 struct cfg80211_update_ft_ies_params ft_params
;
8272 struct net_device
*dev
= info
->user_ptr
[1];
8274 if (!rdev
->ops
->update_ft_ies
)
8277 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8278 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8281 memset(&ft_params
, 0, sizeof(ft_params
));
8282 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8283 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8284 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8286 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8289 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8290 struct genl_info
*info
)
8292 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8293 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8294 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8298 if (!rdev
->ops
->crit_proto_start
)
8301 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8304 if (rdev
->crit_proto_nlportid
)
8307 /* determine protocol if provided */
8308 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8309 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8311 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8314 /* timeout must be provided */
8315 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8319 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8321 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8324 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8326 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8331 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8332 struct genl_info
*info
)
8334 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8335 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8337 if (!rdev
->ops
->crit_proto_stop
)
8340 if (rdev
->crit_proto_nlportid
) {
8341 rdev
->crit_proto_nlportid
= 0;
8342 rdev_crit_proto_stop(rdev
, wdev
);
8347 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
8349 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8350 struct wireless_dev
*wdev
=
8351 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8355 if (!rdev
|| !rdev
->wiphy
.vendor_commands
)
8359 err
= PTR_ERR(wdev
);
8363 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8367 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
8368 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
8371 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
8372 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
8373 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
8374 const struct wiphy_vendor_command
*vcmd
;
8378 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
8380 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
8383 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
8384 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
8387 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
8391 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
8392 if (!wdev
->netdev
||
8393 !netif_running(wdev
->netdev
))
8400 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
8401 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8402 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8405 rdev
->cur_cmd_info
= info
;
8406 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
8408 rdev
->cur_cmd_info
= NULL
;
8415 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
8416 enum nl80211_commands cmd
,
8417 enum nl80211_attrs attr
,
8420 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8422 if (WARN_ON(!rdev
->cur_cmd_info
))
8425 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
,
8428 cmd
, attr
, NULL
, GFP_KERNEL
);
8430 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
8432 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
8434 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8435 void *hdr
= ((void **)skb
->cb
)[1];
8436 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8438 if (WARN_ON(!rdev
->cur_cmd_info
)) {
8443 nla_nest_end(skb
, data
);
8444 genlmsg_end(skb
, hdr
);
8445 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
8447 EXPORT_SYMBOL(cfg80211_vendor_cmd_reply
);
8449 #define NL80211_FLAG_NEED_WIPHY 0x01
8450 #define NL80211_FLAG_NEED_NETDEV 0x02
8451 #define NL80211_FLAG_NEED_RTNL 0x04
8452 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8453 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8454 NL80211_FLAG_CHECK_NETDEV_UP)
8455 #define NL80211_FLAG_NEED_WDEV 0x10
8456 /* If a netdev is associated, it must be UP, P2P must be started */
8457 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8458 NL80211_FLAG_CHECK_NETDEV_UP)
8460 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8461 struct genl_info
*info
)
8463 struct cfg80211_registered_device
*rdev
;
8464 struct wireless_dev
*wdev
;
8465 struct net_device
*dev
;
8466 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8471 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8472 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8476 return PTR_ERR(rdev
);
8478 info
->user_ptr
[0] = rdev
;
8479 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8480 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8481 mutex_lock(&cfg80211_mutex
);
8482 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8485 mutex_unlock(&cfg80211_mutex
);
8488 return PTR_ERR(wdev
);
8492 rdev
= wiphy_to_dev(wdev
->wiphy
);
8494 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8496 mutex_unlock(&cfg80211_mutex
);
8502 info
->user_ptr
[1] = dev
;
8504 info
->user_ptr
[1] = wdev
;
8508 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8509 !netif_running(dev
)) {
8510 mutex_unlock(&cfg80211_mutex
);
8517 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8518 if (!wdev
->p2p_started
) {
8519 mutex_unlock(&cfg80211_mutex
);
8526 cfg80211_lock_rdev(rdev
);
8528 mutex_unlock(&cfg80211_mutex
);
8530 info
->user_ptr
[0] = rdev
;
8536 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8537 struct genl_info
*info
)
8539 if (info
->user_ptr
[0])
8540 cfg80211_unlock_rdev(info
->user_ptr
[0]);
8541 if (info
->user_ptr
[1]) {
8542 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8543 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8546 dev_put(wdev
->netdev
);
8548 dev_put(info
->user_ptr
[1]);
8551 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8555 static struct genl_ops nl80211_ops
[] = {
8557 .cmd
= NL80211_CMD_GET_WIPHY
,
8558 .doit
= nl80211_get_wiphy
,
8559 .dumpit
= nl80211_dump_wiphy
,
8560 .policy
= nl80211_policy
,
8561 /* can be retrieved by unprivileged users */
8562 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
8565 .cmd
= NL80211_CMD_SET_WIPHY
,
8566 .doit
= nl80211_set_wiphy
,
8567 .policy
= nl80211_policy
,
8568 .flags
= GENL_ADMIN_PERM
,
8569 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8572 .cmd
= NL80211_CMD_GET_INTERFACE
,
8573 .doit
= nl80211_get_interface
,
8574 .dumpit
= nl80211_dump_interface
,
8575 .policy
= nl80211_policy
,
8576 /* can be retrieved by unprivileged users */
8577 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
8580 .cmd
= NL80211_CMD_SET_INTERFACE
,
8581 .doit
= nl80211_set_interface
,
8582 .policy
= nl80211_policy
,
8583 .flags
= GENL_ADMIN_PERM
,
8584 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8585 NL80211_FLAG_NEED_RTNL
,
8588 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8589 .doit
= nl80211_new_interface
,
8590 .policy
= nl80211_policy
,
8591 .flags
= GENL_ADMIN_PERM
,
8592 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8593 NL80211_FLAG_NEED_RTNL
,
8596 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8597 .doit
= nl80211_del_interface
,
8598 .policy
= nl80211_policy
,
8599 .flags
= GENL_ADMIN_PERM
,
8600 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8601 NL80211_FLAG_NEED_RTNL
,
8604 .cmd
= NL80211_CMD_GET_KEY
,
8605 .doit
= nl80211_get_key
,
8606 .policy
= nl80211_policy
,
8607 .flags
= GENL_ADMIN_PERM
,
8608 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8609 NL80211_FLAG_NEED_RTNL
,
8612 .cmd
= NL80211_CMD_SET_KEY
,
8613 .doit
= nl80211_set_key
,
8614 .policy
= nl80211_policy
,
8615 .flags
= GENL_ADMIN_PERM
,
8616 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8617 NL80211_FLAG_NEED_RTNL
,
8620 .cmd
= NL80211_CMD_NEW_KEY
,
8621 .doit
= nl80211_new_key
,
8622 .policy
= nl80211_policy
,
8623 .flags
= GENL_ADMIN_PERM
,
8624 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8625 NL80211_FLAG_NEED_RTNL
,
8628 .cmd
= NL80211_CMD_DEL_KEY
,
8629 .doit
= nl80211_del_key
,
8630 .policy
= nl80211_policy
,
8631 .flags
= GENL_ADMIN_PERM
,
8632 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8633 NL80211_FLAG_NEED_RTNL
,
8636 .cmd
= NL80211_CMD_SET_BEACON
,
8637 .policy
= nl80211_policy
,
8638 .flags
= GENL_ADMIN_PERM
,
8639 .doit
= nl80211_set_beacon
,
8640 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8641 NL80211_FLAG_NEED_RTNL
,
8644 .cmd
= NL80211_CMD_START_AP
,
8645 .policy
= nl80211_policy
,
8646 .flags
= GENL_ADMIN_PERM
,
8647 .doit
= nl80211_start_ap
,
8648 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8649 NL80211_FLAG_NEED_RTNL
,
8652 .cmd
= NL80211_CMD_STOP_AP
,
8653 .policy
= nl80211_policy
,
8654 .flags
= GENL_ADMIN_PERM
,
8655 .doit
= nl80211_stop_ap
,
8656 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8657 NL80211_FLAG_NEED_RTNL
,
8660 .cmd
= NL80211_CMD_GET_STATION
,
8661 .doit
= nl80211_get_station
,
8662 .dumpit
= nl80211_dump_station
,
8663 .policy
= nl80211_policy
,
8664 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8665 NL80211_FLAG_NEED_RTNL
,
8668 .cmd
= NL80211_CMD_SET_STATION
,
8669 .doit
= nl80211_set_station
,
8670 .policy
= nl80211_policy
,
8671 .flags
= GENL_ADMIN_PERM
,
8672 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8673 NL80211_FLAG_NEED_RTNL
,
8676 .cmd
= NL80211_CMD_NEW_STATION
,
8677 .doit
= nl80211_new_station
,
8678 .policy
= nl80211_policy
,
8679 .flags
= GENL_ADMIN_PERM
,
8680 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8681 NL80211_FLAG_NEED_RTNL
,
8684 .cmd
= NL80211_CMD_DEL_STATION
,
8685 .doit
= nl80211_del_station
,
8686 .policy
= nl80211_policy
,
8687 .flags
= GENL_ADMIN_PERM
,
8688 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8689 NL80211_FLAG_NEED_RTNL
,
8692 .cmd
= NL80211_CMD_GET_MPATH
,
8693 .doit
= nl80211_get_mpath
,
8694 .dumpit
= nl80211_dump_mpath
,
8695 .policy
= nl80211_policy
,
8696 .flags
= GENL_ADMIN_PERM
,
8697 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8698 NL80211_FLAG_NEED_RTNL
,
8701 .cmd
= NL80211_CMD_SET_MPATH
,
8702 .doit
= nl80211_set_mpath
,
8703 .policy
= nl80211_policy
,
8704 .flags
= GENL_ADMIN_PERM
,
8705 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8706 NL80211_FLAG_NEED_RTNL
,
8709 .cmd
= NL80211_CMD_NEW_MPATH
,
8710 .doit
= nl80211_new_mpath
,
8711 .policy
= nl80211_policy
,
8712 .flags
= GENL_ADMIN_PERM
,
8713 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8714 NL80211_FLAG_NEED_RTNL
,
8717 .cmd
= NL80211_CMD_DEL_MPATH
,
8718 .doit
= nl80211_del_mpath
,
8719 .policy
= nl80211_policy
,
8720 .flags
= GENL_ADMIN_PERM
,
8721 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8722 NL80211_FLAG_NEED_RTNL
,
8725 .cmd
= NL80211_CMD_SET_BSS
,
8726 .doit
= nl80211_set_bss
,
8727 .policy
= nl80211_policy
,
8728 .flags
= GENL_ADMIN_PERM
,
8729 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8730 NL80211_FLAG_NEED_RTNL
,
8733 .cmd
= NL80211_CMD_GET_REG
,
8734 .doit
= nl80211_get_reg
,
8735 .policy
= nl80211_policy
,
8736 /* can be retrieved by unprivileged users */
8739 .cmd
= NL80211_CMD_SET_REG
,
8740 .doit
= nl80211_set_reg
,
8741 .policy
= nl80211_policy
,
8742 .flags
= GENL_ADMIN_PERM
,
8745 .cmd
= NL80211_CMD_REQ_SET_REG
,
8746 .doit
= nl80211_req_set_reg
,
8747 .policy
= nl80211_policy
,
8748 .flags
= GENL_ADMIN_PERM
,
8751 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8752 .doit
= nl80211_get_mesh_config
,
8753 .policy
= nl80211_policy
,
8754 /* can be retrieved by unprivileged users */
8755 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8756 NL80211_FLAG_NEED_RTNL
,
8759 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8760 .doit
= nl80211_update_mesh_config
,
8761 .policy
= nl80211_policy
,
8762 .flags
= GENL_ADMIN_PERM
,
8763 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8764 NL80211_FLAG_NEED_RTNL
,
8767 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8768 .doit
= nl80211_trigger_scan
,
8769 .policy
= nl80211_policy
,
8770 .flags
= GENL_ADMIN_PERM
,
8771 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8772 NL80211_FLAG_NEED_RTNL
,
8775 .cmd
= NL80211_CMD_GET_SCAN
,
8776 .policy
= nl80211_policy
,
8777 .dumpit
= nl80211_dump_scan
,
8780 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8781 .doit
= nl80211_start_sched_scan
,
8782 .policy
= nl80211_policy
,
8783 .flags
= GENL_ADMIN_PERM
,
8784 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8785 NL80211_FLAG_NEED_RTNL
,
8788 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8789 .doit
= nl80211_stop_sched_scan
,
8790 .policy
= nl80211_policy
,
8791 .flags
= GENL_ADMIN_PERM
,
8792 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8793 NL80211_FLAG_NEED_RTNL
,
8796 .cmd
= NL80211_CMD_AUTHENTICATE
,
8797 .doit
= nl80211_authenticate
,
8798 .policy
= nl80211_policy
,
8799 .flags
= GENL_ADMIN_PERM
,
8800 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8801 NL80211_FLAG_NEED_RTNL
,
8804 .cmd
= NL80211_CMD_ASSOCIATE
,
8805 .doit
= nl80211_associate
,
8806 .policy
= nl80211_policy
,
8807 .flags
= GENL_ADMIN_PERM
,
8808 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8809 NL80211_FLAG_NEED_RTNL
,
8812 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8813 .doit
= nl80211_deauthenticate
,
8814 .policy
= nl80211_policy
,
8815 .flags
= GENL_ADMIN_PERM
,
8816 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8817 NL80211_FLAG_NEED_RTNL
,
8820 .cmd
= NL80211_CMD_DISASSOCIATE
,
8821 .doit
= nl80211_disassociate
,
8822 .policy
= nl80211_policy
,
8823 .flags
= GENL_ADMIN_PERM
,
8824 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8825 NL80211_FLAG_NEED_RTNL
,
8828 .cmd
= NL80211_CMD_JOIN_IBSS
,
8829 .doit
= nl80211_join_ibss
,
8830 .policy
= nl80211_policy
,
8831 .flags
= GENL_ADMIN_PERM
,
8832 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8833 NL80211_FLAG_NEED_RTNL
,
8836 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8837 .doit
= nl80211_leave_ibss
,
8838 .policy
= nl80211_policy
,
8839 .flags
= GENL_ADMIN_PERM
,
8840 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8841 NL80211_FLAG_NEED_RTNL
,
8843 #ifdef CONFIG_NL80211_TESTMODE
8845 .cmd
= NL80211_CMD_TESTMODE
,
8846 .doit
= nl80211_testmode_do
,
8847 .dumpit
= nl80211_testmode_dump
,
8848 .policy
= nl80211_policy
,
8849 .flags
= GENL_ADMIN_PERM
,
8850 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8851 NL80211_FLAG_NEED_RTNL
,
8855 .cmd
= NL80211_CMD_CONNECT
,
8856 .doit
= nl80211_connect
,
8857 .policy
= nl80211_policy
,
8858 .flags
= GENL_ADMIN_PERM
,
8859 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8860 NL80211_FLAG_NEED_RTNL
,
8863 .cmd
= NL80211_CMD_DISCONNECT
,
8864 .doit
= nl80211_disconnect
,
8865 .policy
= nl80211_policy
,
8866 .flags
= GENL_ADMIN_PERM
,
8867 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8868 NL80211_FLAG_NEED_RTNL
,
8871 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8872 .doit
= nl80211_wiphy_netns
,
8873 .policy
= nl80211_policy
,
8874 .flags
= GENL_ADMIN_PERM
,
8875 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8876 NL80211_FLAG_NEED_RTNL
,
8879 .cmd
= NL80211_CMD_GET_SURVEY
,
8880 .policy
= nl80211_policy
,
8881 .dumpit
= nl80211_dump_survey
,
8884 .cmd
= NL80211_CMD_SET_PMKSA
,
8885 .doit
= nl80211_setdel_pmksa
,
8886 .policy
= nl80211_policy
,
8887 .flags
= GENL_ADMIN_PERM
,
8888 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8889 NL80211_FLAG_NEED_RTNL
,
8892 .cmd
= NL80211_CMD_DEL_PMKSA
,
8893 .doit
= nl80211_setdel_pmksa
,
8894 .policy
= nl80211_policy
,
8895 .flags
= GENL_ADMIN_PERM
,
8896 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8897 NL80211_FLAG_NEED_RTNL
,
8900 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8901 .doit
= nl80211_flush_pmksa
,
8902 .policy
= nl80211_policy
,
8903 .flags
= GENL_ADMIN_PERM
,
8904 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8905 NL80211_FLAG_NEED_RTNL
,
8908 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8909 .doit
= nl80211_remain_on_channel
,
8910 .policy
= nl80211_policy
,
8911 .flags
= GENL_ADMIN_PERM
,
8912 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8913 NL80211_FLAG_NEED_RTNL
,
8916 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8917 .doit
= nl80211_cancel_remain_on_channel
,
8918 .policy
= nl80211_policy
,
8919 .flags
= GENL_ADMIN_PERM
,
8920 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8921 NL80211_FLAG_NEED_RTNL
,
8924 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8925 .doit
= nl80211_set_tx_bitrate_mask
,
8926 .policy
= nl80211_policy
,
8927 .flags
= GENL_ADMIN_PERM
,
8928 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8929 NL80211_FLAG_NEED_RTNL
,
8932 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8933 .doit
= nl80211_register_mgmt
,
8934 .policy
= nl80211_policy
,
8935 .flags
= GENL_ADMIN_PERM
,
8936 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8937 NL80211_FLAG_NEED_RTNL
,
8940 .cmd
= NL80211_CMD_FRAME
,
8941 .doit
= nl80211_tx_mgmt
,
8942 .policy
= nl80211_policy
,
8943 .flags
= GENL_ADMIN_PERM
,
8944 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8945 NL80211_FLAG_NEED_RTNL
,
8948 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8949 .doit
= nl80211_tx_mgmt_cancel_wait
,
8950 .policy
= nl80211_policy
,
8951 .flags
= GENL_ADMIN_PERM
,
8952 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8953 NL80211_FLAG_NEED_RTNL
,
8956 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8957 .doit
= nl80211_set_power_save
,
8958 .policy
= nl80211_policy
,
8959 .flags
= GENL_ADMIN_PERM
,
8960 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8961 NL80211_FLAG_NEED_RTNL
,
8964 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8965 .doit
= nl80211_get_power_save
,
8966 .policy
= nl80211_policy
,
8967 /* can be retrieved by unprivileged users */
8968 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8969 NL80211_FLAG_NEED_RTNL
,
8972 .cmd
= NL80211_CMD_SET_CQM
,
8973 .doit
= nl80211_set_cqm
,
8974 .policy
= nl80211_policy
,
8975 .flags
= GENL_ADMIN_PERM
,
8976 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8977 NL80211_FLAG_NEED_RTNL
,
8980 .cmd
= NL80211_CMD_SET_CHANNEL
,
8981 .doit
= nl80211_set_channel
,
8982 .policy
= nl80211_policy
,
8983 .flags
= GENL_ADMIN_PERM
,
8984 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8985 NL80211_FLAG_NEED_RTNL
,
8988 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8989 .doit
= nl80211_set_wds_peer
,
8990 .policy
= nl80211_policy
,
8991 .flags
= GENL_ADMIN_PERM
,
8992 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8993 NL80211_FLAG_NEED_RTNL
,
8996 .cmd
= NL80211_CMD_JOIN_MESH
,
8997 .doit
= nl80211_join_mesh
,
8998 .policy
= nl80211_policy
,
8999 .flags
= GENL_ADMIN_PERM
,
9000 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9001 NL80211_FLAG_NEED_RTNL
,
9004 .cmd
= NL80211_CMD_LEAVE_MESH
,
9005 .doit
= nl80211_leave_mesh
,
9006 .policy
= nl80211_policy
,
9007 .flags
= GENL_ADMIN_PERM
,
9008 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9009 NL80211_FLAG_NEED_RTNL
,
9013 .cmd
= NL80211_CMD_GET_WOWLAN
,
9014 .doit
= nl80211_get_wowlan
,
9015 .policy
= nl80211_policy
,
9016 /* can be retrieved by unprivileged users */
9017 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9018 NL80211_FLAG_NEED_RTNL
,
9021 .cmd
= NL80211_CMD_SET_WOWLAN
,
9022 .doit
= nl80211_set_wowlan
,
9023 .policy
= nl80211_policy
,
9024 .flags
= GENL_ADMIN_PERM
,
9025 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9026 NL80211_FLAG_NEED_RTNL
,
9030 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9031 .doit
= nl80211_set_rekey_data
,
9032 .policy
= nl80211_policy
,
9033 .flags
= GENL_ADMIN_PERM
,
9034 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9035 NL80211_FLAG_NEED_RTNL
,
9038 .cmd
= NL80211_CMD_TDLS_MGMT
,
9039 .doit
= nl80211_tdls_mgmt
,
9040 .policy
= nl80211_policy
,
9041 .flags
= GENL_ADMIN_PERM
,
9042 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9043 NL80211_FLAG_NEED_RTNL
,
9046 .cmd
= NL80211_CMD_TDLS_OPER
,
9047 .doit
= nl80211_tdls_oper
,
9048 .policy
= nl80211_policy
,
9049 .flags
= GENL_ADMIN_PERM
,
9050 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9051 NL80211_FLAG_NEED_RTNL
,
9054 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9055 .doit
= nl80211_register_unexpected_frame
,
9056 .policy
= nl80211_policy
,
9057 .flags
= GENL_ADMIN_PERM
,
9058 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9059 NL80211_FLAG_NEED_RTNL
,
9062 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9063 .doit
= nl80211_probe_client
,
9064 .policy
= nl80211_policy
,
9065 .flags
= GENL_ADMIN_PERM
,
9066 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9067 NL80211_FLAG_NEED_RTNL
,
9070 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9071 .doit
= nl80211_register_beacons
,
9072 .policy
= nl80211_policy
,
9073 .flags
= GENL_ADMIN_PERM
,
9074 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9075 NL80211_FLAG_NEED_RTNL
,
9078 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
9079 .doit
= nl80211_set_noack_map
,
9080 .policy
= nl80211_policy
,
9081 .flags
= GENL_ADMIN_PERM
,
9082 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9083 NL80211_FLAG_NEED_RTNL
,
9086 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
9087 .doit
= nl80211_start_p2p_device
,
9088 .policy
= nl80211_policy
,
9089 .flags
= GENL_ADMIN_PERM
,
9090 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9091 NL80211_FLAG_NEED_RTNL
,
9094 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
9095 .doit
= nl80211_stop_p2p_device
,
9096 .policy
= nl80211_policy
,
9097 .flags
= GENL_ADMIN_PERM
,
9098 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9099 NL80211_FLAG_NEED_RTNL
,
9102 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
9103 .doit
= nl80211_set_mcast_rate
,
9104 .policy
= nl80211_policy
,
9105 .flags
= GENL_ADMIN_PERM
,
9106 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9107 NL80211_FLAG_NEED_RTNL
,
9110 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9111 .doit
= nl80211_set_mac_acl
,
9112 .policy
= nl80211_policy
,
9113 .flags
= GENL_ADMIN_PERM
,
9114 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9115 NL80211_FLAG_NEED_RTNL
,
9118 .cmd
= NL80211_CMD_RADAR_DETECT
,
9119 .doit
= nl80211_start_radar_detection
,
9120 .policy
= nl80211_policy
,
9121 .flags
= GENL_ADMIN_PERM
,
9122 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9123 NL80211_FLAG_NEED_RTNL
,
9126 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9127 .doit
= nl80211_get_protocol_features
,
9128 .policy
= nl80211_policy
,
9131 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9132 .doit
= nl80211_update_ft_ies
,
9133 .policy
= nl80211_policy
,
9134 .flags
= GENL_ADMIN_PERM
,
9135 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9136 NL80211_FLAG_NEED_RTNL
,
9139 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9140 .doit
= nl80211_crit_protocol_start
,
9141 .policy
= nl80211_policy
,
9142 .flags
= GENL_ADMIN_PERM
,
9143 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9144 NL80211_FLAG_NEED_RTNL
,
9147 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9148 .doit
= nl80211_crit_protocol_stop
,
9149 .policy
= nl80211_policy
,
9150 .flags
= GENL_ADMIN_PERM
,
9151 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9152 NL80211_FLAG_NEED_RTNL
,
9155 .cmd
= NL80211_CMD_VENDOR
,
9156 .doit
= nl80211_vendor_cmd
,
9157 .policy
= nl80211_policy
,
9158 .flags
= GENL_ADMIN_PERM
,
9159 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9160 NL80211_FLAG_NEED_RTNL
,
9164 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9168 /* multicast groups */
9169 static struct genl_multicast_group nl80211_config_mcgrp
= {
9172 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9175 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9176 .name
= "regulatory",
9179 /* notification functions */
9181 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9183 struct sk_buff
*msg
;
9185 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9189 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0,
9190 false, NULL
, NULL
, NULL
) < 0) {
9195 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9196 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9199 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9200 struct cfg80211_registered_device
*rdev
)
9202 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9203 struct nlattr
*nest
;
9206 lockdep_assert_held(&rdev
->sched_scan_mtx
);
9211 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9213 goto nla_put_failure
;
9214 for (i
= 0; i
< req
->n_ssids
; i
++) {
9215 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9216 goto nla_put_failure
;
9218 nla_nest_end(msg
, nest
);
9220 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9222 goto nla_put_failure
;
9223 for (i
= 0; i
< req
->n_channels
; i
++) {
9224 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9225 goto nla_put_failure
;
9227 nla_nest_end(msg
, nest
);
9230 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9231 goto nla_put_failure
;
9234 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9241 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9242 struct cfg80211_registered_device
*rdev
,
9243 struct wireless_dev
*wdev
,
9244 u32 portid
, u32 seq
, int flags
,
9249 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9253 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9254 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9255 wdev
->netdev
->ifindex
)) ||
9256 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9257 goto nla_put_failure
;
9259 /* ignore errors and send incomplete event anyway */
9260 nl80211_add_scan_req(msg
, rdev
);
9262 return genlmsg_end(msg
, hdr
);
9265 genlmsg_cancel(msg
, hdr
);
9270 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9271 struct cfg80211_registered_device
*rdev
,
9272 struct net_device
*netdev
,
9273 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9277 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9281 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9282 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9283 goto nla_put_failure
;
9285 return genlmsg_end(msg
, hdr
);
9288 genlmsg_cancel(msg
, hdr
);
9292 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9293 struct wireless_dev
*wdev
)
9295 struct sk_buff
*msg
;
9297 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9301 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9302 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9307 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9308 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9311 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9312 struct wireless_dev
*wdev
)
9314 struct sk_buff
*msg
;
9316 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9320 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9321 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9326 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9327 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9330 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9331 struct wireless_dev
*wdev
)
9333 struct sk_buff
*msg
;
9335 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9339 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9340 NL80211_CMD_SCAN_ABORTED
) < 0) {
9345 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9346 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9349 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9350 struct net_device
*netdev
)
9352 struct sk_buff
*msg
;
9354 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9358 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9359 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9364 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9365 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9368 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9369 struct net_device
*netdev
, u32 cmd
)
9371 struct sk_buff
*msg
;
9373 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9377 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9382 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9383 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9387 * This can happen on global regulatory changes or device specific settings
9388 * based on custom world regulatory domains.
9390 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9392 struct sk_buff
*msg
;
9395 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9399 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9405 /* Userspace can always count this one always being set */
9406 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9407 goto nla_put_failure
;
9409 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9410 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9411 NL80211_REGDOM_TYPE_WORLD
))
9412 goto nla_put_failure
;
9413 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9414 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9415 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9416 goto nla_put_failure
;
9417 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9418 request
->intersect
) {
9419 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9420 NL80211_REGDOM_TYPE_INTERSECTION
))
9421 goto nla_put_failure
;
9423 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9424 NL80211_REGDOM_TYPE_COUNTRY
) ||
9425 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9427 goto nla_put_failure
;
9430 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9431 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9432 goto nla_put_failure
;
9434 genlmsg_end(msg
, hdr
);
9437 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9444 genlmsg_cancel(msg
, hdr
);
9448 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9449 struct net_device
*netdev
,
9450 const u8
*buf
, size_t len
,
9451 enum nl80211_commands cmd
, gfp_t gfp
)
9453 struct sk_buff
*msg
;
9456 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9460 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9466 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9467 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9468 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9469 goto nla_put_failure
;
9471 genlmsg_end(msg
, hdr
);
9473 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9474 nl80211_mlme_mcgrp
.id
, gfp
);
9478 genlmsg_cancel(msg
, hdr
);
9482 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9483 struct net_device
*netdev
, const u8
*buf
,
9484 size_t len
, gfp_t gfp
)
9486 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9487 NL80211_CMD_AUTHENTICATE
, gfp
);
9490 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9491 struct net_device
*netdev
, const u8
*buf
,
9492 size_t len
, gfp_t gfp
)
9494 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9495 NL80211_CMD_ASSOCIATE
, gfp
);
9498 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9499 struct net_device
*netdev
, const u8
*buf
,
9500 size_t len
, gfp_t gfp
)
9502 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9503 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9506 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9507 struct net_device
*netdev
, const u8
*buf
,
9508 size_t len
, gfp_t gfp
)
9510 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9511 NL80211_CMD_DISASSOCIATE
, gfp
);
9514 void cfg80211_send_unprot_deauth(struct net_device
*dev
, const u8
*buf
,
9517 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9518 struct wiphy
*wiphy
= wdev
->wiphy
;
9519 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9521 trace_cfg80211_send_unprot_deauth(dev
);
9522 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9523 NL80211_CMD_UNPROT_DEAUTHENTICATE
, GFP_ATOMIC
);
9525 EXPORT_SYMBOL(cfg80211_send_unprot_deauth
);
9527 void cfg80211_send_unprot_disassoc(struct net_device
*dev
, const u8
*buf
,
9530 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9531 struct wiphy
*wiphy
= wdev
->wiphy
;
9532 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9534 trace_cfg80211_send_unprot_disassoc(dev
);
9535 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9536 NL80211_CMD_UNPROT_DISASSOCIATE
, GFP_ATOMIC
);
9538 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc
);
9540 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9541 struct net_device
*netdev
, int cmd
,
9542 const u8
*addr
, gfp_t gfp
)
9544 struct sk_buff
*msg
;
9547 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9551 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9557 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9558 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9559 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9560 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9561 goto nla_put_failure
;
9563 genlmsg_end(msg
, hdr
);
9565 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9566 nl80211_mlme_mcgrp
.id
, gfp
);
9570 genlmsg_cancel(msg
, hdr
);
9574 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9575 struct net_device
*netdev
, const u8
*addr
,
9578 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9582 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9583 struct net_device
*netdev
, const u8
*addr
,
9586 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9590 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9591 struct net_device
*netdev
, const u8
*bssid
,
9592 const u8
*req_ie
, size_t req_ie_len
,
9593 const u8
*resp_ie
, size_t resp_ie_len
,
9594 u16 status
, gfp_t gfp
)
9596 struct sk_buff
*msg
;
9599 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9603 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9609 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9610 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9611 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9612 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9614 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9616 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9617 goto nla_put_failure
;
9619 genlmsg_end(msg
, hdr
);
9621 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9622 nl80211_mlme_mcgrp
.id
, gfp
);
9626 genlmsg_cancel(msg
, hdr
);
9631 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9632 struct net_device
*netdev
, const u8
*bssid
,
9633 const u8
*req_ie
, size_t req_ie_len
,
9634 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9636 struct sk_buff
*msg
;
9639 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9643 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9649 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9650 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9651 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9653 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9655 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9656 goto nla_put_failure
;
9658 genlmsg_end(msg
, hdr
);
9660 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9661 nl80211_mlme_mcgrp
.id
, gfp
);
9665 genlmsg_cancel(msg
, hdr
);
9670 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9671 struct net_device
*netdev
, u16 reason
,
9672 const u8
*ie
, size_t ie_len
, bool from_ap
)
9674 struct sk_buff
*msg
;
9677 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9681 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9687 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9688 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9689 (from_ap
&& reason
&&
9690 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9692 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9693 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9694 goto nla_put_failure
;
9696 genlmsg_end(msg
, hdr
);
9698 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9699 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9703 genlmsg_cancel(msg
, hdr
);
9708 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9709 struct net_device
*netdev
, const u8
*bssid
,
9712 struct sk_buff
*msg
;
9715 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9719 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9725 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9726 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9727 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9728 goto nla_put_failure
;
9730 genlmsg_end(msg
, hdr
);
9732 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9733 nl80211_mlme_mcgrp
.id
, gfp
);
9737 genlmsg_cancel(msg
, hdr
);
9741 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9742 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9744 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9745 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9746 struct sk_buff
*msg
;
9749 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9752 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9754 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9758 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9764 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9765 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9766 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9768 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9769 goto nla_put_failure
;
9771 genlmsg_end(msg
, hdr
);
9773 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9774 nl80211_mlme_mcgrp
.id
, gfp
);
9778 genlmsg_cancel(msg
, hdr
);
9781 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9783 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9784 struct net_device
*netdev
, const u8
*addr
,
9785 enum nl80211_key_type key_type
, int key_id
,
9786 const u8
*tsc
, gfp_t gfp
)
9788 struct sk_buff
*msg
;
9791 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9795 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9801 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9802 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9803 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9804 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9806 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9807 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9808 goto nla_put_failure
;
9810 genlmsg_end(msg
, hdr
);
9812 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9813 nl80211_mlme_mcgrp
.id
, gfp
);
9817 genlmsg_cancel(msg
, hdr
);
9821 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9822 struct ieee80211_channel
*channel_before
,
9823 struct ieee80211_channel
*channel_after
)
9825 struct sk_buff
*msg
;
9827 struct nlattr
*nl_freq
;
9829 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9833 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9840 * Since we are applying the beacon hint to a wiphy we know its
9841 * wiphy_idx is valid
9843 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9844 goto nla_put_failure
;
9847 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9849 goto nla_put_failure
;
9850 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9851 goto nla_put_failure
;
9852 nla_nest_end(msg
, nl_freq
);
9855 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9857 goto nla_put_failure
;
9858 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9859 goto nla_put_failure
;
9860 nla_nest_end(msg
, nl_freq
);
9862 genlmsg_end(msg
, hdr
);
9865 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9872 genlmsg_cancel(msg
, hdr
);
9876 static void nl80211_send_remain_on_chan_event(
9877 int cmd
, struct cfg80211_registered_device
*rdev
,
9878 struct wireless_dev
*wdev
, u64 cookie
,
9879 struct ieee80211_channel
*chan
,
9880 unsigned int duration
, gfp_t gfp
)
9882 struct sk_buff
*msg
;
9885 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9889 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9895 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9896 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9897 wdev
->netdev
->ifindex
)) ||
9898 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9899 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9900 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9901 NL80211_CHAN_NO_HT
) ||
9902 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9903 goto nla_put_failure
;
9905 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9906 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9907 goto nla_put_failure
;
9909 genlmsg_end(msg
, hdr
);
9911 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9912 nl80211_mlme_mcgrp
.id
, gfp
);
9916 genlmsg_cancel(msg
, hdr
);
9920 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9921 struct ieee80211_channel
*chan
,
9922 unsigned int duration
, gfp_t gfp
)
9924 struct wiphy
*wiphy
= wdev
->wiphy
;
9925 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9927 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9928 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9929 rdev
, wdev
, cookie
, chan
,
9932 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9934 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9935 struct ieee80211_channel
*chan
,
9938 struct wiphy
*wiphy
= wdev
->wiphy
;
9939 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9941 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9942 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9943 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9945 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9947 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9948 struct station_info
*sinfo
, gfp_t gfp
)
9950 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9951 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9952 struct sk_buff
*msg
;
9954 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9956 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9960 if (nl80211_send_station(msg
, 0, 0, 0,
9961 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9966 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9967 nl80211_mlme_mcgrp
.id
, gfp
);
9969 EXPORT_SYMBOL(cfg80211_new_sta
);
9971 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9973 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9974 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9975 struct sk_buff
*msg
;
9978 trace_cfg80211_del_sta(dev
, mac_addr
);
9980 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9984 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9990 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9991 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9992 goto nla_put_failure
;
9994 genlmsg_end(msg
, hdr
);
9996 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9997 nl80211_mlme_mcgrp
.id
, gfp
);
10001 genlmsg_cancel(msg
, hdr
);
10004 EXPORT_SYMBOL(cfg80211_del_sta
);
10006 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10007 enum nl80211_connect_failed_reason reason
,
10010 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10011 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10012 struct sk_buff
*msg
;
10015 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10019 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10025 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10026 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10027 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10028 goto nla_put_failure
;
10030 genlmsg_end(msg
, hdr
);
10032 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10033 nl80211_mlme_mcgrp
.id
, gfp
);
10037 genlmsg_cancel(msg
, hdr
);
10040 EXPORT_SYMBOL(cfg80211_conn_failed
);
10042 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10043 const u8
*addr
, gfp_t gfp
)
10045 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10046 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10047 struct sk_buff
*msg
;
10050 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10055 msg
= nlmsg_new(100, gfp
);
10059 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10065 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10066 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10067 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10068 goto nla_put_failure
;
10070 err
= genlmsg_end(msg
, hdr
);
10076 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10080 genlmsg_cancel(msg
, hdr
);
10085 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
10086 const u8
*addr
, gfp_t gfp
)
10088 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10091 trace_cfg80211_rx_spurious_frame(dev
, addr
);
10093 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10094 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
10095 trace_cfg80211_return_bool(false);
10098 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
10100 trace_cfg80211_return_bool(ret
);
10103 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
10105 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
10106 const u8
*addr
, gfp_t gfp
)
10108 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10111 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
10113 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10114 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10115 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
10116 trace_cfg80211_return_bool(false);
10119 ret
= __nl80211_unexpected_frame(dev
,
10120 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
10122 trace_cfg80211_return_bool(ret
);
10125 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10127 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10128 struct wireless_dev
*wdev
, u32 nlportid
,
10129 int freq
, int sig_dbm
,
10130 const u8
*buf
, size_t len
, gfp_t gfp
)
10132 struct net_device
*netdev
= wdev
->netdev
;
10133 struct sk_buff
*msg
;
10136 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10140 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10146 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10147 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10148 netdev
->ifindex
)) ||
10149 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10150 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10152 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10153 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10154 goto nla_put_failure
;
10156 genlmsg_end(msg
, hdr
);
10158 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10161 genlmsg_cancel(msg
, hdr
);
10166 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10167 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10169 struct wiphy
*wiphy
= wdev
->wiphy
;
10170 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10171 struct net_device
*netdev
= wdev
->netdev
;
10172 struct sk_buff
*msg
;
10175 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10177 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10181 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10187 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10188 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10189 netdev
->ifindex
)) ||
10190 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10191 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10192 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10193 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10194 goto nla_put_failure
;
10196 genlmsg_end(msg
, hdr
);
10198 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10199 nl80211_mlme_mcgrp
.id
, gfp
);
10203 genlmsg_cancel(msg
, hdr
);
10206 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10208 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10209 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10212 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10213 struct wiphy
*wiphy
= wdev
->wiphy
;
10214 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10215 struct sk_buff
*msg
;
10216 struct nlattr
*pinfoattr
;
10219 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10221 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10225 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10231 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10232 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10233 goto nla_put_failure
;
10235 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10237 goto nla_put_failure
;
10239 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10241 goto nla_put_failure
;
10243 nla_nest_end(msg
, pinfoattr
);
10245 genlmsg_end(msg
, hdr
);
10247 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10248 nl80211_mlme_mcgrp
.id
, gfp
);
10252 genlmsg_cancel(msg
, hdr
);
10255 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10257 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10258 struct net_device
*netdev
, const u8
*bssid
,
10259 const u8
*replay_ctr
, gfp_t gfp
)
10261 struct sk_buff
*msg
;
10262 struct nlattr
*rekey_attr
;
10265 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10269 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10275 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10276 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10277 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10278 goto nla_put_failure
;
10280 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10282 goto nla_put_failure
;
10284 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10285 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10286 goto nla_put_failure
;
10288 nla_nest_end(msg
, rekey_attr
);
10290 genlmsg_end(msg
, hdr
);
10292 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10293 nl80211_mlme_mcgrp
.id
, gfp
);
10297 genlmsg_cancel(msg
, hdr
);
10301 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10302 const u8
*replay_ctr
, gfp_t gfp
)
10304 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10305 struct wiphy
*wiphy
= wdev
->wiphy
;
10306 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10308 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10309 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10311 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10314 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10315 struct net_device
*netdev
, int index
,
10316 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10318 struct sk_buff
*msg
;
10319 struct nlattr
*attr
;
10322 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10326 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10332 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10333 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10334 goto nla_put_failure
;
10336 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10338 goto nla_put_failure
;
10340 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10341 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10343 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10344 goto nla_put_failure
;
10346 nla_nest_end(msg
, attr
);
10348 genlmsg_end(msg
, hdr
);
10350 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10351 nl80211_mlme_mcgrp
.id
, gfp
);
10355 genlmsg_cancel(msg
, hdr
);
10359 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10360 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10362 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10363 struct wiphy
*wiphy
= wdev
->wiphy
;
10364 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10366 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10367 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10369 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10371 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10372 struct net_device
*netdev
,
10373 struct cfg80211_chan_def
*chandef
,
10376 struct sk_buff
*msg
;
10379 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10383 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10389 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10390 goto nla_put_failure
;
10392 if (nl80211_send_chandef(msg
, chandef
))
10393 goto nla_put_failure
;
10395 genlmsg_end(msg
, hdr
);
10397 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10398 nl80211_mlme_mcgrp
.id
, gfp
);
10402 genlmsg_cancel(msg
, hdr
);
10406 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10407 struct cfg80211_chan_def
*chandef
)
10409 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10410 struct wiphy
*wiphy
= wdev
->wiphy
;
10411 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10413 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10417 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10418 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10421 wdev
->channel
= chandef
->chan
;
10422 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10427 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10429 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10430 const u8
*peer
, u32 num_packets
,
10431 u32 rate
, u32 intvl
, gfp_t gfp
)
10433 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10434 struct wiphy
*wiphy
= wdev
->wiphy
;
10435 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10436 struct sk_buff
*msg
;
10437 struct nlattr
*pinfoattr
;
10440 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10444 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10450 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10451 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10452 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10453 goto nla_put_failure
;
10455 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10457 goto nla_put_failure
;
10459 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10460 goto nla_put_failure
;
10462 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10463 goto nla_put_failure
;
10465 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10466 goto nla_put_failure
;
10468 nla_nest_end(msg
, pinfoattr
);
10470 genlmsg_end(msg
, hdr
);
10472 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10473 nl80211_mlme_mcgrp
.id
, gfp
);
10477 genlmsg_cancel(msg
, hdr
);
10480 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10483 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10484 struct cfg80211_chan_def
*chandef
,
10485 enum nl80211_radar_event event
,
10486 struct net_device
*netdev
, gfp_t gfp
)
10488 struct sk_buff
*msg
;
10491 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10495 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10501 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10502 goto nla_put_failure
;
10504 /* NOP and radar events don't need a netdev parameter */
10506 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10508 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10509 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10510 goto nla_put_failure
;
10513 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10514 goto nla_put_failure
;
10516 if (nl80211_send_chandef(msg
, chandef
))
10517 goto nla_put_failure
;
10519 if (genlmsg_end(msg
, hdr
) < 0) {
10524 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10525 nl80211_mlme_mcgrp
.id
, gfp
);
10529 genlmsg_cancel(msg
, hdr
);
10533 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10534 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10536 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10537 struct wiphy
*wiphy
= wdev
->wiphy
;
10538 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10539 struct sk_buff
*msg
;
10540 struct nlattr
*pinfoattr
;
10543 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10545 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10549 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10555 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10556 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10557 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10558 goto nla_put_failure
;
10560 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10562 goto nla_put_failure
;
10564 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10565 goto nla_put_failure
;
10567 nla_nest_end(msg
, pinfoattr
);
10569 genlmsg_end(msg
, hdr
);
10571 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10572 nl80211_mlme_mcgrp
.id
, gfp
);
10576 genlmsg_cancel(msg
, hdr
);
10579 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10581 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10582 u64 cookie
, bool acked
, gfp_t gfp
)
10584 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10585 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10586 struct sk_buff
*msg
;
10590 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10592 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10597 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10603 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10604 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10605 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10606 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10607 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10608 goto nla_put_failure
;
10610 err
= genlmsg_end(msg
, hdr
);
10616 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10617 nl80211_mlme_mcgrp
.id
, gfp
);
10621 genlmsg_cancel(msg
, hdr
);
10624 EXPORT_SYMBOL(cfg80211_probe_status
);
10626 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10627 const u8
*frame
, size_t len
,
10628 int freq
, int sig_dbm
)
10630 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10631 struct sk_buff
*msg
;
10633 struct cfg80211_beacon_registration
*reg
;
10635 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10637 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10638 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10639 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10641 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10645 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10647 goto nla_put_failure
;
10649 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10651 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10653 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10654 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10655 goto nla_put_failure
;
10657 genlmsg_end(msg
, hdr
);
10659 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10661 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10665 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10667 genlmsg_cancel(msg
, hdr
);
10670 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10673 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10674 struct cfg80211_wowlan_wakeup
*wakeup
,
10677 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10678 struct sk_buff
*msg
;
10680 int err
, size
= 200;
10682 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10685 size
+= wakeup
->packet_present_len
;
10687 msg
= nlmsg_new(size
, gfp
);
10691 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10695 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10696 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10699 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10700 wdev
->netdev
->ifindex
))
10704 struct nlattr
*reasons
;
10706 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10708 if (wakeup
->disconnect
&&
10709 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10711 if (wakeup
->magic_pkt
&&
10712 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10714 if (wakeup
->gtk_rekey_failure
&&
10715 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10717 if (wakeup
->eap_identity_req
&&
10718 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10720 if (wakeup
->four_way_handshake
&&
10721 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10723 if (wakeup
->rfkill_release
&&
10724 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10727 if (wakeup
->pattern_idx
>= 0 &&
10728 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10729 wakeup
->pattern_idx
))
10732 if (wakeup
->tcp_match
)
10733 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10735 if (wakeup
->tcp_connlost
)
10737 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10739 if (wakeup
->tcp_nomoretokens
)
10741 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10743 if (wakeup
->packet
) {
10744 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10745 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10747 if (!wakeup
->packet_80211
) {
10749 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10751 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10754 if (wakeup
->packet_len
&&
10755 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10758 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10763 nla_nest_end(msg
, reasons
);
10766 err
= genlmsg_end(msg
, hdr
);
10770 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10771 nl80211_mlme_mcgrp
.id
, gfp
);
10777 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10780 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10781 enum nl80211_tdls_operation oper
,
10782 u16 reason_code
, gfp_t gfp
)
10784 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10785 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10786 struct sk_buff
*msg
;
10790 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10793 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10797 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10803 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10804 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10805 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10806 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10807 (reason_code
> 0 &&
10808 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10809 goto nla_put_failure
;
10811 err
= genlmsg_end(msg
, hdr
);
10817 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10818 nl80211_mlme_mcgrp
.id
, gfp
);
10822 genlmsg_cancel(msg
, hdr
);
10825 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10827 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10828 unsigned long state
,
10831 struct netlink_notify
*notify
= _notify
;
10832 struct cfg80211_registered_device
*rdev
;
10833 struct wireless_dev
*wdev
;
10834 struct cfg80211_beacon_registration
*reg
, *tmp
;
10836 if (state
!= NETLINK_URELEASE
)
10837 return NOTIFY_DONE
;
10841 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10842 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10843 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10845 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10846 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10848 if (reg
->nlportid
== notify
->portid
) {
10849 list_del(®
->list
);
10854 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10859 return NOTIFY_DONE
;
10862 static struct notifier_block nl80211_netlink_notifier
= {
10863 .notifier_call
= nl80211_netlink_notify
,
10866 void cfg80211_ft_event(struct net_device
*netdev
,
10867 struct cfg80211_ft_event_params
*ft_event
)
10869 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10870 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10871 struct sk_buff
*msg
;
10875 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10877 if (!ft_event
->target_ap
)
10880 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10884 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10890 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10891 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10892 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10894 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10895 if (ft_event
->ric_ies
)
10896 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10897 ft_event
->ric_ies
);
10899 err
= genlmsg_end(msg
, hdr
);
10905 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10906 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10908 EXPORT_SYMBOL(cfg80211_ft_event
);
10910 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10912 struct cfg80211_registered_device
*rdev
;
10913 struct sk_buff
*msg
;
10917 rdev
= wiphy_to_dev(wdev
->wiphy
);
10918 if (!rdev
->crit_proto_nlportid
)
10921 nlportid
= rdev
->crit_proto_nlportid
;
10922 rdev
->crit_proto_nlportid
= 0;
10924 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10928 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10930 goto nla_put_failure
;
10932 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10933 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10934 goto nla_put_failure
;
10936 genlmsg_end(msg
, hdr
);
10938 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10943 genlmsg_cancel(msg
, hdr
);
10947 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10949 /* initialisation/exit functions */
10951 int nl80211_init(void)
10955 err
= genl_register_family_with_ops(&nl80211_fam
,
10956 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10960 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10964 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10968 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10972 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10976 #ifdef CONFIG_NL80211_TESTMODE
10977 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10981 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_vendor_mcgrp
);
10986 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10992 genl_unregister_family(&nl80211_fam
);
10996 void nl80211_exit(void)
10998 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10999 genl_unregister_family(&nl80211_fam
);