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", /* 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
];
62 assert_cfg80211_lock();
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 mutex_lock(&rdev
->devlist_mtx
);
84 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
85 if (have_ifidx
&& wdev
->netdev
&&
86 wdev
->netdev
->ifindex
== ifidx
) {
90 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
95 mutex_unlock(&rdev
->devlist_mtx
);
103 return ERR_PTR(-ENODEV
);
106 static struct cfg80211_registered_device
*
107 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
109 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
110 struct net_device
*netdev
;
112 assert_cfg80211_lock();
114 if (!attrs
[NL80211_ATTR_WIPHY
] &&
115 !attrs
[NL80211_ATTR_IFINDEX
] &&
116 !attrs
[NL80211_ATTR_WDEV
])
117 return ERR_PTR(-EINVAL
);
119 if (attrs
[NL80211_ATTR_WIPHY
])
120 rdev
= cfg80211_rdev_by_wiphy_idx(
121 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
123 if (attrs
[NL80211_ATTR_WDEV
]) {
124 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
125 struct wireless_dev
*wdev
;
128 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
130 /* make sure wdev exists */
131 mutex_lock(&tmp
->devlist_mtx
);
132 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
133 if (wdev
->identifier
!= (u32
)wdev_id
)
138 mutex_unlock(&tmp
->devlist_mtx
);
143 if (rdev
&& tmp
!= rdev
)
144 return ERR_PTR(-EINVAL
);
149 if (attrs
[NL80211_ATTR_IFINDEX
]) {
150 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
151 netdev
= dev_get_by_index(netns
, ifindex
);
153 if (netdev
->ieee80211_ptr
)
155 netdev
->ieee80211_ptr
->wiphy
);
161 /* not wireless device -- return error */
163 return ERR_PTR(-EINVAL
);
165 /* mismatch -- return error */
166 if (rdev
&& tmp
!= rdev
)
167 return ERR_PTR(-EINVAL
);
174 return ERR_PTR(-ENODEV
);
176 if (netns
!= wiphy_net(&rdev
->wiphy
))
177 return ERR_PTR(-ENODEV
);
183 * This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
185 * If successful, it returns non-NULL and also locks
186 * the driver's mutex!
188 * This means that you need to call cfg80211_unlock_rdev()
189 * before being allowed to acquire &cfg80211_mutex!
191 * This is necessary because we need to lock the global
192 * mutex to get an item off the list safely, and then
193 * we lock the rdev mutex so it doesn't go away under us.
195 * We don't want to keep cfg80211_mutex locked
196 * for all the time in order to allow requests on
197 * other interfaces to go through at the same time.
199 * The result of this can be a PTR_ERR and hence must
200 * be checked with IS_ERR() for errors.
202 static struct cfg80211_registered_device
*
203 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
205 struct cfg80211_registered_device
*rdev
;
207 mutex_lock(&cfg80211_mutex
);
208 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
210 /* if it is not an error we grab the lock on
211 * it to assure it won't be going away while
212 * we operate on it */
214 mutex_lock(&rdev
->mtx
);
216 mutex_unlock(&cfg80211_mutex
);
221 /* policy for the attributes */
222 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
223 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
224 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
226 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
228 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
229 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
230 [NL80211_ATTR_CHANNEL_WIDTH
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_CENTER_FREQ1
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_CENTER_FREQ2
] = { .type
= NLA_U32
},
234 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
235 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
236 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
237 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
238 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
240 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
241 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
242 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
244 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
245 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
247 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
248 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
249 .len
= WLAN_MAX_KEY_LEN
},
250 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
251 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
253 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
254 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
256 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
257 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
258 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
259 .len
= IEEE80211_MAX_DATA_LEN
},
260 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
261 .len
= IEEE80211_MAX_DATA_LEN
},
262 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
263 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
264 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
265 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
266 .len
= NL80211_MAX_SUPP_RATES
},
267 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
268 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
269 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
270 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
271 .len
= IEEE80211_MAX_MESH_ID_LEN
},
272 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
274 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
275 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
277 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
278 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
279 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
280 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
281 .len
= NL80211_MAX_SUPP_RATES
},
282 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
284 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
285 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
287 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
289 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
290 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
291 .len
= IEEE80211_MAX_DATA_LEN
},
292 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
293 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
295 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
296 .len
= IEEE80211_MAX_SSID_LEN
},
297 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
298 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
299 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
301 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
302 [NL80211_ATTR_STA_FLAGS2
] = {
303 .len
= sizeof(struct nl80211_sta_flag_update
),
305 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
306 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
307 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
308 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
309 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
311 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
312 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
313 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
314 .len
= WLAN_PMKID_LEN
},
315 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
317 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
318 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
319 .len
= IEEE80211_MAX_DATA_LEN
},
320 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
321 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
322 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
323 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
324 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
325 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
326 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
327 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
328 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
329 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
331 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
332 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
333 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
334 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
335 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
336 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
337 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
338 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
339 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
340 .len
= IEEE80211_MAX_DATA_LEN
},
341 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
342 .len
= IEEE80211_MAX_DATA_LEN
},
343 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
345 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
347 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
348 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
351 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
352 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
353 .len
= IEEE80211_MAX_DATA_LEN
},
354 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
355 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
356 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
357 .len
= NL80211_HT_CAPABILITY_LEN
359 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
360 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
361 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
362 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
363 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
364 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
365 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
366 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
367 [NL80211_ATTR_P2P_CTWINDOW
] = { .type
= NLA_U8
},
368 [NL80211_ATTR_P2P_OPPPS
] = { .type
= NLA_U8
},
369 [NL80211_ATTR_ACL_POLICY
] = {. type
= NLA_U32
},
370 [NL80211_ATTR_MAC_ADDRS
] = { .type
= NLA_NESTED
},
371 [NL80211_ATTR_STA_CAPABILITY
] = { .type
= NLA_U16
},
372 [NL80211_ATTR_STA_EXT_CAPABILITY
] = { .type
= NLA_BINARY
, },
375 /* policy for the key attributes */
376 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
377 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
378 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
379 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
380 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
381 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
382 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
383 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
384 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
387 /* policy for the key default flags */
388 static const struct nla_policy
389 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
390 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
391 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
394 /* policy for WoWLAN attributes */
395 static const struct nla_policy
396 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
397 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
398 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
399 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
400 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
401 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
402 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
403 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
404 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
405 [NL80211_WOWLAN_TRIG_TCP_CONNECTION
] = { .type
= NLA_NESTED
},
408 static const struct nla_policy
409 nl80211_wowlan_tcp_policy
[NUM_NL80211_WOWLAN_TCP
] = {
410 [NL80211_WOWLAN_TCP_SRC_IPV4
] = { .type
= NLA_U32
},
411 [NL80211_WOWLAN_TCP_DST_IPV4
] = { .type
= NLA_U32
},
412 [NL80211_WOWLAN_TCP_DST_MAC
] = { .len
= ETH_ALEN
},
413 [NL80211_WOWLAN_TCP_SRC_PORT
] = { .type
= NLA_U16
},
414 [NL80211_WOWLAN_TCP_DST_PORT
] = { .type
= NLA_U16
},
415 [NL80211_WOWLAN_TCP_DATA_PAYLOAD
] = { .len
= 1 },
416 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
] = {
417 .len
= sizeof(struct nl80211_wowlan_tcp_data_seq
)
419 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
] = {
420 .len
= sizeof(struct nl80211_wowlan_tcp_data_token
)
422 [NL80211_WOWLAN_TCP_DATA_INTERVAL
] = { .type
= NLA_U32
},
423 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] = { .len
= 1 },
424 [NL80211_WOWLAN_TCP_WAKE_MASK
] = { .len
= 1 },
427 /* policy for GTK rekey offload attributes */
428 static const struct nla_policy
429 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
430 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
431 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
432 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
435 static const struct nla_policy
436 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
437 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
438 .len
= IEEE80211_MAX_SSID_LEN
},
439 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
442 /* ifidx get helper */
443 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
447 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
448 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
453 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
456 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
462 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
463 struct netlink_callback
*cb
,
464 struct cfg80211_registered_device
**rdev
,
465 struct net_device
**dev
)
467 int ifidx
= cb
->args
[0];
471 ifidx
= nl80211_get_ifidx(cb
);
479 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
485 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
487 err
= PTR_ERR(*rdev
);
497 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
499 cfg80211_unlock_rdev(rdev
);
504 static bool is_valid_ie_attr(const struct nlattr
*attr
)
512 pos
= nla_data(attr
);
533 /* message building helper */
534 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
537 /* since there is no private header just add the generic one */
538 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
541 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
542 struct ieee80211_channel
*chan
)
544 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
546 goto nla_put_failure
;
548 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
549 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
550 goto nla_put_failure
;
551 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
552 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
553 goto nla_put_failure
;
554 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
555 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
556 goto nla_put_failure
;
557 if (chan
->flags
& IEEE80211_CHAN_RADAR
) {
558 u32 time
= elapsed_jiffies_msecs(chan
->dfs_state_entered
);
559 if (nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
560 goto nla_put_failure
;
561 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_STATE
,
563 goto nla_put_failure
;
564 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_DFS_TIME
, time
))
565 goto nla_put_failure
;
567 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
) &&
568 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS
))
569 goto nla_put_failure
;
570 if ((chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
) &&
571 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS
))
572 goto nla_put_failure
;
573 if ((chan
->flags
& IEEE80211_CHAN_NO_80MHZ
) &&
574 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_80MHZ
))
575 goto nla_put_failure
;
576 if ((chan
->flags
& IEEE80211_CHAN_NO_160MHZ
) &&
577 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_160MHZ
))
578 goto nla_put_failure
;
580 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
581 DBM_TO_MBM(chan
->max_power
)))
582 goto nla_put_failure
;
590 /* netlink command implementations */
597 bool def_uni
, def_multi
;
600 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
602 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
603 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
608 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
609 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
618 if (tb
[NL80211_KEY_IDX
])
619 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
621 if (tb
[NL80211_KEY_DATA
]) {
622 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
623 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
626 if (tb
[NL80211_KEY_SEQ
]) {
627 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
628 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
631 if (tb
[NL80211_KEY_CIPHER
])
632 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
634 if (tb
[NL80211_KEY_TYPE
]) {
635 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
636 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
640 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
641 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
642 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
643 tb
[NL80211_KEY_DEFAULT_TYPES
],
644 nl80211_key_default_policy
);
648 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
649 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
655 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
657 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
658 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
659 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
662 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
663 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
664 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
667 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
668 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
670 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
671 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
673 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
674 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
683 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
684 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
685 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
689 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
690 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
691 int err
= nla_parse_nested(
692 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
693 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
694 nl80211_key_default_policy
);
698 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
699 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
705 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
709 memset(k
, 0, sizeof(*k
));
713 if (info
->attrs
[NL80211_ATTR_KEY
])
714 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
716 err
= nl80211_parse_key_old(info
, k
);
721 if (k
->def
&& k
->defmgmt
)
725 if (k
->def_uni
|| !k
->def_multi
)
731 if (k
->idx
< 4 || k
->idx
> 5)
734 if (k
->idx
< 0 || k
->idx
> 3)
737 if (k
->idx
< 0 || k
->idx
> 5)
745 static struct cfg80211_cached_keys
*
746 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
747 struct nlattr
*keys
, bool *no_ht
)
749 struct key_parse parse
;
751 struct cfg80211_cached_keys
*result
;
752 int rem
, err
, def
= 0;
754 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
756 return ERR_PTR(-ENOMEM
);
759 result
->defmgmt
= -1;
761 nla_for_each_nested(key
, keys
, rem
) {
762 memset(&parse
, 0, sizeof(parse
));
765 err
= nl80211_parse_key_new(key
, &parse
);
771 if (parse
.idx
< 0 || parse
.idx
> 4)
777 result
->def
= parse
.idx
;
778 if (!parse
.def_uni
|| !parse
.def_multi
)
780 } else if (parse
.defmgmt
)
782 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
783 parse
.idx
, false, NULL
);
786 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
787 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
788 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
789 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
791 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
792 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
804 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
806 ASSERT_WDEV_LOCK(wdev
);
808 switch (wdev
->iftype
) {
809 case NL80211_IFTYPE_AP
:
810 case NL80211_IFTYPE_AP_VLAN
:
811 case NL80211_IFTYPE_P2P_GO
:
812 case NL80211_IFTYPE_MESH_POINT
:
814 case NL80211_IFTYPE_ADHOC
:
815 if (!wdev
->current_bss
)
818 case NL80211_IFTYPE_STATION
:
819 case NL80211_IFTYPE_P2P_CLIENT
:
820 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
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
,
856 struct nlattr
*nl_combis
;
859 nl_combis
= nla_nest_start(msg
,
860 NL80211_ATTR_INTERFACE_COMBINATIONS
);
862 goto nla_put_failure
;
864 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
865 const struct ieee80211_iface_combination
*c
;
866 struct nlattr
*nl_combi
, *nl_limits
;
868 c
= &wiphy
->iface_combinations
[i
];
870 nl_combi
= nla_nest_start(msg
, i
+ 1);
872 goto nla_put_failure
;
874 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
876 goto nla_put_failure
;
878 for (j
= 0; j
< c
->n_limits
; j
++) {
879 struct nlattr
*nl_limit
;
881 nl_limit
= nla_nest_start(msg
, j
+ 1);
883 goto nla_put_failure
;
884 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
886 goto nla_put_failure
;
887 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
889 goto nla_put_failure
;
890 nla_nest_end(msg
, nl_limit
);
893 nla_nest_end(msg
, nl_limits
);
895 if (c
->beacon_int_infra_match
&&
896 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
897 goto nla_put_failure
;
898 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
899 c
->num_different_channels
) ||
900 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
902 goto nla_put_failure
;
903 if (nla_put_u32(msg
, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
,
904 c
->radar_detect_widths
))
905 goto nla_put_failure
;
907 nla_nest_end(msg
, nl_combi
);
910 nla_nest_end(msg
, nl_combis
);
918 static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device
*rdev
,
921 const struct wiphy_wowlan_tcp_support
*tcp
= rdev
->wiphy
.wowlan
.tcp
;
922 struct nlattr
*nl_tcp
;
927 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
931 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
932 tcp
->data_payload_max
))
935 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
936 tcp
->data_payload_max
))
939 if (tcp
->seq
&& nla_put_flag(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
))
942 if (tcp
->tok
&& nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
943 sizeof(*tcp
->tok
), tcp
->tok
))
946 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
947 tcp
->data_interval_max
))
950 if (nla_put_u32(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
951 tcp
->wake_payload_max
))
954 nla_nest_end(msg
, nl_tcp
);
959 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
960 struct cfg80211_registered_device
*dev
)
963 struct nlattr
*nl_bands
, *nl_band
;
964 struct nlattr
*nl_freqs
, *nl_freq
;
965 struct nlattr
*nl_rates
, *nl_rate
;
966 struct nlattr
*nl_cmds
;
967 enum ieee80211_band band
;
968 struct ieee80211_channel
*chan
;
969 struct ieee80211_rate
*rate
;
971 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
972 dev
->wiphy
.mgmt_stypes
;
974 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
978 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
979 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
980 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
981 cfg80211_rdev_list_generation
) ||
982 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
983 dev
->wiphy
.retry_short
) ||
984 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
985 dev
->wiphy
.retry_long
) ||
986 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
987 dev
->wiphy
.frag_threshold
) ||
988 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
989 dev
->wiphy
.rts_threshold
) ||
990 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
991 dev
->wiphy
.coverage_class
) ||
992 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
993 dev
->wiphy
.max_scan_ssids
) ||
994 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
995 dev
->wiphy
.max_sched_scan_ssids
) ||
996 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
997 dev
->wiphy
.max_scan_ie_len
) ||
998 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
999 dev
->wiphy
.max_sched_scan_ie_len
) ||
1000 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
1001 dev
->wiphy
.max_match_sets
))
1002 goto nla_put_failure
;
1004 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
1005 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
1006 goto nla_put_failure
;
1007 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
1008 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
1009 goto nla_put_failure
;
1010 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
1011 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
1012 goto nla_put_failure
;
1013 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
1014 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
1015 goto nla_put_failure
;
1016 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
1017 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
1018 goto nla_put_failure
;
1019 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
1020 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
1021 goto nla_put_failure
;
1023 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
1024 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
1025 dev
->wiphy
.cipher_suites
))
1026 goto nla_put_failure
;
1028 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
1029 dev
->wiphy
.max_num_pmkids
))
1030 goto nla_put_failure
;
1032 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
1033 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
1034 goto nla_put_failure
;
1036 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
1037 dev
->wiphy
.available_antennas_tx
) ||
1038 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
1039 dev
->wiphy
.available_antennas_rx
))
1040 goto nla_put_failure
;
1042 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
1043 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
1044 dev
->wiphy
.probe_resp_offload
))
1045 goto nla_put_failure
;
1047 if ((dev
->wiphy
.available_antennas_tx
||
1048 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
1049 u32 tx_ant
= 0, rx_ant
= 0;
1051 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
1053 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
1055 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
1057 goto nla_put_failure
;
1061 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
1062 dev
->wiphy
.interface_modes
))
1063 goto nla_put_failure
;
1065 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
1067 goto nla_put_failure
;
1069 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1070 if (!dev
->wiphy
.bands
[band
])
1073 nl_band
= nla_nest_start(msg
, band
);
1075 goto nla_put_failure
;
1078 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
1079 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
1080 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
1081 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
1082 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
1083 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
1084 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
1085 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
1086 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
1087 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
1088 goto nla_put_failure
;
1091 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
1092 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
1093 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
1094 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
1095 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1096 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
1097 goto nla_put_failure
;
1099 /* add frequencies */
1100 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
1102 goto nla_put_failure
;
1104 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
1105 nl_freq
= nla_nest_start(msg
, i
);
1107 goto nla_put_failure
;
1109 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
1111 if (nl80211_msg_put_channel(msg
, chan
))
1112 goto nla_put_failure
;
1114 nla_nest_end(msg
, nl_freq
);
1117 nla_nest_end(msg
, nl_freqs
);
1120 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1122 goto nla_put_failure
;
1124 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
1125 nl_rate
= nla_nest_start(msg
, i
);
1127 goto nla_put_failure
;
1129 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
1130 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1132 goto nla_put_failure
;
1133 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1135 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1136 goto nla_put_failure
;
1138 nla_nest_end(msg
, nl_rate
);
1141 nla_nest_end(msg
, nl_rates
);
1143 nla_nest_end(msg
, nl_band
);
1145 nla_nest_end(msg
, nl_bands
);
1147 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1149 goto nla_put_failure
;
1152 #define CMD(op, n) \
1154 if (dev->ops->op) { \
1156 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1157 goto nla_put_failure; \
1161 CMD(add_virtual_intf
, NEW_INTERFACE
);
1162 CMD(change_virtual_intf
, SET_INTERFACE
);
1163 CMD(add_key
, NEW_KEY
);
1164 CMD(start_ap
, START_AP
);
1165 CMD(add_station
, NEW_STATION
);
1166 CMD(add_mpath
, NEW_MPATH
);
1167 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1168 CMD(change_bss
, SET_BSS
);
1169 CMD(auth
, AUTHENTICATE
);
1170 CMD(assoc
, ASSOCIATE
);
1171 CMD(deauth
, DEAUTHENTICATE
);
1172 CMD(disassoc
, DISASSOCIATE
);
1173 CMD(join_ibss
, JOIN_IBSS
);
1174 CMD(join_mesh
, JOIN_MESH
);
1175 CMD(set_pmksa
, SET_PMKSA
);
1176 CMD(del_pmksa
, DEL_PMKSA
);
1177 CMD(flush_pmksa
, FLUSH_PMKSA
);
1178 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1179 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1180 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1181 CMD(mgmt_tx
, FRAME
);
1182 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1183 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1185 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1186 goto nla_put_failure
;
1188 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1189 dev
->ops
->join_mesh
) {
1191 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1192 goto nla_put_failure
;
1194 CMD(set_wds_peer
, SET_WDS_PEER
);
1195 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1196 CMD(tdls_mgmt
, TDLS_MGMT
);
1197 CMD(tdls_oper
, TDLS_OPER
);
1199 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1200 CMD(sched_scan_start
, START_SCHED_SCAN
);
1201 CMD(probe_client
, PROBE_CLIENT
);
1202 CMD(set_noack_map
, SET_NOACK_MAP
);
1203 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1205 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1206 goto nla_put_failure
;
1208 CMD(start_p2p_device
, START_P2P_DEVICE
);
1209 CMD(set_mcast_rate
, SET_MCAST_RATE
);
1211 #ifdef CONFIG_NL80211_TESTMODE
1212 CMD(testmode_cmd
, TESTMODE
);
1217 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1219 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1220 goto nla_put_failure
;
1223 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1225 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1226 goto nla_put_failure
;
1229 nla_nest_end(msg
, nl_cmds
);
1231 if (dev
->ops
->remain_on_channel
&&
1232 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1233 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1234 dev
->wiphy
.max_remain_on_channel_duration
))
1235 goto nla_put_failure
;
1237 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1238 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1239 goto nla_put_failure
;
1243 struct nlattr
*nl_ftypes
, *nl_ifs
;
1244 enum nl80211_iftype ift
;
1246 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1248 goto nla_put_failure
;
1250 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1251 nl_ftypes
= nla_nest_start(msg
, ift
);
1253 goto nla_put_failure
;
1255 stypes
= mgmt_stypes
[ift
].tx
;
1258 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1259 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1260 goto nla_put_failure
;
1264 nla_nest_end(msg
, nl_ftypes
);
1267 nla_nest_end(msg
, nl_ifs
);
1269 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1271 goto nla_put_failure
;
1273 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1274 nl_ftypes
= nla_nest_start(msg
, ift
);
1276 goto nla_put_failure
;
1278 stypes
= mgmt_stypes
[ift
].rx
;
1281 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1282 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1283 goto nla_put_failure
;
1287 nla_nest_end(msg
, nl_ftypes
);
1289 nla_nest_end(msg
, nl_ifs
);
1293 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1294 struct nlattr
*nl_wowlan
;
1296 nl_wowlan
= nla_nest_start(msg
,
1297 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1299 goto nla_put_failure
;
1301 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1302 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1303 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1304 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1305 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1306 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1307 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1308 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1309 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1310 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1311 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1312 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1313 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1314 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1315 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1316 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1317 goto nla_put_failure
;
1318 if (dev
->wiphy
.wowlan
.n_patterns
) {
1319 struct nl80211_wowlan_pattern_support pat
= {
1320 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1322 dev
->wiphy
.wowlan
.pattern_min_len
,
1324 dev
->wiphy
.wowlan
.pattern_max_len
,
1326 dev
->wiphy
.wowlan
.max_pkt_offset
,
1328 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1330 goto nla_put_failure
;
1333 if (nl80211_send_wowlan_tcp_caps(dev
, msg
))
1334 goto nla_put_failure
;
1336 nla_nest_end(msg
, nl_wowlan
);
1340 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1341 dev
->wiphy
.software_iftypes
))
1342 goto nla_put_failure
;
1344 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1345 goto nla_put_failure
;
1347 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1348 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1349 dev
->wiphy
.ap_sme_capa
))
1350 goto nla_put_failure
;
1352 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1353 dev
->wiphy
.features
))
1354 goto nla_put_failure
;
1356 if (dev
->wiphy
.ht_capa_mod_mask
&&
1357 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1358 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1359 dev
->wiphy
.ht_capa_mod_mask
))
1360 goto nla_put_failure
;
1362 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
&&
1363 dev
->wiphy
.max_acl_mac_addrs
&&
1364 nla_put_u32(msg
, NL80211_ATTR_MAC_ACL_MAX
,
1365 dev
->wiphy
.max_acl_mac_addrs
))
1366 goto nla_put_failure
;
1368 if (dev
->wiphy
.extended_capabilities
&&
1369 (nla_put(msg
, NL80211_ATTR_EXT_CAPA
,
1370 dev
->wiphy
.extended_capabilities_len
,
1371 dev
->wiphy
.extended_capabilities
) ||
1372 nla_put(msg
, NL80211_ATTR_EXT_CAPA_MASK
,
1373 dev
->wiphy
.extended_capabilities_len
,
1374 dev
->wiphy
.extended_capabilities_mask
)))
1375 goto nla_put_failure
;
1377 return genlmsg_end(msg
, hdr
);
1380 genlmsg_cancel(msg
, hdr
);
1384 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1387 int start
= cb
->args
[0];
1388 struct cfg80211_registered_device
*dev
;
1390 mutex_lock(&cfg80211_mutex
);
1391 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1392 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1396 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).portid
,
1397 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1403 mutex_unlock(&cfg80211_mutex
);
1410 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1412 struct sk_buff
*msg
;
1413 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1415 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1419 if (nl80211_send_wiphy(msg
, info
->snd_portid
, info
->snd_seq
, 0, dev
) < 0) {
1424 return genlmsg_reply(msg
, info
);
1427 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1428 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1429 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1430 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1431 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1432 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1435 static int parse_txq_params(struct nlattr
*tb
[],
1436 struct ieee80211_txq_params
*txq_params
)
1438 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1439 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1440 !tb
[NL80211_TXQ_ATTR_AIFS
])
1443 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1444 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1445 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1446 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1447 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1449 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1455 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1458 * You can only set the channel explicitly for WDS interfaces,
1459 * all others have their channel managed via their respective
1460 * "establish a connection" command (connect, join, ...)
1462 * For AP/GO and mesh mode, the channel can be set with the
1463 * channel userspace API, but is only stored and passed to the
1464 * low-level driver when the AP starts or the mesh is joined.
1465 * This is for backward compatibility, userspace can also give
1466 * the channel in the start-ap or join-mesh commands instead.
1468 * Monitors are special as they are normally slaved to
1469 * whatever else is going on, so they have their own special
1470 * operation to set the monitor channel if possible.
1473 wdev
->iftype
== NL80211_IFTYPE_AP
||
1474 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1475 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1476 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1479 static int nl80211_parse_chandef(struct cfg80211_registered_device
*rdev
,
1480 struct genl_info
*info
,
1481 struct cfg80211_chan_def
*chandef
)
1485 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1488 control_freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1490 chandef
->chan
= ieee80211_get_channel(&rdev
->wiphy
, control_freq
);
1491 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
1492 chandef
->center_freq1
= control_freq
;
1493 chandef
->center_freq2
= 0;
1495 /* Primary channel not allowed */
1496 if (!chandef
->chan
|| chandef
->chan
->flags
& IEEE80211_CHAN_DISABLED
)
1499 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1500 enum nl80211_channel_type chantype
;
1502 chantype
= nla_get_u32(
1503 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1506 case NL80211_CHAN_NO_HT
:
1507 case NL80211_CHAN_HT20
:
1508 case NL80211_CHAN_HT40PLUS
:
1509 case NL80211_CHAN_HT40MINUS
:
1510 cfg80211_chandef_create(chandef
, chandef
->chan
,
1516 } else if (info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]) {
1518 nla_get_u32(info
->attrs
[NL80211_ATTR_CHANNEL_WIDTH
]);
1519 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ1
])
1520 chandef
->center_freq1
=
1522 info
->attrs
[NL80211_ATTR_CENTER_FREQ1
]);
1523 if (info
->attrs
[NL80211_ATTR_CENTER_FREQ2
])
1524 chandef
->center_freq2
=
1526 info
->attrs
[NL80211_ATTR_CENTER_FREQ2
]);
1529 if (!cfg80211_chandef_valid(chandef
))
1532 if (!cfg80211_chandef_usable(&rdev
->wiphy
, chandef
,
1533 IEEE80211_CHAN_DISABLED
))
1539 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1540 struct wireless_dev
*wdev
,
1541 struct genl_info
*info
)
1543 struct cfg80211_chan_def chandef
;
1545 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1548 iftype
= wdev
->iftype
;
1550 if (!nl80211_can_set_dev_channel(wdev
))
1553 result
= nl80211_parse_chandef(rdev
, info
, &chandef
);
1557 mutex_lock(&rdev
->devlist_mtx
);
1559 case NL80211_IFTYPE_AP
:
1560 case NL80211_IFTYPE_P2P_GO
:
1561 if (wdev
->beacon_interval
) {
1565 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &chandef
)) {
1569 wdev
->preset_chandef
= chandef
;
1572 case NL80211_IFTYPE_MESH_POINT
:
1573 result
= cfg80211_set_mesh_channel(rdev
, wdev
, &chandef
);
1575 case NL80211_IFTYPE_MONITOR
:
1576 result
= cfg80211_set_monitor_channel(rdev
, &chandef
);
1581 mutex_unlock(&rdev
->devlist_mtx
);
1586 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1588 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1589 struct net_device
*netdev
= info
->user_ptr
[1];
1591 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1594 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1596 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1597 struct net_device
*dev
= info
->user_ptr
[1];
1598 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1601 if (!info
->attrs
[NL80211_ATTR_MAC
])
1604 if (netif_running(dev
))
1607 if (!rdev
->ops
->set_wds_peer
)
1610 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1613 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1614 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1618 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1620 struct cfg80211_registered_device
*rdev
;
1621 struct net_device
*netdev
= NULL
;
1622 struct wireless_dev
*wdev
;
1623 int result
= 0, rem_txq_params
= 0;
1624 struct nlattr
*nl_txq_params
;
1626 u8 retry_short
= 0, retry_long
= 0;
1627 u32 frag_threshold
= 0, rts_threshold
= 0;
1628 u8 coverage_class
= 0;
1631 * Try to find the wiphy and netdev. Normally this
1632 * function shouldn't need the netdev, but this is
1633 * done for backward compatibility -- previously
1634 * setting the channel was done per wiphy, but now
1635 * it is per netdev. Previous userland like hostapd
1636 * also passed a netdev to set_wiphy, so that it is
1637 * possible to let that go to the right netdev!
1639 mutex_lock(&cfg80211_mutex
);
1641 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1642 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1644 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1645 if (netdev
&& netdev
->ieee80211_ptr
) {
1646 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1647 mutex_lock(&rdev
->mtx
);
1653 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1656 mutex_unlock(&cfg80211_mutex
);
1657 return PTR_ERR(rdev
);
1663 mutex_lock(&rdev
->mtx
);
1665 wdev
= netdev
->ieee80211_ptr
;
1668 * end workaround code, by now the rdev is available
1669 * and locked, and wdev may or may not be NULL.
1672 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1673 result
= cfg80211_dev_rename(
1674 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1676 mutex_unlock(&cfg80211_mutex
);
1681 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1682 struct ieee80211_txq_params txq_params
;
1683 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1685 if (!rdev
->ops
->set_txq_params
) {
1686 result
= -EOPNOTSUPP
;
1695 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1696 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1701 if (!netif_running(netdev
)) {
1706 nla_for_each_nested(nl_txq_params
,
1707 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1709 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1710 nla_data(nl_txq_params
),
1711 nla_len(nl_txq_params
),
1713 result
= parse_txq_params(tb
, &txq_params
);
1717 result
= rdev_set_txq_params(rdev
, netdev
,
1724 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1725 result
= __nl80211_set_channel(rdev
,
1726 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1732 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1733 struct wireless_dev
*txp_wdev
= wdev
;
1734 enum nl80211_tx_power_setting type
;
1737 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_VIF_TXPOWER
))
1740 if (!rdev
->ops
->set_tx_power
) {
1741 result
= -EOPNOTSUPP
;
1745 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1746 type
= nla_get_u32(info
->attrs
[idx
]);
1748 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1749 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1754 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1755 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1756 mbm
= nla_get_u32(info
->attrs
[idx
]);
1759 result
= rdev_set_tx_power(rdev
, txp_wdev
, type
, mbm
);
1764 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1765 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1767 if ((!rdev
->wiphy
.available_antennas_tx
&&
1768 !rdev
->wiphy
.available_antennas_rx
) ||
1769 !rdev
->ops
->set_antenna
) {
1770 result
= -EOPNOTSUPP
;
1774 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1775 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1777 /* reject antenna configurations which don't match the
1778 * available antenna masks, except for the "all" mask */
1779 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1780 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1785 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1786 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1788 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
1795 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1796 retry_short
= nla_get_u8(
1797 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1798 if (retry_short
== 0) {
1802 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1805 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1806 retry_long
= nla_get_u8(
1807 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1808 if (retry_long
== 0) {
1812 changed
|= WIPHY_PARAM_RETRY_LONG
;
1815 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1816 frag_threshold
= nla_get_u32(
1817 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1818 if (frag_threshold
< 256) {
1822 if (frag_threshold
!= (u32
) -1) {
1824 * Fragments (apart from the last one) are required to
1825 * have even length. Make the fragmentation code
1826 * simpler by stripping LSB should someone try to use
1827 * odd threshold value.
1829 frag_threshold
&= ~0x1;
1831 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1834 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1835 rts_threshold
= nla_get_u32(
1836 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1837 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1840 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1841 coverage_class
= nla_get_u8(
1842 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1843 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1847 u8 old_retry_short
, old_retry_long
;
1848 u32 old_frag_threshold
, old_rts_threshold
;
1849 u8 old_coverage_class
;
1851 if (!rdev
->ops
->set_wiphy_params
) {
1852 result
= -EOPNOTSUPP
;
1856 old_retry_short
= rdev
->wiphy
.retry_short
;
1857 old_retry_long
= rdev
->wiphy
.retry_long
;
1858 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1859 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1860 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1862 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1863 rdev
->wiphy
.retry_short
= retry_short
;
1864 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1865 rdev
->wiphy
.retry_long
= retry_long
;
1866 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1867 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1868 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1869 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1870 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1871 rdev
->wiphy
.coverage_class
= coverage_class
;
1873 result
= rdev_set_wiphy_params(rdev
, changed
);
1875 rdev
->wiphy
.retry_short
= old_retry_short
;
1876 rdev
->wiphy
.retry_long
= old_retry_long
;
1877 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1878 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1879 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1884 mutex_unlock(&rdev
->mtx
);
1890 static inline u64
wdev_id(struct wireless_dev
*wdev
)
1892 return (u64
)wdev
->identifier
|
1893 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
1896 static int nl80211_send_chandef(struct sk_buff
*msg
,
1897 struct cfg80211_chan_def
*chandef
)
1899 WARN_ON(!cfg80211_chandef_valid(chandef
));
1901 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1902 chandef
->chan
->center_freq
))
1904 switch (chandef
->width
) {
1905 case NL80211_CHAN_WIDTH_20_NOHT
:
1906 case NL80211_CHAN_WIDTH_20
:
1907 case NL80211_CHAN_WIDTH_40
:
1908 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1909 cfg80211_get_chandef_type(chandef
)))
1915 if (nla_put_u32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
))
1917 if (nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ1
, chandef
->center_freq1
))
1919 if (chandef
->center_freq2
&&
1920 nla_put_u32(msg
, NL80211_ATTR_CENTER_FREQ2
, chandef
->center_freq2
))
1925 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
1926 struct cfg80211_registered_device
*rdev
,
1927 struct wireless_dev
*wdev
)
1929 struct net_device
*dev
= wdev
->netdev
;
1932 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1937 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1938 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
1939 goto nla_put_failure
;
1941 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1942 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
1943 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
1944 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
1945 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1946 rdev
->devlist_generation
^
1947 (cfg80211_rdev_list_generation
<< 2)))
1948 goto nla_put_failure
;
1950 if (rdev
->ops
->get_channel
) {
1952 struct cfg80211_chan_def chandef
;
1954 ret
= rdev_get_channel(rdev
, wdev
, &chandef
);
1956 if (nl80211_send_chandef(msg
, &chandef
))
1957 goto nla_put_failure
;
1961 if (wdev
->ssid_len
) {
1962 if (nla_put(msg
, NL80211_ATTR_SSID
, wdev
->ssid_len
, wdev
->ssid
))
1963 goto nla_put_failure
;
1966 return genlmsg_end(msg
, hdr
);
1969 genlmsg_cancel(msg
, hdr
);
1973 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1977 int wp_start
= cb
->args
[0];
1978 int if_start
= cb
->args
[1];
1979 struct cfg80211_registered_device
*rdev
;
1980 struct wireless_dev
*wdev
;
1982 mutex_lock(&cfg80211_mutex
);
1983 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1984 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1986 if (wp_idx
< wp_start
) {
1992 mutex_lock(&rdev
->devlist_mtx
);
1993 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
1994 if (if_idx
< if_start
) {
1998 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
1999 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2001 mutex_unlock(&rdev
->devlist_mtx
);
2006 mutex_unlock(&rdev
->devlist_mtx
);
2011 mutex_unlock(&cfg80211_mutex
);
2013 cb
->args
[0] = wp_idx
;
2014 cb
->args
[1] = if_idx
;
2019 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2021 struct sk_buff
*msg
;
2022 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
2023 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2025 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2029 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2035 return genlmsg_reply(msg
, info
);
2038 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
2039 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
2040 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
2041 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
2042 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
2043 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
2046 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
2048 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
2056 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
2057 nla
, mntr_flags_policy
))
2060 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
2062 *mntrflags
|= (1<<flag
);
2067 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
2068 struct net_device
*netdev
, u8 use_4addr
,
2069 enum nl80211_iftype iftype
)
2072 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
2078 case NL80211_IFTYPE_AP_VLAN
:
2079 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
2082 case NL80211_IFTYPE_STATION
:
2083 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
2093 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2095 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2096 struct vif_params params
;
2098 enum nl80211_iftype otype
, ntype
;
2099 struct net_device
*dev
= info
->user_ptr
[1];
2100 u32 _flags
, *flags
= NULL
;
2101 bool change
= false;
2103 memset(¶ms
, 0, sizeof(params
));
2105 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
2107 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2108 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2111 if (ntype
> NL80211_IFTYPE_MAX
)
2115 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
2116 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2118 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
2120 if (netif_running(dev
))
2124 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2125 IEEE80211_MAX_MESH_ID_LEN
);
2126 wdev
->mesh_id_up_len
=
2127 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2128 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2129 wdev
->mesh_id_up_len
);
2133 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2134 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2136 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
2140 params
.use_4addr
= -1;
2143 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
2144 if (ntype
!= NL80211_IFTYPE_MONITOR
)
2146 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
2156 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
2160 if (!err
&& params
.use_4addr
!= -1)
2161 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
2166 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2168 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2169 struct vif_params params
;
2170 struct wireless_dev
*wdev
;
2171 struct sk_buff
*msg
;
2173 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
2176 memset(¶ms
, 0, sizeof(params
));
2178 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2181 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2182 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2183 if (type
> NL80211_IFTYPE_MAX
)
2187 if (!rdev
->ops
->add_virtual_intf
||
2188 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2191 if (type
== NL80211_IFTYPE_P2P_DEVICE
&& info
->attrs
[NL80211_ATTR_MAC
]) {
2192 nla_memcpy(params
.macaddr
, info
->attrs
[NL80211_ATTR_MAC
],
2194 if (!is_valid_ether_addr(params
.macaddr
))
2195 return -EADDRNOTAVAIL
;
2198 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2199 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2200 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2205 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2209 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2210 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2212 wdev
= rdev_add_virtual_intf(rdev
,
2213 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2214 type
, err
? NULL
: &flags
, ¶ms
);
2217 return PTR_ERR(wdev
);
2221 case NL80211_IFTYPE_MESH_POINT
:
2222 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2225 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2226 IEEE80211_MAX_MESH_ID_LEN
);
2227 wdev
->mesh_id_up_len
=
2228 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2229 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2230 wdev
->mesh_id_up_len
);
2233 case NL80211_IFTYPE_P2P_DEVICE
:
2235 * P2P Device doesn't have a netdev, so doesn't go
2236 * through the netdev notifier and must be added here
2238 mutex_init(&wdev
->mtx
);
2239 INIT_LIST_HEAD(&wdev
->event_list
);
2240 spin_lock_init(&wdev
->event_lock
);
2241 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2242 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2244 mutex_lock(&rdev
->devlist_mtx
);
2245 wdev
->identifier
= ++rdev
->wdev_id
;
2246 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2247 rdev
->devlist_generation
++;
2248 mutex_unlock(&rdev
->devlist_mtx
);
2254 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2260 return genlmsg_reply(msg
, info
);
2263 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2265 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2266 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2268 if (!rdev
->ops
->del_virtual_intf
)
2272 * If we remove a wireless device without a netdev then clear
2273 * user_ptr[1] so that nl80211_post_doit won't dereference it
2274 * to check if it needs to do dev_put(). Otherwise it crashes
2275 * since the wdev has been freed, unlike with a netdev where
2276 * we need the dev_put() for the netdev to really be freed.
2279 info
->user_ptr
[1] = NULL
;
2281 return rdev_del_virtual_intf(rdev
, wdev
);
2284 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2286 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2287 struct net_device
*dev
= info
->user_ptr
[1];
2290 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2293 if (!rdev
->ops
->set_noack_map
)
2296 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2298 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2301 struct get_key_cookie
{
2302 struct sk_buff
*msg
;
2307 static void get_key_callback(void *c
, struct key_params
*params
)
2310 struct get_key_cookie
*cookie
= c
;
2313 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2314 params
->key_len
, params
->key
)) ||
2316 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2317 params
->seq_len
, params
->seq
)) ||
2319 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2321 goto nla_put_failure
;
2323 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2325 goto nla_put_failure
;
2328 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2329 params
->key_len
, params
->key
)) ||
2331 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2332 params
->seq_len
, params
->seq
)) ||
2334 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2336 goto nla_put_failure
;
2338 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2339 goto nla_put_failure
;
2341 nla_nest_end(cookie
->msg
, key
);
2348 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2350 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2352 struct net_device
*dev
= info
->user_ptr
[1];
2354 const u8
*mac_addr
= NULL
;
2356 struct get_key_cookie cookie
= {
2360 struct sk_buff
*msg
;
2362 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2363 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2368 if (info
->attrs
[NL80211_ATTR_MAC
])
2369 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2371 pairwise
= !!mac_addr
;
2372 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2373 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2374 if (kt
>= NUM_NL80211_KEYTYPES
)
2376 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2377 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2379 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2382 if (!rdev
->ops
->get_key
)
2385 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2389 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2390 NL80211_CMD_NEW_KEY
);
2392 return PTR_ERR(hdr
);
2395 cookie
.idx
= key_idx
;
2397 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2398 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2399 goto nla_put_failure
;
2401 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2402 goto nla_put_failure
;
2404 if (pairwise
&& mac_addr
&&
2405 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2408 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2415 goto nla_put_failure
;
2417 genlmsg_end(msg
, hdr
);
2418 return genlmsg_reply(msg
, info
);
2427 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2429 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2430 struct key_parse key
;
2432 struct net_device
*dev
= info
->user_ptr
[1];
2434 err
= nl80211_parse_key(info
, &key
);
2441 /* only support setting default key */
2442 if (!key
.def
&& !key
.defmgmt
)
2445 wdev_lock(dev
->ieee80211_ptr
);
2448 if (!rdev
->ops
->set_default_key
) {
2453 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2457 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2458 key
.def_uni
, key
.def_multi
);
2463 #ifdef CONFIG_CFG80211_WEXT
2464 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2467 if (key
.def_uni
|| !key
.def_multi
) {
2472 if (!rdev
->ops
->set_default_mgmt_key
) {
2477 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2481 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2485 #ifdef CONFIG_CFG80211_WEXT
2486 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2491 wdev_unlock(dev
->ieee80211_ptr
);
2496 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2498 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2500 struct net_device
*dev
= info
->user_ptr
[1];
2501 struct key_parse key
;
2502 const u8
*mac_addr
= NULL
;
2504 err
= nl80211_parse_key(info
, &key
);
2511 if (info
->attrs
[NL80211_ATTR_MAC
])
2512 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2514 if (key
.type
== -1) {
2516 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2518 key
.type
= NL80211_KEYTYPE_GROUP
;
2522 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2523 key
.type
!= NL80211_KEYTYPE_GROUP
)
2526 if (!rdev
->ops
->add_key
)
2529 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2530 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2534 wdev_lock(dev
->ieee80211_ptr
);
2535 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2537 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2538 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2540 wdev_unlock(dev
->ieee80211_ptr
);
2545 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2547 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2549 struct net_device
*dev
= info
->user_ptr
[1];
2550 u8
*mac_addr
= NULL
;
2551 struct key_parse key
;
2553 err
= nl80211_parse_key(info
, &key
);
2557 if (info
->attrs
[NL80211_ATTR_MAC
])
2558 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2560 if (key
.type
== -1) {
2562 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2564 key
.type
= NL80211_KEYTYPE_GROUP
;
2568 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2569 key
.type
!= NL80211_KEYTYPE_GROUP
)
2572 if (!rdev
->ops
->del_key
)
2575 wdev_lock(dev
->ieee80211_ptr
);
2576 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2578 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2579 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2583 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2584 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2587 #ifdef CONFIG_CFG80211_WEXT
2589 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2590 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2591 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2592 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2595 wdev_unlock(dev
->ieee80211_ptr
);
2600 /* This function returns an error or the number of nested attributes */
2601 static int validate_acl_mac_addrs(struct nlattr
*nl_attr
)
2603 struct nlattr
*attr
;
2604 int n_entries
= 0, tmp
;
2606 nla_for_each_nested(attr
, nl_attr
, tmp
) {
2607 if (nla_len(attr
) != ETH_ALEN
)
2617 * This function parses ACL information and allocates memory for ACL data.
2618 * On successful return, the calling function is responsible to free the
2619 * ACL buffer returned by this function.
2621 static struct cfg80211_acl_data
*parse_acl_data(struct wiphy
*wiphy
,
2622 struct genl_info
*info
)
2624 enum nl80211_acl_policy acl_policy
;
2625 struct nlattr
*attr
;
2626 struct cfg80211_acl_data
*acl
;
2627 int i
= 0, n_entries
, tmp
;
2629 if (!wiphy
->max_acl_mac_addrs
)
2630 return ERR_PTR(-EOPNOTSUPP
);
2632 if (!info
->attrs
[NL80211_ATTR_ACL_POLICY
])
2633 return ERR_PTR(-EINVAL
);
2635 acl_policy
= nla_get_u32(info
->attrs
[NL80211_ATTR_ACL_POLICY
]);
2636 if (acl_policy
!= NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
&&
2637 acl_policy
!= NL80211_ACL_POLICY_DENY_UNLESS_LISTED
)
2638 return ERR_PTR(-EINVAL
);
2640 if (!info
->attrs
[NL80211_ATTR_MAC_ADDRS
])
2641 return ERR_PTR(-EINVAL
);
2643 n_entries
= validate_acl_mac_addrs(info
->attrs
[NL80211_ATTR_MAC_ADDRS
]);
2645 return ERR_PTR(n_entries
);
2647 if (n_entries
> wiphy
->max_acl_mac_addrs
)
2648 return ERR_PTR(-ENOTSUPP
);
2650 acl
= kzalloc(sizeof(*acl
) + (sizeof(struct mac_address
) * n_entries
),
2653 return ERR_PTR(-ENOMEM
);
2655 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_MAC_ADDRS
], tmp
) {
2656 memcpy(acl
->mac_addrs
[i
].addr
, nla_data(attr
), ETH_ALEN
);
2660 acl
->n_acl_entries
= n_entries
;
2661 acl
->acl_policy
= acl_policy
;
2666 static int nl80211_set_mac_acl(struct sk_buff
*skb
, struct genl_info
*info
)
2668 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2669 struct net_device
*dev
= info
->user_ptr
[1];
2670 struct cfg80211_acl_data
*acl
;
2673 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2674 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2677 if (!dev
->ieee80211_ptr
->beacon_interval
)
2680 acl
= parse_acl_data(&rdev
->wiphy
, info
);
2682 return PTR_ERR(acl
);
2684 err
= rdev_set_mac_acl(rdev
, dev
, acl
);
2691 static int nl80211_parse_beacon(struct genl_info
*info
,
2692 struct cfg80211_beacon_data
*bcn
)
2694 bool haveinfo
= false;
2696 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2697 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2698 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2699 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2702 memset(bcn
, 0, sizeof(*bcn
));
2704 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2705 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2706 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2712 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2713 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2715 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2722 if (info
->attrs
[NL80211_ATTR_IE
]) {
2723 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2724 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2727 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2728 bcn
->proberesp_ies
=
2729 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2730 bcn
->proberesp_ies_len
=
2731 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2734 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2735 bcn
->assocresp_ies
=
2736 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2737 bcn
->assocresp_ies_len
=
2738 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2741 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2743 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2744 bcn
->probe_resp_len
=
2745 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2751 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2752 struct cfg80211_ap_settings
*params
)
2754 struct wireless_dev
*wdev
;
2757 mutex_lock(&rdev
->devlist_mtx
);
2759 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2760 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2761 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2764 if (!wdev
->preset_chandef
.chan
)
2767 params
->chandef
= wdev
->preset_chandef
;
2772 mutex_unlock(&rdev
->devlist_mtx
);
2777 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
2778 enum nl80211_auth_type auth_type
,
2779 enum nl80211_commands cmd
)
2781 if (auth_type
> NL80211_AUTHTYPE_MAX
)
2785 case NL80211_CMD_AUTHENTICATE
:
2786 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
2787 auth_type
== NL80211_AUTHTYPE_SAE
)
2790 case NL80211_CMD_CONNECT
:
2791 case NL80211_CMD_START_AP
:
2792 /* SAE not supported yet */
2793 if (auth_type
== NL80211_AUTHTYPE_SAE
)
2801 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2803 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2804 struct net_device
*dev
= info
->user_ptr
[1];
2805 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2806 struct cfg80211_ap_settings params
;
2808 u8 radar_detect_width
= 0;
2810 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2811 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2814 if (!rdev
->ops
->start_ap
)
2817 if (wdev
->beacon_interval
)
2820 memset(¶ms
, 0, sizeof(params
));
2822 /* these are required for START_AP */
2823 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2824 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2825 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2828 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2832 params
.beacon_interval
=
2833 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2834 params
.dtim_period
=
2835 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2837 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2842 * In theory, some of these attributes should be required here
2843 * but since they were not used when the command was originally
2844 * added, keep them optional for old user space programs to let
2845 * them continue to work with drivers that do not need the
2846 * additional information -- drivers must check!
2848 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2849 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2851 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2852 if (params
.ssid_len
== 0 ||
2853 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2857 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2858 params
.hidden_ssid
= nla_get_u32(
2859 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2860 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2861 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2862 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2866 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2868 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2869 params
.auth_type
= nla_get_u32(
2870 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2871 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
2872 NL80211_CMD_START_AP
))
2875 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2877 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2878 NL80211_MAX_NR_CIPHER_SUITES
);
2882 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2883 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2885 params
.inactivity_timeout
= nla_get_u16(
2886 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2889 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
2890 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2892 params
.p2p_ctwindow
=
2893 nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
2894 if (params
.p2p_ctwindow
> 127)
2896 if (params
.p2p_ctwindow
!= 0 &&
2897 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
2901 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
2904 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2906 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
2909 params
.p2p_opp_ps
= tmp
;
2910 if (params
.p2p_opp_ps
!= 0 &&
2911 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
2915 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2916 err
= nl80211_parse_chandef(rdev
, info
, ¶ms
.chandef
);
2919 } else if (wdev
->preset_chandef
.chan
) {
2920 params
.chandef
= wdev
->preset_chandef
;
2921 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2924 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, ¶ms
.chandef
))
2927 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, ¶ms
.chandef
);
2931 radar_detect_width
= BIT(params
.chandef
.width
);
2932 params
.radar_required
= true;
2935 mutex_lock(&rdev
->devlist_mtx
);
2936 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
2937 params
.chandef
.chan
,
2939 radar_detect_width
);
2940 mutex_unlock(&rdev
->devlist_mtx
);
2945 if (info
->attrs
[NL80211_ATTR_ACL_POLICY
]) {
2946 params
.acl
= parse_acl_data(&rdev
->wiphy
, info
);
2947 if (IS_ERR(params
.acl
))
2948 return PTR_ERR(params
.acl
);
2951 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
2953 wdev
->preset_chandef
= params
.chandef
;
2954 wdev
->beacon_interval
= params
.beacon_interval
;
2955 wdev
->channel
= params
.chandef
.chan
;
2956 wdev
->ssid_len
= params
.ssid_len
;
2957 memcpy(wdev
->ssid
, params
.ssid
, wdev
->ssid_len
);
2965 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2967 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2968 struct net_device
*dev
= info
->user_ptr
[1];
2969 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2970 struct cfg80211_beacon_data params
;
2973 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2974 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2977 if (!rdev
->ops
->change_beacon
)
2980 if (!wdev
->beacon_interval
)
2983 err
= nl80211_parse_beacon(info
, ¶ms
);
2987 return rdev_change_beacon(rdev
, dev
, ¶ms
);
2990 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2992 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2993 struct net_device
*dev
= info
->user_ptr
[1];
2995 return cfg80211_stop_ap(rdev
, dev
);
2998 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2999 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
3000 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
3001 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
3002 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
3003 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
3004 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
3007 static int parse_station_flags(struct genl_info
*info
,
3008 enum nl80211_iftype iftype
,
3009 struct station_parameters
*params
)
3011 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
3016 * Try parsing the new attribute first so userspace
3017 * can specify both for older kernels.
3019 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
3021 struct nl80211_sta_flag_update
*sta_flags
;
3023 sta_flags
= nla_data(nla
);
3024 params
->sta_flags_mask
= sta_flags
->mask
;
3025 params
->sta_flags_set
= sta_flags
->set
;
3026 if ((params
->sta_flags_mask
|
3027 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
3032 /* if present, parse the old attribute */
3034 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
3038 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
3039 nla
, sta_flags_policy
))
3043 * Only allow certain flags for interface types so that
3044 * other attributes are silently ignored. Remember that
3045 * this is backward compatibility code with old userspace
3046 * and shouldn't be hit in other cases anyway.
3049 case NL80211_IFTYPE_AP
:
3050 case NL80211_IFTYPE_AP_VLAN
:
3051 case NL80211_IFTYPE_P2P_GO
:
3052 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3053 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3054 BIT(NL80211_STA_FLAG_WME
) |
3055 BIT(NL80211_STA_FLAG_MFP
);
3057 case NL80211_IFTYPE_P2P_CLIENT
:
3058 case NL80211_IFTYPE_STATION
:
3059 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3060 BIT(NL80211_STA_FLAG_TDLS_PEER
);
3062 case NL80211_IFTYPE_MESH_POINT
:
3063 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3064 BIT(NL80211_STA_FLAG_MFP
) |
3065 BIT(NL80211_STA_FLAG_AUTHORIZED
);
3070 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
3072 params
->sta_flags_set
|= (1<<flag
);
3074 /* no longer support new API additions in old API */
3075 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
3083 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
3086 struct nlattr
*rate
;
3090 rate
= nla_nest_start(msg
, attr
);
3094 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3095 bitrate
= cfg80211_calculate_bitrate(info
);
3096 /* report 16-bit bitrate only if we can */
3097 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
3099 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
))
3101 if (bitrate_compat
> 0 &&
3102 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
))
3105 if (info
->flags
& RATE_INFO_FLAGS_MCS
) {
3106 if (nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
))
3108 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3109 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3111 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3112 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3114 } else if (info
->flags
& RATE_INFO_FLAGS_VHT_MCS
) {
3115 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_MCS
, info
->mcs
))
3117 if (nla_put_u8(msg
, NL80211_RATE_INFO_VHT_NSS
, info
->nss
))
3119 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
&&
3120 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
))
3122 if (info
->flags
& RATE_INFO_FLAGS_80_MHZ_WIDTH
&&
3123 nla_put_flag(msg
, NL80211_RATE_INFO_80_MHZ_WIDTH
))
3125 if (info
->flags
& RATE_INFO_FLAGS_80P80_MHZ_WIDTH
&&
3126 nla_put_flag(msg
, NL80211_RATE_INFO_80P80_MHZ_WIDTH
))
3128 if (info
->flags
& RATE_INFO_FLAGS_160_MHZ_WIDTH
&&
3129 nla_put_flag(msg
, NL80211_RATE_INFO_160_MHZ_WIDTH
))
3131 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
&&
3132 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
))
3136 nla_nest_end(msg
, rate
);
3140 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3142 struct cfg80211_registered_device
*rdev
,
3143 struct net_device
*dev
,
3144 const u8
*mac_addr
, struct station_info
*sinfo
)
3147 struct nlattr
*sinfoattr
, *bss_param
;
3149 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3153 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3154 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
3155 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
3156 goto nla_put_failure
;
3158 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
3160 goto nla_put_failure
;
3161 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
3162 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
3163 sinfo
->connected_time
))
3164 goto nla_put_failure
;
3165 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
3166 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
3167 sinfo
->inactive_time
))
3168 goto nla_put_failure
;
3169 if ((sinfo
->filled
& (STATION_INFO_RX_BYTES
|
3170 STATION_INFO_RX_BYTES64
)) &&
3171 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
3172 (u32
)sinfo
->rx_bytes
))
3173 goto nla_put_failure
;
3174 if ((sinfo
->filled
& (STATION_INFO_TX_BYTES
|
3175 NL80211_STA_INFO_TX_BYTES64
)) &&
3176 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
3177 (u32
)sinfo
->tx_bytes
))
3178 goto nla_put_failure
;
3179 if ((sinfo
->filled
& STATION_INFO_RX_BYTES64
) &&
3180 nla_put_u64(msg
, NL80211_STA_INFO_RX_BYTES64
,
3182 goto nla_put_failure
;
3183 if ((sinfo
->filled
& STATION_INFO_TX_BYTES64
) &&
3184 nla_put_u64(msg
, NL80211_STA_INFO_TX_BYTES64
,
3186 goto nla_put_failure
;
3187 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
3188 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
3189 goto nla_put_failure
;
3190 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
3191 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
3192 goto nla_put_failure
;
3193 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
3194 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
3195 sinfo
->plink_state
))
3196 goto nla_put_failure
;
3197 switch (rdev
->wiphy
.signal_type
) {
3198 case CFG80211_SIGNAL_TYPE_MBM
:
3199 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
3200 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
3202 goto nla_put_failure
;
3203 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
3204 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
3206 goto nla_put_failure
;
3211 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
3212 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
3213 NL80211_STA_INFO_TX_BITRATE
))
3214 goto nla_put_failure
;
3216 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
3217 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
3218 NL80211_STA_INFO_RX_BITRATE
))
3219 goto nla_put_failure
;
3221 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
3222 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
3224 goto nla_put_failure
;
3225 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
3226 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
3228 goto nla_put_failure
;
3229 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
3230 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
3232 goto nla_put_failure
;
3233 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
3234 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
3236 goto nla_put_failure
;
3237 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
3238 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
3239 sinfo
->beacon_loss_count
))
3240 goto nla_put_failure
;
3241 if ((sinfo
->filled
& STATION_INFO_LOCAL_PM
) &&
3242 nla_put_u32(msg
, NL80211_STA_INFO_LOCAL_PM
,
3244 goto nla_put_failure
;
3245 if ((sinfo
->filled
& STATION_INFO_PEER_PM
) &&
3246 nla_put_u32(msg
, NL80211_STA_INFO_PEER_PM
,
3248 goto nla_put_failure
;
3249 if ((sinfo
->filled
& STATION_INFO_NONPEER_PM
) &&
3250 nla_put_u32(msg
, NL80211_STA_INFO_NONPEER_PM
,
3252 goto nla_put_failure
;
3253 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
3254 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
3256 goto nla_put_failure
;
3258 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
3259 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
3260 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
3261 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
3262 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
3263 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
3264 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
3265 sinfo
->bss_param
.dtim_period
) ||
3266 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
3267 sinfo
->bss_param
.beacon_interval
))
3268 goto nla_put_failure
;
3270 nla_nest_end(msg
, bss_param
);
3272 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
3273 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
3274 sizeof(struct nl80211_sta_flag_update
),
3276 goto nla_put_failure
;
3277 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
3278 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
3280 goto nla_put_failure
;
3281 nla_nest_end(msg
, sinfoattr
);
3283 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
3284 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
3285 sinfo
->assoc_req_ies
))
3286 goto nla_put_failure
;
3288 return genlmsg_end(msg
, hdr
);
3291 genlmsg_cancel(msg
, hdr
);
3295 static int nl80211_dump_station(struct sk_buff
*skb
,
3296 struct netlink_callback
*cb
)
3298 struct station_info sinfo
;
3299 struct cfg80211_registered_device
*dev
;
3300 struct net_device
*netdev
;
3301 u8 mac_addr
[ETH_ALEN
];
3302 int sta_idx
= cb
->args
[1];
3305 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3309 if (!dev
->ops
->dump_station
) {
3315 memset(&sinfo
, 0, sizeof(sinfo
));
3316 err
= rdev_dump_station(dev
, netdev
, sta_idx
,
3323 if (nl80211_send_station(skb
,
3324 NETLINK_CB(cb
->skb
).portid
,
3325 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3326 dev
, netdev
, mac_addr
,
3335 cb
->args
[1] = sta_idx
;
3338 nl80211_finish_netdev_dump(dev
);
3343 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
3345 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3346 struct net_device
*dev
= info
->user_ptr
[1];
3347 struct station_info sinfo
;
3348 struct sk_buff
*msg
;
3349 u8
*mac_addr
= NULL
;
3352 memset(&sinfo
, 0, sizeof(sinfo
));
3354 if (!info
->attrs
[NL80211_ATTR_MAC
])
3357 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3359 if (!rdev
->ops
->get_station
)
3362 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3366 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3370 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3371 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3376 return genlmsg_reply(msg
, info
);
3380 * Get vlan interface making sure it is running and on the right wiphy.
3382 static struct net_device
*get_vlan(struct genl_info
*info
,
3383 struct cfg80211_registered_device
*rdev
)
3385 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3386 struct net_device
*v
;
3392 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3394 return ERR_PTR(-ENODEV
);
3396 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3401 if (!netif_running(v
)) {
3409 return ERR_PTR(ret
);
3412 static struct nla_policy
3413 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3414 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3415 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3418 static int nl80211_set_station_tdls(struct genl_info
*info
,
3419 struct station_parameters
*params
)
3421 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3425 /* Dummy STA entry gets updated once the peer capabilities are known */
3426 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3428 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3429 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3431 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3433 /* parse WME attributes if present */
3434 if (!info
->attrs
[NL80211_ATTR_STA_WME
])
3437 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3438 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3439 nl80211_sta_wme_policy
);
3443 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3444 params
->uapsd_queues
= nla_get_u8(
3445 tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3446 if (params
->uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3449 if (tb
[NL80211_STA_WME_MAX_SP
])
3450 params
->max_sp
= nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3452 if (params
->max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3455 params
->sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3460 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3462 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3464 struct net_device
*dev
= info
->user_ptr
[1];
3465 struct station_parameters params
;
3466 u8
*mac_addr
= NULL
;
3468 memset(¶ms
, 0, sizeof(params
));
3470 params
.listen_interval
= -1;
3471 params
.plink_state
= -1;
3473 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3476 if (!info
->attrs
[NL80211_ATTR_MAC
])
3479 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3481 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3482 params
.supported_rates
=
3483 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3484 params
.supported_rates_len
=
3485 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3488 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3490 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3491 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3494 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3496 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3497 params
.ext_capab_len
=
3498 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3501 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3504 if (!rdev
->ops
->change_station
)
3507 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3510 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3511 params
.plink_action
=
3512 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3514 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
3515 params
.plink_state
=
3516 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3518 if (info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]) {
3519 enum nl80211_mesh_power_mode pm
= nla_get_u32(
3520 info
->attrs
[NL80211_ATTR_LOCAL_MESH_POWER_MODE
]);
3522 if (pm
<= NL80211_MESH_POWER_UNKNOWN
||
3523 pm
> NL80211_MESH_POWER_MAX
)
3526 params
.local_pm
= pm
;
3529 switch (dev
->ieee80211_ptr
->iftype
) {
3530 case NL80211_IFTYPE_AP
:
3531 case NL80211_IFTYPE_AP_VLAN
:
3532 case NL80211_IFTYPE_P2P_GO
:
3533 /* disallow mesh-specific things */
3534 if (params
.plink_action
)
3536 if (params
.local_pm
)
3539 /* TDLS can't be set, ... */
3540 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3543 * ... but don't bother the driver with it. This works around
3544 * a hostapd/wpa_supplicant issue -- it always includes the
3545 * TLDS_PEER flag in the mask even for AP mode.
3547 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3549 /* accept only the listed bits */
3550 if (params
.sta_flags_mask
&
3551 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3552 BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3553 BIT(NL80211_STA_FLAG_ASSOCIATED
) |
3554 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3555 BIT(NL80211_STA_FLAG_WME
) |
3556 BIT(NL80211_STA_FLAG_MFP
)))
3559 /* but authenticated/associated only if driver handles it */
3560 if (!(rdev
->wiphy
.features
&
3561 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3562 params
.sta_flags_mask
&
3563 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3564 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3567 /* reject other things that can't change */
3568 if (params
.supported_rates
)
3570 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
])
3572 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
])
3574 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
] ||
3575 info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3578 /* must be last in here for error handling */
3579 params
.vlan
= get_vlan(info
, rdev
);
3580 if (IS_ERR(params
.vlan
))
3581 return PTR_ERR(params
.vlan
);
3583 case NL80211_IFTYPE_P2P_CLIENT
:
3584 case NL80211_IFTYPE_STATION
:
3586 * Don't allow userspace to change the TDLS_PEER flag,
3587 * but silently ignore attempts to change it since we
3588 * don't have state here to verify that it doesn't try
3589 * to change the flag.
3591 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3592 /* Include parameters for TDLS peer (driver will check) */
3593 err
= nl80211_set_station_tdls(info
, ¶ms
);
3596 /* disallow things sta doesn't support */
3597 if (params
.plink_action
)
3599 if (params
.local_pm
)
3601 /* reject any changes other than AUTHORIZED or WME (for TDLS) */
3602 if (params
.sta_flags_mask
& ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3603 BIT(NL80211_STA_FLAG_WME
)))
3606 case NL80211_IFTYPE_ADHOC
:
3607 /* disallow things sta doesn't support */
3608 if (params
.plink_action
)
3610 if (params
.local_pm
)
3612 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
] ||
3613 info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3615 /* reject any changes other than AUTHORIZED */
3616 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3619 case NL80211_IFTYPE_MESH_POINT
:
3620 /* disallow things mesh doesn't support */
3623 if (params
.supported_rates
)
3625 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
])
3627 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
])
3629 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
] ||
3630 info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3633 * No special handling for TDLS here -- the userspace
3634 * mesh code doesn't have this bug.
3636 if (params
.sta_flags_mask
&
3637 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3638 BIT(NL80211_STA_FLAG_MFP
) |
3639 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3646 /* be aware of params.vlan when changing code here */
3648 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3651 dev_put(params
.vlan
);
3656 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3658 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3660 struct net_device
*dev
= info
->user_ptr
[1];
3661 struct station_parameters params
;
3662 u8
*mac_addr
= NULL
;
3664 memset(¶ms
, 0, sizeof(params
));
3666 if (!info
->attrs
[NL80211_ATTR_MAC
])
3669 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3672 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3675 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3678 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3679 params
.supported_rates
=
3680 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3681 params
.supported_rates_len
=
3682 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3683 params
.listen_interval
=
3684 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3686 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3687 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3690 if (info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]) {
3692 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_CAPABILITY
]);
3693 params
.sta_modify_mask
|= STATION_PARAM_APPLY_CAPABILITY
;
3696 if (info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]) {
3698 nla_data(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3699 params
.ext_capab_len
=
3700 nla_len(info
->attrs
[NL80211_ATTR_STA_EXT_CAPABILITY
]);
3703 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3705 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3707 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3709 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3711 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3712 params
.plink_action
=
3713 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3715 if (!rdev
->ops
->add_station
)
3718 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3721 switch (dev
->ieee80211_ptr
->iftype
) {
3722 case NL80211_IFTYPE_AP
:
3723 case NL80211_IFTYPE_AP_VLAN
:
3724 case NL80211_IFTYPE_P2P_GO
:
3725 /* parse WME attributes if sta is WME capable */
3726 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3727 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3728 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3729 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3732 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3733 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3734 nl80211_sta_wme_policy
);
3738 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3739 params
.uapsd_queues
=
3740 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3741 if (params
.uapsd_queues
&
3742 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3745 if (tb
[NL80211_STA_WME_MAX_SP
])
3747 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3750 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3753 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3755 /* TDLS peers cannot be added */
3756 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3758 /* but don't bother the driver with it */
3759 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3761 /* allow authenticated/associated only if driver handles it */
3762 if (!(rdev
->wiphy
.features
&
3763 NL80211_FEATURE_FULL_AP_CLIENT_STATE
) &&
3764 params
.sta_flags_mask
&
3765 (BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3766 BIT(NL80211_STA_FLAG_ASSOCIATED
)))
3769 /* must be last in here for error handling */
3770 params
.vlan
= get_vlan(info
, rdev
);
3771 if (IS_ERR(params
.vlan
))
3772 return PTR_ERR(params
.vlan
);
3774 case NL80211_IFTYPE_MESH_POINT
:
3775 /* associated is disallowed */
3776 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
3778 /* TDLS peers cannot be added */
3779 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3782 case NL80211_IFTYPE_STATION
:
3783 /* associated is disallowed */
3784 if (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
3786 /* Only TDLS peers can be added */
3787 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3789 /* Can only add if TDLS ... */
3790 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3792 /* ... with external setup is supported */
3793 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3800 /* be aware of params.vlan when changing code here */
3802 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
3805 dev_put(params
.vlan
);
3809 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3811 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3812 struct net_device
*dev
= info
->user_ptr
[1];
3813 u8
*mac_addr
= NULL
;
3815 if (info
->attrs
[NL80211_ATTR_MAC
])
3816 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3818 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3819 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3820 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3821 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3824 if (!rdev
->ops
->del_station
)
3827 return rdev_del_station(rdev
, dev
, mac_addr
);
3830 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3831 int flags
, struct net_device
*dev
,
3832 u8
*dst
, u8
*next_hop
,
3833 struct mpath_info
*pinfo
)
3836 struct nlattr
*pinfoattr
;
3838 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3842 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3843 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3844 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3845 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3846 goto nla_put_failure
;
3848 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3850 goto nla_put_failure
;
3851 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3852 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3854 goto nla_put_failure
;
3855 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3856 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3857 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3858 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3860 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3861 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3863 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3864 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3866 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3867 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3868 pinfo
->discovery_timeout
)) ||
3869 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3870 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3871 pinfo
->discovery_retries
)))
3872 goto nla_put_failure
;
3874 nla_nest_end(msg
, pinfoattr
);
3876 return genlmsg_end(msg
, hdr
);
3879 genlmsg_cancel(msg
, hdr
);
3883 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3884 struct netlink_callback
*cb
)
3886 struct mpath_info pinfo
;
3887 struct cfg80211_registered_device
*dev
;
3888 struct net_device
*netdev
;
3890 u8 next_hop
[ETH_ALEN
];
3891 int path_idx
= cb
->args
[1];
3894 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3898 if (!dev
->ops
->dump_mpath
) {
3903 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3909 err
= rdev_dump_mpath(dev
, netdev
, path_idx
, dst
, next_hop
,
3916 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
3917 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3918 netdev
, dst
, next_hop
,
3927 cb
->args
[1] = path_idx
;
3930 nl80211_finish_netdev_dump(dev
);
3934 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3936 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3938 struct net_device
*dev
= info
->user_ptr
[1];
3939 struct mpath_info pinfo
;
3940 struct sk_buff
*msg
;
3942 u8 next_hop
[ETH_ALEN
];
3944 memset(&pinfo
, 0, sizeof(pinfo
));
3946 if (!info
->attrs
[NL80211_ATTR_MAC
])
3949 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3951 if (!rdev
->ops
->get_mpath
)
3954 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3957 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
3961 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3965 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3966 dev
, dst
, next_hop
, &pinfo
) < 0) {
3971 return genlmsg_reply(msg
, info
);
3974 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3976 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3977 struct net_device
*dev
= info
->user_ptr
[1];
3979 u8
*next_hop
= NULL
;
3981 if (!info
->attrs
[NL80211_ATTR_MAC
])
3984 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3987 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3988 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3990 if (!rdev
->ops
->change_mpath
)
3993 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3996 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
3999 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4001 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4002 struct net_device
*dev
= info
->user_ptr
[1];
4004 u8
*next_hop
= NULL
;
4006 if (!info
->attrs
[NL80211_ATTR_MAC
])
4009 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
4012 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4013 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
4015 if (!rdev
->ops
->add_mpath
)
4018 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4021 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
4024 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
4026 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4027 struct net_device
*dev
= info
->user_ptr
[1];
4030 if (info
->attrs
[NL80211_ATTR_MAC
])
4031 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4033 if (!rdev
->ops
->del_mpath
)
4036 return rdev_del_mpath(rdev
, dev
, dst
);
4039 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
4041 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4042 struct net_device
*dev
= info
->user_ptr
[1];
4043 struct bss_parameters params
;
4045 memset(¶ms
, 0, sizeof(params
));
4046 /* default to not changing parameters */
4047 params
.use_cts_prot
= -1;
4048 params
.use_short_preamble
= -1;
4049 params
.use_short_slot_time
= -1;
4050 params
.ap_isolate
= -1;
4051 params
.ht_opmode
= -1;
4052 params
.p2p_ctwindow
= -1;
4053 params
.p2p_opp_ps
= -1;
4055 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
4056 params
.use_cts_prot
=
4057 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
4058 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
4059 params
.use_short_preamble
=
4060 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
4061 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
4062 params
.use_short_slot_time
=
4063 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
4064 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4065 params
.basic_rates
=
4066 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4067 params
.basic_rates_len
=
4068 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4070 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
4071 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
4072 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
4074 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
4076 if (info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]) {
4077 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4079 params
.p2p_ctwindow
=
4080 nla_get_s8(info
->attrs
[NL80211_ATTR_P2P_CTWINDOW
]);
4081 if (params
.p2p_ctwindow
< 0)
4083 if (params
.p2p_ctwindow
!= 0 &&
4084 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_CTWIN
))
4088 if (info
->attrs
[NL80211_ATTR_P2P_OPPPS
]) {
4091 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4093 tmp
= nla_get_u8(info
->attrs
[NL80211_ATTR_P2P_OPPPS
]);
4096 params
.p2p_opp_ps
= tmp
;
4097 if (params
.p2p_opp_ps
&&
4098 !(rdev
->wiphy
.features
& NL80211_FEATURE_P2P_GO_OPPPS
))
4102 if (!rdev
->ops
->change_bss
)
4105 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4106 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4109 return rdev_change_bss(rdev
, dev
, ¶ms
);
4112 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
4113 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
4114 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
4115 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
4116 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
4117 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
4118 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
4121 static int parse_reg_rule(struct nlattr
*tb
[],
4122 struct ieee80211_reg_rule
*reg_rule
)
4124 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
4125 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
4127 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
4129 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
4131 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
4133 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
4135 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
4138 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
4140 freq_range
->start_freq_khz
=
4141 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
4142 freq_range
->end_freq_khz
=
4143 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
4144 freq_range
->max_bandwidth_khz
=
4145 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
4147 power_rule
->max_eirp
=
4148 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
4150 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
4151 power_rule
->max_antenna_gain
=
4152 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
4157 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4161 enum nl80211_user_reg_hint_type user_reg_hint_type
;
4164 * You should only get this when cfg80211 hasn't yet initialized
4165 * completely when built-in to the kernel right between the time
4166 * window between nl80211_init() and regulatory_init(), if that is
4169 if (unlikely(!rcu_access_pointer(cfg80211_regdomain
)))
4170 return -EINPROGRESS
;
4172 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4175 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4177 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
4178 user_reg_hint_type
=
4179 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
4181 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
4183 switch (user_reg_hint_type
) {
4184 case NL80211_USER_REG_HINT_USER
:
4185 case NL80211_USER_REG_HINT_CELL_BASE
:
4191 r
= regulatory_hint_user(data
, user_reg_hint_type
);
4196 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
4197 struct genl_info
*info
)
4199 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4200 struct net_device
*dev
= info
->user_ptr
[1];
4201 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4202 struct mesh_config cur_params
;
4205 struct nlattr
*pinfoattr
;
4206 struct sk_buff
*msg
;
4208 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4211 if (!rdev
->ops
->get_mesh_config
)
4215 /* If not connected, get default parameters */
4216 if (!wdev
->mesh_id_len
)
4217 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
4219 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
4225 /* Draw up a netlink message to send back */
4226 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4229 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4230 NL80211_CMD_GET_MESH_CONFIG
);
4233 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
4235 goto nla_put_failure
;
4236 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
4237 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4238 cur_params
.dot11MeshRetryTimeout
) ||
4239 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4240 cur_params
.dot11MeshConfirmTimeout
) ||
4241 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4242 cur_params
.dot11MeshHoldingTimeout
) ||
4243 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4244 cur_params
.dot11MeshMaxPeerLinks
) ||
4245 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
4246 cur_params
.dot11MeshMaxRetries
) ||
4247 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
4248 cur_params
.dot11MeshTTL
) ||
4249 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
4250 cur_params
.element_ttl
) ||
4251 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4252 cur_params
.auto_open_plinks
) ||
4253 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4254 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
4255 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4256 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
4257 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4258 cur_params
.path_refresh_time
) ||
4259 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4260 cur_params
.min_discovery_timeout
) ||
4261 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4262 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
4263 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4264 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
4265 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4266 cur_params
.dot11MeshHWMPperrMinInterval
) ||
4267 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4268 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
4269 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4270 cur_params
.dot11MeshHWMPRootMode
) ||
4271 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4272 cur_params
.dot11MeshHWMPRannInterval
) ||
4273 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4274 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
4275 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
4276 cur_params
.dot11MeshForwarding
) ||
4277 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4278 cur_params
.rssi_threshold
) ||
4279 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
4280 cur_params
.ht_opmode
) ||
4281 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4282 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
4283 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4284 cur_params
.dot11MeshHWMProotInterval
) ||
4285 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4286 cur_params
.dot11MeshHWMPconfirmationInterval
) ||
4287 nla_put_u32(msg
, NL80211_MESHCONF_POWER_MODE
,
4288 cur_params
.power_mode
) ||
4289 nla_put_u16(msg
, NL80211_MESHCONF_AWAKE_WINDOW
,
4290 cur_params
.dot11MeshAwakeWindowDuration
))
4291 goto nla_put_failure
;
4292 nla_nest_end(msg
, pinfoattr
);
4293 genlmsg_end(msg
, hdr
);
4294 return genlmsg_reply(msg
, info
);
4297 genlmsg_cancel(msg
, hdr
);
4303 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
4304 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
4305 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
4306 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
4307 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
4308 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
4309 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
4310 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
4311 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
4312 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
4313 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
4314 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
4315 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
4316 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
4317 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
4318 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
4319 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
4320 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
4321 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
4322 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
4323 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
4324 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
4325 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
4326 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
4327 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
4328 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
4329 [NL80211_MESHCONF_POWER_MODE
] = { .type
= NLA_U32
},
4330 [NL80211_MESHCONF_AWAKE_WINDOW
] = { .type
= NLA_U16
},
4333 static const struct nla_policy
4334 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
4335 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
4336 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
4337 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
4338 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
4339 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
4340 .len
= IEEE80211_MAX_DATA_LEN
},
4341 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
4344 static int nl80211_parse_mesh_config(struct genl_info
*info
,
4345 struct mesh_config
*cfg
,
4348 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
4351 #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
4354 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
4356 cfg->param = fn(tb[attr]); \
4357 mask |= (1 << (attr - 1)); \
4362 if (!info
->attrs
[NL80211_ATTR_MESH_CONFIG
])
4364 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
4365 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
4366 nl80211_meshconf_params_policy
))
4369 /* This makes sure that there aren't more than 32 mesh config
4370 * parameters (otherwise our bitfield scheme would not work.) */
4371 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
4373 /* Fill in the params struct */
4374 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
, 1, 255,
4375 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
4377 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
, 1, 255,
4378 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
4380 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
, 1, 255,
4381 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
4383 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
, 0, 255,
4384 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
4386 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
, 0, 16,
4387 mask
, NL80211_MESHCONF_MAX_RETRIES
,
4389 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
, 1, 255,
4390 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
4391 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
, 1, 255,
4392 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
4394 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
, 0, 1,
4395 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
4397 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
,
4399 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
4401 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
, 0, 255,
4402 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
4404 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
, 1, 65535,
4405 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
4407 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
, 1, 65535,
4408 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
4410 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
4412 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
4414 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
4416 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
4418 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
4420 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
4422 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4423 dot11MeshHWMPnetDiameterTraversalTime
,
4425 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
4427 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, 0, 4,
4428 mask
, NL80211_MESHCONF_HWMP_ROOTMODE
,
4430 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, 1, 65535,
4431 mask
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
4433 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4434 dot11MeshGateAnnouncementProtocol
, 0, 1,
4435 mask
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
4437 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
, 0, 1,
4438 mask
, NL80211_MESHCONF_FORWARDING
,
4440 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
, 1, 255,
4441 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
4443 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
, 0, 16,
4444 mask
, NL80211_MESHCONF_HT_OPMODE
,
4446 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
4448 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
4450 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
, 1, 65535,
4451 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
4453 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
4454 dot11MeshHWMPconfirmationInterval
,
4456 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
4458 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, power_mode
,
4459 NL80211_MESH_POWER_ACTIVE
,
4460 NL80211_MESH_POWER_MAX
,
4461 mask
, NL80211_MESHCONF_POWER_MODE
,
4463 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshAwakeWindowDuration
,
4465 NL80211_MESHCONF_AWAKE_WINDOW
, nla_get_u16
);
4471 #undef FILL_IN_MESH_PARAM_IF_SET
4474 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
4475 struct mesh_setup
*setup
)
4477 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
4479 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
4481 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
4482 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
4483 nl80211_mesh_setup_params_policy
))
4486 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
4487 setup
->sync_method
=
4488 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
4489 IEEE80211_SYNC_METHOD_VENDOR
:
4490 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
4492 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
4493 setup
->path_sel_proto
=
4494 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
4495 IEEE80211_PATH_PROTOCOL_VENDOR
:
4496 IEEE80211_PATH_PROTOCOL_HWMP
;
4498 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
4499 setup
->path_metric
=
4500 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
4501 IEEE80211_PATH_METRIC_VENDOR
:
4502 IEEE80211_PATH_METRIC_AIRTIME
;
4505 if (tb
[NL80211_MESH_SETUP_IE
]) {
4506 struct nlattr
*ieattr
=
4507 tb
[NL80211_MESH_SETUP_IE
];
4508 if (!is_valid_ie_attr(ieattr
))
4510 setup
->ie
= nla_data(ieattr
);
4511 setup
->ie_len
= nla_len(ieattr
);
4513 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
4514 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
4519 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
4520 struct genl_info
*info
)
4522 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4523 struct net_device
*dev
= info
->user_ptr
[1];
4524 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
4525 struct mesh_config cfg
;
4529 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
4532 if (!rdev
->ops
->update_mesh_config
)
4535 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4540 if (!wdev
->mesh_id_len
)
4544 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4551 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4553 const struct ieee80211_regdomain
*regdom
;
4554 struct sk_buff
*msg
;
4556 struct nlattr
*nl_reg_rules
;
4560 mutex_lock(&cfg80211_mutex
);
4562 if (!cfg80211_regdomain
)
4565 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4571 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4572 NL80211_CMD_GET_REG
);
4576 if (reg_last_request_cell_base() &&
4577 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4578 NL80211_USER_REG_HINT_CELL_BASE
))
4579 goto nla_put_failure
;
4582 regdom
= rcu_dereference(cfg80211_regdomain
);
4584 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
, regdom
->alpha2
) ||
4585 (regdom
->dfs_region
&&
4586 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
, regdom
->dfs_region
)))
4587 goto nla_put_failure_rcu
;
4589 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4591 goto nla_put_failure_rcu
;
4593 for (i
= 0; i
< regdom
->n_reg_rules
; i
++) {
4594 struct nlattr
*nl_reg_rule
;
4595 const struct ieee80211_reg_rule
*reg_rule
;
4596 const struct ieee80211_freq_range
*freq_range
;
4597 const struct ieee80211_power_rule
*power_rule
;
4599 reg_rule
= ®dom
->reg_rules
[i
];
4600 freq_range
= ®_rule
->freq_range
;
4601 power_rule
= ®_rule
->power_rule
;
4603 nl_reg_rule
= nla_nest_start(msg
, i
);
4605 goto nla_put_failure_rcu
;
4607 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4609 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4610 freq_range
->start_freq_khz
) ||
4611 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4612 freq_range
->end_freq_khz
) ||
4613 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4614 freq_range
->max_bandwidth_khz
) ||
4615 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4616 power_rule
->max_antenna_gain
) ||
4617 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4618 power_rule
->max_eirp
))
4619 goto nla_put_failure_rcu
;
4621 nla_nest_end(msg
, nl_reg_rule
);
4625 nla_nest_end(msg
, nl_reg_rules
);
4627 genlmsg_end(msg
, hdr
);
4628 err
= genlmsg_reply(msg
, info
);
4631 nla_put_failure_rcu
:
4634 genlmsg_cancel(msg
, hdr
);
4639 mutex_unlock(&cfg80211_mutex
);
4643 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4645 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4646 struct nlattr
*nl_reg_rule
;
4647 char *alpha2
= NULL
;
4648 int rem_reg_rules
= 0, r
= 0;
4649 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4651 struct ieee80211_regdomain
*rd
= NULL
;
4653 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4656 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4659 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4661 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4662 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4664 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4667 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4671 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4672 num_rules
* sizeof(struct ieee80211_reg_rule
);
4674 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4678 rd
->n_reg_rules
= num_rules
;
4679 rd
->alpha2
[0] = alpha2
[0];
4680 rd
->alpha2
[1] = alpha2
[1];
4683 * Disable DFS master mode if the DFS region was
4684 * not supported or known on this kernel.
4686 if (reg_supported_dfs_region(dfs_region
))
4687 rd
->dfs_region
= dfs_region
;
4689 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4691 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4692 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
4694 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
4700 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
4706 mutex_lock(&cfg80211_mutex
);
4709 /* set_regdom took ownership */
4711 mutex_unlock(&cfg80211_mutex
);
4718 static int validate_scan_freqs(struct nlattr
*freqs
)
4720 struct nlattr
*attr1
, *attr2
;
4721 int n_channels
= 0, tmp1
, tmp2
;
4723 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4726 * Some hardware has a limited channel list for
4727 * scanning, and it is pretty much nonsensical
4728 * to scan for a channel twice, so disallow that
4729 * and don't require drivers to check that the
4730 * channel list they get isn't longer than what
4731 * they can scan, as long as they can scan all
4732 * the channels they registered at once.
4734 nla_for_each_nested(attr2
, freqs
, tmp2
)
4735 if (attr1
!= attr2
&&
4736 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4743 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4745 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4746 struct wireless_dev
*wdev
= info
->user_ptr
[1];
4747 struct cfg80211_scan_request
*request
;
4748 struct nlattr
*attr
;
4749 struct wiphy
*wiphy
;
4750 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4753 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4756 wiphy
= &rdev
->wiphy
;
4758 if (!rdev
->ops
->scan
)
4764 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4765 n_channels
= validate_scan_freqs(
4766 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4770 enum ieee80211_band band
;
4773 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4774 if (wiphy
->bands
[band
])
4775 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4778 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4779 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4782 if (n_ssids
> wiphy
->max_scan_ssids
)
4785 if (info
->attrs
[NL80211_ATTR_IE
])
4786 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4790 if (ie_len
> wiphy
->max_scan_ie_len
)
4793 request
= kzalloc(sizeof(*request
)
4794 + sizeof(*request
->ssids
) * n_ssids
4795 + sizeof(*request
->channels
) * n_channels
4796 + ie_len
, GFP_KERNEL
);
4801 request
->ssids
= (void *)&request
->channels
[n_channels
];
4802 request
->n_ssids
= n_ssids
;
4805 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4807 request
->ie
= (void *)(request
->channels
+ n_channels
);
4811 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4812 /* user specified, bail out if channel not found */
4813 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4814 struct ieee80211_channel
*chan
;
4816 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4823 /* ignore disabled channels */
4824 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4827 request
->channels
[i
] = chan
;
4831 enum ieee80211_band band
;
4834 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4836 if (!wiphy
->bands
[band
])
4838 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4839 struct ieee80211_channel
*chan
;
4841 chan
= &wiphy
->bands
[band
]->channels
[j
];
4843 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4846 request
->channels
[i
] = chan
;
4857 request
->n_channels
= i
;
4860 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4861 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4862 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4866 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4867 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4872 if (info
->attrs
[NL80211_ATTR_IE
]) {
4873 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4874 memcpy((void *)request
->ie
,
4875 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4879 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4880 if (wiphy
->bands
[i
])
4882 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4884 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4885 nla_for_each_nested(attr
,
4886 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4888 enum ieee80211_band band
= nla_type(attr
);
4890 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4894 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4897 &request
->rates
[band
]);
4903 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
4904 request
->flags
= nla_get_u32(
4905 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
4906 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
4907 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
4908 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
4909 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
4916 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4918 request
->wdev
= wdev
;
4919 request
->wiphy
= &rdev
->wiphy
;
4920 request
->scan_start
= jiffies
;
4922 rdev
->scan_req
= request
;
4923 err
= rdev_scan(rdev
, request
);
4926 nl80211_send_scan_start(rdev
, wdev
);
4928 dev_hold(wdev
->netdev
);
4931 rdev
->scan_req
= NULL
;
4938 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4939 struct genl_info
*info
)
4941 struct cfg80211_sched_scan_request
*request
;
4942 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4943 struct net_device
*dev
= info
->user_ptr
[1];
4944 struct nlattr
*attr
;
4945 struct wiphy
*wiphy
;
4946 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4948 enum ieee80211_band band
;
4950 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4952 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4953 !rdev
->ops
->sched_scan_start
)
4956 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4959 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4962 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4966 wiphy
= &rdev
->wiphy
;
4968 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4969 n_channels
= validate_scan_freqs(
4970 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4976 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4977 if (wiphy
->bands
[band
])
4978 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4981 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4982 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4986 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4989 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4990 nla_for_each_nested(attr
,
4991 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4995 if (n_match_sets
> wiphy
->max_match_sets
)
4998 if (info
->attrs
[NL80211_ATTR_IE
])
4999 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5003 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
5006 mutex_lock(&rdev
->sched_scan_mtx
);
5008 if (rdev
->sched_scan_req
) {
5013 request
= kzalloc(sizeof(*request
)
5014 + sizeof(*request
->ssids
) * n_ssids
5015 + sizeof(*request
->match_sets
) * n_match_sets
5016 + sizeof(*request
->channels
) * n_channels
5017 + ie_len
, GFP_KERNEL
);
5024 request
->ssids
= (void *)&request
->channels
[n_channels
];
5025 request
->n_ssids
= n_ssids
;
5028 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
5030 request
->ie
= (void *)(request
->channels
+ n_channels
);
5035 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
5036 else if (request
->ssids
)
5037 request
->match_sets
=
5038 (void *)(request
->ssids
+ n_ssids
);
5040 request
->match_sets
=
5041 (void *)(request
->channels
+ n_channels
);
5043 request
->n_match_sets
= n_match_sets
;
5046 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
5047 /* user specified, bail out if channel not found */
5048 nla_for_each_nested(attr
,
5049 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
5051 struct ieee80211_channel
*chan
;
5053 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
5060 /* ignore disabled channels */
5061 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5064 request
->channels
[i
] = chan
;
5069 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5071 if (!wiphy
->bands
[band
])
5073 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
5074 struct ieee80211_channel
*chan
;
5076 chan
= &wiphy
->bands
[band
]->channels
[j
];
5078 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
5081 request
->channels
[i
] = chan
;
5092 request
->n_channels
= i
;
5095 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
5096 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
5098 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
5102 request
->ssids
[i
].ssid_len
= nla_len(attr
);
5103 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
5110 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
5111 nla_for_each_nested(attr
,
5112 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
5114 struct nlattr
*ssid
, *rssi
;
5116 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
5117 nla_data(attr
), nla_len(attr
),
5118 nl80211_match_policy
);
5119 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
5121 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
5125 memcpy(request
->match_sets
[i
].ssid
.ssid
,
5126 nla_data(ssid
), nla_len(ssid
));
5127 request
->match_sets
[i
].ssid
.ssid_len
=
5130 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
5132 request
->rssi_thold
= nla_get_u32(rssi
);
5134 request
->rssi_thold
=
5135 NL80211_SCAN_RSSI_THOLD_OFF
;
5140 if (info
->attrs
[NL80211_ATTR_IE
]) {
5141 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5142 memcpy((void *)request
->ie
,
5143 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5147 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
5148 request
->flags
= nla_get_u32(
5149 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
5150 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
5151 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
5152 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
5153 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
5160 request
->wiphy
= &rdev
->wiphy
;
5161 request
->interval
= interval
;
5162 request
->scan_start
= jiffies
;
5164 err
= rdev_sched_scan_start(rdev
, dev
, request
);
5166 rdev
->sched_scan_req
= request
;
5167 nl80211_send_sched_scan(rdev
, dev
,
5168 NL80211_CMD_START_SCHED_SCAN
);
5175 mutex_unlock(&rdev
->sched_scan_mtx
);
5179 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
5180 struct genl_info
*info
)
5182 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5185 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
5186 !rdev
->ops
->sched_scan_stop
)
5189 mutex_lock(&rdev
->sched_scan_mtx
);
5190 err
= __cfg80211_stop_sched_scan(rdev
, false);
5191 mutex_unlock(&rdev
->sched_scan_mtx
);
5196 static int nl80211_start_radar_detection(struct sk_buff
*skb
,
5197 struct genl_info
*info
)
5199 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5200 struct net_device
*dev
= info
->user_ptr
[1];
5201 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5202 struct cfg80211_chan_def chandef
;
5205 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
5209 if (wdev
->cac_started
)
5212 err
= cfg80211_chandef_dfs_required(wdev
->wiphy
, &chandef
);
5219 if (chandef
.chan
->dfs_state
!= NL80211_DFS_USABLE
)
5222 if (!rdev
->ops
->start_radar_detection
)
5225 mutex_lock(&rdev
->devlist_mtx
);
5226 err
= cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
5227 chandef
.chan
, CHAN_MODE_SHARED
,
5228 BIT(chandef
.width
));
5232 err
= rdev
->ops
->start_radar_detection(&rdev
->wiphy
, dev
, &chandef
);
5234 wdev
->channel
= chandef
.chan
;
5235 wdev
->cac_started
= true;
5236 wdev
->cac_start_time
= jiffies
;
5239 mutex_unlock(&rdev
->devlist_mtx
);
5244 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
5246 struct cfg80211_registered_device
*rdev
,
5247 struct wireless_dev
*wdev
,
5248 struct cfg80211_internal_bss
*intbss
)
5250 struct cfg80211_bss
*res
= &intbss
->pub
;
5251 const struct cfg80211_bss_ies
*ies
;
5256 ASSERT_WDEV_LOCK(wdev
);
5258 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
5259 NL80211_CMD_NEW_SCAN_RESULTS
);
5263 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
5265 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
5266 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
5267 goto nla_put_failure
;
5269 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
5271 goto nla_put_failure
;
5272 if ((!is_zero_ether_addr(res
->bssid
) &&
5273 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)))
5274 goto nla_put_failure
;
5277 ies
= rcu_dereference(res
->ies
);
5279 if (nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5280 goto fail_unlock_rcu
;
5282 if (ies
->len
&& nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
5283 ies
->len
, ies
->data
))
5284 goto fail_unlock_rcu
;
5286 ies
= rcu_dereference(res
->beacon_ies
);
5288 if (!tsf
&& nla_put_u64(msg
, NL80211_BSS_TSF
, ies
->tsf
))
5289 goto fail_unlock_rcu
;
5290 if (ies
->len
&& nla_put(msg
, NL80211_BSS_BEACON_IES
,
5291 ies
->len
, ies
->data
))
5292 goto fail_unlock_rcu
;
5296 if (res
->beacon_interval
&&
5297 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
5298 goto nla_put_failure
;
5299 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
5300 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
5301 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
5302 jiffies_to_msecs(jiffies
- intbss
->ts
)))
5303 goto nla_put_failure
;
5305 switch (rdev
->wiphy
.signal_type
) {
5306 case CFG80211_SIGNAL_TYPE_MBM
:
5307 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
5308 goto nla_put_failure
;
5310 case CFG80211_SIGNAL_TYPE_UNSPEC
:
5311 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
5312 goto nla_put_failure
;
5318 switch (wdev
->iftype
) {
5319 case NL80211_IFTYPE_P2P_CLIENT
:
5320 case NL80211_IFTYPE_STATION
:
5321 if (intbss
== wdev
->current_bss
&&
5322 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5323 NL80211_BSS_STATUS_ASSOCIATED
))
5324 goto nla_put_failure
;
5326 case NL80211_IFTYPE_ADHOC
:
5327 if (intbss
== wdev
->current_bss
&&
5328 nla_put_u32(msg
, NL80211_BSS_STATUS
,
5329 NL80211_BSS_STATUS_IBSS_JOINED
))
5330 goto nla_put_failure
;
5336 nla_nest_end(msg
, bss
);
5338 return genlmsg_end(msg
, hdr
);
5343 genlmsg_cancel(msg
, hdr
);
5347 static int nl80211_dump_scan(struct sk_buff
*skb
,
5348 struct netlink_callback
*cb
)
5350 struct cfg80211_registered_device
*rdev
;
5351 struct net_device
*dev
;
5352 struct cfg80211_internal_bss
*scan
;
5353 struct wireless_dev
*wdev
;
5354 int start
= cb
->args
[1], idx
= 0;
5357 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
5361 wdev
= dev
->ieee80211_ptr
;
5364 spin_lock_bh(&rdev
->bss_lock
);
5365 cfg80211_bss_expire(rdev
);
5367 cb
->seq
= rdev
->bss_generation
;
5369 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
5372 if (nl80211_send_bss(skb
, cb
,
5373 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5374 rdev
, wdev
, scan
) < 0) {
5380 spin_unlock_bh(&rdev
->bss_lock
);
5384 nl80211_finish_netdev_dump(rdev
);
5389 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
5390 int flags
, struct net_device
*dev
,
5391 struct survey_info
*survey
)
5394 struct nlattr
*infoattr
;
5396 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
5397 NL80211_CMD_NEW_SURVEY_RESULTS
);
5401 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
5402 goto nla_put_failure
;
5404 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
5406 goto nla_put_failure
;
5408 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
5409 survey
->channel
->center_freq
))
5410 goto nla_put_failure
;
5412 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
5413 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
5414 goto nla_put_failure
;
5415 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
5416 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
5417 goto nla_put_failure
;
5418 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
5419 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
5420 survey
->channel_time
))
5421 goto nla_put_failure
;
5422 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
5423 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
5424 survey
->channel_time_busy
))
5425 goto nla_put_failure
;
5426 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
5427 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
5428 survey
->channel_time_ext_busy
))
5429 goto nla_put_failure
;
5430 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
5431 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
5432 survey
->channel_time_rx
))
5433 goto nla_put_failure
;
5434 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
5435 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
5436 survey
->channel_time_tx
))
5437 goto nla_put_failure
;
5439 nla_nest_end(msg
, infoattr
);
5441 return genlmsg_end(msg
, hdr
);
5444 genlmsg_cancel(msg
, hdr
);
5448 static int nl80211_dump_survey(struct sk_buff
*skb
,
5449 struct netlink_callback
*cb
)
5451 struct survey_info survey
;
5452 struct cfg80211_registered_device
*dev
;
5453 struct net_device
*netdev
;
5454 int survey_idx
= cb
->args
[1];
5457 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
5461 if (!dev
->ops
->dump_survey
) {
5467 struct ieee80211_channel
*chan
;
5469 res
= rdev_dump_survey(dev
, netdev
, survey_idx
, &survey
);
5475 /* Survey without a channel doesn't make sense */
5476 if (!survey
.channel
) {
5481 chan
= ieee80211_get_channel(&dev
->wiphy
,
5482 survey
.channel
->center_freq
);
5483 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
5488 if (nl80211_send_survey(skb
,
5489 NETLINK_CB(cb
->skb
).portid
,
5490 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5498 cb
->args
[1] = survey_idx
;
5501 nl80211_finish_netdev_dump(dev
);
5505 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
5507 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
5508 NL80211_WPA_VERSION_2
));
5511 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5513 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5514 struct net_device
*dev
= info
->user_ptr
[1];
5515 struct ieee80211_channel
*chan
;
5516 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
5517 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
5518 enum nl80211_auth_type auth_type
;
5519 struct key_parse key
;
5520 bool local_state_change
;
5522 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5525 if (!info
->attrs
[NL80211_ATTR_MAC
])
5528 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
5531 if (!info
->attrs
[NL80211_ATTR_SSID
])
5534 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5537 err
= nl80211_parse_key(info
, &key
);
5542 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
5544 if (!key
.p
.key
|| !key
.p
.key_len
)
5546 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
5547 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
5548 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
5549 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
5561 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
5562 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
5571 if (!rdev
->ops
->auth
)
5574 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5575 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5578 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5579 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5580 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5581 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5584 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5585 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5587 if (info
->attrs
[NL80211_ATTR_IE
]) {
5588 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5589 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5592 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5593 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5596 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5597 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5600 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5601 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5603 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5604 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5605 /* need to include at least Auth Transaction and Status Code */
5606 if (sae_data_len
< 4)
5610 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5613 * Since we no longer track auth state, ignore
5614 * requests to only change local state.
5616 if (local_state_change
)
5619 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5620 ssid
, ssid_len
, ie
, ie_len
,
5621 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5622 sae_data
, sae_data_len
);
5625 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5626 struct genl_info
*info
,
5627 struct cfg80211_crypto_settings
*settings
,
5630 memset(settings
, 0, sizeof(*settings
));
5632 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5634 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5636 proto
= nla_get_u16(
5637 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5638 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5639 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5642 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5643 settings
->control_port_no_encrypt
= true;
5645 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5647 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5651 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5652 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5653 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5655 if (len
% sizeof(u32
))
5658 if (settings
->n_ciphers_pairwise
> cipher_limit
)
5661 memcpy(settings
->ciphers_pairwise
, data
, len
);
5663 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
5664 if (!cfg80211_supported_cipher_suite(
5666 settings
->ciphers_pairwise
[i
]))
5670 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
5671 settings
->cipher_group
=
5672 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
5673 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
5674 settings
->cipher_group
))
5678 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
5679 settings
->wpa_versions
=
5680 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
5681 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
5685 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
5689 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5690 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5691 settings
->n_akm_suites
= len
/ sizeof(u32
);
5693 if (len
% sizeof(u32
))
5696 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
5699 memcpy(settings
->akm_suites
, data
, len
);
5705 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
5707 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5708 struct net_device
*dev
= info
->user_ptr
[1];
5709 struct cfg80211_crypto_settings crypto
;
5710 struct ieee80211_channel
*chan
;
5711 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
5712 int err
, ssid_len
, ie_len
= 0;
5713 bool use_mfp
= false;
5715 struct ieee80211_ht_cap
*ht_capa
= NULL
;
5716 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
5718 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5721 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
5722 !info
->attrs
[NL80211_ATTR_SSID
] ||
5723 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5726 if (!rdev
->ops
->assoc
)
5729 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5730 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5733 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5735 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5736 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5737 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5740 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5741 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5743 if (info
->attrs
[NL80211_ATTR_IE
]) {
5744 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5745 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5748 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
5749 enum nl80211_mfp mfp
=
5750 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
5751 if (mfp
== NL80211_MFP_REQUIRED
)
5753 else if (mfp
!= NL80211_MFP_NO
)
5757 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
5758 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
5760 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5761 flags
|= ASSOC_REQ_DISABLE_HT
;
5763 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5765 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
5767 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5770 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5773 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
5775 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
5776 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
5777 &crypto
, flags
, ht_capa
,
5783 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5785 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5786 struct net_device
*dev
= info
->user_ptr
[1];
5787 const u8
*ie
= NULL
, *bssid
;
5790 bool local_state_change
;
5792 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5795 if (!info
->attrs
[NL80211_ATTR_MAC
])
5798 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5801 if (!rdev
->ops
->deauth
)
5804 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5805 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5808 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5810 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5811 if (reason_code
== 0) {
5812 /* Reason Code 0 is reserved */
5816 if (info
->attrs
[NL80211_ATTR_IE
]) {
5817 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5818 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5821 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5823 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5824 local_state_change
);
5827 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5829 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5830 struct net_device
*dev
= info
->user_ptr
[1];
5831 const u8
*ie
= NULL
, *bssid
;
5834 bool local_state_change
;
5836 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5839 if (!info
->attrs
[NL80211_ATTR_MAC
])
5842 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5845 if (!rdev
->ops
->disassoc
)
5848 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5849 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5852 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5854 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5855 if (reason_code
== 0) {
5856 /* Reason Code 0 is reserved */
5860 if (info
->attrs
[NL80211_ATTR_IE
]) {
5861 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5862 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5865 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5867 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5868 local_state_change
);
5872 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5873 int mcast_rate
[IEEE80211_NUM_BANDS
],
5876 struct wiphy
*wiphy
= &rdev
->wiphy
;
5880 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5881 struct ieee80211_supported_band
*sband
;
5883 sband
= wiphy
->bands
[band
];
5887 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5888 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5889 mcast_rate
[band
] = i
+ 1;
5899 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5901 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5902 struct net_device
*dev
= info
->user_ptr
[1];
5903 struct cfg80211_ibss_params ibss
;
5904 struct wiphy
*wiphy
;
5905 struct cfg80211_cached_keys
*connkeys
= NULL
;
5908 memset(&ibss
, 0, sizeof(ibss
));
5910 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5913 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5914 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5917 ibss
.beacon_interval
= 100;
5919 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5920 ibss
.beacon_interval
=
5921 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5922 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5926 if (!rdev
->ops
->join_ibss
)
5929 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5932 wiphy
= &rdev
->wiphy
;
5934 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5935 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5937 if (!is_valid_ether_addr(ibss
.bssid
))
5940 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5941 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5943 if (info
->attrs
[NL80211_ATTR_IE
]) {
5944 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5945 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5948 err
= nl80211_parse_chandef(rdev
, info
, &ibss
.chandef
);
5952 if (!cfg80211_reg_can_beacon(&rdev
->wiphy
, &ibss
.chandef
))
5955 if (ibss
.chandef
.width
> NL80211_CHAN_WIDTH_40
)
5957 if (ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
&&
5958 !(rdev
->wiphy
.features
& NL80211_FEATURE_HT_IBSS
))
5961 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5962 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5964 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5966 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5968 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5969 struct ieee80211_supported_band
*sband
=
5970 wiphy
->bands
[ibss
.chandef
.chan
->band
];
5972 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5978 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5979 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5980 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5983 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5986 connkeys
= nl80211_parse_connkeys(rdev
,
5987 info
->attrs
[NL80211_ATTR_KEYS
],
5989 if (IS_ERR(connkeys
))
5990 return PTR_ERR(connkeys
);
5992 if ((ibss
.chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
) &&
6000 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
6002 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
6008 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
6010 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6011 struct net_device
*dev
= info
->user_ptr
[1];
6013 if (!rdev
->ops
->leave_ibss
)
6016 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
6019 return cfg80211_leave_ibss(rdev
, dev
, false);
6022 static int nl80211_set_mcast_rate(struct sk_buff
*skb
, struct genl_info
*info
)
6024 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6025 struct net_device
*dev
= info
->user_ptr
[1];
6026 int mcast_rate
[IEEE80211_NUM_BANDS
];
6030 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
6031 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
6034 if (!rdev
->ops
->set_mcast_rate
)
6037 memset(mcast_rate
, 0, sizeof(mcast_rate
));
6039 if (!info
->attrs
[NL80211_ATTR_MCAST_RATE
])
6042 nla_rate
= nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
]);
6043 if (!nl80211_parse_mcast_rate(rdev
, mcast_rate
, nla_rate
))
6046 err
= rdev
->ops
->set_mcast_rate(&rdev
->wiphy
, dev
, mcast_rate
);
6052 #ifdef CONFIG_NL80211_TESTMODE
6053 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
6057 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
6059 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6062 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
6066 if (rdev
->ops
->testmode_cmd
) {
6067 rdev
->testmode_info
= info
;
6068 err
= rdev_testmode_cmd(rdev
,
6069 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
6070 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
6071 rdev
->testmode_info
= NULL
;
6077 static int nl80211_testmode_dump(struct sk_buff
*skb
,
6078 struct netlink_callback
*cb
)
6080 struct cfg80211_registered_device
*rdev
;
6088 * 0 is a valid index, but not valid for args[0],
6089 * so we need to offset by 1.
6091 phy_idx
= cb
->args
[0] - 1;
6093 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
6094 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
6099 mutex_lock(&cfg80211_mutex
);
6100 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
6101 nl80211_fam
.attrbuf
);
6103 mutex_unlock(&cfg80211_mutex
);
6104 return PTR_ERR(rdev
);
6106 phy_idx
= rdev
->wiphy_idx
;
6108 mutex_unlock(&cfg80211_mutex
);
6110 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
6112 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
6116 data
= nla_data((void *)cb
->args
[1]);
6117 data_len
= nla_len((void *)cb
->args
[1]);
6120 mutex_lock(&cfg80211_mutex
);
6121 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
6123 mutex_unlock(&cfg80211_mutex
);
6126 cfg80211_lock_rdev(rdev
);
6127 mutex_unlock(&cfg80211_mutex
);
6129 if (!rdev
->ops
->testmode_dump
) {
6135 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
6136 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
6137 NL80211_CMD_TESTMODE
);
6138 struct nlattr
*tmdata
;
6140 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
6141 genlmsg_cancel(skb
, hdr
);
6145 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6147 genlmsg_cancel(skb
, hdr
);
6150 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
6151 nla_nest_end(skb
, tmdata
);
6153 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
6154 genlmsg_cancel(skb
, hdr
);
6157 genlmsg_cancel(skb
, hdr
);
6161 genlmsg_end(skb
, hdr
);
6166 cb
->args
[0] = phy_idx
+ 1;
6168 cfg80211_unlock_rdev(rdev
);
6172 static struct sk_buff
*
6173 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
6174 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
6176 struct sk_buff
*skb
;
6178 struct nlattr
*data
;
6180 skb
= nlmsg_new(approxlen
+ 100, gfp
);
6184 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
6190 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
6191 goto nla_put_failure
;
6192 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
6194 ((void **)skb
->cb
)[0] = rdev
;
6195 ((void **)skb
->cb
)[1] = hdr
;
6196 ((void **)skb
->cb
)[2] = data
;
6205 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
6208 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6210 if (WARN_ON(!rdev
->testmode_info
))
6213 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
6214 rdev
->testmode_info
->snd_portid
,
6215 rdev
->testmode_info
->snd_seq
,
6218 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
6220 int cfg80211_testmode_reply(struct sk_buff
*skb
)
6222 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
6223 void *hdr
= ((void **)skb
->cb
)[1];
6224 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6226 if (WARN_ON(!rdev
->testmode_info
)) {
6231 nla_nest_end(skb
, data
);
6232 genlmsg_end(skb
, hdr
);
6233 return genlmsg_reply(skb
, rdev
->testmode_info
);
6235 EXPORT_SYMBOL(cfg80211_testmode_reply
);
6237 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
6238 int approxlen
, gfp_t gfp
)
6240 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
6242 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
6244 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
6246 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
6248 void *hdr
= ((void **)skb
->cb
)[1];
6249 struct nlattr
*data
= ((void **)skb
->cb
)[2];
6251 nla_nest_end(skb
, data
);
6252 genlmsg_end(skb
, hdr
);
6253 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
6255 EXPORT_SYMBOL(cfg80211_testmode_event
);
6258 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
6260 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6261 struct net_device
*dev
= info
->user_ptr
[1];
6262 struct cfg80211_connect_params connect
;
6263 struct wiphy
*wiphy
;
6264 struct cfg80211_cached_keys
*connkeys
= NULL
;
6267 memset(&connect
, 0, sizeof(connect
));
6269 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
6272 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
6273 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
6276 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
6278 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
6279 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
6280 NL80211_CMD_CONNECT
))
6283 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
6285 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
6287 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
6288 NL80211_MAX_NR_CIPHER_SUITES
);
6292 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6293 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6296 wiphy
= &rdev
->wiphy
;
6298 connect
.bg_scan_period
= -1;
6299 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
6300 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
6301 connect
.bg_scan_period
=
6302 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
6305 if (info
->attrs
[NL80211_ATTR_MAC
])
6306 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6307 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
6308 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
6310 if (info
->attrs
[NL80211_ATTR_IE
]) {
6311 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
6312 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
6315 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
6316 connect
.mfp
= nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
6317 if (connect
.mfp
!= NL80211_MFP_REQUIRED
&&
6318 connect
.mfp
!= NL80211_MFP_NO
)
6321 connect
.mfp
= NL80211_MFP_NO
;
6324 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6326 ieee80211_get_channel(wiphy
,
6327 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
6328 if (!connect
.channel
||
6329 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
6333 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
6334 connkeys
= nl80211_parse_connkeys(rdev
,
6335 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
6336 if (IS_ERR(connkeys
))
6337 return PTR_ERR(connkeys
);
6340 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
6341 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
6343 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
6344 memcpy(&connect
.ht_capa_mask
,
6345 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
6346 sizeof(connect
.ht_capa_mask
));
6348 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
6349 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
6353 memcpy(&connect
.ht_capa
,
6354 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
6355 sizeof(connect
.ht_capa
));
6358 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
6364 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
6366 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6367 struct net_device
*dev
= info
->user_ptr
[1];
6370 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
6371 reason
= WLAN_REASON_DEAUTH_LEAVING
;
6373 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
6378 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6379 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6382 return cfg80211_disconnect(rdev
, dev
, reason
, true);
6385 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
6387 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6392 if (!info
->attrs
[NL80211_ATTR_PID
])
6395 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
6397 net
= get_net_ns_by_pid(pid
);
6399 return PTR_ERR(net
);
6403 /* check if anything to do */
6404 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
6405 err
= cfg80211_switch_netns(rdev
, net
);
6411 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6413 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6414 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
6415 struct cfg80211_pmksa
*pmksa
) = NULL
;
6416 struct net_device
*dev
= info
->user_ptr
[1];
6417 struct cfg80211_pmksa pmksa
;
6419 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
6421 if (!info
->attrs
[NL80211_ATTR_MAC
])
6424 if (!info
->attrs
[NL80211_ATTR_PMKID
])
6427 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
6428 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6430 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6431 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6434 switch (info
->genlhdr
->cmd
) {
6435 case NL80211_CMD_SET_PMKSA
:
6436 rdev_ops
= rdev
->ops
->set_pmksa
;
6438 case NL80211_CMD_DEL_PMKSA
:
6439 rdev_ops
= rdev
->ops
->del_pmksa
;
6449 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
6452 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
6454 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6455 struct net_device
*dev
= info
->user_ptr
[1];
6457 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
6458 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6461 if (!rdev
->ops
->flush_pmksa
)
6464 return rdev_flush_pmksa(rdev
, dev
);
6467 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6469 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6470 struct net_device
*dev
= info
->user_ptr
[1];
6471 u8 action_code
, dialog_token
;
6475 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6476 !rdev
->ops
->tdls_mgmt
)
6479 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
6480 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
6481 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
6482 !info
->attrs
[NL80211_ATTR_IE
] ||
6483 !info
->attrs
[NL80211_ATTR_MAC
])
6486 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6487 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
6488 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
6489 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
6491 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
6492 dialog_token
, status_code
,
6493 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
6494 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
6497 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
6499 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6500 struct net_device
*dev
= info
->user_ptr
[1];
6501 enum nl80211_tdls_operation operation
;
6504 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
6505 !rdev
->ops
->tdls_oper
)
6508 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
6509 !info
->attrs
[NL80211_ATTR_MAC
])
6512 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
6513 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6515 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
6518 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
6519 struct genl_info
*info
)
6521 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6522 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6523 struct cfg80211_chan_def chandef
;
6524 struct sk_buff
*msg
;
6530 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
6531 !info
->attrs
[NL80211_ATTR_DURATION
])
6534 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6536 if (!rdev
->ops
->remain_on_channel
||
6537 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
6541 * We should be on that channel for at least a minimum amount of
6542 * time (10ms) but no longer than the driver supports.
6544 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6545 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
6548 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6552 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6556 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6557 NL80211_CMD_REMAIN_ON_CHANNEL
);
6564 err
= rdev_remain_on_channel(rdev
, wdev
, chandef
.chan
,
6570 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6571 goto nla_put_failure
;
6573 genlmsg_end(msg
, hdr
);
6575 return genlmsg_reply(msg
, info
);
6584 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
6585 struct genl_info
*info
)
6587 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6588 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6591 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6594 if (!rdev
->ops
->cancel_remain_on_channel
)
6597 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6599 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
6602 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
6603 u8
*rates
, u8 rates_len
)
6608 for (i
= 0; i
< rates_len
; i
++) {
6609 int rate
= (rates
[i
] & 0x7f) * 5;
6611 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
6612 struct ieee80211_rate
*srate
=
6613 &sband
->bitrates
[ridx
];
6614 if (rate
== srate
->bitrate
) {
6619 if (ridx
== sband
->n_bitrates
)
6620 return 0; /* rate not found */
6626 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
6627 u8
*rates
, u8 rates_len
,
6628 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
6632 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
6634 for (i
= 0; i
< rates_len
; i
++) {
6637 ridx
= rates
[i
] / 8;
6638 rbit
= BIT(rates
[i
] % 8);
6640 /* check validity */
6641 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
6644 /* check availability */
6645 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
6654 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
6655 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
6656 .len
= NL80211_MAX_SUPP_RATES
},
6657 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
6658 .len
= NL80211_MAX_SUPP_HT_RATES
},
6661 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
6662 struct genl_info
*info
)
6664 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
6665 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6666 struct cfg80211_bitrate_mask mask
;
6668 struct net_device
*dev
= info
->user_ptr
[1];
6669 struct nlattr
*tx_rates
;
6670 struct ieee80211_supported_band
*sband
;
6672 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
6675 if (!rdev
->ops
->set_bitrate_mask
)
6678 memset(&mask
, 0, sizeof(mask
));
6679 /* Default to all rates enabled */
6680 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
6681 sband
= rdev
->wiphy
.bands
[i
];
6682 mask
.control
[i
].legacy
=
6683 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
6685 memcpy(mask
.control
[i
].mcs
,
6686 sband
->ht_cap
.mcs
.rx_mask
,
6687 sizeof(mask
.control
[i
].mcs
));
6689 memset(mask
.control
[i
].mcs
, 0,
6690 sizeof(mask
.control
[i
].mcs
));
6694 * The nested attribute uses enum nl80211_band as the index. This maps
6695 * directly to the enum ieee80211_band values used in cfg80211.
6697 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
6698 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
6700 enum ieee80211_band band
= nla_type(tx_rates
);
6701 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
6703 sband
= rdev
->wiphy
.bands
[band
];
6706 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
6707 nla_len(tx_rates
), nl80211_txattr_policy
);
6708 if (tb
[NL80211_TXRATE_LEGACY
]) {
6709 mask
.control
[band
].legacy
= rateset_to_mask(
6711 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
6712 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
6713 if ((mask
.control
[band
].legacy
== 0) &&
6714 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
6717 if (tb
[NL80211_TXRATE_MCS
]) {
6718 if (!ht_rateset_to_mask(
6720 nla_data(tb
[NL80211_TXRATE_MCS
]),
6721 nla_len(tb
[NL80211_TXRATE_MCS
]),
6722 mask
.control
[band
].mcs
))
6726 if (mask
.control
[band
].legacy
== 0) {
6727 /* don't allow empty legacy rates if HT
6728 * is not even supported. */
6729 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
6732 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
6733 if (mask
.control
[band
].mcs
[i
])
6736 /* legacy and mcs rates may not be both empty */
6737 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
6742 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
6745 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6747 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6748 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6749 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
6751 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
6754 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
6755 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
6757 switch (wdev
->iftype
) {
6758 case NL80211_IFTYPE_STATION
:
6759 case NL80211_IFTYPE_ADHOC
:
6760 case NL80211_IFTYPE_P2P_CLIENT
:
6761 case NL80211_IFTYPE_AP
:
6762 case NL80211_IFTYPE_AP_VLAN
:
6763 case NL80211_IFTYPE_MESH_POINT
:
6764 case NL80211_IFTYPE_P2P_GO
:
6765 case NL80211_IFTYPE_P2P_DEVICE
:
6771 /* not much point in registering if we can't reply */
6772 if (!rdev
->ops
->mgmt_tx
)
6775 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
6776 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
6777 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
6780 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6782 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6783 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6784 struct cfg80211_chan_def chandef
;
6788 struct sk_buff
*msg
= NULL
;
6789 unsigned int wait
= 0;
6790 bool offchan
, no_cck
, dont_wait_for_ack
;
6792 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
6794 if (!info
->attrs
[NL80211_ATTR_FRAME
])
6797 if (!rdev
->ops
->mgmt_tx
)
6800 switch (wdev
->iftype
) {
6801 case NL80211_IFTYPE_STATION
:
6802 case NL80211_IFTYPE_ADHOC
:
6803 case NL80211_IFTYPE_P2P_CLIENT
:
6804 case NL80211_IFTYPE_AP
:
6805 case NL80211_IFTYPE_AP_VLAN
:
6806 case NL80211_IFTYPE_MESH_POINT
:
6807 case NL80211_IFTYPE_P2P_GO
:
6808 case NL80211_IFTYPE_P2P_DEVICE
:
6814 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
6815 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6817 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6820 * We should wait on the channel for at least a minimum amount
6821 * of time (10ms) but no longer than the driver supports.
6823 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6824 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
6829 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
6831 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6834 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6836 err
= nl80211_parse_chandef(rdev
, info
, &chandef
);
6840 if (!dont_wait_for_ack
) {
6841 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6845 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6854 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chandef
.chan
, offchan
, wait
,
6855 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6856 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6857 no_cck
, dont_wait_for_ack
, &cookie
);
6862 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6863 goto nla_put_failure
;
6865 genlmsg_end(msg
, hdr
);
6866 return genlmsg_reply(msg
, info
);
6878 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6880 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6881 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6884 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6887 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6890 switch (wdev
->iftype
) {
6891 case NL80211_IFTYPE_STATION
:
6892 case NL80211_IFTYPE_ADHOC
:
6893 case NL80211_IFTYPE_P2P_CLIENT
:
6894 case NL80211_IFTYPE_AP
:
6895 case NL80211_IFTYPE_AP_VLAN
:
6896 case NL80211_IFTYPE_P2P_GO
:
6897 case NL80211_IFTYPE_P2P_DEVICE
:
6903 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6905 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
6908 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6910 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6911 struct wireless_dev
*wdev
;
6912 struct net_device
*dev
= info
->user_ptr
[1];
6917 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6920 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6922 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6925 wdev
= dev
->ieee80211_ptr
;
6927 if (!rdev
->ops
->set_power_mgmt
)
6930 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6932 if (state
== wdev
->ps
)
6935 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
6941 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6943 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6944 enum nl80211_ps_state ps_state
;
6945 struct wireless_dev
*wdev
;
6946 struct net_device
*dev
= info
->user_ptr
[1];
6947 struct sk_buff
*msg
;
6951 wdev
= dev
->ieee80211_ptr
;
6953 if (!rdev
->ops
->set_power_mgmt
)
6956 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6960 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6961 NL80211_CMD_GET_POWER_SAVE
);
6968 ps_state
= NL80211_PS_ENABLED
;
6970 ps_state
= NL80211_PS_DISABLED
;
6972 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6973 goto nla_put_failure
;
6975 genlmsg_end(msg
, hdr
);
6976 return genlmsg_reply(msg
, info
);
6985 static struct nla_policy
6986 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6987 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6988 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6989 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6990 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
6991 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
6992 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
6995 static int nl80211_set_cqm_txe(struct genl_info
*info
,
6996 u32 rate
, u32 pkts
, u32 intvl
)
6998 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6999 struct wireless_dev
*wdev
;
7000 struct net_device
*dev
= info
->user_ptr
[1];
7002 if (rate
> 100 || intvl
> NL80211_CQM_TXE_MAX_INTVL
)
7005 wdev
= dev
->ieee80211_ptr
;
7007 if (!rdev
->ops
->set_cqm_txe_config
)
7010 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7011 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7014 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
7017 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
7018 s32 threshold
, u32 hysteresis
)
7020 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7021 struct wireless_dev
*wdev
;
7022 struct net_device
*dev
= info
->user_ptr
[1];
7027 wdev
= dev
->ieee80211_ptr
;
7029 if (!rdev
->ops
->set_cqm_rssi_config
)
7032 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
7033 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
7036 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
7039 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
7041 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
7045 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
7051 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
7052 nl80211_attr_cqm_policy
);
7056 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
7057 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
7060 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
7061 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
7062 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
7063 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
7064 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
7065 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
7066 u32 rate
, pkts
, intvl
;
7067 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
7068 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
7069 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
7070 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
7078 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7080 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7081 struct net_device
*dev
= info
->user_ptr
[1];
7082 struct mesh_config cfg
;
7083 struct mesh_setup setup
;
7086 /* start with default */
7087 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
7088 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
7090 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
7091 /* and parse parameters if given */
7092 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
7097 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
7098 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
7101 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7102 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
7104 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
7105 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
7106 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
7109 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
7110 setup
.beacon_interval
=
7111 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
7112 if (setup
.beacon_interval
< 10 ||
7113 setup
.beacon_interval
> 10000)
7117 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
7119 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
7120 if (setup
.dtim_period
< 1 || setup
.dtim_period
> 100)
7124 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
7125 /* parse additional setup parameters if given */
7126 err
= nl80211_parse_mesh_setup(info
, &setup
);
7131 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
7132 err
= nl80211_parse_chandef(rdev
, info
, &setup
.chandef
);
7136 /* cfg80211_join_mesh() will sort it out */
7137 setup
.chandef
.chan
= NULL
;
7140 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
7143 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
7145 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7146 struct net_device
*dev
= info
->user_ptr
[1];
7148 return cfg80211_leave_mesh(rdev
, dev
);
7152 static int nl80211_send_wowlan_patterns(struct sk_buff
*msg
,
7153 struct cfg80211_registered_device
*rdev
)
7155 struct nlattr
*nl_pats
, *nl_pat
;
7158 if (!rdev
->wowlan
->n_patterns
)
7161 nl_pats
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
);
7165 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
7166 nl_pat
= nla_nest_start(msg
, i
+ 1);
7169 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
7170 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
7171 DIV_ROUND_UP(pat_len
, 8),
7172 rdev
->wowlan
->patterns
[i
].mask
) ||
7173 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
7174 pat_len
, rdev
->wowlan
->patterns
[i
].pattern
) ||
7175 nla_put_u32(msg
, NL80211_WOWLAN_PKTPAT_OFFSET
,
7176 rdev
->wowlan
->patterns
[i
].pkt_offset
))
7178 nla_nest_end(msg
, nl_pat
);
7180 nla_nest_end(msg
, nl_pats
);
7185 static int nl80211_send_wowlan_tcp(struct sk_buff
*msg
,
7186 struct cfg80211_wowlan_tcp
*tcp
)
7188 struct nlattr
*nl_tcp
;
7193 nl_tcp
= nla_nest_start(msg
, NL80211_WOWLAN_TRIG_TCP_CONNECTION
);
7197 if (nla_put_be32(msg
, NL80211_WOWLAN_TCP_SRC_IPV4
, tcp
->src
) ||
7198 nla_put_be32(msg
, NL80211_WOWLAN_TCP_DST_IPV4
, tcp
->dst
) ||
7199 nla_put(msg
, NL80211_WOWLAN_TCP_DST_MAC
, ETH_ALEN
, tcp
->dst_mac
) ||
7200 nla_put_u16(msg
, NL80211_WOWLAN_TCP_SRC_PORT
, tcp
->src_port
) ||
7201 nla_put_u16(msg
, NL80211_WOWLAN_TCP_DST_PORT
, tcp
->dst_port
) ||
7202 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD
,
7203 tcp
->payload_len
, tcp
->payload
) ||
7204 nla_put_u32(msg
, NL80211_WOWLAN_TCP_DATA_INTERVAL
,
7205 tcp
->data_interval
) ||
7206 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_PAYLOAD
,
7207 tcp
->wake_len
, tcp
->wake_data
) ||
7208 nla_put(msg
, NL80211_WOWLAN_TCP_WAKE_MASK
,
7209 DIV_ROUND_UP(tcp
->wake_len
, 8), tcp
->wake_mask
))
7212 if (tcp
->payload_seq
.len
&&
7213 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
,
7214 sizeof(tcp
->payload_seq
), &tcp
->payload_seq
))
7217 if (tcp
->payload_tok
.len
&&
7218 nla_put(msg
, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
,
7219 sizeof(tcp
->payload_tok
) + tcp
->tokens_size
,
7226 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7228 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7229 struct sk_buff
*msg
;
7231 u32 size
= NLMSG_DEFAULT_SIZE
;
7233 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7234 !rdev
->wiphy
.wowlan
.tcp
)
7237 if (rdev
->wowlan
&& rdev
->wowlan
->tcp
) {
7238 /* adjust size to have room for all the data */
7239 size
+= rdev
->wowlan
->tcp
->tokens_size
+
7240 rdev
->wowlan
->tcp
->payload_len
+
7241 rdev
->wowlan
->tcp
->wake_len
+
7242 rdev
->wowlan
->tcp
->wake_len
/ 8;
7245 msg
= nlmsg_new(size
, GFP_KERNEL
);
7249 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7250 NL80211_CMD_GET_WOWLAN
);
7252 goto nla_put_failure
;
7255 struct nlattr
*nl_wowlan
;
7257 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
7259 goto nla_put_failure
;
7261 if ((rdev
->wowlan
->any
&&
7262 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
7263 (rdev
->wowlan
->disconnect
&&
7264 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
7265 (rdev
->wowlan
->magic_pkt
&&
7266 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
7267 (rdev
->wowlan
->gtk_rekey_failure
&&
7268 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
7269 (rdev
->wowlan
->eap_identity_req
&&
7270 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
7271 (rdev
->wowlan
->four_way_handshake
&&
7272 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
7273 (rdev
->wowlan
->rfkill_release
&&
7274 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
7275 goto nla_put_failure
;
7277 if (nl80211_send_wowlan_patterns(msg
, rdev
))
7278 goto nla_put_failure
;
7280 if (nl80211_send_wowlan_tcp(msg
, rdev
->wowlan
->tcp
))
7281 goto nla_put_failure
;
7283 nla_nest_end(msg
, nl_wowlan
);
7286 genlmsg_end(msg
, hdr
);
7287 return genlmsg_reply(msg
, info
);
7294 static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device
*rdev
,
7295 struct nlattr
*attr
,
7296 struct cfg80211_wowlan
*trig
)
7298 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TCP
];
7299 struct cfg80211_wowlan_tcp
*cfg
;
7300 struct nl80211_wowlan_tcp_data_token
*tok
= NULL
;
7301 struct nl80211_wowlan_tcp_data_seq
*seq
= NULL
;
7303 u32 data_size
, wake_size
, tokens_size
= 0, wake_mask_size
;
7306 if (!rdev
->wiphy
.wowlan
.tcp
)
7309 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TCP
,
7310 nla_data(attr
), nla_len(attr
),
7311 nl80211_wowlan_tcp_policy
);
7315 if (!tb
[NL80211_WOWLAN_TCP_SRC_IPV4
] ||
7316 !tb
[NL80211_WOWLAN_TCP_DST_IPV4
] ||
7317 !tb
[NL80211_WOWLAN_TCP_DST_MAC
] ||
7318 !tb
[NL80211_WOWLAN_TCP_DST_PORT
] ||
7319 !tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
] ||
7320 !tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
] ||
7321 !tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
] ||
7322 !tb
[NL80211_WOWLAN_TCP_WAKE_MASK
])
7325 data_size
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]);
7326 if (data_size
> rdev
->wiphy
.wowlan
.tcp
->data_payload_max
)
7329 if (nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]) >
7330 rdev
->wiphy
.wowlan
.tcp
->data_interval_max
)
7333 wake_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]);
7334 if (wake_size
> rdev
->wiphy
.wowlan
.tcp
->wake_payload_max
)
7337 wake_mask_size
= nla_len(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]);
7338 if (wake_mask_size
!= DIV_ROUND_UP(wake_size
, 8))
7341 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]) {
7342 u32 tokln
= nla_len(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7344 tok
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN
]);
7345 tokens_size
= tokln
- sizeof(*tok
);
7347 if (!tok
->len
|| tokens_size
% tok
->len
)
7349 if (!rdev
->wiphy
.wowlan
.tcp
->tok
)
7351 if (tok
->len
> rdev
->wiphy
.wowlan
.tcp
->tok
->max_len
)
7353 if (tok
->len
< rdev
->wiphy
.wowlan
.tcp
->tok
->min_len
)
7355 if (tokens_size
> rdev
->wiphy
.wowlan
.tcp
->tok
->bufsize
)
7357 if (tok
->offset
+ tok
->len
> data_size
)
7361 if (tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]) {
7362 seq
= nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ
]);
7363 if (!rdev
->wiphy
.wowlan
.tcp
->seq
)
7365 if (seq
->len
== 0 || seq
->len
> 4)
7367 if (seq
->len
+ seq
->offset
> data_size
)
7371 size
= sizeof(*cfg
);
7373 size
+= wake_size
+ wake_mask_size
;
7374 size
+= tokens_size
;
7376 cfg
= kzalloc(size
, GFP_KERNEL
);
7379 cfg
->src
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_SRC_IPV4
]);
7380 cfg
->dst
= nla_get_be32(tb
[NL80211_WOWLAN_TCP_DST_IPV4
]);
7381 memcpy(cfg
->dst_mac
, nla_data(tb
[NL80211_WOWLAN_TCP_DST_MAC
]),
7383 if (tb
[NL80211_WOWLAN_TCP_SRC_PORT
])
7384 port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_SRC_PORT
]);
7388 /* allocate a socket and port for it and use it */
7389 err
= __sock_create(wiphy_net(&rdev
->wiphy
), PF_INET
, SOCK_STREAM
,
7390 IPPROTO_TCP
, &cfg
->sock
, 1);
7395 if (inet_csk_get_port(cfg
->sock
->sk
, port
)) {
7396 sock_release(cfg
->sock
);
7400 cfg
->src_port
= inet_sk(cfg
->sock
->sk
)->inet_num
;
7406 cfg
->src_port
= port
;
7409 cfg
->dst_port
= nla_get_u16(tb
[NL80211_WOWLAN_TCP_DST_PORT
]);
7410 cfg
->payload_len
= data_size
;
7411 cfg
->payload
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
;
7412 memcpy((void *)cfg
->payload
,
7413 nla_data(tb
[NL80211_WOWLAN_TCP_DATA_PAYLOAD
]),
7416 cfg
->payload_seq
= *seq
;
7417 cfg
->data_interval
= nla_get_u32(tb
[NL80211_WOWLAN_TCP_DATA_INTERVAL
]);
7418 cfg
->wake_len
= wake_size
;
7419 cfg
->wake_data
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+ data_size
;
7420 memcpy((void *)cfg
->wake_data
,
7421 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_PAYLOAD
]),
7423 cfg
->wake_mask
= (u8
*)cfg
+ sizeof(*cfg
) + tokens_size
+
7424 data_size
+ wake_size
;
7425 memcpy((void *)cfg
->wake_mask
,
7426 nla_data(tb
[NL80211_WOWLAN_TCP_WAKE_MASK
]),
7429 cfg
->tokens_size
= tokens_size
;
7430 memcpy(&cfg
->payload_tok
, tok
, sizeof(*tok
) + tokens_size
);
7438 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
7440 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7441 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
7442 struct cfg80211_wowlan new_triggers
= {};
7443 struct cfg80211_wowlan
*ntrig
;
7444 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
7446 bool prev_enabled
= rdev
->wowlan
;
7448 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
&&
7449 !rdev
->wiphy
.wowlan
.tcp
)
7452 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
7453 cfg80211_rdev_free_wowlan(rdev
);
7454 rdev
->wowlan
= NULL
;
7458 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
7459 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7460 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
7461 nl80211_wowlan_policy
);
7465 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
7466 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
7468 new_triggers
.any
= true;
7471 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
7472 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
7474 new_triggers
.disconnect
= true;
7477 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
7478 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
7480 new_triggers
.magic_pkt
= true;
7483 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
7486 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
7487 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
7489 new_triggers
.gtk_rekey_failure
= true;
7492 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
7493 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
7495 new_triggers
.eap_identity_req
= true;
7498 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
7499 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
7501 new_triggers
.four_way_handshake
= true;
7504 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
7505 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
7507 new_triggers
.rfkill_release
= true;
7510 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
7513 int rem
, pat_len
, mask_len
, pkt_offset
;
7514 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
7516 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7519 if (n_patterns
> wowlan
->n_patterns
)
7522 new_triggers
.patterns
= kcalloc(n_patterns
,
7523 sizeof(new_triggers
.patterns
[0]),
7525 if (!new_triggers
.patterns
)
7528 new_triggers
.n_patterns
= n_patterns
;
7531 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
7533 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
7534 nla_data(pat
), nla_len(pat
), NULL
);
7536 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
7537 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
7539 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
7540 mask_len
= DIV_ROUND_UP(pat_len
, 8);
7541 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
7544 if (pat_len
> wowlan
->pattern_max_len
||
7545 pat_len
< wowlan
->pattern_min_len
)
7548 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
])
7551 pkt_offset
= nla_get_u32(
7552 pat_tb
[NL80211_WOWLAN_PKTPAT_OFFSET
]);
7553 if (pkt_offset
> wowlan
->max_pkt_offset
)
7555 new_triggers
.patterns
[i
].pkt_offset
= pkt_offset
;
7557 new_triggers
.patterns
[i
].mask
=
7558 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
7559 if (!new_triggers
.patterns
[i
].mask
) {
7563 new_triggers
.patterns
[i
].pattern
=
7564 new_triggers
.patterns
[i
].mask
+ mask_len
;
7565 memcpy(new_triggers
.patterns
[i
].mask
,
7566 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
7568 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
7569 memcpy(new_triggers
.patterns
[i
].pattern
,
7570 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
7576 if (tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
]) {
7577 err
= nl80211_parse_wowlan_tcp(
7578 rdev
, tb
[NL80211_WOWLAN_TRIG_TCP_CONNECTION
],
7584 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
7589 cfg80211_rdev_free_wowlan(rdev
);
7590 rdev
->wowlan
= ntrig
;
7593 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
7594 rdev_set_wakeup(rdev
, rdev
->wowlan
);
7598 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
7599 kfree(new_triggers
.patterns
[i
].mask
);
7600 kfree(new_triggers
.patterns
);
7601 if (new_triggers
.tcp
&& new_triggers
.tcp
->sock
)
7602 sock_release(new_triggers
.tcp
->sock
);
7603 kfree(new_triggers
.tcp
);
7608 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
7610 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7611 struct net_device
*dev
= info
->user_ptr
[1];
7612 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7613 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
7614 struct cfg80211_gtk_rekey_data rekey_data
;
7617 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
7620 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
7621 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
7622 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
7623 nl80211_rekey_policy
);
7627 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
7629 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
7631 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
7634 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
7636 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
7638 memcpy(rekey_data
.replay_ctr
,
7639 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
7640 NL80211_REPLAY_CTR_LEN
);
7643 if (!wdev
->current_bss
) {
7648 if (!rdev
->ops
->set_rekey_data
) {
7653 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
7659 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
7660 struct genl_info
*info
)
7662 struct net_device
*dev
= info
->user_ptr
[1];
7663 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7665 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
7666 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
7669 if (wdev
->ap_unexpected_nlportid
)
7672 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
7676 static int nl80211_probe_client(struct sk_buff
*skb
,
7677 struct genl_info
*info
)
7679 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7680 struct net_device
*dev
= info
->user_ptr
[1];
7681 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7682 struct sk_buff
*msg
;
7688 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
7689 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
7692 if (!info
->attrs
[NL80211_ATTR_MAC
])
7695 if (!rdev
->ops
->probe_client
)
7698 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7702 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
7703 NL80211_CMD_PROBE_CLIENT
);
7710 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
7712 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
7716 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
7717 goto nla_put_failure
;
7719 genlmsg_end(msg
, hdr
);
7721 return genlmsg_reply(msg
, info
);
7730 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
7732 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7733 struct cfg80211_beacon_registration
*reg
, *nreg
;
7736 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
7739 nreg
= kzalloc(sizeof(*nreg
), GFP_KERNEL
);
7743 /* First, check if already registered. */
7744 spin_lock_bh(&rdev
->beacon_registrations_lock
);
7745 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
7746 if (reg
->nlportid
== info
->snd_portid
) {
7751 /* Add it to the list */
7752 nreg
->nlportid
= info
->snd_portid
;
7753 list_add(&nreg
->list
, &rdev
->beacon_registrations
);
7755 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
7759 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
7764 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
7766 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7767 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7770 if (!rdev
->ops
->start_p2p_device
)
7773 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
7776 if (wdev
->p2p_started
)
7779 mutex_lock(&rdev
->devlist_mtx
);
7780 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
7781 mutex_unlock(&rdev
->devlist_mtx
);
7785 err
= rdev_start_p2p_device(rdev
, wdev
);
7789 wdev
->p2p_started
= true;
7790 mutex_lock(&rdev
->devlist_mtx
);
7792 mutex_unlock(&rdev
->devlist_mtx
);
7797 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
7799 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
7800 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7802 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
7805 if (!rdev
->ops
->stop_p2p_device
)
7808 if (!wdev
->p2p_started
)
7811 rdev_stop_p2p_device(rdev
, wdev
);
7812 wdev
->p2p_started
= false;
7814 mutex_lock(&rdev
->devlist_mtx
);
7816 mutex_unlock(&rdev
->devlist_mtx
);
7818 if (WARN_ON(rdev
->scan_req
&& rdev
->scan_req
->wdev
== wdev
)) {
7819 rdev
->scan_req
->aborted
= true;
7820 ___cfg80211_scan_done(rdev
, true);
7826 #define NL80211_FLAG_NEED_WIPHY 0x01
7827 #define NL80211_FLAG_NEED_NETDEV 0x02
7828 #define NL80211_FLAG_NEED_RTNL 0x04
7829 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
7830 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
7831 NL80211_FLAG_CHECK_NETDEV_UP)
7832 #define NL80211_FLAG_NEED_WDEV 0x10
7833 /* If a netdev is associated, it must be UP, P2P must be started */
7834 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
7835 NL80211_FLAG_CHECK_NETDEV_UP)
7837 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
7838 struct genl_info
*info
)
7840 struct cfg80211_registered_device
*rdev
;
7841 struct wireless_dev
*wdev
;
7842 struct net_device
*dev
;
7843 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
7848 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
7849 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
7853 return PTR_ERR(rdev
);
7855 info
->user_ptr
[0] = rdev
;
7856 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
7857 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7858 mutex_lock(&cfg80211_mutex
);
7859 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
7862 mutex_unlock(&cfg80211_mutex
);
7865 return PTR_ERR(wdev
);
7869 rdev
= wiphy_to_dev(wdev
->wiphy
);
7871 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
7873 mutex_unlock(&cfg80211_mutex
);
7879 info
->user_ptr
[1] = dev
;
7881 info
->user_ptr
[1] = wdev
;
7885 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
7886 !netif_running(dev
)) {
7887 mutex_unlock(&cfg80211_mutex
);
7894 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
7895 if (!wdev
->p2p_started
) {
7896 mutex_unlock(&cfg80211_mutex
);
7903 cfg80211_lock_rdev(rdev
);
7905 mutex_unlock(&cfg80211_mutex
);
7907 info
->user_ptr
[0] = rdev
;
7913 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
7914 struct genl_info
*info
)
7916 if (info
->user_ptr
[0])
7917 cfg80211_unlock_rdev(info
->user_ptr
[0]);
7918 if (info
->user_ptr
[1]) {
7919 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7920 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7923 dev_put(wdev
->netdev
);
7925 dev_put(info
->user_ptr
[1]);
7928 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
7932 static struct genl_ops nl80211_ops
[] = {
7934 .cmd
= NL80211_CMD_GET_WIPHY
,
7935 .doit
= nl80211_get_wiphy
,
7936 .dumpit
= nl80211_dump_wiphy
,
7937 .policy
= nl80211_policy
,
7938 /* can be retrieved by unprivileged users */
7939 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
7942 .cmd
= NL80211_CMD_SET_WIPHY
,
7943 .doit
= nl80211_set_wiphy
,
7944 .policy
= nl80211_policy
,
7945 .flags
= GENL_ADMIN_PERM
,
7946 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
7949 .cmd
= NL80211_CMD_GET_INTERFACE
,
7950 .doit
= nl80211_get_interface
,
7951 .dumpit
= nl80211_dump_interface
,
7952 .policy
= nl80211_policy
,
7953 /* can be retrieved by unprivileged users */
7954 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
7957 .cmd
= NL80211_CMD_SET_INTERFACE
,
7958 .doit
= nl80211_set_interface
,
7959 .policy
= nl80211_policy
,
7960 .flags
= GENL_ADMIN_PERM
,
7961 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7962 NL80211_FLAG_NEED_RTNL
,
7965 .cmd
= NL80211_CMD_NEW_INTERFACE
,
7966 .doit
= nl80211_new_interface
,
7967 .policy
= nl80211_policy
,
7968 .flags
= GENL_ADMIN_PERM
,
7969 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7970 NL80211_FLAG_NEED_RTNL
,
7973 .cmd
= NL80211_CMD_DEL_INTERFACE
,
7974 .doit
= nl80211_del_interface
,
7975 .policy
= nl80211_policy
,
7976 .flags
= GENL_ADMIN_PERM
,
7977 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7978 NL80211_FLAG_NEED_RTNL
,
7981 .cmd
= NL80211_CMD_GET_KEY
,
7982 .doit
= nl80211_get_key
,
7983 .policy
= nl80211_policy
,
7984 .flags
= GENL_ADMIN_PERM
,
7985 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7986 NL80211_FLAG_NEED_RTNL
,
7989 .cmd
= NL80211_CMD_SET_KEY
,
7990 .doit
= nl80211_set_key
,
7991 .policy
= nl80211_policy
,
7992 .flags
= GENL_ADMIN_PERM
,
7993 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7994 NL80211_FLAG_NEED_RTNL
,
7997 .cmd
= NL80211_CMD_NEW_KEY
,
7998 .doit
= nl80211_new_key
,
7999 .policy
= nl80211_policy
,
8000 .flags
= GENL_ADMIN_PERM
,
8001 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8002 NL80211_FLAG_NEED_RTNL
,
8005 .cmd
= NL80211_CMD_DEL_KEY
,
8006 .doit
= nl80211_del_key
,
8007 .policy
= nl80211_policy
,
8008 .flags
= GENL_ADMIN_PERM
,
8009 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8010 NL80211_FLAG_NEED_RTNL
,
8013 .cmd
= NL80211_CMD_SET_BEACON
,
8014 .policy
= nl80211_policy
,
8015 .flags
= GENL_ADMIN_PERM
,
8016 .doit
= nl80211_set_beacon
,
8017 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8018 NL80211_FLAG_NEED_RTNL
,
8021 .cmd
= NL80211_CMD_START_AP
,
8022 .policy
= nl80211_policy
,
8023 .flags
= GENL_ADMIN_PERM
,
8024 .doit
= nl80211_start_ap
,
8025 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8026 NL80211_FLAG_NEED_RTNL
,
8029 .cmd
= NL80211_CMD_STOP_AP
,
8030 .policy
= nl80211_policy
,
8031 .flags
= GENL_ADMIN_PERM
,
8032 .doit
= nl80211_stop_ap
,
8033 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8034 NL80211_FLAG_NEED_RTNL
,
8037 .cmd
= NL80211_CMD_GET_STATION
,
8038 .doit
= nl80211_get_station
,
8039 .dumpit
= nl80211_dump_station
,
8040 .policy
= nl80211_policy
,
8041 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8042 NL80211_FLAG_NEED_RTNL
,
8045 .cmd
= NL80211_CMD_SET_STATION
,
8046 .doit
= nl80211_set_station
,
8047 .policy
= nl80211_policy
,
8048 .flags
= GENL_ADMIN_PERM
,
8049 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8050 NL80211_FLAG_NEED_RTNL
,
8053 .cmd
= NL80211_CMD_NEW_STATION
,
8054 .doit
= nl80211_new_station
,
8055 .policy
= nl80211_policy
,
8056 .flags
= GENL_ADMIN_PERM
,
8057 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8058 NL80211_FLAG_NEED_RTNL
,
8061 .cmd
= NL80211_CMD_DEL_STATION
,
8062 .doit
= nl80211_del_station
,
8063 .policy
= nl80211_policy
,
8064 .flags
= GENL_ADMIN_PERM
,
8065 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8066 NL80211_FLAG_NEED_RTNL
,
8069 .cmd
= NL80211_CMD_GET_MPATH
,
8070 .doit
= nl80211_get_mpath
,
8071 .dumpit
= nl80211_dump_mpath
,
8072 .policy
= nl80211_policy
,
8073 .flags
= GENL_ADMIN_PERM
,
8074 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8075 NL80211_FLAG_NEED_RTNL
,
8078 .cmd
= NL80211_CMD_SET_MPATH
,
8079 .doit
= nl80211_set_mpath
,
8080 .policy
= nl80211_policy
,
8081 .flags
= GENL_ADMIN_PERM
,
8082 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8083 NL80211_FLAG_NEED_RTNL
,
8086 .cmd
= NL80211_CMD_NEW_MPATH
,
8087 .doit
= nl80211_new_mpath
,
8088 .policy
= nl80211_policy
,
8089 .flags
= GENL_ADMIN_PERM
,
8090 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8091 NL80211_FLAG_NEED_RTNL
,
8094 .cmd
= NL80211_CMD_DEL_MPATH
,
8095 .doit
= nl80211_del_mpath
,
8096 .policy
= nl80211_policy
,
8097 .flags
= GENL_ADMIN_PERM
,
8098 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8099 NL80211_FLAG_NEED_RTNL
,
8102 .cmd
= NL80211_CMD_SET_BSS
,
8103 .doit
= nl80211_set_bss
,
8104 .policy
= nl80211_policy
,
8105 .flags
= GENL_ADMIN_PERM
,
8106 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8107 NL80211_FLAG_NEED_RTNL
,
8110 .cmd
= NL80211_CMD_GET_REG
,
8111 .doit
= nl80211_get_reg
,
8112 .policy
= nl80211_policy
,
8113 /* can be retrieved by unprivileged users */
8116 .cmd
= NL80211_CMD_SET_REG
,
8117 .doit
= nl80211_set_reg
,
8118 .policy
= nl80211_policy
,
8119 .flags
= GENL_ADMIN_PERM
,
8122 .cmd
= NL80211_CMD_REQ_SET_REG
,
8123 .doit
= nl80211_req_set_reg
,
8124 .policy
= nl80211_policy
,
8125 .flags
= GENL_ADMIN_PERM
,
8128 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
8129 .doit
= nl80211_get_mesh_config
,
8130 .policy
= nl80211_policy
,
8131 /* can be retrieved by unprivileged users */
8132 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8133 NL80211_FLAG_NEED_RTNL
,
8136 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
8137 .doit
= nl80211_update_mesh_config
,
8138 .policy
= nl80211_policy
,
8139 .flags
= GENL_ADMIN_PERM
,
8140 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8141 NL80211_FLAG_NEED_RTNL
,
8144 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
8145 .doit
= nl80211_trigger_scan
,
8146 .policy
= nl80211_policy
,
8147 .flags
= GENL_ADMIN_PERM
,
8148 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8149 NL80211_FLAG_NEED_RTNL
,
8152 .cmd
= NL80211_CMD_GET_SCAN
,
8153 .policy
= nl80211_policy
,
8154 .dumpit
= nl80211_dump_scan
,
8157 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
8158 .doit
= nl80211_start_sched_scan
,
8159 .policy
= nl80211_policy
,
8160 .flags
= GENL_ADMIN_PERM
,
8161 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8162 NL80211_FLAG_NEED_RTNL
,
8165 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
8166 .doit
= nl80211_stop_sched_scan
,
8167 .policy
= nl80211_policy
,
8168 .flags
= GENL_ADMIN_PERM
,
8169 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8170 NL80211_FLAG_NEED_RTNL
,
8173 .cmd
= NL80211_CMD_AUTHENTICATE
,
8174 .doit
= nl80211_authenticate
,
8175 .policy
= nl80211_policy
,
8176 .flags
= GENL_ADMIN_PERM
,
8177 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8178 NL80211_FLAG_NEED_RTNL
,
8181 .cmd
= NL80211_CMD_ASSOCIATE
,
8182 .doit
= nl80211_associate
,
8183 .policy
= nl80211_policy
,
8184 .flags
= GENL_ADMIN_PERM
,
8185 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8186 NL80211_FLAG_NEED_RTNL
,
8189 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
8190 .doit
= nl80211_deauthenticate
,
8191 .policy
= nl80211_policy
,
8192 .flags
= GENL_ADMIN_PERM
,
8193 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8194 NL80211_FLAG_NEED_RTNL
,
8197 .cmd
= NL80211_CMD_DISASSOCIATE
,
8198 .doit
= nl80211_disassociate
,
8199 .policy
= nl80211_policy
,
8200 .flags
= GENL_ADMIN_PERM
,
8201 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8202 NL80211_FLAG_NEED_RTNL
,
8205 .cmd
= NL80211_CMD_JOIN_IBSS
,
8206 .doit
= nl80211_join_ibss
,
8207 .policy
= nl80211_policy
,
8208 .flags
= GENL_ADMIN_PERM
,
8209 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8210 NL80211_FLAG_NEED_RTNL
,
8213 .cmd
= NL80211_CMD_LEAVE_IBSS
,
8214 .doit
= nl80211_leave_ibss
,
8215 .policy
= nl80211_policy
,
8216 .flags
= GENL_ADMIN_PERM
,
8217 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8218 NL80211_FLAG_NEED_RTNL
,
8220 #ifdef CONFIG_NL80211_TESTMODE
8222 .cmd
= NL80211_CMD_TESTMODE
,
8223 .doit
= nl80211_testmode_do
,
8224 .dumpit
= nl80211_testmode_dump
,
8225 .policy
= nl80211_policy
,
8226 .flags
= GENL_ADMIN_PERM
,
8227 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8228 NL80211_FLAG_NEED_RTNL
,
8232 .cmd
= NL80211_CMD_CONNECT
,
8233 .doit
= nl80211_connect
,
8234 .policy
= nl80211_policy
,
8235 .flags
= GENL_ADMIN_PERM
,
8236 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8237 NL80211_FLAG_NEED_RTNL
,
8240 .cmd
= NL80211_CMD_DISCONNECT
,
8241 .doit
= nl80211_disconnect
,
8242 .policy
= nl80211_policy
,
8243 .flags
= GENL_ADMIN_PERM
,
8244 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8245 NL80211_FLAG_NEED_RTNL
,
8248 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
8249 .doit
= nl80211_wiphy_netns
,
8250 .policy
= nl80211_policy
,
8251 .flags
= GENL_ADMIN_PERM
,
8252 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8253 NL80211_FLAG_NEED_RTNL
,
8256 .cmd
= NL80211_CMD_GET_SURVEY
,
8257 .policy
= nl80211_policy
,
8258 .dumpit
= nl80211_dump_survey
,
8261 .cmd
= NL80211_CMD_SET_PMKSA
,
8262 .doit
= nl80211_setdel_pmksa
,
8263 .policy
= nl80211_policy
,
8264 .flags
= GENL_ADMIN_PERM
,
8265 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8266 NL80211_FLAG_NEED_RTNL
,
8269 .cmd
= NL80211_CMD_DEL_PMKSA
,
8270 .doit
= nl80211_setdel_pmksa
,
8271 .policy
= nl80211_policy
,
8272 .flags
= GENL_ADMIN_PERM
,
8273 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8274 NL80211_FLAG_NEED_RTNL
,
8277 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
8278 .doit
= nl80211_flush_pmksa
,
8279 .policy
= nl80211_policy
,
8280 .flags
= GENL_ADMIN_PERM
,
8281 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8282 NL80211_FLAG_NEED_RTNL
,
8285 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
8286 .doit
= nl80211_remain_on_channel
,
8287 .policy
= nl80211_policy
,
8288 .flags
= GENL_ADMIN_PERM
,
8289 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8290 NL80211_FLAG_NEED_RTNL
,
8293 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8294 .doit
= nl80211_cancel_remain_on_channel
,
8295 .policy
= nl80211_policy
,
8296 .flags
= GENL_ADMIN_PERM
,
8297 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8298 NL80211_FLAG_NEED_RTNL
,
8301 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
8302 .doit
= nl80211_set_tx_bitrate_mask
,
8303 .policy
= nl80211_policy
,
8304 .flags
= GENL_ADMIN_PERM
,
8305 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8306 NL80211_FLAG_NEED_RTNL
,
8309 .cmd
= NL80211_CMD_REGISTER_FRAME
,
8310 .doit
= nl80211_register_mgmt
,
8311 .policy
= nl80211_policy
,
8312 .flags
= GENL_ADMIN_PERM
,
8313 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8314 NL80211_FLAG_NEED_RTNL
,
8317 .cmd
= NL80211_CMD_FRAME
,
8318 .doit
= nl80211_tx_mgmt
,
8319 .policy
= nl80211_policy
,
8320 .flags
= GENL_ADMIN_PERM
,
8321 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8322 NL80211_FLAG_NEED_RTNL
,
8325 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
8326 .doit
= nl80211_tx_mgmt_cancel_wait
,
8327 .policy
= nl80211_policy
,
8328 .flags
= GENL_ADMIN_PERM
,
8329 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8330 NL80211_FLAG_NEED_RTNL
,
8333 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
8334 .doit
= nl80211_set_power_save
,
8335 .policy
= nl80211_policy
,
8336 .flags
= GENL_ADMIN_PERM
,
8337 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8338 NL80211_FLAG_NEED_RTNL
,
8341 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
8342 .doit
= nl80211_get_power_save
,
8343 .policy
= nl80211_policy
,
8344 /* can be retrieved by unprivileged users */
8345 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8346 NL80211_FLAG_NEED_RTNL
,
8349 .cmd
= NL80211_CMD_SET_CQM
,
8350 .doit
= nl80211_set_cqm
,
8351 .policy
= nl80211_policy
,
8352 .flags
= GENL_ADMIN_PERM
,
8353 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8354 NL80211_FLAG_NEED_RTNL
,
8357 .cmd
= NL80211_CMD_SET_CHANNEL
,
8358 .doit
= nl80211_set_channel
,
8359 .policy
= nl80211_policy
,
8360 .flags
= GENL_ADMIN_PERM
,
8361 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8362 NL80211_FLAG_NEED_RTNL
,
8365 .cmd
= NL80211_CMD_SET_WDS_PEER
,
8366 .doit
= nl80211_set_wds_peer
,
8367 .policy
= nl80211_policy
,
8368 .flags
= GENL_ADMIN_PERM
,
8369 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8370 NL80211_FLAG_NEED_RTNL
,
8373 .cmd
= NL80211_CMD_JOIN_MESH
,
8374 .doit
= nl80211_join_mesh
,
8375 .policy
= nl80211_policy
,
8376 .flags
= GENL_ADMIN_PERM
,
8377 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8378 NL80211_FLAG_NEED_RTNL
,
8381 .cmd
= NL80211_CMD_LEAVE_MESH
,
8382 .doit
= nl80211_leave_mesh
,
8383 .policy
= nl80211_policy
,
8384 .flags
= GENL_ADMIN_PERM
,
8385 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8386 NL80211_FLAG_NEED_RTNL
,
8390 .cmd
= NL80211_CMD_GET_WOWLAN
,
8391 .doit
= nl80211_get_wowlan
,
8392 .policy
= nl80211_policy
,
8393 /* can be retrieved by unprivileged users */
8394 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8395 NL80211_FLAG_NEED_RTNL
,
8398 .cmd
= NL80211_CMD_SET_WOWLAN
,
8399 .doit
= nl80211_set_wowlan
,
8400 .policy
= nl80211_policy
,
8401 .flags
= GENL_ADMIN_PERM
,
8402 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8403 NL80211_FLAG_NEED_RTNL
,
8407 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
8408 .doit
= nl80211_set_rekey_data
,
8409 .policy
= nl80211_policy
,
8410 .flags
= GENL_ADMIN_PERM
,
8411 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8412 NL80211_FLAG_NEED_RTNL
,
8415 .cmd
= NL80211_CMD_TDLS_MGMT
,
8416 .doit
= nl80211_tdls_mgmt
,
8417 .policy
= nl80211_policy
,
8418 .flags
= GENL_ADMIN_PERM
,
8419 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8420 NL80211_FLAG_NEED_RTNL
,
8423 .cmd
= NL80211_CMD_TDLS_OPER
,
8424 .doit
= nl80211_tdls_oper
,
8425 .policy
= nl80211_policy
,
8426 .flags
= GENL_ADMIN_PERM
,
8427 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8428 NL80211_FLAG_NEED_RTNL
,
8431 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
8432 .doit
= nl80211_register_unexpected_frame
,
8433 .policy
= nl80211_policy
,
8434 .flags
= GENL_ADMIN_PERM
,
8435 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8436 NL80211_FLAG_NEED_RTNL
,
8439 .cmd
= NL80211_CMD_PROBE_CLIENT
,
8440 .doit
= nl80211_probe_client
,
8441 .policy
= nl80211_policy
,
8442 .flags
= GENL_ADMIN_PERM
,
8443 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8444 NL80211_FLAG_NEED_RTNL
,
8447 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
8448 .doit
= nl80211_register_beacons
,
8449 .policy
= nl80211_policy
,
8450 .flags
= GENL_ADMIN_PERM
,
8451 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
8452 NL80211_FLAG_NEED_RTNL
,
8455 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
8456 .doit
= nl80211_set_noack_map
,
8457 .policy
= nl80211_policy
,
8458 .flags
= GENL_ADMIN_PERM
,
8459 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8460 NL80211_FLAG_NEED_RTNL
,
8463 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
8464 .doit
= nl80211_start_p2p_device
,
8465 .policy
= nl80211_policy
,
8466 .flags
= GENL_ADMIN_PERM
,
8467 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
8468 NL80211_FLAG_NEED_RTNL
,
8471 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
8472 .doit
= nl80211_stop_p2p_device
,
8473 .policy
= nl80211_policy
,
8474 .flags
= GENL_ADMIN_PERM
,
8475 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
8476 NL80211_FLAG_NEED_RTNL
,
8479 .cmd
= NL80211_CMD_SET_MCAST_RATE
,
8480 .doit
= nl80211_set_mcast_rate
,
8481 .policy
= nl80211_policy
,
8482 .flags
= GENL_ADMIN_PERM
,
8483 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8484 NL80211_FLAG_NEED_RTNL
,
8487 .cmd
= NL80211_CMD_SET_MAC_ACL
,
8488 .doit
= nl80211_set_mac_acl
,
8489 .policy
= nl80211_policy
,
8490 .flags
= GENL_ADMIN_PERM
,
8491 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
8492 NL80211_FLAG_NEED_RTNL
,
8495 .cmd
= NL80211_CMD_RADAR_DETECT
,
8496 .doit
= nl80211_start_radar_detection
,
8497 .policy
= nl80211_policy
,
8498 .flags
= GENL_ADMIN_PERM
,
8499 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
8500 NL80211_FLAG_NEED_RTNL
,
8504 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
8508 /* multicast groups */
8509 static struct genl_multicast_group nl80211_config_mcgrp
= {
8512 static struct genl_multicast_group nl80211_scan_mcgrp
= {
8515 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
8516 .name
= "regulatory",
8519 /* notification functions */
8521 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
8523 struct sk_buff
*msg
;
8525 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8529 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
8534 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8535 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
8538 static int nl80211_add_scan_req(struct sk_buff
*msg
,
8539 struct cfg80211_registered_device
*rdev
)
8541 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
8542 struct nlattr
*nest
;
8545 ASSERT_RDEV_LOCK(rdev
);
8550 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
8552 goto nla_put_failure
;
8553 for (i
= 0; i
< req
->n_ssids
; i
++) {
8554 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
8555 goto nla_put_failure
;
8557 nla_nest_end(msg
, nest
);
8559 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
8561 goto nla_put_failure
;
8562 for (i
= 0; i
< req
->n_channels
; i
++) {
8563 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
8564 goto nla_put_failure
;
8566 nla_nest_end(msg
, nest
);
8569 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
8570 goto nla_put_failure
;
8573 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
8580 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
8581 struct cfg80211_registered_device
*rdev
,
8582 struct wireless_dev
*wdev
,
8583 u32 portid
, u32 seq
, int flags
,
8588 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
8592 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8593 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8594 wdev
->netdev
->ifindex
)) ||
8595 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
8596 goto nla_put_failure
;
8598 /* ignore errors and send incomplete event anyway */
8599 nl80211_add_scan_req(msg
, rdev
);
8601 return genlmsg_end(msg
, hdr
);
8604 genlmsg_cancel(msg
, hdr
);
8609 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
8610 struct cfg80211_registered_device
*rdev
,
8611 struct net_device
*netdev
,
8612 u32 portid
, u32 seq
, int flags
, u32 cmd
)
8616 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
8620 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8621 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8622 goto nla_put_failure
;
8624 return genlmsg_end(msg
, hdr
);
8627 genlmsg_cancel(msg
, hdr
);
8631 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
8632 struct wireless_dev
*wdev
)
8634 struct sk_buff
*msg
;
8636 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8640 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
8641 NL80211_CMD_TRIGGER_SCAN
) < 0) {
8646 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8647 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
8650 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
8651 struct wireless_dev
*wdev
)
8653 struct sk_buff
*msg
;
8655 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8659 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
8660 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
8665 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8666 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
8669 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
8670 struct wireless_dev
*wdev
)
8672 struct sk_buff
*msg
;
8674 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8678 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
8679 NL80211_CMD_SCAN_ABORTED
) < 0) {
8684 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8685 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
8688 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
8689 struct net_device
*netdev
)
8691 struct sk_buff
*msg
;
8693 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8697 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
8698 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
8703 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8704 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
8707 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
8708 struct net_device
*netdev
, u32 cmd
)
8710 struct sk_buff
*msg
;
8712 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8716 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
8721 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8722 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
8726 * This can happen on global regulatory changes or device specific settings
8727 * based on custom world regulatory domains.
8729 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
8731 struct sk_buff
*msg
;
8734 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8738 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
8744 /* Userspace can always count this one always being set */
8745 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
8746 goto nla_put_failure
;
8748 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
8749 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8750 NL80211_REGDOM_TYPE_WORLD
))
8751 goto nla_put_failure
;
8752 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
8753 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8754 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
8755 goto nla_put_failure
;
8756 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
8757 request
->intersect
) {
8758 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8759 NL80211_REGDOM_TYPE_INTERSECTION
))
8760 goto nla_put_failure
;
8762 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
8763 NL80211_REGDOM_TYPE_COUNTRY
) ||
8764 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
8766 goto nla_put_failure
;
8769 if (request
->wiphy_idx
!= WIPHY_IDX_INVALID
&&
8770 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
8771 goto nla_put_failure
;
8773 genlmsg_end(msg
, hdr
);
8776 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8783 genlmsg_cancel(msg
, hdr
);
8787 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
8788 struct net_device
*netdev
,
8789 const u8
*buf
, size_t len
,
8790 enum nl80211_commands cmd
, gfp_t gfp
)
8792 struct sk_buff
*msg
;
8795 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8799 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8805 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8806 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8807 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8808 goto nla_put_failure
;
8810 genlmsg_end(msg
, hdr
);
8812 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8813 nl80211_mlme_mcgrp
.id
, gfp
);
8817 genlmsg_cancel(msg
, hdr
);
8821 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
8822 struct net_device
*netdev
, const u8
*buf
,
8823 size_t len
, gfp_t gfp
)
8825 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8826 NL80211_CMD_AUTHENTICATE
, gfp
);
8829 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
8830 struct net_device
*netdev
, const u8
*buf
,
8831 size_t len
, gfp_t gfp
)
8833 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8834 NL80211_CMD_ASSOCIATE
, gfp
);
8837 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
8838 struct net_device
*netdev
, const u8
*buf
,
8839 size_t len
, gfp_t gfp
)
8841 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8842 NL80211_CMD_DEAUTHENTICATE
, gfp
);
8845 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
8846 struct net_device
*netdev
, const u8
*buf
,
8847 size_t len
, gfp_t gfp
)
8849 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8850 NL80211_CMD_DISASSOCIATE
, gfp
);
8853 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
8854 struct net_device
*netdev
, const u8
*buf
,
8855 size_t len
, gfp_t gfp
)
8857 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8858 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
8861 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
8862 struct net_device
*netdev
, const u8
*buf
,
8863 size_t len
, gfp_t gfp
)
8865 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
8866 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
8869 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
8870 struct net_device
*netdev
, int cmd
,
8871 const u8
*addr
, gfp_t gfp
)
8873 struct sk_buff
*msg
;
8876 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8880 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8886 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8887 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8888 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
8889 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8890 goto nla_put_failure
;
8892 genlmsg_end(msg
, hdr
);
8894 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8895 nl80211_mlme_mcgrp
.id
, gfp
);
8899 genlmsg_cancel(msg
, hdr
);
8903 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
8904 struct net_device
*netdev
, const u8
*addr
,
8907 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
8911 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
8912 struct net_device
*netdev
, const u8
*addr
,
8915 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
8919 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
8920 struct net_device
*netdev
, const u8
*bssid
,
8921 const u8
*req_ie
, size_t req_ie_len
,
8922 const u8
*resp_ie
, size_t resp_ie_len
,
8923 u16 status
, gfp_t gfp
)
8925 struct sk_buff
*msg
;
8928 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8932 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
8938 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8939 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8940 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
8941 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
8943 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8945 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8946 goto nla_put_failure
;
8948 genlmsg_end(msg
, hdr
);
8950 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8951 nl80211_mlme_mcgrp
.id
, gfp
);
8955 genlmsg_cancel(msg
, hdr
);
8960 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
8961 struct net_device
*netdev
, const u8
*bssid
,
8962 const u8
*req_ie
, size_t req_ie_len
,
8963 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
8965 struct sk_buff
*msg
;
8968 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8972 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
8978 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8979 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8980 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
8982 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8984 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8985 goto nla_put_failure
;
8987 genlmsg_end(msg
, hdr
);
8989 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8990 nl80211_mlme_mcgrp
.id
, gfp
);
8994 genlmsg_cancel(msg
, hdr
);
8999 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
9000 struct net_device
*netdev
, u16 reason
,
9001 const u8
*ie
, size_t ie_len
, bool from_ap
)
9003 struct sk_buff
*msg
;
9006 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
9010 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
9016 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9017 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9018 (from_ap
&& reason
&&
9019 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
9021 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
9022 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9023 goto nla_put_failure
;
9025 genlmsg_end(msg
, hdr
);
9027 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9028 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
9032 genlmsg_cancel(msg
, hdr
);
9037 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
9038 struct net_device
*netdev
, const u8
*bssid
,
9041 struct sk_buff
*msg
;
9044 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9048 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
9054 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9055 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9056 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9057 goto nla_put_failure
;
9059 genlmsg_end(msg
, hdr
);
9061 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9062 nl80211_mlme_mcgrp
.id
, gfp
);
9066 genlmsg_cancel(msg
, hdr
);
9070 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
9071 struct net_device
*netdev
,
9072 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
9075 struct sk_buff
*msg
;
9078 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9082 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
9088 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9089 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9090 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
9092 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
9093 goto nla_put_failure
;
9095 genlmsg_end(msg
, hdr
);
9097 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9098 nl80211_mlme_mcgrp
.id
, gfp
);
9102 genlmsg_cancel(msg
, hdr
);
9106 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
9107 struct net_device
*netdev
, const u8
*addr
,
9108 enum nl80211_key_type key_type
, int key_id
,
9109 const u8
*tsc
, gfp_t gfp
)
9111 struct sk_buff
*msg
;
9114 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9118 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
9124 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9125 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9126 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
9127 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
9129 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
9130 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
9131 goto nla_put_failure
;
9133 genlmsg_end(msg
, hdr
);
9135 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9136 nl80211_mlme_mcgrp
.id
, gfp
);
9140 genlmsg_cancel(msg
, hdr
);
9144 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
9145 struct ieee80211_channel
*channel_before
,
9146 struct ieee80211_channel
*channel_after
)
9148 struct sk_buff
*msg
;
9150 struct nlattr
*nl_freq
;
9152 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
9156 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
9163 * Since we are applying the beacon hint to a wiphy we know its
9164 * wiphy_idx is valid
9166 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
9167 goto nla_put_failure
;
9170 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
9172 goto nla_put_failure
;
9173 if (nl80211_msg_put_channel(msg
, channel_before
))
9174 goto nla_put_failure
;
9175 nla_nest_end(msg
, nl_freq
);
9178 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
9180 goto nla_put_failure
;
9181 if (nl80211_msg_put_channel(msg
, channel_after
))
9182 goto nla_put_failure
;
9183 nla_nest_end(msg
, nl_freq
);
9185 genlmsg_end(msg
, hdr
);
9188 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
9195 genlmsg_cancel(msg
, hdr
);
9199 static void nl80211_send_remain_on_chan_event(
9200 int cmd
, struct cfg80211_registered_device
*rdev
,
9201 struct wireless_dev
*wdev
, u64 cookie
,
9202 struct ieee80211_channel
*chan
,
9203 unsigned int duration
, gfp_t gfp
)
9205 struct sk_buff
*msg
;
9208 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9212 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9218 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9219 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9220 wdev
->netdev
->ifindex
)) ||
9221 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
9222 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
9223 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
9224 NL80211_CHAN_NO_HT
) ||
9225 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
9226 goto nla_put_failure
;
9228 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
9229 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
9230 goto nla_put_failure
;
9232 genlmsg_end(msg
, hdr
);
9234 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9235 nl80211_mlme_mcgrp
.id
, gfp
);
9239 genlmsg_cancel(msg
, hdr
);
9243 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
9244 struct wireless_dev
*wdev
, u64 cookie
,
9245 struct ieee80211_channel
*chan
,
9246 unsigned int duration
, gfp_t gfp
)
9248 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
9249 rdev
, wdev
, cookie
, chan
,
9253 void nl80211_send_remain_on_channel_cancel(
9254 struct cfg80211_registered_device
*rdev
,
9255 struct wireless_dev
*wdev
,
9256 u64 cookie
, struct ieee80211_channel
*chan
, gfp_t gfp
)
9258 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
9259 rdev
, wdev
, cookie
, chan
, 0, gfp
);
9262 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
9263 struct net_device
*dev
, const u8
*mac_addr
,
9264 struct station_info
*sinfo
, gfp_t gfp
)
9266 struct sk_buff
*msg
;
9268 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9272 if (nl80211_send_station(msg
, 0, 0, 0,
9273 rdev
, dev
, mac_addr
, sinfo
) < 0) {
9278 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9279 nl80211_mlme_mcgrp
.id
, gfp
);
9282 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
9283 struct net_device
*dev
, const u8
*mac_addr
,
9286 struct sk_buff
*msg
;
9289 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9293 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
9299 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9300 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
9301 goto nla_put_failure
;
9303 genlmsg_end(msg
, hdr
);
9305 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9306 nl80211_mlme_mcgrp
.id
, gfp
);
9310 genlmsg_cancel(msg
, hdr
);
9314 void nl80211_send_conn_failed_event(struct cfg80211_registered_device
*rdev
,
9315 struct net_device
*dev
, const u8
*mac_addr
,
9316 enum nl80211_connect_failed_reason reason
,
9319 struct sk_buff
*msg
;
9322 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
9326 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
9332 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9333 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
9334 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
9335 goto nla_put_failure
;
9337 genlmsg_end(msg
, hdr
);
9339 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9340 nl80211_mlme_mcgrp
.id
, gfp
);
9344 genlmsg_cancel(msg
, hdr
);
9348 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
9349 const u8
*addr
, gfp_t gfp
)
9351 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9352 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9353 struct sk_buff
*msg
;
9356 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
9361 msg
= nlmsg_new(100, gfp
);
9365 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
9371 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9372 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9373 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
9374 goto nla_put_failure
;
9376 err
= genlmsg_end(msg
, hdr
);
9382 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9386 genlmsg_cancel(msg
, hdr
);
9391 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
9393 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
9397 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
9398 const u8
*addr
, gfp_t gfp
)
9400 return __nl80211_unexpected_frame(dev
,
9401 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
9405 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
9406 struct wireless_dev
*wdev
, u32 nlportid
,
9407 int freq
, int sig_dbm
,
9408 const u8
*buf
, size_t len
, gfp_t gfp
)
9410 struct net_device
*netdev
= wdev
->netdev
;
9411 struct sk_buff
*msg
;
9414 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9418 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
9424 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9425 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9426 netdev
->ifindex
)) ||
9427 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
9429 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
9430 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
9431 goto nla_put_failure
;
9433 genlmsg_end(msg
, hdr
);
9435 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
9438 genlmsg_cancel(msg
, hdr
);
9443 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
9444 struct wireless_dev
*wdev
, u64 cookie
,
9445 const u8
*buf
, size_t len
, bool ack
,
9448 struct net_device
*netdev
= wdev
->netdev
;
9449 struct sk_buff
*msg
;
9452 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9456 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
9462 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9463 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9464 netdev
->ifindex
)) ||
9465 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
9466 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
9467 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
9468 goto nla_put_failure
;
9470 genlmsg_end(msg
, hdr
);
9472 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
9476 genlmsg_cancel(msg
, hdr
);
9481 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
9482 struct net_device
*netdev
,
9483 enum nl80211_cqm_rssi_threshold_event rssi_event
,
9486 struct sk_buff
*msg
;
9487 struct nlattr
*pinfoattr
;
9490 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9494 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
9500 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9501 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9502 goto nla_put_failure
;
9504 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
9506 goto nla_put_failure
;
9508 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
9510 goto nla_put_failure
;
9512 nla_nest_end(msg
, pinfoattr
);
9514 genlmsg_end(msg
, hdr
);
9516 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9517 nl80211_mlme_mcgrp
.id
, gfp
);
9521 genlmsg_cancel(msg
, hdr
);
9525 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
9526 struct net_device
*netdev
, const u8
*bssid
,
9527 const u8
*replay_ctr
, gfp_t gfp
)
9529 struct sk_buff
*msg
;
9530 struct nlattr
*rekey_attr
;
9533 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9537 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
9543 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9544 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9545 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
9546 goto nla_put_failure
;
9548 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
9550 goto nla_put_failure
;
9552 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
9553 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
9554 goto nla_put_failure
;
9556 nla_nest_end(msg
, rekey_attr
);
9558 genlmsg_end(msg
, hdr
);
9560 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9561 nl80211_mlme_mcgrp
.id
, gfp
);
9565 genlmsg_cancel(msg
, hdr
);
9569 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
9570 struct net_device
*netdev
, int index
,
9571 const u8
*bssid
, bool preauth
, gfp_t gfp
)
9573 struct sk_buff
*msg
;
9574 struct nlattr
*attr
;
9577 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9581 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
9587 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9588 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9589 goto nla_put_failure
;
9591 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
9593 goto nla_put_failure
;
9595 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
9596 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
9598 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
9599 goto nla_put_failure
;
9601 nla_nest_end(msg
, attr
);
9603 genlmsg_end(msg
, hdr
);
9605 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9606 nl80211_mlme_mcgrp
.id
, gfp
);
9610 genlmsg_cancel(msg
, hdr
);
9614 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
9615 struct net_device
*netdev
,
9616 struct cfg80211_chan_def
*chandef
, gfp_t gfp
)
9618 struct sk_buff
*msg
;
9621 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9625 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
9631 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
9632 goto nla_put_failure
;
9634 if (nl80211_send_chandef(msg
, chandef
))
9635 goto nla_put_failure
;
9637 genlmsg_end(msg
, hdr
);
9639 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9640 nl80211_mlme_mcgrp
.id
, gfp
);
9644 genlmsg_cancel(msg
, hdr
);
9649 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device
*rdev
,
9650 struct net_device
*netdev
, const u8
*peer
,
9651 u32 num_packets
, u32 rate
, u32 intvl
, gfp_t gfp
)
9653 struct sk_buff
*msg
;
9654 struct nlattr
*pinfoattr
;
9657 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
9661 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
9667 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9668 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9669 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
9670 goto nla_put_failure
;
9672 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
9674 goto nla_put_failure
;
9676 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
9677 goto nla_put_failure
;
9679 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
9680 goto nla_put_failure
;
9682 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
9683 goto nla_put_failure
;
9685 nla_nest_end(msg
, pinfoattr
);
9687 genlmsg_end(msg
, hdr
);
9689 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9690 nl80211_mlme_mcgrp
.id
, gfp
);
9694 genlmsg_cancel(msg
, hdr
);
9699 nl80211_radar_notify(struct cfg80211_registered_device
*rdev
,
9700 struct cfg80211_chan_def
*chandef
,
9701 enum nl80211_radar_event event
,
9702 struct net_device
*netdev
, gfp_t gfp
)
9704 struct sk_buff
*msg
;
9707 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9711 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_RADAR_DETECT
);
9717 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
9718 goto nla_put_failure
;
9720 /* NOP and radar events don't need a netdev parameter */
9722 struct wireless_dev
*wdev
= netdev
->ieee80211_ptr
;
9724 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9725 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9726 goto nla_put_failure
;
9729 if (nla_put_u32(msg
, NL80211_ATTR_RADAR_EVENT
, event
))
9730 goto nla_put_failure
;
9732 if (nl80211_send_chandef(msg
, chandef
))
9733 goto nla_put_failure
;
9735 if (genlmsg_end(msg
, hdr
) < 0) {
9740 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9741 nl80211_mlme_mcgrp
.id
, gfp
);
9745 genlmsg_cancel(msg
, hdr
);
9750 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
9751 struct net_device
*netdev
, const u8
*peer
,
9752 u32 num_packets
, gfp_t gfp
)
9754 struct sk_buff
*msg
;
9755 struct nlattr
*pinfoattr
;
9758 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9762 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
9768 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9769 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
9770 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
9771 goto nla_put_failure
;
9773 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
9775 goto nla_put_failure
;
9777 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
9778 goto nla_put_failure
;
9780 nla_nest_end(msg
, pinfoattr
);
9782 genlmsg_end(msg
, hdr
);
9784 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9785 nl80211_mlme_mcgrp
.id
, gfp
);
9789 genlmsg_cancel(msg
, hdr
);
9793 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
9794 u64 cookie
, bool acked
, gfp_t gfp
)
9796 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9797 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9798 struct sk_buff
*msg
;
9802 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
9804 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
9809 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
9815 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9816 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
9817 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
9818 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
9819 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
9820 goto nla_put_failure
;
9822 err
= genlmsg_end(msg
, hdr
);
9828 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9829 nl80211_mlme_mcgrp
.id
, gfp
);
9833 genlmsg_cancel(msg
, hdr
);
9836 EXPORT_SYMBOL(cfg80211_probe_status
);
9838 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
9839 const u8
*frame
, size_t len
,
9840 int freq
, int sig_dbm
)
9842 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
9843 struct sk_buff
*msg
;
9845 struct cfg80211_beacon_registration
*reg
;
9847 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
9849 spin_lock_bh(&rdev
->beacon_registrations_lock
);
9850 list_for_each_entry(reg
, &rdev
->beacon_registrations
, list
) {
9851 msg
= nlmsg_new(len
+ 100, GFP_ATOMIC
);
9853 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9857 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
9859 goto nla_put_failure
;
9861 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9863 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
9865 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
9866 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
9867 goto nla_put_failure
;
9869 genlmsg_end(msg
, hdr
);
9871 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, reg
->nlportid
);
9873 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9877 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
9879 genlmsg_cancel(msg
, hdr
);
9882 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
9885 void cfg80211_report_wowlan_wakeup(struct wireless_dev
*wdev
,
9886 struct cfg80211_wowlan_wakeup
*wakeup
,
9889 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9890 struct sk_buff
*msg
;
9892 int err
, size
= 200;
9894 trace_cfg80211_report_wowlan_wakeup(wdev
->wiphy
, wdev
, wakeup
);
9897 size
+= wakeup
->packet_present_len
;
9899 msg
= nlmsg_new(size
, gfp
);
9903 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_WOWLAN
);
9907 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
9908 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
9911 if (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
9912 wdev
->netdev
->ifindex
))
9916 struct nlattr
*reasons
;
9918 reasons
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
9920 if (wakeup
->disconnect
&&
9921 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
))
9923 if (wakeup
->magic_pkt
&&
9924 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
))
9926 if (wakeup
->gtk_rekey_failure
&&
9927 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
))
9929 if (wakeup
->eap_identity_req
&&
9930 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
))
9932 if (wakeup
->four_way_handshake
&&
9933 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
))
9935 if (wakeup
->rfkill_release
&&
9936 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
))
9939 if (wakeup
->pattern_idx
>= 0 &&
9940 nla_put_u32(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
9941 wakeup
->pattern_idx
))
9944 if (wakeup
->tcp_match
)
9945 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH
);
9947 if (wakeup
->tcp_connlost
)
9949 NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST
);
9951 if (wakeup
->tcp_nomoretokens
)
9953 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS
);
9955 if (wakeup
->packet
) {
9956 u32 pkt_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211
;
9957 u32 len_attr
= NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN
;
9959 if (!wakeup
->packet_80211
) {
9961 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023
;
9963 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN
;
9966 if (wakeup
->packet_len
&&
9967 nla_put_u32(msg
, len_attr
, wakeup
->packet_len
))
9970 if (nla_put(msg
, pkt_attr
, wakeup
->packet_present_len
,
9975 nla_nest_end(msg
, reasons
);
9978 err
= genlmsg_end(msg
, hdr
);
9982 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
9983 nl80211_mlme_mcgrp
.id
, gfp
);
9989 EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup
);
9992 void cfg80211_tdls_oper_request(struct net_device
*dev
, const u8
*peer
,
9993 enum nl80211_tdls_operation oper
,
9994 u16 reason_code
, gfp_t gfp
)
9996 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
9997 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
9998 struct sk_buff
*msg
;
10002 trace_cfg80211_tdls_oper_request(wdev
->wiphy
, dev
, peer
, oper
,
10005 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
10009 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_TDLS_OPER
);
10015 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
10016 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
10017 nla_put_u8(msg
, NL80211_ATTR_TDLS_OPERATION
, oper
) ||
10018 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
) ||
10019 (reason_code
> 0 &&
10020 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
)))
10021 goto nla_put_failure
;
10023 err
= genlmsg_end(msg
, hdr
);
10029 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
10030 nl80211_mlme_mcgrp
.id
, gfp
);
10034 genlmsg_cancel(msg
, hdr
);
10037 EXPORT_SYMBOL(cfg80211_tdls_oper_request
);
10039 static int nl80211_netlink_notify(struct notifier_block
* nb
,
10040 unsigned long state
,
10043 struct netlink_notify
*notify
= _notify
;
10044 struct cfg80211_registered_device
*rdev
;
10045 struct wireless_dev
*wdev
;
10046 struct cfg80211_beacon_registration
*reg
, *tmp
;
10048 if (state
!= NETLINK_URELEASE
)
10049 return NOTIFY_DONE
;
10053 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
10054 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
10055 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
10057 spin_lock_bh(&rdev
->beacon_registrations_lock
);
10058 list_for_each_entry_safe(reg
, tmp
, &rdev
->beacon_registrations
,
10060 if (reg
->nlportid
== notify
->portid
) {
10061 list_del(®
->list
);
10066 spin_unlock_bh(&rdev
->beacon_registrations_lock
);
10071 return NOTIFY_DONE
;
10074 static struct notifier_block nl80211_netlink_notifier
= {
10075 .notifier_call
= nl80211_netlink_notify
,
10078 /* initialisation/exit functions */
10080 int nl80211_init(void)
10084 err
= genl_register_family_with_ops(&nl80211_fam
,
10085 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
10089 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
10093 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
10097 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
10101 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
10105 #ifdef CONFIG_NL80211_TESTMODE
10106 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
10111 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
10117 genl_unregister_family(&nl80211_fam
);
10121 void nl80211_exit(void)
10123 netlink_unregister_notifier(&nl80211_netlink_notifier
);
10124 genl_unregister_family(&nl80211_fam
);