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_GENL_NAME
, /* 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
];
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 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
84 if (have_ifidx
&& wdev
->netdev
&&
85 wdev
->netdev
->ifindex
== ifidx
) {
89 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
101 return ERR_PTR(-ENODEV
);
104 static struct cfg80211_registered_device
*
105 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
107 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
108 struct net_device
*netdev
;
112 if (!attrs
[NL80211_ATTR_WIPHY
] &&
113 !attrs
[NL80211_ATTR_IFINDEX
] &&
114 !attrs
[NL80211_ATTR_WDEV
])
115 return ERR_PTR(-EINVAL
);
117 if (attrs
[NL80211_ATTR_WIPHY
])
118 rdev
= cfg80211_rdev_by_wiphy_idx(
119 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
121 if (attrs
[NL80211_ATTR_WDEV
]) {
122 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
123 struct wireless_dev
*wdev
;
126 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
128 /* make sure wdev exists */
129 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
130 if (wdev
->identifier
!= (u32
)wdev_id
)
139 if (rdev
&& tmp
!= rdev
)
140 return ERR_PTR(-EINVAL
);
145 if (attrs
[NL80211_ATTR_IFINDEX
]) {
146 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
147 netdev
= dev_get_by_index(netns
, ifindex
);
149 if (netdev
->ieee80211_ptr
)
151 netdev
->ieee80211_ptr
->wiphy
);
157 /* not wireless device -- return error */
159 return ERR_PTR(-EINVAL
);
161 /* mismatch -- return error */
162 if (rdev
&& tmp
!= rdev
)
163 return ERR_PTR(-EINVAL
);
170 return ERR_PTR(-ENODEV
);
172 if (netns
!= wiphy_net(&rdev
->wiphy
))
173 return ERR_PTR(-ENODEV
);
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
185 static struct cfg80211_registered_device
*
186 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
188 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
191 /* policy for the attributes */
192 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
193 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
194 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
196 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
198 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
200 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
201 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
202 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
204 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
205 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
210 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
211 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
212 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
214 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
215 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
217 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
218 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
219 .len
= WLAN_MAX_KEY_LEN
},
220 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
221 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
222 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
223 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
224 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
226 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
227 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
229 .len
= IEEE80211_MAX_DATA_LEN
},
230 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
231 .len
= IEEE80211_MAX_DATA_LEN
},
232 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
233 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
234 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
235 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
236 .len
= NL80211_MAX_SUPP_RATES
},
237 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
238 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
239 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
240 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
241 .len
= IEEE80211_MAX_MESH_ID_LEN
},
242 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
244 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
245 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
247 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
250 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
251 .len
= NL80211_MAX_SUPP_RATES
},
252 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
254 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
255 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
257 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
259 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
260 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
261 .len
= IEEE80211_MAX_DATA_LEN
},
262 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
263 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
265 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
266 .len
= IEEE80211_MAX_SSID_LEN
},
267 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
268 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
269 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
270 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
271 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
272 [NL80211_ATTR_STA_FLAGS2
] = {
273 .len
= sizeof(struct nl80211_sta_flag_update
),
275 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
278 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
279 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
280 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
281 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
282 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
283 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
284 .len
= WLAN_PMKID_LEN
},
285 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
286 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
287 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
288 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
289 .len
= IEEE80211_MAX_DATA_LEN
},
290 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
291 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
292 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
293 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
297 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
298 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
299 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
300 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
301 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
303 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
304 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
305 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
306 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
307 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
308 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
309 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
310 .len
= IEEE80211_MAX_DATA_LEN
},
311 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
312 .len
= IEEE80211_MAX_DATA_LEN
},
313 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
314 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
315 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
316 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
318 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
319 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
321 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
322 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
323 .len
= IEEE80211_MAX_DATA_LEN
},
324 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
325 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
326 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
327 .len
= NL80211_HT_CAPABILITY_LEN
329 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
330 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
331 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
332 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
333 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
334 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
335 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
336 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
337 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
338 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
339 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
340 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
341 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
342 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
343 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
344 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
346 .len
= NL80211_VHT_CAPABILITY_LEN
,
348 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
349 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
350 .len
= IEEE80211_MAX_DATA_LEN
},
351 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
354 /* policy for the key attributes */
355 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
356 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
357 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
358 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
359 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
360 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
361 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
362 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
363 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
366 /* policy for the key default flags */
367 static const struct nla_policy
368 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
373 /* policy for WoWLAN attributes */
374 static const struct nla_policy
375 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
376 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
377 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
387 static const struct nla_policy
388 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
390 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
391 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
392 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
393 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
396 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
399 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
406 /* policy for GTK rekey offload attributes */
407 static const struct nla_policy
408 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
409 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
410 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
411 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
414 static const struct nla_policy
415 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
416 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
417 .len
= IEEE80211_MAX_SSID_LEN
},
418 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
421 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
422 struct netlink_callback
*cb
,
423 struct cfg80211_registered_device
**rdev
,
424 struct wireless_dev
**wdev
)
431 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
432 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
437 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
438 nl80211_fam
.attrbuf
);
440 err
= PTR_ERR(*wdev
);
443 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
444 /* 0 is the first index - add 1 to parse only once */
445 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
446 cb
->args
[1] = (*wdev
)->identifier
;
448 /* subtract the 1 again here */
449 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
450 struct wireless_dev
*tmp
;
456 *rdev
= wiphy_to_dev(wiphy
);
459 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
460 if (tmp
->identifier
== cb
->args
[1]) {
478 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
484 static bool is_valid_ie_attr(const struct nlattr
*attr
)
492 pos
= nla_data(attr
);
513 /* message building helper */
514 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
517 /* since there is no private header just add the generic one */
518 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
521 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
522 struct ieee80211_channel
*chan
,
525 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
527 goto nla_put_failure
;
529 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
530 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
531 goto nla_put_failure
;
532 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
533 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
534 goto nla_put_failure
;
535 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
536 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
537 goto nla_put_failure
;
538 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
539 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
540 goto nla_put_failure
;
544 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
546 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
548 goto nla_put_failure
;
549 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
551 goto nla_put_failure
;
556 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
557 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
558 goto nla_put_failure
;
559 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
560 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
561 goto nla_put_failure
;
562 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
563 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
564 goto nla_put_failure
;
565 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
566 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
567 goto nla_put_failure
;
570 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
571 DBM_TO_MBM(chan
->max_power
)))
572 goto nla_put_failure
;
580 /* netlink command implementations */
587 bool def_uni
, def_multi
;
590 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
592 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
593 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
598 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
599 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
608 if (tb
[NL80211_KEY_IDX
])
609 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
611 if (tb
[NL80211_KEY_DATA
]) {
612 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
613 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
616 if (tb
[NL80211_KEY_SEQ
]) {
617 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
618 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
621 if (tb
[NL80211_KEY_CIPHER
])
622 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
624 if (tb
[NL80211_KEY_TYPE
]) {
625 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
626 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
630 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
631 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
632 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
633 tb
[NL80211_KEY_DEFAULT_TYPES
],
634 nl80211_key_default_policy
);
638 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
639 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
645 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
647 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
648 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
649 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
652 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
653 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
654 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
657 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
658 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
660 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
661 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
663 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
664 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
673 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
674 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
675 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
679 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
680 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
681 int err
= nla_parse_nested(
682 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
683 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
684 nl80211_key_default_policy
);
688 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
689 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
695 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
699 memset(k
, 0, sizeof(*k
));
703 if (info
->attrs
[NL80211_ATTR_KEY
])
704 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
706 err
= nl80211_parse_key_old(info
, k
);
711 if (k
->def
&& k
->defmgmt
)
715 if (k
->def_uni
|| !k
->def_multi
)
721 if (k
->idx
< 4 || k
->idx
> 5)
724 if (k
->idx
< 0 || k
->idx
> 3)
727 if (k
->idx
< 0 || k
->idx
> 5)
735 static struct cfg80211_cached_keys
*
736 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
737 struct nlattr
*keys
, bool *no_ht
)
739 struct key_parse parse
;
741 struct cfg80211_cached_keys
*result
;
742 int rem
, err
, def
= 0;
744 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
746 return ERR_PTR(-ENOMEM
);
749 result
->defmgmt
= -1;
751 nla_for_each_nested(key
, keys
, rem
) {
752 memset(&parse
, 0, sizeof(parse
));
755 err
= nl80211_parse_key_new(key
, &parse
);
761 if (parse
.idx
< 0 || parse
.idx
> 4)
767 result
->def
= parse
.idx
;
768 if (!parse
.def_uni
|| !parse
.def_multi
)
770 } else if (parse
.defmgmt
)
772 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
773 parse
.idx
, false, NULL
);
776 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
777 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
778 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
779 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
781 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
782 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
794 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
796 ASSERT_WDEV_LOCK(wdev
);
798 switch (wdev
->iftype
) {
799 case NL80211_IFTYPE_AP
:
800 case NL80211_IFTYPE_AP_VLAN
:
801 case NL80211_IFTYPE_P2P_GO
:
802 case NL80211_IFTYPE_MESH_POINT
:
804 case NL80211_IFTYPE_ADHOC
:
805 case NL80211_IFTYPE_STATION
:
806 case NL80211_IFTYPE_P2P_CLIENT
:
807 if (!wdev
->current_bss
)
817 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
819 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
823 goto nla_put_failure
;
827 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
828 goto nla_put_failure
;
833 nla_nest_end(msg
, nl_modes
);
840 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
844 struct nlattr
*nl_combis
;
847 nl_combis
= nla_nest_start(msg
,
848 NL80211_ATTR_INTERFACE_COMBINATIONS
);
850 goto nla_put_failure
;
852 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
853 const struct ieee80211_iface_combination
*c
;
854 struct nlattr
*nl_combi
, *nl_limits
;
856 c
= &wiphy
->iface_combinations
[i
];
858 nl_combi
= nla_nest_start(msg
, i
+ 1);
860 goto nla_put_failure
;
862 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
864 goto nla_put_failure
;
866 for (j
= 0; j
< c
->n_limits
; j
++) {
867 struct nlattr
*nl_limit
;
869 nl_limit
= nla_nest_start(msg
, j
+ 1);
871 goto nla_put_failure
;
872 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
874 goto nla_put_failure
;
875 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
877 goto nla_put_failure
;
878 nla_nest_end(msg
, nl_limit
);
881 nla_nest_end(msg
, nl_limits
);
883 if (c
->beacon_int_infra_match
&&
884 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
885 goto nla_put_failure
;
886 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
887 c
->num_different_channels
) ||
888 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
890 goto nla_put_failure
;
892 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
893 c
->radar_detect_widths
))
894 goto nla_put_failure
;
896 nla_nest_end(msg
, nl_combi
);
899 nla_nest_end(msg
, nl_combis
);
907 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
910 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
911 struct nlattr
*nl_tcp
;
916 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
920 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
921 tcp
->data_payload_max
))
924 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
925 tcp
->data_payload_max
))
928 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
931 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
932 sizeof(*tcp
->tok
), tcp
->tok
))
935 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
936 tcp
->data_interval_max
))
939 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
940 tcp
->wake_payload_max
))
943 nla_nest_end(msg
, nl_tcp
);
947 static int nl80211_send_wowlan(struct sk_buff
*msg
,
948 struct cfg80211_registered_device
*dev
,
951 struct nlattr
*nl_wowlan
;
953 if (!dev
->wiphy
.wowlan
)
956 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
960 if (((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
961 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
962 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
963 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
964 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
965 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
966 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
967 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
968 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
969 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
970 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
971 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
972 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
973 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
974 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
975 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
978 if (dev
->wiphy
.wowlan
->n_patterns
) {
979 struct nl80211_wowlan_pattern_support pat
= {
980 .max_patterns
= dev
->wiphy
.wowlan
->n_patterns
,
981 .min_pattern_len
= dev
->wiphy
.wowlan
->pattern_min_len
,
982 .max_pattern_len
= dev
->wiphy
.wowlan
->pattern_max_len
,
983 .max_pkt_offset
= dev
->wiphy
.wowlan
->max_pkt_offset
,
986 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
991 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
994 nla_nest_end(msg
, nl_wowlan
);
1000 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1001 struct ieee80211_supported_band
*sband
)
1003 struct nlattr
*nl_rates
, *nl_rate
;
1004 struct ieee80211_rate
*rate
;
1008 if (sband
->ht_cap
.ht_supported
&&
1009 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1010 sizeof(sband
->ht_cap
.mcs
),
1011 &sband
->ht_cap
.mcs
) ||
1012 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1013 sband
->ht_cap
.cap
) ||
1014 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1015 sband
->ht_cap
.ampdu_factor
) ||
1016 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1017 sband
->ht_cap
.ampdu_density
)))
1021 if (sband
->vht_cap
.vht_supported
&&
1022 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1023 sizeof(sband
->vht_cap
.vht_mcs
),
1024 &sband
->vht_cap
.vht_mcs
) ||
1025 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1026 sband
->vht_cap
.cap
)))
1030 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1034 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1035 nl_rate
= nla_nest_start(msg
, i
);
1039 rate
= &sband
->bitrates
[i
];
1040 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1043 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1045 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1048 nla_nest_end(msg
, nl_rate
);
1051 nla_nest_end(msg
, nl_rates
);
1057 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1058 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1061 struct nlattr
*nl_ftypes
, *nl_ifs
;
1062 enum nl80211_iftype ift
;
1068 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1072 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1073 nl_ftypes
= nla_nest_start(msg
, ift
);
1077 stypes
= mgmt_stypes
[ift
].tx
;
1080 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1081 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1086 nla_nest_end(msg
, nl_ftypes
);
1089 nla_nest_end(msg
, nl_ifs
);
1091 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1095 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1096 nl_ftypes
= nla_nest_start(msg
, ift
);
1100 stypes
= mgmt_stypes
[ift
].rx
;
1103 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1104 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1109 nla_nest_end(msg
, nl_ftypes
);
1111 nla_nest_end(msg
, nl_ifs
);
1116 struct nl80211_dump_wiphy_state
{
1119 long split_start
, band_start
, chan_start
;
1123 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1124 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1125 int flags
, struct nl80211_dump_wiphy_state
*state
)
1128 struct nlattr
*nl_bands
, *nl_band
;
1129 struct nlattr
*nl_freqs
, *nl_freq
;
1130 struct nlattr
*nl_cmds
;
1131 enum ieee80211_band band
;
1132 struct ieee80211_channel
*chan
;
1134 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1135 dev
->wiphy
.mgmt_stypes
;
1138 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1142 if (WARN_ON(!state
))
1145 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1146 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1147 wiphy_name(&dev
->wiphy
)) ||
1148 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1149 cfg80211_rdev_list_generation
))
1150 goto nla_put_failure
;
1152 switch (state
->split_start
) {
1154 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1155 dev
->wiphy
.retry_short
) ||
1156 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1157 dev
->wiphy
.retry_long
) ||
1158 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1159 dev
->wiphy
.frag_threshold
) ||
1160 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1161 dev
->wiphy
.rts_threshold
) ||
1162 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1163 dev
->wiphy
.coverage_class
) ||
1164 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1165 dev
->wiphy
.max_scan_ssids
) ||
1166 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1167 dev
->wiphy
.max_sched_scan_ssids
) ||
1168 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1169 dev
->wiphy
.max_scan_ie_len
) ||
1170 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1171 dev
->wiphy
.max_sched_scan_ie_len
) ||
1172 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1173 dev
->wiphy
.max_match_sets
))
1174 goto nla_put_failure
;
1176 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1177 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1178 goto nla_put_failure
;
1179 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1180 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1181 goto nla_put_failure
;
1182 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1183 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1184 goto nla_put_failure
;
1185 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1186 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1187 goto nla_put_failure
;
1188 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1189 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1190 goto nla_put_failure
;
1191 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1192 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1193 goto nla_put_failure
;
1194 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1195 nla_put_flag(msg
, WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1196 goto nla_put_failure
;
1198 state
->split_start
++;
1202 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1203 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1204 dev
->wiphy
.cipher_suites
))
1205 goto nla_put_failure
;
1207 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1208 dev
->wiphy
.max_num_pmkids
))
1209 goto nla_put_failure
;
1211 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1212 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1213 goto nla_put_failure
;
1215 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1216 dev
->wiphy
.available_antennas_tx
) ||
1217 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1218 dev
->wiphy
.available_antennas_rx
))
1219 goto nla_put_failure
;
1221 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1222 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1223 dev
->wiphy
.probe_resp_offload
))
1224 goto nla_put_failure
;
1226 if ((dev
->wiphy
.available_antennas_tx
||
1227 dev
->wiphy
.available_antennas_rx
) &&
1228 dev
->ops
->get_antenna
) {
1229 u32 tx_ant
= 0, rx_ant
= 0;
1231 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1233 if (nla_put_u32(msg
,
1234 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1237 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1239 goto nla_put_failure
;
1243 state
->split_start
++;
1247 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1248 dev
->wiphy
.interface_modes
))
1249 goto nla_put_failure
;
1250 state
->split_start
++;
1254 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1256 goto nla_put_failure
;
1258 for (band
= state
->band_start
;
1259 band
< IEEE80211_NUM_BANDS
; band
++) {
1260 struct ieee80211_supported_band
*sband
;
1262 sband
= dev
->wiphy
.bands
[band
];
1267 nl_band
= nla_nest_start(msg
, band
);
1269 goto nla_put_failure
;
1271 switch (state
->chan_start
) {
1273 if (nl80211_send_band_rateinfo(msg
, sband
))
1274 goto nla_put_failure
;
1275 state
->chan_start
++;
1279 /* add frequencies */
1280 nl_freqs
= nla_nest_start(
1281 msg
, NL80211_BAND_ATTR_FREQS
);
1283 goto nla_put_failure
;
1285 for (i
= state
->chan_start
- 1;
1286 i
< sband
->n_channels
;
1288 nl_freq
= nla_nest_start(msg
, i
);
1290 goto nla_put_failure
;
1292 chan
= &sband
->channels
[i
];
1294 if (nl80211_msg_put_channel(
1297 goto nla_put_failure
;
1299 nla_nest_end(msg
, nl_freq
);
1303 if (i
< sband
->n_channels
)
1304 state
->chan_start
= i
+ 2;
1306 state
->chan_start
= 0;
1307 nla_nest_end(msg
, nl_freqs
);
1310 nla_nest_end(msg
, nl_band
);
1313 /* start again here */
1314 if (state
->chan_start
)
1319 nla_nest_end(msg
, nl_bands
);
1321 if (band
< IEEE80211_NUM_BANDS
)
1322 state
->band_start
= band
+ 1;
1324 state
->band_start
= 0;
1326 /* if bands & channels are done, continue outside */
1327 if (state
->band_start
== 0 && state
->chan_start
== 0)
1328 state
->split_start
++;
1332 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1334 goto nla_put_failure
;
1337 #define CMD(op, n) \
1339 if (dev->ops->op) { \
1341 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1342 goto nla_put_failure; \
1346 CMD(add_virtual_intf
, NEW_INTERFACE
);
1347 CMD(change_virtual_intf
, SET_INTERFACE
);
1348 CMD(add_key
, NEW_KEY
);
1349 CMD(start_ap
, START_AP
);
1350 CMD(add_station
, NEW_STATION
);
1351 CMD(add_mpath
, NEW_MPATH
);
1352 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1353 CMD(change_bss
, SET_BSS
);
1354 CMD(auth
, AUTHENTICATE
);
1355 CMD(assoc
, ASSOCIATE
);
1356 CMD(deauth
, DEAUTHENTICATE
);
1357 CMD(disassoc
, DISASSOCIATE
);
1358 CMD(join_ibss
, JOIN_IBSS
);
1359 CMD(join_mesh
, JOIN_MESH
);
1360 CMD(set_pmksa
, SET_PMKSA
);
1361 CMD(del_pmksa
, DEL_PMKSA
);
1362 CMD(flush_pmksa
, FLUSH_PMKSA
);
1363 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1364 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1365 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1366 CMD(mgmt_tx
, FRAME
);
1367 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1368 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1370 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1371 goto nla_put_failure
;
1373 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1374 dev
->ops
->join_mesh
) {
1376 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1377 goto nla_put_failure
;
1379 CMD(set_wds_peer
, SET_WDS_PEER
);
1380 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1381 CMD(tdls_mgmt
, TDLS_MGMT
);
1382 CMD(tdls_oper
, TDLS_OPER
);
1384 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1385 CMD(sched_scan_start
, START_SCHED_SCAN
);
1386 CMD(probe_client
, PROBE_CLIENT
);
1387 CMD(set_noack_map
, SET_NOACK_MAP
);
1388 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1390 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1391 goto nla_put_failure
;
1393 CMD(start_p2p_device
, START_P2P_DEVICE
);
1394 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1396 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1397 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1400 #ifdef CONFIG_NL80211_TESTMODE
1401 CMD(testmode_cmd
, TESTMODE
);
1406 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1408 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1409 goto nla_put_failure
;
1412 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1414 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1415 goto nla_put_failure
;
1418 nla_nest_end(msg
, nl_cmds
);
1419 state
->split_start
++;
1423 if (dev
->ops
->remain_on_channel
&&
1424 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1426 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1427 dev
->wiphy
.max_remain_on_channel_duration
))
1428 goto nla_put_failure
;
1430 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1431 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1432 goto nla_put_failure
;
1434 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1435 goto nla_put_failure
;
1436 state
->split_start
++;
1441 if (nl80211_send_wowlan(msg
, dev
, state
->split
))
1442 goto nla_put_failure
;
1443 state
->split_start
++;
1447 state
->split_start
++;
1450 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1451 dev
->wiphy
.software_iftypes
))
1452 goto nla_put_failure
;
1454 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
,
1456 goto nla_put_failure
;
1458 state
->split_start
++;
1462 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1463 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1464 dev
->wiphy
.ap_sme_capa
))
1465 goto nla_put_failure
;
1467 features
= dev
->wiphy
.features
;
1469 * We can only add the per-channel limit information if the
1470 * dump is split, otherwise it makes it too big. Therefore
1471 * only advertise it in that case.
1474 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1475 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1476 goto nla_put_failure
;
1478 if (dev
->wiphy
.ht_capa_mod_mask
&&
1479 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1480 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1481 dev
->wiphy
.ht_capa_mod_mask
))
1482 goto nla_put_failure
;
1484 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1485 dev
->wiphy
.max_acl_mac_addrs
&&
1486 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1487 dev
->wiphy
.max_acl_mac_addrs
))
1488 goto nla_put_failure
;
1491 * Any information below this point is only available to
1492 * applications that can deal with it being split. This
1493 * helps ensure that newly added capabilities don't break
1494 * older tools by overrunning their buffers.
1496 * We still increment split_start so that in the split
1497 * case we'll continue with more data in the next round,
1498 * but break unconditionally so unsplit data stops here.
1500 state
->split_start
++;
1503 if (dev
->wiphy
.extended_capabilities
&&
1504 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1505 dev
->wiphy
.extended_capabilities_len
,
1506 dev
->wiphy
.extended_capabilities
) ||
1507 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1508 dev
->wiphy
.extended_capabilities_len
,
1509 dev
->wiphy
.extended_capabilities_mask
)))
1510 goto nla_put_failure
;
1512 if (dev
->wiphy
.vht_capa_mod_mask
&&
1513 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1514 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1515 dev
->wiphy
.vht_capa_mod_mask
))
1516 goto nla_put_failure
;
1519 state
->split_start
= 0;
1522 return genlmsg_end(msg
, hdr
);
1525 genlmsg_cancel(msg
, hdr
);
1529 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1530 struct netlink_callback
*cb
,
1531 struct nl80211_dump_wiphy_state
*state
)
1533 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1534 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1535 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1536 /* ignore parse errors for backward compatibility */
1540 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1541 if (tb
[NL80211_ATTR_WIPHY
])
1542 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1543 if (tb
[NL80211_ATTR_WDEV
])
1544 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1545 if (tb
[NL80211_ATTR_IFINDEX
]) {
1546 struct net_device
*netdev
;
1547 struct cfg80211_registered_device
*rdev
;
1548 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1550 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1553 if (netdev
->ieee80211_ptr
) {
1554 rdev
= wiphy_to_dev(
1555 netdev
->ieee80211_ptr
->wiphy
);
1556 state
->filter_wiphy
= rdev
->wiphy_idx
;
1564 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1567 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1568 struct cfg80211_registered_device
*dev
;
1572 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1577 state
->filter_wiphy
= -1;
1578 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1584 cb
->args
[0] = (long)state
;
1587 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1588 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1590 if (++idx
<= state
->start
)
1592 if (state
->filter_wiphy
!= -1 &&
1593 state
->filter_wiphy
!= dev
->wiphy_idx
)
1595 /* attempt to fit multiple wiphy data chunks into the skb */
1597 ret
= nl80211_send_wiphy(dev
, skb
,
1598 NETLINK_CB(cb
->skb
).portid
,
1600 NLM_F_MULTI
, state
);
1603 * If sending the wiphy data didn't fit (ENOBUFS
1604 * or EMSGSIZE returned), this SKB is still
1605 * empty (so it's not too big because another
1606 * wiphy dataset is already in the skb) and
1607 * we've not tried to adjust the dump allocation
1608 * yet ... then adjust the alloc size to be
1609 * bigger, and return 1 but with the empty skb.
1610 * This results in an empty message being RX'ed
1611 * in userspace, but that is ignored.
1613 * We can then retry with the larger buffer.
1615 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1617 cb
->min_dump_alloc
< 4096) {
1618 cb
->min_dump_alloc
= 4096;
1625 } while (state
->split_start
> 0);
1635 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1637 kfree((void *)cb
->args
[0]);
1641 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1643 struct sk_buff
*msg
;
1644 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1645 struct nl80211_dump_wiphy_state state
= {};
1647 msg
= nlmsg_new(4096, GFP_KERNEL
);
1651 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1657 return genlmsg_reply(msg
, info
);
1660 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1661 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1662 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1663 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1664 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1665 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1668 static int parse_txq_params(struct nlattr
*tb
[],
1669 struct ieee80211_txq_params
*txq_params
)
1671 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1672 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1673 !tb
[NL80211_TXQ_ATTR_AIFS
])
1676 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1677 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1678 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1679 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1680 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1682 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1688 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1691 * You can only set the channel explicitly for WDS interfaces,
1692 * all others have their channel managed via their respective
1693 * "establish a connection" command (connect, join, ...)
1695 * For AP/GO and mesh mode, the channel can be set with the
1696 * channel userspace API, but is only stored and passed to the
1697 * low-level driver when the AP starts or the mesh is joined.
1698 * This is for backward compatibility, userspace can also give
1699 * the channel in the start-ap or join-mesh commands instead.
1701 * Monitors are special as they are normally slaved to
1702 * whatever else is going on, so they have their own special
1703 * operation to set the monitor channel if possible.
1706 wdev
->iftype
== NL80211_IFTYPE_AP
||
1707 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1708 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1709 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1712 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1713 struct genl_info
*info
,
1714 struct cfg80211_chan_def
*chandef
)
1718 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1721 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1723 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1724 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1725 chandef
->center_freq1
= control_freq
;
1726 chandef
->center_freq2
= 0;
1728 /* Primary channel not allowed */
1729 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1732 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1733 enum nl80211_channel_type chantype
;
1735 chantype
= nla_get_u32(
1736 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1739 case NL80211_CHAN_NO_HT
:
1740 case NL80211_CHAN_HT20
:
1741 case NL80211_CHAN_HT40PLUS
:
1742 case NL80211_CHAN_HT40MINUS
:
1743 cfg80211_chandef_create(chandef
, chandef
->chan
,
1749 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1751 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1752 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1753 chandef
->center_freq1
=
1755 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1756 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1757 chandef
->center_freq2
=
1759 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1762 if (!cfg80211_chandef_valid(chandef
))
1765 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1766 IEEE80211_CHAN_DISABLED
))
1769 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1770 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1771 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1777 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1778 struct wireless_dev
*wdev
,
1779 struct genl_info
*info
)
1781 struct cfg80211_chan_def chandef
;
1783 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1786 iftype
= wdev
->iftype
;
1788 if (!nl80211_can_set_dev_channel(wdev
))
1791 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1796 case NL80211_IFTYPE_AP
:
1797 case NL80211_IFTYPE_P2P_GO
:
1798 if (wdev
->beacon_interval
) {
1802 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1806 wdev
->preset_chandef
= chandef
;
1809 case NL80211_IFTYPE_MESH_POINT
:
1810 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1812 case NL80211_IFTYPE_MONITOR
:
1813 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1822 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1825 struct net_device
*netdev
= info
->user_ptr
[1];
1827 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1830 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1832 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1833 struct net_device
*dev
= info
->user_ptr
[1];
1834 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1837 if (!info
->attrs
[NL80211_ATTR_MAC
])
1840 if (netif_running(dev
))
1843 if (!rdev
->ops
->set_wds_peer
)
1846 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1849 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1850 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1854 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1856 struct cfg80211_registered_device
*rdev
;
1857 struct net_device
*netdev
= NULL
;
1858 struct wireless_dev
*wdev
;
1859 int result
= 0, rem_txq_params
= 0;
1860 struct nlattr
*nl_txq_params
;
1862 u8 retry_short
= 0, retry_long
= 0;
1863 u32 frag_threshold
= 0, rts_threshold
= 0;
1864 u8 coverage_class
= 0;
1869 * Try to find the wiphy and netdev. Normally this
1870 * function shouldn't need the netdev, but this is
1871 * done for backward compatibility -- previously
1872 * setting the channel was done per wiphy, but now
1873 * it is per netdev. Previous userland like hostapd
1874 * also passed a netdev to set_wiphy, so that it is
1875 * possible to let that go to the right netdev!
1878 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1879 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1881 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1882 if (netdev
&& netdev
->ieee80211_ptr
)
1883 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1889 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1892 return PTR_ERR(rdev
);
1897 wdev
= netdev
->ieee80211_ptr
;
1900 * end workaround code, by now the rdev is available
1901 * and locked, and wdev may or may not be NULL.
1904 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1905 result
= cfg80211_dev_rename(
1906 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1911 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1912 struct ieee80211_txq_params txq_params
;
1913 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1915 if (!rdev
->ops
->set_txq_params
) {
1916 result
= -EOPNOTSUPP
;
1925 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1926 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1931 if (!netif_running(netdev
)) {
1936 nla_for_each_nested(nl_txq_params
,
1937 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1939 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1940 nla_data(nl_txq_params
),
1941 nla_len(nl_txq_params
),
1943 result
= parse_txq_params(tb
, &txq_params
);
1947 result
= rdev_set_txq_params(rdev
, netdev
,
1954 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1955 result
= __nl80211_set_channel(rdev
,
1956 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1962 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1963 struct wireless_dev
*txp_wdev
= wdev
;
1964 enum nl80211_tx_power_setting type
;
1967 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
1970 if (!rdev
->ops
->set_tx_power
) {
1971 result
= -EOPNOTSUPP
;
1975 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1976 type
= nla_get_u32(info
->attrs
[idx
]);
1978 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1979 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1984 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1985 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1986 mbm
= nla_get_u32(info
->attrs
[idx
]);
1989 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
1994 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1995 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1997 if ((!rdev
->wiphy
.available_antennas_tx
&&
1998 !rdev
->wiphy
.available_antennas_rx
) ||
1999 !rdev
->ops
->set_antenna
) {
2000 result
= -EOPNOTSUPP
;
2004 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2005 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2007 /* reject antenna configurations which don't match the
2008 * available antenna masks, except for the "all" mask */
2009 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2010 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2015 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2016 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2018 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2025 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2026 retry_short
= nla_get_u8(
2027 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2028 if (retry_short
== 0) {
2032 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2035 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2036 retry_long
= nla_get_u8(
2037 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2038 if (retry_long
== 0) {
2042 changed
|= WIPHY_PARAM_RETRY_LONG
;
2045 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2046 frag_threshold
= nla_get_u32(
2047 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2048 if (frag_threshold
< 256) {
2052 if (frag_threshold
!= (u32
) -1) {
2054 * Fragments (apart from the last one) are required to
2055 * have even length. Make the fragmentation code
2056 * simpler by stripping LSB should someone try to use
2057 * odd threshold value.
2059 frag_threshold
&= ~0x1;
2061 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2064 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2065 rts_threshold
= nla_get_u32(
2066 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2067 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2070 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2071 coverage_class
= nla_get_u8(
2072 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2073 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2077 u8 old_retry_short
, old_retry_long
;
2078 u32 old_frag_threshold
, old_rts_threshold
;
2079 u8 old_coverage_class
;
2081 if (!rdev
->ops
->set_wiphy_params
) {
2082 result
= -EOPNOTSUPP
;
2086 old_retry_short
= rdev
->wiphy
.retry_short
;
2087 old_retry_long
= rdev
->wiphy
.retry_long
;
2088 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2089 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2090 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2092 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2093 rdev
->wiphy
.retry_short
= retry_short
;
2094 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2095 rdev
->wiphy
.retry_long
= retry_long
;
2096 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2097 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2098 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2099 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2100 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2101 rdev
->wiphy
.coverage_class
= coverage_class
;
2103 result
= rdev_set_wiphy_params(rdev
, changed
);
2105 rdev
->wiphy
.retry_short
= old_retry_short
;
2106 rdev
->wiphy
.retry_long
= old_retry_long
;
2107 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2108 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2109 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2119 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2121 return (u64
)wdev
->identifier
|
2122 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2125 static int nl80211_send_chandef(struct sk_buff
*msg
,
2126 struct cfg80211_chan_def
*chandef
)
2128 WARN_ON(!cfg80211_chandef_valid(chandef
));
2130 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2131 chandef
->chan
->center_freq
))
2133 switch (chandef
->width
) {
2134 case NL80211_CHAN_WIDTH_20_NOHT
:
2135 case NL80211_CHAN_WIDTH_20
:
2136 case NL80211_CHAN_WIDTH_40
:
2137 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2138 cfg80211_get_chandef_type(chandef
)))
2144 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2146 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2148 if (chandef
->center_freq2
&&
2149 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2154 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2155 struct cfg80211_registered_device
*rdev
,
2156 struct wireless_dev
*wdev
)
2158 struct net_device
*dev
= wdev
->netdev
;
2161 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2166 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2167 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2168 goto nla_put_failure
;
2170 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2171 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2172 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2173 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2174 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2175 rdev
->devlist_generation
^
2176 (cfg80211_rdev_list_generation
<< 2)))
2177 goto nla_put_failure
;
2179 if (rdev
->ops
->get_channel
) {
2181 struct cfg80211_chan_def chandef
;
2183 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2185 if (nl80211_send_chandef(msg
, &chandef
))
2186 goto nla_put_failure
;
2190 if (wdev
->ssid_len
) {
2191 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2192 goto nla_put_failure
;
2195 return genlmsg_end(msg
, hdr
);
2198 genlmsg_cancel(msg
, hdr
);
2202 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2206 int wp_start
= cb
->args
[0];
2207 int if_start
= cb
->args
[1];
2208 struct cfg80211_registered_device
*rdev
;
2209 struct wireless_dev
*wdev
;
2212 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2213 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2215 if (wp_idx
< wp_start
) {
2221 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2222 if (if_idx
< if_start
) {
2226 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2227 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2239 cb
->args
[0] = wp_idx
;
2240 cb
->args
[1] = if_idx
;
2245 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2247 struct sk_buff
*msg
;
2248 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2249 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2251 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2255 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2261 return genlmsg_reply(msg
, info
);
2264 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2265 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2266 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2267 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2268 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2269 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2270 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2273 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2275 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2283 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2284 nla
, mntr_flags_policy
))
2287 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2289 *mntrflags
|= (1<<flag
);
2294 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2295 struct net_device
*netdev
, u8 use_4addr
,
2296 enum nl80211_iftype iftype
)
2299 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2305 case NL80211_IFTYPE_AP_VLAN
:
2306 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2309 case NL80211_IFTYPE_STATION
:
2310 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2320 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2322 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2323 struct vif_params params
;
2325 enum nl80211_iftype otype
, ntype
;
2326 struct net_device
*dev
= info
->user_ptr
[1];
2327 u32 _flags
, *flags
= NULL
;
2328 bool change
= false;
2330 memset(¶ms
, 0, sizeof(params
));
2332 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2334 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2335 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2338 if (ntype
> NL80211_IFTYPE_MAX
)
2342 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2343 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2345 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2347 if (netif_running(dev
))
2351 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2352 IEEE80211_MAX_MESH_ID_LEN
);
2353 wdev
->mesh_id_up_len
=
2354 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2355 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2356 wdev
->mesh_id_up_len
);
2360 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2361 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2363 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2367 params
.use_4addr
= -1;
2370 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2371 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2373 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2382 if (flags
&& (*flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2383 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2387 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2391 if (!err
&& params
.use_4addr
!= -1)
2392 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2397 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2399 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2400 struct vif_params params
;
2401 struct wireless_dev
*wdev
;
2402 struct sk_buff
*msg
;
2404 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2407 memset(¶ms
, 0, sizeof(params
));
2409 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2412 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2413 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2414 if (type
> NL80211_IFTYPE_MAX
)
2418 if (!rdev
->ops
->add_virtual_intf
||
2419 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2422 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2423 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2425 if (!is_valid_ether_addr(params
.macaddr
))
2426 return -EADDRNOTAVAIL
;
2429 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2430 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2431 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2436 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2440 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2441 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2444 if (!err
&& (flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2445 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2448 wdev
= rdev_add_virtual_intf(rdev
,
2449 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2450 type
, err
? NULL
: &flags
, ¶ms
);
2453 return PTR_ERR(wdev
);
2457 case NL80211_IFTYPE_MESH_POINT
:
2458 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2461 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2462 IEEE80211_MAX_MESH_ID_LEN
);
2463 wdev
->mesh_id_up_len
=
2464 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2465 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2466 wdev
->mesh_id_up_len
);
2469 case NL80211_IFTYPE_P2P_DEVICE
:
2471 * P2P Device doesn't have a netdev, so doesn't go
2472 * through the netdev notifier and must be added here
2474 mutex_init(&wdev
->mtx
);
2475 INIT_LIST_HEAD(&wdev
->event_list
);
2476 spin_lock_init(&wdev
->event_lock
);
2477 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2478 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2480 wdev
->identifier
= ++rdev
->wdev_id
;
2481 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2482 rdev
->devlist_generation
++;
2488 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2494 return genlmsg_reply(msg
, info
);
2497 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2499 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2500 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2502 if (!rdev
->ops
->del_virtual_intf
)
2506 * If we remove a wireless device without a netdev then clear
2507 * user_ptr[1] so that nl80211_post_doit won't dereference it
2508 * to check if it needs to do dev_put(). Otherwise it crashes
2509 * since the wdev has been freed, unlike with a netdev where
2510 * we need the dev_put() for the netdev to really be freed.
2513 info
->user_ptr
[1] = NULL
;
2515 return rdev_del_virtual_intf(rdev
, wdev
);
2518 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2520 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2521 struct net_device
*dev
= info
->user_ptr
[1];
2524 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2527 if (!rdev
->ops
->set_noack_map
)
2530 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2532 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2535 struct get_key_cookie
{
2536 struct sk_buff
*msg
;
2541 static void get_key_callback(void *c
, struct key_params
*params
)
2544 struct get_key_cookie
*cookie
= c
;
2547 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2548 params
->key_len
, params
->key
)) ||
2550 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2551 params
->seq_len
, params
->seq
)) ||
2553 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2555 goto nla_put_failure
;
2557 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2559 goto nla_put_failure
;
2562 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2563 params
->key_len
, params
->key
)) ||
2565 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2566 params
->seq_len
, params
->seq
)) ||
2568 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2570 goto nla_put_failure
;
2572 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2573 goto nla_put_failure
;
2575 nla_nest_end(cookie
->msg
, key
);
2582 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2584 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2586 struct net_device
*dev
= info
->user_ptr
[1];
2588 const u8
*mac_addr
= NULL
;
2590 struct get_key_cookie cookie
= {
2594 struct sk_buff
*msg
;
2596 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2597 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2602 if (info
->attrs
[NL80211_ATTR_MAC
])
2603 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2605 pairwise
= !!mac_addr
;
2606 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2607 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2608 if (kt
>= NUM_NL80211_KEYTYPES
)
2610 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2611 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2613 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2616 if (!rdev
->ops
->get_key
)
2619 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2623 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2624 NL80211_CMD_NEW_KEY
);
2629 cookie
.idx
= key_idx
;
2631 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2632 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2633 goto nla_put_failure
;
2635 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2636 goto nla_put_failure
;
2638 if (pairwise
&& mac_addr
&&
2639 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2642 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2649 goto nla_put_failure
;
2651 genlmsg_end(msg
, hdr
);
2652 return genlmsg_reply(msg
, info
);
2661 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2663 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2664 struct key_parse key
;
2666 struct net_device
*dev
= info
->user_ptr
[1];
2668 err
= nl80211_parse_key(info
, &key
);
2675 /* only support setting default key */
2676 if (!key
.def
&& !key
.defmgmt
)
2679 wdev_lock(dev
->ieee80211_ptr
);
2682 if (!rdev
->ops
->set_default_key
) {
2687 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2691 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2692 key
.def_uni
, key
.def_multi
);
2697 #ifdef CONFIG_CFG80211_WEXT
2698 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2701 if (key
.def_uni
|| !key
.def_multi
) {
2706 if (!rdev
->ops
->set_default_mgmt_key
) {
2711 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2715 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2719 #ifdef CONFIG_CFG80211_WEXT
2720 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2725 wdev_unlock(dev
->ieee80211_ptr
);
2730 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2732 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2734 struct net_device
*dev
= info
->user_ptr
[1];
2735 struct key_parse key
;
2736 const u8
*mac_addr
= NULL
;
2738 err
= nl80211_parse_key(info
, &key
);
2745 if (info
->attrs
[NL80211_ATTR_MAC
])
2746 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2748 if (key
.type
== -1) {
2750 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2752 key
.type
= NL80211_KEYTYPE_GROUP
;
2756 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2757 key
.type
!= NL80211_KEYTYPE_GROUP
)
2760 if (!rdev
->ops
->add_key
)
2763 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2764 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2768 wdev_lock(dev
->ieee80211_ptr
);
2769 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2771 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2772 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2774 wdev_unlock(dev
->ieee80211_ptr
);
2779 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2783 struct net_device
*dev
= info
->user_ptr
[1];
2784 u8
*mac_addr
= NULL
;
2785 struct key_parse key
;
2787 err
= nl80211_parse_key(info
, &key
);
2791 if (info
->attrs
[NL80211_ATTR_MAC
])
2792 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2794 if (key
.type
== -1) {
2796 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2798 key
.type
= NL80211_KEYTYPE_GROUP
;
2802 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2803 key
.type
!= NL80211_KEYTYPE_GROUP
)
2806 if (!rdev
->ops
->del_key
)
2809 wdev_lock(dev
->ieee80211_ptr
);
2810 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2812 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2813 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2817 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2818 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2821 #ifdef CONFIG_CFG80211_WEXT
2823 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2824 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2825 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2826 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2829 wdev_unlock(dev
->ieee80211_ptr
);
2834 /* This function returns an error or the number of nested attributes */
2835 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2837 struct nlattr
*attr
;
2838 int n_entries
= 0, tmp
;
2840 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2841 if (nla_len(attr
) != ETH_ALEN
)
2851 * This function parses ACL information and allocates memory for ACL data.
2852 * On successful return, the calling function is responsible to free the
2853 * ACL buffer returned by this function.
2855 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2856 struct genl_info
*info
)
2858 enum nl80211_acl_policy acl_policy
;
2859 struct nlattr
*attr
;
2860 struct cfg80211_acl_data
*acl
;
2861 int i
= 0, n_entries
, tmp
;
2863 if (!wiphy
->max_acl_mac_addrs
)
2864 return ERR_PTR(-EOPNOTSUPP
);
2866 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2867 return ERR_PTR(-EINVAL
);
2869 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2870 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2871 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2872 return ERR_PTR(-EINVAL
);
2874 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2875 return ERR_PTR(-EINVAL
);
2877 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2879 return ERR_PTR(n_entries
);
2881 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2882 return ERR_PTR(-ENOTSUPP
);
2884 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2887 return ERR_PTR(-ENOMEM
);
2889 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2890 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2894 acl
->n_acl_entries
= n_entries
;
2895 acl
->acl_policy
= acl_policy
;
2900 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2903 struct net_device
*dev
= info
->user_ptr
[1];
2904 struct cfg80211_acl_data
*acl
;
2907 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2908 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2911 if (!dev
->ieee80211_ptr
->beacon_interval
)
2914 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2916 return PTR_ERR(acl
);
2918 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2925 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
2926 struct cfg80211_beacon_data
*bcn
)
2928 bool haveinfo
= false;
2930 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2931 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
2932 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2933 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2936 memset(bcn
, 0, sizeof(*bcn
));
2938 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2939 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2940 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2946 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2947 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2948 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2955 if (attrs
[NL80211_ATTR_IE
]) {
2956 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
2957 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
2960 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2961 bcn
->proberesp_ies
=
2962 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2963 bcn
->proberesp_ies_len
=
2964 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2967 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2968 bcn
->assocresp_ies
=
2969 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2970 bcn
->assocresp_ies_len
=
2971 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2974 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
2975 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
2976 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
2982 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2983 struct cfg80211_ap_settings
*params
)
2985 struct wireless_dev
*wdev
;
2988 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2989 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2990 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2993 if (!wdev
->preset_chandef
.chan
)
2996 params
->chandef
= wdev
->preset_chandef
;
3004 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3005 enum nl80211_auth_type auth_type
,
3006 enum nl80211_commands cmd
)
3008 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3012 case NL80211_CMD_AUTHENTICATE
:
3013 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3014 auth_type
== NL80211_AUTHTYPE_SAE
)
3017 case NL80211_CMD_CONNECT
:
3018 case NL80211_CMD_START_AP
:
3019 /* SAE not supported yet */
3020 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3028 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3030 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3031 struct net_device
*dev
= info
->user_ptr
[1];
3032 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3033 struct cfg80211_ap_settings params
;
3035 u8 radar_detect_width
= 0;
3037 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3038 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3041 if (!rdev
->ops
->start_ap
)
3044 if (wdev
->beacon_interval
)
3047 memset(¶ms
, 0, sizeof(params
));
3049 /* these are required for START_AP */
3050 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3051 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3052 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3055 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3059 params
.beacon_interval
=
3060 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3061 params
.dtim_period
=
3062 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3064 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3069 * In theory, some of these attributes should be required here
3070 * but since they were not used when the command was originally
3071 * added, keep them optional for old user space programs to let
3072 * them continue to work with drivers that do not need the
3073 * additional information -- drivers must check!
3075 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3076 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3078 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3079 if (params
.ssid_len
== 0 ||
3080 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3084 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3085 params
.hidden_ssid
= nla_get_u32(
3086 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3087 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3088 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3089 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3093 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3095 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3096 params
.auth_type
= nla_get_u32(
3097 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3098 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3099 NL80211_CMD_START_AP
))
3102 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3104 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3105 NL80211_MAX_NR_CIPHER_SUITES
);
3109 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3110 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3112 params
.inactivity_timeout
= nla_get_u16(
3113 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3116 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3117 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3119 params
.p2p_ctwindow
=
3120 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3121 if (params
.p2p_ctwindow
> 127)
3123 if (params
.p2p_ctwindow
!= 0 &&
3124 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3128 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3131 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3133 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3136 params
.p2p_opp_ps
= tmp
;
3137 if (params
.p2p_opp_ps
!= 0 &&
3138 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3142 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3143 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3146 } else if (wdev
->preset_chandef
.chan
) {
3147 params
.chandef
= wdev
->preset_chandef
;
3148 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3151 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3154 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3158 radar_detect_width
= BIT(params
.chandef
.width
);
3159 params
.radar_required
= true;
3162 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3163 params
.chandef
.chan
,
3165 radar_detect_width
);
3169 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3170 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3171 if (IS_ERR(params
.acl
))
3172 return PTR_ERR(params
.acl
);
3175 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3177 wdev
->preset_chandef
= params
.chandef
;
3178 wdev
->beacon_interval
= params
.beacon_interval
;
3179 wdev
->channel
= params
.chandef
.chan
;
3180 wdev
->ssid_len
= params
.ssid_len
;
3181 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3189 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3191 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3192 struct net_device
*dev
= info
->user_ptr
[1];
3193 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3194 struct cfg80211_beacon_data params
;
3197 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3198 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3201 if (!rdev
->ops
->change_beacon
)
3204 if (!wdev
->beacon_interval
)
3207 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3211 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3214 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3216 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3217 struct net_device
*dev
= info
->user_ptr
[1];
3219 return cfg80211_stop_ap(rdev
, dev
);
3222 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3223 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3224 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3225 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3226 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3227 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3228 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3231 static int parse_station_flags(struct genl_info
*info
,
3232 enum nl80211_iftype iftype
,
3233 struct station_parameters
*params
)
3235 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3240 * Try parsing the new attribute first so userspace
3241 * can specify both for older kernels.
3243 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3245 struct nl80211_sta_flag_update
*sta_flags
;
3247 sta_flags
= nla_data(nla
);
3248 params
->sta_flags_mask
= sta_flags
->mask
;
3249 params
->sta_flags_set
= sta_flags
->set
;
3250 params
->sta_flags_set
&= params
->sta_flags_mask
;
3251 if ((params
->sta_flags_mask
|
3252 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3257 /* if present, parse the old attribute */
3259 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3263 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3264 nla
, sta_flags_policy
))
3268 * Only allow certain flags for interface types so that
3269 * other attributes are silently ignored. Remember that
3270 * this is backward compatibility code with old userspace
3271 * and shouldn't be hit in other cases anyway.
3274 case NL80211_IFTYPE_AP
:
3275 case NL80211_IFTYPE_AP_VLAN
:
3276 case NL80211_IFTYPE_P2P_GO
:
3277 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3278 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3279 BIT(NL80211_STA_FLAG_WME
) |
3280 BIT(NL80211_STA_FLAG_MFP
);
3282 case NL80211_IFTYPE_P2P_CLIENT
:
3283 case NL80211_IFTYPE_STATION
:
3284 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3285 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3287 case NL80211_IFTYPE_MESH_POINT
:
3288 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3289 BIT(NL80211_STA_FLAG_MFP
) |
3290 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3295 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3297 params
->sta_flags_set
|= (1<<flag
);
3299 /* no longer support new API additions in old API */
3300 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3308 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3311 struct nlattr
*rate
;
3315 rate
= nla_nest_start(msg
, attr
);
3319 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3320 bitrate
= cfg80211_calculate_bitrate(info
);
3321 /* report 16-bit bitrate only if we can */
3322 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3324 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3326 if (bitrate_compat
> 0 &&
3327 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3330 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3331 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3333 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3334 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3336 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3337 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3339 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3340 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3342 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3344 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3345 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3347 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3348 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3350 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3351 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3353 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3354 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3356 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3357 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3361 nla_nest_end(msg
, rate
);
3365 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3374 attr
= nla_nest_start(msg
, id
);
3378 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3379 if (!(mask
& BIT(i
)))
3382 if (nla_put_u8(msg
, i
, signal
[i
]))
3386 nla_nest_end(msg
, attr
);
3391 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3393 struct cfg80211_registered_device
*rdev
,
3394 struct net_device
*dev
,
3395 const u8
*mac_addr
, struct station_info
*sinfo
)
3398 struct nlattr
*sinfoattr
, *bss_param
;
3400 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3404 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3405 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3406 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3407 goto nla_put_failure
;
3409 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3411 goto nla_put_failure
;
3412 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3413 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3414 sinfo
->connected_time
))
3415 goto nla_put_failure
;
3416 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3417 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3418 sinfo
->inactive_time
))
3419 goto nla_put_failure
;
3420 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3421 STATION_INFO_RX_BYTES64
)) &&
3422 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3423 (u32
)sinfo
->rx_bytes
))
3424 goto nla_put_failure
;
3425 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3426 STATION_INFO_TX_BYTES64
)) &&
3427 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3428 (u32
)sinfo
->tx_bytes
))
3429 goto nla_put_failure
;
3430 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3431 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3433 goto nla_put_failure
;
3434 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3435 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3437 goto nla_put_failure
;
3438 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3439 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3440 goto nla_put_failure
;
3441 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3442 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3443 goto nla_put_failure
;
3444 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3445 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3446 sinfo
->plink_state
))
3447 goto nla_put_failure
;
3448 switch (rdev
->wiphy
.signal_type
) {
3449 case CFG80211_SIGNAL_TYPE_MBM
:
3450 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3451 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3453 goto nla_put_failure
;
3454 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3455 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3457 goto nla_put_failure
;
3462 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL
) {
3463 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3464 sinfo
->chain_signal
,
3465 NL80211_STA_INFO_CHAIN_SIGNAL
))
3466 goto nla_put_failure
;
3468 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL_AVG
) {
3469 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3470 sinfo
->chain_signal_avg
,
3471 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3472 goto nla_put_failure
;
3474 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3475 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3476 NL80211_STA_INFO_TX_BITRATE
))
3477 goto nla_put_failure
;
3479 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3480 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3481 NL80211_STA_INFO_RX_BITRATE
))
3482 goto nla_put_failure
;
3484 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3485 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3487 goto nla_put_failure
;
3488 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3489 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3491 goto nla_put_failure
;
3492 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3493 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3495 goto nla_put_failure
;
3496 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3497 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3499 goto nla_put_failure
;
3500 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3501 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3502 sinfo
->beacon_loss_count
))
3503 goto nla_put_failure
;
3504 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3505 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3507 goto nla_put_failure
;
3508 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3509 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3511 goto nla_put_failure
;
3512 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3513 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3515 goto nla_put_failure
;
3516 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3517 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3519 goto nla_put_failure
;
3521 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3522 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3523 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3524 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3525 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3526 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3527 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3528 sinfo
->bss_param
.dtim_period
) ||
3529 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3530 sinfo
->bss_param
.beacon_interval
))
3531 goto nla_put_failure
;
3533 nla_nest_end(msg
, bss_param
);
3535 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3536 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3537 sizeof(struct nl80211_sta_flag_update
),
3539 goto nla_put_failure
;
3540 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3541 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3543 goto nla_put_failure
;
3544 nla_nest_end(msg
, sinfoattr
);
3546 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3547 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3548 sinfo
->assoc_req_ies
))
3549 goto nla_put_failure
;
3551 return genlmsg_end(msg
, hdr
);
3554 genlmsg_cancel(msg
, hdr
);
3558 static int nl80211_dump_station(struct sk_buff
*skb
,
3559 struct netlink_callback
*cb
)
3561 struct station_info sinfo
;
3562 struct cfg80211_registered_device
*dev
;
3563 struct wireless_dev
*wdev
;
3564 u8 mac_addr
[ETH_ALEN
];
3565 int sta_idx
= cb
->args
[2];
3568 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3572 if (!wdev
->netdev
) {
3577 if (!dev
->ops
->dump_station
) {
3583 memset(&sinfo
, 0, sizeof(sinfo
));
3584 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3591 if (nl80211_send_station(skb
,
3592 NETLINK_CB(cb
->skb
).portid
,
3593 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3594 dev
, wdev
->netdev
, mac_addr
,
3603 cb
->args
[2] = sta_idx
;
3606 nl80211_finish_wdev_dump(dev
);
3611 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3613 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3614 struct net_device
*dev
= info
->user_ptr
[1];
3615 struct station_info sinfo
;
3616 struct sk_buff
*msg
;
3617 u8
*mac_addr
= NULL
;
3620 memset(&sinfo
, 0, sizeof(sinfo
));
3622 if (!info
->attrs
[NL80211_ATTR_MAC
])
3625 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3627 if (!rdev
->ops
->get_station
)
3630 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3634 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3638 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3639 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3644 return genlmsg_reply(msg
, info
);
3647 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3648 struct station_parameters
*params
,
3649 enum cfg80211_station_type statype
)
3651 if (params
->listen_interval
!= -1)
3656 /* When you run into this, adjust the code below for the new flag */
3657 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3660 case CFG80211_STA_MESH_PEER_KERNEL
:
3661 case CFG80211_STA_MESH_PEER_USER
:
3663 * No ignoring the TDLS flag here -- the userspace mesh
3664 * code doesn't have the bug of including TDLS in the
3667 if (params
->sta_flags_mask
&
3668 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3669 BIT(NL80211_STA_FLAG_MFP
) |
3670 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3673 case CFG80211_STA_TDLS_PEER_SETUP
:
3674 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3675 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3677 /* ignore since it can't change */
3678 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3681 /* disallow mesh-specific things */
3682 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3684 if (params
->local_pm
)
3686 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3690 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3691 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3692 /* TDLS can't be set, ... */
3693 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3696 * ... but don't bother the driver with it. This works around
3697 * a hostapd/wpa_supplicant issue -- it always includes the
3698 * TLDS_PEER flag in the mask even for AP mode.
3700 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3703 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3704 /* reject other things that can't change */
3705 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3707 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3709 if (params
->supported_rates
)
3711 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3715 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3721 case CFG80211_STA_AP_MLME_CLIENT
:
3722 /* Use this only for authorizing/unauthorizing a station */
3723 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3726 case CFG80211_STA_AP_CLIENT
:
3727 /* accept only the listed bits */
3728 if (params
->sta_flags_mask
&
3729 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3730 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3731 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3732 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3733 BIT(NL80211_STA_FLAG_WME
) |
3734 BIT(NL80211_STA_FLAG_MFP
)))
3737 /* but authenticated/associated only if driver handles it */
3738 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3739 params
->sta_flags_mask
&
3740 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3741 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3744 case CFG80211_STA_IBSS
:
3745 case CFG80211_STA_AP_STA
:
3746 /* reject any changes other than AUTHORIZED */
3747 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3750 case CFG80211_STA_TDLS_PEER_SETUP
:
3751 /* reject any changes other than AUTHORIZED or WME */
3752 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3753 BIT(NL80211_STA_FLAG_WME
)))
3755 /* force (at least) rates when authorizing */
3756 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3757 !params
->supported_rates
)
3760 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3761 /* reject any changes */
3763 case CFG80211_STA_MESH_PEER_KERNEL
:
3764 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3767 case CFG80211_STA_MESH_PEER_USER
:
3768 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3775 EXPORT_SYMBOL(cfg80211_check_station_change
);
3778 * Get vlan interface making sure it is running and on the right wiphy.
3780 static struct net_device
*get_vlan(struct genl_info
*info
,
3781 struct cfg80211_registered_device
*rdev
)
3783 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3784 struct net_device
*v
;
3790 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3792 return ERR_PTR(-ENODEV
);
3794 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3799 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3800 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3801 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3806 if (!netif_running(v
)) {
3814 return ERR_PTR(ret
);
3817 static struct nla_policy
3818 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3819 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3820 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3823 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3824 struct station_parameters
*params
)
3826 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3830 /* parse WME attributes if present */
3831 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3834 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3835 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3836 nl80211_sta_wme_policy
);
3840 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3841 params
->uapsd_queues
= nla_get_u8(
3842 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3843 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3846 if (tb
[NL80211_STA_WME_MAX_SP
])
3847 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3849 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3852 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3857 static int nl80211_set_station_tdls(struct genl_info
*info
,
3858 struct station_parameters
*params
)
3860 /* Dummy STA entry gets updated once the peer capabilities are known */
3861 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
3862 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
3863 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3865 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3866 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3868 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3870 return nl80211_parse_sta_wme(info
, params
);
3873 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3875 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3876 struct net_device
*dev
= info
->user_ptr
[1];
3877 struct station_parameters params
;
3881 memset(¶ms
, 0, sizeof(params
));
3883 params
.listen_interval
= -1;
3885 if (!rdev
->ops
->change_station
)
3888 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3891 if (!info
->attrs
[NL80211_ATTR_MAC
])
3894 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3896 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3897 params
.supported_rates
=
3898 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3899 params
.supported_rates_len
=
3900 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3903 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3905 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3906 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3909 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3911 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3912 params
.ext_capab_len
=
3913 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3916 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3919 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3922 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3923 params
.plink_action
=
3924 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3925 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3929 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3930 params
.plink_state
=
3931 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3932 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3934 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3937 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3938 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3939 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3941 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3942 pm
> NL80211_MESH_POWER_MAX
)
3945 params
.local_pm
= pm
;
3948 /* Include parameters for TDLS peer (will check later) */
3949 err
= nl80211_set_station_tdls(info
, ¶ms
);
3953 params
.vlan
= get_vlan(info
, rdev
);
3954 if (IS_ERR(params
.vlan
))
3955 return PTR_ERR(params
.vlan
);
3957 switch (dev
->ieee80211_ptr
->iftype
) {
3958 case NL80211_IFTYPE_AP
:
3959 case NL80211_IFTYPE_AP_VLAN
:
3960 case NL80211_IFTYPE_P2P_GO
:
3961 case NL80211_IFTYPE_P2P_CLIENT
:
3962 case NL80211_IFTYPE_STATION
:
3963 case NL80211_IFTYPE_ADHOC
:
3964 case NL80211_IFTYPE_MESH_POINT
:
3971 /* driver will call cfg80211_check_station_change() */
3972 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3976 dev_put(params
.vlan
);
3981 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3983 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3985 struct net_device
*dev
= info
->user_ptr
[1];
3986 struct station_parameters params
;
3987 u8
*mac_addr
= NULL
;
3989 memset(¶ms
, 0, sizeof(params
));
3991 if (!rdev
->ops
->add_station
)
3994 if (!info
->attrs
[NL80211_ATTR_MAC
])
3997 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4000 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4003 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4004 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4007 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4008 params
.supported_rates
=
4009 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4010 params
.supported_rates_len
=
4011 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4012 params
.listen_interval
=
4013 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4015 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4016 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4018 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4019 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4022 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4024 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4025 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4028 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4030 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4031 params
.ext_capab_len
=
4032 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4035 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4037 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4039 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4041 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4043 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4044 params
.plink_action
=
4045 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4046 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4050 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4054 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4057 /* When you run into this, adjust the code below for the new flag */
4058 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4060 switch (dev
->ieee80211_ptr
->iftype
) {
4061 case NL80211_IFTYPE_AP
:
4062 case NL80211_IFTYPE_AP_VLAN
:
4063 case NL80211_IFTYPE_P2P_GO
:
4064 /* ignore WME attributes if iface/sta is not capable */
4065 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4066 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4067 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4069 /* TDLS peers cannot be added */
4070 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4071 info
->attrs
[NL80211_ATTR_PEER_AID
])
4073 /* but don't bother the driver with it */
4074 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4076 /* allow authenticated/associated only if driver handles it */
4077 if (!(rdev
->wiphy
.features
&
4078 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4079 params
.sta_flags_mask
&
4080 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4081 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4084 /* must be last in here for error handling */
4085 params
.vlan
= get_vlan(info
, rdev
);
4086 if (IS_ERR(params
.vlan
))
4087 return PTR_ERR(params
.vlan
);
4089 case NL80211_IFTYPE_MESH_POINT
:
4090 /* ignore uAPSD data */
4091 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4093 /* associated is disallowed */
4094 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4096 /* TDLS peers cannot be added */
4097 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4098 info
->attrs
[NL80211_ATTR_PEER_AID
])
4101 case NL80211_IFTYPE_STATION
:
4102 case NL80211_IFTYPE_P2P_CLIENT
:
4103 /* ignore uAPSD data */
4104 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4106 /* these are disallowed */
4107 if (params
.sta_flags_mask
&
4108 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4109 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4111 /* Only TDLS peers can be added */
4112 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4114 /* Can only add if TDLS ... */
4115 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4117 /* ... with external setup is supported */
4118 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4121 * Older wpa_supplicant versions always mark the TDLS peer
4122 * as authorized, but it shouldn't yet be.
4124 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4130 /* be aware of params.vlan when changing code here */
4132 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4135 dev_put(params
.vlan
);
4139 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4141 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4142 struct net_device
*dev
= info
->user_ptr
[1];
4143 u8
*mac_addr
= NULL
;
4145 if (info
->attrs
[NL80211_ATTR_MAC
])
4146 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4148 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4149 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4150 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4151 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4154 if (!rdev
->ops
->del_station
)
4157 return rdev_del_station(rdev
, dev
, mac_addr
);
4160 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4161 int flags
, struct net_device
*dev
,
4162 u8
*dst
, u8
*next_hop
,
4163 struct mpath_info
*pinfo
)
4166 struct nlattr
*pinfoattr
;
4168 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4172 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4173 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4174 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4175 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4176 goto nla_put_failure
;
4178 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4180 goto nla_put_failure
;
4181 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4182 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4184 goto nla_put_failure
;
4185 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4186 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4187 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4188 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4190 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4191 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4193 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4194 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4196 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4197 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4198 pinfo
->discovery_timeout
)) ||
4199 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4200 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4201 pinfo
->discovery_retries
)))
4202 goto nla_put_failure
;
4204 nla_nest_end(msg
, pinfoattr
);
4206 return genlmsg_end(msg
, hdr
);
4209 genlmsg_cancel(msg
, hdr
);
4213 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4214 struct netlink_callback
*cb
)
4216 struct mpath_info pinfo
;
4217 struct cfg80211_registered_device
*dev
;
4218 struct wireless_dev
*wdev
;
4220 u8 next_hop
[ETH_ALEN
];
4221 int path_idx
= cb
->args
[2];
4224 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4228 if (!dev
->ops
->dump_mpath
) {
4233 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4239 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4246 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4247 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4248 wdev
->netdev
, dst
, next_hop
,
4257 cb
->args
[2] = path_idx
;
4260 nl80211_finish_wdev_dump(dev
);
4264 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4266 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4268 struct net_device
*dev
= info
->user_ptr
[1];
4269 struct mpath_info pinfo
;
4270 struct sk_buff
*msg
;
4272 u8 next_hop
[ETH_ALEN
];
4274 memset(&pinfo
, 0, sizeof(pinfo
));
4276 if (!info
->attrs
[NL80211_ATTR_MAC
])
4279 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4281 if (!rdev
->ops
->get_mpath
)
4284 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4287 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4291 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4295 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4296 dev
, dst
, next_hop
, &pinfo
) < 0) {
4301 return genlmsg_reply(msg
, info
);
4304 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4306 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4307 struct net_device
*dev
= info
->user_ptr
[1];
4309 u8
*next_hop
= NULL
;
4311 if (!info
->attrs
[NL80211_ATTR_MAC
])
4314 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4317 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4318 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4320 if (!rdev
->ops
->change_mpath
)
4323 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4326 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4329 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4331 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4332 struct net_device
*dev
= info
->user_ptr
[1];
4334 u8
*next_hop
= NULL
;
4336 if (!info
->attrs
[NL80211_ATTR_MAC
])
4339 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4342 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4343 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4345 if (!rdev
->ops
->add_mpath
)
4348 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4351 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4354 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4356 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4357 struct net_device
*dev
= info
->user_ptr
[1];
4360 if (info
->attrs
[NL80211_ATTR_MAC
])
4361 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4363 if (!rdev
->ops
->del_mpath
)
4366 return rdev_del_mpath(rdev
, dev
, dst
);
4369 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4371 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4372 struct net_device
*dev
= info
->user_ptr
[1];
4373 struct bss_parameters params
;
4375 memset(¶ms
, 0, sizeof(params
));
4376 /* default to not changing parameters */
4377 params
.use_cts_prot
= -1;
4378 params
.use_short_preamble
= -1;
4379 params
.use_short_slot_time
= -1;
4380 params
.ap_isolate
= -1;
4381 params
.ht_opmode
= -1;
4382 params
.p2p_ctwindow
= -1;
4383 params
.p2p_opp_ps
= -1;
4385 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4386 params
.use_cts_prot
=
4387 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4388 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4389 params
.use_short_preamble
=
4390 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4391 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4392 params
.use_short_slot_time
=
4393 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4394 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4395 params
.basic_rates
=
4396 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4397 params
.basic_rates_len
=
4398 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4400 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4401 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4402 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4404 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4406 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4407 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4409 params
.p2p_ctwindow
=
4410 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4411 if (params
.p2p_ctwindow
< 0)
4413 if (params
.p2p_ctwindow
!= 0 &&
4414 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4418 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4421 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4423 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4426 params
.p2p_opp_ps
= tmp
;
4427 if (params
.p2p_opp_ps
&&
4428 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4432 if (!rdev
->ops
->change_bss
)
4435 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4436 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4439 return rdev_change_bss(rdev
, dev
, ¶ms
);
4442 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4443 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4444 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4445 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4446 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4447 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4448 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4451 static int parse_reg_rule(struct nlattr
*tb
[],
4452 struct ieee80211_reg_rule
*reg_rule
)
4454 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4455 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4457 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4459 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4461 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4463 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4465 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4468 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4470 freq_range
->start_freq_khz
=
4471 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4472 freq_range
->end_freq_khz
=
4473 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4474 freq_range
->max_bandwidth_khz
=
4475 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4477 power_rule
->max_eirp
=
4478 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4480 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4481 power_rule
->max_antenna_gain
=
4482 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4487 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4491 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4494 * You should only get this when cfg80211 hasn't yet initialized
4495 * completely when built-in to the kernel right between the time
4496 * window between nl80211_init() and regulatory_init(), if that is
4499 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4500 return -EINPROGRESS
;
4502 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4505 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4507 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4508 user_reg_hint_type
=
4509 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4511 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4513 switch (user_reg_hint_type
) {
4514 case NL80211_USER_REG_HINT_USER
:
4515 case NL80211_USER_REG_HINT_CELL_BASE
:
4521 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4526 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4527 struct genl_info
*info
)
4529 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4530 struct net_device
*dev
= info
->user_ptr
[1];
4531 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4532 struct mesh_config cur_params
;
4535 struct nlattr
*pinfoattr
;
4536 struct sk_buff
*msg
;
4538 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4541 if (!rdev
->ops
->get_mesh_config
)
4545 /* If not connected, get default parameters */
4546 if (!wdev
->mesh_id_len
)
4547 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4549 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4555 /* Draw up a netlink message to send back */
4556 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4559 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4560 NL80211_CMD_GET_MESH_CONFIG
);
4563 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4565 goto nla_put_failure
;
4566 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4567 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4568 cur_params
.dot11MeshRetryTimeout
) ||
4569 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4570 cur_params
.dot11MeshConfirmTimeout
) ||
4571 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4572 cur_params
.dot11MeshHoldingTimeout
) ||
4573 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4574 cur_params
.dot11MeshMaxPeerLinks
) ||
4575 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4576 cur_params
.dot11MeshMaxRetries
) ||
4577 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4578 cur_params
.dot11MeshTTL
) ||
4579 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4580 cur_params
.element_ttl
) ||
4581 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4582 cur_params
.auto_open_plinks
) ||
4583 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4584 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4585 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4586 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4587 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4588 cur_params
.path_refresh_time
) ||
4589 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4590 cur_params
.min_discovery_timeout
) ||
4591 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4592 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4593 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4594 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4595 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4596 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4597 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4598 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4599 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4600 cur_params
.dot11MeshHWMPRootMode
) ||
4601 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4602 cur_params
.dot11MeshHWMPRannInterval
) ||
4603 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4604 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4605 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4606 cur_params
.dot11MeshForwarding
) ||
4607 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4608 cur_params
.rssi_threshold
) ||
4609 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4610 cur_params
.ht_opmode
) ||
4611 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4612 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4613 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4614 cur_params
.dot11MeshHWMProotInterval
) ||
4615 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4616 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4617 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4618 cur_params
.power_mode
) ||
4619 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4620 cur_params
.dot11MeshAwakeWindowDuration
) ||
4621 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4622 cur_params
.plink_timeout
))
4623 goto nla_put_failure
;
4624 nla_nest_end(msg
, pinfoattr
);
4625 genlmsg_end(msg
, hdr
);
4626 return genlmsg_reply(msg
, info
);
4629 genlmsg_cancel(msg
, hdr
);
4635 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4636 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4637 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4638 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4639 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4640 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4641 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4642 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4643 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4644 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4645 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4646 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4647 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4648 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4649 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4650 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4651 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4652 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4653 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4654 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4655 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4656 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4657 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4658 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4659 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4660 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4661 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4662 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4663 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
4666 static const struct nla_policy
4667 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4668 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4669 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4670 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4671 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4672 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
4673 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4674 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4675 .len
= IEEE80211_MAX_DATA_LEN
},
4676 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4679 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4680 struct mesh_config
*cfg
,
4683 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4686 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4689 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4691 cfg->param = fn(tb[attr]); \
4692 mask |= (1 << (attr - 1)); \
4697 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4699 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4700 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4701 nl80211_meshconf_params_policy
))
4704 /* This makes sure that there aren't more than 32 mesh config
4705 * parameters (otherwise our bitfield scheme would not work.) */
4706 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4708 /* Fill in the params struct */
4709 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4710 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4712 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4713 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4715 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4716 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4718 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4719 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4721 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4722 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4724 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4725 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4726 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4727 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4729 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4730 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4732 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4734 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4736 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4737 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4739 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4740 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4742 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4743 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4745 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4747 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4749 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4751 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4753 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4755 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4758 dot11MeshHWMPnetDiameterTraversalTime
,
4760 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4762 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4763 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4765 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4766 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4768 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4769 dot11MeshGateAnnouncementProtocol
, 0, 1,
4770 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4772 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4773 mask
, NL80211_MESHCONF_FORWARDING
,
4775 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
4776 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4778 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4779 mask
, NL80211_MESHCONF_HT_OPMODE
,
4781 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4783 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4785 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4786 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4788 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4789 dot11MeshHWMPconfirmationInterval
,
4791 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4793 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4794 NL80211_MESH_POWER_ACTIVE
,
4795 NL80211_MESH_POWER_MAX
,
4796 mask
, NL80211_MESHCONF_POWER_MODE
,
4798 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4800 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4801 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 1, 0xffffffff,
4802 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4809 #undef FILL_IN_MESH_PARAM_IF_SET
4812 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4813 struct mesh_setup
*setup
)
4815 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4816 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4818 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4820 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4821 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4822 nl80211_mesh_setup_params_policy
))
4825 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4826 setup
->sync_method
=
4827 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4828 IEEE80211_SYNC_METHOD_VENDOR
:
4829 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4831 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4832 setup
->path_sel_proto
=
4833 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4834 IEEE80211_PATH_PROTOCOL_VENDOR
:
4835 IEEE80211_PATH_PROTOCOL_HWMP
;
4837 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4838 setup
->path_metric
=
4839 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4840 IEEE80211_PATH_METRIC_VENDOR
:
4841 IEEE80211_PATH_METRIC_AIRTIME
;
4844 if (tb
[NL80211_MESH_SETUP_IE
]) {
4845 struct nlattr
*ieattr
=
4846 tb
[NL80211_MESH_SETUP_IE
];
4847 if (!is_valid_ie_attr(ieattr
))
4849 setup
->ie
= nla_data(ieattr
);
4850 setup
->ie_len
= nla_len(ieattr
);
4852 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4853 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4855 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4856 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4857 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4858 if (setup
->is_secure
)
4859 setup
->user_mpm
= true;
4861 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
4862 if (!setup
->user_mpm
)
4865 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
4871 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4872 struct genl_info
*info
)
4874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4875 struct net_device
*dev
= info
->user_ptr
[1];
4876 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4877 struct mesh_config cfg
;
4881 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4884 if (!rdev
->ops
->update_mesh_config
)
4887 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4892 if (!wdev
->mesh_id_len
)
4896 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4903 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4905 const struct ieee80211_regdomain
*regdom
;
4906 struct sk_buff
*msg
;
4908 struct nlattr
*nl_reg_rules
;
4911 if (!cfg80211_regdomain
)
4914 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4918 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4919 NL80211_CMD_GET_REG
);
4923 if (reg_last_request_cell_base() &&
4924 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4925 NL80211_USER_REG_HINT_CELL_BASE
))
4926 goto nla_put_failure
;
4929 regdom
= rcu_dereference(cfg80211_regdomain
);
4931 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4932 (regdom
->dfs_region
&&
4933 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4934 goto nla_put_failure_rcu
;
4936 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4938 goto nla_put_failure_rcu
;
4940 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4941 struct nlattr
*nl_reg_rule
;
4942 const struct ieee80211_reg_rule
*reg_rule
;
4943 const struct ieee80211_freq_range
*freq_range
;
4944 const struct ieee80211_power_rule
*power_rule
;
4946 reg_rule
= ®dom
->reg_rules
[i
];
4947 freq_range
= ®_rule
->freq_range
;
4948 power_rule
= ®_rule
->power_rule
;
4950 nl_reg_rule
= nla_nest_start(msg
, i
);
4952 goto nla_put_failure_rcu
;
4954 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4956 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4957 freq_range
->start_freq_khz
) ||
4958 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4959 freq_range
->end_freq_khz
) ||
4960 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4961 freq_range
->max_bandwidth_khz
) ||
4962 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4963 power_rule
->max_antenna_gain
) ||
4964 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4965 power_rule
->max_eirp
))
4966 goto nla_put_failure_rcu
;
4968 nla_nest_end(msg
, nl_reg_rule
);
4972 nla_nest_end(msg
, nl_reg_rules
);
4974 genlmsg_end(msg
, hdr
);
4975 return genlmsg_reply(msg
, info
);
4977 nla_put_failure_rcu
:
4980 genlmsg_cancel(msg
, hdr
);
4986 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4988 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4989 struct nlattr
*nl_reg_rule
;
4990 char *alpha2
= NULL
;
4991 int rem_reg_rules
= 0, r
= 0;
4992 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4994 struct ieee80211_regdomain
*rd
= NULL
;
4996 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4999 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5002 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5004 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5005 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5007 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5010 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5014 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5015 num_rules
* sizeof(struct ieee80211_reg_rule
);
5017 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5021 rd
->n_reg_rules
= num_rules
;
5022 rd
->alpha2
[0] = alpha2
[0];
5023 rd
->alpha2
[1] = alpha2
[1];
5026 * Disable DFS master mode if the DFS region was
5027 * not supported or known on this kernel.
5029 if (reg_supported_dfs_region(dfs_region
))
5030 rd
->dfs_region
= dfs_region
;
5032 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5034 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5035 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5037 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5043 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5050 /* set_regdom took ownership */
5058 static int validate_scan_freqs(struct nlattr
*freqs
)
5060 struct nlattr
*attr1
, *attr2
;
5061 int n_channels
= 0, tmp1
, tmp2
;
5063 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5066 * Some hardware has a limited channel list for
5067 * scanning, and it is pretty much nonsensical
5068 * to scan for a channel twice, so disallow that
5069 * and don't require drivers to check that the
5070 * channel list they get isn't longer than what
5071 * they can scan, as long as they can scan all
5072 * the channels they registered at once.
5074 nla_for_each_nested(attr2
, freqs
, tmp2
)
5075 if (attr1
!= attr2
&&
5076 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5083 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5085 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5086 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5087 struct cfg80211_scan_request
*request
;
5088 struct nlattr
*attr
;
5089 struct wiphy
*wiphy
;
5090 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5093 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5096 wiphy
= &rdev
->wiphy
;
5098 if (!rdev
->ops
->scan
)
5101 if (rdev
->scan_req
) {
5106 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5107 n_channels
= validate_scan_freqs(
5108 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5114 enum ieee80211_band band
;
5117 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5118 if (wiphy
->bands
[band
])
5119 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5122 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5123 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5126 if (n_ssids
> wiphy
->max_scan_ssids
) {
5131 if (info
->attrs
[NL80211_ATTR_IE
])
5132 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5136 if (ie_len
> wiphy
->max_scan_ie_len
) {
5141 request
= kzalloc(sizeof(*request
)
5142 + sizeof(*request
->ssids
) * n_ssids
5143 + sizeof(*request
->channels
) * n_channels
5144 + ie_len
, GFP_KERNEL
);
5151 request
->ssids
= (void *)&request
->channels
[n_channels
];
5152 request
->n_ssids
= n_ssids
;
5155 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5157 request
->ie
= (void *)(request
->channels
+ n_channels
);
5161 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5162 /* user specified, bail out if channel not found */
5163 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5164 struct ieee80211_channel
*chan
;
5166 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5173 /* ignore disabled channels */
5174 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5177 request
->channels
[i
] = chan
;
5181 enum ieee80211_band band
;
5184 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5186 if (!wiphy
->bands
[band
])
5188 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5189 struct ieee80211_channel
*chan
;
5191 chan
= &wiphy
->bands
[band
]->channels
[j
];
5193 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5196 request
->channels
[i
] = chan
;
5207 request
->n_channels
= i
;
5210 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5211 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5212 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5216 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5217 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5222 if (info
->attrs
[NL80211_ATTR_IE
]) {
5223 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5224 memcpy((void *)request
->ie
,
5225 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5229 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5230 if (wiphy
->bands
[i
])
5232 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5234 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5235 nla_for_each_nested(attr
,
5236 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5238 enum ieee80211_band band
= nla_type(attr
);
5240 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5244 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5247 &request
->rates
[band
]);
5253 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5254 request
->flags
= nla_get_u32(
5255 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5256 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5257 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5258 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5259 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5266 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5268 request
->wdev
= wdev
;
5269 request
->wiphy
= &rdev
->wiphy
;
5270 request
->scan_start
= jiffies
;
5272 rdev
->scan_req
= request
;
5273 err
= rdev_scan(rdev
, request
);
5276 nl80211_send_scan_start(rdev
, wdev
);
5278 dev_hold(wdev
->netdev
);
5281 rdev
->scan_req
= NULL
;
5289 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5290 struct genl_info
*info
)
5292 struct cfg80211_sched_scan_request
*request
;
5293 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5294 struct net_device
*dev
= info
->user_ptr
[1];
5295 struct nlattr
*attr
;
5296 struct wiphy
*wiphy
;
5297 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5299 enum ieee80211_band band
;
5301 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5303 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5304 !rdev
->ops
->sched_scan_start
)
5307 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5310 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5313 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5317 wiphy
= &rdev
->wiphy
;
5319 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5320 n_channels
= validate_scan_freqs(
5321 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5327 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5328 if (wiphy
->bands
[band
])
5329 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5332 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5333 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5337 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5340 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5341 nla_for_each_nested(attr
,
5342 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5346 if (n_match_sets
> wiphy
->max_match_sets
)
5349 if (info
->attrs
[NL80211_ATTR_IE
])
5350 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5354 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5357 if (rdev
->sched_scan_req
) {
5362 request
= kzalloc(sizeof(*request
)
5363 + sizeof(*request
->ssids
) * n_ssids
5364 + sizeof(*request
->match_sets
) * n_match_sets
5365 + sizeof(*request
->channels
) * n_channels
5366 + ie_len
, GFP_KERNEL
);
5373 request
->ssids
= (void *)&request
->channels
[n_channels
];
5374 request
->n_ssids
= n_ssids
;
5377 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5379 request
->ie
= (void *)(request
->channels
+ n_channels
);
5384 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5385 else if (request
->ssids
)
5386 request
->match_sets
=
5387 (void *)(request
->ssids
+ n_ssids
);
5389 request
->match_sets
=
5390 (void *)(request
->channels
+ n_channels
);
5392 request
->n_match_sets
= n_match_sets
;
5395 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5396 /* user specified, bail out if channel not found */
5397 nla_for_each_nested(attr
,
5398 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5400 struct ieee80211_channel
*chan
;
5402 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5409 /* ignore disabled channels */
5410 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5413 request
->channels
[i
] = chan
;
5418 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5420 if (!wiphy
->bands
[band
])
5422 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5423 struct ieee80211_channel
*chan
;
5425 chan
= &wiphy
->bands
[band
]->channels
[j
];
5427 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5430 request
->channels
[i
] = chan
;
5441 request
->n_channels
= i
;
5444 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5445 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5447 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5451 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5452 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5459 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5460 nla_for_each_nested(attr
,
5461 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5463 struct nlattr
*ssid
, *rssi
;
5465 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5466 nla_data(attr
), nla_len(attr
),
5467 nl80211_match_policy
);
5468 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5470 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5474 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5475 nla_data(ssid
), nla_len(ssid
));
5476 request
->match_sets
[i
].ssid
.ssid_len
=
5479 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5481 request
->rssi_thold
= nla_get_u32(rssi
);
5483 request
->rssi_thold
=
5484 NL80211_SCAN_RSSI_THOLD_OFF
;
5489 if (info
->attrs
[NL80211_ATTR_IE
]) {
5490 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5491 memcpy((void *)request
->ie
,
5492 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5496 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5497 request
->flags
= nla_get_u32(
5498 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5499 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5500 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5501 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5502 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5509 request
->wiphy
= &rdev
->wiphy
;
5510 request
->interval
= interval
;
5511 request
->scan_start
= jiffies
;
5513 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5515 rdev
->sched_scan_req
= request
;
5516 nl80211_send_sched_scan(rdev
, dev
,
5517 NL80211_CMD_START_SCHED_SCAN
);
5527 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5528 struct genl_info
*info
)
5530 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5532 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5533 !rdev
->ops
->sched_scan_stop
)
5536 return __cfg80211_stop_sched_scan(rdev
, false);
5539 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5540 struct genl_info
*info
)
5542 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5543 struct net_device
*dev
= info
->user_ptr
[1];
5544 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5545 struct cfg80211_chan_def chandef
;
5548 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5552 if (wdev
->cac_started
)
5555 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5562 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5565 if (!rdev
->ops
->start_radar_detection
)
5568 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5569 chandef
.chan
, CHAN_MODE_SHARED
,
5570 BIT(chandef
.width
));
5574 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5576 wdev
->channel
= chandef
.chan
;
5577 wdev
->cac_started
= true;
5578 wdev
->cac_start_time
= jiffies
;
5583 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5585 struct cfg80211_registered_device
*rdev
,
5586 struct wireless_dev
*wdev
,
5587 struct cfg80211_internal_bss
*intbss
)
5589 struct cfg80211_bss
*res
= &intbss
->pub
;
5590 const struct cfg80211_bss_ies
*ies
;
5595 ASSERT_WDEV_LOCK(wdev
);
5597 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5598 NL80211_CMD_NEW_SCAN_RESULTS
);
5602 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5604 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5605 goto nla_put_failure
;
5607 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5608 goto nla_put_failure
;
5609 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5610 goto nla_put_failure
;
5612 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5614 goto nla_put_failure
;
5615 if ((!is_zero_ether_addr(res
->bssid
) &&
5616 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5617 goto nla_put_failure
;
5620 ies
= rcu_dereference(res
->ies
);
5622 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5623 goto fail_unlock_rcu
;
5625 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5626 ies
->len
, ies
->data
))
5627 goto fail_unlock_rcu
;
5629 ies
= rcu_dereference(res
->beacon_ies
);
5631 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5632 goto fail_unlock_rcu
;
5633 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5634 ies
->len
, ies
->data
))
5635 goto fail_unlock_rcu
;
5639 if (res
->beacon_interval
&&
5640 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5641 goto nla_put_failure
;
5642 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5643 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5644 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5645 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5646 goto nla_put_failure
;
5648 switch (rdev
->wiphy
.signal_type
) {
5649 case CFG80211_SIGNAL_TYPE_MBM
:
5650 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5651 goto nla_put_failure
;
5653 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5654 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5655 goto nla_put_failure
;
5661 switch (wdev
->iftype
) {
5662 case NL80211_IFTYPE_P2P_CLIENT
:
5663 case NL80211_IFTYPE_STATION
:
5664 if (intbss
== wdev
->current_bss
&&
5665 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5666 NL80211_BSS_STATUS_ASSOCIATED
))
5667 goto nla_put_failure
;
5669 case NL80211_IFTYPE_ADHOC
:
5670 if (intbss
== wdev
->current_bss
&&
5671 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5672 NL80211_BSS_STATUS_IBSS_JOINED
))
5673 goto nla_put_failure
;
5679 nla_nest_end(msg
, bss
);
5681 return genlmsg_end(msg
, hdr
);
5686 genlmsg_cancel(msg
, hdr
);
5690 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5692 struct cfg80211_registered_device
*rdev
;
5693 struct cfg80211_internal_bss
*scan
;
5694 struct wireless_dev
*wdev
;
5695 int start
= cb
->args
[2], idx
= 0;
5698 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5703 spin_lock_bh(&rdev
->bss_lock
);
5704 cfg80211_bss_expire(rdev
);
5706 cb
->seq
= rdev
->bss_generation
;
5708 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5711 if (nl80211_send_bss(skb
, cb
,
5712 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5713 rdev
, wdev
, scan
) < 0) {
5719 spin_unlock_bh(&rdev
->bss_lock
);
5723 nl80211_finish_wdev_dump(rdev
);
5728 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5729 int flags
, struct net_device
*dev
,
5730 struct survey_info
*survey
)
5733 struct nlattr
*infoattr
;
5735 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5736 NL80211_CMD_NEW_SURVEY_RESULTS
);
5740 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5741 goto nla_put_failure
;
5743 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5745 goto nla_put_failure
;
5747 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5748 survey
->channel
->center_freq
))
5749 goto nla_put_failure
;
5751 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5752 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5753 goto nla_put_failure
;
5754 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5755 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5756 goto nla_put_failure
;
5757 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5758 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5759 survey
->channel_time
))
5760 goto nla_put_failure
;
5761 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5762 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5763 survey
->channel_time_busy
))
5764 goto nla_put_failure
;
5765 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5766 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5767 survey
->channel_time_ext_busy
))
5768 goto nla_put_failure
;
5769 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5770 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5771 survey
->channel_time_rx
))
5772 goto nla_put_failure
;
5773 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5774 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5775 survey
->channel_time_tx
))
5776 goto nla_put_failure
;
5778 nla_nest_end(msg
, infoattr
);
5780 return genlmsg_end(msg
, hdr
);
5783 genlmsg_cancel(msg
, hdr
);
5787 static int nl80211_dump_survey(struct sk_buff
*skb
,
5788 struct netlink_callback
*cb
)
5790 struct survey_info survey
;
5791 struct cfg80211_registered_device
*dev
;
5792 struct wireless_dev
*wdev
;
5793 int survey_idx
= cb
->args
[2];
5796 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5800 if (!wdev
->netdev
) {
5805 if (!dev
->ops
->dump_survey
) {
5811 struct ieee80211_channel
*chan
;
5813 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5819 /* Survey without a channel doesn't make sense */
5820 if (!survey
.channel
) {
5825 chan
= ieee80211_get_channel(&dev
->wiphy
,
5826 survey
.channel
->center_freq
);
5827 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5832 if (nl80211_send_survey(skb
,
5833 NETLINK_CB(cb
->skb
).portid
,
5834 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5835 wdev
->netdev
, &survey
) < 0)
5841 cb
->args
[2] = survey_idx
;
5844 nl80211_finish_wdev_dump(dev
);
5848 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5850 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5851 NL80211_WPA_VERSION_2
));
5854 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5856 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5857 struct net_device
*dev
= info
->user_ptr
[1];
5858 struct ieee80211_channel
*chan
;
5859 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5860 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5861 enum nl80211_auth_type auth_type
;
5862 struct key_parse key
;
5863 bool local_state_change
;
5865 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5868 if (!info
->attrs
[NL80211_ATTR_MAC
])
5871 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5874 if (!info
->attrs
[NL80211_ATTR_SSID
])
5877 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5880 err
= nl80211_parse_key(info
, &key
);
5885 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5887 if (!key
.p
.key
|| !key
.p
.key_len
)
5889 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5890 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5891 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5892 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5904 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5905 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5914 if (!rdev
->ops
->auth
)
5917 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5918 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5921 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5922 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5923 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5924 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5927 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5928 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5930 if (info
->attrs
[NL80211_ATTR_IE
]) {
5931 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5932 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5935 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5936 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5939 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5940 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5943 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5944 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5946 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5947 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5948 /* need to include at least Auth Transaction and Status Code */
5949 if (sae_data_len
< 4)
5953 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5956 * Since we no longer track auth state, ignore
5957 * requests to only change local state.
5959 if (local_state_change
)
5962 wdev_lock(dev
->ieee80211_ptr
);
5963 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5964 ssid
, ssid_len
, ie
, ie_len
,
5965 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5966 sae_data
, sae_data_len
);
5967 wdev_unlock(dev
->ieee80211_ptr
);
5971 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5972 struct genl_info
*info
,
5973 struct cfg80211_crypto_settings
*settings
,
5976 memset(settings
, 0, sizeof(*settings
));
5978 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5980 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5982 proto
= nla_get_u16(
5983 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5984 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5985 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5988 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5989 settings
->control_port_no_encrypt
= true;
5991 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5993 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5997 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5998 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5999 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6001 if (len
% sizeof(u32
))
6004 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6007 memcpy(settings
->ciphers_pairwise
, data
, len
);
6009 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6010 if (!cfg80211_supported_cipher_suite(
6012 settings
->ciphers_pairwise
[i
]))
6016 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6017 settings
->cipher_group
=
6018 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6019 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6020 settings
->cipher_group
))
6024 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6025 settings
->wpa_versions
=
6026 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6027 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6031 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6035 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6036 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6037 settings
->n_akm_suites
= len
/ sizeof(u32
);
6039 if (len
% sizeof(u32
))
6042 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6045 memcpy(settings
->akm_suites
, data
, len
);
6051 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6053 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6054 struct net_device
*dev
= info
->user_ptr
[1];
6055 struct ieee80211_channel
*chan
;
6056 struct cfg80211_assoc_request req
= {};
6057 const u8
*bssid
, *ssid
;
6058 int err
, ssid_len
= 0;
6060 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6063 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6064 !info
->attrs
[NL80211_ATTR_SSID
] ||
6065 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6068 if (!rdev
->ops
->assoc
)
6071 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6072 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6075 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6077 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6078 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6079 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6082 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6083 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6085 if (info
->attrs
[NL80211_ATTR_IE
]) {
6086 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6087 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6090 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6091 enum nl80211_mfp mfp
=
6092 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6093 if (mfp
== NL80211_MFP_REQUIRED
)
6095 else if (mfp
!= NL80211_MFP_NO
)
6099 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6100 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6102 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6103 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6105 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6106 memcpy(&req
.ht_capa_mask
,
6107 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6108 sizeof(req
.ht_capa_mask
));
6110 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6111 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6113 memcpy(&req
.ht_capa
,
6114 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6115 sizeof(req
.ht_capa
));
6118 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6119 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6121 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6122 memcpy(&req
.vht_capa_mask
,
6123 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6124 sizeof(req
.vht_capa_mask
));
6126 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6127 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6129 memcpy(&req
.vht_capa
,
6130 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6131 sizeof(req
.vht_capa
));
6134 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6136 wdev_lock(dev
->ieee80211_ptr
);
6137 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6138 ssid
, ssid_len
, &req
);
6139 wdev_unlock(dev
->ieee80211_ptr
);
6145 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6147 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6148 struct net_device
*dev
= info
->user_ptr
[1];
6149 const u8
*ie
= NULL
, *bssid
;
6150 int ie_len
= 0, err
;
6152 bool local_state_change
;
6154 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6157 if (!info
->attrs
[NL80211_ATTR_MAC
])
6160 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6163 if (!rdev
->ops
->deauth
)
6166 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6167 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6170 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6172 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6173 if (reason_code
== 0) {
6174 /* Reason Code 0 is reserved */
6178 if (info
->attrs
[NL80211_ATTR_IE
]) {
6179 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6180 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6183 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6185 wdev_lock(dev
->ieee80211_ptr
);
6186 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6187 local_state_change
);
6188 wdev_unlock(dev
->ieee80211_ptr
);
6192 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6194 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6195 struct net_device
*dev
= info
->user_ptr
[1];
6196 const u8
*ie
= NULL
, *bssid
;
6197 int ie_len
= 0, err
;
6199 bool local_state_change
;
6201 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6204 if (!info
->attrs
[NL80211_ATTR_MAC
])
6207 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6210 if (!rdev
->ops
->disassoc
)
6213 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6214 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6217 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6219 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6220 if (reason_code
== 0) {
6221 /* Reason Code 0 is reserved */
6225 if (info
->attrs
[NL80211_ATTR_IE
]) {
6226 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6227 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6230 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6232 wdev_lock(dev
->ieee80211_ptr
);
6233 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6234 local_state_change
);
6235 wdev_unlock(dev
->ieee80211_ptr
);
6240 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6241 int mcast_rate
[IEEE80211_NUM_BANDS
],
6244 struct wiphy
*wiphy
= &rdev
->wiphy
;
6248 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6249 struct ieee80211_supported_band
*sband
;
6251 sband
= wiphy
->bands
[band
];
6255 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6256 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6257 mcast_rate
[band
] = i
+ 1;
6267 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6269 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6270 struct net_device
*dev
= info
->user_ptr
[1];
6271 struct cfg80211_ibss_params ibss
;
6272 struct wiphy
*wiphy
;
6273 struct cfg80211_cached_keys
*connkeys
= NULL
;
6276 memset(&ibss
, 0, sizeof(ibss
));
6278 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6281 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6282 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6285 ibss
.beacon_interval
= 100;
6287 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6288 ibss
.beacon_interval
=
6289 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6290 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6294 if (!rdev
->ops
->join_ibss
)
6297 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6300 wiphy
= &rdev
->wiphy
;
6302 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6303 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6305 if (!is_valid_ether_addr(ibss
.bssid
))
6308 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6309 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6311 if (info
->attrs
[NL80211_ATTR_IE
]) {
6312 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6313 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6316 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6320 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6323 switch (ibss
.chandef
.width
) {
6324 case NL80211_CHAN_WIDTH_20_NOHT
:
6326 case NL80211_CHAN_WIDTH_20
:
6327 case NL80211_CHAN_WIDTH_40
:
6328 if (rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
)
6334 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6335 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6337 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6339 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6341 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6342 struct ieee80211_supported_band
*sband
=
6343 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6345 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6351 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6352 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6353 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6356 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6359 connkeys
= nl80211_parse_connkeys(rdev
,
6360 info
->attrs
[NL80211_ATTR_KEYS
],
6362 if (IS_ERR(connkeys
))
6363 return PTR_ERR(connkeys
);
6365 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6373 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6375 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6381 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6383 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6384 struct net_device
*dev
= info
->user_ptr
[1];
6386 if (!rdev
->ops
->leave_ibss
)
6389 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6392 return cfg80211_leave_ibss(rdev
, dev
, false);
6395 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6397 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6398 struct net_device
*dev
= info
->user_ptr
[1];
6399 int mcast_rate
[IEEE80211_NUM_BANDS
];
6403 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6404 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6407 if (!rdev
->ops
->set_mcast_rate
)
6410 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6412 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6415 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6416 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6419 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6425 #ifdef CONFIG_NL80211_TESTMODE
6426 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6430 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6432 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6435 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6439 if (rdev
->ops
->testmode_cmd
) {
6440 rdev
->testmode_info
= info
;
6441 err
= rdev_testmode_cmd(rdev
,
6442 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6443 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6444 rdev
->testmode_info
= NULL
;
6450 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6451 struct netlink_callback
*cb
)
6453 struct cfg80211_registered_device
*rdev
;
6463 * 0 is a valid index, but not valid for args[0],
6464 * so we need to offset by 1.
6466 phy_idx
= cb
->args
[0] - 1;
6468 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6469 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6474 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6475 nl80211_fam
.attrbuf
);
6477 err
= PTR_ERR(rdev
);
6480 phy_idx
= rdev
->wiphy_idx
;
6483 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6485 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6489 data
= nla_data((void *)cb
->args
[1]);
6490 data_len
= nla_len((void *)cb
->args
[1]);
6493 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6499 if (!rdev
->ops
->testmode_dump
) {
6505 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6506 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6507 NL80211_CMD_TESTMODE
);
6508 struct nlattr
*tmdata
;
6513 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6514 genlmsg_cancel(skb
, hdr
);
6518 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6520 genlmsg_cancel(skb
, hdr
);
6523 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6524 nla_nest_end(skb
, tmdata
);
6526 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6527 genlmsg_cancel(skb
, hdr
);
6530 genlmsg_cancel(skb
, hdr
);
6534 genlmsg_end(skb
, hdr
);
6539 cb
->args
[0] = phy_idx
+ 1;
6545 static struct sk_buff
*
6546 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
6547 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
6549 struct sk_buff
*skb
;
6551 struct nlattr
*data
;
6553 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6557 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
6563 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6564 goto nla_put_failure
;
6565 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6567 ((void **)skb
->cb
)[0] = rdev
;
6568 ((void **)skb
->cb
)[1] = hdr
;
6569 ((void **)skb
->cb
)[2] = data
;
6578 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
6581 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6583 if (WARN_ON(!rdev
->testmode_info
))
6586 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
6587 rdev
->testmode_info
->snd_portid
,
6588 rdev
->testmode_info
->snd_seq
,
6591 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
6593 int cfg80211_testmode_reply(struct sk_buff
*skb
)
6595 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6596 void *hdr
= ((void **)skb
->cb
)[1];
6597 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6599 if (WARN_ON(!rdev
->testmode_info
)) {
6604 nla_nest_end(skb
, data
);
6605 genlmsg_end(skb
, hdr
);
6606 return genlmsg_reply(skb
, rdev
->testmode_info
);
6608 EXPORT_SYMBOL(cfg80211_testmode_reply
);
6610 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
6611 int approxlen
, gfp_t gfp
)
6613 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6615 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
6617 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
6619 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
6621 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6622 void *hdr
= ((void **)skb
->cb
)[1];
6623 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6625 nla_nest_end(skb
, data
);
6626 genlmsg_end(skb
, hdr
);
6627 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6628 nl80211_testmode_mcgrp
.id
, gfp
);
6630 EXPORT_SYMBOL(cfg80211_testmode_event
);
6633 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6635 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6636 struct net_device
*dev
= info
->user_ptr
[1];
6637 struct cfg80211_connect_params connect
;
6638 struct wiphy
*wiphy
;
6639 struct cfg80211_cached_keys
*connkeys
= NULL
;
6642 memset(&connect
, 0, sizeof(connect
));
6644 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6647 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6648 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6651 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6653 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6654 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6655 NL80211_CMD_CONNECT
))
6658 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6660 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6662 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6663 NL80211_MAX_NR_CIPHER_SUITES
);
6667 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6668 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6671 wiphy
= &rdev
->wiphy
;
6673 connect
.bg_scan_period
= -1;
6674 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6675 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6676 connect
.bg_scan_period
=
6677 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6680 if (info
->attrs
[NL80211_ATTR_MAC
])
6681 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6682 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6683 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6685 if (info
->attrs
[NL80211_ATTR_IE
]) {
6686 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6687 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6690 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6691 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6692 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6693 connect
.mfp
!= NL80211_MFP_NO
)
6696 connect
.mfp
= NL80211_MFP_NO
;
6699 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6701 ieee80211_get_channel(wiphy
,
6702 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6703 if (!connect
.channel
||
6704 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6708 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6709 connkeys
= nl80211_parse_connkeys(rdev
,
6710 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6711 if (IS_ERR(connkeys
))
6712 return PTR_ERR(connkeys
);
6715 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6716 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6718 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6719 memcpy(&connect
.ht_capa_mask
,
6720 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6721 sizeof(connect
.ht_capa_mask
));
6723 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6724 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6728 memcpy(&connect
.ht_capa
,
6729 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6730 sizeof(connect
.ht_capa
));
6733 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6734 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6736 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6737 memcpy(&connect
.vht_capa_mask
,
6738 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6739 sizeof(connect
.vht_capa_mask
));
6741 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6742 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6746 memcpy(&connect
.vht_capa
,
6747 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6748 sizeof(connect
.vht_capa
));
6751 wdev_lock(dev
->ieee80211_ptr
);
6752 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
6753 wdev_unlock(dev
->ieee80211_ptr
);
6759 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6761 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6762 struct net_device
*dev
= info
->user_ptr
[1];
6766 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6767 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6769 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6774 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6775 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6778 wdev_lock(dev
->ieee80211_ptr
);
6779 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
6780 wdev_unlock(dev
->ieee80211_ptr
);
6784 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6786 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6791 if (!info
->attrs
[NL80211_ATTR_PID
])
6794 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6796 net
= get_net_ns_by_pid(pid
);
6798 return PTR_ERR(net
);
6802 /* check if anything to do */
6803 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6804 err
= cfg80211_switch_netns(rdev
, net
);
6810 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6812 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6813 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6814 struct cfg80211_pmksa
*pmksa
) = NULL
;
6815 struct net_device
*dev
= info
->user_ptr
[1];
6816 struct cfg80211_pmksa pmksa
;
6818 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6820 if (!info
->attrs
[NL80211_ATTR_MAC
])
6823 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6826 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6827 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6829 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6830 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6833 switch (info
->genlhdr
->cmd
) {
6834 case NL80211_CMD_SET_PMKSA
:
6835 rdev_ops
= rdev
->ops
->set_pmksa
;
6837 case NL80211_CMD_DEL_PMKSA
:
6838 rdev_ops
= rdev
->ops
->del_pmksa
;
6848 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6851 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6853 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6854 struct net_device
*dev
= info
->user_ptr
[1];
6856 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6857 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6860 if (!rdev
->ops
->flush_pmksa
)
6863 return rdev_flush_pmksa(rdev
, dev
);
6866 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6868 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6869 struct net_device
*dev
= info
->user_ptr
[1];
6870 u8 action_code
, dialog_token
;
6874 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6875 !rdev
->ops
->tdls_mgmt
)
6878 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6879 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6880 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6881 !info
->attrs
[NL80211_ATTR_IE
] ||
6882 !info
->attrs
[NL80211_ATTR_MAC
])
6885 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6886 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6887 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6888 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6890 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6891 dialog_token
, status_code
,
6892 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6893 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6896 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6898 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6899 struct net_device
*dev
= info
->user_ptr
[1];
6900 enum nl80211_tdls_operation operation
;
6903 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6904 !rdev
->ops
->tdls_oper
)
6907 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6908 !info
->attrs
[NL80211_ATTR_MAC
])
6911 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6912 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6914 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6917 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6918 struct genl_info
*info
)
6920 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6921 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6922 struct cfg80211_chan_def chandef
;
6923 struct sk_buff
*msg
;
6929 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6930 !info
->attrs
[NL80211_ATTR_DURATION
])
6933 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6935 if (!rdev
->ops
->remain_on_channel
||
6936 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6940 * We should be on that channel for at least a minimum amount of
6941 * time (10ms) but no longer than the driver supports.
6943 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6944 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6947 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6951 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6955 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6956 NL80211_CMD_REMAIN_ON_CHANNEL
);
6962 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6968 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6969 goto nla_put_failure
;
6971 genlmsg_end(msg
, hdr
);
6973 return genlmsg_reply(msg
, info
);
6982 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
6983 struct genl_info
*info
)
6985 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6986 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6989 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6992 if (!rdev
->ops
->cancel_remain_on_channel
)
6995 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6997 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7000 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7001 u8
*rates
, u8 rates_len
)
7006 for (i
= 0; i
< rates_len
; i
++) {
7007 int rate
= (rates
[i
] & 0x7f) * 5;
7009 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7010 struct ieee80211_rate
*srate
=
7011 &sband
->bitrates
[ridx
];
7012 if (rate
== srate
->bitrate
) {
7017 if (ridx
== sband
->n_bitrates
)
7018 return 0; /* rate not found */
7024 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7025 u8
*rates
, u8 rates_len
,
7026 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7030 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7032 for (i
= 0; i
< rates_len
; i
++) {
7035 ridx
= rates
[i
] / 8;
7036 rbit
= BIT(rates
[i
] % 8);
7038 /* check validity */
7039 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7042 /* check availability */
7043 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7052 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7053 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7054 .len
= NL80211_MAX_SUPP_RATES
},
7055 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7056 .len
= NL80211_MAX_SUPP_HT_RATES
},
7059 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7060 struct genl_info
*info
)
7062 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7063 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7064 struct cfg80211_bitrate_mask mask
;
7066 struct net_device
*dev
= info
->user_ptr
[1];
7067 struct nlattr
*tx_rates
;
7068 struct ieee80211_supported_band
*sband
;
7070 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7073 if (!rdev
->ops
->set_bitrate_mask
)
7076 memset(&mask
, 0, sizeof(mask
));
7077 /* Default to all rates enabled */
7078 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7079 sband
= rdev
->wiphy
.bands
[i
];
7080 mask
.control
[i
].legacy
=
7081 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7083 memcpy(mask
.control
[i
].mcs
,
7084 sband
->ht_cap
.mcs
.rx_mask
,
7085 sizeof(mask
.control
[i
].mcs
));
7087 memset(mask
.control
[i
].mcs
, 0,
7088 sizeof(mask
.control
[i
].mcs
));
7092 * The nested attribute uses enum nl80211_band as the index. This maps
7093 * directly to the enum ieee80211_band values used in cfg80211.
7095 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7096 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7098 enum ieee80211_band band
= nla_type(tx_rates
);
7099 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7101 sband
= rdev
->wiphy
.bands
[band
];
7104 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7105 nla_len(tx_rates
), nl80211_txattr_policy
);
7106 if (tb
[NL80211_TXRATE_LEGACY
]) {
7107 mask
.control
[band
].legacy
= rateset_to_mask(
7109 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7110 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7111 if ((mask
.control
[band
].legacy
== 0) &&
7112 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7115 if (tb
[NL80211_TXRATE_MCS
]) {
7116 if (!ht_rateset_to_mask(
7118 nla_data(tb
[NL80211_TXRATE_MCS
]),
7119 nla_len(tb
[NL80211_TXRATE_MCS
]),
7120 mask
.control
[band
].mcs
))
7124 if (mask
.control
[band
].legacy
== 0) {
7125 /* don't allow empty legacy rates if HT
7126 * is not even supported. */
7127 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7130 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7131 if (mask
.control
[band
].mcs
[i
])
7134 /* legacy and mcs rates may not be both empty */
7135 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7140 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7143 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7145 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7146 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7147 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7149 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7152 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7153 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7155 switch (wdev
->iftype
) {
7156 case NL80211_IFTYPE_STATION
:
7157 case NL80211_IFTYPE_ADHOC
:
7158 case NL80211_IFTYPE_P2P_CLIENT
:
7159 case NL80211_IFTYPE_AP
:
7160 case NL80211_IFTYPE_AP_VLAN
:
7161 case NL80211_IFTYPE_MESH_POINT
:
7162 case NL80211_IFTYPE_P2P_GO
:
7163 case NL80211_IFTYPE_P2P_DEVICE
:
7169 /* not much point in registering if we can't reply */
7170 if (!rdev
->ops
->mgmt_tx
)
7173 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7174 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7175 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7178 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7180 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7181 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7182 struct cfg80211_chan_def chandef
;
7186 struct sk_buff
*msg
= NULL
;
7187 unsigned int wait
= 0;
7188 bool offchan
, no_cck
, dont_wait_for_ack
;
7190 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7192 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7195 if (!rdev
->ops
->mgmt_tx
)
7198 switch (wdev
->iftype
) {
7199 case NL80211_IFTYPE_P2P_DEVICE
:
7200 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7202 case NL80211_IFTYPE_STATION
:
7203 case NL80211_IFTYPE_ADHOC
:
7204 case NL80211_IFTYPE_P2P_CLIENT
:
7205 case NL80211_IFTYPE_AP
:
7206 case NL80211_IFTYPE_AP_VLAN
:
7207 case NL80211_IFTYPE_MESH_POINT
:
7208 case NL80211_IFTYPE_P2P_GO
:
7214 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7215 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7217 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7220 * We should wait on the channel for at least a minimum amount
7221 * of time (10ms) but no longer than the driver supports.
7223 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7224 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7229 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7231 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7234 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7236 /* get the channel if any has been specified, otherwise pass NULL to
7237 * the driver. The latter will use the current one
7239 chandef
.chan
= NULL
;
7240 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7241 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7246 if (!chandef
.chan
&& offchan
)
7249 if (!dont_wait_for_ack
) {
7250 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7254 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7262 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7263 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7264 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7265 no_cck
, dont_wait_for_ack
, &cookie
);
7270 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7271 goto nla_put_failure
;
7273 genlmsg_end(msg
, hdr
);
7274 return genlmsg_reply(msg
, info
);
7286 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7288 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7289 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7292 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7295 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7298 switch (wdev
->iftype
) {
7299 case NL80211_IFTYPE_STATION
:
7300 case NL80211_IFTYPE_ADHOC
:
7301 case NL80211_IFTYPE_P2P_CLIENT
:
7302 case NL80211_IFTYPE_AP
:
7303 case NL80211_IFTYPE_AP_VLAN
:
7304 case NL80211_IFTYPE_P2P_GO
:
7305 case NL80211_IFTYPE_P2P_DEVICE
:
7311 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7313 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7316 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7318 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7319 struct wireless_dev
*wdev
;
7320 struct net_device
*dev
= info
->user_ptr
[1];
7325 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7328 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7330 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7333 wdev
= dev
->ieee80211_ptr
;
7335 if (!rdev
->ops
->set_power_mgmt
)
7338 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7340 if (state
== wdev
->ps
)
7343 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7349 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7351 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7352 enum nl80211_ps_state ps_state
;
7353 struct wireless_dev
*wdev
;
7354 struct net_device
*dev
= info
->user_ptr
[1];
7355 struct sk_buff
*msg
;
7359 wdev
= dev
->ieee80211_ptr
;
7361 if (!rdev
->ops
->set_power_mgmt
)
7364 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7368 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7369 NL80211_CMD_GET_POWER_SAVE
);
7376 ps_state
= NL80211_PS_ENABLED
;
7378 ps_state
= NL80211_PS_DISABLED
;
7380 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7381 goto nla_put_failure
;
7383 genlmsg_end(msg
, hdr
);
7384 return genlmsg_reply(msg
, info
);
7393 static struct nla_policy
7394 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7395 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7396 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7397 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7398 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7399 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7400 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7403 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7404 u32 rate
, u32 pkts
, u32 intvl
)
7406 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7407 struct wireless_dev
*wdev
;
7408 struct net_device
*dev
= info
->user_ptr
[1];
7410 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7413 wdev
= dev
->ieee80211_ptr
;
7415 if (!rdev
->ops
->set_cqm_txe_config
)
7418 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7419 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7422 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7425 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7426 s32 threshold
, u32 hysteresis
)
7428 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7429 struct wireless_dev
*wdev
;
7430 struct net_device
*dev
= info
->user_ptr
[1];
7435 wdev
= dev
->ieee80211_ptr
;
7437 if (!rdev
->ops
->set_cqm_rssi_config
)
7440 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7441 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7444 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7447 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7449 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7453 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7459 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7460 nl80211_attr_cqm_policy
);
7464 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7465 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7468 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7469 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7470 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7471 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7472 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7473 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7474 u32 rate
, pkts
, intvl
;
7475 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7476 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7477 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7478 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7486 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7488 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7489 struct net_device
*dev
= info
->user_ptr
[1];
7490 struct mesh_config cfg
;
7491 struct mesh_setup setup
;
7494 /* start with default */
7495 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7496 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7498 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7499 /* and parse parameters if given */
7500 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7505 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7506 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7509 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7510 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7512 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7513 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7514 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7517 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7518 setup
.beacon_interval
=
7519 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7520 if (setup
.beacon_interval
< 10 ||
7521 setup
.beacon_interval
> 10000)
7525 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7527 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7528 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7532 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7533 /* parse additional setup parameters if given */
7534 err
= nl80211_parse_mesh_setup(info
, &setup
);
7540 cfg
.auto_open_plinks
= false;
7542 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7543 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7547 /* cfg80211_join_mesh() will sort it out */
7548 setup
.chandef
.chan
= NULL
;
7551 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7552 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7554 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7555 struct ieee80211_supported_band
*sband
;
7557 if (!setup
.chandef
.chan
)
7560 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
7562 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7563 &setup
.basic_rates
);
7568 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7571 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7573 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7574 struct net_device
*dev
= info
->user_ptr
[1];
7576 return cfg80211_leave_mesh(rdev
, dev
);
7580 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7581 struct cfg80211_registered_device
*rdev
)
7583 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
7584 struct nlattr
*nl_pats
, *nl_pat
;
7587 if (!wowlan
->n_patterns
)
7590 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7594 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
7595 nl_pat
= nla_nest_start(msg
, i
+ 1);
7598 pat_len
= wowlan
->patterns
[i
].pattern_len
;
7599 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7600 DIV_ROUND_UP(pat_len
, 8),
7601 wowlan
->patterns
[i
].mask
) ||
7602 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7603 pat_len
, wowlan
->patterns
[i
].pattern
) ||
7604 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7605 wowlan
->patterns
[i
].pkt_offset
))
7607 nla_nest_end(msg
, nl_pat
);
7609 nla_nest_end(msg
, nl_pats
);
7614 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7615 struct cfg80211_wowlan_tcp
*tcp
)
7617 struct nlattr
*nl_tcp
;
7622 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7626 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7627 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7628 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7629 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7630 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7631 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7632 tcp
->payload_len
, tcp
->payload
) ||
7633 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7634 tcp
->data_interval
) ||
7635 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7636 tcp
->wake_len
, tcp
->wake_data
) ||
7637 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7638 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7641 if (tcp
->payload_seq
.len
&&
7642 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7643 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7646 if (tcp
->payload_tok
.len
&&
7647 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7648 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7652 nla_nest_end(msg
, nl_tcp
);
7657 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7659 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7660 struct sk_buff
*msg
;
7662 u32 size
= NLMSG_DEFAULT_SIZE
;
7664 if (!rdev
->wiphy
.wowlan
)
7667 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
7668 /* adjust size to have room for all the data */
7669 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
7670 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
7671 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
7672 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
7675 msg
= nlmsg_new(size
, GFP_KERNEL
);
7679 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7680 NL80211_CMD_GET_WOWLAN
);
7682 goto nla_put_failure
;
7684 if (rdev
->wiphy
.wowlan_config
) {
7685 struct nlattr
*nl_wowlan
;
7687 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7689 goto nla_put_failure
;
7691 if ((rdev
->wiphy
.wowlan_config
->any
&&
7692 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7693 (rdev
->wiphy
.wowlan_config
->disconnect
&&
7694 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7695 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
7696 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7697 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
7698 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7699 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
7700 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7701 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
7702 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7703 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
7704 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7705 goto nla_put_failure
;
7707 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7708 goto nla_put_failure
;
7710 if (nl80211_send_wowlan_tcp(msg
,
7711 rdev
->wiphy
.wowlan_config
->tcp
))
7712 goto nla_put_failure
;
7714 nla_nest_end(msg
, nl_wowlan
);
7717 genlmsg_end(msg
, hdr
);
7718 return genlmsg_reply(msg
, info
);
7725 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7726 struct nlattr
*attr
,
7727 struct cfg80211_wowlan
*trig
)
7729 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7730 struct cfg80211_wowlan_tcp
*cfg
;
7731 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7732 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7734 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7737 if (!rdev
->wiphy
.wowlan
->tcp
)
7740 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7741 nla_data(attr
), nla_len(attr
),
7742 nl80211_wowlan_tcp_policy
);
7746 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7747 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7748 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7749 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7750 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7751 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7752 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7753 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7756 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7757 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
7760 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7761 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
7762 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7765 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7766 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
7769 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7770 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7773 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7774 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7776 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7777 tokens_size
= tokln
- sizeof(*tok
);
7779 if (!tok
->len
|| tokens_size
% tok
->len
)
7781 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
7783 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
7785 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
7787 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
7789 if (tok
->offset
+ tok
->len
> data_size
)
7793 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7794 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7795 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
7797 if (seq
->len
== 0 || seq
->len
> 4)
7799 if (seq
->len
+ seq
->offset
> data_size
)
7803 size
= sizeof(*cfg
);
7805 size
+= wake_size
+ wake_mask_size
;
7806 size
+= tokens_size
;
7808 cfg
= kzalloc(size
, GFP_KERNEL
);
7811 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7812 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7813 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7815 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7816 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7820 /* allocate a socket and port for it and use it */
7821 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7822 IPPROTO_TCP
, &cfg
->sock
, 1);
7827 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7828 sock_release(cfg
->sock
);
7832 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7838 cfg
->src_port
= port
;
7841 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7842 cfg
->payload_len
= data_size
;
7843 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7844 memcpy((void *)cfg
->payload
,
7845 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7848 cfg
->payload_seq
= *seq
;
7849 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7850 cfg
->wake_len
= wake_size
;
7851 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7852 memcpy((void *)cfg
->wake_data
,
7853 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7855 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7856 data_size
+ wake_size
;
7857 memcpy((void *)cfg
->wake_mask
,
7858 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7861 cfg
->tokens_size
= tokens_size
;
7862 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7870 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7872 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7873 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7874 struct cfg80211_wowlan new_triggers
= {};
7875 struct cfg80211_wowlan
*ntrig
;
7876 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
7878 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
7883 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7884 cfg80211_rdev_free_wowlan(rdev
);
7885 rdev
->wiphy
.wowlan_config
= NULL
;
7889 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7890 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7891 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7892 nl80211_wowlan_policy
);
7896 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7897 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7899 new_triggers
.any
= true;
7902 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7903 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7905 new_triggers
.disconnect
= true;
7908 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7909 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7911 new_triggers
.magic_pkt
= true;
7914 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7917 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7918 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7920 new_triggers
.gtk_rekey_failure
= true;
7923 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7924 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7926 new_triggers
.eap_identity_req
= true;
7929 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7930 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7932 new_triggers
.four_way_handshake
= true;
7935 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7936 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7938 new_triggers
.rfkill_release
= true;
7941 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7944 int rem
, pat_len
, mask_len
, pkt_offset
;
7945 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7947 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7950 if (n_patterns
> wowlan
->n_patterns
)
7953 new_triggers
.patterns
= kcalloc(n_patterns
,
7954 sizeof(new_triggers
.patterns
[0]),
7956 if (!new_triggers
.patterns
)
7959 new_triggers
.n_patterns
= n_patterns
;
7962 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7964 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7965 nla_data(pat
), nla_len(pat
), NULL
);
7967 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7968 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7970 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7971 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7972 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7975 if (pat_len
> wowlan
->pattern_max_len
||
7976 pat_len
< wowlan
->pattern_min_len
)
7979 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7982 pkt_offset
= nla_get_u32(
7983 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7984 if (pkt_offset
> wowlan
->max_pkt_offset
)
7986 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7988 new_triggers
.patterns
[i
].mask
=
7989 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7990 if (!new_triggers
.patterns
[i
].mask
) {
7994 new_triggers
.patterns
[i
].pattern
=
7995 new_triggers
.patterns
[i
].mask
+ mask_len
;
7996 memcpy(new_triggers
.patterns
[i
].mask
,
7997 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7999 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
8000 memcpy(new_triggers
.patterns
[i
].pattern
,
8001 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
8007 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8008 err
= nl80211_parse_wowlan_tcp(
8009 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8015 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8020 cfg80211_rdev_free_wowlan(rdev
);
8021 rdev
->wiphy
.wowlan_config
= ntrig
;
8024 if (rdev
->ops
->set_wakeup
&&
8025 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
8026 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
8030 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8031 kfree(new_triggers
.patterns
[i
].mask
);
8032 kfree(new_triggers
.patterns
);
8033 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8034 sock_release(new_triggers
.tcp
->sock
);
8035 kfree(new_triggers
.tcp
);
8040 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8042 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8043 struct net_device
*dev
= info
->user_ptr
[1];
8044 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8045 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8046 struct cfg80211_gtk_rekey_data rekey_data
;
8049 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8052 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8053 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8054 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8055 nl80211_rekey_policy
);
8059 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8061 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8063 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8066 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8068 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8070 memcpy(rekey_data
.replay_ctr
,
8071 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8072 NL80211_REPLAY_CTR_LEN
);
8075 if (!wdev
->current_bss
) {
8080 if (!rdev
->ops
->set_rekey_data
) {
8085 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8091 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8092 struct genl_info
*info
)
8094 struct net_device
*dev
= info
->user_ptr
[1];
8095 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8097 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8098 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8101 if (wdev
->ap_unexpected_nlportid
)
8104 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8108 static int nl80211_probe_client(struct sk_buff
*skb
,
8109 struct genl_info
*info
)
8111 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8112 struct net_device
*dev
= info
->user_ptr
[1];
8113 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8114 struct sk_buff
*msg
;
8120 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8121 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8124 if (!info
->attrs
[NL80211_ATTR_MAC
])
8127 if (!rdev
->ops
->probe_client
)
8130 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8134 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8135 NL80211_CMD_PROBE_CLIENT
);
8141 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8143 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8147 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8148 goto nla_put_failure
;
8150 genlmsg_end(msg
, hdr
);
8152 return genlmsg_reply(msg
, info
);
8161 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8163 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8164 struct cfg80211_beacon_registration
*reg
, *nreg
;
8167 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8170 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8174 /* First, check if already registered. */
8175 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8176 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8177 if (reg
->nlportid
== info
->snd_portid
) {
8182 /* Add it to the list */
8183 nreg
->nlportid
= info
->snd_portid
;
8184 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8186 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8190 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8195 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8197 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8198 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8201 if (!rdev
->ops
->start_p2p_device
)
8204 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8207 if (wdev
->p2p_started
)
8210 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8214 err
= rdev_start_p2p_device(rdev
, wdev
);
8218 wdev
->p2p_started
= true;
8224 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8226 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8227 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8229 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8232 if (!rdev
->ops
->stop_p2p_device
)
8235 cfg80211_stop_p2p_device(rdev
, wdev
);
8240 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8241 struct genl_info
*info
)
8244 struct sk_buff
*msg
;
8246 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8250 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8251 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8253 goto nla_put_failure
;
8255 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8256 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8257 goto nla_put_failure
;
8259 genlmsg_end(msg
, hdr
);
8260 return genlmsg_reply(msg
, info
);
8267 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8269 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8270 struct cfg80211_update_ft_ies_params ft_params
;
8271 struct net_device
*dev
= info
->user_ptr
[1];
8273 if (!rdev
->ops
->update_ft_ies
)
8276 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8277 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8280 memset(&ft_params
, 0, sizeof(ft_params
));
8281 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8282 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8283 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8285 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8288 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8289 struct genl_info
*info
)
8291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8292 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8293 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8297 if (!rdev
->ops
->crit_proto_start
)
8300 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8303 if (rdev
->crit_proto_nlportid
)
8306 /* determine protocol if provided */
8307 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8308 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8310 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8313 /* timeout must be provided */
8314 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8318 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8320 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8323 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8325 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8330 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8331 struct genl_info
*info
)
8333 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8334 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8336 if (!rdev
->ops
->crit_proto_stop
)
8339 if (rdev
->crit_proto_nlportid
) {
8340 rdev
->crit_proto_nlportid
= 0;
8341 rdev_crit_proto_stop(rdev
, wdev
);
8346 #define NL80211_FLAG_NEED_WIPHY 0x01
8347 #define NL80211_FLAG_NEED_NETDEV 0x02
8348 #define NL80211_FLAG_NEED_RTNL 0x04
8349 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8350 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8351 NL80211_FLAG_CHECK_NETDEV_UP)
8352 #define NL80211_FLAG_NEED_WDEV 0x10
8353 /* If a netdev is associated, it must be UP, P2P must be started */
8354 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8355 NL80211_FLAG_CHECK_NETDEV_UP)
8357 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8358 struct genl_info
*info
)
8360 struct cfg80211_registered_device
*rdev
;
8361 struct wireless_dev
*wdev
;
8362 struct net_device
*dev
;
8363 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8368 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8369 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8373 return PTR_ERR(rdev
);
8375 info
->user_ptr
[0] = rdev
;
8376 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8377 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8380 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8385 return PTR_ERR(wdev
);
8389 rdev
= wiphy_to_dev(wdev
->wiphy
);
8391 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8398 info
->user_ptr
[1] = dev
;
8400 info
->user_ptr
[1] = wdev
;
8404 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8405 !netif_running(dev
)) {
8412 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8413 if (!wdev
->p2p_started
) {
8420 info
->user_ptr
[0] = rdev
;
8426 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8427 struct genl_info
*info
)
8429 if (info
->user_ptr
[1]) {
8430 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8431 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8434 dev_put(wdev
->netdev
);
8436 dev_put(info
->user_ptr
[1]);
8439 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8443 static struct genl_ops nl80211_ops
[] = {
8445 .cmd
= NL80211_CMD_GET_WIPHY
,
8446 .doit
= nl80211_get_wiphy
,
8447 .dumpit
= nl80211_dump_wiphy
,
8448 .done
= nl80211_dump_wiphy_done
,
8449 .policy
= nl80211_policy
,
8450 /* can be retrieved by unprivileged users */
8451 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8452 NL80211_FLAG_NEED_RTNL
,
8455 .cmd
= NL80211_CMD_SET_WIPHY
,
8456 .doit
= nl80211_set_wiphy
,
8457 .policy
= nl80211_policy
,
8458 .flags
= GENL_ADMIN_PERM
,
8459 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8462 .cmd
= NL80211_CMD_GET_INTERFACE
,
8463 .doit
= nl80211_get_interface
,
8464 .dumpit
= nl80211_dump_interface
,
8465 .policy
= nl80211_policy
,
8466 /* can be retrieved by unprivileged users */
8467 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8468 NL80211_FLAG_NEED_RTNL
,
8471 .cmd
= NL80211_CMD_SET_INTERFACE
,
8472 .doit
= nl80211_set_interface
,
8473 .policy
= nl80211_policy
,
8474 .flags
= GENL_ADMIN_PERM
,
8475 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8476 NL80211_FLAG_NEED_RTNL
,
8479 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8480 .doit
= nl80211_new_interface
,
8481 .policy
= nl80211_policy
,
8482 .flags
= GENL_ADMIN_PERM
,
8483 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8484 NL80211_FLAG_NEED_RTNL
,
8487 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8488 .doit
= nl80211_del_interface
,
8489 .policy
= nl80211_policy
,
8490 .flags
= GENL_ADMIN_PERM
,
8491 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8492 NL80211_FLAG_NEED_RTNL
,
8495 .cmd
= NL80211_CMD_GET_KEY
,
8496 .doit
= nl80211_get_key
,
8497 .policy
= nl80211_policy
,
8498 .flags
= GENL_ADMIN_PERM
,
8499 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8500 NL80211_FLAG_NEED_RTNL
,
8503 .cmd
= NL80211_CMD_SET_KEY
,
8504 .doit
= nl80211_set_key
,
8505 .policy
= nl80211_policy
,
8506 .flags
= GENL_ADMIN_PERM
,
8507 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8508 NL80211_FLAG_NEED_RTNL
,
8511 .cmd
= NL80211_CMD_NEW_KEY
,
8512 .doit
= nl80211_new_key
,
8513 .policy
= nl80211_policy
,
8514 .flags
= GENL_ADMIN_PERM
,
8515 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8516 NL80211_FLAG_NEED_RTNL
,
8519 .cmd
= NL80211_CMD_DEL_KEY
,
8520 .doit
= nl80211_del_key
,
8521 .policy
= nl80211_policy
,
8522 .flags
= GENL_ADMIN_PERM
,
8523 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8524 NL80211_FLAG_NEED_RTNL
,
8527 .cmd
= NL80211_CMD_SET_BEACON
,
8528 .policy
= nl80211_policy
,
8529 .flags
= GENL_ADMIN_PERM
,
8530 .doit
= nl80211_set_beacon
,
8531 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8532 NL80211_FLAG_NEED_RTNL
,
8535 .cmd
= NL80211_CMD_START_AP
,
8536 .policy
= nl80211_policy
,
8537 .flags
= GENL_ADMIN_PERM
,
8538 .doit
= nl80211_start_ap
,
8539 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8540 NL80211_FLAG_NEED_RTNL
,
8543 .cmd
= NL80211_CMD_STOP_AP
,
8544 .policy
= nl80211_policy
,
8545 .flags
= GENL_ADMIN_PERM
,
8546 .doit
= nl80211_stop_ap
,
8547 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8548 NL80211_FLAG_NEED_RTNL
,
8551 .cmd
= NL80211_CMD_GET_STATION
,
8552 .doit
= nl80211_get_station
,
8553 .dumpit
= nl80211_dump_station
,
8554 .policy
= nl80211_policy
,
8555 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8556 NL80211_FLAG_NEED_RTNL
,
8559 .cmd
= NL80211_CMD_SET_STATION
,
8560 .doit
= nl80211_set_station
,
8561 .policy
= nl80211_policy
,
8562 .flags
= GENL_ADMIN_PERM
,
8563 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8564 NL80211_FLAG_NEED_RTNL
,
8567 .cmd
= NL80211_CMD_NEW_STATION
,
8568 .doit
= nl80211_new_station
,
8569 .policy
= nl80211_policy
,
8570 .flags
= GENL_ADMIN_PERM
,
8571 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8572 NL80211_FLAG_NEED_RTNL
,
8575 .cmd
= NL80211_CMD_DEL_STATION
,
8576 .doit
= nl80211_del_station
,
8577 .policy
= nl80211_policy
,
8578 .flags
= GENL_ADMIN_PERM
,
8579 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8580 NL80211_FLAG_NEED_RTNL
,
8583 .cmd
= NL80211_CMD_GET_MPATH
,
8584 .doit
= nl80211_get_mpath
,
8585 .dumpit
= nl80211_dump_mpath
,
8586 .policy
= nl80211_policy
,
8587 .flags
= GENL_ADMIN_PERM
,
8588 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8589 NL80211_FLAG_NEED_RTNL
,
8592 .cmd
= NL80211_CMD_SET_MPATH
,
8593 .doit
= nl80211_set_mpath
,
8594 .policy
= nl80211_policy
,
8595 .flags
= GENL_ADMIN_PERM
,
8596 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8597 NL80211_FLAG_NEED_RTNL
,
8600 .cmd
= NL80211_CMD_NEW_MPATH
,
8601 .doit
= nl80211_new_mpath
,
8602 .policy
= nl80211_policy
,
8603 .flags
= GENL_ADMIN_PERM
,
8604 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8605 NL80211_FLAG_NEED_RTNL
,
8608 .cmd
= NL80211_CMD_DEL_MPATH
,
8609 .doit
= nl80211_del_mpath
,
8610 .policy
= nl80211_policy
,
8611 .flags
= GENL_ADMIN_PERM
,
8612 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8613 NL80211_FLAG_NEED_RTNL
,
8616 .cmd
= NL80211_CMD_SET_BSS
,
8617 .doit
= nl80211_set_bss
,
8618 .policy
= nl80211_policy
,
8619 .flags
= GENL_ADMIN_PERM
,
8620 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8621 NL80211_FLAG_NEED_RTNL
,
8624 .cmd
= NL80211_CMD_GET_REG
,
8625 .doit
= nl80211_get_reg
,
8626 .policy
= nl80211_policy
,
8627 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8628 /* can be retrieved by unprivileged users */
8631 .cmd
= NL80211_CMD_SET_REG
,
8632 .doit
= nl80211_set_reg
,
8633 .policy
= nl80211_policy
,
8634 .flags
= GENL_ADMIN_PERM
,
8635 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8638 .cmd
= NL80211_CMD_REQ_SET_REG
,
8639 .doit
= nl80211_req_set_reg
,
8640 .policy
= nl80211_policy
,
8641 .flags
= GENL_ADMIN_PERM
,
8644 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8645 .doit
= nl80211_get_mesh_config
,
8646 .policy
= nl80211_policy
,
8647 /* can be retrieved by unprivileged users */
8648 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8649 NL80211_FLAG_NEED_RTNL
,
8652 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8653 .doit
= nl80211_update_mesh_config
,
8654 .policy
= nl80211_policy
,
8655 .flags
= GENL_ADMIN_PERM
,
8656 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8657 NL80211_FLAG_NEED_RTNL
,
8660 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8661 .doit
= nl80211_trigger_scan
,
8662 .policy
= nl80211_policy
,
8663 .flags
= GENL_ADMIN_PERM
,
8664 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8665 NL80211_FLAG_NEED_RTNL
,
8668 .cmd
= NL80211_CMD_GET_SCAN
,
8669 .policy
= nl80211_policy
,
8670 .dumpit
= nl80211_dump_scan
,
8673 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8674 .doit
= nl80211_start_sched_scan
,
8675 .policy
= nl80211_policy
,
8676 .flags
= GENL_ADMIN_PERM
,
8677 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8678 NL80211_FLAG_NEED_RTNL
,
8681 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8682 .doit
= nl80211_stop_sched_scan
,
8683 .policy
= nl80211_policy
,
8684 .flags
= GENL_ADMIN_PERM
,
8685 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8686 NL80211_FLAG_NEED_RTNL
,
8689 .cmd
= NL80211_CMD_AUTHENTICATE
,
8690 .doit
= nl80211_authenticate
,
8691 .policy
= nl80211_policy
,
8692 .flags
= GENL_ADMIN_PERM
,
8693 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8694 NL80211_FLAG_NEED_RTNL
,
8697 .cmd
= NL80211_CMD_ASSOCIATE
,
8698 .doit
= nl80211_associate
,
8699 .policy
= nl80211_policy
,
8700 .flags
= GENL_ADMIN_PERM
,
8701 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8702 NL80211_FLAG_NEED_RTNL
,
8705 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8706 .doit
= nl80211_deauthenticate
,
8707 .policy
= nl80211_policy
,
8708 .flags
= GENL_ADMIN_PERM
,
8709 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8710 NL80211_FLAG_NEED_RTNL
,
8713 .cmd
= NL80211_CMD_DISASSOCIATE
,
8714 .doit
= nl80211_disassociate
,
8715 .policy
= nl80211_policy
,
8716 .flags
= GENL_ADMIN_PERM
,
8717 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8718 NL80211_FLAG_NEED_RTNL
,
8721 .cmd
= NL80211_CMD_JOIN_IBSS
,
8722 .doit
= nl80211_join_ibss
,
8723 .policy
= nl80211_policy
,
8724 .flags
= GENL_ADMIN_PERM
,
8725 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8726 NL80211_FLAG_NEED_RTNL
,
8729 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8730 .doit
= nl80211_leave_ibss
,
8731 .policy
= nl80211_policy
,
8732 .flags
= GENL_ADMIN_PERM
,
8733 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8734 NL80211_FLAG_NEED_RTNL
,
8736 #ifdef CONFIG_NL80211_TESTMODE
8738 .cmd
= NL80211_CMD_TESTMODE
,
8739 .doit
= nl80211_testmode_do
,
8740 .dumpit
= nl80211_testmode_dump
,
8741 .policy
= nl80211_policy
,
8742 .flags
= GENL_ADMIN_PERM
,
8743 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8744 NL80211_FLAG_NEED_RTNL
,
8748 .cmd
= NL80211_CMD_CONNECT
,
8749 .doit
= nl80211_connect
,
8750 .policy
= nl80211_policy
,
8751 .flags
= GENL_ADMIN_PERM
,
8752 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8753 NL80211_FLAG_NEED_RTNL
,
8756 .cmd
= NL80211_CMD_DISCONNECT
,
8757 .doit
= nl80211_disconnect
,
8758 .policy
= nl80211_policy
,
8759 .flags
= GENL_ADMIN_PERM
,
8760 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8761 NL80211_FLAG_NEED_RTNL
,
8764 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8765 .doit
= nl80211_wiphy_netns
,
8766 .policy
= nl80211_policy
,
8767 .flags
= GENL_ADMIN_PERM
,
8768 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8769 NL80211_FLAG_NEED_RTNL
,
8772 .cmd
= NL80211_CMD_GET_SURVEY
,
8773 .policy
= nl80211_policy
,
8774 .dumpit
= nl80211_dump_survey
,
8777 .cmd
= NL80211_CMD_SET_PMKSA
,
8778 .doit
= nl80211_setdel_pmksa
,
8779 .policy
= nl80211_policy
,
8780 .flags
= GENL_ADMIN_PERM
,
8781 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8782 NL80211_FLAG_NEED_RTNL
,
8785 .cmd
= NL80211_CMD_DEL_PMKSA
,
8786 .doit
= nl80211_setdel_pmksa
,
8787 .policy
= nl80211_policy
,
8788 .flags
= GENL_ADMIN_PERM
,
8789 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8790 NL80211_FLAG_NEED_RTNL
,
8793 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8794 .doit
= nl80211_flush_pmksa
,
8795 .policy
= nl80211_policy
,
8796 .flags
= GENL_ADMIN_PERM
,
8797 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8798 NL80211_FLAG_NEED_RTNL
,
8801 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8802 .doit
= nl80211_remain_on_channel
,
8803 .policy
= nl80211_policy
,
8804 .flags
= GENL_ADMIN_PERM
,
8805 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8806 NL80211_FLAG_NEED_RTNL
,
8809 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8810 .doit
= nl80211_cancel_remain_on_channel
,
8811 .policy
= nl80211_policy
,
8812 .flags
= GENL_ADMIN_PERM
,
8813 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8814 NL80211_FLAG_NEED_RTNL
,
8817 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8818 .doit
= nl80211_set_tx_bitrate_mask
,
8819 .policy
= nl80211_policy
,
8820 .flags
= GENL_ADMIN_PERM
,
8821 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8822 NL80211_FLAG_NEED_RTNL
,
8825 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8826 .doit
= nl80211_register_mgmt
,
8827 .policy
= nl80211_policy
,
8828 .flags
= GENL_ADMIN_PERM
,
8829 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8830 NL80211_FLAG_NEED_RTNL
,
8833 .cmd
= NL80211_CMD_FRAME
,
8834 .doit
= nl80211_tx_mgmt
,
8835 .policy
= nl80211_policy
,
8836 .flags
= GENL_ADMIN_PERM
,
8837 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8838 NL80211_FLAG_NEED_RTNL
,
8841 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8842 .doit
= nl80211_tx_mgmt_cancel_wait
,
8843 .policy
= nl80211_policy
,
8844 .flags
= GENL_ADMIN_PERM
,
8845 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8846 NL80211_FLAG_NEED_RTNL
,
8849 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8850 .doit
= nl80211_set_power_save
,
8851 .policy
= nl80211_policy
,
8852 .flags
= GENL_ADMIN_PERM
,
8853 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8854 NL80211_FLAG_NEED_RTNL
,
8857 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8858 .doit
= nl80211_get_power_save
,
8859 .policy
= nl80211_policy
,
8860 /* can be retrieved by unprivileged users */
8861 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8862 NL80211_FLAG_NEED_RTNL
,
8865 .cmd
= NL80211_CMD_SET_CQM
,
8866 .doit
= nl80211_set_cqm
,
8867 .policy
= nl80211_policy
,
8868 .flags
= GENL_ADMIN_PERM
,
8869 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8870 NL80211_FLAG_NEED_RTNL
,
8873 .cmd
= NL80211_CMD_SET_CHANNEL
,
8874 .doit
= nl80211_set_channel
,
8875 .policy
= nl80211_policy
,
8876 .flags
= GENL_ADMIN_PERM
,
8877 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8878 NL80211_FLAG_NEED_RTNL
,
8881 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8882 .doit
= nl80211_set_wds_peer
,
8883 .policy
= nl80211_policy
,
8884 .flags
= GENL_ADMIN_PERM
,
8885 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8886 NL80211_FLAG_NEED_RTNL
,
8889 .cmd
= NL80211_CMD_JOIN_MESH
,
8890 .doit
= nl80211_join_mesh
,
8891 .policy
= nl80211_policy
,
8892 .flags
= GENL_ADMIN_PERM
,
8893 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8894 NL80211_FLAG_NEED_RTNL
,
8897 .cmd
= NL80211_CMD_LEAVE_MESH
,
8898 .doit
= nl80211_leave_mesh
,
8899 .policy
= nl80211_policy
,
8900 .flags
= GENL_ADMIN_PERM
,
8901 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8902 NL80211_FLAG_NEED_RTNL
,
8906 .cmd
= NL80211_CMD_GET_WOWLAN
,
8907 .doit
= nl80211_get_wowlan
,
8908 .policy
= nl80211_policy
,
8909 /* can be retrieved by unprivileged users */
8910 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8911 NL80211_FLAG_NEED_RTNL
,
8914 .cmd
= NL80211_CMD_SET_WOWLAN
,
8915 .doit
= nl80211_set_wowlan
,
8916 .policy
= nl80211_policy
,
8917 .flags
= GENL_ADMIN_PERM
,
8918 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8919 NL80211_FLAG_NEED_RTNL
,
8923 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
8924 .doit
= nl80211_set_rekey_data
,
8925 .policy
= nl80211_policy
,
8926 .flags
= GENL_ADMIN_PERM
,
8927 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8928 NL80211_FLAG_NEED_RTNL
,
8931 .cmd
= NL80211_CMD_TDLS_MGMT
,
8932 .doit
= nl80211_tdls_mgmt
,
8933 .policy
= nl80211_policy
,
8934 .flags
= GENL_ADMIN_PERM
,
8935 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8936 NL80211_FLAG_NEED_RTNL
,
8939 .cmd
= NL80211_CMD_TDLS_OPER
,
8940 .doit
= nl80211_tdls_oper
,
8941 .policy
= nl80211_policy
,
8942 .flags
= GENL_ADMIN_PERM
,
8943 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8944 NL80211_FLAG_NEED_RTNL
,
8947 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
8948 .doit
= nl80211_register_unexpected_frame
,
8949 .policy
= nl80211_policy
,
8950 .flags
= GENL_ADMIN_PERM
,
8951 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8952 NL80211_FLAG_NEED_RTNL
,
8955 .cmd
= NL80211_CMD_PROBE_CLIENT
,
8956 .doit
= nl80211_probe_client
,
8957 .policy
= nl80211_policy
,
8958 .flags
= GENL_ADMIN_PERM
,
8959 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8960 NL80211_FLAG_NEED_RTNL
,
8963 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
8964 .doit
= nl80211_register_beacons
,
8965 .policy
= nl80211_policy
,
8966 .flags
= GENL_ADMIN_PERM
,
8967 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8968 NL80211_FLAG_NEED_RTNL
,
8971 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
8972 .doit
= nl80211_set_noack_map
,
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_START_P2P_DEVICE
,
8980 .doit
= nl80211_start_p2p_device
,
8981 .policy
= nl80211_policy
,
8982 .flags
= GENL_ADMIN_PERM
,
8983 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8984 NL80211_FLAG_NEED_RTNL
,
8987 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
8988 .doit
= nl80211_stop_p2p_device
,
8989 .policy
= nl80211_policy
,
8990 .flags
= GENL_ADMIN_PERM
,
8991 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8992 NL80211_FLAG_NEED_RTNL
,
8995 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
8996 .doit
= nl80211_set_mcast_rate
,
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_MAC_ACL
,
9004 .doit
= nl80211_set_mac_acl
,
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_RADAR_DETECT
,
9012 .doit
= nl80211_start_radar_detection
,
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_GET_PROTOCOL_FEATURES
,
9020 .doit
= nl80211_get_protocol_features
,
9021 .policy
= nl80211_policy
,
9024 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9025 .doit
= nl80211_update_ft_ies
,
9026 .policy
= nl80211_policy
,
9027 .flags
= GENL_ADMIN_PERM
,
9028 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9029 NL80211_FLAG_NEED_RTNL
,
9032 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9033 .doit
= nl80211_crit_protocol_start
,
9034 .policy
= nl80211_policy
,
9035 .flags
= GENL_ADMIN_PERM
,
9036 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9037 NL80211_FLAG_NEED_RTNL
,
9040 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9041 .doit
= nl80211_crit_protocol_stop
,
9042 .policy
= nl80211_policy
,
9043 .flags
= GENL_ADMIN_PERM
,
9044 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9045 NL80211_FLAG_NEED_RTNL
,
9049 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9053 /* multicast groups */
9054 static struct genl_multicast_group nl80211_config_mcgrp
= {
9057 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9060 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9061 .name
= "regulatory",
9064 /* notification functions */
9066 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9068 struct sk_buff
*msg
;
9069 struct nl80211_dump_wiphy_state state
= {};
9071 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9075 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0, &state
) < 0) {
9080 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9081 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9084 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9085 struct cfg80211_registered_device
*rdev
)
9087 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9088 struct nlattr
*nest
;
9094 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9096 goto nla_put_failure
;
9097 for (i
= 0; i
< req
->n_ssids
; i
++) {
9098 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9099 goto nla_put_failure
;
9101 nla_nest_end(msg
, nest
);
9103 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9105 goto nla_put_failure
;
9106 for (i
= 0; i
< req
->n_channels
; i
++) {
9107 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9108 goto nla_put_failure
;
9110 nla_nest_end(msg
, nest
);
9113 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9114 goto nla_put_failure
;
9117 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9124 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9125 struct cfg80211_registered_device
*rdev
,
9126 struct wireless_dev
*wdev
,
9127 u32 portid
, u32 seq
, int flags
,
9132 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9136 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9137 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9138 wdev
->netdev
->ifindex
)) ||
9139 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9140 goto nla_put_failure
;
9142 /* ignore errors and send incomplete event anyway */
9143 nl80211_add_scan_req(msg
, rdev
);
9145 return genlmsg_end(msg
, hdr
);
9148 genlmsg_cancel(msg
, hdr
);
9153 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9154 struct cfg80211_registered_device
*rdev
,
9155 struct net_device
*netdev
,
9156 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9160 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9164 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9165 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9166 goto nla_put_failure
;
9168 return genlmsg_end(msg
, hdr
);
9171 genlmsg_cancel(msg
, hdr
);
9175 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9176 struct wireless_dev
*wdev
)
9178 struct sk_buff
*msg
;
9180 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9184 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9185 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9190 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9191 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9194 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9195 struct wireless_dev
*wdev
)
9197 struct sk_buff
*msg
;
9199 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9203 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9204 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9209 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9210 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9213 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9214 struct wireless_dev
*wdev
)
9216 struct sk_buff
*msg
;
9218 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9222 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9223 NL80211_CMD_SCAN_ABORTED
) < 0) {
9228 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9229 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9232 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9233 struct net_device
*netdev
)
9235 struct sk_buff
*msg
;
9237 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9241 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9242 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9247 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9248 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9251 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9252 struct net_device
*netdev
, u32 cmd
)
9254 struct sk_buff
*msg
;
9256 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9260 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9265 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9266 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9270 * This can happen on global regulatory changes or device specific settings
9271 * based on custom world regulatory domains.
9273 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9275 struct sk_buff
*msg
;
9278 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9282 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9288 /* Userspace can always count this one always being set */
9289 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9290 goto nla_put_failure
;
9292 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9293 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9294 NL80211_REGDOM_TYPE_WORLD
))
9295 goto nla_put_failure
;
9296 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9297 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9298 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9299 goto nla_put_failure
;
9300 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9301 request
->intersect
) {
9302 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9303 NL80211_REGDOM_TYPE_INTERSECTION
))
9304 goto nla_put_failure
;
9306 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9307 NL80211_REGDOM_TYPE_COUNTRY
) ||
9308 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9310 goto nla_put_failure
;
9313 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9314 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9315 goto nla_put_failure
;
9317 genlmsg_end(msg
, hdr
);
9320 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9327 genlmsg_cancel(msg
, hdr
);
9331 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9332 struct net_device
*netdev
,
9333 const u8
*buf
, size_t len
,
9334 enum nl80211_commands cmd
, gfp_t gfp
)
9336 struct sk_buff
*msg
;
9339 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9343 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9349 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9350 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9351 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9352 goto nla_put_failure
;
9354 genlmsg_end(msg
, hdr
);
9356 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9357 nl80211_mlme_mcgrp
.id
, gfp
);
9361 genlmsg_cancel(msg
, hdr
);
9365 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9366 struct net_device
*netdev
, const u8
*buf
,
9367 size_t len
, gfp_t gfp
)
9369 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9370 NL80211_CMD_AUTHENTICATE
, gfp
);
9373 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9374 struct net_device
*netdev
, const u8
*buf
,
9375 size_t len
, gfp_t gfp
)
9377 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9378 NL80211_CMD_ASSOCIATE
, gfp
);
9381 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9382 struct net_device
*netdev
, const u8
*buf
,
9383 size_t len
, gfp_t gfp
)
9385 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9386 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9389 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9390 struct net_device
*netdev
, const u8
*buf
,
9391 size_t len
, gfp_t gfp
)
9393 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9394 NL80211_CMD_DISASSOCIATE
, gfp
);
9397 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
9400 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9401 struct wiphy
*wiphy
= wdev
->wiphy
;
9402 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9403 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
9406 if (WARN_ON(len
< 2))
9409 if (ieee80211_is_deauth(mgmt
->frame_control
))
9410 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
9412 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
9414 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
9415 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
);
9417 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
9419 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9420 struct net_device
*netdev
, int cmd
,
9421 const u8
*addr
, gfp_t gfp
)
9423 struct sk_buff
*msg
;
9426 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9430 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9436 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9437 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9438 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9439 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9440 goto nla_put_failure
;
9442 genlmsg_end(msg
, hdr
);
9444 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9445 nl80211_mlme_mcgrp
.id
, gfp
);
9449 genlmsg_cancel(msg
, hdr
);
9453 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9454 struct net_device
*netdev
, const u8
*addr
,
9457 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9461 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9462 struct net_device
*netdev
, const u8
*addr
,
9465 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9469 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9470 struct net_device
*netdev
, const u8
*bssid
,
9471 const u8
*req_ie
, size_t req_ie_len
,
9472 const u8
*resp_ie
, size_t resp_ie_len
,
9473 u16 status
, gfp_t gfp
)
9475 struct sk_buff
*msg
;
9478 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9482 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9488 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9489 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9490 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9491 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9493 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9495 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9496 goto nla_put_failure
;
9498 genlmsg_end(msg
, hdr
);
9500 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9501 nl80211_mlme_mcgrp
.id
, gfp
);
9505 genlmsg_cancel(msg
, hdr
);
9510 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9511 struct net_device
*netdev
, const u8
*bssid
,
9512 const u8
*req_ie
, size_t req_ie_len
,
9513 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9515 struct sk_buff
*msg
;
9518 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9522 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9528 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9529 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9530 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9532 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9534 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9535 goto nla_put_failure
;
9537 genlmsg_end(msg
, hdr
);
9539 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9540 nl80211_mlme_mcgrp
.id
, gfp
);
9544 genlmsg_cancel(msg
, hdr
);
9549 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9550 struct net_device
*netdev
, u16 reason
,
9551 const u8
*ie
, size_t ie_len
, bool from_ap
)
9553 struct sk_buff
*msg
;
9556 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9560 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9566 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9567 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9568 (from_ap
&& reason
&&
9569 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9571 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9572 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9573 goto nla_put_failure
;
9575 genlmsg_end(msg
, hdr
);
9577 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9578 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9582 genlmsg_cancel(msg
, hdr
);
9587 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9588 struct net_device
*netdev
, const u8
*bssid
,
9591 struct sk_buff
*msg
;
9594 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9598 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9604 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9605 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9606 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9607 goto nla_put_failure
;
9609 genlmsg_end(msg
, hdr
);
9611 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9612 nl80211_mlme_mcgrp
.id
, gfp
);
9616 genlmsg_cancel(msg
, hdr
);
9620 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9621 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9623 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9624 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9625 struct sk_buff
*msg
;
9628 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9631 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9633 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9637 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9643 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9644 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9645 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9647 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9648 goto nla_put_failure
;
9650 genlmsg_end(msg
, hdr
);
9652 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9653 nl80211_mlme_mcgrp
.id
, gfp
);
9657 genlmsg_cancel(msg
, hdr
);
9660 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9662 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9663 struct net_device
*netdev
, const u8
*addr
,
9664 enum nl80211_key_type key_type
, int key_id
,
9665 const u8
*tsc
, gfp_t gfp
)
9667 struct sk_buff
*msg
;
9670 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9674 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9680 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9681 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9682 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9683 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9685 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9686 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9687 goto nla_put_failure
;
9689 genlmsg_end(msg
, hdr
);
9691 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9692 nl80211_mlme_mcgrp
.id
, gfp
);
9696 genlmsg_cancel(msg
, hdr
);
9700 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9701 struct ieee80211_channel
*channel_before
,
9702 struct ieee80211_channel
*channel_after
)
9704 struct sk_buff
*msg
;
9706 struct nlattr
*nl_freq
;
9708 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9712 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9719 * Since we are applying the beacon hint to a wiphy we know its
9720 * wiphy_idx is valid
9722 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9723 goto nla_put_failure
;
9726 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9728 goto nla_put_failure
;
9729 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9730 goto nla_put_failure
;
9731 nla_nest_end(msg
, nl_freq
);
9734 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9736 goto nla_put_failure
;
9737 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9738 goto nla_put_failure
;
9739 nla_nest_end(msg
, nl_freq
);
9741 genlmsg_end(msg
, hdr
);
9744 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9751 genlmsg_cancel(msg
, hdr
);
9755 static void nl80211_send_remain_on_chan_event(
9756 int cmd
, struct cfg80211_registered_device
*rdev
,
9757 struct wireless_dev
*wdev
, u64 cookie
,
9758 struct ieee80211_channel
*chan
,
9759 unsigned int duration
, gfp_t gfp
)
9761 struct sk_buff
*msg
;
9764 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9768 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9774 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9775 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9776 wdev
->netdev
->ifindex
)) ||
9777 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9778 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9779 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9780 NL80211_CHAN_NO_HT
) ||
9781 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9782 goto nla_put_failure
;
9784 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9785 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9786 goto nla_put_failure
;
9788 genlmsg_end(msg
, hdr
);
9790 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9791 nl80211_mlme_mcgrp
.id
, gfp
);
9795 genlmsg_cancel(msg
, hdr
);
9799 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9800 struct ieee80211_channel
*chan
,
9801 unsigned int duration
, gfp_t gfp
)
9803 struct wiphy
*wiphy
= wdev
->wiphy
;
9804 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9806 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9807 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9808 rdev
, wdev
, cookie
, chan
,
9811 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9813 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9814 struct ieee80211_channel
*chan
,
9817 struct wiphy
*wiphy
= wdev
->wiphy
;
9818 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9820 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9821 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9822 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9824 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9826 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9827 struct station_info
*sinfo
, gfp_t gfp
)
9829 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9830 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9831 struct sk_buff
*msg
;
9833 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9835 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9839 if (nl80211_send_station(msg
, 0, 0, 0,
9840 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9845 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9846 nl80211_mlme_mcgrp
.id
, gfp
);
9848 EXPORT_SYMBOL(cfg80211_new_sta
);
9850 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9852 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9853 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9854 struct sk_buff
*msg
;
9857 trace_cfg80211_del_sta(dev
, mac_addr
);
9859 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9863 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9869 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9870 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9871 goto nla_put_failure
;
9873 genlmsg_end(msg
, hdr
);
9875 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9876 nl80211_mlme_mcgrp
.id
, gfp
);
9880 genlmsg_cancel(msg
, hdr
);
9883 EXPORT_SYMBOL(cfg80211_del_sta
);
9885 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
9886 enum nl80211_connect_failed_reason reason
,
9889 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9890 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9891 struct sk_buff
*msg
;
9894 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
9898 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
9904 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9905 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
9906 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
9907 goto nla_put_failure
;
9909 genlmsg_end(msg
, hdr
);
9911 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9912 nl80211_mlme_mcgrp
.id
, gfp
);
9916 genlmsg_cancel(msg
, hdr
);
9919 EXPORT_SYMBOL(cfg80211_conn_failed
);
9921 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
9922 const u8
*addr
, gfp_t gfp
)
9924 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9925 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9926 struct sk_buff
*msg
;
9928 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
9933 msg
= nlmsg_new(100, gfp
);
9937 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9943 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9944 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9945 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9946 goto nla_put_failure
;
9948 genlmsg_end(msg
, hdr
);
9949 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9953 genlmsg_cancel(msg
, hdr
);
9958 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
9959 const u8
*addr
, gfp_t gfp
)
9961 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9964 trace_cfg80211_rx_spurious_frame(dev
, addr
);
9966 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9967 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
9968 trace_cfg80211_return_bool(false);
9971 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
9973 trace_cfg80211_return_bool(ret
);
9976 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
9978 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
9979 const u8
*addr
, gfp_t gfp
)
9981 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9984 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
9986 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9987 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
9988 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
9989 trace_cfg80211_return_bool(false);
9992 ret
= __nl80211_unexpected_frame(dev
,
9993 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
9995 trace_cfg80211_return_bool(ret
);
9998 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10000 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10001 struct wireless_dev
*wdev
, u32 nlportid
,
10002 int freq
, int sig_dbm
,
10003 const u8
*buf
, size_t len
, gfp_t gfp
)
10005 struct net_device
*netdev
= wdev
->netdev
;
10006 struct sk_buff
*msg
;
10009 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10013 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10019 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10020 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10021 netdev
->ifindex
)) ||
10022 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10023 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10025 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10026 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10027 goto nla_put_failure
;
10029 genlmsg_end(msg
, hdr
);
10031 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10034 genlmsg_cancel(msg
, hdr
);
10039 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10040 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10042 struct wiphy
*wiphy
= wdev
->wiphy
;
10043 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10044 struct net_device
*netdev
= wdev
->netdev
;
10045 struct sk_buff
*msg
;
10048 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10050 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10054 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10060 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10061 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10062 netdev
->ifindex
)) ||
10063 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10064 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10065 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10066 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10067 goto nla_put_failure
;
10069 genlmsg_end(msg
, hdr
);
10071 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10072 nl80211_mlme_mcgrp
.id
, gfp
);
10076 genlmsg_cancel(msg
, hdr
);
10079 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10081 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10082 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10085 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10086 struct wiphy
*wiphy
= wdev
->wiphy
;
10087 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10088 struct sk_buff
*msg
;
10089 struct nlattr
*pinfoattr
;
10092 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10094 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10098 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10104 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10105 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10106 goto nla_put_failure
;
10108 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10110 goto nla_put_failure
;
10112 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10114 goto nla_put_failure
;
10116 nla_nest_end(msg
, pinfoattr
);
10118 genlmsg_end(msg
, hdr
);
10120 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10121 nl80211_mlme_mcgrp
.id
, gfp
);
10125 genlmsg_cancel(msg
, hdr
);
10128 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10130 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10131 struct net_device
*netdev
, const u8
*bssid
,
10132 const u8
*replay_ctr
, gfp_t gfp
)
10134 struct sk_buff
*msg
;
10135 struct nlattr
*rekey_attr
;
10138 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10142 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10148 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10149 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10150 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10151 goto nla_put_failure
;
10153 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10155 goto nla_put_failure
;
10157 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10158 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10159 goto nla_put_failure
;
10161 nla_nest_end(msg
, rekey_attr
);
10163 genlmsg_end(msg
, hdr
);
10165 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10166 nl80211_mlme_mcgrp
.id
, gfp
);
10170 genlmsg_cancel(msg
, hdr
);
10174 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10175 const u8
*replay_ctr
, gfp_t gfp
)
10177 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10178 struct wiphy
*wiphy
= wdev
->wiphy
;
10179 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10181 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10182 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10184 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10187 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10188 struct net_device
*netdev
, int index
,
10189 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10191 struct sk_buff
*msg
;
10192 struct nlattr
*attr
;
10195 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10199 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10205 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10206 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10207 goto nla_put_failure
;
10209 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10211 goto nla_put_failure
;
10213 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10214 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10216 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10217 goto nla_put_failure
;
10219 nla_nest_end(msg
, attr
);
10221 genlmsg_end(msg
, hdr
);
10223 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10224 nl80211_mlme_mcgrp
.id
, gfp
);
10228 genlmsg_cancel(msg
, hdr
);
10232 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10233 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10235 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10236 struct wiphy
*wiphy
= wdev
->wiphy
;
10237 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10239 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10240 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10242 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10244 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10245 struct net_device
*netdev
,
10246 struct cfg80211_chan_def
*chandef
,
10249 struct sk_buff
*msg
;
10252 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10256 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10262 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10263 goto nla_put_failure
;
10265 if (nl80211_send_chandef(msg
, chandef
))
10266 goto nla_put_failure
;
10268 genlmsg_end(msg
, hdr
);
10270 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10271 nl80211_mlme_mcgrp
.id
, gfp
);
10275 genlmsg_cancel(msg
, hdr
);
10279 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10280 struct cfg80211_chan_def
*chandef
)
10282 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10283 struct wiphy
*wiphy
= wdev
->wiphy
;
10284 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10286 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10290 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10291 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10294 wdev
->channel
= chandef
->chan
;
10295 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10300 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10302 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10303 const u8
*peer
, u32 num_packets
,
10304 u32 rate
, u32 intvl
, gfp_t gfp
)
10306 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10307 struct wiphy
*wiphy
= wdev
->wiphy
;
10308 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10309 struct sk_buff
*msg
;
10310 struct nlattr
*pinfoattr
;
10313 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10317 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10323 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10324 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10325 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10326 goto nla_put_failure
;
10328 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10330 goto nla_put_failure
;
10332 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10333 goto nla_put_failure
;
10335 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10336 goto nla_put_failure
;
10338 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10339 goto nla_put_failure
;
10341 nla_nest_end(msg
, pinfoattr
);
10343 genlmsg_end(msg
, hdr
);
10345 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10346 nl80211_mlme_mcgrp
.id
, gfp
);
10350 genlmsg_cancel(msg
, hdr
);
10353 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10356 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10357 struct cfg80211_chan_def
*chandef
,
10358 enum nl80211_radar_event event
,
10359 struct net_device
*netdev
, gfp_t gfp
)
10361 struct sk_buff
*msg
;
10364 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10368 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10374 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10375 goto nla_put_failure
;
10377 /* NOP and radar events don't need a netdev parameter */
10379 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10381 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10382 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10383 goto nla_put_failure
;
10386 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10387 goto nla_put_failure
;
10389 if (nl80211_send_chandef(msg
, chandef
))
10390 goto nla_put_failure
;
10392 genlmsg_end(msg
, hdr
);
10394 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10395 nl80211_mlme_mcgrp
.id
, gfp
);
10399 genlmsg_cancel(msg
, hdr
);
10403 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10404 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10406 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10407 struct wiphy
*wiphy
= wdev
->wiphy
;
10408 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10409 struct sk_buff
*msg
;
10410 struct nlattr
*pinfoattr
;
10413 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10415 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10419 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10425 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10426 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10427 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10428 goto nla_put_failure
;
10430 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10432 goto nla_put_failure
;
10434 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10435 goto nla_put_failure
;
10437 nla_nest_end(msg
, pinfoattr
);
10439 genlmsg_end(msg
, hdr
);
10441 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10442 nl80211_mlme_mcgrp
.id
, gfp
);
10446 genlmsg_cancel(msg
, hdr
);
10449 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10451 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10452 u64 cookie
, bool acked
, gfp_t gfp
)
10454 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10455 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10456 struct sk_buff
*msg
;
10459 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10461 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10466 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10472 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10473 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10474 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10475 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10476 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10477 goto nla_put_failure
;
10479 genlmsg_end(msg
, hdr
);
10481 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10482 nl80211_mlme_mcgrp
.id
, gfp
);
10486 genlmsg_cancel(msg
, hdr
);
10489 EXPORT_SYMBOL(cfg80211_probe_status
);
10491 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10492 const u8
*frame
, size_t len
,
10493 int freq
, int sig_dbm
)
10495 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10496 struct sk_buff
*msg
;
10498 struct cfg80211_beacon_registration
*reg
;
10500 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10502 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10503 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10504 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10506 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10510 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10512 goto nla_put_failure
;
10514 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10516 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10518 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10519 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10520 goto nla_put_failure
;
10522 genlmsg_end(msg
, hdr
);
10524 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10526 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10530 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10532 genlmsg_cancel(msg
, hdr
);
10535 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10538 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10539 struct cfg80211_wowlan_wakeup
*wakeup
,
10542 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10543 struct sk_buff
*msg
;
10547 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10550 size
+= wakeup
->packet_present_len
;
10552 msg
= nlmsg_new(size
, gfp
);
10556 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10560 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10561 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10564 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10565 wdev
->netdev
->ifindex
))
10569 struct nlattr
*reasons
;
10571 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10573 if (wakeup
->disconnect
&&
10574 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10576 if (wakeup
->magic_pkt
&&
10577 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10579 if (wakeup
->gtk_rekey_failure
&&
10580 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10582 if (wakeup
->eap_identity_req
&&
10583 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10585 if (wakeup
->four_way_handshake
&&
10586 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10588 if (wakeup
->rfkill_release
&&
10589 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10592 if (wakeup
->pattern_idx
>= 0 &&
10593 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10594 wakeup
->pattern_idx
))
10597 if (wakeup
->tcp_match
)
10598 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10600 if (wakeup
->tcp_connlost
)
10602 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10604 if (wakeup
->tcp_nomoretokens
)
10606 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10608 if (wakeup
->packet
) {
10609 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10610 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10612 if (!wakeup
->packet_80211
) {
10614 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10616 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10619 if (wakeup
->packet_len
&&
10620 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10623 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10628 nla_nest_end(msg
, reasons
);
10631 genlmsg_end(msg
, hdr
);
10633 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10634 nl80211_mlme_mcgrp
.id
, gfp
);
10640 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10643 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10644 enum nl80211_tdls_operation oper
,
10645 u16 reason_code
, gfp_t gfp
)
10647 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10648 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10649 struct sk_buff
*msg
;
10652 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10655 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10659 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10665 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10666 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10667 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10668 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10669 (reason_code
> 0 &&
10670 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10671 goto nla_put_failure
;
10673 genlmsg_end(msg
, hdr
);
10675 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10676 nl80211_mlme_mcgrp
.id
, gfp
);
10680 genlmsg_cancel(msg
, hdr
);
10683 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10685 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10686 unsigned long state
,
10689 struct netlink_notify
*notify
= _notify
;
10690 struct cfg80211_registered_device
*rdev
;
10691 struct wireless_dev
*wdev
;
10692 struct cfg80211_beacon_registration
*reg
, *tmp
;
10694 if (state
!= NETLINK_URELEASE
)
10695 return NOTIFY_DONE
;
10699 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10700 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10701 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10703 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10704 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10706 if (reg
->nlportid
== notify
->portid
) {
10707 list_del(®
->list
);
10712 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10717 return NOTIFY_DONE
;
10720 static struct notifier_block nl80211_netlink_notifier
= {
10721 .notifier_call
= nl80211_netlink_notify
,
10724 void cfg80211_ft_event(struct net_device
*netdev
,
10725 struct cfg80211_ft_event_params
*ft_event
)
10727 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10728 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10729 struct sk_buff
*msg
;
10732 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10734 if (!ft_event
->target_ap
)
10737 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10741 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10747 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10748 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10749 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10751 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10752 if (ft_event
->ric_ies
)
10753 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10754 ft_event
->ric_ies
);
10756 genlmsg_end(msg
, hdr
);
10758 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10759 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10761 EXPORT_SYMBOL(cfg80211_ft_event
);
10763 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10765 struct cfg80211_registered_device
*rdev
;
10766 struct sk_buff
*msg
;
10770 rdev
= wiphy_to_dev(wdev
->wiphy
);
10771 if (!rdev
->crit_proto_nlportid
)
10774 nlportid
= rdev
->crit_proto_nlportid
;
10775 rdev
->crit_proto_nlportid
= 0;
10777 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10781 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10783 goto nla_put_failure
;
10785 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10786 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10787 goto nla_put_failure
;
10789 genlmsg_end(msg
, hdr
);
10791 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10796 genlmsg_cancel(msg
, hdr
);
10800 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10802 /* initialisation/exit functions */
10804 int nl80211_init(void)
10808 err
= genl_register_family_with_ops(&nl80211_fam
,
10809 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10813 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10817 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10821 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10825 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10829 #ifdef CONFIG_NL80211_TESTMODE
10830 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10835 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10841 genl_unregister_family(&nl80211_fam
);
10845 void nl80211_exit(void)
10847 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10848 genl_unregister_family(&nl80211_fam
);