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 if (!wdev
->current_bss
)
806 case NL80211_IFTYPE_STATION
:
807 case NL80211_IFTYPE_P2P_CLIENT
:
808 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
818 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
820 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
824 goto nla_put_failure
;
828 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
829 goto nla_put_failure
;
834 nla_nest_end(msg
, nl_modes
);
841 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
845 struct nlattr
*nl_combis
;
848 nl_combis
= nla_nest_start(msg
,
849 NL80211_ATTR_INTERFACE_COMBINATIONS
);
851 goto nla_put_failure
;
853 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
854 const struct ieee80211_iface_combination
*c
;
855 struct nlattr
*nl_combi
, *nl_limits
;
857 c
= &wiphy
->iface_combinations
[i
];
859 nl_combi
= nla_nest_start(msg
, i
+ 1);
861 goto nla_put_failure
;
863 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
865 goto nla_put_failure
;
867 for (j
= 0; j
< c
->n_limits
; j
++) {
868 struct nlattr
*nl_limit
;
870 nl_limit
= nla_nest_start(msg
, j
+ 1);
872 goto nla_put_failure
;
873 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
875 goto nla_put_failure
;
876 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
878 goto nla_put_failure
;
879 nla_nest_end(msg
, nl_limit
);
882 nla_nest_end(msg
, nl_limits
);
884 if (c
->beacon_int_infra_match
&&
885 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
886 goto nla_put_failure
;
887 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
888 c
->num_different_channels
) ||
889 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
891 goto nla_put_failure
;
893 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
894 c
->radar_detect_widths
))
895 goto nla_put_failure
;
897 nla_nest_end(msg
, nl_combi
);
900 nla_nest_end(msg
, nl_combis
);
908 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
911 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
.tcp
;
912 struct nlattr
*nl_tcp
;
917 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
921 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
922 tcp
->data_payload_max
))
925 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
926 tcp
->data_payload_max
))
929 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
932 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
933 sizeof(*tcp
->tok
), tcp
->tok
))
936 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
937 tcp
->data_interval_max
))
940 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
941 tcp
->wake_payload_max
))
944 nla_nest_end(msg
, nl_tcp
);
948 static int nl80211_send_wowlan(struct sk_buff
*msg
,
949 struct cfg80211_registered_device
*dev
,
952 struct nlattr
*nl_wowlan
;
954 if (!dev
->wiphy
.wowlan
.flags
&& !dev
->wiphy
.wowlan
.n_patterns
)
957 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
961 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
962 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
963 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
964 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
965 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
966 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
967 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
968 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
969 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
970 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
971 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
972 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
973 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
974 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
975 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
976 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
979 if (dev
->wiphy
.wowlan
.n_patterns
) {
980 struct nl80211_wowlan_pattern_support pat
= {
981 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
982 .min_pattern_len
= dev
->wiphy
.wowlan
.pattern_min_len
,
983 .max_pattern_len
= dev
->wiphy
.wowlan
.pattern_max_len
,
984 .max_pkt_offset
= dev
->wiphy
.wowlan
.max_pkt_offset
,
987 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
992 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
995 nla_nest_end(msg
, nl_wowlan
);
1001 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1002 struct ieee80211_supported_band
*sband
)
1004 struct nlattr
*nl_rates
, *nl_rate
;
1005 struct ieee80211_rate
*rate
;
1009 if (sband
->ht_cap
.ht_supported
&&
1010 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1011 sizeof(sband
->ht_cap
.mcs
),
1012 &sband
->ht_cap
.mcs
) ||
1013 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1014 sband
->ht_cap
.cap
) ||
1015 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1016 sband
->ht_cap
.ampdu_factor
) ||
1017 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1018 sband
->ht_cap
.ampdu_density
)))
1022 if (sband
->vht_cap
.vht_supported
&&
1023 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1024 sizeof(sband
->vht_cap
.vht_mcs
),
1025 &sband
->vht_cap
.vht_mcs
) ||
1026 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1027 sband
->vht_cap
.cap
)))
1031 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1035 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1036 nl_rate
= nla_nest_start(msg
, i
);
1040 rate
= &sband
->bitrates
[i
];
1041 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1044 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1046 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1049 nla_nest_end(msg
, nl_rate
);
1052 nla_nest_end(msg
, nl_rates
);
1058 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1059 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1062 struct nlattr
*nl_ftypes
, *nl_ifs
;
1063 enum nl80211_iftype ift
;
1069 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1073 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1074 nl_ftypes
= nla_nest_start(msg
, ift
);
1078 stypes
= mgmt_stypes
[ift
].tx
;
1081 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1082 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1087 nla_nest_end(msg
, nl_ftypes
);
1090 nla_nest_end(msg
, nl_ifs
);
1092 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1096 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1097 nl_ftypes
= nla_nest_start(msg
, ift
);
1101 stypes
= mgmt_stypes
[ift
].rx
;
1104 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1105 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1110 nla_nest_end(msg
, nl_ftypes
);
1112 nla_nest_end(msg
, nl_ifs
);
1117 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1118 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1119 int flags
, bool split
, long *split_start
,
1120 long *band_start
, long *chan_start
)
1123 struct nlattr
*nl_bands
, *nl_band
;
1124 struct nlattr
*nl_freqs
, *nl_freq
;
1125 struct nlattr
*nl_cmds
;
1126 enum ieee80211_band band
;
1127 struct ieee80211_channel
*chan
;
1129 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1130 dev
->wiphy
.mgmt_stypes
;
1131 long start
= 0, start_chan
= 0, start_band
= 0;
1134 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1138 /* allow always using the variables */
1140 split_start
= &start
;
1141 band_start
= &start_band
;
1142 chan_start
= &start_chan
;
1145 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1146 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1147 wiphy_name(&dev
->wiphy
)) ||
1148 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1149 cfg80211_rdev_list_generation
))
1150 goto nla_put_failure
;
1152 switch (*split_start
) {
1154 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1155 dev
->wiphy
.retry_short
) ||
1156 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1157 dev
->wiphy
.retry_long
) ||
1158 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1159 dev
->wiphy
.frag_threshold
) ||
1160 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1161 dev
->wiphy
.rts_threshold
) ||
1162 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1163 dev
->wiphy
.coverage_class
) ||
1164 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1165 dev
->wiphy
.max_scan_ssids
) ||
1166 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1167 dev
->wiphy
.max_sched_scan_ssids
) ||
1168 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1169 dev
->wiphy
.max_scan_ie_len
) ||
1170 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1171 dev
->wiphy
.max_sched_scan_ie_len
) ||
1172 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1173 dev
->wiphy
.max_match_sets
))
1174 goto nla_put_failure
;
1176 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1177 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1178 goto nla_put_failure
;
1179 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1180 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1181 goto nla_put_failure
;
1182 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1183 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1184 goto nla_put_failure
;
1185 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1186 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1187 goto nla_put_failure
;
1188 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1189 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1190 goto nla_put_failure
;
1191 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1192 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1193 goto nla_put_failure
;
1199 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1200 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1201 dev
->wiphy
.cipher_suites
))
1202 goto nla_put_failure
;
1204 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1205 dev
->wiphy
.max_num_pmkids
))
1206 goto nla_put_failure
;
1208 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1209 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1210 goto nla_put_failure
;
1212 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1213 dev
->wiphy
.available_antennas_tx
) ||
1214 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1215 dev
->wiphy
.available_antennas_rx
))
1216 goto nla_put_failure
;
1218 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1219 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1220 dev
->wiphy
.probe_resp_offload
))
1221 goto nla_put_failure
;
1223 if ((dev
->wiphy
.available_antennas_tx
||
1224 dev
->wiphy
.available_antennas_rx
) &&
1225 dev
->ops
->get_antenna
) {
1226 u32 tx_ant
= 0, rx_ant
= 0;
1228 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1230 if (nla_put_u32(msg
,
1231 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1234 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1236 goto nla_put_failure
;
1244 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1245 dev
->wiphy
.interface_modes
))
1246 goto nla_put_failure
;
1251 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1253 goto nla_put_failure
;
1255 for (band
= *band_start
; band
< IEEE80211_NUM_BANDS
; band
++) {
1256 struct ieee80211_supported_band
*sband
;
1258 sband
= dev
->wiphy
.bands
[band
];
1263 nl_band
= nla_nest_start(msg
, band
);
1265 goto nla_put_failure
;
1267 switch (*chan_start
) {
1269 if (nl80211_send_band_rateinfo(msg
, sband
))
1270 goto nla_put_failure
;
1275 /* add frequencies */
1276 nl_freqs
= nla_nest_start(
1277 msg
, NL80211_BAND_ATTR_FREQS
);
1279 goto nla_put_failure
;
1281 for (i
= *chan_start
- 1;
1282 i
< sband
->n_channels
;
1284 nl_freq
= nla_nest_start(msg
, i
);
1286 goto nla_put_failure
;
1288 chan
= &sband
->channels
[i
];
1290 if (nl80211_msg_put_channel(msg
, chan
,
1292 goto nla_put_failure
;
1294 nla_nest_end(msg
, nl_freq
);
1298 if (i
< sband
->n_channels
)
1299 *chan_start
= i
+ 2;
1302 nla_nest_end(msg
, nl_freqs
);
1305 nla_nest_end(msg
, nl_band
);
1308 /* start again here */
1314 nla_nest_end(msg
, nl_bands
);
1316 if (band
< IEEE80211_NUM_BANDS
)
1317 *band_start
= band
+ 1;
1321 /* if bands & channels are done, continue outside */
1322 if (*band_start
== 0 && *chan_start
== 0)
1327 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1329 goto nla_put_failure
;
1332 #define CMD(op, n) \
1334 if (dev->ops->op) { \
1336 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1337 goto nla_put_failure; \
1341 CMD(add_virtual_intf
, NEW_INTERFACE
);
1342 CMD(change_virtual_intf
, SET_INTERFACE
);
1343 CMD(add_key
, NEW_KEY
);
1344 CMD(start_ap
, START_AP
);
1345 CMD(add_station
, NEW_STATION
);
1346 CMD(add_mpath
, NEW_MPATH
);
1347 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1348 CMD(change_bss
, SET_BSS
);
1349 CMD(auth
, AUTHENTICATE
);
1350 CMD(assoc
, ASSOCIATE
);
1351 CMD(deauth
, DEAUTHENTICATE
);
1352 CMD(disassoc
, DISASSOCIATE
);
1353 CMD(join_ibss
, JOIN_IBSS
);
1354 CMD(join_mesh
, JOIN_MESH
);
1355 CMD(set_pmksa
, SET_PMKSA
);
1356 CMD(del_pmksa
, DEL_PMKSA
);
1357 CMD(flush_pmksa
, FLUSH_PMKSA
);
1358 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1359 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1360 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1361 CMD(mgmt_tx
, FRAME
);
1362 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1363 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1365 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1366 goto nla_put_failure
;
1368 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1369 dev
->ops
->join_mesh
) {
1371 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1372 goto nla_put_failure
;
1374 CMD(set_wds_peer
, SET_WDS_PEER
);
1375 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1376 CMD(tdls_mgmt
, TDLS_MGMT
);
1377 CMD(tdls_oper
, TDLS_OPER
);
1379 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1380 CMD(sched_scan_start
, START_SCHED_SCAN
);
1381 CMD(probe_client
, PROBE_CLIENT
);
1382 CMD(set_noack_map
, SET_NOACK_MAP
);
1383 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1385 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1386 goto nla_put_failure
;
1388 CMD(start_p2p_device
, START_P2P_DEVICE
);
1389 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1391 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1392 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1395 #ifdef CONFIG_NL80211_TESTMODE
1396 CMD(testmode_cmd
, TESTMODE
);
1401 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1403 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1404 goto nla_put_failure
;
1407 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1409 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1410 goto nla_put_failure
;
1413 nla_nest_end(msg
, nl_cmds
);
1418 if (dev
->ops
->remain_on_channel
&&
1419 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1421 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1422 dev
->wiphy
.max_remain_on_channel_duration
))
1423 goto nla_put_failure
;
1425 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1426 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1427 goto nla_put_failure
;
1429 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1430 goto nla_put_failure
;
1436 if (nl80211_send_wowlan(msg
, dev
, split
))
1437 goto nla_put_failure
;
1445 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1446 dev
->wiphy
.software_iftypes
))
1447 goto nla_put_failure
;
1449 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
, split
))
1450 goto nla_put_failure
;
1456 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1457 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1458 dev
->wiphy
.ap_sme_capa
))
1459 goto nla_put_failure
;
1461 features
= dev
->wiphy
.features
;
1463 * We can only add the per-channel limit information if the
1464 * dump is split, otherwise it makes it too big. Therefore
1465 * only advertise it in that case.
1468 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1469 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1470 goto nla_put_failure
;
1472 if (dev
->wiphy
.ht_capa_mod_mask
&&
1473 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1474 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1475 dev
->wiphy
.ht_capa_mod_mask
))
1476 goto nla_put_failure
;
1478 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1479 dev
->wiphy
.max_acl_mac_addrs
&&
1480 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1481 dev
->wiphy
.max_acl_mac_addrs
))
1482 goto nla_put_failure
;
1485 * Any information below this point is only available to
1486 * applications that can deal with it being split. This
1487 * helps ensure that newly added capabilities don't break
1488 * older tools by overrunning their buffers.
1490 * We still increment split_start so that in the split
1491 * case we'll continue with more data in the next round,
1492 * but break unconditionally so unsplit data stops here.
1497 if (dev
->wiphy
.extended_capabilities
&&
1498 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1499 dev
->wiphy
.extended_capabilities_len
,
1500 dev
->wiphy
.extended_capabilities
) ||
1501 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1502 dev
->wiphy
.extended_capabilities_len
,
1503 dev
->wiphy
.extended_capabilities_mask
)))
1504 goto nla_put_failure
;
1506 if (dev
->wiphy
.vht_capa_mod_mask
&&
1507 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1508 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1509 dev
->wiphy
.vht_capa_mod_mask
))
1510 goto nla_put_failure
;
1516 return genlmsg_end(msg
, hdr
);
1519 genlmsg_cancel(msg
, hdr
);
1523 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1526 int start
= cb
->args
[0];
1527 struct cfg80211_registered_device
*dev
;
1528 s64 filter_wiphy
= -1;
1533 /* will be zeroed in nlmsg_parse() */
1534 tb
= kmalloc(sizeof(*tb
) * (NL80211_ATTR_MAX
+ 1), GFP_KERNEL
);
1540 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1541 tb
, NL80211_ATTR_MAX
, nl80211_policy
);
1543 split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1544 if (tb
[NL80211_ATTR_WIPHY
])
1545 filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1546 if (tb
[NL80211_ATTR_WDEV
])
1547 filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1548 if (tb
[NL80211_ATTR_IFINDEX
]) {
1549 struct net_device
*netdev
;
1550 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1552 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1558 if (netdev
->ieee80211_ptr
) {
1560 netdev
->ieee80211_ptr
->wiphy
);
1561 filter_wiphy
= dev
->wiphy_idx
;
1568 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1569 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1573 if (filter_wiphy
!= -1 && dev
->wiphy_idx
!= filter_wiphy
)
1575 /* attempt to fit multiple wiphy data chunks into the skb */
1577 ret
= nl80211_send_wiphy(dev
, skb
,
1578 NETLINK_CB(cb
->skb
).portid
,
1581 split
, &cb
->args
[1],
1586 * If sending the wiphy data didn't fit (ENOBUFS
1587 * or EMSGSIZE returned), this SKB is still
1588 * empty (so it's not too big because another
1589 * wiphy dataset is already in the skb) and
1590 * we've not tried to adjust the dump allocation
1591 * yet ... then adjust the alloc size to be
1592 * bigger, and return 1 but with the empty skb.
1593 * This results in an empty message being RX'ed
1594 * in userspace, but that is ignored.
1596 * We can then retry with the larger buffer.
1598 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1600 cb
->min_dump_alloc
< 4096) {
1601 cb
->min_dump_alloc
= 4096;
1608 } while (cb
->args
[1] > 0);
1618 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1620 struct sk_buff
*msg
;
1621 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1623 msg
= nlmsg_new(4096, GFP_KERNEL
);
1627 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1628 false, NULL
, NULL
, NULL
) < 0) {
1633 return genlmsg_reply(msg
, info
);
1636 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1637 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1638 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1639 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1640 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1641 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1644 static int parse_txq_params(struct nlattr
*tb
[],
1645 struct ieee80211_txq_params
*txq_params
)
1647 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1648 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1649 !tb
[NL80211_TXQ_ATTR_AIFS
])
1652 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1653 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1654 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1655 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1656 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1658 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1664 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1667 * You can only set the channel explicitly for WDS interfaces,
1668 * all others have their channel managed via their respective
1669 * "establish a connection" command (connect, join, ...)
1671 * For AP/GO and mesh mode, the channel can be set with the
1672 * channel userspace API, but is only stored and passed to the
1673 * low-level driver when the AP starts or the mesh is joined.
1674 * This is for backward compatibility, userspace can also give
1675 * the channel in the start-ap or join-mesh commands instead.
1677 * Monitors are special as they are normally slaved to
1678 * whatever else is going on, so they have their own special
1679 * operation to set the monitor channel if possible.
1682 wdev
->iftype
== NL80211_IFTYPE_AP
||
1683 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1684 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1685 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1688 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1689 struct genl_info
*info
,
1690 struct cfg80211_chan_def
*chandef
)
1694 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1697 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1699 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1700 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1701 chandef
->center_freq1
= control_freq
;
1702 chandef
->center_freq2
= 0;
1704 /* Primary channel not allowed */
1705 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1708 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1709 enum nl80211_channel_type chantype
;
1711 chantype
= nla_get_u32(
1712 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1715 case NL80211_CHAN_NO_HT
:
1716 case NL80211_CHAN_HT20
:
1717 case NL80211_CHAN_HT40PLUS
:
1718 case NL80211_CHAN_HT40MINUS
:
1719 cfg80211_chandef_create(chandef
, chandef
->chan
,
1725 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1727 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1728 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1729 chandef
->center_freq1
=
1731 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1732 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1733 chandef
->center_freq2
=
1735 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1738 if (!cfg80211_chandef_valid(chandef
))
1741 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1742 IEEE80211_CHAN_DISABLED
))
1748 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1749 struct wireless_dev
*wdev
,
1750 struct genl_info
*info
)
1752 struct cfg80211_chan_def chandef
;
1754 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1757 iftype
= wdev
->iftype
;
1759 if (!nl80211_can_set_dev_channel(wdev
))
1762 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1767 case NL80211_IFTYPE_AP
:
1768 case NL80211_IFTYPE_P2P_GO
:
1769 if (wdev
->beacon_interval
) {
1773 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1777 wdev
->preset_chandef
= chandef
;
1780 case NL80211_IFTYPE_MESH_POINT
:
1781 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1783 case NL80211_IFTYPE_MONITOR
:
1784 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1793 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1795 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1796 struct net_device
*netdev
= info
->user_ptr
[1];
1798 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1801 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1803 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1804 struct net_device
*dev
= info
->user_ptr
[1];
1805 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1808 if (!info
->attrs
[NL80211_ATTR_MAC
])
1811 if (netif_running(dev
))
1814 if (!rdev
->ops
->set_wds_peer
)
1817 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1820 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1821 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1825 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1827 struct cfg80211_registered_device
*rdev
;
1828 struct net_device
*netdev
= NULL
;
1829 struct wireless_dev
*wdev
;
1830 int result
= 0, rem_txq_params
= 0;
1831 struct nlattr
*nl_txq_params
;
1833 u8 retry_short
= 0, retry_long
= 0;
1834 u32 frag_threshold
= 0, rts_threshold
= 0;
1835 u8 coverage_class
= 0;
1840 * Try to find the wiphy and netdev. Normally this
1841 * function shouldn't need the netdev, but this is
1842 * done for backward compatibility -- previously
1843 * setting the channel was done per wiphy, but now
1844 * it is per netdev. Previous userland like hostapd
1845 * also passed a netdev to set_wiphy, so that it is
1846 * possible to let that go to the right netdev!
1849 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1850 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1852 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1853 if (netdev
&& netdev
->ieee80211_ptr
)
1854 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1860 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1863 return PTR_ERR(rdev
);
1868 wdev
= netdev
->ieee80211_ptr
;
1871 * end workaround code, by now the rdev is available
1872 * and locked, and wdev may or may not be NULL.
1875 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1876 result
= cfg80211_dev_rename(
1877 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1882 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1883 struct ieee80211_txq_params txq_params
;
1884 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1886 if (!rdev
->ops
->set_txq_params
) {
1887 result
= -EOPNOTSUPP
;
1896 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1897 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1902 if (!netif_running(netdev
)) {
1907 nla_for_each_nested(nl_txq_params
,
1908 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1910 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1911 nla_data(nl_txq_params
),
1912 nla_len(nl_txq_params
),
1914 result
= parse_txq_params(tb
, &txq_params
);
1918 result
= rdev_set_txq_params(rdev
, netdev
,
1925 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1926 result
= __nl80211_set_channel(rdev
,
1927 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1933 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1934 struct wireless_dev
*txp_wdev
= wdev
;
1935 enum nl80211_tx_power_setting type
;
1938 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
1941 if (!rdev
->ops
->set_tx_power
) {
1942 result
= -EOPNOTSUPP
;
1946 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1947 type
= nla_get_u32(info
->attrs
[idx
]);
1949 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1950 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1955 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1956 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1957 mbm
= nla_get_u32(info
->attrs
[idx
]);
1960 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
1965 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1966 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1968 if ((!rdev
->wiphy
.available_antennas_tx
&&
1969 !rdev
->wiphy
.available_antennas_rx
) ||
1970 !rdev
->ops
->set_antenna
) {
1971 result
= -EOPNOTSUPP
;
1975 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1976 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1978 /* reject antenna configurations which don't match the
1979 * available antenna masks, except for the "all" mask */
1980 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1981 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1986 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1987 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1989 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
1996 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1997 retry_short
= nla_get_u8(
1998 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1999 if (retry_short
== 0) {
2003 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2006 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2007 retry_long
= nla_get_u8(
2008 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2009 if (retry_long
== 0) {
2013 changed
|= WIPHY_PARAM_RETRY_LONG
;
2016 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2017 frag_threshold
= nla_get_u32(
2018 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2019 if (frag_threshold
< 256) {
2023 if (frag_threshold
!= (u32
) -1) {
2025 * Fragments (apart from the last one) are required to
2026 * have even length. Make the fragmentation code
2027 * simpler by stripping LSB should someone try to use
2028 * odd threshold value.
2030 frag_threshold
&= ~0x1;
2032 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2035 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2036 rts_threshold
= nla_get_u32(
2037 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2038 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2041 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2042 coverage_class
= nla_get_u8(
2043 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2044 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2048 u8 old_retry_short
, old_retry_long
;
2049 u32 old_frag_threshold
, old_rts_threshold
;
2050 u8 old_coverage_class
;
2052 if (!rdev
->ops
->set_wiphy_params
) {
2053 result
= -EOPNOTSUPP
;
2057 old_retry_short
= rdev
->wiphy
.retry_short
;
2058 old_retry_long
= rdev
->wiphy
.retry_long
;
2059 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2060 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2061 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2063 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2064 rdev
->wiphy
.retry_short
= retry_short
;
2065 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2066 rdev
->wiphy
.retry_long
= retry_long
;
2067 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2068 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2069 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2070 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2071 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2072 rdev
->wiphy
.coverage_class
= coverage_class
;
2074 result
= rdev_set_wiphy_params(rdev
, changed
);
2076 rdev
->wiphy
.retry_short
= old_retry_short
;
2077 rdev
->wiphy
.retry_long
= old_retry_long
;
2078 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2079 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2080 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2090 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2092 return (u64
)wdev
->identifier
|
2093 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2096 static int nl80211_send_chandef(struct sk_buff
*msg
,
2097 struct cfg80211_chan_def
*chandef
)
2099 WARN_ON(!cfg80211_chandef_valid(chandef
));
2101 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2102 chandef
->chan
->center_freq
))
2104 switch (chandef
->width
) {
2105 case NL80211_CHAN_WIDTH_20_NOHT
:
2106 case NL80211_CHAN_WIDTH_20
:
2107 case NL80211_CHAN_WIDTH_40
:
2108 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2109 cfg80211_get_chandef_type(chandef
)))
2115 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2117 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2119 if (chandef
->center_freq2
&&
2120 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2125 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2126 struct cfg80211_registered_device
*rdev
,
2127 struct wireless_dev
*wdev
)
2129 struct net_device
*dev
= wdev
->netdev
;
2132 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2137 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2138 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2139 goto nla_put_failure
;
2141 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2142 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2143 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2144 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2145 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2146 rdev
->devlist_generation
^
2147 (cfg80211_rdev_list_generation
<< 2)))
2148 goto nla_put_failure
;
2150 if (rdev
->ops
->get_channel
) {
2152 struct cfg80211_chan_def chandef
;
2154 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2156 if (nl80211_send_chandef(msg
, &chandef
))
2157 goto nla_put_failure
;
2161 if (wdev
->ssid_len
) {
2162 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2163 goto nla_put_failure
;
2166 return genlmsg_end(msg
, hdr
);
2169 genlmsg_cancel(msg
, hdr
);
2173 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2177 int wp_start
= cb
->args
[0];
2178 int if_start
= cb
->args
[1];
2179 struct cfg80211_registered_device
*rdev
;
2180 struct wireless_dev
*wdev
;
2183 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2184 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2186 if (wp_idx
< wp_start
) {
2192 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2193 if (if_idx
< if_start
) {
2197 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2198 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2210 cb
->args
[0] = wp_idx
;
2211 cb
->args
[1] = if_idx
;
2216 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2218 struct sk_buff
*msg
;
2219 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2220 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2222 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2226 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2232 return genlmsg_reply(msg
, info
);
2235 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2236 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2237 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2238 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2239 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2240 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2241 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2244 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2246 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2254 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2255 nla
, mntr_flags_policy
))
2258 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2260 *mntrflags
|= (1<<flag
);
2265 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2266 struct net_device
*netdev
, u8 use_4addr
,
2267 enum nl80211_iftype iftype
)
2270 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2276 case NL80211_IFTYPE_AP_VLAN
:
2277 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2280 case NL80211_IFTYPE_STATION
:
2281 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2291 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2293 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2294 struct vif_params params
;
2296 enum nl80211_iftype otype
, ntype
;
2297 struct net_device
*dev
= info
->user_ptr
[1];
2298 u32 _flags
, *flags
= NULL
;
2299 bool change
= false;
2301 memset(¶ms
, 0, sizeof(params
));
2303 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2305 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2306 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2309 if (ntype
> NL80211_IFTYPE_MAX
)
2313 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2314 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2316 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2318 if (netif_running(dev
))
2322 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2323 IEEE80211_MAX_MESH_ID_LEN
);
2324 wdev
->mesh_id_up_len
=
2325 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2326 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2327 wdev
->mesh_id_up_len
);
2331 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2332 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2334 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2338 params
.use_4addr
= -1;
2341 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2342 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2344 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2353 if (flags
&& (*flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2354 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2358 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2362 if (!err
&& params
.use_4addr
!= -1)
2363 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2368 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2370 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2371 struct vif_params params
;
2372 struct wireless_dev
*wdev
;
2373 struct sk_buff
*msg
;
2375 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2378 memset(¶ms
, 0, sizeof(params
));
2380 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2383 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2384 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2385 if (type
> NL80211_IFTYPE_MAX
)
2389 if (!rdev
->ops
->add_virtual_intf
||
2390 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2393 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2394 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2396 if (!is_valid_ether_addr(params
.macaddr
))
2397 return -EADDRNOTAVAIL
;
2400 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2401 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2402 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2407 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2411 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2412 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2415 if (!err
&& (flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2416 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2419 wdev
= rdev_add_virtual_intf(rdev
,
2420 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2421 type
, err
? NULL
: &flags
, ¶ms
);
2424 return PTR_ERR(wdev
);
2428 case NL80211_IFTYPE_MESH_POINT
:
2429 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2432 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2433 IEEE80211_MAX_MESH_ID_LEN
);
2434 wdev
->mesh_id_up_len
=
2435 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2436 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2437 wdev
->mesh_id_up_len
);
2440 case NL80211_IFTYPE_P2P_DEVICE
:
2442 * P2P Device doesn't have a netdev, so doesn't go
2443 * through the netdev notifier and must be added here
2445 mutex_init(&wdev
->mtx
);
2446 INIT_LIST_HEAD(&wdev
->event_list
);
2447 spin_lock_init(&wdev
->event_lock
);
2448 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2449 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2451 wdev
->identifier
= ++rdev
->wdev_id
;
2452 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2453 rdev
->devlist_generation
++;
2459 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2465 return genlmsg_reply(msg
, info
);
2468 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2470 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2471 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2473 if (!rdev
->ops
->del_virtual_intf
)
2477 * If we remove a wireless device without a netdev then clear
2478 * user_ptr[1] so that nl80211_post_doit won't dereference it
2479 * to check if it needs to do dev_put(). Otherwise it crashes
2480 * since the wdev has been freed, unlike with a netdev where
2481 * we need the dev_put() for the netdev to really be freed.
2484 info
->user_ptr
[1] = NULL
;
2486 return rdev_del_virtual_intf(rdev
, wdev
);
2489 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2491 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2492 struct net_device
*dev
= info
->user_ptr
[1];
2495 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2498 if (!rdev
->ops
->set_noack_map
)
2501 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2503 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2506 struct get_key_cookie
{
2507 struct sk_buff
*msg
;
2512 static void get_key_callback(void *c
, struct key_params
*params
)
2515 struct get_key_cookie
*cookie
= c
;
2518 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2519 params
->key_len
, params
->key
)) ||
2521 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2522 params
->seq_len
, params
->seq
)) ||
2524 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2526 goto nla_put_failure
;
2528 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2530 goto nla_put_failure
;
2533 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2534 params
->key_len
, params
->key
)) ||
2536 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2537 params
->seq_len
, params
->seq
)) ||
2539 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2541 goto nla_put_failure
;
2543 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2544 goto nla_put_failure
;
2546 nla_nest_end(cookie
->msg
, key
);
2553 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2555 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2557 struct net_device
*dev
= info
->user_ptr
[1];
2559 const u8
*mac_addr
= NULL
;
2561 struct get_key_cookie cookie
= {
2565 struct sk_buff
*msg
;
2567 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2568 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2573 if (info
->attrs
[NL80211_ATTR_MAC
])
2574 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2576 pairwise
= !!mac_addr
;
2577 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2578 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2579 if (kt
>= NUM_NL80211_KEYTYPES
)
2581 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2582 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2584 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2587 if (!rdev
->ops
->get_key
)
2590 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2594 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2595 NL80211_CMD_NEW_KEY
);
2597 return PTR_ERR(hdr
);
2600 cookie
.idx
= key_idx
;
2602 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2603 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2604 goto nla_put_failure
;
2606 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2607 goto nla_put_failure
;
2609 if (pairwise
&& mac_addr
&&
2610 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2613 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2620 goto nla_put_failure
;
2622 genlmsg_end(msg
, hdr
);
2623 return genlmsg_reply(msg
, info
);
2632 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2634 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2635 struct key_parse key
;
2637 struct net_device
*dev
= info
->user_ptr
[1];
2639 err
= nl80211_parse_key(info
, &key
);
2646 /* only support setting default key */
2647 if (!key
.def
&& !key
.defmgmt
)
2650 wdev_lock(dev
->ieee80211_ptr
);
2653 if (!rdev
->ops
->set_default_key
) {
2658 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2662 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2663 key
.def_uni
, key
.def_multi
);
2668 #ifdef CONFIG_CFG80211_WEXT
2669 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2672 if (key
.def_uni
|| !key
.def_multi
) {
2677 if (!rdev
->ops
->set_default_mgmt_key
) {
2682 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2686 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2690 #ifdef CONFIG_CFG80211_WEXT
2691 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2696 wdev_unlock(dev
->ieee80211_ptr
);
2701 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2703 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2705 struct net_device
*dev
= info
->user_ptr
[1];
2706 struct key_parse key
;
2707 const u8
*mac_addr
= NULL
;
2709 err
= nl80211_parse_key(info
, &key
);
2716 if (info
->attrs
[NL80211_ATTR_MAC
])
2717 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2719 if (key
.type
== -1) {
2721 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2723 key
.type
= NL80211_KEYTYPE_GROUP
;
2727 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2728 key
.type
!= NL80211_KEYTYPE_GROUP
)
2731 if (!rdev
->ops
->add_key
)
2734 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2735 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2739 wdev_lock(dev
->ieee80211_ptr
);
2740 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2742 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2743 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2745 wdev_unlock(dev
->ieee80211_ptr
);
2750 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2752 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2754 struct net_device
*dev
= info
->user_ptr
[1];
2755 u8
*mac_addr
= NULL
;
2756 struct key_parse key
;
2758 err
= nl80211_parse_key(info
, &key
);
2762 if (info
->attrs
[NL80211_ATTR_MAC
])
2763 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2765 if (key
.type
== -1) {
2767 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2769 key
.type
= NL80211_KEYTYPE_GROUP
;
2773 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2774 key
.type
!= NL80211_KEYTYPE_GROUP
)
2777 if (!rdev
->ops
->del_key
)
2780 wdev_lock(dev
->ieee80211_ptr
);
2781 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2783 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2784 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2788 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2789 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2792 #ifdef CONFIG_CFG80211_WEXT
2794 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2795 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2796 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2797 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2800 wdev_unlock(dev
->ieee80211_ptr
);
2805 /* This function returns an error or the number of nested attributes */
2806 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2808 struct nlattr
*attr
;
2809 int n_entries
= 0, tmp
;
2811 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2812 if (nla_len(attr
) != ETH_ALEN
)
2822 * This function parses ACL information and allocates memory for ACL data.
2823 * On successful return, the calling function is responsible to free the
2824 * ACL buffer returned by this function.
2826 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2827 struct genl_info
*info
)
2829 enum nl80211_acl_policy acl_policy
;
2830 struct nlattr
*attr
;
2831 struct cfg80211_acl_data
*acl
;
2832 int i
= 0, n_entries
, tmp
;
2834 if (!wiphy
->max_acl_mac_addrs
)
2835 return ERR_PTR(-EOPNOTSUPP
);
2837 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2838 return ERR_PTR(-EINVAL
);
2840 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2841 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2842 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2843 return ERR_PTR(-EINVAL
);
2845 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2846 return ERR_PTR(-EINVAL
);
2848 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2850 return ERR_PTR(n_entries
);
2852 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2853 return ERR_PTR(-ENOTSUPP
);
2855 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2858 return ERR_PTR(-ENOMEM
);
2860 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2861 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2865 acl
->n_acl_entries
= n_entries
;
2866 acl
->acl_policy
= acl_policy
;
2871 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2873 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2874 struct net_device
*dev
= info
->user_ptr
[1];
2875 struct cfg80211_acl_data
*acl
;
2878 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2879 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2882 if (!dev
->ieee80211_ptr
->beacon_interval
)
2885 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2887 return PTR_ERR(acl
);
2889 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2896 static int nl80211_parse_beacon(struct genl_info
*info
,
2897 struct cfg80211_beacon_data
*bcn
)
2899 bool haveinfo
= false;
2901 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2902 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2903 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2904 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2907 memset(bcn
, 0, sizeof(*bcn
));
2909 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2910 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2911 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2917 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2918 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2920 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2927 if (info
->attrs
[NL80211_ATTR_IE
]) {
2928 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2929 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2932 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2933 bcn
->proberesp_ies
=
2934 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2935 bcn
->proberesp_ies_len
=
2936 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2939 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2940 bcn
->assocresp_ies
=
2941 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2942 bcn
->assocresp_ies_len
=
2943 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2946 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2948 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2949 bcn
->probe_resp_len
=
2950 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2956 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2957 struct cfg80211_ap_settings
*params
)
2959 struct wireless_dev
*wdev
;
2962 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2963 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2964 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2967 if (!wdev
->preset_chandef
.chan
)
2970 params
->chandef
= wdev
->preset_chandef
;
2978 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
2979 enum nl80211_auth_type auth_type
,
2980 enum nl80211_commands cmd
)
2982 if (auth_type
> NL80211_AUTHTYPE_MAX
)
2986 case NL80211_CMD_AUTHENTICATE
:
2987 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
2988 auth_type
== NL80211_AUTHTYPE_SAE
)
2991 case NL80211_CMD_CONNECT
:
2992 case NL80211_CMD_START_AP
:
2993 /* SAE not supported yet */
2994 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3002 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3004 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3005 struct net_device
*dev
= info
->user_ptr
[1];
3006 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3007 struct cfg80211_ap_settings params
;
3009 u8 radar_detect_width
= 0;
3011 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3012 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3015 if (!rdev
->ops
->start_ap
)
3018 if (wdev
->beacon_interval
)
3021 memset(¶ms
, 0, sizeof(params
));
3023 /* these are required for START_AP */
3024 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3025 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3026 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3029 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
3033 params
.beacon_interval
=
3034 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3035 params
.dtim_period
=
3036 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3038 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3043 * In theory, some of these attributes should be required here
3044 * but since they were not used when the command was originally
3045 * added, keep them optional for old user space programs to let
3046 * them continue to work with drivers that do not need the
3047 * additional information -- drivers must check!
3049 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3050 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3052 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3053 if (params
.ssid_len
== 0 ||
3054 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3058 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3059 params
.hidden_ssid
= nla_get_u32(
3060 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3061 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3062 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3063 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3067 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3069 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3070 params
.auth_type
= nla_get_u32(
3071 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3072 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3073 NL80211_CMD_START_AP
))
3076 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3078 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3079 NL80211_MAX_NR_CIPHER_SUITES
);
3083 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3084 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3086 params
.inactivity_timeout
= nla_get_u16(
3087 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3090 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3091 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3093 params
.p2p_ctwindow
=
3094 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3095 if (params
.p2p_ctwindow
> 127)
3097 if (params
.p2p_ctwindow
!= 0 &&
3098 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3102 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3105 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3107 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3110 params
.p2p_opp_ps
= tmp
;
3111 if (params
.p2p_opp_ps
!= 0 &&
3112 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3116 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3117 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3120 } else if (wdev
->preset_chandef
.chan
) {
3121 params
.chandef
= wdev
->preset_chandef
;
3122 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3125 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3128 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3132 radar_detect_width
= BIT(params
.chandef
.width
);
3133 params
.radar_required
= true;
3136 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3137 params
.chandef
.chan
,
3139 radar_detect_width
);
3143 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3144 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3145 if (IS_ERR(params
.acl
))
3146 return PTR_ERR(params
.acl
);
3149 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3151 wdev
->preset_chandef
= params
.chandef
;
3152 wdev
->beacon_interval
= params
.beacon_interval
;
3153 wdev
->channel
= params
.chandef
.chan
;
3154 wdev
->ssid_len
= params
.ssid_len
;
3155 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3163 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3165 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3166 struct net_device
*dev
= info
->user_ptr
[1];
3167 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3168 struct cfg80211_beacon_data params
;
3171 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3172 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3175 if (!rdev
->ops
->change_beacon
)
3178 if (!wdev
->beacon_interval
)
3181 err
= nl80211_parse_beacon(info
, ¶ms
);
3185 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3188 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3190 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3191 struct net_device
*dev
= info
->user_ptr
[1];
3193 return cfg80211_stop_ap(rdev
, dev
);
3196 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3197 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3198 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3199 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3200 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3201 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3202 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3205 static int parse_station_flags(struct genl_info
*info
,
3206 enum nl80211_iftype iftype
,
3207 struct station_parameters
*params
)
3209 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3214 * Try parsing the new attribute first so userspace
3215 * can specify both for older kernels.
3217 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3219 struct nl80211_sta_flag_update
*sta_flags
;
3221 sta_flags
= nla_data(nla
);
3222 params
->sta_flags_mask
= sta_flags
->mask
;
3223 params
->sta_flags_set
= sta_flags
->set
;
3224 params
->sta_flags_set
&= params
->sta_flags_mask
;
3225 if ((params
->sta_flags_mask
|
3226 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3231 /* if present, parse the old attribute */
3233 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3237 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3238 nla
, sta_flags_policy
))
3242 * Only allow certain flags for interface types so that
3243 * other attributes are silently ignored. Remember that
3244 * this is backward compatibility code with old userspace
3245 * and shouldn't be hit in other cases anyway.
3248 case NL80211_IFTYPE_AP
:
3249 case NL80211_IFTYPE_AP_VLAN
:
3250 case NL80211_IFTYPE_P2P_GO
:
3251 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3252 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3253 BIT(NL80211_STA_FLAG_WME
) |
3254 BIT(NL80211_STA_FLAG_MFP
);
3256 case NL80211_IFTYPE_P2P_CLIENT
:
3257 case NL80211_IFTYPE_STATION
:
3258 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3259 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3261 case NL80211_IFTYPE_MESH_POINT
:
3262 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3263 BIT(NL80211_STA_FLAG_MFP
) |
3264 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3269 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3271 params
->sta_flags_set
|= (1<<flag
);
3273 /* no longer support new API additions in old API */
3274 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3282 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3285 struct nlattr
*rate
;
3289 rate
= nla_nest_start(msg
, attr
);
3293 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3294 bitrate
= cfg80211_calculate_bitrate(info
);
3295 /* report 16-bit bitrate only if we can */
3296 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3298 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3300 if (bitrate_compat
> 0 &&
3301 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3304 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3305 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3307 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3308 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3310 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3311 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3313 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3314 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3316 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3318 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3319 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3321 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3322 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3324 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3325 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3327 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3328 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3330 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3331 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3335 nla_nest_end(msg
, rate
);
3339 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3348 attr
= nla_nest_start(msg
, id
);
3352 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3353 if (!(mask
& BIT(i
)))
3356 if (nla_put_u8(msg
, i
, signal
[i
]))
3360 nla_nest_end(msg
, attr
);
3365 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3367 struct cfg80211_registered_device
*rdev
,
3368 struct net_device
*dev
,
3369 const u8
*mac_addr
, struct station_info
*sinfo
)
3372 struct nlattr
*sinfoattr
, *bss_param
;
3374 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3378 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3379 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3380 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3381 goto nla_put_failure
;
3383 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3385 goto nla_put_failure
;
3386 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3387 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3388 sinfo
->connected_time
))
3389 goto nla_put_failure
;
3390 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3391 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3392 sinfo
->inactive_time
))
3393 goto nla_put_failure
;
3394 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3395 STATION_INFO_RX_BYTES64
)) &&
3396 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3397 (u32
)sinfo
->rx_bytes
))
3398 goto nla_put_failure
;
3399 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3400 STATION_INFO_TX_BYTES64
)) &&
3401 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3402 (u32
)sinfo
->tx_bytes
))
3403 goto nla_put_failure
;
3404 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3405 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3407 goto nla_put_failure
;
3408 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3409 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3411 goto nla_put_failure
;
3412 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3413 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3414 goto nla_put_failure
;
3415 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3416 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3417 goto nla_put_failure
;
3418 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3419 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3420 sinfo
->plink_state
))
3421 goto nla_put_failure
;
3422 switch (rdev
->wiphy
.signal_type
) {
3423 case CFG80211_SIGNAL_TYPE_MBM
:
3424 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3425 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3427 goto nla_put_failure
;
3428 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3429 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3431 goto nla_put_failure
;
3436 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL
) {
3437 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3438 sinfo
->chain_signal
,
3439 NL80211_STA_INFO_CHAIN_SIGNAL
))
3440 goto nla_put_failure
;
3442 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL_AVG
) {
3443 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3444 sinfo
->chain_signal_avg
,
3445 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3446 goto nla_put_failure
;
3448 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3449 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3450 NL80211_STA_INFO_TX_BITRATE
))
3451 goto nla_put_failure
;
3453 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3454 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3455 NL80211_STA_INFO_RX_BITRATE
))
3456 goto nla_put_failure
;
3458 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3459 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3461 goto nla_put_failure
;
3462 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3463 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3465 goto nla_put_failure
;
3466 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3467 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3469 goto nla_put_failure
;
3470 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3471 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3473 goto nla_put_failure
;
3474 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3475 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3476 sinfo
->beacon_loss_count
))
3477 goto nla_put_failure
;
3478 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3479 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3481 goto nla_put_failure
;
3482 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3483 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3485 goto nla_put_failure
;
3486 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3487 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3489 goto nla_put_failure
;
3490 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3491 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3493 goto nla_put_failure
;
3495 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3496 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3497 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3498 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3499 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3500 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3501 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3502 sinfo
->bss_param
.dtim_period
) ||
3503 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3504 sinfo
->bss_param
.beacon_interval
))
3505 goto nla_put_failure
;
3507 nla_nest_end(msg
, bss_param
);
3509 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3510 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3511 sizeof(struct nl80211_sta_flag_update
),
3513 goto nla_put_failure
;
3514 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3515 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3517 goto nla_put_failure
;
3518 nla_nest_end(msg
, sinfoattr
);
3520 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3521 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3522 sinfo
->assoc_req_ies
))
3523 goto nla_put_failure
;
3525 return genlmsg_end(msg
, hdr
);
3528 genlmsg_cancel(msg
, hdr
);
3532 static int nl80211_dump_station(struct sk_buff
*skb
,
3533 struct netlink_callback
*cb
)
3535 struct station_info sinfo
;
3536 struct cfg80211_registered_device
*dev
;
3537 struct wireless_dev
*wdev
;
3538 u8 mac_addr
[ETH_ALEN
];
3539 int sta_idx
= cb
->args
[2];
3542 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3546 if (!wdev
->netdev
) {
3551 if (!dev
->ops
->dump_station
) {
3557 memset(&sinfo
, 0, sizeof(sinfo
));
3558 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3565 if (nl80211_send_station(skb
,
3566 NETLINK_CB(cb
->skb
).portid
,
3567 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3568 dev
, wdev
->netdev
, mac_addr
,
3577 cb
->args
[2] = sta_idx
;
3580 nl80211_finish_wdev_dump(dev
);
3585 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3587 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3588 struct net_device
*dev
= info
->user_ptr
[1];
3589 struct station_info sinfo
;
3590 struct sk_buff
*msg
;
3591 u8
*mac_addr
= NULL
;
3594 memset(&sinfo
, 0, sizeof(sinfo
));
3596 if (!info
->attrs
[NL80211_ATTR_MAC
])
3599 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3601 if (!rdev
->ops
->get_station
)
3604 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3608 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3612 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3613 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3618 return genlmsg_reply(msg
, info
);
3621 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3622 struct station_parameters
*params
,
3623 enum cfg80211_station_type statype
)
3625 if (params
->listen_interval
!= -1)
3630 /* When you run into this, adjust the code below for the new flag */
3631 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3634 case CFG80211_STA_MESH_PEER_KERNEL
:
3635 case CFG80211_STA_MESH_PEER_USER
:
3637 * No ignoring the TDLS flag here -- the userspace mesh
3638 * code doesn't have the bug of including TDLS in the
3641 if (params
->sta_flags_mask
&
3642 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3643 BIT(NL80211_STA_FLAG_MFP
) |
3644 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3647 case CFG80211_STA_TDLS_PEER_SETUP
:
3648 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3649 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3651 /* ignore since it can't change */
3652 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3655 /* disallow mesh-specific things */
3656 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3658 if (params
->local_pm
)
3660 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3664 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3665 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3666 /* TDLS can't be set, ... */
3667 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3670 * ... but don't bother the driver with it. This works around
3671 * a hostapd/wpa_supplicant issue -- it always includes the
3672 * TLDS_PEER flag in the mask even for AP mode.
3674 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3677 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3678 /* reject other things that can't change */
3679 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3681 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3683 if (params
->supported_rates
)
3685 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3689 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3695 case CFG80211_STA_AP_MLME_CLIENT
:
3696 /* Use this only for authorizing/unauthorizing a station */
3697 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3700 case CFG80211_STA_AP_CLIENT
:
3701 /* accept only the listed bits */
3702 if (params
->sta_flags_mask
&
3703 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3704 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3705 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3706 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3707 BIT(NL80211_STA_FLAG_WME
) |
3708 BIT(NL80211_STA_FLAG_MFP
)))
3711 /* but authenticated/associated only if driver handles it */
3712 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3713 params
->sta_flags_mask
&
3714 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3715 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3718 case CFG80211_STA_IBSS
:
3719 case CFG80211_STA_AP_STA
:
3720 /* reject any changes other than AUTHORIZED */
3721 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3724 case CFG80211_STA_TDLS_PEER_SETUP
:
3725 /* reject any changes other than AUTHORIZED or WME */
3726 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3727 BIT(NL80211_STA_FLAG_WME
)))
3729 /* force (at least) rates when authorizing */
3730 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3731 !params
->supported_rates
)
3734 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3735 /* reject any changes */
3737 case CFG80211_STA_MESH_PEER_KERNEL
:
3738 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3741 case CFG80211_STA_MESH_PEER_USER
:
3742 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3749 EXPORT_SYMBOL(cfg80211_check_station_change
);
3752 * Get vlan interface making sure it is running and on the right wiphy.
3754 static struct net_device
*get_vlan(struct genl_info
*info
,
3755 struct cfg80211_registered_device
*rdev
)
3757 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3758 struct net_device
*v
;
3764 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3766 return ERR_PTR(-ENODEV
);
3768 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3773 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3774 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3775 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3780 if (!netif_running(v
)) {
3788 return ERR_PTR(ret
);
3791 static struct nla_policy
3792 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3793 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3794 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3797 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3798 struct station_parameters
*params
)
3800 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3804 /* parse WME attributes if present */
3805 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3808 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3809 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3810 nl80211_sta_wme_policy
);
3814 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3815 params
->uapsd_queues
= nla_get_u8(
3816 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3817 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3820 if (tb
[NL80211_STA_WME_MAX_SP
])
3821 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3823 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3826 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3831 static int nl80211_set_station_tdls(struct genl_info
*info
,
3832 struct station_parameters
*params
)
3834 /* Dummy STA entry gets updated once the peer capabilities are known */
3835 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
3836 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
3837 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3839 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3840 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3842 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3844 return nl80211_parse_sta_wme(info
, params
);
3847 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3849 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3850 struct net_device
*dev
= info
->user_ptr
[1];
3851 struct station_parameters params
;
3855 memset(¶ms
, 0, sizeof(params
));
3857 params
.listen_interval
= -1;
3859 if (!rdev
->ops
->change_station
)
3862 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3865 if (!info
->attrs
[NL80211_ATTR_MAC
])
3868 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3870 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3871 params
.supported_rates
=
3872 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3873 params
.supported_rates_len
=
3874 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3877 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3879 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3880 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3883 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3885 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3886 params
.ext_capab_len
=
3887 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3890 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3893 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3896 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3897 params
.plink_action
=
3898 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3899 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3903 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3904 params
.plink_state
=
3905 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3906 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3908 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3911 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3912 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3913 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3915 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3916 pm
> NL80211_MESH_POWER_MAX
)
3919 params
.local_pm
= pm
;
3922 /* Include parameters for TDLS peer (will check later) */
3923 err
= nl80211_set_station_tdls(info
, ¶ms
);
3927 params
.vlan
= get_vlan(info
, rdev
);
3928 if (IS_ERR(params
.vlan
))
3929 return PTR_ERR(params
.vlan
);
3931 switch (dev
->ieee80211_ptr
->iftype
) {
3932 case NL80211_IFTYPE_AP
:
3933 case NL80211_IFTYPE_AP_VLAN
:
3934 case NL80211_IFTYPE_P2P_GO
:
3935 case NL80211_IFTYPE_P2P_CLIENT
:
3936 case NL80211_IFTYPE_STATION
:
3937 case NL80211_IFTYPE_ADHOC
:
3938 case NL80211_IFTYPE_MESH_POINT
:
3945 /* driver will call cfg80211_check_station_change() */
3946 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3950 dev_put(params
.vlan
);
3955 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3957 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3959 struct net_device
*dev
= info
->user_ptr
[1];
3960 struct station_parameters params
;
3961 u8
*mac_addr
= NULL
;
3963 memset(¶ms
, 0, sizeof(params
));
3965 if (!rdev
->ops
->add_station
)
3968 if (!info
->attrs
[NL80211_ATTR_MAC
])
3971 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3974 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3977 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
3978 !info
->attrs
[NL80211_ATTR_PEER_AID
])
3981 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3982 params
.supported_rates
=
3983 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3984 params
.supported_rates_len
=
3985 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3986 params
.listen_interval
=
3987 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3989 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3990 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3992 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
3993 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3996 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3998 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3999 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4002 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4004 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4005 params
.ext_capab_len
=
4006 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4009 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4011 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4013 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4015 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4017 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4018 params
.plink_action
=
4019 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4020 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4024 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4028 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4031 /* When you run into this, adjust the code below for the new flag */
4032 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4034 switch (dev
->ieee80211_ptr
->iftype
) {
4035 case NL80211_IFTYPE_AP
:
4036 case NL80211_IFTYPE_AP_VLAN
:
4037 case NL80211_IFTYPE_P2P_GO
:
4038 /* ignore WME attributes if iface/sta is not capable */
4039 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4040 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4041 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4043 /* TDLS peers cannot be added */
4044 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4046 /* but don't bother the driver with it */
4047 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4049 /* allow authenticated/associated only if driver handles it */
4050 if (!(rdev
->wiphy
.features
&
4051 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4052 params
.sta_flags_mask
&
4053 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4054 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4057 /* must be last in here for error handling */
4058 params
.vlan
= get_vlan(info
, rdev
);
4059 if (IS_ERR(params
.vlan
))
4060 return PTR_ERR(params
.vlan
);
4062 case NL80211_IFTYPE_MESH_POINT
:
4063 /* ignore uAPSD data */
4064 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4066 /* associated is disallowed */
4067 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4069 /* TDLS peers cannot be added */
4070 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
4073 case NL80211_IFTYPE_STATION
:
4074 case NL80211_IFTYPE_P2P_CLIENT
:
4075 /* ignore uAPSD data */
4076 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4078 /* these are disallowed */
4079 if (params
.sta_flags_mask
&
4080 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4081 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4083 /* Only TDLS peers can be added */
4084 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4086 /* Can only add if TDLS ... */
4087 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4089 /* ... with external setup is supported */
4090 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4093 * Older wpa_supplicant versions always mark the TDLS peer
4094 * as authorized, but it shouldn't yet be.
4096 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4102 /* be aware of params.vlan when changing code here */
4104 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4107 dev_put(params
.vlan
);
4111 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4113 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4114 struct net_device
*dev
= info
->user_ptr
[1];
4115 u8
*mac_addr
= NULL
;
4117 if (info
->attrs
[NL80211_ATTR_MAC
])
4118 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4120 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4121 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4122 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4123 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4126 if (!rdev
->ops
->del_station
)
4129 return rdev_del_station(rdev
, dev
, mac_addr
);
4132 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4133 int flags
, struct net_device
*dev
,
4134 u8
*dst
, u8
*next_hop
,
4135 struct mpath_info
*pinfo
)
4138 struct nlattr
*pinfoattr
;
4140 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4144 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4145 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4146 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4147 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4148 goto nla_put_failure
;
4150 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4152 goto nla_put_failure
;
4153 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4154 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4156 goto nla_put_failure
;
4157 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4158 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4159 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4160 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4162 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4163 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4165 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4166 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4168 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4169 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4170 pinfo
->discovery_timeout
)) ||
4171 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4172 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4173 pinfo
->discovery_retries
)))
4174 goto nla_put_failure
;
4176 nla_nest_end(msg
, pinfoattr
);
4178 return genlmsg_end(msg
, hdr
);
4181 genlmsg_cancel(msg
, hdr
);
4185 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4186 struct netlink_callback
*cb
)
4188 struct mpath_info pinfo
;
4189 struct cfg80211_registered_device
*dev
;
4190 struct wireless_dev
*wdev
;
4192 u8 next_hop
[ETH_ALEN
];
4193 int path_idx
= cb
->args
[2];
4196 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4200 if (!dev
->ops
->dump_mpath
) {
4205 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4211 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4218 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4219 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4220 wdev
->netdev
, dst
, next_hop
,
4229 cb
->args
[2] = path_idx
;
4232 nl80211_finish_wdev_dump(dev
);
4236 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4238 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4240 struct net_device
*dev
= info
->user_ptr
[1];
4241 struct mpath_info pinfo
;
4242 struct sk_buff
*msg
;
4244 u8 next_hop
[ETH_ALEN
];
4246 memset(&pinfo
, 0, sizeof(pinfo
));
4248 if (!info
->attrs
[NL80211_ATTR_MAC
])
4251 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4253 if (!rdev
->ops
->get_mpath
)
4256 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4259 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4263 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4267 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4268 dev
, dst
, next_hop
, &pinfo
) < 0) {
4273 return genlmsg_reply(msg
, info
);
4276 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4278 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4279 struct net_device
*dev
= info
->user_ptr
[1];
4281 u8
*next_hop
= NULL
;
4283 if (!info
->attrs
[NL80211_ATTR_MAC
])
4286 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4289 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4290 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4292 if (!rdev
->ops
->change_mpath
)
4295 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4298 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4301 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4303 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4304 struct net_device
*dev
= info
->user_ptr
[1];
4306 u8
*next_hop
= NULL
;
4308 if (!info
->attrs
[NL80211_ATTR_MAC
])
4311 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4314 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4315 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4317 if (!rdev
->ops
->add_mpath
)
4320 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4323 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4326 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4328 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4329 struct net_device
*dev
= info
->user_ptr
[1];
4332 if (info
->attrs
[NL80211_ATTR_MAC
])
4333 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4335 if (!rdev
->ops
->del_mpath
)
4338 return rdev_del_mpath(rdev
, dev
, dst
);
4341 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4343 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4344 struct net_device
*dev
= info
->user_ptr
[1];
4345 struct bss_parameters params
;
4347 memset(¶ms
, 0, sizeof(params
));
4348 /* default to not changing parameters */
4349 params
.use_cts_prot
= -1;
4350 params
.use_short_preamble
= -1;
4351 params
.use_short_slot_time
= -1;
4352 params
.ap_isolate
= -1;
4353 params
.ht_opmode
= -1;
4354 params
.p2p_ctwindow
= -1;
4355 params
.p2p_opp_ps
= -1;
4357 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4358 params
.use_cts_prot
=
4359 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4360 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4361 params
.use_short_preamble
=
4362 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4363 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4364 params
.use_short_slot_time
=
4365 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4366 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4367 params
.basic_rates
=
4368 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4369 params
.basic_rates_len
=
4370 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4372 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4373 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4374 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4376 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4378 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4379 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4381 params
.p2p_ctwindow
=
4382 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4383 if (params
.p2p_ctwindow
< 0)
4385 if (params
.p2p_ctwindow
!= 0 &&
4386 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4390 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4393 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4395 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4398 params
.p2p_opp_ps
= tmp
;
4399 if (params
.p2p_opp_ps
&&
4400 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4404 if (!rdev
->ops
->change_bss
)
4407 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4408 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4411 return rdev_change_bss(rdev
, dev
, ¶ms
);
4414 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4415 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4416 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4417 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4418 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4419 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4420 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4423 static int parse_reg_rule(struct nlattr
*tb
[],
4424 struct ieee80211_reg_rule
*reg_rule
)
4426 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4427 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4429 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4431 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4433 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4435 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4437 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4440 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4442 freq_range
->start_freq_khz
=
4443 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4444 freq_range
->end_freq_khz
=
4445 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4446 freq_range
->max_bandwidth_khz
=
4447 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4449 power_rule
->max_eirp
=
4450 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4452 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4453 power_rule
->max_antenna_gain
=
4454 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4459 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4463 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4466 * You should only get this when cfg80211 hasn't yet initialized
4467 * completely when built-in to the kernel right between the time
4468 * window between nl80211_init() and regulatory_init(), if that is
4471 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4472 return -EINPROGRESS
;
4474 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4477 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4479 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4480 user_reg_hint_type
=
4481 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4483 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4485 switch (user_reg_hint_type
) {
4486 case NL80211_USER_REG_HINT_USER
:
4487 case NL80211_USER_REG_HINT_CELL_BASE
:
4493 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4498 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4499 struct genl_info
*info
)
4501 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4502 struct net_device
*dev
= info
->user_ptr
[1];
4503 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4504 struct mesh_config cur_params
;
4507 struct nlattr
*pinfoattr
;
4508 struct sk_buff
*msg
;
4510 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4513 if (!rdev
->ops
->get_mesh_config
)
4517 /* If not connected, get default parameters */
4518 if (!wdev
->mesh_id_len
)
4519 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4521 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4527 /* Draw up a netlink message to send back */
4528 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4531 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4532 NL80211_CMD_GET_MESH_CONFIG
);
4535 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4537 goto nla_put_failure
;
4538 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4539 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4540 cur_params
.dot11MeshRetryTimeout
) ||
4541 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4542 cur_params
.dot11MeshConfirmTimeout
) ||
4543 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4544 cur_params
.dot11MeshHoldingTimeout
) ||
4545 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4546 cur_params
.dot11MeshMaxPeerLinks
) ||
4547 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4548 cur_params
.dot11MeshMaxRetries
) ||
4549 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4550 cur_params
.dot11MeshTTL
) ||
4551 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4552 cur_params
.element_ttl
) ||
4553 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4554 cur_params
.auto_open_plinks
) ||
4555 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4556 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4557 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4558 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4559 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4560 cur_params
.path_refresh_time
) ||
4561 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4562 cur_params
.min_discovery_timeout
) ||
4563 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4564 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4565 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4566 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4567 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4568 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4569 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4570 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4571 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4572 cur_params
.dot11MeshHWMPRootMode
) ||
4573 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4574 cur_params
.dot11MeshHWMPRannInterval
) ||
4575 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4576 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4577 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4578 cur_params
.dot11MeshForwarding
) ||
4579 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4580 cur_params
.rssi_threshold
) ||
4581 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4582 cur_params
.ht_opmode
) ||
4583 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4584 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4585 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4586 cur_params
.dot11MeshHWMProotInterval
) ||
4587 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4588 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4589 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4590 cur_params
.power_mode
) ||
4591 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4592 cur_params
.dot11MeshAwakeWindowDuration
))
4593 goto nla_put_failure
;
4594 nla_nest_end(msg
, pinfoattr
);
4595 genlmsg_end(msg
, hdr
);
4596 return genlmsg_reply(msg
, info
);
4599 genlmsg_cancel(msg
, hdr
);
4605 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4606 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4607 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4608 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4609 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4610 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4611 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4612 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4613 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4614 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4615 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4616 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4617 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4618 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4619 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4620 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4621 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4622 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4623 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4624 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4625 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4626 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4627 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4628 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4629 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4630 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4631 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4632 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4635 static const struct nla_policy
4636 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4637 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4638 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4639 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4640 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4641 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
4642 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4643 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4644 .len
= IEEE80211_MAX_DATA_LEN
},
4645 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4648 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4649 struct mesh_config
*cfg
,
4652 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4655 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4658 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4660 cfg->param = fn(tb[attr]); \
4661 mask |= (1 << (attr - 1)); \
4666 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4668 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4669 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4670 nl80211_meshconf_params_policy
))
4673 /* This makes sure that there aren't more than 32 mesh config
4674 * parameters (otherwise our bitfield scheme would not work.) */
4675 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4677 /* Fill in the params struct */
4678 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4679 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4681 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4682 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4684 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4685 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4687 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4688 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4690 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4691 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4693 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4694 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4695 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4696 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4698 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4699 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4701 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4703 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4705 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4706 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4708 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4709 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4711 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4712 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4714 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4716 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4718 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4720 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4722 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4724 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4726 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4727 dot11MeshHWMPnetDiameterTraversalTime
,
4729 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4731 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4732 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4734 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4735 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4737 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4738 dot11MeshGateAnnouncementProtocol
, 0, 1,
4739 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4741 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4742 mask
, NL80211_MESHCONF_FORWARDING
,
4744 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4745 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4747 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4748 mask
, NL80211_MESHCONF_HT_OPMODE
,
4750 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4752 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4754 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4755 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4758 dot11MeshHWMPconfirmationInterval
,
4760 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4762 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4763 NL80211_MESH_POWER_ACTIVE
,
4764 NL80211_MESH_POWER_MAX
,
4765 mask
, NL80211_MESHCONF_POWER_MODE
,
4767 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4769 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4775 #undef FILL_IN_MESH_PARAM_IF_SET
4778 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4779 struct mesh_setup
*setup
)
4781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4782 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4784 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4786 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4787 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4788 nl80211_mesh_setup_params_policy
))
4791 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4792 setup
->sync_method
=
4793 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4794 IEEE80211_SYNC_METHOD_VENDOR
:
4795 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4797 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4798 setup
->path_sel_proto
=
4799 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4800 IEEE80211_PATH_PROTOCOL_VENDOR
:
4801 IEEE80211_PATH_PROTOCOL_HWMP
;
4803 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4804 setup
->path_metric
=
4805 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4806 IEEE80211_PATH_METRIC_VENDOR
:
4807 IEEE80211_PATH_METRIC_AIRTIME
;
4810 if (tb
[NL80211_MESH_SETUP_IE
]) {
4811 struct nlattr
*ieattr
=
4812 tb
[NL80211_MESH_SETUP_IE
];
4813 if (!is_valid_ie_attr(ieattr
))
4815 setup
->ie
= nla_data(ieattr
);
4816 setup
->ie_len
= nla_len(ieattr
);
4818 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4819 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4821 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4822 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4823 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4824 if (setup
->is_secure
)
4825 setup
->user_mpm
= true;
4827 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
4828 if (!setup
->user_mpm
)
4831 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
4837 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4838 struct genl_info
*info
)
4840 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4841 struct net_device
*dev
= info
->user_ptr
[1];
4842 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4843 struct mesh_config cfg
;
4847 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4850 if (!rdev
->ops
->update_mesh_config
)
4853 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4858 if (!wdev
->mesh_id_len
)
4862 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4869 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4871 const struct ieee80211_regdomain
*regdom
;
4872 struct sk_buff
*msg
;
4874 struct nlattr
*nl_reg_rules
;
4877 if (!cfg80211_regdomain
)
4880 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4884 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4885 NL80211_CMD_GET_REG
);
4889 if (reg_last_request_cell_base() &&
4890 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4891 NL80211_USER_REG_HINT_CELL_BASE
))
4892 goto nla_put_failure
;
4895 regdom
= rcu_dereference(cfg80211_regdomain
);
4897 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4898 (regdom
->dfs_region
&&
4899 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4900 goto nla_put_failure_rcu
;
4902 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4904 goto nla_put_failure_rcu
;
4906 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4907 struct nlattr
*nl_reg_rule
;
4908 const struct ieee80211_reg_rule
*reg_rule
;
4909 const struct ieee80211_freq_range
*freq_range
;
4910 const struct ieee80211_power_rule
*power_rule
;
4912 reg_rule
= ®dom
->reg_rules
[i
];
4913 freq_range
= ®_rule
->freq_range
;
4914 power_rule
= ®_rule
->power_rule
;
4916 nl_reg_rule
= nla_nest_start(msg
, i
);
4918 goto nla_put_failure_rcu
;
4920 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4922 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4923 freq_range
->start_freq_khz
) ||
4924 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4925 freq_range
->end_freq_khz
) ||
4926 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4927 freq_range
->max_bandwidth_khz
) ||
4928 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4929 power_rule
->max_antenna_gain
) ||
4930 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4931 power_rule
->max_eirp
))
4932 goto nla_put_failure_rcu
;
4934 nla_nest_end(msg
, nl_reg_rule
);
4938 nla_nest_end(msg
, nl_reg_rules
);
4940 genlmsg_end(msg
, hdr
);
4941 return genlmsg_reply(msg
, info
);
4943 nla_put_failure_rcu
:
4946 genlmsg_cancel(msg
, hdr
);
4952 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4954 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4955 struct nlattr
*nl_reg_rule
;
4956 char *alpha2
= NULL
;
4957 int rem_reg_rules
= 0, r
= 0;
4958 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4960 struct ieee80211_regdomain
*rd
= NULL
;
4962 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4965 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4968 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4970 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4971 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4973 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4976 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4980 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4981 num_rules
* sizeof(struct ieee80211_reg_rule
);
4983 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4987 rd
->n_reg_rules
= num_rules
;
4988 rd
->alpha2
[0] = alpha2
[0];
4989 rd
->alpha2
[1] = alpha2
[1];
4992 * Disable DFS master mode if the DFS region was
4993 * not supported or known on this kernel.
4995 if (reg_supported_dfs_region(dfs_region
))
4996 rd
->dfs_region
= dfs_region
;
4998 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5000 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5001 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5003 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5009 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5016 /* set_regdom took ownership */
5024 static int validate_scan_freqs(struct nlattr
*freqs
)
5026 struct nlattr
*attr1
, *attr2
;
5027 int n_channels
= 0, tmp1
, tmp2
;
5029 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5032 * Some hardware has a limited channel list for
5033 * scanning, and it is pretty much nonsensical
5034 * to scan for a channel twice, so disallow that
5035 * and don't require drivers to check that the
5036 * channel list they get isn't longer than what
5037 * they can scan, as long as they can scan all
5038 * the channels they registered at once.
5040 nla_for_each_nested(attr2
, freqs
, tmp2
)
5041 if (attr1
!= attr2
&&
5042 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5049 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5051 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5052 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5053 struct cfg80211_scan_request
*request
;
5054 struct nlattr
*attr
;
5055 struct wiphy
*wiphy
;
5056 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5059 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5062 wiphy
= &rdev
->wiphy
;
5064 if (!rdev
->ops
->scan
)
5067 if (rdev
->scan_req
) {
5072 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5073 n_channels
= validate_scan_freqs(
5074 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5080 enum ieee80211_band band
;
5083 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5084 if (wiphy
->bands
[band
])
5085 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5088 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5089 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5092 if (n_ssids
> wiphy
->max_scan_ssids
) {
5097 if (info
->attrs
[NL80211_ATTR_IE
])
5098 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5102 if (ie_len
> wiphy
->max_scan_ie_len
) {
5107 request
= kzalloc(sizeof(*request
)
5108 + sizeof(*request
->ssids
) * n_ssids
5109 + sizeof(*request
->channels
) * n_channels
5110 + ie_len
, GFP_KERNEL
);
5117 request
->ssids
= (void *)&request
->channels
[n_channels
];
5118 request
->n_ssids
= n_ssids
;
5121 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5123 request
->ie
= (void *)(request
->channels
+ n_channels
);
5127 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5128 /* user specified, bail out if channel not found */
5129 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5130 struct ieee80211_channel
*chan
;
5132 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5139 /* ignore disabled channels */
5140 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5143 request
->channels
[i
] = chan
;
5147 enum ieee80211_band band
;
5150 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5152 if (!wiphy
->bands
[band
])
5154 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5155 struct ieee80211_channel
*chan
;
5157 chan
= &wiphy
->bands
[band
]->channels
[j
];
5159 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5162 request
->channels
[i
] = chan
;
5173 request
->n_channels
= i
;
5176 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5177 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5178 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5182 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5183 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5188 if (info
->attrs
[NL80211_ATTR_IE
]) {
5189 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5190 memcpy((void *)request
->ie
,
5191 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5195 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5196 if (wiphy
->bands
[i
])
5198 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5200 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5201 nla_for_each_nested(attr
,
5202 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5204 enum ieee80211_band band
= nla_type(attr
);
5206 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5210 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5213 &request
->rates
[band
]);
5219 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5220 request
->flags
= nla_get_u32(
5221 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5222 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5223 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5224 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5225 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5232 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5234 request
->wdev
= wdev
;
5235 request
->wiphy
= &rdev
->wiphy
;
5236 request
->scan_start
= jiffies
;
5238 rdev
->scan_req
= request
;
5239 err
= rdev_scan(rdev
, request
);
5242 nl80211_send_scan_start(rdev
, wdev
);
5244 dev_hold(wdev
->netdev
);
5247 rdev
->scan_req
= NULL
;
5255 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5256 struct genl_info
*info
)
5258 struct cfg80211_sched_scan_request
*request
;
5259 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5260 struct net_device
*dev
= info
->user_ptr
[1];
5261 struct nlattr
*attr
;
5262 struct wiphy
*wiphy
;
5263 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5265 enum ieee80211_band band
;
5267 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5269 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5270 !rdev
->ops
->sched_scan_start
)
5273 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5276 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5279 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5283 wiphy
= &rdev
->wiphy
;
5285 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5286 n_channels
= validate_scan_freqs(
5287 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5293 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5294 if (wiphy
->bands
[band
])
5295 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5298 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5299 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5303 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5306 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5307 nla_for_each_nested(attr
,
5308 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5312 if (n_match_sets
> wiphy
->max_match_sets
)
5315 if (info
->attrs
[NL80211_ATTR_IE
])
5316 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5320 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5323 if (rdev
->sched_scan_req
) {
5328 request
= kzalloc(sizeof(*request
)
5329 + sizeof(*request
->ssids
) * n_ssids
5330 + sizeof(*request
->match_sets
) * n_match_sets
5331 + sizeof(*request
->channels
) * n_channels
5332 + ie_len
, GFP_KERNEL
);
5339 request
->ssids
= (void *)&request
->channels
[n_channels
];
5340 request
->n_ssids
= n_ssids
;
5343 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5345 request
->ie
= (void *)(request
->channels
+ n_channels
);
5350 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5351 else if (request
->ssids
)
5352 request
->match_sets
=
5353 (void *)(request
->ssids
+ n_ssids
);
5355 request
->match_sets
=
5356 (void *)(request
->channels
+ n_channels
);
5358 request
->n_match_sets
= n_match_sets
;
5361 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5362 /* user specified, bail out if channel not found */
5363 nla_for_each_nested(attr
,
5364 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5366 struct ieee80211_channel
*chan
;
5368 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5375 /* ignore disabled channels */
5376 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5379 request
->channels
[i
] = chan
;
5384 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5386 if (!wiphy
->bands
[band
])
5388 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5389 struct ieee80211_channel
*chan
;
5391 chan
= &wiphy
->bands
[band
]->channels
[j
];
5393 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5396 request
->channels
[i
] = chan
;
5407 request
->n_channels
= i
;
5410 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5411 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5413 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5417 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5418 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5425 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5426 nla_for_each_nested(attr
,
5427 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5429 struct nlattr
*ssid
, *rssi
;
5431 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5432 nla_data(attr
), nla_len(attr
),
5433 nl80211_match_policy
);
5434 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5436 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5440 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5441 nla_data(ssid
), nla_len(ssid
));
5442 request
->match_sets
[i
].ssid
.ssid_len
=
5445 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5447 request
->rssi_thold
= nla_get_u32(rssi
);
5449 request
->rssi_thold
=
5450 NL80211_SCAN_RSSI_THOLD_OFF
;
5455 if (info
->attrs
[NL80211_ATTR_IE
]) {
5456 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5457 memcpy((void *)request
->ie
,
5458 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5462 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5463 request
->flags
= nla_get_u32(
5464 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5465 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5466 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5467 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5468 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5475 request
->wiphy
= &rdev
->wiphy
;
5476 request
->interval
= interval
;
5477 request
->scan_start
= jiffies
;
5479 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5481 rdev
->sched_scan_req
= request
;
5482 nl80211_send_sched_scan(rdev
, dev
,
5483 NL80211_CMD_START_SCHED_SCAN
);
5493 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5494 struct genl_info
*info
)
5496 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5498 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5499 !rdev
->ops
->sched_scan_stop
)
5502 return __cfg80211_stop_sched_scan(rdev
, false);
5505 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5506 struct genl_info
*info
)
5508 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5509 struct net_device
*dev
= info
->user_ptr
[1];
5510 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5511 struct cfg80211_chan_def chandef
;
5514 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5518 if (wdev
->cac_started
)
5521 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5528 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5531 if (!rdev
->ops
->start_radar_detection
)
5534 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5535 chandef
.chan
, CHAN_MODE_SHARED
,
5536 BIT(chandef
.width
));
5540 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5542 wdev
->channel
= chandef
.chan
;
5543 wdev
->cac_started
= true;
5544 wdev
->cac_start_time
= jiffies
;
5549 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5551 struct cfg80211_registered_device
*rdev
,
5552 struct wireless_dev
*wdev
,
5553 struct cfg80211_internal_bss
*intbss
)
5555 struct cfg80211_bss
*res
= &intbss
->pub
;
5556 const struct cfg80211_bss_ies
*ies
;
5561 ASSERT_WDEV_LOCK(wdev
);
5563 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5564 NL80211_CMD_NEW_SCAN_RESULTS
);
5568 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5570 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5571 goto nla_put_failure
;
5573 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5574 goto nla_put_failure
;
5575 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5576 goto nla_put_failure
;
5578 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5580 goto nla_put_failure
;
5581 if ((!is_zero_ether_addr(res
->bssid
) &&
5582 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5583 goto nla_put_failure
;
5586 ies
= rcu_dereference(res
->ies
);
5588 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5589 goto fail_unlock_rcu
;
5591 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5592 ies
->len
, ies
->data
))
5593 goto fail_unlock_rcu
;
5595 ies
= rcu_dereference(res
->beacon_ies
);
5597 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5598 goto fail_unlock_rcu
;
5599 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5600 ies
->len
, ies
->data
))
5601 goto fail_unlock_rcu
;
5605 if (res
->beacon_interval
&&
5606 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5607 goto nla_put_failure
;
5608 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5609 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5610 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5611 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5612 goto nla_put_failure
;
5614 switch (rdev
->wiphy
.signal_type
) {
5615 case CFG80211_SIGNAL_TYPE_MBM
:
5616 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5617 goto nla_put_failure
;
5619 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5620 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5621 goto nla_put_failure
;
5627 switch (wdev
->iftype
) {
5628 case NL80211_IFTYPE_P2P_CLIENT
:
5629 case NL80211_IFTYPE_STATION
:
5630 if (intbss
== wdev
->current_bss
&&
5631 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5632 NL80211_BSS_STATUS_ASSOCIATED
))
5633 goto nla_put_failure
;
5635 case NL80211_IFTYPE_ADHOC
:
5636 if (intbss
== wdev
->current_bss
&&
5637 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5638 NL80211_BSS_STATUS_IBSS_JOINED
))
5639 goto nla_put_failure
;
5645 nla_nest_end(msg
, bss
);
5647 return genlmsg_end(msg
, hdr
);
5652 genlmsg_cancel(msg
, hdr
);
5656 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5658 struct cfg80211_registered_device
*rdev
;
5659 struct cfg80211_internal_bss
*scan
;
5660 struct wireless_dev
*wdev
;
5661 int start
= cb
->args
[2], idx
= 0;
5664 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5669 spin_lock_bh(&rdev
->bss_lock
);
5670 cfg80211_bss_expire(rdev
);
5672 cb
->seq
= rdev
->bss_generation
;
5674 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5677 if (nl80211_send_bss(skb
, cb
,
5678 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5679 rdev
, wdev
, scan
) < 0) {
5685 spin_unlock_bh(&rdev
->bss_lock
);
5689 nl80211_finish_wdev_dump(rdev
);
5694 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5695 int flags
, struct net_device
*dev
,
5696 struct survey_info
*survey
)
5699 struct nlattr
*infoattr
;
5701 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5702 NL80211_CMD_NEW_SURVEY_RESULTS
);
5706 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5707 goto nla_put_failure
;
5709 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5711 goto nla_put_failure
;
5713 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5714 survey
->channel
->center_freq
))
5715 goto nla_put_failure
;
5717 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5718 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5719 goto nla_put_failure
;
5720 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5721 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5722 goto nla_put_failure
;
5723 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5724 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5725 survey
->channel_time
))
5726 goto nla_put_failure
;
5727 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5728 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5729 survey
->channel_time_busy
))
5730 goto nla_put_failure
;
5731 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5732 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5733 survey
->channel_time_ext_busy
))
5734 goto nla_put_failure
;
5735 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5736 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5737 survey
->channel_time_rx
))
5738 goto nla_put_failure
;
5739 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5740 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5741 survey
->channel_time_tx
))
5742 goto nla_put_failure
;
5744 nla_nest_end(msg
, infoattr
);
5746 return genlmsg_end(msg
, hdr
);
5749 genlmsg_cancel(msg
, hdr
);
5753 static int nl80211_dump_survey(struct sk_buff
*skb
,
5754 struct netlink_callback
*cb
)
5756 struct survey_info survey
;
5757 struct cfg80211_registered_device
*dev
;
5758 struct wireless_dev
*wdev
;
5759 int survey_idx
= cb
->args
[2];
5762 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5766 if (!wdev
->netdev
) {
5771 if (!dev
->ops
->dump_survey
) {
5777 struct ieee80211_channel
*chan
;
5779 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5785 /* Survey without a channel doesn't make sense */
5786 if (!survey
.channel
) {
5791 chan
= ieee80211_get_channel(&dev
->wiphy
,
5792 survey
.channel
->center_freq
);
5793 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5798 if (nl80211_send_survey(skb
,
5799 NETLINK_CB(cb
->skb
).portid
,
5800 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5801 wdev
->netdev
, &survey
) < 0)
5807 cb
->args
[2] = survey_idx
;
5810 nl80211_finish_wdev_dump(dev
);
5814 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5816 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5817 NL80211_WPA_VERSION_2
));
5820 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5822 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5823 struct net_device
*dev
= info
->user_ptr
[1];
5824 struct ieee80211_channel
*chan
;
5825 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5826 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5827 enum nl80211_auth_type auth_type
;
5828 struct key_parse key
;
5829 bool local_state_change
;
5831 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5834 if (!info
->attrs
[NL80211_ATTR_MAC
])
5837 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5840 if (!info
->attrs
[NL80211_ATTR_SSID
])
5843 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5846 err
= nl80211_parse_key(info
, &key
);
5851 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5853 if (!key
.p
.key
|| !key
.p
.key_len
)
5855 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5856 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5857 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5858 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5870 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5871 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5880 if (!rdev
->ops
->auth
)
5883 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5884 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5887 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5888 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5889 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5890 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5893 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5894 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5896 if (info
->attrs
[NL80211_ATTR_IE
]) {
5897 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5898 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5901 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5902 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5905 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5906 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5909 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5910 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5912 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5913 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5914 /* need to include at least Auth Transaction and Status Code */
5915 if (sae_data_len
< 4)
5919 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5922 * Since we no longer track auth state, ignore
5923 * requests to only change local state.
5925 if (local_state_change
)
5928 wdev_lock(dev
->ieee80211_ptr
);
5929 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5930 ssid
, ssid_len
, ie
, ie_len
,
5931 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5932 sae_data
, sae_data_len
);
5933 wdev_unlock(dev
->ieee80211_ptr
);
5937 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5938 struct genl_info
*info
,
5939 struct cfg80211_crypto_settings
*settings
,
5942 memset(settings
, 0, sizeof(*settings
));
5944 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5946 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5948 proto
= nla_get_u16(
5949 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5950 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5951 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5954 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5955 settings
->control_port_no_encrypt
= true;
5957 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5959 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5963 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5964 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5965 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5967 if (len
% sizeof(u32
))
5970 if (settings
->n_ciphers_pairwise
> cipher_limit
)
5973 memcpy(settings
->ciphers_pairwise
, data
, len
);
5975 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
5976 if (!cfg80211_supported_cipher_suite(
5978 settings
->ciphers_pairwise
[i
]))
5982 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
5983 settings
->cipher_group
=
5984 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
5985 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
5986 settings
->cipher_group
))
5990 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
5991 settings
->wpa_versions
=
5992 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
5993 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
5997 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6001 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6002 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6003 settings
->n_akm_suites
= len
/ sizeof(u32
);
6005 if (len
% sizeof(u32
))
6008 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6011 memcpy(settings
->akm_suites
, data
, len
);
6017 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6019 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6020 struct net_device
*dev
= info
->user_ptr
[1];
6021 struct ieee80211_channel
*chan
;
6022 struct cfg80211_assoc_request req
= {};
6023 const u8
*bssid
, *ssid
;
6024 int err
, ssid_len
= 0;
6026 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6029 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6030 !info
->attrs
[NL80211_ATTR_SSID
] ||
6031 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6034 if (!rdev
->ops
->assoc
)
6037 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6038 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6041 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6043 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6044 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6045 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6048 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6049 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6051 if (info
->attrs
[NL80211_ATTR_IE
]) {
6052 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6053 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6056 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6057 enum nl80211_mfp mfp
=
6058 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6059 if (mfp
== NL80211_MFP_REQUIRED
)
6061 else if (mfp
!= NL80211_MFP_NO
)
6065 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6066 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6068 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6069 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6071 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6072 memcpy(&req
.ht_capa_mask
,
6073 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6074 sizeof(req
.ht_capa_mask
));
6076 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6077 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6079 memcpy(&req
.ht_capa
,
6080 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6081 sizeof(req
.ht_capa
));
6084 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6085 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6087 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6088 memcpy(&req
.vht_capa_mask
,
6089 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6090 sizeof(req
.vht_capa_mask
));
6092 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6093 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6095 memcpy(&req
.vht_capa
,
6096 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6097 sizeof(req
.vht_capa
));
6100 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6102 wdev_lock(dev
->ieee80211_ptr
);
6103 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6104 ssid
, ssid_len
, &req
);
6105 wdev_unlock(dev
->ieee80211_ptr
);
6111 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6113 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6114 struct net_device
*dev
= info
->user_ptr
[1];
6115 const u8
*ie
= NULL
, *bssid
;
6116 int ie_len
= 0, err
;
6118 bool local_state_change
;
6120 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6123 if (!info
->attrs
[NL80211_ATTR_MAC
])
6126 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6129 if (!rdev
->ops
->deauth
)
6132 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6133 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6136 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6138 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6139 if (reason_code
== 0) {
6140 /* Reason Code 0 is reserved */
6144 if (info
->attrs
[NL80211_ATTR_IE
]) {
6145 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6146 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6149 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6151 wdev_lock(dev
->ieee80211_ptr
);
6152 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6153 local_state_change
);
6154 wdev_unlock(dev
->ieee80211_ptr
);
6158 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6160 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6161 struct net_device
*dev
= info
->user_ptr
[1];
6162 const u8
*ie
= NULL
, *bssid
;
6163 int ie_len
= 0, err
;
6165 bool local_state_change
;
6167 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6170 if (!info
->attrs
[NL80211_ATTR_MAC
])
6173 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6176 if (!rdev
->ops
->disassoc
)
6179 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6180 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6183 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6185 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6186 if (reason_code
== 0) {
6187 /* Reason Code 0 is reserved */
6191 if (info
->attrs
[NL80211_ATTR_IE
]) {
6192 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6193 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6196 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6198 wdev_lock(dev
->ieee80211_ptr
);
6199 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6200 local_state_change
);
6201 wdev_unlock(dev
->ieee80211_ptr
);
6206 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6207 int mcast_rate
[IEEE80211_NUM_BANDS
],
6210 struct wiphy
*wiphy
= &rdev
->wiphy
;
6214 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6215 struct ieee80211_supported_band
*sband
;
6217 sband
= wiphy
->bands
[band
];
6221 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6222 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6223 mcast_rate
[band
] = i
+ 1;
6233 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6235 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6236 struct net_device
*dev
= info
->user_ptr
[1];
6237 struct cfg80211_ibss_params ibss
;
6238 struct wiphy
*wiphy
;
6239 struct cfg80211_cached_keys
*connkeys
= NULL
;
6242 memset(&ibss
, 0, sizeof(ibss
));
6244 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6247 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6248 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6251 ibss
.beacon_interval
= 100;
6253 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6254 ibss
.beacon_interval
=
6255 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6256 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6260 if (!rdev
->ops
->join_ibss
)
6263 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6266 wiphy
= &rdev
->wiphy
;
6268 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6269 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6271 if (!is_valid_ether_addr(ibss
.bssid
))
6274 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6275 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6277 if (info
->attrs
[NL80211_ATTR_IE
]) {
6278 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6279 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6282 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6286 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6289 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
6291 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
6292 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
6295 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6296 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6298 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6300 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6302 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6303 struct ieee80211_supported_band
*sband
=
6304 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6306 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6312 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6313 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6314 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6317 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6320 connkeys
= nl80211_parse_connkeys(rdev
,
6321 info
->attrs
[NL80211_ATTR_KEYS
],
6323 if (IS_ERR(connkeys
))
6324 return PTR_ERR(connkeys
);
6326 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6334 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6336 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6342 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6344 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6345 struct net_device
*dev
= info
->user_ptr
[1];
6347 if (!rdev
->ops
->leave_ibss
)
6350 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6353 return cfg80211_leave_ibss(rdev
, dev
, false);
6356 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6358 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6359 struct net_device
*dev
= info
->user_ptr
[1];
6360 int mcast_rate
[IEEE80211_NUM_BANDS
];
6364 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6365 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6368 if (!rdev
->ops
->set_mcast_rate
)
6371 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6373 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6376 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6377 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6380 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6386 #ifdef CONFIG_NL80211_TESTMODE
6387 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6391 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6393 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6396 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6400 if (rdev
->ops
->testmode_cmd
) {
6401 rdev
->testmode_info
= info
;
6402 err
= rdev_testmode_cmd(rdev
,
6403 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6404 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6405 rdev
->testmode_info
= NULL
;
6411 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6412 struct netlink_callback
*cb
)
6414 struct cfg80211_registered_device
*rdev
;
6424 * 0 is a valid index, but not valid for args[0],
6425 * so we need to offset by 1.
6427 phy_idx
= cb
->args
[0] - 1;
6429 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6430 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6435 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6436 nl80211_fam
.attrbuf
);
6438 err
= PTR_ERR(rdev
);
6441 phy_idx
= rdev
->wiphy_idx
;
6444 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6446 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6450 data
= nla_data((void *)cb
->args
[1]);
6451 data_len
= nla_len((void *)cb
->args
[1]);
6454 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6460 if (!rdev
->ops
->testmode_dump
) {
6466 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6467 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6468 NL80211_CMD_TESTMODE
);
6469 struct nlattr
*tmdata
;
6471 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6472 genlmsg_cancel(skb
, hdr
);
6476 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6478 genlmsg_cancel(skb
, hdr
);
6481 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6482 nla_nest_end(skb
, tmdata
);
6484 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6485 genlmsg_cancel(skb
, hdr
);
6488 genlmsg_cancel(skb
, hdr
);
6492 genlmsg_end(skb
, hdr
);
6497 cb
->args
[0] = phy_idx
+ 1;
6503 static struct sk_buff
*
6504 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
6505 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
6507 struct sk_buff
*skb
;
6509 struct nlattr
*data
;
6511 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6515 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
6521 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6522 goto nla_put_failure
;
6523 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6525 ((void **)skb
->cb
)[0] = rdev
;
6526 ((void **)skb
->cb
)[1] = hdr
;
6527 ((void **)skb
->cb
)[2] = data
;
6536 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
6539 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6541 if (WARN_ON(!rdev
->testmode_info
))
6544 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
6545 rdev
->testmode_info
->snd_portid
,
6546 rdev
->testmode_info
->snd_seq
,
6549 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
6551 int cfg80211_testmode_reply(struct sk_buff
*skb
)
6553 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6554 void *hdr
= ((void **)skb
->cb
)[1];
6555 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6557 if (WARN_ON(!rdev
->testmode_info
)) {
6562 nla_nest_end(skb
, data
);
6563 genlmsg_end(skb
, hdr
);
6564 return genlmsg_reply(skb
, rdev
->testmode_info
);
6566 EXPORT_SYMBOL(cfg80211_testmode_reply
);
6568 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
6569 int approxlen
, gfp_t gfp
)
6571 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6573 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
6575 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
6577 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
6579 void *hdr
= ((void **)skb
->cb
)[1];
6580 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6582 nla_nest_end(skb
, data
);
6583 genlmsg_end(skb
, hdr
);
6584 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
6586 EXPORT_SYMBOL(cfg80211_testmode_event
);
6589 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6591 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6592 struct net_device
*dev
= info
->user_ptr
[1];
6593 struct cfg80211_connect_params connect
;
6594 struct wiphy
*wiphy
;
6595 struct cfg80211_cached_keys
*connkeys
= NULL
;
6598 memset(&connect
, 0, sizeof(connect
));
6600 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6603 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6604 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6607 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6609 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6610 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6611 NL80211_CMD_CONNECT
))
6614 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6616 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6618 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6619 NL80211_MAX_NR_CIPHER_SUITES
);
6623 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6624 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6627 wiphy
= &rdev
->wiphy
;
6629 connect
.bg_scan_period
= -1;
6630 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6631 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6632 connect
.bg_scan_period
=
6633 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6636 if (info
->attrs
[NL80211_ATTR_MAC
])
6637 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6638 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6639 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6641 if (info
->attrs
[NL80211_ATTR_IE
]) {
6642 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6643 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6646 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6647 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6648 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6649 connect
.mfp
!= NL80211_MFP_NO
)
6652 connect
.mfp
= NL80211_MFP_NO
;
6655 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6657 ieee80211_get_channel(wiphy
,
6658 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6659 if (!connect
.channel
||
6660 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6664 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6665 connkeys
= nl80211_parse_connkeys(rdev
,
6666 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6667 if (IS_ERR(connkeys
))
6668 return PTR_ERR(connkeys
);
6671 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6672 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6674 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6675 memcpy(&connect
.ht_capa_mask
,
6676 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6677 sizeof(connect
.ht_capa_mask
));
6679 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6680 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6684 memcpy(&connect
.ht_capa
,
6685 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6686 sizeof(connect
.ht_capa
));
6689 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6690 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6692 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6693 memcpy(&connect
.vht_capa_mask
,
6694 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6695 sizeof(connect
.vht_capa_mask
));
6697 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6698 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6702 memcpy(&connect
.vht_capa
,
6703 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6704 sizeof(connect
.vht_capa
));
6707 wdev_lock(dev
->ieee80211_ptr
);
6708 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
6709 wdev_unlock(dev
->ieee80211_ptr
);
6715 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6717 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6718 struct net_device
*dev
= info
->user_ptr
[1];
6722 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6723 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6725 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6730 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6731 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6734 wdev_lock(dev
->ieee80211_ptr
);
6735 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
6736 wdev_unlock(dev
->ieee80211_ptr
);
6740 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6742 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6747 if (!info
->attrs
[NL80211_ATTR_PID
])
6750 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6752 net
= get_net_ns_by_pid(pid
);
6754 return PTR_ERR(net
);
6758 /* check if anything to do */
6759 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6760 err
= cfg80211_switch_netns(rdev
, net
);
6766 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6768 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6769 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6770 struct cfg80211_pmksa
*pmksa
) = NULL
;
6771 struct net_device
*dev
= info
->user_ptr
[1];
6772 struct cfg80211_pmksa pmksa
;
6774 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6776 if (!info
->attrs
[NL80211_ATTR_MAC
])
6779 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6782 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6783 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6785 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6786 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6789 switch (info
->genlhdr
->cmd
) {
6790 case NL80211_CMD_SET_PMKSA
:
6791 rdev_ops
= rdev
->ops
->set_pmksa
;
6793 case NL80211_CMD_DEL_PMKSA
:
6794 rdev_ops
= rdev
->ops
->del_pmksa
;
6804 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6807 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6809 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6810 struct net_device
*dev
= info
->user_ptr
[1];
6812 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6813 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6816 if (!rdev
->ops
->flush_pmksa
)
6819 return rdev_flush_pmksa(rdev
, dev
);
6822 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6824 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6825 struct net_device
*dev
= info
->user_ptr
[1];
6826 u8 action_code
, dialog_token
;
6830 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6831 !rdev
->ops
->tdls_mgmt
)
6834 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6835 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6836 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6837 !info
->attrs
[NL80211_ATTR_IE
] ||
6838 !info
->attrs
[NL80211_ATTR_MAC
])
6841 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6842 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6843 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6844 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6846 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6847 dialog_token
, status_code
,
6848 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6849 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6852 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6854 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6855 struct net_device
*dev
= info
->user_ptr
[1];
6856 enum nl80211_tdls_operation operation
;
6859 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6860 !rdev
->ops
->tdls_oper
)
6863 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6864 !info
->attrs
[NL80211_ATTR_MAC
])
6867 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6868 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6870 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6873 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6874 struct genl_info
*info
)
6876 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6877 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6878 struct cfg80211_chan_def chandef
;
6879 struct sk_buff
*msg
;
6885 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6886 !info
->attrs
[NL80211_ATTR_DURATION
])
6889 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6891 if (!rdev
->ops
->remain_on_channel
||
6892 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6896 * We should be on that channel for at least a minimum amount of
6897 * time (10ms) but no longer than the driver supports.
6899 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6900 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6903 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6907 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6911 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6912 NL80211_CMD_REMAIN_ON_CHANNEL
);
6919 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6925 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6926 goto nla_put_failure
;
6928 genlmsg_end(msg
, hdr
);
6930 return genlmsg_reply(msg
, info
);
6939 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
6940 struct genl_info
*info
)
6942 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6943 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6946 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6949 if (!rdev
->ops
->cancel_remain_on_channel
)
6952 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6954 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
6957 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
6958 u8
*rates
, u8 rates_len
)
6963 for (i
= 0; i
< rates_len
; i
++) {
6964 int rate
= (rates
[i
] & 0x7f) * 5;
6966 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
6967 struct ieee80211_rate
*srate
=
6968 &sband
->bitrates
[ridx
];
6969 if (rate
== srate
->bitrate
) {
6974 if (ridx
== sband
->n_bitrates
)
6975 return 0; /* rate not found */
6981 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
6982 u8
*rates
, u8 rates_len
,
6983 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
6987 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
6989 for (i
= 0; i
< rates_len
; i
++) {
6992 ridx
= rates
[i
] / 8;
6993 rbit
= BIT(rates
[i
] % 8);
6995 /* check validity */
6996 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
6999 /* check availability */
7000 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7009 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7010 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7011 .len
= NL80211_MAX_SUPP_RATES
},
7012 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7013 .len
= NL80211_MAX_SUPP_HT_RATES
},
7016 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7017 struct genl_info
*info
)
7019 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7020 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7021 struct cfg80211_bitrate_mask mask
;
7023 struct net_device
*dev
= info
->user_ptr
[1];
7024 struct nlattr
*tx_rates
;
7025 struct ieee80211_supported_band
*sband
;
7027 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7030 if (!rdev
->ops
->set_bitrate_mask
)
7033 memset(&mask
, 0, sizeof(mask
));
7034 /* Default to all rates enabled */
7035 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7036 sband
= rdev
->wiphy
.bands
[i
];
7037 mask
.control
[i
].legacy
=
7038 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7040 memcpy(mask
.control
[i
].mcs
,
7041 sband
->ht_cap
.mcs
.rx_mask
,
7042 sizeof(mask
.control
[i
].mcs
));
7044 memset(mask
.control
[i
].mcs
, 0,
7045 sizeof(mask
.control
[i
].mcs
));
7049 * The nested attribute uses enum nl80211_band as the index. This maps
7050 * directly to the enum ieee80211_band values used in cfg80211.
7052 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7053 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7055 enum ieee80211_band band
= nla_type(tx_rates
);
7056 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7058 sband
= rdev
->wiphy
.bands
[band
];
7061 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7062 nla_len(tx_rates
), nl80211_txattr_policy
);
7063 if (tb
[NL80211_TXRATE_LEGACY
]) {
7064 mask
.control
[band
].legacy
= rateset_to_mask(
7066 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7067 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7068 if ((mask
.control
[band
].legacy
== 0) &&
7069 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7072 if (tb
[NL80211_TXRATE_MCS
]) {
7073 if (!ht_rateset_to_mask(
7075 nla_data(tb
[NL80211_TXRATE_MCS
]),
7076 nla_len(tb
[NL80211_TXRATE_MCS
]),
7077 mask
.control
[band
].mcs
))
7081 if (mask
.control
[band
].legacy
== 0) {
7082 /* don't allow empty legacy rates if HT
7083 * is not even supported. */
7084 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7087 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7088 if (mask
.control
[band
].mcs
[i
])
7091 /* legacy and mcs rates may not be both empty */
7092 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7097 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7100 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7102 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7103 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7104 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7106 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7109 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7110 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7112 switch (wdev
->iftype
) {
7113 case NL80211_IFTYPE_STATION
:
7114 case NL80211_IFTYPE_ADHOC
:
7115 case NL80211_IFTYPE_P2P_CLIENT
:
7116 case NL80211_IFTYPE_AP
:
7117 case NL80211_IFTYPE_AP_VLAN
:
7118 case NL80211_IFTYPE_MESH_POINT
:
7119 case NL80211_IFTYPE_P2P_GO
:
7120 case NL80211_IFTYPE_P2P_DEVICE
:
7126 /* not much point in registering if we can't reply */
7127 if (!rdev
->ops
->mgmt_tx
)
7130 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7131 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7132 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7135 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7137 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7138 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7139 struct cfg80211_chan_def chandef
;
7143 struct sk_buff
*msg
= NULL
;
7144 unsigned int wait
= 0;
7145 bool offchan
, no_cck
, dont_wait_for_ack
;
7147 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7149 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7152 if (!rdev
->ops
->mgmt_tx
)
7155 switch (wdev
->iftype
) {
7156 case NL80211_IFTYPE_STATION
:
7157 case NL80211_IFTYPE_ADHOC
:
7158 case NL80211_IFTYPE_P2P_CLIENT
:
7159 case NL80211_IFTYPE_AP
:
7160 case NL80211_IFTYPE_AP_VLAN
:
7161 case NL80211_IFTYPE_MESH_POINT
:
7162 case NL80211_IFTYPE_P2P_GO
:
7163 case NL80211_IFTYPE_P2P_DEVICE
:
7169 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7170 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7172 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7175 * We should wait on the channel for at least a minimum amount
7176 * of time (10ms) but no longer than the driver supports.
7178 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7179 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7184 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7186 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7189 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7191 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7195 if (!dont_wait_for_ack
) {
7196 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7200 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7209 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7210 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7211 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7212 no_cck
, dont_wait_for_ack
, &cookie
);
7217 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7218 goto nla_put_failure
;
7220 genlmsg_end(msg
, hdr
);
7221 return genlmsg_reply(msg
, info
);
7233 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7235 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7236 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7239 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7242 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7245 switch (wdev
->iftype
) {
7246 case NL80211_IFTYPE_STATION
:
7247 case NL80211_IFTYPE_ADHOC
:
7248 case NL80211_IFTYPE_P2P_CLIENT
:
7249 case NL80211_IFTYPE_AP
:
7250 case NL80211_IFTYPE_AP_VLAN
:
7251 case NL80211_IFTYPE_P2P_GO
:
7252 case NL80211_IFTYPE_P2P_DEVICE
:
7258 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7260 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7263 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7265 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7266 struct wireless_dev
*wdev
;
7267 struct net_device
*dev
= info
->user_ptr
[1];
7272 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7275 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7277 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7280 wdev
= dev
->ieee80211_ptr
;
7282 if (!rdev
->ops
->set_power_mgmt
)
7285 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7287 if (state
== wdev
->ps
)
7290 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7296 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7298 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7299 enum nl80211_ps_state ps_state
;
7300 struct wireless_dev
*wdev
;
7301 struct net_device
*dev
= info
->user_ptr
[1];
7302 struct sk_buff
*msg
;
7306 wdev
= dev
->ieee80211_ptr
;
7308 if (!rdev
->ops
->set_power_mgmt
)
7311 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7315 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7316 NL80211_CMD_GET_POWER_SAVE
);
7323 ps_state
= NL80211_PS_ENABLED
;
7325 ps_state
= NL80211_PS_DISABLED
;
7327 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7328 goto nla_put_failure
;
7330 genlmsg_end(msg
, hdr
);
7331 return genlmsg_reply(msg
, info
);
7340 static struct nla_policy
7341 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7342 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7343 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7344 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7345 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7346 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7347 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7350 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7351 u32 rate
, u32 pkts
, u32 intvl
)
7353 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7354 struct wireless_dev
*wdev
;
7355 struct net_device
*dev
= info
->user_ptr
[1];
7357 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7360 wdev
= dev
->ieee80211_ptr
;
7362 if (!rdev
->ops
->set_cqm_txe_config
)
7365 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7366 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7369 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7372 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7373 s32 threshold
, u32 hysteresis
)
7375 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7376 struct wireless_dev
*wdev
;
7377 struct net_device
*dev
= info
->user_ptr
[1];
7382 wdev
= dev
->ieee80211_ptr
;
7384 if (!rdev
->ops
->set_cqm_rssi_config
)
7387 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7388 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7391 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7394 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7396 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7400 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7406 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7407 nl80211_attr_cqm_policy
);
7411 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7412 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7415 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7416 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7417 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7418 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7419 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7420 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7421 u32 rate
, pkts
, intvl
;
7422 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7423 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7424 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7425 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7433 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7435 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7436 struct net_device
*dev
= info
->user_ptr
[1];
7437 struct mesh_config cfg
;
7438 struct mesh_setup setup
;
7441 /* start with default */
7442 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7443 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7445 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7446 /* and parse parameters if given */
7447 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7452 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7453 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7456 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7457 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7459 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7460 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7461 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7464 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7465 setup
.beacon_interval
=
7466 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7467 if (setup
.beacon_interval
< 10 ||
7468 setup
.beacon_interval
> 10000)
7472 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7474 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7475 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7479 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7480 /* parse additional setup parameters if given */
7481 err
= nl80211_parse_mesh_setup(info
, &setup
);
7487 cfg
.auto_open_plinks
= false;
7489 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7490 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7494 /* cfg80211_join_mesh() will sort it out */
7495 setup
.chandef
.chan
= NULL
;
7498 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7501 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7503 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7504 struct net_device
*dev
= info
->user_ptr
[1];
7506 return cfg80211_leave_mesh(rdev
, dev
);
7510 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7511 struct cfg80211_registered_device
*rdev
)
7513 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
7514 struct nlattr
*nl_pats
, *nl_pat
;
7517 if (!wowlan
->n_patterns
)
7520 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7524 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
7525 nl_pat
= nla_nest_start(msg
, i
+ 1);
7528 pat_len
= wowlan
->patterns
[i
].pattern_len
;
7529 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7530 DIV_ROUND_UP(pat_len
, 8),
7531 wowlan
->patterns
[i
].mask
) ||
7532 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7533 pat_len
, wowlan
->patterns
[i
].pattern
) ||
7534 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7535 wowlan
->patterns
[i
].pkt_offset
))
7537 nla_nest_end(msg
, nl_pat
);
7539 nla_nest_end(msg
, nl_pats
);
7544 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7545 struct cfg80211_wowlan_tcp
*tcp
)
7547 struct nlattr
*nl_tcp
;
7552 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7556 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7557 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7558 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7559 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7560 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7561 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7562 tcp
->payload_len
, tcp
->payload
) ||
7563 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7564 tcp
->data_interval
) ||
7565 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7566 tcp
->wake_len
, tcp
->wake_data
) ||
7567 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7568 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7571 if (tcp
->payload_seq
.len
&&
7572 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7573 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7576 if (tcp
->payload_tok
.len
&&
7577 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7578 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7582 nla_nest_end(msg
, nl_tcp
);
7587 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7589 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7590 struct sk_buff
*msg
;
7592 u32 size
= NLMSG_DEFAULT_SIZE
;
7594 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7595 !rdev
->wiphy
.wowlan
.tcp
)
7598 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
7599 /* adjust size to have room for all the data */
7600 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
7601 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
7602 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
7603 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
7606 msg
= nlmsg_new(size
, GFP_KERNEL
);
7610 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7611 NL80211_CMD_GET_WOWLAN
);
7613 goto nla_put_failure
;
7615 if (rdev
->wiphy
.wowlan_config
) {
7616 struct nlattr
*nl_wowlan
;
7618 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7620 goto nla_put_failure
;
7622 if ((rdev
->wiphy
.wowlan_config
->any
&&
7623 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7624 (rdev
->wiphy
.wowlan_config
->disconnect
&&
7625 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7626 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
7627 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7628 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
7629 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7630 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
7631 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7632 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
7633 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7634 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
7635 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7636 goto nla_put_failure
;
7638 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7639 goto nla_put_failure
;
7641 if (nl80211_send_wowlan_tcp(msg
,
7642 rdev
->wiphy
.wowlan_config
->tcp
))
7643 goto nla_put_failure
;
7645 nla_nest_end(msg
, nl_wowlan
);
7648 genlmsg_end(msg
, hdr
);
7649 return genlmsg_reply(msg
, info
);
7656 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7657 struct nlattr
*attr
,
7658 struct cfg80211_wowlan
*trig
)
7660 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7661 struct cfg80211_wowlan_tcp
*cfg
;
7662 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7663 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7665 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7668 if (!rdev
->wiphy
.wowlan
.tcp
)
7671 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7672 nla_data(attr
), nla_len(attr
),
7673 nl80211_wowlan_tcp_policy
);
7677 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7678 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7679 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7680 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7681 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7682 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7683 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7684 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7687 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7688 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7691 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7692 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
||
7693 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7696 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7697 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7700 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7701 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7704 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7705 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7707 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7708 tokens_size
= tokln
- sizeof(*tok
);
7710 if (!tok
->len
|| tokens_size
% tok
->len
)
7712 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7714 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7716 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7718 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7720 if (tok
->offset
+ tok
->len
> data_size
)
7724 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7725 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7726 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7728 if (seq
->len
== 0 || seq
->len
> 4)
7730 if (seq
->len
+ seq
->offset
> data_size
)
7734 size
= sizeof(*cfg
);
7736 size
+= wake_size
+ wake_mask_size
;
7737 size
+= tokens_size
;
7739 cfg
= kzalloc(size
, GFP_KERNEL
);
7742 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7743 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7744 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7746 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7747 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7751 /* allocate a socket and port for it and use it */
7752 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7753 IPPROTO_TCP
, &cfg
->sock
, 1);
7758 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7759 sock_release(cfg
->sock
);
7763 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7769 cfg
->src_port
= port
;
7772 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7773 cfg
->payload_len
= data_size
;
7774 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7775 memcpy((void *)cfg
->payload
,
7776 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7779 cfg
->payload_seq
= *seq
;
7780 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7781 cfg
->wake_len
= wake_size
;
7782 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7783 memcpy((void *)cfg
->wake_data
,
7784 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7786 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7787 data_size
+ wake_size
;
7788 memcpy((void *)cfg
->wake_mask
,
7789 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7792 cfg
->tokens_size
= tokens_size
;
7793 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7801 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7803 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7804 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7805 struct cfg80211_wowlan new_triggers
= {};
7806 struct cfg80211_wowlan
*ntrig
;
7807 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7809 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
7811 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7812 !rdev
->wiphy
.wowlan
.tcp
)
7815 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7816 cfg80211_rdev_free_wowlan(rdev
);
7817 rdev
->wiphy
.wowlan_config
= NULL
;
7821 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7822 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7823 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7824 nl80211_wowlan_policy
);
7828 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7829 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7831 new_triggers
.any
= true;
7834 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7835 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7837 new_triggers
.disconnect
= true;
7840 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7841 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7843 new_triggers
.magic_pkt
= true;
7846 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7849 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7850 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7852 new_triggers
.gtk_rekey_failure
= true;
7855 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7856 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7858 new_triggers
.eap_identity_req
= true;
7861 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7862 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7864 new_triggers
.four_way_handshake
= true;
7867 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7868 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7870 new_triggers
.rfkill_release
= true;
7873 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7876 int rem
, pat_len
, mask_len
, pkt_offset
;
7877 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7879 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7882 if (n_patterns
> wowlan
->n_patterns
)
7885 new_triggers
.patterns
= kcalloc(n_patterns
,
7886 sizeof(new_triggers
.patterns
[0]),
7888 if (!new_triggers
.patterns
)
7891 new_triggers
.n_patterns
= n_patterns
;
7894 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7896 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7897 nla_data(pat
), nla_len(pat
), NULL
);
7899 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7900 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7902 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7903 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7904 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7907 if (pat_len
> wowlan
->pattern_max_len
||
7908 pat_len
< wowlan
->pattern_min_len
)
7911 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7914 pkt_offset
= nla_get_u32(
7915 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7916 if (pkt_offset
> wowlan
->max_pkt_offset
)
7918 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7920 new_triggers
.patterns
[i
].mask
=
7921 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7922 if (!new_triggers
.patterns
[i
].mask
) {
7926 new_triggers
.patterns
[i
].pattern
=
7927 new_triggers
.patterns
[i
].mask
+ mask_len
;
7928 memcpy(new_triggers
.patterns
[i
].mask
,
7929 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7931 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7932 memcpy(new_triggers
.patterns
[i
].pattern
,
7933 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
7939 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
7940 err
= nl80211_parse_wowlan_tcp(
7941 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
7947 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
7952 cfg80211_rdev_free_wowlan(rdev
);
7953 rdev
->wiphy
.wowlan_config
= ntrig
;
7956 if (rdev
->ops
->set_wakeup
&&
7957 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
7958 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
7962 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
7963 kfree(new_triggers
.patterns
[i
].mask
);
7964 kfree(new_triggers
.patterns
);
7965 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
7966 sock_release(new_triggers
.tcp
->sock
);
7967 kfree(new_triggers
.tcp
);
7972 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
7974 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7975 struct net_device
*dev
= info
->user_ptr
[1];
7976 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7977 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
7978 struct cfg80211_gtk_rekey_data rekey_data
;
7981 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
7984 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
7985 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
7986 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
7987 nl80211_rekey_policy
);
7991 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
7993 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
7995 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
7998 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8000 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8002 memcpy(rekey_data
.replay_ctr
,
8003 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8004 NL80211_REPLAY_CTR_LEN
);
8007 if (!wdev
->current_bss
) {
8012 if (!rdev
->ops
->set_rekey_data
) {
8017 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8023 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8024 struct genl_info
*info
)
8026 struct net_device
*dev
= info
->user_ptr
[1];
8027 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8029 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8030 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8033 if (wdev
->ap_unexpected_nlportid
)
8036 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8040 static int nl80211_probe_client(struct sk_buff
*skb
,
8041 struct genl_info
*info
)
8043 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8044 struct net_device
*dev
= info
->user_ptr
[1];
8045 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8046 struct sk_buff
*msg
;
8052 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8053 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8056 if (!info
->attrs
[NL80211_ATTR_MAC
])
8059 if (!rdev
->ops
->probe_client
)
8062 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8066 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8067 NL80211_CMD_PROBE_CLIENT
);
8074 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8076 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8080 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8081 goto nla_put_failure
;
8083 genlmsg_end(msg
, hdr
);
8085 return genlmsg_reply(msg
, info
);
8094 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8096 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8097 struct cfg80211_beacon_registration
*reg
, *nreg
;
8100 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8103 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8107 /* First, check if already registered. */
8108 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8109 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8110 if (reg
->nlportid
== info
->snd_portid
) {
8115 /* Add it to the list */
8116 nreg
->nlportid
= info
->snd_portid
;
8117 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8119 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8123 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8128 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8130 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8131 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8134 if (!rdev
->ops
->start_p2p_device
)
8137 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8140 if (wdev
->p2p_started
)
8143 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8147 err
= rdev_start_p2p_device(rdev
, wdev
);
8151 wdev
->p2p_started
= true;
8157 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8159 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8160 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8162 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8165 if (!rdev
->ops
->stop_p2p_device
)
8168 cfg80211_stop_p2p_device(rdev
, wdev
);
8173 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8174 struct genl_info
*info
)
8177 struct sk_buff
*msg
;
8179 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8183 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8184 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8186 goto nla_put_failure
;
8188 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8189 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8190 goto nla_put_failure
;
8192 genlmsg_end(msg
, hdr
);
8193 return genlmsg_reply(msg
, info
);
8200 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8202 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8203 struct cfg80211_update_ft_ies_params ft_params
;
8204 struct net_device
*dev
= info
->user_ptr
[1];
8206 if (!rdev
->ops
->update_ft_ies
)
8209 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8210 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8213 memset(&ft_params
, 0, sizeof(ft_params
));
8214 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8215 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8216 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8218 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8221 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8222 struct genl_info
*info
)
8224 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8225 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8226 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8230 if (!rdev
->ops
->crit_proto_start
)
8233 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8236 if (rdev
->crit_proto_nlportid
)
8239 /* determine protocol if provided */
8240 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8241 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8243 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8246 /* timeout must be provided */
8247 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8251 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8253 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8256 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8258 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8263 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8264 struct genl_info
*info
)
8266 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8267 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8269 if (!rdev
->ops
->crit_proto_stop
)
8272 if (rdev
->crit_proto_nlportid
) {
8273 rdev
->crit_proto_nlportid
= 0;
8274 rdev_crit_proto_stop(rdev
, wdev
);
8279 #define NL80211_FLAG_NEED_WIPHY 0x01
8280 #define NL80211_FLAG_NEED_NETDEV 0x02
8281 #define NL80211_FLAG_NEED_RTNL 0x04
8282 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8283 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8284 NL80211_FLAG_CHECK_NETDEV_UP)
8285 #define NL80211_FLAG_NEED_WDEV 0x10
8286 /* If a netdev is associated, it must be UP, P2P must be started */
8287 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8288 NL80211_FLAG_CHECK_NETDEV_UP)
8290 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8291 struct genl_info
*info
)
8293 struct cfg80211_registered_device
*rdev
;
8294 struct wireless_dev
*wdev
;
8295 struct net_device
*dev
;
8296 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8301 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8302 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8306 return PTR_ERR(rdev
);
8308 info
->user_ptr
[0] = rdev
;
8309 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8310 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8313 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8318 return PTR_ERR(wdev
);
8322 rdev
= wiphy_to_dev(wdev
->wiphy
);
8324 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8331 info
->user_ptr
[1] = dev
;
8333 info
->user_ptr
[1] = wdev
;
8337 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8338 !netif_running(dev
)) {
8345 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8346 if (!wdev
->p2p_started
) {
8353 info
->user_ptr
[0] = rdev
;
8359 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8360 struct genl_info
*info
)
8362 if (info
->user_ptr
[1]) {
8363 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8364 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8367 dev_put(wdev
->netdev
);
8369 dev_put(info
->user_ptr
[1]);
8372 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8376 static struct genl_ops nl80211_ops
[] = {
8378 .cmd
= NL80211_CMD_GET_WIPHY
,
8379 .doit
= nl80211_get_wiphy
,
8380 .dumpit
= nl80211_dump_wiphy
,
8381 .policy
= nl80211_policy
,
8382 /* can be retrieved by unprivileged users */
8383 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8384 NL80211_FLAG_NEED_RTNL
,
8387 .cmd
= NL80211_CMD_SET_WIPHY
,
8388 .doit
= nl80211_set_wiphy
,
8389 .policy
= nl80211_policy
,
8390 .flags
= GENL_ADMIN_PERM
,
8391 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8394 .cmd
= NL80211_CMD_GET_INTERFACE
,
8395 .doit
= nl80211_get_interface
,
8396 .dumpit
= nl80211_dump_interface
,
8397 .policy
= nl80211_policy
,
8398 /* can be retrieved by unprivileged users */
8399 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8400 NL80211_FLAG_NEED_RTNL
,
8403 .cmd
= NL80211_CMD_SET_INTERFACE
,
8404 .doit
= nl80211_set_interface
,
8405 .policy
= nl80211_policy
,
8406 .flags
= GENL_ADMIN_PERM
,
8407 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8408 NL80211_FLAG_NEED_RTNL
,
8411 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8412 .doit
= nl80211_new_interface
,
8413 .policy
= nl80211_policy
,
8414 .flags
= GENL_ADMIN_PERM
,
8415 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8416 NL80211_FLAG_NEED_RTNL
,
8419 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8420 .doit
= nl80211_del_interface
,
8421 .policy
= nl80211_policy
,
8422 .flags
= GENL_ADMIN_PERM
,
8423 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8424 NL80211_FLAG_NEED_RTNL
,
8427 .cmd
= NL80211_CMD_GET_KEY
,
8428 .doit
= nl80211_get_key
,
8429 .policy
= nl80211_policy
,
8430 .flags
= GENL_ADMIN_PERM
,
8431 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8432 NL80211_FLAG_NEED_RTNL
,
8435 .cmd
= NL80211_CMD_SET_KEY
,
8436 .doit
= nl80211_set_key
,
8437 .policy
= nl80211_policy
,
8438 .flags
= GENL_ADMIN_PERM
,
8439 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8440 NL80211_FLAG_NEED_RTNL
,
8443 .cmd
= NL80211_CMD_NEW_KEY
,
8444 .doit
= nl80211_new_key
,
8445 .policy
= nl80211_policy
,
8446 .flags
= GENL_ADMIN_PERM
,
8447 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8448 NL80211_FLAG_NEED_RTNL
,
8451 .cmd
= NL80211_CMD_DEL_KEY
,
8452 .doit
= nl80211_del_key
,
8453 .policy
= nl80211_policy
,
8454 .flags
= GENL_ADMIN_PERM
,
8455 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8456 NL80211_FLAG_NEED_RTNL
,
8459 .cmd
= NL80211_CMD_SET_BEACON
,
8460 .policy
= nl80211_policy
,
8461 .flags
= GENL_ADMIN_PERM
,
8462 .doit
= nl80211_set_beacon
,
8463 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8464 NL80211_FLAG_NEED_RTNL
,
8467 .cmd
= NL80211_CMD_START_AP
,
8468 .policy
= nl80211_policy
,
8469 .flags
= GENL_ADMIN_PERM
,
8470 .doit
= nl80211_start_ap
,
8471 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8472 NL80211_FLAG_NEED_RTNL
,
8475 .cmd
= NL80211_CMD_STOP_AP
,
8476 .policy
= nl80211_policy
,
8477 .flags
= GENL_ADMIN_PERM
,
8478 .doit
= nl80211_stop_ap
,
8479 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8480 NL80211_FLAG_NEED_RTNL
,
8483 .cmd
= NL80211_CMD_GET_STATION
,
8484 .doit
= nl80211_get_station
,
8485 .dumpit
= nl80211_dump_station
,
8486 .policy
= nl80211_policy
,
8487 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8488 NL80211_FLAG_NEED_RTNL
,
8491 .cmd
= NL80211_CMD_SET_STATION
,
8492 .doit
= nl80211_set_station
,
8493 .policy
= nl80211_policy
,
8494 .flags
= GENL_ADMIN_PERM
,
8495 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8496 NL80211_FLAG_NEED_RTNL
,
8499 .cmd
= NL80211_CMD_NEW_STATION
,
8500 .doit
= nl80211_new_station
,
8501 .policy
= nl80211_policy
,
8502 .flags
= GENL_ADMIN_PERM
,
8503 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8504 NL80211_FLAG_NEED_RTNL
,
8507 .cmd
= NL80211_CMD_DEL_STATION
,
8508 .doit
= nl80211_del_station
,
8509 .policy
= nl80211_policy
,
8510 .flags
= GENL_ADMIN_PERM
,
8511 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8512 NL80211_FLAG_NEED_RTNL
,
8515 .cmd
= NL80211_CMD_GET_MPATH
,
8516 .doit
= nl80211_get_mpath
,
8517 .dumpit
= nl80211_dump_mpath
,
8518 .policy
= nl80211_policy
,
8519 .flags
= GENL_ADMIN_PERM
,
8520 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8521 NL80211_FLAG_NEED_RTNL
,
8524 .cmd
= NL80211_CMD_SET_MPATH
,
8525 .doit
= nl80211_set_mpath
,
8526 .policy
= nl80211_policy
,
8527 .flags
= GENL_ADMIN_PERM
,
8528 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8529 NL80211_FLAG_NEED_RTNL
,
8532 .cmd
= NL80211_CMD_NEW_MPATH
,
8533 .doit
= nl80211_new_mpath
,
8534 .policy
= nl80211_policy
,
8535 .flags
= GENL_ADMIN_PERM
,
8536 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8537 NL80211_FLAG_NEED_RTNL
,
8540 .cmd
= NL80211_CMD_DEL_MPATH
,
8541 .doit
= nl80211_del_mpath
,
8542 .policy
= nl80211_policy
,
8543 .flags
= GENL_ADMIN_PERM
,
8544 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8545 NL80211_FLAG_NEED_RTNL
,
8548 .cmd
= NL80211_CMD_SET_BSS
,
8549 .doit
= nl80211_set_bss
,
8550 .policy
= nl80211_policy
,
8551 .flags
= GENL_ADMIN_PERM
,
8552 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8553 NL80211_FLAG_NEED_RTNL
,
8556 .cmd
= NL80211_CMD_GET_REG
,
8557 .doit
= nl80211_get_reg
,
8558 .policy
= nl80211_policy
,
8559 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8560 /* can be retrieved by unprivileged users */
8563 .cmd
= NL80211_CMD_SET_REG
,
8564 .doit
= nl80211_set_reg
,
8565 .policy
= nl80211_policy
,
8566 .flags
= GENL_ADMIN_PERM
,
8567 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8570 .cmd
= NL80211_CMD_REQ_SET_REG
,
8571 .doit
= nl80211_req_set_reg
,
8572 .policy
= nl80211_policy
,
8573 .flags
= GENL_ADMIN_PERM
,
8576 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8577 .doit
= nl80211_get_mesh_config
,
8578 .policy
= nl80211_policy
,
8579 /* can be retrieved by unprivileged users */
8580 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8581 NL80211_FLAG_NEED_RTNL
,
8584 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8585 .doit
= nl80211_update_mesh_config
,
8586 .policy
= nl80211_policy
,
8587 .flags
= GENL_ADMIN_PERM
,
8588 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8589 NL80211_FLAG_NEED_RTNL
,
8592 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8593 .doit
= nl80211_trigger_scan
,
8594 .policy
= nl80211_policy
,
8595 .flags
= GENL_ADMIN_PERM
,
8596 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8597 NL80211_FLAG_NEED_RTNL
,
8600 .cmd
= NL80211_CMD_GET_SCAN
,
8601 .policy
= nl80211_policy
,
8602 .dumpit
= nl80211_dump_scan
,
8605 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8606 .doit
= nl80211_start_sched_scan
,
8607 .policy
= nl80211_policy
,
8608 .flags
= GENL_ADMIN_PERM
,
8609 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8610 NL80211_FLAG_NEED_RTNL
,
8613 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8614 .doit
= nl80211_stop_sched_scan
,
8615 .policy
= nl80211_policy
,
8616 .flags
= GENL_ADMIN_PERM
,
8617 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8618 NL80211_FLAG_NEED_RTNL
,
8621 .cmd
= NL80211_CMD_AUTHENTICATE
,
8622 .doit
= nl80211_authenticate
,
8623 .policy
= nl80211_policy
,
8624 .flags
= GENL_ADMIN_PERM
,
8625 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8626 NL80211_FLAG_NEED_RTNL
,
8629 .cmd
= NL80211_CMD_ASSOCIATE
,
8630 .doit
= nl80211_associate
,
8631 .policy
= nl80211_policy
,
8632 .flags
= GENL_ADMIN_PERM
,
8633 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8634 NL80211_FLAG_NEED_RTNL
,
8637 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8638 .doit
= nl80211_deauthenticate
,
8639 .policy
= nl80211_policy
,
8640 .flags
= GENL_ADMIN_PERM
,
8641 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8642 NL80211_FLAG_NEED_RTNL
,
8645 .cmd
= NL80211_CMD_DISASSOCIATE
,
8646 .doit
= nl80211_disassociate
,
8647 .policy
= nl80211_policy
,
8648 .flags
= GENL_ADMIN_PERM
,
8649 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8650 NL80211_FLAG_NEED_RTNL
,
8653 .cmd
= NL80211_CMD_JOIN_IBSS
,
8654 .doit
= nl80211_join_ibss
,
8655 .policy
= nl80211_policy
,
8656 .flags
= GENL_ADMIN_PERM
,
8657 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8658 NL80211_FLAG_NEED_RTNL
,
8661 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8662 .doit
= nl80211_leave_ibss
,
8663 .policy
= nl80211_policy
,
8664 .flags
= GENL_ADMIN_PERM
,
8665 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8666 NL80211_FLAG_NEED_RTNL
,
8668 #ifdef CONFIG_NL80211_TESTMODE
8670 .cmd
= NL80211_CMD_TESTMODE
,
8671 .doit
= nl80211_testmode_do
,
8672 .dumpit
= nl80211_testmode_dump
,
8673 .policy
= nl80211_policy
,
8674 .flags
= GENL_ADMIN_PERM
,
8675 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8676 NL80211_FLAG_NEED_RTNL
,
8680 .cmd
= NL80211_CMD_CONNECT
,
8681 .doit
= nl80211_connect
,
8682 .policy
= nl80211_policy
,
8683 .flags
= GENL_ADMIN_PERM
,
8684 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8685 NL80211_FLAG_NEED_RTNL
,
8688 .cmd
= NL80211_CMD_DISCONNECT
,
8689 .doit
= nl80211_disconnect
,
8690 .policy
= nl80211_policy
,
8691 .flags
= GENL_ADMIN_PERM
,
8692 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8693 NL80211_FLAG_NEED_RTNL
,
8696 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8697 .doit
= nl80211_wiphy_netns
,
8698 .policy
= nl80211_policy
,
8699 .flags
= GENL_ADMIN_PERM
,
8700 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8701 NL80211_FLAG_NEED_RTNL
,
8704 .cmd
= NL80211_CMD_GET_SURVEY
,
8705 .policy
= nl80211_policy
,
8706 .dumpit
= nl80211_dump_survey
,
8709 .cmd
= NL80211_CMD_SET_PMKSA
,
8710 .doit
= nl80211_setdel_pmksa
,
8711 .policy
= nl80211_policy
,
8712 .flags
= GENL_ADMIN_PERM
,
8713 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8714 NL80211_FLAG_NEED_RTNL
,
8717 .cmd
= NL80211_CMD_DEL_PMKSA
,
8718 .doit
= nl80211_setdel_pmksa
,
8719 .policy
= nl80211_policy
,
8720 .flags
= GENL_ADMIN_PERM
,
8721 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8722 NL80211_FLAG_NEED_RTNL
,
8725 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8726 .doit
= nl80211_flush_pmksa
,
8727 .policy
= nl80211_policy
,
8728 .flags
= GENL_ADMIN_PERM
,
8729 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8730 NL80211_FLAG_NEED_RTNL
,
8733 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8734 .doit
= nl80211_remain_on_channel
,
8735 .policy
= nl80211_policy
,
8736 .flags
= GENL_ADMIN_PERM
,
8737 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8738 NL80211_FLAG_NEED_RTNL
,
8741 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8742 .doit
= nl80211_cancel_remain_on_channel
,
8743 .policy
= nl80211_policy
,
8744 .flags
= GENL_ADMIN_PERM
,
8745 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8746 NL80211_FLAG_NEED_RTNL
,
8749 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8750 .doit
= nl80211_set_tx_bitrate_mask
,
8751 .policy
= nl80211_policy
,
8752 .flags
= GENL_ADMIN_PERM
,
8753 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8754 NL80211_FLAG_NEED_RTNL
,
8757 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8758 .doit
= nl80211_register_mgmt
,
8759 .policy
= nl80211_policy
,
8760 .flags
= GENL_ADMIN_PERM
,
8761 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8762 NL80211_FLAG_NEED_RTNL
,
8765 .cmd
= NL80211_CMD_FRAME
,
8766 .doit
= nl80211_tx_mgmt
,
8767 .policy
= nl80211_policy
,
8768 .flags
= GENL_ADMIN_PERM
,
8769 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8770 NL80211_FLAG_NEED_RTNL
,
8773 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8774 .doit
= nl80211_tx_mgmt_cancel_wait
,
8775 .policy
= nl80211_policy
,
8776 .flags
= GENL_ADMIN_PERM
,
8777 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8778 NL80211_FLAG_NEED_RTNL
,
8781 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8782 .doit
= nl80211_set_power_save
,
8783 .policy
= nl80211_policy
,
8784 .flags
= GENL_ADMIN_PERM
,
8785 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8786 NL80211_FLAG_NEED_RTNL
,
8789 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8790 .doit
= nl80211_get_power_save
,
8791 .policy
= nl80211_policy
,
8792 /* can be retrieved by unprivileged users */
8793 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8794 NL80211_FLAG_NEED_RTNL
,
8797 .cmd
= NL80211_CMD_SET_CQM
,
8798 .doit
= nl80211_set_cqm
,
8799 .policy
= nl80211_policy
,
8800 .flags
= GENL_ADMIN_PERM
,
8801 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8802 NL80211_FLAG_NEED_RTNL
,
8805 .cmd
= NL80211_CMD_SET_CHANNEL
,
8806 .doit
= nl80211_set_channel
,
8807 .policy
= nl80211_policy
,
8808 .flags
= GENL_ADMIN_PERM
,
8809 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8810 NL80211_FLAG_NEED_RTNL
,
8813 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8814 .doit
= nl80211_set_wds_peer
,
8815 .policy
= nl80211_policy
,
8816 .flags
= GENL_ADMIN_PERM
,
8817 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8818 NL80211_FLAG_NEED_RTNL
,
8821 .cmd
= NL80211_CMD_JOIN_MESH
,
8822 .doit
= nl80211_join_mesh
,
8823 .policy
= nl80211_policy
,
8824 .flags
= GENL_ADMIN_PERM
,
8825 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8826 NL80211_FLAG_NEED_RTNL
,
8829 .cmd
= NL80211_CMD_LEAVE_MESH
,
8830 .doit
= nl80211_leave_mesh
,
8831 .policy
= nl80211_policy
,
8832 .flags
= GENL_ADMIN_PERM
,
8833 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8834 NL80211_FLAG_NEED_RTNL
,
8838 .cmd
= NL80211_CMD_GET_WOWLAN
,
8839 .doit
= nl80211_get_wowlan
,
8840 .policy
= nl80211_policy
,
8841 /* can be retrieved by unprivileged users */
8842 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8843 NL80211_FLAG_NEED_RTNL
,
8846 .cmd
= NL80211_CMD_SET_WOWLAN
,
8847 .doit
= nl80211_set_wowlan
,
8848 .policy
= nl80211_policy
,
8849 .flags
= GENL_ADMIN_PERM
,
8850 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8851 NL80211_FLAG_NEED_RTNL
,
8855 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
8856 .doit
= nl80211_set_rekey_data
,
8857 .policy
= nl80211_policy
,
8858 .flags
= GENL_ADMIN_PERM
,
8859 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8860 NL80211_FLAG_NEED_RTNL
,
8863 .cmd
= NL80211_CMD_TDLS_MGMT
,
8864 .doit
= nl80211_tdls_mgmt
,
8865 .policy
= nl80211_policy
,
8866 .flags
= GENL_ADMIN_PERM
,
8867 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8868 NL80211_FLAG_NEED_RTNL
,
8871 .cmd
= NL80211_CMD_TDLS_OPER
,
8872 .doit
= nl80211_tdls_oper
,
8873 .policy
= nl80211_policy
,
8874 .flags
= GENL_ADMIN_PERM
,
8875 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8876 NL80211_FLAG_NEED_RTNL
,
8879 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
8880 .doit
= nl80211_register_unexpected_frame
,
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_PROBE_CLIENT
,
8888 .doit
= nl80211_probe_client
,
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_REGISTER_BEACONS
,
8896 .doit
= nl80211_register_beacons
,
8897 .policy
= nl80211_policy
,
8898 .flags
= GENL_ADMIN_PERM
,
8899 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8900 NL80211_FLAG_NEED_RTNL
,
8903 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
8904 .doit
= nl80211_set_noack_map
,
8905 .policy
= nl80211_policy
,
8906 .flags
= GENL_ADMIN_PERM
,
8907 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8908 NL80211_FLAG_NEED_RTNL
,
8911 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
8912 .doit
= nl80211_start_p2p_device
,
8913 .policy
= nl80211_policy
,
8914 .flags
= GENL_ADMIN_PERM
,
8915 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8916 NL80211_FLAG_NEED_RTNL
,
8919 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
8920 .doit
= nl80211_stop_p2p_device
,
8921 .policy
= nl80211_policy
,
8922 .flags
= GENL_ADMIN_PERM
,
8923 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8924 NL80211_FLAG_NEED_RTNL
,
8927 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
8928 .doit
= nl80211_set_mcast_rate
,
8929 .policy
= nl80211_policy
,
8930 .flags
= GENL_ADMIN_PERM
,
8931 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8932 NL80211_FLAG_NEED_RTNL
,
8935 .cmd
= NL80211_CMD_SET_MAC_ACL
,
8936 .doit
= nl80211_set_mac_acl
,
8937 .policy
= nl80211_policy
,
8938 .flags
= GENL_ADMIN_PERM
,
8939 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8940 NL80211_FLAG_NEED_RTNL
,
8943 .cmd
= NL80211_CMD_RADAR_DETECT
,
8944 .doit
= nl80211_start_radar_detection
,
8945 .policy
= nl80211_policy
,
8946 .flags
= GENL_ADMIN_PERM
,
8947 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8948 NL80211_FLAG_NEED_RTNL
,
8951 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
8952 .doit
= nl80211_get_protocol_features
,
8953 .policy
= nl80211_policy
,
8956 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
8957 .doit
= nl80211_update_ft_ies
,
8958 .policy
= nl80211_policy
,
8959 .flags
= GENL_ADMIN_PERM
,
8960 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8961 NL80211_FLAG_NEED_RTNL
,
8964 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
8965 .doit
= nl80211_crit_protocol_start
,
8966 .policy
= nl80211_policy
,
8967 .flags
= GENL_ADMIN_PERM
,
8968 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8969 NL80211_FLAG_NEED_RTNL
,
8972 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
8973 .doit
= nl80211_crit_protocol_stop
,
8974 .policy
= nl80211_policy
,
8975 .flags
= GENL_ADMIN_PERM
,
8976 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8977 NL80211_FLAG_NEED_RTNL
,
8981 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
8985 /* multicast groups */
8986 static struct genl_multicast_group nl80211_config_mcgrp
= {
8989 static struct genl_multicast_group nl80211_scan_mcgrp
= {
8992 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
8993 .name
= "regulatory",
8996 /* notification functions */
8998 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9000 struct sk_buff
*msg
;
9002 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9006 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0,
9007 false, NULL
, NULL
, NULL
) < 0) {
9012 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9013 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9016 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9017 struct cfg80211_registered_device
*rdev
)
9019 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9020 struct nlattr
*nest
;
9026 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9028 goto nla_put_failure
;
9029 for (i
= 0; i
< req
->n_ssids
; i
++) {
9030 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9031 goto nla_put_failure
;
9033 nla_nest_end(msg
, nest
);
9035 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9037 goto nla_put_failure
;
9038 for (i
= 0; i
< req
->n_channels
; i
++) {
9039 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9040 goto nla_put_failure
;
9042 nla_nest_end(msg
, nest
);
9045 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9046 goto nla_put_failure
;
9049 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9056 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9057 struct cfg80211_registered_device
*rdev
,
9058 struct wireless_dev
*wdev
,
9059 u32 portid
, u32 seq
, int flags
,
9064 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9068 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9069 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9070 wdev
->netdev
->ifindex
)) ||
9071 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9072 goto nla_put_failure
;
9074 /* ignore errors and send incomplete event anyway */
9075 nl80211_add_scan_req(msg
, rdev
);
9077 return genlmsg_end(msg
, hdr
);
9080 genlmsg_cancel(msg
, hdr
);
9085 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9086 struct cfg80211_registered_device
*rdev
,
9087 struct net_device
*netdev
,
9088 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9092 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9096 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9097 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9098 goto nla_put_failure
;
9100 return genlmsg_end(msg
, hdr
);
9103 genlmsg_cancel(msg
, hdr
);
9107 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9108 struct wireless_dev
*wdev
)
9110 struct sk_buff
*msg
;
9112 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9116 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9117 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9122 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9123 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9126 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9127 struct wireless_dev
*wdev
)
9129 struct sk_buff
*msg
;
9131 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9135 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9136 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9141 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9142 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9145 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9146 struct wireless_dev
*wdev
)
9148 struct sk_buff
*msg
;
9150 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9154 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9155 NL80211_CMD_SCAN_ABORTED
) < 0) {
9160 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9161 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9164 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9165 struct net_device
*netdev
)
9167 struct sk_buff
*msg
;
9169 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9173 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9174 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9179 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9180 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9183 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9184 struct net_device
*netdev
, u32 cmd
)
9186 struct sk_buff
*msg
;
9188 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9192 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9197 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9198 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9202 * This can happen on global regulatory changes or device specific settings
9203 * based on custom world regulatory domains.
9205 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9207 struct sk_buff
*msg
;
9210 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9214 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9220 /* Userspace can always count this one always being set */
9221 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9222 goto nla_put_failure
;
9224 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9225 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9226 NL80211_REGDOM_TYPE_WORLD
))
9227 goto nla_put_failure
;
9228 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9229 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9230 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9231 goto nla_put_failure
;
9232 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9233 request
->intersect
) {
9234 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9235 NL80211_REGDOM_TYPE_INTERSECTION
))
9236 goto nla_put_failure
;
9238 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9239 NL80211_REGDOM_TYPE_COUNTRY
) ||
9240 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9242 goto nla_put_failure
;
9245 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9246 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9247 goto nla_put_failure
;
9249 genlmsg_end(msg
, hdr
);
9252 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9259 genlmsg_cancel(msg
, hdr
);
9263 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9264 struct net_device
*netdev
,
9265 const u8
*buf
, size_t len
,
9266 enum nl80211_commands cmd
, gfp_t gfp
)
9268 struct sk_buff
*msg
;
9271 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9275 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9281 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9282 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9283 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9284 goto nla_put_failure
;
9286 genlmsg_end(msg
, hdr
);
9288 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9289 nl80211_mlme_mcgrp
.id
, gfp
);
9293 genlmsg_cancel(msg
, hdr
);
9297 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9298 struct net_device
*netdev
, const u8
*buf
,
9299 size_t len
, gfp_t gfp
)
9301 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9302 NL80211_CMD_AUTHENTICATE
, gfp
);
9305 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9306 struct net_device
*netdev
, const u8
*buf
,
9307 size_t len
, gfp_t gfp
)
9309 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9310 NL80211_CMD_ASSOCIATE
, gfp
);
9313 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9314 struct net_device
*netdev
, const u8
*buf
,
9315 size_t len
, gfp_t gfp
)
9317 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9318 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9321 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9322 struct net_device
*netdev
, const u8
*buf
,
9323 size_t len
, gfp_t gfp
)
9325 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9326 NL80211_CMD_DISASSOCIATE
, gfp
);
9329 void cfg80211_send_unprot_deauth(struct net_device
*dev
, const u8
*buf
,
9332 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9333 struct wiphy
*wiphy
= wdev
->wiphy
;
9334 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9336 trace_cfg80211_send_unprot_deauth(dev
);
9337 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9338 NL80211_CMD_UNPROT_DEAUTHENTICATE
, GFP_ATOMIC
);
9340 EXPORT_SYMBOL(cfg80211_send_unprot_deauth
);
9342 void cfg80211_send_unprot_disassoc(struct net_device
*dev
, const u8
*buf
,
9345 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9346 struct wiphy
*wiphy
= wdev
->wiphy
;
9347 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9349 trace_cfg80211_send_unprot_disassoc(dev
);
9350 nl80211_send_mlme_event(rdev
, dev
, buf
, len
,
9351 NL80211_CMD_UNPROT_DISASSOCIATE
, GFP_ATOMIC
);
9353 EXPORT_SYMBOL(cfg80211_send_unprot_disassoc
);
9355 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9356 struct net_device
*netdev
, int cmd
,
9357 const u8
*addr
, gfp_t gfp
)
9359 struct sk_buff
*msg
;
9362 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9366 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9372 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9373 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9374 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9375 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9376 goto nla_put_failure
;
9378 genlmsg_end(msg
, hdr
);
9380 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9381 nl80211_mlme_mcgrp
.id
, gfp
);
9385 genlmsg_cancel(msg
, hdr
);
9389 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9390 struct net_device
*netdev
, const u8
*addr
,
9393 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9397 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9398 struct net_device
*netdev
, const u8
*addr
,
9401 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9405 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9406 struct net_device
*netdev
, const u8
*bssid
,
9407 const u8
*req_ie
, size_t req_ie_len
,
9408 const u8
*resp_ie
, size_t resp_ie_len
,
9409 u16 status
, gfp_t gfp
)
9411 struct sk_buff
*msg
;
9414 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9418 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9424 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9425 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9426 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9427 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9429 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9431 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9432 goto nla_put_failure
;
9434 genlmsg_end(msg
, hdr
);
9436 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9437 nl80211_mlme_mcgrp
.id
, gfp
);
9441 genlmsg_cancel(msg
, hdr
);
9446 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9447 struct net_device
*netdev
, const u8
*bssid
,
9448 const u8
*req_ie
, size_t req_ie_len
,
9449 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9451 struct sk_buff
*msg
;
9454 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9458 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9464 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9465 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9466 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9468 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9470 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9471 goto nla_put_failure
;
9473 genlmsg_end(msg
, hdr
);
9475 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9476 nl80211_mlme_mcgrp
.id
, gfp
);
9480 genlmsg_cancel(msg
, hdr
);
9485 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9486 struct net_device
*netdev
, u16 reason
,
9487 const u8
*ie
, size_t ie_len
, bool from_ap
)
9489 struct sk_buff
*msg
;
9492 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9496 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9502 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9503 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9504 (from_ap
&& reason
&&
9505 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9507 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9508 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9509 goto nla_put_failure
;
9511 genlmsg_end(msg
, hdr
);
9513 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9514 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9518 genlmsg_cancel(msg
, hdr
);
9523 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9524 struct net_device
*netdev
, const u8
*bssid
,
9527 struct sk_buff
*msg
;
9530 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9534 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9540 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9541 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9542 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9543 goto nla_put_failure
;
9545 genlmsg_end(msg
, hdr
);
9547 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9548 nl80211_mlme_mcgrp
.id
, gfp
);
9552 genlmsg_cancel(msg
, hdr
);
9556 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9557 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9559 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9560 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9561 struct sk_buff
*msg
;
9564 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9567 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9569 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9573 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9579 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9580 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9581 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9583 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9584 goto nla_put_failure
;
9586 genlmsg_end(msg
, hdr
);
9588 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9589 nl80211_mlme_mcgrp
.id
, gfp
);
9593 genlmsg_cancel(msg
, hdr
);
9596 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9598 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9599 struct net_device
*netdev
, const u8
*addr
,
9600 enum nl80211_key_type key_type
, int key_id
,
9601 const u8
*tsc
, gfp_t gfp
)
9603 struct sk_buff
*msg
;
9606 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9610 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9616 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9617 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9618 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9619 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9621 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9622 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9623 goto nla_put_failure
;
9625 genlmsg_end(msg
, hdr
);
9627 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9628 nl80211_mlme_mcgrp
.id
, gfp
);
9632 genlmsg_cancel(msg
, hdr
);
9636 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9637 struct ieee80211_channel
*channel_before
,
9638 struct ieee80211_channel
*channel_after
)
9640 struct sk_buff
*msg
;
9642 struct nlattr
*nl_freq
;
9644 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9648 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9655 * Since we are applying the beacon hint to a wiphy we know its
9656 * wiphy_idx is valid
9658 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9659 goto nla_put_failure
;
9662 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9664 goto nla_put_failure
;
9665 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9666 goto nla_put_failure
;
9667 nla_nest_end(msg
, nl_freq
);
9670 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9672 goto nla_put_failure
;
9673 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9674 goto nla_put_failure
;
9675 nla_nest_end(msg
, nl_freq
);
9677 genlmsg_end(msg
, hdr
);
9680 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9687 genlmsg_cancel(msg
, hdr
);
9691 static void nl80211_send_remain_on_chan_event(
9692 int cmd
, struct cfg80211_registered_device
*rdev
,
9693 struct wireless_dev
*wdev
, u64 cookie
,
9694 struct ieee80211_channel
*chan
,
9695 unsigned int duration
, gfp_t gfp
)
9697 struct sk_buff
*msg
;
9700 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9704 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9710 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9711 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9712 wdev
->netdev
->ifindex
)) ||
9713 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9714 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9715 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9716 NL80211_CHAN_NO_HT
) ||
9717 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9718 goto nla_put_failure
;
9720 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9721 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9722 goto nla_put_failure
;
9724 genlmsg_end(msg
, hdr
);
9726 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9727 nl80211_mlme_mcgrp
.id
, gfp
);
9731 genlmsg_cancel(msg
, hdr
);
9735 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9736 struct ieee80211_channel
*chan
,
9737 unsigned int duration
, gfp_t gfp
)
9739 struct wiphy
*wiphy
= wdev
->wiphy
;
9740 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9742 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9743 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9744 rdev
, wdev
, cookie
, chan
,
9747 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9749 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9750 struct ieee80211_channel
*chan
,
9753 struct wiphy
*wiphy
= wdev
->wiphy
;
9754 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9756 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9757 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9758 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9760 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9762 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9763 struct station_info
*sinfo
, gfp_t gfp
)
9765 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9766 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9767 struct sk_buff
*msg
;
9769 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9771 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9775 if (nl80211_send_station(msg
, 0, 0, 0,
9776 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9781 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9782 nl80211_mlme_mcgrp
.id
, gfp
);
9784 EXPORT_SYMBOL(cfg80211_new_sta
);
9786 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9788 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9789 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9790 struct sk_buff
*msg
;
9793 trace_cfg80211_del_sta(dev
, mac_addr
);
9795 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9799 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9805 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9806 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9807 goto nla_put_failure
;
9809 genlmsg_end(msg
, hdr
);
9811 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9812 nl80211_mlme_mcgrp
.id
, gfp
);
9816 genlmsg_cancel(msg
, hdr
);
9819 EXPORT_SYMBOL(cfg80211_del_sta
);
9821 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
9822 enum nl80211_connect_failed_reason reason
,
9825 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9826 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9827 struct sk_buff
*msg
;
9830 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
9834 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
9840 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9841 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
9842 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
9843 goto nla_put_failure
;
9845 genlmsg_end(msg
, hdr
);
9847 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9848 nl80211_mlme_mcgrp
.id
, gfp
);
9852 genlmsg_cancel(msg
, hdr
);
9855 EXPORT_SYMBOL(cfg80211_conn_failed
);
9857 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
9858 const u8
*addr
, gfp_t gfp
)
9860 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9861 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9862 struct sk_buff
*msg
;
9865 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
9870 msg
= nlmsg_new(100, gfp
);
9874 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9880 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9881 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9882 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9883 goto nla_put_failure
;
9885 err
= genlmsg_end(msg
, hdr
);
9891 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9895 genlmsg_cancel(msg
, hdr
);
9900 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
9901 const u8
*addr
, gfp_t gfp
)
9903 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9906 trace_cfg80211_rx_spurious_frame(dev
, addr
);
9908 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9909 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
9910 trace_cfg80211_return_bool(false);
9913 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
9915 trace_cfg80211_return_bool(ret
);
9918 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
9920 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
9921 const u8
*addr
, gfp_t gfp
)
9923 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9926 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
9928 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9929 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
9930 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
9931 trace_cfg80211_return_bool(false);
9934 ret
= __nl80211_unexpected_frame(dev
,
9935 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
9937 trace_cfg80211_return_bool(ret
);
9940 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
9942 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
9943 struct wireless_dev
*wdev
, u32 nlportid
,
9944 int freq
, int sig_dbm
,
9945 const u8
*buf
, size_t len
, gfp_t gfp
)
9947 struct net_device
*netdev
= wdev
->netdev
;
9948 struct sk_buff
*msg
;
9951 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9955 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
9961 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9962 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9963 netdev
->ifindex
)) ||
9964 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9965 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
9967 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
9968 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9969 goto nla_put_failure
;
9971 genlmsg_end(msg
, hdr
);
9973 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9976 genlmsg_cancel(msg
, hdr
);
9981 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
9982 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
9984 struct wiphy
*wiphy
= wdev
->wiphy
;
9985 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9986 struct net_device
*netdev
= wdev
->netdev
;
9987 struct sk_buff
*msg
;
9990 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
9992 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9996 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10002 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10003 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10004 netdev
->ifindex
)) ||
10005 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10006 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10007 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10008 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10009 goto nla_put_failure
;
10011 genlmsg_end(msg
, hdr
);
10013 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
10017 genlmsg_cancel(msg
, hdr
);
10020 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10022 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10023 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10026 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10027 struct wiphy
*wiphy
= wdev
->wiphy
;
10028 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10029 struct sk_buff
*msg
;
10030 struct nlattr
*pinfoattr
;
10033 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10035 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10039 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10045 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10046 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10047 goto nla_put_failure
;
10049 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10051 goto nla_put_failure
;
10053 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10055 goto nla_put_failure
;
10057 nla_nest_end(msg
, pinfoattr
);
10059 genlmsg_end(msg
, hdr
);
10061 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10062 nl80211_mlme_mcgrp
.id
, gfp
);
10066 genlmsg_cancel(msg
, hdr
);
10069 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10071 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10072 struct net_device
*netdev
, const u8
*bssid
,
10073 const u8
*replay_ctr
, gfp_t gfp
)
10075 struct sk_buff
*msg
;
10076 struct nlattr
*rekey_attr
;
10079 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10083 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10089 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10090 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10091 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10092 goto nla_put_failure
;
10094 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10096 goto nla_put_failure
;
10098 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10099 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10100 goto nla_put_failure
;
10102 nla_nest_end(msg
, rekey_attr
);
10104 genlmsg_end(msg
, hdr
);
10106 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10107 nl80211_mlme_mcgrp
.id
, gfp
);
10111 genlmsg_cancel(msg
, hdr
);
10115 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10116 const u8
*replay_ctr
, gfp_t gfp
)
10118 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10119 struct wiphy
*wiphy
= wdev
->wiphy
;
10120 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10122 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10123 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10125 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10128 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10129 struct net_device
*netdev
, int index
,
10130 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10132 struct sk_buff
*msg
;
10133 struct nlattr
*attr
;
10136 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10140 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10146 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10147 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10148 goto nla_put_failure
;
10150 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10152 goto nla_put_failure
;
10154 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10155 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10157 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10158 goto nla_put_failure
;
10160 nla_nest_end(msg
, attr
);
10162 genlmsg_end(msg
, hdr
);
10164 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10165 nl80211_mlme_mcgrp
.id
, gfp
);
10169 genlmsg_cancel(msg
, hdr
);
10173 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10174 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10176 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10177 struct wiphy
*wiphy
= wdev
->wiphy
;
10178 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10180 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10181 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10183 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10185 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10186 struct net_device
*netdev
,
10187 struct cfg80211_chan_def
*chandef
,
10190 struct sk_buff
*msg
;
10193 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10197 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10203 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10204 goto nla_put_failure
;
10206 if (nl80211_send_chandef(msg
, chandef
))
10207 goto nla_put_failure
;
10209 genlmsg_end(msg
, hdr
);
10211 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10212 nl80211_mlme_mcgrp
.id
, gfp
);
10216 genlmsg_cancel(msg
, hdr
);
10220 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10221 struct cfg80211_chan_def
*chandef
)
10223 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10224 struct wiphy
*wiphy
= wdev
->wiphy
;
10225 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10227 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10231 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10232 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10235 wdev
->channel
= chandef
->chan
;
10236 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10241 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10243 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10244 const u8
*peer
, u32 num_packets
,
10245 u32 rate
, u32 intvl
, gfp_t gfp
)
10247 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10248 struct wiphy
*wiphy
= wdev
->wiphy
;
10249 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10250 struct sk_buff
*msg
;
10251 struct nlattr
*pinfoattr
;
10254 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10258 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10264 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10265 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10266 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10267 goto nla_put_failure
;
10269 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10271 goto nla_put_failure
;
10273 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10274 goto nla_put_failure
;
10276 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10277 goto nla_put_failure
;
10279 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10280 goto nla_put_failure
;
10282 nla_nest_end(msg
, pinfoattr
);
10284 genlmsg_end(msg
, hdr
);
10286 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10287 nl80211_mlme_mcgrp
.id
, gfp
);
10291 genlmsg_cancel(msg
, hdr
);
10294 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10297 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10298 struct cfg80211_chan_def
*chandef
,
10299 enum nl80211_radar_event event
,
10300 struct net_device
*netdev
, gfp_t gfp
)
10302 struct sk_buff
*msg
;
10305 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10309 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10315 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10316 goto nla_put_failure
;
10318 /* NOP and radar events don't need a netdev parameter */
10320 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10322 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10323 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10324 goto nla_put_failure
;
10327 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10328 goto nla_put_failure
;
10330 if (nl80211_send_chandef(msg
, chandef
))
10331 goto nla_put_failure
;
10333 if (genlmsg_end(msg
, hdr
) < 0) {
10338 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10339 nl80211_mlme_mcgrp
.id
, gfp
);
10343 genlmsg_cancel(msg
, hdr
);
10347 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10348 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10350 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10351 struct wiphy
*wiphy
= wdev
->wiphy
;
10352 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10353 struct sk_buff
*msg
;
10354 struct nlattr
*pinfoattr
;
10357 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10359 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10363 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10369 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10370 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10371 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10372 goto nla_put_failure
;
10374 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10376 goto nla_put_failure
;
10378 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10379 goto nla_put_failure
;
10381 nla_nest_end(msg
, pinfoattr
);
10383 genlmsg_end(msg
, hdr
);
10385 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10386 nl80211_mlme_mcgrp
.id
, gfp
);
10390 genlmsg_cancel(msg
, hdr
);
10393 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10395 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10396 u64 cookie
, bool acked
, gfp_t gfp
)
10398 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10399 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10400 struct sk_buff
*msg
;
10404 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10406 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10411 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10417 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10418 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10419 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10420 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10421 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10422 goto nla_put_failure
;
10424 err
= genlmsg_end(msg
, hdr
);
10430 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10431 nl80211_mlme_mcgrp
.id
, gfp
);
10435 genlmsg_cancel(msg
, hdr
);
10438 EXPORT_SYMBOL(cfg80211_probe_status
);
10440 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10441 const u8
*frame
, size_t len
,
10442 int freq
, int sig_dbm
)
10444 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10445 struct sk_buff
*msg
;
10447 struct cfg80211_beacon_registration
*reg
;
10449 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10451 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10452 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10453 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10455 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10459 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10461 goto nla_put_failure
;
10463 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10465 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10467 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10468 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10469 goto nla_put_failure
;
10471 genlmsg_end(msg
, hdr
);
10473 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10475 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10479 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10481 genlmsg_cancel(msg
, hdr
);
10484 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10487 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10488 struct cfg80211_wowlan_wakeup
*wakeup
,
10491 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10492 struct sk_buff
*msg
;
10494 int err
, size
= 200;
10496 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10499 size
+= wakeup
->packet_present_len
;
10501 msg
= nlmsg_new(size
, gfp
);
10505 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10509 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10510 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10513 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10514 wdev
->netdev
->ifindex
))
10518 struct nlattr
*reasons
;
10520 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10522 if (wakeup
->disconnect
&&
10523 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10525 if (wakeup
->magic_pkt
&&
10526 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10528 if (wakeup
->gtk_rekey_failure
&&
10529 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10531 if (wakeup
->eap_identity_req
&&
10532 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10534 if (wakeup
->four_way_handshake
&&
10535 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10537 if (wakeup
->rfkill_release
&&
10538 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10541 if (wakeup
->pattern_idx
>= 0 &&
10542 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10543 wakeup
->pattern_idx
))
10546 if (wakeup
->tcp_match
)
10547 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10549 if (wakeup
->tcp_connlost
)
10551 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10553 if (wakeup
->tcp_nomoretokens
)
10555 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10557 if (wakeup
->packet
) {
10558 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10559 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10561 if (!wakeup
->packet_80211
) {
10563 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10565 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10568 if (wakeup
->packet_len
&&
10569 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10572 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10577 nla_nest_end(msg
, reasons
);
10580 err
= genlmsg_end(msg
, hdr
);
10584 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10585 nl80211_mlme_mcgrp
.id
, gfp
);
10591 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10594 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10595 enum nl80211_tdls_operation oper
,
10596 u16 reason_code
, gfp_t gfp
)
10598 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10599 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10600 struct sk_buff
*msg
;
10604 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10607 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10611 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10617 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10618 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10619 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10620 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10621 (reason_code
> 0 &&
10622 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10623 goto nla_put_failure
;
10625 err
= genlmsg_end(msg
, hdr
);
10631 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10632 nl80211_mlme_mcgrp
.id
, gfp
);
10636 genlmsg_cancel(msg
, hdr
);
10639 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10641 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10642 unsigned long state
,
10645 struct netlink_notify
*notify
= _notify
;
10646 struct cfg80211_registered_device
*rdev
;
10647 struct wireless_dev
*wdev
;
10648 struct cfg80211_beacon_registration
*reg
, *tmp
;
10650 if (state
!= NETLINK_URELEASE
)
10651 return NOTIFY_DONE
;
10655 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10656 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10657 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10659 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10660 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10662 if (reg
->nlportid
== notify
->portid
) {
10663 list_del(®
->list
);
10668 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10673 return NOTIFY_DONE
;
10676 static struct notifier_block nl80211_netlink_notifier
= {
10677 .notifier_call
= nl80211_netlink_notify
,
10680 void cfg80211_ft_event(struct net_device
*netdev
,
10681 struct cfg80211_ft_event_params
*ft_event
)
10683 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10684 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10685 struct sk_buff
*msg
;
10689 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10691 if (!ft_event
->target_ap
)
10694 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10698 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10704 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10705 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10706 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10708 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10709 if (ft_event
->ric_ies
)
10710 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10711 ft_event
->ric_ies
);
10713 err
= genlmsg_end(msg
, hdr
);
10719 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10720 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10722 EXPORT_SYMBOL(cfg80211_ft_event
);
10724 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10726 struct cfg80211_registered_device
*rdev
;
10727 struct sk_buff
*msg
;
10731 rdev
= wiphy_to_dev(wdev
->wiphy
);
10732 if (!rdev
->crit_proto_nlportid
)
10735 nlportid
= rdev
->crit_proto_nlportid
;
10736 rdev
->crit_proto_nlportid
= 0;
10738 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10742 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10744 goto nla_put_failure
;
10746 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10747 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10748 goto nla_put_failure
;
10750 genlmsg_end(msg
, hdr
);
10752 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10757 genlmsg_cancel(msg
, hdr
);
10761 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10763 /* initialisation/exit functions */
10765 int nl80211_init(void)
10769 err
= genl_register_family_with_ops(&nl80211_fam
,
10770 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10774 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10778 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10782 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10786 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10790 #ifdef CONFIG_NL80211_TESTMODE
10791 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10796 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10802 genl_unregister_family(&nl80211_fam
);
10806 void nl80211_exit(void)
10808 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10809 genl_unregister_family(&nl80211_fam
);