2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
22 #include <net/inet_connection_sock.h>
28 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
29 struct genl_info
*info
,
30 struct cfg80211_crypto_settings
*settings
,
33 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
34 struct genl_info
*info
);
35 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
36 struct genl_info
*info
);
38 /* the netlink family */
39 static struct genl_family nl80211_fam
= {
40 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
41 .name
= NL80211_GENL_NAME
, /* have users key off the name instead */
42 .hdrsize
= 0, /* no private header */
43 .version
= 1, /* no particular meaning now */
44 .maxattr
= NL80211_ATTR_MAX
,
46 .pre_doit
= nl80211_pre_doit
,
47 .post_doit
= nl80211_post_doit
,
50 /* returns ERR_PTR values */
51 static struct wireless_dev
*
52 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
54 struct cfg80211_registered_device
*rdev
;
55 struct wireless_dev
*result
= NULL
;
56 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
57 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
64 if (!have_ifidx
&& !have_wdev_id
)
65 return ERR_PTR(-EINVAL
);
68 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
70 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
71 wiphy_idx
= wdev_id
>> 32;
74 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
75 struct wireless_dev
*wdev
;
77 if (wiphy_net(&rdev
->wiphy
) != netns
)
80 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
83 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
84 if (have_ifidx
&& wdev
->netdev
&&
85 wdev
->netdev
->ifindex
== ifidx
) {
89 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
101 return ERR_PTR(-ENODEV
);
104 static struct cfg80211_registered_device
*
105 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
107 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
108 struct net_device
*netdev
;
112 if (!attrs
[NL80211_ATTR_WIPHY
] &&
113 !attrs
[NL80211_ATTR_IFINDEX
] &&
114 !attrs
[NL80211_ATTR_WDEV
])
115 return ERR_PTR(-EINVAL
);
117 if (attrs
[NL80211_ATTR_WIPHY
])
118 rdev
= cfg80211_rdev_by_wiphy_idx(
119 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
121 if (attrs
[NL80211_ATTR_WDEV
]) {
122 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
123 struct wireless_dev
*wdev
;
126 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
128 /* make sure wdev exists */
129 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
130 if (wdev
->identifier
!= (u32
)wdev_id
)
139 if (rdev
&& tmp
!= rdev
)
140 return ERR_PTR(-EINVAL
);
145 if (attrs
[NL80211_ATTR_IFINDEX
]) {
146 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
147 netdev
= dev_get_by_index(netns
, ifindex
);
149 if (netdev
->ieee80211_ptr
)
151 netdev
->ieee80211_ptr
->wiphy
);
157 /* not wireless device -- return error */
159 return ERR_PTR(-EINVAL
);
161 /* mismatch -- return error */
162 if (rdev
&& tmp
!= rdev
)
163 return ERR_PTR(-EINVAL
);
170 return ERR_PTR(-ENODEV
);
172 if (netns
!= wiphy_net(&rdev
->wiphy
))
173 return ERR_PTR(-ENODEV
);
179 * This function returns a pointer to the driver
180 * that the genl_info item that is passed refers to.
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
185 static struct cfg80211_registered_device
*
186 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
188 return __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
191 /* policy for the attributes */
192 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
193 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
194 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
196 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
198 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
199 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
200 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
201 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
202 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
204 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
205 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
206 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
207 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
208 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
210 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
211 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
212 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
214 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
215 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
217 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
218 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
219 .len
= WLAN_MAX_KEY_LEN
},
220 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
221 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
222 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
223 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
224 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
226 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
227 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
229 .len
= IEEE80211_MAX_DATA_LEN
},
230 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
231 .len
= IEEE80211_MAX_DATA_LEN
},
232 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
233 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
234 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
235 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
236 .len
= NL80211_MAX_SUPP_RATES
},
237 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
238 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
239 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
240 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
241 .len
= IEEE80211_MAX_MESH_ID_LEN
},
242 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
244 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
245 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
247 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
248 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
249 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
250 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
251 .len
= NL80211_MAX_SUPP_RATES
},
252 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
254 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
255 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
257 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
259 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
260 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
261 .len
= IEEE80211_MAX_DATA_LEN
},
262 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
263 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
265 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
266 .len
= IEEE80211_MAX_SSID_LEN
},
267 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
268 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
269 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
270 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
271 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
272 [NL80211_ATTR_STA_FLAGS2
] = {
273 .len
= sizeof(struct nl80211_sta_flag_update
),
275 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
276 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
277 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
278 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
279 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
280 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
281 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
282 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
283 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
284 .len
= WLAN_PMKID_LEN
},
285 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
286 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
287 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
288 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
289 .len
= IEEE80211_MAX_DATA_LEN
},
290 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
291 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
292 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
293 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
295 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
296 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
297 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
298 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
299 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
300 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
301 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
303 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
304 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
305 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
306 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
307 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
308 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
309 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
310 .len
= IEEE80211_MAX_DATA_LEN
},
311 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
312 .len
= IEEE80211_MAX_DATA_LEN
},
313 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
314 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
315 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
316 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
317 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
318 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
319 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
320 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
321 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
322 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
323 .len
= IEEE80211_MAX_DATA_LEN
},
324 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
325 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
326 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
327 .len
= NL80211_HT_CAPABILITY_LEN
329 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
330 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
331 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
332 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
333 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
334 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
335 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
336 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
337 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
338 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
339 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
340 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
341 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
342 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
343 [NL80211_ATTR_SPLIT_WIPHY_DUMP
] = { .type
= NLA_FLAG
, },
344 [NL80211_ATTR_DISABLE_VHT
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_VHT_CAPABILITY_MASK
] = {
346 .len
= NL80211_VHT_CAPABILITY_LEN
,
348 [NL80211_ATTR_MDID
] = { .type
= NLA_U16
},
349 [NL80211_ATTR_IE_RIC
] = { .type
= NLA_BINARY
,
350 .len
= IEEE80211_MAX_DATA_LEN
},
351 [NL80211_ATTR_PEER_AID
] = { .type
= NLA_U16
},
354 /* policy for the key attributes */
355 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
356 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
357 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
358 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
359 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
360 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
361 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
362 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
363 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
366 /* policy for the key default flags */
367 static const struct nla_policy
368 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
369 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
370 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
373 /* policy for WoWLAN attributes */
374 static const struct nla_policy
375 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
376 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
377 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
378 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
379 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
380 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
381 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
382 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
383 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
384 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
387 static const struct nla_policy
388 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
389 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
390 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
391 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
392 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
393 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
394 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
395 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
396 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
398 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
399 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
401 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
402 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
403 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
406 /* policy for GTK rekey offload attributes */
407 static const struct nla_policy
408 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
409 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
410 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
411 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
414 static const struct nla_policy
415 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
416 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
417 .len
= IEEE80211_MAX_SSID_LEN
},
418 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
421 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
422 struct netlink_callback
*cb
,
423 struct cfg80211_registered_device
**rdev
,
424 struct wireless_dev
**wdev
)
431 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
432 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
437 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
438 nl80211_fam
.attrbuf
);
440 err
= PTR_ERR(*wdev
);
443 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
444 cb
->args
[0] = (*rdev
)->wiphy_idx
;
445 cb
->args
[1] = (*wdev
)->identifier
;
447 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0]);
448 struct wireless_dev
*tmp
;
454 *rdev
= wiphy_to_dev(wiphy
);
457 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
458 if (tmp
->identifier
== cb
->args
[1]) {
476 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
482 static bool is_valid_ie_attr(const struct nlattr
*attr
)
490 pos
= nla_data(attr
);
511 /* message building helper */
512 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
515 /* since there is no private header just add the generic one */
516 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
519 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
520 struct ieee80211_channel
*chan
,
523 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
525 goto nla_put_failure
;
527 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
528 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
529 goto nla_put_failure
;
530 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
531 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
532 goto nla_put_failure
;
533 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
534 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
535 goto nla_put_failure
;
536 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
537 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
538 goto nla_put_failure
;
542 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
544 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
546 goto nla_put_failure
;
547 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
549 goto nla_put_failure
;
554 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
555 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
556 goto nla_put_failure
;
557 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
558 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
559 goto nla_put_failure
;
560 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
561 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
562 goto nla_put_failure
;
563 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
564 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
565 goto nla_put_failure
;
568 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
569 DBM_TO_MBM(chan
->max_power
)))
570 goto nla_put_failure
;
578 /* netlink command implementations */
585 bool def_uni
, def_multi
;
588 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
590 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
591 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
596 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
597 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
606 if (tb
[NL80211_KEY_IDX
])
607 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
609 if (tb
[NL80211_KEY_DATA
]) {
610 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
611 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
614 if (tb
[NL80211_KEY_SEQ
]) {
615 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
616 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
619 if (tb
[NL80211_KEY_CIPHER
])
620 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
622 if (tb
[NL80211_KEY_TYPE
]) {
623 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
624 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
628 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
629 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
630 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
631 tb
[NL80211_KEY_DEFAULT_TYPES
],
632 nl80211_key_default_policy
);
636 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
637 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
643 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
645 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
646 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
647 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
650 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
651 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
652 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
655 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
656 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
658 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
659 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
661 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
662 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
671 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
672 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
673 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
677 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
678 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
679 int err
= nla_parse_nested(
680 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
681 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
682 nl80211_key_default_policy
);
686 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
687 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
693 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
697 memset(k
, 0, sizeof(*k
));
701 if (info
->attrs
[NL80211_ATTR_KEY
])
702 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
704 err
= nl80211_parse_key_old(info
, k
);
709 if (k
->def
&& k
->defmgmt
)
713 if (k
->def_uni
|| !k
->def_multi
)
719 if (k
->idx
< 4 || k
->idx
> 5)
722 if (k
->idx
< 0 || k
->idx
> 3)
725 if (k
->idx
< 0 || k
->idx
> 5)
733 static struct cfg80211_cached_keys
*
734 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
735 struct nlattr
*keys
, bool *no_ht
)
737 struct key_parse parse
;
739 struct cfg80211_cached_keys
*result
;
740 int rem
, err
, def
= 0;
742 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
744 return ERR_PTR(-ENOMEM
);
747 result
->defmgmt
= -1;
749 nla_for_each_nested(key
, keys
, rem
) {
750 memset(&parse
, 0, sizeof(parse
));
753 err
= nl80211_parse_key_new(key
, &parse
);
759 if (parse
.idx
< 0 || parse
.idx
> 4)
765 result
->def
= parse
.idx
;
766 if (!parse
.def_uni
|| !parse
.def_multi
)
768 } else if (parse
.defmgmt
)
770 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
771 parse
.idx
, false, NULL
);
774 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
775 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
776 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
777 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
779 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
780 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
792 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
794 ASSERT_WDEV_LOCK(wdev
);
796 switch (wdev
->iftype
) {
797 case NL80211_IFTYPE_AP
:
798 case NL80211_IFTYPE_AP_VLAN
:
799 case NL80211_IFTYPE_P2P_GO
:
800 case NL80211_IFTYPE_MESH_POINT
:
802 case NL80211_IFTYPE_ADHOC
:
803 case NL80211_IFTYPE_STATION
:
804 case NL80211_IFTYPE_P2P_CLIENT
:
805 if (!wdev
->current_bss
)
815 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
817 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
821 goto nla_put_failure
;
825 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
826 goto nla_put_failure
;
831 nla_nest_end(msg
, nl_modes
);
838 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
842 struct nlattr
*nl_combis
;
845 nl_combis
= nla_nest_start(msg
,
846 NL80211_ATTR_INTERFACE_COMBINATIONS
);
848 goto nla_put_failure
;
850 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
851 const struct ieee80211_iface_combination
*c
;
852 struct nlattr
*nl_combi
, *nl_limits
;
854 c
= &wiphy
->iface_combinations
[i
];
856 nl_combi
= nla_nest_start(msg
, i
+ 1);
858 goto nla_put_failure
;
860 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
862 goto nla_put_failure
;
864 for (j
= 0; j
< c
->n_limits
; j
++) {
865 struct nlattr
*nl_limit
;
867 nl_limit
= nla_nest_start(msg
, j
+ 1);
869 goto nla_put_failure
;
870 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
872 goto nla_put_failure
;
873 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
875 goto nla_put_failure
;
876 nla_nest_end(msg
, nl_limit
);
879 nla_nest_end(msg
, nl_limits
);
881 if (c
->beacon_int_infra_match
&&
882 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
883 goto nla_put_failure
;
884 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
885 c
->num_different_channels
) ||
886 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
888 goto nla_put_failure
;
890 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
891 c
->radar_detect_widths
))
892 goto nla_put_failure
;
894 nla_nest_end(msg
, nl_combi
);
897 nla_nest_end(msg
, nl_combis
);
905 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
908 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
909 struct nlattr
*nl_tcp
;
914 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
918 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
919 tcp
->data_payload_max
))
922 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
923 tcp
->data_payload_max
))
926 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
929 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
930 sizeof(*tcp
->tok
), tcp
->tok
))
933 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
934 tcp
->data_interval_max
))
937 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
938 tcp
->wake_payload_max
))
941 nla_nest_end(msg
, nl_tcp
);
945 static int nl80211_send_wowlan(struct sk_buff
*msg
,
946 struct cfg80211_registered_device
*dev
,
949 struct nlattr
*nl_wowlan
;
951 if (!dev
->wiphy
.wowlan
)
954 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
958 if (((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
959 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
960 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
961 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
962 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
963 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
964 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
965 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
966 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
967 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
968 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
969 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
970 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
971 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
972 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
973 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
976 if (dev
->wiphy
.wowlan
->n_patterns
) {
977 struct nl80211_wowlan_pattern_support pat
= {
978 .max_patterns
= dev
->wiphy
.wowlan
->n_patterns
,
979 .min_pattern_len
= dev
->wiphy
.wowlan
->pattern_min_len
,
980 .max_pattern_len
= dev
->wiphy
.wowlan
->pattern_max_len
,
981 .max_pkt_offset
= dev
->wiphy
.wowlan
->max_pkt_offset
,
984 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
989 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
992 nla_nest_end(msg
, nl_wowlan
);
998 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
999 struct ieee80211_supported_band
*sband
)
1001 struct nlattr
*nl_rates
, *nl_rate
;
1002 struct ieee80211_rate
*rate
;
1006 if (sband
->ht_cap
.ht_supported
&&
1007 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1008 sizeof(sband
->ht_cap
.mcs
),
1009 &sband
->ht_cap
.mcs
) ||
1010 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1011 sband
->ht_cap
.cap
) ||
1012 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1013 sband
->ht_cap
.ampdu_factor
) ||
1014 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1015 sband
->ht_cap
.ampdu_density
)))
1019 if (sband
->vht_cap
.vht_supported
&&
1020 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1021 sizeof(sband
->vht_cap
.vht_mcs
),
1022 &sband
->vht_cap
.vht_mcs
) ||
1023 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1024 sband
->vht_cap
.cap
)))
1028 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1032 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1033 nl_rate
= nla_nest_start(msg
, i
);
1037 rate
= &sband
->bitrates
[i
];
1038 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1041 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1043 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1046 nla_nest_end(msg
, nl_rate
);
1049 nla_nest_end(msg
, nl_rates
);
1055 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1056 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1059 struct nlattr
*nl_ftypes
, *nl_ifs
;
1060 enum nl80211_iftype ift
;
1066 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1070 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1071 nl_ftypes
= nla_nest_start(msg
, ift
);
1075 stypes
= mgmt_stypes
[ift
].tx
;
1078 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1079 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1084 nla_nest_end(msg
, nl_ftypes
);
1087 nla_nest_end(msg
, nl_ifs
);
1089 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1093 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1094 nl_ftypes
= nla_nest_start(msg
, ift
);
1098 stypes
= mgmt_stypes
[ift
].rx
;
1101 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1102 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1107 nla_nest_end(msg
, nl_ftypes
);
1109 nla_nest_end(msg
, nl_ifs
);
1114 struct nl80211_dump_wiphy_state
{
1117 long split_start
, band_start
, chan_start
;
1121 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1122 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1123 int flags
, struct nl80211_dump_wiphy_state
*state
)
1126 struct nlattr
*nl_bands
, *nl_band
;
1127 struct nlattr
*nl_freqs
, *nl_freq
;
1128 struct nlattr
*nl_cmds
;
1129 enum ieee80211_band band
;
1130 struct ieee80211_channel
*chan
;
1132 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1133 dev
->wiphy
.mgmt_stypes
;
1136 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1140 if (WARN_ON(!state
))
1143 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1144 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1145 wiphy_name(&dev
->wiphy
)) ||
1146 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1147 cfg80211_rdev_list_generation
))
1148 goto nla_put_failure
;
1150 switch (state
->split_start
) {
1152 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1153 dev
->wiphy
.retry_short
) ||
1154 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1155 dev
->wiphy
.retry_long
) ||
1156 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1157 dev
->wiphy
.frag_threshold
) ||
1158 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1159 dev
->wiphy
.rts_threshold
) ||
1160 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1161 dev
->wiphy
.coverage_class
) ||
1162 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1163 dev
->wiphy
.max_scan_ssids
) ||
1164 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1165 dev
->wiphy
.max_sched_scan_ssids
) ||
1166 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1167 dev
->wiphy
.max_scan_ie_len
) ||
1168 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1169 dev
->wiphy
.max_sched_scan_ie_len
) ||
1170 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1171 dev
->wiphy
.max_match_sets
))
1172 goto nla_put_failure
;
1174 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1175 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1176 goto nla_put_failure
;
1177 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1178 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1179 goto nla_put_failure
;
1180 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1181 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1182 goto nla_put_failure
;
1183 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1184 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1185 goto nla_put_failure
;
1186 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1187 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1188 goto nla_put_failure
;
1189 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1190 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1191 goto nla_put_failure
;
1192 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1193 nla_put_flag(msg
, WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1194 goto nla_put_failure
;
1196 state
->split_start
++;
1200 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1201 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1202 dev
->wiphy
.cipher_suites
))
1203 goto nla_put_failure
;
1205 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1206 dev
->wiphy
.max_num_pmkids
))
1207 goto nla_put_failure
;
1209 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1210 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1211 goto nla_put_failure
;
1213 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1214 dev
->wiphy
.available_antennas_tx
) ||
1215 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1216 dev
->wiphy
.available_antennas_rx
))
1217 goto nla_put_failure
;
1219 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1220 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1221 dev
->wiphy
.probe_resp_offload
))
1222 goto nla_put_failure
;
1224 if ((dev
->wiphy
.available_antennas_tx
||
1225 dev
->wiphy
.available_antennas_rx
) &&
1226 dev
->ops
->get_antenna
) {
1227 u32 tx_ant
= 0, rx_ant
= 0;
1229 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1231 if (nla_put_u32(msg
,
1232 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1235 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1237 goto nla_put_failure
;
1241 state
->split_start
++;
1245 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1246 dev
->wiphy
.interface_modes
))
1247 goto nla_put_failure
;
1248 state
->split_start
++;
1252 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1254 goto nla_put_failure
;
1256 for (band
= state
->band_start
;
1257 band
< IEEE80211_NUM_BANDS
; band
++) {
1258 struct ieee80211_supported_band
*sband
;
1260 sband
= dev
->wiphy
.bands
[band
];
1265 nl_band
= nla_nest_start(msg
, band
);
1267 goto nla_put_failure
;
1269 switch (state
->chan_start
) {
1271 if (nl80211_send_band_rateinfo(msg
, sband
))
1272 goto nla_put_failure
;
1273 state
->chan_start
++;
1277 /* add frequencies */
1278 nl_freqs
= nla_nest_start(
1279 msg
, NL80211_BAND_ATTR_FREQS
);
1281 goto nla_put_failure
;
1283 for (i
= state
->chan_start
- 1;
1284 i
< sband
->n_channels
;
1286 nl_freq
= nla_nest_start(msg
, i
);
1288 goto nla_put_failure
;
1290 chan
= &sband
->channels
[i
];
1292 if (nl80211_msg_put_channel(
1295 goto nla_put_failure
;
1297 nla_nest_end(msg
, nl_freq
);
1301 if (i
< sband
->n_channels
)
1302 state
->chan_start
= i
+ 2;
1304 state
->chan_start
= 0;
1305 nla_nest_end(msg
, nl_freqs
);
1308 nla_nest_end(msg
, nl_band
);
1311 /* start again here */
1312 if (state
->chan_start
)
1317 nla_nest_end(msg
, nl_bands
);
1319 if (band
< IEEE80211_NUM_BANDS
)
1320 state
->band_start
= band
+ 1;
1322 state
->band_start
= 0;
1324 /* if bands & channels are done, continue outside */
1325 if (state
->band_start
== 0 && state
->chan_start
== 0)
1326 state
->split_start
++;
1330 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1332 goto nla_put_failure
;
1335 #define CMD(op, n) \
1337 if (dev->ops->op) { \
1339 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1340 goto nla_put_failure; \
1344 CMD(add_virtual_intf
, NEW_INTERFACE
);
1345 CMD(change_virtual_intf
, SET_INTERFACE
);
1346 CMD(add_key
, NEW_KEY
);
1347 CMD(start_ap
, START_AP
);
1348 CMD(add_station
, NEW_STATION
);
1349 CMD(add_mpath
, NEW_MPATH
);
1350 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1351 CMD(change_bss
, SET_BSS
);
1352 CMD(auth
, AUTHENTICATE
);
1353 CMD(assoc
, ASSOCIATE
);
1354 CMD(deauth
, DEAUTHENTICATE
);
1355 CMD(disassoc
, DISASSOCIATE
);
1356 CMD(join_ibss
, JOIN_IBSS
);
1357 CMD(join_mesh
, JOIN_MESH
);
1358 CMD(set_pmksa
, SET_PMKSA
);
1359 CMD(del_pmksa
, DEL_PMKSA
);
1360 CMD(flush_pmksa
, FLUSH_PMKSA
);
1361 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1362 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1363 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1364 CMD(mgmt_tx
, FRAME
);
1365 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1366 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1368 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1369 goto nla_put_failure
;
1371 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1372 dev
->ops
->join_mesh
) {
1374 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1375 goto nla_put_failure
;
1377 CMD(set_wds_peer
, SET_WDS_PEER
);
1378 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1379 CMD(tdls_mgmt
, TDLS_MGMT
);
1380 CMD(tdls_oper
, TDLS_OPER
);
1382 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1383 CMD(sched_scan_start
, START_SCHED_SCAN
);
1384 CMD(probe_client
, PROBE_CLIENT
);
1385 CMD(set_noack_map
, SET_NOACK_MAP
);
1386 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1388 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1389 goto nla_put_failure
;
1391 CMD(start_p2p_device
, START_P2P_DEVICE
);
1392 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1394 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1395 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1398 #ifdef CONFIG_NL80211_TESTMODE
1399 CMD(testmode_cmd
, TESTMODE
);
1404 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1406 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1407 goto nla_put_failure
;
1410 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1412 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1413 goto nla_put_failure
;
1416 nla_nest_end(msg
, nl_cmds
);
1417 state
->split_start
++;
1421 if (dev
->ops
->remain_on_channel
&&
1422 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1424 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1425 dev
->wiphy
.max_remain_on_channel_duration
))
1426 goto nla_put_failure
;
1428 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1429 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1430 goto nla_put_failure
;
1432 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1433 goto nla_put_failure
;
1434 state
->split_start
++;
1439 if (nl80211_send_wowlan(msg
, dev
, state
->split
))
1440 goto nla_put_failure
;
1441 state
->split_start
++;
1445 state
->split_start
++;
1448 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1449 dev
->wiphy
.software_iftypes
))
1450 goto nla_put_failure
;
1452 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
,
1454 goto nla_put_failure
;
1456 state
->split_start
++;
1460 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1461 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1462 dev
->wiphy
.ap_sme_capa
))
1463 goto nla_put_failure
;
1465 features
= dev
->wiphy
.features
;
1467 * We can only add the per-channel limit information if the
1468 * dump is split, otherwise it makes it too big. Therefore
1469 * only advertise it in that case.
1472 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1473 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1474 goto nla_put_failure
;
1476 if (dev
->wiphy
.ht_capa_mod_mask
&&
1477 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1478 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1479 dev
->wiphy
.ht_capa_mod_mask
))
1480 goto nla_put_failure
;
1482 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1483 dev
->wiphy
.max_acl_mac_addrs
&&
1484 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1485 dev
->wiphy
.max_acl_mac_addrs
))
1486 goto nla_put_failure
;
1489 * Any information below this point is only available to
1490 * applications that can deal with it being split. This
1491 * helps ensure that newly added capabilities don't break
1492 * older tools by overrunning their buffers.
1494 * We still increment split_start so that in the split
1495 * case we'll continue with more data in the next round,
1496 * but break unconditionally so unsplit data stops here.
1498 state
->split_start
++;
1501 if (dev
->wiphy
.extended_capabilities
&&
1502 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1503 dev
->wiphy
.extended_capabilities_len
,
1504 dev
->wiphy
.extended_capabilities
) ||
1505 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1506 dev
->wiphy
.extended_capabilities_len
,
1507 dev
->wiphy
.extended_capabilities_mask
)))
1508 goto nla_put_failure
;
1510 if (dev
->wiphy
.vht_capa_mod_mask
&&
1511 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1512 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1513 dev
->wiphy
.vht_capa_mod_mask
))
1514 goto nla_put_failure
;
1517 state
->split_start
= 0;
1520 return genlmsg_end(msg
, hdr
);
1523 genlmsg_cancel(msg
, hdr
);
1527 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1528 struct netlink_callback
*cb
,
1529 struct nl80211_dump_wiphy_state
*state
)
1531 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1532 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1533 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1534 /* ignore parse errors for backward compatibility */
1538 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1539 if (tb
[NL80211_ATTR_WIPHY
])
1540 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1541 if (tb
[NL80211_ATTR_WDEV
])
1542 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1543 if (tb
[NL80211_ATTR_IFINDEX
]) {
1544 struct net_device
*netdev
;
1545 struct cfg80211_registered_device
*rdev
;
1546 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1548 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1551 if (netdev
->ieee80211_ptr
) {
1552 rdev
= wiphy_to_dev(
1553 netdev
->ieee80211_ptr
->wiphy
);
1554 state
->filter_wiphy
= rdev
->wiphy_idx
;
1562 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1565 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1566 struct cfg80211_registered_device
*dev
;
1570 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1575 state
->filter_wiphy
= -1;
1576 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1582 cb
->args
[0] = (long)state
;
1585 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1586 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1588 if (++idx
<= state
->start
)
1590 if (state
->filter_wiphy
!= -1 &&
1591 state
->filter_wiphy
!= dev
->wiphy_idx
)
1593 /* attempt to fit multiple wiphy data chunks into the skb */
1595 ret
= nl80211_send_wiphy(dev
, skb
,
1596 NETLINK_CB(cb
->skb
).portid
,
1598 NLM_F_MULTI
, state
);
1601 * If sending the wiphy data didn't fit (ENOBUFS
1602 * or EMSGSIZE returned), this SKB is still
1603 * empty (so it's not too big because another
1604 * wiphy dataset is already in the skb) and
1605 * we've not tried to adjust the dump allocation
1606 * yet ... then adjust the alloc size to be
1607 * bigger, and return 1 but with the empty skb.
1608 * This results in an empty message being RX'ed
1609 * in userspace, but that is ignored.
1611 * We can then retry with the larger buffer.
1613 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1615 cb
->min_dump_alloc
< 4096) {
1616 cb
->min_dump_alloc
= 4096;
1623 } while (state
->split_start
> 0);
1633 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1635 kfree((void *)cb
->args
[0]);
1639 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1641 struct sk_buff
*msg
;
1642 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1643 struct nl80211_dump_wiphy_state state
= {};
1645 msg
= nlmsg_new(4096, GFP_KERNEL
);
1649 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1655 return genlmsg_reply(msg
, info
);
1658 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1659 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1660 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1661 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1662 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1663 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1666 static int parse_txq_params(struct nlattr
*tb
[],
1667 struct ieee80211_txq_params
*txq_params
)
1669 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1670 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1671 !tb
[NL80211_TXQ_ATTR_AIFS
])
1674 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1675 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1676 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1677 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1678 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1680 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1686 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1689 * You can only set the channel explicitly for WDS interfaces,
1690 * all others have their channel managed via their respective
1691 * "establish a connection" command (connect, join, ...)
1693 * For AP/GO and mesh mode, the channel can be set with the
1694 * channel userspace API, but is only stored and passed to the
1695 * low-level driver when the AP starts or the mesh is joined.
1696 * This is for backward compatibility, userspace can also give
1697 * the channel in the start-ap or join-mesh commands instead.
1699 * Monitors are special as they are normally slaved to
1700 * whatever else is going on, so they have their own special
1701 * operation to set the monitor channel if possible.
1704 wdev
->iftype
== NL80211_IFTYPE_AP
||
1705 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1706 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1707 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1710 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1711 struct genl_info
*info
,
1712 struct cfg80211_chan_def
*chandef
)
1716 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1719 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1721 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1722 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1723 chandef
->center_freq1
= control_freq
;
1724 chandef
->center_freq2
= 0;
1726 /* Primary channel not allowed */
1727 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1730 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1731 enum nl80211_channel_type chantype
;
1733 chantype
= nla_get_u32(
1734 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1737 case NL80211_CHAN_NO_HT
:
1738 case NL80211_CHAN_HT20
:
1739 case NL80211_CHAN_HT40PLUS
:
1740 case NL80211_CHAN_HT40MINUS
:
1741 cfg80211_chandef_create(chandef
, chandef
->chan
,
1747 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1749 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1750 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1751 chandef
->center_freq1
=
1753 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1754 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1755 chandef
->center_freq2
=
1757 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1760 if (!cfg80211_chandef_valid(chandef
))
1763 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1764 IEEE80211_CHAN_DISABLED
))
1767 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1768 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1769 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1775 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1776 struct wireless_dev
*wdev
,
1777 struct genl_info
*info
)
1779 struct cfg80211_chan_def chandef
;
1781 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1784 iftype
= wdev
->iftype
;
1786 if (!nl80211_can_set_dev_channel(wdev
))
1789 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1794 case NL80211_IFTYPE_AP
:
1795 case NL80211_IFTYPE_P2P_GO
:
1796 if (wdev
->beacon_interval
) {
1800 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1804 wdev
->preset_chandef
= chandef
;
1807 case NL80211_IFTYPE_MESH_POINT
:
1808 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1810 case NL80211_IFTYPE_MONITOR
:
1811 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1820 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1822 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1823 struct net_device
*netdev
= info
->user_ptr
[1];
1825 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1828 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1830 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1831 struct net_device
*dev
= info
->user_ptr
[1];
1832 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1835 if (!info
->attrs
[NL80211_ATTR_MAC
])
1838 if (netif_running(dev
))
1841 if (!rdev
->ops
->set_wds_peer
)
1844 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1847 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1848 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1852 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1854 struct cfg80211_registered_device
*rdev
;
1855 struct net_device
*netdev
= NULL
;
1856 struct wireless_dev
*wdev
;
1857 int result
= 0, rem_txq_params
= 0;
1858 struct nlattr
*nl_txq_params
;
1860 u8 retry_short
= 0, retry_long
= 0;
1861 u32 frag_threshold
= 0, rts_threshold
= 0;
1862 u8 coverage_class
= 0;
1867 * Try to find the wiphy and netdev. Normally this
1868 * function shouldn't need the netdev, but this is
1869 * done for backward compatibility -- previously
1870 * setting the channel was done per wiphy, but now
1871 * it is per netdev. Previous userland like hostapd
1872 * also passed a netdev to set_wiphy, so that it is
1873 * possible to let that go to the right netdev!
1876 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1877 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1879 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1880 if (netdev
&& netdev
->ieee80211_ptr
)
1881 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1887 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1890 return PTR_ERR(rdev
);
1895 wdev
= netdev
->ieee80211_ptr
;
1898 * end workaround code, by now the rdev is available
1899 * and locked, and wdev may or may not be NULL.
1902 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1903 result
= cfg80211_dev_rename(
1904 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1909 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1910 struct ieee80211_txq_params txq_params
;
1911 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1913 if (!rdev
->ops
->set_txq_params
) {
1914 result
= -EOPNOTSUPP
;
1923 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1924 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1929 if (!netif_running(netdev
)) {
1934 nla_for_each_nested(nl_txq_params
,
1935 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1937 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1938 nla_data(nl_txq_params
),
1939 nla_len(nl_txq_params
),
1941 result
= parse_txq_params(tb
, &txq_params
);
1945 result
= rdev_set_txq_params(rdev
, netdev
,
1952 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1953 result
= __nl80211_set_channel(rdev
,
1954 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1960 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1961 struct wireless_dev
*txp_wdev
= wdev
;
1962 enum nl80211_tx_power_setting type
;
1965 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
1968 if (!rdev
->ops
->set_tx_power
) {
1969 result
= -EOPNOTSUPP
;
1973 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1974 type
= nla_get_u32(info
->attrs
[idx
]);
1976 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1977 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1982 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1983 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1984 mbm
= nla_get_u32(info
->attrs
[idx
]);
1987 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
1992 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1993 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1995 if ((!rdev
->wiphy
.available_antennas_tx
&&
1996 !rdev
->wiphy
.available_antennas_rx
) ||
1997 !rdev
->ops
->set_antenna
) {
1998 result
= -EOPNOTSUPP
;
2002 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2003 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2005 /* reject antenna configurations which don't match the
2006 * available antenna masks, except for the "all" mask */
2007 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2008 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2013 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2014 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2016 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2023 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2024 retry_short
= nla_get_u8(
2025 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2026 if (retry_short
== 0) {
2030 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2033 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2034 retry_long
= nla_get_u8(
2035 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2036 if (retry_long
== 0) {
2040 changed
|= WIPHY_PARAM_RETRY_LONG
;
2043 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2044 frag_threshold
= nla_get_u32(
2045 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2046 if (frag_threshold
< 256) {
2050 if (frag_threshold
!= (u32
) -1) {
2052 * Fragments (apart from the last one) are required to
2053 * have even length. Make the fragmentation code
2054 * simpler by stripping LSB should someone try to use
2055 * odd threshold value.
2057 frag_threshold
&= ~0x1;
2059 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2062 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2063 rts_threshold
= nla_get_u32(
2064 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2065 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2068 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2069 coverage_class
= nla_get_u8(
2070 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2071 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2075 u8 old_retry_short
, old_retry_long
;
2076 u32 old_frag_threshold
, old_rts_threshold
;
2077 u8 old_coverage_class
;
2079 if (!rdev
->ops
->set_wiphy_params
) {
2080 result
= -EOPNOTSUPP
;
2084 old_retry_short
= rdev
->wiphy
.retry_short
;
2085 old_retry_long
= rdev
->wiphy
.retry_long
;
2086 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2087 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2088 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2090 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2091 rdev
->wiphy
.retry_short
= retry_short
;
2092 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2093 rdev
->wiphy
.retry_long
= retry_long
;
2094 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2095 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2096 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2097 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2098 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2099 rdev
->wiphy
.coverage_class
= coverage_class
;
2101 result
= rdev_set_wiphy_params(rdev
, changed
);
2103 rdev
->wiphy
.retry_short
= old_retry_short
;
2104 rdev
->wiphy
.retry_long
= old_retry_long
;
2105 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2106 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2107 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2117 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2119 return (u64
)wdev
->identifier
|
2120 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2123 static int nl80211_send_chandef(struct sk_buff
*msg
,
2124 struct cfg80211_chan_def
*chandef
)
2126 WARN_ON(!cfg80211_chandef_valid(chandef
));
2128 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2129 chandef
->chan
->center_freq
))
2131 switch (chandef
->width
) {
2132 case NL80211_CHAN_WIDTH_20_NOHT
:
2133 case NL80211_CHAN_WIDTH_20
:
2134 case NL80211_CHAN_WIDTH_40
:
2135 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2136 cfg80211_get_chandef_type(chandef
)))
2142 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2144 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2146 if (chandef
->center_freq2
&&
2147 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2152 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2153 struct cfg80211_registered_device
*rdev
,
2154 struct wireless_dev
*wdev
)
2156 struct net_device
*dev
= wdev
->netdev
;
2159 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2164 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2165 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2166 goto nla_put_failure
;
2168 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2169 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2170 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2171 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2172 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2173 rdev
->devlist_generation
^
2174 (cfg80211_rdev_list_generation
<< 2)))
2175 goto nla_put_failure
;
2177 if (rdev
->ops
->get_channel
) {
2179 struct cfg80211_chan_def chandef
;
2181 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2183 if (nl80211_send_chandef(msg
, &chandef
))
2184 goto nla_put_failure
;
2188 if (wdev
->ssid_len
) {
2189 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2190 goto nla_put_failure
;
2193 return genlmsg_end(msg
, hdr
);
2196 genlmsg_cancel(msg
, hdr
);
2200 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2204 int wp_start
= cb
->args
[0];
2205 int if_start
= cb
->args
[1];
2206 struct cfg80211_registered_device
*rdev
;
2207 struct wireless_dev
*wdev
;
2210 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2211 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2213 if (wp_idx
< wp_start
) {
2219 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2220 if (if_idx
< if_start
) {
2224 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2225 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2237 cb
->args
[0] = wp_idx
;
2238 cb
->args
[1] = if_idx
;
2243 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2245 struct sk_buff
*msg
;
2246 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2247 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2249 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2253 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2259 return genlmsg_reply(msg
, info
);
2262 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2263 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2264 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2265 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2266 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2267 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2268 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2271 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2273 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2281 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2282 nla
, mntr_flags_policy
))
2285 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2287 *mntrflags
|= (1<<flag
);
2292 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2293 struct net_device
*netdev
, u8 use_4addr
,
2294 enum nl80211_iftype iftype
)
2297 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2303 case NL80211_IFTYPE_AP_VLAN
:
2304 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2307 case NL80211_IFTYPE_STATION
:
2308 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2318 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2320 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2321 struct vif_params params
;
2323 enum nl80211_iftype otype
, ntype
;
2324 struct net_device
*dev
= info
->user_ptr
[1];
2325 u32 _flags
, *flags
= NULL
;
2326 bool change
= false;
2328 memset(¶ms
, 0, sizeof(params
));
2330 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2332 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2333 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2336 if (ntype
> NL80211_IFTYPE_MAX
)
2340 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2341 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2343 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2345 if (netif_running(dev
))
2349 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2350 IEEE80211_MAX_MESH_ID_LEN
);
2351 wdev
->mesh_id_up_len
=
2352 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2353 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2354 wdev
->mesh_id_up_len
);
2358 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2359 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2361 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2365 params
.use_4addr
= -1;
2368 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2369 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2371 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2380 if (flags
&& (*flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2381 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2385 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2389 if (!err
&& params
.use_4addr
!= -1)
2390 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2395 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2397 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2398 struct vif_params params
;
2399 struct wireless_dev
*wdev
;
2400 struct sk_buff
*msg
;
2402 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2405 memset(¶ms
, 0, sizeof(params
));
2407 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2410 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2411 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2412 if (type
> NL80211_IFTYPE_MAX
)
2416 if (!rdev
->ops
->add_virtual_intf
||
2417 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2420 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2421 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2423 if (!is_valid_ether_addr(params
.macaddr
))
2424 return -EADDRNOTAVAIL
;
2427 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2428 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2429 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2434 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2438 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2439 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2442 if (!err
&& (flags
& NL80211_MNTR_FLAG_ACTIVE
) &&
2443 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2446 wdev
= rdev_add_virtual_intf(rdev
,
2447 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2448 type
, err
? NULL
: &flags
, ¶ms
);
2451 return PTR_ERR(wdev
);
2455 case NL80211_IFTYPE_MESH_POINT
:
2456 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2459 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2460 IEEE80211_MAX_MESH_ID_LEN
);
2461 wdev
->mesh_id_up_len
=
2462 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2463 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2464 wdev
->mesh_id_up_len
);
2467 case NL80211_IFTYPE_P2P_DEVICE
:
2469 * P2P Device doesn't have a netdev, so doesn't go
2470 * through the netdev notifier and must be added here
2472 mutex_init(&wdev
->mtx
);
2473 INIT_LIST_HEAD(&wdev
->event_list
);
2474 spin_lock_init(&wdev
->event_lock
);
2475 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2476 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2478 wdev
->identifier
= ++rdev
->wdev_id
;
2479 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2480 rdev
->devlist_generation
++;
2486 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2492 return genlmsg_reply(msg
, info
);
2495 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2497 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2498 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2500 if (!rdev
->ops
->del_virtual_intf
)
2504 * If we remove a wireless device without a netdev then clear
2505 * user_ptr[1] so that nl80211_post_doit won't dereference it
2506 * to check if it needs to do dev_put(). Otherwise it crashes
2507 * since the wdev has been freed, unlike with a netdev where
2508 * we need the dev_put() for the netdev to really be freed.
2511 info
->user_ptr
[1] = NULL
;
2513 return rdev_del_virtual_intf(rdev
, wdev
);
2516 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2518 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2519 struct net_device
*dev
= info
->user_ptr
[1];
2522 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2525 if (!rdev
->ops
->set_noack_map
)
2528 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2530 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2533 struct get_key_cookie
{
2534 struct sk_buff
*msg
;
2539 static void get_key_callback(void *c
, struct key_params
*params
)
2542 struct get_key_cookie
*cookie
= c
;
2545 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2546 params
->key_len
, params
->key
)) ||
2548 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2549 params
->seq_len
, params
->seq
)) ||
2551 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2553 goto nla_put_failure
;
2555 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2557 goto nla_put_failure
;
2560 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2561 params
->key_len
, params
->key
)) ||
2563 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2564 params
->seq_len
, params
->seq
)) ||
2566 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2568 goto nla_put_failure
;
2570 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2571 goto nla_put_failure
;
2573 nla_nest_end(cookie
->msg
, key
);
2580 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2582 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2584 struct net_device
*dev
= info
->user_ptr
[1];
2586 const u8
*mac_addr
= NULL
;
2588 struct get_key_cookie cookie
= {
2592 struct sk_buff
*msg
;
2594 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2595 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2600 if (info
->attrs
[NL80211_ATTR_MAC
])
2601 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2603 pairwise
= !!mac_addr
;
2604 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2605 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2606 if (kt
>= NUM_NL80211_KEYTYPES
)
2608 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2609 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2611 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2614 if (!rdev
->ops
->get_key
)
2617 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2621 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2622 NL80211_CMD_NEW_KEY
);
2624 return PTR_ERR(hdr
);
2627 cookie
.idx
= key_idx
;
2629 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2630 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2631 goto nla_put_failure
;
2633 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2634 goto nla_put_failure
;
2636 if (pairwise
&& mac_addr
&&
2637 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2640 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2647 goto nla_put_failure
;
2649 genlmsg_end(msg
, hdr
);
2650 return genlmsg_reply(msg
, info
);
2659 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2661 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2662 struct key_parse key
;
2664 struct net_device
*dev
= info
->user_ptr
[1];
2666 err
= nl80211_parse_key(info
, &key
);
2673 /* only support setting default key */
2674 if (!key
.def
&& !key
.defmgmt
)
2677 wdev_lock(dev
->ieee80211_ptr
);
2680 if (!rdev
->ops
->set_default_key
) {
2685 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2689 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2690 key
.def_uni
, key
.def_multi
);
2695 #ifdef CONFIG_CFG80211_WEXT
2696 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2699 if (key
.def_uni
|| !key
.def_multi
) {
2704 if (!rdev
->ops
->set_default_mgmt_key
) {
2709 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2713 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2717 #ifdef CONFIG_CFG80211_WEXT
2718 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2723 wdev_unlock(dev
->ieee80211_ptr
);
2728 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2730 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2732 struct net_device
*dev
= info
->user_ptr
[1];
2733 struct key_parse key
;
2734 const u8
*mac_addr
= NULL
;
2736 err
= nl80211_parse_key(info
, &key
);
2743 if (info
->attrs
[NL80211_ATTR_MAC
])
2744 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2746 if (key
.type
== -1) {
2748 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2750 key
.type
= NL80211_KEYTYPE_GROUP
;
2754 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2755 key
.type
!= NL80211_KEYTYPE_GROUP
)
2758 if (!rdev
->ops
->add_key
)
2761 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2762 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2766 wdev_lock(dev
->ieee80211_ptr
);
2767 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2769 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2770 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2772 wdev_unlock(dev
->ieee80211_ptr
);
2777 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2779 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2781 struct net_device
*dev
= info
->user_ptr
[1];
2782 u8
*mac_addr
= NULL
;
2783 struct key_parse key
;
2785 err
= nl80211_parse_key(info
, &key
);
2789 if (info
->attrs
[NL80211_ATTR_MAC
])
2790 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2792 if (key
.type
== -1) {
2794 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2796 key
.type
= NL80211_KEYTYPE_GROUP
;
2800 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2801 key
.type
!= NL80211_KEYTYPE_GROUP
)
2804 if (!rdev
->ops
->del_key
)
2807 wdev_lock(dev
->ieee80211_ptr
);
2808 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2810 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2811 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2815 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2816 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2819 #ifdef CONFIG_CFG80211_WEXT
2821 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2822 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2823 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2824 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2827 wdev_unlock(dev
->ieee80211_ptr
);
2832 /* This function returns an error or the number of nested attributes */
2833 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2835 struct nlattr
*attr
;
2836 int n_entries
= 0, tmp
;
2838 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2839 if (nla_len(attr
) != ETH_ALEN
)
2849 * This function parses ACL information and allocates memory for ACL data.
2850 * On successful return, the calling function is responsible to free the
2851 * ACL buffer returned by this function.
2853 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2854 struct genl_info
*info
)
2856 enum nl80211_acl_policy acl_policy
;
2857 struct nlattr
*attr
;
2858 struct cfg80211_acl_data
*acl
;
2859 int i
= 0, n_entries
, tmp
;
2861 if (!wiphy
->max_acl_mac_addrs
)
2862 return ERR_PTR(-EOPNOTSUPP
);
2864 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2865 return ERR_PTR(-EINVAL
);
2867 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2868 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2869 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2870 return ERR_PTR(-EINVAL
);
2872 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2873 return ERR_PTR(-EINVAL
);
2875 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2877 return ERR_PTR(n_entries
);
2879 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2880 return ERR_PTR(-ENOTSUPP
);
2882 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2885 return ERR_PTR(-ENOMEM
);
2887 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2888 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2892 acl
->n_acl_entries
= n_entries
;
2893 acl
->acl_policy
= acl_policy
;
2898 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2900 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2901 struct net_device
*dev
= info
->user_ptr
[1];
2902 struct cfg80211_acl_data
*acl
;
2905 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2906 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2909 if (!dev
->ieee80211_ptr
->beacon_interval
)
2912 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2914 return PTR_ERR(acl
);
2916 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2923 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
2924 struct cfg80211_beacon_data
*bcn
)
2926 bool haveinfo
= false;
2928 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2929 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
2930 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2931 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2934 memset(bcn
, 0, sizeof(*bcn
));
2936 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2937 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2938 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2944 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2945 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2946 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2953 if (attrs
[NL80211_ATTR_IE
]) {
2954 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
2955 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
2958 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2959 bcn
->proberesp_ies
=
2960 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2961 bcn
->proberesp_ies_len
=
2962 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2965 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2966 bcn
->assocresp_ies
=
2967 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2968 bcn
->assocresp_ies_len
=
2969 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2972 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
2973 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
2974 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
2980 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2981 struct cfg80211_ap_settings
*params
)
2983 struct wireless_dev
*wdev
;
2986 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2987 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2988 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2991 if (!wdev
->preset_chandef
.chan
)
2994 params
->chandef
= wdev
->preset_chandef
;
3002 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3003 enum nl80211_auth_type auth_type
,
3004 enum nl80211_commands cmd
)
3006 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3010 case NL80211_CMD_AUTHENTICATE
:
3011 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3012 auth_type
== NL80211_AUTHTYPE_SAE
)
3015 case NL80211_CMD_CONNECT
:
3016 case NL80211_CMD_START_AP
:
3017 /* SAE not supported yet */
3018 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3026 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3028 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3029 struct net_device
*dev
= info
->user_ptr
[1];
3030 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3031 struct cfg80211_ap_settings params
;
3033 u8 radar_detect_width
= 0;
3035 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3036 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3039 if (!rdev
->ops
->start_ap
)
3042 if (wdev
->beacon_interval
)
3045 memset(¶ms
, 0, sizeof(params
));
3047 /* these are required for START_AP */
3048 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3049 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3050 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3053 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3057 params
.beacon_interval
=
3058 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3059 params
.dtim_period
=
3060 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3062 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3067 * In theory, some of these attributes should be required here
3068 * but since they were not used when the command was originally
3069 * added, keep them optional for old user space programs to let
3070 * them continue to work with drivers that do not need the
3071 * additional information -- drivers must check!
3073 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3074 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3076 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3077 if (params
.ssid_len
== 0 ||
3078 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3082 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3083 params
.hidden_ssid
= nla_get_u32(
3084 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3085 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3086 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3087 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3091 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3093 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3094 params
.auth_type
= nla_get_u32(
3095 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3096 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3097 NL80211_CMD_START_AP
))
3100 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3102 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3103 NL80211_MAX_NR_CIPHER_SUITES
);
3107 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3108 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3110 params
.inactivity_timeout
= nla_get_u16(
3111 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3114 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3115 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3117 params
.p2p_ctwindow
=
3118 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3119 if (params
.p2p_ctwindow
> 127)
3121 if (params
.p2p_ctwindow
!= 0 &&
3122 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3126 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3129 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3131 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3134 params
.p2p_opp_ps
= tmp
;
3135 if (params
.p2p_opp_ps
!= 0 &&
3136 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3140 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3141 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3144 } else if (wdev
->preset_chandef
.chan
) {
3145 params
.chandef
= wdev
->preset_chandef
;
3146 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3149 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3152 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3156 radar_detect_width
= BIT(params
.chandef
.width
);
3157 params
.radar_required
= true;
3160 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3161 params
.chandef
.chan
,
3163 radar_detect_width
);
3167 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3168 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3169 if (IS_ERR(params
.acl
))
3170 return PTR_ERR(params
.acl
);
3173 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3175 wdev
->preset_chandef
= params
.chandef
;
3176 wdev
->beacon_interval
= params
.beacon_interval
;
3177 wdev
->channel
= params
.chandef
.chan
;
3178 wdev
->ssid_len
= params
.ssid_len
;
3179 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3187 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3190 struct net_device
*dev
= info
->user_ptr
[1];
3191 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3192 struct cfg80211_beacon_data params
;
3195 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3196 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3199 if (!rdev
->ops
->change_beacon
)
3202 if (!wdev
->beacon_interval
)
3205 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3209 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3212 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3214 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3215 struct net_device
*dev
= info
->user_ptr
[1];
3217 return cfg80211_stop_ap(rdev
, dev
);
3220 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3221 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3222 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3223 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3224 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3225 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3226 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3229 static int parse_station_flags(struct genl_info
*info
,
3230 enum nl80211_iftype iftype
,
3231 struct station_parameters
*params
)
3233 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3238 * Try parsing the new attribute first so userspace
3239 * can specify both for older kernels.
3241 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3243 struct nl80211_sta_flag_update
*sta_flags
;
3245 sta_flags
= nla_data(nla
);
3246 params
->sta_flags_mask
= sta_flags
->mask
;
3247 params
->sta_flags_set
= sta_flags
->set
;
3248 params
->sta_flags_set
&= params
->sta_flags_mask
;
3249 if ((params
->sta_flags_mask
|
3250 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3255 /* if present, parse the old attribute */
3257 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3261 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3262 nla
, sta_flags_policy
))
3266 * Only allow certain flags for interface types so that
3267 * other attributes are silently ignored. Remember that
3268 * this is backward compatibility code with old userspace
3269 * and shouldn't be hit in other cases anyway.
3272 case NL80211_IFTYPE_AP
:
3273 case NL80211_IFTYPE_AP_VLAN
:
3274 case NL80211_IFTYPE_P2P_GO
:
3275 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3276 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3277 BIT(NL80211_STA_FLAG_WME
) |
3278 BIT(NL80211_STA_FLAG_MFP
);
3280 case NL80211_IFTYPE_P2P_CLIENT
:
3281 case NL80211_IFTYPE_STATION
:
3282 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3283 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3285 case NL80211_IFTYPE_MESH_POINT
:
3286 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3287 BIT(NL80211_STA_FLAG_MFP
) |
3288 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3293 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3295 params
->sta_flags_set
|= (1<<flag
);
3297 /* no longer support new API additions in old API */
3298 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3306 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3309 struct nlattr
*rate
;
3313 rate
= nla_nest_start(msg
, attr
);
3317 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3318 bitrate
= cfg80211_calculate_bitrate(info
);
3319 /* report 16-bit bitrate only if we can */
3320 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3322 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3324 if (bitrate_compat
> 0 &&
3325 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3328 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3329 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3331 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3332 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3334 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3335 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3337 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3338 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3340 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3342 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3343 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3345 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3346 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3348 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3349 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3351 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3352 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3354 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3355 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3359 nla_nest_end(msg
, rate
);
3363 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3372 attr
= nla_nest_start(msg
, id
);
3376 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3377 if (!(mask
& BIT(i
)))
3380 if (nla_put_u8(msg
, i
, signal
[i
]))
3384 nla_nest_end(msg
, attr
);
3389 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3391 struct cfg80211_registered_device
*rdev
,
3392 struct net_device
*dev
,
3393 const u8
*mac_addr
, struct station_info
*sinfo
)
3396 struct nlattr
*sinfoattr
, *bss_param
;
3398 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3402 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3403 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3404 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3405 goto nla_put_failure
;
3407 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3409 goto nla_put_failure
;
3410 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3411 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3412 sinfo
->connected_time
))
3413 goto nla_put_failure
;
3414 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3415 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3416 sinfo
->inactive_time
))
3417 goto nla_put_failure
;
3418 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3419 STATION_INFO_RX_BYTES64
)) &&
3420 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3421 (u32
)sinfo
->rx_bytes
))
3422 goto nla_put_failure
;
3423 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3424 STATION_INFO_TX_BYTES64
)) &&
3425 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3426 (u32
)sinfo
->tx_bytes
))
3427 goto nla_put_failure
;
3428 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3429 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3431 goto nla_put_failure
;
3432 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3433 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3435 goto nla_put_failure
;
3436 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3437 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3438 goto nla_put_failure
;
3439 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3440 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3441 goto nla_put_failure
;
3442 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3443 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3444 sinfo
->plink_state
))
3445 goto nla_put_failure
;
3446 switch (rdev
->wiphy
.signal_type
) {
3447 case CFG80211_SIGNAL_TYPE_MBM
:
3448 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3449 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3451 goto nla_put_failure
;
3452 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3453 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3455 goto nla_put_failure
;
3460 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL
) {
3461 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3462 sinfo
->chain_signal
,
3463 NL80211_STA_INFO_CHAIN_SIGNAL
))
3464 goto nla_put_failure
;
3466 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL_AVG
) {
3467 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3468 sinfo
->chain_signal_avg
,
3469 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3470 goto nla_put_failure
;
3472 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3473 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3474 NL80211_STA_INFO_TX_BITRATE
))
3475 goto nla_put_failure
;
3477 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3478 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3479 NL80211_STA_INFO_RX_BITRATE
))
3480 goto nla_put_failure
;
3482 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3483 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3485 goto nla_put_failure
;
3486 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3487 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3489 goto nla_put_failure
;
3490 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3491 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3493 goto nla_put_failure
;
3494 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3495 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3497 goto nla_put_failure
;
3498 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3499 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3500 sinfo
->beacon_loss_count
))
3501 goto nla_put_failure
;
3502 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3503 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3505 goto nla_put_failure
;
3506 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3507 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3509 goto nla_put_failure
;
3510 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3511 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3513 goto nla_put_failure
;
3514 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3515 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3517 goto nla_put_failure
;
3519 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3520 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3521 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3522 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3523 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3524 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3525 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3526 sinfo
->bss_param
.dtim_period
) ||
3527 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3528 sinfo
->bss_param
.beacon_interval
))
3529 goto nla_put_failure
;
3531 nla_nest_end(msg
, bss_param
);
3533 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3534 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3535 sizeof(struct nl80211_sta_flag_update
),
3537 goto nla_put_failure
;
3538 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3539 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3541 goto nla_put_failure
;
3542 nla_nest_end(msg
, sinfoattr
);
3544 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3545 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3546 sinfo
->assoc_req_ies
))
3547 goto nla_put_failure
;
3549 return genlmsg_end(msg
, hdr
);
3552 genlmsg_cancel(msg
, hdr
);
3556 static int nl80211_dump_station(struct sk_buff
*skb
,
3557 struct netlink_callback
*cb
)
3559 struct station_info sinfo
;
3560 struct cfg80211_registered_device
*dev
;
3561 struct wireless_dev
*wdev
;
3562 u8 mac_addr
[ETH_ALEN
];
3563 int sta_idx
= cb
->args
[2];
3566 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3570 if (!wdev
->netdev
) {
3575 if (!dev
->ops
->dump_station
) {
3581 memset(&sinfo
, 0, sizeof(sinfo
));
3582 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3589 if (nl80211_send_station(skb
,
3590 NETLINK_CB(cb
->skb
).portid
,
3591 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3592 dev
, wdev
->netdev
, mac_addr
,
3601 cb
->args
[2] = sta_idx
;
3604 nl80211_finish_wdev_dump(dev
);
3609 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3611 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3612 struct net_device
*dev
= info
->user_ptr
[1];
3613 struct station_info sinfo
;
3614 struct sk_buff
*msg
;
3615 u8
*mac_addr
= NULL
;
3618 memset(&sinfo
, 0, sizeof(sinfo
));
3620 if (!info
->attrs
[NL80211_ATTR_MAC
])
3623 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3625 if (!rdev
->ops
->get_station
)
3628 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3632 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3636 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3637 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3642 return genlmsg_reply(msg
, info
);
3645 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3646 struct station_parameters
*params
,
3647 enum cfg80211_station_type statype
)
3649 if (params
->listen_interval
!= -1)
3654 /* When you run into this, adjust the code below for the new flag */
3655 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3658 case CFG80211_STA_MESH_PEER_KERNEL
:
3659 case CFG80211_STA_MESH_PEER_USER
:
3661 * No ignoring the TDLS flag here -- the userspace mesh
3662 * code doesn't have the bug of including TDLS in the
3665 if (params
->sta_flags_mask
&
3666 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3667 BIT(NL80211_STA_FLAG_MFP
) |
3668 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3671 case CFG80211_STA_TDLS_PEER_SETUP
:
3672 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3673 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3675 /* ignore since it can't change */
3676 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3679 /* disallow mesh-specific things */
3680 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3682 if (params
->local_pm
)
3684 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3688 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3689 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3690 /* TDLS can't be set, ... */
3691 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3694 * ... but don't bother the driver with it. This works around
3695 * a hostapd/wpa_supplicant issue -- it always includes the
3696 * TLDS_PEER flag in the mask even for AP mode.
3698 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3701 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3702 /* reject other things that can't change */
3703 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3705 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3707 if (params
->supported_rates
)
3709 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3713 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3719 case CFG80211_STA_AP_MLME_CLIENT
:
3720 /* Use this only for authorizing/unauthorizing a station */
3721 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3724 case CFG80211_STA_AP_CLIENT
:
3725 /* accept only the listed bits */
3726 if (params
->sta_flags_mask
&
3727 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3728 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3729 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3730 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3731 BIT(NL80211_STA_FLAG_WME
) |
3732 BIT(NL80211_STA_FLAG_MFP
)))
3735 /* but authenticated/associated only if driver handles it */
3736 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3737 params
->sta_flags_mask
&
3738 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3739 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3742 case CFG80211_STA_IBSS
:
3743 case CFG80211_STA_AP_STA
:
3744 /* reject any changes other than AUTHORIZED */
3745 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3748 case CFG80211_STA_TDLS_PEER_SETUP
:
3749 /* reject any changes other than AUTHORIZED or WME */
3750 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3751 BIT(NL80211_STA_FLAG_WME
)))
3753 /* force (at least) rates when authorizing */
3754 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3755 !params
->supported_rates
)
3758 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3759 /* reject any changes */
3761 case CFG80211_STA_MESH_PEER_KERNEL
:
3762 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3765 case CFG80211_STA_MESH_PEER_USER
:
3766 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3773 EXPORT_SYMBOL(cfg80211_check_station_change
);
3776 * Get vlan interface making sure it is running and on the right wiphy.
3778 static struct net_device
*get_vlan(struct genl_info
*info
,
3779 struct cfg80211_registered_device
*rdev
)
3781 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3782 struct net_device
*v
;
3788 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3790 return ERR_PTR(-ENODEV
);
3792 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3797 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3798 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3799 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3804 if (!netif_running(v
)) {
3812 return ERR_PTR(ret
);
3815 static struct nla_policy
3816 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3817 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3818 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3821 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3822 struct station_parameters
*params
)
3824 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3828 /* parse WME attributes if present */
3829 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3832 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3833 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3834 nl80211_sta_wme_policy
);
3838 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3839 params
->uapsd_queues
= nla_get_u8(
3840 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3841 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3844 if (tb
[NL80211_STA_WME_MAX_SP
])
3845 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3847 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3850 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3855 static int nl80211_set_station_tdls(struct genl_info
*info
,
3856 struct station_parameters
*params
)
3858 /* Dummy STA entry gets updated once the peer capabilities are known */
3859 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
3860 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
3861 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3863 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3864 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3866 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3868 return nl80211_parse_sta_wme(info
, params
);
3871 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3873 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3874 struct net_device
*dev
= info
->user_ptr
[1];
3875 struct station_parameters params
;
3879 memset(¶ms
, 0, sizeof(params
));
3881 params
.listen_interval
= -1;
3883 if (!rdev
->ops
->change_station
)
3886 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3889 if (!info
->attrs
[NL80211_ATTR_MAC
])
3892 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3894 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3895 params
.supported_rates
=
3896 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3897 params
.supported_rates_len
=
3898 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3901 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3903 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3904 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3907 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3909 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3910 params
.ext_capab_len
=
3911 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3914 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3917 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3920 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3921 params
.plink_action
=
3922 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3923 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3927 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3928 params
.plink_state
=
3929 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3930 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3932 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3935 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3936 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3937 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3939 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3940 pm
> NL80211_MESH_POWER_MAX
)
3943 params
.local_pm
= pm
;
3946 /* Include parameters for TDLS peer (will check later) */
3947 err
= nl80211_set_station_tdls(info
, ¶ms
);
3951 params
.vlan
= get_vlan(info
, rdev
);
3952 if (IS_ERR(params
.vlan
))
3953 return PTR_ERR(params
.vlan
);
3955 switch (dev
->ieee80211_ptr
->iftype
) {
3956 case NL80211_IFTYPE_AP
:
3957 case NL80211_IFTYPE_AP_VLAN
:
3958 case NL80211_IFTYPE_P2P_GO
:
3959 case NL80211_IFTYPE_P2P_CLIENT
:
3960 case NL80211_IFTYPE_STATION
:
3961 case NL80211_IFTYPE_ADHOC
:
3962 case NL80211_IFTYPE_MESH_POINT
:
3969 /* driver will call cfg80211_check_station_change() */
3970 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3974 dev_put(params
.vlan
);
3979 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3981 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3983 struct net_device
*dev
= info
->user_ptr
[1];
3984 struct station_parameters params
;
3985 u8
*mac_addr
= NULL
;
3987 memset(¶ms
, 0, sizeof(params
));
3989 if (!rdev
->ops
->add_station
)
3992 if (!info
->attrs
[NL80211_ATTR_MAC
])
3995 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3998 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4001 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4002 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4005 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4006 params
.supported_rates
=
4007 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4008 params
.supported_rates_len
=
4009 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4010 params
.listen_interval
=
4011 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4013 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4014 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4016 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4017 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4020 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4022 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4023 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4026 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4028 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4029 params
.ext_capab_len
=
4030 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4033 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4035 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4037 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4039 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4041 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4042 params
.plink_action
=
4043 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4044 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4048 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4052 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4055 /* When you run into this, adjust the code below for the new flag */
4056 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4058 switch (dev
->ieee80211_ptr
->iftype
) {
4059 case NL80211_IFTYPE_AP
:
4060 case NL80211_IFTYPE_AP_VLAN
:
4061 case NL80211_IFTYPE_P2P_GO
:
4062 /* ignore WME attributes if iface/sta is not capable */
4063 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4064 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4065 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4067 /* TDLS peers cannot be added */
4068 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4069 info
->attrs
[NL80211_ATTR_PEER_AID
])
4071 /* but don't bother the driver with it */
4072 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4074 /* allow authenticated/associated only if driver handles it */
4075 if (!(rdev
->wiphy
.features
&
4076 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4077 params
.sta_flags_mask
&
4078 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4079 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4082 /* must be last in here for error handling */
4083 params
.vlan
= get_vlan(info
, rdev
);
4084 if (IS_ERR(params
.vlan
))
4085 return PTR_ERR(params
.vlan
);
4087 case NL80211_IFTYPE_MESH_POINT
:
4088 /* ignore uAPSD data */
4089 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4091 /* associated is disallowed */
4092 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4094 /* TDLS peers cannot be added */
4095 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4096 info
->attrs
[NL80211_ATTR_PEER_AID
])
4099 case NL80211_IFTYPE_STATION
:
4100 case NL80211_IFTYPE_P2P_CLIENT
:
4101 /* ignore uAPSD data */
4102 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4104 /* these are disallowed */
4105 if (params
.sta_flags_mask
&
4106 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4107 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4109 /* Only TDLS peers can be added */
4110 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4112 /* Can only add if TDLS ... */
4113 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4115 /* ... with external setup is supported */
4116 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4119 * Older wpa_supplicant versions always mark the TDLS peer
4120 * as authorized, but it shouldn't yet be.
4122 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4128 /* be aware of params.vlan when changing code here */
4130 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4133 dev_put(params
.vlan
);
4137 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4140 struct net_device
*dev
= info
->user_ptr
[1];
4141 u8
*mac_addr
= NULL
;
4143 if (info
->attrs
[NL80211_ATTR_MAC
])
4144 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4146 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4147 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4148 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4149 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4152 if (!rdev
->ops
->del_station
)
4155 return rdev_del_station(rdev
, dev
, mac_addr
);
4158 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4159 int flags
, struct net_device
*dev
,
4160 u8
*dst
, u8
*next_hop
,
4161 struct mpath_info
*pinfo
)
4164 struct nlattr
*pinfoattr
;
4166 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4170 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4171 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4172 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4173 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4174 goto nla_put_failure
;
4176 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4178 goto nla_put_failure
;
4179 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4180 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4182 goto nla_put_failure
;
4183 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4184 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4185 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4186 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4188 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4189 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4191 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4192 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4194 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4195 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4196 pinfo
->discovery_timeout
)) ||
4197 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4198 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4199 pinfo
->discovery_retries
)))
4200 goto nla_put_failure
;
4202 nla_nest_end(msg
, pinfoattr
);
4204 return genlmsg_end(msg
, hdr
);
4207 genlmsg_cancel(msg
, hdr
);
4211 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4212 struct netlink_callback
*cb
)
4214 struct mpath_info pinfo
;
4215 struct cfg80211_registered_device
*dev
;
4216 struct wireless_dev
*wdev
;
4218 u8 next_hop
[ETH_ALEN
];
4219 int path_idx
= cb
->args
[2];
4222 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4226 if (!dev
->ops
->dump_mpath
) {
4231 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4237 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4244 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4245 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4246 wdev
->netdev
, dst
, next_hop
,
4255 cb
->args
[2] = path_idx
;
4258 nl80211_finish_wdev_dump(dev
);
4262 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4264 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4266 struct net_device
*dev
= info
->user_ptr
[1];
4267 struct mpath_info pinfo
;
4268 struct sk_buff
*msg
;
4270 u8 next_hop
[ETH_ALEN
];
4272 memset(&pinfo
, 0, sizeof(pinfo
));
4274 if (!info
->attrs
[NL80211_ATTR_MAC
])
4277 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4279 if (!rdev
->ops
->get_mpath
)
4282 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4285 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4289 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4293 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4294 dev
, dst
, next_hop
, &pinfo
) < 0) {
4299 return genlmsg_reply(msg
, info
);
4302 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4304 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4305 struct net_device
*dev
= info
->user_ptr
[1];
4307 u8
*next_hop
= NULL
;
4309 if (!info
->attrs
[NL80211_ATTR_MAC
])
4312 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4315 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4316 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4318 if (!rdev
->ops
->change_mpath
)
4321 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4324 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4327 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4329 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4330 struct net_device
*dev
= info
->user_ptr
[1];
4332 u8
*next_hop
= NULL
;
4334 if (!info
->attrs
[NL80211_ATTR_MAC
])
4337 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4340 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4341 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4343 if (!rdev
->ops
->add_mpath
)
4346 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4349 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4352 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4354 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4355 struct net_device
*dev
= info
->user_ptr
[1];
4358 if (info
->attrs
[NL80211_ATTR_MAC
])
4359 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4361 if (!rdev
->ops
->del_mpath
)
4364 return rdev_del_mpath(rdev
, dev
, dst
);
4367 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4369 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4370 struct net_device
*dev
= info
->user_ptr
[1];
4371 struct bss_parameters params
;
4373 memset(¶ms
, 0, sizeof(params
));
4374 /* default to not changing parameters */
4375 params
.use_cts_prot
= -1;
4376 params
.use_short_preamble
= -1;
4377 params
.use_short_slot_time
= -1;
4378 params
.ap_isolate
= -1;
4379 params
.ht_opmode
= -1;
4380 params
.p2p_ctwindow
= -1;
4381 params
.p2p_opp_ps
= -1;
4383 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4384 params
.use_cts_prot
=
4385 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4386 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4387 params
.use_short_preamble
=
4388 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4389 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4390 params
.use_short_slot_time
=
4391 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4392 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4393 params
.basic_rates
=
4394 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4395 params
.basic_rates_len
=
4396 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4398 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4399 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4400 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4402 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4404 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4405 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4407 params
.p2p_ctwindow
=
4408 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4409 if (params
.p2p_ctwindow
< 0)
4411 if (params
.p2p_ctwindow
!= 0 &&
4412 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4416 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4419 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4421 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4424 params
.p2p_opp_ps
= tmp
;
4425 if (params
.p2p_opp_ps
&&
4426 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4430 if (!rdev
->ops
->change_bss
)
4433 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4434 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4437 return rdev_change_bss(rdev
, dev
, ¶ms
);
4440 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4441 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4442 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4443 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4444 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4445 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4446 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4449 static int parse_reg_rule(struct nlattr
*tb
[],
4450 struct ieee80211_reg_rule
*reg_rule
)
4452 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4453 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4455 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4457 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4459 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4461 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4463 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4466 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4468 freq_range
->start_freq_khz
=
4469 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4470 freq_range
->end_freq_khz
=
4471 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4472 freq_range
->max_bandwidth_khz
=
4473 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4475 power_rule
->max_eirp
=
4476 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4478 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4479 power_rule
->max_antenna_gain
=
4480 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4485 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4489 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4492 * You should only get this when cfg80211 hasn't yet initialized
4493 * completely when built-in to the kernel right between the time
4494 * window between nl80211_init() and regulatory_init(), if that is
4497 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4498 return -EINPROGRESS
;
4500 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4503 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4505 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4506 user_reg_hint_type
=
4507 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4509 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4511 switch (user_reg_hint_type
) {
4512 case NL80211_USER_REG_HINT_USER
:
4513 case NL80211_USER_REG_HINT_CELL_BASE
:
4519 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4524 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4525 struct genl_info
*info
)
4527 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4528 struct net_device
*dev
= info
->user_ptr
[1];
4529 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4530 struct mesh_config cur_params
;
4533 struct nlattr
*pinfoattr
;
4534 struct sk_buff
*msg
;
4536 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4539 if (!rdev
->ops
->get_mesh_config
)
4543 /* If not connected, get default parameters */
4544 if (!wdev
->mesh_id_len
)
4545 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4547 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4553 /* Draw up a netlink message to send back */
4554 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4557 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4558 NL80211_CMD_GET_MESH_CONFIG
);
4561 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4563 goto nla_put_failure
;
4564 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4565 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4566 cur_params
.dot11MeshRetryTimeout
) ||
4567 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4568 cur_params
.dot11MeshConfirmTimeout
) ||
4569 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4570 cur_params
.dot11MeshHoldingTimeout
) ||
4571 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4572 cur_params
.dot11MeshMaxPeerLinks
) ||
4573 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4574 cur_params
.dot11MeshMaxRetries
) ||
4575 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4576 cur_params
.dot11MeshTTL
) ||
4577 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4578 cur_params
.element_ttl
) ||
4579 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4580 cur_params
.auto_open_plinks
) ||
4581 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4582 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4583 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4584 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4585 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4586 cur_params
.path_refresh_time
) ||
4587 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4588 cur_params
.min_discovery_timeout
) ||
4589 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4590 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4591 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4592 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4593 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4594 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4595 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4596 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4597 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4598 cur_params
.dot11MeshHWMPRootMode
) ||
4599 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4600 cur_params
.dot11MeshHWMPRannInterval
) ||
4601 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4602 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4603 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4604 cur_params
.dot11MeshForwarding
) ||
4605 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4606 cur_params
.rssi_threshold
) ||
4607 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4608 cur_params
.ht_opmode
) ||
4609 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4610 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4611 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4612 cur_params
.dot11MeshHWMProotInterval
) ||
4613 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4614 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4615 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4616 cur_params
.power_mode
) ||
4617 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4618 cur_params
.dot11MeshAwakeWindowDuration
) ||
4619 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4620 cur_params
.plink_timeout
))
4621 goto nla_put_failure
;
4622 nla_nest_end(msg
, pinfoattr
);
4623 genlmsg_end(msg
, hdr
);
4624 return genlmsg_reply(msg
, info
);
4627 genlmsg_cancel(msg
, hdr
);
4633 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4634 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4635 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4636 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4637 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4638 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4639 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4640 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4641 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4642 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4643 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4644 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4645 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4646 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4647 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4648 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4649 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4650 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4651 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4652 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4653 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4654 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4655 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4656 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4657 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4658 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4659 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4660 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4661 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
4664 static const struct nla_policy
4665 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4666 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4667 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4668 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4669 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4670 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
4671 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4672 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4673 .len
= IEEE80211_MAX_DATA_LEN
},
4674 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4677 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4678 struct mesh_config
*cfg
,
4681 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4684 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4687 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4689 cfg->param = fn(tb[attr]); \
4690 mask |= (1 << (attr - 1)); \
4695 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4697 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4698 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4699 nl80211_meshconf_params_policy
))
4702 /* This makes sure that there aren't more than 32 mesh config
4703 * parameters (otherwise our bitfield scheme would not work.) */
4704 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4706 /* Fill in the params struct */
4707 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4708 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4710 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4711 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4713 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4714 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4716 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4717 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4719 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4720 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4722 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4723 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4724 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4725 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4727 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4728 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4730 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4732 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4734 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4735 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4737 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4738 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4740 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4741 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4743 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4745 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4747 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4749 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4751 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4753 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4755 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4756 dot11MeshHWMPnetDiameterTraversalTime
,
4758 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4760 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4761 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4763 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4764 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4766 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4767 dot11MeshGateAnnouncementProtocol
, 0, 1,
4768 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4770 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4771 mask
, NL80211_MESHCONF_FORWARDING
,
4773 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4774 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4776 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4777 mask
, NL80211_MESHCONF_HT_OPMODE
,
4779 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4781 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4783 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4784 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4786 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4787 dot11MeshHWMPconfirmationInterval
,
4789 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4791 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4792 NL80211_MESH_POWER_ACTIVE
,
4793 NL80211_MESH_POWER_MAX
,
4794 mask
, NL80211_MESHCONF_POWER_MODE
,
4796 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4798 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4799 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 1, 0xffffffff,
4800 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4807 #undef FILL_IN_MESH_PARAM_IF_SET
4810 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4811 struct mesh_setup
*setup
)
4813 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4814 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4816 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4818 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4819 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4820 nl80211_mesh_setup_params_policy
))
4823 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4824 setup
->sync_method
=
4825 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4826 IEEE80211_SYNC_METHOD_VENDOR
:
4827 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4829 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4830 setup
->path_sel_proto
=
4831 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4832 IEEE80211_PATH_PROTOCOL_VENDOR
:
4833 IEEE80211_PATH_PROTOCOL_HWMP
;
4835 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4836 setup
->path_metric
=
4837 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4838 IEEE80211_PATH_METRIC_VENDOR
:
4839 IEEE80211_PATH_METRIC_AIRTIME
;
4842 if (tb
[NL80211_MESH_SETUP_IE
]) {
4843 struct nlattr
*ieattr
=
4844 tb
[NL80211_MESH_SETUP_IE
];
4845 if (!is_valid_ie_attr(ieattr
))
4847 setup
->ie
= nla_data(ieattr
);
4848 setup
->ie_len
= nla_len(ieattr
);
4850 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4851 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4853 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4854 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4855 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4856 if (setup
->is_secure
)
4857 setup
->user_mpm
= true;
4859 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
4860 if (!setup
->user_mpm
)
4863 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
4869 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4870 struct genl_info
*info
)
4872 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4873 struct net_device
*dev
= info
->user_ptr
[1];
4874 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4875 struct mesh_config cfg
;
4879 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4882 if (!rdev
->ops
->update_mesh_config
)
4885 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4890 if (!wdev
->mesh_id_len
)
4894 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4901 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4903 const struct ieee80211_regdomain
*regdom
;
4904 struct sk_buff
*msg
;
4906 struct nlattr
*nl_reg_rules
;
4909 if (!cfg80211_regdomain
)
4912 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4916 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4917 NL80211_CMD_GET_REG
);
4921 if (reg_last_request_cell_base() &&
4922 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4923 NL80211_USER_REG_HINT_CELL_BASE
))
4924 goto nla_put_failure
;
4927 regdom
= rcu_dereference(cfg80211_regdomain
);
4929 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4930 (regdom
->dfs_region
&&
4931 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4932 goto nla_put_failure_rcu
;
4934 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4936 goto nla_put_failure_rcu
;
4938 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4939 struct nlattr
*nl_reg_rule
;
4940 const struct ieee80211_reg_rule
*reg_rule
;
4941 const struct ieee80211_freq_range
*freq_range
;
4942 const struct ieee80211_power_rule
*power_rule
;
4944 reg_rule
= ®dom
->reg_rules
[i
];
4945 freq_range
= ®_rule
->freq_range
;
4946 power_rule
= ®_rule
->power_rule
;
4948 nl_reg_rule
= nla_nest_start(msg
, i
);
4950 goto nla_put_failure_rcu
;
4952 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4954 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4955 freq_range
->start_freq_khz
) ||
4956 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4957 freq_range
->end_freq_khz
) ||
4958 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4959 freq_range
->max_bandwidth_khz
) ||
4960 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4961 power_rule
->max_antenna_gain
) ||
4962 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4963 power_rule
->max_eirp
))
4964 goto nla_put_failure_rcu
;
4966 nla_nest_end(msg
, nl_reg_rule
);
4970 nla_nest_end(msg
, nl_reg_rules
);
4972 genlmsg_end(msg
, hdr
);
4973 return genlmsg_reply(msg
, info
);
4975 nla_put_failure_rcu
:
4978 genlmsg_cancel(msg
, hdr
);
4984 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4986 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4987 struct nlattr
*nl_reg_rule
;
4988 char *alpha2
= NULL
;
4989 int rem_reg_rules
= 0, r
= 0;
4990 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4992 struct ieee80211_regdomain
*rd
= NULL
;
4994 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4997 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5000 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5002 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5003 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5005 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5008 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5012 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5013 num_rules
* sizeof(struct ieee80211_reg_rule
);
5015 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5019 rd
->n_reg_rules
= num_rules
;
5020 rd
->alpha2
[0] = alpha2
[0];
5021 rd
->alpha2
[1] = alpha2
[1];
5024 * Disable DFS master mode if the DFS region was
5025 * not supported or known on this kernel.
5027 if (reg_supported_dfs_region(dfs_region
))
5028 rd
->dfs_region
= dfs_region
;
5030 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5032 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5033 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5035 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5041 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5048 /* set_regdom took ownership */
5056 static int validate_scan_freqs(struct nlattr
*freqs
)
5058 struct nlattr
*attr1
, *attr2
;
5059 int n_channels
= 0, tmp1
, tmp2
;
5061 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5064 * Some hardware has a limited channel list for
5065 * scanning, and it is pretty much nonsensical
5066 * to scan for a channel twice, so disallow that
5067 * and don't require drivers to check that the
5068 * channel list they get isn't longer than what
5069 * they can scan, as long as they can scan all
5070 * the channels they registered at once.
5072 nla_for_each_nested(attr2
, freqs
, tmp2
)
5073 if (attr1
!= attr2
&&
5074 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5081 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5083 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5084 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5085 struct cfg80211_scan_request
*request
;
5086 struct nlattr
*attr
;
5087 struct wiphy
*wiphy
;
5088 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5091 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5094 wiphy
= &rdev
->wiphy
;
5096 if (!rdev
->ops
->scan
)
5099 if (rdev
->scan_req
) {
5104 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5105 n_channels
= validate_scan_freqs(
5106 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5112 enum ieee80211_band band
;
5115 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5116 if (wiphy
->bands
[band
])
5117 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5120 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5121 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5124 if (n_ssids
> wiphy
->max_scan_ssids
) {
5129 if (info
->attrs
[NL80211_ATTR_IE
])
5130 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5134 if (ie_len
> wiphy
->max_scan_ie_len
) {
5139 request
= kzalloc(sizeof(*request
)
5140 + sizeof(*request
->ssids
) * n_ssids
5141 + sizeof(*request
->channels
) * n_channels
5142 + ie_len
, GFP_KERNEL
);
5149 request
->ssids
= (void *)&request
->channels
[n_channels
];
5150 request
->n_ssids
= n_ssids
;
5153 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5155 request
->ie
= (void *)(request
->channels
+ n_channels
);
5159 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5160 /* user specified, bail out if channel not found */
5161 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5162 struct ieee80211_channel
*chan
;
5164 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5171 /* ignore disabled channels */
5172 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5175 request
->channels
[i
] = chan
;
5179 enum ieee80211_band band
;
5182 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5184 if (!wiphy
->bands
[band
])
5186 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5187 struct ieee80211_channel
*chan
;
5189 chan
= &wiphy
->bands
[band
]->channels
[j
];
5191 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5194 request
->channels
[i
] = chan
;
5205 request
->n_channels
= i
;
5208 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5209 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5210 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5214 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5215 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5220 if (info
->attrs
[NL80211_ATTR_IE
]) {
5221 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5222 memcpy((void *)request
->ie
,
5223 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5227 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5228 if (wiphy
->bands
[i
])
5230 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5232 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5233 nla_for_each_nested(attr
,
5234 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5236 enum ieee80211_band band
= nla_type(attr
);
5238 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5242 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5245 &request
->rates
[band
]);
5251 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5252 request
->flags
= nla_get_u32(
5253 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5254 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5255 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5256 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5257 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5264 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5266 request
->wdev
= wdev
;
5267 request
->wiphy
= &rdev
->wiphy
;
5268 request
->scan_start
= jiffies
;
5270 rdev
->scan_req
= request
;
5271 err
= rdev_scan(rdev
, request
);
5274 nl80211_send_scan_start(rdev
, wdev
);
5276 dev_hold(wdev
->netdev
);
5279 rdev
->scan_req
= NULL
;
5287 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5288 struct genl_info
*info
)
5290 struct cfg80211_sched_scan_request
*request
;
5291 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5292 struct net_device
*dev
= info
->user_ptr
[1];
5293 struct nlattr
*attr
;
5294 struct wiphy
*wiphy
;
5295 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5297 enum ieee80211_band band
;
5299 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5301 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5302 !rdev
->ops
->sched_scan_start
)
5305 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5308 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5311 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5315 wiphy
= &rdev
->wiphy
;
5317 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5318 n_channels
= validate_scan_freqs(
5319 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5325 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5326 if (wiphy
->bands
[band
])
5327 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5330 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5331 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5335 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5338 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5339 nla_for_each_nested(attr
,
5340 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5344 if (n_match_sets
> wiphy
->max_match_sets
)
5347 if (info
->attrs
[NL80211_ATTR_IE
])
5348 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5352 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5355 if (rdev
->sched_scan_req
) {
5360 request
= kzalloc(sizeof(*request
)
5361 + sizeof(*request
->ssids
) * n_ssids
5362 + sizeof(*request
->match_sets
) * n_match_sets
5363 + sizeof(*request
->channels
) * n_channels
5364 + ie_len
, GFP_KERNEL
);
5371 request
->ssids
= (void *)&request
->channels
[n_channels
];
5372 request
->n_ssids
= n_ssids
;
5375 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5377 request
->ie
= (void *)(request
->channels
+ n_channels
);
5382 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5383 else if (request
->ssids
)
5384 request
->match_sets
=
5385 (void *)(request
->ssids
+ n_ssids
);
5387 request
->match_sets
=
5388 (void *)(request
->channels
+ n_channels
);
5390 request
->n_match_sets
= n_match_sets
;
5393 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5394 /* user specified, bail out if channel not found */
5395 nla_for_each_nested(attr
,
5396 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5398 struct ieee80211_channel
*chan
;
5400 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5407 /* ignore disabled channels */
5408 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5411 request
->channels
[i
] = chan
;
5416 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5418 if (!wiphy
->bands
[band
])
5420 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5421 struct ieee80211_channel
*chan
;
5423 chan
= &wiphy
->bands
[band
]->channels
[j
];
5425 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5428 request
->channels
[i
] = chan
;
5439 request
->n_channels
= i
;
5442 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5443 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5445 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5449 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5450 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5457 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5458 nla_for_each_nested(attr
,
5459 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5461 struct nlattr
*ssid
, *rssi
;
5463 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5464 nla_data(attr
), nla_len(attr
),
5465 nl80211_match_policy
);
5466 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5468 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5472 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5473 nla_data(ssid
), nla_len(ssid
));
5474 request
->match_sets
[i
].ssid
.ssid_len
=
5477 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5479 request
->rssi_thold
= nla_get_u32(rssi
);
5481 request
->rssi_thold
=
5482 NL80211_SCAN_RSSI_THOLD_OFF
;
5487 if (info
->attrs
[NL80211_ATTR_IE
]) {
5488 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5489 memcpy((void *)request
->ie
,
5490 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5494 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5495 request
->flags
= nla_get_u32(
5496 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5497 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5498 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5499 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5500 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5507 request
->wiphy
= &rdev
->wiphy
;
5508 request
->interval
= interval
;
5509 request
->scan_start
= jiffies
;
5511 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5513 rdev
->sched_scan_req
= request
;
5514 nl80211_send_sched_scan(rdev
, dev
,
5515 NL80211_CMD_START_SCHED_SCAN
);
5525 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5526 struct genl_info
*info
)
5528 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5530 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5531 !rdev
->ops
->sched_scan_stop
)
5534 return __cfg80211_stop_sched_scan(rdev
, false);
5537 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5538 struct genl_info
*info
)
5540 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5541 struct net_device
*dev
= info
->user_ptr
[1];
5542 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5543 struct cfg80211_chan_def chandef
;
5546 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5550 if (wdev
->cac_started
)
5553 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5560 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5563 if (!rdev
->ops
->start_radar_detection
)
5566 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5567 chandef
.chan
, CHAN_MODE_SHARED
,
5568 BIT(chandef
.width
));
5572 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5574 wdev
->channel
= chandef
.chan
;
5575 wdev
->cac_started
= true;
5576 wdev
->cac_start_time
= jiffies
;
5581 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5583 struct cfg80211_registered_device
*rdev
,
5584 struct wireless_dev
*wdev
,
5585 struct cfg80211_internal_bss
*intbss
)
5587 struct cfg80211_bss
*res
= &intbss
->pub
;
5588 const struct cfg80211_bss_ies
*ies
;
5593 ASSERT_WDEV_LOCK(wdev
);
5595 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5596 NL80211_CMD_NEW_SCAN_RESULTS
);
5600 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5602 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5603 goto nla_put_failure
;
5605 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5606 goto nla_put_failure
;
5607 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5608 goto nla_put_failure
;
5610 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5612 goto nla_put_failure
;
5613 if ((!is_zero_ether_addr(res
->bssid
) &&
5614 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5615 goto nla_put_failure
;
5618 ies
= rcu_dereference(res
->ies
);
5620 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5621 goto fail_unlock_rcu
;
5623 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5624 ies
->len
, ies
->data
))
5625 goto fail_unlock_rcu
;
5627 ies
= rcu_dereference(res
->beacon_ies
);
5629 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5630 goto fail_unlock_rcu
;
5631 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5632 ies
->len
, ies
->data
))
5633 goto fail_unlock_rcu
;
5637 if (res
->beacon_interval
&&
5638 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5639 goto nla_put_failure
;
5640 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5641 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5642 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5643 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5644 goto nla_put_failure
;
5646 switch (rdev
->wiphy
.signal_type
) {
5647 case CFG80211_SIGNAL_TYPE_MBM
:
5648 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5649 goto nla_put_failure
;
5651 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5652 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5653 goto nla_put_failure
;
5659 switch (wdev
->iftype
) {
5660 case NL80211_IFTYPE_P2P_CLIENT
:
5661 case NL80211_IFTYPE_STATION
:
5662 if (intbss
== wdev
->current_bss
&&
5663 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5664 NL80211_BSS_STATUS_ASSOCIATED
))
5665 goto nla_put_failure
;
5667 case NL80211_IFTYPE_ADHOC
:
5668 if (intbss
== wdev
->current_bss
&&
5669 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5670 NL80211_BSS_STATUS_IBSS_JOINED
))
5671 goto nla_put_failure
;
5677 nla_nest_end(msg
, bss
);
5679 return genlmsg_end(msg
, hdr
);
5684 genlmsg_cancel(msg
, hdr
);
5688 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5690 struct cfg80211_registered_device
*rdev
;
5691 struct cfg80211_internal_bss
*scan
;
5692 struct wireless_dev
*wdev
;
5693 int start
= cb
->args
[2], idx
= 0;
5696 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5701 spin_lock_bh(&rdev
->bss_lock
);
5702 cfg80211_bss_expire(rdev
);
5704 cb
->seq
= rdev
->bss_generation
;
5706 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5709 if (nl80211_send_bss(skb
, cb
,
5710 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5711 rdev
, wdev
, scan
) < 0) {
5717 spin_unlock_bh(&rdev
->bss_lock
);
5721 nl80211_finish_wdev_dump(rdev
);
5726 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5727 int flags
, struct net_device
*dev
,
5728 struct survey_info
*survey
)
5731 struct nlattr
*infoattr
;
5733 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5734 NL80211_CMD_NEW_SURVEY_RESULTS
);
5738 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5739 goto nla_put_failure
;
5741 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5743 goto nla_put_failure
;
5745 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5746 survey
->channel
->center_freq
))
5747 goto nla_put_failure
;
5749 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5750 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5751 goto nla_put_failure
;
5752 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5753 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5754 goto nla_put_failure
;
5755 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5756 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5757 survey
->channel_time
))
5758 goto nla_put_failure
;
5759 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5760 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5761 survey
->channel_time_busy
))
5762 goto nla_put_failure
;
5763 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5764 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5765 survey
->channel_time_ext_busy
))
5766 goto nla_put_failure
;
5767 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5768 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5769 survey
->channel_time_rx
))
5770 goto nla_put_failure
;
5771 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5772 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5773 survey
->channel_time_tx
))
5774 goto nla_put_failure
;
5776 nla_nest_end(msg
, infoattr
);
5778 return genlmsg_end(msg
, hdr
);
5781 genlmsg_cancel(msg
, hdr
);
5785 static int nl80211_dump_survey(struct sk_buff
*skb
,
5786 struct netlink_callback
*cb
)
5788 struct survey_info survey
;
5789 struct cfg80211_registered_device
*dev
;
5790 struct wireless_dev
*wdev
;
5791 int survey_idx
= cb
->args
[2];
5794 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5798 if (!wdev
->netdev
) {
5803 if (!dev
->ops
->dump_survey
) {
5809 struct ieee80211_channel
*chan
;
5811 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5817 /* Survey without a channel doesn't make sense */
5818 if (!survey
.channel
) {
5823 chan
= ieee80211_get_channel(&dev
->wiphy
,
5824 survey
.channel
->center_freq
);
5825 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5830 if (nl80211_send_survey(skb
,
5831 NETLINK_CB(cb
->skb
).portid
,
5832 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5833 wdev
->netdev
, &survey
) < 0)
5839 cb
->args
[2] = survey_idx
;
5842 nl80211_finish_wdev_dump(dev
);
5846 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5848 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5849 NL80211_WPA_VERSION_2
));
5852 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5854 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5855 struct net_device
*dev
= info
->user_ptr
[1];
5856 struct ieee80211_channel
*chan
;
5857 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5858 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5859 enum nl80211_auth_type auth_type
;
5860 struct key_parse key
;
5861 bool local_state_change
;
5863 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5866 if (!info
->attrs
[NL80211_ATTR_MAC
])
5869 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5872 if (!info
->attrs
[NL80211_ATTR_SSID
])
5875 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5878 err
= nl80211_parse_key(info
, &key
);
5883 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5885 if (!key
.p
.key
|| !key
.p
.key_len
)
5887 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5888 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5889 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5890 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5902 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5903 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5912 if (!rdev
->ops
->auth
)
5915 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5916 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5919 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5920 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5921 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5922 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5925 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5926 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5928 if (info
->attrs
[NL80211_ATTR_IE
]) {
5929 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5930 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5933 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5934 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5937 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5938 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5941 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5942 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5944 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5945 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5946 /* need to include at least Auth Transaction and Status Code */
5947 if (sae_data_len
< 4)
5951 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5954 * Since we no longer track auth state, ignore
5955 * requests to only change local state.
5957 if (local_state_change
)
5960 wdev_lock(dev
->ieee80211_ptr
);
5961 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5962 ssid
, ssid_len
, ie
, ie_len
,
5963 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5964 sae_data
, sae_data_len
);
5965 wdev_unlock(dev
->ieee80211_ptr
);
5969 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5970 struct genl_info
*info
,
5971 struct cfg80211_crypto_settings
*settings
,
5974 memset(settings
, 0, sizeof(*settings
));
5976 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5978 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5980 proto
= nla_get_u16(
5981 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5982 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5983 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5986 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5987 settings
->control_port_no_encrypt
= true;
5989 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5991 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5995 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5996 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5997 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5999 if (len
% sizeof(u32
))
6002 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6005 memcpy(settings
->ciphers_pairwise
, data
, len
);
6007 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6008 if (!cfg80211_supported_cipher_suite(
6010 settings
->ciphers_pairwise
[i
]))
6014 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6015 settings
->cipher_group
=
6016 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6017 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6018 settings
->cipher_group
))
6022 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6023 settings
->wpa_versions
=
6024 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6025 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6029 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6033 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6034 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6035 settings
->n_akm_suites
= len
/ sizeof(u32
);
6037 if (len
% sizeof(u32
))
6040 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6043 memcpy(settings
->akm_suites
, data
, len
);
6049 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6051 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6052 struct net_device
*dev
= info
->user_ptr
[1];
6053 struct ieee80211_channel
*chan
;
6054 struct cfg80211_assoc_request req
= {};
6055 const u8
*bssid
, *ssid
;
6056 int err
, ssid_len
= 0;
6058 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6061 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6062 !info
->attrs
[NL80211_ATTR_SSID
] ||
6063 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6066 if (!rdev
->ops
->assoc
)
6069 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6070 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6073 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6075 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6076 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6077 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6080 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6081 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6083 if (info
->attrs
[NL80211_ATTR_IE
]) {
6084 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6085 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6088 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6089 enum nl80211_mfp mfp
=
6090 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6091 if (mfp
== NL80211_MFP_REQUIRED
)
6093 else if (mfp
!= NL80211_MFP_NO
)
6097 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6098 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6100 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6101 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6103 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6104 memcpy(&req
.ht_capa_mask
,
6105 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6106 sizeof(req
.ht_capa_mask
));
6108 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6109 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6111 memcpy(&req
.ht_capa
,
6112 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6113 sizeof(req
.ht_capa
));
6116 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6117 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6119 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6120 memcpy(&req
.vht_capa_mask
,
6121 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6122 sizeof(req
.vht_capa_mask
));
6124 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6125 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6127 memcpy(&req
.vht_capa
,
6128 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6129 sizeof(req
.vht_capa
));
6132 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6134 wdev_lock(dev
->ieee80211_ptr
);
6135 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6136 ssid
, ssid_len
, &req
);
6137 wdev_unlock(dev
->ieee80211_ptr
);
6143 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6145 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6146 struct net_device
*dev
= info
->user_ptr
[1];
6147 const u8
*ie
= NULL
, *bssid
;
6148 int ie_len
= 0, err
;
6150 bool local_state_change
;
6152 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6155 if (!info
->attrs
[NL80211_ATTR_MAC
])
6158 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6161 if (!rdev
->ops
->deauth
)
6164 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6165 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6168 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6170 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6171 if (reason_code
== 0) {
6172 /* Reason Code 0 is reserved */
6176 if (info
->attrs
[NL80211_ATTR_IE
]) {
6177 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6178 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6181 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6183 wdev_lock(dev
->ieee80211_ptr
);
6184 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6185 local_state_change
);
6186 wdev_unlock(dev
->ieee80211_ptr
);
6190 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6192 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6193 struct net_device
*dev
= info
->user_ptr
[1];
6194 const u8
*ie
= NULL
, *bssid
;
6195 int ie_len
= 0, err
;
6197 bool local_state_change
;
6199 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6202 if (!info
->attrs
[NL80211_ATTR_MAC
])
6205 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6208 if (!rdev
->ops
->disassoc
)
6211 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6212 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6215 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6217 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6218 if (reason_code
== 0) {
6219 /* Reason Code 0 is reserved */
6223 if (info
->attrs
[NL80211_ATTR_IE
]) {
6224 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6225 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6228 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6230 wdev_lock(dev
->ieee80211_ptr
);
6231 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6232 local_state_change
);
6233 wdev_unlock(dev
->ieee80211_ptr
);
6238 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6239 int mcast_rate
[IEEE80211_NUM_BANDS
],
6242 struct wiphy
*wiphy
= &rdev
->wiphy
;
6246 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6247 struct ieee80211_supported_band
*sband
;
6249 sband
= wiphy
->bands
[band
];
6253 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6254 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6255 mcast_rate
[band
] = i
+ 1;
6265 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6268 struct net_device
*dev
= info
->user_ptr
[1];
6269 struct cfg80211_ibss_params ibss
;
6270 struct wiphy
*wiphy
;
6271 struct cfg80211_cached_keys
*connkeys
= NULL
;
6274 memset(&ibss
, 0, sizeof(ibss
));
6276 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6279 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6280 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6283 ibss
.beacon_interval
= 100;
6285 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6286 ibss
.beacon_interval
=
6287 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6288 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6292 if (!rdev
->ops
->join_ibss
)
6295 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6298 wiphy
= &rdev
->wiphy
;
6300 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6301 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6303 if (!is_valid_ether_addr(ibss
.bssid
))
6306 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6307 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6309 if (info
->attrs
[NL80211_ATTR_IE
]) {
6310 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6311 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6314 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6318 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6321 switch (ibss
.chandef
.width
) {
6322 case NL80211_CHAN_WIDTH_20_NOHT
:
6324 case NL80211_CHAN_WIDTH_20
:
6325 case NL80211_CHAN_WIDTH_40
:
6326 if (rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
)
6332 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6333 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6335 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6337 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6339 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6340 struct ieee80211_supported_band
*sband
=
6341 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6343 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6349 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6350 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6351 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6354 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6357 connkeys
= nl80211_parse_connkeys(rdev
,
6358 info
->attrs
[NL80211_ATTR_KEYS
],
6360 if (IS_ERR(connkeys
))
6361 return PTR_ERR(connkeys
);
6363 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6371 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6373 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6379 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6381 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6382 struct net_device
*dev
= info
->user_ptr
[1];
6384 if (!rdev
->ops
->leave_ibss
)
6387 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6390 return cfg80211_leave_ibss(rdev
, dev
, false);
6393 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6395 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6396 struct net_device
*dev
= info
->user_ptr
[1];
6397 int mcast_rate
[IEEE80211_NUM_BANDS
];
6401 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6402 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6405 if (!rdev
->ops
->set_mcast_rate
)
6408 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6410 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6413 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6414 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6417 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6423 #ifdef CONFIG_NL80211_TESTMODE
6424 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6428 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6430 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6433 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6437 if (rdev
->ops
->testmode_cmd
) {
6438 rdev
->testmode_info
= info
;
6439 err
= rdev_testmode_cmd(rdev
,
6440 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6441 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6442 rdev
->testmode_info
= NULL
;
6448 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6449 struct netlink_callback
*cb
)
6451 struct cfg80211_registered_device
*rdev
;
6461 * 0 is a valid index, but not valid for args[0],
6462 * so we need to offset by 1.
6464 phy_idx
= cb
->args
[0] - 1;
6466 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6467 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6472 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6473 nl80211_fam
.attrbuf
);
6475 err
= PTR_ERR(rdev
);
6478 phy_idx
= rdev
->wiphy_idx
;
6481 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6483 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6487 data
= nla_data((void *)cb
->args
[1]);
6488 data_len
= nla_len((void *)cb
->args
[1]);
6491 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6497 if (!rdev
->ops
->testmode_dump
) {
6503 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6504 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6505 NL80211_CMD_TESTMODE
);
6506 struct nlattr
*tmdata
;
6508 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6509 genlmsg_cancel(skb
, hdr
);
6513 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6515 genlmsg_cancel(skb
, hdr
);
6518 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6519 nla_nest_end(skb
, tmdata
);
6521 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6522 genlmsg_cancel(skb
, hdr
);
6525 genlmsg_cancel(skb
, hdr
);
6529 genlmsg_end(skb
, hdr
);
6534 cb
->args
[0] = phy_idx
+ 1;
6540 static struct sk_buff
*
6541 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
6542 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
6544 struct sk_buff
*skb
;
6546 struct nlattr
*data
;
6548 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6552 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
6558 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6559 goto nla_put_failure
;
6560 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6562 ((void **)skb
->cb
)[0] = rdev
;
6563 ((void **)skb
->cb
)[1] = hdr
;
6564 ((void **)skb
->cb
)[2] = data
;
6573 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
6576 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6578 if (WARN_ON(!rdev
->testmode_info
))
6581 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
6582 rdev
->testmode_info
->snd_portid
,
6583 rdev
->testmode_info
->snd_seq
,
6586 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
6588 int cfg80211_testmode_reply(struct sk_buff
*skb
)
6590 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6591 void *hdr
= ((void **)skb
->cb
)[1];
6592 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6594 if (WARN_ON(!rdev
->testmode_info
)) {
6599 nla_nest_end(skb
, data
);
6600 genlmsg_end(skb
, hdr
);
6601 return genlmsg_reply(skb
, rdev
->testmode_info
);
6603 EXPORT_SYMBOL(cfg80211_testmode_reply
);
6605 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
6606 int approxlen
, gfp_t gfp
)
6608 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6610 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
6612 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
6614 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
6616 void *hdr
= ((void **)skb
->cb
)[1];
6617 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6619 nla_nest_end(skb
, data
);
6620 genlmsg_end(skb
, hdr
);
6621 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
6623 EXPORT_SYMBOL(cfg80211_testmode_event
);
6626 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6628 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6629 struct net_device
*dev
= info
->user_ptr
[1];
6630 struct cfg80211_connect_params connect
;
6631 struct wiphy
*wiphy
;
6632 struct cfg80211_cached_keys
*connkeys
= NULL
;
6635 memset(&connect
, 0, sizeof(connect
));
6637 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6640 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6641 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6644 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6646 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6647 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6648 NL80211_CMD_CONNECT
))
6651 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6653 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6655 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6656 NL80211_MAX_NR_CIPHER_SUITES
);
6660 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6661 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6664 wiphy
= &rdev
->wiphy
;
6666 connect
.bg_scan_period
= -1;
6667 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6668 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6669 connect
.bg_scan_period
=
6670 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6673 if (info
->attrs
[NL80211_ATTR_MAC
])
6674 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6675 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6676 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6678 if (info
->attrs
[NL80211_ATTR_IE
]) {
6679 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6680 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6683 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6684 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6685 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6686 connect
.mfp
!= NL80211_MFP_NO
)
6689 connect
.mfp
= NL80211_MFP_NO
;
6692 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6694 ieee80211_get_channel(wiphy
,
6695 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6696 if (!connect
.channel
||
6697 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6701 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6702 connkeys
= nl80211_parse_connkeys(rdev
,
6703 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6704 if (IS_ERR(connkeys
))
6705 return PTR_ERR(connkeys
);
6708 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6709 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6711 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6712 memcpy(&connect
.ht_capa_mask
,
6713 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6714 sizeof(connect
.ht_capa_mask
));
6716 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6717 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6721 memcpy(&connect
.ht_capa
,
6722 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6723 sizeof(connect
.ht_capa
));
6726 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6727 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6729 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6730 memcpy(&connect
.vht_capa_mask
,
6731 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6732 sizeof(connect
.vht_capa_mask
));
6734 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6735 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6739 memcpy(&connect
.vht_capa
,
6740 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6741 sizeof(connect
.vht_capa
));
6744 wdev_lock(dev
->ieee80211_ptr
);
6745 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
6746 wdev_unlock(dev
->ieee80211_ptr
);
6752 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6754 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6755 struct net_device
*dev
= info
->user_ptr
[1];
6759 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6760 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6762 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6767 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6768 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6771 wdev_lock(dev
->ieee80211_ptr
);
6772 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
6773 wdev_unlock(dev
->ieee80211_ptr
);
6777 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6779 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6784 if (!info
->attrs
[NL80211_ATTR_PID
])
6787 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6789 net
= get_net_ns_by_pid(pid
);
6791 return PTR_ERR(net
);
6795 /* check if anything to do */
6796 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6797 err
= cfg80211_switch_netns(rdev
, net
);
6803 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6805 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6806 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6807 struct cfg80211_pmksa
*pmksa
) = NULL
;
6808 struct net_device
*dev
= info
->user_ptr
[1];
6809 struct cfg80211_pmksa pmksa
;
6811 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6813 if (!info
->attrs
[NL80211_ATTR_MAC
])
6816 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6819 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6820 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6822 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6823 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6826 switch (info
->genlhdr
->cmd
) {
6827 case NL80211_CMD_SET_PMKSA
:
6828 rdev_ops
= rdev
->ops
->set_pmksa
;
6830 case NL80211_CMD_DEL_PMKSA
:
6831 rdev_ops
= rdev
->ops
->del_pmksa
;
6841 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6844 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6846 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6847 struct net_device
*dev
= info
->user_ptr
[1];
6849 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6850 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6853 if (!rdev
->ops
->flush_pmksa
)
6856 return rdev_flush_pmksa(rdev
, dev
);
6859 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6862 struct net_device
*dev
= info
->user_ptr
[1];
6863 u8 action_code
, dialog_token
;
6867 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6868 !rdev
->ops
->tdls_mgmt
)
6871 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6872 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6873 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6874 !info
->attrs
[NL80211_ATTR_IE
] ||
6875 !info
->attrs
[NL80211_ATTR_MAC
])
6878 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6879 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6880 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6881 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6883 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6884 dialog_token
, status_code
,
6885 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6886 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6889 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6891 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6892 struct net_device
*dev
= info
->user_ptr
[1];
6893 enum nl80211_tdls_operation operation
;
6896 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6897 !rdev
->ops
->tdls_oper
)
6900 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6901 !info
->attrs
[NL80211_ATTR_MAC
])
6904 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6905 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6907 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6910 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6911 struct genl_info
*info
)
6913 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6914 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6915 struct cfg80211_chan_def chandef
;
6916 struct sk_buff
*msg
;
6922 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6923 !info
->attrs
[NL80211_ATTR_DURATION
])
6926 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6928 if (!rdev
->ops
->remain_on_channel
||
6929 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6933 * We should be on that channel for at least a minimum amount of
6934 * time (10ms) but no longer than the driver supports.
6936 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6937 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6940 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6944 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6948 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6949 NL80211_CMD_REMAIN_ON_CHANNEL
);
6956 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6962 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6963 goto nla_put_failure
;
6965 genlmsg_end(msg
, hdr
);
6967 return genlmsg_reply(msg
, info
);
6976 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
6977 struct genl_info
*info
)
6979 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6980 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6983 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6986 if (!rdev
->ops
->cancel_remain_on_channel
)
6989 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6991 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
6994 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
6995 u8
*rates
, u8 rates_len
)
7000 for (i
= 0; i
< rates_len
; i
++) {
7001 int rate
= (rates
[i
] & 0x7f) * 5;
7003 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7004 struct ieee80211_rate
*srate
=
7005 &sband
->bitrates
[ridx
];
7006 if (rate
== srate
->bitrate
) {
7011 if (ridx
== sband
->n_bitrates
)
7012 return 0; /* rate not found */
7018 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7019 u8
*rates
, u8 rates_len
,
7020 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7024 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7026 for (i
= 0; i
< rates_len
; i
++) {
7029 ridx
= rates
[i
] / 8;
7030 rbit
= BIT(rates
[i
] % 8);
7032 /* check validity */
7033 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7036 /* check availability */
7037 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7046 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7047 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7048 .len
= NL80211_MAX_SUPP_RATES
},
7049 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7050 .len
= NL80211_MAX_SUPP_HT_RATES
},
7053 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7054 struct genl_info
*info
)
7056 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7057 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7058 struct cfg80211_bitrate_mask mask
;
7060 struct net_device
*dev
= info
->user_ptr
[1];
7061 struct nlattr
*tx_rates
;
7062 struct ieee80211_supported_band
*sband
;
7064 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7067 if (!rdev
->ops
->set_bitrate_mask
)
7070 memset(&mask
, 0, sizeof(mask
));
7071 /* Default to all rates enabled */
7072 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7073 sband
= rdev
->wiphy
.bands
[i
];
7074 mask
.control
[i
].legacy
=
7075 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7077 memcpy(mask
.control
[i
].mcs
,
7078 sband
->ht_cap
.mcs
.rx_mask
,
7079 sizeof(mask
.control
[i
].mcs
));
7081 memset(mask
.control
[i
].mcs
, 0,
7082 sizeof(mask
.control
[i
].mcs
));
7086 * The nested attribute uses enum nl80211_band as the index. This maps
7087 * directly to the enum ieee80211_band values used in cfg80211.
7089 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7090 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7092 enum ieee80211_band band
= nla_type(tx_rates
);
7093 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7095 sband
= rdev
->wiphy
.bands
[band
];
7098 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7099 nla_len(tx_rates
), nl80211_txattr_policy
);
7100 if (tb
[NL80211_TXRATE_LEGACY
]) {
7101 mask
.control
[band
].legacy
= rateset_to_mask(
7103 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7104 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7105 if ((mask
.control
[band
].legacy
== 0) &&
7106 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7109 if (tb
[NL80211_TXRATE_MCS
]) {
7110 if (!ht_rateset_to_mask(
7112 nla_data(tb
[NL80211_TXRATE_MCS
]),
7113 nla_len(tb
[NL80211_TXRATE_MCS
]),
7114 mask
.control
[band
].mcs
))
7118 if (mask
.control
[band
].legacy
== 0) {
7119 /* don't allow empty legacy rates if HT
7120 * is not even supported. */
7121 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7124 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7125 if (mask
.control
[band
].mcs
[i
])
7128 /* legacy and mcs rates may not be both empty */
7129 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7134 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7137 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7140 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7141 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7143 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7146 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7147 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7149 switch (wdev
->iftype
) {
7150 case NL80211_IFTYPE_STATION
:
7151 case NL80211_IFTYPE_ADHOC
:
7152 case NL80211_IFTYPE_P2P_CLIENT
:
7153 case NL80211_IFTYPE_AP
:
7154 case NL80211_IFTYPE_AP_VLAN
:
7155 case NL80211_IFTYPE_MESH_POINT
:
7156 case NL80211_IFTYPE_P2P_GO
:
7157 case NL80211_IFTYPE_P2P_DEVICE
:
7163 /* not much point in registering if we can't reply */
7164 if (!rdev
->ops
->mgmt_tx
)
7167 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7168 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7169 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7172 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7174 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7175 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7176 struct cfg80211_chan_def chandef
;
7180 struct sk_buff
*msg
= NULL
;
7181 unsigned int wait
= 0;
7182 bool offchan
, no_cck
, dont_wait_for_ack
;
7184 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7186 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7189 if (!rdev
->ops
->mgmt_tx
)
7192 switch (wdev
->iftype
) {
7193 case NL80211_IFTYPE_P2P_DEVICE
:
7194 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7196 case NL80211_IFTYPE_STATION
:
7197 case NL80211_IFTYPE_ADHOC
:
7198 case NL80211_IFTYPE_P2P_CLIENT
:
7199 case NL80211_IFTYPE_AP
:
7200 case NL80211_IFTYPE_AP_VLAN
:
7201 case NL80211_IFTYPE_MESH_POINT
:
7202 case NL80211_IFTYPE_P2P_GO
:
7208 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7209 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7211 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7214 * We should wait on the channel for at least a minimum amount
7215 * of time (10ms) but no longer than the driver supports.
7217 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7218 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7223 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7225 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7228 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7230 /* get the channel if any has been specified, otherwise pass NULL to
7231 * the driver. The latter will use the current one
7233 chandef
.chan
= NULL
;
7234 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7235 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7240 if (!chandef
.chan
&& offchan
)
7243 if (!dont_wait_for_ack
) {
7244 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7248 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7257 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7258 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7259 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7260 no_cck
, dont_wait_for_ack
, &cookie
);
7265 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7266 goto nla_put_failure
;
7268 genlmsg_end(msg
, hdr
);
7269 return genlmsg_reply(msg
, info
);
7281 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7283 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7284 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7287 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7290 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7293 switch (wdev
->iftype
) {
7294 case NL80211_IFTYPE_STATION
:
7295 case NL80211_IFTYPE_ADHOC
:
7296 case NL80211_IFTYPE_P2P_CLIENT
:
7297 case NL80211_IFTYPE_AP
:
7298 case NL80211_IFTYPE_AP_VLAN
:
7299 case NL80211_IFTYPE_P2P_GO
:
7300 case NL80211_IFTYPE_P2P_DEVICE
:
7306 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7308 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7311 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7313 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7314 struct wireless_dev
*wdev
;
7315 struct net_device
*dev
= info
->user_ptr
[1];
7320 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7323 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7325 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7328 wdev
= dev
->ieee80211_ptr
;
7330 if (!rdev
->ops
->set_power_mgmt
)
7333 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7335 if (state
== wdev
->ps
)
7338 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7344 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7346 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7347 enum nl80211_ps_state ps_state
;
7348 struct wireless_dev
*wdev
;
7349 struct net_device
*dev
= info
->user_ptr
[1];
7350 struct sk_buff
*msg
;
7354 wdev
= dev
->ieee80211_ptr
;
7356 if (!rdev
->ops
->set_power_mgmt
)
7359 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7363 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7364 NL80211_CMD_GET_POWER_SAVE
);
7371 ps_state
= NL80211_PS_ENABLED
;
7373 ps_state
= NL80211_PS_DISABLED
;
7375 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7376 goto nla_put_failure
;
7378 genlmsg_end(msg
, hdr
);
7379 return genlmsg_reply(msg
, info
);
7388 static struct nla_policy
7389 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7390 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7391 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7392 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7393 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7394 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7395 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7398 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7399 u32 rate
, u32 pkts
, u32 intvl
)
7401 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7402 struct wireless_dev
*wdev
;
7403 struct net_device
*dev
= info
->user_ptr
[1];
7405 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7408 wdev
= dev
->ieee80211_ptr
;
7410 if (!rdev
->ops
->set_cqm_txe_config
)
7413 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7414 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7417 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7420 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7421 s32 threshold
, u32 hysteresis
)
7423 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7424 struct wireless_dev
*wdev
;
7425 struct net_device
*dev
= info
->user_ptr
[1];
7430 wdev
= dev
->ieee80211_ptr
;
7432 if (!rdev
->ops
->set_cqm_rssi_config
)
7435 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7436 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7439 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7442 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7444 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7448 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7454 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7455 nl80211_attr_cqm_policy
);
7459 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7460 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7463 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7464 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7465 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7466 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7467 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7468 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7469 u32 rate
, pkts
, intvl
;
7470 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7471 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7472 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7473 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7481 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7483 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7484 struct net_device
*dev
= info
->user_ptr
[1];
7485 struct mesh_config cfg
;
7486 struct mesh_setup setup
;
7489 /* start with default */
7490 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7491 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7493 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7494 /* and parse parameters if given */
7495 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7500 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7501 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7504 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7505 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7507 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7508 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7509 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7512 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7513 setup
.beacon_interval
=
7514 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7515 if (setup
.beacon_interval
< 10 ||
7516 setup
.beacon_interval
> 10000)
7520 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7522 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7523 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7527 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7528 /* parse additional setup parameters if given */
7529 err
= nl80211_parse_mesh_setup(info
, &setup
);
7535 cfg
.auto_open_plinks
= false;
7537 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7538 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7542 /* cfg80211_join_mesh() will sort it out */
7543 setup
.chandef
.chan
= NULL
;
7546 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7547 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7549 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7550 struct ieee80211_supported_band
*sband
;
7552 if (!setup
.chandef
.chan
)
7555 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
7557 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7558 &setup
.basic_rates
);
7563 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7566 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7568 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7569 struct net_device
*dev
= info
->user_ptr
[1];
7571 return cfg80211_leave_mesh(rdev
, dev
);
7575 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7576 struct cfg80211_registered_device
*rdev
)
7578 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
7579 struct nlattr
*nl_pats
, *nl_pat
;
7582 if (!wowlan
->n_patterns
)
7585 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7589 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
7590 nl_pat
= nla_nest_start(msg
, i
+ 1);
7593 pat_len
= wowlan
->patterns
[i
].pattern_len
;
7594 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7595 DIV_ROUND_UP(pat_len
, 8),
7596 wowlan
->patterns
[i
].mask
) ||
7597 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7598 pat_len
, wowlan
->patterns
[i
].pattern
) ||
7599 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7600 wowlan
->patterns
[i
].pkt_offset
))
7602 nla_nest_end(msg
, nl_pat
);
7604 nla_nest_end(msg
, nl_pats
);
7609 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7610 struct cfg80211_wowlan_tcp
*tcp
)
7612 struct nlattr
*nl_tcp
;
7617 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7621 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7622 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7623 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7624 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7625 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7626 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7627 tcp
->payload_len
, tcp
->payload
) ||
7628 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7629 tcp
->data_interval
) ||
7630 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7631 tcp
->wake_len
, tcp
->wake_data
) ||
7632 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7633 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7636 if (tcp
->payload_seq
.len
&&
7637 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7638 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7641 if (tcp
->payload_tok
.len
&&
7642 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7643 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7647 nla_nest_end(msg
, nl_tcp
);
7652 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7654 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7655 struct sk_buff
*msg
;
7657 u32 size
= NLMSG_DEFAULT_SIZE
;
7659 if (!rdev
->wiphy
.wowlan
)
7662 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
7663 /* adjust size to have room for all the data */
7664 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
7665 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
7666 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
7667 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
7670 msg
= nlmsg_new(size
, GFP_KERNEL
);
7674 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7675 NL80211_CMD_GET_WOWLAN
);
7677 goto nla_put_failure
;
7679 if (rdev
->wiphy
.wowlan_config
) {
7680 struct nlattr
*nl_wowlan
;
7682 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7684 goto nla_put_failure
;
7686 if ((rdev
->wiphy
.wowlan_config
->any
&&
7687 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7688 (rdev
->wiphy
.wowlan_config
->disconnect
&&
7689 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7690 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
7691 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7692 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
7693 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7694 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
7695 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7696 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
7697 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7698 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
7699 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7700 goto nla_put_failure
;
7702 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7703 goto nla_put_failure
;
7705 if (nl80211_send_wowlan_tcp(msg
,
7706 rdev
->wiphy
.wowlan_config
->tcp
))
7707 goto nla_put_failure
;
7709 nla_nest_end(msg
, nl_wowlan
);
7712 genlmsg_end(msg
, hdr
);
7713 return genlmsg_reply(msg
, info
);
7720 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7721 struct nlattr
*attr
,
7722 struct cfg80211_wowlan
*trig
)
7724 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7725 struct cfg80211_wowlan_tcp
*cfg
;
7726 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7727 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7729 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7732 if (!rdev
->wiphy
.wowlan
->tcp
)
7735 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7736 nla_data(attr
), nla_len(attr
),
7737 nl80211_wowlan_tcp_policy
);
7741 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7742 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7743 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7744 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7745 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7746 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7747 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7748 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7751 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7752 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
7755 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7756 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
7757 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7760 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7761 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
7764 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7765 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7768 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7769 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7771 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7772 tokens_size
= tokln
- sizeof(*tok
);
7774 if (!tok
->len
|| tokens_size
% tok
->len
)
7776 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
7778 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
7780 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
7782 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
7784 if (tok
->offset
+ tok
->len
> data_size
)
7788 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7789 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7790 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
7792 if (seq
->len
== 0 || seq
->len
> 4)
7794 if (seq
->len
+ seq
->offset
> data_size
)
7798 size
= sizeof(*cfg
);
7800 size
+= wake_size
+ wake_mask_size
;
7801 size
+= tokens_size
;
7803 cfg
= kzalloc(size
, GFP_KERNEL
);
7806 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7807 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7808 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7810 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7811 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7815 /* allocate a socket and port for it and use it */
7816 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7817 IPPROTO_TCP
, &cfg
->sock
, 1);
7822 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7823 sock_release(cfg
->sock
);
7827 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7833 cfg
->src_port
= port
;
7836 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7837 cfg
->payload_len
= data_size
;
7838 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7839 memcpy((void *)cfg
->payload
,
7840 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7843 cfg
->payload_seq
= *seq
;
7844 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7845 cfg
->wake_len
= wake_size
;
7846 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7847 memcpy((void *)cfg
->wake_data
,
7848 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7850 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7851 data_size
+ wake_size
;
7852 memcpy((void *)cfg
->wake_mask
,
7853 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7856 cfg
->tokens_size
= tokens_size
;
7857 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7865 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7867 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7868 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7869 struct cfg80211_wowlan new_triggers
= {};
7870 struct cfg80211_wowlan
*ntrig
;
7871 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
7873 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
7878 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7879 cfg80211_rdev_free_wowlan(rdev
);
7880 rdev
->wiphy
.wowlan_config
= NULL
;
7884 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7885 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7886 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7887 nl80211_wowlan_policy
);
7891 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7892 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7894 new_triggers
.any
= true;
7897 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7898 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7900 new_triggers
.disconnect
= true;
7903 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7904 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7906 new_triggers
.magic_pkt
= true;
7909 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7912 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7913 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7915 new_triggers
.gtk_rekey_failure
= true;
7918 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7919 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7921 new_triggers
.eap_identity_req
= true;
7924 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7925 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7927 new_triggers
.four_way_handshake
= true;
7930 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7931 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7933 new_triggers
.rfkill_release
= true;
7936 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7939 int rem
, pat_len
, mask_len
, pkt_offset
;
7940 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7942 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7945 if (n_patterns
> wowlan
->n_patterns
)
7948 new_triggers
.patterns
= kcalloc(n_patterns
,
7949 sizeof(new_triggers
.patterns
[0]),
7951 if (!new_triggers
.patterns
)
7954 new_triggers
.n_patterns
= n_patterns
;
7957 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7959 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7960 nla_data(pat
), nla_len(pat
), NULL
);
7962 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7963 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7965 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7966 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7967 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7970 if (pat_len
> wowlan
->pattern_max_len
||
7971 pat_len
< wowlan
->pattern_min_len
)
7974 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7977 pkt_offset
= nla_get_u32(
7978 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7979 if (pkt_offset
> wowlan
->max_pkt_offset
)
7981 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7983 new_triggers
.patterns
[i
].mask
=
7984 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7985 if (!new_triggers
.patterns
[i
].mask
) {
7989 new_triggers
.patterns
[i
].pattern
=
7990 new_triggers
.patterns
[i
].mask
+ mask_len
;
7991 memcpy(new_triggers
.patterns
[i
].mask
,
7992 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7994 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7995 memcpy(new_triggers
.patterns
[i
].pattern
,
7996 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
8002 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8003 err
= nl80211_parse_wowlan_tcp(
8004 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8010 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8015 cfg80211_rdev_free_wowlan(rdev
);
8016 rdev
->wiphy
.wowlan_config
= ntrig
;
8019 if (rdev
->ops
->set_wakeup
&&
8020 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
8021 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
8025 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8026 kfree(new_triggers
.patterns
[i
].mask
);
8027 kfree(new_triggers
.patterns
);
8028 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8029 sock_release(new_triggers
.tcp
->sock
);
8030 kfree(new_triggers
.tcp
);
8035 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8037 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8038 struct net_device
*dev
= info
->user_ptr
[1];
8039 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8040 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8041 struct cfg80211_gtk_rekey_data rekey_data
;
8044 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8047 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8048 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8049 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8050 nl80211_rekey_policy
);
8054 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8056 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8058 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8061 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8063 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8065 memcpy(rekey_data
.replay_ctr
,
8066 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8067 NL80211_REPLAY_CTR_LEN
);
8070 if (!wdev
->current_bss
) {
8075 if (!rdev
->ops
->set_rekey_data
) {
8080 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8086 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8087 struct genl_info
*info
)
8089 struct net_device
*dev
= info
->user_ptr
[1];
8090 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8092 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8093 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8096 if (wdev
->ap_unexpected_nlportid
)
8099 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8103 static int nl80211_probe_client(struct sk_buff
*skb
,
8104 struct genl_info
*info
)
8106 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8107 struct net_device
*dev
= info
->user_ptr
[1];
8108 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8109 struct sk_buff
*msg
;
8115 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8116 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8119 if (!info
->attrs
[NL80211_ATTR_MAC
])
8122 if (!rdev
->ops
->probe_client
)
8125 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8129 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8130 NL80211_CMD_PROBE_CLIENT
);
8137 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8139 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8143 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8144 goto nla_put_failure
;
8146 genlmsg_end(msg
, hdr
);
8148 return genlmsg_reply(msg
, info
);
8157 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8159 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8160 struct cfg80211_beacon_registration
*reg
, *nreg
;
8163 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8166 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8170 /* First, check if already registered. */
8171 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8172 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8173 if (reg
->nlportid
== info
->snd_portid
) {
8178 /* Add it to the list */
8179 nreg
->nlportid
= info
->snd_portid
;
8180 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8182 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8186 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8191 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8193 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8194 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8197 if (!rdev
->ops
->start_p2p_device
)
8200 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8203 if (wdev
->p2p_started
)
8206 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8210 err
= rdev_start_p2p_device(rdev
, wdev
);
8214 wdev
->p2p_started
= true;
8220 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8222 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8223 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8225 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8228 if (!rdev
->ops
->stop_p2p_device
)
8231 cfg80211_stop_p2p_device(rdev
, wdev
);
8236 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8237 struct genl_info
*info
)
8240 struct sk_buff
*msg
;
8242 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8246 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8247 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8249 goto nla_put_failure
;
8251 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8252 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8253 goto nla_put_failure
;
8255 genlmsg_end(msg
, hdr
);
8256 return genlmsg_reply(msg
, info
);
8263 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8265 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8266 struct cfg80211_update_ft_ies_params ft_params
;
8267 struct net_device
*dev
= info
->user_ptr
[1];
8269 if (!rdev
->ops
->update_ft_ies
)
8272 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8273 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8276 memset(&ft_params
, 0, sizeof(ft_params
));
8277 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8278 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8279 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8281 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8284 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8285 struct genl_info
*info
)
8287 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8288 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8289 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8293 if (!rdev
->ops
->crit_proto_start
)
8296 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8299 if (rdev
->crit_proto_nlportid
)
8302 /* determine protocol if provided */
8303 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8304 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8306 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8309 /* timeout must be provided */
8310 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8314 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8316 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8319 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8321 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8326 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8327 struct genl_info
*info
)
8329 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8330 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8332 if (!rdev
->ops
->crit_proto_stop
)
8335 if (rdev
->crit_proto_nlportid
) {
8336 rdev
->crit_proto_nlportid
= 0;
8337 rdev_crit_proto_stop(rdev
, wdev
);
8342 #define NL80211_FLAG_NEED_WIPHY 0x01
8343 #define NL80211_FLAG_NEED_NETDEV 0x02
8344 #define NL80211_FLAG_NEED_RTNL 0x04
8345 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8346 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8347 NL80211_FLAG_CHECK_NETDEV_UP)
8348 #define NL80211_FLAG_NEED_WDEV 0x10
8349 /* If a netdev is associated, it must be UP, P2P must be started */
8350 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8351 NL80211_FLAG_CHECK_NETDEV_UP)
8353 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8354 struct genl_info
*info
)
8356 struct cfg80211_registered_device
*rdev
;
8357 struct wireless_dev
*wdev
;
8358 struct net_device
*dev
;
8359 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8364 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8365 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8369 return PTR_ERR(rdev
);
8371 info
->user_ptr
[0] = rdev
;
8372 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8373 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8376 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8381 return PTR_ERR(wdev
);
8385 rdev
= wiphy_to_dev(wdev
->wiphy
);
8387 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8394 info
->user_ptr
[1] = dev
;
8396 info
->user_ptr
[1] = wdev
;
8400 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8401 !netif_running(dev
)) {
8408 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8409 if (!wdev
->p2p_started
) {
8416 info
->user_ptr
[0] = rdev
;
8422 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8423 struct genl_info
*info
)
8425 if (info
->user_ptr
[1]) {
8426 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8427 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8430 dev_put(wdev
->netdev
);
8432 dev_put(info
->user_ptr
[1]);
8435 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8439 static struct genl_ops nl80211_ops
[] = {
8441 .cmd
= NL80211_CMD_GET_WIPHY
,
8442 .doit
= nl80211_get_wiphy
,
8443 .dumpit
= nl80211_dump_wiphy
,
8444 .done
= nl80211_dump_wiphy_done
,
8445 .policy
= nl80211_policy
,
8446 /* can be retrieved by unprivileged users */
8447 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8448 NL80211_FLAG_NEED_RTNL
,
8451 .cmd
= NL80211_CMD_SET_WIPHY
,
8452 .doit
= nl80211_set_wiphy
,
8453 .policy
= nl80211_policy
,
8454 .flags
= GENL_ADMIN_PERM
,
8455 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8458 .cmd
= NL80211_CMD_GET_INTERFACE
,
8459 .doit
= nl80211_get_interface
,
8460 .dumpit
= nl80211_dump_interface
,
8461 .policy
= nl80211_policy
,
8462 /* can be retrieved by unprivileged users */
8463 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8464 NL80211_FLAG_NEED_RTNL
,
8467 .cmd
= NL80211_CMD_SET_INTERFACE
,
8468 .doit
= nl80211_set_interface
,
8469 .policy
= nl80211_policy
,
8470 .flags
= GENL_ADMIN_PERM
,
8471 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8472 NL80211_FLAG_NEED_RTNL
,
8475 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8476 .doit
= nl80211_new_interface
,
8477 .policy
= nl80211_policy
,
8478 .flags
= GENL_ADMIN_PERM
,
8479 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8480 NL80211_FLAG_NEED_RTNL
,
8483 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8484 .doit
= nl80211_del_interface
,
8485 .policy
= nl80211_policy
,
8486 .flags
= GENL_ADMIN_PERM
,
8487 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8488 NL80211_FLAG_NEED_RTNL
,
8491 .cmd
= NL80211_CMD_GET_KEY
,
8492 .doit
= nl80211_get_key
,
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_SET_KEY
,
8500 .doit
= nl80211_set_key
,
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_NEW_KEY
,
8508 .doit
= nl80211_new_key
,
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_DEL_KEY
,
8516 .doit
= nl80211_del_key
,
8517 .policy
= nl80211_policy
,
8518 .flags
= GENL_ADMIN_PERM
,
8519 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8520 NL80211_FLAG_NEED_RTNL
,
8523 .cmd
= NL80211_CMD_SET_BEACON
,
8524 .policy
= nl80211_policy
,
8525 .flags
= GENL_ADMIN_PERM
,
8526 .doit
= nl80211_set_beacon
,
8527 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8528 NL80211_FLAG_NEED_RTNL
,
8531 .cmd
= NL80211_CMD_START_AP
,
8532 .policy
= nl80211_policy
,
8533 .flags
= GENL_ADMIN_PERM
,
8534 .doit
= nl80211_start_ap
,
8535 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8536 NL80211_FLAG_NEED_RTNL
,
8539 .cmd
= NL80211_CMD_STOP_AP
,
8540 .policy
= nl80211_policy
,
8541 .flags
= GENL_ADMIN_PERM
,
8542 .doit
= nl80211_stop_ap
,
8543 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8544 NL80211_FLAG_NEED_RTNL
,
8547 .cmd
= NL80211_CMD_GET_STATION
,
8548 .doit
= nl80211_get_station
,
8549 .dumpit
= nl80211_dump_station
,
8550 .policy
= nl80211_policy
,
8551 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8552 NL80211_FLAG_NEED_RTNL
,
8555 .cmd
= NL80211_CMD_SET_STATION
,
8556 .doit
= nl80211_set_station
,
8557 .policy
= nl80211_policy
,
8558 .flags
= GENL_ADMIN_PERM
,
8559 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8560 NL80211_FLAG_NEED_RTNL
,
8563 .cmd
= NL80211_CMD_NEW_STATION
,
8564 .doit
= nl80211_new_station
,
8565 .policy
= nl80211_policy
,
8566 .flags
= GENL_ADMIN_PERM
,
8567 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8568 NL80211_FLAG_NEED_RTNL
,
8571 .cmd
= NL80211_CMD_DEL_STATION
,
8572 .doit
= nl80211_del_station
,
8573 .policy
= nl80211_policy
,
8574 .flags
= GENL_ADMIN_PERM
,
8575 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8576 NL80211_FLAG_NEED_RTNL
,
8579 .cmd
= NL80211_CMD_GET_MPATH
,
8580 .doit
= nl80211_get_mpath
,
8581 .dumpit
= nl80211_dump_mpath
,
8582 .policy
= nl80211_policy
,
8583 .flags
= GENL_ADMIN_PERM
,
8584 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8585 NL80211_FLAG_NEED_RTNL
,
8588 .cmd
= NL80211_CMD_SET_MPATH
,
8589 .doit
= nl80211_set_mpath
,
8590 .policy
= nl80211_policy
,
8591 .flags
= GENL_ADMIN_PERM
,
8592 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8593 NL80211_FLAG_NEED_RTNL
,
8596 .cmd
= NL80211_CMD_NEW_MPATH
,
8597 .doit
= nl80211_new_mpath
,
8598 .policy
= nl80211_policy
,
8599 .flags
= GENL_ADMIN_PERM
,
8600 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8601 NL80211_FLAG_NEED_RTNL
,
8604 .cmd
= NL80211_CMD_DEL_MPATH
,
8605 .doit
= nl80211_del_mpath
,
8606 .policy
= nl80211_policy
,
8607 .flags
= GENL_ADMIN_PERM
,
8608 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8609 NL80211_FLAG_NEED_RTNL
,
8612 .cmd
= NL80211_CMD_SET_BSS
,
8613 .doit
= nl80211_set_bss
,
8614 .policy
= nl80211_policy
,
8615 .flags
= GENL_ADMIN_PERM
,
8616 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8617 NL80211_FLAG_NEED_RTNL
,
8620 .cmd
= NL80211_CMD_GET_REG
,
8621 .doit
= nl80211_get_reg
,
8622 .policy
= nl80211_policy
,
8623 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8624 /* can be retrieved by unprivileged users */
8627 .cmd
= NL80211_CMD_SET_REG
,
8628 .doit
= nl80211_set_reg
,
8629 .policy
= nl80211_policy
,
8630 .flags
= GENL_ADMIN_PERM
,
8631 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8634 .cmd
= NL80211_CMD_REQ_SET_REG
,
8635 .doit
= nl80211_req_set_reg
,
8636 .policy
= nl80211_policy
,
8637 .flags
= GENL_ADMIN_PERM
,
8640 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8641 .doit
= nl80211_get_mesh_config
,
8642 .policy
= nl80211_policy
,
8643 /* can be retrieved by unprivileged users */
8644 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8645 NL80211_FLAG_NEED_RTNL
,
8648 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8649 .doit
= nl80211_update_mesh_config
,
8650 .policy
= nl80211_policy
,
8651 .flags
= GENL_ADMIN_PERM
,
8652 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8653 NL80211_FLAG_NEED_RTNL
,
8656 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8657 .doit
= nl80211_trigger_scan
,
8658 .policy
= nl80211_policy
,
8659 .flags
= GENL_ADMIN_PERM
,
8660 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8661 NL80211_FLAG_NEED_RTNL
,
8664 .cmd
= NL80211_CMD_GET_SCAN
,
8665 .policy
= nl80211_policy
,
8666 .dumpit
= nl80211_dump_scan
,
8669 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8670 .doit
= nl80211_start_sched_scan
,
8671 .policy
= nl80211_policy
,
8672 .flags
= GENL_ADMIN_PERM
,
8673 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8674 NL80211_FLAG_NEED_RTNL
,
8677 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8678 .doit
= nl80211_stop_sched_scan
,
8679 .policy
= nl80211_policy
,
8680 .flags
= GENL_ADMIN_PERM
,
8681 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8682 NL80211_FLAG_NEED_RTNL
,
8685 .cmd
= NL80211_CMD_AUTHENTICATE
,
8686 .doit
= nl80211_authenticate
,
8687 .policy
= nl80211_policy
,
8688 .flags
= GENL_ADMIN_PERM
,
8689 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8690 NL80211_FLAG_NEED_RTNL
,
8693 .cmd
= NL80211_CMD_ASSOCIATE
,
8694 .doit
= nl80211_associate
,
8695 .policy
= nl80211_policy
,
8696 .flags
= GENL_ADMIN_PERM
,
8697 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8698 NL80211_FLAG_NEED_RTNL
,
8701 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8702 .doit
= nl80211_deauthenticate
,
8703 .policy
= nl80211_policy
,
8704 .flags
= GENL_ADMIN_PERM
,
8705 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8706 NL80211_FLAG_NEED_RTNL
,
8709 .cmd
= NL80211_CMD_DISASSOCIATE
,
8710 .doit
= nl80211_disassociate
,
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_JOIN_IBSS
,
8718 .doit
= nl80211_join_ibss
,
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_LEAVE_IBSS
,
8726 .doit
= nl80211_leave_ibss
,
8727 .policy
= nl80211_policy
,
8728 .flags
= GENL_ADMIN_PERM
,
8729 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8730 NL80211_FLAG_NEED_RTNL
,
8732 #ifdef CONFIG_NL80211_TESTMODE
8734 .cmd
= NL80211_CMD_TESTMODE
,
8735 .doit
= nl80211_testmode_do
,
8736 .dumpit
= nl80211_testmode_dump
,
8737 .policy
= nl80211_policy
,
8738 .flags
= GENL_ADMIN_PERM
,
8739 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8740 NL80211_FLAG_NEED_RTNL
,
8744 .cmd
= NL80211_CMD_CONNECT
,
8745 .doit
= nl80211_connect
,
8746 .policy
= nl80211_policy
,
8747 .flags
= GENL_ADMIN_PERM
,
8748 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8749 NL80211_FLAG_NEED_RTNL
,
8752 .cmd
= NL80211_CMD_DISCONNECT
,
8753 .doit
= nl80211_disconnect
,
8754 .policy
= nl80211_policy
,
8755 .flags
= GENL_ADMIN_PERM
,
8756 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8757 NL80211_FLAG_NEED_RTNL
,
8760 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8761 .doit
= nl80211_wiphy_netns
,
8762 .policy
= nl80211_policy
,
8763 .flags
= GENL_ADMIN_PERM
,
8764 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8765 NL80211_FLAG_NEED_RTNL
,
8768 .cmd
= NL80211_CMD_GET_SURVEY
,
8769 .policy
= nl80211_policy
,
8770 .dumpit
= nl80211_dump_survey
,
8773 .cmd
= NL80211_CMD_SET_PMKSA
,
8774 .doit
= nl80211_setdel_pmksa
,
8775 .policy
= nl80211_policy
,
8776 .flags
= GENL_ADMIN_PERM
,
8777 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8778 NL80211_FLAG_NEED_RTNL
,
8781 .cmd
= NL80211_CMD_DEL_PMKSA
,
8782 .doit
= nl80211_setdel_pmksa
,
8783 .policy
= nl80211_policy
,
8784 .flags
= GENL_ADMIN_PERM
,
8785 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8786 NL80211_FLAG_NEED_RTNL
,
8789 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8790 .doit
= nl80211_flush_pmksa
,
8791 .policy
= nl80211_policy
,
8792 .flags
= GENL_ADMIN_PERM
,
8793 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8794 NL80211_FLAG_NEED_RTNL
,
8797 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8798 .doit
= nl80211_remain_on_channel
,
8799 .policy
= nl80211_policy
,
8800 .flags
= GENL_ADMIN_PERM
,
8801 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8802 NL80211_FLAG_NEED_RTNL
,
8805 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8806 .doit
= nl80211_cancel_remain_on_channel
,
8807 .policy
= nl80211_policy
,
8808 .flags
= GENL_ADMIN_PERM
,
8809 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8810 NL80211_FLAG_NEED_RTNL
,
8813 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8814 .doit
= nl80211_set_tx_bitrate_mask
,
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_REGISTER_FRAME
,
8822 .doit
= nl80211_register_mgmt
,
8823 .policy
= nl80211_policy
,
8824 .flags
= GENL_ADMIN_PERM
,
8825 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8826 NL80211_FLAG_NEED_RTNL
,
8829 .cmd
= NL80211_CMD_FRAME
,
8830 .doit
= nl80211_tx_mgmt
,
8831 .policy
= nl80211_policy
,
8832 .flags
= GENL_ADMIN_PERM
,
8833 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8834 NL80211_FLAG_NEED_RTNL
,
8837 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8838 .doit
= nl80211_tx_mgmt_cancel_wait
,
8839 .policy
= nl80211_policy
,
8840 .flags
= GENL_ADMIN_PERM
,
8841 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8842 NL80211_FLAG_NEED_RTNL
,
8845 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8846 .doit
= nl80211_set_power_save
,
8847 .policy
= nl80211_policy
,
8848 .flags
= GENL_ADMIN_PERM
,
8849 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8850 NL80211_FLAG_NEED_RTNL
,
8853 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8854 .doit
= nl80211_get_power_save
,
8855 .policy
= nl80211_policy
,
8856 /* can be retrieved by unprivileged users */
8857 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8858 NL80211_FLAG_NEED_RTNL
,
8861 .cmd
= NL80211_CMD_SET_CQM
,
8862 .doit
= nl80211_set_cqm
,
8863 .policy
= nl80211_policy
,
8864 .flags
= GENL_ADMIN_PERM
,
8865 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8866 NL80211_FLAG_NEED_RTNL
,
8869 .cmd
= NL80211_CMD_SET_CHANNEL
,
8870 .doit
= nl80211_set_channel
,
8871 .policy
= nl80211_policy
,
8872 .flags
= GENL_ADMIN_PERM
,
8873 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8874 NL80211_FLAG_NEED_RTNL
,
8877 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8878 .doit
= nl80211_set_wds_peer
,
8879 .policy
= nl80211_policy
,
8880 .flags
= GENL_ADMIN_PERM
,
8881 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8882 NL80211_FLAG_NEED_RTNL
,
8885 .cmd
= NL80211_CMD_JOIN_MESH
,
8886 .doit
= nl80211_join_mesh
,
8887 .policy
= nl80211_policy
,
8888 .flags
= GENL_ADMIN_PERM
,
8889 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8890 NL80211_FLAG_NEED_RTNL
,
8893 .cmd
= NL80211_CMD_LEAVE_MESH
,
8894 .doit
= nl80211_leave_mesh
,
8895 .policy
= nl80211_policy
,
8896 .flags
= GENL_ADMIN_PERM
,
8897 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8898 NL80211_FLAG_NEED_RTNL
,
8902 .cmd
= NL80211_CMD_GET_WOWLAN
,
8903 .doit
= nl80211_get_wowlan
,
8904 .policy
= nl80211_policy
,
8905 /* can be retrieved by unprivileged users */
8906 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8907 NL80211_FLAG_NEED_RTNL
,
8910 .cmd
= NL80211_CMD_SET_WOWLAN
,
8911 .doit
= nl80211_set_wowlan
,
8912 .policy
= nl80211_policy
,
8913 .flags
= GENL_ADMIN_PERM
,
8914 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8915 NL80211_FLAG_NEED_RTNL
,
8919 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
8920 .doit
= nl80211_set_rekey_data
,
8921 .policy
= nl80211_policy
,
8922 .flags
= GENL_ADMIN_PERM
,
8923 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8924 NL80211_FLAG_NEED_RTNL
,
8927 .cmd
= NL80211_CMD_TDLS_MGMT
,
8928 .doit
= nl80211_tdls_mgmt
,
8929 .policy
= nl80211_policy
,
8930 .flags
= GENL_ADMIN_PERM
,
8931 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8932 NL80211_FLAG_NEED_RTNL
,
8935 .cmd
= NL80211_CMD_TDLS_OPER
,
8936 .doit
= nl80211_tdls_oper
,
8937 .policy
= nl80211_policy
,
8938 .flags
= GENL_ADMIN_PERM
,
8939 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8940 NL80211_FLAG_NEED_RTNL
,
8943 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
8944 .doit
= nl80211_register_unexpected_frame
,
8945 .policy
= nl80211_policy
,
8946 .flags
= GENL_ADMIN_PERM
,
8947 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8948 NL80211_FLAG_NEED_RTNL
,
8951 .cmd
= NL80211_CMD_PROBE_CLIENT
,
8952 .doit
= nl80211_probe_client
,
8953 .policy
= nl80211_policy
,
8954 .flags
= GENL_ADMIN_PERM
,
8955 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8956 NL80211_FLAG_NEED_RTNL
,
8959 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
8960 .doit
= nl80211_register_beacons
,
8961 .policy
= nl80211_policy
,
8962 .flags
= GENL_ADMIN_PERM
,
8963 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8964 NL80211_FLAG_NEED_RTNL
,
8967 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
8968 .doit
= nl80211_set_noack_map
,
8969 .policy
= nl80211_policy
,
8970 .flags
= GENL_ADMIN_PERM
,
8971 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8972 NL80211_FLAG_NEED_RTNL
,
8975 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
8976 .doit
= nl80211_start_p2p_device
,
8977 .policy
= nl80211_policy
,
8978 .flags
= GENL_ADMIN_PERM
,
8979 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8980 NL80211_FLAG_NEED_RTNL
,
8983 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
8984 .doit
= nl80211_stop_p2p_device
,
8985 .policy
= nl80211_policy
,
8986 .flags
= GENL_ADMIN_PERM
,
8987 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8988 NL80211_FLAG_NEED_RTNL
,
8991 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
8992 .doit
= nl80211_set_mcast_rate
,
8993 .policy
= nl80211_policy
,
8994 .flags
= GENL_ADMIN_PERM
,
8995 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8996 NL80211_FLAG_NEED_RTNL
,
8999 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9000 .doit
= nl80211_set_mac_acl
,
9001 .policy
= nl80211_policy
,
9002 .flags
= GENL_ADMIN_PERM
,
9003 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9004 NL80211_FLAG_NEED_RTNL
,
9007 .cmd
= NL80211_CMD_RADAR_DETECT
,
9008 .doit
= nl80211_start_radar_detection
,
9009 .policy
= nl80211_policy
,
9010 .flags
= GENL_ADMIN_PERM
,
9011 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9012 NL80211_FLAG_NEED_RTNL
,
9015 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9016 .doit
= nl80211_get_protocol_features
,
9017 .policy
= nl80211_policy
,
9020 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9021 .doit
= nl80211_update_ft_ies
,
9022 .policy
= nl80211_policy
,
9023 .flags
= GENL_ADMIN_PERM
,
9024 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9025 NL80211_FLAG_NEED_RTNL
,
9028 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9029 .doit
= nl80211_crit_protocol_start
,
9030 .policy
= nl80211_policy
,
9031 .flags
= GENL_ADMIN_PERM
,
9032 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9033 NL80211_FLAG_NEED_RTNL
,
9036 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9037 .doit
= nl80211_crit_protocol_stop
,
9038 .policy
= nl80211_policy
,
9039 .flags
= GENL_ADMIN_PERM
,
9040 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9041 NL80211_FLAG_NEED_RTNL
,
9045 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9049 /* multicast groups */
9050 static struct genl_multicast_group nl80211_config_mcgrp
= {
9053 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9056 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9057 .name
= "regulatory",
9060 /* notification functions */
9062 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9064 struct sk_buff
*msg
;
9065 struct nl80211_dump_wiphy_state state
= {};
9067 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9071 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0, &state
) < 0) {
9076 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9077 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9080 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9081 struct cfg80211_registered_device
*rdev
)
9083 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9084 struct nlattr
*nest
;
9090 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9092 goto nla_put_failure
;
9093 for (i
= 0; i
< req
->n_ssids
; i
++) {
9094 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9095 goto nla_put_failure
;
9097 nla_nest_end(msg
, nest
);
9099 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9101 goto nla_put_failure
;
9102 for (i
= 0; i
< req
->n_channels
; i
++) {
9103 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9104 goto nla_put_failure
;
9106 nla_nest_end(msg
, nest
);
9109 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9110 goto nla_put_failure
;
9113 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9120 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9121 struct cfg80211_registered_device
*rdev
,
9122 struct wireless_dev
*wdev
,
9123 u32 portid
, u32 seq
, int flags
,
9128 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9132 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9133 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9134 wdev
->netdev
->ifindex
)) ||
9135 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9136 goto nla_put_failure
;
9138 /* ignore errors and send incomplete event anyway */
9139 nl80211_add_scan_req(msg
, rdev
);
9141 return genlmsg_end(msg
, hdr
);
9144 genlmsg_cancel(msg
, hdr
);
9149 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9150 struct cfg80211_registered_device
*rdev
,
9151 struct net_device
*netdev
,
9152 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9156 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9160 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9161 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9162 goto nla_put_failure
;
9164 return genlmsg_end(msg
, hdr
);
9167 genlmsg_cancel(msg
, hdr
);
9171 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9172 struct wireless_dev
*wdev
)
9174 struct sk_buff
*msg
;
9176 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9180 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9181 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9186 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9187 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9190 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9191 struct wireless_dev
*wdev
)
9193 struct sk_buff
*msg
;
9195 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9199 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9200 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9205 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9206 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9209 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9210 struct wireless_dev
*wdev
)
9212 struct sk_buff
*msg
;
9214 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9218 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9219 NL80211_CMD_SCAN_ABORTED
) < 0) {
9224 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9225 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9228 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9229 struct net_device
*netdev
)
9231 struct sk_buff
*msg
;
9233 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9237 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9238 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9243 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9244 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9247 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9248 struct net_device
*netdev
, u32 cmd
)
9250 struct sk_buff
*msg
;
9252 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9256 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9261 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9262 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9266 * This can happen on global regulatory changes or device specific settings
9267 * based on custom world regulatory domains.
9269 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9271 struct sk_buff
*msg
;
9274 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9278 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9284 /* Userspace can always count this one always being set */
9285 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9286 goto nla_put_failure
;
9288 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9289 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9290 NL80211_REGDOM_TYPE_WORLD
))
9291 goto nla_put_failure
;
9292 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9293 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9294 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9295 goto nla_put_failure
;
9296 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9297 request
->intersect
) {
9298 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9299 NL80211_REGDOM_TYPE_INTERSECTION
))
9300 goto nla_put_failure
;
9302 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9303 NL80211_REGDOM_TYPE_COUNTRY
) ||
9304 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9306 goto nla_put_failure
;
9309 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9310 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9311 goto nla_put_failure
;
9313 genlmsg_end(msg
, hdr
);
9316 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9323 genlmsg_cancel(msg
, hdr
);
9327 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9328 struct net_device
*netdev
,
9329 const u8
*buf
, size_t len
,
9330 enum nl80211_commands cmd
, gfp_t gfp
)
9332 struct sk_buff
*msg
;
9335 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9339 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9345 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9346 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9347 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9348 goto nla_put_failure
;
9350 genlmsg_end(msg
, hdr
);
9352 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9353 nl80211_mlme_mcgrp
.id
, gfp
);
9357 genlmsg_cancel(msg
, hdr
);
9361 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9362 struct net_device
*netdev
, const u8
*buf
,
9363 size_t len
, gfp_t gfp
)
9365 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9366 NL80211_CMD_AUTHENTICATE
, gfp
);
9369 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9370 struct net_device
*netdev
, const u8
*buf
,
9371 size_t len
, gfp_t gfp
)
9373 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9374 NL80211_CMD_ASSOCIATE
, gfp
);
9377 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9378 struct net_device
*netdev
, const u8
*buf
,
9379 size_t len
, gfp_t gfp
)
9381 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9382 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9385 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9386 struct net_device
*netdev
, const u8
*buf
,
9387 size_t len
, gfp_t gfp
)
9389 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9390 NL80211_CMD_DISASSOCIATE
, gfp
);
9393 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
9396 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9397 struct wiphy
*wiphy
= wdev
->wiphy
;
9398 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9399 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
9402 if (WARN_ON(len
< 2))
9405 if (ieee80211_is_deauth(mgmt
->frame_control
))
9406 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
9408 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
9410 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
9411 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
);
9413 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
9415 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9416 struct net_device
*netdev
, int cmd
,
9417 const u8
*addr
, gfp_t gfp
)
9419 struct sk_buff
*msg
;
9422 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9426 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9432 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9433 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9434 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9435 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9436 goto nla_put_failure
;
9438 genlmsg_end(msg
, hdr
);
9440 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9441 nl80211_mlme_mcgrp
.id
, gfp
);
9445 genlmsg_cancel(msg
, hdr
);
9449 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9450 struct net_device
*netdev
, const u8
*addr
,
9453 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9457 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9458 struct net_device
*netdev
, const u8
*addr
,
9461 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9465 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9466 struct net_device
*netdev
, const u8
*bssid
,
9467 const u8
*req_ie
, size_t req_ie_len
,
9468 const u8
*resp_ie
, size_t resp_ie_len
,
9469 u16 status
, gfp_t gfp
)
9471 struct sk_buff
*msg
;
9474 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9478 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9484 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9485 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9486 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9487 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9489 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9491 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9492 goto nla_put_failure
;
9494 genlmsg_end(msg
, hdr
);
9496 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9497 nl80211_mlme_mcgrp
.id
, gfp
);
9501 genlmsg_cancel(msg
, hdr
);
9506 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9507 struct net_device
*netdev
, const u8
*bssid
,
9508 const u8
*req_ie
, size_t req_ie_len
,
9509 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9511 struct sk_buff
*msg
;
9514 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9518 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9524 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9525 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9526 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
9528 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9530 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9531 goto nla_put_failure
;
9533 genlmsg_end(msg
, hdr
);
9535 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9536 nl80211_mlme_mcgrp
.id
, gfp
);
9540 genlmsg_cancel(msg
, hdr
);
9545 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9546 struct net_device
*netdev
, u16 reason
,
9547 const u8
*ie
, size_t ie_len
, bool from_ap
)
9549 struct sk_buff
*msg
;
9552 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9556 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9562 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9563 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9564 (from_ap
&& reason
&&
9565 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9567 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9568 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9569 goto nla_put_failure
;
9571 genlmsg_end(msg
, hdr
);
9573 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9574 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9578 genlmsg_cancel(msg
, hdr
);
9583 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9584 struct net_device
*netdev
, const u8
*bssid
,
9587 struct sk_buff
*msg
;
9590 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9594 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9600 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9601 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9602 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9603 goto nla_put_failure
;
9605 genlmsg_end(msg
, hdr
);
9607 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9608 nl80211_mlme_mcgrp
.id
, gfp
);
9612 genlmsg_cancel(msg
, hdr
);
9616 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
9617 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
9619 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9620 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9621 struct sk_buff
*msg
;
9624 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
9627 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
9629 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9633 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9639 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9640 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9641 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9643 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9644 goto nla_put_failure
;
9646 genlmsg_end(msg
, hdr
);
9648 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9649 nl80211_mlme_mcgrp
.id
, gfp
);
9653 genlmsg_cancel(msg
, hdr
);
9656 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
9658 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9659 struct net_device
*netdev
, const u8
*addr
,
9660 enum nl80211_key_type key_type
, int key_id
,
9661 const u8
*tsc
, gfp_t gfp
)
9663 struct sk_buff
*msg
;
9666 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9670 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9676 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9677 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9678 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9679 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9681 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9682 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9683 goto nla_put_failure
;
9685 genlmsg_end(msg
, hdr
);
9687 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9688 nl80211_mlme_mcgrp
.id
, gfp
);
9692 genlmsg_cancel(msg
, hdr
);
9696 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9697 struct ieee80211_channel
*channel_before
,
9698 struct ieee80211_channel
*channel_after
)
9700 struct sk_buff
*msg
;
9702 struct nlattr
*nl_freq
;
9704 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9708 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9715 * Since we are applying the beacon hint to a wiphy we know its
9716 * wiphy_idx is valid
9718 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9719 goto nla_put_failure
;
9722 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9724 goto nla_put_failure
;
9725 if (nl80211_msg_put_channel(msg
, channel_before
, false))
9726 goto nla_put_failure
;
9727 nla_nest_end(msg
, nl_freq
);
9730 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9732 goto nla_put_failure
;
9733 if (nl80211_msg_put_channel(msg
, channel_after
, false))
9734 goto nla_put_failure
;
9735 nla_nest_end(msg
, nl_freq
);
9737 genlmsg_end(msg
, hdr
);
9740 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9747 genlmsg_cancel(msg
, hdr
);
9751 static void nl80211_send_remain_on_chan_event(
9752 int cmd
, struct cfg80211_registered_device
*rdev
,
9753 struct wireless_dev
*wdev
, u64 cookie
,
9754 struct ieee80211_channel
*chan
,
9755 unsigned int duration
, gfp_t gfp
)
9757 struct sk_buff
*msg
;
9760 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9764 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9770 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9771 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9772 wdev
->netdev
->ifindex
)) ||
9773 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9774 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9775 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9776 NL80211_CHAN_NO_HT
) ||
9777 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9778 goto nla_put_failure
;
9780 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9781 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9782 goto nla_put_failure
;
9784 genlmsg_end(msg
, hdr
);
9786 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9787 nl80211_mlme_mcgrp
.id
, gfp
);
9791 genlmsg_cancel(msg
, hdr
);
9795 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
9796 struct ieee80211_channel
*chan
,
9797 unsigned int duration
, gfp_t gfp
)
9799 struct wiphy
*wiphy
= wdev
->wiphy
;
9800 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9802 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
9803 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9804 rdev
, wdev
, cookie
, chan
,
9807 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
9809 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
9810 struct ieee80211_channel
*chan
,
9813 struct wiphy
*wiphy
= wdev
->wiphy
;
9814 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9816 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
9817 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9818 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9820 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
9822 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
9823 struct station_info
*sinfo
, gfp_t gfp
)
9825 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9826 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9827 struct sk_buff
*msg
;
9829 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
9831 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9835 if (nl80211_send_station(msg
, 0, 0, 0,
9836 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9841 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9842 nl80211_mlme_mcgrp
.id
, gfp
);
9844 EXPORT_SYMBOL(cfg80211_new_sta
);
9846 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
9848 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9849 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9850 struct sk_buff
*msg
;
9853 trace_cfg80211_del_sta(dev
, mac_addr
);
9855 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9859 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9865 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9866 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9867 goto nla_put_failure
;
9869 genlmsg_end(msg
, hdr
);
9871 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9872 nl80211_mlme_mcgrp
.id
, gfp
);
9876 genlmsg_cancel(msg
, hdr
);
9879 EXPORT_SYMBOL(cfg80211_del_sta
);
9881 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
9882 enum nl80211_connect_failed_reason reason
,
9885 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
9886 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9887 struct sk_buff
*msg
;
9890 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
9894 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
9900 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9901 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
9902 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
9903 goto nla_put_failure
;
9905 genlmsg_end(msg
, hdr
);
9907 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9908 nl80211_mlme_mcgrp
.id
, gfp
);
9912 genlmsg_cancel(msg
, hdr
);
9915 EXPORT_SYMBOL(cfg80211_conn_failed
);
9917 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
9918 const u8
*addr
, gfp_t gfp
)
9920 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9921 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9922 struct sk_buff
*msg
;
9924 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
9929 msg
= nlmsg_new(100, gfp
);
9933 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9939 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9940 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9941 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9942 goto nla_put_failure
;
9944 genlmsg_end(msg
, hdr
);
9945 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9949 genlmsg_cancel(msg
, hdr
);
9954 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
9955 const u8
*addr
, gfp_t gfp
)
9957 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9960 trace_cfg80211_rx_spurious_frame(dev
, addr
);
9962 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9963 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
9964 trace_cfg80211_return_bool(false);
9967 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
9969 trace_cfg80211_return_bool(ret
);
9972 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
9974 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
9975 const u8
*addr
, gfp_t gfp
)
9977 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9980 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
9982 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
9983 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
9984 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
9985 trace_cfg80211_return_bool(false);
9988 ret
= __nl80211_unexpected_frame(dev
,
9989 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
9991 trace_cfg80211_return_bool(ret
);
9994 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
9996 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
9997 struct wireless_dev
*wdev
, u32 nlportid
,
9998 int freq
, int sig_dbm
,
9999 const u8
*buf
, size_t len
, gfp_t gfp
)
10001 struct net_device
*netdev
= wdev
->netdev
;
10002 struct sk_buff
*msg
;
10005 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10009 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10015 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10016 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10017 netdev
->ifindex
)) ||
10018 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10019 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10021 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10022 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
10023 goto nla_put_failure
;
10025 genlmsg_end(msg
, hdr
);
10027 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10030 genlmsg_cancel(msg
, hdr
);
10035 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10036 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10038 struct wiphy
*wiphy
= wdev
->wiphy
;
10039 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10040 struct net_device
*netdev
= wdev
->netdev
;
10041 struct sk_buff
*msg
;
10044 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10046 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10050 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10056 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10057 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10058 netdev
->ifindex
)) ||
10059 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10060 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10061 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10062 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10063 goto nla_put_failure
;
10065 genlmsg_end(msg
, hdr
);
10067 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
10071 genlmsg_cancel(msg
, hdr
);
10074 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10076 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10077 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10080 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10081 struct wiphy
*wiphy
= wdev
->wiphy
;
10082 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10083 struct sk_buff
*msg
;
10084 struct nlattr
*pinfoattr
;
10087 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10089 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10093 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10099 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10100 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10101 goto nla_put_failure
;
10103 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10105 goto nla_put_failure
;
10107 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10109 goto nla_put_failure
;
10111 nla_nest_end(msg
, pinfoattr
);
10113 genlmsg_end(msg
, hdr
);
10115 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10116 nl80211_mlme_mcgrp
.id
, gfp
);
10120 genlmsg_cancel(msg
, hdr
);
10123 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10125 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10126 struct net_device
*netdev
, const u8
*bssid
,
10127 const u8
*replay_ctr
, gfp_t gfp
)
10129 struct sk_buff
*msg
;
10130 struct nlattr
*rekey_attr
;
10133 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10137 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10143 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10144 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10145 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10146 goto nla_put_failure
;
10148 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10150 goto nla_put_failure
;
10152 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10153 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10154 goto nla_put_failure
;
10156 nla_nest_end(msg
, rekey_attr
);
10158 genlmsg_end(msg
, hdr
);
10160 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10161 nl80211_mlme_mcgrp
.id
, gfp
);
10165 genlmsg_cancel(msg
, hdr
);
10169 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10170 const u8
*replay_ctr
, gfp_t gfp
)
10172 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10173 struct wiphy
*wiphy
= wdev
->wiphy
;
10174 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10176 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10177 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10179 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10182 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10183 struct net_device
*netdev
, int index
,
10184 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10186 struct sk_buff
*msg
;
10187 struct nlattr
*attr
;
10190 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10194 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10200 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10201 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10202 goto nla_put_failure
;
10204 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10206 goto nla_put_failure
;
10208 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10209 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10211 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10212 goto nla_put_failure
;
10214 nla_nest_end(msg
, attr
);
10216 genlmsg_end(msg
, hdr
);
10218 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10219 nl80211_mlme_mcgrp
.id
, gfp
);
10223 genlmsg_cancel(msg
, hdr
);
10227 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10228 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10230 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10231 struct wiphy
*wiphy
= wdev
->wiphy
;
10232 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10234 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10235 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10237 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10239 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10240 struct net_device
*netdev
,
10241 struct cfg80211_chan_def
*chandef
,
10244 struct sk_buff
*msg
;
10247 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10251 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10257 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10258 goto nla_put_failure
;
10260 if (nl80211_send_chandef(msg
, chandef
))
10261 goto nla_put_failure
;
10263 genlmsg_end(msg
, hdr
);
10265 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10266 nl80211_mlme_mcgrp
.id
, gfp
);
10270 genlmsg_cancel(msg
, hdr
);
10274 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10275 struct cfg80211_chan_def
*chandef
)
10277 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10278 struct wiphy
*wiphy
= wdev
->wiphy
;
10279 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10281 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10285 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10286 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
))
10289 wdev
->channel
= chandef
->chan
;
10290 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10295 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10297 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10298 const u8
*peer
, u32 num_packets
,
10299 u32 rate
, u32 intvl
, gfp_t gfp
)
10301 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10302 struct wiphy
*wiphy
= wdev
->wiphy
;
10303 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10304 struct sk_buff
*msg
;
10305 struct nlattr
*pinfoattr
;
10308 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10312 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10318 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10319 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10320 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10321 goto nla_put_failure
;
10323 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10325 goto nla_put_failure
;
10327 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10328 goto nla_put_failure
;
10330 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10331 goto nla_put_failure
;
10333 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10334 goto nla_put_failure
;
10336 nla_nest_end(msg
, pinfoattr
);
10338 genlmsg_end(msg
, hdr
);
10340 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10341 nl80211_mlme_mcgrp
.id
, gfp
);
10345 genlmsg_cancel(msg
, hdr
);
10348 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10351 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10352 struct cfg80211_chan_def
*chandef
,
10353 enum nl80211_radar_event event
,
10354 struct net_device
*netdev
, gfp_t gfp
)
10356 struct sk_buff
*msg
;
10359 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10363 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10369 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10370 goto nla_put_failure
;
10372 /* NOP and radar events don't need a netdev parameter */
10374 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10376 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10377 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10378 goto nla_put_failure
;
10381 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10382 goto nla_put_failure
;
10384 if (nl80211_send_chandef(msg
, chandef
))
10385 goto nla_put_failure
;
10387 genlmsg_end(msg
, hdr
);
10389 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10390 nl80211_mlme_mcgrp
.id
, gfp
);
10394 genlmsg_cancel(msg
, hdr
);
10398 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10399 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10401 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10402 struct wiphy
*wiphy
= wdev
->wiphy
;
10403 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10404 struct sk_buff
*msg
;
10405 struct nlattr
*pinfoattr
;
10408 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10410 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10414 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10420 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10421 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10422 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10423 goto nla_put_failure
;
10425 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10427 goto nla_put_failure
;
10429 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10430 goto nla_put_failure
;
10432 nla_nest_end(msg
, pinfoattr
);
10434 genlmsg_end(msg
, hdr
);
10436 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10437 nl80211_mlme_mcgrp
.id
, gfp
);
10441 genlmsg_cancel(msg
, hdr
);
10444 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10446 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10447 u64 cookie
, bool acked
, gfp_t gfp
)
10449 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10450 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10451 struct sk_buff
*msg
;
10454 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10456 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10461 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10467 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10468 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10469 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10470 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10471 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10472 goto nla_put_failure
;
10474 genlmsg_end(msg
, hdr
);
10476 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10477 nl80211_mlme_mcgrp
.id
, gfp
);
10481 genlmsg_cancel(msg
, hdr
);
10484 EXPORT_SYMBOL(cfg80211_probe_status
);
10486 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10487 const u8
*frame
, size_t len
,
10488 int freq
, int sig_dbm
)
10490 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10491 struct sk_buff
*msg
;
10493 struct cfg80211_beacon_registration
*reg
;
10495 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10497 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10498 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10499 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10501 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10505 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10507 goto nla_put_failure
;
10509 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10511 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10513 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10514 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10515 goto nla_put_failure
;
10517 genlmsg_end(msg
, hdr
);
10519 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
10521 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10525 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10527 genlmsg_cancel(msg
, hdr
);
10530 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
10533 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
10534 struct cfg80211_wowlan_wakeup
*wakeup
,
10537 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10538 struct sk_buff
*msg
;
10542 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
10545 size
+= wakeup
->packet_present_len
;
10547 msg
= nlmsg_new(size
, gfp
);
10551 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
10555 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10556 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10559 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10560 wdev
->netdev
->ifindex
))
10564 struct nlattr
*reasons
;
10566 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
10568 if (wakeup
->disconnect
&&
10569 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
10571 if (wakeup
->magic_pkt
&&
10572 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
10574 if (wakeup
->gtk_rekey_failure
&&
10575 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
10577 if (wakeup
->eap_identity_req
&&
10578 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
10580 if (wakeup
->four_way_handshake
&&
10581 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
10583 if (wakeup
->rfkill_release
&&
10584 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
10587 if (wakeup
->pattern_idx
>= 0 &&
10588 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
10589 wakeup
->pattern_idx
))
10592 if (wakeup
->tcp_match
)
10593 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
10595 if (wakeup
->tcp_connlost
)
10597 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
10599 if (wakeup
->tcp_nomoretokens
)
10601 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
10603 if (wakeup
->packet
) {
10604 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
10605 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
10607 if (!wakeup
->packet_80211
) {
10609 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
10611 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
10614 if (wakeup
->packet_len
&&
10615 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
10618 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
10623 nla_nest_end(msg
, reasons
);
10626 genlmsg_end(msg
, hdr
);
10628 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10629 nl80211_mlme_mcgrp
.id
, gfp
);
10635 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
10638 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
10639 enum nl80211_tdls_operation oper
,
10640 u16 reason_code
, gfp_t gfp
)
10642 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10643 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10644 struct sk_buff
*msg
;
10647 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10650 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10654 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10660 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10661 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10662 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10663 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10664 (reason_code
> 0 &&
10665 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10666 goto nla_put_failure
;
10668 genlmsg_end(msg
, hdr
);
10670 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10671 nl80211_mlme_mcgrp
.id
, gfp
);
10675 genlmsg_cancel(msg
, hdr
);
10678 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10680 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10681 unsigned long state
,
10684 struct netlink_notify
*notify
= _notify
;
10685 struct cfg80211_registered_device
*rdev
;
10686 struct wireless_dev
*wdev
;
10687 struct cfg80211_beacon_registration
*reg
, *tmp
;
10689 if (state
!= NETLINK_URELEASE
)
10690 return NOTIFY_DONE
;
10694 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10695 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10696 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10698 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10699 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10701 if (reg
->nlportid
== notify
->portid
) {
10702 list_del(®
->list
);
10707 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10712 return NOTIFY_DONE
;
10715 static struct notifier_block nl80211_netlink_notifier
= {
10716 .notifier_call
= nl80211_netlink_notify
,
10719 void cfg80211_ft_event(struct net_device
*netdev
,
10720 struct cfg80211_ft_event_params
*ft_event
)
10722 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
10723 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10724 struct sk_buff
*msg
;
10727 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
10729 if (!ft_event
->target_ap
)
10732 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10736 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
10742 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
10743 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
10744 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
10746 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
10747 if (ft_event
->ric_ies
)
10748 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
10749 ft_event
->ric_ies
);
10751 genlmsg_end(msg
, hdr
);
10753 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10754 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10756 EXPORT_SYMBOL(cfg80211_ft_event
);
10758 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
10760 struct cfg80211_registered_device
*rdev
;
10761 struct sk_buff
*msg
;
10765 rdev
= wiphy_to_dev(wdev
->wiphy
);
10766 if (!rdev
->crit_proto_nlportid
)
10769 nlportid
= rdev
->crit_proto_nlportid
;
10770 rdev
->crit_proto_nlportid
= 0;
10772 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10776 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
10778 goto nla_put_failure
;
10780 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10781 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10782 goto nla_put_failure
;
10784 genlmsg_end(msg
, hdr
);
10786 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10791 genlmsg_cancel(msg
, hdr
);
10795 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
10797 /* initialisation/exit functions */
10799 int nl80211_init(void)
10803 err
= genl_register_family_with_ops(&nl80211_fam
,
10804 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10808 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10812 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10816 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10820 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10824 #ifdef CONFIG_NL80211_TESTMODE
10825 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10830 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10836 genl_unregister_family(&nl80211_fam
);
10840 void nl80211_exit(void)
10842 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10843 genl_unregister_family(&nl80211_fam
);