2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
22 #include <net/inet_connection_sock.h>
28 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
29 struct genl_info
*info
,
30 struct cfg80211_crypto_settings
*settings
,
33 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
34 struct genl_info
*info
);
35 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
38 /* the netlink family */
39 static struct genl_family nl80211_fam
= {
40 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
41 .name
= "nl80211", /* have users key off the name instead */
42 .hdrsize
= 0, /* no private header */
43 .version
= 1, /* no particular meaning now */
44 .maxattr
= NL80211_ATTR_MAX
,
46 .pre_doit
= nl80211_pre_doit
,
47 .post_doit
= nl80211_post_doit
,
50 /* returns ERR_PTR values */
51 static struct wireless_dev
*
52 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
54 struct cfg80211_registered_device
*rdev
;
55 struct wireless_dev
*result
= NULL
;
56 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
57 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
62 assert_cfg80211_lock();
64 if (!have_ifidx
&& !have_wdev_id
)
65 return ERR_PTR(-EINVAL
);
68 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
70 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
71 wiphy_idx
= wdev_id
>> 32;
74 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
75 struct wireless_dev
*wdev
;
77 if (wiphy_net(&rdev
->wiphy
) != netns
)
80 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
83 mutex_lock(&rdev
->devlist_mtx
);
84 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
85 if (have_ifidx
&& wdev
->netdev
&&
86 wdev
->netdev
->ifindex
== ifidx
) {
90 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
95 mutex_unlock(&rdev
->devlist_mtx
);
103 return ERR_PTR(-ENODEV
);
106 static struct cfg80211_registered_device
*
107 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
109 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
110 struct net_device
*netdev
;
112 assert_cfg80211_lock();
114 if (!attrs
[NL80211_ATTR_WIPHY
] &&
115 !attrs
[NL80211_ATTR_IFINDEX
] &&
116 !attrs
[NL80211_ATTR_WDEV
])
117 return ERR_PTR(-EINVAL
);
119 if (attrs
[NL80211_ATTR_WIPHY
])
120 rdev
= cfg80211_rdev_by_wiphy_idx(
121 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
123 if (attrs
[NL80211_ATTR_WDEV
]) {
124 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
125 struct wireless_dev
*wdev
;
128 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
130 /* make sure wdev exists */
131 mutex_lock(&tmp
->devlist_mtx
);
132 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
133 if (wdev
->identifier
!= (u32
)wdev_id
)
138 mutex_unlock(&tmp
->devlist_mtx
);
143 if (rdev
&& tmp
!= rdev
)
144 return ERR_PTR(-EINVAL
);
149 if (attrs
[NL80211_ATTR_IFINDEX
]) {
150 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
151 netdev
= dev_get_by_index(netns
, ifindex
);
153 if (netdev
->ieee80211_ptr
)
155 netdev
->ieee80211_ptr
->wiphy
);
161 /* not wireless device -- return error */
163 return ERR_PTR(-EINVAL
);
165 /* mismatch -- return error */
166 if (rdev
&& tmp
!= rdev
)
167 return ERR_PTR(-EINVAL
);
174 return ERR_PTR(-ENODEV
);
176 if (netns
!= wiphy_net(&rdev
->wiphy
))
177 return ERR_PTR(-ENODEV
);
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
202 static struct cfg80211_registered_device
*
203 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
205 struct cfg80211_registered_device
*rdev
;
207 mutex_lock(&cfg80211_mutex
);
208 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
214 mutex_lock(&rdev
->mtx
);
216 mutex_unlock(&cfg80211_mutex
);
221 /* policy for the attributes */
222 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
223 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
226 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
228 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
235 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
240 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
241 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
242 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
244 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
245 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
247 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
248 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
249 .len
= WLAN_MAX_KEY_LEN
},
250 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
251 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
253 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
254 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
256 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
258 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
259 .len
= IEEE80211_MAX_DATA_LEN
},
260 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
261 .len
= IEEE80211_MAX_DATA_LEN
},
262 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
263 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
264 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
265 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
266 .len
= NL80211_MAX_SUPP_RATES
},
267 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
268 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
269 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
270 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
271 .len
= IEEE80211_MAX_MESH_ID_LEN
},
272 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
274 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
275 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
277 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
280 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
281 .len
= NL80211_MAX_SUPP_RATES
},
282 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
284 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
285 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
287 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
289 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
290 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
291 .len
= IEEE80211_MAX_DATA_LEN
},
292 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
293 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
295 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
296 .len
= IEEE80211_MAX_SSID_LEN
},
297 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
298 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
299 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
302 [NL80211_ATTR_STA_FLAGS2
] = {
303 .len
= sizeof(struct nl80211_sta_flag_update
),
305 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
308 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
309 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
312 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
313 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
314 .len
= WLAN_PMKID_LEN
},
315 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
317 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
318 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
319 .len
= IEEE80211_MAX_DATA_LEN
},
320 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
321 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
323 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
324 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
327 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
328 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
331 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
332 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
333 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
334 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
335 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
336 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
337 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
338 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
339 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
340 .len
= IEEE80211_MAX_DATA_LEN
},
341 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
342 .len
= IEEE80211_MAX_DATA_LEN
},
343 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
345 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
351 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
352 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
353 .len
= IEEE80211_MAX_DATA_LEN
},
354 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
355 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
356 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
357 .len
= NL80211_HT_CAPABILITY_LEN
359 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
360 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
361 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
362 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
363 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
364 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
365 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
366 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
367 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
368 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
369 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
370 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
371 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
372 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
373 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
374 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
375 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
376 .len
= NL80211_VHT_CAPABILITY_LEN
,
378 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
379 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
380 .len
= IEEE80211_MAX_DATA_LEN
},
381 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
382 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
384 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
385 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
386 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
389 /* policy for the key attributes */
390 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
391 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
392 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
393 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
394 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
395 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
396 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
397 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
398 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
401 /* policy for the key default flags */
402 static const struct nla_policy
403 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
404 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
405 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
408 /* policy for WoWLAN attributes */
409 static const struct nla_policy
410 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
411 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
412 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
413 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
414 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
415 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
416 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
417 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
418 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
419 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
422 static const struct nla_policy
423 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
424 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
425 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
426 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
427 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
428 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
430 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
431 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
433 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
434 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
436 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
437 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
438 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
441 /* policy for GTK rekey offload attributes */
442 static const struct nla_policy
443 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
444 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
445 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
446 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
449 static const struct nla_policy
450 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
451 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
452 .len
= IEEE80211_MAX_SSID_LEN
},
453 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
456 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
457 struct netlink_callback
*cb
,
458 struct cfg80211_registered_device
**rdev
,
459 struct wireless_dev
**wdev
)
464 mutex_lock(&cfg80211_mutex
);
467 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
468 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
473 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
474 nl80211_fam
.attrbuf
);
476 err
= PTR_ERR(*wdev
);
479 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
480 /* 0 is the first index - add 1 to parse only once */
481 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
482 cb
->args
[1] = (*wdev
)->identifier
;
484 /* subtract the 1 again here */
485 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
486 struct wireless_dev
*tmp
;
492 *rdev
= wiphy_to_dev(wiphy
);
495 mutex_lock(&(*rdev
)->devlist_mtx
);
496 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
497 if (tmp
->identifier
== cb
->args
[1]) {
502 mutex_unlock(&(*rdev
)->devlist_mtx
);
510 cfg80211_lock_rdev(*rdev
);
512 mutex_unlock(&cfg80211_mutex
);
515 mutex_unlock(&cfg80211_mutex
);
520 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
522 cfg80211_unlock_rdev(rdev
);
527 static bool is_valid_ie_attr(const struct nlattr
*attr
)
535 pos
= nla_data(attr
);
556 /* message building helper */
557 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
560 /* since there is no private header just add the generic one */
561 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
564 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
565 struct ieee80211_channel
*chan
,
568 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
570 goto nla_put_failure
;
572 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
573 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
574 goto nla_put_failure
;
575 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
576 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
577 goto nla_put_failure
;
578 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
579 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
580 goto nla_put_failure
;
581 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
582 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
583 goto nla_put_failure
;
587 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
589 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
591 goto nla_put_failure
;
592 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
594 goto nla_put_failure
;
599 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
600 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
601 goto nla_put_failure
;
602 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
603 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
604 goto nla_put_failure
;
605 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
606 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
607 goto nla_put_failure
;
608 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
609 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
610 goto nla_put_failure
;
613 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
614 DBM_TO_MBM(chan
->max_power
)))
615 goto nla_put_failure
;
623 /* netlink command implementations */
630 bool def_uni
, def_multi
;
633 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
635 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
636 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
641 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
642 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
651 if (tb
[NL80211_KEY_IDX
])
652 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
654 if (tb
[NL80211_KEY_DATA
]) {
655 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
656 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
659 if (tb
[NL80211_KEY_SEQ
]) {
660 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
661 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
664 if (tb
[NL80211_KEY_CIPHER
])
665 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
667 if (tb
[NL80211_KEY_TYPE
]) {
668 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
669 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
673 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
674 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
675 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
676 tb
[NL80211_KEY_DEFAULT_TYPES
],
677 nl80211_key_default_policy
);
681 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
682 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
688 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
690 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
691 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
692 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
695 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
696 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
697 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
700 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
701 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
703 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
704 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
706 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
707 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
716 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
717 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
718 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
722 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
723 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
724 int err
= nla_parse_nested(
725 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
726 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
727 nl80211_key_default_policy
);
731 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
732 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
738 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
742 memset(k
, 0, sizeof(*k
));
746 if (info
->attrs
[NL80211_ATTR_KEY
])
747 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
749 err
= nl80211_parse_key_old(info
, k
);
754 if (k
->def
&& k
->defmgmt
)
758 if (k
->def_uni
|| !k
->def_multi
)
764 if (k
->idx
< 4 || k
->idx
> 5)
767 if (k
->idx
< 0 || k
->idx
> 3)
770 if (k
->idx
< 0 || k
->idx
> 5)
778 static struct cfg80211_cached_keys
*
779 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
780 struct nlattr
*keys
, bool *no_ht
)
782 struct key_parse parse
;
784 struct cfg80211_cached_keys
*result
;
785 int rem
, err
, def
= 0;
787 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
789 return ERR_PTR(-ENOMEM
);
792 result
->defmgmt
= -1;
794 nla_for_each_nested(key
, keys
, rem
) {
795 memset(&parse
, 0, sizeof(parse
));
798 err
= nl80211_parse_key_new(key
, &parse
);
804 if (parse
.idx
< 0 || parse
.idx
> 4)
810 result
->def
= parse
.idx
;
811 if (!parse
.def_uni
|| !parse
.def_multi
)
813 } else if (parse
.defmgmt
)
815 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
816 parse
.idx
, false, NULL
);
819 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
820 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
821 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
822 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
824 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
825 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
837 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
839 ASSERT_WDEV_LOCK(wdev
);
841 switch (wdev
->iftype
) {
842 case NL80211_IFTYPE_AP
:
843 case NL80211_IFTYPE_AP_VLAN
:
844 case NL80211_IFTYPE_P2P_GO
:
845 case NL80211_IFTYPE_MESH_POINT
:
847 case NL80211_IFTYPE_ADHOC
:
848 if (!wdev
->current_bss
)
851 case NL80211_IFTYPE_STATION
:
852 case NL80211_IFTYPE_P2P_CLIENT
:
853 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
863 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
865 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
869 goto nla_put_failure
;
873 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
874 goto nla_put_failure
;
879 nla_nest_end(msg
, nl_modes
);
886 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
890 struct nlattr
*nl_combis
;
893 nl_combis
= nla_nest_start(msg
,
894 NL80211_ATTR_INTERFACE_COMBINATIONS
);
896 goto nla_put_failure
;
898 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
899 const struct ieee80211_iface_combination
*c
;
900 struct nlattr
*nl_combi
, *nl_limits
;
902 c
= &wiphy
->iface_combinations
[i
];
904 nl_combi
= nla_nest_start(msg
, i
+ 1);
906 goto nla_put_failure
;
908 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
910 goto nla_put_failure
;
912 for (j
= 0; j
< c
->n_limits
; j
++) {
913 struct nlattr
*nl_limit
;
915 nl_limit
= nla_nest_start(msg
, j
+ 1);
917 goto nla_put_failure
;
918 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
920 goto nla_put_failure
;
921 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
923 goto nla_put_failure
;
924 nla_nest_end(msg
, nl_limit
);
927 nla_nest_end(msg
, nl_limits
);
929 if (c
->beacon_int_infra_match
&&
930 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
931 goto nla_put_failure
;
932 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
933 c
->num_different_channels
) ||
934 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
936 goto nla_put_failure
;
938 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
939 c
->radar_detect_widths
))
940 goto nla_put_failure
;
942 nla_nest_end(msg
, nl_combi
);
945 nla_nest_end(msg
, nl_combis
);
953 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
956 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
.tcp
;
957 struct nlattr
*nl_tcp
;
962 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
966 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
967 tcp
->data_payload_max
))
970 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
971 tcp
->data_payload_max
))
974 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
977 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
978 sizeof(*tcp
->tok
), tcp
->tok
))
981 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
982 tcp
->data_interval_max
))
985 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
986 tcp
->wake_payload_max
))
989 nla_nest_end(msg
, nl_tcp
);
993 static int nl80211_send_wowlan(struct sk_buff
*msg
,
994 struct cfg80211_registered_device
*dev
,
997 struct nlattr
*nl_wowlan
;
999 if (!dev
->wiphy
.wowlan
.flags
&& !dev
->wiphy
.wowlan
.n_patterns
)
1002 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1006 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1007 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1008 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1009 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1010 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1011 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1012 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1013 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1014 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1015 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1016 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1017 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1018 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1019 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1020 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1021 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1024 if (dev
->wiphy
.wowlan
.n_patterns
) {
1025 struct nl80211_wowlan_pattern_support pat
= {
1026 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1027 .min_pattern_len
= dev
->wiphy
.wowlan
.pattern_min_len
,
1028 .max_pattern_len
= dev
->wiphy
.wowlan
.pattern_max_len
,
1029 .max_pkt_offset
= dev
->wiphy
.wowlan
.max_pkt_offset
,
1032 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1037 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
1040 nla_nest_end(msg
, nl_wowlan
);
1046 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1047 struct ieee80211_supported_band
*sband
)
1049 struct nlattr
*nl_rates
, *nl_rate
;
1050 struct ieee80211_rate
*rate
;
1054 if (sband
->ht_cap
.ht_supported
&&
1055 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1056 sizeof(sband
->ht_cap
.mcs
),
1057 &sband
->ht_cap
.mcs
) ||
1058 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1059 sband
->ht_cap
.cap
) ||
1060 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1061 sband
->ht_cap
.ampdu_factor
) ||
1062 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1063 sband
->ht_cap
.ampdu_density
)))
1067 if (sband
->vht_cap
.vht_supported
&&
1068 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1069 sizeof(sband
->vht_cap
.vht_mcs
),
1070 &sband
->vht_cap
.vht_mcs
) ||
1071 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1072 sband
->vht_cap
.cap
)))
1076 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1080 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1081 nl_rate
= nla_nest_start(msg
, i
);
1085 rate
= &sband
->bitrates
[i
];
1086 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1089 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1091 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1094 nla_nest_end(msg
, nl_rate
);
1097 nla_nest_end(msg
, nl_rates
);
1103 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1104 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1107 struct nlattr
*nl_ftypes
, *nl_ifs
;
1108 enum nl80211_iftype ift
;
1114 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1118 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1119 nl_ftypes
= nla_nest_start(msg
, ift
);
1123 stypes
= mgmt_stypes
[ift
].tx
;
1126 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1127 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1132 nla_nest_end(msg
, nl_ftypes
);
1135 nla_nest_end(msg
, nl_ifs
);
1137 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1141 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1142 nl_ftypes
= nla_nest_start(msg
, ift
);
1146 stypes
= mgmt_stypes
[ift
].rx
;
1149 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1150 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1155 nla_nest_end(msg
, nl_ftypes
);
1157 nla_nest_end(msg
, nl_ifs
);
1162 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1163 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1164 int flags
, bool split
, long *split_start
,
1165 long *band_start
, long *chan_start
)
1168 struct nlattr
*nl_bands
, *nl_band
;
1169 struct nlattr
*nl_freqs
, *nl_freq
;
1170 struct nlattr
*nl_cmds
;
1171 enum ieee80211_band band
;
1172 struct ieee80211_channel
*chan
;
1174 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1175 dev
->wiphy
.mgmt_stypes
;
1176 long start
= 0, start_chan
= 0, start_band
= 0;
1179 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1183 /* allow always using the variables */
1185 split_start
= &start
;
1186 band_start
= &start_band
;
1187 chan_start
= &start_chan
;
1190 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1191 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1192 wiphy_name(&dev
->wiphy
)) ||
1193 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1194 cfg80211_rdev_list_generation
))
1195 goto nla_put_failure
;
1197 switch (*split_start
) {
1199 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1200 dev
->wiphy
.retry_short
) ||
1201 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1202 dev
->wiphy
.retry_long
) ||
1203 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1204 dev
->wiphy
.frag_threshold
) ||
1205 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1206 dev
->wiphy
.rts_threshold
) ||
1207 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1208 dev
->wiphy
.coverage_class
) ||
1209 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1210 dev
->wiphy
.max_scan_ssids
) ||
1211 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1212 dev
->wiphy
.max_sched_scan_ssids
) ||
1213 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1214 dev
->wiphy
.max_scan_ie_len
) ||
1215 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1216 dev
->wiphy
.max_sched_scan_ie_len
) ||
1217 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1218 dev
->wiphy
.max_match_sets
))
1219 goto nla_put_failure
;
1221 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1222 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1223 goto nla_put_failure
;
1224 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1225 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1226 goto nla_put_failure
;
1227 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1228 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1229 goto nla_put_failure
;
1230 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1231 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1232 goto nla_put_failure
;
1233 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1234 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1235 goto nla_put_failure
;
1236 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1237 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1238 goto nla_put_failure
;
1244 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1245 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1246 dev
->wiphy
.cipher_suites
))
1247 goto nla_put_failure
;
1249 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1250 dev
->wiphy
.max_num_pmkids
))
1251 goto nla_put_failure
;
1253 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1254 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1255 goto nla_put_failure
;
1257 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1258 dev
->wiphy
.available_antennas_tx
) ||
1259 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1260 dev
->wiphy
.available_antennas_rx
))
1261 goto nla_put_failure
;
1263 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1264 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1265 dev
->wiphy
.probe_resp_offload
))
1266 goto nla_put_failure
;
1268 if ((dev
->wiphy
.available_antennas_tx
||
1269 dev
->wiphy
.available_antennas_rx
) &&
1270 dev
->ops
->get_antenna
) {
1271 u32 tx_ant
= 0, rx_ant
= 0;
1273 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1275 if (nla_put_u32(msg
,
1276 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1279 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1281 goto nla_put_failure
;
1289 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1290 dev
->wiphy
.interface_modes
))
1291 goto nla_put_failure
;
1296 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1298 goto nla_put_failure
;
1300 for (band
= *band_start
; band
< IEEE80211_NUM_BANDS
; band
++) {
1301 struct ieee80211_supported_band
*sband
;
1303 sband
= dev
->wiphy
.bands
[band
];
1308 nl_band
= nla_nest_start(msg
, band
);
1310 goto nla_put_failure
;
1312 switch (*chan_start
) {
1314 if (nl80211_send_band_rateinfo(msg
, sband
))
1315 goto nla_put_failure
;
1320 /* add frequencies */
1321 nl_freqs
= nla_nest_start(
1322 msg
, NL80211_BAND_ATTR_FREQS
);
1324 goto nla_put_failure
;
1326 for (i
= *chan_start
- 1;
1327 i
< sband
->n_channels
;
1329 nl_freq
= nla_nest_start(msg
, i
);
1331 goto nla_put_failure
;
1333 chan
= &sband
->channels
[i
];
1335 if (nl80211_msg_put_channel(msg
, chan
,
1337 goto nla_put_failure
;
1339 nla_nest_end(msg
, nl_freq
);
1343 if (i
< sband
->n_channels
)
1344 *chan_start
= i
+ 2;
1347 nla_nest_end(msg
, nl_freqs
);
1350 nla_nest_end(msg
, nl_band
);
1353 /* start again here */
1359 nla_nest_end(msg
, nl_bands
);
1361 if (band
< IEEE80211_NUM_BANDS
)
1362 *band_start
= band
+ 1;
1366 /* if bands & channels are done, continue outside */
1367 if (*band_start
== 0 && *chan_start
== 0)
1372 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1374 goto nla_put_failure
;
1377 #define CMD(op, n) \
1379 if (dev->ops->op) { \
1381 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1382 goto nla_put_failure; \
1386 CMD(add_virtual_intf
, NEW_INTERFACE
);
1387 CMD(change_virtual_intf
, SET_INTERFACE
);
1388 CMD(add_key
, NEW_KEY
);
1389 CMD(start_ap
, START_AP
);
1390 CMD(add_station
, NEW_STATION
);
1391 CMD(add_mpath
, NEW_MPATH
);
1392 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1393 CMD(change_bss
, SET_BSS
);
1394 CMD(auth
, AUTHENTICATE
);
1395 CMD(assoc
, ASSOCIATE
);
1396 CMD(deauth
, DEAUTHENTICATE
);
1397 CMD(disassoc
, DISASSOCIATE
);
1398 CMD(join_ibss
, JOIN_IBSS
);
1399 CMD(join_mesh
, JOIN_MESH
);
1400 CMD(set_pmksa
, SET_PMKSA
);
1401 CMD(del_pmksa
, DEL_PMKSA
);
1402 CMD(flush_pmksa
, FLUSH_PMKSA
);
1403 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1404 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1405 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1406 CMD(mgmt_tx
, FRAME
);
1407 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1408 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1410 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1411 goto nla_put_failure
;
1413 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1414 dev
->ops
->join_mesh
) {
1416 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1417 goto nla_put_failure
;
1419 CMD(set_wds_peer
, SET_WDS_PEER
);
1420 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1421 CMD(tdls_mgmt
, TDLS_MGMT
);
1422 CMD(tdls_oper
, TDLS_OPER
);
1424 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1425 CMD(sched_scan_start
, START_SCHED_SCAN
);
1426 CMD(probe_client
, PROBE_CLIENT
);
1427 CMD(set_noack_map
, SET_NOACK_MAP
);
1428 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1430 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1431 goto nla_put_failure
;
1433 CMD(start_p2p_device
, START_P2P_DEVICE
);
1434 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1436 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1437 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1440 #ifdef CONFIG_NL80211_TESTMODE
1441 CMD(testmode_cmd
, TESTMODE
);
1446 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1448 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1449 goto nla_put_failure
;
1452 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1454 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1455 goto nla_put_failure
;
1458 nla_nest_end(msg
, nl_cmds
);
1463 if (dev
->ops
->remain_on_channel
&&
1464 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1466 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1467 dev
->wiphy
.max_remain_on_channel_duration
))
1468 goto nla_put_failure
;
1470 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1471 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1472 goto nla_put_failure
;
1474 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1475 goto nla_put_failure
;
1481 if (nl80211_send_wowlan(msg
, dev
, split
))
1482 goto nla_put_failure
;
1490 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1491 dev
->wiphy
.software_iftypes
))
1492 goto nla_put_failure
;
1494 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
, split
))
1495 goto nla_put_failure
;
1501 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1502 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1503 dev
->wiphy
.ap_sme_capa
))
1504 goto nla_put_failure
;
1506 features
= dev
->wiphy
.features
;
1508 * We can only add the per-channel limit information if the
1509 * dump is split, otherwise it makes it too big. Therefore
1510 * only advertise it in that case.
1513 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1514 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1515 goto nla_put_failure
;
1517 if (dev
->wiphy
.ht_capa_mod_mask
&&
1518 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1519 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1520 dev
->wiphy
.ht_capa_mod_mask
))
1521 goto nla_put_failure
;
1523 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1524 dev
->wiphy
.max_acl_mac_addrs
&&
1525 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1526 dev
->wiphy
.max_acl_mac_addrs
))
1527 goto nla_put_failure
;
1529 if (dev
->wiphy
.n_vendor_commands
) {
1530 const struct nl80211_vendor_cmd_info
*info
;
1531 struct nlattr
*nested
;
1533 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1535 goto nla_put_failure
;
1537 for (i
= 0; i
< dev
->wiphy
.n_vendor_commands
; i
++) {
1538 info
= &dev
->wiphy
.vendor_commands
[i
].info
;
1539 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1540 goto nla_put_failure
;
1542 nla_nest_end(msg
, nested
);
1545 if (dev
->wiphy
.n_vendor_events
) {
1546 const struct nl80211_vendor_cmd_info
*info
;
1547 struct nlattr
*nested
;
1549 nested
= nla_nest_start(msg
,
1550 NL80211_ATTR_VENDOR_EVENTS
);
1552 goto nla_put_failure
;
1554 for (i
= 0; i
< dev
->wiphy
.n_vendor_events
; i
++) {
1555 info
= &dev
->wiphy
.vendor_events
[i
];
1556 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1557 goto nla_put_failure
;
1559 nla_nest_end(msg
, nested
);
1563 * Any information below this point is only available to
1564 * applications that can deal with it being split. This
1565 * helps ensure that newly added capabilities don't break
1566 * older tools by overrunning their buffers.
1568 * We still increment split_start so that in the split
1569 * case we'll continue with more data in the next round,
1570 * but break unconditionally so unsplit data stops here.
1575 if (dev
->wiphy
.extended_capabilities
&&
1576 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1577 dev
->wiphy
.extended_capabilities_len
,
1578 dev
->wiphy
.extended_capabilities
) ||
1579 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1580 dev
->wiphy
.extended_capabilities_len
,
1581 dev
->wiphy
.extended_capabilities_mask
)))
1582 goto nla_put_failure
;
1584 if (dev
->wiphy
.vht_capa_mod_mask
&&
1585 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1586 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1587 dev
->wiphy
.vht_capa_mod_mask
))
1588 goto nla_put_failure
;
1594 return genlmsg_end(msg
, hdr
);
1597 genlmsg_cancel(msg
, hdr
);
1601 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1604 int start
= cb
->args
[0];
1605 struct cfg80211_registered_device
*dev
;
1606 s64 filter_wiphy
= -1;
1611 /* will be zeroed in nlmsg_parse() */
1612 tb
= kmalloc(sizeof(*tb
) * (NL80211_ATTR_MAX
+ 1), GFP_KERNEL
);
1616 mutex_lock(&cfg80211_mutex
);
1617 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1618 tb
, NL80211_ATTR_MAX
, nl80211_policy
);
1620 split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1621 if (tb
[NL80211_ATTR_WIPHY
])
1622 filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1623 if (tb
[NL80211_ATTR_WDEV
])
1624 filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1625 if (tb
[NL80211_ATTR_IFINDEX
]) {
1626 struct net_device
*netdev
;
1627 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1629 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1631 mutex_unlock(&cfg80211_mutex
);
1635 if (netdev
->ieee80211_ptr
) {
1637 netdev
->ieee80211_ptr
->wiphy
);
1638 filter_wiphy
= dev
->wiphy_idx
;
1645 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1646 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1650 if (filter_wiphy
!= -1 && dev
->wiphy_idx
!= filter_wiphy
)
1652 /* attempt to fit multiple wiphy data chunks into the skb */
1654 ret
= nl80211_send_wiphy(dev
, skb
,
1655 NETLINK_CB(cb
->skb
).portid
,
1658 split
, &cb
->args
[1],
1663 * If sending the wiphy data didn't fit (ENOBUFS
1664 * or EMSGSIZE returned), this SKB is still
1665 * empty (so it's not too big because another
1666 * wiphy dataset is already in the skb) and
1667 * we've not tried to adjust the dump allocation
1668 * yet ... then adjust the alloc size to be
1669 * bigger, and return 1 but with the empty skb.
1670 * This results in an empty message being RX'ed
1671 * in userspace, but that is ignored.
1673 * We can then retry with the larger buffer.
1675 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1677 cb
->min_dump_alloc
< 4096) {
1678 cb
->min_dump_alloc
= 4096;
1679 mutex_unlock(&cfg80211_mutex
);
1685 } while (cb
->args
[1] > 0);
1688 mutex_unlock(&cfg80211_mutex
);
1695 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1697 struct sk_buff
*msg
;
1698 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1700 msg
= nlmsg_new(4096, GFP_KERNEL
);
1704 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1705 false, NULL
, NULL
, NULL
) < 0) {
1710 return genlmsg_reply(msg
, info
);
1713 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1714 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1715 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1716 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1717 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1718 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1721 static int parse_txq_params(struct nlattr
*tb
[],
1722 struct ieee80211_txq_params
*txq_params
)
1724 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1725 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1726 !tb
[NL80211_TXQ_ATTR_AIFS
])
1729 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1730 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1731 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1732 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1733 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1735 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1741 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1744 * You can only set the channel explicitly for WDS interfaces,
1745 * all others have their channel managed via their respective
1746 * "establish a connection" command (connect, join, ...)
1748 * For AP/GO and mesh mode, the channel can be set with the
1749 * channel userspace API, but is only stored and passed to the
1750 * low-level driver when the AP starts or the mesh is joined.
1751 * This is for backward compatibility, userspace can also give
1752 * the channel in the start-ap or join-mesh commands instead.
1754 * Monitors are special as they are normally slaved to
1755 * whatever else is going on, so they have their own special
1756 * operation to set the monitor channel if possible.
1759 wdev
->iftype
== NL80211_IFTYPE_AP
||
1760 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1761 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1762 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1765 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1766 struct genl_info
*info
,
1767 struct cfg80211_chan_def
*chandef
)
1771 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1774 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1776 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1777 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1778 chandef
->center_freq1
= control_freq
;
1779 chandef
->center_freq2
= 0;
1781 /* Primary channel not allowed */
1782 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1785 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1786 enum nl80211_channel_type chantype
;
1788 chantype
= nla_get_u32(
1789 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1792 case NL80211_CHAN_NO_HT
:
1793 case NL80211_CHAN_HT20
:
1794 case NL80211_CHAN_HT40PLUS
:
1795 case NL80211_CHAN_HT40MINUS
:
1796 cfg80211_chandef_create(chandef
, chandef
->chan
,
1802 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1804 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1805 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1806 chandef
->center_freq1
=
1808 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1809 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1810 chandef
->center_freq2
=
1812 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1815 if (!cfg80211_chandef_valid(chandef
))
1818 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1819 IEEE80211_CHAN_DISABLED
))
1825 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1826 struct wireless_dev
*wdev
,
1827 struct genl_info
*info
)
1829 struct cfg80211_chan_def chandef
;
1831 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1834 iftype
= wdev
->iftype
;
1836 if (!nl80211_can_set_dev_channel(wdev
))
1839 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1843 mutex_lock(&rdev
->devlist_mtx
);
1845 case NL80211_IFTYPE_AP
:
1846 case NL80211_IFTYPE_P2P_GO
:
1847 if (wdev
->beacon_interval
) {
1851 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1855 wdev
->preset_chandef
= chandef
;
1858 case NL80211_IFTYPE_MESH_POINT
:
1859 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1861 case NL80211_IFTYPE_MONITOR
:
1862 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1867 mutex_unlock(&rdev
->devlist_mtx
);
1872 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1875 struct net_device
*netdev
= info
->user_ptr
[1];
1877 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1880 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1882 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1883 struct net_device
*dev
= info
->user_ptr
[1];
1884 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1887 if (!info
->attrs
[NL80211_ATTR_MAC
])
1890 if (netif_running(dev
))
1893 if (!rdev
->ops
->set_wds_peer
)
1896 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1899 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1900 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1904 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1906 struct cfg80211_registered_device
*rdev
;
1907 struct net_device
*netdev
= NULL
;
1908 struct wireless_dev
*wdev
;
1909 int result
= 0, rem_txq_params
= 0;
1910 struct nlattr
*nl_txq_params
;
1912 u8 retry_short
= 0, retry_long
= 0;
1913 u32 frag_threshold
= 0, rts_threshold
= 0;
1914 u8 coverage_class
= 0;
1917 * Try to find the wiphy and netdev. Normally this
1918 * function shouldn't need the netdev, but this is
1919 * done for backward compatibility -- previously
1920 * setting the channel was done per wiphy, but now
1921 * it is per netdev. Previous userland like hostapd
1922 * also passed a netdev to set_wiphy, so that it is
1923 * possible to let that go to the right netdev!
1925 mutex_lock(&cfg80211_mutex
);
1927 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1928 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1930 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1931 if (netdev
&& netdev
->ieee80211_ptr
) {
1932 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1933 mutex_lock(&rdev
->mtx
);
1939 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1942 mutex_unlock(&cfg80211_mutex
);
1943 return PTR_ERR(rdev
);
1949 mutex_lock(&rdev
->mtx
);
1951 wdev
= netdev
->ieee80211_ptr
;
1954 * end workaround code, by now the rdev is available
1955 * and locked, and wdev may or may not be NULL.
1958 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1959 result
= cfg80211_dev_rename(
1960 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1962 mutex_unlock(&cfg80211_mutex
);
1967 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1968 struct ieee80211_txq_params txq_params
;
1969 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1971 if (!rdev
->ops
->set_txq_params
) {
1972 result
= -EOPNOTSUPP
;
1981 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1982 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1987 if (!netif_running(netdev
)) {
1992 nla_for_each_nested(nl_txq_params
,
1993 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1995 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1996 nla_data(nl_txq_params
),
1997 nla_len(nl_txq_params
),
1999 result
= parse_txq_params(tb
, &txq_params
);
2003 result
= rdev_set_txq_params(rdev
, netdev
,
2010 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2011 result
= __nl80211_set_channel(rdev
,
2012 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
2018 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2019 struct wireless_dev
*txp_wdev
= wdev
;
2020 enum nl80211_tx_power_setting type
;
2023 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2026 if (!rdev
->ops
->set_tx_power
) {
2027 result
= -EOPNOTSUPP
;
2031 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2032 type
= nla_get_u32(info
->attrs
[idx
]);
2034 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2035 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
2040 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2041 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2042 mbm
= nla_get_u32(info
->attrs
[idx
]);
2045 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2050 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2051 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2053 if ((!rdev
->wiphy
.available_antennas_tx
&&
2054 !rdev
->wiphy
.available_antennas_rx
) ||
2055 !rdev
->ops
->set_antenna
) {
2056 result
= -EOPNOTSUPP
;
2060 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2061 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2063 /* reject antenna configurations which don't match the
2064 * available antenna masks, except for the "all" mask */
2065 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2066 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2071 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2072 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2074 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2081 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2082 retry_short
= nla_get_u8(
2083 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2084 if (retry_short
== 0) {
2088 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2091 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2092 retry_long
= nla_get_u8(
2093 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2094 if (retry_long
== 0) {
2098 changed
|= WIPHY_PARAM_RETRY_LONG
;
2101 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2102 frag_threshold
= nla_get_u32(
2103 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2104 if (frag_threshold
< 256) {
2108 if (frag_threshold
!= (u32
) -1) {
2110 * Fragments (apart from the last one) are required to
2111 * have even length. Make the fragmentation code
2112 * simpler by stripping LSB should someone try to use
2113 * odd threshold value.
2115 frag_threshold
&= ~0x1;
2117 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2120 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2121 rts_threshold
= nla_get_u32(
2122 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2123 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2126 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2127 coverage_class
= nla_get_u8(
2128 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2129 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2133 u8 old_retry_short
, old_retry_long
;
2134 u32 old_frag_threshold
, old_rts_threshold
;
2135 u8 old_coverage_class
;
2137 if (!rdev
->ops
->set_wiphy_params
) {
2138 result
= -EOPNOTSUPP
;
2142 old_retry_short
= rdev
->wiphy
.retry_short
;
2143 old_retry_long
= rdev
->wiphy
.retry_long
;
2144 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2145 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2146 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2148 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2149 rdev
->wiphy
.retry_short
= retry_short
;
2150 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2151 rdev
->wiphy
.retry_long
= retry_long
;
2152 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2153 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2154 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2155 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2156 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2157 rdev
->wiphy
.coverage_class
= coverage_class
;
2159 result
= rdev_set_wiphy_params(rdev
, changed
);
2161 rdev
->wiphy
.retry_short
= old_retry_short
;
2162 rdev
->wiphy
.retry_long
= old_retry_long
;
2163 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2164 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2165 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2170 mutex_unlock(&rdev
->mtx
);
2176 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2178 return (u64
)wdev
->identifier
|
2179 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2182 static int nl80211_send_chandef(struct sk_buff
*msg
,
2183 struct cfg80211_chan_def
*chandef
)
2185 WARN_ON(!cfg80211_chandef_valid(chandef
));
2187 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2188 chandef
->chan
->center_freq
))
2190 switch (chandef
->width
) {
2191 case NL80211_CHAN_WIDTH_20_NOHT
:
2192 case NL80211_CHAN_WIDTH_20
:
2193 case NL80211_CHAN_WIDTH_40
:
2194 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2195 cfg80211_get_chandef_type(chandef
)))
2201 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2203 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2205 if (chandef
->center_freq2
&&
2206 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2211 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2212 struct cfg80211_registered_device
*rdev
,
2213 struct wireless_dev
*wdev
)
2215 struct net_device
*dev
= wdev
->netdev
;
2218 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2223 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2224 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2225 goto nla_put_failure
;
2227 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2228 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2229 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2230 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2231 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2232 rdev
->devlist_generation
^
2233 (cfg80211_rdev_list_generation
<< 2)))
2234 goto nla_put_failure
;
2236 if (rdev
->ops
->get_channel
) {
2238 struct cfg80211_chan_def chandef
;
2240 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2242 if (nl80211_send_chandef(msg
, &chandef
))
2243 goto nla_put_failure
;
2247 if (wdev
->ssid_len
) {
2248 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2249 goto nla_put_failure
;
2252 return genlmsg_end(msg
, hdr
);
2255 genlmsg_cancel(msg
, hdr
);
2259 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2263 int wp_start
= cb
->args
[0];
2264 int if_start
= cb
->args
[1];
2265 struct cfg80211_registered_device
*rdev
;
2266 struct wireless_dev
*wdev
;
2268 mutex_lock(&cfg80211_mutex
);
2269 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2270 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2272 if (wp_idx
< wp_start
) {
2278 mutex_lock(&rdev
->devlist_mtx
);
2279 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2280 if (if_idx
< if_start
) {
2284 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2285 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2287 mutex_unlock(&rdev
->devlist_mtx
);
2292 mutex_unlock(&rdev
->devlist_mtx
);
2297 mutex_unlock(&cfg80211_mutex
);
2299 cb
->args
[0] = wp_idx
;
2300 cb
->args
[1] = if_idx
;
2305 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2307 struct sk_buff
*msg
;
2308 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2309 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2311 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2315 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2321 return genlmsg_reply(msg
, info
);
2324 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2325 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2326 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2327 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2328 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2329 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2332 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2334 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2342 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2343 nla
, mntr_flags_policy
))
2346 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2348 *mntrflags
|= (1<<flag
);
2353 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2354 struct net_device
*netdev
, u8 use_4addr
,
2355 enum nl80211_iftype iftype
)
2358 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2364 case NL80211_IFTYPE_AP_VLAN
:
2365 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2368 case NL80211_IFTYPE_STATION
:
2369 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2379 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2381 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2382 struct vif_params params
;
2384 enum nl80211_iftype otype
, ntype
;
2385 struct net_device
*dev
= info
->user_ptr
[1];
2386 u32 _flags
, *flags
= NULL
;
2387 bool change
= false;
2389 memset(¶ms
, 0, sizeof(params
));
2391 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2393 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2394 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2397 if (ntype
> NL80211_IFTYPE_MAX
)
2401 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2402 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2404 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2406 if (netif_running(dev
))
2410 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2411 IEEE80211_MAX_MESH_ID_LEN
);
2412 wdev
->mesh_id_up_len
=
2413 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2414 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2415 wdev
->mesh_id_up_len
);
2419 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2420 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2422 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2426 params
.use_4addr
= -1;
2429 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2430 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2432 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2442 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2446 if (!err
&& params
.use_4addr
!= -1)
2447 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2452 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2454 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2455 struct vif_params params
;
2456 struct wireless_dev
*wdev
;
2457 struct sk_buff
*msg
;
2459 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2462 memset(¶ms
, 0, sizeof(params
));
2464 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2467 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2468 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2469 if (type
> NL80211_IFTYPE_MAX
)
2473 if (!rdev
->ops
->add_virtual_intf
||
2474 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2477 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2478 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2480 if (!is_valid_ether_addr(params
.macaddr
))
2481 return -EADDRNOTAVAIL
;
2484 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2485 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2486 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2491 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2495 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2496 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2498 wdev
= rdev_add_virtual_intf(rdev
,
2499 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2500 type
, err
? NULL
: &flags
, ¶ms
);
2503 return PTR_ERR(wdev
);
2507 case NL80211_IFTYPE_MESH_POINT
:
2508 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2511 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2512 IEEE80211_MAX_MESH_ID_LEN
);
2513 wdev
->mesh_id_up_len
=
2514 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2515 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2516 wdev
->mesh_id_up_len
);
2519 case NL80211_IFTYPE_P2P_DEVICE
:
2521 * P2P Device doesn't have a netdev, so doesn't go
2522 * through the netdev notifier and must be added here
2524 mutex_init(&wdev
->mtx
);
2525 INIT_LIST_HEAD(&wdev
->event_list
);
2526 spin_lock_init(&wdev
->event_lock
);
2527 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2528 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2530 mutex_lock(&rdev
->devlist_mtx
);
2531 wdev
->identifier
= ++rdev
->wdev_id
;
2532 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2533 rdev
->devlist_generation
++;
2534 mutex_unlock(&rdev
->devlist_mtx
);
2540 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2546 return genlmsg_reply(msg
, info
);
2549 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2551 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2552 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2554 if (!rdev
->ops
->del_virtual_intf
)
2558 * If we remove a wireless device without a netdev then clear
2559 * user_ptr[1] so that nl80211_post_doit won't dereference it
2560 * to check if it needs to do dev_put(). Otherwise it crashes
2561 * since the wdev has been freed, unlike with a netdev where
2562 * we need the dev_put() for the netdev to really be freed.
2565 info
->user_ptr
[1] = NULL
;
2567 return rdev_del_virtual_intf(rdev
, wdev
);
2570 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2572 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2573 struct net_device
*dev
= info
->user_ptr
[1];
2576 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2579 if (!rdev
->ops
->set_noack_map
)
2582 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2584 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2587 struct get_key_cookie
{
2588 struct sk_buff
*msg
;
2593 static void get_key_callback(void *c
, struct key_params
*params
)
2596 struct get_key_cookie
*cookie
= c
;
2599 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2600 params
->key_len
, params
->key
)) ||
2602 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2603 params
->seq_len
, params
->seq
)) ||
2605 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2607 goto nla_put_failure
;
2609 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2611 goto nla_put_failure
;
2614 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2615 params
->key_len
, params
->key
)) ||
2617 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2618 params
->seq_len
, params
->seq
)) ||
2620 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2622 goto nla_put_failure
;
2624 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2625 goto nla_put_failure
;
2627 nla_nest_end(cookie
->msg
, key
);
2634 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2638 struct net_device
*dev
= info
->user_ptr
[1];
2640 const u8
*mac_addr
= NULL
;
2642 struct get_key_cookie cookie
= {
2646 struct sk_buff
*msg
;
2648 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2649 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2654 if (info
->attrs
[NL80211_ATTR_MAC
])
2655 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2657 pairwise
= !!mac_addr
;
2658 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2659 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2660 if (kt
>= NUM_NL80211_KEYTYPES
)
2662 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2663 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2665 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2668 if (!rdev
->ops
->get_key
)
2671 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2674 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2678 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2679 NL80211_CMD_NEW_KEY
);
2681 goto nla_put_failure
;
2684 cookie
.idx
= key_idx
;
2686 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2687 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2688 goto nla_put_failure
;
2690 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2691 goto nla_put_failure
;
2693 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2700 goto nla_put_failure
;
2702 genlmsg_end(msg
, hdr
);
2703 return genlmsg_reply(msg
, info
);
2712 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2714 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2715 struct key_parse key
;
2717 struct net_device
*dev
= info
->user_ptr
[1];
2719 err
= nl80211_parse_key(info
, &key
);
2726 /* only support setting default key */
2727 if (!key
.def
&& !key
.defmgmt
)
2730 wdev_lock(dev
->ieee80211_ptr
);
2733 if (!rdev
->ops
->set_default_key
) {
2738 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2742 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2743 key
.def_uni
, key
.def_multi
);
2748 #ifdef CONFIG_CFG80211_WEXT
2749 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2752 if (key
.def_uni
|| !key
.def_multi
) {
2757 if (!rdev
->ops
->set_default_mgmt_key
) {
2762 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2766 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2770 #ifdef CONFIG_CFG80211_WEXT
2771 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2776 wdev_unlock(dev
->ieee80211_ptr
);
2781 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2783 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2785 struct net_device
*dev
= info
->user_ptr
[1];
2786 struct key_parse key
;
2787 const u8
*mac_addr
= NULL
;
2789 err
= nl80211_parse_key(info
, &key
);
2796 if (info
->attrs
[NL80211_ATTR_MAC
])
2797 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2799 if (key
.type
== -1) {
2801 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2803 key
.type
= NL80211_KEYTYPE_GROUP
;
2807 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2808 key
.type
!= NL80211_KEYTYPE_GROUP
)
2811 if (!rdev
->ops
->add_key
)
2814 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2815 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2819 wdev_lock(dev
->ieee80211_ptr
);
2820 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2822 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2823 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2825 wdev_unlock(dev
->ieee80211_ptr
);
2830 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2832 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2834 struct net_device
*dev
= info
->user_ptr
[1];
2835 u8
*mac_addr
= NULL
;
2836 struct key_parse key
;
2838 err
= nl80211_parse_key(info
, &key
);
2842 if (info
->attrs
[NL80211_ATTR_MAC
])
2843 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2845 if (key
.type
== -1) {
2847 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2849 key
.type
= NL80211_KEYTYPE_GROUP
;
2853 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2854 key
.type
!= NL80211_KEYTYPE_GROUP
)
2857 if (!rdev
->ops
->del_key
)
2860 wdev_lock(dev
->ieee80211_ptr
);
2861 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2863 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
2864 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2868 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2869 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2872 #ifdef CONFIG_CFG80211_WEXT
2874 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2875 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2876 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2877 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2880 wdev_unlock(dev
->ieee80211_ptr
);
2885 /* This function returns an error or the number of nested attributes */
2886 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2888 struct nlattr
*attr
;
2889 int n_entries
= 0, tmp
;
2891 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2892 if (nla_len(attr
) != ETH_ALEN
)
2902 * This function parses ACL information and allocates memory for ACL data.
2903 * On successful return, the calling function is responsible to free the
2904 * ACL buffer returned by this function.
2906 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2907 struct genl_info
*info
)
2909 enum nl80211_acl_policy acl_policy
;
2910 struct nlattr
*attr
;
2911 struct cfg80211_acl_data
*acl
;
2912 int i
= 0, n_entries
, tmp
;
2914 if (!wiphy
->max_acl_mac_addrs
)
2915 return ERR_PTR(-EOPNOTSUPP
);
2917 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2918 return ERR_PTR(-EINVAL
);
2920 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2921 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2922 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2923 return ERR_PTR(-EINVAL
);
2925 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2926 return ERR_PTR(-EINVAL
);
2928 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2930 return ERR_PTR(n_entries
);
2932 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2933 return ERR_PTR(-ENOTSUPP
);
2935 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2938 return ERR_PTR(-ENOMEM
);
2940 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2941 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2945 acl
->n_acl_entries
= n_entries
;
2946 acl
->acl_policy
= acl_policy
;
2951 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2953 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2954 struct net_device
*dev
= info
->user_ptr
[1];
2955 struct cfg80211_acl_data
*acl
;
2958 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2959 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2962 if (!dev
->ieee80211_ptr
->beacon_interval
)
2965 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2967 return PTR_ERR(acl
);
2969 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2976 static int nl80211_parse_beacon(struct genl_info
*info
,
2977 struct cfg80211_beacon_data
*bcn
)
2979 bool haveinfo
= false;
2981 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2982 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2983 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2984 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2987 memset(bcn
, 0, sizeof(*bcn
));
2989 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2990 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2991 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2997 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2998 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3000 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3007 if (info
->attrs
[NL80211_ATTR_IE
]) {
3008 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3009 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3012 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3013 bcn
->proberesp_ies
=
3014 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3015 bcn
->proberesp_ies_len
=
3016 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3019 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3020 bcn
->assocresp_ies
=
3021 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3022 bcn
->assocresp_ies_len
=
3023 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3026 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
3028 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3029 bcn
->probe_resp_len
=
3030 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3036 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3037 struct cfg80211_ap_settings
*params
)
3039 struct wireless_dev
*wdev
;
3042 mutex_lock(&rdev
->devlist_mtx
);
3044 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3045 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3046 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3049 if (!wdev
->preset_chandef
.chan
)
3052 params
->chandef
= wdev
->preset_chandef
;
3057 mutex_unlock(&rdev
->devlist_mtx
);
3062 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3063 enum nl80211_auth_type auth_type
,
3064 enum nl80211_commands cmd
)
3066 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3070 case NL80211_CMD_AUTHENTICATE
:
3071 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3072 auth_type
== NL80211_AUTHTYPE_SAE
)
3075 case NL80211_CMD_CONNECT
:
3076 case NL80211_CMD_START_AP
:
3077 /* SAE not supported yet */
3078 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3086 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3088 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3089 struct net_device
*dev
= info
->user_ptr
[1];
3090 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3091 struct cfg80211_ap_settings params
;
3093 u8 radar_detect_width
= 0;
3095 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3096 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3099 if (!rdev
->ops
->start_ap
)
3102 if (wdev
->beacon_interval
)
3105 memset(¶ms
, 0, sizeof(params
));
3107 /* these are required for START_AP */
3108 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3109 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3110 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3113 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
3117 params
.beacon_interval
=
3118 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3119 params
.dtim_period
=
3120 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3122 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3127 * In theory, some of these attributes should be required here
3128 * but since they were not used when the command was originally
3129 * added, keep them optional for old user space programs to let
3130 * them continue to work with drivers that do not need the
3131 * additional information -- drivers must check!
3133 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3134 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3136 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3137 if (params
.ssid_len
== 0 ||
3138 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3142 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3143 params
.hidden_ssid
= nla_get_u32(
3144 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3145 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3146 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3147 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3151 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3153 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3154 params
.auth_type
= nla_get_u32(
3155 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3156 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3157 NL80211_CMD_START_AP
))
3160 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3162 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3163 NL80211_MAX_NR_CIPHER_SUITES
);
3167 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3168 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3170 params
.inactivity_timeout
= nla_get_u16(
3171 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3174 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3175 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3177 params
.p2p_ctwindow
=
3178 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3179 if (params
.p2p_ctwindow
> 127)
3181 if (params
.p2p_ctwindow
!= 0 &&
3182 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3186 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3189 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3191 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3194 params
.p2p_opp_ps
= tmp
;
3195 if (params
.p2p_opp_ps
!= 0 &&
3196 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3200 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3201 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3204 } else if (wdev
->preset_chandef
.chan
) {
3205 params
.chandef
= wdev
->preset_chandef
;
3206 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3209 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3212 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3216 radar_detect_width
= BIT(params
.chandef
.width
);
3217 params
.radar_required
= true;
3220 mutex_lock(&rdev
->devlist_mtx
);
3221 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3222 params
.chandef
.chan
,
3224 radar_detect_width
);
3225 mutex_unlock(&rdev
->devlist_mtx
);
3230 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3231 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3232 if (IS_ERR(params
.acl
))
3233 return PTR_ERR(params
.acl
);
3236 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3238 wdev
->preset_chandef
= params
.chandef
;
3239 wdev
->beacon_interval
= params
.beacon_interval
;
3240 wdev
->channel
= params
.chandef
.chan
;
3241 wdev
->ssid_len
= params
.ssid_len
;
3242 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3250 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3252 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3253 struct net_device
*dev
= info
->user_ptr
[1];
3254 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3255 struct cfg80211_beacon_data params
;
3258 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3259 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3262 if (!rdev
->ops
->change_beacon
)
3265 if (!wdev
->beacon_interval
)
3268 err
= nl80211_parse_beacon(info
, ¶ms
);
3272 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3275 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3277 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3278 struct net_device
*dev
= info
->user_ptr
[1];
3280 return cfg80211_stop_ap(rdev
, dev
);
3283 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3284 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3285 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3286 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3287 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3288 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3289 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3292 static int parse_station_flags(struct genl_info
*info
,
3293 enum nl80211_iftype iftype
,
3294 struct station_parameters
*params
)
3296 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3301 * Try parsing the new attribute first so userspace
3302 * can specify both for older kernels.
3304 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3306 struct nl80211_sta_flag_update
*sta_flags
;
3308 sta_flags
= nla_data(nla
);
3309 params
->sta_flags_mask
= sta_flags
->mask
;
3310 params
->sta_flags_set
= sta_flags
->set
;
3311 params
->sta_flags_set
&= params
->sta_flags_mask
;
3312 if ((params
->sta_flags_mask
|
3313 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3318 /* if present, parse the old attribute */
3320 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3324 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3325 nla
, sta_flags_policy
))
3329 * Only allow certain flags for interface types so that
3330 * other attributes are silently ignored. Remember that
3331 * this is backward compatibility code with old userspace
3332 * and shouldn't be hit in other cases anyway.
3335 case NL80211_IFTYPE_AP
:
3336 case NL80211_IFTYPE_AP_VLAN
:
3337 case NL80211_IFTYPE_P2P_GO
:
3338 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3339 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3340 BIT(NL80211_STA_FLAG_WME
) |
3341 BIT(NL80211_STA_FLAG_MFP
);
3343 case NL80211_IFTYPE_P2P_CLIENT
:
3344 case NL80211_IFTYPE_STATION
:
3345 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3346 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3348 case NL80211_IFTYPE_MESH_POINT
:
3349 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3350 BIT(NL80211_STA_FLAG_MFP
) |
3351 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3356 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3358 params
->sta_flags_set
|= (1<<flag
);
3360 /* no longer support new API additions in old API */
3361 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3369 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3372 struct nlattr
*rate
;
3376 rate
= nla_nest_start(msg
, attr
);
3380 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3381 bitrate
= cfg80211_calculate_bitrate(info
);
3382 /* report 16-bit bitrate only if we can */
3383 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3385 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3387 if (bitrate_compat
> 0 &&
3388 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3391 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3392 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3394 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3395 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3397 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3398 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3400 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3401 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3403 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3405 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3406 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3408 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3409 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3411 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3412 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3414 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3415 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3417 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3418 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3422 nla_nest_end(msg
, rate
);
3426 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3428 struct cfg80211_registered_device
*rdev
,
3429 struct net_device
*dev
,
3430 const u8
*mac_addr
, struct station_info
*sinfo
)
3433 struct nlattr
*sinfoattr
, *bss_param
;
3435 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3439 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3440 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3441 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3442 goto nla_put_failure
;
3444 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3446 goto nla_put_failure
;
3447 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3448 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3449 sinfo
->connected_time
))
3450 goto nla_put_failure
;
3451 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3452 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3453 sinfo
->inactive_time
))
3454 goto nla_put_failure
;
3455 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3456 STATION_INFO_RX_BYTES64
)) &&
3457 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3458 (u32
)sinfo
->rx_bytes
))
3459 goto nla_put_failure
;
3460 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3461 STATION_INFO_TX_BYTES64
)) &&
3462 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3463 (u32
)sinfo
->tx_bytes
))
3464 goto nla_put_failure
;
3465 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3466 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3468 goto nla_put_failure
;
3469 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3470 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3472 goto nla_put_failure
;
3473 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3474 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3475 goto nla_put_failure
;
3476 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3477 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3478 goto nla_put_failure
;
3479 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3480 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3481 sinfo
->plink_state
))
3482 goto nla_put_failure
;
3483 switch (rdev
->wiphy
.signal_type
) {
3484 case CFG80211_SIGNAL_TYPE_MBM
:
3485 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3486 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3488 goto nla_put_failure
;
3489 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3490 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3492 goto nla_put_failure
;
3497 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3498 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3499 NL80211_STA_INFO_TX_BITRATE
))
3500 goto nla_put_failure
;
3502 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3503 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3504 NL80211_STA_INFO_RX_BITRATE
))
3505 goto nla_put_failure
;
3507 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3508 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3510 goto nla_put_failure
;
3511 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3512 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3514 goto nla_put_failure
;
3515 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3516 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3518 goto nla_put_failure
;
3519 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3520 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3522 goto nla_put_failure
;
3523 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3524 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3525 sinfo
->beacon_loss_count
))
3526 goto nla_put_failure
;
3527 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3528 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3530 goto nla_put_failure
;
3531 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3532 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3534 goto nla_put_failure
;
3535 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3536 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3538 goto nla_put_failure
;
3539 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3540 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3542 goto nla_put_failure
;
3544 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3545 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3546 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3547 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3548 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3549 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3550 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3551 sinfo
->bss_param
.dtim_period
) ||
3552 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3553 sinfo
->bss_param
.beacon_interval
))
3554 goto nla_put_failure
;
3556 nla_nest_end(msg
, bss_param
);
3558 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3559 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3560 sizeof(struct nl80211_sta_flag_update
),
3562 goto nla_put_failure
;
3563 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3564 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3566 goto nla_put_failure
;
3567 nla_nest_end(msg
, sinfoattr
);
3569 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3570 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3571 sinfo
->assoc_req_ies
))
3572 goto nla_put_failure
;
3574 return genlmsg_end(msg
, hdr
);
3577 genlmsg_cancel(msg
, hdr
);
3581 static int nl80211_dump_station(struct sk_buff
*skb
,
3582 struct netlink_callback
*cb
)
3584 struct station_info sinfo
;
3585 struct cfg80211_registered_device
*dev
;
3586 struct wireless_dev
*wdev
;
3587 u8 mac_addr
[ETH_ALEN
];
3588 int sta_idx
= cb
->args
[2];
3591 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3595 if (!wdev
->netdev
) {
3600 if (!dev
->ops
->dump_station
) {
3606 memset(&sinfo
, 0, sizeof(sinfo
));
3607 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3614 if (nl80211_send_station(skb
,
3615 NETLINK_CB(cb
->skb
).portid
,
3616 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3617 dev
, wdev
->netdev
, mac_addr
,
3626 cb
->args
[2] = sta_idx
;
3629 nl80211_finish_wdev_dump(dev
);
3634 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3637 struct net_device
*dev
= info
->user_ptr
[1];
3638 struct station_info sinfo
;
3639 struct sk_buff
*msg
;
3640 u8
*mac_addr
= NULL
;
3643 memset(&sinfo
, 0, sizeof(sinfo
));
3645 if (!info
->attrs
[NL80211_ATTR_MAC
])
3648 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3650 if (!rdev
->ops
->get_station
)
3653 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3657 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3661 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3662 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3667 return genlmsg_reply(msg
, info
);
3670 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3671 struct station_parameters
*params
,
3672 enum cfg80211_station_type statype
)
3674 if (params
->listen_interval
!= -1)
3679 /* When you run into this, adjust the code below for the new flag */
3680 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3683 case CFG80211_STA_MESH_PEER_KERNEL
:
3684 case CFG80211_STA_MESH_PEER_USER
:
3686 * No ignoring the TDLS flag here -- the userspace mesh
3687 * code doesn't have the bug of including TDLS in the
3690 if (params
->sta_flags_mask
&
3691 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3692 BIT(NL80211_STA_FLAG_MFP
) |
3693 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3696 case CFG80211_STA_TDLS_PEER_SETUP
:
3697 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3698 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3700 /* ignore since it can't change */
3701 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3704 /* disallow mesh-specific things */
3705 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3707 if (params
->local_pm
)
3709 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3713 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3714 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3715 /* TDLS can't be set, ... */
3716 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3719 * ... but don't bother the driver with it. This works around
3720 * a hostapd/wpa_supplicant issue -- it always includes the
3721 * TLDS_PEER flag in the mask even for AP mode.
3723 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3726 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3727 /* reject other things that can't change */
3728 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3730 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3732 if (params
->supported_rates
)
3734 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3738 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3744 case CFG80211_STA_AP_MLME_CLIENT
:
3745 /* Use this only for authorizing/unauthorizing a station */
3746 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3749 case CFG80211_STA_AP_CLIENT
:
3750 /* accept only the listed bits */
3751 if (params
->sta_flags_mask
&
3752 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3753 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3754 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3755 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3756 BIT(NL80211_STA_FLAG_WME
) |
3757 BIT(NL80211_STA_FLAG_MFP
)))
3760 /* but authenticated/associated only if driver handles it */
3761 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3762 params
->sta_flags_mask
&
3763 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3764 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3767 case CFG80211_STA_IBSS
:
3768 case CFG80211_STA_AP_STA
:
3769 /* reject any changes other than AUTHORIZED */
3770 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3773 case CFG80211_STA_TDLS_PEER_SETUP
:
3774 /* reject any changes other than AUTHORIZED or WME */
3775 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3776 BIT(NL80211_STA_FLAG_WME
)))
3778 /* force (at least) rates when authorizing */
3779 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3780 !params
->supported_rates
)
3783 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3784 /* reject any changes */
3786 case CFG80211_STA_MESH_PEER_KERNEL
:
3787 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3790 case CFG80211_STA_MESH_PEER_USER
:
3791 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3798 EXPORT_SYMBOL(cfg80211_check_station_change
);
3801 * Get vlan interface making sure it is running and on the right wiphy.
3803 static struct net_device
*get_vlan(struct genl_info
*info
,
3804 struct cfg80211_registered_device
*rdev
)
3806 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3807 struct net_device
*v
;
3813 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3815 return ERR_PTR(-ENODEV
);
3817 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3822 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3823 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3824 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3829 if (!netif_running(v
)) {
3837 return ERR_PTR(ret
);
3840 static struct nla_policy
3841 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3842 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3843 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3846 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3847 struct station_parameters
*params
)
3849 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3853 /* parse WME attributes if present */
3854 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3857 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3858 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3859 nl80211_sta_wme_policy
);
3863 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3864 params
->uapsd_queues
= nla_get_u8(
3865 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3866 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3869 if (tb
[NL80211_STA_WME_MAX_SP
])
3870 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3872 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3875 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3880 static int nl80211_set_station_tdls(struct genl_info
*info
,
3881 struct station_parameters
*params
)
3883 /* Dummy STA entry gets updated once the peer capabilities are known */
3884 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3886 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3887 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3889 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3891 return nl80211_parse_sta_wme(info
, params
);
3894 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3896 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3897 struct net_device
*dev
= info
->user_ptr
[1];
3898 struct station_parameters params
;
3902 memset(¶ms
, 0, sizeof(params
));
3904 params
.listen_interval
= -1;
3906 if (!rdev
->ops
->change_station
)
3909 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3912 if (!info
->attrs
[NL80211_ATTR_MAC
])
3915 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3917 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3918 params
.supported_rates
=
3919 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3920 params
.supported_rates_len
=
3921 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3924 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3926 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3927 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3930 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3932 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3933 params
.ext_capab_len
=
3934 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3937 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3940 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3943 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3944 params
.plink_action
=
3945 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3946 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3950 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3951 params
.plink_state
=
3952 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3953 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3955 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3958 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3959 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3960 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3962 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3963 pm
> NL80211_MESH_POWER_MAX
)
3966 params
.local_pm
= pm
;
3969 /* Include parameters for TDLS peer (will check later) */
3970 err
= nl80211_set_station_tdls(info
, ¶ms
);
3974 params
.vlan
= get_vlan(info
, rdev
);
3975 if (IS_ERR(params
.vlan
))
3976 return PTR_ERR(params
.vlan
);
3978 switch (dev
->ieee80211_ptr
->iftype
) {
3979 case NL80211_IFTYPE_AP
:
3980 case NL80211_IFTYPE_AP_VLAN
:
3981 case NL80211_IFTYPE_P2P_GO
:
3982 case NL80211_IFTYPE_P2P_CLIENT
:
3983 case NL80211_IFTYPE_STATION
:
3984 case NL80211_IFTYPE_ADHOC
:
3985 case NL80211_IFTYPE_MESH_POINT
:
3992 /* driver will call cfg80211_check_station_change() */
3993 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3997 dev_put(params
.vlan
);
4002 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4004 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4006 struct net_device
*dev
= info
->user_ptr
[1];
4007 struct station_parameters params
;
4008 u8
*mac_addr
= NULL
;
4010 memset(¶ms
, 0, sizeof(params
));
4012 if (!rdev
->ops
->add_station
)
4015 if (!info
->attrs
[NL80211_ATTR_MAC
])
4018 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4021 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4024 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
4027 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4028 params
.supported_rates
=
4029 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4030 params
.supported_rates_len
=
4031 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4032 params
.listen_interval
=
4033 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4035 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4036 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4039 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4041 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4042 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4045 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4047 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4048 params
.ext_capab_len
=
4049 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4052 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4054 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4056 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4058 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4060 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4061 params
.plink_action
=
4062 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4063 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4067 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4071 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4074 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4075 * as userspace might just pass through the capabilities from the IEs
4076 * directly, rather than enforcing this restriction and returning an
4077 * error in this case.
4079 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4080 params
.ht_capa
= NULL
;
4081 params
.vht_capa
= NULL
;
4084 /* When you run into this, adjust the code below for the new flag */
4085 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4087 switch (dev
->ieee80211_ptr
->iftype
) {
4088 case NL80211_IFTYPE_AP
:
4089 case NL80211_IFTYPE_AP_VLAN
:
4090 case NL80211_IFTYPE_P2P_GO
:
4091 /* ignore WME attributes if iface/sta is not capable */
4092 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4093 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4094 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4096 /* TDLS peers cannot be added */
4097 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4099 /* but don't bother the driver with it */
4100 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4102 /* allow authenticated/associated only if driver handles it */
4103 if (!(rdev
->wiphy
.features
&
4104 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4105 params
.sta_flags_mask
&
4106 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4107 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4110 /* must be last in here for error handling */
4111 params
.vlan
= get_vlan(info
, rdev
);
4112 if (IS_ERR(params
.vlan
))
4113 return PTR_ERR(params
.vlan
);
4115 case NL80211_IFTYPE_MESH_POINT
:
4116 /* ignore uAPSD data */
4117 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4119 /* associated is disallowed */
4120 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4122 /* TDLS peers cannot be added */
4123 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4126 case NL80211_IFTYPE_STATION
:
4127 case NL80211_IFTYPE_P2P_CLIENT
:
4128 /* ignore uAPSD data */
4129 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4131 /* these are disallowed */
4132 if (params
.sta_flags_mask
&
4133 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4134 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4136 /* Only TDLS peers can be added */
4137 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4139 /* Can only add if TDLS ... */
4140 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4142 /* ... with external setup is supported */
4143 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4146 * Older wpa_supplicant versions always mark the TDLS peer
4147 * as authorized, but it shouldn't yet be.
4149 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4155 /* be aware of params.vlan when changing code here */
4157 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4160 dev_put(params
.vlan
);
4164 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4166 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4167 struct net_device
*dev
= info
->user_ptr
[1];
4168 u8
*mac_addr
= NULL
;
4170 if (info
->attrs
[NL80211_ATTR_MAC
])
4171 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4173 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4174 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4175 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4176 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4179 if (!rdev
->ops
->del_station
)
4182 return rdev_del_station(rdev
, dev
, mac_addr
);
4185 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4186 int flags
, struct net_device
*dev
,
4187 u8
*dst
, u8
*next_hop
,
4188 struct mpath_info
*pinfo
)
4191 struct nlattr
*pinfoattr
;
4193 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4197 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4198 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4199 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4200 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4201 goto nla_put_failure
;
4203 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4205 goto nla_put_failure
;
4206 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4207 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4209 goto nla_put_failure
;
4210 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4211 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4212 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4213 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4215 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4216 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4218 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4219 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4221 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4222 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4223 pinfo
->discovery_timeout
)) ||
4224 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4225 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4226 pinfo
->discovery_retries
)))
4227 goto nla_put_failure
;
4229 nla_nest_end(msg
, pinfoattr
);
4231 return genlmsg_end(msg
, hdr
);
4234 genlmsg_cancel(msg
, hdr
);
4238 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4239 struct netlink_callback
*cb
)
4241 struct mpath_info pinfo
;
4242 struct cfg80211_registered_device
*dev
;
4243 struct wireless_dev
*wdev
;
4245 u8 next_hop
[ETH_ALEN
];
4246 int path_idx
= cb
->args
[2];
4249 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4253 if (!dev
->ops
->dump_mpath
) {
4258 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4264 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4271 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4272 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4273 wdev
->netdev
, dst
, next_hop
,
4282 cb
->args
[2] = path_idx
;
4285 nl80211_finish_wdev_dump(dev
);
4289 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4293 struct net_device
*dev
= info
->user_ptr
[1];
4294 struct mpath_info pinfo
;
4295 struct sk_buff
*msg
;
4297 u8 next_hop
[ETH_ALEN
];
4299 memset(&pinfo
, 0, sizeof(pinfo
));
4301 if (!info
->attrs
[NL80211_ATTR_MAC
])
4304 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4306 if (!rdev
->ops
->get_mpath
)
4309 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4312 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4316 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4320 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4321 dev
, dst
, next_hop
, &pinfo
) < 0) {
4326 return genlmsg_reply(msg
, info
);
4329 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4331 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4332 struct net_device
*dev
= info
->user_ptr
[1];
4334 u8
*next_hop
= NULL
;
4336 if (!info
->attrs
[NL80211_ATTR_MAC
])
4339 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4342 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4343 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4345 if (!rdev
->ops
->change_mpath
)
4348 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4351 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4354 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4356 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4357 struct net_device
*dev
= info
->user_ptr
[1];
4359 u8
*next_hop
= NULL
;
4361 if (!info
->attrs
[NL80211_ATTR_MAC
])
4364 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4367 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4368 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4370 if (!rdev
->ops
->add_mpath
)
4373 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4376 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4379 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4381 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4382 struct net_device
*dev
= info
->user_ptr
[1];
4385 if (info
->attrs
[NL80211_ATTR_MAC
])
4386 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4388 if (!rdev
->ops
->del_mpath
)
4391 return rdev_del_mpath(rdev
, dev
, dst
);
4394 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4396 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4397 struct net_device
*dev
= info
->user_ptr
[1];
4398 struct bss_parameters params
;
4400 memset(¶ms
, 0, sizeof(params
));
4401 /* default to not changing parameters */
4402 params
.use_cts_prot
= -1;
4403 params
.use_short_preamble
= -1;
4404 params
.use_short_slot_time
= -1;
4405 params
.ap_isolate
= -1;
4406 params
.ht_opmode
= -1;
4407 params
.p2p_ctwindow
= -1;
4408 params
.p2p_opp_ps
= -1;
4410 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4411 params
.use_cts_prot
=
4412 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4413 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4414 params
.use_short_preamble
=
4415 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4416 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4417 params
.use_short_slot_time
=
4418 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4419 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4420 params
.basic_rates
=
4421 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4422 params
.basic_rates_len
=
4423 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4425 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4426 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4427 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4429 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4431 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4432 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4434 params
.p2p_ctwindow
=
4435 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4436 if (params
.p2p_ctwindow
< 0)
4438 if (params
.p2p_ctwindow
!= 0 &&
4439 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4443 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4446 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4448 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4451 params
.p2p_opp_ps
= tmp
;
4452 if (params
.p2p_opp_ps
&&
4453 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4457 if (!rdev
->ops
->change_bss
)
4460 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4461 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4464 return rdev_change_bss(rdev
, dev
, ¶ms
);
4467 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4468 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4469 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4470 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4471 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4472 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4473 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4476 static int parse_reg_rule(struct nlattr
*tb
[],
4477 struct ieee80211_reg_rule
*reg_rule
)
4479 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4480 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4482 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4484 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4486 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4488 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4490 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4493 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4495 freq_range
->start_freq_khz
=
4496 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4497 freq_range
->end_freq_khz
=
4498 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4499 freq_range
->max_bandwidth_khz
=
4500 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4502 power_rule
->max_eirp
=
4503 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4505 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4506 power_rule
->max_antenna_gain
=
4507 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4512 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4516 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4519 * You should only get this when cfg80211 hasn't yet initialized
4520 * completely when built-in to the kernel right between the time
4521 * window between nl80211_init() and regulatory_init(), if that is
4524 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4525 return -EINPROGRESS
;
4527 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4530 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4532 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4533 user_reg_hint_type
=
4534 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4536 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4538 switch (user_reg_hint_type
) {
4539 case NL80211_USER_REG_HINT_USER
:
4540 case NL80211_USER_REG_HINT_CELL_BASE
:
4546 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4551 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4552 struct genl_info
*info
)
4554 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4555 struct net_device
*dev
= info
->user_ptr
[1];
4556 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4557 struct mesh_config cur_params
;
4560 struct nlattr
*pinfoattr
;
4561 struct sk_buff
*msg
;
4563 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4566 if (!rdev
->ops
->get_mesh_config
)
4570 /* If not connected, get default parameters */
4571 if (!wdev
->mesh_id_len
)
4572 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4574 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4580 /* Draw up a netlink message to send back */
4581 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4584 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4585 NL80211_CMD_GET_MESH_CONFIG
);
4588 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4590 goto nla_put_failure
;
4591 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4592 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4593 cur_params
.dot11MeshRetryTimeout
) ||
4594 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4595 cur_params
.dot11MeshConfirmTimeout
) ||
4596 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4597 cur_params
.dot11MeshHoldingTimeout
) ||
4598 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4599 cur_params
.dot11MeshMaxPeerLinks
) ||
4600 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4601 cur_params
.dot11MeshMaxRetries
) ||
4602 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4603 cur_params
.dot11MeshTTL
) ||
4604 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4605 cur_params
.element_ttl
) ||
4606 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4607 cur_params
.auto_open_plinks
) ||
4608 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4609 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4610 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4611 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4612 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4613 cur_params
.path_refresh_time
) ||
4614 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4615 cur_params
.min_discovery_timeout
) ||
4616 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4617 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4618 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4619 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4620 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4621 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4622 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4623 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4624 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4625 cur_params
.dot11MeshHWMPRootMode
) ||
4626 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4627 cur_params
.dot11MeshHWMPRannInterval
) ||
4628 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4629 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4630 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4631 cur_params
.dot11MeshForwarding
) ||
4632 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4633 cur_params
.rssi_threshold
) ||
4634 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4635 cur_params
.ht_opmode
) ||
4636 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4637 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4638 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4639 cur_params
.dot11MeshHWMProotInterval
) ||
4640 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4641 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4642 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4643 cur_params
.power_mode
) ||
4644 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4645 cur_params
.dot11MeshAwakeWindowDuration
))
4646 goto nla_put_failure
;
4647 nla_nest_end(msg
, pinfoattr
);
4648 genlmsg_end(msg
, hdr
);
4649 return genlmsg_reply(msg
, info
);
4652 genlmsg_cancel(msg
, hdr
);
4658 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4659 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4660 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4661 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4662 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4663 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4664 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4665 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4666 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4667 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4668 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4669 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4670 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4671 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4672 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4673 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4674 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4675 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4676 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4677 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4678 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4679 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4680 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4681 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4682 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4683 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4684 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4685 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4688 static const struct nla_policy
4689 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4690 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4691 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4692 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4693 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4694 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4695 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4696 .len
= IEEE80211_MAX_DATA_LEN
},
4697 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4700 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4701 struct mesh_config
*cfg
,
4704 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4707 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4710 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4712 cfg->param = fn(tb[attr]); \
4713 mask |= (1 << (attr - 1)); \
4718 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4720 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4721 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4722 nl80211_meshconf_params_policy
))
4725 /* This makes sure that there aren't more than 32 mesh config
4726 * parameters (otherwise our bitfield scheme would not work.) */
4727 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4729 /* Fill in the params struct */
4730 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4731 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4733 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4734 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4736 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4737 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4739 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4740 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4742 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4743 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4745 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4746 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4747 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4748 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4750 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4751 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4753 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4755 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4758 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4760 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4761 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4763 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4764 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4766 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4768 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4770 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4772 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4774 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4776 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4778 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4779 dot11MeshHWMPnetDiameterTraversalTime
,
4781 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4783 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4784 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4786 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4787 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4789 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4790 dot11MeshGateAnnouncementProtocol
, 0, 1,
4791 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4793 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4794 mask
, NL80211_MESHCONF_FORWARDING
,
4796 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4797 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4799 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4800 mask
, NL80211_MESHCONF_HT_OPMODE
,
4802 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4804 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4806 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4807 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4809 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4810 dot11MeshHWMPconfirmationInterval
,
4812 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4814 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4815 NL80211_MESH_POWER_ACTIVE
,
4816 NL80211_MESH_POWER_MAX
,
4817 mask
, NL80211_MESHCONF_POWER_MODE
,
4819 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4821 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4827 #undef FILL_IN_MESH_PARAM_IF_SET
4830 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4831 struct mesh_setup
*setup
)
4833 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4834 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4836 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4838 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4839 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4840 nl80211_mesh_setup_params_policy
))
4843 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4844 setup
->sync_method
=
4845 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4846 IEEE80211_SYNC_METHOD_VENDOR
:
4847 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4849 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4850 setup
->path_sel_proto
=
4851 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4852 IEEE80211_PATH_PROTOCOL_VENDOR
:
4853 IEEE80211_PATH_PROTOCOL_HWMP
;
4855 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4856 setup
->path_metric
=
4857 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4858 IEEE80211_PATH_METRIC_VENDOR
:
4859 IEEE80211_PATH_METRIC_AIRTIME
;
4862 if (tb
[NL80211_MESH_SETUP_IE
]) {
4863 struct nlattr
*ieattr
=
4864 tb
[NL80211_MESH_SETUP_IE
];
4865 if (!is_valid_ie_attr(ieattr
))
4867 setup
->ie
= nla_data(ieattr
);
4868 setup
->ie_len
= nla_len(ieattr
);
4870 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4871 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4873 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4874 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4875 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4876 if (setup
->is_secure
)
4877 setup
->user_mpm
= true;
4882 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4883 struct genl_info
*info
)
4885 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4886 struct net_device
*dev
= info
->user_ptr
[1];
4887 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4888 struct mesh_config cfg
;
4892 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4895 if (!rdev
->ops
->update_mesh_config
)
4898 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4903 if (!wdev
->mesh_id_len
)
4907 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4914 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4916 const struct ieee80211_regdomain
*regdom
;
4917 struct sk_buff
*msg
;
4919 struct nlattr
*nl_reg_rules
;
4923 mutex_lock(&cfg80211_mutex
);
4925 if (!cfg80211_regdomain
)
4928 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4934 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4935 NL80211_CMD_GET_REG
);
4939 if (reg_last_request_cell_base() &&
4940 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4941 NL80211_USER_REG_HINT_CELL_BASE
))
4942 goto nla_put_failure
;
4945 regdom
= rcu_dereference(cfg80211_regdomain
);
4947 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4948 (regdom
->dfs_region
&&
4949 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4950 goto nla_put_failure_rcu
;
4952 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4954 goto nla_put_failure_rcu
;
4956 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4957 struct nlattr
*nl_reg_rule
;
4958 const struct ieee80211_reg_rule
*reg_rule
;
4959 const struct ieee80211_freq_range
*freq_range
;
4960 const struct ieee80211_power_rule
*power_rule
;
4962 reg_rule
= ®dom
->reg_rules
[i
];
4963 freq_range
= ®_rule
->freq_range
;
4964 power_rule
= ®_rule
->power_rule
;
4966 nl_reg_rule
= nla_nest_start(msg
, i
);
4968 goto nla_put_failure_rcu
;
4970 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4972 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4973 freq_range
->start_freq_khz
) ||
4974 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4975 freq_range
->end_freq_khz
) ||
4976 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4977 freq_range
->max_bandwidth_khz
) ||
4978 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4979 power_rule
->max_antenna_gain
) ||
4980 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4981 power_rule
->max_eirp
))
4982 goto nla_put_failure_rcu
;
4984 nla_nest_end(msg
, nl_reg_rule
);
4988 nla_nest_end(msg
, nl_reg_rules
);
4990 genlmsg_end(msg
, hdr
);
4991 err
= genlmsg_reply(msg
, info
);
4994 nla_put_failure_rcu
:
4997 genlmsg_cancel(msg
, hdr
);
5002 mutex_unlock(&cfg80211_mutex
);
5006 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5008 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5009 struct nlattr
*nl_reg_rule
;
5010 char *alpha2
= NULL
;
5011 int rem_reg_rules
= 0, r
= 0;
5012 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5014 struct ieee80211_regdomain
*rd
= NULL
;
5016 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5019 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5022 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5024 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5025 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5027 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5030 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5034 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5035 num_rules
* sizeof(struct ieee80211_reg_rule
);
5037 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5041 rd
->n_reg_rules
= num_rules
;
5042 rd
->alpha2
[0] = alpha2
[0];
5043 rd
->alpha2
[1] = alpha2
[1];
5046 * Disable DFS master mode if the DFS region was
5047 * not supported or known on this kernel.
5049 if (reg_supported_dfs_region(dfs_region
))
5050 rd
->dfs_region
= dfs_region
;
5052 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5054 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5055 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5057 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5063 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5069 mutex_lock(&cfg80211_mutex
);
5072 /* set_regdom took ownership */
5074 mutex_unlock(&cfg80211_mutex
);
5081 static int validate_scan_freqs(struct nlattr
*freqs
)
5083 struct nlattr
*attr1
, *attr2
;
5084 int n_channels
= 0, tmp1
, tmp2
;
5086 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5089 * Some hardware has a limited channel list for
5090 * scanning, and it is pretty much nonsensical
5091 * to scan for a channel twice, so disallow that
5092 * and don't require drivers to check that the
5093 * channel list they get isn't longer than what
5094 * they can scan, as long as they can scan all
5095 * the channels they registered at once.
5097 nla_for_each_nested(attr2
, freqs
, tmp2
)
5098 if (attr1
!= attr2
&&
5099 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5106 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5108 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5109 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5110 struct cfg80211_scan_request
*request
;
5111 struct nlattr
*attr
;
5112 struct wiphy
*wiphy
;
5113 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5116 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5119 wiphy
= &rdev
->wiphy
;
5121 if (!rdev
->ops
->scan
)
5124 mutex_lock(&rdev
->sched_scan_mtx
);
5125 if (rdev
->scan_req
) {
5130 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5131 n_channels
= validate_scan_freqs(
5132 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5138 enum ieee80211_band band
;
5141 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5142 if (wiphy
->bands
[band
])
5143 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5146 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5147 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5150 if (n_ssids
> wiphy
->max_scan_ssids
) {
5155 if (info
->attrs
[NL80211_ATTR_IE
])
5156 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5160 if (ie_len
> wiphy
->max_scan_ie_len
) {
5165 request
= kzalloc(sizeof(*request
)
5166 + sizeof(*request
->ssids
) * n_ssids
5167 + sizeof(*request
->channels
) * n_channels
5168 + ie_len
, GFP_KERNEL
);
5175 request
->ssids
= (void *)&request
->channels
[n_channels
];
5176 request
->n_ssids
= n_ssids
;
5179 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5181 request
->ie
= (void *)(request
->channels
+ n_channels
);
5185 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5186 /* user specified, bail out if channel not found */
5187 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5188 struct ieee80211_channel
*chan
;
5190 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5197 /* ignore disabled channels */
5198 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5201 request
->channels
[i
] = chan
;
5205 enum ieee80211_band band
;
5208 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5210 if (!wiphy
->bands
[band
])
5212 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5213 struct ieee80211_channel
*chan
;
5215 chan
= &wiphy
->bands
[band
]->channels
[j
];
5217 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5220 request
->channels
[i
] = chan
;
5231 request
->n_channels
= i
;
5234 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5235 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5236 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5240 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5241 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5246 if (info
->attrs
[NL80211_ATTR_IE
]) {
5247 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5248 memcpy((void *)request
->ie
,
5249 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5253 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5254 if (wiphy
->bands
[i
])
5256 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5258 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5259 nla_for_each_nested(attr
,
5260 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5262 enum ieee80211_band band
= nla_type(attr
);
5264 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5268 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5271 &request
->rates
[band
]);
5277 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5278 request
->flags
= nla_get_u32(
5279 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5280 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5281 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5282 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5283 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5290 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5292 request
->wdev
= wdev
;
5293 request
->wiphy
= &rdev
->wiphy
;
5294 request
->scan_start
= jiffies
;
5296 rdev
->scan_req
= request
;
5297 err
= rdev_scan(rdev
, request
);
5300 nl80211_send_scan_start(rdev
, wdev
);
5302 dev_hold(wdev
->netdev
);
5305 rdev
->scan_req
= NULL
;
5310 mutex_unlock(&rdev
->sched_scan_mtx
);
5314 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5315 struct genl_info
*info
)
5317 struct cfg80211_sched_scan_request
*request
;
5318 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5319 struct net_device
*dev
= info
->user_ptr
[1];
5320 struct nlattr
*attr
;
5321 struct wiphy
*wiphy
;
5322 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5324 enum ieee80211_band band
;
5326 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5328 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5329 !rdev
->ops
->sched_scan_start
)
5332 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5335 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5338 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5342 wiphy
= &rdev
->wiphy
;
5344 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5345 n_channels
= validate_scan_freqs(
5346 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5352 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5353 if (wiphy
->bands
[band
])
5354 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5357 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5358 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5362 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5365 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5366 nla_for_each_nested(attr
,
5367 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5371 if (n_match_sets
> wiphy
->max_match_sets
)
5374 if (info
->attrs
[NL80211_ATTR_IE
])
5375 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5379 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5382 mutex_lock(&rdev
->sched_scan_mtx
);
5384 if (rdev
->sched_scan_req
) {
5389 request
= kzalloc(sizeof(*request
)
5390 + sizeof(*request
->ssids
) * n_ssids
5391 + sizeof(*request
->match_sets
) * n_match_sets
5392 + sizeof(*request
->channels
) * n_channels
5393 + ie_len
, GFP_KERNEL
);
5400 request
->ssids
= (void *)&request
->channels
[n_channels
];
5401 request
->n_ssids
= n_ssids
;
5404 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5406 request
->ie
= (void *)(request
->channels
+ n_channels
);
5411 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5412 else if (request
->ssids
)
5413 request
->match_sets
=
5414 (void *)(request
->ssids
+ n_ssids
);
5416 request
->match_sets
=
5417 (void *)(request
->channels
+ n_channels
);
5419 request
->n_match_sets
= n_match_sets
;
5422 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5423 /* user specified, bail out if channel not found */
5424 nla_for_each_nested(attr
,
5425 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5427 struct ieee80211_channel
*chan
;
5429 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5436 /* ignore disabled channels */
5437 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5440 request
->channels
[i
] = chan
;
5445 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5447 if (!wiphy
->bands
[band
])
5449 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5450 struct ieee80211_channel
*chan
;
5452 chan
= &wiphy
->bands
[band
]->channels
[j
];
5454 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5457 request
->channels
[i
] = chan
;
5468 request
->n_channels
= i
;
5471 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5472 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5474 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5478 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5479 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5486 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5487 nla_for_each_nested(attr
,
5488 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5490 struct nlattr
*ssid
, *rssi
;
5492 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5493 nla_data(attr
), nla_len(attr
),
5494 nl80211_match_policy
);
5495 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5497 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5501 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5502 nla_data(ssid
), nla_len(ssid
));
5503 request
->match_sets
[i
].ssid
.ssid_len
=
5506 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5508 request
->rssi_thold
= nla_get_u32(rssi
);
5510 request
->rssi_thold
=
5511 NL80211_SCAN_RSSI_THOLD_OFF
;
5516 if (info
->attrs
[NL80211_ATTR_IE
]) {
5517 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5518 memcpy((void *)request
->ie
,
5519 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5523 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5524 request
->flags
= nla_get_u32(
5525 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5526 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5527 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5528 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5529 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5536 request
->wiphy
= &rdev
->wiphy
;
5537 request
->interval
= interval
;
5538 request
->scan_start
= jiffies
;
5540 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5542 rdev
->sched_scan_req
= request
;
5543 nl80211_send_sched_scan(rdev
, dev
,
5544 NL80211_CMD_START_SCHED_SCAN
);
5551 mutex_unlock(&rdev
->sched_scan_mtx
);
5555 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5556 struct genl_info
*info
)
5558 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5561 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5562 !rdev
->ops
->sched_scan_stop
)
5565 mutex_lock(&rdev
->sched_scan_mtx
);
5566 err
= __cfg80211_stop_sched_scan(rdev
, false);
5567 mutex_unlock(&rdev
->sched_scan_mtx
);
5572 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5573 struct genl_info
*info
)
5575 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5576 struct net_device
*dev
= info
->user_ptr
[1];
5577 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5578 struct cfg80211_chan_def chandef
;
5581 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5585 if (wdev
->cac_started
)
5588 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5595 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5598 if (!rdev
->ops
->start_radar_detection
)
5601 mutex_lock(&rdev
->devlist_mtx
);
5602 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5603 chandef
.chan
, CHAN_MODE_SHARED
,
5604 BIT(chandef
.width
));
5608 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5610 wdev
->channel
= chandef
.chan
;
5611 wdev
->cac_started
= true;
5612 wdev
->cac_start_time
= jiffies
;
5615 mutex_unlock(&rdev
->devlist_mtx
);
5620 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5622 struct cfg80211_registered_device
*rdev
,
5623 struct wireless_dev
*wdev
,
5624 struct cfg80211_internal_bss
*intbss
)
5626 struct cfg80211_bss
*res
= &intbss
->pub
;
5627 const struct cfg80211_bss_ies
*ies
;
5632 ASSERT_WDEV_LOCK(wdev
);
5634 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5635 NL80211_CMD_NEW_SCAN_RESULTS
);
5639 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5641 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5642 goto nla_put_failure
;
5644 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5645 goto nla_put_failure
;
5646 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5647 goto nla_put_failure
;
5649 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5651 goto nla_put_failure
;
5652 if ((!is_zero_ether_addr(res
->bssid
) &&
5653 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5654 goto nla_put_failure
;
5657 ies
= rcu_dereference(res
->ies
);
5659 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5660 goto fail_unlock_rcu
;
5662 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5663 ies
->len
, ies
->data
))
5664 goto fail_unlock_rcu
;
5666 ies
= rcu_dereference(res
->beacon_ies
);
5668 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5669 goto fail_unlock_rcu
;
5670 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5671 ies
->len
, ies
->data
))
5672 goto fail_unlock_rcu
;
5676 if (res
->beacon_interval
&&
5677 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5678 goto nla_put_failure
;
5679 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5680 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5681 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5682 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5683 goto nla_put_failure
;
5685 switch (rdev
->wiphy
.signal_type
) {
5686 case CFG80211_SIGNAL_TYPE_MBM
:
5687 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5688 goto nla_put_failure
;
5690 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5691 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5692 goto nla_put_failure
;
5698 switch (wdev
->iftype
) {
5699 case NL80211_IFTYPE_P2P_CLIENT
:
5700 case NL80211_IFTYPE_STATION
:
5701 if (intbss
== wdev
->current_bss
&&
5702 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5703 NL80211_BSS_STATUS_ASSOCIATED
))
5704 goto nla_put_failure
;
5706 case NL80211_IFTYPE_ADHOC
:
5707 if (intbss
== wdev
->current_bss
&&
5708 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5709 NL80211_BSS_STATUS_IBSS_JOINED
))
5710 goto nla_put_failure
;
5716 nla_nest_end(msg
, bss
);
5718 return genlmsg_end(msg
, hdr
);
5723 genlmsg_cancel(msg
, hdr
);
5727 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5729 struct cfg80211_registered_device
*rdev
;
5730 struct cfg80211_internal_bss
*scan
;
5731 struct wireless_dev
*wdev
;
5732 int start
= cb
->args
[2], idx
= 0;
5735 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5740 spin_lock_bh(&rdev
->bss_lock
);
5741 cfg80211_bss_expire(rdev
);
5743 cb
->seq
= rdev
->bss_generation
;
5745 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5748 if (nl80211_send_bss(skb
, cb
,
5749 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5750 rdev
, wdev
, scan
) < 0) {
5756 spin_unlock_bh(&rdev
->bss_lock
);
5760 nl80211_finish_wdev_dump(rdev
);
5765 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5766 int flags
, struct net_device
*dev
,
5767 struct survey_info
*survey
)
5770 struct nlattr
*infoattr
;
5772 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5773 NL80211_CMD_NEW_SURVEY_RESULTS
);
5777 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5778 goto nla_put_failure
;
5780 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5782 goto nla_put_failure
;
5784 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5785 survey
->channel
->center_freq
))
5786 goto nla_put_failure
;
5788 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5789 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5790 goto nla_put_failure
;
5791 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5792 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5793 goto nla_put_failure
;
5794 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5795 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5796 survey
->channel_time
))
5797 goto nla_put_failure
;
5798 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5799 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5800 survey
->channel_time_busy
))
5801 goto nla_put_failure
;
5802 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5803 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5804 survey
->channel_time_ext_busy
))
5805 goto nla_put_failure
;
5806 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5807 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5808 survey
->channel_time_rx
))
5809 goto nla_put_failure
;
5810 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5811 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5812 survey
->channel_time_tx
))
5813 goto nla_put_failure
;
5815 nla_nest_end(msg
, infoattr
);
5817 return genlmsg_end(msg
, hdr
);
5820 genlmsg_cancel(msg
, hdr
);
5824 static int nl80211_dump_survey(struct sk_buff
*skb
,
5825 struct netlink_callback
*cb
)
5827 struct survey_info survey
;
5828 struct cfg80211_registered_device
*dev
;
5829 struct wireless_dev
*wdev
;
5830 int survey_idx
= cb
->args
[2];
5833 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5837 if (!wdev
->netdev
) {
5842 if (!dev
->ops
->dump_survey
) {
5848 struct ieee80211_channel
*chan
;
5850 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5856 /* Survey without a channel doesn't make sense */
5857 if (!survey
.channel
) {
5862 chan
= ieee80211_get_channel(&dev
->wiphy
,
5863 survey
.channel
->center_freq
);
5864 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5869 if (nl80211_send_survey(skb
,
5870 NETLINK_CB(cb
->skb
).portid
,
5871 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5872 wdev
->netdev
, &survey
) < 0)
5878 cb
->args
[2] = survey_idx
;
5881 nl80211_finish_wdev_dump(dev
);
5885 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5887 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5888 NL80211_WPA_VERSION_2
));
5891 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5893 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5894 struct net_device
*dev
= info
->user_ptr
[1];
5895 struct ieee80211_channel
*chan
;
5896 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5897 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5898 enum nl80211_auth_type auth_type
;
5899 struct key_parse key
;
5900 bool local_state_change
;
5902 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5905 if (!info
->attrs
[NL80211_ATTR_MAC
])
5908 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5911 if (!info
->attrs
[NL80211_ATTR_SSID
])
5914 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5917 err
= nl80211_parse_key(info
, &key
);
5922 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5924 if (!key
.p
.key
|| !key
.p
.key_len
)
5926 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5927 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5928 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5929 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5941 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5942 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5951 if (!rdev
->ops
->auth
)
5954 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5955 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5958 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5959 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5960 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5961 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5964 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5965 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5967 if (info
->attrs
[NL80211_ATTR_IE
]) {
5968 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5969 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5972 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5973 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5976 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5977 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5980 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5981 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5983 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5984 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5985 /* need to include at least Auth Transaction and Status Code */
5986 if (sae_data_len
< 4)
5990 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5993 * Since we no longer track auth state, ignore
5994 * requests to only change local state.
5996 if (local_state_change
)
5999 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
6000 ssid
, ssid_len
, ie
, ie_len
,
6001 key
.p
.key
, key
.p
.key_len
, key
.idx
,
6002 sae_data
, sae_data_len
);
6005 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
6006 struct genl_info
*info
,
6007 struct cfg80211_crypto_settings
*settings
,
6010 memset(settings
, 0, sizeof(*settings
));
6012 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6014 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6016 proto
= nla_get_u16(
6017 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6018 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6019 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6022 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6023 settings
->control_port_no_encrypt
= true;
6025 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6027 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6031 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6032 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6033 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6035 if (len
% sizeof(u32
))
6038 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6041 memcpy(settings
->ciphers_pairwise
, data
, len
);
6043 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6044 if (!cfg80211_supported_cipher_suite(
6046 settings
->ciphers_pairwise
[i
]))
6050 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6051 settings
->cipher_group
=
6052 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6053 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6054 settings
->cipher_group
))
6058 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6059 settings
->wpa_versions
=
6060 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6061 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6065 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6069 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6070 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6071 settings
->n_akm_suites
= len
/ sizeof(u32
);
6073 if (len
% sizeof(u32
))
6076 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6079 memcpy(settings
->akm_suites
, data
, len
);
6085 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6087 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6088 struct net_device
*dev
= info
->user_ptr
[1];
6089 struct ieee80211_channel
*chan
;
6090 struct cfg80211_assoc_request req
= {};
6091 const u8
*bssid
, *ssid
;
6092 int err
, ssid_len
= 0;
6094 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6097 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6098 !info
->attrs
[NL80211_ATTR_SSID
] ||
6099 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6102 if (!rdev
->ops
->assoc
)
6105 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6106 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6109 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6111 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6112 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6113 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6116 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6117 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6119 if (info
->attrs
[NL80211_ATTR_IE
]) {
6120 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6121 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6124 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6125 enum nl80211_mfp mfp
=
6126 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6127 if (mfp
== NL80211_MFP_REQUIRED
)
6129 else if (mfp
!= NL80211_MFP_NO
)
6133 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6134 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6136 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6137 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6139 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6140 memcpy(&req
.ht_capa_mask
,
6141 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6142 sizeof(req
.ht_capa_mask
));
6144 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6145 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6147 memcpy(&req
.ht_capa
,
6148 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6149 sizeof(req
.ht_capa
));
6152 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6153 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6155 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6156 memcpy(&req
.vht_capa_mask
,
6157 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6158 sizeof(req
.vht_capa_mask
));
6160 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6161 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6163 memcpy(&req
.vht_capa
,
6164 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6165 sizeof(req
.vht_capa
));
6168 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6170 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6171 ssid
, ssid_len
, &req
);
6176 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6178 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6179 struct net_device
*dev
= info
->user_ptr
[1];
6180 const u8
*ie
= NULL
, *bssid
;
6183 bool local_state_change
;
6185 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6188 if (!info
->attrs
[NL80211_ATTR_MAC
])
6191 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6194 if (!rdev
->ops
->deauth
)
6197 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6198 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6201 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6203 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6204 if (reason_code
== 0) {
6205 /* Reason Code 0 is reserved */
6209 if (info
->attrs
[NL80211_ATTR_IE
]) {
6210 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6211 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6214 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6216 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6217 local_state_change
);
6220 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6222 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6223 struct net_device
*dev
= info
->user_ptr
[1];
6224 const u8
*ie
= NULL
, *bssid
;
6227 bool local_state_change
;
6229 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6232 if (!info
->attrs
[NL80211_ATTR_MAC
])
6235 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6238 if (!rdev
->ops
->disassoc
)
6241 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6242 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6245 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6247 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6248 if (reason_code
== 0) {
6249 /* Reason Code 0 is reserved */
6253 if (info
->attrs
[NL80211_ATTR_IE
]) {
6254 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6255 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6258 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6260 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6261 local_state_change
);
6265 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6266 int mcast_rate
[IEEE80211_NUM_BANDS
],
6269 struct wiphy
*wiphy
= &rdev
->wiphy
;
6273 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6274 struct ieee80211_supported_band
*sband
;
6276 sband
= wiphy
->bands
[band
];
6280 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6281 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6282 mcast_rate
[band
] = i
+ 1;
6292 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6294 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6295 struct net_device
*dev
= info
->user_ptr
[1];
6296 struct cfg80211_ibss_params ibss
;
6297 struct wiphy
*wiphy
;
6298 struct cfg80211_cached_keys
*connkeys
= NULL
;
6301 memset(&ibss
, 0, sizeof(ibss
));
6303 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6306 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6307 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6310 ibss
.beacon_interval
= 100;
6312 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6313 ibss
.beacon_interval
=
6314 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6315 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6319 if (!rdev
->ops
->join_ibss
)
6322 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6325 wiphy
= &rdev
->wiphy
;
6327 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6328 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6330 if (!is_valid_ether_addr(ibss
.bssid
))
6333 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6334 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6336 if (info
->attrs
[NL80211_ATTR_IE
]) {
6337 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6338 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6341 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6345 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6348 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
6350 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
6351 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
6354 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6355 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6357 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6359 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6361 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6362 struct ieee80211_supported_band
*sband
=
6363 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6365 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6371 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6372 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6373 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6376 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6379 connkeys
= nl80211_parse_connkeys(rdev
,
6380 info
->attrs
[NL80211_ATTR_KEYS
],
6382 if (IS_ERR(connkeys
))
6383 return PTR_ERR(connkeys
);
6385 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6393 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6395 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6401 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6403 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6404 struct net_device
*dev
= info
->user_ptr
[1];
6406 if (!rdev
->ops
->leave_ibss
)
6409 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6412 return cfg80211_leave_ibss(rdev
, dev
, false);
6415 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6417 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6418 struct net_device
*dev
= info
->user_ptr
[1];
6419 int mcast_rate
[IEEE80211_NUM_BANDS
];
6423 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6424 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6427 if (!rdev
->ops
->set_mcast_rate
)
6430 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6432 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6435 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6436 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6439 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6444 static struct sk_buff
*
6445 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
6446 int approxlen
, u32 portid
, u32 seq
,
6447 enum nl80211_commands cmd
,
6448 enum nl80211_attrs attr
,
6449 const struct nl80211_vendor_cmd_info
*info
,
6452 struct sk_buff
*skb
;
6454 struct nlattr
*data
;
6456 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6460 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
6466 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6467 goto nla_put_failure
;
6470 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
6472 goto nla_put_failure
;
6473 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
6475 goto nla_put_failure
;
6478 data
= nla_nest_start(skb
, attr
);
6480 ((void **)skb
->cb
)[0] = rdev
;
6481 ((void **)skb
->cb
)[1] = hdr
;
6482 ((void **)skb
->cb
)[2] = data
;
6491 #ifdef CONFIG_NL80211_TESTMODE
6492 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6496 static struct genl_multicast_group nl80211_vendor_mcgrp
= {
6500 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6502 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6505 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6509 if (rdev
->ops
->testmode_cmd
) {
6510 rdev
->cur_cmd_info
= info
;
6511 err
= rdev_testmode_cmd(rdev
,
6512 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6513 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6514 rdev
->cur_cmd_info
= NULL
;
6520 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6521 struct netlink_callback
*cb
)
6523 struct cfg80211_registered_device
*rdev
;
6531 * 0 is a valid index, but not valid for args[0],
6532 * so we need to offset by 1.
6534 phy_idx
= cb
->args
[0] - 1;
6536 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6537 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6542 mutex_lock(&cfg80211_mutex
);
6543 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6544 nl80211_fam
.attrbuf
);
6546 mutex_unlock(&cfg80211_mutex
);
6547 return PTR_ERR(rdev
);
6549 phy_idx
= rdev
->wiphy_idx
;
6551 mutex_unlock(&cfg80211_mutex
);
6553 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6555 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6559 data
= nla_data((void *)cb
->args
[1]);
6560 data_len
= nla_len((void *)cb
->args
[1]);
6563 mutex_lock(&cfg80211_mutex
);
6564 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6566 mutex_unlock(&cfg80211_mutex
);
6569 cfg80211_lock_rdev(rdev
);
6570 mutex_unlock(&cfg80211_mutex
);
6572 if (!rdev
->ops
->testmode_dump
) {
6578 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6579 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6580 NL80211_CMD_TESTMODE
);
6581 struct nlattr
*tmdata
;
6586 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6587 genlmsg_cancel(skb
, hdr
);
6591 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6593 genlmsg_cancel(skb
, hdr
);
6596 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6597 nla_nest_end(skb
, tmdata
);
6599 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6600 genlmsg_cancel(skb
, hdr
);
6603 genlmsg_cancel(skb
, hdr
);
6607 genlmsg_end(skb
, hdr
);
6612 cb
->args
[0] = phy_idx
+ 1;
6614 cfg80211_unlock_rdev(rdev
);
6618 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
6619 enum nl80211_commands cmd
,
6620 enum nl80211_attrs attr
,
6621 int vendor_event_idx
,
6622 int approxlen
, gfp_t gfp
)
6624 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6625 const struct nl80211_vendor_cmd_info
*info
;
6628 case NL80211_CMD_TESTMODE
:
6629 if (WARN_ON(vendor_event_idx
!= -1))
6633 case NL80211_CMD_VENDOR
:
6634 if (WARN_ON(vendor_event_idx
< 0 ||
6635 vendor_event_idx
>= wiphy
->n_vendor_events
))
6637 info
= &wiphy
->vendor_events
[vendor_event_idx
];
6643 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
, 0, 0,
6644 cmd
, attr
, info
, gfp
);
6646 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
6648 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
6650 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6651 void *hdr
= ((void **)skb
->cb
)[1];
6652 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6654 /* clear CB data for netlink core to own from now on */
6655 memset(skb
->cb
, 0, sizeof(skb
->cb
));
6657 nla_nest_end(skb
, data
);
6658 genlmsg_end(skb
, hdr
);
6660 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
6661 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6662 nl80211_vendor_mcgrp
.id
, gfp
);
6664 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6665 nl80211_testmode_mcgrp
.id
, gfp
);
6667 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
6670 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6672 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6673 struct net_device
*dev
= info
->user_ptr
[1];
6674 struct cfg80211_connect_params connect
;
6675 struct wiphy
*wiphy
;
6676 struct cfg80211_cached_keys
*connkeys
= NULL
;
6679 memset(&connect
, 0, sizeof(connect
));
6681 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6684 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6685 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6688 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6690 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6691 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6692 NL80211_CMD_CONNECT
))
6695 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6697 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6699 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6700 NL80211_MAX_NR_CIPHER_SUITES
);
6704 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6705 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6708 wiphy
= &rdev
->wiphy
;
6710 connect
.bg_scan_period
= -1;
6711 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6712 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6713 connect
.bg_scan_period
=
6714 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6717 if (info
->attrs
[NL80211_ATTR_MAC
])
6718 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6719 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6720 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6722 if (info
->attrs
[NL80211_ATTR_IE
]) {
6723 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6724 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6727 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6728 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6729 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6730 connect
.mfp
!= NL80211_MFP_NO
)
6733 connect
.mfp
= NL80211_MFP_NO
;
6736 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6738 ieee80211_get_channel(wiphy
,
6739 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6740 if (!connect
.channel
||
6741 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6745 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6746 connkeys
= nl80211_parse_connkeys(rdev
,
6747 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6748 if (IS_ERR(connkeys
))
6749 return PTR_ERR(connkeys
);
6752 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6753 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6755 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6756 memcpy(&connect
.ht_capa_mask
,
6757 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6758 sizeof(connect
.ht_capa_mask
));
6760 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6761 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6765 memcpy(&connect
.ht_capa
,
6766 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6767 sizeof(connect
.ht_capa
));
6770 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6771 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6773 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6774 memcpy(&connect
.vht_capa_mask
,
6775 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6776 sizeof(connect
.vht_capa_mask
));
6778 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6779 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6783 memcpy(&connect
.vht_capa
,
6784 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6785 sizeof(connect
.vht_capa
));
6788 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
6794 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6796 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6797 struct net_device
*dev
= info
->user_ptr
[1];
6800 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6801 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6803 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6808 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6809 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6812 return cfg80211_disconnect(rdev
, dev
, reason
, true);
6815 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6817 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6822 if (!info
->attrs
[NL80211_ATTR_PID
])
6825 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6827 net
= get_net_ns_by_pid(pid
);
6829 return PTR_ERR(net
);
6833 /* check if anything to do */
6834 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6835 err
= cfg80211_switch_netns(rdev
, net
);
6841 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6843 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6844 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6845 struct cfg80211_pmksa
*pmksa
) = NULL
;
6846 struct net_device
*dev
= info
->user_ptr
[1];
6847 struct cfg80211_pmksa pmksa
;
6849 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6851 if (!info
->attrs
[NL80211_ATTR_MAC
])
6854 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6857 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6858 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6860 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6861 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6864 switch (info
->genlhdr
->cmd
) {
6865 case NL80211_CMD_SET_PMKSA
:
6866 rdev_ops
= rdev
->ops
->set_pmksa
;
6868 case NL80211_CMD_DEL_PMKSA
:
6869 rdev_ops
= rdev
->ops
->del_pmksa
;
6879 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6882 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6884 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6885 struct net_device
*dev
= info
->user_ptr
[1];
6887 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6888 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6891 if (!rdev
->ops
->flush_pmksa
)
6894 return rdev_flush_pmksa(rdev
, dev
);
6897 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6899 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6900 struct net_device
*dev
= info
->user_ptr
[1];
6901 u8 action_code
, dialog_token
;
6905 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6906 !rdev
->ops
->tdls_mgmt
)
6909 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6910 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6911 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6912 !info
->attrs
[NL80211_ATTR_IE
] ||
6913 !info
->attrs
[NL80211_ATTR_MAC
])
6916 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6917 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6918 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6919 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6921 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6922 dialog_token
, status_code
,
6923 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6924 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6927 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6929 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6930 struct net_device
*dev
= info
->user_ptr
[1];
6931 enum nl80211_tdls_operation operation
;
6934 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6935 !rdev
->ops
->tdls_oper
)
6938 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6939 !info
->attrs
[NL80211_ATTR_MAC
])
6942 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6943 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6945 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6948 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6949 struct genl_info
*info
)
6951 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6952 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6953 struct cfg80211_chan_def chandef
;
6954 struct sk_buff
*msg
;
6960 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6961 !info
->attrs
[NL80211_ATTR_DURATION
])
6964 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6966 if (!rdev
->ops
->remain_on_channel
||
6967 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6971 * We should be on that channel for at least a minimum amount of
6972 * time (10ms) but no longer than the driver supports.
6974 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6975 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6978 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6982 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6986 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6987 NL80211_CMD_REMAIN_ON_CHANNEL
);
6993 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6999 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7000 goto nla_put_failure
;
7002 genlmsg_end(msg
, hdr
);
7004 return genlmsg_reply(msg
, info
);
7013 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7014 struct genl_info
*info
)
7016 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7017 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7020 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7023 if (!rdev
->ops
->cancel_remain_on_channel
)
7026 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7028 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7031 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7032 u8
*rates
, u8 rates_len
)
7037 for (i
= 0; i
< rates_len
; i
++) {
7038 int rate
= (rates
[i
] & 0x7f) * 5;
7040 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7041 struct ieee80211_rate
*srate
=
7042 &sband
->bitrates
[ridx
];
7043 if (rate
== srate
->bitrate
) {
7048 if (ridx
== sband
->n_bitrates
)
7049 return 0; /* rate not found */
7055 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7056 u8
*rates
, u8 rates_len
,
7057 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7061 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7063 for (i
= 0; i
< rates_len
; i
++) {
7066 ridx
= rates
[i
] / 8;
7067 rbit
= BIT(rates
[i
] % 8);
7069 /* check validity */
7070 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7073 /* check availability */
7074 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7083 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7084 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7085 .len
= NL80211_MAX_SUPP_RATES
},
7086 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7087 .len
= NL80211_MAX_SUPP_HT_RATES
},
7090 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7091 struct genl_info
*info
)
7093 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7094 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7095 struct cfg80211_bitrate_mask mask
;
7097 struct net_device
*dev
= info
->user_ptr
[1];
7098 struct nlattr
*tx_rates
;
7099 struct ieee80211_supported_band
*sband
;
7101 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7104 if (!rdev
->ops
->set_bitrate_mask
)
7107 memset(&mask
, 0, sizeof(mask
));
7108 /* Default to all rates enabled */
7109 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7110 sband
= rdev
->wiphy
.bands
[i
];
7111 mask
.control
[i
].legacy
=
7112 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7114 memcpy(mask
.control
[i
].mcs
,
7115 sband
->ht_cap
.mcs
.rx_mask
,
7116 sizeof(mask
.control
[i
].mcs
));
7118 memset(mask
.control
[i
].mcs
, 0,
7119 sizeof(mask
.control
[i
].mcs
));
7123 * The nested attribute uses enum nl80211_band as the index. This maps
7124 * directly to the enum ieee80211_band values used in cfg80211.
7126 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7127 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7129 enum ieee80211_band band
= nla_type(tx_rates
);
7130 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7132 sband
= rdev
->wiphy
.bands
[band
];
7135 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7136 nla_len(tx_rates
), nl80211_txattr_policy
);
7137 if (tb
[NL80211_TXRATE_LEGACY
]) {
7138 mask
.control
[band
].legacy
= rateset_to_mask(
7140 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7141 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7142 if ((mask
.control
[band
].legacy
== 0) &&
7143 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7146 if (tb
[NL80211_TXRATE_MCS
]) {
7147 if (!ht_rateset_to_mask(
7149 nla_data(tb
[NL80211_TXRATE_MCS
]),
7150 nla_len(tb
[NL80211_TXRATE_MCS
]),
7151 mask
.control
[band
].mcs
))
7155 if (mask
.control
[band
].legacy
== 0) {
7156 /* don't allow empty legacy rates if HT
7157 * is not even supported. */
7158 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7161 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7162 if (mask
.control
[band
].mcs
[i
])
7165 /* legacy and mcs rates may not be both empty */
7166 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7171 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7174 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7176 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7177 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7178 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7180 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7183 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7184 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7186 switch (wdev
->iftype
) {
7187 case NL80211_IFTYPE_STATION
:
7188 case NL80211_IFTYPE_ADHOC
:
7189 case NL80211_IFTYPE_P2P_CLIENT
:
7190 case NL80211_IFTYPE_AP
:
7191 case NL80211_IFTYPE_AP_VLAN
:
7192 case NL80211_IFTYPE_MESH_POINT
:
7193 case NL80211_IFTYPE_P2P_GO
:
7194 case NL80211_IFTYPE_P2P_DEVICE
:
7200 /* not much point in registering if we can't reply */
7201 if (!rdev
->ops
->mgmt_tx
)
7204 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7205 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7206 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7209 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7211 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7212 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7213 struct cfg80211_chan_def chandef
;
7217 struct sk_buff
*msg
= NULL
;
7218 unsigned int wait
= 0;
7219 bool offchan
, no_cck
, dont_wait_for_ack
;
7221 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7223 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7226 if (!rdev
->ops
->mgmt_tx
)
7229 switch (wdev
->iftype
) {
7230 case NL80211_IFTYPE_STATION
:
7231 case NL80211_IFTYPE_ADHOC
:
7232 case NL80211_IFTYPE_P2P_CLIENT
:
7233 case NL80211_IFTYPE_AP
:
7234 case NL80211_IFTYPE_AP_VLAN
:
7235 case NL80211_IFTYPE_MESH_POINT
:
7236 case NL80211_IFTYPE_P2P_GO
:
7237 case NL80211_IFTYPE_P2P_DEVICE
:
7243 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7244 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7246 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7249 * We should wait on the channel for at least a minimum amount
7250 * of time (10ms) but no longer than the driver supports.
7252 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7253 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7258 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7260 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7263 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7265 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7269 if (!dont_wait_for_ack
) {
7270 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7274 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7282 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7283 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7284 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7285 no_cck
, dont_wait_for_ack
, &cookie
);
7290 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7291 goto nla_put_failure
;
7293 genlmsg_end(msg
, hdr
);
7294 return genlmsg_reply(msg
, info
);
7306 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7309 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7312 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7315 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7318 switch (wdev
->iftype
) {
7319 case NL80211_IFTYPE_STATION
:
7320 case NL80211_IFTYPE_ADHOC
:
7321 case NL80211_IFTYPE_P2P_CLIENT
:
7322 case NL80211_IFTYPE_AP
:
7323 case NL80211_IFTYPE_AP_VLAN
:
7324 case NL80211_IFTYPE_P2P_GO
:
7325 case NL80211_IFTYPE_P2P_DEVICE
:
7331 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7333 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7336 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7338 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7339 struct wireless_dev
*wdev
;
7340 struct net_device
*dev
= info
->user_ptr
[1];
7345 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7348 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7350 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7353 wdev
= dev
->ieee80211_ptr
;
7355 if (!rdev
->ops
->set_power_mgmt
)
7358 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7360 if (state
== wdev
->ps
)
7363 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7369 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7371 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7372 enum nl80211_ps_state ps_state
;
7373 struct wireless_dev
*wdev
;
7374 struct net_device
*dev
= info
->user_ptr
[1];
7375 struct sk_buff
*msg
;
7379 wdev
= dev
->ieee80211_ptr
;
7381 if (!rdev
->ops
->set_power_mgmt
)
7384 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7388 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7389 NL80211_CMD_GET_POWER_SAVE
);
7396 ps_state
= NL80211_PS_ENABLED
;
7398 ps_state
= NL80211_PS_DISABLED
;
7400 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7401 goto nla_put_failure
;
7403 genlmsg_end(msg
, hdr
);
7404 return genlmsg_reply(msg
, info
);
7413 static struct nla_policy
7414 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7415 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7416 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7417 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7418 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7419 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7420 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7423 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7424 u32 rate
, u32 pkts
, u32 intvl
)
7426 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7427 struct wireless_dev
*wdev
;
7428 struct net_device
*dev
= info
->user_ptr
[1];
7430 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7433 wdev
= dev
->ieee80211_ptr
;
7435 if (!rdev
->ops
->set_cqm_txe_config
)
7438 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7439 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7442 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7445 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7446 s32 threshold
, u32 hysteresis
)
7448 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7449 struct wireless_dev
*wdev
;
7450 struct net_device
*dev
= info
->user_ptr
[1];
7455 wdev
= dev
->ieee80211_ptr
;
7457 if (!rdev
->ops
->set_cqm_rssi_config
)
7460 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7461 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7464 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7467 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7469 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7473 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7479 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7480 nl80211_attr_cqm_policy
);
7484 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7485 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7488 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7489 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7490 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7491 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7492 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7493 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7494 u32 rate
, pkts
, intvl
;
7495 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7496 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7497 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7498 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7506 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7508 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7509 struct net_device
*dev
= info
->user_ptr
[1];
7510 struct mesh_config cfg
;
7511 struct mesh_setup setup
;
7514 /* start with default */
7515 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7516 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7518 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7519 /* and parse parameters if given */
7520 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7525 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7526 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7529 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7530 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7532 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7533 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7534 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7537 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7538 setup
.beacon_interval
=
7539 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7540 if (setup
.beacon_interval
< 10 ||
7541 setup
.beacon_interval
> 10000)
7545 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7547 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7548 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7552 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7553 /* parse additional setup parameters if given */
7554 err
= nl80211_parse_mesh_setup(info
, &setup
);
7560 cfg
.auto_open_plinks
= false;
7562 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7563 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7567 /* cfg80211_join_mesh() will sort it out */
7568 setup
.chandef
.chan
= NULL
;
7571 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7574 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7576 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7577 struct net_device
*dev
= info
->user_ptr
[1];
7579 return cfg80211_leave_mesh(rdev
, dev
);
7583 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7584 struct cfg80211_registered_device
*rdev
)
7586 struct nlattr
*nl_pats
, *nl_pat
;
7589 if (!rdev
->wowlan
->n_patterns
)
7592 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7596 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
7597 nl_pat
= nla_nest_start(msg
, i
+ 1);
7600 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
7601 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7602 DIV_ROUND_UP(pat_len
, 8),
7603 rdev
->wowlan
->patterns
[i
].mask
) ||
7604 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7605 pat_len
, rdev
->wowlan
->patterns
[i
].pattern
) ||
7606 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7607 rdev
->wowlan
->patterns
[i
].pkt_offset
))
7609 nla_nest_end(msg
, nl_pat
);
7611 nla_nest_end(msg
, nl_pats
);
7616 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7617 struct cfg80211_wowlan_tcp
*tcp
)
7619 struct nlattr
*nl_tcp
;
7624 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7628 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7629 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7630 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7631 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7632 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7633 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7634 tcp
->payload_len
, tcp
->payload
) ||
7635 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7636 tcp
->data_interval
) ||
7637 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7638 tcp
->wake_len
, tcp
->wake_data
) ||
7639 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7640 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7643 if (tcp
->payload_seq
.len
&&
7644 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7645 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7648 if (tcp
->payload_tok
.len
&&
7649 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7650 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7654 nla_nest_end(msg
, nl_tcp
);
7659 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7661 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7662 struct sk_buff
*msg
;
7664 u32 size
= NLMSG_DEFAULT_SIZE
;
7666 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7667 !rdev
->wiphy
.wowlan
.tcp
)
7670 if (rdev
->wowlan
&& rdev
->wowlan
->tcp
) {
7671 /* adjust size to have room for all the data */
7672 size
+= rdev
->wowlan
->tcp
->tokens_size
+
7673 rdev
->wowlan
->tcp
->payload_len
+
7674 rdev
->wowlan
->tcp
->wake_len
+
7675 rdev
->wowlan
->tcp
->wake_len
/ 8;
7678 msg
= nlmsg_new(size
, GFP_KERNEL
);
7682 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7683 NL80211_CMD_GET_WOWLAN
);
7685 goto nla_put_failure
;
7688 struct nlattr
*nl_wowlan
;
7690 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7692 goto nla_put_failure
;
7694 if ((rdev
->wowlan
->any
&&
7695 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7696 (rdev
->wowlan
->disconnect
&&
7697 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7698 (rdev
->wowlan
->magic_pkt
&&
7699 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7700 (rdev
->wowlan
->gtk_rekey_failure
&&
7701 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7702 (rdev
->wowlan
->eap_identity_req
&&
7703 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7704 (rdev
->wowlan
->four_way_handshake
&&
7705 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7706 (rdev
->wowlan
->rfkill_release
&&
7707 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7708 goto nla_put_failure
;
7710 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7711 goto nla_put_failure
;
7713 if (nl80211_send_wowlan_tcp(msg
, rdev
->wowlan
->tcp
))
7714 goto nla_put_failure
;
7716 nla_nest_end(msg
, nl_wowlan
);
7719 genlmsg_end(msg
, hdr
);
7720 return genlmsg_reply(msg
, info
);
7727 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7728 struct nlattr
*attr
,
7729 struct cfg80211_wowlan
*trig
)
7731 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7732 struct cfg80211_wowlan_tcp
*cfg
;
7733 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7734 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7736 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7739 if (!rdev
->wiphy
.wowlan
.tcp
)
7742 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7743 nla_data(attr
), nla_len(attr
),
7744 nl80211_wowlan_tcp_policy
);
7748 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7749 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7750 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7751 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7752 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7753 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7754 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7755 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7758 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7759 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7762 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7763 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
||
7764 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7767 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7768 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7771 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7772 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7775 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7776 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7778 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7779 tokens_size
= tokln
- sizeof(*tok
);
7781 if (!tok
->len
|| tokens_size
% tok
->len
)
7783 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7785 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7787 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7789 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7791 if (tok
->offset
+ tok
->len
> data_size
)
7795 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7796 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7797 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7799 if (seq
->len
== 0 || seq
->len
> 4)
7801 if (seq
->len
+ seq
->offset
> data_size
)
7805 size
= sizeof(*cfg
);
7807 size
+= wake_size
+ wake_mask_size
;
7808 size
+= tokens_size
;
7810 cfg
= kzalloc(size
, GFP_KERNEL
);
7813 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7814 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7815 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7817 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7818 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7822 /* allocate a socket and port for it and use it */
7823 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7824 IPPROTO_TCP
, &cfg
->sock
, 1);
7829 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7830 sock_release(cfg
->sock
);
7834 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7840 cfg
->src_port
= port
;
7843 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7844 cfg
->payload_len
= data_size
;
7845 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7846 memcpy((void *)cfg
->payload
,
7847 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7850 cfg
->payload_seq
= *seq
;
7851 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7852 cfg
->wake_len
= wake_size
;
7853 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7854 memcpy((void *)cfg
->wake_data
,
7855 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7857 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7858 data_size
+ wake_size
;
7859 memcpy((void *)cfg
->wake_mask
,
7860 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7863 cfg
->tokens_size
= tokens_size
;
7864 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7872 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7875 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7876 struct cfg80211_wowlan new_triggers
= {};
7877 struct cfg80211_wowlan
*ntrig
;
7878 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7880 bool prev_enabled
= rdev
->wowlan
;
7882 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7883 !rdev
->wiphy
.wowlan
.tcp
)
7886 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7887 cfg80211_rdev_free_wowlan(rdev
);
7888 rdev
->wowlan
= NULL
;
7892 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7893 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7894 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7895 nl80211_wowlan_policy
);
7899 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7900 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7902 new_triggers
.any
= true;
7905 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7906 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7908 new_triggers
.disconnect
= true;
7911 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7912 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7914 new_triggers
.magic_pkt
= true;
7917 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7920 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7921 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7923 new_triggers
.gtk_rekey_failure
= true;
7926 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7927 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7929 new_triggers
.eap_identity_req
= true;
7932 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7933 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7935 new_triggers
.four_way_handshake
= true;
7938 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7939 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7941 new_triggers
.rfkill_release
= true;
7944 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7947 int rem
, pat_len
, mask_len
, pkt_offset
;
7948 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7950 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7953 if (n_patterns
> wowlan
->n_patterns
)
7956 new_triggers
.patterns
= kcalloc(n_patterns
,
7957 sizeof(new_triggers
.patterns
[0]),
7959 if (!new_triggers
.patterns
)
7962 new_triggers
.n_patterns
= n_patterns
;
7965 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7967 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7968 nla_data(pat
), nla_len(pat
), NULL
);
7970 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7971 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7973 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7974 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7975 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7978 if (pat_len
> wowlan
->pattern_max_len
||
7979 pat_len
< wowlan
->pattern_min_len
)
7982 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7985 pkt_offset
= nla_get_u32(
7986 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7987 if (pkt_offset
> wowlan
->max_pkt_offset
)
7989 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7991 new_triggers
.patterns
[i
].mask
=
7992 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7993 if (!new_triggers
.patterns
[i
].mask
) {
7997 new_triggers
.patterns
[i
].pattern
=
7998 new_triggers
.patterns
[i
].mask
+ mask_len
;
7999 memcpy(new_triggers
.patterns
[i
].mask
,
8000 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
8002 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
8003 memcpy(new_triggers
.patterns
[i
].pattern
,
8004 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
8010 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8011 err
= nl80211_parse_wowlan_tcp(
8012 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8018 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8023 cfg80211_rdev_free_wowlan(rdev
);
8024 rdev
->wowlan
= ntrig
;
8027 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
8028 rdev_set_wakeup(rdev
, rdev
->wowlan
);
8032 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8033 kfree(new_triggers
.patterns
[i
].mask
);
8034 kfree(new_triggers
.patterns
);
8035 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8036 sock_release(new_triggers
.tcp
->sock
);
8037 kfree(new_triggers
.tcp
);
8042 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8044 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8045 struct net_device
*dev
= info
->user_ptr
[1];
8046 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8047 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8048 struct cfg80211_gtk_rekey_data rekey_data
;
8051 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8054 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8055 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8056 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8057 nl80211_rekey_policy
);
8061 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8063 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8065 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8068 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8070 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8072 memcpy(rekey_data
.replay_ctr
,
8073 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8074 NL80211_REPLAY_CTR_LEN
);
8077 if (!wdev
->current_bss
) {
8082 if (!rdev
->ops
->set_rekey_data
) {
8087 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8093 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8094 struct genl_info
*info
)
8096 struct net_device
*dev
= info
->user_ptr
[1];
8097 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8099 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8100 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8103 if (wdev
->ap_unexpected_nlportid
)
8106 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8110 static int nl80211_probe_client(struct sk_buff
*skb
,
8111 struct genl_info
*info
)
8113 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8114 struct net_device
*dev
= info
->user_ptr
[1];
8115 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8116 struct sk_buff
*msg
;
8122 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8123 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8126 if (!info
->attrs
[NL80211_ATTR_MAC
])
8129 if (!rdev
->ops
->probe_client
)
8132 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8136 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8137 NL80211_CMD_PROBE_CLIENT
);
8143 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8145 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8149 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8150 goto nla_put_failure
;
8152 genlmsg_end(msg
, hdr
);
8154 return genlmsg_reply(msg
, info
);
8163 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8165 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8166 struct cfg80211_beacon_registration
*reg
, *nreg
;
8169 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8172 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8176 /* First, check if already registered. */
8177 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8178 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8179 if (reg
->nlportid
== info
->snd_portid
) {
8184 /* Add it to the list */
8185 nreg
->nlportid
= info
->snd_portid
;
8186 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8188 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8192 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8197 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8199 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8200 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8203 if (!rdev
->ops
->start_p2p_device
)
8206 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8209 if (wdev
->p2p_started
)
8212 mutex_lock(&rdev
->devlist_mtx
);
8213 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8214 mutex_unlock(&rdev
->devlist_mtx
);
8218 err
= rdev_start_p2p_device(rdev
, wdev
);
8222 wdev
->p2p_started
= true;
8223 mutex_lock(&rdev
->devlist_mtx
);
8225 mutex_unlock(&rdev
->devlist_mtx
);
8230 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8232 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8233 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8235 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8238 if (!rdev
->ops
->stop_p2p_device
)
8241 mutex_lock(&rdev
->devlist_mtx
);
8242 mutex_lock(&rdev
->sched_scan_mtx
);
8243 cfg80211_stop_p2p_device(rdev
, wdev
);
8244 mutex_unlock(&rdev
->sched_scan_mtx
);
8245 mutex_unlock(&rdev
->devlist_mtx
);
8250 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8251 struct genl_info
*info
)
8254 struct sk_buff
*msg
;
8256 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8260 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8261 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8263 goto nla_put_failure
;
8265 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8266 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8267 goto nla_put_failure
;
8269 genlmsg_end(msg
, hdr
);
8270 return genlmsg_reply(msg
, info
);
8277 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8279 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8280 struct cfg80211_update_ft_ies_params ft_params
;
8281 struct net_device
*dev
= info
->user_ptr
[1];
8283 if (!rdev
->ops
->update_ft_ies
)
8286 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8287 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8290 memset(&ft_params
, 0, sizeof(ft_params
));
8291 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8292 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8293 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8295 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8298 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8299 struct genl_info
*info
)
8301 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8302 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8303 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8307 if (!rdev
->ops
->crit_proto_start
)
8310 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8313 if (rdev
->crit_proto_nlportid
)
8316 /* determine protocol if provided */
8317 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8318 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8320 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8323 /* timeout must be provided */
8324 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8328 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8330 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8333 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8335 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8340 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8341 struct genl_info
*info
)
8343 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8344 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8346 if (!rdev
->ops
->crit_proto_stop
)
8349 if (rdev
->crit_proto_nlportid
) {
8350 rdev
->crit_proto_nlportid
= 0;
8351 rdev_crit_proto_stop(rdev
, wdev
);
8356 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
8358 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8359 struct wireless_dev
*wdev
=
8360 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8364 if (!rdev
|| !rdev
->wiphy
.vendor_commands
)
8368 err
= PTR_ERR(wdev
);
8372 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8376 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
8377 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
8380 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
8381 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
8382 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
8383 const struct wiphy_vendor_command
*vcmd
;
8387 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
8389 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
8392 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
8393 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
8396 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
8400 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
8401 if (!wdev
->netdev
||
8402 !netif_running(wdev
->netdev
))
8409 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
8410 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8411 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8414 rdev
->cur_cmd_info
= info
;
8415 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
8417 rdev
->cur_cmd_info
= NULL
;
8424 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
8425 enum nl80211_commands cmd
,
8426 enum nl80211_attrs attr
,
8429 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8431 if (WARN_ON(!rdev
->cur_cmd_info
))
8434 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
,
8437 cmd
, attr
, NULL
, GFP_KERNEL
);
8439 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
8441 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
8443 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8444 void *hdr
= ((void **)skb
->cb
)[1];
8445 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8447 if (WARN_ON(!rdev
->cur_cmd_info
)) {
8452 nla_nest_end(skb
, data
);
8453 genlmsg_end(skb
, hdr
);
8454 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
8456 EXPORT_SYMBOL(cfg80211_vendor_cmd_reply
);
8458 #define NL80211_FLAG_NEED_WIPHY 0x01
8459 #define NL80211_FLAG_NEED_NETDEV 0x02
8460 #define NL80211_FLAG_NEED_RTNL 0x04
8461 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8462 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8463 NL80211_FLAG_CHECK_NETDEV_UP)
8464 #define NL80211_FLAG_NEED_WDEV 0x10
8465 /* If a netdev is associated, it must be UP, P2P must be started */
8466 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8467 NL80211_FLAG_CHECK_NETDEV_UP)
8469 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8470 struct genl_info
*info
)
8472 struct cfg80211_registered_device
*rdev
;
8473 struct wireless_dev
*wdev
;
8474 struct net_device
*dev
;
8475 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8480 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8481 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8485 return PTR_ERR(rdev
);
8487 info
->user_ptr
[0] = rdev
;
8488 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8489 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8490 mutex_lock(&cfg80211_mutex
);
8491 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8494 mutex_unlock(&cfg80211_mutex
);
8497 return PTR_ERR(wdev
);
8501 rdev
= wiphy_to_dev(wdev
->wiphy
);
8503 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8505 mutex_unlock(&cfg80211_mutex
);
8511 info
->user_ptr
[1] = dev
;
8513 info
->user_ptr
[1] = wdev
;
8517 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8518 !netif_running(dev
)) {
8519 mutex_unlock(&cfg80211_mutex
);
8526 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8527 if (!wdev
->p2p_started
) {
8528 mutex_unlock(&cfg80211_mutex
);
8535 cfg80211_lock_rdev(rdev
);
8537 mutex_unlock(&cfg80211_mutex
);
8539 info
->user_ptr
[0] = rdev
;
8545 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8546 struct genl_info
*info
)
8548 if (info
->user_ptr
[0])
8549 cfg80211_unlock_rdev(info
->user_ptr
[0]);
8550 if (info
->user_ptr
[1]) {
8551 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8552 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8555 dev_put(wdev
->netdev
);
8557 dev_put(info
->user_ptr
[1]);
8560 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8564 static struct genl_ops nl80211_ops
[] = {
8566 .cmd
= NL80211_CMD_GET_WIPHY
,
8567 .doit
= nl80211_get_wiphy
,
8568 .dumpit
= nl80211_dump_wiphy
,
8569 .policy
= nl80211_policy
,
8570 /* can be retrieved by unprivileged users */
8571 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
8574 .cmd
= NL80211_CMD_SET_WIPHY
,
8575 .doit
= nl80211_set_wiphy
,
8576 .policy
= nl80211_policy
,
8577 .flags
= GENL_ADMIN_PERM
,
8578 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8581 .cmd
= NL80211_CMD_GET_INTERFACE
,
8582 .doit
= nl80211_get_interface
,
8583 .dumpit
= nl80211_dump_interface
,
8584 .policy
= nl80211_policy
,
8585 /* can be retrieved by unprivileged users */
8586 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
8589 .cmd
= NL80211_CMD_SET_INTERFACE
,
8590 .doit
= nl80211_set_interface
,
8591 .policy
= nl80211_policy
,
8592 .flags
= GENL_ADMIN_PERM
,
8593 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8594 NL80211_FLAG_NEED_RTNL
,
8597 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8598 .doit
= nl80211_new_interface
,
8599 .policy
= nl80211_policy
,
8600 .flags
= GENL_ADMIN_PERM
,
8601 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8602 NL80211_FLAG_NEED_RTNL
,
8605 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8606 .doit
= nl80211_del_interface
,
8607 .policy
= nl80211_policy
,
8608 .flags
= GENL_ADMIN_PERM
,
8609 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8610 NL80211_FLAG_NEED_RTNL
,
8613 .cmd
= NL80211_CMD_GET_KEY
,
8614 .doit
= nl80211_get_key
,
8615 .policy
= nl80211_policy
,
8616 .flags
= GENL_ADMIN_PERM
,
8617 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8618 NL80211_FLAG_NEED_RTNL
,
8621 .cmd
= NL80211_CMD_SET_KEY
,
8622 .doit
= nl80211_set_key
,
8623 .policy
= nl80211_policy
,
8624 .flags
= GENL_ADMIN_PERM
,
8625 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8626 NL80211_FLAG_NEED_RTNL
,
8629 .cmd
= NL80211_CMD_NEW_KEY
,
8630 .doit
= nl80211_new_key
,
8631 .policy
= nl80211_policy
,
8632 .flags
= GENL_ADMIN_PERM
,
8633 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8634 NL80211_FLAG_NEED_RTNL
,
8637 .cmd
= NL80211_CMD_DEL_KEY
,
8638 .doit
= nl80211_del_key
,
8639 .policy
= nl80211_policy
,
8640 .flags
= GENL_ADMIN_PERM
,
8641 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8642 NL80211_FLAG_NEED_RTNL
,
8645 .cmd
= NL80211_CMD_SET_BEACON
,
8646 .policy
= nl80211_policy
,
8647 .flags
= GENL_ADMIN_PERM
,
8648 .doit
= nl80211_set_beacon
,
8649 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8650 NL80211_FLAG_NEED_RTNL
,
8653 .cmd
= NL80211_CMD_START_AP
,
8654 .policy
= nl80211_policy
,
8655 .flags
= GENL_ADMIN_PERM
,
8656 .doit
= nl80211_start_ap
,
8657 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8658 NL80211_FLAG_NEED_RTNL
,
8661 .cmd
= NL80211_CMD_STOP_AP
,
8662 .policy
= nl80211_policy
,
8663 .flags
= GENL_ADMIN_PERM
,
8664 .doit
= nl80211_stop_ap
,
8665 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8666 NL80211_FLAG_NEED_RTNL
,
8669 .cmd
= NL80211_CMD_GET_STATION
,
8670 .doit
= nl80211_get_station
,
8671 .dumpit
= nl80211_dump_station
,
8672 .policy
= nl80211_policy
,
8673 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8674 NL80211_FLAG_NEED_RTNL
,
8677 .cmd
= NL80211_CMD_SET_STATION
,
8678 .doit
= nl80211_set_station
,
8679 .policy
= nl80211_policy
,
8680 .flags
= GENL_ADMIN_PERM
,
8681 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8682 NL80211_FLAG_NEED_RTNL
,
8685 .cmd
= NL80211_CMD_NEW_STATION
,
8686 .doit
= nl80211_new_station
,
8687 .policy
= nl80211_policy
,
8688 .flags
= GENL_ADMIN_PERM
,
8689 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8690 NL80211_FLAG_NEED_RTNL
,
8693 .cmd
= NL80211_CMD_DEL_STATION
,
8694 .doit
= nl80211_del_station
,
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_GET_MPATH
,
8702 .doit
= nl80211_get_mpath
,
8703 .dumpit
= nl80211_dump_mpath
,
8704 .policy
= nl80211_policy
,
8705 .flags
= GENL_ADMIN_PERM
,
8706 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8707 NL80211_FLAG_NEED_RTNL
,
8710 .cmd
= NL80211_CMD_SET_MPATH
,
8711 .doit
= nl80211_set_mpath
,
8712 .policy
= nl80211_policy
,
8713 .flags
= GENL_ADMIN_PERM
,
8714 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8715 NL80211_FLAG_NEED_RTNL
,
8718 .cmd
= NL80211_CMD_NEW_MPATH
,
8719 .doit
= nl80211_new_mpath
,
8720 .policy
= nl80211_policy
,
8721 .flags
= GENL_ADMIN_PERM
,
8722 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8723 NL80211_FLAG_NEED_RTNL
,
8726 .cmd
= NL80211_CMD_DEL_MPATH
,
8727 .doit
= nl80211_del_mpath
,
8728 .policy
= nl80211_policy
,
8729 .flags
= GENL_ADMIN_PERM
,
8730 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8731 NL80211_FLAG_NEED_RTNL
,
8734 .cmd
= NL80211_CMD_SET_BSS
,
8735 .doit
= nl80211_set_bss
,
8736 .policy
= nl80211_policy
,
8737 .flags
= GENL_ADMIN_PERM
,
8738 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8739 NL80211_FLAG_NEED_RTNL
,
8742 .cmd
= NL80211_CMD_GET_REG
,
8743 .doit
= nl80211_get_reg
,
8744 .policy
= nl80211_policy
,
8745 /* can be retrieved by unprivileged users */
8748 .cmd
= NL80211_CMD_SET_REG
,
8749 .doit
= nl80211_set_reg
,
8750 .policy
= nl80211_policy
,
8751 .flags
= GENL_ADMIN_PERM
,
8754 .cmd
= NL80211_CMD_REQ_SET_REG
,
8755 .doit
= nl80211_req_set_reg
,
8756 .policy
= nl80211_policy
,
8757 .flags
= GENL_ADMIN_PERM
,
8760 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8761 .doit
= nl80211_get_mesh_config
,
8762 .policy
= nl80211_policy
,
8763 /* can be retrieved by unprivileged users */
8764 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8765 NL80211_FLAG_NEED_RTNL
,
8768 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8769 .doit
= nl80211_update_mesh_config
,
8770 .policy
= nl80211_policy
,
8771 .flags
= GENL_ADMIN_PERM
,
8772 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8773 NL80211_FLAG_NEED_RTNL
,
8776 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8777 .doit
= nl80211_trigger_scan
,
8778 .policy
= nl80211_policy
,
8779 .flags
= GENL_ADMIN_PERM
,
8780 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8781 NL80211_FLAG_NEED_RTNL
,
8784 .cmd
= NL80211_CMD_GET_SCAN
,
8785 .policy
= nl80211_policy
,
8786 .dumpit
= nl80211_dump_scan
,
8789 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8790 .doit
= nl80211_start_sched_scan
,
8791 .policy
= nl80211_policy
,
8792 .flags
= GENL_ADMIN_PERM
,
8793 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8794 NL80211_FLAG_NEED_RTNL
,
8797 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8798 .doit
= nl80211_stop_sched_scan
,
8799 .policy
= nl80211_policy
,
8800 .flags
= GENL_ADMIN_PERM
,
8801 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8802 NL80211_FLAG_NEED_RTNL
,
8805 .cmd
= NL80211_CMD_AUTHENTICATE
,
8806 .doit
= nl80211_authenticate
,
8807 .policy
= nl80211_policy
,
8808 .flags
= GENL_ADMIN_PERM
,
8809 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8810 NL80211_FLAG_NEED_RTNL
,
8813 .cmd
= NL80211_CMD_ASSOCIATE
,
8814 .doit
= nl80211_associate
,
8815 .policy
= nl80211_policy
,
8816 .flags
= GENL_ADMIN_PERM
,
8817 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8818 NL80211_FLAG_NEED_RTNL
,
8821 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8822 .doit
= nl80211_deauthenticate
,
8823 .policy
= nl80211_policy
,
8824 .flags
= GENL_ADMIN_PERM
,
8825 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8826 NL80211_FLAG_NEED_RTNL
,
8829 .cmd
= NL80211_CMD_DISASSOCIATE
,
8830 .doit
= nl80211_disassociate
,
8831 .policy
= nl80211_policy
,
8832 .flags
= GENL_ADMIN_PERM
,
8833 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8834 NL80211_FLAG_NEED_RTNL
,
8837 .cmd
= NL80211_CMD_JOIN_IBSS
,
8838 .doit
= nl80211_join_ibss
,
8839 .policy
= nl80211_policy
,
8840 .flags
= GENL_ADMIN_PERM
,
8841 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8842 NL80211_FLAG_NEED_RTNL
,
8845 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8846 .doit
= nl80211_leave_ibss
,
8847 .policy
= nl80211_policy
,
8848 .flags
= GENL_ADMIN_PERM
,
8849 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8850 NL80211_FLAG_NEED_RTNL
,
8852 #ifdef CONFIG_NL80211_TESTMODE
8854 .cmd
= NL80211_CMD_TESTMODE
,
8855 .doit
= nl80211_testmode_do
,
8856 .dumpit
= nl80211_testmode_dump
,
8857 .policy
= nl80211_policy
,
8858 .flags
= GENL_ADMIN_PERM
,
8859 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8860 NL80211_FLAG_NEED_RTNL
,
8864 .cmd
= NL80211_CMD_CONNECT
,
8865 .doit
= nl80211_connect
,
8866 .policy
= nl80211_policy
,
8867 .flags
= GENL_ADMIN_PERM
,
8868 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8869 NL80211_FLAG_NEED_RTNL
,
8872 .cmd
= NL80211_CMD_DISCONNECT
,
8873 .doit
= nl80211_disconnect
,
8874 .policy
= nl80211_policy
,
8875 .flags
= GENL_ADMIN_PERM
,
8876 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8877 NL80211_FLAG_NEED_RTNL
,
8880 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8881 .doit
= nl80211_wiphy_netns
,
8882 .policy
= nl80211_policy
,
8883 .flags
= GENL_ADMIN_PERM
,
8884 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8885 NL80211_FLAG_NEED_RTNL
,
8888 .cmd
= NL80211_CMD_GET_SURVEY
,
8889 .policy
= nl80211_policy
,
8890 .dumpit
= nl80211_dump_survey
,
8893 .cmd
= NL80211_CMD_SET_PMKSA
,
8894 .doit
= nl80211_setdel_pmksa
,
8895 .policy
= nl80211_policy
,
8896 .flags
= GENL_ADMIN_PERM
,
8897 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8898 NL80211_FLAG_NEED_RTNL
,
8901 .cmd
= NL80211_CMD_DEL_PMKSA
,
8902 .doit
= nl80211_setdel_pmksa
,
8903 .policy
= nl80211_policy
,
8904 .flags
= GENL_ADMIN_PERM
,
8905 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8906 NL80211_FLAG_NEED_RTNL
,
8909 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8910 .doit
= nl80211_flush_pmksa
,
8911 .policy
= nl80211_policy
,
8912 .flags
= GENL_ADMIN_PERM
,
8913 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8914 NL80211_FLAG_NEED_RTNL
,
8917 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8918 .doit
= nl80211_remain_on_channel
,
8919 .policy
= nl80211_policy
,
8920 .flags
= GENL_ADMIN_PERM
,
8921 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8922 NL80211_FLAG_NEED_RTNL
,
8925 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8926 .doit
= nl80211_cancel_remain_on_channel
,
8927 .policy
= nl80211_policy
,
8928 .flags
= GENL_ADMIN_PERM
,
8929 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8930 NL80211_FLAG_NEED_RTNL
,
8933 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8934 .doit
= nl80211_set_tx_bitrate_mask
,
8935 .policy
= nl80211_policy
,
8936 .flags
= GENL_ADMIN_PERM
,
8937 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8938 NL80211_FLAG_NEED_RTNL
,
8941 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8942 .doit
= nl80211_register_mgmt
,
8943 .policy
= nl80211_policy
,
8944 .flags
= GENL_ADMIN_PERM
,
8945 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8946 NL80211_FLAG_NEED_RTNL
,
8949 .cmd
= NL80211_CMD_FRAME
,
8950 .doit
= nl80211_tx_mgmt
,
8951 .policy
= nl80211_policy
,
8952 .flags
= GENL_ADMIN_PERM
,
8953 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8954 NL80211_FLAG_NEED_RTNL
,
8957 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8958 .doit
= nl80211_tx_mgmt_cancel_wait
,
8959 .policy
= nl80211_policy
,
8960 .flags
= GENL_ADMIN_PERM
,
8961 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8962 NL80211_FLAG_NEED_RTNL
,
8965 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8966 .doit
= nl80211_set_power_save
,
8967 .policy
= nl80211_policy
,
8968 .flags
= GENL_ADMIN_PERM
,
8969 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8970 NL80211_FLAG_NEED_RTNL
,
8973 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8974 .doit
= nl80211_get_power_save
,
8975 .policy
= nl80211_policy
,
8976 /* can be retrieved by unprivileged users */
8977 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8978 NL80211_FLAG_NEED_RTNL
,
8981 .cmd
= NL80211_CMD_SET_CQM
,
8982 .doit
= nl80211_set_cqm
,
8983 .policy
= nl80211_policy
,
8984 .flags
= GENL_ADMIN_PERM
,
8985 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8986 NL80211_FLAG_NEED_RTNL
,
8989 .cmd
= NL80211_CMD_SET_CHANNEL
,
8990 .doit
= nl80211_set_channel
,
8991 .policy
= nl80211_policy
,
8992 .flags
= GENL_ADMIN_PERM
,
8993 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8994 NL80211_FLAG_NEED_RTNL
,
8997 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8998 .doit
= nl80211_set_wds_peer
,
8999 .policy
= nl80211_policy
,
9000 .flags
= GENL_ADMIN_PERM
,
9001 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9002 NL80211_FLAG_NEED_RTNL
,
9005 .cmd
= NL80211_CMD_JOIN_MESH
,
9006 .doit
= nl80211_join_mesh
,
9007 .policy
= nl80211_policy
,
9008 .flags
= GENL_ADMIN_PERM
,
9009 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9010 NL80211_FLAG_NEED_RTNL
,
9013 .cmd
= NL80211_CMD_LEAVE_MESH
,
9014 .doit
= nl80211_leave_mesh
,
9015 .policy
= nl80211_policy
,
9016 .flags
= GENL_ADMIN_PERM
,
9017 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9018 NL80211_FLAG_NEED_RTNL
,
9022 .cmd
= NL80211_CMD_GET_WOWLAN
,
9023 .doit
= nl80211_get_wowlan
,
9024 .policy
= nl80211_policy
,
9025 /* can be retrieved by unprivileged users */
9026 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9027 NL80211_FLAG_NEED_RTNL
,
9030 .cmd
= NL80211_CMD_SET_WOWLAN
,
9031 .doit
= nl80211_set_wowlan
,
9032 .policy
= nl80211_policy
,
9033 .flags
= GENL_ADMIN_PERM
,
9034 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9035 NL80211_FLAG_NEED_RTNL
,
9039 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9040 .doit
= nl80211_set_rekey_data
,
9041 .policy
= nl80211_policy
,
9042 .flags
= GENL_ADMIN_PERM
,
9043 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9044 NL80211_FLAG_NEED_RTNL
,
9047 .cmd
= NL80211_CMD_TDLS_MGMT
,
9048 .doit
= nl80211_tdls_mgmt
,
9049 .policy
= nl80211_policy
,
9050 .flags
= GENL_ADMIN_PERM
,
9051 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9052 NL80211_FLAG_NEED_RTNL
,
9055 .cmd
= NL80211_CMD_TDLS_OPER
,
9056 .doit
= nl80211_tdls_oper
,
9057 .policy
= nl80211_policy
,
9058 .flags
= GENL_ADMIN_PERM
,
9059 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9060 NL80211_FLAG_NEED_RTNL
,
9063 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9064 .doit
= nl80211_register_unexpected_frame
,
9065 .policy
= nl80211_policy
,
9066 .flags
= GENL_ADMIN_PERM
,
9067 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9068 NL80211_FLAG_NEED_RTNL
,
9071 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9072 .doit
= nl80211_probe_client
,
9073 .policy
= nl80211_policy
,
9074 .flags
= GENL_ADMIN_PERM
,
9075 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9076 NL80211_FLAG_NEED_RTNL
,
9079 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9080 .doit
= nl80211_register_beacons
,
9081 .policy
= nl80211_policy
,
9082 .flags
= GENL_ADMIN_PERM
,
9083 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9084 NL80211_FLAG_NEED_RTNL
,
9087 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
9088 .doit
= nl80211_set_noack_map
,
9089 .policy
= nl80211_policy
,
9090 .flags
= GENL_ADMIN_PERM
,
9091 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9092 NL80211_FLAG_NEED_RTNL
,
9095 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
9096 .doit
= nl80211_start_p2p_device
,
9097 .policy
= nl80211_policy
,
9098 .flags
= GENL_ADMIN_PERM
,
9099 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9100 NL80211_FLAG_NEED_RTNL
,
9103 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
9104 .doit
= nl80211_stop_p2p_device
,
9105 .policy
= nl80211_policy
,
9106 .flags
= GENL_ADMIN_PERM
,
9107 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9108 NL80211_FLAG_NEED_RTNL
,
9111 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
9112 .doit
= nl80211_set_mcast_rate
,
9113 .policy
= nl80211_policy
,
9114 .flags
= GENL_ADMIN_PERM
,
9115 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9116 NL80211_FLAG_NEED_RTNL
,
9119 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9120 .doit
= nl80211_set_mac_acl
,
9121 .policy
= nl80211_policy
,
9122 .flags
= GENL_ADMIN_PERM
,
9123 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9124 NL80211_FLAG_NEED_RTNL
,
9127 .cmd
= NL80211_CMD_RADAR_DETECT
,
9128 .doit
= nl80211_start_radar_detection
,
9129 .policy
= nl80211_policy
,
9130 .flags
= GENL_ADMIN_PERM
,
9131 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9132 NL80211_FLAG_NEED_RTNL
,
9135 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9136 .doit
= nl80211_get_protocol_features
,
9137 .policy
= nl80211_policy
,
9140 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9141 .doit
= nl80211_update_ft_ies
,
9142 .policy
= nl80211_policy
,
9143 .flags
= GENL_ADMIN_PERM
,
9144 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9145 NL80211_FLAG_NEED_RTNL
,
9148 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9149 .doit
= nl80211_crit_protocol_start
,
9150 .policy
= nl80211_policy
,
9151 .flags
= GENL_ADMIN_PERM
,
9152 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9153 NL80211_FLAG_NEED_RTNL
,
9156 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9157 .doit
= nl80211_crit_protocol_stop
,
9158 .policy
= nl80211_policy
,
9159 .flags
= GENL_ADMIN_PERM
,
9160 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9161 NL80211_FLAG_NEED_RTNL
,
9164 .cmd
= NL80211_CMD_VENDOR
,
9165 .doit
= nl80211_vendor_cmd
,
9166 .policy
= nl80211_policy
,
9167 .flags
= GENL_ADMIN_PERM
,
9168 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9169 NL80211_FLAG_NEED_RTNL
,
9173 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9177 /* multicast groups */
9178 static struct genl_multicast_group nl80211_config_mcgrp
= {
9181 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9184 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9185 .name
= "regulatory",
9188 /* notification functions */
9190 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9192 struct sk_buff
*msg
;
9194 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9198 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0,
9199 false, NULL
, NULL
, NULL
) < 0) {
9204 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9205 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9208 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9209 struct cfg80211_registered_device
*rdev
)
9211 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9212 struct nlattr
*nest
;
9215 lockdep_assert_held(&rdev
->sched_scan_mtx
);
9220 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9222 goto nla_put_failure
;
9223 for (i
= 0; i
< req
->n_ssids
; i
++) {
9224 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9225 goto nla_put_failure
;
9227 nla_nest_end(msg
, nest
);
9229 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9231 goto nla_put_failure
;
9232 for (i
= 0; i
< req
->n_channels
; i
++) {
9233 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9234 goto nla_put_failure
;
9236 nla_nest_end(msg
, nest
);
9239 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9240 goto nla_put_failure
;
9243 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9250 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9251 struct cfg80211_registered_device
*rdev
,
9252 struct wireless_dev
*wdev
,
9253 u32 portid
, u32 seq
, int flags
,
9258 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9262 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9263 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9264 wdev
->netdev
->ifindex
)) ||
9265 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9266 goto nla_put_failure
;
9268 /* ignore errors and send incomplete event anyway */
9269 nl80211_add_scan_req(msg
, rdev
);
9271 return genlmsg_end(msg
, hdr
);
9274 genlmsg_cancel(msg
, hdr
);
9279 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9280 struct cfg80211_registered_device
*rdev
,
9281 struct net_device
*netdev
,
9282 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9286 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9290 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9291 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9292 goto nla_put_failure
;
9294 return genlmsg_end(msg
, hdr
);
9297 genlmsg_cancel(msg
, hdr
);
9301 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9302 struct wireless_dev
*wdev
)
9304 struct sk_buff
*msg
;
9306 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9310 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9311 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9316 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9317 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9320 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9321 struct wireless_dev
*wdev
)
9323 struct sk_buff
*msg
;
9325 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9329 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9330 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9335 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9336 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9339 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9340 struct wireless_dev
*wdev
)
9342 struct sk_buff
*msg
;
9344 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9348 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9349 NL80211_CMD_SCAN_ABORTED
) < 0) {
9354 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9355 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9358 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9359 struct net_device
*netdev
)
9361 struct sk_buff
*msg
;
9363 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9367 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9368 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9373 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9374 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9377 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9378 struct net_device
*netdev
, u32 cmd
)
9380 struct sk_buff
*msg
;
9382 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9386 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9391 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9392 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9396 * This can happen on global regulatory changes or device specific settings
9397 * based on custom world regulatory domains.
9399 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9401 struct sk_buff
*msg
;
9404 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9408 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9414 /* Userspace can always count this one always being set */
9415 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9416 goto nla_put_failure
;
9418 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9419 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9420 NL80211_REGDOM_TYPE_WORLD
))
9421 goto nla_put_failure
;
9422 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9423 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9424 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9425 goto nla_put_failure
;
9426 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9427 request
->intersect
) {
9428 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9429 NL80211_REGDOM_TYPE_INTERSECTION
))
9430 goto nla_put_failure
;
9432 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9433 NL80211_REGDOM_TYPE_COUNTRY
) ||
9434 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9436 goto nla_put_failure
;
9439 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9440 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9441 goto nla_put_failure
;
9443 genlmsg_end(msg
, hdr
);
9446 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9453 genlmsg_cancel(msg
, hdr
);
9457 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9458 struct net_device
*netdev
,
9459 const u8
*buf
, size_t len
,
9460 enum nl80211_commands cmd
, gfp_t gfp
)
9462 struct sk_buff
*msg
;
9465 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9469 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9475 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9476 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9477 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9478 goto nla_put_failure
;
9480 genlmsg_end(msg
, hdr
);
9482 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9483 nl80211_mlme_mcgrp
.id
, gfp
);
9487 genlmsg_cancel(msg
, hdr
);
9491 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9492 struct net_device
*netdev
, const u8
*buf
,
9493 size_t len
, gfp_t gfp
)
9495 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9496 NL80211_CMD_AUTHENTICATE
, gfp
);
9499 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9500 struct net_device
*netdev
, const u8
*buf
,
9501 size_t len
, gfp_t gfp
)
9503 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9504 NL80211_CMD_ASSOCIATE
, gfp
);
9507 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9508 struct net_device
*netdev
, const u8
*buf
,
9509 size_t len
, gfp_t gfp
)
9511 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9512 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9515 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9516 struct net_device
*netdev
, const u8
*buf
,
9517 size_t len
, gfp_t gfp
)
9519 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9520 NL80211_CMD_DISASSOCIATE
, gfp
);
9523 void cfg80211_send_unprot_deauth(struct net_device
*dev
, const u8
*buf
,
9526 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9527 struct wiphy
*wiphy
= wdev
->wiphy
;
9528 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9530 trace_cfg80211_send_unprot_deauth(dev
);
9531 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9532 NL80211_CMD_UNPROT_DEAUTHENTICATE
, GFP_ATOMIC
);
9534 EXPORT_SYMBOL(cfg80211_send_unprot_deauth
);
9536 void cfg80211_send_unprot_disassoc(struct net_device
*dev
, const u8
*buf
,
9539 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9540 struct wiphy
*wiphy
= wdev
->wiphy
;
9541 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9543 trace_cfg80211_send_unprot_disassoc(dev
);
9544 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9545 NL80211_CMD_UNPROT_DISASSOCIATE
, GFP_ATOMIC
);
9547 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc
);
9549 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9550 struct net_device
*netdev
, int cmd
,
9551 const u8
*addr
, gfp_t gfp
)
9553 struct sk_buff
*msg
;
9556 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9560 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9566 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9567 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9568 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9569 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9570 goto nla_put_failure
;
9572 genlmsg_end(msg
, hdr
);
9574 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9575 nl80211_mlme_mcgrp
.id
, gfp
);
9579 genlmsg_cancel(msg
, hdr
);
9583 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9584 struct net_device
*netdev
, const u8
*addr
,
9587 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9591 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9592 struct net_device
*netdev
, const u8
*addr
,
9595 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9599 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9600 struct net_device
*netdev
, const u8
*bssid
,
9601 const u8
*req_ie
, size_t req_ie_len
,
9602 const u8
*resp_ie
, size_t resp_ie_len
,
9603 u16 status
, gfp_t gfp
)
9605 struct sk_buff
*msg
;
9608 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9612 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9618 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9619 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9620 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9621 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9623 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9625 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9626 goto nla_put_failure
;
9628 genlmsg_end(msg
, hdr
);
9630 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9631 nl80211_mlme_mcgrp
.id
, gfp
);
9635 genlmsg_cancel(msg
, hdr
);
9640 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9641 struct net_device
*netdev
, const u8
*bssid
,
9642 const u8
*req_ie
, size_t req_ie_len
,
9643 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9645 struct sk_buff
*msg
;
9648 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9652 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9658 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9659 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9660 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9662 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9664 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9665 goto nla_put_failure
;
9667 genlmsg_end(msg
, hdr
);
9669 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9670 nl80211_mlme_mcgrp
.id
, gfp
);
9674 genlmsg_cancel(msg
, hdr
);
9679 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9680 struct net_device
*netdev
, u16 reason
,
9681 const u8
*ie
, size_t ie_len
, bool from_ap
)
9683 struct sk_buff
*msg
;
9686 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9690 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9696 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9697 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9698 (from_ap
&& reason
&&
9699 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9701 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9702 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9703 goto nla_put_failure
;
9705 genlmsg_end(msg
, hdr
);
9707 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9708 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9712 genlmsg_cancel(msg
, hdr
);
9717 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9718 struct net_device
*netdev
, const u8
*bssid
,
9721 struct sk_buff
*msg
;
9724 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9728 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9734 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9735 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9736 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9737 goto nla_put_failure
;
9739 genlmsg_end(msg
, hdr
);
9741 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9742 nl80211_mlme_mcgrp
.id
, gfp
);
9746 genlmsg_cancel(msg
, hdr
);
9750 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9751 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9753 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9754 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9755 struct sk_buff
*msg
;
9758 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9761 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9763 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9767 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9773 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9774 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9775 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9777 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9778 goto nla_put_failure
;
9780 genlmsg_end(msg
, hdr
);
9782 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9783 nl80211_mlme_mcgrp
.id
, gfp
);
9787 genlmsg_cancel(msg
, hdr
);
9790 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9792 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9793 struct net_device
*netdev
, const u8
*addr
,
9794 enum nl80211_key_type key_type
, int key_id
,
9795 const u8
*tsc
, gfp_t gfp
)
9797 struct sk_buff
*msg
;
9800 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9804 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9810 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9811 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9812 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9813 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9815 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9816 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9817 goto nla_put_failure
;
9819 genlmsg_end(msg
, hdr
);
9821 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9822 nl80211_mlme_mcgrp
.id
, gfp
);
9826 genlmsg_cancel(msg
, hdr
);
9830 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9831 struct ieee80211_channel
*channel_before
,
9832 struct ieee80211_channel
*channel_after
)
9834 struct sk_buff
*msg
;
9836 struct nlattr
*nl_freq
;
9838 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9842 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9849 * Since we are applying the beacon hint to a wiphy we know its
9850 * wiphy_idx is valid
9852 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9853 goto nla_put_failure
;
9856 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9858 goto nla_put_failure
;
9859 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9860 goto nla_put_failure
;
9861 nla_nest_end(msg
, nl_freq
);
9864 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9866 goto nla_put_failure
;
9867 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9868 goto nla_put_failure
;
9869 nla_nest_end(msg
, nl_freq
);
9871 genlmsg_end(msg
, hdr
);
9874 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9881 genlmsg_cancel(msg
, hdr
);
9885 static void nl80211_send_remain_on_chan_event(
9886 int cmd
, struct cfg80211_registered_device
*rdev
,
9887 struct wireless_dev
*wdev
, u64 cookie
,
9888 struct ieee80211_channel
*chan
,
9889 unsigned int duration
, gfp_t gfp
)
9891 struct sk_buff
*msg
;
9894 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9898 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9904 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9905 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9906 wdev
->netdev
->ifindex
)) ||
9907 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9908 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9909 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9910 NL80211_CHAN_NO_HT
) ||
9911 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9912 goto nla_put_failure
;
9914 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9915 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9916 goto nla_put_failure
;
9918 genlmsg_end(msg
, hdr
);
9920 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9921 nl80211_mlme_mcgrp
.id
, gfp
);
9925 genlmsg_cancel(msg
, hdr
);
9929 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9930 struct ieee80211_channel
*chan
,
9931 unsigned int duration
, gfp_t gfp
)
9933 struct wiphy
*wiphy
= wdev
->wiphy
;
9934 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9936 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9937 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9938 rdev
, wdev
, cookie
, chan
,
9941 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9943 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9944 struct ieee80211_channel
*chan
,
9947 struct wiphy
*wiphy
= wdev
->wiphy
;
9948 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9950 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9951 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9952 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9954 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9956 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9957 struct station_info
*sinfo
, gfp_t gfp
)
9959 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9960 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9961 struct sk_buff
*msg
;
9963 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9965 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9969 if (nl80211_send_station(msg
, 0, 0, 0,
9970 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9975 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9976 nl80211_mlme_mcgrp
.id
, gfp
);
9978 EXPORT_SYMBOL(cfg80211_new_sta
);
9980 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9982 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9983 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9984 struct sk_buff
*msg
;
9987 trace_cfg80211_del_sta(dev
, mac_addr
);
9989 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9993 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9999 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10000 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
10001 goto nla_put_failure
;
10003 genlmsg_end(msg
, hdr
);
10005 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10006 nl80211_mlme_mcgrp
.id
, gfp
);
10010 genlmsg_cancel(msg
, hdr
);
10013 EXPORT_SYMBOL(cfg80211_del_sta
);
10015 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10016 enum nl80211_connect_failed_reason reason
,
10019 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10020 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10021 struct sk_buff
*msg
;
10024 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10028 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10034 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10035 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10036 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10037 goto nla_put_failure
;
10039 genlmsg_end(msg
, hdr
);
10041 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10042 nl80211_mlme_mcgrp
.id
, gfp
);
10046 genlmsg_cancel(msg
, hdr
);
10049 EXPORT_SYMBOL(cfg80211_conn_failed
);
10051 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10052 const u8
*addr
, gfp_t gfp
)
10054 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10055 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10056 struct sk_buff
*msg
;
10059 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10064 msg
= nlmsg_new(100, gfp
);
10068 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10074 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10075 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10076 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10077 goto nla_put_failure
;
10079 err
= genlmsg_end(msg
, hdr
);
10085 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10089 genlmsg_cancel(msg
, hdr
);
10094 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
10095 const u8
*addr
, gfp_t gfp
)
10097 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10100 trace_cfg80211_rx_spurious_frame(dev
, addr
);
10102 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10103 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
10104 trace_cfg80211_return_bool(false);
10107 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
10109 trace_cfg80211_return_bool(ret
);
10112 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
10114 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
10115 const u8
*addr
, gfp_t gfp
)
10117 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10120 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
10122 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10123 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10124 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
10125 trace_cfg80211_return_bool(false);
10128 ret
= __nl80211_unexpected_frame(dev
,
10129 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
10131 trace_cfg80211_return_bool(ret
);
10134 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10136 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10137 struct wireless_dev
*wdev
, u32 nlportid
,
10138 int freq
, int sig_dbm
,
10139 const u8
*buf
, size_t len
, gfp_t gfp
)
10141 struct net_device
*netdev
= wdev
->netdev
;
10142 struct sk_buff
*msg
;
10145 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10149 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10155 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10156 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10157 netdev
->ifindex
)) ||
10158 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10159 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10161 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10162 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10163 goto nla_put_failure
;
10165 genlmsg_end(msg
, hdr
);
10167 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10170 genlmsg_cancel(msg
, hdr
);
10175 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10176 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10178 struct wiphy
*wiphy
= wdev
->wiphy
;
10179 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10180 struct net_device
*netdev
= wdev
->netdev
;
10181 struct sk_buff
*msg
;
10184 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10186 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10190 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10196 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10197 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10198 netdev
->ifindex
)) ||
10199 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10200 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10201 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10202 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10203 goto nla_put_failure
;
10205 genlmsg_end(msg
, hdr
);
10207 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10208 nl80211_mlme_mcgrp
.id
, gfp
);
10212 genlmsg_cancel(msg
, hdr
);
10215 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10217 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10218 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10221 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10222 struct wiphy
*wiphy
= wdev
->wiphy
;
10223 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10224 struct sk_buff
*msg
;
10225 struct nlattr
*pinfoattr
;
10228 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10230 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10234 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10240 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10241 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10242 goto nla_put_failure
;
10244 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10246 goto nla_put_failure
;
10248 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10250 goto nla_put_failure
;
10252 nla_nest_end(msg
, pinfoattr
);
10254 genlmsg_end(msg
, hdr
);
10256 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10257 nl80211_mlme_mcgrp
.id
, gfp
);
10261 genlmsg_cancel(msg
, hdr
);
10264 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10266 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10267 struct net_device
*netdev
, const u8
*bssid
,
10268 const u8
*replay_ctr
, gfp_t gfp
)
10270 struct sk_buff
*msg
;
10271 struct nlattr
*rekey_attr
;
10274 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10278 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10284 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10285 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10286 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10287 goto nla_put_failure
;
10289 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10291 goto nla_put_failure
;
10293 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10294 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10295 goto nla_put_failure
;
10297 nla_nest_end(msg
, rekey_attr
);
10299 genlmsg_end(msg
, hdr
);
10301 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10302 nl80211_mlme_mcgrp
.id
, gfp
);
10306 genlmsg_cancel(msg
, hdr
);
10310 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10311 const u8
*replay_ctr
, gfp_t gfp
)
10313 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10314 struct wiphy
*wiphy
= wdev
->wiphy
;
10315 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10317 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10318 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10320 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10323 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10324 struct net_device
*netdev
, int index
,
10325 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10327 struct sk_buff
*msg
;
10328 struct nlattr
*attr
;
10331 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10335 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10341 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10342 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10343 goto nla_put_failure
;
10345 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10347 goto nla_put_failure
;
10349 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10350 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10352 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10353 goto nla_put_failure
;
10355 nla_nest_end(msg
, attr
);
10357 genlmsg_end(msg
, hdr
);
10359 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10360 nl80211_mlme_mcgrp
.id
, gfp
);
10364 genlmsg_cancel(msg
, hdr
);
10368 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10369 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10371 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10372 struct wiphy
*wiphy
= wdev
->wiphy
;
10373 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10375 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10376 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10378 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10380 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10381 struct net_device
*netdev
,
10382 struct cfg80211_chan_def
*chandef
,
10385 struct sk_buff
*msg
;
10388 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10392 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10398 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10399 goto nla_put_failure
;
10401 if (nl80211_send_chandef(msg
, chandef
))
10402 goto nla_put_failure
;
10404 genlmsg_end(msg
, hdr
);
10406 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10407 nl80211_mlme_mcgrp
.id
, gfp
);
10411 genlmsg_cancel(msg
, hdr
);
10415 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10416 struct cfg80211_chan_def
*chandef
)
10418 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10419 struct wiphy
*wiphy
= wdev
->wiphy
;
10420 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10422 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10426 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10427 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10430 wdev
->channel
= chandef
->chan
;
10431 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10436 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10438 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10439 const u8
*peer
, u32 num_packets
,
10440 u32 rate
, u32 intvl
, gfp_t gfp
)
10442 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10443 struct wiphy
*wiphy
= wdev
->wiphy
;
10444 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10445 struct sk_buff
*msg
;
10446 struct nlattr
*pinfoattr
;
10449 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10453 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10459 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10460 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10461 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10462 goto nla_put_failure
;
10464 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10466 goto nla_put_failure
;
10468 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10469 goto nla_put_failure
;
10471 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10472 goto nla_put_failure
;
10474 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10475 goto nla_put_failure
;
10477 nla_nest_end(msg
, pinfoattr
);
10479 genlmsg_end(msg
, hdr
);
10481 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10482 nl80211_mlme_mcgrp
.id
, gfp
);
10486 genlmsg_cancel(msg
, hdr
);
10489 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10492 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10493 struct cfg80211_chan_def
*chandef
,
10494 enum nl80211_radar_event event
,
10495 struct net_device
*netdev
, gfp_t gfp
)
10497 struct sk_buff
*msg
;
10500 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10504 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10510 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10511 goto nla_put_failure
;
10513 /* NOP and radar events don't need a netdev parameter */
10515 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10517 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10518 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10519 goto nla_put_failure
;
10522 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10523 goto nla_put_failure
;
10525 if (nl80211_send_chandef(msg
, chandef
))
10526 goto nla_put_failure
;
10528 if (genlmsg_end(msg
, hdr
) < 0) {
10533 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10534 nl80211_mlme_mcgrp
.id
, gfp
);
10538 genlmsg_cancel(msg
, hdr
);
10542 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10543 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10545 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10546 struct wiphy
*wiphy
= wdev
->wiphy
;
10547 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10548 struct sk_buff
*msg
;
10549 struct nlattr
*pinfoattr
;
10552 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10554 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10558 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10564 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10565 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10566 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10567 goto nla_put_failure
;
10569 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10571 goto nla_put_failure
;
10573 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10574 goto nla_put_failure
;
10576 nla_nest_end(msg
, pinfoattr
);
10578 genlmsg_end(msg
, hdr
);
10580 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10581 nl80211_mlme_mcgrp
.id
, gfp
);
10585 genlmsg_cancel(msg
, hdr
);
10588 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10590 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10591 u64 cookie
, bool acked
, gfp_t gfp
)
10593 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10594 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10595 struct sk_buff
*msg
;
10599 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10601 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10606 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10612 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10613 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10614 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10615 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10616 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10617 goto nla_put_failure
;
10619 err
= genlmsg_end(msg
, hdr
);
10625 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10626 nl80211_mlme_mcgrp
.id
, gfp
);
10630 genlmsg_cancel(msg
, hdr
);
10633 EXPORT_SYMBOL(cfg80211_probe_status
);
10635 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10636 const u8
*frame
, size_t len
,
10637 int freq
, int sig_dbm
)
10639 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10640 struct sk_buff
*msg
;
10642 struct cfg80211_beacon_registration
*reg
;
10644 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10646 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10647 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10648 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10650 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10654 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10656 goto nla_put_failure
;
10658 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10660 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10662 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10663 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10664 goto nla_put_failure
;
10666 genlmsg_end(msg
, hdr
);
10668 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10670 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10674 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10676 genlmsg_cancel(msg
, hdr
);
10679 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10682 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10683 struct cfg80211_wowlan_wakeup
*wakeup
,
10686 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10687 struct sk_buff
*msg
;
10689 int err
, size
= 200;
10691 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10694 size
+= wakeup
->packet_present_len
;
10696 msg
= nlmsg_new(size
, gfp
);
10700 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10704 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10705 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10708 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10709 wdev
->netdev
->ifindex
))
10713 struct nlattr
*reasons
;
10715 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10717 if (wakeup
->disconnect
&&
10718 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10720 if (wakeup
->magic_pkt
&&
10721 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10723 if (wakeup
->gtk_rekey_failure
&&
10724 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10726 if (wakeup
->eap_identity_req
&&
10727 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10729 if (wakeup
->four_way_handshake
&&
10730 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10732 if (wakeup
->rfkill_release
&&
10733 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10736 if (wakeup
->pattern_idx
>= 0 &&
10737 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10738 wakeup
->pattern_idx
))
10741 if (wakeup
->tcp_match
)
10742 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10744 if (wakeup
->tcp_connlost
)
10746 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10748 if (wakeup
->tcp_nomoretokens
)
10750 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10752 if (wakeup
->packet
) {
10753 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10754 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10756 if (!wakeup
->packet_80211
) {
10758 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10760 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10763 if (wakeup
->packet_len
&&
10764 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10767 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10772 nla_nest_end(msg
, reasons
);
10775 err
= genlmsg_end(msg
, hdr
);
10779 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10780 nl80211_mlme_mcgrp
.id
, gfp
);
10786 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10789 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10790 enum nl80211_tdls_operation oper
,
10791 u16 reason_code
, gfp_t gfp
)
10793 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10794 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10795 struct sk_buff
*msg
;
10799 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10802 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10806 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10812 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10813 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10814 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10815 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10816 (reason_code
> 0 &&
10817 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10818 goto nla_put_failure
;
10820 err
= genlmsg_end(msg
, hdr
);
10826 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10827 nl80211_mlme_mcgrp
.id
, gfp
);
10831 genlmsg_cancel(msg
, hdr
);
10834 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10836 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10837 unsigned long state
,
10840 struct netlink_notify
*notify
= _notify
;
10841 struct cfg80211_registered_device
*rdev
;
10842 struct wireless_dev
*wdev
;
10843 struct cfg80211_beacon_registration
*reg
, *tmp
;
10845 if (state
!= NETLINK_URELEASE
)
10846 return NOTIFY_DONE
;
10850 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10851 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10852 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10854 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10855 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10857 if (reg
->nlportid
== notify
->portid
) {
10858 list_del(®
->list
);
10863 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10868 return NOTIFY_DONE
;
10871 static struct notifier_block nl80211_netlink_notifier
= {
10872 .notifier_call
= nl80211_netlink_notify
,
10875 void cfg80211_ft_event(struct net_device
*netdev
,
10876 struct cfg80211_ft_event_params
*ft_event
)
10878 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10879 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10880 struct sk_buff
*msg
;
10884 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10886 if (!ft_event
->target_ap
)
10889 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10893 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10899 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10900 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10901 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10903 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10904 if (ft_event
->ric_ies
)
10905 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10906 ft_event
->ric_ies
);
10908 err
= genlmsg_end(msg
, hdr
);
10914 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10915 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10917 EXPORT_SYMBOL(cfg80211_ft_event
);
10919 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10921 struct cfg80211_registered_device
*rdev
;
10922 struct sk_buff
*msg
;
10926 rdev
= wiphy_to_dev(wdev
->wiphy
);
10927 if (!rdev
->crit_proto_nlportid
)
10930 nlportid
= rdev
->crit_proto_nlportid
;
10931 rdev
->crit_proto_nlportid
= 0;
10933 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10937 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10939 goto nla_put_failure
;
10941 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10942 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10943 goto nla_put_failure
;
10945 genlmsg_end(msg
, hdr
);
10947 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10952 genlmsg_cancel(msg
, hdr
);
10956 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10958 /* initialisation/exit functions */
10960 int nl80211_init(void)
10964 err
= genl_register_family_with_ops(&nl80211_fam
,
10965 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10969 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10973 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10977 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10981 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10985 #ifdef CONFIG_NL80211_TESTMODE
10986 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10990 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_vendor_mcgrp
);
10995 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
11001 genl_unregister_family(&nl80211_fam
);
11005 void nl80211_exit(void)
11007 netlink_unregister_notifier(&nl80211_netlink_notifier
);
11008 genl_unregister_family(&nl80211_fam
);