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
},
352 [NL80211_ATTR_CH_SWITCH_COUNT
] = { .type
= NLA_U32
},
353 [NL80211_ATTR_CH_SWITCH_BLOCK_TX
] = { .type
= NLA_FLAG
},
354 [NL80211_ATTR_CSA_IES
] = { .type
= NLA_NESTED
},
355 [NL80211_ATTR_CSA_C_OFF_BEACON
] = { .type
= NLA_U16
},
356 [NL80211_ATTR_CSA_C_OFF_PRESP
] = { .type
= NLA_U16
},
359 /* policy for the key attributes */
360 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
361 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
362 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
363 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
364 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
365 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
366 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
367 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
368 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
371 /* policy for the key default flags */
372 static const struct nla_policy
373 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
374 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
375 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
378 /* policy for WoWLAN attributes */
379 static const struct nla_policy
380 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
381 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
382 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
383 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
384 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
385 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
386 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
387 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
388 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
389 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
392 static const struct nla_policy
393 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
394 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
395 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
396 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
397 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
398 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
399 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
400 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
401 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
403 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
404 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
406 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
407 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
408 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
411 /* policy for coalesce rule attributes */
412 static const struct nla_policy
413 nl80211_coalesce_policy
[NUM_NL80211_ATTR_COALESCE_RULE
] = {
414 [NL80211_ATTR_COALESCE_RULE_DELAY
] = { .type
= NLA_U32
},
415 [NL80211_ATTR_COALESCE_RULE_CONDITION
] = { .type
= NLA_U32
},
416 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
] = { .type
= NLA_NESTED
},
419 /* policy for GTK rekey offload attributes */
420 static const struct nla_policy
421 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
422 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
423 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
424 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
427 static const struct nla_policy
428 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
429 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
430 .len
= IEEE80211_MAX_SSID_LEN
},
431 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
434 static int nl80211_prepare_wdev_dump(struct sk_buff
*skb
,
435 struct netlink_callback
*cb
,
436 struct cfg80211_registered_device
**rdev
,
437 struct wireless_dev
**wdev
)
444 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
445 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
450 *wdev
= __cfg80211_wdev_from_attrs(sock_net(skb
->sk
),
451 nl80211_fam
.attrbuf
);
453 err
= PTR_ERR(*wdev
);
456 *rdev
= wiphy_to_dev((*wdev
)->wiphy
);
457 /* 0 is the first index - add 1 to parse only once */
458 cb
->args
[0] = (*rdev
)->wiphy_idx
+ 1;
459 cb
->args
[1] = (*wdev
)->identifier
;
461 /* subtract the 1 again here */
462 struct wiphy
*wiphy
= wiphy_idx_to_wiphy(cb
->args
[0] - 1);
463 struct wireless_dev
*tmp
;
469 *rdev
= wiphy_to_dev(wiphy
);
472 list_for_each_entry(tmp
, &(*rdev
)->wdev_list
, list
) {
473 if (tmp
->identifier
== cb
->args
[1]) {
491 static void nl80211_finish_wdev_dump(struct cfg80211_registered_device
*rdev
)
497 static bool is_valid_ie_attr(const struct nlattr
*attr
)
505 pos
= nla_data(attr
);
526 /* message building helper */
527 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
530 /* since there is no private header just add the generic one */
531 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
534 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
535 struct ieee80211_channel
*chan
,
538 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
540 goto nla_put_failure
;
542 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
543 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
544 goto nla_put_failure
;
545 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
546 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
547 goto nla_put_failure
;
548 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
549 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
550 goto nla_put_failure
;
551 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
552 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
553 goto nla_put_failure
;
557 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
559 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
561 goto nla_put_failure
;
562 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
,
564 goto nla_put_failure
;
569 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
570 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
571 goto nla_put_failure
;
572 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
573 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
574 goto nla_put_failure
;
575 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
576 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
577 goto nla_put_failure
;
578 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
579 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
580 goto nla_put_failure
;
583 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
584 DBM_TO_MBM(chan
->max_power
)))
585 goto nla_put_failure
;
593 /* netlink command implementations */
600 bool def_uni
, def_multi
;
603 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
605 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
606 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
611 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
612 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
621 if (tb
[NL80211_KEY_IDX
])
622 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
624 if (tb
[NL80211_KEY_DATA
]) {
625 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
626 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
629 if (tb
[NL80211_KEY_SEQ
]) {
630 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
631 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
634 if (tb
[NL80211_KEY_CIPHER
])
635 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
637 if (tb
[NL80211_KEY_TYPE
]) {
638 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
639 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
643 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
644 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
645 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
646 tb
[NL80211_KEY_DEFAULT_TYPES
],
647 nl80211_key_default_policy
);
651 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
652 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
658 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
660 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
661 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
662 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
665 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
666 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
667 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
670 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
671 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
673 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
674 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
676 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
677 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
686 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
687 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
688 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
692 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
693 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
694 int err
= nla_parse_nested(
695 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
696 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
697 nl80211_key_default_policy
);
701 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
702 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
708 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
712 memset(k
, 0, sizeof(*k
));
716 if (info
->attrs
[NL80211_ATTR_KEY
])
717 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
719 err
= nl80211_parse_key_old(info
, k
);
724 if (k
->def
&& k
->defmgmt
)
728 if (k
->def_uni
|| !k
->def_multi
)
734 if (k
->idx
< 4 || k
->idx
> 5)
737 if (k
->idx
< 0 || k
->idx
> 3)
740 if (k
->idx
< 0 || k
->idx
> 5)
748 static struct cfg80211_cached_keys
*
749 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
750 struct nlattr
*keys
, bool *no_ht
)
752 struct key_parse parse
;
754 struct cfg80211_cached_keys
*result
;
755 int rem
, err
, def
= 0;
757 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
759 return ERR_PTR(-ENOMEM
);
762 result
->defmgmt
= -1;
764 nla_for_each_nested(key
, keys
, rem
) {
765 memset(&parse
, 0, sizeof(parse
));
768 err
= nl80211_parse_key_new(key
, &parse
);
774 if (parse
.idx
< 0 || parse
.idx
> 4)
780 result
->def
= parse
.idx
;
781 if (!parse
.def_uni
|| !parse
.def_multi
)
783 } else if (parse
.defmgmt
)
785 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
786 parse
.idx
, false, NULL
);
789 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
790 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
791 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
792 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
794 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
795 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
807 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
809 ASSERT_WDEV_LOCK(wdev
);
811 switch (wdev
->iftype
) {
812 case NL80211_IFTYPE_AP
:
813 case NL80211_IFTYPE_AP_VLAN
:
814 case NL80211_IFTYPE_P2P_GO
:
815 case NL80211_IFTYPE_MESH_POINT
:
817 case NL80211_IFTYPE_ADHOC
:
818 case NL80211_IFTYPE_STATION
:
819 case NL80211_IFTYPE_P2P_CLIENT
:
820 if (!wdev
->current_bss
)
830 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
832 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
836 goto nla_put_failure
;
840 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
841 goto nla_put_failure
;
846 nla_nest_end(msg
, nl_modes
);
853 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
857 struct nlattr
*nl_combis
;
860 nl_combis
= nla_nest_start(msg
,
861 NL80211_ATTR_INTERFACE_COMBINATIONS
);
863 goto nla_put_failure
;
865 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
866 const struct ieee80211_iface_combination
*c
;
867 struct nlattr
*nl_combi
, *nl_limits
;
869 c
= &wiphy
->iface_combinations
[i
];
871 nl_combi
= nla_nest_start(msg
, i
+ 1);
873 goto nla_put_failure
;
875 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
877 goto nla_put_failure
;
879 for (j
= 0; j
< c
->n_limits
; j
++) {
880 struct nlattr
*nl_limit
;
882 nl_limit
= nla_nest_start(msg
, j
+ 1);
884 goto nla_put_failure
;
885 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
887 goto nla_put_failure
;
888 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
890 goto nla_put_failure
;
891 nla_nest_end(msg
, nl_limit
);
894 nla_nest_end(msg
, nl_limits
);
896 if (c
->beacon_int_infra_match
&&
897 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
898 goto nla_put_failure
;
899 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
900 c
->num_different_channels
) ||
901 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
903 goto nla_put_failure
;
905 nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
906 c
->radar_detect_widths
))
907 goto nla_put_failure
;
909 nla_nest_end(msg
, nl_combi
);
912 nla_nest_end(msg
, nl_combis
);
920 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
923 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
->tcp
;
924 struct nlattr
*nl_tcp
;
929 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
933 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
934 tcp
->data_payload_max
))
937 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
938 tcp
->data_payload_max
))
941 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
944 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
945 sizeof(*tcp
->tok
), tcp
->tok
))
948 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
949 tcp
->data_interval_max
))
952 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
953 tcp
->wake_payload_max
))
956 nla_nest_end(msg
, nl_tcp
);
960 static int nl80211_send_wowlan(struct sk_buff
*msg
,
961 struct cfg80211_registered_device
*dev
,
964 struct nlattr
*nl_wowlan
;
966 if (!dev
->wiphy
.wowlan
)
969 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
973 if (((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_ANY
) &&
974 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
975 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
) &&
976 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
977 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
978 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
979 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
980 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
981 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
982 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
983 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
984 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
985 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
986 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
987 ((dev
->wiphy
.wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
988 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
991 if (dev
->wiphy
.wowlan
->n_patterns
) {
992 struct nl80211_pattern_support pat
= {
993 .max_patterns
= dev
->wiphy
.wowlan
->n_patterns
,
994 .min_pattern_len
= dev
->wiphy
.wowlan
->pattern_min_len
,
995 .max_pattern_len
= dev
->wiphy
.wowlan
->pattern_max_len
,
996 .max_pkt_offset
= dev
->wiphy
.wowlan
->max_pkt_offset
,
999 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1004 if (large
&& nl80211_send_wowlan_tcp_caps(dev
, msg
))
1007 nla_nest_end(msg
, nl_wowlan
);
1013 static int nl80211_send_coalesce(struct sk_buff
*msg
,
1014 struct cfg80211_registered_device
*dev
)
1016 struct nl80211_coalesce_rule_support rule
;
1018 if (!dev
->wiphy
.coalesce
)
1021 rule
.max_rules
= dev
->wiphy
.coalesce
->n_rules
;
1022 rule
.max_delay
= dev
->wiphy
.coalesce
->max_delay
;
1023 rule
.pat
.max_patterns
= dev
->wiphy
.coalesce
->n_patterns
;
1024 rule
.pat
.min_pattern_len
= dev
->wiphy
.coalesce
->pattern_min_len
;
1025 rule
.pat
.max_pattern_len
= dev
->wiphy
.coalesce
->pattern_max_len
;
1026 rule
.pat
.max_pkt_offset
= dev
->wiphy
.coalesce
->max_pkt_offset
;
1028 if (nla_put(msg
, NL80211_ATTR_COALESCE_RULE
, sizeof(rule
), &rule
))
1034 static int nl80211_send_band_rateinfo(struct sk_buff
*msg
,
1035 struct ieee80211_supported_band
*sband
)
1037 struct nlattr
*nl_rates
, *nl_rate
;
1038 struct ieee80211_rate
*rate
;
1042 if (sband
->ht_cap
.ht_supported
&&
1043 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1044 sizeof(sband
->ht_cap
.mcs
),
1045 &sband
->ht_cap
.mcs
) ||
1046 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1047 sband
->ht_cap
.cap
) ||
1048 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1049 sband
->ht_cap
.ampdu_factor
) ||
1050 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1051 sband
->ht_cap
.ampdu_density
)))
1055 if (sband
->vht_cap
.vht_supported
&&
1056 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1057 sizeof(sband
->vht_cap
.vht_mcs
),
1058 &sband
->vht_cap
.vht_mcs
) ||
1059 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1060 sband
->vht_cap
.cap
)))
1064 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1068 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1069 nl_rate
= nla_nest_start(msg
, i
);
1073 rate
= &sband
->bitrates
[i
];
1074 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1077 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1079 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1082 nla_nest_end(msg
, nl_rate
);
1085 nla_nest_end(msg
, nl_rates
);
1091 nl80211_send_mgmt_stypes(struct sk_buff
*msg
,
1092 const struct ieee80211_txrx_stypes
*mgmt_stypes
)
1095 struct nlattr
*nl_ftypes
, *nl_ifs
;
1096 enum nl80211_iftype ift
;
1102 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1106 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1107 nl_ftypes
= nla_nest_start(msg
, ift
);
1111 stypes
= mgmt_stypes
[ift
].tx
;
1114 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1115 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1120 nla_nest_end(msg
, nl_ftypes
);
1123 nla_nest_end(msg
, nl_ifs
);
1125 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1129 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1130 nl_ftypes
= nla_nest_start(msg
, ift
);
1134 stypes
= mgmt_stypes
[ift
].rx
;
1137 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1138 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1143 nla_nest_end(msg
, nl_ftypes
);
1145 nla_nest_end(msg
, nl_ifs
);
1150 struct nl80211_dump_wiphy_state
{
1153 long split_start
, band_start
, chan_start
;
1157 static int nl80211_send_wiphy(struct cfg80211_registered_device
*dev
,
1158 struct sk_buff
*msg
, u32 portid
, u32 seq
,
1159 int flags
, struct nl80211_dump_wiphy_state
*state
)
1162 struct nlattr
*nl_bands
, *nl_band
;
1163 struct nlattr
*nl_freqs
, *nl_freq
;
1164 struct nlattr
*nl_cmds
;
1165 enum ieee80211_band band
;
1166 struct ieee80211_channel
*chan
;
1168 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
1169 dev
->wiphy
.mgmt_stypes
;
1172 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
1176 if (WARN_ON(!state
))
1179 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
1180 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
,
1181 wiphy_name(&dev
->wiphy
)) ||
1182 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1183 cfg80211_rdev_list_generation
))
1184 goto nla_put_failure
;
1186 switch (state
->split_start
) {
1188 if (nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
1189 dev
->wiphy
.retry_short
) ||
1190 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
1191 dev
->wiphy
.retry_long
) ||
1192 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
1193 dev
->wiphy
.frag_threshold
) ||
1194 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
1195 dev
->wiphy
.rts_threshold
) ||
1196 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
1197 dev
->wiphy
.coverage_class
) ||
1198 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
1199 dev
->wiphy
.max_scan_ssids
) ||
1200 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
1201 dev
->wiphy
.max_sched_scan_ssids
) ||
1202 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
1203 dev
->wiphy
.max_scan_ie_len
) ||
1204 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
1205 dev
->wiphy
.max_sched_scan_ie_len
) ||
1206 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1207 dev
->wiphy
.max_match_sets
))
1208 goto nla_put_failure
;
1210 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1211 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1212 goto nla_put_failure
;
1213 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1214 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1215 goto nla_put_failure
;
1216 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1217 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1218 goto nla_put_failure
;
1219 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1220 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1221 goto nla_put_failure
;
1222 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1223 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1224 goto nla_put_failure
;
1225 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1226 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1227 goto nla_put_failure
;
1228 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
) &&
1229 nla_put_flag(msg
, WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1230 goto nla_put_failure
;
1232 state
->split_start
++;
1236 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1237 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1238 dev
->wiphy
.cipher_suites
))
1239 goto nla_put_failure
;
1241 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1242 dev
->wiphy
.max_num_pmkids
))
1243 goto nla_put_failure
;
1245 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1246 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1247 goto nla_put_failure
;
1249 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1250 dev
->wiphy
.available_antennas_tx
) ||
1251 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1252 dev
->wiphy
.available_antennas_rx
))
1253 goto nla_put_failure
;
1255 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1256 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1257 dev
->wiphy
.probe_resp_offload
))
1258 goto nla_put_failure
;
1260 if ((dev
->wiphy
.available_antennas_tx
||
1261 dev
->wiphy
.available_antennas_rx
) &&
1262 dev
->ops
->get_antenna
) {
1263 u32 tx_ant
= 0, rx_ant
= 0;
1265 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1267 if (nla_put_u32(msg
,
1268 NL80211_ATTR_WIPHY_ANTENNA_TX
,
1271 NL80211_ATTR_WIPHY_ANTENNA_RX
,
1273 goto nla_put_failure
;
1277 state
->split_start
++;
1281 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1282 dev
->wiphy
.interface_modes
))
1283 goto nla_put_failure
;
1284 state
->split_start
++;
1288 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1290 goto nla_put_failure
;
1292 for (band
= state
->band_start
;
1293 band
< IEEE80211_NUM_BANDS
; band
++) {
1294 struct ieee80211_supported_band
*sband
;
1296 sband
= dev
->wiphy
.bands
[band
];
1301 nl_band
= nla_nest_start(msg
, band
);
1303 goto nla_put_failure
;
1305 switch (state
->chan_start
) {
1307 if (nl80211_send_band_rateinfo(msg
, sband
))
1308 goto nla_put_failure
;
1309 state
->chan_start
++;
1313 /* add frequencies */
1314 nl_freqs
= nla_nest_start(
1315 msg
, NL80211_BAND_ATTR_FREQS
);
1317 goto nla_put_failure
;
1319 for (i
= state
->chan_start
- 1;
1320 i
< sband
->n_channels
;
1322 nl_freq
= nla_nest_start(msg
, i
);
1324 goto nla_put_failure
;
1326 chan
= &sband
->channels
[i
];
1328 if (nl80211_msg_put_channel(
1331 goto nla_put_failure
;
1333 nla_nest_end(msg
, nl_freq
);
1337 if (i
< sband
->n_channels
)
1338 state
->chan_start
= i
+ 2;
1340 state
->chan_start
= 0;
1341 nla_nest_end(msg
, nl_freqs
);
1344 nla_nest_end(msg
, nl_band
);
1347 /* start again here */
1348 if (state
->chan_start
)
1353 nla_nest_end(msg
, nl_bands
);
1355 if (band
< IEEE80211_NUM_BANDS
)
1356 state
->band_start
= band
+ 1;
1358 state
->band_start
= 0;
1360 /* if bands & channels are done, continue outside */
1361 if (state
->band_start
== 0 && state
->chan_start
== 0)
1362 state
->split_start
++;
1366 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1368 goto nla_put_failure
;
1371 #define CMD(op, n) \
1373 if (dev->ops->op) { \
1375 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1376 goto nla_put_failure; \
1380 CMD(add_virtual_intf
, NEW_INTERFACE
);
1381 CMD(change_virtual_intf
, SET_INTERFACE
);
1382 CMD(add_key
, NEW_KEY
);
1383 CMD(start_ap
, START_AP
);
1384 CMD(add_station
, NEW_STATION
);
1385 CMD(add_mpath
, NEW_MPATH
);
1386 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1387 CMD(change_bss
, SET_BSS
);
1388 CMD(auth
, AUTHENTICATE
);
1389 CMD(assoc
, ASSOCIATE
);
1390 CMD(deauth
, DEAUTHENTICATE
);
1391 CMD(disassoc
, DISASSOCIATE
);
1392 CMD(join_ibss
, JOIN_IBSS
);
1393 CMD(join_mesh
, JOIN_MESH
);
1394 CMD(set_pmksa
, SET_PMKSA
);
1395 CMD(del_pmksa
, DEL_PMKSA
);
1396 CMD(flush_pmksa
, FLUSH_PMKSA
);
1397 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1398 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1399 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1400 CMD(mgmt_tx
, FRAME
);
1401 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1402 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1404 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1405 goto nla_put_failure
;
1407 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1408 dev
->ops
->join_mesh
) {
1410 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1411 goto nla_put_failure
;
1413 CMD(set_wds_peer
, SET_WDS_PEER
);
1414 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1415 CMD(tdls_mgmt
, TDLS_MGMT
);
1416 CMD(tdls_oper
, TDLS_OPER
);
1418 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1419 CMD(sched_scan_start
, START_SCHED_SCAN
);
1420 CMD(probe_client
, PROBE_CLIENT
);
1421 CMD(set_noack_map
, SET_NOACK_MAP
);
1422 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1424 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1425 goto nla_put_failure
;
1427 CMD(start_p2p_device
, START_P2P_DEVICE
);
1428 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1430 CMD(crit_proto_start
, CRIT_PROTOCOL_START
);
1431 CMD(crit_proto_stop
, CRIT_PROTOCOL_STOP
);
1432 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
)
1433 CMD(channel_switch
, CHANNEL_SWITCH
);
1436 #ifdef CONFIG_NL80211_TESTMODE
1437 CMD(testmode_cmd
, TESTMODE
);
1442 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1444 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1445 goto nla_put_failure
;
1448 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1450 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1451 goto nla_put_failure
;
1454 nla_nest_end(msg
, nl_cmds
);
1455 state
->split_start
++;
1459 if (dev
->ops
->remain_on_channel
&&
1460 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1462 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1463 dev
->wiphy
.max_remain_on_channel_duration
))
1464 goto nla_put_failure
;
1466 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1467 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1468 goto nla_put_failure
;
1470 if (nl80211_send_mgmt_stypes(msg
, mgmt_stypes
))
1471 goto nla_put_failure
;
1472 state
->split_start
++;
1477 if (nl80211_send_wowlan(msg
, dev
, state
->split
))
1478 goto nla_put_failure
;
1479 state
->split_start
++;
1483 state
->split_start
++;
1486 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1487 dev
->wiphy
.software_iftypes
))
1488 goto nla_put_failure
;
1490 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
,
1492 goto nla_put_failure
;
1494 state
->split_start
++;
1498 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1499 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1500 dev
->wiphy
.ap_sme_capa
))
1501 goto nla_put_failure
;
1503 features
= dev
->wiphy
.features
;
1505 * We can only add the per-channel limit information if the
1506 * dump is split, otherwise it makes it too big. Therefore
1507 * only advertise it in that case.
1510 features
|= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS
;
1511 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
, features
))
1512 goto nla_put_failure
;
1514 if (dev
->wiphy
.ht_capa_mod_mask
&&
1515 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1516 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1517 dev
->wiphy
.ht_capa_mod_mask
))
1518 goto nla_put_failure
;
1520 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1521 dev
->wiphy
.max_acl_mac_addrs
&&
1522 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1523 dev
->wiphy
.max_acl_mac_addrs
))
1524 goto nla_put_failure
;
1527 * Any information below this point is only available to
1528 * applications that can deal with it being split. This
1529 * helps ensure that newly added capabilities don't break
1530 * older tools by overrunning their buffers.
1532 * We still increment split_start so that in the split
1533 * case we'll continue with more data in the next round,
1534 * but break unconditionally so unsplit data stops here.
1536 state
->split_start
++;
1539 if (dev
->wiphy
.extended_capabilities
&&
1540 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1541 dev
->wiphy
.extended_capabilities_len
,
1542 dev
->wiphy
.extended_capabilities
) ||
1543 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1544 dev
->wiphy
.extended_capabilities_len
,
1545 dev
->wiphy
.extended_capabilities_mask
)))
1546 goto nla_put_failure
;
1548 if (dev
->wiphy
.vht_capa_mod_mask
&&
1549 nla_put(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
,
1550 sizeof(*dev
->wiphy
.vht_capa_mod_mask
),
1551 dev
->wiphy
.vht_capa_mod_mask
))
1552 goto nla_put_failure
;
1554 state
->split_start
++;
1557 if (nl80211_send_coalesce(msg
, dev
))
1558 goto nla_put_failure
;
1561 state
->split_start
= 0;
1564 return genlmsg_end(msg
, hdr
);
1567 genlmsg_cancel(msg
, hdr
);
1571 static int nl80211_dump_wiphy_parse(struct sk_buff
*skb
,
1572 struct netlink_callback
*cb
,
1573 struct nl80211_dump_wiphy_state
*state
)
1575 struct nlattr
**tb
= nl80211_fam
.attrbuf
;
1576 int ret
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1577 tb
, nl80211_fam
.maxattr
, nl80211_policy
);
1578 /* ignore parse errors for backward compatibility */
1582 state
->split
= tb
[NL80211_ATTR_SPLIT_WIPHY_DUMP
];
1583 if (tb
[NL80211_ATTR_WIPHY
])
1584 state
->filter_wiphy
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
1585 if (tb
[NL80211_ATTR_WDEV
])
1586 state
->filter_wiphy
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]) >> 32;
1587 if (tb
[NL80211_ATTR_IFINDEX
]) {
1588 struct net_device
*netdev
;
1589 struct cfg80211_registered_device
*rdev
;
1590 int ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
1592 netdev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1595 if (netdev
->ieee80211_ptr
) {
1596 rdev
= wiphy_to_dev(
1597 netdev
->ieee80211_ptr
->wiphy
);
1598 state
->filter_wiphy
= rdev
->wiphy_idx
;
1606 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1609 struct nl80211_dump_wiphy_state
*state
= (void *)cb
->args
[0];
1610 struct cfg80211_registered_device
*dev
;
1614 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
1619 state
->filter_wiphy
= -1;
1620 ret
= nl80211_dump_wiphy_parse(skb
, cb
, state
);
1626 cb
->args
[0] = (long)state
;
1629 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1630 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1632 if (++idx
<= state
->start
)
1634 if (state
->filter_wiphy
!= -1 &&
1635 state
->filter_wiphy
!= dev
->wiphy_idx
)
1637 /* attempt to fit multiple wiphy data chunks into the skb */
1639 ret
= nl80211_send_wiphy(dev
, skb
,
1640 NETLINK_CB(cb
->skb
).portid
,
1642 NLM_F_MULTI
, state
);
1645 * If sending the wiphy data didn't fit (ENOBUFS
1646 * or EMSGSIZE returned), this SKB is still
1647 * empty (so it's not too big because another
1648 * wiphy dataset is already in the skb) and
1649 * we've not tried to adjust the dump allocation
1650 * yet ... then adjust the alloc size to be
1651 * bigger, and return 1 but with the empty skb.
1652 * This results in an empty message being RX'ed
1653 * in userspace, but that is ignored.
1655 * We can then retry with the larger buffer.
1657 if ((ret
== -ENOBUFS
|| ret
== -EMSGSIZE
) &&
1659 cb
->min_dump_alloc
< 4096) {
1660 cb
->min_dump_alloc
= 4096;
1667 } while (state
->split_start
> 0);
1677 static int nl80211_dump_wiphy_done(struct netlink_callback
*cb
)
1679 kfree((void *)cb
->args
[0]);
1683 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1685 struct sk_buff
*msg
;
1686 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1687 struct nl80211_dump_wiphy_state state
= {};
1689 msg
= nlmsg_new(4096, GFP_KERNEL
);
1693 if (nl80211_send_wiphy(dev
, msg
, info
->snd_portid
, info
->snd_seq
, 0,
1699 return genlmsg_reply(msg
, info
);
1702 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1703 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1704 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1705 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1706 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1707 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1710 static int parse_txq_params(struct nlattr
*tb
[],
1711 struct ieee80211_txq_params
*txq_params
)
1713 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1714 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1715 !tb
[NL80211_TXQ_ATTR_AIFS
])
1718 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1719 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1720 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1721 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1722 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1724 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1730 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1733 * You can only set the channel explicitly for WDS interfaces,
1734 * all others have their channel managed via their respective
1735 * "establish a connection" command (connect, join, ...)
1737 * For AP/GO and mesh mode, the channel can be set with the
1738 * channel userspace API, but is only stored and passed to the
1739 * low-level driver when the AP starts or the mesh is joined.
1740 * This is for backward compatibility, userspace can also give
1741 * the channel in the start-ap or join-mesh commands instead.
1743 * Monitors are special as they are normally slaved to
1744 * whatever else is going on, so they have their own special
1745 * operation to set the monitor channel if possible.
1748 wdev
->iftype
== NL80211_IFTYPE_AP
||
1749 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1750 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1751 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1754 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1755 struct genl_info
*info
,
1756 struct cfg80211_chan_def
*chandef
)
1760 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1763 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1765 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1766 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1767 chandef
->center_freq1
= control_freq
;
1768 chandef
->center_freq2
= 0;
1770 /* Primary channel not allowed */
1771 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1774 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1775 enum nl80211_channel_type chantype
;
1777 chantype
= nla_get_u32(
1778 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1781 case NL80211_CHAN_NO_HT
:
1782 case NL80211_CHAN_HT20
:
1783 case NL80211_CHAN_HT40PLUS
:
1784 case NL80211_CHAN_HT40MINUS
:
1785 cfg80211_chandef_create(chandef
, chandef
->chan
,
1791 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1793 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1794 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1795 chandef
->center_freq1
=
1797 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1798 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1799 chandef
->center_freq2
=
1801 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1804 if (!cfg80211_chandef_valid(chandef
))
1807 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1808 IEEE80211_CHAN_DISABLED
))
1811 if ((chandef
->width
== NL80211_CHAN_WIDTH_5
||
1812 chandef
->width
== NL80211_CHAN_WIDTH_10
) &&
1813 !(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_5_10_MHZ
))
1819 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1820 struct wireless_dev
*wdev
,
1821 struct genl_info
*info
)
1823 struct cfg80211_chan_def chandef
;
1825 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1828 iftype
= wdev
->iftype
;
1830 if (!nl80211_can_set_dev_channel(wdev
))
1833 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1838 case NL80211_IFTYPE_AP
:
1839 case NL80211_IFTYPE_P2P_GO
:
1840 if (wdev
->beacon_interval
) {
1844 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1848 wdev
->preset_chandef
= chandef
;
1851 case NL80211_IFTYPE_MESH_POINT
:
1852 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1854 case NL80211_IFTYPE_MONITOR
:
1855 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1864 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1866 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1867 struct net_device
*netdev
= info
->user_ptr
[1];
1869 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1872 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1874 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1875 struct net_device
*dev
= info
->user_ptr
[1];
1876 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1879 if (!info
->attrs
[NL80211_ATTR_MAC
])
1882 if (netif_running(dev
))
1885 if (!rdev
->ops
->set_wds_peer
)
1888 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1891 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1892 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1896 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1898 struct cfg80211_registered_device
*rdev
;
1899 struct net_device
*netdev
= NULL
;
1900 struct wireless_dev
*wdev
;
1901 int result
= 0, rem_txq_params
= 0;
1902 struct nlattr
*nl_txq_params
;
1904 u8 retry_short
= 0, retry_long
= 0;
1905 u32 frag_threshold
= 0, rts_threshold
= 0;
1906 u8 coverage_class
= 0;
1911 * Try to find the wiphy and netdev. Normally this
1912 * function shouldn't need the netdev, but this is
1913 * done for backward compatibility -- previously
1914 * setting the channel was done per wiphy, but now
1915 * it is per netdev. Previous userland like hostapd
1916 * also passed a netdev to set_wiphy, so that it is
1917 * possible to let that go to the right netdev!
1920 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1921 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1923 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1924 if (netdev
&& netdev
->ieee80211_ptr
)
1925 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1931 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1934 return PTR_ERR(rdev
);
1939 wdev
= netdev
->ieee80211_ptr
;
1942 * end workaround code, by now the rdev is available
1943 * and locked, and wdev may or may not be NULL.
1946 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1947 result
= cfg80211_dev_rename(
1948 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1953 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1954 struct ieee80211_txq_params txq_params
;
1955 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1957 if (!rdev
->ops
->set_txq_params
) {
1958 result
= -EOPNOTSUPP
;
1967 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1968 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1973 if (!netif_running(netdev
)) {
1978 nla_for_each_nested(nl_txq_params
,
1979 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1981 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1982 nla_data(nl_txq_params
),
1983 nla_len(nl_txq_params
),
1985 result
= parse_txq_params(tb
, &txq_params
);
1989 result
= rdev_set_txq_params(rdev
, netdev
,
1996 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1997 result
= __nl80211_set_channel(rdev
,
1998 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
2004 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
2005 struct wireless_dev
*txp_wdev
= wdev
;
2006 enum nl80211_tx_power_setting type
;
2009 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
2012 if (!rdev
->ops
->set_tx_power
) {
2013 result
= -EOPNOTSUPP
;
2017 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
2018 type
= nla_get_u32(info
->attrs
[idx
]);
2020 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
2021 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
2026 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
2027 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
2028 mbm
= nla_get_u32(info
->attrs
[idx
]);
2031 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
2036 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
2037 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
2039 if ((!rdev
->wiphy
.available_antennas_tx
&&
2040 !rdev
->wiphy
.available_antennas_rx
) ||
2041 !rdev
->ops
->set_antenna
) {
2042 result
= -EOPNOTSUPP
;
2046 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
2047 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
2049 /* reject antenna configurations which don't match the
2050 * available antenna masks, except for the "all" mask */
2051 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
2052 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
2057 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
2058 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
2060 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
2067 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
2068 retry_short
= nla_get_u8(
2069 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
2070 if (retry_short
== 0) {
2074 changed
|= WIPHY_PARAM_RETRY_SHORT
;
2077 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
2078 retry_long
= nla_get_u8(
2079 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
2080 if (retry_long
== 0) {
2084 changed
|= WIPHY_PARAM_RETRY_LONG
;
2087 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
2088 frag_threshold
= nla_get_u32(
2089 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
2090 if (frag_threshold
< 256) {
2094 if (frag_threshold
!= (u32
) -1) {
2096 * Fragments (apart from the last one) are required to
2097 * have even length. Make the fragmentation code
2098 * simpler by stripping LSB should someone try to use
2099 * odd threshold value.
2101 frag_threshold
&= ~0x1;
2103 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
2106 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
2107 rts_threshold
= nla_get_u32(
2108 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
2109 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
2112 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
2113 coverage_class
= nla_get_u8(
2114 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
2115 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
2119 u8 old_retry_short
, old_retry_long
;
2120 u32 old_frag_threshold
, old_rts_threshold
;
2121 u8 old_coverage_class
;
2123 if (!rdev
->ops
->set_wiphy_params
) {
2124 result
= -EOPNOTSUPP
;
2128 old_retry_short
= rdev
->wiphy
.retry_short
;
2129 old_retry_long
= rdev
->wiphy
.retry_long
;
2130 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
2131 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
2132 old_coverage_class
= rdev
->wiphy
.coverage_class
;
2134 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
2135 rdev
->wiphy
.retry_short
= retry_short
;
2136 if (changed
& WIPHY_PARAM_RETRY_LONG
)
2137 rdev
->wiphy
.retry_long
= retry_long
;
2138 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
2139 rdev
->wiphy
.frag_threshold
= frag_threshold
;
2140 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
2141 rdev
->wiphy
.rts_threshold
= rts_threshold
;
2142 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
2143 rdev
->wiphy
.coverage_class
= coverage_class
;
2145 result
= rdev_set_wiphy_params(rdev
, changed
);
2147 rdev
->wiphy
.retry_short
= old_retry_short
;
2148 rdev
->wiphy
.retry_long
= old_retry_long
;
2149 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
2150 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
2151 rdev
->wiphy
.coverage_class
= old_coverage_class
;
2161 static inline u64
wdev_id(struct wireless_dev
*wdev
)
2163 return (u64
)wdev
->identifier
|
2164 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
2167 static int nl80211_send_chandef(struct sk_buff
*msg
,
2168 struct cfg80211_chan_def
*chandef
)
2170 WARN_ON(!cfg80211_chandef_valid(chandef
));
2172 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
2173 chandef
->chan
->center_freq
))
2175 switch (chandef
->width
) {
2176 case NL80211_CHAN_WIDTH_20_NOHT
:
2177 case NL80211_CHAN_WIDTH_20
:
2178 case NL80211_CHAN_WIDTH_40
:
2179 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
2180 cfg80211_get_chandef_type(chandef
)))
2186 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
2188 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
2190 if (chandef
->center_freq2
&&
2191 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
2196 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
2197 struct cfg80211_registered_device
*rdev
,
2198 struct wireless_dev
*wdev
)
2200 struct net_device
*dev
= wdev
->netdev
;
2203 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
2208 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2209 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
2210 goto nla_put_failure
;
2212 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
2213 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
2214 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
2215 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
2216 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
2217 rdev
->devlist_generation
^
2218 (cfg80211_rdev_list_generation
<< 2)))
2219 goto nla_put_failure
;
2221 if (rdev
->ops
->get_channel
) {
2223 struct cfg80211_chan_def chandef
;
2225 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
2227 if (nl80211_send_chandef(msg
, &chandef
))
2228 goto nla_put_failure
;
2232 if (wdev
->ssid_len
) {
2233 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
2234 goto nla_put_failure
;
2237 return genlmsg_end(msg
, hdr
);
2240 genlmsg_cancel(msg
, hdr
);
2244 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2248 int wp_start
= cb
->args
[0];
2249 int if_start
= cb
->args
[1];
2250 struct cfg80211_registered_device
*rdev
;
2251 struct wireless_dev
*wdev
;
2254 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
2255 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
2257 if (wp_idx
< wp_start
) {
2263 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2264 if (if_idx
< if_start
) {
2268 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
2269 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2281 cb
->args
[0] = wp_idx
;
2282 cb
->args
[1] = if_idx
;
2287 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2289 struct sk_buff
*msg
;
2290 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2291 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2293 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2297 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2303 return genlmsg_reply(msg
, info
);
2306 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2307 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2308 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2309 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2310 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2311 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2312 [NL80211_MNTR_FLAG_ACTIVE
] = { .type
= NLA_FLAG
},
2315 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2317 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2325 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2326 nla
, mntr_flags_policy
))
2329 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2331 *mntrflags
|= (1<<flag
);
2336 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2337 struct net_device
*netdev
, u8 use_4addr
,
2338 enum nl80211_iftype iftype
)
2341 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2347 case NL80211_IFTYPE_AP_VLAN
:
2348 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2351 case NL80211_IFTYPE_STATION
:
2352 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2362 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2364 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2365 struct vif_params params
;
2367 enum nl80211_iftype otype
, ntype
;
2368 struct net_device
*dev
= info
->user_ptr
[1];
2369 u32 _flags
, *flags
= NULL
;
2370 bool change
= false;
2372 memset(¶ms
, 0, sizeof(params
));
2374 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2376 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2377 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2380 if (ntype
> NL80211_IFTYPE_MAX
)
2384 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2385 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2387 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2389 if (netif_running(dev
))
2393 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2394 IEEE80211_MAX_MESH_ID_LEN
);
2395 wdev
->mesh_id_up_len
=
2396 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2397 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2398 wdev
->mesh_id_up_len
);
2402 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2403 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2405 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2409 params
.use_4addr
= -1;
2412 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2413 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2415 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2424 if (flags
&& (*flags
& MONITOR_FLAG_ACTIVE
) &&
2425 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2429 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2433 if (!err
&& params
.use_4addr
!= -1)
2434 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2439 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2441 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2442 struct vif_params params
;
2443 struct wireless_dev
*wdev
;
2444 struct sk_buff
*msg
;
2446 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2449 memset(¶ms
, 0, sizeof(params
));
2451 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2454 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2455 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2456 if (type
> NL80211_IFTYPE_MAX
)
2460 if (!rdev
->ops
->add_virtual_intf
||
2461 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2464 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2465 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2467 if (!is_valid_ether_addr(params
.macaddr
))
2468 return -EADDRNOTAVAIL
;
2471 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2472 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2473 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2478 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2482 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2483 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2486 if (!err
&& (flags
& MONITOR_FLAG_ACTIVE
) &&
2487 !(rdev
->wiphy
.features
& NL80211_FEATURE_ACTIVE_MONITOR
))
2490 wdev
= rdev_add_virtual_intf(rdev
,
2491 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2492 type
, err
? NULL
: &flags
, ¶ms
);
2495 return PTR_ERR(wdev
);
2499 case NL80211_IFTYPE_MESH_POINT
:
2500 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2503 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2504 IEEE80211_MAX_MESH_ID_LEN
);
2505 wdev
->mesh_id_up_len
=
2506 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2507 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2508 wdev
->mesh_id_up_len
);
2511 case NL80211_IFTYPE_P2P_DEVICE
:
2513 * P2P Device doesn't have a netdev, so doesn't go
2514 * through the netdev notifier and must be added here
2516 mutex_init(&wdev
->mtx
);
2517 INIT_LIST_HEAD(&wdev
->event_list
);
2518 spin_lock_init(&wdev
->event_lock
);
2519 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2520 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2522 wdev
->identifier
= ++rdev
->wdev_id
;
2523 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2524 rdev
->devlist_generation
++;
2530 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2536 return genlmsg_reply(msg
, info
);
2539 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2541 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2542 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2544 if (!rdev
->ops
->del_virtual_intf
)
2548 * If we remove a wireless device without a netdev then clear
2549 * user_ptr[1] so that nl80211_post_doit won't dereference it
2550 * to check if it needs to do dev_put(). Otherwise it crashes
2551 * since the wdev has been freed, unlike with a netdev where
2552 * we need the dev_put() for the netdev to really be freed.
2555 info
->user_ptr
[1] = NULL
;
2557 return rdev_del_virtual_intf(rdev
, wdev
);
2560 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2562 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2563 struct net_device
*dev
= info
->user_ptr
[1];
2566 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2569 if (!rdev
->ops
->set_noack_map
)
2572 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2574 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2577 struct get_key_cookie
{
2578 struct sk_buff
*msg
;
2583 static void get_key_callback(void *c
, struct key_params
*params
)
2586 struct get_key_cookie
*cookie
= c
;
2589 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2590 params
->key_len
, params
->key
)) ||
2592 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2593 params
->seq_len
, params
->seq
)) ||
2595 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2597 goto nla_put_failure
;
2599 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2601 goto nla_put_failure
;
2604 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2605 params
->key_len
, params
->key
)) ||
2607 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2608 params
->seq_len
, params
->seq
)) ||
2610 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2612 goto nla_put_failure
;
2614 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2615 goto nla_put_failure
;
2617 nla_nest_end(cookie
->msg
, key
);
2624 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2626 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2628 struct net_device
*dev
= info
->user_ptr
[1];
2630 const u8
*mac_addr
= NULL
;
2632 struct get_key_cookie cookie
= {
2636 struct sk_buff
*msg
;
2638 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2639 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2644 if (info
->attrs
[NL80211_ATTR_MAC
])
2645 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2647 pairwise
= !!mac_addr
;
2648 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2649 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2650 if (kt
>= NUM_NL80211_KEYTYPES
)
2652 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2653 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2655 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2658 if (!rdev
->ops
->get_key
)
2661 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2665 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2666 NL80211_CMD_NEW_KEY
);
2671 cookie
.idx
= key_idx
;
2673 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2674 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2675 goto nla_put_failure
;
2677 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2678 goto nla_put_failure
;
2680 if (pairwise
&& mac_addr
&&
2681 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2684 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2691 goto nla_put_failure
;
2693 genlmsg_end(msg
, hdr
);
2694 return genlmsg_reply(msg
, info
);
2703 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2705 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2706 struct key_parse key
;
2708 struct net_device
*dev
= info
->user_ptr
[1];
2710 err
= nl80211_parse_key(info
, &key
);
2717 /* only support setting default key */
2718 if (!key
.def
&& !key
.defmgmt
)
2721 wdev_lock(dev
->ieee80211_ptr
);
2724 if (!rdev
->ops
->set_default_key
) {
2729 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2733 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2734 key
.def_uni
, key
.def_multi
);
2739 #ifdef CONFIG_CFG80211_WEXT
2740 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2743 if (key
.def_uni
|| !key
.def_multi
) {
2748 if (!rdev
->ops
->set_default_mgmt_key
) {
2753 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2757 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2761 #ifdef CONFIG_CFG80211_WEXT
2762 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2767 wdev_unlock(dev
->ieee80211_ptr
);
2772 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2774 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2776 struct net_device
*dev
= info
->user_ptr
[1];
2777 struct key_parse key
;
2778 const u8
*mac_addr
= NULL
;
2780 err
= nl80211_parse_key(info
, &key
);
2787 if (info
->attrs
[NL80211_ATTR_MAC
])
2788 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2790 if (key
.type
== -1) {
2792 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2794 key
.type
= NL80211_KEYTYPE_GROUP
;
2798 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2799 key
.type
!= NL80211_KEYTYPE_GROUP
)
2802 if (!rdev
->ops
->add_key
)
2805 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2806 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2810 wdev_lock(dev
->ieee80211_ptr
);
2811 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2813 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2814 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2816 wdev_unlock(dev
->ieee80211_ptr
);
2821 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2823 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2825 struct net_device
*dev
= info
->user_ptr
[1];
2826 u8
*mac_addr
= NULL
;
2827 struct key_parse key
;
2829 err
= nl80211_parse_key(info
, &key
);
2833 if (info
->attrs
[NL80211_ATTR_MAC
])
2834 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2836 if (key
.type
== -1) {
2838 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2840 key
.type
= NL80211_KEYTYPE_GROUP
;
2844 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2845 key
.type
!= NL80211_KEYTYPE_GROUP
)
2848 if (!rdev
->ops
->del_key
)
2851 wdev_lock(dev
->ieee80211_ptr
);
2852 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2854 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2855 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2859 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2860 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2863 #ifdef CONFIG_CFG80211_WEXT
2865 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2866 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2867 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2868 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2871 wdev_unlock(dev
->ieee80211_ptr
);
2876 /* This function returns an error or the number of nested attributes */
2877 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2879 struct nlattr
*attr
;
2880 int n_entries
= 0, tmp
;
2882 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2883 if (nla_len(attr
) != ETH_ALEN
)
2893 * This function parses ACL information and allocates memory for ACL data.
2894 * On successful return, the calling function is responsible to free the
2895 * ACL buffer returned by this function.
2897 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2898 struct genl_info
*info
)
2900 enum nl80211_acl_policy acl_policy
;
2901 struct nlattr
*attr
;
2902 struct cfg80211_acl_data
*acl
;
2903 int i
= 0, n_entries
, tmp
;
2905 if (!wiphy
->max_acl_mac_addrs
)
2906 return ERR_PTR(-EOPNOTSUPP
);
2908 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2909 return ERR_PTR(-EINVAL
);
2911 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2912 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2913 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2914 return ERR_PTR(-EINVAL
);
2916 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2917 return ERR_PTR(-EINVAL
);
2919 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2921 return ERR_PTR(n_entries
);
2923 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2924 return ERR_PTR(-ENOTSUPP
);
2926 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2929 return ERR_PTR(-ENOMEM
);
2931 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2932 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2936 acl
->n_acl_entries
= n_entries
;
2937 acl
->acl_policy
= acl_policy
;
2942 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2944 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2945 struct net_device
*dev
= info
->user_ptr
[1];
2946 struct cfg80211_acl_data
*acl
;
2949 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2950 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2953 if (!dev
->ieee80211_ptr
->beacon_interval
)
2956 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2958 return PTR_ERR(acl
);
2960 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2967 static int nl80211_parse_beacon(struct nlattr
*attrs
[],
2968 struct cfg80211_beacon_data
*bcn
)
2970 bool haveinfo
= false;
2972 if (!is_valid_ie_attr(attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2973 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE
]) ||
2974 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2975 !is_valid_ie_attr(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2978 memset(bcn
, 0, sizeof(*bcn
));
2980 if (attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2981 bcn
->head
= nla_data(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2982 bcn
->head_len
= nla_len(attrs
[NL80211_ATTR_BEACON_HEAD
]);
2988 if (attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2989 bcn
->tail
= nla_data(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2990 bcn
->tail_len
= nla_len(attrs
[NL80211_ATTR_BEACON_TAIL
]);
2997 if (attrs
[NL80211_ATTR_IE
]) {
2998 bcn
->beacon_ies
= nla_data(attrs
[NL80211_ATTR_IE
]);
2999 bcn
->beacon_ies_len
= nla_len(attrs
[NL80211_ATTR_IE
]);
3002 if (attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
3003 bcn
->proberesp_ies
=
3004 nla_data(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3005 bcn
->proberesp_ies_len
=
3006 nla_len(attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
3009 if (attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
3010 bcn
->assocresp_ies
=
3011 nla_data(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3012 bcn
->assocresp_ies_len
=
3013 nla_len(attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
3016 if (attrs
[NL80211_ATTR_PROBE_RESP
]) {
3017 bcn
->probe_resp
= nla_data(attrs
[NL80211_ATTR_PROBE_RESP
]);
3018 bcn
->probe_resp_len
= nla_len(attrs
[NL80211_ATTR_PROBE_RESP
]);
3024 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
3025 struct cfg80211_ap_settings
*params
)
3027 struct wireless_dev
*wdev
;
3030 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
3031 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
3032 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3035 if (!wdev
->preset_chandef
.chan
)
3038 params
->chandef
= wdev
->preset_chandef
;
3046 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
3047 enum nl80211_auth_type auth_type
,
3048 enum nl80211_commands cmd
)
3050 if (auth_type
> NL80211_AUTHTYPE_MAX
)
3054 case NL80211_CMD_AUTHENTICATE
:
3055 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
3056 auth_type
== NL80211_AUTHTYPE_SAE
)
3059 case NL80211_CMD_CONNECT
:
3060 case NL80211_CMD_START_AP
:
3061 /* SAE not supported yet */
3062 if (auth_type
== NL80211_AUTHTYPE_SAE
)
3070 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3072 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3073 struct net_device
*dev
= info
->user_ptr
[1];
3074 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3075 struct cfg80211_ap_settings params
;
3077 u8 radar_detect_width
= 0;
3079 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3080 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3083 if (!rdev
->ops
->start_ap
)
3086 if (wdev
->beacon_interval
)
3089 memset(¶ms
, 0, sizeof(params
));
3091 /* these are required for START_AP */
3092 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
3093 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
3094 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
3097 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon
);
3101 params
.beacon_interval
=
3102 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3103 params
.dtim_period
=
3104 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
3106 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
3111 * In theory, some of these attributes should be required here
3112 * but since they were not used when the command was originally
3113 * added, keep them optional for old user space programs to let
3114 * them continue to work with drivers that do not need the
3115 * additional information -- drivers must check!
3117 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3118 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3120 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3121 if (params
.ssid_len
== 0 ||
3122 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
3126 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
3127 params
.hidden_ssid
= nla_get_u32(
3128 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
3129 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
3130 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
3131 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
3135 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3137 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3138 params
.auth_type
= nla_get_u32(
3139 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3140 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
3141 NL80211_CMD_START_AP
))
3144 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3146 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
3147 NL80211_MAX_NR_CIPHER_SUITES
);
3151 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
3152 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
3154 params
.inactivity_timeout
= nla_get_u16(
3155 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
3158 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
3159 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3161 params
.p2p_ctwindow
=
3162 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
3163 if (params
.p2p_ctwindow
> 127)
3165 if (params
.p2p_ctwindow
!= 0 &&
3166 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
3170 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
3173 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3175 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
3178 params
.p2p_opp_ps
= tmp
;
3179 if (params
.p2p_opp_ps
!= 0 &&
3180 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
3184 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3185 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
3188 } else if (wdev
->preset_chandef
.chan
) {
3189 params
.chandef
= wdev
->preset_chandef
;
3190 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
3193 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
3196 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
3200 radar_detect_width
= BIT(params
.chandef
.width
);
3201 params
.radar_required
= true;
3204 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
3205 params
.chandef
.chan
,
3207 radar_detect_width
);
3211 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
3212 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
3213 if (IS_ERR(params
.acl
))
3214 return PTR_ERR(params
.acl
);
3217 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
3219 wdev
->preset_chandef
= params
.chandef
;
3220 wdev
->beacon_interval
= params
.beacon_interval
;
3221 wdev
->channel
= params
.chandef
.chan
;
3222 wdev
->ssid_len
= params
.ssid_len
;
3223 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
3231 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
3233 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3234 struct net_device
*dev
= info
->user_ptr
[1];
3235 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3236 struct cfg80211_beacon_data params
;
3239 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3240 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3243 if (!rdev
->ops
->change_beacon
)
3246 if (!wdev
->beacon_interval
)
3249 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
);
3253 return rdev_change_beacon(rdev
, dev
, ¶ms
);
3256 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
3258 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3259 struct net_device
*dev
= info
->user_ptr
[1];
3261 return cfg80211_stop_ap(rdev
, dev
);
3264 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
3265 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3266 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3267 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3268 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3269 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3270 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3273 static int parse_station_flags(struct genl_info
*info
,
3274 enum nl80211_iftype iftype
,
3275 struct station_parameters
*params
)
3277 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3282 * Try parsing the new attribute first so userspace
3283 * can specify both for older kernels.
3285 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3287 struct nl80211_sta_flag_update
*sta_flags
;
3289 sta_flags
= nla_data(nla
);
3290 params
->sta_flags_mask
= sta_flags
->mask
;
3291 params
->sta_flags_set
= sta_flags
->set
;
3292 params
->sta_flags_set
&= params
->sta_flags_mask
;
3293 if ((params
->sta_flags_mask
|
3294 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3299 /* if present, parse the old attribute */
3301 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3305 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3306 nla
, sta_flags_policy
))
3310 * Only allow certain flags for interface types so that
3311 * other attributes are silently ignored. Remember that
3312 * this is backward compatibility code with old userspace
3313 * and shouldn't be hit in other cases anyway.
3316 case NL80211_IFTYPE_AP
:
3317 case NL80211_IFTYPE_AP_VLAN
:
3318 case NL80211_IFTYPE_P2P_GO
:
3319 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3320 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3321 BIT(NL80211_STA_FLAG_WME
) |
3322 BIT(NL80211_STA_FLAG_MFP
);
3324 case NL80211_IFTYPE_P2P_CLIENT
:
3325 case NL80211_IFTYPE_STATION
:
3326 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3327 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3329 case NL80211_IFTYPE_MESH_POINT
:
3330 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3331 BIT(NL80211_STA_FLAG_MFP
) |
3332 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3337 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3339 params
->sta_flags_set
|= (1<<flag
);
3341 /* no longer support new API additions in old API */
3342 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3350 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3353 struct nlattr
*rate
;
3357 rate
= nla_nest_start(msg
, attr
);
3361 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3362 bitrate
= cfg80211_calculate_bitrate(info
);
3363 /* report 16-bit bitrate only if we can */
3364 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3366 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3368 if (bitrate_compat
> 0 &&
3369 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3372 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3373 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3375 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3376 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3378 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3379 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3381 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3382 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3384 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3386 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3387 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3389 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3390 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3392 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3393 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3395 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3396 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3398 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3399 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3403 nla_nest_end(msg
, rate
);
3407 static bool nl80211_put_signal(struct sk_buff
*msg
, u8 mask
, s8
*signal
,
3416 attr
= nla_nest_start(msg
, id
);
3420 for (i
= 0; i
< IEEE80211_MAX_CHAINS
; i
++) {
3421 if (!(mask
& BIT(i
)))
3424 if (nla_put_u8(msg
, i
, signal
[i
]))
3428 nla_nest_end(msg
, attr
);
3433 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3435 struct cfg80211_registered_device
*rdev
,
3436 struct net_device
*dev
,
3437 const u8
*mac_addr
, struct station_info
*sinfo
)
3440 struct nlattr
*sinfoattr
, *bss_param
;
3442 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3446 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3447 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3448 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3449 goto nla_put_failure
;
3451 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3453 goto nla_put_failure
;
3454 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3455 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3456 sinfo
->connected_time
))
3457 goto nla_put_failure
;
3458 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3459 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3460 sinfo
->inactive_time
))
3461 goto nla_put_failure
;
3462 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3463 STATION_INFO_RX_BYTES64
)) &&
3464 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3465 (u32
)sinfo
->rx_bytes
))
3466 goto nla_put_failure
;
3467 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3468 STATION_INFO_TX_BYTES64
)) &&
3469 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3470 (u32
)sinfo
->tx_bytes
))
3471 goto nla_put_failure
;
3472 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3473 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3475 goto nla_put_failure
;
3476 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3477 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3479 goto nla_put_failure
;
3480 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3481 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3482 goto nla_put_failure
;
3483 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3484 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3485 goto nla_put_failure
;
3486 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3487 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3488 sinfo
->plink_state
))
3489 goto nla_put_failure
;
3490 switch (rdev
->wiphy
.signal_type
) {
3491 case CFG80211_SIGNAL_TYPE_MBM
:
3492 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3493 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3495 goto nla_put_failure
;
3496 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3497 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3499 goto nla_put_failure
;
3504 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL
) {
3505 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3506 sinfo
->chain_signal
,
3507 NL80211_STA_INFO_CHAIN_SIGNAL
))
3508 goto nla_put_failure
;
3510 if (sinfo
->filled
& STATION_INFO_CHAIN_SIGNAL_AVG
) {
3511 if (!nl80211_put_signal(msg
, sinfo
->chains
,
3512 sinfo
->chain_signal_avg
,
3513 NL80211_STA_INFO_CHAIN_SIGNAL_AVG
))
3514 goto nla_put_failure
;
3516 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3517 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3518 NL80211_STA_INFO_TX_BITRATE
))
3519 goto nla_put_failure
;
3521 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3522 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3523 NL80211_STA_INFO_RX_BITRATE
))
3524 goto nla_put_failure
;
3526 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3527 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3529 goto nla_put_failure
;
3530 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3531 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3533 goto nla_put_failure
;
3534 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3535 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3537 goto nla_put_failure
;
3538 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3539 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3541 goto nla_put_failure
;
3542 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3543 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3544 sinfo
->beacon_loss_count
))
3545 goto nla_put_failure
;
3546 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3547 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3549 goto nla_put_failure
;
3550 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3551 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3553 goto nla_put_failure
;
3554 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3555 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3557 goto nla_put_failure
;
3558 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3559 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3561 goto nla_put_failure
;
3563 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3564 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3565 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3566 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3567 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3568 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3569 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3570 sinfo
->bss_param
.dtim_period
) ||
3571 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3572 sinfo
->bss_param
.beacon_interval
))
3573 goto nla_put_failure
;
3575 nla_nest_end(msg
, bss_param
);
3577 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3578 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3579 sizeof(struct nl80211_sta_flag_update
),
3581 goto nla_put_failure
;
3582 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3583 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3585 goto nla_put_failure
;
3586 nla_nest_end(msg
, sinfoattr
);
3588 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3589 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3590 sinfo
->assoc_req_ies
))
3591 goto nla_put_failure
;
3593 return genlmsg_end(msg
, hdr
);
3596 genlmsg_cancel(msg
, hdr
);
3600 static int nl80211_dump_station(struct sk_buff
*skb
,
3601 struct netlink_callback
*cb
)
3603 struct station_info sinfo
;
3604 struct cfg80211_registered_device
*dev
;
3605 struct wireless_dev
*wdev
;
3606 u8 mac_addr
[ETH_ALEN
];
3607 int sta_idx
= cb
->args
[2];
3610 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
3614 if (!wdev
->netdev
) {
3619 if (!dev
->ops
->dump_station
) {
3625 memset(&sinfo
, 0, sizeof(sinfo
));
3626 err
= rdev_dump_station(dev
, wdev
->netdev
, sta_idx
,
3633 if (nl80211_send_station(skb
,
3634 NETLINK_CB(cb
->skb
).portid
,
3635 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3636 dev
, wdev
->netdev
, mac_addr
,
3645 cb
->args
[2] = sta_idx
;
3648 nl80211_finish_wdev_dump(dev
);
3653 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3655 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3656 struct net_device
*dev
= info
->user_ptr
[1];
3657 struct station_info sinfo
;
3658 struct sk_buff
*msg
;
3659 u8
*mac_addr
= NULL
;
3662 memset(&sinfo
, 0, sizeof(sinfo
));
3664 if (!info
->attrs
[NL80211_ATTR_MAC
])
3667 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3669 if (!rdev
->ops
->get_station
)
3672 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3676 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3680 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3681 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3686 return genlmsg_reply(msg
, info
);
3689 int cfg80211_check_station_change(struct wiphy
*wiphy
,
3690 struct station_parameters
*params
,
3691 enum cfg80211_station_type statype
)
3693 if (params
->listen_interval
!= -1)
3698 /* When you run into this, adjust the code below for the new flag */
3699 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
3702 case CFG80211_STA_MESH_PEER_KERNEL
:
3703 case CFG80211_STA_MESH_PEER_USER
:
3705 * No ignoring the TDLS flag here -- the userspace mesh
3706 * code doesn't have the bug of including TDLS in the
3709 if (params
->sta_flags_mask
&
3710 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3711 BIT(NL80211_STA_FLAG_MFP
) |
3712 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3715 case CFG80211_STA_TDLS_PEER_SETUP
:
3716 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3717 if (!(params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3719 /* ignore since it can't change */
3720 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3723 /* disallow mesh-specific things */
3724 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3726 if (params
->local_pm
)
3728 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3732 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
&&
3733 statype
!= CFG80211_STA_TDLS_PEER_ACTIVE
) {
3734 /* TDLS can't be set, ... */
3735 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3738 * ... but don't bother the driver with it. This works around
3739 * a hostapd/wpa_supplicant issue -- it always includes the
3740 * TLDS_PEER flag in the mask even for AP mode.
3742 params
->sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3745 if (statype
!= CFG80211_STA_TDLS_PEER_SETUP
) {
3746 /* reject other things that can't change */
3747 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_UAPSD
)
3749 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_CAPABILITY
)
3751 if (params
->supported_rates
)
3753 if (params
->ext_capab
|| params
->ht_capa
|| params
->vht_capa
)
3757 if (statype
!= CFG80211_STA_AP_CLIENT
) {
3763 case CFG80211_STA_AP_MLME_CLIENT
:
3764 /* Use this only for authorizing/unauthorizing a station */
3765 if (!(params
->sta_flags_mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3768 case CFG80211_STA_AP_CLIENT
:
3769 /* accept only the listed bits */
3770 if (params
->sta_flags_mask
&
3771 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3772 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3773 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3774 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3775 BIT(NL80211_STA_FLAG_WME
) |
3776 BIT(NL80211_STA_FLAG_MFP
)))
3779 /* but authenticated/associated only if driver handles it */
3780 if (!(wiphy
->features
& NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3781 params
->sta_flags_mask
&
3782 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3783 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3786 case CFG80211_STA_IBSS
:
3787 case CFG80211_STA_AP_STA
:
3788 /* reject any changes other than AUTHORIZED */
3789 if (params
->sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3792 case CFG80211_STA_TDLS_PEER_SETUP
:
3793 /* reject any changes other than AUTHORIZED or WME */
3794 if (params
->sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3795 BIT(NL80211_STA_FLAG_WME
)))
3797 /* force (at least) rates when authorizing */
3798 if (params
->sta_flags_set
& BIT(NL80211_STA_FLAG_AUTHORIZED
) &&
3799 !params
->supported_rates
)
3802 case CFG80211_STA_TDLS_PEER_ACTIVE
:
3803 /* reject any changes */
3805 case CFG80211_STA_MESH_PEER_KERNEL
:
3806 if (params
->sta_modify_mask
& STATION_PARAM_APPLY_PLINK_STATE
)
3809 case CFG80211_STA_MESH_PEER_USER
:
3810 if (params
->plink_action
!= NL80211_PLINK_ACTION_NO_ACTION
)
3817 EXPORT_SYMBOL(cfg80211_check_station_change
);
3820 * Get vlan interface making sure it is running and on the right wiphy.
3822 static struct net_device
*get_vlan(struct genl_info
*info
,
3823 struct cfg80211_registered_device
*rdev
)
3825 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3826 struct net_device
*v
;
3832 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3834 return ERR_PTR(-ENODEV
);
3836 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3841 if (v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3842 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3843 v
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
3848 if (!netif_running(v
)) {
3856 return ERR_PTR(ret
);
3859 static struct nla_policy
3860 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3861 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3862 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3865 static int nl80211_parse_sta_wme(struct genl_info
*info
,
3866 struct station_parameters
*params
)
3868 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3872 /* parse WME attributes if present */
3873 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3876 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3877 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3878 nl80211_sta_wme_policy
);
3882 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3883 params
->uapsd_queues
= nla_get_u8(
3884 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3885 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3888 if (tb
[NL80211_STA_WME_MAX_SP
])
3889 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3891 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3894 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3899 static int nl80211_set_station_tdls(struct genl_info
*info
,
3900 struct station_parameters
*params
)
3902 /* Dummy STA entry gets updated once the peer capabilities are known */
3903 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
3904 params
->aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
3905 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3907 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3908 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3910 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3912 return nl80211_parse_sta_wme(info
, params
);
3915 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3917 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3918 struct net_device
*dev
= info
->user_ptr
[1];
3919 struct station_parameters params
;
3923 memset(¶ms
, 0, sizeof(params
));
3925 params
.listen_interval
= -1;
3927 if (!rdev
->ops
->change_station
)
3930 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3933 if (!info
->attrs
[NL80211_ATTR_MAC
])
3936 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3938 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3939 params
.supported_rates
=
3940 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3941 params
.supported_rates_len
=
3942 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3945 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3947 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3948 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3951 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3953 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3954 params
.ext_capab_len
=
3955 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3958 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3961 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3964 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
3965 params
.plink_action
=
3966 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3967 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
3971 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]) {
3972 params
.plink_state
=
3973 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3974 if (params
.plink_state
>= NUM_NL80211_PLINK_STATES
)
3976 params
.sta_modify_mask
|= STATION_PARAM_APPLY_PLINK_STATE
;
3979 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3980 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3981 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3983 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3984 pm
> NL80211_MESH_POWER_MAX
)
3987 params
.local_pm
= pm
;
3990 /* Include parameters for TDLS peer (will check later) */
3991 err
= nl80211_set_station_tdls(info
, ¶ms
);
3995 params
.vlan
= get_vlan(info
, rdev
);
3996 if (IS_ERR(params
.vlan
))
3997 return PTR_ERR(params
.vlan
);
3999 switch (dev
->ieee80211_ptr
->iftype
) {
4000 case NL80211_IFTYPE_AP
:
4001 case NL80211_IFTYPE_AP_VLAN
:
4002 case NL80211_IFTYPE_P2P_GO
:
4003 case NL80211_IFTYPE_P2P_CLIENT
:
4004 case NL80211_IFTYPE_STATION
:
4005 case NL80211_IFTYPE_ADHOC
:
4006 case NL80211_IFTYPE_MESH_POINT
:
4013 /* driver will call cfg80211_check_station_change() */
4014 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
4018 dev_put(params
.vlan
);
4023 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
4025 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4027 struct net_device
*dev
= info
->user_ptr
[1];
4028 struct station_parameters params
;
4029 u8
*mac_addr
= NULL
;
4031 memset(¶ms
, 0, sizeof(params
));
4033 if (!rdev
->ops
->add_station
)
4036 if (!info
->attrs
[NL80211_ATTR_MAC
])
4039 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
4042 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
4045 if (!info
->attrs
[NL80211_ATTR_STA_AID
] &&
4046 !info
->attrs
[NL80211_ATTR_PEER_AID
])
4049 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4050 params
.supported_rates
=
4051 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4052 params
.supported_rates_len
=
4053 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
4054 params
.listen_interval
=
4055 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
4057 if (info
->attrs
[NL80211_ATTR_PEER_AID
])
4058 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_PEER_AID
]);
4060 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
4061 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
4064 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
4066 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
4067 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
4070 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
4072 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4073 params
.ext_capab_len
=
4074 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
4077 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
4079 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4081 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
4083 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
4085 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]) {
4086 params
.plink_action
=
4087 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
4088 if (params
.plink_action
>= NUM_NL80211_PLINK_ACTIONS
)
4092 err
= nl80211_parse_sta_wme(info
, ¶ms
);
4096 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
4099 /* When you run into this, adjust the code below for the new flag */
4100 BUILD_BUG_ON(NL80211_STA_FLAG_MAX
!= 7);
4102 switch (dev
->ieee80211_ptr
->iftype
) {
4103 case NL80211_IFTYPE_AP
:
4104 case NL80211_IFTYPE_AP_VLAN
:
4105 case NL80211_IFTYPE_P2P_GO
:
4106 /* ignore WME attributes if iface/sta is not capable */
4107 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) ||
4108 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)))
4109 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4111 /* TDLS peers cannot be added */
4112 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4113 info
->attrs
[NL80211_ATTR_PEER_AID
])
4115 /* but don't bother the driver with it */
4116 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
4118 /* allow authenticated/associated only if driver handles it */
4119 if (!(rdev
->wiphy
.features
&
4120 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
4121 params
.sta_flags_mask
&
4122 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
4123 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
4126 /* must be last in here for error handling */
4127 params
.vlan
= get_vlan(info
, rdev
);
4128 if (IS_ERR(params
.vlan
))
4129 return PTR_ERR(params
.vlan
);
4131 case NL80211_IFTYPE_MESH_POINT
:
4132 /* ignore uAPSD data */
4133 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4135 /* associated is disallowed */
4136 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
4138 /* TDLS peers cannot be added */
4139 if ((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) ||
4140 info
->attrs
[NL80211_ATTR_PEER_AID
])
4143 case NL80211_IFTYPE_STATION
:
4144 case NL80211_IFTYPE_P2P_CLIENT
:
4145 /* ignore uAPSD data */
4146 params
.sta_modify_mask
&= ~STATION_PARAM_APPLY_UAPSD
;
4148 /* these are disallowed */
4149 if (params
.sta_flags_mask
&
4150 (BIT(NL80211_STA_FLAG_ASSOCIATED
) |
4151 BIT(NL80211_STA_FLAG_AUTHENTICATED
)))
4153 /* Only TDLS peers can be added */
4154 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
4156 /* Can only add if TDLS ... */
4157 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
4159 /* ... with external setup is supported */
4160 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
4163 * Older wpa_supplicant versions always mark the TDLS peer
4164 * as authorized, but it shouldn't yet be.
4166 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_AUTHORIZED
);
4172 /* be aware of params.vlan when changing code here */
4174 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
4177 dev_put(params
.vlan
);
4181 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
4183 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4184 struct net_device
*dev
= info
->user_ptr
[1];
4185 u8
*mac_addr
= NULL
;
4187 if (info
->attrs
[NL80211_ATTR_MAC
])
4188 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4190 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4191 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4192 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4193 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4196 if (!rdev
->ops
->del_station
)
4199 return rdev_del_station(rdev
, dev
, mac_addr
);
4202 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4203 int flags
, struct net_device
*dev
,
4204 u8
*dst
, u8
*next_hop
,
4205 struct mpath_info
*pinfo
)
4208 struct nlattr
*pinfoattr
;
4210 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
4214 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4215 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
4216 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
4217 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
4218 goto nla_put_failure
;
4220 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
4222 goto nla_put_failure
;
4223 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
4224 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
4226 goto nla_put_failure
;
4227 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
4228 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
4229 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
4230 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
4232 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
4233 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
4235 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
4236 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
4238 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
4239 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
4240 pinfo
->discovery_timeout
)) ||
4241 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
4242 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
4243 pinfo
->discovery_retries
)))
4244 goto nla_put_failure
;
4246 nla_nest_end(msg
, pinfoattr
);
4248 return genlmsg_end(msg
, hdr
);
4251 genlmsg_cancel(msg
, hdr
);
4255 static int nl80211_dump_mpath(struct sk_buff
*skb
,
4256 struct netlink_callback
*cb
)
4258 struct mpath_info pinfo
;
4259 struct cfg80211_registered_device
*dev
;
4260 struct wireless_dev
*wdev
;
4262 u8 next_hop
[ETH_ALEN
];
4263 int path_idx
= cb
->args
[2];
4266 err
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
4270 if (!dev
->ops
->dump_mpath
) {
4275 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
4281 err
= rdev_dump_mpath(dev
, wdev
->netdev
, path_idx
, dst
,
4288 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
4289 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4290 wdev
->netdev
, dst
, next_hop
,
4299 cb
->args
[2] = path_idx
;
4302 nl80211_finish_wdev_dump(dev
);
4306 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4310 struct net_device
*dev
= info
->user_ptr
[1];
4311 struct mpath_info pinfo
;
4312 struct sk_buff
*msg
;
4314 u8 next_hop
[ETH_ALEN
];
4316 memset(&pinfo
, 0, sizeof(pinfo
));
4318 if (!info
->attrs
[NL80211_ATTR_MAC
])
4321 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4323 if (!rdev
->ops
->get_mpath
)
4326 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4329 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
4333 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4337 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4338 dev
, dst
, next_hop
, &pinfo
) < 0) {
4343 return genlmsg_reply(msg
, info
);
4346 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4348 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4349 struct net_device
*dev
= info
->user_ptr
[1];
4351 u8
*next_hop
= NULL
;
4353 if (!info
->attrs
[NL80211_ATTR_MAC
])
4356 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4359 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4360 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4362 if (!rdev
->ops
->change_mpath
)
4365 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4368 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
4371 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4373 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4374 struct net_device
*dev
= info
->user_ptr
[1];
4376 u8
*next_hop
= NULL
;
4378 if (!info
->attrs
[NL80211_ATTR_MAC
])
4381 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4384 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4385 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4387 if (!rdev
->ops
->add_mpath
)
4390 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4393 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4396 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4398 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4399 struct net_device
*dev
= info
->user_ptr
[1];
4402 if (info
->attrs
[NL80211_ATTR_MAC
])
4403 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4405 if (!rdev
->ops
->del_mpath
)
4408 return rdev_del_mpath(rdev
, dev
, dst
);
4411 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4413 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4414 struct net_device
*dev
= info
->user_ptr
[1];
4415 struct bss_parameters params
;
4417 memset(¶ms
, 0, sizeof(params
));
4418 /* default to not changing parameters */
4419 params
.use_cts_prot
= -1;
4420 params
.use_short_preamble
= -1;
4421 params
.use_short_slot_time
= -1;
4422 params
.ap_isolate
= -1;
4423 params
.ht_opmode
= -1;
4424 params
.p2p_ctwindow
= -1;
4425 params
.p2p_opp_ps
= -1;
4427 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4428 params
.use_cts_prot
=
4429 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4430 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4431 params
.use_short_preamble
=
4432 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4433 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4434 params
.use_short_slot_time
=
4435 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4436 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4437 params
.basic_rates
=
4438 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4439 params
.basic_rates_len
=
4440 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4442 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4443 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4444 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4446 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4448 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4449 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4451 params
.p2p_ctwindow
=
4452 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4453 if (params
.p2p_ctwindow
< 0)
4455 if (params
.p2p_ctwindow
!= 0 &&
4456 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4460 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4463 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4465 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4468 params
.p2p_opp_ps
= tmp
;
4469 if (params
.p2p_opp_ps
&&
4470 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4474 if (!rdev
->ops
->change_bss
)
4477 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4478 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4481 return rdev_change_bss(rdev
, dev
, ¶ms
);
4484 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4485 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4486 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4487 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4488 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4489 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4490 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4493 static int parse_reg_rule(struct nlattr
*tb
[],
4494 struct ieee80211_reg_rule
*reg_rule
)
4496 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4497 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4499 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4501 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4503 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4505 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4507 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4510 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4512 freq_range
->start_freq_khz
=
4513 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4514 freq_range
->end_freq_khz
=
4515 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4516 freq_range
->max_bandwidth_khz
=
4517 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4519 power_rule
->max_eirp
=
4520 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4522 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4523 power_rule
->max_antenna_gain
=
4524 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4529 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4533 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4536 * You should only get this when cfg80211 hasn't yet initialized
4537 * completely when built-in to the kernel right between the time
4538 * window between nl80211_init() and regulatory_init(), if that is
4541 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4542 return -EINPROGRESS
;
4544 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4547 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4549 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4550 user_reg_hint_type
=
4551 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4553 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4555 switch (user_reg_hint_type
) {
4556 case NL80211_USER_REG_HINT_USER
:
4557 case NL80211_USER_REG_HINT_CELL_BASE
:
4563 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4568 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4569 struct genl_info
*info
)
4571 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4572 struct net_device
*dev
= info
->user_ptr
[1];
4573 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4574 struct mesh_config cur_params
;
4577 struct nlattr
*pinfoattr
;
4578 struct sk_buff
*msg
;
4580 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4583 if (!rdev
->ops
->get_mesh_config
)
4587 /* If not connected, get default parameters */
4588 if (!wdev
->mesh_id_len
)
4589 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4591 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4597 /* Draw up a netlink message to send back */
4598 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4601 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4602 NL80211_CMD_GET_MESH_CONFIG
);
4605 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4607 goto nla_put_failure
;
4608 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4609 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4610 cur_params
.dot11MeshRetryTimeout
) ||
4611 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4612 cur_params
.dot11MeshConfirmTimeout
) ||
4613 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4614 cur_params
.dot11MeshHoldingTimeout
) ||
4615 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4616 cur_params
.dot11MeshMaxPeerLinks
) ||
4617 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4618 cur_params
.dot11MeshMaxRetries
) ||
4619 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4620 cur_params
.dot11MeshTTL
) ||
4621 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4622 cur_params
.element_ttl
) ||
4623 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4624 cur_params
.auto_open_plinks
) ||
4625 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4626 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4627 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4628 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4629 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4630 cur_params
.path_refresh_time
) ||
4631 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4632 cur_params
.min_discovery_timeout
) ||
4633 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4634 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4635 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4636 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4637 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4638 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4639 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4640 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4641 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4642 cur_params
.dot11MeshHWMPRootMode
) ||
4643 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4644 cur_params
.dot11MeshHWMPRannInterval
) ||
4645 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4646 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4647 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4648 cur_params
.dot11MeshForwarding
) ||
4649 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4650 cur_params
.rssi_threshold
) ||
4651 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4652 cur_params
.ht_opmode
) ||
4653 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4654 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4655 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4656 cur_params
.dot11MeshHWMProotInterval
) ||
4657 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4658 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4659 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4660 cur_params
.power_mode
) ||
4661 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4662 cur_params
.dot11MeshAwakeWindowDuration
) ||
4663 nla_put_u32(msg
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4664 cur_params
.plink_timeout
))
4665 goto nla_put_failure
;
4666 nla_nest_end(msg
, pinfoattr
);
4667 genlmsg_end(msg
, hdr
);
4668 return genlmsg_reply(msg
, info
);
4671 genlmsg_cancel(msg
, hdr
);
4677 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4678 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4679 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4680 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4681 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4682 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4683 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4684 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4685 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4686 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4687 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4688 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4689 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4690 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4691 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4692 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4693 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4694 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4695 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4696 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4697 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4698 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4699 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4700 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4701 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4702 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4703 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4704 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4705 [NL80211_MESHCONF_PLINK_TIMEOUT
] = { .type
= NLA_U32
},
4708 static const struct nla_policy
4709 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4710 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4711 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4712 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4713 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4714 [NL80211_MESH_SETUP_AUTH_PROTOCOL
] = { .type
= NLA_U8
},
4715 [NL80211_MESH_SETUP_USERSPACE_MPM
] = { .type
= NLA_FLAG
},
4716 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4717 .len
= IEEE80211_MAX_DATA_LEN
},
4718 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4721 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4722 struct mesh_config
*cfg
,
4725 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4728 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4731 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4733 cfg->param = fn(tb[attr]); \
4734 mask |= (1 << (attr - 1)); \
4739 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4741 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4742 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4743 nl80211_meshconf_params_policy
))
4746 /* This makes sure that there aren't more than 32 mesh config
4747 * parameters (otherwise our bitfield scheme would not work.) */
4748 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4750 /* Fill in the params struct */
4751 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4752 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4754 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4755 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4758 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4760 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4761 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4763 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4764 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4766 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4767 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4768 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4769 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4771 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4772 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4774 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4776 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4778 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4779 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4781 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4782 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4784 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4785 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4787 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4789 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4791 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4793 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4795 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4797 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4799 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4800 dot11MeshHWMPnetDiameterTraversalTime
,
4802 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4804 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4805 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4807 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4808 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4810 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4811 dot11MeshGateAnnouncementProtocol
, 0, 1,
4812 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4814 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4815 mask
, NL80211_MESHCONF_FORWARDING
,
4817 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, -255, 0,
4818 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4820 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4821 mask
, NL80211_MESHCONF_HT_OPMODE
,
4823 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4825 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4827 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4828 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4830 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4831 dot11MeshHWMPconfirmationInterval
,
4833 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4835 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4836 NL80211_MESH_POWER_ACTIVE
,
4837 NL80211_MESH_POWER_MAX
,
4838 mask
, NL80211_MESHCONF_POWER_MODE
,
4840 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4842 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4843 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, plink_timeout
, 1, 0xffffffff,
4844 mask
, NL80211_MESHCONF_PLINK_TIMEOUT
,
4851 #undef FILL_IN_MESH_PARAM_IF_SET
4854 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4855 struct mesh_setup
*setup
)
4857 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4858 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4860 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4862 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4863 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4864 nl80211_mesh_setup_params_policy
))
4867 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4868 setup
->sync_method
=
4869 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4870 IEEE80211_SYNC_METHOD_VENDOR
:
4871 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4873 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4874 setup
->path_sel_proto
=
4875 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4876 IEEE80211_PATH_PROTOCOL_VENDOR
:
4877 IEEE80211_PATH_PROTOCOL_HWMP
;
4879 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4880 setup
->path_metric
=
4881 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4882 IEEE80211_PATH_METRIC_VENDOR
:
4883 IEEE80211_PATH_METRIC_AIRTIME
;
4886 if (tb
[NL80211_MESH_SETUP_IE
]) {
4887 struct nlattr
*ieattr
=
4888 tb
[NL80211_MESH_SETUP_IE
];
4889 if (!is_valid_ie_attr(ieattr
))
4891 setup
->ie
= nla_data(ieattr
);
4892 setup
->ie_len
= nla_len(ieattr
);
4894 if (tb
[NL80211_MESH_SETUP_USERSPACE_MPM
] &&
4895 !(rdev
->wiphy
.features
& NL80211_FEATURE_USERSPACE_MPM
))
4897 setup
->user_mpm
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_MPM
]);
4898 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4899 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4900 if (setup
->is_secure
)
4901 setup
->user_mpm
= true;
4903 if (tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]) {
4904 if (!setup
->user_mpm
)
4907 nla_get_u8(tb
[NL80211_MESH_SETUP_AUTH_PROTOCOL
]);
4913 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4914 struct genl_info
*info
)
4916 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4917 struct net_device
*dev
= info
->user_ptr
[1];
4918 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4919 struct mesh_config cfg
;
4923 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4926 if (!rdev
->ops
->update_mesh_config
)
4929 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4934 if (!wdev
->mesh_id_len
)
4938 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4945 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4947 const struct ieee80211_regdomain
*regdom
;
4948 struct sk_buff
*msg
;
4950 struct nlattr
*nl_reg_rules
;
4953 if (!cfg80211_regdomain
)
4956 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4960 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4961 NL80211_CMD_GET_REG
);
4965 if (reg_last_request_cell_base() &&
4966 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4967 NL80211_USER_REG_HINT_CELL_BASE
))
4968 goto nla_put_failure
;
4971 regdom
= rcu_dereference(cfg80211_regdomain
);
4973 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4974 (regdom
->dfs_region
&&
4975 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4976 goto nla_put_failure_rcu
;
4978 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4980 goto nla_put_failure_rcu
;
4982 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4983 struct nlattr
*nl_reg_rule
;
4984 const struct ieee80211_reg_rule
*reg_rule
;
4985 const struct ieee80211_freq_range
*freq_range
;
4986 const struct ieee80211_power_rule
*power_rule
;
4988 reg_rule
= ®dom
->reg_rules
[i
];
4989 freq_range
= ®_rule
->freq_range
;
4990 power_rule
= ®_rule
->power_rule
;
4992 nl_reg_rule
= nla_nest_start(msg
, i
);
4994 goto nla_put_failure_rcu
;
4996 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4998 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4999 freq_range
->start_freq_khz
) ||
5000 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
5001 freq_range
->end_freq_khz
) ||
5002 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
5003 freq_range
->max_bandwidth_khz
) ||
5004 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
5005 power_rule
->max_antenna_gain
) ||
5006 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
5007 power_rule
->max_eirp
))
5008 goto nla_put_failure_rcu
;
5010 nla_nest_end(msg
, nl_reg_rule
);
5014 nla_nest_end(msg
, nl_reg_rules
);
5016 genlmsg_end(msg
, hdr
);
5017 return genlmsg_reply(msg
, info
);
5019 nla_put_failure_rcu
:
5022 genlmsg_cancel(msg
, hdr
);
5028 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
5030 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
5031 struct nlattr
*nl_reg_rule
;
5032 char *alpha2
= NULL
;
5033 int rem_reg_rules
= 0, r
= 0;
5034 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
5036 struct ieee80211_regdomain
*rd
= NULL
;
5038 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
5041 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
5044 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
5046 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
5047 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
5049 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5052 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
5056 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
5057 num_rules
* sizeof(struct ieee80211_reg_rule
);
5059 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
5063 rd
->n_reg_rules
= num_rules
;
5064 rd
->alpha2
[0] = alpha2
[0];
5065 rd
->alpha2
[1] = alpha2
[1];
5068 * Disable DFS master mode if the DFS region was
5069 * not supported or known on this kernel.
5071 if (reg_supported_dfs_region(dfs_region
))
5072 rd
->dfs_region
= dfs_region
;
5074 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
5076 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
5077 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
5079 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
5085 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
5092 /* set_regdom took ownership */
5100 static int validate_scan_freqs(struct nlattr
*freqs
)
5102 struct nlattr
*attr1
, *attr2
;
5103 int n_channels
= 0, tmp1
, tmp2
;
5105 nla_for_each_nested(attr1
, freqs
, tmp1
) {
5108 * Some hardware has a limited channel list for
5109 * scanning, and it is pretty much nonsensical
5110 * to scan for a channel twice, so disallow that
5111 * and don't require drivers to check that the
5112 * channel list they get isn't longer than what
5113 * they can scan, as long as they can scan all
5114 * the channels they registered at once.
5116 nla_for_each_nested(attr2
, freqs
, tmp2
)
5117 if (attr1
!= attr2
&&
5118 nla_get_u32(attr1
) == nla_get_u32(attr2
))
5125 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
5127 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5128 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5129 struct cfg80211_scan_request
*request
;
5130 struct nlattr
*attr
;
5131 struct wiphy
*wiphy
;
5132 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
5135 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5138 wiphy
= &rdev
->wiphy
;
5140 if (!rdev
->ops
->scan
)
5143 if (rdev
->scan_req
) {
5148 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5149 n_channels
= validate_scan_freqs(
5150 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5156 enum ieee80211_band band
;
5159 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5160 if (wiphy
->bands
[band
])
5161 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5164 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5165 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
5168 if (n_ssids
> wiphy
->max_scan_ssids
) {
5173 if (info
->attrs
[NL80211_ATTR_IE
])
5174 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5178 if (ie_len
> wiphy
->max_scan_ie_len
) {
5183 request
= kzalloc(sizeof(*request
)
5184 + sizeof(*request
->ssids
) * n_ssids
5185 + sizeof(*request
->channels
) * n_channels
5186 + ie_len
, GFP_KERNEL
);
5193 request
->ssids
= (void *)&request
->channels
[n_channels
];
5194 request
->n_ssids
= n_ssids
;
5197 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5199 request
->ie
= (void *)(request
->channels
+ n_channels
);
5203 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5204 /* user specified, bail out if channel not found */
5205 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
5206 struct ieee80211_channel
*chan
;
5208 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5215 /* ignore disabled channels */
5216 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5219 request
->channels
[i
] = chan
;
5223 enum ieee80211_band band
;
5226 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5228 if (!wiphy
->bands
[band
])
5230 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5231 struct ieee80211_channel
*chan
;
5233 chan
= &wiphy
->bands
[band
]->channels
[j
];
5235 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5238 request
->channels
[i
] = chan
;
5249 request
->n_channels
= i
;
5252 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5253 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
5254 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5258 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5259 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
5264 if (info
->attrs
[NL80211_ATTR_IE
]) {
5265 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5266 memcpy((void *)request
->ie
,
5267 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5271 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
5272 if (wiphy
->bands
[i
])
5274 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
5276 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
5277 nla_for_each_nested(attr
,
5278 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
5280 enum ieee80211_band band
= nla_type(attr
);
5282 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
5286 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
5289 &request
->rates
[band
]);
5295 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5296 request
->flags
= nla_get_u32(
5297 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5298 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5299 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5300 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5301 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5308 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5310 request
->wdev
= wdev
;
5311 request
->wiphy
= &rdev
->wiphy
;
5312 request
->scan_start
= jiffies
;
5314 rdev
->scan_req
= request
;
5315 err
= rdev_scan(rdev
, request
);
5318 nl80211_send_scan_start(rdev
, wdev
);
5320 dev_hold(wdev
->netdev
);
5323 rdev
->scan_req
= NULL
;
5331 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
5332 struct genl_info
*info
)
5334 struct cfg80211_sched_scan_request
*request
;
5335 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5336 struct net_device
*dev
= info
->user_ptr
[1];
5337 struct nlattr
*attr
;
5338 struct wiphy
*wiphy
;
5339 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
5341 enum ieee80211_band band
;
5343 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
5345 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5346 !rdev
->ops
->sched_scan_start
)
5349 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5352 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
5355 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
5359 wiphy
= &rdev
->wiphy
;
5361 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5362 n_channels
= validate_scan_freqs(
5363 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
5369 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
5370 if (wiphy
->bands
[band
])
5371 n_channels
+= wiphy
->bands
[band
]->n_channels
;
5374 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
5375 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5379 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
5382 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
5383 nla_for_each_nested(attr
,
5384 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5388 if (n_match_sets
> wiphy
->max_match_sets
)
5391 if (info
->attrs
[NL80211_ATTR_IE
])
5392 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5396 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5399 if (rdev
->sched_scan_req
) {
5404 request
= kzalloc(sizeof(*request
)
5405 + sizeof(*request
->ssids
) * n_ssids
5406 + sizeof(*request
->match_sets
) * n_match_sets
5407 + sizeof(*request
->channels
) * n_channels
5408 + ie_len
, GFP_KERNEL
);
5415 request
->ssids
= (void *)&request
->channels
[n_channels
];
5416 request
->n_ssids
= n_ssids
;
5419 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5421 request
->ie
= (void *)(request
->channels
+ n_channels
);
5426 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5427 else if (request
->ssids
)
5428 request
->match_sets
=
5429 (void *)(request
->ssids
+ n_ssids
);
5431 request
->match_sets
=
5432 (void *)(request
->channels
+ n_channels
);
5434 request
->n_match_sets
= n_match_sets
;
5437 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5438 /* user specified, bail out if channel not found */
5439 nla_for_each_nested(attr
,
5440 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5442 struct ieee80211_channel
*chan
;
5444 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5451 /* ignore disabled channels */
5452 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5455 request
->channels
[i
] = chan
;
5460 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5462 if (!wiphy
->bands
[band
])
5464 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5465 struct ieee80211_channel
*chan
;
5467 chan
= &wiphy
->bands
[band
]->channels
[j
];
5469 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5472 request
->channels
[i
] = chan
;
5483 request
->n_channels
= i
;
5486 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5487 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5489 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5493 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5494 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5501 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5502 nla_for_each_nested(attr
,
5503 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5505 struct nlattr
*ssid
, *rssi
;
5507 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5508 nla_data(attr
), nla_len(attr
),
5509 nl80211_match_policy
);
5510 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5512 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5516 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5517 nla_data(ssid
), nla_len(ssid
));
5518 request
->match_sets
[i
].ssid
.ssid_len
=
5521 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5523 request
->rssi_thold
= nla_get_u32(rssi
);
5525 request
->rssi_thold
=
5526 NL80211_SCAN_RSSI_THOLD_OFF
;
5531 if (info
->attrs
[NL80211_ATTR_IE
]) {
5532 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5533 memcpy((void *)request
->ie
,
5534 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5538 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5539 request
->flags
= nla_get_u32(
5540 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5541 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5542 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5543 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5544 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5551 request
->wiphy
= &rdev
->wiphy
;
5552 request
->interval
= interval
;
5553 request
->scan_start
= jiffies
;
5555 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5557 rdev
->sched_scan_req
= request
;
5558 nl80211_send_sched_scan(rdev
, dev
,
5559 NL80211_CMD_START_SCHED_SCAN
);
5569 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5570 struct genl_info
*info
)
5572 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5574 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5575 !rdev
->ops
->sched_scan_stop
)
5578 return __cfg80211_stop_sched_scan(rdev
, false);
5581 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5582 struct genl_info
*info
)
5584 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5585 struct net_device
*dev
= info
->user_ptr
[1];
5586 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5587 struct cfg80211_chan_def chandef
;
5590 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5594 if (netif_carrier_ok(dev
))
5597 if (wdev
->cac_started
)
5600 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5607 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5610 if (!rdev
->ops
->start_radar_detection
)
5613 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5614 chandef
.chan
, CHAN_MODE_SHARED
,
5615 BIT(chandef
.width
));
5619 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5621 wdev
->channel
= chandef
.chan
;
5622 wdev
->cac_started
= true;
5623 wdev
->cac_start_time
= jiffies
;
5628 static int nl80211_channel_switch(struct sk_buff
*skb
, struct genl_info
*info
)
5630 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5631 struct net_device
*dev
= info
->user_ptr
[1];
5632 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5633 struct cfg80211_csa_settings params
;
5634 /* csa_attrs is defined static to avoid waste of stack size - this
5635 * function is called under RTNL lock, so this should not be a problem.
5637 static struct nlattr
*csa_attrs
[NL80211_ATTR_MAX
+1];
5638 u8 radar_detect_width
= 0;
5640 bool need_new_beacon
= false;
5642 if (!rdev
->ops
->channel_switch
||
5643 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_CHANNEL_SWITCH
))
5646 switch (dev
->ieee80211_ptr
->iftype
) {
5647 case NL80211_IFTYPE_AP
:
5648 case NL80211_IFTYPE_P2P_GO
:
5649 need_new_beacon
= true;
5651 /* useless if AP is not running */
5652 if (!wdev
->beacon_interval
)
5655 case NL80211_IFTYPE_ADHOC
:
5661 memset(¶ms
, 0, sizeof(params
));
5663 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5664 !info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
])
5667 /* only important for AP, IBSS and mesh create IEs internally */
5668 if (need_new_beacon
&&
5669 (!info
->attrs
[NL80211_ATTR_CSA_IES
] ||
5670 !info
->attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]))
5673 params
.count
= nla_get_u32(info
->attrs
[NL80211_ATTR_CH_SWITCH_COUNT
]);
5675 if (!need_new_beacon
)
5678 err
= nl80211_parse_beacon(info
->attrs
, ¶ms
.beacon_after
);
5682 err
= nla_parse_nested(csa_attrs
, NL80211_ATTR_MAX
,
5683 info
->attrs
[NL80211_ATTR_CSA_IES
],
5688 err
= nl80211_parse_beacon(csa_attrs
, ¶ms
.beacon_csa
);
5692 if (!csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
])
5695 params
.counter_offset_beacon
=
5696 nla_get_u16(csa_attrs
[NL80211_ATTR_CSA_C_OFF_BEACON
]);
5697 if (params
.counter_offset_beacon
>= params
.beacon_csa
.tail_len
)
5700 /* sanity check - counters should be the same */
5701 if (params
.beacon_csa
.tail
[params
.counter_offset_beacon
] !=
5705 if (csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]) {
5706 params
.counter_offset_presp
=
5707 nla_get_u16(csa_attrs
[NL80211_ATTR_CSA_C_OFF_PRESP
]);
5708 if (params
.counter_offset_presp
>=
5709 params
.beacon_csa
.probe_resp_len
)
5712 if (params
.beacon_csa
.probe_resp
[params
.counter_offset_presp
] !=
5718 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
5722 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
5725 /* DFS channels are only supported for AP/P2P GO ... for now. */
5726 if (dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_AP
||
5727 dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_P2P_GO
) {
5728 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
,
5733 radar_detect_width
= BIT(params
.chandef
.width
);
5734 params
.radar_required
= true;
5738 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5739 params
.chandef
.chan
,
5741 radar_detect_width
);
5745 if (info
->attrs
[NL80211_ATTR_CH_SWITCH_BLOCK_TX
])
5746 params
.block_tx
= true;
5748 return rdev_channel_switch(rdev
, dev
, ¶ms
);
5751 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5753 struct cfg80211_registered_device
*rdev
,
5754 struct wireless_dev
*wdev
,
5755 struct cfg80211_internal_bss
*intbss
)
5757 struct cfg80211_bss
*res
= &intbss
->pub
;
5758 const struct cfg80211_bss_ies
*ies
;
5763 ASSERT_WDEV_LOCK(wdev
);
5765 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5766 NL80211_CMD_NEW_SCAN_RESULTS
);
5770 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5772 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
))
5773 goto nla_put_failure
;
5775 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5776 goto nla_put_failure
;
5777 if (nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
5778 goto nla_put_failure
;
5780 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5782 goto nla_put_failure
;
5783 if ((!is_zero_ether_addr(res
->bssid
) &&
5784 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5785 goto nla_put_failure
;
5788 ies
= rcu_dereference(res
->ies
);
5790 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5791 goto fail_unlock_rcu
;
5793 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5794 ies
->len
, ies
->data
))
5795 goto fail_unlock_rcu
;
5797 ies
= rcu_dereference(res
->beacon_ies
);
5799 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5800 goto fail_unlock_rcu
;
5801 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5802 ies
->len
, ies
->data
))
5803 goto fail_unlock_rcu
;
5807 if (res
->beacon_interval
&&
5808 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5809 goto nla_put_failure
;
5810 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5811 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5812 nla_put_u32(msg
, NL80211_BSS_CHAN_WIDTH
, res
->scan_width
) ||
5813 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5814 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5815 goto nla_put_failure
;
5817 switch (rdev
->wiphy
.signal_type
) {
5818 case CFG80211_SIGNAL_TYPE_MBM
:
5819 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5820 goto nla_put_failure
;
5822 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5823 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5824 goto nla_put_failure
;
5830 switch (wdev
->iftype
) {
5831 case NL80211_IFTYPE_P2P_CLIENT
:
5832 case NL80211_IFTYPE_STATION
:
5833 if (intbss
== wdev
->current_bss
&&
5834 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5835 NL80211_BSS_STATUS_ASSOCIATED
))
5836 goto nla_put_failure
;
5838 case NL80211_IFTYPE_ADHOC
:
5839 if (intbss
== wdev
->current_bss
&&
5840 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5841 NL80211_BSS_STATUS_IBSS_JOINED
))
5842 goto nla_put_failure
;
5848 nla_nest_end(msg
, bss
);
5850 return genlmsg_end(msg
, hdr
);
5855 genlmsg_cancel(msg
, hdr
);
5859 static int nl80211_dump_scan(struct sk_buff
*skb
, struct netlink_callback
*cb
)
5861 struct cfg80211_registered_device
*rdev
;
5862 struct cfg80211_internal_bss
*scan
;
5863 struct wireless_dev
*wdev
;
5864 int start
= cb
->args
[2], idx
= 0;
5867 err
= nl80211_prepare_wdev_dump(skb
, cb
, &rdev
, &wdev
);
5872 spin_lock_bh(&rdev
->bss_lock
);
5873 cfg80211_bss_expire(rdev
);
5875 cb
->seq
= rdev
->bss_generation
;
5877 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5880 if (nl80211_send_bss(skb
, cb
,
5881 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5882 rdev
, wdev
, scan
) < 0) {
5888 spin_unlock_bh(&rdev
->bss_lock
);
5892 nl80211_finish_wdev_dump(rdev
);
5897 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5898 int flags
, struct net_device
*dev
,
5899 struct survey_info
*survey
)
5902 struct nlattr
*infoattr
;
5904 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5905 NL80211_CMD_NEW_SURVEY_RESULTS
);
5909 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5910 goto nla_put_failure
;
5912 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5914 goto nla_put_failure
;
5916 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5917 survey
->channel
->center_freq
))
5918 goto nla_put_failure
;
5920 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5921 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5922 goto nla_put_failure
;
5923 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5924 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5925 goto nla_put_failure
;
5926 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5927 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5928 survey
->channel_time
))
5929 goto nla_put_failure
;
5930 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5931 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5932 survey
->channel_time_busy
))
5933 goto nla_put_failure
;
5934 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5935 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5936 survey
->channel_time_ext_busy
))
5937 goto nla_put_failure
;
5938 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5939 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5940 survey
->channel_time_rx
))
5941 goto nla_put_failure
;
5942 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5943 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5944 survey
->channel_time_tx
))
5945 goto nla_put_failure
;
5947 nla_nest_end(msg
, infoattr
);
5949 return genlmsg_end(msg
, hdr
);
5952 genlmsg_cancel(msg
, hdr
);
5956 static int nl80211_dump_survey(struct sk_buff
*skb
,
5957 struct netlink_callback
*cb
)
5959 struct survey_info survey
;
5960 struct cfg80211_registered_device
*dev
;
5961 struct wireless_dev
*wdev
;
5962 int survey_idx
= cb
->args
[2];
5965 res
= nl80211_prepare_wdev_dump(skb
, cb
, &dev
, &wdev
);
5969 if (!wdev
->netdev
) {
5974 if (!dev
->ops
->dump_survey
) {
5980 struct ieee80211_channel
*chan
;
5982 res
= rdev_dump_survey(dev
, wdev
->netdev
, survey_idx
, &survey
);
5988 /* Survey without a channel doesn't make sense */
5989 if (!survey
.channel
) {
5994 chan
= ieee80211_get_channel(&dev
->wiphy
,
5995 survey
.channel
->center_freq
);
5996 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
6001 if (nl80211_send_survey(skb
,
6002 NETLINK_CB(cb
->skb
).portid
,
6003 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6004 wdev
->netdev
, &survey
) < 0)
6010 cb
->args
[2] = survey_idx
;
6013 nl80211_finish_wdev_dump(dev
);
6017 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
6019 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
6020 NL80211_WPA_VERSION_2
));
6023 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6025 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6026 struct net_device
*dev
= info
->user_ptr
[1];
6027 struct ieee80211_channel
*chan
;
6028 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
6029 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
6030 enum nl80211_auth_type auth_type
;
6031 struct key_parse key
;
6032 bool local_state_change
;
6034 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6037 if (!info
->attrs
[NL80211_ATTR_MAC
])
6040 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
6043 if (!info
->attrs
[NL80211_ATTR_SSID
])
6046 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6049 err
= nl80211_parse_key(info
, &key
);
6054 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
6056 if (!key
.p
.key
|| !key
.p
.key_len
)
6058 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
6059 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
6060 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
6061 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
6073 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
6074 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
6083 if (!rdev
->ops
->auth
)
6086 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6087 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6090 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6091 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6092 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6093 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6096 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6097 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6099 if (info
->attrs
[NL80211_ATTR_IE
]) {
6100 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6101 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6104 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6105 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
6108 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
6109 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
6112 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
6113 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
6115 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
6116 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
6117 /* need to include at least Auth Transaction and Status Code */
6118 if (sae_data_len
< 4)
6122 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6125 * Since we no longer track auth state, ignore
6126 * requests to only change local state.
6128 if (local_state_change
)
6131 wdev_lock(dev
->ieee80211_ptr
);
6132 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
6133 ssid
, ssid_len
, ie
, ie_len
,
6134 key
.p
.key
, key
.p
.key_len
, key
.idx
,
6135 sae_data
, sae_data_len
);
6136 wdev_unlock(dev
->ieee80211_ptr
);
6140 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
6141 struct genl_info
*info
,
6142 struct cfg80211_crypto_settings
*settings
,
6145 memset(settings
, 0, sizeof(*settings
));
6147 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
6149 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
6151 proto
= nla_get_u16(
6152 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
6153 settings
->control_port_ethertype
= cpu_to_be16(proto
);
6154 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
6157 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
6158 settings
->control_port_no_encrypt
= true;
6160 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
6162 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
6166 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6167 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
6168 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
6170 if (len
% sizeof(u32
))
6173 if (settings
->n_ciphers_pairwise
> cipher_limit
)
6176 memcpy(settings
->ciphers_pairwise
, data
, len
);
6178 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
6179 if (!cfg80211_supported_cipher_suite(
6181 settings
->ciphers_pairwise
[i
]))
6185 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
6186 settings
->cipher_group
=
6187 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
6188 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
6189 settings
->cipher_group
))
6193 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
6194 settings
->wpa_versions
=
6195 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
6196 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
6200 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
6204 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6205 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
6206 settings
->n_akm_suites
= len
/ sizeof(u32
);
6208 if (len
% sizeof(u32
))
6211 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
6214 memcpy(settings
->akm_suites
, data
, len
);
6220 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
6222 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6223 struct net_device
*dev
= info
->user_ptr
[1];
6224 struct ieee80211_channel
*chan
;
6225 struct cfg80211_assoc_request req
= {};
6226 const u8
*bssid
, *ssid
;
6227 int err
, ssid_len
= 0;
6229 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6232 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
6233 !info
->attrs
[NL80211_ATTR_SSID
] ||
6234 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6237 if (!rdev
->ops
->assoc
)
6240 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6241 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6244 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6246 chan
= ieee80211_get_channel(&rdev
->wiphy
,
6247 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6248 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
6251 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6252 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6254 if (info
->attrs
[NL80211_ATTR_IE
]) {
6255 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6256 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6259 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6260 enum nl80211_mfp mfp
=
6261 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6262 if (mfp
== NL80211_MFP_REQUIRED
)
6264 else if (mfp
!= NL80211_MFP_NO
)
6268 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
6269 req
.prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
6271 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6272 req
.flags
|= ASSOC_REQ_DISABLE_HT
;
6274 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6275 memcpy(&req
.ht_capa_mask
,
6276 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6277 sizeof(req
.ht_capa_mask
));
6279 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6280 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6282 memcpy(&req
.ht_capa
,
6283 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6284 sizeof(req
.ht_capa
));
6287 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6288 req
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6290 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6291 memcpy(&req
.vht_capa_mask
,
6292 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6293 sizeof(req
.vht_capa_mask
));
6295 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6296 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6298 memcpy(&req
.vht_capa
,
6299 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6300 sizeof(req
.vht_capa
));
6303 err
= nl80211_crypto_settings(rdev
, info
, &req
.crypto
, 1);
6305 wdev_lock(dev
->ieee80211_ptr
);
6306 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
,
6307 ssid
, ssid_len
, &req
);
6308 wdev_unlock(dev
->ieee80211_ptr
);
6314 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
6316 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6317 struct net_device
*dev
= info
->user_ptr
[1];
6318 const u8
*ie
= NULL
, *bssid
;
6319 int ie_len
= 0, err
;
6321 bool local_state_change
;
6323 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6326 if (!info
->attrs
[NL80211_ATTR_MAC
])
6329 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6332 if (!rdev
->ops
->deauth
)
6335 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6336 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6339 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6341 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6342 if (reason_code
== 0) {
6343 /* Reason Code 0 is reserved */
6347 if (info
->attrs
[NL80211_ATTR_IE
]) {
6348 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6349 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6352 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6354 wdev_lock(dev
->ieee80211_ptr
);
6355 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6356 local_state_change
);
6357 wdev_unlock(dev
->ieee80211_ptr
);
6361 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
6363 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6364 struct net_device
*dev
= info
->user_ptr
[1];
6365 const u8
*ie
= NULL
, *bssid
;
6366 int ie_len
= 0, err
;
6368 bool local_state_change
;
6370 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6373 if (!info
->attrs
[NL80211_ATTR_MAC
])
6376 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6379 if (!rdev
->ops
->disassoc
)
6382 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6383 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6386 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6388 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6389 if (reason_code
== 0) {
6390 /* Reason Code 0 is reserved */
6394 if (info
->attrs
[NL80211_ATTR_IE
]) {
6395 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6396 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6399 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
6401 wdev_lock(dev
->ieee80211_ptr
);
6402 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
6403 local_state_change
);
6404 wdev_unlock(dev
->ieee80211_ptr
);
6409 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
6410 int mcast_rate
[IEEE80211_NUM_BANDS
],
6413 struct wiphy
*wiphy
= &rdev
->wiphy
;
6417 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
6418 struct ieee80211_supported_band
*sband
;
6420 sband
= wiphy
->bands
[band
];
6424 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
6425 if (sband
->bitrates
[i
].bitrate
== rateval
) {
6426 mcast_rate
[band
] = i
+ 1;
6436 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6438 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6439 struct net_device
*dev
= info
->user_ptr
[1];
6440 struct cfg80211_ibss_params ibss
;
6441 struct wiphy
*wiphy
;
6442 struct cfg80211_cached_keys
*connkeys
= NULL
;
6445 memset(&ibss
, 0, sizeof(ibss
));
6447 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6450 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6451 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6454 ibss
.beacon_interval
= 100;
6456 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
6457 ibss
.beacon_interval
=
6458 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
6459 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
6463 if (!rdev
->ops
->join_ibss
)
6466 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6469 wiphy
= &rdev
->wiphy
;
6471 if (info
->attrs
[NL80211_ATTR_MAC
]) {
6472 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6474 if (!is_valid_ether_addr(ibss
.bssid
))
6477 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6478 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6480 if (info
->attrs
[NL80211_ATTR_IE
]) {
6481 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6482 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6485 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
6489 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
6492 switch (ibss
.chandef
.width
) {
6493 case NL80211_CHAN_WIDTH_5
:
6494 case NL80211_CHAN_WIDTH_10
:
6495 case NL80211_CHAN_WIDTH_20_NOHT
:
6497 case NL80211_CHAN_WIDTH_20
:
6498 case NL80211_CHAN_WIDTH_40
:
6499 if (rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
)
6505 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
6506 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
6508 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
6510 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6512 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
6513 struct ieee80211_supported_band
*sband
=
6514 wiphy
->bands
[ibss
.chandef
.chan
->band
];
6516 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
6522 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6523 memcpy(&ibss
.ht_capa_mask
,
6524 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6525 sizeof(ibss
.ht_capa_mask
));
6527 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6528 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6530 memcpy(&ibss
.ht_capa
,
6531 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6532 sizeof(ibss
.ht_capa
));
6535 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6536 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
6537 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6540 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6543 connkeys
= nl80211_parse_connkeys(rdev
,
6544 info
->attrs
[NL80211_ATTR_KEYS
],
6546 if (IS_ERR(connkeys
))
6547 return PTR_ERR(connkeys
);
6549 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6557 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6559 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6565 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6567 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6568 struct net_device
*dev
= info
->user_ptr
[1];
6570 if (!rdev
->ops
->leave_ibss
)
6573 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6576 return cfg80211_leave_ibss(rdev
, dev
, false);
6579 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6581 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6582 struct net_device
*dev
= info
->user_ptr
[1];
6583 int mcast_rate
[IEEE80211_NUM_BANDS
];
6587 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6588 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6591 if (!rdev
->ops
->set_mcast_rate
)
6594 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6596 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6599 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6600 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6603 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6609 #ifdef CONFIG_NL80211_TESTMODE
6610 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6614 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6616 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6617 struct wireless_dev
*wdev
=
6618 __cfg80211_wdev_from_attrs(genl_info_net(info
), info
->attrs
);
6621 if (!rdev
->ops
->testmode_cmd
)
6625 err
= PTR_ERR(wdev
);
6629 } else if (wdev
->wiphy
!= &rdev
->wiphy
) {
6633 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6636 rdev
->testmode_info
= info
;
6637 err
= rdev_testmode_cmd(rdev
, wdev
,
6638 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6639 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6640 rdev
->testmode_info
= NULL
;
6645 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6646 struct netlink_callback
*cb
)
6648 struct cfg80211_registered_device
*rdev
;
6658 * 0 is a valid index, but not valid for args[0],
6659 * so we need to offset by 1.
6661 phy_idx
= cb
->args
[0] - 1;
6663 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6664 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6669 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6670 nl80211_fam
.attrbuf
);
6672 err
= PTR_ERR(rdev
);
6675 phy_idx
= rdev
->wiphy_idx
;
6678 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6680 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6684 data
= nla_data((void *)cb
->args
[1]);
6685 data_len
= nla_len((void *)cb
->args
[1]);
6688 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6694 if (!rdev
->ops
->testmode_dump
) {
6700 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6701 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6702 NL80211_CMD_TESTMODE
);
6703 struct nlattr
*tmdata
;
6708 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6709 genlmsg_cancel(skb
, hdr
);
6713 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6715 genlmsg_cancel(skb
, hdr
);
6718 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6719 nla_nest_end(skb
, tmdata
);
6721 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6722 genlmsg_cancel(skb
, hdr
);
6725 genlmsg_cancel(skb
, hdr
);
6729 genlmsg_end(skb
, hdr
);
6734 cb
->args
[0] = phy_idx
+ 1;
6740 static struct sk_buff
*
6741 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
6742 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
6744 struct sk_buff
*skb
;
6746 struct nlattr
*data
;
6748 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6752 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
6758 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6759 goto nla_put_failure
;
6760 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6762 ((void **)skb
->cb
)[0] = rdev
;
6763 ((void **)skb
->cb
)[1] = hdr
;
6764 ((void **)skb
->cb
)[2] = data
;
6773 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
6776 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6778 if (WARN_ON(!rdev
->testmode_info
))
6781 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
6782 rdev
->testmode_info
->snd_portid
,
6783 rdev
->testmode_info
->snd_seq
,
6786 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
6788 int cfg80211_testmode_reply(struct sk_buff
*skb
)
6790 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6791 void *hdr
= ((void **)skb
->cb
)[1];
6792 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6794 if (WARN_ON(!rdev
->testmode_info
)) {
6799 nla_nest_end(skb
, data
);
6800 genlmsg_end(skb
, hdr
);
6801 return genlmsg_reply(skb
, rdev
->testmode_info
);
6803 EXPORT_SYMBOL(cfg80211_testmode_reply
);
6805 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
6806 int approxlen
, gfp_t gfp
)
6808 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6810 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
6812 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
6814 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
6816 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6817 void *hdr
= ((void **)skb
->cb
)[1];
6818 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6820 nla_nest_end(skb
, data
);
6821 genlmsg_end(skb
, hdr
);
6822 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), skb
, 0,
6823 nl80211_testmode_mcgrp
.id
, gfp
);
6825 EXPORT_SYMBOL(cfg80211_testmode_event
);
6828 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6830 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6831 struct net_device
*dev
= info
->user_ptr
[1];
6832 struct cfg80211_connect_params connect
;
6833 struct wiphy
*wiphy
;
6834 struct cfg80211_cached_keys
*connkeys
= NULL
;
6837 memset(&connect
, 0, sizeof(connect
));
6839 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6842 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6843 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6846 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6848 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6849 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6850 NL80211_CMD_CONNECT
))
6853 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6855 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6857 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6858 NL80211_MAX_NR_CIPHER_SUITES
);
6862 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6863 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6866 wiphy
= &rdev
->wiphy
;
6868 connect
.bg_scan_period
= -1;
6869 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6870 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6871 connect
.bg_scan_period
=
6872 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6875 if (info
->attrs
[NL80211_ATTR_MAC
])
6876 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6877 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6878 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6880 if (info
->attrs
[NL80211_ATTR_IE
]) {
6881 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6882 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6885 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6886 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6887 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6888 connect
.mfp
!= NL80211_MFP_NO
)
6891 connect
.mfp
= NL80211_MFP_NO
;
6894 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6896 ieee80211_get_channel(wiphy
,
6897 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6898 if (!connect
.channel
||
6899 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6903 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6904 connkeys
= nl80211_parse_connkeys(rdev
,
6905 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6906 if (IS_ERR(connkeys
))
6907 return PTR_ERR(connkeys
);
6910 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6911 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6913 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6914 memcpy(&connect
.ht_capa_mask
,
6915 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6916 sizeof(connect
.ht_capa_mask
));
6918 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6919 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6923 memcpy(&connect
.ht_capa
,
6924 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6925 sizeof(connect
.ht_capa
));
6928 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_VHT
]))
6929 connect
.flags
|= ASSOC_REQ_DISABLE_VHT
;
6931 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
])
6932 memcpy(&connect
.vht_capa_mask
,
6933 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]),
6934 sizeof(connect
.vht_capa_mask
));
6936 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]) {
6937 if (!info
->attrs
[NL80211_ATTR_VHT_CAPABILITY_MASK
]) {
6941 memcpy(&connect
.vht_capa
,
6942 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]),
6943 sizeof(connect
.vht_capa
));
6946 wdev_lock(dev
->ieee80211_ptr
);
6947 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
, NULL
);
6948 wdev_unlock(dev
->ieee80211_ptr
);
6954 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6956 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6957 struct net_device
*dev
= info
->user_ptr
[1];
6961 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6962 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6964 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6969 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6970 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6973 wdev_lock(dev
->ieee80211_ptr
);
6974 ret
= cfg80211_disconnect(rdev
, dev
, reason
, true);
6975 wdev_unlock(dev
->ieee80211_ptr
);
6979 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6981 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6986 if (!info
->attrs
[NL80211_ATTR_PID
])
6989 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6991 net
= get_net_ns_by_pid(pid
);
6993 return PTR_ERR(net
);
6997 /* check if anything to do */
6998 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6999 err
= cfg80211_switch_netns(rdev
, net
);
7005 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
7007 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7008 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
7009 struct cfg80211_pmksa
*pmksa
) = NULL
;
7010 struct net_device
*dev
= info
->user_ptr
[1];
7011 struct cfg80211_pmksa pmksa
;
7013 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
7015 if (!info
->attrs
[NL80211_ATTR_MAC
])
7018 if (!info
->attrs
[NL80211_ATTR_PMKID
])
7021 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
7022 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7024 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7025 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7028 switch (info
->genlhdr
->cmd
) {
7029 case NL80211_CMD_SET_PMKSA
:
7030 rdev_ops
= rdev
->ops
->set_pmksa
;
7032 case NL80211_CMD_DEL_PMKSA
:
7033 rdev_ops
= rdev
->ops
->del_pmksa
;
7043 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
7046 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
7048 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7049 struct net_device
*dev
= info
->user_ptr
[1];
7051 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
7052 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7055 if (!rdev
->ops
->flush_pmksa
)
7058 return rdev_flush_pmksa(rdev
, dev
);
7061 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7063 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7064 struct net_device
*dev
= info
->user_ptr
[1];
7065 u8 action_code
, dialog_token
;
7069 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
7070 !rdev
->ops
->tdls_mgmt
)
7073 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
7074 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
7075 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
7076 !info
->attrs
[NL80211_ATTR_IE
] ||
7077 !info
->attrs
[NL80211_ATTR_MAC
])
7080 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7081 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
7082 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
7083 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
7085 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
7086 dialog_token
, status_code
,
7087 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
7088 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
7091 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
7093 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7094 struct net_device
*dev
= info
->user_ptr
[1];
7095 enum nl80211_tdls_operation operation
;
7098 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
7099 !rdev
->ops
->tdls_oper
)
7102 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
7103 !info
->attrs
[NL80211_ATTR_MAC
])
7106 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
7107 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7109 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
7112 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
7113 struct genl_info
*info
)
7115 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7116 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7117 struct cfg80211_chan_def chandef
;
7118 struct sk_buff
*msg
;
7124 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
7125 !info
->attrs
[NL80211_ATTR_DURATION
])
7128 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7130 if (!rdev
->ops
->remain_on_channel
||
7131 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
7135 * We should be on that channel for at least a minimum amount of
7136 * time (10ms) but no longer than the driver supports.
7138 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7139 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
7142 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7146 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7150 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7151 NL80211_CMD_REMAIN_ON_CHANNEL
);
7157 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
7163 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7164 goto nla_put_failure
;
7166 genlmsg_end(msg
, hdr
);
7168 return genlmsg_reply(msg
, info
);
7177 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
7178 struct genl_info
*info
)
7180 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7181 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7184 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7187 if (!rdev
->ops
->cancel_remain_on_channel
)
7190 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7192 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
7195 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
7196 u8
*rates
, u8 rates_len
)
7201 for (i
= 0; i
< rates_len
; i
++) {
7202 int rate
= (rates
[i
] & 0x7f) * 5;
7204 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
7205 struct ieee80211_rate
*srate
=
7206 &sband
->bitrates
[ridx
];
7207 if (rate
== srate
->bitrate
) {
7212 if (ridx
== sband
->n_bitrates
)
7213 return 0; /* rate not found */
7219 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
7220 u8
*rates
, u8 rates_len
,
7221 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
7225 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
7227 for (i
= 0; i
< rates_len
; i
++) {
7230 ridx
= rates
[i
] / 8;
7231 rbit
= BIT(rates
[i
] % 8);
7233 /* check validity */
7234 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
7237 /* check availability */
7238 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
7247 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
7248 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
7249 .len
= NL80211_MAX_SUPP_RATES
},
7250 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
7251 .len
= NL80211_MAX_SUPP_HT_RATES
},
7254 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
7255 struct genl_info
*info
)
7257 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
7258 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7259 struct cfg80211_bitrate_mask mask
;
7261 struct net_device
*dev
= info
->user_ptr
[1];
7262 struct nlattr
*tx_rates
;
7263 struct ieee80211_supported_band
*sband
;
7265 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
7268 if (!rdev
->ops
->set_bitrate_mask
)
7271 memset(&mask
, 0, sizeof(mask
));
7272 /* Default to all rates enabled */
7273 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
7274 sband
= rdev
->wiphy
.bands
[i
];
7275 mask
.control
[i
].legacy
=
7276 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
7278 memcpy(mask
.control
[i
].mcs
,
7279 sband
->ht_cap
.mcs
.rx_mask
,
7280 sizeof(mask
.control
[i
].mcs
));
7282 memset(mask
.control
[i
].mcs
, 0,
7283 sizeof(mask
.control
[i
].mcs
));
7287 * The nested attribute uses enum nl80211_band as the index. This maps
7288 * directly to the enum ieee80211_band values used in cfg80211.
7290 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
7291 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
7293 enum ieee80211_band band
= nla_type(tx_rates
);
7294 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
7296 sband
= rdev
->wiphy
.bands
[band
];
7299 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
7300 nla_len(tx_rates
), nl80211_txattr_policy
);
7301 if (tb
[NL80211_TXRATE_LEGACY
]) {
7302 mask
.control
[band
].legacy
= rateset_to_mask(
7304 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
7305 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
7306 if ((mask
.control
[band
].legacy
== 0) &&
7307 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
7310 if (tb
[NL80211_TXRATE_MCS
]) {
7311 if (!ht_rateset_to_mask(
7313 nla_data(tb
[NL80211_TXRATE_MCS
]),
7314 nla_len(tb
[NL80211_TXRATE_MCS
]),
7315 mask
.control
[band
].mcs
))
7319 if (mask
.control
[band
].legacy
== 0) {
7320 /* don't allow empty legacy rates if HT
7321 * is not even supported. */
7322 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
7325 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
7326 if (mask
.control
[band
].mcs
[i
])
7329 /* legacy and mcs rates may not be both empty */
7330 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
7335 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
7338 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7340 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7341 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7342 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
7344 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
7347 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
7348 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
7350 switch (wdev
->iftype
) {
7351 case NL80211_IFTYPE_STATION
:
7352 case NL80211_IFTYPE_ADHOC
:
7353 case NL80211_IFTYPE_P2P_CLIENT
:
7354 case NL80211_IFTYPE_AP
:
7355 case NL80211_IFTYPE_AP_VLAN
:
7356 case NL80211_IFTYPE_MESH_POINT
:
7357 case NL80211_IFTYPE_P2P_GO
:
7358 case NL80211_IFTYPE_P2P_DEVICE
:
7364 /* not much point in registering if we can't reply */
7365 if (!rdev
->ops
->mgmt_tx
)
7368 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
7369 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
7370 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
7373 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
7375 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7376 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7377 struct cfg80211_chan_def chandef
;
7381 struct sk_buff
*msg
= NULL
;
7382 unsigned int wait
= 0;
7383 bool offchan
, no_cck
, dont_wait_for_ack
;
7385 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
7387 if (!info
->attrs
[NL80211_ATTR_FRAME
])
7390 if (!rdev
->ops
->mgmt_tx
)
7393 switch (wdev
->iftype
) {
7394 case NL80211_IFTYPE_P2P_DEVICE
:
7395 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
7397 case NL80211_IFTYPE_STATION
:
7398 case NL80211_IFTYPE_ADHOC
:
7399 case NL80211_IFTYPE_P2P_CLIENT
:
7400 case NL80211_IFTYPE_AP
:
7401 case NL80211_IFTYPE_AP_VLAN
:
7402 case NL80211_IFTYPE_MESH_POINT
:
7403 case NL80211_IFTYPE_P2P_GO
:
7409 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
7410 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7412 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
7415 * We should wait on the channel for at least a minimum amount
7416 * of time (10ms) but no longer than the driver supports.
7418 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
7419 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
7424 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
7426 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
7429 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
7431 /* get the channel if any has been specified, otherwise pass NULL to
7432 * the driver. The latter will use the current one
7434 chandef
.chan
= NULL
;
7435 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7436 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
7441 if (!chandef
.chan
&& offchan
)
7444 if (!dont_wait_for_ack
) {
7445 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7449 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7457 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
7458 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
7459 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
7460 no_cck
, dont_wait_for_ack
, &cookie
);
7465 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7466 goto nla_put_failure
;
7468 genlmsg_end(msg
, hdr
);
7469 return genlmsg_reply(msg
, info
);
7481 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
7483 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7484 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7487 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
7490 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
7493 switch (wdev
->iftype
) {
7494 case NL80211_IFTYPE_STATION
:
7495 case NL80211_IFTYPE_ADHOC
:
7496 case NL80211_IFTYPE_P2P_CLIENT
:
7497 case NL80211_IFTYPE_AP
:
7498 case NL80211_IFTYPE_AP_VLAN
:
7499 case NL80211_IFTYPE_P2P_GO
:
7500 case NL80211_IFTYPE_P2P_DEVICE
:
7506 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
7508 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
7511 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7513 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7514 struct wireless_dev
*wdev
;
7515 struct net_device
*dev
= info
->user_ptr
[1];
7520 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
7523 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
7525 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
7528 wdev
= dev
->ieee80211_ptr
;
7530 if (!rdev
->ops
->set_power_mgmt
)
7533 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
7535 if (state
== wdev
->ps
)
7538 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
7544 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
7546 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7547 enum nl80211_ps_state ps_state
;
7548 struct wireless_dev
*wdev
;
7549 struct net_device
*dev
= info
->user_ptr
[1];
7550 struct sk_buff
*msg
;
7554 wdev
= dev
->ieee80211_ptr
;
7556 if (!rdev
->ops
->set_power_mgmt
)
7559 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7563 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7564 NL80211_CMD_GET_POWER_SAVE
);
7571 ps_state
= NL80211_PS_ENABLED
;
7573 ps_state
= NL80211_PS_DISABLED
;
7575 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
7576 goto nla_put_failure
;
7578 genlmsg_end(msg
, hdr
);
7579 return genlmsg_reply(msg
, info
);
7588 static struct nla_policy
7589 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
7590 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
7591 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
7592 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
7593 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
7594 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
7595 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
7598 static int nl80211_set_cqm_txe(struct genl_info
*info
,
7599 u32 rate
, u32 pkts
, u32 intvl
)
7601 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7602 struct net_device
*dev
= info
->user_ptr
[1];
7603 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7605 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7608 if (!rdev
->ops
->set_cqm_txe_config
)
7611 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7612 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7615 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7618 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7619 s32 threshold
, u32 hysteresis
)
7621 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7622 struct net_device
*dev
= info
->user_ptr
[1];
7623 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7628 /* disabling - hysteresis should also be zero then */
7632 if (!rdev
->ops
->set_cqm_rssi_config
)
7635 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7636 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7639 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7642 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7644 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7648 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7652 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7653 nl80211_attr_cqm_policy
);
7657 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7658 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7659 s32 threshold
= nla_get_s32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7660 u32 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7662 return nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7665 if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7666 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7667 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7668 u32 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7669 u32 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7670 u32 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7672 return nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7678 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7680 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7681 struct net_device
*dev
= info
->user_ptr
[1];
7682 struct mesh_config cfg
;
7683 struct mesh_setup setup
;
7686 /* start with default */
7687 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7688 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7690 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7691 /* and parse parameters if given */
7692 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7697 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7698 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7701 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7702 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7704 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7705 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7706 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7709 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7710 setup
.beacon_interval
=
7711 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7712 if (setup
.beacon_interval
< 10 ||
7713 setup
.beacon_interval
> 10000)
7717 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7719 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7720 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7724 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7725 /* parse additional setup parameters if given */
7726 err
= nl80211_parse_mesh_setup(info
, &setup
);
7732 cfg
.auto_open_plinks
= false;
7734 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7735 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7739 /* cfg80211_join_mesh() will sort it out */
7740 setup
.chandef
.chan
= NULL
;
7743 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
7744 u8
*rates
= nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7746 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
7747 struct ieee80211_supported_band
*sband
;
7749 if (!setup
.chandef
.chan
)
7752 sband
= rdev
->wiphy
.bands
[setup
.chandef
.chan
->band
];
7754 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
7755 &setup
.basic_rates
);
7760 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7763 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7765 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7766 struct net_device
*dev
= info
->user_ptr
[1];
7768 return cfg80211_leave_mesh(rdev
, dev
);
7772 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7773 struct cfg80211_registered_device
*rdev
)
7775 struct cfg80211_wowlan
*wowlan
= rdev
->wiphy
.wowlan_config
;
7776 struct nlattr
*nl_pats
, *nl_pat
;
7779 if (!wowlan
->n_patterns
)
7782 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7786 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
7787 nl_pat
= nla_nest_start(msg
, i
+ 1);
7790 pat_len
= wowlan
->patterns
[i
].pattern_len
;
7791 if (nla_put(msg
, NL80211_PKTPAT_MASK
, DIV_ROUND_UP(pat_len
, 8),
7792 wowlan
->patterns
[i
].mask
) ||
7793 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
7794 wowlan
->patterns
[i
].pattern
) ||
7795 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
7796 wowlan
->patterns
[i
].pkt_offset
))
7798 nla_nest_end(msg
, nl_pat
);
7800 nla_nest_end(msg
, nl_pats
);
7805 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7806 struct cfg80211_wowlan_tcp
*tcp
)
7808 struct nlattr
*nl_tcp
;
7813 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7817 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7818 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7819 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7820 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7821 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7822 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7823 tcp
->payload_len
, tcp
->payload
) ||
7824 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7825 tcp
->data_interval
) ||
7826 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7827 tcp
->wake_len
, tcp
->wake_data
) ||
7828 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7829 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7832 if (tcp
->payload_seq
.len
&&
7833 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7834 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7837 if (tcp
->payload_tok
.len
&&
7838 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7839 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7843 nla_nest_end(msg
, nl_tcp
);
7848 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7850 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7851 struct sk_buff
*msg
;
7853 u32 size
= NLMSG_DEFAULT_SIZE
;
7855 if (!rdev
->wiphy
.wowlan
)
7858 if (rdev
->wiphy
.wowlan_config
&& rdev
->wiphy
.wowlan_config
->tcp
) {
7859 /* adjust size to have room for all the data */
7860 size
+= rdev
->wiphy
.wowlan_config
->tcp
->tokens_size
+
7861 rdev
->wiphy
.wowlan_config
->tcp
->payload_len
+
7862 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
+
7863 rdev
->wiphy
.wowlan_config
->tcp
->wake_len
/ 8;
7866 msg
= nlmsg_new(size
, GFP_KERNEL
);
7870 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7871 NL80211_CMD_GET_WOWLAN
);
7873 goto nla_put_failure
;
7875 if (rdev
->wiphy
.wowlan_config
) {
7876 struct nlattr
*nl_wowlan
;
7878 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7880 goto nla_put_failure
;
7882 if ((rdev
->wiphy
.wowlan_config
->any
&&
7883 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7884 (rdev
->wiphy
.wowlan_config
->disconnect
&&
7885 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7886 (rdev
->wiphy
.wowlan_config
->magic_pkt
&&
7887 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7888 (rdev
->wiphy
.wowlan_config
->gtk_rekey_failure
&&
7889 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7890 (rdev
->wiphy
.wowlan_config
->eap_identity_req
&&
7891 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7892 (rdev
->wiphy
.wowlan_config
->four_way_handshake
&&
7893 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7894 (rdev
->wiphy
.wowlan_config
->rfkill_release
&&
7895 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7896 goto nla_put_failure
;
7898 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7899 goto nla_put_failure
;
7901 if (nl80211_send_wowlan_tcp(msg
,
7902 rdev
->wiphy
.wowlan_config
->tcp
))
7903 goto nla_put_failure
;
7905 nla_nest_end(msg
, nl_wowlan
);
7908 genlmsg_end(msg
, hdr
);
7909 return genlmsg_reply(msg
, info
);
7916 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7917 struct nlattr
*attr
,
7918 struct cfg80211_wowlan
*trig
)
7920 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7921 struct cfg80211_wowlan_tcp
*cfg
;
7922 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7923 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7925 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7928 if (!rdev
->wiphy
.wowlan
->tcp
)
7931 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7932 nla_data(attr
), nla_len(attr
),
7933 nl80211_wowlan_tcp_policy
);
7937 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7938 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7939 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7940 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7941 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7942 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7943 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7944 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7947 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7948 if (data_size
> rdev
->wiphy
.wowlan
->tcp
->data_payload_max
)
7951 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7952 rdev
->wiphy
.wowlan
->tcp
->data_interval_max
||
7953 nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) == 0)
7956 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7957 if (wake_size
> rdev
->wiphy
.wowlan
->tcp
->wake_payload_max
)
7960 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7961 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7964 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7965 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7967 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7968 tokens_size
= tokln
- sizeof(*tok
);
7970 if (!tok
->len
|| tokens_size
% tok
->len
)
7972 if (!rdev
->wiphy
.wowlan
->tcp
->tok
)
7974 if (tok
->len
> rdev
->wiphy
.wowlan
->tcp
->tok
->max_len
)
7976 if (tok
->len
< rdev
->wiphy
.wowlan
->tcp
->tok
->min_len
)
7978 if (tokens_size
> rdev
->wiphy
.wowlan
->tcp
->tok
->bufsize
)
7980 if (tok
->offset
+ tok
->len
> data_size
)
7984 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7985 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7986 if (!rdev
->wiphy
.wowlan
->tcp
->seq
)
7988 if (seq
->len
== 0 || seq
->len
> 4)
7990 if (seq
->len
+ seq
->offset
> data_size
)
7994 size
= sizeof(*cfg
);
7996 size
+= wake_size
+ wake_mask_size
;
7997 size
+= tokens_size
;
7999 cfg
= kzalloc(size
, GFP_KERNEL
);
8002 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
8003 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
8004 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
8006 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
8007 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
8011 /* allocate a socket and port for it and use it */
8012 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
8013 IPPROTO_TCP
, &cfg
->sock
, 1);
8018 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
8019 sock_release(cfg
->sock
);
8023 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
8029 cfg
->src_port
= port
;
8032 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
8033 cfg
->payload_len
= data_size
;
8034 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
8035 memcpy((void *)cfg
->payload
,
8036 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
8039 cfg
->payload_seq
= *seq
;
8040 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
8041 cfg
->wake_len
= wake_size
;
8042 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
8043 memcpy((void *)cfg
->wake_data
,
8044 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
8046 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
8047 data_size
+ wake_size
;
8048 memcpy((void *)cfg
->wake_mask
,
8049 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
8052 cfg
->tokens_size
= tokens_size
;
8053 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
8061 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
8063 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8064 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
8065 struct cfg80211_wowlan new_triggers
= {};
8066 struct cfg80211_wowlan
*ntrig
;
8067 const struct wiphy_wowlan_support
*wowlan
= rdev
->wiphy
.wowlan
;
8069 bool prev_enabled
= rdev
->wiphy
.wowlan_config
;
8074 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
8075 cfg80211_rdev_free_wowlan(rdev
);
8076 rdev
->wiphy
.wowlan_config
= NULL
;
8080 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
8081 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
8082 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
8083 nl80211_wowlan_policy
);
8087 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
8088 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
8090 new_triggers
.any
= true;
8093 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
8094 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
8096 new_triggers
.disconnect
= true;
8099 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
8100 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
8102 new_triggers
.magic_pkt
= true;
8105 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
8108 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
8109 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
8111 new_triggers
.gtk_rekey_failure
= true;
8114 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
8115 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
8117 new_triggers
.eap_identity_req
= true;
8120 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
8121 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
8123 new_triggers
.four_way_handshake
= true;
8126 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
8127 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
8129 new_triggers
.rfkill_release
= true;
8132 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
8135 int rem
, pat_len
, mask_len
, pkt_offset
;
8136 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
8138 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
8141 if (n_patterns
> wowlan
->n_patterns
)
8144 new_triggers
.patterns
= kcalloc(n_patterns
,
8145 sizeof(new_triggers
.patterns
[0]),
8147 if (!new_triggers
.patterns
)
8150 new_triggers
.n_patterns
= n_patterns
;
8153 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
8155 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
8156 nla_len(pat
), NULL
);
8158 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
8159 !pat_tb
[NL80211_PKTPAT_PATTERN
])
8161 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
8162 mask_len
= DIV_ROUND_UP(pat_len
, 8);
8163 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
8165 if (pat_len
> wowlan
->pattern_max_len
||
8166 pat_len
< wowlan
->pattern_min_len
)
8169 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
8172 pkt_offset
= nla_get_u32(
8173 pat_tb
[NL80211_PKTPAT_OFFSET
]);
8174 if (pkt_offset
> wowlan
->max_pkt_offset
)
8176 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
8178 new_triggers
.patterns
[i
].mask
=
8179 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
8180 if (!new_triggers
.patterns
[i
].mask
) {
8184 new_triggers
.patterns
[i
].pattern
=
8185 new_triggers
.patterns
[i
].mask
+ mask_len
;
8186 memcpy(new_triggers
.patterns
[i
].mask
,
8187 nla_data(pat_tb
[NL80211_PKTPAT_MASK
]),
8189 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
8190 memcpy(new_triggers
.patterns
[i
].pattern
,
8191 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]),
8197 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
8198 err
= nl80211_parse_wowlan_tcp(
8199 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
8205 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
8210 cfg80211_rdev_free_wowlan(rdev
);
8211 rdev
->wiphy
.wowlan_config
= ntrig
;
8214 if (rdev
->ops
->set_wakeup
&&
8215 prev_enabled
!= !!rdev
->wiphy
.wowlan_config
)
8216 rdev_set_wakeup(rdev
, rdev
->wiphy
.wowlan_config
);
8220 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
8221 kfree(new_triggers
.patterns
[i
].mask
);
8222 kfree(new_triggers
.patterns
);
8223 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
8224 sock_release(new_triggers
.tcp
->sock
);
8225 kfree(new_triggers
.tcp
);
8230 static int nl80211_send_coalesce_rules(struct sk_buff
*msg
,
8231 struct cfg80211_registered_device
*rdev
)
8233 struct nlattr
*nl_pats
, *nl_pat
, *nl_rule
, *nl_rules
;
8235 struct cfg80211_coalesce_rules
*rule
;
8237 if (!rdev
->coalesce
->n_rules
)
8240 nl_rules
= nla_nest_start(msg
, NL80211_ATTR_COALESCE_RULE
);
8244 for (i
= 0; i
< rdev
->coalesce
->n_rules
; i
++) {
8245 nl_rule
= nla_nest_start(msg
, i
+ 1);
8249 rule
= &rdev
->coalesce
->rules
[i
];
8250 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_DELAY
,
8254 if (nla_put_u32(msg
, NL80211_ATTR_COALESCE_RULE_CONDITION
,
8258 nl_pats
= nla_nest_start(msg
,
8259 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
);
8263 for (j
= 0; j
< rule
->n_patterns
; j
++) {
8264 nl_pat
= nla_nest_start(msg
, j
+ 1);
8267 pat_len
= rule
->patterns
[j
].pattern_len
;
8268 if (nla_put(msg
, NL80211_PKTPAT_MASK
,
8269 DIV_ROUND_UP(pat_len
, 8),
8270 rule
->patterns
[j
].mask
) ||
8271 nla_put(msg
, NL80211_PKTPAT_PATTERN
, pat_len
,
8272 rule
->patterns
[j
].pattern
) ||
8273 nla_put_u32(msg
, NL80211_PKTPAT_OFFSET
,
8274 rule
->patterns
[j
].pkt_offset
))
8276 nla_nest_end(msg
, nl_pat
);
8278 nla_nest_end(msg
, nl_pats
);
8279 nla_nest_end(msg
, nl_rule
);
8281 nla_nest_end(msg
, nl_rules
);
8286 static int nl80211_get_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
8288 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8289 struct sk_buff
*msg
;
8292 if (!rdev
->wiphy
.coalesce
)
8295 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8299 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8300 NL80211_CMD_GET_COALESCE
);
8302 goto nla_put_failure
;
8304 if (rdev
->coalesce
&& nl80211_send_coalesce_rules(msg
, rdev
))
8305 goto nla_put_failure
;
8307 genlmsg_end(msg
, hdr
);
8308 return genlmsg_reply(msg
, info
);
8315 void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device
*rdev
)
8317 struct cfg80211_coalesce
*coalesce
= rdev
->coalesce
;
8319 struct cfg80211_coalesce_rules
*rule
;
8324 for (i
= 0; i
< coalesce
->n_rules
; i
++) {
8325 rule
= &coalesce
->rules
[i
];
8326 for (j
= 0; j
< rule
->n_patterns
; j
++)
8327 kfree(rule
->patterns
[j
].mask
);
8328 kfree(rule
->patterns
);
8330 kfree(coalesce
->rules
);
8332 rdev
->coalesce
= NULL
;
8335 static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device
*rdev
,
8336 struct nlattr
*rule
,
8337 struct cfg80211_coalesce_rules
*new_rule
)
8340 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
8341 struct nlattr
*tb
[NUM_NL80211_ATTR_COALESCE_RULE
], *pat
;
8342 int rem
, pat_len
, mask_len
, pkt_offset
, n_patterns
= 0;
8343 struct nlattr
*pat_tb
[NUM_NL80211_PKTPAT
];
8345 err
= nla_parse(tb
, NL80211_ATTR_COALESCE_RULE_MAX
, nla_data(rule
),
8346 nla_len(rule
), nl80211_coalesce_policy
);
8350 if (tb
[NL80211_ATTR_COALESCE_RULE_DELAY
])
8352 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_DELAY
]);
8353 if (new_rule
->delay
> coalesce
->max_delay
)
8356 if (tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
])
8357 new_rule
->condition
=
8358 nla_get_u32(tb
[NL80211_ATTR_COALESCE_RULE_CONDITION
]);
8359 if (new_rule
->condition
!= NL80211_COALESCE_CONDITION_MATCH
&&
8360 new_rule
->condition
!= NL80211_COALESCE_CONDITION_NO_MATCH
)
8363 if (!tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
])
8366 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
8369 if (n_patterns
> coalesce
->n_patterns
)
8372 new_rule
->patterns
= kcalloc(n_patterns
, sizeof(new_rule
->patterns
[0]),
8374 if (!new_rule
->patterns
)
8377 new_rule
->n_patterns
= n_patterns
;
8380 nla_for_each_nested(pat
, tb
[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN
],
8382 nla_parse(pat_tb
, MAX_NL80211_PKTPAT
, nla_data(pat
),
8383 nla_len(pat
), NULL
);
8384 if (!pat_tb
[NL80211_PKTPAT_MASK
] ||
8385 !pat_tb
[NL80211_PKTPAT_PATTERN
])
8387 pat_len
= nla_len(pat_tb
[NL80211_PKTPAT_PATTERN
]);
8388 mask_len
= DIV_ROUND_UP(pat_len
, 8);
8389 if (nla_len(pat_tb
[NL80211_PKTPAT_MASK
]) != mask_len
)
8391 if (pat_len
> coalesce
->pattern_max_len
||
8392 pat_len
< coalesce
->pattern_min_len
)
8395 if (!pat_tb
[NL80211_PKTPAT_OFFSET
])
8398 pkt_offset
= nla_get_u32(pat_tb
[NL80211_PKTPAT_OFFSET
]);
8399 if (pkt_offset
> coalesce
->max_pkt_offset
)
8401 new_rule
->patterns
[i
].pkt_offset
= pkt_offset
;
8403 new_rule
->patterns
[i
].mask
=
8404 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
8405 if (!new_rule
->patterns
[i
].mask
)
8407 new_rule
->patterns
[i
].pattern
=
8408 new_rule
->patterns
[i
].mask
+ mask_len
;
8409 memcpy(new_rule
->patterns
[i
].mask
,
8410 nla_data(pat_tb
[NL80211_PKTPAT_MASK
]), mask_len
);
8411 new_rule
->patterns
[i
].pattern_len
= pat_len
;
8412 memcpy(new_rule
->patterns
[i
].pattern
,
8413 nla_data(pat_tb
[NL80211_PKTPAT_PATTERN
]), pat_len
);
8420 static int nl80211_set_coalesce(struct sk_buff
*skb
, struct genl_info
*info
)
8422 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8423 const struct wiphy_coalesce_support
*coalesce
= rdev
->wiphy
.coalesce
;
8424 struct cfg80211_coalesce new_coalesce
= {};
8425 struct cfg80211_coalesce
*n_coalesce
;
8426 int err
, rem_rule
, n_rules
= 0, i
, j
;
8427 struct nlattr
*rule
;
8428 struct cfg80211_coalesce_rules
*tmp_rule
;
8430 if (!rdev
->wiphy
.coalesce
|| !rdev
->ops
->set_coalesce
)
8433 if (!info
->attrs
[NL80211_ATTR_COALESCE_RULE
]) {
8434 cfg80211_rdev_free_coalesce(rdev
);
8435 rdev
->ops
->set_coalesce(&rdev
->wiphy
, NULL
);
8439 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
8442 if (n_rules
> coalesce
->n_rules
)
8445 new_coalesce
.rules
= kcalloc(n_rules
, sizeof(new_coalesce
.rules
[0]),
8447 if (!new_coalesce
.rules
)
8450 new_coalesce
.n_rules
= n_rules
;
8453 nla_for_each_nested(rule
, info
->attrs
[NL80211_ATTR_COALESCE_RULE
],
8455 err
= nl80211_parse_coalesce_rule(rdev
, rule
,
8456 &new_coalesce
.rules
[i
]);
8463 err
= rdev
->ops
->set_coalesce(&rdev
->wiphy
, &new_coalesce
);
8467 n_coalesce
= kmemdup(&new_coalesce
, sizeof(new_coalesce
), GFP_KERNEL
);
8472 cfg80211_rdev_free_coalesce(rdev
);
8473 rdev
->coalesce
= n_coalesce
;
8477 for (i
= 0; i
< new_coalesce
.n_rules
; i
++) {
8478 tmp_rule
= &new_coalesce
.rules
[i
];
8479 for (j
= 0; j
< tmp_rule
->n_patterns
; j
++)
8480 kfree(tmp_rule
->patterns
[j
].mask
);
8481 kfree(tmp_rule
->patterns
);
8483 kfree(new_coalesce
.rules
);
8488 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
8490 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8491 struct net_device
*dev
= info
->user_ptr
[1];
8492 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8493 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
8494 struct cfg80211_gtk_rekey_data rekey_data
;
8497 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
8500 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
8501 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8502 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
8503 nl80211_rekey_policy
);
8507 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
8509 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
8511 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
8514 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
8516 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
8518 memcpy(rekey_data
.replay_ctr
,
8519 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
8520 NL80211_REPLAY_CTR_LEN
);
8523 if (!wdev
->current_bss
) {
8528 if (!rdev
->ops
->set_rekey_data
) {
8533 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
8539 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
8540 struct genl_info
*info
)
8542 struct net_device
*dev
= info
->user_ptr
[1];
8543 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8545 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8546 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8549 if (wdev
->ap_unexpected_nlportid
)
8552 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
8556 static int nl80211_probe_client(struct sk_buff
*skb
,
8557 struct genl_info
*info
)
8559 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8560 struct net_device
*dev
= info
->user_ptr
[1];
8561 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8562 struct sk_buff
*msg
;
8568 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
8569 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
8572 if (!info
->attrs
[NL80211_ATTR_MAC
])
8575 if (!rdev
->ops
->probe_client
)
8578 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8582 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8583 NL80211_CMD_PROBE_CLIENT
);
8589 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
8591 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
8595 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8596 goto nla_put_failure
;
8598 genlmsg_end(msg
, hdr
);
8600 return genlmsg_reply(msg
, info
);
8609 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
8611 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8612 struct cfg80211_beacon_registration
*reg
, *nreg
;
8615 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
8618 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
8622 /* First, check if already registered. */
8623 spin_lock_bh(&rdev
->beacon_registrations_lock
);
8624 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
8625 if (reg
->nlportid
== info
->snd_portid
) {
8630 /* Add it to the list */
8631 nreg
->nlportid
= info
->snd_portid
;
8632 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
8634 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8638 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
8643 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8645 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8646 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8649 if (!rdev
->ops
->start_p2p_device
)
8652 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8655 if (wdev
->p2p_started
)
8658 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
8662 err
= rdev_start_p2p_device(rdev
, wdev
);
8666 wdev
->p2p_started
= true;
8672 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
8674 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8675 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8677 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
8680 if (!rdev
->ops
->stop_p2p_device
)
8683 cfg80211_stop_p2p_device(rdev
, wdev
);
8688 static int nl80211_get_protocol_features(struct sk_buff
*skb
,
8689 struct genl_info
*info
)
8692 struct sk_buff
*msg
;
8694 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8698 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
8699 NL80211_CMD_GET_PROTOCOL_FEATURES
);
8701 goto nla_put_failure
;
8703 if (nla_put_u32(msg
, NL80211_ATTR_PROTOCOL_FEATURES
,
8704 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
))
8705 goto nla_put_failure
;
8707 genlmsg_end(msg
, hdr
);
8708 return genlmsg_reply(msg
, info
);
8715 static int nl80211_update_ft_ies(struct sk_buff
*skb
, struct genl_info
*info
)
8717 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8718 struct cfg80211_update_ft_ies_params ft_params
;
8719 struct net_device
*dev
= info
->user_ptr
[1];
8721 if (!rdev
->ops
->update_ft_ies
)
8724 if (!info
->attrs
[NL80211_ATTR_MDID
] ||
8725 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
8728 memset(&ft_params
, 0, sizeof(ft_params
));
8729 ft_params
.md
= nla_get_u16(info
->attrs
[NL80211_ATTR_MDID
]);
8730 ft_params
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
8731 ft_params
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
8733 return rdev_update_ft_ies(rdev
, dev
, &ft_params
);
8736 static int nl80211_crit_protocol_start(struct sk_buff
*skb
,
8737 struct genl_info
*info
)
8739 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8740 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8741 enum nl80211_crit_proto_id proto
= NL80211_CRIT_PROTO_UNSPEC
;
8745 if (!rdev
->ops
->crit_proto_start
)
8748 if (WARN_ON(!rdev
->ops
->crit_proto_stop
))
8751 if (rdev
->crit_proto_nlportid
)
8754 /* determine protocol if provided */
8755 if (info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
])
8756 proto
= nla_get_u16(info
->attrs
[NL80211_ATTR_CRIT_PROT_ID
]);
8758 if (proto
>= NUM_NL80211_CRIT_PROTO
)
8761 /* timeout must be provided */
8762 if (!info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
])
8766 nla_get_u16(info
->attrs
[NL80211_ATTR_MAX_CRIT_PROT_DURATION
]);
8768 if (duration
> NL80211_CRIT_PROTO_MAX_DURATION
)
8771 ret
= rdev_crit_proto_start(rdev
, wdev
, proto
, duration
);
8773 rdev
->crit_proto_nlportid
= info
->snd_portid
;
8778 static int nl80211_crit_protocol_stop(struct sk_buff
*skb
,
8779 struct genl_info
*info
)
8781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
8782 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8784 if (!rdev
->ops
->crit_proto_stop
)
8787 if (rdev
->crit_proto_nlportid
) {
8788 rdev
->crit_proto_nlportid
= 0;
8789 rdev_crit_proto_stop(rdev
, wdev
);
8794 #define NL80211_FLAG_NEED_WIPHY 0x01
8795 #define NL80211_FLAG_NEED_NETDEV 0x02
8796 #define NL80211_FLAG_NEED_RTNL 0x04
8797 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
8798 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
8799 NL80211_FLAG_CHECK_NETDEV_UP)
8800 #define NL80211_FLAG_NEED_WDEV 0x10
8801 /* If a netdev is associated, it must be UP, P2P must be started */
8802 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
8803 NL80211_FLAG_CHECK_NETDEV_UP)
8805 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8806 struct genl_info
*info
)
8808 struct cfg80211_registered_device
*rdev
;
8809 struct wireless_dev
*wdev
;
8810 struct net_device
*dev
;
8811 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
8816 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
8817 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
8821 return PTR_ERR(rdev
);
8823 info
->user_ptr
[0] = rdev
;
8824 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
8825 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8828 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
8833 return PTR_ERR(wdev
);
8837 rdev
= wiphy_to_dev(wdev
->wiphy
);
8839 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
8846 info
->user_ptr
[1] = dev
;
8848 info
->user_ptr
[1] = wdev
;
8852 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
8853 !netif_running(dev
)) {
8860 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
8861 if (!wdev
->p2p_started
) {
8868 info
->user_ptr
[0] = rdev
;
8874 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
8875 struct genl_info
*info
)
8877 if (info
->user_ptr
[1]) {
8878 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
8879 struct wireless_dev
*wdev
= info
->user_ptr
[1];
8882 dev_put(wdev
->netdev
);
8884 dev_put(info
->user_ptr
[1]);
8887 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
8891 static struct genl_ops nl80211_ops
[] = {
8893 .cmd
= NL80211_CMD_GET_WIPHY
,
8894 .doit
= nl80211_get_wiphy
,
8895 .dumpit
= nl80211_dump_wiphy
,
8896 .done
= nl80211_dump_wiphy_done
,
8897 .policy
= nl80211_policy
,
8898 /* can be retrieved by unprivileged users */
8899 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8900 NL80211_FLAG_NEED_RTNL
,
8903 .cmd
= NL80211_CMD_SET_WIPHY
,
8904 .doit
= nl80211_set_wiphy
,
8905 .policy
= nl80211_policy
,
8906 .flags
= GENL_ADMIN_PERM
,
8907 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
8910 .cmd
= NL80211_CMD_GET_INTERFACE
,
8911 .doit
= nl80211_get_interface
,
8912 .dumpit
= nl80211_dump_interface
,
8913 .policy
= nl80211_policy
,
8914 /* can be retrieved by unprivileged users */
8915 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8916 NL80211_FLAG_NEED_RTNL
,
8919 .cmd
= NL80211_CMD_SET_INTERFACE
,
8920 .doit
= nl80211_set_interface
,
8921 .policy
= nl80211_policy
,
8922 .flags
= GENL_ADMIN_PERM
,
8923 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8924 NL80211_FLAG_NEED_RTNL
,
8927 .cmd
= NL80211_CMD_NEW_INTERFACE
,
8928 .doit
= nl80211_new_interface
,
8929 .policy
= nl80211_policy
,
8930 .flags
= GENL_ADMIN_PERM
,
8931 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8932 NL80211_FLAG_NEED_RTNL
,
8935 .cmd
= NL80211_CMD_DEL_INTERFACE
,
8936 .doit
= nl80211_del_interface
,
8937 .policy
= nl80211_policy
,
8938 .flags
= GENL_ADMIN_PERM
,
8939 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8940 NL80211_FLAG_NEED_RTNL
,
8943 .cmd
= NL80211_CMD_GET_KEY
,
8944 .doit
= nl80211_get_key
,
8945 .policy
= nl80211_policy
,
8946 .flags
= GENL_ADMIN_PERM
,
8947 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8948 NL80211_FLAG_NEED_RTNL
,
8951 .cmd
= NL80211_CMD_SET_KEY
,
8952 .doit
= nl80211_set_key
,
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_NEW_KEY
,
8960 .doit
= nl80211_new_key
,
8961 .policy
= nl80211_policy
,
8962 .flags
= GENL_ADMIN_PERM
,
8963 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8964 NL80211_FLAG_NEED_RTNL
,
8967 .cmd
= NL80211_CMD_DEL_KEY
,
8968 .doit
= nl80211_del_key
,
8969 .policy
= nl80211_policy
,
8970 .flags
= GENL_ADMIN_PERM
,
8971 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8972 NL80211_FLAG_NEED_RTNL
,
8975 .cmd
= NL80211_CMD_SET_BEACON
,
8976 .policy
= nl80211_policy
,
8977 .flags
= GENL_ADMIN_PERM
,
8978 .doit
= nl80211_set_beacon
,
8979 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8980 NL80211_FLAG_NEED_RTNL
,
8983 .cmd
= NL80211_CMD_START_AP
,
8984 .policy
= nl80211_policy
,
8985 .flags
= GENL_ADMIN_PERM
,
8986 .doit
= nl80211_start_ap
,
8987 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8988 NL80211_FLAG_NEED_RTNL
,
8991 .cmd
= NL80211_CMD_STOP_AP
,
8992 .policy
= nl80211_policy
,
8993 .flags
= GENL_ADMIN_PERM
,
8994 .doit
= nl80211_stop_ap
,
8995 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8996 NL80211_FLAG_NEED_RTNL
,
8999 .cmd
= NL80211_CMD_GET_STATION
,
9000 .doit
= nl80211_get_station
,
9001 .dumpit
= nl80211_dump_station
,
9002 .policy
= nl80211_policy
,
9003 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9004 NL80211_FLAG_NEED_RTNL
,
9007 .cmd
= NL80211_CMD_SET_STATION
,
9008 .doit
= nl80211_set_station
,
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_NEW_STATION
,
9016 .doit
= nl80211_new_station
,
9017 .policy
= nl80211_policy
,
9018 .flags
= GENL_ADMIN_PERM
,
9019 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9020 NL80211_FLAG_NEED_RTNL
,
9023 .cmd
= NL80211_CMD_DEL_STATION
,
9024 .doit
= nl80211_del_station
,
9025 .policy
= nl80211_policy
,
9026 .flags
= GENL_ADMIN_PERM
,
9027 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9028 NL80211_FLAG_NEED_RTNL
,
9031 .cmd
= NL80211_CMD_GET_MPATH
,
9032 .doit
= nl80211_get_mpath
,
9033 .dumpit
= nl80211_dump_mpath
,
9034 .policy
= nl80211_policy
,
9035 .flags
= GENL_ADMIN_PERM
,
9036 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9037 NL80211_FLAG_NEED_RTNL
,
9040 .cmd
= NL80211_CMD_SET_MPATH
,
9041 .doit
= nl80211_set_mpath
,
9042 .policy
= nl80211_policy
,
9043 .flags
= GENL_ADMIN_PERM
,
9044 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9045 NL80211_FLAG_NEED_RTNL
,
9048 .cmd
= NL80211_CMD_NEW_MPATH
,
9049 .doit
= nl80211_new_mpath
,
9050 .policy
= nl80211_policy
,
9051 .flags
= GENL_ADMIN_PERM
,
9052 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9053 NL80211_FLAG_NEED_RTNL
,
9056 .cmd
= NL80211_CMD_DEL_MPATH
,
9057 .doit
= nl80211_del_mpath
,
9058 .policy
= nl80211_policy
,
9059 .flags
= GENL_ADMIN_PERM
,
9060 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9061 NL80211_FLAG_NEED_RTNL
,
9064 .cmd
= NL80211_CMD_SET_BSS
,
9065 .doit
= nl80211_set_bss
,
9066 .policy
= nl80211_policy
,
9067 .flags
= GENL_ADMIN_PERM
,
9068 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9069 NL80211_FLAG_NEED_RTNL
,
9072 .cmd
= NL80211_CMD_GET_REG
,
9073 .doit
= nl80211_get_reg
,
9074 .policy
= nl80211_policy
,
9075 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9076 /* can be retrieved by unprivileged users */
9079 .cmd
= NL80211_CMD_SET_REG
,
9080 .doit
= nl80211_set_reg
,
9081 .policy
= nl80211_policy
,
9082 .flags
= GENL_ADMIN_PERM
,
9083 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
9086 .cmd
= NL80211_CMD_REQ_SET_REG
,
9087 .doit
= nl80211_req_set_reg
,
9088 .policy
= nl80211_policy
,
9089 .flags
= GENL_ADMIN_PERM
,
9092 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
9093 .doit
= nl80211_get_mesh_config
,
9094 .policy
= nl80211_policy
,
9095 /* can be retrieved by unprivileged users */
9096 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9097 NL80211_FLAG_NEED_RTNL
,
9100 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
9101 .doit
= nl80211_update_mesh_config
,
9102 .policy
= nl80211_policy
,
9103 .flags
= GENL_ADMIN_PERM
,
9104 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9105 NL80211_FLAG_NEED_RTNL
,
9108 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
9109 .doit
= nl80211_trigger_scan
,
9110 .policy
= nl80211_policy
,
9111 .flags
= GENL_ADMIN_PERM
,
9112 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9113 NL80211_FLAG_NEED_RTNL
,
9116 .cmd
= NL80211_CMD_GET_SCAN
,
9117 .policy
= nl80211_policy
,
9118 .dumpit
= nl80211_dump_scan
,
9121 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
9122 .doit
= nl80211_start_sched_scan
,
9123 .policy
= nl80211_policy
,
9124 .flags
= GENL_ADMIN_PERM
,
9125 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9126 NL80211_FLAG_NEED_RTNL
,
9129 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
9130 .doit
= nl80211_stop_sched_scan
,
9131 .policy
= nl80211_policy
,
9132 .flags
= GENL_ADMIN_PERM
,
9133 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9134 NL80211_FLAG_NEED_RTNL
,
9137 .cmd
= NL80211_CMD_AUTHENTICATE
,
9138 .doit
= nl80211_authenticate
,
9139 .policy
= nl80211_policy
,
9140 .flags
= GENL_ADMIN_PERM
,
9141 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9142 NL80211_FLAG_NEED_RTNL
,
9145 .cmd
= NL80211_CMD_ASSOCIATE
,
9146 .doit
= nl80211_associate
,
9147 .policy
= nl80211_policy
,
9148 .flags
= GENL_ADMIN_PERM
,
9149 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9150 NL80211_FLAG_NEED_RTNL
,
9153 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
9154 .doit
= nl80211_deauthenticate
,
9155 .policy
= nl80211_policy
,
9156 .flags
= GENL_ADMIN_PERM
,
9157 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9158 NL80211_FLAG_NEED_RTNL
,
9161 .cmd
= NL80211_CMD_DISASSOCIATE
,
9162 .doit
= nl80211_disassociate
,
9163 .policy
= nl80211_policy
,
9164 .flags
= GENL_ADMIN_PERM
,
9165 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9166 NL80211_FLAG_NEED_RTNL
,
9169 .cmd
= NL80211_CMD_JOIN_IBSS
,
9170 .doit
= nl80211_join_ibss
,
9171 .policy
= nl80211_policy
,
9172 .flags
= GENL_ADMIN_PERM
,
9173 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9174 NL80211_FLAG_NEED_RTNL
,
9177 .cmd
= NL80211_CMD_LEAVE_IBSS
,
9178 .doit
= nl80211_leave_ibss
,
9179 .policy
= nl80211_policy
,
9180 .flags
= GENL_ADMIN_PERM
,
9181 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9182 NL80211_FLAG_NEED_RTNL
,
9184 #ifdef CONFIG_NL80211_TESTMODE
9186 .cmd
= NL80211_CMD_TESTMODE
,
9187 .doit
= nl80211_testmode_do
,
9188 .dumpit
= nl80211_testmode_dump
,
9189 .policy
= nl80211_policy
,
9190 .flags
= GENL_ADMIN_PERM
,
9191 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9192 NL80211_FLAG_NEED_RTNL
,
9196 .cmd
= NL80211_CMD_CONNECT
,
9197 .doit
= nl80211_connect
,
9198 .policy
= nl80211_policy
,
9199 .flags
= GENL_ADMIN_PERM
,
9200 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9201 NL80211_FLAG_NEED_RTNL
,
9204 .cmd
= NL80211_CMD_DISCONNECT
,
9205 .doit
= nl80211_disconnect
,
9206 .policy
= nl80211_policy
,
9207 .flags
= GENL_ADMIN_PERM
,
9208 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9209 NL80211_FLAG_NEED_RTNL
,
9212 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
9213 .doit
= nl80211_wiphy_netns
,
9214 .policy
= nl80211_policy
,
9215 .flags
= GENL_ADMIN_PERM
,
9216 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9217 NL80211_FLAG_NEED_RTNL
,
9220 .cmd
= NL80211_CMD_GET_SURVEY
,
9221 .policy
= nl80211_policy
,
9222 .dumpit
= nl80211_dump_survey
,
9225 .cmd
= NL80211_CMD_SET_PMKSA
,
9226 .doit
= nl80211_setdel_pmksa
,
9227 .policy
= nl80211_policy
,
9228 .flags
= GENL_ADMIN_PERM
,
9229 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9230 NL80211_FLAG_NEED_RTNL
,
9233 .cmd
= NL80211_CMD_DEL_PMKSA
,
9234 .doit
= nl80211_setdel_pmksa
,
9235 .policy
= nl80211_policy
,
9236 .flags
= GENL_ADMIN_PERM
,
9237 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9238 NL80211_FLAG_NEED_RTNL
,
9241 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
9242 .doit
= nl80211_flush_pmksa
,
9243 .policy
= nl80211_policy
,
9244 .flags
= GENL_ADMIN_PERM
,
9245 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9246 NL80211_FLAG_NEED_RTNL
,
9249 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
9250 .doit
= nl80211_remain_on_channel
,
9251 .policy
= nl80211_policy
,
9252 .flags
= GENL_ADMIN_PERM
,
9253 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9254 NL80211_FLAG_NEED_RTNL
,
9257 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9258 .doit
= nl80211_cancel_remain_on_channel
,
9259 .policy
= nl80211_policy
,
9260 .flags
= GENL_ADMIN_PERM
,
9261 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9262 NL80211_FLAG_NEED_RTNL
,
9265 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
9266 .doit
= nl80211_set_tx_bitrate_mask
,
9267 .policy
= nl80211_policy
,
9268 .flags
= GENL_ADMIN_PERM
,
9269 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9270 NL80211_FLAG_NEED_RTNL
,
9273 .cmd
= NL80211_CMD_REGISTER_FRAME
,
9274 .doit
= nl80211_register_mgmt
,
9275 .policy
= nl80211_policy
,
9276 .flags
= GENL_ADMIN_PERM
,
9277 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9278 NL80211_FLAG_NEED_RTNL
,
9281 .cmd
= NL80211_CMD_FRAME
,
9282 .doit
= nl80211_tx_mgmt
,
9283 .policy
= nl80211_policy
,
9284 .flags
= GENL_ADMIN_PERM
,
9285 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9286 NL80211_FLAG_NEED_RTNL
,
9289 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
9290 .doit
= nl80211_tx_mgmt_cancel_wait
,
9291 .policy
= nl80211_policy
,
9292 .flags
= GENL_ADMIN_PERM
,
9293 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9294 NL80211_FLAG_NEED_RTNL
,
9297 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
9298 .doit
= nl80211_set_power_save
,
9299 .policy
= nl80211_policy
,
9300 .flags
= GENL_ADMIN_PERM
,
9301 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9302 NL80211_FLAG_NEED_RTNL
,
9305 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
9306 .doit
= nl80211_get_power_save
,
9307 .policy
= nl80211_policy
,
9308 /* can be retrieved by unprivileged users */
9309 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9310 NL80211_FLAG_NEED_RTNL
,
9313 .cmd
= NL80211_CMD_SET_CQM
,
9314 .doit
= nl80211_set_cqm
,
9315 .policy
= nl80211_policy
,
9316 .flags
= GENL_ADMIN_PERM
,
9317 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9318 NL80211_FLAG_NEED_RTNL
,
9321 .cmd
= NL80211_CMD_SET_CHANNEL
,
9322 .doit
= nl80211_set_channel
,
9323 .policy
= nl80211_policy
,
9324 .flags
= GENL_ADMIN_PERM
,
9325 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9326 NL80211_FLAG_NEED_RTNL
,
9329 .cmd
= NL80211_CMD_SET_WDS_PEER
,
9330 .doit
= nl80211_set_wds_peer
,
9331 .policy
= nl80211_policy
,
9332 .flags
= GENL_ADMIN_PERM
,
9333 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9334 NL80211_FLAG_NEED_RTNL
,
9337 .cmd
= NL80211_CMD_JOIN_MESH
,
9338 .doit
= nl80211_join_mesh
,
9339 .policy
= nl80211_policy
,
9340 .flags
= GENL_ADMIN_PERM
,
9341 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9342 NL80211_FLAG_NEED_RTNL
,
9345 .cmd
= NL80211_CMD_LEAVE_MESH
,
9346 .doit
= nl80211_leave_mesh
,
9347 .policy
= nl80211_policy
,
9348 .flags
= GENL_ADMIN_PERM
,
9349 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9350 NL80211_FLAG_NEED_RTNL
,
9354 .cmd
= NL80211_CMD_GET_WOWLAN
,
9355 .doit
= nl80211_get_wowlan
,
9356 .policy
= nl80211_policy
,
9357 /* can be retrieved by unprivileged users */
9358 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9359 NL80211_FLAG_NEED_RTNL
,
9362 .cmd
= NL80211_CMD_SET_WOWLAN
,
9363 .doit
= nl80211_set_wowlan
,
9364 .policy
= nl80211_policy
,
9365 .flags
= GENL_ADMIN_PERM
,
9366 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9367 NL80211_FLAG_NEED_RTNL
,
9371 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
9372 .doit
= nl80211_set_rekey_data
,
9373 .policy
= nl80211_policy
,
9374 .flags
= GENL_ADMIN_PERM
,
9375 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9376 NL80211_FLAG_NEED_RTNL
,
9379 .cmd
= NL80211_CMD_TDLS_MGMT
,
9380 .doit
= nl80211_tdls_mgmt
,
9381 .policy
= nl80211_policy
,
9382 .flags
= GENL_ADMIN_PERM
,
9383 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9384 NL80211_FLAG_NEED_RTNL
,
9387 .cmd
= NL80211_CMD_TDLS_OPER
,
9388 .doit
= nl80211_tdls_oper
,
9389 .policy
= nl80211_policy
,
9390 .flags
= GENL_ADMIN_PERM
,
9391 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9392 NL80211_FLAG_NEED_RTNL
,
9395 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
9396 .doit
= nl80211_register_unexpected_frame
,
9397 .policy
= nl80211_policy
,
9398 .flags
= GENL_ADMIN_PERM
,
9399 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9400 NL80211_FLAG_NEED_RTNL
,
9403 .cmd
= NL80211_CMD_PROBE_CLIENT
,
9404 .doit
= nl80211_probe_client
,
9405 .policy
= nl80211_policy
,
9406 .flags
= GENL_ADMIN_PERM
,
9407 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9408 NL80211_FLAG_NEED_RTNL
,
9411 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
9412 .doit
= nl80211_register_beacons
,
9413 .policy
= nl80211_policy
,
9414 .flags
= GENL_ADMIN_PERM
,
9415 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9416 NL80211_FLAG_NEED_RTNL
,
9419 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
9420 .doit
= nl80211_set_noack_map
,
9421 .policy
= nl80211_policy
,
9422 .flags
= GENL_ADMIN_PERM
,
9423 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9424 NL80211_FLAG_NEED_RTNL
,
9427 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
9428 .doit
= nl80211_start_p2p_device
,
9429 .policy
= nl80211_policy
,
9430 .flags
= GENL_ADMIN_PERM
,
9431 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
9432 NL80211_FLAG_NEED_RTNL
,
9435 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
9436 .doit
= nl80211_stop_p2p_device
,
9437 .policy
= nl80211_policy
,
9438 .flags
= GENL_ADMIN_PERM
,
9439 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9440 NL80211_FLAG_NEED_RTNL
,
9443 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
9444 .doit
= nl80211_set_mcast_rate
,
9445 .policy
= nl80211_policy
,
9446 .flags
= GENL_ADMIN_PERM
,
9447 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9448 NL80211_FLAG_NEED_RTNL
,
9451 .cmd
= NL80211_CMD_SET_MAC_ACL
,
9452 .doit
= nl80211_set_mac_acl
,
9453 .policy
= nl80211_policy
,
9454 .flags
= GENL_ADMIN_PERM
,
9455 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
9456 NL80211_FLAG_NEED_RTNL
,
9459 .cmd
= NL80211_CMD_RADAR_DETECT
,
9460 .doit
= nl80211_start_radar_detection
,
9461 .policy
= nl80211_policy
,
9462 .flags
= GENL_ADMIN_PERM
,
9463 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9464 NL80211_FLAG_NEED_RTNL
,
9467 .cmd
= NL80211_CMD_GET_PROTOCOL_FEATURES
,
9468 .doit
= nl80211_get_protocol_features
,
9469 .policy
= nl80211_policy
,
9472 .cmd
= NL80211_CMD_UPDATE_FT_IES
,
9473 .doit
= nl80211_update_ft_ies
,
9474 .policy
= nl80211_policy
,
9475 .flags
= GENL_ADMIN_PERM
,
9476 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9477 NL80211_FLAG_NEED_RTNL
,
9480 .cmd
= NL80211_CMD_CRIT_PROTOCOL_START
,
9481 .doit
= nl80211_crit_protocol_start
,
9482 .policy
= nl80211_policy
,
9483 .flags
= GENL_ADMIN_PERM
,
9484 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9485 NL80211_FLAG_NEED_RTNL
,
9488 .cmd
= NL80211_CMD_CRIT_PROTOCOL_STOP
,
9489 .doit
= nl80211_crit_protocol_stop
,
9490 .policy
= nl80211_policy
,
9491 .flags
= GENL_ADMIN_PERM
,
9492 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
9493 NL80211_FLAG_NEED_RTNL
,
9496 .cmd
= NL80211_CMD_GET_COALESCE
,
9497 .doit
= nl80211_get_coalesce
,
9498 .policy
= nl80211_policy
,
9499 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9500 NL80211_FLAG_NEED_RTNL
,
9503 .cmd
= NL80211_CMD_SET_COALESCE
,
9504 .doit
= nl80211_set_coalesce
,
9505 .policy
= nl80211_policy
,
9506 .flags
= GENL_ADMIN_PERM
,
9507 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
9508 NL80211_FLAG_NEED_RTNL
,
9511 .cmd
= NL80211_CMD_CHANNEL_SWITCH
,
9512 .doit
= nl80211_channel_switch
,
9513 .policy
= nl80211_policy
,
9514 .flags
= GENL_ADMIN_PERM
,
9515 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
9516 NL80211_FLAG_NEED_RTNL
,
9520 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
9524 /* multicast groups */
9525 static struct genl_multicast_group nl80211_config_mcgrp
= {
9528 static struct genl_multicast_group nl80211_scan_mcgrp
= {
9531 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
9532 .name
= "regulatory",
9535 /* notification functions */
9537 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
9539 struct sk_buff
*msg
;
9540 struct nl80211_dump_wiphy_state state
= {};
9542 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9546 if (nl80211_send_wiphy(rdev
, msg
, 0, 0, 0, &state
) < 0) {
9551 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9552 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
9555 static int nl80211_add_scan_req(struct sk_buff
*msg
,
9556 struct cfg80211_registered_device
*rdev
)
9558 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
9559 struct nlattr
*nest
;
9565 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
9567 goto nla_put_failure
;
9568 for (i
= 0; i
< req
->n_ssids
; i
++) {
9569 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
9570 goto nla_put_failure
;
9572 nla_nest_end(msg
, nest
);
9574 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
9576 goto nla_put_failure
;
9577 for (i
= 0; i
< req
->n_channels
; i
++) {
9578 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
9579 goto nla_put_failure
;
9581 nla_nest_end(msg
, nest
);
9584 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
9585 goto nla_put_failure
;
9588 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
9595 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
9596 struct cfg80211_registered_device
*rdev
,
9597 struct wireless_dev
*wdev
,
9598 u32 portid
, u32 seq
, int flags
,
9603 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9607 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9608 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9609 wdev
->netdev
->ifindex
)) ||
9610 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9611 goto nla_put_failure
;
9613 /* ignore errors and send incomplete event anyway */
9614 nl80211_add_scan_req(msg
, rdev
);
9616 return genlmsg_end(msg
, hdr
);
9619 genlmsg_cancel(msg
, hdr
);
9624 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
9625 struct cfg80211_registered_device
*rdev
,
9626 struct net_device
*netdev
,
9627 u32 portid
, u32 seq
, int flags
, u32 cmd
)
9631 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
9635 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9636 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9637 goto nla_put_failure
;
9639 return genlmsg_end(msg
, hdr
);
9642 genlmsg_cancel(msg
, hdr
);
9646 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
9647 struct wireless_dev
*wdev
)
9649 struct sk_buff
*msg
;
9651 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9655 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9656 NL80211_CMD_TRIGGER_SCAN
) < 0) {
9661 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9662 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9665 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
9666 struct wireless_dev
*wdev
)
9668 struct sk_buff
*msg
;
9670 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9674 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9675 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
9680 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9681 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9684 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
9685 struct wireless_dev
*wdev
)
9687 struct sk_buff
*msg
;
9689 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9693 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
9694 NL80211_CMD_SCAN_ABORTED
) < 0) {
9699 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9700 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9703 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
9704 struct net_device
*netdev
)
9706 struct sk_buff
*msg
;
9708 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9712 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
9713 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
9718 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9719 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9722 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
9723 struct net_device
*netdev
, u32 cmd
)
9725 struct sk_buff
*msg
;
9727 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9731 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
9736 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9737 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
9741 * This can happen on global regulatory changes or device specific settings
9742 * based on custom world regulatory domains.
9744 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
9746 struct sk_buff
*msg
;
9749 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9753 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
9759 /* Userspace can always count this one always being set */
9760 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
9761 goto nla_put_failure
;
9763 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
9764 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9765 NL80211_REGDOM_TYPE_WORLD
))
9766 goto nla_put_failure
;
9767 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
9768 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9769 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
9770 goto nla_put_failure
;
9771 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
9772 request
->intersect
) {
9773 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9774 NL80211_REGDOM_TYPE_INTERSECTION
))
9775 goto nla_put_failure
;
9777 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
9778 NL80211_REGDOM_TYPE_COUNTRY
) ||
9779 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
9781 goto nla_put_failure
;
9784 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
9785 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
9786 goto nla_put_failure
;
9788 genlmsg_end(msg
, hdr
);
9791 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9798 genlmsg_cancel(msg
, hdr
);
9802 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
9803 struct net_device
*netdev
,
9804 const u8
*buf
, size_t len
,
9805 enum nl80211_commands cmd
, gfp_t gfp
)
9807 struct sk_buff
*msg
;
9810 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9814 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9820 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9821 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9822 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9823 goto nla_put_failure
;
9825 genlmsg_end(msg
, hdr
);
9827 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9828 nl80211_mlme_mcgrp
.id
, gfp
);
9832 genlmsg_cancel(msg
, hdr
);
9836 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
9837 struct net_device
*netdev
, const u8
*buf
,
9838 size_t len
, gfp_t gfp
)
9840 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9841 NL80211_CMD_AUTHENTICATE
, gfp
);
9844 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
9845 struct net_device
*netdev
, const u8
*buf
,
9846 size_t len
, gfp_t gfp
)
9848 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9849 NL80211_CMD_ASSOCIATE
, gfp
);
9852 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
9853 struct net_device
*netdev
, const u8
*buf
,
9854 size_t len
, gfp_t gfp
)
9856 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9857 NL80211_CMD_DEAUTHENTICATE
, gfp
);
9860 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
9861 struct net_device
*netdev
, const u8
*buf
,
9862 size_t len
, gfp_t gfp
)
9864 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
9865 NL80211_CMD_DISASSOCIATE
, gfp
);
9868 void cfg80211_rx_unprot_mlme_mgmt(struct net_device
*dev
, const u8
*buf
,
9871 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9872 struct wiphy
*wiphy
= wdev
->wiphy
;
9873 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9874 const struct ieee80211_mgmt
*mgmt
= (void *)buf
;
9877 if (WARN_ON(len
< 2))
9880 if (ieee80211_is_deauth(mgmt
->frame_control
))
9881 cmd
= NL80211_CMD_UNPROT_DEAUTHENTICATE
;
9883 cmd
= NL80211_CMD_UNPROT_DISASSOCIATE
;
9885 trace_cfg80211_rx_unprot_mlme_mgmt(dev
, buf
, len
);
9886 nl80211_send_mlme_event(rdev
, dev
, buf
, len
, cmd
, GFP_ATOMIC
);
9888 EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt
);
9890 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
9891 struct net_device
*netdev
, int cmd
,
9892 const u8
*addr
, gfp_t gfp
)
9894 struct sk_buff
*msg
;
9897 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9901 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9907 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9908 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9909 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
9910 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9911 goto nla_put_failure
;
9913 genlmsg_end(msg
, hdr
);
9915 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9916 nl80211_mlme_mcgrp
.id
, gfp
);
9920 genlmsg_cancel(msg
, hdr
);
9924 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
9925 struct net_device
*netdev
, const u8
*addr
,
9928 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
9932 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
9933 struct net_device
*netdev
, const u8
*addr
,
9936 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
9940 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
9941 struct net_device
*netdev
, const u8
*bssid
,
9942 const u8
*req_ie
, size_t req_ie_len
,
9943 const u8
*resp_ie
, size_t resp_ie_len
,
9944 u16 status
, gfp_t gfp
)
9946 struct sk_buff
*msg
;
9949 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9953 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
9959 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9960 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9961 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
9962 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
9964 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
9966 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
9967 goto nla_put_failure
;
9969 genlmsg_end(msg
, hdr
);
9971 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9972 nl80211_mlme_mcgrp
.id
, gfp
);
9976 genlmsg_cancel(msg
, hdr
);
9981 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
9982 struct net_device
*netdev
, const u8
*bssid
,
9983 const u8
*req_ie
, size_t req_ie_len
,
9984 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
9986 struct sk_buff
*msg
;
9989 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9993 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
9999 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10000 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10001 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
10003 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
10005 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
10006 goto nla_put_failure
;
10008 genlmsg_end(msg
, hdr
);
10010 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10011 nl80211_mlme_mcgrp
.id
, gfp
);
10015 genlmsg_cancel(msg
, hdr
);
10020 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
10021 struct net_device
*netdev
, u16 reason
,
10022 const u8
*ie
, size_t ie_len
, bool from_ap
)
10024 struct sk_buff
*msg
;
10027 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
10031 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
10037 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10038 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10039 (from_ap
&& reason
&&
10040 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
10042 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
10043 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
10044 goto nla_put_failure
;
10046 genlmsg_end(msg
, hdr
);
10048 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10049 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
10053 genlmsg_cancel(msg
, hdr
);
10058 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
10059 struct net_device
*netdev
, const u8
*bssid
,
10062 struct sk_buff
*msg
;
10065 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10069 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
10075 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10076 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10077 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10078 goto nla_put_failure
;
10080 genlmsg_end(msg
, hdr
);
10082 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10083 nl80211_mlme_mcgrp
.id
, gfp
);
10087 genlmsg_cancel(msg
, hdr
);
10091 void cfg80211_notify_new_peer_candidate(struct net_device
*dev
, const u8
*addr
,
10092 const u8
* ie
, u8 ie_len
, gfp_t gfp
)
10094 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10095 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10096 struct sk_buff
*msg
;
10099 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
))
10102 trace_cfg80211_notify_new_peer_candidate(dev
, addr
);
10104 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10108 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
10114 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10115 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10116 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10118 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
10119 goto nla_put_failure
;
10121 genlmsg_end(msg
, hdr
);
10123 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10124 nl80211_mlme_mcgrp
.id
, gfp
);
10128 genlmsg_cancel(msg
, hdr
);
10131 EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate
);
10133 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
10134 struct net_device
*netdev
, const u8
*addr
,
10135 enum nl80211_key_type key_type
, int key_id
,
10136 const u8
*tsc
, gfp_t gfp
)
10138 struct sk_buff
*msg
;
10141 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10145 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
10151 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10152 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10153 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
10154 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
10156 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
10157 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
10158 goto nla_put_failure
;
10160 genlmsg_end(msg
, hdr
);
10162 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10163 nl80211_mlme_mcgrp
.id
, gfp
);
10167 genlmsg_cancel(msg
, hdr
);
10171 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
10172 struct ieee80211_channel
*channel_before
,
10173 struct ieee80211_channel
*channel_after
)
10175 struct sk_buff
*msg
;
10177 struct nlattr
*nl_freq
;
10179 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
10183 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
10190 * Since we are applying the beacon hint to a wiphy we know its
10191 * wiphy_idx is valid
10193 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
10194 goto nla_put_failure
;
10197 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
10199 goto nla_put_failure
;
10200 if (nl80211_msg_put_channel(msg
, channel_before
, false))
10201 goto nla_put_failure
;
10202 nla_nest_end(msg
, nl_freq
);
10205 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
10207 goto nla_put_failure
;
10208 if (nl80211_msg_put_channel(msg
, channel_after
, false))
10209 goto nla_put_failure
;
10210 nla_nest_end(msg
, nl_freq
);
10212 genlmsg_end(msg
, hdr
);
10215 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
10222 genlmsg_cancel(msg
, hdr
);
10226 static void nl80211_send_remain_on_chan_event(
10227 int cmd
, struct cfg80211_registered_device
*rdev
,
10228 struct wireless_dev
*wdev
, u64 cookie
,
10229 struct ieee80211_channel
*chan
,
10230 unsigned int duration
, gfp_t gfp
)
10232 struct sk_buff
*msg
;
10235 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10239 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10245 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10246 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10247 wdev
->netdev
->ifindex
)) ||
10248 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10249 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
10250 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10251 NL80211_CHAN_NO_HT
) ||
10252 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
10253 goto nla_put_failure
;
10255 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
10256 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
10257 goto nla_put_failure
;
10259 genlmsg_end(msg
, hdr
);
10261 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10262 nl80211_mlme_mcgrp
.id
, gfp
);
10266 genlmsg_cancel(msg
, hdr
);
10270 void cfg80211_ready_on_channel(struct wireless_dev
*wdev
, u64 cookie
,
10271 struct ieee80211_channel
*chan
,
10272 unsigned int duration
, gfp_t gfp
)
10274 struct wiphy
*wiphy
= wdev
->wiphy
;
10275 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10277 trace_cfg80211_ready_on_channel(wdev
, cookie
, chan
, duration
);
10278 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
10279 rdev
, wdev
, cookie
, chan
,
10282 EXPORT_SYMBOL(cfg80211_ready_on_channel
);
10284 void cfg80211_remain_on_channel_expired(struct wireless_dev
*wdev
, u64 cookie
,
10285 struct ieee80211_channel
*chan
,
10288 struct wiphy
*wiphy
= wdev
->wiphy
;
10289 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10291 trace_cfg80211_ready_on_channel_expired(wdev
, cookie
, chan
);
10292 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
10293 rdev
, wdev
, cookie
, chan
, 0, gfp
);
10295 EXPORT_SYMBOL(cfg80211_remain_on_channel_expired
);
10297 void cfg80211_new_sta(struct net_device
*dev
, const u8
*mac_addr
,
10298 struct station_info
*sinfo
, gfp_t gfp
)
10300 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10301 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10302 struct sk_buff
*msg
;
10304 trace_cfg80211_new_sta(dev
, mac_addr
, sinfo
);
10306 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10310 if (nl80211_send_station(msg
, 0, 0, 0,
10311 rdev
, dev
, mac_addr
, sinfo
) < 0) {
10316 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10317 nl80211_mlme_mcgrp
.id
, gfp
);
10319 EXPORT_SYMBOL(cfg80211_new_sta
);
10321 void cfg80211_del_sta(struct net_device
*dev
, const u8
*mac_addr
, gfp_t gfp
)
10323 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10324 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10325 struct sk_buff
*msg
;
10328 trace_cfg80211_del_sta(dev
, mac_addr
);
10330 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10334 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
10340 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10341 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
10342 goto nla_put_failure
;
10344 genlmsg_end(msg
, hdr
);
10346 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10347 nl80211_mlme_mcgrp
.id
, gfp
);
10351 genlmsg_cancel(msg
, hdr
);
10354 EXPORT_SYMBOL(cfg80211_del_sta
);
10356 void cfg80211_conn_failed(struct net_device
*dev
, const u8
*mac_addr
,
10357 enum nl80211_connect_failed_reason reason
,
10360 struct wiphy
*wiphy
= dev
->ieee80211_ptr
->wiphy
;
10361 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10362 struct sk_buff
*msg
;
10365 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10369 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
10375 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10376 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
10377 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
10378 goto nla_put_failure
;
10380 genlmsg_end(msg
, hdr
);
10382 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10383 nl80211_mlme_mcgrp
.id
, gfp
);
10387 genlmsg_cancel(msg
, hdr
);
10390 EXPORT_SYMBOL(cfg80211_conn_failed
);
10392 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
10393 const u8
*addr
, gfp_t gfp
)
10395 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10396 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10397 struct sk_buff
*msg
;
10399 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
10404 msg
= nlmsg_new(100, gfp
);
10408 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
10414 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10415 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10416 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
10417 goto nla_put_failure
;
10419 genlmsg_end(msg
, hdr
);
10420 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10424 genlmsg_cancel(msg
, hdr
);
10429 bool cfg80211_rx_spurious_frame(struct net_device
*dev
,
10430 const u8
*addr
, gfp_t gfp
)
10432 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10435 trace_cfg80211_rx_spurious_frame(dev
, addr
);
10437 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10438 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)) {
10439 trace_cfg80211_return_bool(false);
10442 ret
= __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
10444 trace_cfg80211_return_bool(ret
);
10447 EXPORT_SYMBOL(cfg80211_rx_spurious_frame
);
10449 bool cfg80211_rx_unexpected_4addr_frame(struct net_device
*dev
,
10450 const u8
*addr
, gfp_t gfp
)
10452 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10455 trace_cfg80211_rx_unexpected_4addr_frame(dev
, addr
);
10457 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10458 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10459 wdev
->iftype
!= NL80211_IFTYPE_AP_VLAN
)) {
10460 trace_cfg80211_return_bool(false);
10463 ret
= __nl80211_unexpected_frame(dev
,
10464 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
10466 trace_cfg80211_return_bool(ret
);
10469 EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame
);
10471 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
10472 struct wireless_dev
*wdev
, u32 nlportid
,
10473 int freq
, int sig_dbm
,
10474 const u8
*buf
, size_t len
, u32 flags
, gfp_t gfp
)
10476 struct net_device
*netdev
= wdev
->netdev
;
10477 struct sk_buff
*msg
;
10480 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10484 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10490 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10491 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10492 netdev
->ifindex
)) ||
10493 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10494 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
10496 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10497 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10499 nla_put_u32(msg
, NL80211_ATTR_RXMGMT_FLAGS
, flags
)))
10500 goto nla_put_failure
;
10502 genlmsg_end(msg
, hdr
);
10504 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
10507 genlmsg_cancel(msg
, hdr
);
10512 void cfg80211_mgmt_tx_status(struct wireless_dev
*wdev
, u64 cookie
,
10513 const u8
*buf
, size_t len
, bool ack
, gfp_t gfp
)
10515 struct wiphy
*wiphy
= wdev
->wiphy
;
10516 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10517 struct net_device
*netdev
= wdev
->netdev
;
10518 struct sk_buff
*msg
;
10521 trace_cfg80211_mgmt_tx_status(wdev
, cookie
, ack
);
10523 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10527 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
10533 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10534 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
10535 netdev
->ifindex
)) ||
10536 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
10537 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
10538 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10539 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10540 goto nla_put_failure
;
10542 genlmsg_end(msg
, hdr
);
10544 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10545 nl80211_mlme_mcgrp
.id
, gfp
);
10549 genlmsg_cancel(msg
, hdr
);
10552 EXPORT_SYMBOL(cfg80211_mgmt_tx_status
);
10554 void cfg80211_cqm_rssi_notify(struct net_device
*dev
,
10555 enum nl80211_cqm_rssi_threshold_event rssi_event
,
10558 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10559 struct wiphy
*wiphy
= wdev
->wiphy
;
10560 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10561 struct sk_buff
*msg
;
10562 struct nlattr
*pinfoattr
;
10565 trace_cfg80211_cqm_rssi_notify(dev
, rssi_event
);
10567 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10571 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10577 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10578 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
10579 goto nla_put_failure
;
10581 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10583 goto nla_put_failure
;
10585 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
10587 goto nla_put_failure
;
10589 nla_nest_end(msg
, pinfoattr
);
10591 genlmsg_end(msg
, hdr
);
10593 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10594 nl80211_mlme_mcgrp
.id
, gfp
);
10598 genlmsg_cancel(msg
, hdr
);
10601 EXPORT_SYMBOL(cfg80211_cqm_rssi_notify
);
10603 static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
10604 struct net_device
*netdev
, const u8
*bssid
,
10605 const u8
*replay_ctr
, gfp_t gfp
)
10607 struct sk_buff
*msg
;
10608 struct nlattr
*rekey_attr
;
10611 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10615 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10621 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10622 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10623 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
10624 goto nla_put_failure
;
10626 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10628 goto nla_put_failure
;
10630 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
10631 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
10632 goto nla_put_failure
;
10634 nla_nest_end(msg
, rekey_attr
);
10636 genlmsg_end(msg
, hdr
);
10638 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10639 nl80211_mlme_mcgrp
.id
, gfp
);
10643 genlmsg_cancel(msg
, hdr
);
10647 void cfg80211_gtk_rekey_notify(struct net_device
*dev
, const u8
*bssid
,
10648 const u8
*replay_ctr
, gfp_t gfp
)
10650 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10651 struct wiphy
*wiphy
= wdev
->wiphy
;
10652 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10654 trace_cfg80211_gtk_rekey_notify(dev
, bssid
);
10655 nl80211_gtk_rekey_notify(rdev
, dev
, bssid
, replay_ctr
, gfp
);
10657 EXPORT_SYMBOL(cfg80211_gtk_rekey_notify
);
10660 nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
10661 struct net_device
*netdev
, int index
,
10662 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10664 struct sk_buff
*msg
;
10665 struct nlattr
*attr
;
10668 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10672 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
10678 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10679 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10680 goto nla_put_failure
;
10682 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
10684 goto nla_put_failure
;
10686 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
10687 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
10689 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
10690 goto nla_put_failure
;
10692 nla_nest_end(msg
, attr
);
10694 genlmsg_end(msg
, hdr
);
10696 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10697 nl80211_mlme_mcgrp
.id
, gfp
);
10701 genlmsg_cancel(msg
, hdr
);
10705 void cfg80211_pmksa_candidate_notify(struct net_device
*dev
, int index
,
10706 const u8
*bssid
, bool preauth
, gfp_t gfp
)
10708 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10709 struct wiphy
*wiphy
= wdev
->wiphy
;
10710 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10712 trace_cfg80211_pmksa_candidate_notify(dev
, index
, bssid
, preauth
);
10713 nl80211_pmksa_candidate_notify(rdev
, dev
, index
, bssid
, preauth
, gfp
);
10715 EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify
);
10717 static void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
10718 struct net_device
*netdev
,
10719 struct cfg80211_chan_def
*chandef
,
10722 struct sk_buff
*msg
;
10725 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10729 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
10735 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
10736 goto nla_put_failure
;
10738 if (nl80211_send_chandef(msg
, chandef
))
10739 goto nla_put_failure
;
10741 genlmsg_end(msg
, hdr
);
10743 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10744 nl80211_mlme_mcgrp
.id
, gfp
);
10748 genlmsg_cancel(msg
, hdr
);
10752 void cfg80211_ch_switch_notify(struct net_device
*dev
,
10753 struct cfg80211_chan_def
*chandef
)
10755 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10756 struct wiphy
*wiphy
= wdev
->wiphy
;
10757 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10759 trace_cfg80211_ch_switch_notify(dev
, chandef
);
10763 if (WARN_ON(wdev
->iftype
!= NL80211_IFTYPE_AP
&&
10764 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
10765 wdev
->iftype
!= NL80211_IFTYPE_ADHOC
))
10768 wdev
->channel
= chandef
->chan
;
10769 nl80211_ch_switch_notify(rdev
, dev
, chandef
, GFP_KERNEL
);
10774 EXPORT_SYMBOL(cfg80211_ch_switch_notify
);
10776 void cfg80211_cqm_txe_notify(struct net_device
*dev
,
10777 const u8
*peer
, u32 num_packets
,
10778 u32 rate
, u32 intvl
, gfp_t gfp
)
10780 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10781 struct wiphy
*wiphy
= wdev
->wiphy
;
10782 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10783 struct sk_buff
*msg
;
10784 struct nlattr
*pinfoattr
;
10787 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
10791 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10797 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10798 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10799 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10800 goto nla_put_failure
;
10802 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10804 goto nla_put_failure
;
10806 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
10807 goto nla_put_failure
;
10809 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
10810 goto nla_put_failure
;
10812 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
10813 goto nla_put_failure
;
10815 nla_nest_end(msg
, pinfoattr
);
10817 genlmsg_end(msg
, hdr
);
10819 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10820 nl80211_mlme_mcgrp
.id
, gfp
);
10824 genlmsg_cancel(msg
, hdr
);
10827 EXPORT_SYMBOL(cfg80211_cqm_txe_notify
);
10830 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
10831 struct cfg80211_chan_def
*chandef
,
10832 enum nl80211_radar_event event
,
10833 struct net_device
*netdev
, gfp_t gfp
)
10835 struct sk_buff
*msg
;
10838 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10842 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
10848 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
10849 goto nla_put_failure
;
10851 /* NOP and radar events don't need a netdev parameter */
10853 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
10855 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
10856 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
10857 goto nla_put_failure
;
10860 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
10861 goto nla_put_failure
;
10863 if (nl80211_send_chandef(msg
, chandef
))
10864 goto nla_put_failure
;
10866 genlmsg_end(msg
, hdr
);
10868 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10869 nl80211_mlme_mcgrp
.id
, gfp
);
10873 genlmsg_cancel(msg
, hdr
);
10877 void cfg80211_cqm_pktloss_notify(struct net_device
*dev
,
10878 const u8
*peer
, u32 num_packets
, gfp_t gfp
)
10880 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10881 struct wiphy
*wiphy
= wdev
->wiphy
;
10882 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10883 struct sk_buff
*msg
;
10884 struct nlattr
*pinfoattr
;
10887 trace_cfg80211_cqm_pktloss_notify(dev
, peer
, num_packets
);
10889 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10893 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
10899 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10900 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10901 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
10902 goto nla_put_failure
;
10904 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
10906 goto nla_put_failure
;
10908 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
10909 goto nla_put_failure
;
10911 nla_nest_end(msg
, pinfoattr
);
10913 genlmsg_end(msg
, hdr
);
10915 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10916 nl80211_mlme_mcgrp
.id
, gfp
);
10920 genlmsg_cancel(msg
, hdr
);
10923 EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify
);
10925 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
10926 u64 cookie
, bool acked
, gfp_t gfp
)
10928 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
10929 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
10930 struct sk_buff
*msg
;
10933 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
10935 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10940 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
10946 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10947 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10948 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
10949 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
10950 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
10951 goto nla_put_failure
;
10953 genlmsg_end(msg
, hdr
);
10955 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10956 nl80211_mlme_mcgrp
.id
, gfp
);
10960 genlmsg_cancel(msg
, hdr
);
10963 EXPORT_SYMBOL(cfg80211_probe_status
);
10965 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
10966 const u8
*frame
, size_t len
,
10967 int freq
, int sig_dbm
)
10969 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
10970 struct sk_buff
*msg
;
10972 struct cfg80211_beacon_registration
*reg
;
10974 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
10976 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10977 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
10978 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
10980 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10984 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
10986 goto nla_put_failure
;
10988 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10990 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
10992 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
10993 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
10994 goto nla_put_failure
;
10996 genlmsg_end(msg
, hdr
);
10998 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
11000 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11004 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11006 genlmsg_cancel(msg
, hdr
);
11009 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
11012 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
11013 struct cfg80211_wowlan_wakeup
*wakeup
,
11016 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
11017 struct sk_buff
*msg
;
11021 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
11024 size
+= wakeup
->packet_present_len
;
11026 msg
= nlmsg_new(size
, gfp
);
11030 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
11034 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11035 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11038 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
11039 wdev
->netdev
->ifindex
))
11043 struct nlattr
*reasons
;
11045 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
11047 if (wakeup
->disconnect
&&
11048 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
11050 if (wakeup
->magic_pkt
&&
11051 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
11053 if (wakeup
->gtk_rekey_failure
&&
11054 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
11056 if (wakeup
->eap_identity_req
&&
11057 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
11059 if (wakeup
->four_way_handshake
&&
11060 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
11062 if (wakeup
->rfkill_release
&&
11063 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
11066 if (wakeup
->pattern_idx
>= 0 &&
11067 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
11068 wakeup
->pattern_idx
))
11071 if (wakeup
->tcp_match
)
11072 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
11074 if (wakeup
->tcp_connlost
)
11076 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
11078 if (wakeup
->tcp_nomoretokens
)
11080 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
11082 if (wakeup
->packet
) {
11083 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
11084 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
11086 if (!wakeup
->packet_80211
) {
11088 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
11090 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
11093 if (wakeup
->packet_len
&&
11094 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
11097 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
11102 nla_nest_end(msg
, reasons
);
11105 genlmsg_end(msg
, hdr
);
11107 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
11108 nl80211_mlme_mcgrp
.id
, gfp
);
11114 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
11117 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
11118 enum nl80211_tdls_operation oper
,
11119 u16 reason_code
, gfp_t gfp
)
11121 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
11122 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
11123 struct sk_buff
*msg
;
11126 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
11129 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11133 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
11139 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11140 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
11141 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
11142 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
11143 (reason_code
> 0 &&
11144 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
11145 goto nla_put_failure
;
11147 genlmsg_end(msg
, hdr
);
11149 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
11150 nl80211_mlme_mcgrp
.id
, gfp
);
11154 genlmsg_cancel(msg
, hdr
);
11157 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
11159 static int nl80211_netlink_notify(struct notifier_block
* nb
,
11160 unsigned long state
,
11163 struct netlink_notify
*notify
= _notify
;
11164 struct cfg80211_registered_device
*rdev
;
11165 struct wireless_dev
*wdev
;
11166 struct cfg80211_beacon_registration
*reg
, *tmp
;
11168 if (state
!= NETLINK_URELEASE
)
11169 return NOTIFY_DONE
;
11173 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
11174 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
11175 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
11177 spin_lock_bh(&rdev
->beacon_registrations_lock
);
11178 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
11180 if (reg
->nlportid
== notify
->portid
) {
11181 list_del(®
->list
);
11186 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
11191 return NOTIFY_DONE
;
11194 static struct notifier_block nl80211_netlink_notifier
= {
11195 .notifier_call
= nl80211_netlink_notify
,
11198 void cfg80211_ft_event(struct net_device
*netdev
,
11199 struct cfg80211_ft_event_params
*ft_event
)
11201 struct wiphy
*wiphy
= netdev
->ieee80211_ptr
->wiphy
;
11202 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
11203 struct sk_buff
*msg
;
11206 trace_cfg80211_ft_event(wiphy
, netdev
, ft_event
);
11208 if (!ft_event
->target_ap
)
11211 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
11215 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FT_EVENT
);
11221 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
11222 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
11223 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, ft_event
->target_ap
);
11225 nla_put(msg
, NL80211_ATTR_IE
, ft_event
->ies_len
, ft_event
->ies
);
11226 if (ft_event
->ric_ies
)
11227 nla_put(msg
, NL80211_ATTR_IE_RIC
, ft_event
->ric_ies_len
,
11228 ft_event
->ric_ies
);
11230 genlmsg_end(msg
, hdr
);
11232 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
11233 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
11235 EXPORT_SYMBOL(cfg80211_ft_event
);
11237 void cfg80211_crit_proto_stopped(struct wireless_dev
*wdev
, gfp_t gfp
)
11239 struct cfg80211_registered_device
*rdev
;
11240 struct sk_buff
*msg
;
11244 rdev
= wiphy_to_dev(wdev
->wiphy
);
11245 if (!rdev
->crit_proto_nlportid
)
11248 nlportid
= rdev
->crit_proto_nlportid
;
11249 rdev
->crit_proto_nlportid
= 0;
11251 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
11255 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP
);
11257 goto nla_put_failure
;
11259 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
11260 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
11261 goto nla_put_failure
;
11263 genlmsg_end(msg
, hdr
);
11265 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
11270 genlmsg_cancel(msg
, hdr
);
11274 EXPORT_SYMBOL(cfg80211_crit_proto_stopped
);
11276 /* initialisation/exit functions */
11278 int nl80211_init(void)
11282 err
= genl_register_family_with_ops(&nl80211_fam
,
11283 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
11287 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
11291 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
11295 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
11299 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
11303 #ifdef CONFIG_NL80211_TESTMODE
11304 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
11309 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
11315 genl_unregister_family(&nl80211_fam
);
11319 void nl80211_exit(void)
11321 netlink_unregister_notifier(&nl80211_netlink_notifier
);
11322 genl_unregister_family(&nl80211_fam
);