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 cb
->args
[0] = (*rdev
)->wiphy_idx
;
445 cb
->args
[1] = (*wdev
)->identifier
;
447 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0]);
448 struct wireless_dev
*tmp
;
454 *rdev
= wiphy_to_dev(wiphy
);
457 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
458 if (tmp
->identifier
== cb
->args
[1]) {
476 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
482 static bool is_valid_ie_attr(const struct nlattr
*attr
)
490 pos
= nla_data(attr
);
511 /* message building helper */
512 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
515 /* since there is no private header just add the generic one */
516 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
519 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
520 struct ieee80211_channel
*chan
,
523 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
525 goto nla_put_failure
;
527 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
528 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
529 goto nla_put_failure
;
530 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
531 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
532 goto nla_put_failure
;
533 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
534 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
535 goto nla_put_failure
;
536 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
537 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
538 goto nla_put_failure
;
542 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
544 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
546 goto nla_put_failure
;
547 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
549 goto nla_put_failure
;
554 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
555 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
556 goto nla_put_failure
;
557 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
558 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
559 goto nla_put_failure
;
560 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
561 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
562 goto nla_put_failure
;
563 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
564 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
565 goto nla_put_failure
;
568 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
569 DBM_TO_MBM(chan
->max_power
)))
570 goto nla_put_failure
;
578 /* netlink command implementations */
585 bool def_uni
, def_multi
;
588 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
590 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
591 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
596 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
597 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
606 if (tb
[NL80211_KEY_IDX
])
607 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
609 if (tb
[NL80211_KEY_DATA
]) {
610 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
611 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
614 if (tb
[NL80211_KEY_SEQ
]) {
615 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
616 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
619 if (tb
[NL80211_KEY_CIPHER
])
620 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
622 if (tb
[NL80211_KEY_TYPE
]) {
623 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
624 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
628 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
629 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
630 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
631 tb
[NL80211_KEY_DEFAULT_TYPES
],
632 nl80211_key_default_policy
);
636 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
637 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
643 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
645 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
646 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
647 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
650 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
651 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
652 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
655 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
656 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
658 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
659 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
661 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
662 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
671 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
672 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
673 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
677 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
678 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
679 int err
= nla_parse_nested(
680 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
681 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
682 nl80211_key_default_policy
);
686 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
687 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
693 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
697 memset(k
, 0, sizeof(*k
));
701 if (info
->attrs
[NL80211_ATTR_KEY
])
702 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
704 err
= nl80211_parse_key_old(info
, k
);
709 if (k
->def
&& k
->defmgmt
)
713 if (k
->def_uni
|| !k
->def_multi
)
719 if (k
->idx
< 4 || k
->idx
> 5)
722 if (k
->idx
< 0 || k
->idx
> 3)
725 if (k
->idx
< 0 || k
->idx
> 5)
733 static struct cfg80211_cached_keys
*
734 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
735 struct nlattr
*keys
, bool *no_ht
)
737 struct key_parse parse
;
739 struct cfg80211_cached_keys
*result
;
740 int rem
, err
, def
= 0;
742 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
744 return ERR_PTR(-ENOMEM
);
747 result
->defmgmt
= -1;
749 nla_for_each_nested(key
, keys
, rem
) {
750 memset(&parse
, 0, sizeof(parse
));
753 err
= nl80211_parse_key_new(key
, &parse
);
759 if (parse
.idx
< 0 || parse
.idx
> 4)
765 result
->def
= parse
.idx
;
766 if (!parse
.def_uni
|| !parse
.def_multi
)
768 } else if (parse
.defmgmt
)
770 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
771 parse
.idx
, false, NULL
);
774 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
775 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
776 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
777 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
779 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
780 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
792 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
794 ASSERT_WDEV_LOCK(wdev
);
796 switch (wdev
->iftype
) {
797 case NL80211_IFTYPE_AP
:
798 case NL80211_IFTYPE_AP_VLAN
:
799 case NL80211_IFTYPE_P2P_GO
:
800 case NL80211_IFTYPE_MESH_POINT
:
802 case NL80211_IFTYPE_ADHOC
:
803 case NL80211_IFTYPE_STATION
:
804 case NL80211_IFTYPE_P2P_CLIENT
:
805 if (!wdev
->current_bss
)
815 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
817 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
821 goto nla_put_failure
;
825 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
826 goto nla_put_failure
;
831 nla_nest_end(msg
, nl_modes
);
838 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
842 struct nlattr
*nl_combis
;
845 nl_combis
= nla_nest_start(msg
,
846 NL80211_ATTR_INTERFACE_COMBINATIONS
);
848 goto nla_put_failure
;
850 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
851 const struct ieee80211_iface_combination
*c
;
852 struct nlattr
*nl_combi
, *nl_limits
;
854 c
= &wiphy
->iface_combinations
[i
];
856 nl_combi
= nla_nest_start(msg
, i
+ 1);
858 goto nla_put_failure
;
860 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
862 goto nla_put_failure
;
864 for (j
= 0; j
< c
->n_limits
; j
++) {
865 struct nlattr
*nl_limit
;
867 nl_limit
= nla_nest_start(msg
, j
+ 1);
869 goto nla_put_failure
;
870 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
872 goto nla_put_failure
;
873 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
875 goto nla_put_failure
;
876 nla_nest_end(msg
, nl_limit
);
879 nla_nest_end(msg
, nl_limits
);
881 if (c
->beacon_int_infra_match
&&
882 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
883 goto nla_put_failure
;
884 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
885 c
->num_different_channels
) ||
886 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
888 goto nla_put_failure
;
890 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
891 c
->radar_detect_widths
))
892 goto nla_put_failure
;
894 nla_nest_end(msg
, nl_combi
);
897 nla_nest_end(msg
, nl_combis
);
905 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
908 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
909 struct nlattr
*nl_tcp
;
914 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
918 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
919 tcp
->data_payload_max
))
922 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
923 tcp
->data_payload_max
))
926 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
929 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
930 sizeof(*tcp
->tok
), tcp
->tok
))
933 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
934 tcp
->data_interval_max
))
937 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
938 tcp
->wake_payload_max
))
941 nla_nest_end(msg
, nl_tcp
);
945 static int nl80211_send_wowlan(struct sk_buff
*msg
,
946 struct cfg80211_registered_device
*dev
,
949 struct nlattr
*nl_wowlan
;
951 if (!dev
->wiphy
.wowlan
)
954 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
958 if (((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
959 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
960 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
961 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
962 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
963 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
964 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
965 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
966 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
967 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
968 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
969 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
970 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
971 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
972 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
973 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
976 if (dev
->wiphy
.wowlan
->n_patterns
) {
977 struct nl80211_wowlan_pattern_support pat
= {
978 .max_patterns
= dev
->wiphy
.wowlan
->n_patterns
,
979 .min_pattern_len
= dev
->wiphy
.wowlan
->pattern_min_len
,
980 .max_pattern_len
= dev
->wiphy
.wowlan
->pattern_max_len
,
981 .max_pkt_offset
= dev
->wiphy
.wowlan
->max_pkt_offset
,
984 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
989 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
992 nla_nest_end(msg
, nl_wowlan
);
998 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
999 struct ieee80211_supported_band
*sband
)
1001 struct nlattr
*nl_rates
, *nl_rate
;
1002 struct ieee80211_rate
*rate
;
1006 if (sband
->ht_cap
.ht_supported
&&
1007 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1008 sizeof(sband
->ht_cap
.mcs
),
1009 &sband
->ht_cap
.mcs
) ||
1010 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1011 sband
->ht_cap
.cap
) ||
1012 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1013 sband
->ht_cap
.ampdu_factor
) ||
1014 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1015 sband
->ht_cap
.ampdu_density
)))
1019 if (sband
->vht_cap
.vht_supported
&&
1020 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1021 sizeof(sband
->vht_cap
.vht_mcs
),
1022 &sband
->vht_cap
.vht_mcs
) ||
1023 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1024 sband
->vht_cap
.cap
)))
1028 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1032 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1033 nl_rate
= nla_nest_start(msg
, i
);
1037 rate
= &sband
->bitrates
[i
];
1038 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1041 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1043 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1046 nla_nest_end(msg
, nl_rate
);
1049 nla_nest_end(msg
, nl_rates
);
1055 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1056 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1059 struct nlattr
*nl_ftypes
, *nl_ifs
;
1060 enum nl80211_iftype ift
;
1066 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1070 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1071 nl_ftypes
= nla_nest_start(msg
, ift
);
1075 stypes
= mgmt_stypes
[ift
].tx
;
1078 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1079 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1084 nla_nest_end(msg
, nl_ftypes
);
1087 nla_nest_end(msg
, nl_ifs
);
1089 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1093 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1094 nl_ftypes
= nla_nest_start(msg
, ift
);
1098 stypes
= mgmt_stypes
[ift
].rx
;
1101 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1102 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1107 nla_nest_end(msg
, nl_ftypes
);
1109 nla_nest_end(msg
, nl_ifs
);
1114 struct nl80211_dump_wiphy_state
{
1117 long split_start
, band_start
, chan_start
;
1121 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1122 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1123 int flags
, struct nl80211_dump_wiphy_state
*state
)
1126 struct nlattr
*nl_bands
, *nl_band
;
1127 struct nlattr
*nl_freqs
, *nl_freq
;
1128 struct nlattr
*nl_cmds
;
1129 enum ieee80211_band band
;
1130 struct ieee80211_channel
*chan
;
1132 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1133 dev
->wiphy
.mgmt_stypes
;
1136 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1140 if (WARN_ON(!state
))
1143 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1144 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1145 wiphy_name(&dev
->wiphy
)) ||
1146 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1147 cfg80211_rdev_list_generation
))
1148 goto nla_put_failure
;
1150 switch (state
->split_start
) {
1152 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1153 dev
->wiphy
.retry_short
) ||
1154 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1155 dev
->wiphy
.retry_long
) ||
1156 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1157 dev
->wiphy
.frag_threshold
) ||
1158 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1159 dev
->wiphy
.rts_threshold
) ||
1160 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1161 dev
->wiphy
.coverage_class
) ||
1162 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1163 dev
->wiphy
.max_scan_ssids
) ||
1164 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1165 dev
->wiphy
.max_sched_scan_ssids
) ||
1166 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1167 dev
->wiphy
.max_scan_ie_len
) ||
1168 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1169 dev
->wiphy
.max_sched_scan_ie_len
) ||
1170 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1171 dev
->wiphy
.max_match_sets
))
1172 goto nla_put_failure
;
1174 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1175 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1176 goto nla_put_failure
;
1177 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1178 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1179 goto nla_put_failure
;
1180 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1181 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1182 goto nla_put_failure
;
1183 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1184 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1185 goto nla_put_failure
;
1186 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1187 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1188 goto nla_put_failure
;
1189 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1190 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1191 goto nla_put_failure
;
1192 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1193 nla_put_flag(msg
, WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1194 goto nla_put_failure
;
1196 state
->split_start
++;
1200 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1201 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1202 dev
->wiphy
.cipher_suites
))
1203 goto nla_put_failure
;
1205 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1206 dev
->wiphy
.max_num_pmkids
))
1207 goto nla_put_failure
;
1209 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1210 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1211 goto nla_put_failure
;
1213 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1214 dev
->wiphy
.available_antennas_tx
) ||
1215 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1216 dev
->wiphy
.available_antennas_rx
))
1217 goto nla_put_failure
;
1219 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1220 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1221 dev
->wiphy
.probe_resp_offload
))
1222 goto nla_put_failure
;
1224 if ((dev
->wiphy
.available_antennas_tx
||
1225 dev
->wiphy
.available_antennas_rx
) &&
1226 dev
->ops
->get_antenna
) {
1227 u32 tx_ant
= 0, rx_ant
= 0;
1229 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1231 if (nla_put_u32(msg
,
1232 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1235 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1237 goto nla_put_failure
;
1241 state
->split_start
++;
1245 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1246 dev
->wiphy
.interface_modes
))
1247 goto nla_put_failure
;
1248 state
->split_start
++;
1252 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1254 goto nla_put_failure
;
1256 for (band
= state
->band_start
;
1257 band
< IEEE80211_NUM_BANDS
; band
++) {
1258 struct ieee80211_supported_band
*sband
;
1260 sband
= dev
->wiphy
.bands
[band
];
1265 nl_band
= nla_nest_start(msg
, band
);
1267 goto nla_put_failure
;
1269 switch (state
->chan_start
) {
1271 if (nl80211_send_band_rateinfo(msg
, sband
))
1272 goto nla_put_failure
;
1273 state
->chan_start
++;
1277 /* add frequencies */
1278 nl_freqs
= nla_nest_start(
1279 msg
, NL80211_BAND_ATTR_FREQS
);
1281 goto nla_put_failure
;
1283 for (i
= state
->chan_start
- 1;
1284 i
< sband
->n_channels
;
1286 nl_freq
= nla_nest_start(msg
, i
);
1288 goto nla_put_failure
;
1290 chan
= &sband
->channels
[i
];
1292 if (nl80211_msg_put_channel(
1295 goto nla_put_failure
;
1297 nla_nest_end(msg
, nl_freq
);
1301 if (i
< sband
->n_channels
)
1302 state
->chan_start
= i
+ 2;
1304 state
->chan_start
= 0;
1305 nla_nest_end(msg
, nl_freqs
);
1308 nla_nest_end(msg
, nl_band
);
1311 /* start again here */
1312 if (state
->chan_start
)
1317 nla_nest_end(msg
, nl_bands
);
1319 if (band
< IEEE80211_NUM_BANDS
)
1320 state
->band_start
= band
+ 1;
1322 state
->band_start
= 0;
1324 /* if bands & channels are done, continue outside */
1325 if (state
->band_start
== 0 && state
->chan_start
== 0)
1326 state
->split_start
++;
1330 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1332 goto nla_put_failure
;
1335 #define CMD(op, n) \
1337 if (dev->ops->op) { \
1339 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1340 goto nla_put_failure; \
1344 CMD(add_virtual_intf
, NEW_INTERFACE
);
1345 CMD(change_virtual_intf
, SET_INTERFACE
);
1346 CMD(add_key
, NEW_KEY
);
1347 CMD(start_ap
, START_AP
);
1348 CMD(add_station
, NEW_STATION
);
1349 CMD(add_mpath
, NEW_MPATH
);
1350 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1351 CMD(change_bss
, SET_BSS
);
1352 CMD(auth
, AUTHENTICATE
);
1353 CMD(assoc
, ASSOCIATE
);
1354 CMD(deauth
, DEAUTHENTICATE
);
1355 CMD(disassoc
, DISASSOCIATE
);
1356 CMD(join_ibss
, JOIN_IBSS
);
1357 CMD(join_mesh
, JOIN_MESH
);
1358 CMD(set_pmksa
, SET_PMKSA
);
1359 CMD(del_pmksa
, DEL_PMKSA
);
1360 CMD(flush_pmksa
, FLUSH_PMKSA
);
1361 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1362 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1363 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1364 CMD(mgmt_tx
, FRAME
);
1365 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1366 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1368 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1369 goto nla_put_failure
;
1371 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1372 dev
->ops
->join_mesh
) {
1374 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1375 goto nla_put_failure
;
1377 CMD(set_wds_peer
, SET_WDS_PEER
);
1378 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1379 CMD(tdls_mgmt
, TDLS_MGMT
);
1380 CMD(tdls_oper
, TDLS_OPER
);
1382 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1383 CMD(sched_scan_start
, START_SCHED_SCAN
);
1384 CMD(probe_client
, PROBE_CLIENT
);
1385 CMD(set_noack_map
, SET_NOACK_MAP
);
1386 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1388 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1389 goto nla_put_failure
;
1391 CMD(start_p2p_device
, START_P2P_DEVICE
);
1392 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1394 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1395 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1398 #ifdef CONFIG_NL80211_TESTMODE
1399 CMD(testmode_cmd
, TESTMODE
);
1404 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1406 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1407 goto nla_put_failure
;
1410 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1412 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1413 goto nla_put_failure
;
1416 nla_nest_end(msg
, nl_cmds
);
1417 state
->split_start
++;
1421 if (dev
->ops
->remain_on_channel
&&
1422 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1424 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1425 dev
->wiphy
.max_remain_on_channel_duration
))
1426 goto nla_put_failure
;
1428 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1429 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1430 goto nla_put_failure
;
1432 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1433 goto nla_put_failure
;
1434 state
->split_start
++;
1439 if (nl80211_send_wowlan(msg
, dev
, state
->split
))
1440 goto nla_put_failure
;
1441 state
->split_start
++;
1445 state
->split_start
++;
1448 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1449 dev
->wiphy
.software_iftypes
))
1450 goto nla_put_failure
;
1452 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
,
1454 goto nla_put_failure
;
1456 state
->split_start
++;
1460 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1461 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1462 dev
->wiphy
.ap_sme_capa
))
1463 goto nla_put_failure
;
1465 features
= dev
->wiphy
.features
;
1467 * We can only add the per-channel limit information if the
1468 * dump is split, otherwise it makes it too big. Therefore
1469 * only advertise it in that case.
1472 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1473 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1474 goto nla_put_failure
;
1476 if (dev
->wiphy
.ht_capa_mod_mask
&&
1477 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1478 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1479 dev
->wiphy
.ht_capa_mod_mask
))
1480 goto nla_put_failure
;
1482 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1483 dev
->wiphy
.max_acl_mac_addrs
&&
1484 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1485 dev
->wiphy
.max_acl_mac_addrs
))
1486 goto nla_put_failure
;
1489 * Any information below this point is only available to
1490 * applications that can deal with it being split. This
1491 * helps ensure that newly added capabilities don't break
1492 * older tools by overrunning their buffers.
1494 * We still increment split_start so that in the split
1495 * case we'll continue with more data in the next round,
1496 * but break unconditionally so unsplit data stops here.
1498 state
->split_start
++;
1501 if (dev
->wiphy
.extended_capabilities
&&
1502 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1503 dev
->wiphy
.extended_capabilities_len
,
1504 dev
->wiphy
.extended_capabilities
) ||
1505 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1506 dev
->wiphy
.extended_capabilities_len
,
1507 dev
->wiphy
.extended_capabilities_mask
)))
1508 goto nla_put_failure
;
1510 if (dev
->wiphy
.vht_capa_mod_mask
&&
1511 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1512 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1513 dev
->wiphy
.vht_capa_mod_mask
))
1514 goto nla_put_failure
;
1517 state
->split_start
= 0;
1520 return genlmsg_end(msg
, hdr
);
1523 genlmsg_cancel(msg
, hdr
);
1527 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1528 struct netlink_callback
*cb
,
1529 struct nl80211_dump_wiphy_state
*state
)
1531 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1532 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1533 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1534 /* ignore parse errors for backward compatibility */
1538 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1539 if (tb
[NL80211_ATTR_WIPHY
])
1540 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1541 if (tb
[NL80211_ATTR_WDEV
])
1542 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1543 if (tb
[NL80211_ATTR_IFINDEX
]) {
1544 struct net_device
*netdev
;
1545 struct cfg80211_registered_device
*rdev
;
1546 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1548 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1551 if (netdev
->ieee80211_ptr
) {
1552 rdev
= wiphy_to_dev(
1553 netdev
->ieee80211_ptr
->wiphy
);
1554 state
->filter_wiphy
= rdev
->wiphy_idx
;
1562 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1565 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1566 struct cfg80211_registered_device
*dev
;
1570 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1575 state
->filter_wiphy
= -1;
1576 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1582 cb
->args
[0] = (long)state
;
1585 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1586 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1588 if (++idx
<= state
->start
)
1590 if (state
->filter_wiphy
!= -1 &&
1591 state
->filter_wiphy
!= dev
->wiphy_idx
)
1593 /* attempt to fit multiple wiphy data chunks into the skb */
1595 ret
= nl80211_send_wiphy(dev
, skb
,
1596 NETLINK_CB(cb
->skb
).portid
,
1598 NLM_F_MULTI
, state
);
1601 * If sending the wiphy data didn't fit (ENOBUFS
1602 * or EMSGSIZE returned), this SKB is still
1603 * empty (so it's not too big because another
1604 * wiphy dataset is already in the skb) and
1605 * we've not tried to adjust the dump allocation
1606 * yet ... then adjust the alloc size to be
1607 * bigger, and return 1 but with the empty skb.
1608 * This results in an empty message being RX'ed
1609 * in userspace, but that is ignored.
1611 * We can then retry with the larger buffer.
1613 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1615 cb
->min_dump_alloc
< 4096) {
1616 cb
->min_dump_alloc
= 4096;
1623 } while (state
->split_start
> 0);
1633 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1635 kfree((void *)cb
->args
[0]);
1639 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1641 struct sk_buff
*msg
;
1642 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1643 struct nl80211_dump_wiphy_state state
= {};
1645 msg
= nlmsg_new(4096, GFP_KERNEL
);
1649 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1655 return genlmsg_reply(msg
, info
);
1658 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1659 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1660 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1661 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1662 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1663 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1666 static int parse_txq_params(struct nlattr
*tb
[],
1667 struct ieee80211_txq_params
*txq_params
)
1669 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1670 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1671 !tb
[NL80211_TXQ_ATTR_AIFS
])
1674 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1675 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1676 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1677 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1678 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1680 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1686 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1689 * You can only set the channel explicitly for WDS interfaces,
1690 * all others have their channel managed via their respective
1691 * "establish a connection" command (connect, join, ...)
1693 * For AP/GO and mesh mode, the channel can be set with the
1694 * channel userspace API, but is only stored and passed to the
1695 * low-level driver when the AP starts or the mesh is joined.
1696 * This is for backward compatibility, userspace can also give
1697 * the channel in the start-ap or join-mesh commands instead.
1699 * Monitors are special as they are normally slaved to
1700 * whatever else is going on, so they have their own special
1701 * operation to set the monitor channel if possible.
1704 wdev
->iftype
== NL80211_IFTYPE_AP
||
1705 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1706 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1707 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1710 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1711 struct genl_info
*info
,
1712 struct cfg80211_chan_def
*chandef
)
1716 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1719 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1721 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1722 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1723 chandef
->center_freq1
= control_freq
;
1724 chandef
->center_freq2
= 0;
1726 /* Primary channel not allowed */
1727 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1730 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1731 enum nl80211_channel_type chantype
;
1733 chantype
= nla_get_u32(
1734 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1737 case NL80211_CHAN_NO_HT
:
1738 case NL80211_CHAN_HT20
:
1739 case NL80211_CHAN_HT40PLUS
:
1740 case NL80211_CHAN_HT40MINUS
:
1741 cfg80211_chandef_create(chandef
, chandef
->chan
,
1747 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1749 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1750 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1751 chandef
->center_freq1
=
1753 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1754 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1755 chandef
->center_freq2
=
1757 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1760 if (!cfg80211_chandef_valid(chandef
))
1763 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1764 IEEE80211_CHAN_DISABLED
))
1767 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1768 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1769 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1775 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1776 struct wireless_dev
*wdev
,
1777 struct genl_info
*info
)
1779 struct cfg80211_chan_def chandef
;
1781 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1784 iftype
= wdev
->iftype
;
1786 if (!nl80211_can_set_dev_channel(wdev
))
1789 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1794 case NL80211_IFTYPE_AP
:
1795 case NL80211_IFTYPE_P2P_GO
:
1796 if (wdev
->beacon_interval
) {
1800 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1804 wdev
->preset_chandef
= chandef
;
1807 case NL80211_IFTYPE_MESH_POINT
:
1808 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1810 case NL80211_IFTYPE_MONITOR
:
1811 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1820 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1822 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1823 struct net_device
*netdev
= info
->user_ptr
[1];
1825 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1828 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1830 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1831 struct net_device
*dev
= info
->user_ptr
[1];
1832 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1835 if (!info
->attrs
[NL80211_ATTR_MAC
])
1838 if (netif_running(dev
))
1841 if (!rdev
->ops
->set_wds_peer
)
1844 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1847 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1848 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1852 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1854 struct cfg80211_registered_device
*rdev
;
1855 struct net_device
*netdev
= NULL
;
1856 struct wireless_dev
*wdev
;
1857 int result
= 0, rem_txq_params
= 0;
1858 struct nlattr
*nl_txq_params
;
1860 u8 retry_short
= 0, retry_long
= 0;
1861 u32 frag_threshold
= 0, rts_threshold
= 0;
1862 u8 coverage_class
= 0;
1867 * Try to find the wiphy and netdev. Normally this
1868 * function shouldn't need the netdev, but this is
1869 * done for backward compatibility -- previously
1870 * setting the channel was done per wiphy, but now
1871 * it is per netdev. Previous userland like hostapd
1872 * also passed a netdev to set_wiphy, so that it is
1873 * possible to let that go to the right netdev!
1876 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1877 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1879 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1880 if (netdev
&& netdev
->ieee80211_ptr
)
1881 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1887 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1890 return PTR_ERR(rdev
);
1895 wdev
= netdev
->ieee80211_ptr
;
1898 * end workaround code, by now the rdev is available
1899 * and locked, and wdev may or may not be NULL.
1902 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1903 result
= cfg80211_dev_rename(
1904 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1909 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1910 struct ieee80211_txq_params txq_params
;
1911 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1913 if (!rdev
->ops
->set_txq_params
) {
1914 result
= -EOPNOTSUPP
;
1923 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1924 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1929 if (!netif_running(netdev
)) {
1934 nla_for_each_nested(nl_txq_params
,
1935 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1937 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1938 nla_data(nl_txq_params
),
1939 nla_len(nl_txq_params
),
1941 result
= parse_txq_params(tb
, &txq_params
);
1945 result
= rdev_set_txq_params(rdev
, netdev
,
1952 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1953 result
= __nl80211_set_channel(rdev
,
1954 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1960 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1961 struct wireless_dev
*txp_wdev
= wdev
;
1962 enum nl80211_tx_power_setting type
;
1965 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
1968 if (!rdev
->ops
->set_tx_power
) {
1969 result
= -EOPNOTSUPP
;
1973 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1974 type
= nla_get_u32(info
->attrs
[idx
]);
1976 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1977 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1982 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1983 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1984 mbm
= nla_get_u32(info
->attrs
[idx
]);
1987 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
1992 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1993 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1995 if ((!rdev
->wiphy
.available_antennas_tx
&&
1996 !rdev
->wiphy
.available_antennas_rx
) ||
1997 !rdev
->ops
->set_antenna
) {
1998 result
= -EOPNOTSUPP
;
2002 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2003 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2005 /* reject antenna configurations which don't match the
2006 * available antenna masks, except for the "all" mask */
2007 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2008 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2013 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2014 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2016 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2023 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2024 retry_short
= nla_get_u8(
2025 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2026 if (retry_short
== 0) {
2030 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2033 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2034 retry_long
= nla_get_u8(
2035 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2036 if (retry_long
== 0) {
2040 changed
|= WIPHY_PARAM_RETRY_LONG
;
2043 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2044 frag_threshold
= nla_get_u32(
2045 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2046 if (frag_threshold
< 256) {
2050 if (frag_threshold
!= (u32
) -1) {
2052 * Fragments (apart from the last one) are required to
2053 * have even length. Make the fragmentation code
2054 * simpler by stripping LSB should someone try to use
2055 * odd threshold value.
2057 frag_threshold
&= ~0x1;
2059 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2062 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2063 rts_threshold
= nla_get_u32(
2064 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2065 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2068 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2069 coverage_class
= nla_get_u8(
2070 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2071 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2075 u8 old_retry_short
, old_retry_long
;
2076 u32 old_frag_threshold
, old_rts_threshold
;
2077 u8 old_coverage_class
;
2079 if (!rdev
->ops
->set_wiphy_params
) {
2080 result
= -EOPNOTSUPP
;
2084 old_retry_short
= rdev
->wiphy
.retry_short
;
2085 old_retry_long
= rdev
->wiphy
.retry_long
;
2086 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2087 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2088 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2090 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2091 rdev
->wiphy
.retry_short
= retry_short
;
2092 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2093 rdev
->wiphy
.retry_long
= retry_long
;
2094 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2095 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2096 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2097 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2098 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2099 rdev
->wiphy
.coverage_class
= coverage_class
;
2101 result
= rdev_set_wiphy_params(rdev
, changed
);
2103 rdev
->wiphy
.retry_short
= old_retry_short
;
2104 rdev
->wiphy
.retry_long
= old_retry_long
;
2105 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2106 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2107 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2117 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2119 return (u64
)wdev
->identifier
|
2120 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2123 static int nl80211_send_chandef(struct sk_buff
*msg
,
2124 struct cfg80211_chan_def
*chandef
)
2126 WARN_ON(!cfg80211_chandef_valid(chandef
));
2128 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2129 chandef
->chan
->center_freq
))
2131 switch (chandef
->width
) {
2132 case NL80211_CHAN_WIDTH_20_NOHT
:
2133 case NL80211_CHAN_WIDTH_20
:
2134 case NL80211_CHAN_WIDTH_40
:
2135 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2136 cfg80211_get_chandef_type(chandef
)))
2142 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2144 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2146 if (chandef
->center_freq2
&&
2147 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2152 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2153 struct cfg80211_registered_device
*rdev
,
2154 struct wireless_dev
*wdev
)
2156 struct net_device
*dev
= wdev
->netdev
;
2159 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2164 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2165 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2166 goto nla_put_failure
;
2168 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2169 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2170 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2171 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2172 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2173 rdev
->devlist_generation
^
2174 (cfg80211_rdev_list_generation
<< 2)))
2175 goto nla_put_failure
;
2177 if (rdev
->ops
->get_channel
) {
2179 struct cfg80211_chan_def chandef
;
2181 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2183 if (nl80211_send_chandef(msg
, &chandef
))
2184 goto nla_put_failure
;
2188 if (wdev
->ssid_len
) {
2189 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2190 goto nla_put_failure
;
2193 return genlmsg_end(msg
, hdr
);
2196 genlmsg_cancel(msg
, hdr
);
2200 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2204 int wp_start
= cb
->args
[0];
2205 int if_start
= cb
->args
[1];
2206 struct cfg80211_registered_device
*rdev
;
2207 struct wireless_dev
*wdev
;
2210 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2211 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2213 if (wp_idx
< wp_start
) {
2219 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2220 if (if_idx
< if_start
) {
2224 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2225 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2237 cb
->args
[0] = wp_idx
;
2238 cb
->args
[1] = if_idx
;
2243 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2245 struct sk_buff
*msg
;
2246 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2247 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2249 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2253 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2259 return genlmsg_reply(msg
, info
);
2262 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2263 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2264 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2265 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2266 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2267 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2268 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2271 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2273 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2281 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2282 nla
, mntr_flags_policy
))
2285 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2287 *mntrflags
|= (1<<flag
);
2292 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2293 struct net_device
*netdev
, u8 use_4addr
,
2294 enum nl80211_iftype iftype
)
2297 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2303 case NL80211_IFTYPE_AP_VLAN
:
2304 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2307 case NL80211_IFTYPE_STATION
:
2308 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2318 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2320 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2321 struct vif_params params
;
2323 enum nl80211_iftype otype
, ntype
;
2324 struct net_device
*dev
= info
->user_ptr
[1];
2325 u32 _flags
, *flags
= NULL
;
2326 bool change
= false;
2328 memset(¶ms
, 0, sizeof(params
));
2330 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2332 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2333 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2336 if (ntype
> NL80211_IFTYPE_MAX
)
2340 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2341 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2343 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2345 if (netif_running(dev
))
2349 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2350 IEEE80211_MAX_MESH_ID_LEN
);
2351 wdev
->mesh_id_up_len
=
2352 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2353 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2354 wdev
->mesh_id_up_len
);
2358 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2359 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2361 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2365 params
.use_4addr
= -1;
2368 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2369 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2371 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2380 if (flags
&& (*flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2381 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2385 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2389 if (!err
&& params
.use_4addr
!= -1)
2390 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2395 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2397 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2398 struct vif_params params
;
2399 struct wireless_dev
*wdev
;
2400 struct sk_buff
*msg
;
2402 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2405 memset(¶ms
, 0, sizeof(params
));
2407 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2410 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2411 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2412 if (type
> NL80211_IFTYPE_MAX
)
2416 if (!rdev
->ops
->add_virtual_intf
||
2417 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2420 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2421 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2423 if (!is_valid_ether_addr(params
.macaddr
))
2424 return -EADDRNOTAVAIL
;
2427 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2428 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2429 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2434 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2438 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2439 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2442 if (!err
&& (flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2443 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2446 wdev
= rdev_add_virtual_intf(rdev
,
2447 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2448 type
, err
? NULL
: &flags
, ¶ms
);
2451 return PTR_ERR(wdev
);
2455 case NL80211_IFTYPE_MESH_POINT
:
2456 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2459 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2460 IEEE80211_MAX_MESH_ID_LEN
);
2461 wdev
->mesh_id_up_len
=
2462 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2463 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2464 wdev
->mesh_id_up_len
);
2467 case NL80211_IFTYPE_P2P_DEVICE
:
2469 * P2P Device doesn't have a netdev, so doesn't go
2470 * through the netdev notifier and must be added here
2472 mutex_init(&wdev
->mtx
);
2473 INIT_LIST_HEAD(&wdev
->event_list
);
2474 spin_lock_init(&wdev
->event_lock
);
2475 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2476 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2478 wdev
->identifier
= ++rdev
->wdev_id
;
2479 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2480 rdev
->devlist_generation
++;
2486 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2492 return genlmsg_reply(msg
, info
);
2495 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2497 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2498 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2500 if (!rdev
->ops
->del_virtual_intf
)
2504 * If we remove a wireless device without a netdev then clear
2505 * user_ptr[1] so that nl80211_post_doit won't dereference it
2506 * to check if it needs to do dev_put(). Otherwise it crashes
2507 * since the wdev has been freed, unlike with a netdev where
2508 * we need the dev_put() for the netdev to really be freed.
2511 info
->user_ptr
[1] = NULL
;
2513 return rdev_del_virtual_intf(rdev
, wdev
);
2516 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2518 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2519 struct net_device
*dev
= info
->user_ptr
[1];
2522 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2525 if (!rdev
->ops
->set_noack_map
)
2528 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2530 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2533 struct get_key_cookie
{
2534 struct sk_buff
*msg
;
2539 static void get_key_callback(void *c
, struct key_params
*params
)
2542 struct get_key_cookie
*cookie
= c
;
2545 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2546 params
->key_len
, params
->key
)) ||
2548 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2549 params
->seq_len
, params
->seq
)) ||
2551 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2553 goto nla_put_failure
;
2555 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2557 goto nla_put_failure
;
2560 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2561 params
->key_len
, params
->key
)) ||
2563 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2564 params
->seq_len
, params
->seq
)) ||
2566 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2568 goto nla_put_failure
;
2570 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2571 goto nla_put_failure
;
2573 nla_nest_end(cookie
->msg
, key
);
2580 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2582 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2584 struct net_device
*dev
= info
->user_ptr
[1];
2586 const u8
*mac_addr
= NULL
;
2588 struct get_key_cookie cookie
= {
2592 struct sk_buff
*msg
;
2594 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2595 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2600 if (info
->attrs
[NL80211_ATTR_MAC
])
2601 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2603 pairwise
= !!mac_addr
;
2604 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2605 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2606 if (kt
>= NUM_NL80211_KEYTYPES
)
2608 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2609 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2611 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2614 if (!rdev
->ops
->get_key
)
2617 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2621 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2622 NL80211_CMD_NEW_KEY
);
2624 return PTR_ERR(hdr
);
2627 cookie
.idx
= key_idx
;
2629 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2630 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2631 goto nla_put_failure
;
2633 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2634 goto nla_put_failure
;
2636 if (pairwise
&& mac_addr
&&
2637 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2640 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2647 goto nla_put_failure
;
2649 genlmsg_end(msg
, hdr
);
2650 return genlmsg_reply(msg
, info
);
2659 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2661 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2662 struct key_parse key
;
2664 struct net_device
*dev
= info
->user_ptr
[1];
2666 err
= nl80211_parse_key(info
, &key
);
2673 /* only support setting default key */
2674 if (!key
.def
&& !key
.defmgmt
)
2677 wdev_lock(dev
->ieee80211_ptr
);
2680 if (!rdev
->ops
->set_default_key
) {
2685 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2689 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2690 key
.def_uni
, key
.def_multi
);
2695 #ifdef CONFIG_CFG80211_WEXT
2696 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2699 if (key
.def_uni
|| !key
.def_multi
) {
2704 if (!rdev
->ops
->set_default_mgmt_key
) {
2709 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2713 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2717 #ifdef CONFIG_CFG80211_WEXT
2718 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2723 wdev_unlock(dev
->ieee80211_ptr
);
2728 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2730 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2732 struct net_device
*dev
= info
->user_ptr
[1];
2733 struct key_parse key
;
2734 const u8
*mac_addr
= NULL
;
2736 err
= nl80211_parse_key(info
, &key
);
2743 if (info
->attrs
[NL80211_ATTR_MAC
])
2744 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2746 if (key
.type
== -1) {
2748 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2750 key
.type
= NL80211_KEYTYPE_GROUP
;
2754 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2755 key
.type
!= NL80211_KEYTYPE_GROUP
)
2758 if (!rdev
->ops
->add_key
)
2761 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2762 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2766 wdev_lock(dev
->ieee80211_ptr
);
2767 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2769 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2770 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2772 wdev_unlock(dev
->ieee80211_ptr
);
2777 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2779 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2781 struct net_device
*dev
= info
->user_ptr
[1];
2782 u8
*mac_addr
= NULL
;
2783 struct key_parse key
;
2785 err
= nl80211_parse_key(info
, &key
);
2789 if (info
->attrs
[NL80211_ATTR_MAC
])
2790 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2792 if (key
.type
== -1) {
2794 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2796 key
.type
= NL80211_KEYTYPE_GROUP
;
2800 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2801 key
.type
!= NL80211_KEYTYPE_GROUP
)
2804 if (!rdev
->ops
->del_key
)
2807 wdev_lock(dev
->ieee80211_ptr
);
2808 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2810 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2811 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2815 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2816 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2819 #ifdef CONFIG_CFG80211_WEXT
2821 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2822 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2823 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2824 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2827 wdev_unlock(dev
->ieee80211_ptr
);
2832 /* This function returns an error or the number of nested attributes */
2833 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2835 struct nlattr
*attr
;
2836 int n_entries
= 0, tmp
;
2838 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2839 if (nla_len(attr
) != ETH_ALEN
)
2849 * This function parses ACL information and allocates memory for ACL data.
2850 * On successful return, the calling function is responsible to free the
2851 * ACL buffer returned by this function.
2853 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2854 struct genl_info
*info
)
2856 enum nl80211_acl_policy acl_policy
;
2857 struct nlattr
*attr
;
2858 struct cfg80211_acl_data
*acl
;
2859 int i
= 0, n_entries
, tmp
;
2861 if (!wiphy
->max_acl_mac_addrs
)
2862 return ERR_PTR(-EOPNOTSUPP
);
2864 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2865 return ERR_PTR(-EINVAL
);
2867 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2868 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2869 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2870 return ERR_PTR(-EINVAL
);
2872 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2873 return ERR_PTR(-EINVAL
);
2875 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2877 return ERR_PTR(n_entries
);
2879 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2880 return ERR_PTR(-ENOTSUPP
);
2882 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2885 return ERR_PTR(-ENOMEM
);
2887 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2888 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2892 acl
->n_acl_entries
= n_entries
;
2893 acl
->acl_policy
= acl_policy
;
2898 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2900 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2901 struct net_device
*dev
= info
->user_ptr
[1];
2902 struct cfg80211_acl_data
*acl
;
2905 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2906 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2909 if (!dev
->ieee80211_ptr
->beacon_interval
)
2912 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2914 return PTR_ERR(acl
);
2916 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2923 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
2924 struct cfg80211_beacon_data
*bcn
)
2926 bool haveinfo
= false;
2928 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2929 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
2930 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2931 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2934 memset(bcn
, 0, sizeof(*bcn
));
2936 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2937 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2938 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2944 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2945 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2946 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2953 if (attrs
[NL80211_ATTR_IE
]) {
2954 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
2955 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
2958 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2959 bcn
->proberesp_ies
=
2960 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2961 bcn
->proberesp_ies_len
=
2962 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2965 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2966 bcn
->assocresp_ies
=
2967 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2968 bcn
->assocresp_ies_len
=
2969 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2972 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
2973 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
2974 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
2980 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2981 struct cfg80211_ap_settings
*params
)
2983 struct wireless_dev
*wdev
;
2986 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2987 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2988 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2991 if (!wdev
->preset_chandef
.chan
)
2994 params
->chandef
= wdev
->preset_chandef
;
3002 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3003 enum nl80211_auth_type auth_type
,
3004 enum nl80211_commands cmd
)
3006 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3010 case NL80211_CMD_AUTHENTICATE
:
3011 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3012 auth_type
== NL80211_AUTHTYPE_SAE
)
3015 case NL80211_CMD_CONNECT
:
3016 case NL80211_CMD_START_AP
:
3017 /* SAE not supported yet */
3018 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3026 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3028 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3029 struct net_device
*dev
= info
->user_ptr
[1];
3030 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3031 struct cfg80211_ap_settings params
;
3033 u8 radar_detect_width
= 0;
3035 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3036 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3039 if (!rdev
->ops
->start_ap
)
3042 if (wdev
->beacon_interval
)
3045 memset(¶ms
, 0, sizeof(params
));
3047 /* these are required for START_AP */
3048 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3049 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3050 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3053 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3057 params
.beacon_interval
=
3058 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3059 params
.dtim_period
=
3060 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3062 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3067 * In theory, some of these attributes should be required here
3068 * but since they were not used when the command was originally
3069 * added, keep them optional for old user space programs to let
3070 * them continue to work with drivers that do not need the
3071 * additional information -- drivers must check!
3073 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3074 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3076 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3077 if (params
.ssid_len
== 0 ||
3078 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3082 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3083 params
.hidden_ssid
= nla_get_u32(
3084 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3085 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3086 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3087 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3091 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3093 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3094 params
.auth_type
= nla_get_u32(
3095 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3096 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3097 NL80211_CMD_START_AP
))
3100 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3102 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3103 NL80211_MAX_NR_CIPHER_SUITES
);
3107 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3108 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3110 params
.inactivity_timeout
= nla_get_u16(
3111 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3114 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3115 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3117 params
.p2p_ctwindow
=
3118 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3119 if (params
.p2p_ctwindow
> 127)
3121 if (params
.p2p_ctwindow
!= 0 &&
3122 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3126 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3129 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3131 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3134 params
.p2p_opp_ps
= tmp
;
3135 if (params
.p2p_opp_ps
!= 0 &&
3136 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3140 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3141 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3144 } else if (wdev
->preset_chandef
.chan
) {
3145 params
.chandef
= wdev
->preset_chandef
;
3146 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3149 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3152 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3156 radar_detect_width
= BIT(params
.chandef
.width
);
3157 params
.radar_required
= true;
3160 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3161 params
.chandef
.chan
,
3163 radar_detect_width
);
3167 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3168 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3169 if (IS_ERR(params
.acl
))
3170 return PTR_ERR(params
.acl
);
3173 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3175 wdev
->preset_chandef
= params
.chandef
;
3176 wdev
->beacon_interval
= params
.beacon_interval
;
3177 wdev
->channel
= params
.chandef
.chan
;
3178 wdev
->ssid_len
= params
.ssid_len
;
3179 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3187 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3190 struct net_device
*dev
= info
->user_ptr
[1];
3191 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3192 struct cfg80211_beacon_data params
;
3195 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3196 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3199 if (!rdev
->ops
->change_beacon
)
3202 if (!wdev
->beacon_interval
)
3205 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3209 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3212 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3214 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3215 struct net_device
*dev
= info
->user_ptr
[1];
3217 return cfg80211_stop_ap(rdev
, dev
);
3220 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3221 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3222 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3223 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3224 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3225 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3226 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3229 static int parse_station_flags(struct genl_info
*info
,
3230 enum nl80211_iftype iftype
,
3231 struct station_parameters
*params
)
3233 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3238 * Try parsing the new attribute first so userspace
3239 * can specify both for older kernels.
3241 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3243 struct nl80211_sta_flag_update
*sta_flags
;
3245 sta_flags
= nla_data(nla
);
3246 params
->sta_flags_mask
= sta_flags
->mask
;
3247 params
->sta_flags_set
= sta_flags
->set
;
3248 params
->sta_flags_set
&= params
->sta_flags_mask
;
3249 if ((params
->sta_flags_mask
|
3250 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3255 /* if present, parse the old attribute */
3257 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3261 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3262 nla
, sta_flags_policy
))
3266 * Only allow certain flags for interface types so that
3267 * other attributes are silently ignored. Remember that
3268 * this is backward compatibility code with old userspace
3269 * and shouldn't be hit in other cases anyway.
3272 case NL80211_IFTYPE_AP
:
3273 case NL80211_IFTYPE_AP_VLAN
:
3274 case NL80211_IFTYPE_P2P_GO
:
3275 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3276 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3277 BIT(NL80211_STA_FLAG_WME
) |
3278 BIT(NL80211_STA_FLAG_MFP
);
3280 case NL80211_IFTYPE_P2P_CLIENT
:
3281 case NL80211_IFTYPE_STATION
:
3282 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3283 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3285 case NL80211_IFTYPE_MESH_POINT
:
3286 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3287 BIT(NL80211_STA_FLAG_MFP
) |
3288 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3293 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3295 params
->sta_flags_set
|= (1<<flag
);
3297 /* no longer support new API additions in old API */
3298 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3306 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3309 struct nlattr
*rate
;
3313 rate
= nla_nest_start(msg
, attr
);
3317 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3318 bitrate
= cfg80211_calculate_bitrate(info
);
3319 /* report 16-bit bitrate only if we can */
3320 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3322 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3324 if (bitrate_compat
> 0 &&
3325 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3328 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3329 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3331 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3332 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3334 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3335 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3337 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3338 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3340 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3342 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3343 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3345 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3346 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3348 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3349 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3351 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3352 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3354 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3355 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3359 nla_nest_end(msg
, rate
);
3363 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3372 attr
= nla_nest_start(msg
, id
);
3376 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3377 if (!(mask
& BIT(i
)))
3380 if (nla_put_u8(msg
, i
, signal
[i
]))
3384 nla_nest_end(msg
, attr
);
3389 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3391 struct cfg80211_registered_device
*rdev
,
3392 struct net_device
*dev
,
3393 const u8
*mac_addr
, struct station_info
*sinfo
)
3396 struct nlattr
*sinfoattr
, *bss_param
;
3398 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3402 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3403 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3404 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3405 goto nla_put_failure
;
3407 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3409 goto nla_put_failure
;
3410 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3411 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3412 sinfo
->connected_time
))
3413 goto nla_put_failure
;
3414 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3415 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3416 sinfo
->inactive_time
))
3417 goto nla_put_failure
;
3418 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3419 STATION_INFO_RX_BYTES64
)) &&
3420 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3421 (u32
)sinfo
->rx_bytes
))
3422 goto nla_put_failure
;
3423 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3424 STATION_INFO_TX_BYTES64
)) &&
3425 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3426 (u32
)sinfo
->tx_bytes
))
3427 goto nla_put_failure
;
3428 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3429 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3431 goto nla_put_failure
;
3432 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3433 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3435 goto nla_put_failure
;
3436 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3437 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3438 goto nla_put_failure
;
3439 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3440 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3441 goto nla_put_failure
;
3442 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3443 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3444 sinfo
->plink_state
))
3445 goto nla_put_failure
;
3446 switch (rdev
->wiphy
.signal_type
) {
3447 case CFG80211_SIGNAL_TYPE_MBM
:
3448 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3449 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3451 goto nla_put_failure
;
3452 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3453 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3455 goto nla_put_failure
;
3460 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL
) {
3461 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3462 sinfo
->chain_signal
,
3463 NL80211_STA_INFO_CHAIN_SIGNAL
))
3464 goto nla_put_failure
;
3466 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL_AVG
) {
3467 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3468 sinfo
->chain_signal_avg
,
3469 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3470 goto nla_put_failure
;
3472 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3473 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3474 NL80211_STA_INFO_TX_BITRATE
))
3475 goto nla_put_failure
;
3477 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3478 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3479 NL80211_STA_INFO_RX_BITRATE
))
3480 goto nla_put_failure
;
3482 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3483 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3485 goto nla_put_failure
;
3486 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3487 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3489 goto nla_put_failure
;
3490 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3491 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3493 goto nla_put_failure
;
3494 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3495 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3497 goto nla_put_failure
;
3498 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3499 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3500 sinfo
->beacon_loss_count
))
3501 goto nla_put_failure
;
3502 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3503 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3505 goto nla_put_failure
;
3506 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3507 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3509 goto nla_put_failure
;
3510 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3511 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3513 goto nla_put_failure
;
3514 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3515 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3517 goto nla_put_failure
;
3519 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3520 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3521 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3522 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3523 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3524 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3525 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3526 sinfo
->bss_param
.dtim_period
) ||
3527 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3528 sinfo
->bss_param
.beacon_interval
))
3529 goto nla_put_failure
;
3531 nla_nest_end(msg
, bss_param
);
3533 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3534 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3535 sizeof(struct nl80211_sta_flag_update
),
3537 goto nla_put_failure
;
3538 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3539 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3541 goto nla_put_failure
;
3542 nla_nest_end(msg
, sinfoattr
);
3544 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3545 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3546 sinfo
->assoc_req_ies
))
3547 goto nla_put_failure
;
3549 return genlmsg_end(msg
, hdr
);
3552 genlmsg_cancel(msg
, hdr
);
3556 static int nl80211_dump_station(struct sk_buff
*skb
,
3557 struct netlink_callback
*cb
)
3559 struct station_info sinfo
;
3560 struct cfg80211_registered_device
*dev
;
3561 struct wireless_dev
*wdev
;
3562 u8 mac_addr
[ETH_ALEN
];
3563 int sta_idx
= cb
->args
[2];
3566 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3570 if (!wdev
->netdev
) {
3575 if (!dev
->ops
->dump_station
) {
3581 memset(&sinfo
, 0, sizeof(sinfo
));
3582 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3589 if (nl80211_send_station(skb
,
3590 NETLINK_CB(cb
->skb
).portid
,
3591 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3592 dev
, wdev
->netdev
, mac_addr
,
3601 cb
->args
[2] = sta_idx
;
3604 nl80211_finish_wdev_dump(dev
);
3609 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3611 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3612 struct net_device
*dev
= info
->user_ptr
[1];
3613 struct station_info sinfo
;
3614 struct sk_buff
*msg
;
3615 u8
*mac_addr
= NULL
;
3618 memset(&sinfo
, 0, sizeof(sinfo
));
3620 if (!info
->attrs
[NL80211_ATTR_MAC
])
3623 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3625 if (!rdev
->ops
->get_station
)
3628 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3632 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3636 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3637 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3642 return genlmsg_reply(msg
, info
);
3645 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3646 struct station_parameters
*params
,
3647 enum cfg80211_station_type statype
)
3649 if (params
->listen_interval
!= -1)
3654 /* When you run into this, adjust the code below for the new flag */
3655 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3658 case CFG80211_STA_MESH_PEER_KERNEL
:
3659 case CFG80211_STA_MESH_PEER_USER
:
3661 * No ignoring the TDLS flag here -- the userspace mesh
3662 * code doesn't have the bug of including TDLS in the
3665 if (params
->sta_flags_mask
&
3666 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3667 BIT(NL80211_STA_FLAG_MFP
) |
3668 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3671 case CFG80211_STA_TDLS_PEER_SETUP
:
3672 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3673 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3675 /* ignore since it can't change */
3676 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3679 /* disallow mesh-specific things */
3680 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3682 if (params
->local_pm
)
3684 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3688 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3689 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3690 /* TDLS can't be set, ... */
3691 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3694 * ... but don't bother the driver with it. This works around
3695 * a hostapd/wpa_supplicant issue -- it always includes the
3696 * TLDS_PEER flag in the mask even for AP mode.
3698 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3701 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3702 /* reject other things that can't change */
3703 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3705 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3707 if (params
->supported_rates
)
3709 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3713 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3719 case CFG80211_STA_AP_MLME_CLIENT
:
3720 /* Use this only for authorizing/unauthorizing a station */
3721 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3724 case CFG80211_STA_AP_CLIENT
:
3725 /* accept only the listed bits */
3726 if (params
->sta_flags_mask
&
3727 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3728 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3729 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3730 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3731 BIT(NL80211_STA_FLAG_WME
) |
3732 BIT(NL80211_STA_FLAG_MFP
)))
3735 /* but authenticated/associated only if driver handles it */
3736 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3737 params
->sta_flags_mask
&
3738 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3739 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3742 case CFG80211_STA_IBSS
:
3743 case CFG80211_STA_AP_STA
:
3744 /* reject any changes other than AUTHORIZED */
3745 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3748 case CFG80211_STA_TDLS_PEER_SETUP
:
3749 /* reject any changes other than AUTHORIZED or WME */
3750 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3751 BIT(NL80211_STA_FLAG_WME
)))
3753 /* force (at least) rates when authorizing */
3754 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3755 !params
->supported_rates
)
3758 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3759 /* reject any changes */
3761 case CFG80211_STA_MESH_PEER_KERNEL
:
3762 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3765 case CFG80211_STA_MESH_PEER_USER
:
3766 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3773 EXPORT_SYMBOL(cfg80211_check_station_change
);
3776 * Get vlan interface making sure it is running and on the right wiphy.
3778 static struct net_device
*get_vlan(struct genl_info
*info
,
3779 struct cfg80211_registered_device
*rdev
)
3781 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3782 struct net_device
*v
;
3788 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3790 return ERR_PTR(-ENODEV
);
3792 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3797 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3798 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3799 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3804 if (!netif_running(v
)) {
3812 return ERR_PTR(ret
);
3815 static struct nla_policy
3816 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3817 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3818 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3821 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3822 struct station_parameters
*params
)
3824 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3828 /* parse WME attributes if present */
3829 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3832 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3833 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3834 nl80211_sta_wme_policy
);
3838 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3839 params
->uapsd_queues
= nla_get_u8(
3840 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3841 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3844 if (tb
[NL80211_STA_WME_MAX_SP
])
3845 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3847 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3850 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3855 static int nl80211_set_station_tdls(struct genl_info
*info
,
3856 struct station_parameters
*params
)
3858 /* Dummy STA entry gets updated once the peer capabilities are known */
3859 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
3860 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
3861 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3863 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3864 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3866 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3868 return nl80211_parse_sta_wme(info
, params
);
3871 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3873 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3874 struct net_device
*dev
= info
->user_ptr
[1];
3875 struct station_parameters params
;
3879 memset(¶ms
, 0, sizeof(params
));
3881 params
.listen_interval
= -1;
3883 if (!rdev
->ops
->change_station
)
3886 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3889 if (!info
->attrs
[NL80211_ATTR_MAC
])
3892 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3894 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3895 params
.supported_rates
=
3896 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3897 params
.supported_rates_len
=
3898 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3901 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3903 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3904 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3907 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3909 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3910 params
.ext_capab_len
=
3911 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3914 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3917 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3920 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3921 params
.plink_action
=
3922 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3923 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3927 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3928 params
.plink_state
=
3929 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3930 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3932 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3935 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3936 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3937 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3939 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3940 pm
> NL80211_MESH_POWER_MAX
)
3943 params
.local_pm
= pm
;
3946 /* Include parameters for TDLS peer (will check later) */
3947 err
= nl80211_set_station_tdls(info
, ¶ms
);
3951 params
.vlan
= get_vlan(info
, rdev
);
3952 if (IS_ERR(params
.vlan
))
3953 return PTR_ERR(params
.vlan
);
3955 switch (dev
->ieee80211_ptr
->iftype
) {
3956 case NL80211_IFTYPE_AP
:
3957 case NL80211_IFTYPE_AP_VLAN
:
3958 case NL80211_IFTYPE_P2P_GO
:
3959 case NL80211_IFTYPE_P2P_CLIENT
:
3960 case NL80211_IFTYPE_STATION
:
3961 case NL80211_IFTYPE_ADHOC
:
3962 case NL80211_IFTYPE_MESH_POINT
:
3969 /* driver will call cfg80211_check_station_change() */
3970 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3974 dev_put(params
.vlan
);
3979 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3981 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3983 struct net_device
*dev
= info
->user_ptr
[1];
3984 struct station_parameters params
;
3985 u8
*mac_addr
= NULL
;
3987 memset(¶ms
, 0, sizeof(params
));
3989 if (!rdev
->ops
->add_station
)
3992 if (!info
->attrs
[NL80211_ATTR_MAC
])
3995 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3998 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4001 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4002 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4005 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4006 params
.supported_rates
=
4007 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4008 params
.supported_rates_len
=
4009 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4010 params
.listen_interval
=
4011 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4013 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4014 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4016 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4017 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4020 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4022 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4023 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4026 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4028 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4029 params
.ext_capab_len
=
4030 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4033 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4035 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4037 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4039 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4041 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4042 params
.plink_action
=
4043 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4044 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4048 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4052 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4055 /* When you run into this, adjust the code below for the new flag */
4056 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4058 switch (dev
->ieee80211_ptr
->iftype
) {
4059 case NL80211_IFTYPE_AP
:
4060 case NL80211_IFTYPE_AP_VLAN
:
4061 case NL80211_IFTYPE_P2P_GO
:
4062 /* ignore WME attributes if iface/sta is not capable */
4063 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4064 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4065 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4067 /* TDLS peers cannot be added */
4068 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4069 info
->attrs
[NL80211_ATTR_PEER_AID
])
4071 /* but don't bother the driver with it */
4072 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4074 /* allow authenticated/associated only if driver handles it */
4075 if (!(rdev
->wiphy
.features
&
4076 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4077 params
.sta_flags_mask
&
4078 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4079 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4082 /* must be last in here for error handling */
4083 params
.vlan
= get_vlan(info
, rdev
);
4084 if (IS_ERR(params
.vlan
))
4085 return PTR_ERR(params
.vlan
);
4087 case NL80211_IFTYPE_MESH_POINT
:
4088 /* ignore uAPSD data */
4089 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4091 /* associated is disallowed */
4092 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4094 /* TDLS peers cannot be added */
4095 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4096 info
->attrs
[NL80211_ATTR_PEER_AID
])
4099 case NL80211_IFTYPE_STATION
:
4100 case NL80211_IFTYPE_P2P_CLIENT
:
4101 /* ignore uAPSD data */
4102 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4104 /* these are disallowed */
4105 if (params
.sta_flags_mask
&
4106 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4107 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4109 /* Only TDLS peers can be added */
4110 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4112 /* Can only add if TDLS ... */
4113 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4115 /* ... with external setup is supported */
4116 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4119 * Older wpa_supplicant versions always mark the TDLS peer
4120 * as authorized, but it shouldn't yet be.
4122 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4128 /* be aware of params.vlan when changing code here */
4130 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4133 dev_put(params
.vlan
);
4137 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4140 struct net_device
*dev
= info
->user_ptr
[1];
4141 u8
*mac_addr
= NULL
;
4143 if (info
->attrs
[NL80211_ATTR_MAC
])
4144 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4146 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4147 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4148 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4149 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4152 if (!rdev
->ops
->del_station
)
4155 return rdev_del_station(rdev
, dev
, mac_addr
);
4158 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4159 int flags
, struct net_device
*dev
,
4160 u8
*dst
, u8
*next_hop
,
4161 struct mpath_info
*pinfo
)
4164 struct nlattr
*pinfoattr
;
4166 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4170 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4171 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4172 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4173 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4174 goto nla_put_failure
;
4176 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4178 goto nla_put_failure
;
4179 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4180 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4182 goto nla_put_failure
;
4183 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4184 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4185 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4186 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4188 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4189 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4191 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4192 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4194 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4195 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4196 pinfo
->discovery_timeout
)) ||
4197 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4198 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4199 pinfo
->discovery_retries
)))
4200 goto nla_put_failure
;
4202 nla_nest_end(msg
, pinfoattr
);
4204 return genlmsg_end(msg
, hdr
);
4207 genlmsg_cancel(msg
, hdr
);
4211 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4212 struct netlink_callback
*cb
)
4214 struct mpath_info pinfo
;
4215 struct cfg80211_registered_device
*dev
;
4216 struct wireless_dev
*wdev
;
4218 u8 next_hop
[ETH_ALEN
];
4219 int path_idx
= cb
->args
[2];
4222 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4226 if (!dev
->ops
->dump_mpath
) {
4231 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4237 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4244 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4245 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4246 wdev
->netdev
, dst
, next_hop
,
4255 cb
->args
[2] = path_idx
;
4258 nl80211_finish_wdev_dump(dev
);
4262 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4264 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4266 struct net_device
*dev
= info
->user_ptr
[1];
4267 struct mpath_info pinfo
;
4268 struct sk_buff
*msg
;
4270 u8 next_hop
[ETH_ALEN
];
4272 memset(&pinfo
, 0, sizeof(pinfo
));
4274 if (!info
->attrs
[NL80211_ATTR_MAC
])
4277 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4279 if (!rdev
->ops
->get_mpath
)
4282 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4285 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4289 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4293 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4294 dev
, dst
, next_hop
, &pinfo
) < 0) {
4299 return genlmsg_reply(msg
, info
);
4302 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4304 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4305 struct net_device
*dev
= info
->user_ptr
[1];
4307 u8
*next_hop
= NULL
;
4309 if (!info
->attrs
[NL80211_ATTR_MAC
])
4312 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4315 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4316 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4318 if (!rdev
->ops
->change_mpath
)
4321 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4324 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4327 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4329 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4330 struct net_device
*dev
= info
->user_ptr
[1];
4332 u8
*next_hop
= NULL
;
4334 if (!info
->attrs
[NL80211_ATTR_MAC
])
4337 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4340 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4341 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4343 if (!rdev
->ops
->add_mpath
)
4346 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4349 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4352 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4354 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4355 struct net_device
*dev
= info
->user_ptr
[1];
4358 if (info
->attrs
[NL80211_ATTR_MAC
])
4359 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4361 if (!rdev
->ops
->del_mpath
)
4364 return rdev_del_mpath(rdev
, dev
, dst
);
4367 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4369 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4370 struct net_device
*dev
= info
->user_ptr
[1];
4371 struct bss_parameters params
;
4373 memset(¶ms
, 0, sizeof(params
));
4374 /* default to not changing parameters */
4375 params
.use_cts_prot
= -1;
4376 params
.use_short_preamble
= -1;
4377 params
.use_short_slot_time
= -1;
4378 params
.ap_isolate
= -1;
4379 params
.ht_opmode
= -1;
4380 params
.p2p_ctwindow
= -1;
4381 params
.p2p_opp_ps
= -1;
4383 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4384 params
.use_cts_prot
=
4385 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4386 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4387 params
.use_short_preamble
=
4388 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4389 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4390 params
.use_short_slot_time
=
4391 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4392 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4393 params
.basic_rates
=
4394 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4395 params
.basic_rates_len
=
4396 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4398 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4399 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4400 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4402 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4404 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4405 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4407 params
.p2p_ctwindow
=
4408 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4409 if (params
.p2p_ctwindow
< 0)
4411 if (params
.p2p_ctwindow
!= 0 &&
4412 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4416 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4419 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4421 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4424 params
.p2p_opp_ps
= tmp
;
4425 if (params
.p2p_opp_ps
&&
4426 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4430 if (!rdev
->ops
->change_bss
)
4433 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4434 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4437 return rdev_change_bss(rdev
, dev
, ¶ms
);
4440 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4441 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4442 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4443 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4444 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4445 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4446 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4449 static int parse_reg_rule(struct nlattr
*tb
[],
4450 struct ieee80211_reg_rule
*reg_rule
)
4452 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4453 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4455 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4457 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4459 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4461 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4463 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4466 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4468 freq_range
->start_freq_khz
=
4469 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4470 freq_range
->end_freq_khz
=
4471 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4472 freq_range
->max_bandwidth_khz
=
4473 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4475 power_rule
->max_eirp
=
4476 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4478 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4479 power_rule
->max_antenna_gain
=
4480 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4485 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4489 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4492 * You should only get this when cfg80211 hasn't yet initialized
4493 * completely when built-in to the kernel right between the time
4494 * window between nl80211_init() and regulatory_init(), if that is
4497 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4498 return -EINPROGRESS
;
4500 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4503 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4505 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4506 user_reg_hint_type
=
4507 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4509 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4511 switch (user_reg_hint_type
) {
4512 case NL80211_USER_REG_HINT_USER
:
4513 case NL80211_USER_REG_HINT_CELL_BASE
:
4519 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4524 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4525 struct genl_info
*info
)
4527 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4528 struct net_device
*dev
= info
->user_ptr
[1];
4529 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4530 struct mesh_config cur_params
;
4533 struct nlattr
*pinfoattr
;
4534 struct sk_buff
*msg
;
4536 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4539 if (!rdev
->ops
->get_mesh_config
)
4543 /* If not connected, get default parameters */
4544 if (!wdev
->mesh_id_len
)
4545 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4547 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4553 /* Draw up a netlink message to send back */
4554 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4557 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4558 NL80211_CMD_GET_MESH_CONFIG
);
4561 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4563 goto nla_put_failure
;
4564 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4565 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4566 cur_params
.dot11MeshRetryTimeout
) ||
4567 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4568 cur_params
.dot11MeshConfirmTimeout
) ||
4569 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4570 cur_params
.dot11MeshHoldingTimeout
) ||
4571 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4572 cur_params
.dot11MeshMaxPeerLinks
) ||
4573 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4574 cur_params
.dot11MeshMaxRetries
) ||
4575 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4576 cur_params
.dot11MeshTTL
) ||
4577 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4578 cur_params
.element_ttl
) ||
4579 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4580 cur_params
.auto_open_plinks
) ||
4581 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4582 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4583 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4584 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4585 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4586 cur_params
.path_refresh_time
) ||
4587 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4588 cur_params
.min_discovery_timeout
) ||
4589 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4590 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4591 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4592 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4593 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4594 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4595 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4596 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4597 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4598 cur_params
.dot11MeshHWMPRootMode
) ||
4599 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4600 cur_params
.dot11MeshHWMPRannInterval
) ||
4601 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4602 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4603 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4604 cur_params
.dot11MeshForwarding
) ||
4605 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4606 cur_params
.rssi_threshold
) ||
4607 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4608 cur_params
.ht_opmode
) ||
4609 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4610 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4611 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4612 cur_params
.dot11MeshHWMProotInterval
) ||
4613 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4614 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4615 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4616 cur_params
.power_mode
) ||
4617 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4618 cur_params
.dot11MeshAwakeWindowDuration
) ||
4619 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4620 cur_params
.plink_timeout
))
4621 goto nla_put_failure
;
4622 nla_nest_end(msg
, pinfoattr
);
4623 genlmsg_end(msg
, hdr
);
4624 return genlmsg_reply(msg
, info
);
4627 genlmsg_cancel(msg
, hdr
);
4633 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4634 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4635 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4636 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4637 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4638 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4639 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4640 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4641 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4642 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4643 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4644 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4645 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4646 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4647 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4648 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4649 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4650 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4651 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4652 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4653 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4654 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4655 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4656 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4657 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4658 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4659 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4660 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4661 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
4664 static const struct nla_policy
4665 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4666 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4667 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4668 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4669 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4670 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
4671 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4672 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4673 .len
= IEEE80211_MAX_DATA_LEN
},
4674 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4677 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4678 struct mesh_config
*cfg
,
4681 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4684 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4687 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4689 cfg->param = fn(tb[attr]); \
4690 mask |= (1 << (attr - 1)); \
4695 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4697 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4698 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4699 nl80211_meshconf_params_policy
))
4702 /* This makes sure that there aren't more than 32 mesh config
4703 * parameters (otherwise our bitfield scheme would not work.) */
4704 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4706 /* Fill in the params struct */
4707 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4708 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4710 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4711 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4713 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4714 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4716 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4717 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4719 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4720 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4722 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4723 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4724 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4725 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4727 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4728 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4730 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4732 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4734 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4735 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4737 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4738 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4740 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4741 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4743 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4745 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4747 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4749 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4751 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4753 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4755 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4756 dot11MeshHWMPnetDiameterTraversalTime
,
4758 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4760 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4761 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4763 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4764 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4766 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4767 dot11MeshGateAnnouncementProtocol
, 0, 1,
4768 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4770 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4771 mask
, NL80211_MESHCONF_FORWARDING
,
4773 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
4774 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4776 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4777 mask
, NL80211_MESHCONF_HT_OPMODE
,
4779 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4781 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4783 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4784 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4786 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4787 dot11MeshHWMPconfirmationInterval
,
4789 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4791 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4792 NL80211_MESH_POWER_ACTIVE
,
4793 NL80211_MESH_POWER_MAX
,
4794 mask
, NL80211_MESHCONF_POWER_MODE
,
4796 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4798 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4799 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 1, 0xffffffff,
4800 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4807 #undef FILL_IN_MESH_PARAM_IF_SET
4810 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4811 struct mesh_setup
*setup
)
4813 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4814 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4816 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4818 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4819 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4820 nl80211_mesh_setup_params_policy
))
4823 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4824 setup
->sync_method
=
4825 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4826 IEEE80211_SYNC_METHOD_VENDOR
:
4827 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4829 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4830 setup
->path_sel_proto
=
4831 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4832 IEEE80211_PATH_PROTOCOL_VENDOR
:
4833 IEEE80211_PATH_PROTOCOL_HWMP
;
4835 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4836 setup
->path_metric
=
4837 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4838 IEEE80211_PATH_METRIC_VENDOR
:
4839 IEEE80211_PATH_METRIC_AIRTIME
;
4842 if (tb
[NL80211_MESH_SETUP_IE
]) {
4843 struct nlattr
*ieattr
=
4844 tb
[NL80211_MESH_SETUP_IE
];
4845 if (!is_valid_ie_attr(ieattr
))
4847 setup
->ie
= nla_data(ieattr
);
4848 setup
->ie_len
= nla_len(ieattr
);
4850 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4851 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4853 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4854 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4855 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4856 if (setup
->is_secure
)
4857 setup
->user_mpm
= true;
4859 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
4860 if (!setup
->user_mpm
)
4863 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
4869 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4870 struct genl_info
*info
)
4872 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4873 struct net_device
*dev
= info
->user_ptr
[1];
4874 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4875 struct mesh_config cfg
;
4879 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4882 if (!rdev
->ops
->update_mesh_config
)
4885 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4890 if (!wdev
->mesh_id_len
)
4894 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4901 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4903 const struct ieee80211_regdomain
*regdom
;
4904 struct sk_buff
*msg
;
4906 struct nlattr
*nl_reg_rules
;
4909 if (!cfg80211_regdomain
)
4912 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4916 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4917 NL80211_CMD_GET_REG
);
4921 if (reg_last_request_cell_base() &&
4922 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4923 NL80211_USER_REG_HINT_CELL_BASE
))
4924 goto nla_put_failure
;
4927 regdom
= rcu_dereference(cfg80211_regdomain
);
4929 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4930 (regdom
->dfs_region
&&
4931 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4932 goto nla_put_failure_rcu
;
4934 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4936 goto nla_put_failure_rcu
;
4938 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4939 struct nlattr
*nl_reg_rule
;
4940 const struct ieee80211_reg_rule
*reg_rule
;
4941 const struct ieee80211_freq_range
*freq_range
;
4942 const struct ieee80211_power_rule
*power_rule
;
4944 reg_rule
= ®dom
->reg_rules
[i
];
4945 freq_range
= ®_rule
->freq_range
;
4946 power_rule
= ®_rule
->power_rule
;
4948 nl_reg_rule
= nla_nest_start(msg
, i
);
4950 goto nla_put_failure_rcu
;
4952 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4954 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4955 freq_range
->start_freq_khz
) ||
4956 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4957 freq_range
->end_freq_khz
) ||
4958 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4959 freq_range
->max_bandwidth_khz
) ||
4960 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4961 power_rule
->max_antenna_gain
) ||
4962 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4963 power_rule
->max_eirp
))
4964 goto nla_put_failure_rcu
;
4966 nla_nest_end(msg
, nl_reg_rule
);
4970 nla_nest_end(msg
, nl_reg_rules
);
4972 genlmsg_end(msg
, hdr
);
4973 return genlmsg_reply(msg
, info
);
4975 nla_put_failure_rcu
:
4978 genlmsg_cancel(msg
, hdr
);
4984 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4986 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4987 struct nlattr
*nl_reg_rule
;
4988 char *alpha2
= NULL
;
4989 int rem_reg_rules
= 0, r
= 0;
4990 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4992 struct ieee80211_regdomain
*rd
= NULL
;
4994 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4997 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5000 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5002 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5003 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5005 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5008 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5012 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5013 num_rules
* sizeof(struct ieee80211_reg_rule
);
5015 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5019 rd
->n_reg_rules
= num_rules
;
5020 rd
->alpha2
[0] = alpha2
[0];
5021 rd
->alpha2
[1] = alpha2
[1];
5024 * Disable DFS master mode if the DFS region was
5025 * not supported or known on this kernel.
5027 if (reg_supported_dfs_region(dfs_region
))
5028 rd
->dfs_region
= dfs_region
;
5030 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5032 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5033 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5035 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5041 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5048 /* set_regdom took ownership */
5056 static int validate_scan_freqs(struct nlattr
*freqs
)
5058 struct nlattr
*attr1
, *attr2
;
5059 int n_channels
= 0, tmp1
, tmp2
;
5061 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5064 * Some hardware has a limited channel list for
5065 * scanning, and it is pretty much nonsensical
5066 * to scan for a channel twice, so disallow that
5067 * and don't require drivers to check that the
5068 * channel list they get isn't longer than what
5069 * they can scan, as long as they can scan all
5070 * the channels they registered at once.
5072 nla_for_each_nested(attr2
, freqs
, tmp2
)
5073 if (attr1
!= attr2
&&
5074 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5081 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5083 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5084 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5085 struct cfg80211_scan_request
*request
;
5086 struct nlattr
*attr
;
5087 struct wiphy
*wiphy
;
5088 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5091 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5094 wiphy
= &rdev
->wiphy
;
5096 if (!rdev
->ops
->scan
)
5099 if (rdev
->scan_req
) {
5104 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5105 n_channels
= validate_scan_freqs(
5106 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5112 enum ieee80211_band band
;
5115 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5116 if (wiphy
->bands
[band
])
5117 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5120 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5121 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5124 if (n_ssids
> wiphy
->max_scan_ssids
) {
5129 if (info
->attrs
[NL80211_ATTR_IE
])
5130 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5134 if (ie_len
> wiphy
->max_scan_ie_len
) {
5139 request
= kzalloc(sizeof(*request
)
5140 + sizeof(*request
->ssids
) * n_ssids
5141 + sizeof(*request
->channels
) * n_channels
5142 + ie_len
, GFP_KERNEL
);
5149 request
->ssids
= (void *)&request
->channels
[n_channels
];
5150 request
->n_ssids
= n_ssids
;
5153 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5155 request
->ie
= (void *)(request
->channels
+ n_channels
);
5159 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5160 /* user specified, bail out if channel not found */
5161 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5162 struct ieee80211_channel
*chan
;
5164 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5171 /* ignore disabled channels */
5172 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5175 request
->channels
[i
] = chan
;
5179 enum ieee80211_band band
;
5182 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5184 if (!wiphy
->bands
[band
])
5186 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5187 struct ieee80211_channel
*chan
;
5189 chan
= &wiphy
->bands
[band
]->channels
[j
];
5191 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5194 request
->channels
[i
] = chan
;
5205 request
->n_channels
= i
;
5208 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5209 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5210 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5214 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5215 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5220 if (info
->attrs
[NL80211_ATTR_IE
]) {
5221 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5222 memcpy((void *)request
->ie
,
5223 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5227 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5228 if (wiphy
->bands
[i
])
5230 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5232 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5233 nla_for_each_nested(attr
,
5234 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5236 enum ieee80211_band band
= nla_type(attr
);
5238 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5242 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5245 &request
->rates
[band
]);
5251 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5252 request
->flags
= nla_get_u32(
5253 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5254 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5255 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5256 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5257 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5264 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5266 request
->wdev
= wdev
;
5267 request
->wiphy
= &rdev
->wiphy
;
5268 request
->scan_start
= jiffies
;
5270 rdev
->scan_req
= request
;
5271 err
= rdev_scan(rdev
, request
);
5274 nl80211_send_scan_start(rdev
, wdev
);
5276 dev_hold(wdev
->netdev
);
5279 rdev
->scan_req
= NULL
;
5287 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5288 struct genl_info
*info
)
5290 struct cfg80211_sched_scan_request
*request
;
5291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5292 struct net_device
*dev
= info
->user_ptr
[1];
5293 struct nlattr
*attr
;
5294 struct wiphy
*wiphy
;
5295 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5297 enum ieee80211_band band
;
5299 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5301 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5302 !rdev
->ops
->sched_scan_start
)
5305 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5308 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5311 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5315 wiphy
= &rdev
->wiphy
;
5317 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5318 n_channels
= validate_scan_freqs(
5319 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5325 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5326 if (wiphy
->bands
[band
])
5327 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5330 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5331 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5335 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5338 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5339 nla_for_each_nested(attr
,
5340 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5344 if (n_match_sets
> wiphy
->max_match_sets
)
5347 if (info
->attrs
[NL80211_ATTR_IE
])
5348 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5352 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5355 if (rdev
->sched_scan_req
) {
5360 request
= kzalloc(sizeof(*request
)
5361 + sizeof(*request
->ssids
) * n_ssids
5362 + sizeof(*request
->match_sets
) * n_match_sets
5363 + sizeof(*request
->channels
) * n_channels
5364 + ie_len
, GFP_KERNEL
);
5371 request
->ssids
= (void *)&request
->channels
[n_channels
];
5372 request
->n_ssids
= n_ssids
;
5375 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5377 request
->ie
= (void *)(request
->channels
+ n_channels
);
5382 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5383 else if (request
->ssids
)
5384 request
->match_sets
=
5385 (void *)(request
->ssids
+ n_ssids
);
5387 request
->match_sets
=
5388 (void *)(request
->channels
+ n_channels
);
5390 request
->n_match_sets
= n_match_sets
;
5393 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5394 /* user specified, bail out if channel not found */
5395 nla_for_each_nested(attr
,
5396 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5398 struct ieee80211_channel
*chan
;
5400 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5407 /* ignore disabled channels */
5408 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5411 request
->channels
[i
] = chan
;
5416 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5418 if (!wiphy
->bands
[band
])
5420 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5421 struct ieee80211_channel
*chan
;
5423 chan
= &wiphy
->bands
[band
]->channels
[j
];
5425 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5428 request
->channels
[i
] = chan
;
5439 request
->n_channels
= i
;
5442 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5443 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5445 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5449 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5450 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5457 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5458 nla_for_each_nested(attr
,
5459 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5461 struct nlattr
*ssid
, *rssi
;
5463 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5464 nla_data(attr
), nla_len(attr
),
5465 nl80211_match_policy
);
5466 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5468 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5472 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5473 nla_data(ssid
), nla_len(ssid
));
5474 request
->match_sets
[i
].ssid
.ssid_len
=
5477 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5479 request
->rssi_thold
= nla_get_u32(rssi
);
5481 request
->rssi_thold
=
5482 NL80211_SCAN_RSSI_THOLD_OFF
;
5487 if (info
->attrs
[NL80211_ATTR_IE
]) {
5488 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5489 memcpy((void *)request
->ie
,
5490 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5494 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5495 request
->flags
= nla_get_u32(
5496 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5497 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5498 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5499 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5500 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5507 request
->wiphy
= &rdev
->wiphy
;
5508 request
->interval
= interval
;
5509 request
->scan_start
= jiffies
;
5511 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5513 rdev
->sched_scan_req
= request
;
5514 nl80211_send_sched_scan(rdev
, dev
,
5515 NL80211_CMD_START_SCHED_SCAN
);
5525 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5526 struct genl_info
*info
)
5528 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5530 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5531 !rdev
->ops
->sched_scan_stop
)
5534 return __cfg80211_stop_sched_scan(rdev
, false);
5537 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5538 struct genl_info
*info
)
5540 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5541 struct net_device
*dev
= info
->user_ptr
[1];
5542 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5543 struct cfg80211_chan_def chandef
;
5546 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5550 if (wdev
->cac_started
)
5553 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5560 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5563 if (!rdev
->ops
->start_radar_detection
)
5566 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5567 chandef
.chan
, CHAN_MODE_SHARED
,
5568 BIT(chandef
.width
));
5572 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5574 wdev
->channel
= chandef
.chan
;
5575 wdev
->cac_started
= true;
5576 wdev
->cac_start_time
= jiffies
;
5581 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5583 struct cfg80211_registered_device
*rdev
,
5584 struct wireless_dev
*wdev
,
5585 struct cfg80211_internal_bss
*intbss
)
5587 struct cfg80211_bss
*res
= &intbss
->pub
;
5588 const struct cfg80211_bss_ies
*ies
;
5593 ASSERT_WDEV_LOCK(wdev
);
5595 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5596 NL80211_CMD_NEW_SCAN_RESULTS
);
5600 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5602 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5603 goto nla_put_failure
;
5605 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5606 goto nla_put_failure
;
5607 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5608 goto nla_put_failure
;
5610 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5612 goto nla_put_failure
;
5613 if ((!is_zero_ether_addr(res
->bssid
) &&
5614 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5615 goto nla_put_failure
;
5618 ies
= rcu_dereference(res
->ies
);
5620 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5621 goto fail_unlock_rcu
;
5623 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5624 ies
->len
, ies
->data
))
5625 goto fail_unlock_rcu
;
5627 ies
= rcu_dereference(res
->beacon_ies
);
5629 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5630 goto fail_unlock_rcu
;
5631 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5632 ies
->len
, ies
->data
))
5633 goto fail_unlock_rcu
;
5637 if (res
->beacon_interval
&&
5638 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5639 goto nla_put_failure
;
5640 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5641 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5642 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5643 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5644 goto nla_put_failure
;
5646 switch (rdev
->wiphy
.signal_type
) {
5647 case CFG80211_SIGNAL_TYPE_MBM
:
5648 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5649 goto nla_put_failure
;
5651 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5652 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5653 goto nla_put_failure
;
5659 switch (wdev
->iftype
) {
5660 case NL80211_IFTYPE_P2P_CLIENT
:
5661 case NL80211_IFTYPE_STATION
:
5662 if (intbss
== wdev
->current_bss
&&
5663 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5664 NL80211_BSS_STATUS_ASSOCIATED
))
5665 goto nla_put_failure
;
5667 case NL80211_IFTYPE_ADHOC
:
5668 if (intbss
== wdev
->current_bss
&&
5669 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5670 NL80211_BSS_STATUS_IBSS_JOINED
))
5671 goto nla_put_failure
;
5677 nla_nest_end(msg
, bss
);
5679 return genlmsg_end(msg
, hdr
);
5684 genlmsg_cancel(msg
, hdr
);
5688 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5690 struct cfg80211_registered_device
*rdev
;
5691 struct cfg80211_internal_bss
*scan
;
5692 struct wireless_dev
*wdev
;
5693 int start
= cb
->args
[2], idx
= 0;
5696 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5701 spin_lock_bh(&rdev
->bss_lock
);
5702 cfg80211_bss_expire(rdev
);
5704 cb
->seq
= rdev
->bss_generation
;
5706 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5709 if (nl80211_send_bss(skb
, cb
,
5710 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5711 rdev
, wdev
, scan
) < 0) {
5717 spin_unlock_bh(&rdev
->bss_lock
);
5721 nl80211_finish_wdev_dump(rdev
);
5726 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5727 int flags
, struct net_device
*dev
,
5728 struct survey_info
*survey
)
5731 struct nlattr
*infoattr
;
5733 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5734 NL80211_CMD_NEW_SURVEY_RESULTS
);
5738 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5739 goto nla_put_failure
;
5741 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5743 goto nla_put_failure
;
5745 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5746 survey
->channel
->center_freq
))
5747 goto nla_put_failure
;
5749 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5750 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5751 goto nla_put_failure
;
5752 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5753 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5754 goto nla_put_failure
;
5755 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5756 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5757 survey
->channel_time
))
5758 goto nla_put_failure
;
5759 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5760 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5761 survey
->channel_time_busy
))
5762 goto nla_put_failure
;
5763 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5764 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5765 survey
->channel_time_ext_busy
))
5766 goto nla_put_failure
;
5767 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5768 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5769 survey
->channel_time_rx
))
5770 goto nla_put_failure
;
5771 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5772 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5773 survey
->channel_time_tx
))
5774 goto nla_put_failure
;
5776 nla_nest_end(msg
, infoattr
);
5778 return genlmsg_end(msg
, hdr
);
5781 genlmsg_cancel(msg
, hdr
);
5785 static int nl80211_dump_survey(struct sk_buff
*skb
,
5786 struct netlink_callback
*cb
)
5788 struct survey_info survey
;
5789 struct cfg80211_registered_device
*dev
;
5790 struct wireless_dev
*wdev
;
5791 int survey_idx
= cb
->args
[2];
5794 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5798 if (!wdev
->netdev
) {
5803 if (!dev
->ops
->dump_survey
) {
5809 struct ieee80211_channel
*chan
;
5811 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5817 /* Survey without a channel doesn't make sense */
5818 if (!survey
.channel
) {
5823 chan
= ieee80211_get_channel(&dev
->wiphy
,
5824 survey
.channel
->center_freq
);
5825 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5830 if (nl80211_send_survey(skb
,
5831 NETLINK_CB(cb
->skb
).portid
,
5832 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5833 wdev
->netdev
, &survey
) < 0)
5839 cb
->args
[2] = survey_idx
;
5842 nl80211_finish_wdev_dump(dev
);
5846 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5848 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5849 NL80211_WPA_VERSION_2
));
5852 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5854 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5855 struct net_device
*dev
= info
->user_ptr
[1];
5856 struct ieee80211_channel
*chan
;
5857 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5858 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5859 enum nl80211_auth_type auth_type
;
5860 struct key_parse key
;
5861 bool local_state_change
;
5863 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5866 if (!info
->attrs
[NL80211_ATTR_MAC
])
5869 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5872 if (!info
->attrs
[NL80211_ATTR_SSID
])
5875 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5878 err
= nl80211_parse_key(info
, &key
);
5883 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5885 if (!key
.p
.key
|| !key
.p
.key_len
)
5887 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5888 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5889 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5890 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5902 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5903 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5912 if (!rdev
->ops
->auth
)
5915 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5916 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5919 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5920 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5921 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5922 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5925 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5926 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5928 if (info
->attrs
[NL80211_ATTR_IE
]) {
5929 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5930 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5933 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5934 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5937 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5938 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5941 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5942 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5944 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5945 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5946 /* need to include at least Auth Transaction and Status Code */
5947 if (sae_data_len
< 4)
5951 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5954 * Since we no longer track auth state, ignore
5955 * requests to only change local state.
5957 if (local_state_change
)
5960 wdev_lock(dev
->ieee80211_ptr
);
5961 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5962 ssid
, ssid_len
, ie
, ie_len
,
5963 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5964 sae_data
, sae_data_len
);
5965 wdev_unlock(dev
->ieee80211_ptr
);
5969 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5970 struct genl_info
*info
,
5971 struct cfg80211_crypto_settings
*settings
,
5974 memset(settings
, 0, sizeof(*settings
));
5976 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5978 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5980 proto
= nla_get_u16(
5981 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5982 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5983 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5986 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5987 settings
->control_port_no_encrypt
= true;
5989 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5991 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5995 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5996 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5997 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5999 if (len
% sizeof(u32
))
6002 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6005 memcpy(settings
->ciphers_pairwise
, data
, len
);
6007 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6008 if (!cfg80211_supported_cipher_suite(
6010 settings
->ciphers_pairwise
[i
]))
6014 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6015 settings
->cipher_group
=
6016 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6017 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6018 settings
->cipher_group
))
6022 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6023 settings
->wpa_versions
=
6024 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6025 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6029 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6033 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6034 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6035 settings
->n_akm_suites
= len
/ sizeof(u32
);
6037 if (len
% sizeof(u32
))
6040 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6043 memcpy(settings
->akm_suites
, data
, len
);
6049 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6051 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6052 struct net_device
*dev
= info
->user_ptr
[1];
6053 struct ieee80211_channel
*chan
;
6054 struct cfg80211_assoc_request req
= {};
6055 const u8
*bssid
, *ssid
;
6056 int err
, ssid_len
= 0;
6058 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6061 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6062 !info
->attrs
[NL80211_ATTR_SSID
] ||
6063 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6066 if (!rdev
->ops
->assoc
)
6069 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6070 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6073 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6075 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6076 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6077 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6080 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6081 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6083 if (info
->attrs
[NL80211_ATTR_IE
]) {
6084 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6085 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6088 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6089 enum nl80211_mfp mfp
=
6090 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6091 if (mfp
== NL80211_MFP_REQUIRED
)
6093 else if (mfp
!= NL80211_MFP_NO
)
6097 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6098 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6100 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6101 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6103 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6104 memcpy(&req
.ht_capa_mask
,
6105 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6106 sizeof(req
.ht_capa_mask
));
6108 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6109 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6111 memcpy(&req
.ht_capa
,
6112 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6113 sizeof(req
.ht_capa
));
6116 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6117 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6119 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6120 memcpy(&req
.vht_capa_mask
,
6121 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6122 sizeof(req
.vht_capa_mask
));
6124 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6125 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6127 memcpy(&req
.vht_capa
,
6128 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6129 sizeof(req
.vht_capa
));
6132 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6134 wdev_lock(dev
->ieee80211_ptr
);
6135 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6136 ssid
, ssid_len
, &req
);
6137 wdev_unlock(dev
->ieee80211_ptr
);
6143 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6145 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6146 struct net_device
*dev
= info
->user_ptr
[1];
6147 const u8
*ie
= NULL
, *bssid
;
6148 int ie_len
= 0, err
;
6150 bool local_state_change
;
6152 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6155 if (!info
->attrs
[NL80211_ATTR_MAC
])
6158 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6161 if (!rdev
->ops
->deauth
)
6164 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6165 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6168 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6170 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6171 if (reason_code
== 0) {
6172 /* Reason Code 0 is reserved */
6176 if (info
->attrs
[NL80211_ATTR_IE
]) {
6177 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6178 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6181 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6183 wdev_lock(dev
->ieee80211_ptr
);
6184 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6185 local_state_change
);
6186 wdev_unlock(dev
->ieee80211_ptr
);
6190 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6192 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6193 struct net_device
*dev
= info
->user_ptr
[1];
6194 const u8
*ie
= NULL
, *bssid
;
6195 int ie_len
= 0, err
;
6197 bool local_state_change
;
6199 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6202 if (!info
->attrs
[NL80211_ATTR_MAC
])
6205 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6208 if (!rdev
->ops
->disassoc
)
6211 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6212 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6215 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6217 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6218 if (reason_code
== 0) {
6219 /* Reason Code 0 is reserved */
6223 if (info
->attrs
[NL80211_ATTR_IE
]) {
6224 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6225 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6228 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6230 wdev_lock(dev
->ieee80211_ptr
);
6231 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6232 local_state_change
);
6233 wdev_unlock(dev
->ieee80211_ptr
);
6238 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6239 int mcast_rate
[IEEE80211_NUM_BANDS
],
6242 struct wiphy
*wiphy
= &rdev
->wiphy
;
6246 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6247 struct ieee80211_supported_band
*sband
;
6249 sband
= wiphy
->bands
[band
];
6253 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6254 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6255 mcast_rate
[band
] = i
+ 1;
6265 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6268 struct net_device
*dev
= info
->user_ptr
[1];
6269 struct cfg80211_ibss_params ibss
;
6270 struct wiphy
*wiphy
;
6271 struct cfg80211_cached_keys
*connkeys
= NULL
;
6274 memset(&ibss
, 0, sizeof(ibss
));
6276 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6279 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6280 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6283 ibss
.beacon_interval
= 100;
6285 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6286 ibss
.beacon_interval
=
6287 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6288 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6292 if (!rdev
->ops
->join_ibss
)
6295 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6298 wiphy
= &rdev
->wiphy
;
6300 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6301 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6303 if (!is_valid_ether_addr(ibss
.bssid
))
6306 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6307 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6309 if (info
->attrs
[NL80211_ATTR_IE
]) {
6310 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6311 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6314 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6318 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6321 switch (ibss
.chandef
.width
) {
6322 case NL80211_CHAN_WIDTH_20_NOHT
:
6324 case NL80211_CHAN_WIDTH_20
:
6325 case NL80211_CHAN_WIDTH_40
:
6326 if (rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
)
6332 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6333 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6335 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6337 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6339 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6340 struct ieee80211_supported_band
*sband
=
6341 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6343 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6349 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6350 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6351 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6354 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6357 connkeys
= nl80211_parse_connkeys(rdev
,
6358 info
->attrs
[NL80211_ATTR_KEYS
],
6360 if (IS_ERR(connkeys
))
6361 return PTR_ERR(connkeys
);
6363 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6371 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6373 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6379 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6381 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6382 struct net_device
*dev
= info
->user_ptr
[1];
6384 if (!rdev
->ops
->leave_ibss
)
6387 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6390 return cfg80211_leave_ibss(rdev
, dev
, false);
6393 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6395 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6396 struct net_device
*dev
= info
->user_ptr
[1];
6397 int mcast_rate
[IEEE80211_NUM_BANDS
];
6401 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6402 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6405 if (!rdev
->ops
->set_mcast_rate
)
6408 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6410 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6413 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6414 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6417 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6423 #ifdef CONFIG_NL80211_TESTMODE
6424 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6428 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6430 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6433 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6437 if (rdev
->ops
->testmode_cmd
) {
6438 rdev
->testmode_info
= info
;
6439 err
= rdev_testmode_cmd(rdev
,
6440 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6441 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6442 rdev
->testmode_info
= NULL
;
6448 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6449 struct netlink_callback
*cb
)
6451 struct cfg80211_registered_device
*rdev
;
6461 * 0 is a valid index, but not valid for args[0],
6462 * so we need to offset by 1.
6464 phy_idx
= cb
->args
[0] - 1;
6466 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6467 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6472 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6473 nl80211_fam
.attrbuf
);
6475 err
= PTR_ERR(rdev
);
6478 phy_idx
= rdev
->wiphy_idx
;
6481 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6483 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6487 data
= nla_data((void *)cb
->args
[1]);
6488 data_len
= nla_len((void *)cb
->args
[1]);
6491 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6497 if (!rdev
->ops
->testmode_dump
) {
6503 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6504 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6505 NL80211_CMD_TESTMODE
);
6506 struct nlattr
*tmdata
;
6508 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6509 genlmsg_cancel(skb
, hdr
);
6513 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6515 genlmsg_cancel(skb
, hdr
);
6518 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6519 nla_nest_end(skb
, tmdata
);
6521 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6522 genlmsg_cancel(skb
, hdr
);
6525 genlmsg_cancel(skb
, hdr
);
6529 genlmsg_end(skb
, hdr
);
6534 cb
->args
[0] = phy_idx
+ 1;
6540 static struct sk_buff
*
6541 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
6542 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
6544 struct sk_buff
*skb
;
6546 struct nlattr
*data
;
6548 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6552 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
6558 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6559 goto nla_put_failure
;
6560 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6562 ((void **)skb
->cb
)[0] = rdev
;
6563 ((void **)skb
->cb
)[1] = hdr
;
6564 ((void **)skb
->cb
)[2] = data
;
6573 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
6576 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6578 if (WARN_ON(!rdev
->testmode_info
))
6581 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
6582 rdev
->testmode_info
->snd_portid
,
6583 rdev
->testmode_info
->snd_seq
,
6586 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
6588 int cfg80211_testmode_reply(struct sk_buff
*skb
)
6590 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6591 void *hdr
= ((void **)skb
->cb
)[1];
6592 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6594 if (WARN_ON(!rdev
->testmode_info
)) {
6599 nla_nest_end(skb
, data
);
6600 genlmsg_end(skb
, hdr
);
6601 return genlmsg_reply(skb
, rdev
->testmode_info
);
6603 EXPORT_SYMBOL(cfg80211_testmode_reply
);
6605 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
6606 int approxlen
, gfp_t gfp
)
6608 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6610 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
6612 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
6614 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
6616 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6617 void *hdr
= ((void **)skb
->cb
)[1];
6618 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6620 nla_nest_end(skb
, data
);
6621 genlmsg_end(skb
, hdr
);
6622 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6623 nl80211_testmode_mcgrp
.id
, gfp
);
6625 EXPORT_SYMBOL(cfg80211_testmode_event
);
6628 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6630 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6631 struct net_device
*dev
= info
->user_ptr
[1];
6632 struct cfg80211_connect_params connect
;
6633 struct wiphy
*wiphy
;
6634 struct cfg80211_cached_keys
*connkeys
= NULL
;
6637 memset(&connect
, 0, sizeof(connect
));
6639 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6642 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6643 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6646 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6648 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6649 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6650 NL80211_CMD_CONNECT
))
6653 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6655 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6657 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6658 NL80211_MAX_NR_CIPHER_SUITES
);
6662 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6663 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6666 wiphy
= &rdev
->wiphy
;
6668 connect
.bg_scan_period
= -1;
6669 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6670 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6671 connect
.bg_scan_period
=
6672 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6675 if (info
->attrs
[NL80211_ATTR_MAC
])
6676 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6677 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6678 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6680 if (info
->attrs
[NL80211_ATTR_IE
]) {
6681 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6682 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6685 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6686 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6687 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6688 connect
.mfp
!= NL80211_MFP_NO
)
6691 connect
.mfp
= NL80211_MFP_NO
;
6694 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6696 ieee80211_get_channel(wiphy
,
6697 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6698 if (!connect
.channel
||
6699 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6703 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6704 connkeys
= nl80211_parse_connkeys(rdev
,
6705 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6706 if (IS_ERR(connkeys
))
6707 return PTR_ERR(connkeys
);
6710 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6711 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6713 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6714 memcpy(&connect
.ht_capa_mask
,
6715 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6716 sizeof(connect
.ht_capa_mask
));
6718 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6719 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6723 memcpy(&connect
.ht_capa
,
6724 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6725 sizeof(connect
.ht_capa
));
6728 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6729 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6731 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6732 memcpy(&connect
.vht_capa_mask
,
6733 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6734 sizeof(connect
.vht_capa_mask
));
6736 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6737 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6741 memcpy(&connect
.vht_capa
,
6742 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6743 sizeof(connect
.vht_capa
));
6746 wdev_lock(dev
->ieee80211_ptr
);
6747 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
6748 wdev_unlock(dev
->ieee80211_ptr
);
6754 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6756 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6757 struct net_device
*dev
= info
->user_ptr
[1];
6761 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6762 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6764 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6769 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6770 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6773 wdev_lock(dev
->ieee80211_ptr
);
6774 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
6775 wdev_unlock(dev
->ieee80211_ptr
);
6779 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6786 if (!info
->attrs
[NL80211_ATTR_PID
])
6789 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6791 net
= get_net_ns_by_pid(pid
);
6793 return PTR_ERR(net
);
6797 /* check if anything to do */
6798 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6799 err
= cfg80211_switch_netns(rdev
, net
);
6805 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6807 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6808 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6809 struct cfg80211_pmksa
*pmksa
) = NULL
;
6810 struct net_device
*dev
= info
->user_ptr
[1];
6811 struct cfg80211_pmksa pmksa
;
6813 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6815 if (!info
->attrs
[NL80211_ATTR_MAC
])
6818 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6821 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6822 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6824 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6825 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6828 switch (info
->genlhdr
->cmd
) {
6829 case NL80211_CMD_SET_PMKSA
:
6830 rdev_ops
= rdev
->ops
->set_pmksa
;
6832 case NL80211_CMD_DEL_PMKSA
:
6833 rdev_ops
= rdev
->ops
->del_pmksa
;
6843 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6846 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6848 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6849 struct net_device
*dev
= info
->user_ptr
[1];
6851 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6852 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6855 if (!rdev
->ops
->flush_pmksa
)
6858 return rdev_flush_pmksa(rdev
, dev
);
6861 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6863 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6864 struct net_device
*dev
= info
->user_ptr
[1];
6865 u8 action_code
, dialog_token
;
6869 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6870 !rdev
->ops
->tdls_mgmt
)
6873 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6874 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6875 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6876 !info
->attrs
[NL80211_ATTR_IE
] ||
6877 !info
->attrs
[NL80211_ATTR_MAC
])
6880 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6881 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6882 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6883 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6885 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6886 dialog_token
, status_code
,
6887 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6888 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6891 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6893 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6894 struct net_device
*dev
= info
->user_ptr
[1];
6895 enum nl80211_tdls_operation operation
;
6898 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6899 !rdev
->ops
->tdls_oper
)
6902 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6903 !info
->attrs
[NL80211_ATTR_MAC
])
6906 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6907 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6909 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6912 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6913 struct genl_info
*info
)
6915 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6916 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6917 struct cfg80211_chan_def chandef
;
6918 struct sk_buff
*msg
;
6924 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6925 !info
->attrs
[NL80211_ATTR_DURATION
])
6928 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6930 if (!rdev
->ops
->remain_on_channel
||
6931 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6935 * We should be on that channel for at least a minimum amount of
6936 * time (10ms) but no longer than the driver supports.
6938 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6939 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6942 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6946 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6950 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6951 NL80211_CMD_REMAIN_ON_CHANNEL
);
6958 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6964 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6965 goto nla_put_failure
;
6967 genlmsg_end(msg
, hdr
);
6969 return genlmsg_reply(msg
, info
);
6978 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
6979 struct genl_info
*info
)
6981 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6982 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6985 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6988 if (!rdev
->ops
->cancel_remain_on_channel
)
6991 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6993 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
6996 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
6997 u8
*rates
, u8 rates_len
)
7002 for (i
= 0; i
< rates_len
; i
++) {
7003 int rate
= (rates
[i
] & 0x7f) * 5;
7005 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7006 struct ieee80211_rate
*srate
=
7007 &sband
->bitrates
[ridx
];
7008 if (rate
== srate
->bitrate
) {
7013 if (ridx
== sband
->n_bitrates
)
7014 return 0; /* rate not found */
7020 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7021 u8
*rates
, u8 rates_len
,
7022 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7026 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7028 for (i
= 0; i
< rates_len
; i
++) {
7031 ridx
= rates
[i
] / 8;
7032 rbit
= BIT(rates
[i
] % 8);
7034 /* check validity */
7035 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7038 /* check availability */
7039 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7048 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7049 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7050 .len
= NL80211_MAX_SUPP_RATES
},
7051 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7052 .len
= NL80211_MAX_SUPP_HT_RATES
},
7055 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7056 struct genl_info
*info
)
7058 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7059 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7060 struct cfg80211_bitrate_mask mask
;
7062 struct net_device
*dev
= info
->user_ptr
[1];
7063 struct nlattr
*tx_rates
;
7064 struct ieee80211_supported_band
*sband
;
7066 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7069 if (!rdev
->ops
->set_bitrate_mask
)
7072 memset(&mask
, 0, sizeof(mask
));
7073 /* Default to all rates enabled */
7074 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7075 sband
= rdev
->wiphy
.bands
[i
];
7076 mask
.control
[i
].legacy
=
7077 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7079 memcpy(mask
.control
[i
].mcs
,
7080 sband
->ht_cap
.mcs
.rx_mask
,
7081 sizeof(mask
.control
[i
].mcs
));
7083 memset(mask
.control
[i
].mcs
, 0,
7084 sizeof(mask
.control
[i
].mcs
));
7088 * The nested attribute uses enum nl80211_band as the index. This maps
7089 * directly to the enum ieee80211_band values used in cfg80211.
7091 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7092 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7094 enum ieee80211_band band
= nla_type(tx_rates
);
7095 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7097 sband
= rdev
->wiphy
.bands
[band
];
7100 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7101 nla_len(tx_rates
), nl80211_txattr_policy
);
7102 if (tb
[NL80211_TXRATE_LEGACY
]) {
7103 mask
.control
[band
].legacy
= rateset_to_mask(
7105 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7106 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7107 if ((mask
.control
[band
].legacy
== 0) &&
7108 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7111 if (tb
[NL80211_TXRATE_MCS
]) {
7112 if (!ht_rateset_to_mask(
7114 nla_data(tb
[NL80211_TXRATE_MCS
]),
7115 nla_len(tb
[NL80211_TXRATE_MCS
]),
7116 mask
.control
[band
].mcs
))
7120 if (mask
.control
[band
].legacy
== 0) {
7121 /* don't allow empty legacy rates if HT
7122 * is not even supported. */
7123 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7126 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7127 if (mask
.control
[band
].mcs
[i
])
7130 /* legacy and mcs rates may not be both empty */
7131 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7136 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7139 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7141 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7142 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7143 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7145 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7148 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7149 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7151 switch (wdev
->iftype
) {
7152 case NL80211_IFTYPE_STATION
:
7153 case NL80211_IFTYPE_ADHOC
:
7154 case NL80211_IFTYPE_P2P_CLIENT
:
7155 case NL80211_IFTYPE_AP
:
7156 case NL80211_IFTYPE_AP_VLAN
:
7157 case NL80211_IFTYPE_MESH_POINT
:
7158 case NL80211_IFTYPE_P2P_GO
:
7159 case NL80211_IFTYPE_P2P_DEVICE
:
7165 /* not much point in registering if we can't reply */
7166 if (!rdev
->ops
->mgmt_tx
)
7169 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7170 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7171 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7174 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7176 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7177 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7178 struct cfg80211_chan_def chandef
;
7182 struct sk_buff
*msg
= NULL
;
7183 unsigned int wait
= 0;
7184 bool offchan
, no_cck
, dont_wait_for_ack
;
7186 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7188 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7191 if (!rdev
->ops
->mgmt_tx
)
7194 switch (wdev
->iftype
) {
7195 case NL80211_IFTYPE_P2P_DEVICE
:
7196 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7198 case NL80211_IFTYPE_STATION
:
7199 case NL80211_IFTYPE_ADHOC
:
7200 case NL80211_IFTYPE_P2P_CLIENT
:
7201 case NL80211_IFTYPE_AP
:
7202 case NL80211_IFTYPE_AP_VLAN
:
7203 case NL80211_IFTYPE_MESH_POINT
:
7204 case NL80211_IFTYPE_P2P_GO
:
7210 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7211 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7213 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7216 * We should wait on the channel for at least a minimum amount
7217 * of time (10ms) but no longer than the driver supports.
7219 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7220 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7225 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7227 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7230 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7232 /* get the channel if any has been specified, otherwise pass NULL to
7233 * the driver. The latter will use the current one
7235 chandef
.chan
= NULL
;
7236 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7237 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7242 if (!chandef
.chan
&& offchan
)
7245 if (!dont_wait_for_ack
) {
7246 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7250 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7259 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7260 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7261 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7262 no_cck
, dont_wait_for_ack
, &cookie
);
7267 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7268 goto nla_put_failure
;
7270 genlmsg_end(msg
, hdr
);
7271 return genlmsg_reply(msg
, info
);
7283 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7285 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7286 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7289 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7292 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7295 switch (wdev
->iftype
) {
7296 case NL80211_IFTYPE_STATION
:
7297 case NL80211_IFTYPE_ADHOC
:
7298 case NL80211_IFTYPE_P2P_CLIENT
:
7299 case NL80211_IFTYPE_AP
:
7300 case NL80211_IFTYPE_AP_VLAN
:
7301 case NL80211_IFTYPE_P2P_GO
:
7302 case NL80211_IFTYPE_P2P_DEVICE
:
7308 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7310 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7313 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7315 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7316 struct wireless_dev
*wdev
;
7317 struct net_device
*dev
= info
->user_ptr
[1];
7322 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7325 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7327 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7330 wdev
= dev
->ieee80211_ptr
;
7332 if (!rdev
->ops
->set_power_mgmt
)
7335 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7337 if (state
== wdev
->ps
)
7340 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7346 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7348 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7349 enum nl80211_ps_state ps_state
;
7350 struct wireless_dev
*wdev
;
7351 struct net_device
*dev
= info
->user_ptr
[1];
7352 struct sk_buff
*msg
;
7356 wdev
= dev
->ieee80211_ptr
;
7358 if (!rdev
->ops
->set_power_mgmt
)
7361 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7365 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7366 NL80211_CMD_GET_POWER_SAVE
);
7373 ps_state
= NL80211_PS_ENABLED
;
7375 ps_state
= NL80211_PS_DISABLED
;
7377 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7378 goto nla_put_failure
;
7380 genlmsg_end(msg
, hdr
);
7381 return genlmsg_reply(msg
, info
);
7390 static struct nla_policy
7391 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7392 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7393 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7394 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7395 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7396 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7397 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7400 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7401 u32 rate
, u32 pkts
, u32 intvl
)
7403 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7404 struct wireless_dev
*wdev
;
7405 struct net_device
*dev
= info
->user_ptr
[1];
7407 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7410 wdev
= dev
->ieee80211_ptr
;
7412 if (!rdev
->ops
->set_cqm_txe_config
)
7415 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7416 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7419 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7422 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7423 s32 threshold
, u32 hysteresis
)
7425 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7426 struct wireless_dev
*wdev
;
7427 struct net_device
*dev
= info
->user_ptr
[1];
7432 wdev
= dev
->ieee80211_ptr
;
7434 if (!rdev
->ops
->set_cqm_rssi_config
)
7437 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7438 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7441 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7444 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7446 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7450 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7456 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7457 nl80211_attr_cqm_policy
);
7461 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7462 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7465 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7466 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7467 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7468 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7469 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7470 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7471 u32 rate
, pkts
, intvl
;
7472 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7473 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7474 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7475 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7483 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7485 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7486 struct net_device
*dev
= info
->user_ptr
[1];
7487 struct mesh_config cfg
;
7488 struct mesh_setup setup
;
7491 /* start with default */
7492 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7493 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7495 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7496 /* and parse parameters if given */
7497 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7502 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7503 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7506 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7507 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7509 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7510 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7511 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7514 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7515 setup
.beacon_interval
=
7516 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7517 if (setup
.beacon_interval
< 10 ||
7518 setup
.beacon_interval
> 10000)
7522 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7524 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7525 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7529 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7530 /* parse additional setup parameters if given */
7531 err
= nl80211_parse_mesh_setup(info
, &setup
);
7537 cfg
.auto_open_plinks
= false;
7539 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7540 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7544 /* cfg80211_join_mesh() will sort it out */
7545 setup
.chandef
.chan
= NULL
;
7548 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7549 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7551 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7552 struct ieee80211_supported_band
*sband
;
7554 if (!setup
.chandef
.chan
)
7557 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
7559 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7560 &setup
.basic_rates
);
7565 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7568 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7570 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7571 struct net_device
*dev
= info
->user_ptr
[1];
7573 return cfg80211_leave_mesh(rdev
, dev
);
7577 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7578 struct cfg80211_registered_device
*rdev
)
7580 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
7581 struct nlattr
*nl_pats
, *nl_pat
;
7584 if (!wowlan
->n_patterns
)
7587 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7591 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
7592 nl_pat
= nla_nest_start(msg
, i
+ 1);
7595 pat_len
= wowlan
->patterns
[i
].pattern_len
;
7596 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7597 DIV_ROUND_UP(pat_len
, 8),
7598 wowlan
->patterns
[i
].mask
) ||
7599 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7600 pat_len
, wowlan
->patterns
[i
].pattern
) ||
7601 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7602 wowlan
->patterns
[i
].pkt_offset
))
7604 nla_nest_end(msg
, nl_pat
);
7606 nla_nest_end(msg
, nl_pats
);
7611 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7612 struct cfg80211_wowlan_tcp
*tcp
)
7614 struct nlattr
*nl_tcp
;
7619 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7623 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7624 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7625 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7626 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7627 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7628 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7629 tcp
->payload_len
, tcp
->payload
) ||
7630 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7631 tcp
->data_interval
) ||
7632 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7633 tcp
->wake_len
, tcp
->wake_data
) ||
7634 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7635 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7638 if (tcp
->payload_seq
.len
&&
7639 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7640 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7643 if (tcp
->payload_tok
.len
&&
7644 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7645 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7649 nla_nest_end(msg
, nl_tcp
);
7654 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7656 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7657 struct sk_buff
*msg
;
7659 u32 size
= NLMSG_DEFAULT_SIZE
;
7661 if (!rdev
->wiphy
.wowlan
)
7664 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
7665 /* adjust size to have room for all the data */
7666 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
7667 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
7668 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
7669 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
7672 msg
= nlmsg_new(size
, GFP_KERNEL
);
7676 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7677 NL80211_CMD_GET_WOWLAN
);
7679 goto nla_put_failure
;
7681 if (rdev
->wiphy
.wowlan_config
) {
7682 struct nlattr
*nl_wowlan
;
7684 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7686 goto nla_put_failure
;
7688 if ((rdev
->wiphy
.wowlan_config
->any
&&
7689 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7690 (rdev
->wiphy
.wowlan_config
->disconnect
&&
7691 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7692 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
7693 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7694 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
7695 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7696 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
7697 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7698 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
7699 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7700 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
7701 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7702 goto nla_put_failure
;
7704 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7705 goto nla_put_failure
;
7707 if (nl80211_send_wowlan_tcp(msg
,
7708 rdev
->wiphy
.wowlan_config
->tcp
))
7709 goto nla_put_failure
;
7711 nla_nest_end(msg
, nl_wowlan
);
7714 genlmsg_end(msg
, hdr
);
7715 return genlmsg_reply(msg
, info
);
7722 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7723 struct nlattr
*attr
,
7724 struct cfg80211_wowlan
*trig
)
7726 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7727 struct cfg80211_wowlan_tcp
*cfg
;
7728 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7729 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7731 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7734 if (!rdev
->wiphy
.wowlan
->tcp
)
7737 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7738 nla_data(attr
), nla_len(attr
),
7739 nl80211_wowlan_tcp_policy
);
7743 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7744 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7745 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7746 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7747 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7748 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7749 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7750 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7753 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7754 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
7757 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7758 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
7759 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7762 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7763 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
7766 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7767 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7770 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7771 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7773 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7774 tokens_size
= tokln
- sizeof(*tok
);
7776 if (!tok
->len
|| tokens_size
% tok
->len
)
7778 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
7780 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
7782 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
7784 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
7786 if (tok
->offset
+ tok
->len
> data_size
)
7790 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7791 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7792 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
7794 if (seq
->len
== 0 || seq
->len
> 4)
7796 if (seq
->len
+ seq
->offset
> data_size
)
7800 size
= sizeof(*cfg
);
7802 size
+= wake_size
+ wake_mask_size
;
7803 size
+= tokens_size
;
7805 cfg
= kzalloc(size
, GFP_KERNEL
);
7808 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7809 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7810 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7812 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7813 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7817 /* allocate a socket and port for it and use it */
7818 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7819 IPPROTO_TCP
, &cfg
->sock
, 1);
7824 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7825 sock_release(cfg
->sock
);
7829 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7835 cfg
->src_port
= port
;
7838 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7839 cfg
->payload_len
= data_size
;
7840 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7841 memcpy((void *)cfg
->payload
,
7842 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7845 cfg
->payload_seq
= *seq
;
7846 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7847 cfg
->wake_len
= wake_size
;
7848 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7849 memcpy((void *)cfg
->wake_data
,
7850 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7852 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7853 data_size
+ wake_size
;
7854 memcpy((void *)cfg
->wake_mask
,
7855 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7858 cfg
->tokens_size
= tokens_size
;
7859 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7867 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7869 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7870 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7871 struct cfg80211_wowlan new_triggers
= {};
7872 struct cfg80211_wowlan
*ntrig
;
7873 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
7875 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
7880 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7881 cfg80211_rdev_free_wowlan(rdev
);
7882 rdev
->wiphy
.wowlan_config
= NULL
;
7886 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7887 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7888 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7889 nl80211_wowlan_policy
);
7893 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7894 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7896 new_triggers
.any
= true;
7899 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7900 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7902 new_triggers
.disconnect
= true;
7905 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7906 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7908 new_triggers
.magic_pkt
= true;
7911 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7914 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7915 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7917 new_triggers
.gtk_rekey_failure
= true;
7920 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7921 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7923 new_triggers
.eap_identity_req
= true;
7926 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7927 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7929 new_triggers
.four_way_handshake
= true;
7932 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7933 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7935 new_triggers
.rfkill_release
= true;
7938 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7941 int rem
, pat_len
, mask_len
, pkt_offset
;
7942 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7944 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7947 if (n_patterns
> wowlan
->n_patterns
)
7950 new_triggers
.patterns
= kcalloc(n_patterns
,
7951 sizeof(new_triggers
.patterns
[0]),
7953 if (!new_triggers
.patterns
)
7956 new_triggers
.n_patterns
= n_patterns
;
7959 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7961 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7962 nla_data(pat
), nla_len(pat
), NULL
);
7964 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7965 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7967 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7968 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7969 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7972 if (pat_len
> wowlan
->pattern_max_len
||
7973 pat_len
< wowlan
->pattern_min_len
)
7976 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7979 pkt_offset
= nla_get_u32(
7980 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7981 if (pkt_offset
> wowlan
->max_pkt_offset
)
7983 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7985 new_triggers
.patterns
[i
].mask
=
7986 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7987 if (!new_triggers
.patterns
[i
].mask
) {
7991 new_triggers
.patterns
[i
].pattern
=
7992 new_triggers
.patterns
[i
].mask
+ mask_len
;
7993 memcpy(new_triggers
.patterns
[i
].mask
,
7994 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7996 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7997 memcpy(new_triggers
.patterns
[i
].pattern
,
7998 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
8004 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8005 err
= nl80211_parse_wowlan_tcp(
8006 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8012 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8017 cfg80211_rdev_free_wowlan(rdev
);
8018 rdev
->wiphy
.wowlan_config
= ntrig
;
8021 if (rdev
->ops
->set_wakeup
&&
8022 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
8023 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
8027 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8028 kfree(new_triggers
.patterns
[i
].mask
);
8029 kfree(new_triggers
.patterns
);
8030 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8031 sock_release(new_triggers
.tcp
->sock
);
8032 kfree(new_triggers
.tcp
);
8037 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8039 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8040 struct net_device
*dev
= info
->user_ptr
[1];
8041 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8042 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8043 struct cfg80211_gtk_rekey_data rekey_data
;
8046 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8049 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8050 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8051 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8052 nl80211_rekey_policy
);
8056 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8058 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8060 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8063 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8065 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8067 memcpy(rekey_data
.replay_ctr
,
8068 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8069 NL80211_REPLAY_CTR_LEN
);
8072 if (!wdev
->current_bss
) {
8077 if (!rdev
->ops
->set_rekey_data
) {
8082 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8088 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8089 struct genl_info
*info
)
8091 struct net_device
*dev
= info
->user_ptr
[1];
8092 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8094 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8095 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8098 if (wdev
->ap_unexpected_nlportid
)
8101 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8105 static int nl80211_probe_client(struct sk_buff
*skb
,
8106 struct genl_info
*info
)
8108 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8109 struct net_device
*dev
= info
->user_ptr
[1];
8110 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8111 struct sk_buff
*msg
;
8117 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8118 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8121 if (!info
->attrs
[NL80211_ATTR_MAC
])
8124 if (!rdev
->ops
->probe_client
)
8127 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8131 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8132 NL80211_CMD_PROBE_CLIENT
);
8139 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8141 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8145 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8146 goto nla_put_failure
;
8148 genlmsg_end(msg
, hdr
);
8150 return genlmsg_reply(msg
, info
);
8159 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8161 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8162 struct cfg80211_beacon_registration
*reg
, *nreg
;
8165 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8168 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8172 /* First, check if already registered. */
8173 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8174 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8175 if (reg
->nlportid
== info
->snd_portid
) {
8180 /* Add it to the list */
8181 nreg
->nlportid
= info
->snd_portid
;
8182 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8184 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8188 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8193 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8195 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8196 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8199 if (!rdev
->ops
->start_p2p_device
)
8202 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8205 if (wdev
->p2p_started
)
8208 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8212 err
= rdev_start_p2p_device(rdev
, wdev
);
8216 wdev
->p2p_started
= true;
8222 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8224 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8225 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8227 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8230 if (!rdev
->ops
->stop_p2p_device
)
8233 cfg80211_stop_p2p_device(rdev
, wdev
);
8238 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8239 struct genl_info
*info
)
8242 struct sk_buff
*msg
;
8244 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8248 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8249 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8251 goto nla_put_failure
;
8253 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8254 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8255 goto nla_put_failure
;
8257 genlmsg_end(msg
, hdr
);
8258 return genlmsg_reply(msg
, info
);
8265 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8268 struct cfg80211_update_ft_ies_params ft_params
;
8269 struct net_device
*dev
= info
->user_ptr
[1];
8271 if (!rdev
->ops
->update_ft_ies
)
8274 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8275 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8278 memset(&ft_params
, 0, sizeof(ft_params
));
8279 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8280 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8281 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8283 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8286 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8287 struct genl_info
*info
)
8289 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8290 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8291 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8295 if (!rdev
->ops
->crit_proto_start
)
8298 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8301 if (rdev
->crit_proto_nlportid
)
8304 /* determine protocol if provided */
8305 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8306 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8308 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8311 /* timeout must be provided */
8312 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8316 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8318 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8321 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8323 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8328 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8329 struct genl_info
*info
)
8331 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8332 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8334 if (!rdev
->ops
->crit_proto_stop
)
8337 if (rdev
->crit_proto_nlportid
) {
8338 rdev
->crit_proto_nlportid
= 0;
8339 rdev_crit_proto_stop(rdev
, wdev
);
8344 #define NL80211_FLAG_NEED_WIPHY 0x01
8345 #define NL80211_FLAG_NEED_NETDEV 0x02
8346 #define NL80211_FLAG_NEED_RTNL 0x04
8347 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8348 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8349 NL80211_FLAG_CHECK_NETDEV_UP)
8350 #define NL80211_FLAG_NEED_WDEV 0x10
8351 /* If a netdev is associated, it must be UP, P2P must be started */
8352 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8353 NL80211_FLAG_CHECK_NETDEV_UP)
8355 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8356 struct genl_info
*info
)
8358 struct cfg80211_registered_device
*rdev
;
8359 struct wireless_dev
*wdev
;
8360 struct net_device
*dev
;
8361 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8366 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8367 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8371 return PTR_ERR(rdev
);
8373 info
->user_ptr
[0] = rdev
;
8374 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8375 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8378 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8383 return PTR_ERR(wdev
);
8387 rdev
= wiphy_to_dev(wdev
->wiphy
);
8389 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8396 info
->user_ptr
[1] = dev
;
8398 info
->user_ptr
[1] = wdev
;
8402 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8403 !netif_running(dev
)) {
8410 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8411 if (!wdev
->p2p_started
) {
8418 info
->user_ptr
[0] = rdev
;
8424 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8425 struct genl_info
*info
)
8427 if (info
->user_ptr
[1]) {
8428 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8429 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8432 dev_put(wdev
->netdev
);
8434 dev_put(info
->user_ptr
[1]);
8437 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8441 static struct genl_ops nl80211_ops
[] = {
8443 .cmd
= NL80211_CMD_GET_WIPHY
,
8444 .doit
= nl80211_get_wiphy
,
8445 .dumpit
= nl80211_dump_wiphy
,
8446 .done
= nl80211_dump_wiphy_done
,
8447 .policy
= nl80211_policy
,
8448 /* can be retrieved by unprivileged users */
8449 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8450 NL80211_FLAG_NEED_RTNL
,
8453 .cmd
= NL80211_CMD_SET_WIPHY
,
8454 .doit
= nl80211_set_wiphy
,
8455 .policy
= nl80211_policy
,
8456 .flags
= GENL_ADMIN_PERM
,
8457 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8460 .cmd
= NL80211_CMD_GET_INTERFACE
,
8461 .doit
= nl80211_get_interface
,
8462 .dumpit
= nl80211_dump_interface
,
8463 .policy
= nl80211_policy
,
8464 /* can be retrieved by unprivileged users */
8465 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8466 NL80211_FLAG_NEED_RTNL
,
8469 .cmd
= NL80211_CMD_SET_INTERFACE
,
8470 .doit
= nl80211_set_interface
,
8471 .policy
= nl80211_policy
,
8472 .flags
= GENL_ADMIN_PERM
,
8473 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8474 NL80211_FLAG_NEED_RTNL
,
8477 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8478 .doit
= nl80211_new_interface
,
8479 .policy
= nl80211_policy
,
8480 .flags
= GENL_ADMIN_PERM
,
8481 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8482 NL80211_FLAG_NEED_RTNL
,
8485 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8486 .doit
= nl80211_del_interface
,
8487 .policy
= nl80211_policy
,
8488 .flags
= GENL_ADMIN_PERM
,
8489 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8490 NL80211_FLAG_NEED_RTNL
,
8493 .cmd
= NL80211_CMD_GET_KEY
,
8494 .doit
= nl80211_get_key
,
8495 .policy
= nl80211_policy
,
8496 .flags
= GENL_ADMIN_PERM
,
8497 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8498 NL80211_FLAG_NEED_RTNL
,
8501 .cmd
= NL80211_CMD_SET_KEY
,
8502 .doit
= nl80211_set_key
,
8503 .policy
= nl80211_policy
,
8504 .flags
= GENL_ADMIN_PERM
,
8505 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8506 NL80211_FLAG_NEED_RTNL
,
8509 .cmd
= NL80211_CMD_NEW_KEY
,
8510 .doit
= nl80211_new_key
,
8511 .policy
= nl80211_policy
,
8512 .flags
= GENL_ADMIN_PERM
,
8513 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8514 NL80211_FLAG_NEED_RTNL
,
8517 .cmd
= NL80211_CMD_DEL_KEY
,
8518 .doit
= nl80211_del_key
,
8519 .policy
= nl80211_policy
,
8520 .flags
= GENL_ADMIN_PERM
,
8521 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8522 NL80211_FLAG_NEED_RTNL
,
8525 .cmd
= NL80211_CMD_SET_BEACON
,
8526 .policy
= nl80211_policy
,
8527 .flags
= GENL_ADMIN_PERM
,
8528 .doit
= nl80211_set_beacon
,
8529 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8530 NL80211_FLAG_NEED_RTNL
,
8533 .cmd
= NL80211_CMD_START_AP
,
8534 .policy
= nl80211_policy
,
8535 .flags
= GENL_ADMIN_PERM
,
8536 .doit
= nl80211_start_ap
,
8537 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8538 NL80211_FLAG_NEED_RTNL
,
8541 .cmd
= NL80211_CMD_STOP_AP
,
8542 .policy
= nl80211_policy
,
8543 .flags
= GENL_ADMIN_PERM
,
8544 .doit
= nl80211_stop_ap
,
8545 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8546 NL80211_FLAG_NEED_RTNL
,
8549 .cmd
= NL80211_CMD_GET_STATION
,
8550 .doit
= nl80211_get_station
,
8551 .dumpit
= nl80211_dump_station
,
8552 .policy
= nl80211_policy
,
8553 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8554 NL80211_FLAG_NEED_RTNL
,
8557 .cmd
= NL80211_CMD_SET_STATION
,
8558 .doit
= nl80211_set_station
,
8559 .policy
= nl80211_policy
,
8560 .flags
= GENL_ADMIN_PERM
,
8561 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8562 NL80211_FLAG_NEED_RTNL
,
8565 .cmd
= NL80211_CMD_NEW_STATION
,
8566 .doit
= nl80211_new_station
,
8567 .policy
= nl80211_policy
,
8568 .flags
= GENL_ADMIN_PERM
,
8569 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8570 NL80211_FLAG_NEED_RTNL
,
8573 .cmd
= NL80211_CMD_DEL_STATION
,
8574 .doit
= nl80211_del_station
,
8575 .policy
= nl80211_policy
,
8576 .flags
= GENL_ADMIN_PERM
,
8577 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8578 NL80211_FLAG_NEED_RTNL
,
8581 .cmd
= NL80211_CMD_GET_MPATH
,
8582 .doit
= nl80211_get_mpath
,
8583 .dumpit
= nl80211_dump_mpath
,
8584 .policy
= nl80211_policy
,
8585 .flags
= GENL_ADMIN_PERM
,
8586 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8587 NL80211_FLAG_NEED_RTNL
,
8590 .cmd
= NL80211_CMD_SET_MPATH
,
8591 .doit
= nl80211_set_mpath
,
8592 .policy
= nl80211_policy
,
8593 .flags
= GENL_ADMIN_PERM
,
8594 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8595 NL80211_FLAG_NEED_RTNL
,
8598 .cmd
= NL80211_CMD_NEW_MPATH
,
8599 .doit
= nl80211_new_mpath
,
8600 .policy
= nl80211_policy
,
8601 .flags
= GENL_ADMIN_PERM
,
8602 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8603 NL80211_FLAG_NEED_RTNL
,
8606 .cmd
= NL80211_CMD_DEL_MPATH
,
8607 .doit
= nl80211_del_mpath
,
8608 .policy
= nl80211_policy
,
8609 .flags
= GENL_ADMIN_PERM
,
8610 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8611 NL80211_FLAG_NEED_RTNL
,
8614 .cmd
= NL80211_CMD_SET_BSS
,
8615 .doit
= nl80211_set_bss
,
8616 .policy
= nl80211_policy
,
8617 .flags
= GENL_ADMIN_PERM
,
8618 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8619 NL80211_FLAG_NEED_RTNL
,
8622 .cmd
= NL80211_CMD_GET_REG
,
8623 .doit
= nl80211_get_reg
,
8624 .policy
= nl80211_policy
,
8625 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8626 /* can be retrieved by unprivileged users */
8629 .cmd
= NL80211_CMD_SET_REG
,
8630 .doit
= nl80211_set_reg
,
8631 .policy
= nl80211_policy
,
8632 .flags
= GENL_ADMIN_PERM
,
8633 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8636 .cmd
= NL80211_CMD_REQ_SET_REG
,
8637 .doit
= nl80211_req_set_reg
,
8638 .policy
= nl80211_policy
,
8639 .flags
= GENL_ADMIN_PERM
,
8642 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8643 .doit
= nl80211_get_mesh_config
,
8644 .policy
= nl80211_policy
,
8645 /* can be retrieved by unprivileged users */
8646 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8647 NL80211_FLAG_NEED_RTNL
,
8650 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8651 .doit
= nl80211_update_mesh_config
,
8652 .policy
= nl80211_policy
,
8653 .flags
= GENL_ADMIN_PERM
,
8654 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8655 NL80211_FLAG_NEED_RTNL
,
8658 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8659 .doit
= nl80211_trigger_scan
,
8660 .policy
= nl80211_policy
,
8661 .flags
= GENL_ADMIN_PERM
,
8662 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8663 NL80211_FLAG_NEED_RTNL
,
8666 .cmd
= NL80211_CMD_GET_SCAN
,
8667 .policy
= nl80211_policy
,
8668 .dumpit
= nl80211_dump_scan
,
8671 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8672 .doit
= nl80211_start_sched_scan
,
8673 .policy
= nl80211_policy
,
8674 .flags
= GENL_ADMIN_PERM
,
8675 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8676 NL80211_FLAG_NEED_RTNL
,
8679 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8680 .doit
= nl80211_stop_sched_scan
,
8681 .policy
= nl80211_policy
,
8682 .flags
= GENL_ADMIN_PERM
,
8683 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8684 NL80211_FLAG_NEED_RTNL
,
8687 .cmd
= NL80211_CMD_AUTHENTICATE
,
8688 .doit
= nl80211_authenticate
,
8689 .policy
= nl80211_policy
,
8690 .flags
= GENL_ADMIN_PERM
,
8691 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8692 NL80211_FLAG_NEED_RTNL
,
8695 .cmd
= NL80211_CMD_ASSOCIATE
,
8696 .doit
= nl80211_associate
,
8697 .policy
= nl80211_policy
,
8698 .flags
= GENL_ADMIN_PERM
,
8699 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8700 NL80211_FLAG_NEED_RTNL
,
8703 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8704 .doit
= nl80211_deauthenticate
,
8705 .policy
= nl80211_policy
,
8706 .flags
= GENL_ADMIN_PERM
,
8707 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8708 NL80211_FLAG_NEED_RTNL
,
8711 .cmd
= NL80211_CMD_DISASSOCIATE
,
8712 .doit
= nl80211_disassociate
,
8713 .policy
= nl80211_policy
,
8714 .flags
= GENL_ADMIN_PERM
,
8715 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8716 NL80211_FLAG_NEED_RTNL
,
8719 .cmd
= NL80211_CMD_JOIN_IBSS
,
8720 .doit
= nl80211_join_ibss
,
8721 .policy
= nl80211_policy
,
8722 .flags
= GENL_ADMIN_PERM
,
8723 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8724 NL80211_FLAG_NEED_RTNL
,
8727 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8728 .doit
= nl80211_leave_ibss
,
8729 .policy
= nl80211_policy
,
8730 .flags
= GENL_ADMIN_PERM
,
8731 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8732 NL80211_FLAG_NEED_RTNL
,
8734 #ifdef CONFIG_NL80211_TESTMODE
8736 .cmd
= NL80211_CMD_TESTMODE
,
8737 .doit
= nl80211_testmode_do
,
8738 .dumpit
= nl80211_testmode_dump
,
8739 .policy
= nl80211_policy
,
8740 .flags
= GENL_ADMIN_PERM
,
8741 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8742 NL80211_FLAG_NEED_RTNL
,
8746 .cmd
= NL80211_CMD_CONNECT
,
8747 .doit
= nl80211_connect
,
8748 .policy
= nl80211_policy
,
8749 .flags
= GENL_ADMIN_PERM
,
8750 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8751 NL80211_FLAG_NEED_RTNL
,
8754 .cmd
= NL80211_CMD_DISCONNECT
,
8755 .doit
= nl80211_disconnect
,
8756 .policy
= nl80211_policy
,
8757 .flags
= GENL_ADMIN_PERM
,
8758 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8759 NL80211_FLAG_NEED_RTNL
,
8762 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8763 .doit
= nl80211_wiphy_netns
,
8764 .policy
= nl80211_policy
,
8765 .flags
= GENL_ADMIN_PERM
,
8766 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8767 NL80211_FLAG_NEED_RTNL
,
8770 .cmd
= NL80211_CMD_GET_SURVEY
,
8771 .policy
= nl80211_policy
,
8772 .dumpit
= nl80211_dump_survey
,
8775 .cmd
= NL80211_CMD_SET_PMKSA
,
8776 .doit
= nl80211_setdel_pmksa
,
8777 .policy
= nl80211_policy
,
8778 .flags
= GENL_ADMIN_PERM
,
8779 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8780 NL80211_FLAG_NEED_RTNL
,
8783 .cmd
= NL80211_CMD_DEL_PMKSA
,
8784 .doit
= nl80211_setdel_pmksa
,
8785 .policy
= nl80211_policy
,
8786 .flags
= GENL_ADMIN_PERM
,
8787 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8788 NL80211_FLAG_NEED_RTNL
,
8791 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8792 .doit
= nl80211_flush_pmksa
,
8793 .policy
= nl80211_policy
,
8794 .flags
= GENL_ADMIN_PERM
,
8795 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8796 NL80211_FLAG_NEED_RTNL
,
8799 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8800 .doit
= nl80211_remain_on_channel
,
8801 .policy
= nl80211_policy
,
8802 .flags
= GENL_ADMIN_PERM
,
8803 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8804 NL80211_FLAG_NEED_RTNL
,
8807 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8808 .doit
= nl80211_cancel_remain_on_channel
,
8809 .policy
= nl80211_policy
,
8810 .flags
= GENL_ADMIN_PERM
,
8811 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8812 NL80211_FLAG_NEED_RTNL
,
8815 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8816 .doit
= nl80211_set_tx_bitrate_mask
,
8817 .policy
= nl80211_policy
,
8818 .flags
= GENL_ADMIN_PERM
,
8819 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8820 NL80211_FLAG_NEED_RTNL
,
8823 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8824 .doit
= nl80211_register_mgmt
,
8825 .policy
= nl80211_policy
,
8826 .flags
= GENL_ADMIN_PERM
,
8827 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8828 NL80211_FLAG_NEED_RTNL
,
8831 .cmd
= NL80211_CMD_FRAME
,
8832 .doit
= nl80211_tx_mgmt
,
8833 .policy
= nl80211_policy
,
8834 .flags
= GENL_ADMIN_PERM
,
8835 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8836 NL80211_FLAG_NEED_RTNL
,
8839 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8840 .doit
= nl80211_tx_mgmt_cancel_wait
,
8841 .policy
= nl80211_policy
,
8842 .flags
= GENL_ADMIN_PERM
,
8843 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8844 NL80211_FLAG_NEED_RTNL
,
8847 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8848 .doit
= nl80211_set_power_save
,
8849 .policy
= nl80211_policy
,
8850 .flags
= GENL_ADMIN_PERM
,
8851 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8852 NL80211_FLAG_NEED_RTNL
,
8855 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8856 .doit
= nl80211_get_power_save
,
8857 .policy
= nl80211_policy
,
8858 /* can be retrieved by unprivileged users */
8859 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8860 NL80211_FLAG_NEED_RTNL
,
8863 .cmd
= NL80211_CMD_SET_CQM
,
8864 .doit
= nl80211_set_cqm
,
8865 .policy
= nl80211_policy
,
8866 .flags
= GENL_ADMIN_PERM
,
8867 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8868 NL80211_FLAG_NEED_RTNL
,
8871 .cmd
= NL80211_CMD_SET_CHANNEL
,
8872 .doit
= nl80211_set_channel
,
8873 .policy
= nl80211_policy
,
8874 .flags
= GENL_ADMIN_PERM
,
8875 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8876 NL80211_FLAG_NEED_RTNL
,
8879 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8880 .doit
= nl80211_set_wds_peer
,
8881 .policy
= nl80211_policy
,
8882 .flags
= GENL_ADMIN_PERM
,
8883 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8884 NL80211_FLAG_NEED_RTNL
,
8887 .cmd
= NL80211_CMD_JOIN_MESH
,
8888 .doit
= nl80211_join_mesh
,
8889 .policy
= nl80211_policy
,
8890 .flags
= GENL_ADMIN_PERM
,
8891 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8892 NL80211_FLAG_NEED_RTNL
,
8895 .cmd
= NL80211_CMD_LEAVE_MESH
,
8896 .doit
= nl80211_leave_mesh
,
8897 .policy
= nl80211_policy
,
8898 .flags
= GENL_ADMIN_PERM
,
8899 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8900 NL80211_FLAG_NEED_RTNL
,
8904 .cmd
= NL80211_CMD_GET_WOWLAN
,
8905 .doit
= nl80211_get_wowlan
,
8906 .policy
= nl80211_policy
,
8907 /* can be retrieved by unprivileged users */
8908 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8909 NL80211_FLAG_NEED_RTNL
,
8912 .cmd
= NL80211_CMD_SET_WOWLAN
,
8913 .doit
= nl80211_set_wowlan
,
8914 .policy
= nl80211_policy
,
8915 .flags
= GENL_ADMIN_PERM
,
8916 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8917 NL80211_FLAG_NEED_RTNL
,
8921 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
8922 .doit
= nl80211_set_rekey_data
,
8923 .policy
= nl80211_policy
,
8924 .flags
= GENL_ADMIN_PERM
,
8925 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8926 NL80211_FLAG_NEED_RTNL
,
8929 .cmd
= NL80211_CMD_TDLS_MGMT
,
8930 .doit
= nl80211_tdls_mgmt
,
8931 .policy
= nl80211_policy
,
8932 .flags
= GENL_ADMIN_PERM
,
8933 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8934 NL80211_FLAG_NEED_RTNL
,
8937 .cmd
= NL80211_CMD_TDLS_OPER
,
8938 .doit
= nl80211_tdls_oper
,
8939 .policy
= nl80211_policy
,
8940 .flags
= GENL_ADMIN_PERM
,
8941 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8942 NL80211_FLAG_NEED_RTNL
,
8945 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
8946 .doit
= nl80211_register_unexpected_frame
,
8947 .policy
= nl80211_policy
,
8948 .flags
= GENL_ADMIN_PERM
,
8949 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8950 NL80211_FLAG_NEED_RTNL
,
8953 .cmd
= NL80211_CMD_PROBE_CLIENT
,
8954 .doit
= nl80211_probe_client
,
8955 .policy
= nl80211_policy
,
8956 .flags
= GENL_ADMIN_PERM
,
8957 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8958 NL80211_FLAG_NEED_RTNL
,
8961 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
8962 .doit
= nl80211_register_beacons
,
8963 .policy
= nl80211_policy
,
8964 .flags
= GENL_ADMIN_PERM
,
8965 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8966 NL80211_FLAG_NEED_RTNL
,
8969 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
8970 .doit
= nl80211_set_noack_map
,
8971 .policy
= nl80211_policy
,
8972 .flags
= GENL_ADMIN_PERM
,
8973 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8974 NL80211_FLAG_NEED_RTNL
,
8977 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
8978 .doit
= nl80211_start_p2p_device
,
8979 .policy
= nl80211_policy
,
8980 .flags
= GENL_ADMIN_PERM
,
8981 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8982 NL80211_FLAG_NEED_RTNL
,
8985 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
8986 .doit
= nl80211_stop_p2p_device
,
8987 .policy
= nl80211_policy
,
8988 .flags
= GENL_ADMIN_PERM
,
8989 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8990 NL80211_FLAG_NEED_RTNL
,
8993 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
8994 .doit
= nl80211_set_mcast_rate
,
8995 .policy
= nl80211_policy
,
8996 .flags
= GENL_ADMIN_PERM
,
8997 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8998 NL80211_FLAG_NEED_RTNL
,
9001 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9002 .doit
= nl80211_set_mac_acl
,
9003 .policy
= nl80211_policy
,
9004 .flags
= GENL_ADMIN_PERM
,
9005 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9006 NL80211_FLAG_NEED_RTNL
,
9009 .cmd
= NL80211_CMD_RADAR_DETECT
,
9010 .doit
= nl80211_start_radar_detection
,
9011 .policy
= nl80211_policy
,
9012 .flags
= GENL_ADMIN_PERM
,
9013 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9014 NL80211_FLAG_NEED_RTNL
,
9017 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9018 .doit
= nl80211_get_protocol_features
,
9019 .policy
= nl80211_policy
,
9022 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9023 .doit
= nl80211_update_ft_ies
,
9024 .policy
= nl80211_policy
,
9025 .flags
= GENL_ADMIN_PERM
,
9026 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9027 NL80211_FLAG_NEED_RTNL
,
9030 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9031 .doit
= nl80211_crit_protocol_start
,
9032 .policy
= nl80211_policy
,
9033 .flags
= GENL_ADMIN_PERM
,
9034 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9035 NL80211_FLAG_NEED_RTNL
,
9038 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9039 .doit
= nl80211_crit_protocol_stop
,
9040 .policy
= nl80211_policy
,
9041 .flags
= GENL_ADMIN_PERM
,
9042 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9043 NL80211_FLAG_NEED_RTNL
,
9047 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9051 /* multicast groups */
9052 static struct genl_multicast_group nl80211_config_mcgrp
= {
9055 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9058 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9059 .name
= "regulatory",
9062 /* notification functions */
9064 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9066 struct sk_buff
*msg
;
9067 struct nl80211_dump_wiphy_state state
= {};
9069 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9073 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0, &state
) < 0) {
9078 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9079 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9082 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9083 struct cfg80211_registered_device
*rdev
)
9085 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9086 struct nlattr
*nest
;
9092 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9094 goto nla_put_failure
;
9095 for (i
= 0; i
< req
->n_ssids
; i
++) {
9096 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9097 goto nla_put_failure
;
9099 nla_nest_end(msg
, nest
);
9101 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9103 goto nla_put_failure
;
9104 for (i
= 0; i
< req
->n_channels
; i
++) {
9105 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9106 goto nla_put_failure
;
9108 nla_nest_end(msg
, nest
);
9111 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9112 goto nla_put_failure
;
9115 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9122 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9123 struct cfg80211_registered_device
*rdev
,
9124 struct wireless_dev
*wdev
,
9125 u32 portid
, u32 seq
, int flags
,
9130 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9134 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9135 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9136 wdev
->netdev
->ifindex
)) ||
9137 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9138 goto nla_put_failure
;
9140 /* ignore errors and send incomplete event anyway */
9141 nl80211_add_scan_req(msg
, rdev
);
9143 return genlmsg_end(msg
, hdr
);
9146 genlmsg_cancel(msg
, hdr
);
9151 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9152 struct cfg80211_registered_device
*rdev
,
9153 struct net_device
*netdev
,
9154 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9158 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9162 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9163 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9164 goto nla_put_failure
;
9166 return genlmsg_end(msg
, hdr
);
9169 genlmsg_cancel(msg
, hdr
);
9173 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9174 struct wireless_dev
*wdev
)
9176 struct sk_buff
*msg
;
9178 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9182 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9183 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9188 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9189 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9192 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9193 struct wireless_dev
*wdev
)
9195 struct sk_buff
*msg
;
9197 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9201 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9202 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9207 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9208 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9211 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9212 struct wireless_dev
*wdev
)
9214 struct sk_buff
*msg
;
9216 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9220 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9221 NL80211_CMD_SCAN_ABORTED
) < 0) {
9226 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9227 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9230 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9231 struct net_device
*netdev
)
9233 struct sk_buff
*msg
;
9235 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9239 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9240 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9245 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9246 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9249 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9250 struct net_device
*netdev
, u32 cmd
)
9252 struct sk_buff
*msg
;
9254 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9258 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9263 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9264 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9268 * This can happen on global regulatory changes or device specific settings
9269 * based on custom world regulatory domains.
9271 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9273 struct sk_buff
*msg
;
9276 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9280 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9286 /* Userspace can always count this one always being set */
9287 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9288 goto nla_put_failure
;
9290 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9291 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9292 NL80211_REGDOM_TYPE_WORLD
))
9293 goto nla_put_failure
;
9294 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9295 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9296 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9297 goto nla_put_failure
;
9298 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9299 request
->intersect
) {
9300 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9301 NL80211_REGDOM_TYPE_INTERSECTION
))
9302 goto nla_put_failure
;
9304 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9305 NL80211_REGDOM_TYPE_COUNTRY
) ||
9306 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9308 goto nla_put_failure
;
9311 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9312 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9313 goto nla_put_failure
;
9315 genlmsg_end(msg
, hdr
);
9318 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9325 genlmsg_cancel(msg
, hdr
);
9329 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9330 struct net_device
*netdev
,
9331 const u8
*buf
, size_t len
,
9332 enum nl80211_commands cmd
, gfp_t gfp
)
9334 struct sk_buff
*msg
;
9337 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9341 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9347 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9348 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9349 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9350 goto nla_put_failure
;
9352 genlmsg_end(msg
, hdr
);
9354 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9355 nl80211_mlme_mcgrp
.id
, gfp
);
9359 genlmsg_cancel(msg
, hdr
);
9363 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9364 struct net_device
*netdev
, const u8
*buf
,
9365 size_t len
, gfp_t gfp
)
9367 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9368 NL80211_CMD_AUTHENTICATE
, gfp
);
9371 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9372 struct net_device
*netdev
, const u8
*buf
,
9373 size_t len
, gfp_t gfp
)
9375 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9376 NL80211_CMD_ASSOCIATE
, gfp
);
9379 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9380 struct net_device
*netdev
, const u8
*buf
,
9381 size_t len
, gfp_t gfp
)
9383 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9384 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9387 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9388 struct net_device
*netdev
, const u8
*buf
,
9389 size_t len
, gfp_t gfp
)
9391 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9392 NL80211_CMD_DISASSOCIATE
, gfp
);
9395 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
9398 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9399 struct wiphy
*wiphy
= wdev
->wiphy
;
9400 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9401 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
9404 if (WARN_ON(len
< 2))
9407 if (ieee80211_is_deauth(mgmt
->frame_control
))
9408 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
9410 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
9412 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
9413 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
);
9415 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
9417 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9418 struct net_device
*netdev
, int cmd
,
9419 const u8
*addr
, gfp_t gfp
)
9421 struct sk_buff
*msg
;
9424 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9428 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9434 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9435 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9436 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9437 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9438 goto nla_put_failure
;
9440 genlmsg_end(msg
, hdr
);
9442 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9443 nl80211_mlme_mcgrp
.id
, gfp
);
9447 genlmsg_cancel(msg
, hdr
);
9451 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9452 struct net_device
*netdev
, const u8
*addr
,
9455 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9459 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9460 struct net_device
*netdev
, const u8
*addr
,
9463 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9467 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9468 struct net_device
*netdev
, const u8
*bssid
,
9469 const u8
*req_ie
, size_t req_ie_len
,
9470 const u8
*resp_ie
, size_t resp_ie_len
,
9471 u16 status
, gfp_t gfp
)
9473 struct sk_buff
*msg
;
9476 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9480 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9486 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9487 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9488 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9489 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9491 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9493 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9494 goto nla_put_failure
;
9496 genlmsg_end(msg
, hdr
);
9498 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9499 nl80211_mlme_mcgrp
.id
, gfp
);
9503 genlmsg_cancel(msg
, hdr
);
9508 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9509 struct net_device
*netdev
, const u8
*bssid
,
9510 const u8
*req_ie
, size_t req_ie_len
,
9511 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9513 struct sk_buff
*msg
;
9516 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9520 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9526 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9527 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9528 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9530 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9532 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9533 goto nla_put_failure
;
9535 genlmsg_end(msg
, hdr
);
9537 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9538 nl80211_mlme_mcgrp
.id
, gfp
);
9542 genlmsg_cancel(msg
, hdr
);
9547 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9548 struct net_device
*netdev
, u16 reason
,
9549 const u8
*ie
, size_t ie_len
, bool from_ap
)
9551 struct sk_buff
*msg
;
9554 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9558 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9564 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9565 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9566 (from_ap
&& reason
&&
9567 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9569 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9570 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9571 goto nla_put_failure
;
9573 genlmsg_end(msg
, hdr
);
9575 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9576 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9580 genlmsg_cancel(msg
, hdr
);
9585 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9586 struct net_device
*netdev
, const u8
*bssid
,
9589 struct sk_buff
*msg
;
9592 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9596 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9602 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9603 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9604 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9605 goto nla_put_failure
;
9607 genlmsg_end(msg
, hdr
);
9609 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9610 nl80211_mlme_mcgrp
.id
, gfp
);
9614 genlmsg_cancel(msg
, hdr
);
9618 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9619 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9621 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9622 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9623 struct sk_buff
*msg
;
9626 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9629 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9631 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9635 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9641 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9642 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9643 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9645 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9646 goto nla_put_failure
;
9648 genlmsg_end(msg
, hdr
);
9650 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9651 nl80211_mlme_mcgrp
.id
, gfp
);
9655 genlmsg_cancel(msg
, hdr
);
9658 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9660 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9661 struct net_device
*netdev
, const u8
*addr
,
9662 enum nl80211_key_type key_type
, int key_id
,
9663 const u8
*tsc
, gfp_t gfp
)
9665 struct sk_buff
*msg
;
9668 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9672 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9678 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9679 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9680 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9681 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9683 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9684 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9685 goto nla_put_failure
;
9687 genlmsg_end(msg
, hdr
);
9689 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9690 nl80211_mlme_mcgrp
.id
, gfp
);
9694 genlmsg_cancel(msg
, hdr
);
9698 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9699 struct ieee80211_channel
*channel_before
,
9700 struct ieee80211_channel
*channel_after
)
9702 struct sk_buff
*msg
;
9704 struct nlattr
*nl_freq
;
9706 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9710 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9717 * Since we are applying the beacon hint to a wiphy we know its
9718 * wiphy_idx is valid
9720 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9721 goto nla_put_failure
;
9724 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9726 goto nla_put_failure
;
9727 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9728 goto nla_put_failure
;
9729 nla_nest_end(msg
, nl_freq
);
9732 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9734 goto nla_put_failure
;
9735 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9736 goto nla_put_failure
;
9737 nla_nest_end(msg
, nl_freq
);
9739 genlmsg_end(msg
, hdr
);
9742 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9749 genlmsg_cancel(msg
, hdr
);
9753 static void nl80211_send_remain_on_chan_event(
9754 int cmd
, struct cfg80211_registered_device
*rdev
,
9755 struct wireless_dev
*wdev
, u64 cookie
,
9756 struct ieee80211_channel
*chan
,
9757 unsigned int duration
, gfp_t gfp
)
9759 struct sk_buff
*msg
;
9762 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9766 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9772 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9773 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9774 wdev
->netdev
->ifindex
)) ||
9775 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9776 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9777 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9778 NL80211_CHAN_NO_HT
) ||
9779 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9780 goto nla_put_failure
;
9782 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9783 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9784 goto nla_put_failure
;
9786 genlmsg_end(msg
, hdr
);
9788 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9789 nl80211_mlme_mcgrp
.id
, gfp
);
9793 genlmsg_cancel(msg
, hdr
);
9797 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9798 struct ieee80211_channel
*chan
,
9799 unsigned int duration
, gfp_t gfp
)
9801 struct wiphy
*wiphy
= wdev
->wiphy
;
9802 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9804 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9805 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9806 rdev
, wdev
, cookie
, chan
,
9809 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9811 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9812 struct ieee80211_channel
*chan
,
9815 struct wiphy
*wiphy
= wdev
->wiphy
;
9816 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9818 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9819 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9820 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9822 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9824 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9825 struct station_info
*sinfo
, gfp_t gfp
)
9827 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9828 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9829 struct sk_buff
*msg
;
9831 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9833 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9837 if (nl80211_send_station(msg
, 0, 0, 0,
9838 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9843 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9844 nl80211_mlme_mcgrp
.id
, gfp
);
9846 EXPORT_SYMBOL(cfg80211_new_sta
);
9848 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9850 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9851 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9852 struct sk_buff
*msg
;
9855 trace_cfg80211_del_sta(dev
, mac_addr
);
9857 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9861 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9867 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9868 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9869 goto nla_put_failure
;
9871 genlmsg_end(msg
, hdr
);
9873 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9874 nl80211_mlme_mcgrp
.id
, gfp
);
9878 genlmsg_cancel(msg
, hdr
);
9881 EXPORT_SYMBOL(cfg80211_del_sta
);
9883 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
9884 enum nl80211_connect_failed_reason reason
,
9887 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9888 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9889 struct sk_buff
*msg
;
9892 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
9896 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
9902 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9903 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
9904 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
9905 goto nla_put_failure
;
9907 genlmsg_end(msg
, hdr
);
9909 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9910 nl80211_mlme_mcgrp
.id
, gfp
);
9914 genlmsg_cancel(msg
, hdr
);
9917 EXPORT_SYMBOL(cfg80211_conn_failed
);
9919 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
9920 const u8
*addr
, gfp_t gfp
)
9922 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9923 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9924 struct sk_buff
*msg
;
9926 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
9931 msg
= nlmsg_new(100, gfp
);
9935 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9941 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9942 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9943 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9944 goto nla_put_failure
;
9946 genlmsg_end(msg
, hdr
);
9947 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9951 genlmsg_cancel(msg
, hdr
);
9956 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
9957 const u8
*addr
, gfp_t gfp
)
9959 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9962 trace_cfg80211_rx_spurious_frame(dev
, addr
);
9964 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9965 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
9966 trace_cfg80211_return_bool(false);
9969 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
9971 trace_cfg80211_return_bool(ret
);
9974 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
9976 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
9977 const u8
*addr
, gfp_t gfp
)
9979 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9982 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
9984 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9985 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
9986 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
9987 trace_cfg80211_return_bool(false);
9990 ret
= __nl80211_unexpected_frame(dev
,
9991 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
9993 trace_cfg80211_return_bool(ret
);
9996 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
9998 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
9999 struct wireless_dev
*wdev
, u32 nlportid
,
10000 int freq
, int sig_dbm
,
10001 const u8
*buf
, size_t len
, gfp_t gfp
)
10003 struct net_device
*netdev
= wdev
->netdev
;
10004 struct sk_buff
*msg
;
10007 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10011 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10017 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10018 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10019 netdev
->ifindex
)) ||
10020 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10021 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10023 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10024 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10025 goto nla_put_failure
;
10027 genlmsg_end(msg
, hdr
);
10029 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10032 genlmsg_cancel(msg
, hdr
);
10037 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10038 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10040 struct wiphy
*wiphy
= wdev
->wiphy
;
10041 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10042 struct net_device
*netdev
= wdev
->netdev
;
10043 struct sk_buff
*msg
;
10046 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10048 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10052 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10058 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10059 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10060 netdev
->ifindex
)) ||
10061 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10062 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10063 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10064 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10065 goto nla_put_failure
;
10067 genlmsg_end(msg
, hdr
);
10069 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10070 nl80211_mlme_mcgrp
.id
, gfp
);
10074 genlmsg_cancel(msg
, hdr
);
10077 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10079 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10080 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10083 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10084 struct wiphy
*wiphy
= wdev
->wiphy
;
10085 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10086 struct sk_buff
*msg
;
10087 struct nlattr
*pinfoattr
;
10090 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10092 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10096 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10102 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10103 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10104 goto nla_put_failure
;
10106 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10108 goto nla_put_failure
;
10110 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10112 goto nla_put_failure
;
10114 nla_nest_end(msg
, pinfoattr
);
10116 genlmsg_end(msg
, hdr
);
10118 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10119 nl80211_mlme_mcgrp
.id
, gfp
);
10123 genlmsg_cancel(msg
, hdr
);
10126 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10128 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10129 struct net_device
*netdev
, const u8
*bssid
,
10130 const u8
*replay_ctr
, gfp_t gfp
)
10132 struct sk_buff
*msg
;
10133 struct nlattr
*rekey_attr
;
10136 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10140 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10146 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10147 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10148 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10149 goto nla_put_failure
;
10151 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10153 goto nla_put_failure
;
10155 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10156 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10157 goto nla_put_failure
;
10159 nla_nest_end(msg
, rekey_attr
);
10161 genlmsg_end(msg
, hdr
);
10163 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10164 nl80211_mlme_mcgrp
.id
, gfp
);
10168 genlmsg_cancel(msg
, hdr
);
10172 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10173 const u8
*replay_ctr
, gfp_t gfp
)
10175 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10176 struct wiphy
*wiphy
= wdev
->wiphy
;
10177 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10179 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10180 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10182 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10185 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10186 struct net_device
*netdev
, int index
,
10187 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10189 struct sk_buff
*msg
;
10190 struct nlattr
*attr
;
10193 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10197 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10203 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10204 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10205 goto nla_put_failure
;
10207 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10209 goto nla_put_failure
;
10211 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10212 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10214 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10215 goto nla_put_failure
;
10217 nla_nest_end(msg
, attr
);
10219 genlmsg_end(msg
, hdr
);
10221 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10222 nl80211_mlme_mcgrp
.id
, gfp
);
10226 genlmsg_cancel(msg
, hdr
);
10230 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10231 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10233 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10234 struct wiphy
*wiphy
= wdev
->wiphy
;
10235 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10237 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10238 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10240 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10242 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10243 struct net_device
*netdev
,
10244 struct cfg80211_chan_def
*chandef
,
10247 struct sk_buff
*msg
;
10250 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10254 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10260 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10261 goto nla_put_failure
;
10263 if (nl80211_send_chandef(msg
, chandef
))
10264 goto nla_put_failure
;
10266 genlmsg_end(msg
, hdr
);
10268 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10269 nl80211_mlme_mcgrp
.id
, gfp
);
10273 genlmsg_cancel(msg
, hdr
);
10277 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10278 struct cfg80211_chan_def
*chandef
)
10280 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10281 struct wiphy
*wiphy
= wdev
->wiphy
;
10282 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10284 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10288 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10289 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10292 wdev
->channel
= chandef
->chan
;
10293 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10298 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10300 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10301 const u8
*peer
, u32 num_packets
,
10302 u32 rate
, u32 intvl
, gfp_t gfp
)
10304 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10305 struct wiphy
*wiphy
= wdev
->wiphy
;
10306 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10307 struct sk_buff
*msg
;
10308 struct nlattr
*pinfoattr
;
10311 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10315 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10321 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10322 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10323 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10324 goto nla_put_failure
;
10326 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10328 goto nla_put_failure
;
10330 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10331 goto nla_put_failure
;
10333 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10334 goto nla_put_failure
;
10336 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10337 goto nla_put_failure
;
10339 nla_nest_end(msg
, pinfoattr
);
10341 genlmsg_end(msg
, hdr
);
10343 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10344 nl80211_mlme_mcgrp
.id
, gfp
);
10348 genlmsg_cancel(msg
, hdr
);
10351 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10354 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10355 struct cfg80211_chan_def
*chandef
,
10356 enum nl80211_radar_event event
,
10357 struct net_device
*netdev
, gfp_t gfp
)
10359 struct sk_buff
*msg
;
10362 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10366 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10372 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10373 goto nla_put_failure
;
10375 /* NOP and radar events don't need a netdev parameter */
10377 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10379 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10380 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10381 goto nla_put_failure
;
10384 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10385 goto nla_put_failure
;
10387 if (nl80211_send_chandef(msg
, chandef
))
10388 goto nla_put_failure
;
10390 genlmsg_end(msg
, hdr
);
10392 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10393 nl80211_mlme_mcgrp
.id
, gfp
);
10397 genlmsg_cancel(msg
, hdr
);
10401 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10402 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10404 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10405 struct wiphy
*wiphy
= wdev
->wiphy
;
10406 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10407 struct sk_buff
*msg
;
10408 struct nlattr
*pinfoattr
;
10411 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10413 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10417 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10423 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10424 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10425 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10426 goto nla_put_failure
;
10428 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10430 goto nla_put_failure
;
10432 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10433 goto nla_put_failure
;
10435 nla_nest_end(msg
, pinfoattr
);
10437 genlmsg_end(msg
, hdr
);
10439 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10440 nl80211_mlme_mcgrp
.id
, gfp
);
10444 genlmsg_cancel(msg
, hdr
);
10447 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10449 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10450 u64 cookie
, bool acked
, gfp_t gfp
)
10452 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10453 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10454 struct sk_buff
*msg
;
10457 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10459 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10464 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10470 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10471 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10472 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10473 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10474 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10475 goto nla_put_failure
;
10477 genlmsg_end(msg
, hdr
);
10479 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10480 nl80211_mlme_mcgrp
.id
, gfp
);
10484 genlmsg_cancel(msg
, hdr
);
10487 EXPORT_SYMBOL(cfg80211_probe_status
);
10489 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10490 const u8
*frame
, size_t len
,
10491 int freq
, int sig_dbm
)
10493 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10494 struct sk_buff
*msg
;
10496 struct cfg80211_beacon_registration
*reg
;
10498 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10500 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10501 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10502 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10504 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10508 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10510 goto nla_put_failure
;
10512 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10514 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10516 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10517 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10518 goto nla_put_failure
;
10520 genlmsg_end(msg
, hdr
);
10522 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10524 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10528 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10530 genlmsg_cancel(msg
, hdr
);
10533 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10536 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10537 struct cfg80211_wowlan_wakeup
*wakeup
,
10540 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10541 struct sk_buff
*msg
;
10545 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10548 size
+= wakeup
->packet_present_len
;
10550 msg
= nlmsg_new(size
, gfp
);
10554 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10558 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10559 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10562 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10563 wdev
->netdev
->ifindex
))
10567 struct nlattr
*reasons
;
10569 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10571 if (wakeup
->disconnect
&&
10572 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10574 if (wakeup
->magic_pkt
&&
10575 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10577 if (wakeup
->gtk_rekey_failure
&&
10578 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10580 if (wakeup
->eap_identity_req
&&
10581 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10583 if (wakeup
->four_way_handshake
&&
10584 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10586 if (wakeup
->rfkill_release
&&
10587 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10590 if (wakeup
->pattern_idx
>= 0 &&
10591 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10592 wakeup
->pattern_idx
))
10595 if (wakeup
->tcp_match
)
10596 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10598 if (wakeup
->tcp_connlost
)
10600 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10602 if (wakeup
->tcp_nomoretokens
)
10604 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10606 if (wakeup
->packet
) {
10607 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10608 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10610 if (!wakeup
->packet_80211
) {
10612 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10614 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10617 if (wakeup
->packet_len
&&
10618 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10621 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10626 nla_nest_end(msg
, reasons
);
10629 genlmsg_end(msg
, hdr
);
10631 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10632 nl80211_mlme_mcgrp
.id
, gfp
);
10638 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10641 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10642 enum nl80211_tdls_operation oper
,
10643 u16 reason_code
, gfp_t gfp
)
10645 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10646 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10647 struct sk_buff
*msg
;
10650 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10653 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10657 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10663 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10664 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10665 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10666 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10667 (reason_code
> 0 &&
10668 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10669 goto nla_put_failure
;
10671 genlmsg_end(msg
, hdr
);
10673 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10674 nl80211_mlme_mcgrp
.id
, gfp
);
10678 genlmsg_cancel(msg
, hdr
);
10681 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10683 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10684 unsigned long state
,
10687 struct netlink_notify
*notify
= _notify
;
10688 struct cfg80211_registered_device
*rdev
;
10689 struct wireless_dev
*wdev
;
10690 struct cfg80211_beacon_registration
*reg
, *tmp
;
10692 if (state
!= NETLINK_URELEASE
)
10693 return NOTIFY_DONE
;
10697 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10698 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10699 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10701 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10702 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10704 if (reg
->nlportid
== notify
->portid
) {
10705 list_del(®
->list
);
10710 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10715 return NOTIFY_DONE
;
10718 static struct notifier_block nl80211_netlink_notifier
= {
10719 .notifier_call
= nl80211_netlink_notify
,
10722 void cfg80211_ft_event(struct net_device
*netdev
,
10723 struct cfg80211_ft_event_params
*ft_event
)
10725 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10726 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10727 struct sk_buff
*msg
;
10730 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10732 if (!ft_event
->target_ap
)
10735 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10739 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10745 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10746 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10747 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10749 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10750 if (ft_event
->ric_ies
)
10751 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10752 ft_event
->ric_ies
);
10754 genlmsg_end(msg
, hdr
);
10756 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10757 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10759 EXPORT_SYMBOL(cfg80211_ft_event
);
10761 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10763 struct cfg80211_registered_device
*rdev
;
10764 struct sk_buff
*msg
;
10768 rdev
= wiphy_to_dev(wdev
->wiphy
);
10769 if (!rdev
->crit_proto_nlportid
)
10772 nlportid
= rdev
->crit_proto_nlportid
;
10773 rdev
->crit_proto_nlportid
= 0;
10775 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10779 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10781 goto nla_put_failure
;
10783 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10784 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10785 goto nla_put_failure
;
10787 genlmsg_end(msg
, hdr
);
10789 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10794 genlmsg_cancel(msg
, hdr
);
10798 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10800 /* initialisation/exit functions */
10802 int nl80211_init(void)
10806 err
= genl_register_family_with_ops(&nl80211_fam
,
10807 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10811 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10815 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10819 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10823 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10827 #ifdef CONFIG_NL80211_TESTMODE
10828 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10833 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10839 genl_unregister_family(&nl80211_fam
);
10843 void nl80211_exit(void)
10845 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10846 genl_unregister_family(&nl80211_fam
);