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
] = { .len
= WLAN_PMKID_LEN
},
314 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
315 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
316 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
317 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
318 .len
= IEEE80211_MAX_DATA_LEN
},
319 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
320 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
322 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
323 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
324 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
325 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
326 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
327 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
328 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
331 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
332 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
333 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
334 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
335 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
336 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
337 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
338 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
339 .len
= IEEE80211_MAX_DATA_LEN
},
340 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
341 .len
= IEEE80211_MAX_DATA_LEN
},
342 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
343 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
344 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
346 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
347 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
349 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
351 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
352 .len
= IEEE80211_MAX_DATA_LEN
},
353 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
354 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
355 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
356 .len
= NL80211_HT_CAPABILITY_LEN
358 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
359 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
360 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
361 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
362 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
363 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
364 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
365 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
366 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
367 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
368 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
369 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
370 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
371 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
372 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
373 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
374 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
375 .len
= NL80211_VHT_CAPABILITY_LEN
,
377 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
378 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
379 .len
= IEEE80211_MAX_DATA_LEN
},
380 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
381 [NL80211_ATTR_STA_SUPPORTED_CHANNELS
] = { .type
= NLA_BINARY
},
382 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES
] = { .type
= NLA_BINARY
},
383 [NL80211_ATTR_VENDOR_ID
] = { .type
= NLA_U32
},
384 [NL80211_ATTR_VENDOR_SUBCMD
] = { .type
= NLA_U32
},
385 [NL80211_ATTR_VENDOR_DATA
] = { .type
= NLA_BINARY
},
388 /* policy for the key attributes */
389 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
390 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
391 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
392 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
393 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
394 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
395 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
396 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
397 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
400 /* policy for the key default flags */
401 static const struct nla_policy
402 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
403 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
404 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
407 /* policy for WoWLAN attributes */
408 static const struct nla_policy
409 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
410 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
411 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
412 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
413 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
414 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
415 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
416 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
417 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
418 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
421 static const struct nla_policy
422 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
423 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
424 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
425 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
426 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
427 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
428 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
429 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
430 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
432 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
433 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
435 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
436 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
437 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
440 /* policy for GTK rekey offload attributes */
441 static const struct nla_policy
442 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
443 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
444 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
445 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
448 static const struct nla_policy
449 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
450 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
451 .len
= IEEE80211_MAX_SSID_LEN
},
452 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
455 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
456 struct netlink_callback
*cb
,
457 struct cfg80211_registered_device
**rdev
,
458 struct wireless_dev
**wdev
)
463 mutex_lock(&cfg80211_mutex
);
466 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
467 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
472 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
473 nl80211_fam
.attrbuf
);
475 err
= PTR_ERR(*wdev
);
478 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
479 /* 0 is the first index - add 1 to parse only once */
480 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
481 cb
->args
[1] = (*wdev
)->identifier
;
483 /* subtract the 1 again here */
484 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
485 struct wireless_dev
*tmp
;
491 *rdev
= wiphy_to_dev(wiphy
);
494 mutex_lock(&(*rdev
)->devlist_mtx
);
495 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
496 if (tmp
->identifier
== cb
->args
[1]) {
501 mutex_unlock(&(*rdev
)->devlist_mtx
);
509 cfg80211_lock_rdev(*rdev
);
511 mutex_unlock(&cfg80211_mutex
);
514 mutex_unlock(&cfg80211_mutex
);
519 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
521 cfg80211_unlock_rdev(rdev
);
526 static bool is_valid_ie_attr(const struct nlattr
*attr
)
534 pos
= nla_data(attr
);
555 /* message building helper */
556 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
559 /* since there is no private header just add the generic one */
560 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
563 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
564 struct ieee80211_channel
*chan
,
567 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
569 goto nla_put_failure
;
571 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
572 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
573 goto nla_put_failure
;
574 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
575 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
576 goto nla_put_failure
;
577 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
578 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
579 goto nla_put_failure
;
580 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
581 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
582 goto nla_put_failure
;
586 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
588 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
590 goto nla_put_failure
;
591 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
593 goto nla_put_failure
;
598 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
599 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
600 goto nla_put_failure
;
601 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
602 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
603 goto nla_put_failure
;
604 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
605 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
606 goto nla_put_failure
;
607 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
608 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
609 goto nla_put_failure
;
612 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
613 DBM_TO_MBM(chan
->max_power
)))
614 goto nla_put_failure
;
622 /* netlink command implementations */
629 bool def_uni
, def_multi
;
632 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
634 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
635 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
640 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
641 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
650 if (tb
[NL80211_KEY_IDX
])
651 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
653 if (tb
[NL80211_KEY_DATA
]) {
654 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
655 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
658 if (tb
[NL80211_KEY_SEQ
]) {
659 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
660 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
663 if (tb
[NL80211_KEY_CIPHER
])
664 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
666 if (tb
[NL80211_KEY_TYPE
]) {
667 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
668 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
672 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
673 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
674 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
675 tb
[NL80211_KEY_DEFAULT_TYPES
],
676 nl80211_key_default_policy
);
680 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
681 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
687 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
689 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
690 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
691 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
694 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
695 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
696 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
699 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
700 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
702 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
703 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
705 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
706 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
715 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
716 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
717 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
721 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
722 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
723 int err
= nla_parse_nested(
724 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
725 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
726 nl80211_key_default_policy
);
730 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
731 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
737 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
741 memset(k
, 0, sizeof(*k
));
745 if (info
->attrs
[NL80211_ATTR_KEY
])
746 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
748 err
= nl80211_parse_key_old(info
, k
);
753 if (k
->def
&& k
->defmgmt
)
757 if (k
->def_uni
|| !k
->def_multi
)
763 if (k
->idx
< 4 || k
->idx
> 5)
766 if (k
->idx
< 0 || k
->idx
> 3)
769 if (k
->idx
< 0 || k
->idx
> 5)
777 static struct cfg80211_cached_keys
*
778 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
779 struct nlattr
*keys
, bool *no_ht
)
781 struct key_parse parse
;
783 struct cfg80211_cached_keys
*result
;
784 int rem
, err
, def
= 0;
786 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
788 return ERR_PTR(-ENOMEM
);
791 result
->defmgmt
= -1;
793 nla_for_each_nested(key
, keys
, rem
) {
794 memset(&parse
, 0, sizeof(parse
));
797 err
= nl80211_parse_key_new(key
, &parse
);
803 if (parse
.idx
< 0 || parse
.idx
> 4)
809 result
->def
= parse
.idx
;
810 if (!parse
.def_uni
|| !parse
.def_multi
)
812 } else if (parse
.defmgmt
)
814 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
815 parse
.idx
, false, NULL
);
818 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
819 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
820 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
821 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
823 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
824 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
836 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
838 ASSERT_WDEV_LOCK(wdev
);
840 switch (wdev
->iftype
) {
841 case NL80211_IFTYPE_AP
:
842 case NL80211_IFTYPE_AP_VLAN
:
843 case NL80211_IFTYPE_P2P_GO
:
844 case NL80211_IFTYPE_MESH_POINT
:
846 case NL80211_IFTYPE_ADHOC
:
847 if (!wdev
->current_bss
)
850 case NL80211_IFTYPE_STATION
:
851 case NL80211_IFTYPE_P2P_CLIENT
:
852 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
862 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
864 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
868 goto nla_put_failure
;
872 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
873 goto nla_put_failure
;
878 nla_nest_end(msg
, nl_modes
);
885 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
889 struct nlattr
*nl_combis
;
892 nl_combis
= nla_nest_start(msg
,
893 NL80211_ATTR_INTERFACE_COMBINATIONS
);
895 goto nla_put_failure
;
897 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
898 const struct ieee80211_iface_combination
*c
;
899 struct nlattr
*nl_combi
, *nl_limits
;
901 c
= &wiphy
->iface_combinations
[i
];
903 nl_combi
= nla_nest_start(msg
, i
+ 1);
905 goto nla_put_failure
;
907 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
909 goto nla_put_failure
;
911 for (j
= 0; j
< c
->n_limits
; j
++) {
912 struct nlattr
*nl_limit
;
914 nl_limit
= nla_nest_start(msg
, j
+ 1);
916 goto nla_put_failure
;
917 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
919 goto nla_put_failure
;
920 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
922 goto nla_put_failure
;
923 nla_nest_end(msg
, nl_limit
);
926 nla_nest_end(msg
, nl_limits
);
928 if (c
->beacon_int_infra_match
&&
929 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
930 goto nla_put_failure
;
931 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
932 c
->num_different_channels
) ||
933 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
935 goto nla_put_failure
;
937 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
938 c
->radar_detect_widths
))
939 goto nla_put_failure
;
941 nla_nest_end(msg
, nl_combi
);
944 nla_nest_end(msg
, nl_combis
);
952 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
955 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
.tcp
;
956 struct nlattr
*nl_tcp
;
961 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
965 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
966 tcp
->data_payload_max
))
969 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
970 tcp
->data_payload_max
))
973 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
976 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
977 sizeof(*tcp
->tok
), tcp
->tok
))
980 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
981 tcp
->data_interval_max
))
984 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
985 tcp
->wake_payload_max
))
988 nla_nest_end(msg
, nl_tcp
);
992 static int nl80211_send_wowlan(struct sk_buff
*msg
,
993 struct cfg80211_registered_device
*dev
,
996 struct nlattr
*nl_wowlan
;
998 if (!dev
->wiphy
.wowlan
.flags
&& !dev
->wiphy
.wowlan
.n_patterns
)
1001 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1005 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1006 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1007 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1008 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1009 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1010 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1011 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1012 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1013 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1014 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1015 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1016 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1017 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1018 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1019 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1020 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1023 if (dev
->wiphy
.wowlan
.n_patterns
) {
1024 struct nl80211_wowlan_pattern_support pat
= {
1025 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1026 .min_pattern_len
= dev
->wiphy
.wowlan
.pattern_min_len
,
1027 .max_pattern_len
= dev
->wiphy
.wowlan
.pattern_max_len
,
1028 .max_pkt_offset
= dev
->wiphy
.wowlan
.max_pkt_offset
,
1031 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1036 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
1039 nla_nest_end(msg
, nl_wowlan
);
1045 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1046 struct ieee80211_supported_band
*sband
)
1048 struct nlattr
*nl_rates
, *nl_rate
;
1049 struct ieee80211_rate
*rate
;
1053 if (sband
->ht_cap
.ht_supported
&&
1054 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1055 sizeof(sband
->ht_cap
.mcs
),
1056 &sband
->ht_cap
.mcs
) ||
1057 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1058 sband
->ht_cap
.cap
) ||
1059 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1060 sband
->ht_cap
.ampdu_factor
) ||
1061 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1062 sband
->ht_cap
.ampdu_density
)))
1066 if (sband
->vht_cap
.vht_supported
&&
1067 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1068 sizeof(sband
->vht_cap
.vht_mcs
),
1069 &sband
->vht_cap
.vht_mcs
) ||
1070 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1071 sband
->vht_cap
.cap
)))
1075 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1079 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1080 nl_rate
= nla_nest_start(msg
, i
);
1084 rate
= &sband
->bitrates
[i
];
1085 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1088 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1090 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1093 nla_nest_end(msg
, nl_rate
);
1096 nla_nest_end(msg
, nl_rates
);
1102 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1103 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1106 struct nlattr
*nl_ftypes
, *nl_ifs
;
1107 enum nl80211_iftype ift
;
1113 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1117 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1118 nl_ftypes
= nla_nest_start(msg
, ift
);
1122 stypes
= mgmt_stypes
[ift
].tx
;
1125 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1126 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1131 nla_nest_end(msg
, nl_ftypes
);
1134 nla_nest_end(msg
, nl_ifs
);
1136 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1140 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1141 nl_ftypes
= nla_nest_start(msg
, ift
);
1145 stypes
= mgmt_stypes
[ift
].rx
;
1148 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1149 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1154 nla_nest_end(msg
, nl_ftypes
);
1156 nla_nest_end(msg
, nl_ifs
);
1161 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1162 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1163 int flags
, bool split
, long *split_start
,
1164 long *band_start
, long *chan_start
)
1167 struct nlattr
*nl_bands
, *nl_band
;
1168 struct nlattr
*nl_freqs
, *nl_freq
;
1169 struct nlattr
*nl_cmds
;
1170 enum ieee80211_band band
;
1171 struct ieee80211_channel
*chan
;
1173 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1174 dev
->wiphy
.mgmt_stypes
;
1175 long start
= 0, start_chan
= 0, start_band
= 0;
1178 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1182 /* allow always using the variables */
1184 split_start
= &start
;
1185 band_start
= &start_band
;
1186 chan_start
= &start_chan
;
1189 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1190 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1191 wiphy_name(&dev
->wiphy
)) ||
1192 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1193 cfg80211_rdev_list_generation
))
1194 goto nla_put_failure
;
1196 switch (*split_start
) {
1198 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1199 dev
->wiphy
.retry_short
) ||
1200 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1201 dev
->wiphy
.retry_long
) ||
1202 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1203 dev
->wiphy
.frag_threshold
) ||
1204 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1205 dev
->wiphy
.rts_threshold
) ||
1206 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1207 dev
->wiphy
.coverage_class
) ||
1208 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1209 dev
->wiphy
.max_scan_ssids
) ||
1210 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1211 dev
->wiphy
.max_sched_scan_ssids
) ||
1212 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1213 dev
->wiphy
.max_scan_ie_len
) ||
1214 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1215 dev
->wiphy
.max_sched_scan_ie_len
) ||
1216 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1217 dev
->wiphy
.max_match_sets
))
1218 goto nla_put_failure
;
1220 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1221 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1222 goto nla_put_failure
;
1223 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1224 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1225 goto nla_put_failure
;
1226 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1227 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1228 goto nla_put_failure
;
1229 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1230 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1231 goto nla_put_failure
;
1232 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1233 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1234 goto nla_put_failure
;
1235 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1236 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1237 goto nla_put_failure
;
1243 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1244 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1245 dev
->wiphy
.cipher_suites
))
1246 goto nla_put_failure
;
1248 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1249 dev
->wiphy
.max_num_pmkids
))
1250 goto nla_put_failure
;
1252 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1253 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1254 goto nla_put_failure
;
1256 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1257 dev
->wiphy
.available_antennas_tx
) ||
1258 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1259 dev
->wiphy
.available_antennas_rx
))
1260 goto nla_put_failure
;
1262 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1263 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1264 dev
->wiphy
.probe_resp_offload
))
1265 goto nla_put_failure
;
1267 if ((dev
->wiphy
.available_antennas_tx
||
1268 dev
->wiphy
.available_antennas_rx
) &&
1269 dev
->ops
->get_antenna
) {
1270 u32 tx_ant
= 0, rx_ant
= 0;
1272 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1274 if (nla_put_u32(msg
,
1275 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1278 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1280 goto nla_put_failure
;
1288 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1289 dev
->wiphy
.interface_modes
))
1290 goto nla_put_failure
;
1295 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1297 goto nla_put_failure
;
1299 for (band
= *band_start
; band
< IEEE80211_NUM_BANDS
; band
++) {
1300 struct ieee80211_supported_band
*sband
;
1302 sband
= dev
->wiphy
.bands
[band
];
1307 nl_band
= nla_nest_start(msg
, band
);
1309 goto nla_put_failure
;
1311 switch (*chan_start
) {
1313 if (nl80211_send_band_rateinfo(msg
, sband
))
1314 goto nla_put_failure
;
1319 /* add frequencies */
1320 nl_freqs
= nla_nest_start(
1321 msg
, NL80211_BAND_ATTR_FREQS
);
1323 goto nla_put_failure
;
1325 for (i
= *chan_start
- 1;
1326 i
< sband
->n_channels
;
1328 nl_freq
= nla_nest_start(msg
, i
);
1330 goto nla_put_failure
;
1332 chan
= &sband
->channels
[i
];
1334 if (nl80211_msg_put_channel(msg
, chan
,
1336 goto nla_put_failure
;
1338 nla_nest_end(msg
, nl_freq
);
1342 if (i
< sband
->n_channels
)
1343 *chan_start
= i
+ 2;
1346 nla_nest_end(msg
, nl_freqs
);
1349 nla_nest_end(msg
, nl_band
);
1352 /* start again here */
1358 nla_nest_end(msg
, nl_bands
);
1360 if (band
< IEEE80211_NUM_BANDS
)
1361 *band_start
= band
+ 1;
1365 /* if bands & channels are done, continue outside */
1366 if (*band_start
== 0 && *chan_start
== 0)
1371 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1373 goto nla_put_failure
;
1376 #define CMD(op, n) \
1378 if (dev->ops->op) { \
1380 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1381 goto nla_put_failure; \
1385 CMD(add_virtual_intf
, NEW_INTERFACE
);
1386 CMD(change_virtual_intf
, SET_INTERFACE
);
1387 CMD(add_key
, NEW_KEY
);
1388 CMD(start_ap
, START_AP
);
1389 CMD(add_station
, NEW_STATION
);
1390 CMD(add_mpath
, NEW_MPATH
);
1391 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1392 CMD(change_bss
, SET_BSS
);
1393 CMD(auth
, AUTHENTICATE
);
1394 CMD(assoc
, ASSOCIATE
);
1395 CMD(deauth
, DEAUTHENTICATE
);
1396 CMD(disassoc
, DISASSOCIATE
);
1397 CMD(join_ibss
, JOIN_IBSS
);
1398 CMD(join_mesh
, JOIN_MESH
);
1399 CMD(set_pmksa
, SET_PMKSA
);
1400 CMD(del_pmksa
, DEL_PMKSA
);
1401 CMD(flush_pmksa
, FLUSH_PMKSA
);
1402 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1403 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1404 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1405 CMD(mgmt_tx
, FRAME
);
1406 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1407 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1409 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1410 goto nla_put_failure
;
1412 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1413 dev
->ops
->join_mesh
) {
1415 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1416 goto nla_put_failure
;
1418 CMD(set_wds_peer
, SET_WDS_PEER
);
1419 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1420 CMD(tdls_mgmt
, TDLS_MGMT
);
1421 CMD(tdls_oper
, TDLS_OPER
);
1423 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1424 CMD(sched_scan_start
, START_SCHED_SCAN
);
1425 CMD(probe_client
, PROBE_CLIENT
);
1426 CMD(set_noack_map
, SET_NOACK_MAP
);
1427 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1429 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1430 goto nla_put_failure
;
1432 CMD(start_p2p_device
, START_P2P_DEVICE
);
1433 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1435 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1436 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1439 #ifdef CONFIG_NL80211_TESTMODE
1440 CMD(testmode_cmd
, TESTMODE
);
1445 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1447 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1448 goto nla_put_failure
;
1451 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1453 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1454 goto nla_put_failure
;
1457 nla_nest_end(msg
, nl_cmds
);
1462 if (dev
->ops
->remain_on_channel
&&
1463 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1465 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1466 dev
->wiphy
.max_remain_on_channel_duration
))
1467 goto nla_put_failure
;
1469 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1470 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1471 goto nla_put_failure
;
1473 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1474 goto nla_put_failure
;
1480 if (nl80211_send_wowlan(msg
, dev
, split
))
1481 goto nla_put_failure
;
1489 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1490 dev
->wiphy
.software_iftypes
))
1491 goto nla_put_failure
;
1493 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
, split
))
1494 goto nla_put_failure
;
1500 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1501 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1502 dev
->wiphy
.ap_sme_capa
))
1503 goto nla_put_failure
;
1505 features
= dev
->wiphy
.features
;
1507 * We can only add the per-channel limit information if the
1508 * dump is split, otherwise it makes it too big. Therefore
1509 * only advertise it in that case.
1512 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1513 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1514 goto nla_put_failure
;
1516 if (dev
->wiphy
.ht_capa_mod_mask
&&
1517 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1518 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1519 dev
->wiphy
.ht_capa_mod_mask
))
1520 goto nla_put_failure
;
1522 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1523 dev
->wiphy
.max_acl_mac_addrs
&&
1524 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1525 dev
->wiphy
.max_acl_mac_addrs
))
1526 goto nla_put_failure
;
1528 if (dev
->wiphy
.n_vendor_commands
) {
1529 const struct nl80211_vendor_cmd_info
*info
;
1530 struct nlattr
*nested
;
1532 nested
= nla_nest_start(msg
, NL80211_ATTR_VENDOR_DATA
);
1534 goto nla_put_failure
;
1536 for (i
= 0; i
< dev
->wiphy
.n_vendor_commands
; i
++) {
1537 info
= &dev
->wiphy
.vendor_commands
[i
].info
;
1538 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1539 goto nla_put_failure
;
1541 nla_nest_end(msg
, nested
);
1544 if (dev
->wiphy
.n_vendor_events
) {
1545 const struct nl80211_vendor_cmd_info
*info
;
1546 struct nlattr
*nested
;
1548 nested
= nla_nest_start(msg
,
1549 NL80211_ATTR_VENDOR_EVENTS
);
1551 goto nla_put_failure
;
1553 for (i
= 0; i
< dev
->wiphy
.n_vendor_events
; i
++) {
1554 info
= &dev
->wiphy
.vendor_events
[i
];
1555 if (nla_put(msg
, i
+ 1, sizeof(*info
), info
))
1556 goto nla_put_failure
;
1558 nla_nest_end(msg
, nested
);
1562 * Any information below this point is only available to
1563 * applications that can deal with it being split. This
1564 * helps ensure that newly added capabilities don't break
1565 * older tools by overrunning their buffers.
1567 * We still increment split_start so that in the split
1568 * case we'll continue with more data in the next round,
1569 * but break unconditionally so unsplit data stops here.
1574 if (dev
->wiphy
.extended_capabilities
&&
1575 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1576 dev
->wiphy
.extended_capabilities_len
,
1577 dev
->wiphy
.extended_capabilities
) ||
1578 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1579 dev
->wiphy
.extended_capabilities_len
,
1580 dev
->wiphy
.extended_capabilities_mask
)))
1581 goto nla_put_failure
;
1583 if (dev
->wiphy
.vht_capa_mod_mask
&&
1584 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1585 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1586 dev
->wiphy
.vht_capa_mod_mask
))
1587 goto nla_put_failure
;
1593 return genlmsg_end(msg
, hdr
);
1596 genlmsg_cancel(msg
, hdr
);
1600 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1603 int start
= cb
->args
[0];
1604 struct cfg80211_registered_device
*dev
;
1605 s64 filter_wiphy
= -1;
1610 /* will be zeroed in nlmsg_parse() */
1611 tb
= kmalloc(sizeof(*tb
) * (NL80211_ATTR_MAX
+ 1), GFP_KERNEL
);
1615 mutex_lock(&cfg80211_mutex
);
1616 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1617 tb
, NL80211_ATTR_MAX
, nl80211_policy
);
1619 split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1620 if (tb
[NL80211_ATTR_WIPHY
])
1621 filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1622 if (tb
[NL80211_ATTR_WDEV
])
1623 filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1624 if (tb
[NL80211_ATTR_IFINDEX
]) {
1625 struct net_device
*netdev
;
1626 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1628 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1630 mutex_unlock(&cfg80211_mutex
);
1634 if (netdev
->ieee80211_ptr
) {
1636 netdev
->ieee80211_ptr
->wiphy
);
1637 filter_wiphy
= dev
->wiphy_idx
;
1644 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1645 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1649 if (filter_wiphy
!= -1 && dev
->wiphy_idx
!= filter_wiphy
)
1651 /* attempt to fit multiple wiphy data chunks into the skb */
1653 ret
= nl80211_send_wiphy(dev
, skb
,
1654 NETLINK_CB(cb
->skb
).portid
,
1657 split
, &cb
->args
[1],
1662 * If sending the wiphy data didn't fit (ENOBUFS
1663 * or EMSGSIZE returned), this SKB is still
1664 * empty (so it's not too big because another
1665 * wiphy dataset is already in the skb) and
1666 * we've not tried to adjust the dump allocation
1667 * yet ... then adjust the alloc size to be
1668 * bigger, and return 1 but with the empty skb.
1669 * This results in an empty message being RX'ed
1670 * in userspace, but that is ignored.
1672 * We can then retry with the larger buffer.
1674 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1676 cb
->min_dump_alloc
< 4096) {
1677 cb
->min_dump_alloc
= 4096;
1678 mutex_unlock(&cfg80211_mutex
);
1684 } while (cb
->args
[1] > 0);
1687 mutex_unlock(&cfg80211_mutex
);
1694 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1696 struct sk_buff
*msg
;
1697 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1699 msg
= nlmsg_new(4096, GFP_KERNEL
);
1703 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1704 false, NULL
, NULL
, NULL
) < 0) {
1709 return genlmsg_reply(msg
, info
);
1712 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1713 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1714 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1715 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1716 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1717 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1720 static int parse_txq_params(struct nlattr
*tb
[],
1721 struct ieee80211_txq_params
*txq_params
)
1723 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1724 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1725 !tb
[NL80211_TXQ_ATTR_AIFS
])
1728 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1729 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1730 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1731 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1732 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1734 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1740 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1743 * You can only set the channel explicitly for WDS interfaces,
1744 * all others have their channel managed via their respective
1745 * "establish a connection" command (connect, join, ...)
1747 * For AP/GO and mesh mode, the channel can be set with the
1748 * channel userspace API, but is only stored and passed to the
1749 * low-level driver when the AP starts or the mesh is joined.
1750 * This is for backward compatibility, userspace can also give
1751 * the channel in the start-ap or join-mesh commands instead.
1753 * Monitors are special as they are normally slaved to
1754 * whatever else is going on, so they have their own special
1755 * operation to set the monitor channel if possible.
1758 wdev
->iftype
== NL80211_IFTYPE_AP
||
1759 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1760 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1761 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1764 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1765 struct genl_info
*info
,
1766 struct cfg80211_chan_def
*chandef
)
1770 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1773 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1775 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1776 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1777 chandef
->center_freq1
= control_freq
;
1778 chandef
->center_freq2
= 0;
1780 /* Primary channel not allowed */
1781 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1784 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1785 enum nl80211_channel_type chantype
;
1787 chantype
= nla_get_u32(
1788 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1791 case NL80211_CHAN_NO_HT
:
1792 case NL80211_CHAN_HT20
:
1793 case NL80211_CHAN_HT40PLUS
:
1794 case NL80211_CHAN_HT40MINUS
:
1795 cfg80211_chandef_create(chandef
, chandef
->chan
,
1801 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1803 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1804 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1805 chandef
->center_freq1
=
1807 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1808 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1809 chandef
->center_freq2
=
1811 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1814 if (!cfg80211_chandef_valid(chandef
))
1817 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1818 IEEE80211_CHAN_DISABLED
))
1824 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1825 struct wireless_dev
*wdev
,
1826 struct genl_info
*info
)
1828 struct cfg80211_chan_def chandef
;
1830 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1833 iftype
= wdev
->iftype
;
1835 if (!nl80211_can_set_dev_channel(wdev
))
1838 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1842 mutex_lock(&rdev
->devlist_mtx
);
1844 case NL80211_IFTYPE_AP
:
1845 case NL80211_IFTYPE_P2P_GO
:
1846 if (wdev
->beacon_interval
) {
1850 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1854 wdev
->preset_chandef
= chandef
;
1857 case NL80211_IFTYPE_MESH_POINT
:
1858 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1860 case NL80211_IFTYPE_MONITOR
:
1861 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1866 mutex_unlock(&rdev
->devlist_mtx
);
1871 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1873 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1874 struct net_device
*netdev
= info
->user_ptr
[1];
1876 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1879 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1881 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1882 struct net_device
*dev
= info
->user_ptr
[1];
1883 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1886 if (!info
->attrs
[NL80211_ATTR_MAC
])
1889 if (netif_running(dev
))
1892 if (!rdev
->ops
->set_wds_peer
)
1895 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1898 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1899 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1903 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1905 struct cfg80211_registered_device
*rdev
;
1906 struct net_device
*netdev
= NULL
;
1907 struct wireless_dev
*wdev
;
1908 int result
= 0, rem_txq_params
= 0;
1909 struct nlattr
*nl_txq_params
;
1911 u8 retry_short
= 0, retry_long
= 0;
1912 u32 frag_threshold
= 0, rts_threshold
= 0;
1913 u8 coverage_class
= 0;
1916 * Try to find the wiphy and netdev. Normally this
1917 * function shouldn't need the netdev, but this is
1918 * done for backward compatibility -- previously
1919 * setting the channel was done per wiphy, but now
1920 * it is per netdev. Previous userland like hostapd
1921 * also passed a netdev to set_wiphy, so that it is
1922 * possible to let that go to the right netdev!
1924 mutex_lock(&cfg80211_mutex
);
1926 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1927 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1929 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1930 if (netdev
&& netdev
->ieee80211_ptr
) {
1931 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1932 mutex_lock(&rdev
->mtx
);
1938 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1941 mutex_unlock(&cfg80211_mutex
);
1942 return PTR_ERR(rdev
);
1948 mutex_lock(&rdev
->mtx
);
1950 wdev
= netdev
->ieee80211_ptr
;
1953 * end workaround code, by now the rdev is available
1954 * and locked, and wdev may or may not be NULL.
1957 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1958 result
= cfg80211_dev_rename(
1959 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1961 mutex_unlock(&cfg80211_mutex
);
1966 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1967 struct ieee80211_txq_params txq_params
;
1968 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1970 if (!rdev
->ops
->set_txq_params
) {
1971 result
= -EOPNOTSUPP
;
1980 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1981 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1986 if (!netif_running(netdev
)) {
1991 nla_for_each_nested(nl_txq_params
,
1992 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1994 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1995 nla_data(nl_txq_params
),
1996 nla_len(nl_txq_params
),
1998 result
= parse_txq_params(tb
, &txq_params
);
2002 result
= rdev_set_txq_params(rdev
, netdev
,
2009 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2010 result
= __nl80211_set_channel(rdev
,
2011 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
2017 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2018 struct wireless_dev
*txp_wdev
= wdev
;
2019 enum nl80211_tx_power_setting type
;
2022 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2025 if (!rdev
->ops
->set_tx_power
) {
2026 result
= -EOPNOTSUPP
;
2030 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2031 type
= nla_get_u32(info
->attrs
[idx
]);
2033 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2034 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
2039 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2040 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2041 mbm
= nla_get_u32(info
->attrs
[idx
]);
2044 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2049 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2050 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2052 if ((!rdev
->wiphy
.available_antennas_tx
&&
2053 !rdev
->wiphy
.available_antennas_rx
) ||
2054 !rdev
->ops
->set_antenna
) {
2055 result
= -EOPNOTSUPP
;
2059 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2060 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2062 /* reject antenna configurations which don't match the
2063 * available antenna masks, except for the "all" mask */
2064 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2065 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2070 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2071 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2073 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2080 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2081 retry_short
= nla_get_u8(
2082 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2083 if (retry_short
== 0) {
2087 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2090 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2091 retry_long
= nla_get_u8(
2092 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2093 if (retry_long
== 0) {
2097 changed
|= WIPHY_PARAM_RETRY_LONG
;
2100 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2101 frag_threshold
= nla_get_u32(
2102 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2103 if (frag_threshold
< 256) {
2107 if (frag_threshold
!= (u32
) -1) {
2109 * Fragments (apart from the last one) are required to
2110 * have even length. Make the fragmentation code
2111 * simpler by stripping LSB should someone try to use
2112 * odd threshold value.
2114 frag_threshold
&= ~0x1;
2116 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2119 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2120 rts_threshold
= nla_get_u32(
2121 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2122 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2125 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2126 coverage_class
= nla_get_u8(
2127 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2128 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2132 u8 old_retry_short
, old_retry_long
;
2133 u32 old_frag_threshold
, old_rts_threshold
;
2134 u8 old_coverage_class
;
2136 if (!rdev
->ops
->set_wiphy_params
) {
2137 result
= -EOPNOTSUPP
;
2141 old_retry_short
= rdev
->wiphy
.retry_short
;
2142 old_retry_long
= rdev
->wiphy
.retry_long
;
2143 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2144 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2145 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2147 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2148 rdev
->wiphy
.retry_short
= retry_short
;
2149 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2150 rdev
->wiphy
.retry_long
= retry_long
;
2151 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2152 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2153 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2154 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2155 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2156 rdev
->wiphy
.coverage_class
= coverage_class
;
2158 result
= rdev_set_wiphy_params(rdev
, changed
);
2160 rdev
->wiphy
.retry_short
= old_retry_short
;
2161 rdev
->wiphy
.retry_long
= old_retry_long
;
2162 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2163 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2164 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2169 mutex_unlock(&rdev
->mtx
);
2175 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2177 return (u64
)wdev
->identifier
|
2178 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2181 static int nl80211_send_chandef(struct sk_buff
*msg
,
2182 struct cfg80211_chan_def
*chandef
)
2184 WARN_ON(!cfg80211_chandef_valid(chandef
));
2186 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2187 chandef
->chan
->center_freq
))
2189 switch (chandef
->width
) {
2190 case NL80211_CHAN_WIDTH_20_NOHT
:
2191 case NL80211_CHAN_WIDTH_20
:
2192 case NL80211_CHAN_WIDTH_40
:
2193 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2194 cfg80211_get_chandef_type(chandef
)))
2200 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2202 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2204 if (chandef
->center_freq2
&&
2205 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2210 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2211 struct cfg80211_registered_device
*rdev
,
2212 struct wireless_dev
*wdev
)
2214 struct net_device
*dev
= wdev
->netdev
;
2217 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2222 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2223 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2224 goto nla_put_failure
;
2226 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2227 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2228 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2229 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2230 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2231 rdev
->devlist_generation
^
2232 (cfg80211_rdev_list_generation
<< 2)))
2233 goto nla_put_failure
;
2235 if (rdev
->ops
->get_channel
) {
2237 struct cfg80211_chan_def chandef
;
2239 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2241 if (nl80211_send_chandef(msg
, &chandef
))
2242 goto nla_put_failure
;
2246 if (wdev
->ssid_len
) {
2247 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2248 goto nla_put_failure
;
2251 return genlmsg_end(msg
, hdr
);
2254 genlmsg_cancel(msg
, hdr
);
2258 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2262 int wp_start
= cb
->args
[0];
2263 int if_start
= cb
->args
[1];
2264 struct cfg80211_registered_device
*rdev
;
2265 struct wireless_dev
*wdev
;
2267 mutex_lock(&cfg80211_mutex
);
2268 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2269 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2271 if (wp_idx
< wp_start
) {
2277 mutex_lock(&rdev
->devlist_mtx
);
2278 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2279 if (if_idx
< if_start
) {
2283 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2284 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2286 mutex_unlock(&rdev
->devlist_mtx
);
2291 mutex_unlock(&rdev
->devlist_mtx
);
2296 mutex_unlock(&cfg80211_mutex
);
2298 cb
->args
[0] = wp_idx
;
2299 cb
->args
[1] = if_idx
;
2304 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2306 struct sk_buff
*msg
;
2307 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2308 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2310 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2314 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2320 return genlmsg_reply(msg
, info
);
2323 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2324 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2325 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2326 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2327 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2328 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2331 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2333 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2341 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2342 nla
, mntr_flags_policy
))
2345 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2347 *mntrflags
|= (1<<flag
);
2352 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2353 struct net_device
*netdev
, u8 use_4addr
,
2354 enum nl80211_iftype iftype
)
2357 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2363 case NL80211_IFTYPE_AP_VLAN
:
2364 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2367 case NL80211_IFTYPE_STATION
:
2368 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2378 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2380 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2381 struct vif_params params
;
2383 enum nl80211_iftype otype
, ntype
;
2384 struct net_device
*dev
= info
->user_ptr
[1];
2385 u32 _flags
, *flags
= NULL
;
2386 bool change
= false;
2388 memset(¶ms
, 0, sizeof(params
));
2390 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2392 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2393 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2396 if (ntype
> NL80211_IFTYPE_MAX
)
2400 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2401 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2403 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2405 if (netif_running(dev
))
2409 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2410 IEEE80211_MAX_MESH_ID_LEN
);
2411 wdev
->mesh_id_up_len
=
2412 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2413 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2414 wdev
->mesh_id_up_len
);
2418 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2419 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2421 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2425 params
.use_4addr
= -1;
2428 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2429 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2431 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2441 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2445 if (!err
&& params
.use_4addr
!= -1)
2446 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2451 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2453 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2454 struct vif_params params
;
2455 struct wireless_dev
*wdev
;
2456 struct sk_buff
*msg
;
2458 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2461 memset(¶ms
, 0, sizeof(params
));
2463 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2466 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2467 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2468 if (type
> NL80211_IFTYPE_MAX
)
2472 if (!rdev
->ops
->add_virtual_intf
||
2473 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2476 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2477 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2479 if (!is_valid_ether_addr(params
.macaddr
))
2480 return -EADDRNOTAVAIL
;
2483 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2484 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2485 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2490 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2494 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2495 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2497 wdev
= rdev_add_virtual_intf(rdev
,
2498 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2499 type
, err
? NULL
: &flags
, ¶ms
);
2502 return PTR_ERR(wdev
);
2506 case NL80211_IFTYPE_MESH_POINT
:
2507 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2510 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2511 IEEE80211_MAX_MESH_ID_LEN
);
2512 wdev
->mesh_id_up_len
=
2513 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2514 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2515 wdev
->mesh_id_up_len
);
2518 case NL80211_IFTYPE_P2P_DEVICE
:
2520 * P2P Device doesn't have a netdev, so doesn't go
2521 * through the netdev notifier and must be added here
2523 mutex_init(&wdev
->mtx
);
2524 INIT_LIST_HEAD(&wdev
->event_list
);
2525 spin_lock_init(&wdev
->event_lock
);
2526 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2527 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2529 mutex_lock(&rdev
->devlist_mtx
);
2530 wdev
->identifier
= ++rdev
->wdev_id
;
2531 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2532 rdev
->devlist_generation
++;
2533 mutex_unlock(&rdev
->devlist_mtx
);
2539 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2545 return genlmsg_reply(msg
, info
);
2548 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2550 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2551 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2553 if (!rdev
->ops
->del_virtual_intf
)
2557 * If we remove a wireless device without a netdev then clear
2558 * user_ptr[1] so that nl80211_post_doit won't dereference it
2559 * to check if it needs to do dev_put(). Otherwise it crashes
2560 * since the wdev has been freed, unlike with a netdev where
2561 * we need the dev_put() for the netdev to really be freed.
2564 info
->user_ptr
[1] = NULL
;
2566 return rdev_del_virtual_intf(rdev
, wdev
);
2569 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2571 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2572 struct net_device
*dev
= info
->user_ptr
[1];
2575 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2578 if (!rdev
->ops
->set_noack_map
)
2581 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2583 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2586 struct get_key_cookie
{
2587 struct sk_buff
*msg
;
2592 static void get_key_callback(void *c
, struct key_params
*params
)
2595 struct get_key_cookie
*cookie
= c
;
2598 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2599 params
->key_len
, params
->key
)) ||
2601 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2602 params
->seq_len
, params
->seq
)) ||
2604 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2606 goto nla_put_failure
;
2608 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2610 goto nla_put_failure
;
2613 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2614 params
->key_len
, params
->key
)) ||
2616 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2617 params
->seq_len
, params
->seq
)) ||
2619 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2621 goto nla_put_failure
;
2623 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2624 goto nla_put_failure
;
2626 nla_nest_end(cookie
->msg
, key
);
2633 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2635 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2637 struct net_device
*dev
= info
->user_ptr
[1];
2639 const u8
*mac_addr
= NULL
;
2641 struct get_key_cookie cookie
= {
2645 struct sk_buff
*msg
;
2647 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2648 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2653 if (info
->attrs
[NL80211_ATTR_MAC
])
2654 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2656 pairwise
= !!mac_addr
;
2657 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2658 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2659 if (kt
>= NUM_NL80211_KEYTYPES
)
2661 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2662 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2664 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2667 if (!rdev
->ops
->get_key
)
2670 if (!pairwise
&& mac_addr
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2673 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2677 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2678 NL80211_CMD_NEW_KEY
);
2680 goto nla_put_failure
;
2683 cookie
.idx
= key_idx
;
2685 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2686 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2687 goto nla_put_failure
;
2689 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2690 goto nla_put_failure
;
2692 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2699 goto nla_put_failure
;
2701 genlmsg_end(msg
, hdr
);
2702 return genlmsg_reply(msg
, info
);
2711 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2713 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2714 struct key_parse key
;
2716 struct net_device
*dev
= info
->user_ptr
[1];
2718 err
= nl80211_parse_key(info
, &key
);
2725 /* only support setting default key */
2726 if (!key
.def
&& !key
.defmgmt
)
2729 wdev_lock(dev
->ieee80211_ptr
);
2732 if (!rdev
->ops
->set_default_key
) {
2737 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2741 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2742 key
.def_uni
, key
.def_multi
);
2747 #ifdef CONFIG_CFG80211_WEXT
2748 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2751 if (key
.def_uni
|| !key
.def_multi
) {
2756 if (!rdev
->ops
->set_default_mgmt_key
) {
2761 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2765 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2769 #ifdef CONFIG_CFG80211_WEXT
2770 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2775 wdev_unlock(dev
->ieee80211_ptr
);
2780 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2782 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2784 struct net_device
*dev
= info
->user_ptr
[1];
2785 struct key_parse key
;
2786 const u8
*mac_addr
= NULL
;
2788 err
= nl80211_parse_key(info
, &key
);
2795 if (info
->attrs
[NL80211_ATTR_MAC
])
2796 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2798 if (key
.type
== -1) {
2800 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2802 key
.type
= NL80211_KEYTYPE_GROUP
;
2806 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2807 key
.type
!= NL80211_KEYTYPE_GROUP
)
2810 if (!rdev
->ops
->add_key
)
2813 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2814 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2818 wdev_lock(dev
->ieee80211_ptr
);
2819 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2821 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2822 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2824 wdev_unlock(dev
->ieee80211_ptr
);
2829 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2831 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2833 struct net_device
*dev
= info
->user_ptr
[1];
2834 u8
*mac_addr
= NULL
;
2835 struct key_parse key
;
2837 err
= nl80211_parse_key(info
, &key
);
2841 if (info
->attrs
[NL80211_ATTR_MAC
])
2842 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2844 if (key
.type
== -1) {
2846 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2848 key
.type
= NL80211_KEYTYPE_GROUP
;
2852 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2853 key
.type
!= NL80211_KEYTYPE_GROUP
)
2856 if (!rdev
->ops
->del_key
)
2859 wdev_lock(dev
->ieee80211_ptr
);
2860 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2862 if (key
.type
== NL80211_KEYTYPE_GROUP
&& mac_addr
&&
2863 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2867 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2868 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2871 #ifdef CONFIG_CFG80211_WEXT
2873 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2874 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2875 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2876 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2879 wdev_unlock(dev
->ieee80211_ptr
);
2884 /* This function returns an error or the number of nested attributes */
2885 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2887 struct nlattr
*attr
;
2888 int n_entries
= 0, tmp
;
2890 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2891 if (nla_len(attr
) != ETH_ALEN
)
2901 * This function parses ACL information and allocates memory for ACL data.
2902 * On successful return, the calling function is responsible to free the
2903 * ACL buffer returned by this function.
2905 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2906 struct genl_info
*info
)
2908 enum nl80211_acl_policy acl_policy
;
2909 struct nlattr
*attr
;
2910 struct cfg80211_acl_data
*acl
;
2911 int i
= 0, n_entries
, tmp
;
2913 if (!wiphy
->max_acl_mac_addrs
)
2914 return ERR_PTR(-EOPNOTSUPP
);
2916 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2917 return ERR_PTR(-EINVAL
);
2919 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2920 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2921 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2922 return ERR_PTR(-EINVAL
);
2924 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2925 return ERR_PTR(-EINVAL
);
2927 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2929 return ERR_PTR(n_entries
);
2931 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2932 return ERR_PTR(-ENOTSUPP
);
2934 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2937 return ERR_PTR(-ENOMEM
);
2939 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2940 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2944 acl
->n_acl_entries
= n_entries
;
2945 acl
->acl_policy
= acl_policy
;
2950 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2952 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2953 struct net_device
*dev
= info
->user_ptr
[1];
2954 struct cfg80211_acl_data
*acl
;
2957 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2958 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2961 if (!dev
->ieee80211_ptr
->beacon_interval
)
2964 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2966 return PTR_ERR(acl
);
2968 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2975 static int nl80211_parse_beacon(struct genl_info
*info
,
2976 struct cfg80211_beacon_data
*bcn
)
2978 bool haveinfo
= false;
2980 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2981 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2982 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2983 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2986 memset(bcn
, 0, sizeof(*bcn
));
2988 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2989 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2990 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2996 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2997 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2999 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
3006 if (info
->attrs
[NL80211_ATTR_IE
]) {
3007 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3008 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3011 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3012 bcn
->proberesp_ies
=
3013 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3014 bcn
->proberesp_ies_len
=
3015 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3018 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3019 bcn
->assocresp_ies
=
3020 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3021 bcn
->assocresp_ies_len
=
3022 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3025 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
3027 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3028 bcn
->probe_resp_len
=
3029 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
3035 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3036 struct cfg80211_ap_settings
*params
)
3038 struct wireless_dev
*wdev
;
3041 mutex_lock(&rdev
->devlist_mtx
);
3043 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3044 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3045 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3048 if (!wdev
->preset_chandef
.chan
)
3051 params
->chandef
= wdev
->preset_chandef
;
3056 mutex_unlock(&rdev
->devlist_mtx
);
3061 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3062 enum nl80211_auth_type auth_type
,
3063 enum nl80211_commands cmd
)
3065 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3069 case NL80211_CMD_AUTHENTICATE
:
3070 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3071 auth_type
== NL80211_AUTHTYPE_SAE
)
3074 case NL80211_CMD_CONNECT
:
3075 case NL80211_CMD_START_AP
:
3076 /* SAE not supported yet */
3077 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3085 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3087 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3088 struct net_device
*dev
= info
->user_ptr
[1];
3089 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3090 struct cfg80211_ap_settings params
;
3092 u8 radar_detect_width
= 0;
3094 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3095 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3098 if (!rdev
->ops
->start_ap
)
3101 if (wdev
->beacon_interval
)
3104 memset(¶ms
, 0, sizeof(params
));
3106 /* these are required for START_AP */
3107 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3108 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3109 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3112 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
3116 params
.beacon_interval
=
3117 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3118 params
.dtim_period
=
3119 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3121 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3126 * In theory, some of these attributes should be required here
3127 * but since they were not used when the command was originally
3128 * added, keep them optional for old user space programs to let
3129 * them continue to work with drivers that do not need the
3130 * additional information -- drivers must check!
3132 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3133 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3135 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3136 if (params
.ssid_len
== 0 ||
3137 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3141 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3142 params
.hidden_ssid
= nla_get_u32(
3143 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3144 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3145 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3146 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3150 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3152 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3153 params
.auth_type
= nla_get_u32(
3154 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3155 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3156 NL80211_CMD_START_AP
))
3159 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3161 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3162 NL80211_MAX_NR_CIPHER_SUITES
);
3166 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3167 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3169 params
.inactivity_timeout
= nla_get_u16(
3170 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3173 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3174 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3176 params
.p2p_ctwindow
=
3177 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3178 if (params
.p2p_ctwindow
> 127)
3180 if (params
.p2p_ctwindow
!= 0 &&
3181 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3185 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3188 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3190 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3193 params
.p2p_opp_ps
= tmp
;
3194 if (params
.p2p_opp_ps
!= 0 &&
3195 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3199 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3200 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3203 } else if (wdev
->preset_chandef
.chan
) {
3204 params
.chandef
= wdev
->preset_chandef
;
3205 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3208 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3211 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3215 radar_detect_width
= BIT(params
.chandef
.width
);
3216 params
.radar_required
= true;
3219 mutex_lock(&rdev
->devlist_mtx
);
3220 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3221 params
.chandef
.chan
,
3223 radar_detect_width
);
3224 mutex_unlock(&rdev
->devlist_mtx
);
3229 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3230 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3231 if (IS_ERR(params
.acl
))
3232 return PTR_ERR(params
.acl
);
3235 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3237 wdev
->preset_chandef
= params
.chandef
;
3238 wdev
->beacon_interval
= params
.beacon_interval
;
3239 wdev
->channel
= params
.chandef
.chan
;
3240 wdev
->ssid_len
= params
.ssid_len
;
3241 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3249 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3251 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3252 struct net_device
*dev
= info
->user_ptr
[1];
3253 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3254 struct cfg80211_beacon_data params
;
3257 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3258 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3261 if (!rdev
->ops
->change_beacon
)
3264 if (!wdev
->beacon_interval
)
3267 err
= nl80211_parse_beacon(info
, ¶ms
);
3271 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3274 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3276 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3277 struct net_device
*dev
= info
->user_ptr
[1];
3279 return cfg80211_stop_ap(rdev
, dev
);
3282 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3283 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3284 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3285 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3286 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3287 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3288 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3291 static int parse_station_flags(struct genl_info
*info
,
3292 enum nl80211_iftype iftype
,
3293 struct station_parameters
*params
)
3295 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3300 * Try parsing the new attribute first so userspace
3301 * can specify both for older kernels.
3303 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3305 struct nl80211_sta_flag_update
*sta_flags
;
3307 sta_flags
= nla_data(nla
);
3308 params
->sta_flags_mask
= sta_flags
->mask
;
3309 params
->sta_flags_set
= sta_flags
->set
;
3310 params
->sta_flags_set
&= params
->sta_flags_mask
;
3311 if ((params
->sta_flags_mask
|
3312 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3317 /* if present, parse the old attribute */
3319 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3323 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3324 nla
, sta_flags_policy
))
3328 * Only allow certain flags for interface types so that
3329 * other attributes are silently ignored. Remember that
3330 * this is backward compatibility code with old userspace
3331 * and shouldn't be hit in other cases anyway.
3334 case NL80211_IFTYPE_AP
:
3335 case NL80211_IFTYPE_AP_VLAN
:
3336 case NL80211_IFTYPE_P2P_GO
:
3337 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3338 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3339 BIT(NL80211_STA_FLAG_WME
) |
3340 BIT(NL80211_STA_FLAG_MFP
);
3342 case NL80211_IFTYPE_P2P_CLIENT
:
3343 case NL80211_IFTYPE_STATION
:
3344 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3345 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3347 case NL80211_IFTYPE_MESH_POINT
:
3348 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3349 BIT(NL80211_STA_FLAG_MFP
) |
3350 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3355 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3357 params
->sta_flags_set
|= (1<<flag
);
3359 /* no longer support new API additions in old API */
3360 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3368 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3371 struct nlattr
*rate
;
3375 rate
= nla_nest_start(msg
, attr
);
3379 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3380 bitrate
= cfg80211_calculate_bitrate(info
);
3381 /* report 16-bit bitrate only if we can */
3382 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3384 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3386 if (bitrate_compat
> 0 &&
3387 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3390 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3391 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3393 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3394 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3396 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3397 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3399 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3400 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3402 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3404 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3405 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3407 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3408 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3410 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3411 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3413 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3414 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3416 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3417 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3421 nla_nest_end(msg
, rate
);
3425 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3427 struct cfg80211_registered_device
*rdev
,
3428 struct net_device
*dev
,
3429 const u8
*mac_addr
, struct station_info
*sinfo
)
3432 struct nlattr
*sinfoattr
, *bss_param
;
3434 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3438 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3439 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3440 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3441 goto nla_put_failure
;
3443 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3445 goto nla_put_failure
;
3446 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3447 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3448 sinfo
->connected_time
))
3449 goto nla_put_failure
;
3450 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3451 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3452 sinfo
->inactive_time
))
3453 goto nla_put_failure
;
3454 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3455 STATION_INFO_RX_BYTES64
)) &&
3456 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3457 (u32
)sinfo
->rx_bytes
))
3458 goto nla_put_failure
;
3459 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3460 STATION_INFO_TX_BYTES64
)) &&
3461 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3462 (u32
)sinfo
->tx_bytes
))
3463 goto nla_put_failure
;
3464 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3465 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3467 goto nla_put_failure
;
3468 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3469 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3471 goto nla_put_failure
;
3472 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3473 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3474 goto nla_put_failure
;
3475 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3476 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3477 goto nla_put_failure
;
3478 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3479 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3480 sinfo
->plink_state
))
3481 goto nla_put_failure
;
3482 switch (rdev
->wiphy
.signal_type
) {
3483 case CFG80211_SIGNAL_TYPE_MBM
:
3484 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3485 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3487 goto nla_put_failure
;
3488 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3489 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3491 goto nla_put_failure
;
3496 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3497 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3498 NL80211_STA_INFO_TX_BITRATE
))
3499 goto nla_put_failure
;
3501 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3502 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3503 NL80211_STA_INFO_RX_BITRATE
))
3504 goto nla_put_failure
;
3506 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3507 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3509 goto nla_put_failure
;
3510 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3511 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3513 goto nla_put_failure
;
3514 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3515 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3517 goto nla_put_failure
;
3518 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3519 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3521 goto nla_put_failure
;
3522 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3523 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3524 sinfo
->beacon_loss_count
))
3525 goto nla_put_failure
;
3526 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3527 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3529 goto nla_put_failure
;
3530 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3531 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3533 goto nla_put_failure
;
3534 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3535 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3537 goto nla_put_failure
;
3538 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3539 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3541 goto nla_put_failure
;
3543 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3544 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3545 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3546 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3547 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3548 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3549 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3550 sinfo
->bss_param
.dtim_period
) ||
3551 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3552 sinfo
->bss_param
.beacon_interval
))
3553 goto nla_put_failure
;
3555 nla_nest_end(msg
, bss_param
);
3557 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3558 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3559 sizeof(struct nl80211_sta_flag_update
),
3561 goto nla_put_failure
;
3562 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3563 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3565 goto nla_put_failure
;
3566 nla_nest_end(msg
, sinfoattr
);
3568 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3569 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3570 sinfo
->assoc_req_ies
))
3571 goto nla_put_failure
;
3573 return genlmsg_end(msg
, hdr
);
3576 genlmsg_cancel(msg
, hdr
);
3580 static int nl80211_dump_station(struct sk_buff
*skb
,
3581 struct netlink_callback
*cb
)
3583 struct station_info sinfo
;
3584 struct cfg80211_registered_device
*dev
;
3585 struct wireless_dev
*wdev
;
3586 u8 mac_addr
[ETH_ALEN
];
3587 int sta_idx
= cb
->args
[2];
3590 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3594 if (!wdev
->netdev
) {
3599 if (!dev
->ops
->dump_station
) {
3605 memset(&sinfo
, 0, sizeof(sinfo
));
3606 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3613 if (nl80211_send_station(skb
,
3614 NETLINK_CB(cb
->skb
).portid
,
3615 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3616 dev
, wdev
->netdev
, mac_addr
,
3625 cb
->args
[2] = sta_idx
;
3628 nl80211_finish_wdev_dump(dev
);
3633 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3635 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3636 struct net_device
*dev
= info
->user_ptr
[1];
3637 struct station_info sinfo
;
3638 struct sk_buff
*msg
;
3639 u8
*mac_addr
= NULL
;
3642 memset(&sinfo
, 0, sizeof(sinfo
));
3644 if (!info
->attrs
[NL80211_ATTR_MAC
])
3647 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3649 if (!rdev
->ops
->get_station
)
3652 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3656 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3660 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3661 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3666 return genlmsg_reply(msg
, info
);
3669 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3670 struct station_parameters
*params
,
3671 enum cfg80211_station_type statype
)
3673 if (params
->listen_interval
!= -1)
3678 /* When you run into this, adjust the code below for the new flag */
3679 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3682 case CFG80211_STA_MESH_PEER_KERNEL
:
3683 case CFG80211_STA_MESH_PEER_USER
:
3685 * No ignoring the TDLS flag here -- the userspace mesh
3686 * code doesn't have the bug of including TDLS in the
3689 if (params
->sta_flags_mask
&
3690 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3691 BIT(NL80211_STA_FLAG_MFP
) |
3692 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3695 case CFG80211_STA_TDLS_PEER_SETUP
:
3696 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3697 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3699 /* ignore since it can't change */
3700 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3703 /* disallow mesh-specific things */
3704 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3706 if (params
->local_pm
)
3708 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3712 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3713 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3714 /* TDLS can't be set, ... */
3715 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3718 * ... but don't bother the driver with it. This works around
3719 * a hostapd/wpa_supplicant issue -- it always includes the
3720 * TLDS_PEER flag in the mask even for AP mode.
3722 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3725 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3726 /* reject other things that can't change */
3727 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3729 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3731 if (params
->supported_rates
)
3733 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3737 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3743 case CFG80211_STA_AP_MLME_CLIENT
:
3744 /* Use this only for authorizing/unauthorizing a station */
3745 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3748 case CFG80211_STA_AP_CLIENT
:
3749 /* accept only the listed bits */
3750 if (params
->sta_flags_mask
&
3751 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3752 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3753 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3754 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3755 BIT(NL80211_STA_FLAG_WME
) |
3756 BIT(NL80211_STA_FLAG_MFP
)))
3759 /* but authenticated/associated only if driver handles it */
3760 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3761 params
->sta_flags_mask
&
3762 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3763 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3766 case CFG80211_STA_IBSS
:
3767 case CFG80211_STA_AP_STA
:
3768 /* reject any changes other than AUTHORIZED */
3769 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3772 case CFG80211_STA_TDLS_PEER_SETUP
:
3773 /* reject any changes other than AUTHORIZED or WME */
3774 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3775 BIT(NL80211_STA_FLAG_WME
)))
3777 /* force (at least) rates when authorizing */
3778 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3779 !params
->supported_rates
)
3782 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3783 /* reject any changes */
3785 case CFG80211_STA_MESH_PEER_KERNEL
:
3786 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3789 case CFG80211_STA_MESH_PEER_USER
:
3790 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3797 EXPORT_SYMBOL(cfg80211_check_station_change
);
3800 * Get vlan interface making sure it is running and on the right wiphy.
3802 static struct net_device
*get_vlan(struct genl_info
*info
,
3803 struct cfg80211_registered_device
*rdev
)
3805 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3806 struct net_device
*v
;
3812 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3814 return ERR_PTR(-ENODEV
);
3816 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3821 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3822 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3823 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3828 if (!netif_running(v
)) {
3836 return ERR_PTR(ret
);
3839 static struct nla_policy
3840 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3841 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3842 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3845 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3846 struct station_parameters
*params
)
3848 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3852 /* parse WME attributes if present */
3853 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3856 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3857 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3858 nl80211_sta_wme_policy
);
3862 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3863 params
->uapsd_queues
= nla_get_u8(
3864 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3865 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3868 if (tb
[NL80211_STA_WME_MAX_SP
])
3869 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3871 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3874 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3879 static int nl80211_set_station_tdls(struct genl_info
*info
,
3880 struct station_parameters
*params
)
3882 /* Dummy STA entry gets updated once the peer capabilities are known */
3883 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3885 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3886 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3888 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3890 return nl80211_parse_sta_wme(info
, params
);
3893 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3895 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3896 struct net_device
*dev
= info
->user_ptr
[1];
3897 struct station_parameters params
;
3901 memset(¶ms
, 0, sizeof(params
));
3903 params
.listen_interval
= -1;
3905 if (!rdev
->ops
->change_station
)
3908 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3911 if (!info
->attrs
[NL80211_ATTR_MAC
])
3914 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3916 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3917 params
.supported_rates
=
3918 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3919 params
.supported_rates_len
=
3920 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3923 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3925 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3926 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3929 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3931 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3932 params
.ext_capab_len
=
3933 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3936 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3939 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3942 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3943 params
.plink_action
=
3944 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3945 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3949 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3950 params
.plink_state
=
3951 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3952 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3954 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3957 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3958 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3959 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3961 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3962 pm
> NL80211_MESH_POWER_MAX
)
3965 params
.local_pm
= pm
;
3968 /* Include parameters for TDLS peer (will check later) */
3969 err
= nl80211_set_station_tdls(info
, ¶ms
);
3973 params
.vlan
= get_vlan(info
, rdev
);
3974 if (IS_ERR(params
.vlan
))
3975 return PTR_ERR(params
.vlan
);
3977 switch (dev
->ieee80211_ptr
->iftype
) {
3978 case NL80211_IFTYPE_AP
:
3979 case NL80211_IFTYPE_AP_VLAN
:
3980 case NL80211_IFTYPE_P2P_GO
:
3981 case NL80211_IFTYPE_P2P_CLIENT
:
3982 case NL80211_IFTYPE_STATION
:
3983 case NL80211_IFTYPE_ADHOC
:
3984 case NL80211_IFTYPE_MESH_POINT
:
3991 /* driver will call cfg80211_check_station_change() */
3992 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3996 dev_put(params
.vlan
);
4001 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4003 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4005 struct net_device
*dev
= info
->user_ptr
[1];
4006 struct station_parameters params
;
4007 u8
*mac_addr
= NULL
;
4009 memset(¶ms
, 0, sizeof(params
));
4011 if (!rdev
->ops
->add_station
)
4014 if (!info
->attrs
[NL80211_ATTR_MAC
])
4017 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4020 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4023 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
4026 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4027 params
.supported_rates
=
4028 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4029 params
.supported_rates_len
=
4030 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4031 params
.listen_interval
=
4032 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4034 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4035 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4038 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4040 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4041 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4044 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4046 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4047 params
.ext_capab_len
=
4048 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4051 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4053 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4055 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4057 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4059 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4060 params
.plink_action
=
4061 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4062 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4066 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4070 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4073 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4074 * as userspace might just pass through the capabilities from the IEs
4075 * directly, rather than enforcing this restriction and returning an
4076 * error in this case.
4078 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
))) {
4079 params
.ht_capa
= NULL
;
4080 params
.vht_capa
= NULL
;
4083 /* When you run into this, adjust the code below for the new flag */
4084 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4086 switch (dev
->ieee80211_ptr
->iftype
) {
4087 case NL80211_IFTYPE_AP
:
4088 case NL80211_IFTYPE_AP_VLAN
:
4089 case NL80211_IFTYPE_P2P_GO
:
4090 /* ignore WME attributes if iface/sta is not capable */
4091 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4092 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4093 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4095 /* TDLS peers cannot be added */
4096 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4098 /* but don't bother the driver with it */
4099 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4101 /* allow authenticated/associated only if driver handles it */
4102 if (!(rdev
->wiphy
.features
&
4103 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4104 params
.sta_flags_mask
&
4105 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4106 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4109 /* must be last in here for error handling */
4110 params
.vlan
= get_vlan(info
, rdev
);
4111 if (IS_ERR(params
.vlan
))
4112 return PTR_ERR(params
.vlan
);
4114 case NL80211_IFTYPE_MESH_POINT
:
4115 /* ignore uAPSD data */
4116 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4118 /* associated is disallowed */
4119 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4121 /* TDLS peers cannot be added */
4122 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4125 case NL80211_IFTYPE_STATION
:
4126 case NL80211_IFTYPE_P2P_CLIENT
:
4127 /* ignore uAPSD data */
4128 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4130 /* these are disallowed */
4131 if (params
.sta_flags_mask
&
4132 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4133 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4135 /* Only TDLS peers can be added */
4136 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4138 /* Can only add if TDLS ... */
4139 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4141 /* ... with external setup is supported */
4142 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4145 * Older wpa_supplicant versions always mark the TDLS peer
4146 * as authorized, but it shouldn't yet be.
4148 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4154 /* be aware of params.vlan when changing code here */
4156 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4159 dev_put(params
.vlan
);
4163 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4165 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4166 struct net_device
*dev
= info
->user_ptr
[1];
4167 u8
*mac_addr
= NULL
;
4169 if (info
->attrs
[NL80211_ATTR_MAC
])
4170 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4172 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4173 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4174 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4175 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4178 if (!rdev
->ops
->del_station
)
4181 return rdev_del_station(rdev
, dev
, mac_addr
);
4184 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4185 int flags
, struct net_device
*dev
,
4186 u8
*dst
, u8
*next_hop
,
4187 struct mpath_info
*pinfo
)
4190 struct nlattr
*pinfoattr
;
4192 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4196 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4197 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4198 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4199 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4200 goto nla_put_failure
;
4202 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4204 goto nla_put_failure
;
4205 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4206 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4208 goto nla_put_failure
;
4209 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4210 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4211 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4212 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4214 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4215 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4217 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4218 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4220 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4221 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4222 pinfo
->discovery_timeout
)) ||
4223 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4224 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4225 pinfo
->discovery_retries
)))
4226 goto nla_put_failure
;
4228 nla_nest_end(msg
, pinfoattr
);
4230 return genlmsg_end(msg
, hdr
);
4233 genlmsg_cancel(msg
, hdr
);
4237 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4238 struct netlink_callback
*cb
)
4240 struct mpath_info pinfo
;
4241 struct cfg80211_registered_device
*dev
;
4242 struct wireless_dev
*wdev
;
4244 u8 next_hop
[ETH_ALEN
];
4245 int path_idx
= cb
->args
[2];
4248 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4252 if (!dev
->ops
->dump_mpath
) {
4257 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4263 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4270 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4271 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4272 wdev
->netdev
, dst
, next_hop
,
4281 cb
->args
[2] = path_idx
;
4284 nl80211_finish_wdev_dump(dev
);
4288 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4290 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4292 struct net_device
*dev
= info
->user_ptr
[1];
4293 struct mpath_info pinfo
;
4294 struct sk_buff
*msg
;
4296 u8 next_hop
[ETH_ALEN
];
4298 memset(&pinfo
, 0, sizeof(pinfo
));
4300 if (!info
->attrs
[NL80211_ATTR_MAC
])
4303 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4305 if (!rdev
->ops
->get_mpath
)
4308 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4311 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4315 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4319 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4320 dev
, dst
, next_hop
, &pinfo
) < 0) {
4325 return genlmsg_reply(msg
, info
);
4328 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4330 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4331 struct net_device
*dev
= info
->user_ptr
[1];
4333 u8
*next_hop
= NULL
;
4335 if (!info
->attrs
[NL80211_ATTR_MAC
])
4338 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4341 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4342 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4344 if (!rdev
->ops
->change_mpath
)
4347 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4350 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4353 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4355 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4356 struct net_device
*dev
= info
->user_ptr
[1];
4358 u8
*next_hop
= NULL
;
4360 if (!info
->attrs
[NL80211_ATTR_MAC
])
4363 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4366 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4367 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4369 if (!rdev
->ops
->add_mpath
)
4372 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4375 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4378 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4380 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4381 struct net_device
*dev
= info
->user_ptr
[1];
4384 if (info
->attrs
[NL80211_ATTR_MAC
])
4385 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4387 if (!rdev
->ops
->del_mpath
)
4390 return rdev_del_mpath(rdev
, dev
, dst
);
4393 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4395 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4396 struct net_device
*dev
= info
->user_ptr
[1];
4397 struct bss_parameters params
;
4399 memset(¶ms
, 0, sizeof(params
));
4400 /* default to not changing parameters */
4401 params
.use_cts_prot
= -1;
4402 params
.use_short_preamble
= -1;
4403 params
.use_short_slot_time
= -1;
4404 params
.ap_isolate
= -1;
4405 params
.ht_opmode
= -1;
4406 params
.p2p_ctwindow
= -1;
4407 params
.p2p_opp_ps
= -1;
4409 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4410 params
.use_cts_prot
=
4411 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4412 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4413 params
.use_short_preamble
=
4414 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4415 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4416 params
.use_short_slot_time
=
4417 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4418 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4419 params
.basic_rates
=
4420 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4421 params
.basic_rates_len
=
4422 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4424 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4425 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4426 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4428 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4430 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4431 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4433 params
.p2p_ctwindow
=
4434 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4435 if (params
.p2p_ctwindow
< 0)
4437 if (params
.p2p_ctwindow
!= 0 &&
4438 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4442 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4445 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4447 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4450 params
.p2p_opp_ps
= tmp
;
4451 if (params
.p2p_opp_ps
&&
4452 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4456 if (!rdev
->ops
->change_bss
)
4459 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4460 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4463 return rdev_change_bss(rdev
, dev
, ¶ms
);
4466 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4467 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4468 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4469 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4470 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4471 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4472 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4475 static int parse_reg_rule(struct nlattr
*tb
[],
4476 struct ieee80211_reg_rule
*reg_rule
)
4478 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4479 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4481 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4483 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4485 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4487 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4489 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4492 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4494 freq_range
->start_freq_khz
=
4495 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4496 freq_range
->end_freq_khz
=
4497 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4498 freq_range
->max_bandwidth_khz
=
4499 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4501 power_rule
->max_eirp
=
4502 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4504 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4505 power_rule
->max_antenna_gain
=
4506 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4511 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4515 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4518 * You should only get this when cfg80211 hasn't yet initialized
4519 * completely when built-in to the kernel right between the time
4520 * window between nl80211_init() and regulatory_init(), if that is
4523 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4524 return -EINPROGRESS
;
4526 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4529 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4531 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4532 user_reg_hint_type
=
4533 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4535 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4537 switch (user_reg_hint_type
) {
4538 case NL80211_USER_REG_HINT_USER
:
4539 case NL80211_USER_REG_HINT_CELL_BASE
:
4545 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4550 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4551 struct genl_info
*info
)
4553 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4554 struct net_device
*dev
= info
->user_ptr
[1];
4555 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4556 struct mesh_config cur_params
;
4559 struct nlattr
*pinfoattr
;
4560 struct sk_buff
*msg
;
4562 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4565 if (!rdev
->ops
->get_mesh_config
)
4569 /* If not connected, get default parameters */
4570 if (!wdev
->mesh_id_len
)
4571 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4573 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4579 /* Draw up a netlink message to send back */
4580 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4583 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4584 NL80211_CMD_GET_MESH_CONFIG
);
4587 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4589 goto nla_put_failure
;
4590 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4591 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4592 cur_params
.dot11MeshRetryTimeout
) ||
4593 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4594 cur_params
.dot11MeshConfirmTimeout
) ||
4595 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4596 cur_params
.dot11MeshHoldingTimeout
) ||
4597 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4598 cur_params
.dot11MeshMaxPeerLinks
) ||
4599 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4600 cur_params
.dot11MeshMaxRetries
) ||
4601 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4602 cur_params
.dot11MeshTTL
) ||
4603 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4604 cur_params
.element_ttl
) ||
4605 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4606 cur_params
.auto_open_plinks
) ||
4607 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4608 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4609 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4610 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4611 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4612 cur_params
.path_refresh_time
) ||
4613 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4614 cur_params
.min_discovery_timeout
) ||
4615 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4616 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4617 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4618 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4619 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4620 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4621 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4622 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4623 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4624 cur_params
.dot11MeshHWMPRootMode
) ||
4625 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4626 cur_params
.dot11MeshHWMPRannInterval
) ||
4627 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4628 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4629 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4630 cur_params
.dot11MeshForwarding
) ||
4631 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4632 cur_params
.rssi_threshold
) ||
4633 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4634 cur_params
.ht_opmode
) ||
4635 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4636 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4637 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4638 cur_params
.dot11MeshHWMProotInterval
) ||
4639 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4640 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4641 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4642 cur_params
.power_mode
) ||
4643 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4644 cur_params
.dot11MeshAwakeWindowDuration
))
4645 goto nla_put_failure
;
4646 nla_nest_end(msg
, pinfoattr
);
4647 genlmsg_end(msg
, hdr
);
4648 return genlmsg_reply(msg
, info
);
4651 genlmsg_cancel(msg
, hdr
);
4657 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4658 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4659 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4660 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4661 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4662 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4663 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4664 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4665 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4666 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4667 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4668 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4669 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4670 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4671 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4672 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4673 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4674 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4675 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4676 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4677 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4678 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4679 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4680 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4681 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4682 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4683 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4684 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4687 static const struct nla_policy
4688 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4689 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4690 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4691 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4692 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4693 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4694 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4695 .len
= IEEE80211_MAX_DATA_LEN
},
4696 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4699 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4700 struct mesh_config
*cfg
,
4703 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4706 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4709 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4711 cfg->param = fn(tb[attr]); \
4712 mask |= (1 << (attr - 1)); \
4717 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4719 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4720 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4721 nl80211_meshconf_params_policy
))
4724 /* This makes sure that there aren't more than 32 mesh config
4725 * parameters (otherwise our bitfield scheme would not work.) */
4726 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4728 /* Fill in the params struct */
4729 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4730 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4732 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4733 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4735 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4736 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4738 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4739 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4741 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4742 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4744 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4745 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4746 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4747 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4749 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4750 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4752 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4754 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4756 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4757 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4759 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4760 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4762 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4763 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4765 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4767 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4769 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4771 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4773 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4775 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4777 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4778 dot11MeshHWMPnetDiameterTraversalTime
,
4780 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4782 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4783 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4785 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4786 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4788 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4789 dot11MeshGateAnnouncementProtocol
, 0, 1,
4790 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4792 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4793 mask
, NL80211_MESHCONF_FORWARDING
,
4795 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4796 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4798 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4799 mask
, NL80211_MESHCONF_HT_OPMODE
,
4801 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4803 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4805 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4806 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4808 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4809 dot11MeshHWMPconfirmationInterval
,
4811 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4813 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4814 NL80211_MESH_POWER_ACTIVE
,
4815 NL80211_MESH_POWER_MAX
,
4816 mask
, NL80211_MESHCONF_POWER_MODE
,
4818 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4820 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4826 #undef FILL_IN_MESH_PARAM_IF_SET
4829 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4830 struct mesh_setup
*setup
)
4832 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4833 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4835 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4837 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4838 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4839 nl80211_mesh_setup_params_policy
))
4842 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4843 setup
->sync_method
=
4844 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4845 IEEE80211_SYNC_METHOD_VENDOR
:
4846 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4848 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4849 setup
->path_sel_proto
=
4850 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4851 IEEE80211_PATH_PROTOCOL_VENDOR
:
4852 IEEE80211_PATH_PROTOCOL_HWMP
;
4854 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4855 setup
->path_metric
=
4856 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4857 IEEE80211_PATH_METRIC_VENDOR
:
4858 IEEE80211_PATH_METRIC_AIRTIME
;
4861 if (tb
[NL80211_MESH_SETUP_IE
]) {
4862 struct nlattr
*ieattr
=
4863 tb
[NL80211_MESH_SETUP_IE
];
4864 if (!is_valid_ie_attr(ieattr
))
4866 setup
->ie
= nla_data(ieattr
);
4867 setup
->ie_len
= nla_len(ieattr
);
4869 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4870 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4872 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4873 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4874 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4875 if (setup
->is_secure
)
4876 setup
->user_mpm
= true;
4881 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4882 struct genl_info
*info
)
4884 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4885 struct net_device
*dev
= info
->user_ptr
[1];
4886 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4887 struct mesh_config cfg
;
4891 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4894 if (!rdev
->ops
->update_mesh_config
)
4897 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4902 if (!wdev
->mesh_id_len
)
4906 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4913 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4915 const struct ieee80211_regdomain
*regdom
;
4916 struct sk_buff
*msg
;
4918 struct nlattr
*nl_reg_rules
;
4922 mutex_lock(&cfg80211_mutex
);
4924 if (!cfg80211_regdomain
)
4927 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4933 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4934 NL80211_CMD_GET_REG
);
4938 if (reg_last_request_cell_base() &&
4939 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4940 NL80211_USER_REG_HINT_CELL_BASE
))
4941 goto nla_put_failure
;
4944 regdom
= rcu_dereference(cfg80211_regdomain
);
4946 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4947 (regdom
->dfs_region
&&
4948 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4949 goto nla_put_failure_rcu
;
4951 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4953 goto nla_put_failure_rcu
;
4955 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4956 struct nlattr
*nl_reg_rule
;
4957 const struct ieee80211_reg_rule
*reg_rule
;
4958 const struct ieee80211_freq_range
*freq_range
;
4959 const struct ieee80211_power_rule
*power_rule
;
4961 reg_rule
= ®dom
->reg_rules
[i
];
4962 freq_range
= ®_rule
->freq_range
;
4963 power_rule
= ®_rule
->power_rule
;
4965 nl_reg_rule
= nla_nest_start(msg
, i
);
4967 goto nla_put_failure_rcu
;
4969 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4971 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4972 freq_range
->start_freq_khz
) ||
4973 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4974 freq_range
->end_freq_khz
) ||
4975 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4976 freq_range
->max_bandwidth_khz
) ||
4977 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4978 power_rule
->max_antenna_gain
) ||
4979 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4980 power_rule
->max_eirp
))
4981 goto nla_put_failure_rcu
;
4983 nla_nest_end(msg
, nl_reg_rule
);
4987 nla_nest_end(msg
, nl_reg_rules
);
4989 genlmsg_end(msg
, hdr
);
4990 err
= genlmsg_reply(msg
, info
);
4993 nla_put_failure_rcu
:
4996 genlmsg_cancel(msg
, hdr
);
5001 mutex_unlock(&cfg80211_mutex
);
5005 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5007 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5008 struct nlattr
*nl_reg_rule
;
5009 char *alpha2
= NULL
;
5010 int rem_reg_rules
= 0, r
= 0;
5011 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5013 struct ieee80211_regdomain
*rd
= NULL
;
5015 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5018 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5021 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5023 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5024 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5026 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5029 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5033 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5034 num_rules
* sizeof(struct ieee80211_reg_rule
);
5036 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5040 rd
->n_reg_rules
= num_rules
;
5041 rd
->alpha2
[0] = alpha2
[0];
5042 rd
->alpha2
[1] = alpha2
[1];
5045 * Disable DFS master mode if the DFS region was
5046 * not supported or known on this kernel.
5048 if (reg_supported_dfs_region(dfs_region
))
5049 rd
->dfs_region
= dfs_region
;
5051 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5053 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5054 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5056 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5062 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5068 mutex_lock(&cfg80211_mutex
);
5071 /* set_regdom took ownership */
5073 mutex_unlock(&cfg80211_mutex
);
5080 static int validate_scan_freqs(struct nlattr
*freqs
)
5082 struct nlattr
*attr1
, *attr2
;
5083 int n_channels
= 0, tmp1
, tmp2
;
5085 nla_for_each_nested(attr1
, freqs
, tmp1
)
5086 if (nla_len(attr1
) != sizeof(u32
))
5089 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5092 * Some hardware has a limited channel list for
5093 * scanning, and it is pretty much nonsensical
5094 * to scan for a channel twice, so disallow that
5095 * and don't require drivers to check that the
5096 * channel list they get isn't longer than what
5097 * they can scan, as long as they can scan all
5098 * the channels they registered at once.
5100 nla_for_each_nested(attr2
, freqs
, tmp2
)
5101 if (attr1
!= attr2
&&
5102 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5109 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5111 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5112 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5113 struct cfg80211_scan_request
*request
;
5114 struct nlattr
*attr
;
5115 struct wiphy
*wiphy
;
5116 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5119 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5122 wiphy
= &rdev
->wiphy
;
5124 if (!rdev
->ops
->scan
)
5127 mutex_lock(&rdev
->sched_scan_mtx
);
5128 if (rdev
->scan_req
) {
5133 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5134 n_channels
= validate_scan_freqs(
5135 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5141 enum ieee80211_band band
;
5144 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5145 if (wiphy
->bands
[band
])
5146 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5149 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5150 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5153 if (n_ssids
> wiphy
->max_scan_ssids
) {
5158 if (info
->attrs
[NL80211_ATTR_IE
])
5159 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5163 if (ie_len
> wiphy
->max_scan_ie_len
) {
5168 request
= kzalloc(sizeof(*request
)
5169 + sizeof(*request
->ssids
) * n_ssids
5170 + sizeof(*request
->channels
) * n_channels
5171 + ie_len
, GFP_KERNEL
);
5178 request
->ssids
= (void *)&request
->channels
[n_channels
];
5179 request
->n_ssids
= n_ssids
;
5182 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5184 request
->ie
= (void *)(request
->channels
+ n_channels
);
5188 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5189 /* user specified, bail out if channel not found */
5190 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5191 struct ieee80211_channel
*chan
;
5193 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5200 /* ignore disabled channels */
5201 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5204 request
->channels
[i
] = chan
;
5208 enum ieee80211_band band
;
5211 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5213 if (!wiphy
->bands
[band
])
5215 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5216 struct ieee80211_channel
*chan
;
5218 chan
= &wiphy
->bands
[band
]->channels
[j
];
5220 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5223 request
->channels
[i
] = chan
;
5234 request
->n_channels
= i
;
5237 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5238 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5239 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5243 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5244 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5249 if (info
->attrs
[NL80211_ATTR_IE
]) {
5250 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5251 memcpy((void *)request
->ie
,
5252 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5256 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5257 if (wiphy
->bands
[i
])
5259 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5261 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5262 nla_for_each_nested(attr
,
5263 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5265 enum ieee80211_band band
= nla_type(attr
);
5267 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5271 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5274 &request
->rates
[band
]);
5280 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5281 request
->flags
= nla_get_u32(
5282 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5283 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5284 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5285 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5286 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5293 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5295 request
->wdev
= wdev
;
5296 request
->wiphy
= &rdev
->wiphy
;
5297 request
->scan_start
= jiffies
;
5299 rdev
->scan_req
= request
;
5300 err
= rdev_scan(rdev
, request
);
5303 nl80211_send_scan_start(rdev
, wdev
);
5305 dev_hold(wdev
->netdev
);
5308 rdev
->scan_req
= NULL
;
5313 mutex_unlock(&rdev
->sched_scan_mtx
);
5317 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5318 struct genl_info
*info
)
5320 struct cfg80211_sched_scan_request
*request
;
5321 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5322 struct net_device
*dev
= info
->user_ptr
[1];
5323 struct nlattr
*attr
;
5324 struct wiphy
*wiphy
;
5325 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5327 enum ieee80211_band band
;
5329 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5331 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5332 !rdev
->ops
->sched_scan_start
)
5335 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5338 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5341 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5345 wiphy
= &rdev
->wiphy
;
5347 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5348 n_channels
= validate_scan_freqs(
5349 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5355 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5356 if (wiphy
->bands
[band
])
5357 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5360 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5361 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5365 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5368 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5369 nla_for_each_nested(attr
,
5370 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5374 if (n_match_sets
> wiphy
->max_match_sets
)
5377 if (info
->attrs
[NL80211_ATTR_IE
])
5378 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5382 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5385 mutex_lock(&rdev
->sched_scan_mtx
);
5387 if (rdev
->sched_scan_req
) {
5392 request
= kzalloc(sizeof(*request
)
5393 + sizeof(*request
->ssids
) * n_ssids
5394 + sizeof(*request
->match_sets
) * n_match_sets
5395 + sizeof(*request
->channels
) * n_channels
5396 + ie_len
, GFP_KERNEL
);
5403 request
->ssids
= (void *)&request
->channels
[n_channels
];
5404 request
->n_ssids
= n_ssids
;
5407 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5409 request
->ie
= (void *)(request
->channels
+ n_channels
);
5414 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5415 else if (request
->ssids
)
5416 request
->match_sets
=
5417 (void *)(request
->ssids
+ n_ssids
);
5419 request
->match_sets
=
5420 (void *)(request
->channels
+ n_channels
);
5422 request
->n_match_sets
= n_match_sets
;
5425 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5426 /* user specified, bail out if channel not found */
5427 nla_for_each_nested(attr
,
5428 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5430 struct ieee80211_channel
*chan
;
5432 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5439 /* ignore disabled channels */
5440 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5443 request
->channels
[i
] = chan
;
5448 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5450 if (!wiphy
->bands
[band
])
5452 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5453 struct ieee80211_channel
*chan
;
5455 chan
= &wiphy
->bands
[band
]->channels
[j
];
5457 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5460 request
->channels
[i
] = chan
;
5471 request
->n_channels
= i
;
5474 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5475 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5477 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5481 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5482 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5489 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5490 nla_for_each_nested(attr
,
5491 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5493 struct nlattr
*ssid
, *rssi
;
5495 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5496 nla_data(attr
), nla_len(attr
),
5497 nl80211_match_policy
);
5498 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5500 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5504 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5505 nla_data(ssid
), nla_len(ssid
));
5506 request
->match_sets
[i
].ssid
.ssid_len
=
5509 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5511 request
->rssi_thold
= nla_get_u32(rssi
);
5513 request
->rssi_thold
=
5514 NL80211_SCAN_RSSI_THOLD_OFF
;
5519 if (info
->attrs
[NL80211_ATTR_IE
]) {
5520 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5521 memcpy((void *)request
->ie
,
5522 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5526 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5527 request
->flags
= nla_get_u32(
5528 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5529 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5530 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5531 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5532 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5539 request
->wiphy
= &rdev
->wiphy
;
5540 request
->interval
= interval
;
5541 request
->scan_start
= jiffies
;
5543 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5545 rdev
->sched_scan_req
= request
;
5546 nl80211_send_sched_scan(rdev
, dev
,
5547 NL80211_CMD_START_SCHED_SCAN
);
5554 mutex_unlock(&rdev
->sched_scan_mtx
);
5558 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5559 struct genl_info
*info
)
5561 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5564 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5565 !rdev
->ops
->sched_scan_stop
)
5568 mutex_lock(&rdev
->sched_scan_mtx
);
5569 err
= __cfg80211_stop_sched_scan(rdev
, false);
5570 mutex_unlock(&rdev
->sched_scan_mtx
);
5575 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5576 struct genl_info
*info
)
5578 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5579 struct net_device
*dev
= info
->user_ptr
[1];
5580 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5581 struct cfg80211_chan_def chandef
;
5584 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5588 if (wdev
->cac_started
)
5591 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5598 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5601 if (!rdev
->ops
->start_radar_detection
)
5604 mutex_lock(&rdev
->devlist_mtx
);
5605 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5606 chandef
.chan
, CHAN_MODE_SHARED
,
5607 BIT(chandef
.width
));
5611 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5613 wdev
->channel
= chandef
.chan
;
5614 wdev
->cac_started
= true;
5615 wdev
->cac_start_time
= jiffies
;
5618 mutex_unlock(&rdev
->devlist_mtx
);
5623 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5625 struct cfg80211_registered_device
*rdev
,
5626 struct wireless_dev
*wdev
,
5627 struct cfg80211_internal_bss
*intbss
)
5629 struct cfg80211_bss
*res
= &intbss
->pub
;
5630 const struct cfg80211_bss_ies
*ies
;
5635 ASSERT_WDEV_LOCK(wdev
);
5637 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5638 NL80211_CMD_NEW_SCAN_RESULTS
);
5642 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5644 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5645 goto nla_put_failure
;
5647 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5648 goto nla_put_failure
;
5649 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5650 goto nla_put_failure
;
5652 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5654 goto nla_put_failure
;
5655 if ((!is_zero_ether_addr(res
->bssid
) &&
5656 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5657 goto nla_put_failure
;
5660 ies
= rcu_dereference(res
->ies
);
5662 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5663 goto fail_unlock_rcu
;
5665 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5666 ies
->len
, ies
->data
))
5667 goto fail_unlock_rcu
;
5669 ies
= rcu_dereference(res
->beacon_ies
);
5671 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5672 goto fail_unlock_rcu
;
5673 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5674 ies
->len
, ies
->data
))
5675 goto fail_unlock_rcu
;
5679 if (res
->beacon_interval
&&
5680 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5681 goto nla_put_failure
;
5682 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5683 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5684 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5685 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5686 goto nla_put_failure
;
5688 switch (rdev
->wiphy
.signal_type
) {
5689 case CFG80211_SIGNAL_TYPE_MBM
:
5690 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5691 goto nla_put_failure
;
5693 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5694 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5695 goto nla_put_failure
;
5701 switch (wdev
->iftype
) {
5702 case NL80211_IFTYPE_P2P_CLIENT
:
5703 case NL80211_IFTYPE_STATION
:
5704 if (intbss
== wdev
->current_bss
&&
5705 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5706 NL80211_BSS_STATUS_ASSOCIATED
))
5707 goto nla_put_failure
;
5709 case NL80211_IFTYPE_ADHOC
:
5710 if (intbss
== wdev
->current_bss
&&
5711 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5712 NL80211_BSS_STATUS_IBSS_JOINED
))
5713 goto nla_put_failure
;
5719 nla_nest_end(msg
, bss
);
5721 return genlmsg_end(msg
, hdr
);
5726 genlmsg_cancel(msg
, hdr
);
5730 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5732 struct cfg80211_registered_device
*rdev
;
5733 struct cfg80211_internal_bss
*scan
;
5734 struct wireless_dev
*wdev
;
5735 int start
= cb
->args
[2], idx
= 0;
5738 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5743 spin_lock_bh(&rdev
->bss_lock
);
5744 cfg80211_bss_expire(rdev
);
5746 cb
->seq
= rdev
->bss_generation
;
5748 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5751 if (nl80211_send_bss(skb
, cb
,
5752 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5753 rdev
, wdev
, scan
) < 0) {
5759 spin_unlock_bh(&rdev
->bss_lock
);
5763 nl80211_finish_wdev_dump(rdev
);
5768 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5769 int flags
, struct net_device
*dev
,
5770 struct survey_info
*survey
)
5773 struct nlattr
*infoattr
;
5775 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5776 NL80211_CMD_NEW_SURVEY_RESULTS
);
5780 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5781 goto nla_put_failure
;
5783 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5785 goto nla_put_failure
;
5787 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5788 survey
->channel
->center_freq
))
5789 goto nla_put_failure
;
5791 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5792 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5793 goto nla_put_failure
;
5794 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5795 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5796 goto nla_put_failure
;
5797 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5798 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5799 survey
->channel_time
))
5800 goto nla_put_failure
;
5801 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5802 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5803 survey
->channel_time_busy
))
5804 goto nla_put_failure
;
5805 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5806 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5807 survey
->channel_time_ext_busy
))
5808 goto nla_put_failure
;
5809 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5810 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5811 survey
->channel_time_rx
))
5812 goto nla_put_failure
;
5813 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5814 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5815 survey
->channel_time_tx
))
5816 goto nla_put_failure
;
5818 nla_nest_end(msg
, infoattr
);
5820 return genlmsg_end(msg
, hdr
);
5823 genlmsg_cancel(msg
, hdr
);
5827 static int nl80211_dump_survey(struct sk_buff
*skb
,
5828 struct netlink_callback
*cb
)
5830 struct survey_info survey
;
5831 struct cfg80211_registered_device
*dev
;
5832 struct wireless_dev
*wdev
;
5833 int survey_idx
= cb
->args
[2];
5836 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5840 if (!wdev
->netdev
) {
5845 if (!dev
->ops
->dump_survey
) {
5851 struct ieee80211_channel
*chan
;
5853 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5859 /* Survey without a channel doesn't make sense */
5860 if (!survey
.channel
) {
5865 chan
= ieee80211_get_channel(&dev
->wiphy
,
5866 survey
.channel
->center_freq
);
5867 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5872 if (nl80211_send_survey(skb
,
5873 NETLINK_CB(cb
->skb
).portid
,
5874 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5875 wdev
->netdev
, &survey
) < 0)
5881 cb
->args
[2] = survey_idx
;
5884 nl80211_finish_wdev_dump(dev
);
5888 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5890 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5891 NL80211_WPA_VERSION_2
));
5894 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5896 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5897 struct net_device
*dev
= info
->user_ptr
[1];
5898 struct ieee80211_channel
*chan
;
5899 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5900 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5901 enum nl80211_auth_type auth_type
;
5902 struct key_parse key
;
5903 bool local_state_change
;
5905 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5908 if (!info
->attrs
[NL80211_ATTR_MAC
])
5911 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5914 if (!info
->attrs
[NL80211_ATTR_SSID
])
5917 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5920 err
= nl80211_parse_key(info
, &key
);
5925 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5927 if (!key
.p
.key
|| !key
.p
.key_len
)
5929 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5930 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5931 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5932 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5944 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5945 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5954 if (!rdev
->ops
->auth
)
5957 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5958 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5961 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5962 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5963 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5964 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5967 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5968 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5970 if (info
->attrs
[NL80211_ATTR_IE
]) {
5971 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5972 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5975 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5976 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5979 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5980 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5983 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5984 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5986 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5987 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5988 /* need to include at least Auth Transaction and Status Code */
5989 if (sae_data_len
< 4)
5993 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5996 * Since we no longer track auth state, ignore
5997 * requests to only change local state.
5999 if (local_state_change
)
6002 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
6003 ssid
, ssid_len
, ie
, ie_len
,
6004 key
.p
.key
, key
.p
.key_len
, key
.idx
,
6005 sae_data
, sae_data_len
);
6008 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
6009 struct genl_info
*info
,
6010 struct cfg80211_crypto_settings
*settings
,
6013 memset(settings
, 0, sizeof(*settings
));
6015 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6017 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6019 proto
= nla_get_u16(
6020 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6021 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6022 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6025 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6026 settings
->control_port_no_encrypt
= true;
6028 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6030 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6034 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6035 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6036 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6038 if (len
% sizeof(u32
))
6041 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6044 memcpy(settings
->ciphers_pairwise
, data
, len
);
6046 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6047 if (!cfg80211_supported_cipher_suite(
6049 settings
->ciphers_pairwise
[i
]))
6053 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6054 settings
->cipher_group
=
6055 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6056 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6057 settings
->cipher_group
))
6061 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6062 settings
->wpa_versions
=
6063 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6064 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6068 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6072 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6073 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6074 settings
->n_akm_suites
= len
/ sizeof(u32
);
6076 if (len
% sizeof(u32
))
6079 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6082 memcpy(settings
->akm_suites
, data
, len
);
6088 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6090 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6091 struct net_device
*dev
= info
->user_ptr
[1];
6092 struct ieee80211_channel
*chan
;
6093 struct cfg80211_assoc_request req
= {};
6094 const u8
*bssid
, *ssid
;
6095 int err
, ssid_len
= 0;
6097 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6100 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6101 !info
->attrs
[NL80211_ATTR_SSID
] ||
6102 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6105 if (!rdev
->ops
->assoc
)
6108 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6109 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6112 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6114 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6115 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6116 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6119 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6120 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6122 if (info
->attrs
[NL80211_ATTR_IE
]) {
6123 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6124 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6127 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6128 enum nl80211_mfp mfp
=
6129 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6130 if (mfp
== NL80211_MFP_REQUIRED
)
6132 else if (mfp
!= NL80211_MFP_NO
)
6136 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6137 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6139 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6140 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6142 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6143 memcpy(&req
.ht_capa_mask
,
6144 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6145 sizeof(req
.ht_capa_mask
));
6147 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6148 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6150 memcpy(&req
.ht_capa
,
6151 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6152 sizeof(req
.ht_capa
));
6155 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6156 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6158 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6159 memcpy(&req
.vht_capa_mask
,
6160 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6161 sizeof(req
.vht_capa_mask
));
6163 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6164 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6166 memcpy(&req
.vht_capa
,
6167 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6168 sizeof(req
.vht_capa
));
6171 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6173 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6174 ssid
, ssid_len
, &req
);
6179 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6181 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6182 struct net_device
*dev
= info
->user_ptr
[1];
6183 const u8
*ie
= NULL
, *bssid
;
6186 bool local_state_change
;
6188 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6191 if (!info
->attrs
[NL80211_ATTR_MAC
])
6194 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6197 if (!rdev
->ops
->deauth
)
6200 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6201 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6204 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6206 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6207 if (reason_code
== 0) {
6208 /* Reason Code 0 is reserved */
6212 if (info
->attrs
[NL80211_ATTR_IE
]) {
6213 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6214 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6217 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6219 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6220 local_state_change
);
6223 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6225 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6226 struct net_device
*dev
= info
->user_ptr
[1];
6227 const u8
*ie
= NULL
, *bssid
;
6230 bool local_state_change
;
6232 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6235 if (!info
->attrs
[NL80211_ATTR_MAC
])
6238 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6241 if (!rdev
->ops
->disassoc
)
6244 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6245 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6248 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6250 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6251 if (reason_code
== 0) {
6252 /* Reason Code 0 is reserved */
6256 if (info
->attrs
[NL80211_ATTR_IE
]) {
6257 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6258 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6261 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6263 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6264 local_state_change
);
6268 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6269 int mcast_rate
[IEEE80211_NUM_BANDS
],
6272 struct wiphy
*wiphy
= &rdev
->wiphy
;
6276 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6277 struct ieee80211_supported_band
*sband
;
6279 sband
= wiphy
->bands
[band
];
6283 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6284 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6285 mcast_rate
[band
] = i
+ 1;
6295 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6297 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6298 struct net_device
*dev
= info
->user_ptr
[1];
6299 struct cfg80211_ibss_params ibss
;
6300 struct wiphy
*wiphy
;
6301 struct cfg80211_cached_keys
*connkeys
= NULL
;
6304 memset(&ibss
, 0, sizeof(ibss
));
6306 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6309 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6310 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6313 ibss
.beacon_interval
= 100;
6315 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6316 ibss
.beacon_interval
=
6317 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6318 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6322 if (!rdev
->ops
->join_ibss
)
6325 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6328 wiphy
= &rdev
->wiphy
;
6330 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6331 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6333 if (!is_valid_ether_addr(ibss
.bssid
))
6336 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6337 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6339 if (info
->attrs
[NL80211_ATTR_IE
]) {
6340 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6341 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6344 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6348 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6351 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
6353 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
6354 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
6357 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6358 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6360 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6362 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6364 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6365 struct ieee80211_supported_band
*sband
=
6366 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6368 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6374 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6375 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6376 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6379 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6382 connkeys
= nl80211_parse_connkeys(rdev
,
6383 info
->attrs
[NL80211_ATTR_KEYS
],
6385 if (IS_ERR(connkeys
))
6386 return PTR_ERR(connkeys
);
6388 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6396 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6398 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6404 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6406 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6407 struct net_device
*dev
= info
->user_ptr
[1];
6409 if (!rdev
->ops
->leave_ibss
)
6412 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6415 return cfg80211_leave_ibss(rdev
, dev
, false);
6418 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6420 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6421 struct net_device
*dev
= info
->user_ptr
[1];
6422 int mcast_rate
[IEEE80211_NUM_BANDS
];
6426 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6427 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6430 if (!rdev
->ops
->set_mcast_rate
)
6433 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6435 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6438 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6439 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6442 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6447 static struct sk_buff
*
6448 __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device
*rdev
,
6449 int approxlen
, u32 portid
, u32 seq
,
6450 enum nl80211_commands cmd
,
6451 enum nl80211_attrs attr
,
6452 const struct nl80211_vendor_cmd_info
*info
,
6455 struct sk_buff
*skb
;
6457 struct nlattr
*data
;
6459 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6463 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, cmd
);
6469 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6470 goto nla_put_failure
;
6473 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_ID
,
6475 goto nla_put_failure
;
6476 if (nla_put_u32(skb
, NL80211_ATTR_VENDOR_SUBCMD
,
6478 goto nla_put_failure
;
6481 data
= nla_nest_start(skb
, attr
);
6483 ((void **)skb
->cb
)[0] = rdev
;
6484 ((void **)skb
->cb
)[1] = hdr
;
6485 ((void **)skb
->cb
)[2] = data
;
6494 #ifdef CONFIG_NL80211_TESTMODE
6495 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6499 static struct genl_multicast_group nl80211_vendor_mcgrp
= {
6503 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6505 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6508 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6512 if (rdev
->ops
->testmode_cmd
) {
6513 rdev
->cur_cmd_info
= info
;
6514 err
= rdev_testmode_cmd(rdev
,
6515 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6516 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6517 rdev
->cur_cmd_info
= NULL
;
6523 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6524 struct netlink_callback
*cb
)
6526 struct cfg80211_registered_device
*rdev
;
6534 * 0 is a valid index, but not valid for args[0],
6535 * so we need to offset by 1.
6537 phy_idx
= cb
->args
[0] - 1;
6539 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6540 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6545 mutex_lock(&cfg80211_mutex
);
6546 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6547 nl80211_fam
.attrbuf
);
6549 mutex_unlock(&cfg80211_mutex
);
6550 return PTR_ERR(rdev
);
6552 phy_idx
= rdev
->wiphy_idx
;
6554 mutex_unlock(&cfg80211_mutex
);
6556 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6558 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6562 data
= nla_data((void *)cb
->args
[1]);
6563 data_len
= nla_len((void *)cb
->args
[1]);
6566 mutex_lock(&cfg80211_mutex
);
6567 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6569 mutex_unlock(&cfg80211_mutex
);
6572 cfg80211_lock_rdev(rdev
);
6573 mutex_unlock(&cfg80211_mutex
);
6575 if (!rdev
->ops
->testmode_dump
) {
6581 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6582 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6583 NL80211_CMD_TESTMODE
);
6584 struct nlattr
*tmdata
;
6589 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6590 genlmsg_cancel(skb
, hdr
);
6594 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6596 genlmsg_cancel(skb
, hdr
);
6599 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6600 nla_nest_end(skb
, tmdata
);
6602 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6603 genlmsg_cancel(skb
, hdr
);
6606 genlmsg_cancel(skb
, hdr
);
6610 genlmsg_end(skb
, hdr
);
6615 cb
->args
[0] = phy_idx
+ 1;
6617 cfg80211_unlock_rdev(rdev
);
6621 struct sk_buff
*__cfg80211_alloc_event_skb(struct wiphy
*wiphy
,
6622 enum nl80211_commands cmd
,
6623 enum nl80211_attrs attr
,
6624 int vendor_event_idx
,
6625 int approxlen
, gfp_t gfp
)
6627 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6628 const struct nl80211_vendor_cmd_info
*info
;
6631 case NL80211_CMD_TESTMODE
:
6632 if (WARN_ON(vendor_event_idx
!= -1))
6636 case NL80211_CMD_VENDOR
:
6637 if (WARN_ON(vendor_event_idx
< 0 ||
6638 vendor_event_idx
>= wiphy
->n_vendor_events
))
6640 info
= &wiphy
->vendor_events
[vendor_event_idx
];
6646 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
, 0, 0,
6647 cmd
, attr
, info
, gfp
);
6649 EXPORT_SYMBOL(__cfg80211_alloc_event_skb
);
6651 void __cfg80211_send_event_skb(struct sk_buff
*skb
, gfp_t gfp
)
6653 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6654 void *hdr
= ((void **)skb
->cb
)[1];
6655 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6657 /* clear CB data for netlink core to own from now on */
6658 memset(skb
->cb
, 0, sizeof(skb
->cb
));
6660 nla_nest_end(skb
, data
);
6661 genlmsg_end(skb
, hdr
);
6663 if (data
->nla_type
== NL80211_ATTR_VENDOR_DATA
)
6664 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6665 nl80211_vendor_mcgrp
.id
, gfp
);
6667 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6668 nl80211_testmode_mcgrp
.id
, gfp
);
6670 EXPORT_SYMBOL(__cfg80211_send_event_skb
);
6673 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6675 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6676 struct net_device
*dev
= info
->user_ptr
[1];
6677 struct cfg80211_connect_params connect
;
6678 struct wiphy
*wiphy
;
6679 struct cfg80211_cached_keys
*connkeys
= NULL
;
6682 memset(&connect
, 0, sizeof(connect
));
6684 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6687 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6688 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6691 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6693 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6694 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6695 NL80211_CMD_CONNECT
))
6698 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6700 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6702 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6703 NL80211_MAX_NR_CIPHER_SUITES
);
6707 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6708 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6711 wiphy
= &rdev
->wiphy
;
6713 connect
.bg_scan_period
= -1;
6714 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6715 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6716 connect
.bg_scan_period
=
6717 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6720 if (info
->attrs
[NL80211_ATTR_MAC
])
6721 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6722 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6723 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6725 if (info
->attrs
[NL80211_ATTR_IE
]) {
6726 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6727 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6730 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6731 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6732 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6733 connect
.mfp
!= NL80211_MFP_NO
)
6736 connect
.mfp
= NL80211_MFP_NO
;
6739 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6741 ieee80211_get_channel(wiphy
,
6742 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6743 if (!connect
.channel
||
6744 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6748 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6749 connkeys
= nl80211_parse_connkeys(rdev
,
6750 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6751 if (IS_ERR(connkeys
))
6752 return PTR_ERR(connkeys
);
6755 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6756 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6758 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6759 memcpy(&connect
.ht_capa_mask
,
6760 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6761 sizeof(connect
.ht_capa_mask
));
6763 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6764 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6768 memcpy(&connect
.ht_capa
,
6769 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6770 sizeof(connect
.ht_capa
));
6773 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6774 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6776 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6777 memcpy(&connect
.vht_capa_mask
,
6778 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6779 sizeof(connect
.vht_capa_mask
));
6781 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6782 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6786 memcpy(&connect
.vht_capa
,
6787 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6788 sizeof(connect
.vht_capa
));
6791 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
6797 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6799 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6800 struct net_device
*dev
= info
->user_ptr
[1];
6803 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6804 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6806 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6811 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6812 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6815 return cfg80211_disconnect(rdev
, dev
, reason
, true);
6818 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6820 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6825 if (!info
->attrs
[NL80211_ATTR_PID
])
6828 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6830 net
= get_net_ns_by_pid(pid
);
6832 return PTR_ERR(net
);
6836 /* check if anything to do */
6837 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6838 err
= cfg80211_switch_netns(rdev
, net
);
6844 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6846 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6847 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6848 struct cfg80211_pmksa
*pmksa
) = NULL
;
6849 struct net_device
*dev
= info
->user_ptr
[1];
6850 struct cfg80211_pmksa pmksa
;
6852 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6854 if (!info
->attrs
[NL80211_ATTR_MAC
])
6857 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6860 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6861 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6863 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6864 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6867 switch (info
->genlhdr
->cmd
) {
6868 case NL80211_CMD_SET_PMKSA
:
6869 rdev_ops
= rdev
->ops
->set_pmksa
;
6871 case NL80211_CMD_DEL_PMKSA
:
6872 rdev_ops
= rdev
->ops
->del_pmksa
;
6882 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6885 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6887 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6888 struct net_device
*dev
= info
->user_ptr
[1];
6890 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6891 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6894 if (!rdev
->ops
->flush_pmksa
)
6897 return rdev_flush_pmksa(rdev
, dev
);
6900 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6903 struct net_device
*dev
= info
->user_ptr
[1];
6904 u8 action_code
, dialog_token
;
6908 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6909 !rdev
->ops
->tdls_mgmt
)
6912 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6913 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6914 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6915 !info
->attrs
[NL80211_ATTR_IE
] ||
6916 !info
->attrs
[NL80211_ATTR_MAC
])
6919 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6920 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6921 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6922 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6924 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6925 dialog_token
, status_code
,
6926 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6927 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6930 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6932 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6933 struct net_device
*dev
= info
->user_ptr
[1];
6934 enum nl80211_tdls_operation operation
;
6937 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6938 !rdev
->ops
->tdls_oper
)
6941 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6942 !info
->attrs
[NL80211_ATTR_MAC
])
6945 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6946 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6948 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6951 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6952 struct genl_info
*info
)
6954 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6955 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6956 struct cfg80211_chan_def chandef
;
6957 struct sk_buff
*msg
;
6963 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6964 !info
->attrs
[NL80211_ATTR_DURATION
])
6967 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6969 if (!rdev
->ops
->remain_on_channel
||
6970 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6974 * We should be on that channel for at least a minimum amount of
6975 * time (10ms) but no longer than the driver supports.
6977 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6978 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6981 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6985 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6989 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6990 NL80211_CMD_REMAIN_ON_CHANNEL
);
6996 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
7002 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7003 goto nla_put_failure
;
7005 genlmsg_end(msg
, hdr
);
7007 return genlmsg_reply(msg
, info
);
7016 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7017 struct genl_info
*info
)
7019 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7020 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7023 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7026 if (!rdev
->ops
->cancel_remain_on_channel
)
7029 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7031 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7034 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7035 u8
*rates
, u8 rates_len
)
7040 for (i
= 0; i
< rates_len
; i
++) {
7041 int rate
= (rates
[i
] & 0x7f) * 5;
7043 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7044 struct ieee80211_rate
*srate
=
7045 &sband
->bitrates
[ridx
];
7046 if (rate
== srate
->bitrate
) {
7051 if (ridx
== sband
->n_bitrates
)
7052 return 0; /* rate not found */
7058 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7059 u8
*rates
, u8 rates_len
,
7060 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7064 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7066 for (i
= 0; i
< rates_len
; i
++) {
7069 ridx
= rates
[i
] / 8;
7070 rbit
= BIT(rates
[i
] % 8);
7072 /* check validity */
7073 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7076 /* check availability */
7077 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7086 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7087 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7088 .len
= NL80211_MAX_SUPP_RATES
},
7089 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7090 .len
= NL80211_MAX_SUPP_HT_RATES
},
7093 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7094 struct genl_info
*info
)
7096 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7097 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7098 struct cfg80211_bitrate_mask mask
;
7100 struct net_device
*dev
= info
->user_ptr
[1];
7101 struct nlattr
*tx_rates
;
7102 struct ieee80211_supported_band
*sband
;
7104 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7107 if (!rdev
->ops
->set_bitrate_mask
)
7110 memset(&mask
, 0, sizeof(mask
));
7111 /* Default to all rates enabled */
7112 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7113 sband
= rdev
->wiphy
.bands
[i
];
7114 mask
.control
[i
].legacy
=
7115 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7117 memcpy(mask
.control
[i
].mcs
,
7118 sband
->ht_cap
.mcs
.rx_mask
,
7119 sizeof(mask
.control
[i
].mcs
));
7121 memset(mask
.control
[i
].mcs
, 0,
7122 sizeof(mask
.control
[i
].mcs
));
7126 * The nested attribute uses enum nl80211_band as the index. This maps
7127 * directly to the enum ieee80211_band values used in cfg80211.
7129 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7130 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7132 enum ieee80211_band band
= nla_type(tx_rates
);
7133 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7135 sband
= rdev
->wiphy
.bands
[band
];
7138 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7139 nla_len(tx_rates
), nl80211_txattr_policy
);
7140 if (tb
[NL80211_TXRATE_LEGACY
]) {
7141 mask
.control
[band
].legacy
= rateset_to_mask(
7143 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7144 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7145 if ((mask
.control
[band
].legacy
== 0) &&
7146 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7149 if (tb
[NL80211_TXRATE_MCS
]) {
7150 if (!ht_rateset_to_mask(
7152 nla_data(tb
[NL80211_TXRATE_MCS
]),
7153 nla_len(tb
[NL80211_TXRATE_MCS
]),
7154 mask
.control
[band
].mcs
))
7158 if (mask
.control
[band
].legacy
== 0) {
7159 /* don't allow empty legacy rates if HT
7160 * is not even supported. */
7161 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7164 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7165 if (mask
.control
[band
].mcs
[i
])
7168 /* legacy and mcs rates may not be both empty */
7169 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7174 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7177 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7179 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7180 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7181 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7183 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7186 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7187 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7189 switch (wdev
->iftype
) {
7190 case NL80211_IFTYPE_STATION
:
7191 case NL80211_IFTYPE_ADHOC
:
7192 case NL80211_IFTYPE_P2P_CLIENT
:
7193 case NL80211_IFTYPE_AP
:
7194 case NL80211_IFTYPE_AP_VLAN
:
7195 case NL80211_IFTYPE_MESH_POINT
:
7196 case NL80211_IFTYPE_P2P_GO
:
7197 case NL80211_IFTYPE_P2P_DEVICE
:
7203 /* not much point in registering if we can't reply */
7204 if (!rdev
->ops
->mgmt_tx
)
7207 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7208 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7209 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7212 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7214 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7215 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7216 struct cfg80211_chan_def chandef
;
7220 struct sk_buff
*msg
= NULL
;
7221 unsigned int wait
= 0;
7222 bool offchan
, no_cck
, dont_wait_for_ack
;
7224 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7226 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7229 if (!rdev
->ops
->mgmt_tx
)
7232 switch (wdev
->iftype
) {
7233 case NL80211_IFTYPE_STATION
:
7234 case NL80211_IFTYPE_ADHOC
:
7235 case NL80211_IFTYPE_P2P_CLIENT
:
7236 case NL80211_IFTYPE_AP
:
7237 case NL80211_IFTYPE_AP_VLAN
:
7238 case NL80211_IFTYPE_MESH_POINT
:
7239 case NL80211_IFTYPE_P2P_GO
:
7240 case NL80211_IFTYPE_P2P_DEVICE
:
7246 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7247 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7249 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7252 * We should wait on the channel for at least a minimum amount
7253 * of time (10ms) but no longer than the driver supports.
7255 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7256 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7261 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7263 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7266 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7268 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7272 if (!dont_wait_for_ack
) {
7273 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7277 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7285 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7286 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7287 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7288 no_cck
, dont_wait_for_ack
, &cookie
);
7293 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7294 goto nla_put_failure
;
7296 genlmsg_end(msg
, hdr
);
7297 return genlmsg_reply(msg
, info
);
7309 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7311 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7312 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7315 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7318 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7321 switch (wdev
->iftype
) {
7322 case NL80211_IFTYPE_STATION
:
7323 case NL80211_IFTYPE_ADHOC
:
7324 case NL80211_IFTYPE_P2P_CLIENT
:
7325 case NL80211_IFTYPE_AP
:
7326 case NL80211_IFTYPE_AP_VLAN
:
7327 case NL80211_IFTYPE_P2P_GO
:
7328 case NL80211_IFTYPE_P2P_DEVICE
:
7334 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7336 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7339 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7341 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7342 struct wireless_dev
*wdev
;
7343 struct net_device
*dev
= info
->user_ptr
[1];
7348 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7351 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7353 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7356 wdev
= dev
->ieee80211_ptr
;
7358 if (!rdev
->ops
->set_power_mgmt
)
7361 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7363 if (state
== wdev
->ps
)
7366 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7372 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7374 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7375 enum nl80211_ps_state ps_state
;
7376 struct wireless_dev
*wdev
;
7377 struct net_device
*dev
= info
->user_ptr
[1];
7378 struct sk_buff
*msg
;
7382 wdev
= dev
->ieee80211_ptr
;
7384 if (!rdev
->ops
->set_power_mgmt
)
7387 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7391 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7392 NL80211_CMD_GET_POWER_SAVE
);
7399 ps_state
= NL80211_PS_ENABLED
;
7401 ps_state
= NL80211_PS_DISABLED
;
7403 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7404 goto nla_put_failure
;
7406 genlmsg_end(msg
, hdr
);
7407 return genlmsg_reply(msg
, info
);
7416 static struct nla_policy
7417 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7418 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7419 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7420 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7421 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7422 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7423 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7426 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7427 u32 rate
, u32 pkts
, u32 intvl
)
7429 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7430 struct wireless_dev
*wdev
;
7431 struct net_device
*dev
= info
->user_ptr
[1];
7433 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7436 wdev
= dev
->ieee80211_ptr
;
7438 if (!rdev
->ops
->set_cqm_txe_config
)
7441 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7442 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7445 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7448 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7449 s32 threshold
, u32 hysteresis
)
7451 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7452 struct wireless_dev
*wdev
;
7453 struct net_device
*dev
= info
->user_ptr
[1];
7458 wdev
= dev
->ieee80211_ptr
;
7460 if (!rdev
->ops
->set_cqm_rssi_config
)
7463 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7464 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7467 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7470 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7472 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7476 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7482 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7483 nl80211_attr_cqm_policy
);
7487 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7488 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7491 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7492 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7493 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7494 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7495 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7496 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7497 u32 rate
, pkts
, intvl
;
7498 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7499 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7500 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7501 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7509 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7511 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7512 struct net_device
*dev
= info
->user_ptr
[1];
7513 struct mesh_config cfg
;
7514 struct mesh_setup setup
;
7517 /* start with default */
7518 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7519 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7521 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7522 /* and parse parameters if given */
7523 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7528 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7529 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7532 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7533 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7535 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7536 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7537 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7540 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7541 setup
.beacon_interval
=
7542 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7543 if (setup
.beacon_interval
< 10 ||
7544 setup
.beacon_interval
> 10000)
7548 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7550 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7551 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7555 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7556 /* parse additional setup parameters if given */
7557 err
= nl80211_parse_mesh_setup(info
, &setup
);
7563 cfg
.auto_open_plinks
= false;
7565 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7566 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7570 /* cfg80211_join_mesh() will sort it out */
7571 setup
.chandef
.chan
= NULL
;
7574 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7577 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7579 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7580 struct net_device
*dev
= info
->user_ptr
[1];
7582 return cfg80211_leave_mesh(rdev
, dev
);
7586 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7587 struct cfg80211_registered_device
*rdev
)
7589 struct nlattr
*nl_pats
, *nl_pat
;
7592 if (!rdev
->wowlan
->n_patterns
)
7595 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7599 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
7600 nl_pat
= nla_nest_start(msg
, i
+ 1);
7603 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
7604 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7605 DIV_ROUND_UP(pat_len
, 8),
7606 rdev
->wowlan
->patterns
[i
].mask
) ||
7607 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7608 pat_len
, rdev
->wowlan
->patterns
[i
].pattern
) ||
7609 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7610 rdev
->wowlan
->patterns
[i
].pkt_offset
))
7612 nla_nest_end(msg
, nl_pat
);
7614 nla_nest_end(msg
, nl_pats
);
7619 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7620 struct cfg80211_wowlan_tcp
*tcp
)
7622 struct nlattr
*nl_tcp
;
7627 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7631 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7632 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7633 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7634 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7635 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7636 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7637 tcp
->payload_len
, tcp
->payload
) ||
7638 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7639 tcp
->data_interval
) ||
7640 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7641 tcp
->wake_len
, tcp
->wake_data
) ||
7642 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7643 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7646 if (tcp
->payload_seq
.len
&&
7647 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7648 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7651 if (tcp
->payload_tok
.len
&&
7652 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7653 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7657 nla_nest_end(msg
, nl_tcp
);
7662 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7664 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7665 struct sk_buff
*msg
;
7667 u32 size
= NLMSG_DEFAULT_SIZE
;
7669 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7670 !rdev
->wiphy
.wowlan
.tcp
)
7673 if (rdev
->wowlan
&& rdev
->wowlan
->tcp
) {
7674 /* adjust size to have room for all the data */
7675 size
+= rdev
->wowlan
->tcp
->tokens_size
+
7676 rdev
->wowlan
->tcp
->payload_len
+
7677 rdev
->wowlan
->tcp
->wake_len
+
7678 rdev
->wowlan
->tcp
->wake_len
/ 8;
7681 msg
= nlmsg_new(size
, GFP_KERNEL
);
7685 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7686 NL80211_CMD_GET_WOWLAN
);
7688 goto nla_put_failure
;
7691 struct nlattr
*nl_wowlan
;
7693 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7695 goto nla_put_failure
;
7697 if ((rdev
->wowlan
->any
&&
7698 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7699 (rdev
->wowlan
->disconnect
&&
7700 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7701 (rdev
->wowlan
->magic_pkt
&&
7702 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7703 (rdev
->wowlan
->gtk_rekey_failure
&&
7704 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7705 (rdev
->wowlan
->eap_identity_req
&&
7706 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7707 (rdev
->wowlan
->four_way_handshake
&&
7708 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7709 (rdev
->wowlan
->rfkill_release
&&
7710 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7711 goto nla_put_failure
;
7713 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7714 goto nla_put_failure
;
7716 if (nl80211_send_wowlan_tcp(msg
, rdev
->wowlan
->tcp
))
7717 goto nla_put_failure
;
7719 nla_nest_end(msg
, nl_wowlan
);
7722 genlmsg_end(msg
, hdr
);
7723 return genlmsg_reply(msg
, info
);
7730 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7731 struct nlattr
*attr
,
7732 struct cfg80211_wowlan
*trig
)
7734 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7735 struct cfg80211_wowlan_tcp
*cfg
;
7736 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7737 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7739 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7742 if (!rdev
->wiphy
.wowlan
.tcp
)
7745 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7746 nla_data(attr
), nla_len(attr
),
7747 nl80211_wowlan_tcp_policy
);
7751 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7752 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7753 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7754 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7755 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7756 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7757 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7758 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7761 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7762 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7765 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7766 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
||
7767 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7770 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7771 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7774 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7775 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7778 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7779 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7781 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7782 tokens_size
= tokln
- sizeof(*tok
);
7784 if (!tok
->len
|| tokens_size
% tok
->len
)
7786 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7788 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7790 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7792 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7794 if (tok
->offset
+ tok
->len
> data_size
)
7798 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7799 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7800 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7802 if (seq
->len
== 0 || seq
->len
> 4)
7804 if (seq
->len
+ seq
->offset
> data_size
)
7808 size
= sizeof(*cfg
);
7810 size
+= wake_size
+ wake_mask_size
;
7811 size
+= tokens_size
;
7813 cfg
= kzalloc(size
, GFP_KERNEL
);
7816 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7817 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7818 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7820 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7821 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7825 /* allocate a socket and port for it and use it */
7826 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7827 IPPROTO_TCP
, &cfg
->sock
, 1);
7832 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7833 sock_release(cfg
->sock
);
7837 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7843 cfg
->src_port
= port
;
7846 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7847 cfg
->payload_len
= data_size
;
7848 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7849 memcpy((void *)cfg
->payload
,
7850 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7853 cfg
->payload_seq
= *seq
;
7854 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7855 cfg
->wake_len
= wake_size
;
7856 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7857 memcpy((void *)cfg
->wake_data
,
7858 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7860 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7861 data_size
+ wake_size
;
7862 memcpy((void *)cfg
->wake_mask
,
7863 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7866 cfg
->tokens_size
= tokens_size
;
7867 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7875 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7877 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7878 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7879 struct cfg80211_wowlan new_triggers
= {};
7880 struct cfg80211_wowlan
*ntrig
;
7881 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7883 bool prev_enabled
= rdev
->wowlan
;
7885 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7886 !rdev
->wiphy
.wowlan
.tcp
)
7889 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7890 cfg80211_rdev_free_wowlan(rdev
);
7891 rdev
->wowlan
= NULL
;
7895 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7896 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7897 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7898 nl80211_wowlan_policy
);
7902 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7903 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7905 new_triggers
.any
= true;
7908 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7909 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7911 new_triggers
.disconnect
= true;
7914 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7915 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7917 new_triggers
.magic_pkt
= true;
7920 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7923 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7924 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7926 new_triggers
.gtk_rekey_failure
= true;
7929 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7930 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7932 new_triggers
.eap_identity_req
= true;
7935 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7936 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7938 new_triggers
.four_way_handshake
= true;
7941 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7942 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7944 new_triggers
.rfkill_release
= true;
7947 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7950 int rem
, pat_len
, mask_len
, pkt_offset
;
7951 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7953 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7956 if (n_patterns
> wowlan
->n_patterns
)
7959 new_triggers
.patterns
= kcalloc(n_patterns
,
7960 sizeof(new_triggers
.patterns
[0]),
7962 if (!new_triggers
.patterns
)
7965 new_triggers
.n_patterns
= n_patterns
;
7968 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7970 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7971 nla_data(pat
), nla_len(pat
), NULL
);
7973 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7974 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7976 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7977 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7978 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7981 if (pat_len
> wowlan
->pattern_max_len
||
7982 pat_len
< wowlan
->pattern_min_len
)
7985 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7988 pkt_offset
= nla_get_u32(
7989 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7990 if (pkt_offset
> wowlan
->max_pkt_offset
)
7992 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7994 new_triggers
.patterns
[i
].mask
=
7995 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7996 if (!new_triggers
.patterns
[i
].mask
) {
8000 new_triggers
.patterns
[i
].pattern
=
8001 new_triggers
.patterns
[i
].mask
+ mask_len
;
8002 memcpy(new_triggers
.patterns
[i
].mask
,
8003 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
8005 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
8006 memcpy(new_triggers
.patterns
[i
].pattern
,
8007 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
8013 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8014 err
= nl80211_parse_wowlan_tcp(
8015 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8021 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8026 cfg80211_rdev_free_wowlan(rdev
);
8027 rdev
->wowlan
= ntrig
;
8030 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
8031 rdev_set_wakeup(rdev
, rdev
->wowlan
);
8035 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8036 kfree(new_triggers
.patterns
[i
].mask
);
8037 kfree(new_triggers
.patterns
);
8038 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8039 sock_release(new_triggers
.tcp
->sock
);
8040 kfree(new_triggers
.tcp
);
8045 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8047 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8048 struct net_device
*dev
= info
->user_ptr
[1];
8049 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8050 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8051 struct cfg80211_gtk_rekey_data rekey_data
;
8054 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8057 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8058 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8059 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8060 nl80211_rekey_policy
);
8064 if (!tb
[NL80211_REKEY_DATA_REPLAY_CTR
] || !tb
[NL80211_REKEY_DATA_KEK
] ||
8065 !tb
[NL80211_REKEY_DATA_KCK
])
8067 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8069 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8071 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8074 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8076 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8078 memcpy(rekey_data
.replay_ctr
,
8079 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8080 NL80211_REPLAY_CTR_LEN
);
8083 if (!wdev
->current_bss
) {
8088 if (!rdev
->ops
->set_rekey_data
) {
8093 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8099 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8100 struct genl_info
*info
)
8102 struct net_device
*dev
= info
->user_ptr
[1];
8103 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8105 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8106 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8109 if (wdev
->ap_unexpected_nlportid
)
8112 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8116 static int nl80211_probe_client(struct sk_buff
*skb
,
8117 struct genl_info
*info
)
8119 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8120 struct net_device
*dev
= info
->user_ptr
[1];
8121 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8122 struct sk_buff
*msg
;
8128 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8129 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8132 if (!info
->attrs
[NL80211_ATTR_MAC
])
8135 if (!rdev
->ops
->probe_client
)
8138 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8142 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8143 NL80211_CMD_PROBE_CLIENT
);
8149 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8151 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8155 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8156 goto nla_put_failure
;
8158 genlmsg_end(msg
, hdr
);
8160 return genlmsg_reply(msg
, info
);
8169 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8171 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8172 struct cfg80211_beacon_registration
*reg
, *nreg
;
8175 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8178 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8182 /* First, check if already registered. */
8183 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8184 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8185 if (reg
->nlportid
== info
->snd_portid
) {
8190 /* Add it to the list */
8191 nreg
->nlportid
= info
->snd_portid
;
8192 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8194 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8198 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8203 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8205 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8206 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8209 if (!rdev
->ops
->start_p2p_device
)
8212 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8215 if (wdev
->p2p_started
)
8218 mutex_lock(&rdev
->devlist_mtx
);
8219 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8220 mutex_unlock(&rdev
->devlist_mtx
);
8224 err
= rdev_start_p2p_device(rdev
, wdev
);
8228 wdev
->p2p_started
= true;
8229 mutex_lock(&rdev
->devlist_mtx
);
8231 mutex_unlock(&rdev
->devlist_mtx
);
8236 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8238 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8239 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8241 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8244 if (!rdev
->ops
->stop_p2p_device
)
8247 mutex_lock(&rdev
->devlist_mtx
);
8248 mutex_lock(&rdev
->sched_scan_mtx
);
8249 cfg80211_stop_p2p_device(rdev
, wdev
);
8250 mutex_unlock(&rdev
->sched_scan_mtx
);
8251 mutex_unlock(&rdev
->devlist_mtx
);
8256 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8257 struct genl_info
*info
)
8260 struct sk_buff
*msg
;
8262 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8266 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8267 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8269 goto nla_put_failure
;
8271 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8272 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8273 goto nla_put_failure
;
8275 genlmsg_end(msg
, hdr
);
8276 return genlmsg_reply(msg
, info
);
8283 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8285 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8286 struct cfg80211_update_ft_ies_params ft_params
;
8287 struct net_device
*dev
= info
->user_ptr
[1];
8289 if (!rdev
->ops
->update_ft_ies
)
8292 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8293 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8296 memset(&ft_params
, 0, sizeof(ft_params
));
8297 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8298 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8299 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8301 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8304 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8305 struct genl_info
*info
)
8307 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8308 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8309 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8313 if (!rdev
->ops
->crit_proto_start
)
8316 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8319 if (rdev
->crit_proto_nlportid
)
8322 /* determine protocol if provided */
8323 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8324 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8326 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8329 /* timeout must be provided */
8330 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8334 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8336 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8339 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8341 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8346 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8347 struct genl_info
*info
)
8349 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8350 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8352 if (!rdev
->ops
->crit_proto_stop
)
8355 if (rdev
->crit_proto_nlportid
) {
8356 rdev
->crit_proto_nlportid
= 0;
8357 rdev_crit_proto_stop(rdev
, wdev
);
8362 static int nl80211_vendor_cmd(struct sk_buff
*skb
, struct genl_info
*info
)
8364 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8365 struct wireless_dev
*wdev
=
8366 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
8370 if (!rdev
|| !rdev
->wiphy
.vendor_commands
)
8374 err
= PTR_ERR(wdev
);
8378 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
8382 if (!info
->attrs
[NL80211_ATTR_VENDOR_ID
] ||
8383 !info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
])
8386 vid
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_ID
]);
8387 subcmd
= nla_get_u32(info
->attrs
[NL80211_ATTR_VENDOR_SUBCMD
]);
8388 for (i
= 0; i
< rdev
->wiphy
.n_vendor_commands
; i
++) {
8389 const struct wiphy_vendor_command
*vcmd
;
8393 vcmd
= &rdev
->wiphy
.vendor_commands
[i
];
8395 if (vcmd
->info
.vendor_id
!= vid
|| vcmd
->info
.subcmd
!= subcmd
)
8398 if (vcmd
->flags
& (WIPHY_VENDOR_CMD_NEED_WDEV
|
8399 WIPHY_VENDOR_CMD_NEED_NETDEV
)) {
8402 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_NETDEV
&&
8406 if (vcmd
->flags
& WIPHY_VENDOR_CMD_NEED_RUNNING
) {
8407 if (!wdev
->netdev
||
8408 !netif_running(wdev
->netdev
))
8415 if (info
->attrs
[NL80211_ATTR_VENDOR_DATA
]) {
8416 data
= nla_data(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8417 len
= nla_len(info
->attrs
[NL80211_ATTR_VENDOR_DATA
]);
8420 rdev
->cur_cmd_info
= info
;
8421 err
= rdev
->wiphy
.vendor_commands
[i
].doit(&rdev
->wiphy
, wdev
,
8423 rdev
->cur_cmd_info
= NULL
;
8430 struct sk_buff
*__cfg80211_alloc_reply_skb(struct wiphy
*wiphy
,
8431 enum nl80211_commands cmd
,
8432 enum nl80211_attrs attr
,
8435 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8437 if (WARN_ON(!rdev
->cur_cmd_info
))
8440 return __cfg80211_alloc_vendor_skb(rdev
, approxlen
,
8443 cmd
, attr
, NULL
, GFP_KERNEL
);
8445 EXPORT_SYMBOL(__cfg80211_alloc_reply_skb
);
8447 int cfg80211_vendor_cmd_reply(struct sk_buff
*skb
)
8449 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
8450 void *hdr
= ((void **)skb
->cb
)[1];
8451 struct nlattr
*data
= ((void **)skb
->cb
)[2];
8453 if (WARN_ON(!rdev
->cur_cmd_info
)) {
8458 nla_nest_end(skb
, data
);
8459 genlmsg_end(skb
, hdr
);
8460 return genlmsg_reply(skb
, rdev
->cur_cmd_info
);
8462 EXPORT_SYMBOL(cfg80211_vendor_cmd_reply
);
8464 #define NL80211_FLAG_NEED_WIPHY 0x01
8465 #define NL80211_FLAG_NEED_NETDEV 0x02
8466 #define NL80211_FLAG_NEED_RTNL 0x04
8467 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8468 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8469 NL80211_FLAG_CHECK_NETDEV_UP)
8470 #define NL80211_FLAG_NEED_WDEV 0x10
8471 /* If a netdev is associated, it must be UP, P2P must be started */
8472 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8473 NL80211_FLAG_CHECK_NETDEV_UP)
8475 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8476 struct genl_info
*info
)
8478 struct cfg80211_registered_device
*rdev
;
8479 struct wireless_dev
*wdev
;
8480 struct net_device
*dev
;
8481 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8486 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8487 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8491 return PTR_ERR(rdev
);
8493 info
->user_ptr
[0] = rdev
;
8494 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8495 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8496 mutex_lock(&cfg80211_mutex
);
8497 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8500 mutex_unlock(&cfg80211_mutex
);
8503 return PTR_ERR(wdev
);
8507 rdev
= wiphy_to_dev(wdev
->wiphy
);
8509 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8511 mutex_unlock(&cfg80211_mutex
);
8517 info
->user_ptr
[1] = dev
;
8519 info
->user_ptr
[1] = wdev
;
8523 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8524 !netif_running(dev
)) {
8525 mutex_unlock(&cfg80211_mutex
);
8532 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8533 if (!wdev
->p2p_started
) {
8534 mutex_unlock(&cfg80211_mutex
);
8541 cfg80211_lock_rdev(rdev
);
8543 mutex_unlock(&cfg80211_mutex
);
8545 info
->user_ptr
[0] = rdev
;
8551 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8552 struct genl_info
*info
)
8554 if (info
->user_ptr
[0])
8555 cfg80211_unlock_rdev(info
->user_ptr
[0]);
8556 if (info
->user_ptr
[1]) {
8557 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8558 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8561 dev_put(wdev
->netdev
);
8563 dev_put(info
->user_ptr
[1]);
8566 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8570 static struct genl_ops nl80211_ops
[] = {
8572 .cmd
= NL80211_CMD_GET_WIPHY
,
8573 .doit
= nl80211_get_wiphy
,
8574 .dumpit
= nl80211_dump_wiphy
,
8575 .policy
= nl80211_policy
,
8576 /* can be retrieved by unprivileged users */
8577 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
8580 .cmd
= NL80211_CMD_SET_WIPHY
,
8581 .doit
= nl80211_set_wiphy
,
8582 .policy
= nl80211_policy
,
8583 .flags
= GENL_ADMIN_PERM
,
8584 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8587 .cmd
= NL80211_CMD_GET_INTERFACE
,
8588 .doit
= nl80211_get_interface
,
8589 .dumpit
= nl80211_dump_interface
,
8590 .policy
= nl80211_policy
,
8591 /* can be retrieved by unprivileged users */
8592 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
8595 .cmd
= NL80211_CMD_SET_INTERFACE
,
8596 .doit
= nl80211_set_interface
,
8597 .policy
= nl80211_policy
,
8598 .flags
= GENL_ADMIN_PERM
,
8599 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8600 NL80211_FLAG_NEED_RTNL
,
8603 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8604 .doit
= nl80211_new_interface
,
8605 .policy
= nl80211_policy
,
8606 .flags
= GENL_ADMIN_PERM
,
8607 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8608 NL80211_FLAG_NEED_RTNL
,
8611 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8612 .doit
= nl80211_del_interface
,
8613 .policy
= nl80211_policy
,
8614 .flags
= GENL_ADMIN_PERM
,
8615 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8616 NL80211_FLAG_NEED_RTNL
,
8619 .cmd
= NL80211_CMD_GET_KEY
,
8620 .doit
= nl80211_get_key
,
8621 .policy
= nl80211_policy
,
8622 .flags
= GENL_ADMIN_PERM
,
8623 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8624 NL80211_FLAG_NEED_RTNL
,
8627 .cmd
= NL80211_CMD_SET_KEY
,
8628 .doit
= nl80211_set_key
,
8629 .policy
= nl80211_policy
,
8630 .flags
= GENL_ADMIN_PERM
,
8631 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8632 NL80211_FLAG_NEED_RTNL
,
8635 .cmd
= NL80211_CMD_NEW_KEY
,
8636 .doit
= nl80211_new_key
,
8637 .policy
= nl80211_policy
,
8638 .flags
= GENL_ADMIN_PERM
,
8639 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8640 NL80211_FLAG_NEED_RTNL
,
8643 .cmd
= NL80211_CMD_DEL_KEY
,
8644 .doit
= nl80211_del_key
,
8645 .policy
= nl80211_policy
,
8646 .flags
= GENL_ADMIN_PERM
,
8647 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8648 NL80211_FLAG_NEED_RTNL
,
8651 .cmd
= NL80211_CMD_SET_BEACON
,
8652 .policy
= nl80211_policy
,
8653 .flags
= GENL_ADMIN_PERM
,
8654 .doit
= nl80211_set_beacon
,
8655 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8656 NL80211_FLAG_NEED_RTNL
,
8659 .cmd
= NL80211_CMD_START_AP
,
8660 .policy
= nl80211_policy
,
8661 .flags
= GENL_ADMIN_PERM
,
8662 .doit
= nl80211_start_ap
,
8663 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8664 NL80211_FLAG_NEED_RTNL
,
8667 .cmd
= NL80211_CMD_STOP_AP
,
8668 .policy
= nl80211_policy
,
8669 .flags
= GENL_ADMIN_PERM
,
8670 .doit
= nl80211_stop_ap
,
8671 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8672 NL80211_FLAG_NEED_RTNL
,
8675 .cmd
= NL80211_CMD_GET_STATION
,
8676 .doit
= nl80211_get_station
,
8677 .dumpit
= nl80211_dump_station
,
8678 .policy
= nl80211_policy
,
8679 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8680 NL80211_FLAG_NEED_RTNL
,
8683 .cmd
= NL80211_CMD_SET_STATION
,
8684 .doit
= nl80211_set_station
,
8685 .policy
= nl80211_policy
,
8686 .flags
= GENL_ADMIN_PERM
,
8687 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8688 NL80211_FLAG_NEED_RTNL
,
8691 .cmd
= NL80211_CMD_NEW_STATION
,
8692 .doit
= nl80211_new_station
,
8693 .policy
= nl80211_policy
,
8694 .flags
= GENL_ADMIN_PERM
,
8695 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8696 NL80211_FLAG_NEED_RTNL
,
8699 .cmd
= NL80211_CMD_DEL_STATION
,
8700 .doit
= nl80211_del_station
,
8701 .policy
= nl80211_policy
,
8702 .flags
= GENL_ADMIN_PERM
,
8703 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8704 NL80211_FLAG_NEED_RTNL
,
8707 .cmd
= NL80211_CMD_GET_MPATH
,
8708 .doit
= nl80211_get_mpath
,
8709 .dumpit
= nl80211_dump_mpath
,
8710 .policy
= nl80211_policy
,
8711 .flags
= GENL_ADMIN_PERM
,
8712 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8713 NL80211_FLAG_NEED_RTNL
,
8716 .cmd
= NL80211_CMD_SET_MPATH
,
8717 .doit
= nl80211_set_mpath
,
8718 .policy
= nl80211_policy
,
8719 .flags
= GENL_ADMIN_PERM
,
8720 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8721 NL80211_FLAG_NEED_RTNL
,
8724 .cmd
= NL80211_CMD_NEW_MPATH
,
8725 .doit
= nl80211_new_mpath
,
8726 .policy
= nl80211_policy
,
8727 .flags
= GENL_ADMIN_PERM
,
8728 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8729 NL80211_FLAG_NEED_RTNL
,
8732 .cmd
= NL80211_CMD_DEL_MPATH
,
8733 .doit
= nl80211_del_mpath
,
8734 .policy
= nl80211_policy
,
8735 .flags
= GENL_ADMIN_PERM
,
8736 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8737 NL80211_FLAG_NEED_RTNL
,
8740 .cmd
= NL80211_CMD_SET_BSS
,
8741 .doit
= nl80211_set_bss
,
8742 .policy
= nl80211_policy
,
8743 .flags
= GENL_ADMIN_PERM
,
8744 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8745 NL80211_FLAG_NEED_RTNL
,
8748 .cmd
= NL80211_CMD_GET_REG
,
8749 .doit
= nl80211_get_reg
,
8750 .policy
= nl80211_policy
,
8751 /* can be retrieved by unprivileged users */
8754 .cmd
= NL80211_CMD_SET_REG
,
8755 .doit
= nl80211_set_reg
,
8756 .policy
= nl80211_policy
,
8757 .flags
= GENL_ADMIN_PERM
,
8760 .cmd
= NL80211_CMD_REQ_SET_REG
,
8761 .doit
= nl80211_req_set_reg
,
8762 .policy
= nl80211_policy
,
8763 .flags
= GENL_ADMIN_PERM
,
8766 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8767 .doit
= nl80211_get_mesh_config
,
8768 .policy
= nl80211_policy
,
8769 /* can be retrieved by unprivileged users */
8770 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8771 NL80211_FLAG_NEED_RTNL
,
8774 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8775 .doit
= nl80211_update_mesh_config
,
8776 .policy
= nl80211_policy
,
8777 .flags
= GENL_ADMIN_PERM
,
8778 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8779 NL80211_FLAG_NEED_RTNL
,
8782 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8783 .doit
= nl80211_trigger_scan
,
8784 .policy
= nl80211_policy
,
8785 .flags
= GENL_ADMIN_PERM
,
8786 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8787 NL80211_FLAG_NEED_RTNL
,
8790 .cmd
= NL80211_CMD_GET_SCAN
,
8791 .policy
= nl80211_policy
,
8792 .dumpit
= nl80211_dump_scan
,
8795 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8796 .doit
= nl80211_start_sched_scan
,
8797 .policy
= nl80211_policy
,
8798 .flags
= GENL_ADMIN_PERM
,
8799 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8800 NL80211_FLAG_NEED_RTNL
,
8803 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8804 .doit
= nl80211_stop_sched_scan
,
8805 .policy
= nl80211_policy
,
8806 .flags
= GENL_ADMIN_PERM
,
8807 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8808 NL80211_FLAG_NEED_RTNL
,
8811 .cmd
= NL80211_CMD_AUTHENTICATE
,
8812 .doit
= nl80211_authenticate
,
8813 .policy
= nl80211_policy
,
8814 .flags
= GENL_ADMIN_PERM
,
8815 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8816 NL80211_FLAG_NEED_RTNL
,
8819 .cmd
= NL80211_CMD_ASSOCIATE
,
8820 .doit
= nl80211_associate
,
8821 .policy
= nl80211_policy
,
8822 .flags
= GENL_ADMIN_PERM
,
8823 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8824 NL80211_FLAG_NEED_RTNL
,
8827 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8828 .doit
= nl80211_deauthenticate
,
8829 .policy
= nl80211_policy
,
8830 .flags
= GENL_ADMIN_PERM
,
8831 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8832 NL80211_FLAG_NEED_RTNL
,
8835 .cmd
= NL80211_CMD_DISASSOCIATE
,
8836 .doit
= nl80211_disassociate
,
8837 .policy
= nl80211_policy
,
8838 .flags
= GENL_ADMIN_PERM
,
8839 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8840 NL80211_FLAG_NEED_RTNL
,
8843 .cmd
= NL80211_CMD_JOIN_IBSS
,
8844 .doit
= nl80211_join_ibss
,
8845 .policy
= nl80211_policy
,
8846 .flags
= GENL_ADMIN_PERM
,
8847 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8848 NL80211_FLAG_NEED_RTNL
,
8851 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8852 .doit
= nl80211_leave_ibss
,
8853 .policy
= nl80211_policy
,
8854 .flags
= GENL_ADMIN_PERM
,
8855 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8856 NL80211_FLAG_NEED_RTNL
,
8858 #ifdef CONFIG_NL80211_TESTMODE
8860 .cmd
= NL80211_CMD_TESTMODE
,
8861 .doit
= nl80211_testmode_do
,
8862 .dumpit
= nl80211_testmode_dump
,
8863 .policy
= nl80211_policy
,
8864 .flags
= GENL_ADMIN_PERM
,
8865 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8866 NL80211_FLAG_NEED_RTNL
,
8870 .cmd
= NL80211_CMD_CONNECT
,
8871 .doit
= nl80211_connect
,
8872 .policy
= nl80211_policy
,
8873 .flags
= GENL_ADMIN_PERM
,
8874 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8875 NL80211_FLAG_NEED_RTNL
,
8878 .cmd
= NL80211_CMD_DISCONNECT
,
8879 .doit
= nl80211_disconnect
,
8880 .policy
= nl80211_policy
,
8881 .flags
= GENL_ADMIN_PERM
,
8882 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8883 NL80211_FLAG_NEED_RTNL
,
8886 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8887 .doit
= nl80211_wiphy_netns
,
8888 .policy
= nl80211_policy
,
8889 .flags
= GENL_ADMIN_PERM
,
8890 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8891 NL80211_FLAG_NEED_RTNL
,
8894 .cmd
= NL80211_CMD_GET_SURVEY
,
8895 .policy
= nl80211_policy
,
8896 .dumpit
= nl80211_dump_survey
,
8899 .cmd
= NL80211_CMD_SET_PMKSA
,
8900 .doit
= nl80211_setdel_pmksa
,
8901 .policy
= nl80211_policy
,
8902 .flags
= GENL_ADMIN_PERM
,
8903 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8904 NL80211_FLAG_NEED_RTNL
,
8907 .cmd
= NL80211_CMD_DEL_PMKSA
,
8908 .doit
= nl80211_setdel_pmksa
,
8909 .policy
= nl80211_policy
,
8910 .flags
= GENL_ADMIN_PERM
,
8911 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8912 NL80211_FLAG_NEED_RTNL
,
8915 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8916 .doit
= nl80211_flush_pmksa
,
8917 .policy
= nl80211_policy
,
8918 .flags
= GENL_ADMIN_PERM
,
8919 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8920 NL80211_FLAG_NEED_RTNL
,
8923 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8924 .doit
= nl80211_remain_on_channel
,
8925 .policy
= nl80211_policy
,
8926 .flags
= GENL_ADMIN_PERM
,
8927 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8928 NL80211_FLAG_NEED_RTNL
,
8931 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8932 .doit
= nl80211_cancel_remain_on_channel
,
8933 .policy
= nl80211_policy
,
8934 .flags
= GENL_ADMIN_PERM
,
8935 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8936 NL80211_FLAG_NEED_RTNL
,
8939 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8940 .doit
= nl80211_set_tx_bitrate_mask
,
8941 .policy
= nl80211_policy
,
8942 .flags
= GENL_ADMIN_PERM
,
8943 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8944 NL80211_FLAG_NEED_RTNL
,
8947 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8948 .doit
= nl80211_register_mgmt
,
8949 .policy
= nl80211_policy
,
8950 .flags
= GENL_ADMIN_PERM
,
8951 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8952 NL80211_FLAG_NEED_RTNL
,
8955 .cmd
= NL80211_CMD_FRAME
,
8956 .doit
= nl80211_tx_mgmt
,
8957 .policy
= nl80211_policy
,
8958 .flags
= GENL_ADMIN_PERM
,
8959 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8960 NL80211_FLAG_NEED_RTNL
,
8963 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8964 .doit
= nl80211_tx_mgmt_cancel_wait
,
8965 .policy
= nl80211_policy
,
8966 .flags
= GENL_ADMIN_PERM
,
8967 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8968 NL80211_FLAG_NEED_RTNL
,
8971 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8972 .doit
= nl80211_set_power_save
,
8973 .policy
= nl80211_policy
,
8974 .flags
= GENL_ADMIN_PERM
,
8975 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8976 NL80211_FLAG_NEED_RTNL
,
8979 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8980 .doit
= nl80211_get_power_save
,
8981 .policy
= nl80211_policy
,
8982 /* can be retrieved by unprivileged users */
8983 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8984 NL80211_FLAG_NEED_RTNL
,
8987 .cmd
= NL80211_CMD_SET_CQM
,
8988 .doit
= nl80211_set_cqm
,
8989 .policy
= nl80211_policy
,
8990 .flags
= GENL_ADMIN_PERM
,
8991 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8992 NL80211_FLAG_NEED_RTNL
,
8995 .cmd
= NL80211_CMD_SET_CHANNEL
,
8996 .doit
= nl80211_set_channel
,
8997 .policy
= nl80211_policy
,
8998 .flags
= GENL_ADMIN_PERM
,
8999 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9000 NL80211_FLAG_NEED_RTNL
,
9003 .cmd
= NL80211_CMD_SET_WDS_PEER
,
9004 .doit
= nl80211_set_wds_peer
,
9005 .policy
= nl80211_policy
,
9006 .flags
= GENL_ADMIN_PERM
,
9007 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9008 NL80211_FLAG_NEED_RTNL
,
9011 .cmd
= NL80211_CMD_JOIN_MESH
,
9012 .doit
= nl80211_join_mesh
,
9013 .policy
= nl80211_policy
,
9014 .flags
= GENL_ADMIN_PERM
,
9015 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9016 NL80211_FLAG_NEED_RTNL
,
9019 .cmd
= NL80211_CMD_LEAVE_MESH
,
9020 .doit
= nl80211_leave_mesh
,
9021 .policy
= nl80211_policy
,
9022 .flags
= GENL_ADMIN_PERM
,
9023 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9024 NL80211_FLAG_NEED_RTNL
,
9028 .cmd
= NL80211_CMD_GET_WOWLAN
,
9029 .doit
= nl80211_get_wowlan
,
9030 .policy
= nl80211_policy
,
9031 /* can be retrieved by unprivileged users */
9032 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9033 NL80211_FLAG_NEED_RTNL
,
9036 .cmd
= NL80211_CMD_SET_WOWLAN
,
9037 .doit
= nl80211_set_wowlan
,
9038 .policy
= nl80211_policy
,
9039 .flags
= GENL_ADMIN_PERM
,
9040 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9041 NL80211_FLAG_NEED_RTNL
,
9045 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9046 .doit
= nl80211_set_rekey_data
,
9047 .policy
= nl80211_policy
,
9048 .flags
= GENL_ADMIN_PERM
,
9049 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9050 NL80211_FLAG_NEED_RTNL
,
9053 .cmd
= NL80211_CMD_TDLS_MGMT
,
9054 .doit
= nl80211_tdls_mgmt
,
9055 .policy
= nl80211_policy
,
9056 .flags
= GENL_ADMIN_PERM
,
9057 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9058 NL80211_FLAG_NEED_RTNL
,
9061 .cmd
= NL80211_CMD_TDLS_OPER
,
9062 .doit
= nl80211_tdls_oper
,
9063 .policy
= nl80211_policy
,
9064 .flags
= GENL_ADMIN_PERM
,
9065 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9066 NL80211_FLAG_NEED_RTNL
,
9069 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9070 .doit
= nl80211_register_unexpected_frame
,
9071 .policy
= nl80211_policy
,
9072 .flags
= GENL_ADMIN_PERM
,
9073 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9074 NL80211_FLAG_NEED_RTNL
,
9077 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9078 .doit
= nl80211_probe_client
,
9079 .policy
= nl80211_policy
,
9080 .flags
= GENL_ADMIN_PERM
,
9081 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9082 NL80211_FLAG_NEED_RTNL
,
9085 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9086 .doit
= nl80211_register_beacons
,
9087 .policy
= nl80211_policy
,
9088 .flags
= GENL_ADMIN_PERM
,
9089 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9090 NL80211_FLAG_NEED_RTNL
,
9093 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
9094 .doit
= nl80211_set_noack_map
,
9095 .policy
= nl80211_policy
,
9096 .flags
= GENL_ADMIN_PERM
,
9097 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9098 NL80211_FLAG_NEED_RTNL
,
9101 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
9102 .doit
= nl80211_start_p2p_device
,
9103 .policy
= nl80211_policy
,
9104 .flags
= GENL_ADMIN_PERM
,
9105 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9106 NL80211_FLAG_NEED_RTNL
,
9109 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
9110 .doit
= nl80211_stop_p2p_device
,
9111 .policy
= nl80211_policy
,
9112 .flags
= GENL_ADMIN_PERM
,
9113 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9114 NL80211_FLAG_NEED_RTNL
,
9117 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
9118 .doit
= nl80211_set_mcast_rate
,
9119 .policy
= nl80211_policy
,
9120 .flags
= GENL_ADMIN_PERM
,
9121 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9122 NL80211_FLAG_NEED_RTNL
,
9125 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9126 .doit
= nl80211_set_mac_acl
,
9127 .policy
= nl80211_policy
,
9128 .flags
= GENL_ADMIN_PERM
,
9129 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9130 NL80211_FLAG_NEED_RTNL
,
9133 .cmd
= NL80211_CMD_RADAR_DETECT
,
9134 .doit
= nl80211_start_radar_detection
,
9135 .policy
= nl80211_policy
,
9136 .flags
= GENL_ADMIN_PERM
,
9137 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9138 NL80211_FLAG_NEED_RTNL
,
9141 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9142 .doit
= nl80211_get_protocol_features
,
9143 .policy
= nl80211_policy
,
9146 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9147 .doit
= nl80211_update_ft_ies
,
9148 .policy
= nl80211_policy
,
9149 .flags
= GENL_ADMIN_PERM
,
9150 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9151 NL80211_FLAG_NEED_RTNL
,
9154 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9155 .doit
= nl80211_crit_protocol_start
,
9156 .policy
= nl80211_policy
,
9157 .flags
= GENL_ADMIN_PERM
,
9158 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9159 NL80211_FLAG_NEED_RTNL
,
9162 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9163 .doit
= nl80211_crit_protocol_stop
,
9164 .policy
= nl80211_policy
,
9165 .flags
= GENL_ADMIN_PERM
,
9166 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9167 NL80211_FLAG_NEED_RTNL
,
9170 .cmd
= NL80211_CMD_VENDOR
,
9171 .doit
= nl80211_vendor_cmd
,
9172 .policy
= nl80211_policy
,
9173 .flags
= GENL_ADMIN_PERM
,
9174 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9175 NL80211_FLAG_NEED_RTNL
,
9179 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9183 /* multicast groups */
9184 static struct genl_multicast_group nl80211_config_mcgrp
= {
9187 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9190 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9191 .name
= "regulatory",
9194 /* notification functions */
9196 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9198 struct sk_buff
*msg
;
9200 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9204 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0,
9205 false, NULL
, NULL
, NULL
) < 0) {
9210 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9211 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9214 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9215 struct cfg80211_registered_device
*rdev
)
9217 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9218 struct nlattr
*nest
;
9221 lockdep_assert_held(&rdev
->sched_scan_mtx
);
9226 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9228 goto nla_put_failure
;
9229 for (i
= 0; i
< req
->n_ssids
; i
++) {
9230 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9231 goto nla_put_failure
;
9233 nla_nest_end(msg
, nest
);
9235 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9237 goto nla_put_failure
;
9238 for (i
= 0; i
< req
->n_channels
; i
++) {
9239 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9240 goto nla_put_failure
;
9242 nla_nest_end(msg
, nest
);
9245 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9246 goto nla_put_failure
;
9249 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9256 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9257 struct cfg80211_registered_device
*rdev
,
9258 struct wireless_dev
*wdev
,
9259 u32 portid
, u32 seq
, int flags
,
9264 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9268 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9269 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9270 wdev
->netdev
->ifindex
)) ||
9271 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9272 goto nla_put_failure
;
9274 /* ignore errors and send incomplete event anyway */
9275 nl80211_add_scan_req(msg
, rdev
);
9277 return genlmsg_end(msg
, hdr
);
9280 genlmsg_cancel(msg
, hdr
);
9285 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9286 struct cfg80211_registered_device
*rdev
,
9287 struct net_device
*netdev
,
9288 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9292 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9296 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9297 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9298 goto nla_put_failure
;
9300 return genlmsg_end(msg
, hdr
);
9303 genlmsg_cancel(msg
, hdr
);
9307 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9308 struct wireless_dev
*wdev
)
9310 struct sk_buff
*msg
;
9312 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9316 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9317 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9322 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9323 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9326 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9327 struct wireless_dev
*wdev
)
9329 struct sk_buff
*msg
;
9331 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9335 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9336 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9341 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9342 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9345 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9346 struct wireless_dev
*wdev
)
9348 struct sk_buff
*msg
;
9350 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9354 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9355 NL80211_CMD_SCAN_ABORTED
) < 0) {
9360 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9361 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9364 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9365 struct net_device
*netdev
)
9367 struct sk_buff
*msg
;
9369 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9373 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9374 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9379 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9380 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9383 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9384 struct net_device
*netdev
, u32 cmd
)
9386 struct sk_buff
*msg
;
9388 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9392 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9397 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9398 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9402 * This can happen on global regulatory changes or device specific settings
9403 * based on custom world regulatory domains.
9405 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9407 struct sk_buff
*msg
;
9410 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9414 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9420 /* Userspace can always count this one always being set */
9421 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9422 goto nla_put_failure
;
9424 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9425 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9426 NL80211_REGDOM_TYPE_WORLD
))
9427 goto nla_put_failure
;
9428 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9429 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9430 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9431 goto nla_put_failure
;
9432 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9433 request
->intersect
) {
9434 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9435 NL80211_REGDOM_TYPE_INTERSECTION
))
9436 goto nla_put_failure
;
9438 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9439 NL80211_REGDOM_TYPE_COUNTRY
) ||
9440 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9442 goto nla_put_failure
;
9445 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9446 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9447 goto nla_put_failure
;
9449 genlmsg_end(msg
, hdr
);
9452 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9459 genlmsg_cancel(msg
, hdr
);
9463 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9464 struct net_device
*netdev
,
9465 const u8
*buf
, size_t len
,
9466 enum nl80211_commands cmd
, gfp_t gfp
)
9468 struct sk_buff
*msg
;
9471 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9475 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9481 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9482 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9483 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9484 goto nla_put_failure
;
9486 genlmsg_end(msg
, hdr
);
9488 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9489 nl80211_mlme_mcgrp
.id
, gfp
);
9493 genlmsg_cancel(msg
, hdr
);
9497 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9498 struct net_device
*netdev
, const u8
*buf
,
9499 size_t len
, gfp_t gfp
)
9501 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9502 NL80211_CMD_AUTHENTICATE
, gfp
);
9505 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9506 struct net_device
*netdev
, const u8
*buf
,
9507 size_t len
, gfp_t gfp
)
9509 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9510 NL80211_CMD_ASSOCIATE
, gfp
);
9513 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9514 struct net_device
*netdev
, const u8
*buf
,
9515 size_t len
, gfp_t gfp
)
9517 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9518 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9521 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9522 struct net_device
*netdev
, const u8
*buf
,
9523 size_t len
, gfp_t gfp
)
9525 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9526 NL80211_CMD_DISASSOCIATE
, gfp
);
9529 void cfg80211_send_unprot_deauth(struct net_device
*dev
, const u8
*buf
,
9532 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9533 struct wiphy
*wiphy
= wdev
->wiphy
;
9534 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9536 trace_cfg80211_send_unprot_deauth(dev
);
9537 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9538 NL80211_CMD_UNPROT_DEAUTHENTICATE
, GFP_ATOMIC
);
9540 EXPORT_SYMBOL(cfg80211_send_unprot_deauth
);
9542 void cfg80211_send_unprot_disassoc(struct net_device
*dev
, const u8
*buf
,
9545 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9546 struct wiphy
*wiphy
= wdev
->wiphy
;
9547 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9549 trace_cfg80211_send_unprot_disassoc(dev
);
9550 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9551 NL80211_CMD_UNPROT_DISASSOCIATE
, GFP_ATOMIC
);
9553 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc
);
9555 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9556 struct net_device
*netdev
, int cmd
,
9557 const u8
*addr
, gfp_t gfp
)
9559 struct sk_buff
*msg
;
9562 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9566 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9572 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9573 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9574 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9575 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9576 goto nla_put_failure
;
9578 genlmsg_end(msg
, hdr
);
9580 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9581 nl80211_mlme_mcgrp
.id
, gfp
);
9585 genlmsg_cancel(msg
, hdr
);
9589 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9590 struct net_device
*netdev
, const u8
*addr
,
9593 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9597 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9598 struct net_device
*netdev
, const u8
*addr
,
9601 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9605 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9606 struct net_device
*netdev
, const u8
*bssid
,
9607 const u8
*req_ie
, size_t req_ie_len
,
9608 const u8
*resp_ie
, size_t resp_ie_len
,
9609 u16 status
, gfp_t gfp
)
9611 struct sk_buff
*msg
;
9614 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9618 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9624 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9625 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9626 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9627 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9629 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9631 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9632 goto nla_put_failure
;
9634 genlmsg_end(msg
, hdr
);
9636 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9637 nl80211_mlme_mcgrp
.id
, gfp
);
9641 genlmsg_cancel(msg
, hdr
);
9646 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9647 struct net_device
*netdev
, const u8
*bssid
,
9648 const u8
*req_ie
, size_t req_ie_len
,
9649 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9651 struct sk_buff
*msg
;
9654 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9658 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9664 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9665 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9666 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9668 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9670 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9671 goto nla_put_failure
;
9673 genlmsg_end(msg
, hdr
);
9675 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9676 nl80211_mlme_mcgrp
.id
, gfp
);
9680 genlmsg_cancel(msg
, hdr
);
9685 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9686 struct net_device
*netdev
, u16 reason
,
9687 const u8
*ie
, size_t ie_len
, bool from_ap
)
9689 struct sk_buff
*msg
;
9692 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9696 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9702 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9703 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9704 (from_ap
&& reason
&&
9705 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9707 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9708 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9709 goto nla_put_failure
;
9711 genlmsg_end(msg
, hdr
);
9713 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9714 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9718 genlmsg_cancel(msg
, hdr
);
9723 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9724 struct net_device
*netdev
, const u8
*bssid
,
9727 struct sk_buff
*msg
;
9730 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9734 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9740 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9741 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9742 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9743 goto nla_put_failure
;
9745 genlmsg_end(msg
, hdr
);
9747 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9748 nl80211_mlme_mcgrp
.id
, gfp
);
9752 genlmsg_cancel(msg
, hdr
);
9756 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9757 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9759 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9760 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9761 struct sk_buff
*msg
;
9764 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9767 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9769 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9773 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9779 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9780 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9781 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9783 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9784 goto nla_put_failure
;
9786 genlmsg_end(msg
, hdr
);
9788 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9789 nl80211_mlme_mcgrp
.id
, gfp
);
9793 genlmsg_cancel(msg
, hdr
);
9796 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9798 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9799 struct net_device
*netdev
, const u8
*addr
,
9800 enum nl80211_key_type key_type
, int key_id
,
9801 const u8
*tsc
, gfp_t gfp
)
9803 struct sk_buff
*msg
;
9806 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9810 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9816 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9817 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9818 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9819 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9821 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9822 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9823 goto nla_put_failure
;
9825 genlmsg_end(msg
, hdr
);
9827 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9828 nl80211_mlme_mcgrp
.id
, gfp
);
9832 genlmsg_cancel(msg
, hdr
);
9836 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9837 struct ieee80211_channel
*channel_before
,
9838 struct ieee80211_channel
*channel_after
)
9840 struct sk_buff
*msg
;
9842 struct nlattr
*nl_freq
;
9844 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9848 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9855 * Since we are applying the beacon hint to a wiphy we know its
9856 * wiphy_idx is valid
9858 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9859 goto nla_put_failure
;
9862 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9864 goto nla_put_failure
;
9865 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9866 goto nla_put_failure
;
9867 nla_nest_end(msg
, nl_freq
);
9870 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9872 goto nla_put_failure
;
9873 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9874 goto nla_put_failure
;
9875 nla_nest_end(msg
, nl_freq
);
9877 genlmsg_end(msg
, hdr
);
9880 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9887 genlmsg_cancel(msg
, hdr
);
9891 static void nl80211_send_remain_on_chan_event(
9892 int cmd
, struct cfg80211_registered_device
*rdev
,
9893 struct wireless_dev
*wdev
, u64 cookie
,
9894 struct ieee80211_channel
*chan
,
9895 unsigned int duration
, gfp_t gfp
)
9897 struct sk_buff
*msg
;
9900 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9904 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9910 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9911 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9912 wdev
->netdev
->ifindex
)) ||
9913 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9914 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9915 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9916 NL80211_CHAN_NO_HT
) ||
9917 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9918 goto nla_put_failure
;
9920 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9921 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9922 goto nla_put_failure
;
9924 genlmsg_end(msg
, hdr
);
9926 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9927 nl80211_mlme_mcgrp
.id
, gfp
);
9931 genlmsg_cancel(msg
, hdr
);
9935 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9936 struct ieee80211_channel
*chan
,
9937 unsigned int duration
, gfp_t gfp
)
9939 struct wiphy
*wiphy
= wdev
->wiphy
;
9940 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9942 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9943 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9944 rdev
, wdev
, cookie
, chan
,
9947 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9949 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9950 struct ieee80211_channel
*chan
,
9953 struct wiphy
*wiphy
= wdev
->wiphy
;
9954 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9956 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9957 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9958 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9960 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9962 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9963 struct station_info
*sinfo
, gfp_t gfp
)
9965 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9966 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9967 struct sk_buff
*msg
;
9969 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9971 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9975 if (nl80211_send_station(msg
, 0, 0, 0,
9976 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9981 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9982 nl80211_mlme_mcgrp
.id
, gfp
);
9984 EXPORT_SYMBOL(cfg80211_new_sta
);
9986 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9988 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9989 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9990 struct sk_buff
*msg
;
9993 trace_cfg80211_del_sta(dev
, mac_addr
);
9995 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9999 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
10005 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10006 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
10007 goto nla_put_failure
;
10009 genlmsg_end(msg
, hdr
);
10011 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10012 nl80211_mlme_mcgrp
.id
, gfp
);
10016 genlmsg_cancel(msg
, hdr
);
10019 EXPORT_SYMBOL(cfg80211_del_sta
);
10021 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10022 enum nl80211_connect_failed_reason reason
,
10025 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10026 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10027 struct sk_buff
*msg
;
10030 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10034 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10040 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10041 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10042 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10043 goto nla_put_failure
;
10045 genlmsg_end(msg
, hdr
);
10047 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10048 nl80211_mlme_mcgrp
.id
, gfp
);
10052 genlmsg_cancel(msg
, hdr
);
10055 EXPORT_SYMBOL(cfg80211_conn_failed
);
10057 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10058 const u8
*addr
, gfp_t gfp
)
10060 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10061 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10062 struct sk_buff
*msg
;
10065 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10070 msg
= nlmsg_new(100, gfp
);
10074 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10080 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10081 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10082 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10083 goto nla_put_failure
;
10085 err
= genlmsg_end(msg
, hdr
);
10091 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10095 genlmsg_cancel(msg
, hdr
);
10100 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
10101 const u8
*addr
, gfp_t gfp
)
10103 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10106 trace_cfg80211_rx_spurious_frame(dev
, addr
);
10108 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10109 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
10110 trace_cfg80211_return_bool(false);
10113 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
10115 trace_cfg80211_return_bool(ret
);
10118 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
10120 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
10121 const u8
*addr
, gfp_t gfp
)
10123 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10126 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
10128 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10129 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10130 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
10131 trace_cfg80211_return_bool(false);
10134 ret
= __nl80211_unexpected_frame(dev
,
10135 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
10137 trace_cfg80211_return_bool(ret
);
10140 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10142 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10143 struct wireless_dev
*wdev
, u32 nlportid
,
10144 int freq
, int sig_dbm
,
10145 const u8
*buf
, size_t len
, gfp_t gfp
)
10147 struct net_device
*netdev
= wdev
->netdev
;
10148 struct sk_buff
*msg
;
10151 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10155 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10161 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10162 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10163 netdev
->ifindex
)) ||
10164 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10165 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10167 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10168 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10169 goto nla_put_failure
;
10171 genlmsg_end(msg
, hdr
);
10173 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10176 genlmsg_cancel(msg
, hdr
);
10181 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10182 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10184 struct wiphy
*wiphy
= wdev
->wiphy
;
10185 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10186 struct net_device
*netdev
= wdev
->netdev
;
10187 struct sk_buff
*msg
;
10190 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10192 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10196 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10202 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10203 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10204 netdev
->ifindex
)) ||
10205 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10206 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10207 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10208 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10209 goto nla_put_failure
;
10211 genlmsg_end(msg
, hdr
);
10213 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10214 nl80211_mlme_mcgrp
.id
, gfp
);
10218 genlmsg_cancel(msg
, hdr
);
10221 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10223 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10224 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10227 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10228 struct wiphy
*wiphy
= wdev
->wiphy
;
10229 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10230 struct sk_buff
*msg
;
10231 struct nlattr
*pinfoattr
;
10234 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10236 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10240 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10246 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10247 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10248 goto nla_put_failure
;
10250 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10252 goto nla_put_failure
;
10254 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10256 goto nla_put_failure
;
10258 nla_nest_end(msg
, pinfoattr
);
10260 genlmsg_end(msg
, hdr
);
10262 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10263 nl80211_mlme_mcgrp
.id
, gfp
);
10267 genlmsg_cancel(msg
, hdr
);
10270 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10272 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10273 struct net_device
*netdev
, const u8
*bssid
,
10274 const u8
*replay_ctr
, gfp_t gfp
)
10276 struct sk_buff
*msg
;
10277 struct nlattr
*rekey_attr
;
10280 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10284 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10290 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10291 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10292 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10293 goto nla_put_failure
;
10295 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10297 goto nla_put_failure
;
10299 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10300 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10301 goto nla_put_failure
;
10303 nla_nest_end(msg
, rekey_attr
);
10305 genlmsg_end(msg
, hdr
);
10307 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10308 nl80211_mlme_mcgrp
.id
, gfp
);
10312 genlmsg_cancel(msg
, hdr
);
10316 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10317 const u8
*replay_ctr
, gfp_t gfp
)
10319 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10320 struct wiphy
*wiphy
= wdev
->wiphy
;
10321 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10323 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10324 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10326 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10329 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10330 struct net_device
*netdev
, int index
,
10331 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10333 struct sk_buff
*msg
;
10334 struct nlattr
*attr
;
10337 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10341 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10347 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10348 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10349 goto nla_put_failure
;
10351 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10353 goto nla_put_failure
;
10355 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10356 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10358 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10359 goto nla_put_failure
;
10361 nla_nest_end(msg
, attr
);
10363 genlmsg_end(msg
, hdr
);
10365 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10366 nl80211_mlme_mcgrp
.id
, gfp
);
10370 genlmsg_cancel(msg
, hdr
);
10374 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10375 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10377 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10378 struct wiphy
*wiphy
= wdev
->wiphy
;
10379 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10381 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10382 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10384 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10386 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10387 struct net_device
*netdev
,
10388 struct cfg80211_chan_def
*chandef
,
10391 struct sk_buff
*msg
;
10394 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10398 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10404 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10405 goto nla_put_failure
;
10407 if (nl80211_send_chandef(msg
, chandef
))
10408 goto nla_put_failure
;
10410 genlmsg_end(msg
, hdr
);
10412 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10413 nl80211_mlme_mcgrp
.id
, gfp
);
10417 genlmsg_cancel(msg
, hdr
);
10421 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10422 struct cfg80211_chan_def
*chandef
)
10424 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10425 struct wiphy
*wiphy
= wdev
->wiphy
;
10426 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10428 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10432 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10433 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10436 wdev
->channel
= chandef
->chan
;
10437 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10442 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10444 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10445 const u8
*peer
, u32 num_packets
,
10446 u32 rate
, u32 intvl
, gfp_t gfp
)
10448 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10449 struct wiphy
*wiphy
= wdev
->wiphy
;
10450 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10451 struct sk_buff
*msg
;
10452 struct nlattr
*pinfoattr
;
10455 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10459 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10465 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10466 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10467 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10468 goto nla_put_failure
;
10470 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10472 goto nla_put_failure
;
10474 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10475 goto nla_put_failure
;
10477 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10478 goto nla_put_failure
;
10480 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10481 goto nla_put_failure
;
10483 nla_nest_end(msg
, pinfoattr
);
10485 genlmsg_end(msg
, hdr
);
10487 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10488 nl80211_mlme_mcgrp
.id
, gfp
);
10492 genlmsg_cancel(msg
, hdr
);
10495 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10498 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10499 struct cfg80211_chan_def
*chandef
,
10500 enum nl80211_radar_event event
,
10501 struct net_device
*netdev
, gfp_t gfp
)
10503 struct sk_buff
*msg
;
10506 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10510 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10516 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10517 goto nla_put_failure
;
10519 /* NOP and radar events don't need a netdev parameter */
10521 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10523 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10524 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10525 goto nla_put_failure
;
10528 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10529 goto nla_put_failure
;
10531 if (nl80211_send_chandef(msg
, chandef
))
10532 goto nla_put_failure
;
10534 if (genlmsg_end(msg
, hdr
) < 0) {
10539 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10540 nl80211_mlme_mcgrp
.id
, gfp
);
10544 genlmsg_cancel(msg
, hdr
);
10548 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10549 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10551 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10552 struct wiphy
*wiphy
= wdev
->wiphy
;
10553 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10554 struct sk_buff
*msg
;
10555 struct nlattr
*pinfoattr
;
10558 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10560 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10564 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10570 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10571 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10572 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10573 goto nla_put_failure
;
10575 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10577 goto nla_put_failure
;
10579 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10580 goto nla_put_failure
;
10582 nla_nest_end(msg
, pinfoattr
);
10584 genlmsg_end(msg
, hdr
);
10586 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10587 nl80211_mlme_mcgrp
.id
, gfp
);
10591 genlmsg_cancel(msg
, hdr
);
10594 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10596 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10597 u64 cookie
, bool acked
, gfp_t gfp
)
10599 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10600 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10601 struct sk_buff
*msg
;
10605 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10607 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10612 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10618 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10619 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10620 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10621 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10622 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10623 goto nla_put_failure
;
10625 err
= genlmsg_end(msg
, hdr
);
10631 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10632 nl80211_mlme_mcgrp
.id
, gfp
);
10636 genlmsg_cancel(msg
, hdr
);
10639 EXPORT_SYMBOL(cfg80211_probe_status
);
10641 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10642 const u8
*frame
, size_t len
,
10643 int freq
, int sig_dbm
)
10645 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10646 struct sk_buff
*msg
;
10648 struct cfg80211_beacon_registration
*reg
;
10650 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10652 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10653 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10654 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10656 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10660 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10662 goto nla_put_failure
;
10664 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10666 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10668 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10669 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10670 goto nla_put_failure
;
10672 genlmsg_end(msg
, hdr
);
10674 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10676 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10680 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10682 genlmsg_cancel(msg
, hdr
);
10685 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10688 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10689 struct cfg80211_wowlan_wakeup
*wakeup
,
10692 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10693 struct sk_buff
*msg
;
10695 int err
, size
= 200;
10697 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10700 size
+= wakeup
->packet_present_len
;
10702 msg
= nlmsg_new(size
, gfp
);
10706 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10710 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10711 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10714 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10715 wdev
->netdev
->ifindex
))
10719 struct nlattr
*reasons
;
10721 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10723 if (wakeup
->disconnect
&&
10724 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10726 if (wakeup
->magic_pkt
&&
10727 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10729 if (wakeup
->gtk_rekey_failure
&&
10730 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10732 if (wakeup
->eap_identity_req
&&
10733 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10735 if (wakeup
->four_way_handshake
&&
10736 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10738 if (wakeup
->rfkill_release
&&
10739 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10742 if (wakeup
->pattern_idx
>= 0 &&
10743 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10744 wakeup
->pattern_idx
))
10747 if (wakeup
->tcp_match
)
10748 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10750 if (wakeup
->tcp_connlost
)
10752 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10754 if (wakeup
->tcp_nomoretokens
)
10756 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10758 if (wakeup
->packet
) {
10759 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10760 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10762 if (!wakeup
->packet_80211
) {
10764 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10766 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10769 if (wakeup
->packet_len
&&
10770 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10773 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10778 nla_nest_end(msg
, reasons
);
10781 err
= genlmsg_end(msg
, hdr
);
10785 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10786 nl80211_mlme_mcgrp
.id
, gfp
);
10792 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10795 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10796 enum nl80211_tdls_operation oper
,
10797 u16 reason_code
, gfp_t gfp
)
10799 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10800 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10801 struct sk_buff
*msg
;
10805 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10808 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10812 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10818 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10819 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10820 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10821 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10822 (reason_code
> 0 &&
10823 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10824 goto nla_put_failure
;
10826 err
= genlmsg_end(msg
, hdr
);
10832 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10833 nl80211_mlme_mcgrp
.id
, gfp
);
10837 genlmsg_cancel(msg
, hdr
);
10840 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10842 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10843 unsigned long state
,
10846 struct netlink_notify
*notify
= _notify
;
10847 struct cfg80211_registered_device
*rdev
;
10848 struct wireless_dev
*wdev
;
10849 struct cfg80211_beacon_registration
*reg
, *tmp
;
10851 if (state
!= NETLINK_URELEASE
|| notify
->protocol
!= NETLINK_GENERIC
)
10852 return NOTIFY_DONE
;
10856 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10857 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10858 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10860 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10861 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10863 if (reg
->nlportid
== notify
->portid
) {
10864 list_del(®
->list
);
10869 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10874 return NOTIFY_DONE
;
10877 static struct notifier_block nl80211_netlink_notifier
= {
10878 .notifier_call
= nl80211_netlink_notify
,
10881 void cfg80211_ft_event(struct net_device
*netdev
,
10882 struct cfg80211_ft_event_params
*ft_event
)
10884 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10885 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10886 struct sk_buff
*msg
;
10890 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10892 if (!ft_event
->target_ap
)
10895 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10899 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10905 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10906 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10907 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10909 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10910 if (ft_event
->ric_ies
)
10911 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10912 ft_event
->ric_ies
);
10914 err
= genlmsg_end(msg
, hdr
);
10920 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10921 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10923 EXPORT_SYMBOL(cfg80211_ft_event
);
10925 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10927 struct cfg80211_registered_device
*rdev
;
10928 struct sk_buff
*msg
;
10932 rdev
= wiphy_to_dev(wdev
->wiphy
);
10933 if (!rdev
->crit_proto_nlportid
)
10936 nlportid
= rdev
->crit_proto_nlportid
;
10937 rdev
->crit_proto_nlportid
= 0;
10939 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10943 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10945 goto nla_put_failure
;
10947 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10948 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10949 goto nla_put_failure
;
10951 genlmsg_end(msg
, hdr
);
10953 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10958 genlmsg_cancel(msg
, hdr
);
10962 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10964 /* initialisation/exit functions */
10966 int nl80211_init(void)
10970 err
= genl_register_family_with_ops(&nl80211_fam
,
10971 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10975 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10979 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10983 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10987 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10991 #ifdef CONFIG_NL80211_TESTMODE
10992 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10996 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_vendor_mcgrp
);
11001 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
11007 genl_unregister_family(&nl80211_fam
);
11011 void nl80211_exit(void)
11013 netlink_unregister_notifier(&nl80211_netlink_notifier
);
11014 genl_unregister_family(&nl80211_fam
);