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>
27 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
28 struct genl_info
*info
,
29 struct cfg80211_crypto_settings
*settings
,
32 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
33 struct genl_info
*info
);
34 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
35 struct genl_info
*info
);
37 /* the netlink family */
38 static struct genl_family nl80211_fam
= {
39 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
40 .name
= "nl80211", /* have users key off the name instead */
41 .hdrsize
= 0, /* no private header */
42 .version
= 1, /* no particular meaning now */
43 .maxattr
= NL80211_ATTR_MAX
,
45 .pre_doit
= nl80211_pre_doit
,
46 .post_doit
= nl80211_post_doit
,
49 /* returns ERR_PTR values */
50 static struct wireless_dev
*
51 __cfg80211_wdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
53 struct cfg80211_registered_device
*rdev
;
54 struct wireless_dev
*result
= NULL
;
55 bool have_ifidx
= attrs
[NL80211_ATTR_IFINDEX
];
56 bool have_wdev_id
= attrs
[NL80211_ATTR_WDEV
];
61 assert_cfg80211_lock();
63 if (!have_ifidx
&& !have_wdev_id
)
64 return ERR_PTR(-EINVAL
);
67 ifidx
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
69 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
70 wiphy_idx
= wdev_id
>> 32;
73 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
74 struct wireless_dev
*wdev
;
76 if (wiphy_net(&rdev
->wiphy
) != netns
)
79 if (have_wdev_id
&& rdev
->wiphy_idx
!= wiphy_idx
)
82 mutex_lock(&rdev
->devlist_mtx
);
83 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
84 if (have_ifidx
&& wdev
->netdev
&&
85 wdev
->netdev
->ifindex
== ifidx
) {
89 if (have_wdev_id
&& wdev
->identifier
== (u32
)wdev_id
) {
94 mutex_unlock(&rdev
->devlist_mtx
);
102 return ERR_PTR(-ENODEV
);
105 static struct cfg80211_registered_device
*
106 __cfg80211_rdev_from_attrs(struct net
*netns
, struct nlattr
**attrs
)
108 struct cfg80211_registered_device
*rdev
= NULL
, *tmp
;
109 struct net_device
*netdev
;
111 assert_cfg80211_lock();
113 if (!attrs
[NL80211_ATTR_WIPHY
] &&
114 !attrs
[NL80211_ATTR_IFINDEX
] &&
115 !attrs
[NL80211_ATTR_WDEV
])
116 return ERR_PTR(-EINVAL
);
118 if (attrs
[NL80211_ATTR_WIPHY
])
119 rdev
= cfg80211_rdev_by_wiphy_idx(
120 nla_get_u32(attrs
[NL80211_ATTR_WIPHY
]));
122 if (attrs
[NL80211_ATTR_WDEV
]) {
123 u64 wdev_id
= nla_get_u64(attrs
[NL80211_ATTR_WDEV
]);
124 struct wireless_dev
*wdev
;
127 tmp
= cfg80211_rdev_by_wiphy_idx(wdev_id
>> 32);
129 /* make sure wdev exists */
130 mutex_lock(&tmp
->devlist_mtx
);
131 list_for_each_entry(wdev
, &tmp
->wdev_list
, list
) {
132 if (wdev
->identifier
!= (u32
)wdev_id
)
137 mutex_unlock(&tmp
->devlist_mtx
);
142 if (rdev
&& tmp
!= rdev
)
143 return ERR_PTR(-EINVAL
);
148 if (attrs
[NL80211_ATTR_IFINDEX
]) {
149 int ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
150 netdev
= dev_get_by_index(netns
, ifindex
);
152 if (netdev
->ieee80211_ptr
)
154 netdev
->ieee80211_ptr
->wiphy
);
160 /* not wireless device -- return error */
162 return ERR_PTR(-EINVAL
);
164 /* mismatch -- return error */
165 if (rdev
&& tmp
!= rdev
)
166 return ERR_PTR(-EINVAL
);
173 return ERR_PTR(-ENODEV
);
175 if (netns
!= wiphy_net(&rdev
->wiphy
))
176 return ERR_PTR(-ENODEV
);
182 * This function returns a pointer to the driver
183 * that the genl_info item that is passed refers to.
184 * If successful, it returns non-NULL and also locks
185 * the driver's mutex!
187 * This means that you need to call cfg80211_unlock_rdev()
188 * before being allowed to acquire &cfg80211_mutex!
190 * This is necessary because we need to lock the global
191 * mutex to get an item off the list safely, and then
192 * we lock the rdev mutex so it doesn't go away under us.
194 * We don't want to keep cfg80211_mutex locked
195 * for all the time in order to allow requests on
196 * other interfaces to go through at the same time.
198 * The result of this can be a PTR_ERR and hence must
199 * be checked with IS_ERR() for errors.
201 static struct cfg80211_registered_device
*
202 cfg80211_get_dev_from_info(struct net
*netns
, struct genl_info
*info
)
204 struct cfg80211_registered_device
*rdev
;
206 mutex_lock(&cfg80211_mutex
);
207 rdev
= __cfg80211_rdev_from_attrs(netns
, info
->attrs
);
209 /* if it is not an error we grab the lock on
210 * it to assure it won't be going away while
211 * we operate on it */
213 mutex_lock(&rdev
->mtx
);
215 mutex_unlock(&cfg80211_mutex
);
220 /* policy for the attributes */
221 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
222 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
223 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
225 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
226 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
227 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
228 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
229 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
230 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
231 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
232 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
234 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
235 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
236 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
238 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
239 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
241 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
242 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
243 .len
= WLAN_MAX_KEY_LEN
},
244 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
245 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
246 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
247 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
248 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
250 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
251 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
252 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
253 .len
= IEEE80211_MAX_DATA_LEN
},
254 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
255 .len
= IEEE80211_MAX_DATA_LEN
},
256 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
257 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
258 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
259 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
260 .len
= NL80211_MAX_SUPP_RATES
},
261 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
262 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
263 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
264 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
265 .len
= IEEE80211_MAX_MESH_ID_LEN
},
266 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
268 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
269 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
271 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
272 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
273 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
274 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
275 .len
= NL80211_MAX_SUPP_RATES
},
276 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
278 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
279 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
281 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
283 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
284 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
285 .len
= IEEE80211_MAX_DATA_LEN
},
286 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
287 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
289 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
290 .len
= IEEE80211_MAX_SSID_LEN
},
291 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
292 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
293 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
294 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
295 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
296 [NL80211_ATTR_STA_FLAGS2
] = {
297 .len
= sizeof(struct nl80211_sta_flag_update
),
299 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
300 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
301 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
302 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
303 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
304 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
305 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
306 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
307 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
308 .len
= WLAN_PMKID_LEN
},
309 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
310 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
311 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
312 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
313 .len
= IEEE80211_MAX_DATA_LEN
},
314 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
315 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
316 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
317 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
318 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
319 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
320 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
321 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
322 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
323 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
324 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
325 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
326 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
327 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
328 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
329 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
330 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
331 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
332 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
333 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
334 .len
= IEEE80211_MAX_DATA_LEN
},
335 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
336 .len
= IEEE80211_MAX_DATA_LEN
},
337 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
338 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
339 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
340 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
341 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
342 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
343 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
344 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
345 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
346 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
347 .len
= IEEE80211_MAX_DATA_LEN
},
348 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
349 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
350 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
351 .len
= NL80211_HT_CAPABILITY_LEN
353 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
354 [NL80211_ATTR_INACTIVITY_TIMEOUT
] = { .type
= NLA_U16
},
355 [NL80211_ATTR_BG_SCAN_PERIOD
] = { .type
= NLA_U16
},
356 [NL80211_ATTR_WDEV
] = { .type
= NLA_U64
},
357 [NL80211_ATTR_USER_REG_HINT_TYPE
] = { .type
= NLA_U32
},
358 [NL80211_ATTR_SAE_DATA
] = { .type
= NLA_BINARY
, },
359 [NL80211_ATTR_VHT_CAPABILITY
] = { .len
= NL80211_VHT_CAPABILITY_LEN
},
360 [NL80211_ATTR_SCAN_FLAGS
] = { .type
= NLA_U32
},
363 /* policy for the key attributes */
364 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
365 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
366 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
367 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
368 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
369 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
370 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
371 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
372 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
375 /* policy for the key default flags */
376 static const struct nla_policy
377 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
378 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
379 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
382 /* policy for WoWLAN attributes */
383 static const struct nla_policy
384 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
385 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
386 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
387 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
388 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
389 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
390 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
391 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
392 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
395 /* policy for GTK rekey offload attributes */
396 static const struct nla_policy
397 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
398 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
399 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
400 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
403 static const struct nla_policy
404 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
405 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID
] = { .type
= NLA_BINARY
,
406 .len
= IEEE80211_MAX_SSID_LEN
},
407 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
] = { .type
= NLA_U32
},
410 /* ifidx get helper */
411 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
415 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
416 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
421 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
424 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
430 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
431 struct netlink_callback
*cb
,
432 struct cfg80211_registered_device
**rdev
,
433 struct net_device
**dev
)
435 int ifidx
= cb
->args
[0];
439 ifidx
= nl80211_get_ifidx(cb
);
447 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
453 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
455 err
= PTR_ERR(*rdev
);
465 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
467 cfg80211_unlock_rdev(rdev
);
472 static bool is_valid_ie_attr(const struct nlattr
*attr
)
480 pos
= nla_data(attr
);
501 /* message building helper */
502 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
505 /* since there is no private header just add the generic one */
506 return genlmsg_put(skb
, portid
, seq
, &nl80211_fam
, flags
, cmd
);
509 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
510 struct ieee80211_channel
*chan
)
512 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
514 goto nla_put_failure
;
516 if ((chan
->flags
& IEEE80211_CHAN_DISABLED
) &&
517 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_DISABLED
))
518 goto nla_put_failure
;
519 if ((chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
) &&
520 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
))
521 goto nla_put_failure
;
522 if ((chan
->flags
& IEEE80211_CHAN_NO_IBSS
) &&
523 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
))
524 goto nla_put_failure
;
525 if ((chan
->flags
& IEEE80211_CHAN_RADAR
) &&
526 nla_put_flag(msg
, NL80211_FREQUENCY_ATTR_RADAR
))
527 goto nla_put_failure
;
529 if (nla_put_u32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
530 DBM_TO_MBM(chan
->max_power
)))
531 goto nla_put_failure
;
539 /* netlink command implementations */
546 bool def_uni
, def_multi
;
549 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
551 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
552 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
557 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
558 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
567 if (tb
[NL80211_KEY_IDX
])
568 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
570 if (tb
[NL80211_KEY_DATA
]) {
571 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
572 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
575 if (tb
[NL80211_KEY_SEQ
]) {
576 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
577 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
580 if (tb
[NL80211_KEY_CIPHER
])
581 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
583 if (tb
[NL80211_KEY_TYPE
]) {
584 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
585 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
589 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
590 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
591 err
= nla_parse_nested(kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
592 tb
[NL80211_KEY_DEFAULT_TYPES
],
593 nl80211_key_default_policy
);
597 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
598 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
604 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
606 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
607 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
608 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
611 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
612 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
613 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
616 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
617 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
619 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
620 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
622 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
623 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
632 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
633 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
634 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
638 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
639 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
640 int err
= nla_parse_nested(
641 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
642 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
643 nl80211_key_default_policy
);
647 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
648 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
654 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
658 memset(k
, 0, sizeof(*k
));
662 if (info
->attrs
[NL80211_ATTR_KEY
])
663 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
665 err
= nl80211_parse_key_old(info
, k
);
670 if (k
->def
&& k
->defmgmt
)
674 if (k
->def_uni
|| !k
->def_multi
)
680 if (k
->idx
< 4 || k
->idx
> 5)
683 if (k
->idx
< 0 || k
->idx
> 3)
686 if (k
->idx
< 0 || k
->idx
> 5)
694 static struct cfg80211_cached_keys
*
695 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
696 struct nlattr
*keys
, bool *no_ht
)
698 struct key_parse parse
;
700 struct cfg80211_cached_keys
*result
;
701 int rem
, err
, def
= 0;
703 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
705 return ERR_PTR(-ENOMEM
);
708 result
->defmgmt
= -1;
710 nla_for_each_nested(key
, keys
, rem
) {
711 memset(&parse
, 0, sizeof(parse
));
714 err
= nl80211_parse_key_new(key
, &parse
);
720 if (parse
.idx
< 0 || parse
.idx
> 4)
726 result
->def
= parse
.idx
;
727 if (!parse
.def_uni
|| !parse
.def_multi
)
729 } else if (parse
.defmgmt
)
731 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
732 parse
.idx
, false, NULL
);
735 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
736 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
737 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
738 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
740 if (parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP40
||
741 parse
.p
.cipher
== WLAN_CIPHER_SUITE_WEP104
) {
753 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
755 ASSERT_WDEV_LOCK(wdev
);
757 switch (wdev
->iftype
) {
758 case NL80211_IFTYPE_AP
:
759 case NL80211_IFTYPE_AP_VLAN
:
760 case NL80211_IFTYPE_P2P_GO
:
761 case NL80211_IFTYPE_MESH_POINT
:
763 case NL80211_IFTYPE_ADHOC
:
764 if (!wdev
->current_bss
)
767 case NL80211_IFTYPE_STATION
:
768 case NL80211_IFTYPE_P2P_CLIENT
:
769 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
779 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
781 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
785 goto nla_put_failure
;
789 if ((ifmodes
& 1) && nla_put_flag(msg
, i
))
790 goto nla_put_failure
;
795 nla_nest_end(msg
, nl_modes
);
802 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
805 struct nlattr
*nl_combis
;
808 nl_combis
= nla_nest_start(msg
,
809 NL80211_ATTR_INTERFACE_COMBINATIONS
);
811 goto nla_put_failure
;
813 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
814 const struct ieee80211_iface_combination
*c
;
815 struct nlattr
*nl_combi
, *nl_limits
;
817 c
= &wiphy
->iface_combinations
[i
];
819 nl_combi
= nla_nest_start(msg
, i
+ 1);
821 goto nla_put_failure
;
823 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
825 goto nla_put_failure
;
827 for (j
= 0; j
< c
->n_limits
; j
++) {
828 struct nlattr
*nl_limit
;
830 nl_limit
= nla_nest_start(msg
, j
+ 1);
832 goto nla_put_failure
;
833 if (nla_put_u32(msg
, NL80211_IFACE_LIMIT_MAX
,
835 goto nla_put_failure
;
836 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
838 goto nla_put_failure
;
839 nla_nest_end(msg
, nl_limit
);
842 nla_nest_end(msg
, nl_limits
);
844 if (c
->beacon_int_infra_match
&&
845 nla_put_flag(msg
, NL80211_IFACE_COMB_STA_AP_BI_MATCH
))
846 goto nla_put_failure
;
847 if (nla_put_u32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
848 c
->num_different_channels
) ||
849 nla_put_u32(msg
, NL80211_IFACE_COMB_MAXNUM
,
851 goto nla_put_failure
;
853 nla_nest_end(msg
, nl_combi
);
856 nla_nest_end(msg
, nl_combis
);
863 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
864 struct cfg80211_registered_device
*dev
)
867 struct nlattr
*nl_bands
, *nl_band
;
868 struct nlattr
*nl_freqs
, *nl_freq
;
869 struct nlattr
*nl_rates
, *nl_rate
;
870 struct nlattr
*nl_cmds
;
871 enum ieee80211_band band
;
872 struct ieee80211_channel
*chan
;
873 struct ieee80211_rate
*rate
;
875 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
876 dev
->wiphy
.mgmt_stypes
;
878 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
882 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) ||
883 nla_put_string(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
)) ||
884 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
885 cfg80211_rdev_list_generation
) ||
886 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
887 dev
->wiphy
.retry_short
) ||
888 nla_put_u8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
889 dev
->wiphy
.retry_long
) ||
890 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
891 dev
->wiphy
.frag_threshold
) ||
892 nla_put_u32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
893 dev
->wiphy
.rts_threshold
) ||
894 nla_put_u8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
895 dev
->wiphy
.coverage_class
) ||
896 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
897 dev
->wiphy
.max_scan_ssids
) ||
898 nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
899 dev
->wiphy
.max_sched_scan_ssids
) ||
900 nla_put_u16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
901 dev
->wiphy
.max_scan_ie_len
) ||
902 nla_put_u16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
903 dev
->wiphy
.max_sched_scan_ie_len
) ||
904 nla_put_u8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
905 dev
->wiphy
.max_match_sets
))
906 goto nla_put_failure
;
908 if ((dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
) &&
909 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
))
910 goto nla_put_failure
;
911 if ((dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
) &&
912 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
))
913 goto nla_put_failure
;
914 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
915 nla_put_flag(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
))
916 goto nla_put_failure
;
917 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
) &&
918 nla_put_flag(msg
, NL80211_ATTR_ROAM_SUPPORT
))
919 goto nla_put_failure
;
920 if ((dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
921 nla_put_flag(msg
, NL80211_ATTR_TDLS_SUPPORT
))
922 goto nla_put_failure
;
923 if ((dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
) &&
924 nla_put_flag(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
))
925 goto nla_put_failure
;
927 if (nla_put(msg
, NL80211_ATTR_CIPHER_SUITES
,
928 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
929 dev
->wiphy
.cipher_suites
))
930 goto nla_put_failure
;
932 if (nla_put_u8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
933 dev
->wiphy
.max_num_pmkids
))
934 goto nla_put_failure
;
936 if ((dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
937 nla_put_flag(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
))
938 goto nla_put_failure
;
940 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
941 dev
->wiphy
.available_antennas_tx
) ||
942 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
943 dev
->wiphy
.available_antennas_rx
))
944 goto nla_put_failure
;
946 if ((dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
) &&
947 nla_put_u32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
948 dev
->wiphy
.probe_resp_offload
))
949 goto nla_put_failure
;
951 if ((dev
->wiphy
.available_antennas_tx
||
952 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
953 u32 tx_ant
= 0, rx_ant
= 0;
955 res
= rdev_get_antenna(dev
, &tx_ant
, &rx_ant
);
957 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
,
959 nla_put_u32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
,
961 goto nla_put_failure
;
965 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
966 dev
->wiphy
.interface_modes
))
967 goto nla_put_failure
;
969 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
971 goto nla_put_failure
;
973 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
974 if (!dev
->wiphy
.bands
[band
])
977 nl_band
= nla_nest_start(msg
, band
);
979 goto nla_put_failure
;
982 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
&&
983 (nla_put(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
984 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
985 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
) ||
986 nla_put_u16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
987 dev
->wiphy
.bands
[band
]->ht_cap
.cap
) ||
988 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
989 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
) ||
990 nla_put_u8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
991 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
)))
992 goto nla_put_failure
;
995 if (dev
->wiphy
.bands
[band
]->vht_cap
.vht_supported
&&
996 (nla_put(msg
, NL80211_BAND_ATTR_VHT_MCS_SET
,
997 sizeof(dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
),
998 &dev
->wiphy
.bands
[band
]->vht_cap
.vht_mcs
) ||
999 nla_put_u32(msg
, NL80211_BAND_ATTR_VHT_CAPA
,
1000 dev
->wiphy
.bands
[band
]->vht_cap
.cap
)))
1001 goto nla_put_failure
;
1003 /* add frequencies */
1004 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
1006 goto nla_put_failure
;
1008 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
1009 nl_freq
= nla_nest_start(msg
, i
);
1011 goto nla_put_failure
;
1013 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
1015 if (nl80211_msg_put_channel(msg
, chan
))
1016 goto nla_put_failure
;
1018 nla_nest_end(msg
, nl_freq
);
1021 nla_nest_end(msg
, nl_freqs
);
1024 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
1026 goto nla_put_failure
;
1028 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
1029 nl_rate
= nla_nest_start(msg
, i
);
1031 goto nla_put_failure
;
1033 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
1034 if (nla_put_u32(msg
, NL80211_BITRATE_ATTR_RATE
,
1036 goto nla_put_failure
;
1037 if ((rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
) &&
1039 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
))
1040 goto nla_put_failure
;
1042 nla_nest_end(msg
, nl_rate
);
1045 nla_nest_end(msg
, nl_rates
);
1047 nla_nest_end(msg
, nl_band
);
1049 nla_nest_end(msg
, nl_bands
);
1051 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
1053 goto nla_put_failure
;
1056 #define CMD(op, n) \
1058 if (dev->ops->op) { \
1060 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1061 goto nla_put_failure; \
1065 CMD(add_virtual_intf
, NEW_INTERFACE
);
1066 CMD(change_virtual_intf
, SET_INTERFACE
);
1067 CMD(add_key
, NEW_KEY
);
1068 CMD(start_ap
, START_AP
);
1069 CMD(add_station
, NEW_STATION
);
1070 CMD(add_mpath
, NEW_MPATH
);
1071 CMD(update_mesh_config
, SET_MESH_CONFIG
);
1072 CMD(change_bss
, SET_BSS
);
1073 CMD(auth
, AUTHENTICATE
);
1074 CMD(assoc
, ASSOCIATE
);
1075 CMD(deauth
, DEAUTHENTICATE
);
1076 CMD(disassoc
, DISASSOCIATE
);
1077 CMD(join_ibss
, JOIN_IBSS
);
1078 CMD(join_mesh
, JOIN_MESH
);
1079 CMD(set_pmksa
, SET_PMKSA
);
1080 CMD(del_pmksa
, DEL_PMKSA
);
1081 CMD(flush_pmksa
, FLUSH_PMKSA
);
1082 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
1083 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
1084 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
1085 CMD(mgmt_tx
, FRAME
);
1086 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
1087 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
1089 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
))
1090 goto nla_put_failure
;
1092 if (dev
->ops
->set_monitor_channel
|| dev
->ops
->start_ap
||
1093 dev
->ops
->join_mesh
) {
1095 if (nla_put_u32(msg
, i
, NL80211_CMD_SET_CHANNEL
))
1096 goto nla_put_failure
;
1098 CMD(set_wds_peer
, SET_WDS_PEER
);
1099 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
1100 CMD(tdls_mgmt
, TDLS_MGMT
);
1101 CMD(tdls_oper
, TDLS_OPER
);
1103 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
1104 CMD(sched_scan_start
, START_SCHED_SCAN
);
1105 CMD(probe_client
, PROBE_CLIENT
);
1106 CMD(set_noack_map
, SET_NOACK_MAP
);
1107 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
1109 if (nla_put_u32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
))
1110 goto nla_put_failure
;
1112 CMD(start_p2p_device
, START_P2P_DEVICE
);
1114 #ifdef CONFIG_NL80211_TESTMODE
1115 CMD(testmode_cmd
, TESTMODE
);
1120 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
1122 if (nla_put_u32(msg
, i
, NL80211_CMD_CONNECT
))
1123 goto nla_put_failure
;
1126 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
1128 if (nla_put_u32(msg
, i
, NL80211_CMD_DISCONNECT
))
1129 goto nla_put_failure
;
1132 nla_nest_end(msg
, nl_cmds
);
1134 if (dev
->ops
->remain_on_channel
&&
1135 (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
) &&
1136 nla_put_u32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
1137 dev
->wiphy
.max_remain_on_channel_duration
))
1138 goto nla_put_failure
;
1140 if ((dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
) &&
1141 nla_put_flag(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
))
1142 goto nla_put_failure
;
1146 struct nlattr
*nl_ftypes
, *nl_ifs
;
1147 enum nl80211_iftype ift
;
1149 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
1151 goto nla_put_failure
;
1153 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1154 nl_ftypes
= nla_nest_start(msg
, ift
);
1156 goto nla_put_failure
;
1158 stypes
= mgmt_stypes
[ift
].tx
;
1161 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1162 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1163 goto nla_put_failure
;
1167 nla_nest_end(msg
, nl_ftypes
);
1170 nla_nest_end(msg
, nl_ifs
);
1172 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
1174 goto nla_put_failure
;
1176 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
1177 nl_ftypes
= nla_nest_start(msg
, ift
);
1179 goto nla_put_failure
;
1181 stypes
= mgmt_stypes
[ift
].rx
;
1184 nla_put_u16(msg
, NL80211_ATTR_FRAME_TYPE
,
1185 (i
<< 4) | IEEE80211_FTYPE_MGMT
))
1186 goto nla_put_failure
;
1190 nla_nest_end(msg
, nl_ftypes
);
1192 nla_nest_end(msg
, nl_ifs
);
1196 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
1197 struct nlattr
*nl_wowlan
;
1199 nl_wowlan
= nla_nest_start(msg
,
1200 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
1202 goto nla_put_failure
;
1204 if (((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
) &&
1205 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
1206 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
) &&
1207 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
1208 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
) &&
1209 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
1210 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
) &&
1211 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
)) ||
1212 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
) &&
1213 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
1214 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
) &&
1215 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
1216 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
) &&
1217 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
1218 ((dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
) &&
1219 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
1220 goto nla_put_failure
;
1221 if (dev
->wiphy
.wowlan
.n_patterns
) {
1222 struct nl80211_wowlan_pattern_support pat
= {
1223 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1225 dev
->wiphy
.wowlan
.pattern_min_len
,
1227 dev
->wiphy
.wowlan
.pattern_max_len
,
1229 if (nla_put(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1231 goto nla_put_failure
;
1234 nla_nest_end(msg
, nl_wowlan
);
1238 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1239 dev
->wiphy
.software_iftypes
))
1240 goto nla_put_failure
;
1242 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1243 goto nla_put_failure
;
1245 if ((dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
) &&
1246 nla_put_u32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1247 dev
->wiphy
.ap_sme_capa
))
1248 goto nla_put_failure
;
1250 if (nla_put_u32(msg
, NL80211_ATTR_FEATURE_FLAGS
,
1251 dev
->wiphy
.features
))
1252 goto nla_put_failure
;
1254 if (dev
->wiphy
.ht_capa_mod_mask
&&
1255 nla_put(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1256 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1257 dev
->wiphy
.ht_capa_mod_mask
))
1258 goto nla_put_failure
;
1260 return genlmsg_end(msg
, hdr
);
1263 genlmsg_cancel(msg
, hdr
);
1267 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1270 int start
= cb
->args
[0];
1271 struct cfg80211_registered_device
*dev
;
1273 mutex_lock(&cfg80211_mutex
);
1274 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1275 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1279 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).portid
,
1280 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1286 mutex_unlock(&cfg80211_mutex
);
1293 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1295 struct sk_buff
*msg
;
1296 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1298 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1302 if (nl80211_send_wiphy(msg
, info
->snd_portid
, info
->snd_seq
, 0, dev
) < 0) {
1307 return genlmsg_reply(msg
, info
);
1310 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1311 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1312 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1313 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1314 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1315 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1318 static int parse_txq_params(struct nlattr
*tb
[],
1319 struct ieee80211_txq_params
*txq_params
)
1321 if (!tb
[NL80211_TXQ_ATTR_AC
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1322 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1323 !tb
[NL80211_TXQ_ATTR_AIFS
])
1326 txq_params
->ac
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AC
]);
1327 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1328 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1329 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1330 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1332 if (txq_params
->ac
>= NL80211_NUM_ACS
)
1338 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1341 * You can only set the channel explicitly for WDS interfaces,
1342 * all others have their channel managed via their respective
1343 * "establish a connection" command (connect, join, ...)
1345 * For AP/GO and mesh mode, the channel can be set with the
1346 * channel userspace API, but is only stored and passed to the
1347 * low-level driver when the AP starts or the mesh is joined.
1348 * This is for backward compatibility, userspace can also give
1349 * the channel in the start-ap or join-mesh commands instead.
1351 * Monitors are special as they are normally slaved to
1352 * whatever else is going on, so they have their own special
1353 * operation to set the monitor channel if possible.
1356 wdev
->iftype
== NL80211_IFTYPE_AP
||
1357 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1358 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1359 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1362 static bool nl80211_valid_channel_type(struct genl_info
*info
,
1363 enum nl80211_channel_type
*channel_type
)
1365 enum nl80211_channel_type tmp
;
1367 if (!info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1370 tmp
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1371 if (tmp
!= NL80211_CHAN_NO_HT
&&
1372 tmp
!= NL80211_CHAN_HT20
&&
1373 tmp
!= NL80211_CHAN_HT40PLUS
&&
1374 tmp
!= NL80211_CHAN_HT40MINUS
)
1378 *channel_type
= tmp
;
1383 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1384 struct wireless_dev
*wdev
,
1385 struct genl_info
*info
)
1387 struct ieee80211_channel
*channel
;
1388 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1391 enum nl80211_iftype iftype
= NL80211_IFTYPE_MONITOR
;
1394 iftype
= wdev
->iftype
;
1396 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1399 if (!nl80211_can_set_dev_channel(wdev
))
1402 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
1403 !nl80211_valid_channel_type(info
, &channel_type
))
1406 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1408 mutex_lock(&rdev
->devlist_mtx
);
1410 case NL80211_IFTYPE_AP
:
1411 case NL80211_IFTYPE_P2P_GO
:
1412 if (wdev
->beacon_interval
) {
1416 channel
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
1417 if (!channel
|| !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
,
1423 wdev
->preset_chan
= channel
;
1424 wdev
->preset_chantype
= channel_type
;
1427 case NL80211_IFTYPE_MESH_POINT
:
1428 result
= cfg80211_set_mesh_freq(rdev
, wdev
, freq
, channel_type
);
1430 case NL80211_IFTYPE_MONITOR
:
1431 result
= cfg80211_set_monitor_channel(rdev
, freq
, channel_type
);
1436 mutex_unlock(&rdev
->devlist_mtx
);
1441 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1443 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1444 struct net_device
*netdev
= info
->user_ptr
[1];
1446 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1449 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1451 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1452 struct net_device
*dev
= info
->user_ptr
[1];
1453 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1456 if (!info
->attrs
[NL80211_ATTR_MAC
])
1459 if (netif_running(dev
))
1462 if (!rdev
->ops
->set_wds_peer
)
1465 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1468 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1469 return rdev_set_wds_peer(rdev
, dev
, bssid
);
1473 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1475 struct cfg80211_registered_device
*rdev
;
1476 struct net_device
*netdev
= NULL
;
1477 struct wireless_dev
*wdev
;
1478 int result
= 0, rem_txq_params
= 0;
1479 struct nlattr
*nl_txq_params
;
1481 u8 retry_short
= 0, retry_long
= 0;
1482 u32 frag_threshold
= 0, rts_threshold
= 0;
1483 u8 coverage_class
= 0;
1486 * Try to find the wiphy and netdev. Normally this
1487 * function shouldn't need the netdev, but this is
1488 * done for backward compatibility -- previously
1489 * setting the channel was done per wiphy, but now
1490 * it is per netdev. Previous userland like hostapd
1491 * also passed a netdev to set_wiphy, so that it is
1492 * possible to let that go to the right netdev!
1494 mutex_lock(&cfg80211_mutex
);
1496 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1497 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1499 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1500 if (netdev
&& netdev
->ieee80211_ptr
) {
1501 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1502 mutex_lock(&rdev
->mtx
);
1508 rdev
= __cfg80211_rdev_from_attrs(genl_info_net(info
),
1511 mutex_unlock(&cfg80211_mutex
);
1512 return PTR_ERR(rdev
);
1518 mutex_lock(&rdev
->mtx
);
1520 wdev
= netdev
->ieee80211_ptr
;
1523 * end workaround code, by now the rdev is available
1524 * and locked, and wdev may or may not be NULL.
1527 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1528 result
= cfg80211_dev_rename(
1529 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1531 mutex_unlock(&cfg80211_mutex
);
1536 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1537 struct ieee80211_txq_params txq_params
;
1538 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1540 if (!rdev
->ops
->set_txq_params
) {
1541 result
= -EOPNOTSUPP
;
1550 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1551 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1556 if (!netif_running(netdev
)) {
1561 nla_for_each_nested(nl_txq_params
,
1562 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1564 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1565 nla_data(nl_txq_params
),
1566 nla_len(nl_txq_params
),
1568 result
= parse_txq_params(tb
, &txq_params
);
1572 result
= rdev_set_txq_params(rdev
, netdev
,
1579 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1580 result
= __nl80211_set_channel(rdev
,
1581 nl80211_can_set_dev_channel(wdev
) ? wdev
: NULL
,
1587 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1588 enum nl80211_tx_power_setting type
;
1591 if (!rdev
->ops
->set_tx_power
) {
1592 result
= -EOPNOTSUPP
;
1596 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1597 type
= nla_get_u32(info
->attrs
[idx
]);
1599 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1600 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1605 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1606 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1607 mbm
= nla_get_u32(info
->attrs
[idx
]);
1610 result
= rdev_set_tx_power(rdev
, type
, mbm
);
1615 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1616 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1618 if ((!rdev
->wiphy
.available_antennas_tx
&&
1619 !rdev
->wiphy
.available_antennas_rx
) ||
1620 !rdev
->ops
->set_antenna
) {
1621 result
= -EOPNOTSUPP
;
1625 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1626 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1628 /* reject antenna configurations which don't match the
1629 * available antenna masks, except for the "all" mask */
1630 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1631 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1636 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1637 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1639 result
= rdev_set_antenna(rdev
, tx_ant
, rx_ant
);
1646 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1647 retry_short
= nla_get_u8(
1648 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1649 if (retry_short
== 0) {
1653 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1656 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1657 retry_long
= nla_get_u8(
1658 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1659 if (retry_long
== 0) {
1663 changed
|= WIPHY_PARAM_RETRY_LONG
;
1666 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1667 frag_threshold
= nla_get_u32(
1668 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1669 if (frag_threshold
< 256) {
1673 if (frag_threshold
!= (u32
) -1) {
1675 * Fragments (apart from the last one) are required to
1676 * have even length. Make the fragmentation code
1677 * simpler by stripping LSB should someone try to use
1678 * odd threshold value.
1680 frag_threshold
&= ~0x1;
1682 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1685 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1686 rts_threshold
= nla_get_u32(
1687 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1688 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1691 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1692 coverage_class
= nla_get_u8(
1693 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1694 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1698 u8 old_retry_short
, old_retry_long
;
1699 u32 old_frag_threshold
, old_rts_threshold
;
1700 u8 old_coverage_class
;
1702 if (!rdev
->ops
->set_wiphy_params
) {
1703 result
= -EOPNOTSUPP
;
1707 old_retry_short
= rdev
->wiphy
.retry_short
;
1708 old_retry_long
= rdev
->wiphy
.retry_long
;
1709 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1710 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1711 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1713 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1714 rdev
->wiphy
.retry_short
= retry_short
;
1715 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1716 rdev
->wiphy
.retry_long
= retry_long
;
1717 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1718 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1719 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1720 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1721 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1722 rdev
->wiphy
.coverage_class
= coverage_class
;
1724 result
= rdev_set_wiphy_params(rdev
, changed
);
1726 rdev
->wiphy
.retry_short
= old_retry_short
;
1727 rdev
->wiphy
.retry_long
= old_retry_long
;
1728 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1729 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1730 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1735 mutex_unlock(&rdev
->mtx
);
1741 static inline u64
wdev_id(struct wireless_dev
*wdev
)
1743 return (u64
)wdev
->identifier
|
1744 ((u64
)wiphy_to_dev(wdev
->wiphy
)->wiphy_idx
<< 32);
1747 static int nl80211_send_iface(struct sk_buff
*msg
, u32 portid
, u32 seq
, int flags
,
1748 struct cfg80211_registered_device
*rdev
,
1749 struct wireless_dev
*wdev
)
1751 struct net_device
*dev
= wdev
->netdev
;
1754 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1759 (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
1760 nla_put_string(msg
, NL80211_ATTR_IFNAME
, dev
->name
)))
1761 goto nla_put_failure
;
1763 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
1764 nla_put_u32(msg
, NL80211_ATTR_IFTYPE
, wdev
->iftype
) ||
1765 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
1766 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, wdev_address(wdev
)) ||
1767 nla_put_u32(msg
, NL80211_ATTR_GENERATION
,
1768 rdev
->devlist_generation
^
1769 (cfg80211_rdev_list_generation
<< 2)))
1770 goto nla_put_failure
;
1772 if (rdev
->ops
->get_channel
) {
1773 struct ieee80211_channel
*chan
;
1774 enum nl80211_channel_type channel_type
;
1776 chan
= rdev_get_channel(rdev
, wdev
, &channel_type
);
1778 (nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
,
1779 chan
->center_freq
) ||
1780 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
1782 goto nla_put_failure
;
1785 return genlmsg_end(msg
, hdr
);
1788 genlmsg_cancel(msg
, hdr
);
1792 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1796 int wp_start
= cb
->args
[0];
1797 int if_start
= cb
->args
[1];
1798 struct cfg80211_registered_device
*rdev
;
1799 struct wireless_dev
*wdev
;
1801 mutex_lock(&cfg80211_mutex
);
1802 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1803 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1805 if (wp_idx
< wp_start
) {
1811 mutex_lock(&rdev
->devlist_mtx
);
1812 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
1813 if (if_idx
< if_start
) {
1817 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).portid
,
1818 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1820 mutex_unlock(&rdev
->devlist_mtx
);
1825 mutex_unlock(&rdev
->devlist_mtx
);
1830 mutex_unlock(&cfg80211_mutex
);
1832 cb
->args
[0] = wp_idx
;
1833 cb
->args
[1] = if_idx
;
1838 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1840 struct sk_buff
*msg
;
1841 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1842 struct wireless_dev
*wdev
= info
->user_ptr
[1];
1844 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1848 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
1854 return genlmsg_reply(msg
, info
);
1857 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1858 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1859 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1860 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1861 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1862 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1865 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1867 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1875 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1876 nla
, mntr_flags_policy
))
1879 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1881 *mntrflags
|= (1<<flag
);
1886 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1887 struct net_device
*netdev
, u8 use_4addr
,
1888 enum nl80211_iftype iftype
)
1891 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1897 case NL80211_IFTYPE_AP_VLAN
:
1898 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1901 case NL80211_IFTYPE_STATION
:
1902 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1912 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1914 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1915 struct vif_params params
;
1917 enum nl80211_iftype otype
, ntype
;
1918 struct net_device
*dev
= info
->user_ptr
[1];
1919 u32 _flags
, *flags
= NULL
;
1920 bool change
= false;
1922 memset(¶ms
, 0, sizeof(params
));
1924 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1926 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1927 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1930 if (ntype
> NL80211_IFTYPE_MAX
)
1934 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1935 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1937 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1939 if (netif_running(dev
))
1943 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1944 IEEE80211_MAX_MESH_ID_LEN
);
1945 wdev
->mesh_id_up_len
=
1946 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1947 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1948 wdev
->mesh_id_up_len
);
1952 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1953 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1955 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1959 params
.use_4addr
= -1;
1962 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1963 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1965 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1975 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1979 if (!err
&& params
.use_4addr
!= -1)
1980 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1985 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1987 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1988 struct vif_params params
;
1989 struct wireless_dev
*wdev
;
1990 struct sk_buff
*msg
;
1992 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1995 memset(¶ms
, 0, sizeof(params
));
1997 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
2000 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
2001 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
2002 if (type
> NL80211_IFTYPE_MAX
)
2006 if (!rdev
->ops
->add_virtual_intf
||
2007 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
2010 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
2011 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
2012 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
2017 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2021 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
2022 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
2024 wdev
= rdev_add_virtual_intf(rdev
,
2025 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
2026 type
, err
? NULL
: &flags
, ¶ms
);
2029 return PTR_ERR(wdev
);
2033 case NL80211_IFTYPE_MESH_POINT
:
2034 if (!info
->attrs
[NL80211_ATTR_MESH_ID
])
2037 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
2038 IEEE80211_MAX_MESH_ID_LEN
);
2039 wdev
->mesh_id_up_len
=
2040 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
2041 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
2042 wdev
->mesh_id_up_len
);
2045 case NL80211_IFTYPE_P2P_DEVICE
:
2047 * P2P Device doesn't have a netdev, so doesn't go
2048 * through the netdev notifier and must be added here
2050 mutex_init(&wdev
->mtx
);
2051 INIT_LIST_HEAD(&wdev
->event_list
);
2052 spin_lock_init(&wdev
->event_lock
);
2053 INIT_LIST_HEAD(&wdev
->mgmt_registrations
);
2054 spin_lock_init(&wdev
->mgmt_registrations_lock
);
2056 mutex_lock(&rdev
->devlist_mtx
);
2057 wdev
->identifier
= ++rdev
->wdev_id
;
2058 list_add_rcu(&wdev
->list
, &rdev
->wdev_list
);
2059 rdev
->devlist_generation
++;
2060 mutex_unlock(&rdev
->devlist_mtx
);
2066 if (nl80211_send_iface(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2072 return genlmsg_reply(msg
, info
);
2075 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
2077 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2078 struct wireless_dev
*wdev
= info
->user_ptr
[1];
2080 if (!rdev
->ops
->del_virtual_intf
)
2084 * If we remove a wireless device without a netdev then clear
2085 * user_ptr[1] so that nl80211_post_doit won't dereference it
2086 * to check if it needs to do dev_put(). Otherwise it crashes
2087 * since the wdev has been freed, unlike with a netdev where
2088 * we need the dev_put() for the netdev to really be freed.
2091 info
->user_ptr
[1] = NULL
;
2093 return rdev_del_virtual_intf(rdev
, wdev
);
2096 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
2098 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2099 struct net_device
*dev
= info
->user_ptr
[1];
2102 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
2105 if (!rdev
->ops
->set_noack_map
)
2108 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
2110 return rdev_set_noack_map(rdev
, dev
, noack_map
);
2113 struct get_key_cookie
{
2114 struct sk_buff
*msg
;
2119 static void get_key_callback(void *c
, struct key_params
*params
)
2122 struct get_key_cookie
*cookie
= c
;
2125 nla_put(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
2126 params
->key_len
, params
->key
)) ||
2128 nla_put(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
2129 params
->seq_len
, params
->seq
)) ||
2131 nla_put_u32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
2133 goto nla_put_failure
;
2135 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
2137 goto nla_put_failure
;
2140 nla_put(cookie
->msg
, NL80211_KEY_DATA
,
2141 params
->key_len
, params
->key
)) ||
2143 nla_put(cookie
->msg
, NL80211_KEY_SEQ
,
2144 params
->seq_len
, params
->seq
)) ||
2146 nla_put_u32(cookie
->msg
, NL80211_KEY_CIPHER
,
2148 goto nla_put_failure
;
2150 if (nla_put_u8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
))
2151 goto nla_put_failure
;
2153 nla_nest_end(cookie
->msg
, key
);
2160 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
2162 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2164 struct net_device
*dev
= info
->user_ptr
[1];
2166 const u8
*mac_addr
= NULL
;
2168 struct get_key_cookie cookie
= {
2172 struct sk_buff
*msg
;
2174 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
2175 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
2180 if (info
->attrs
[NL80211_ATTR_MAC
])
2181 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2183 pairwise
= !!mac_addr
;
2184 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
2185 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
2186 if (kt
>= NUM_NL80211_KEYTYPES
)
2188 if (kt
!= NL80211_KEYTYPE_GROUP
&&
2189 kt
!= NL80211_KEYTYPE_PAIRWISE
)
2191 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
2194 if (!rdev
->ops
->get_key
)
2197 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2201 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
2202 NL80211_CMD_NEW_KEY
);
2204 return PTR_ERR(hdr
);
2207 cookie
.idx
= key_idx
;
2209 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2210 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
))
2211 goto nla_put_failure
;
2213 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
2214 goto nla_put_failure
;
2216 if (pairwise
&& mac_addr
&&
2217 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2220 err
= rdev_get_key(rdev
, dev
, key_idx
, pairwise
, mac_addr
, &cookie
,
2227 goto nla_put_failure
;
2229 genlmsg_end(msg
, hdr
);
2230 return genlmsg_reply(msg
, info
);
2239 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
2241 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2242 struct key_parse key
;
2244 struct net_device
*dev
= info
->user_ptr
[1];
2246 err
= nl80211_parse_key(info
, &key
);
2253 /* only support setting default key */
2254 if (!key
.def
&& !key
.defmgmt
)
2257 wdev_lock(dev
->ieee80211_ptr
);
2260 if (!rdev
->ops
->set_default_key
) {
2265 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2269 err
= rdev_set_default_key(rdev
, dev
, key
.idx
,
2270 key
.def_uni
, key
.def_multi
);
2275 #ifdef CONFIG_CFG80211_WEXT
2276 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
2279 if (key
.def_uni
|| !key
.def_multi
) {
2284 if (!rdev
->ops
->set_default_mgmt_key
) {
2289 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2293 err
= rdev_set_default_mgmt_key(rdev
, dev
, key
.idx
);
2297 #ifdef CONFIG_CFG80211_WEXT
2298 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
2303 wdev_unlock(dev
->ieee80211_ptr
);
2308 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
2310 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2312 struct net_device
*dev
= info
->user_ptr
[1];
2313 struct key_parse key
;
2314 const u8
*mac_addr
= NULL
;
2316 err
= nl80211_parse_key(info
, &key
);
2323 if (info
->attrs
[NL80211_ATTR_MAC
])
2324 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2326 if (key
.type
== -1) {
2328 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2330 key
.type
= NL80211_KEYTYPE_GROUP
;
2334 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2335 key
.type
!= NL80211_KEYTYPE_GROUP
)
2338 if (!rdev
->ops
->add_key
)
2341 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2342 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2346 wdev_lock(dev
->ieee80211_ptr
);
2347 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2349 err
= rdev_add_key(rdev
, dev
, key
.idx
,
2350 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2352 wdev_unlock(dev
->ieee80211_ptr
);
2357 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2359 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2361 struct net_device
*dev
= info
->user_ptr
[1];
2362 u8
*mac_addr
= NULL
;
2363 struct key_parse key
;
2365 err
= nl80211_parse_key(info
, &key
);
2369 if (info
->attrs
[NL80211_ATTR_MAC
])
2370 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2372 if (key
.type
== -1) {
2374 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2376 key
.type
= NL80211_KEYTYPE_GROUP
;
2380 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2381 key
.type
!= NL80211_KEYTYPE_GROUP
)
2384 if (!rdev
->ops
->del_key
)
2387 wdev_lock(dev
->ieee80211_ptr
);
2388 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2390 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2391 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2395 err
= rdev_del_key(rdev
, dev
, key
.idx
,
2396 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2399 #ifdef CONFIG_CFG80211_WEXT
2401 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2402 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2403 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2404 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2407 wdev_unlock(dev
->ieee80211_ptr
);
2412 static int nl80211_parse_beacon(struct genl_info
*info
,
2413 struct cfg80211_beacon_data
*bcn
)
2415 bool haveinfo
= false;
2417 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2418 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2419 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2420 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2423 memset(bcn
, 0, sizeof(*bcn
));
2425 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2426 bcn
->head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2427 bcn
->head_len
= nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2433 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2434 bcn
->tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2436 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2443 if (info
->attrs
[NL80211_ATTR_IE
]) {
2444 bcn
->beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2445 bcn
->beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2448 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2449 bcn
->proberesp_ies
=
2450 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2451 bcn
->proberesp_ies_len
=
2452 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2455 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2456 bcn
->assocresp_ies
=
2457 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2458 bcn
->assocresp_ies_len
=
2459 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2462 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2464 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2465 bcn
->probe_resp_len
=
2466 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2472 static bool nl80211_get_ap_channel(struct cfg80211_registered_device
*rdev
,
2473 struct cfg80211_ap_settings
*params
)
2475 struct wireless_dev
*wdev
;
2478 mutex_lock(&rdev
->devlist_mtx
);
2480 list_for_each_entry(wdev
, &rdev
->wdev_list
, list
) {
2481 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
2482 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2485 if (!wdev
->preset_chan
)
2488 params
->channel
= wdev
->preset_chan
;
2489 params
->channel_type
= wdev
->preset_chantype
;
2494 mutex_unlock(&rdev
->devlist_mtx
);
2499 static bool nl80211_valid_auth_type(struct cfg80211_registered_device
*rdev
,
2500 enum nl80211_auth_type auth_type
,
2501 enum nl80211_commands cmd
)
2503 if (auth_type
> NL80211_AUTHTYPE_MAX
)
2507 case NL80211_CMD_AUTHENTICATE
:
2508 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_SAE
) &&
2509 auth_type
== NL80211_AUTHTYPE_SAE
)
2512 case NL80211_CMD_CONNECT
:
2513 case NL80211_CMD_START_AP
:
2514 /* SAE not supported yet */
2515 if (auth_type
== NL80211_AUTHTYPE_SAE
)
2523 static int nl80211_start_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2525 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2526 struct net_device
*dev
= info
->user_ptr
[1];
2527 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2528 struct cfg80211_ap_settings params
;
2531 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2532 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2535 if (!rdev
->ops
->start_ap
)
2538 if (wdev
->beacon_interval
)
2541 memset(¶ms
, 0, sizeof(params
));
2543 /* these are required for START_AP */
2544 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2545 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2546 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2549 err
= nl80211_parse_beacon(info
, ¶ms
.beacon
);
2553 params
.beacon_interval
=
2554 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2555 params
.dtim_period
=
2556 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2558 err
= cfg80211_validate_beacon_int(rdev
, params
.beacon_interval
);
2563 * In theory, some of these attributes should be required here
2564 * but since they were not used when the command was originally
2565 * added, keep them optional for old user space programs to let
2566 * them continue to work with drivers that do not need the
2567 * additional information -- drivers must check!
2569 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2570 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2572 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2573 if (params
.ssid_len
== 0 ||
2574 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2578 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2579 params
.hidden_ssid
= nla_get_u32(
2580 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2581 if (params
.hidden_ssid
!= NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2582 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_LEN
&&
2583 params
.hidden_ssid
!= NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2587 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2589 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2590 params
.auth_type
= nla_get_u32(
2591 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2592 if (!nl80211_valid_auth_type(rdev
, params
.auth_type
,
2593 NL80211_CMD_START_AP
))
2596 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2598 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2599 NL80211_MAX_NR_CIPHER_SUITES
);
2603 if (info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]) {
2604 if (!(rdev
->wiphy
.features
& NL80211_FEATURE_INACTIVITY_TIMER
))
2606 params
.inactivity_timeout
= nla_get_u16(
2607 info
->attrs
[NL80211_ATTR_INACTIVITY_TIMEOUT
]);
2610 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2611 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
2613 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
2614 !nl80211_valid_channel_type(info
, &channel_type
))
2617 params
.channel
= rdev_freq_to_chan(rdev
,
2618 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
2620 if (!params
.channel
)
2622 params
.channel_type
= channel_type
;
2623 } else if (wdev
->preset_chan
) {
2624 params
.channel
= wdev
->preset_chan
;
2625 params
.channel_type
= wdev
->preset_chantype
;
2626 } else if (!nl80211_get_ap_channel(rdev
, ¶ms
))
2629 if (!cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, params
.channel
,
2630 params
.channel_type
))
2633 mutex_lock(&rdev
->devlist_mtx
);
2634 err
= cfg80211_can_use_chan(rdev
, wdev
, params
.channel
,
2636 mutex_unlock(&rdev
->devlist_mtx
);
2641 err
= rdev_start_ap(rdev
, dev
, ¶ms
);
2643 wdev
->preset_chan
= params
.channel
;
2644 wdev
->preset_chantype
= params
.channel_type
;
2645 wdev
->beacon_interval
= params
.beacon_interval
;
2646 wdev
->channel
= params
.channel
;
2651 static int nl80211_set_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2653 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2654 struct net_device
*dev
= info
->user_ptr
[1];
2655 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2656 struct cfg80211_beacon_data params
;
2659 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2660 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2663 if (!rdev
->ops
->change_beacon
)
2666 if (!wdev
->beacon_interval
)
2669 err
= nl80211_parse_beacon(info
, ¶ms
);
2673 return rdev_change_beacon(rdev
, dev
, ¶ms
);
2676 static int nl80211_stop_ap(struct sk_buff
*skb
, struct genl_info
*info
)
2678 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2679 struct net_device
*dev
= info
->user_ptr
[1];
2681 return cfg80211_stop_ap(rdev
, dev
);
2684 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2685 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2686 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2687 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2688 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2689 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2690 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2693 static int parse_station_flags(struct genl_info
*info
,
2694 enum nl80211_iftype iftype
,
2695 struct station_parameters
*params
)
2697 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2702 * Try parsing the new attribute first so userspace
2703 * can specify both for older kernels.
2705 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2707 struct nl80211_sta_flag_update
*sta_flags
;
2709 sta_flags
= nla_data(nla
);
2710 params
->sta_flags_mask
= sta_flags
->mask
;
2711 params
->sta_flags_set
= sta_flags
->set
;
2712 if ((params
->sta_flags_mask
|
2713 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2718 /* if present, parse the old attribute */
2720 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2724 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2725 nla
, sta_flags_policy
))
2729 * Only allow certain flags for interface types so that
2730 * other attributes are silently ignored. Remember that
2731 * this is backward compatibility code with old userspace
2732 * and shouldn't be hit in other cases anyway.
2735 case NL80211_IFTYPE_AP
:
2736 case NL80211_IFTYPE_AP_VLAN
:
2737 case NL80211_IFTYPE_P2P_GO
:
2738 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2739 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2740 BIT(NL80211_STA_FLAG_WME
) |
2741 BIT(NL80211_STA_FLAG_MFP
);
2743 case NL80211_IFTYPE_P2P_CLIENT
:
2744 case NL80211_IFTYPE_STATION
:
2745 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2746 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2748 case NL80211_IFTYPE_MESH_POINT
:
2749 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2750 BIT(NL80211_STA_FLAG_MFP
) |
2751 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2756 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++) {
2758 params
->sta_flags_set
|= (1<<flag
);
2760 /* no longer support new API additions in old API */
2761 if (flag
> NL80211_STA_FLAG_MAX_OLD_API
)
2769 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2772 struct nlattr
*rate
;
2776 rate
= nla_nest_start(msg
, attr
);
2778 goto nla_put_failure
;
2780 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2781 bitrate
= cfg80211_calculate_bitrate(info
);
2782 /* report 16-bit bitrate only if we can */
2783 bitrate_compat
= bitrate
< (1UL << 16) ? bitrate
: 0;
2785 nla_put_u32(msg
, NL80211_RATE_INFO_BITRATE32
, bitrate
)) ||
2786 (bitrate_compat
> 0 &&
2787 nla_put_u16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate_compat
)) ||
2788 ((info
->flags
& RATE_INFO_FLAGS_MCS
) &&
2789 nla_put_u8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
)) ||
2790 ((info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) &&
2791 nla_put_flag(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
)) ||
2792 ((info
->flags
& RATE_INFO_FLAGS_SHORT_GI
) &&
2793 nla_put_flag(msg
, NL80211_RATE_INFO_SHORT_GI
)))
2794 goto nla_put_failure
;
2796 nla_nest_end(msg
, rate
);
2803 static int nl80211_send_station(struct sk_buff
*msg
, u32 portid
, u32 seq
,
2805 struct cfg80211_registered_device
*rdev
,
2806 struct net_device
*dev
,
2807 const u8
*mac_addr
, struct station_info
*sinfo
)
2810 struct nlattr
*sinfoattr
, *bss_param
;
2812 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2816 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
2817 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
2818 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
))
2819 goto nla_put_failure
;
2821 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2823 goto nla_put_failure
;
2824 if ((sinfo
->filled
& STATION_INFO_CONNECTED_TIME
) &&
2825 nla_put_u32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2826 sinfo
->connected_time
))
2827 goto nla_put_failure
;
2828 if ((sinfo
->filled
& STATION_INFO_INACTIVE_TIME
) &&
2829 nla_put_u32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2830 sinfo
->inactive_time
))
2831 goto nla_put_failure
;
2832 if ((sinfo
->filled
& STATION_INFO_RX_BYTES
) &&
2833 nla_put_u32(msg
, NL80211_STA_INFO_RX_BYTES
,
2835 goto nla_put_failure
;
2836 if ((sinfo
->filled
& STATION_INFO_TX_BYTES
) &&
2837 nla_put_u32(msg
, NL80211_STA_INFO_TX_BYTES
,
2839 goto nla_put_failure
;
2840 if ((sinfo
->filled
& STATION_INFO_LLID
) &&
2841 nla_put_u16(msg
, NL80211_STA_INFO_LLID
, sinfo
->llid
))
2842 goto nla_put_failure
;
2843 if ((sinfo
->filled
& STATION_INFO_PLID
) &&
2844 nla_put_u16(msg
, NL80211_STA_INFO_PLID
, sinfo
->plid
))
2845 goto nla_put_failure
;
2846 if ((sinfo
->filled
& STATION_INFO_PLINK_STATE
) &&
2847 nla_put_u8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2848 sinfo
->plink_state
))
2849 goto nla_put_failure
;
2850 switch (rdev
->wiphy
.signal_type
) {
2851 case CFG80211_SIGNAL_TYPE_MBM
:
2852 if ((sinfo
->filled
& STATION_INFO_SIGNAL
) &&
2853 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL
,
2855 goto nla_put_failure
;
2856 if ((sinfo
->filled
& STATION_INFO_SIGNAL_AVG
) &&
2857 nla_put_u8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2859 goto nla_put_failure
;
2864 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2865 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2866 NL80211_STA_INFO_TX_BITRATE
))
2867 goto nla_put_failure
;
2869 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2870 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2871 NL80211_STA_INFO_RX_BITRATE
))
2872 goto nla_put_failure
;
2874 if ((sinfo
->filled
& STATION_INFO_RX_PACKETS
) &&
2875 nla_put_u32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2877 goto nla_put_failure
;
2878 if ((sinfo
->filled
& STATION_INFO_TX_PACKETS
) &&
2879 nla_put_u32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2881 goto nla_put_failure
;
2882 if ((sinfo
->filled
& STATION_INFO_TX_RETRIES
) &&
2883 nla_put_u32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2885 goto nla_put_failure
;
2886 if ((sinfo
->filled
& STATION_INFO_TX_FAILED
) &&
2887 nla_put_u32(msg
, NL80211_STA_INFO_TX_FAILED
,
2889 goto nla_put_failure
;
2890 if ((sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
) &&
2891 nla_put_u32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2892 sinfo
->beacon_loss_count
))
2893 goto nla_put_failure
;
2894 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2895 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2897 goto nla_put_failure
;
2899 if (((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
) &&
2900 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
)) ||
2901 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
) &&
2902 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
)) ||
2903 ((sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
) &&
2904 nla_put_flag(msg
, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
)) ||
2905 nla_put_u8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2906 sinfo
->bss_param
.dtim_period
) ||
2907 nla_put_u16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2908 sinfo
->bss_param
.beacon_interval
))
2909 goto nla_put_failure
;
2911 nla_nest_end(msg
, bss_param
);
2913 if ((sinfo
->filled
& STATION_INFO_STA_FLAGS
) &&
2914 nla_put(msg
, NL80211_STA_INFO_STA_FLAGS
,
2915 sizeof(struct nl80211_sta_flag_update
),
2917 goto nla_put_failure
;
2918 if ((sinfo
->filled
& STATION_INFO_T_OFFSET
) &&
2919 nla_put_u64(msg
, NL80211_STA_INFO_T_OFFSET
,
2921 goto nla_put_failure
;
2922 nla_nest_end(msg
, sinfoattr
);
2924 if ((sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
) &&
2925 nla_put(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2926 sinfo
->assoc_req_ies
))
2927 goto nla_put_failure
;
2929 return genlmsg_end(msg
, hdr
);
2932 genlmsg_cancel(msg
, hdr
);
2936 static int nl80211_dump_station(struct sk_buff
*skb
,
2937 struct netlink_callback
*cb
)
2939 struct station_info sinfo
;
2940 struct cfg80211_registered_device
*dev
;
2941 struct net_device
*netdev
;
2942 u8 mac_addr
[ETH_ALEN
];
2943 int sta_idx
= cb
->args
[1];
2946 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2950 if (!dev
->ops
->dump_station
) {
2956 memset(&sinfo
, 0, sizeof(sinfo
));
2957 err
= rdev_dump_station(dev
, netdev
, sta_idx
,
2964 if (nl80211_send_station(skb
,
2965 NETLINK_CB(cb
->skb
).portid
,
2966 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2967 dev
, netdev
, mac_addr
,
2976 cb
->args
[1] = sta_idx
;
2979 nl80211_finish_netdev_dump(dev
);
2984 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2986 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2987 struct net_device
*dev
= info
->user_ptr
[1];
2988 struct station_info sinfo
;
2989 struct sk_buff
*msg
;
2990 u8
*mac_addr
= NULL
;
2993 memset(&sinfo
, 0, sizeof(sinfo
));
2995 if (!info
->attrs
[NL80211_ATTR_MAC
])
2998 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3000 if (!rdev
->ops
->get_station
)
3003 err
= rdev_get_station(rdev
, dev
, mac_addr
, &sinfo
);
3007 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3011 if (nl80211_send_station(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3012 rdev
, dev
, mac_addr
, &sinfo
) < 0) {
3017 return genlmsg_reply(msg
, info
);
3021 * Get vlan interface making sure it is running and on the right wiphy.
3023 static struct net_device
*get_vlan(struct genl_info
*info
,
3024 struct cfg80211_registered_device
*rdev
)
3026 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
3027 struct net_device
*v
;
3033 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
3035 return ERR_PTR(-ENODEV
);
3037 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
3042 if (!netif_running(v
)) {
3050 return ERR_PTR(ret
);
3053 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
3055 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3057 struct net_device
*dev
= info
->user_ptr
[1];
3058 struct station_parameters params
;
3059 u8
*mac_addr
= NULL
;
3061 memset(¶ms
, 0, sizeof(params
));
3063 params
.listen_interval
= -1;
3064 params
.plink_state
= -1;
3066 if (info
->attrs
[NL80211_ATTR_STA_AID
])
3069 if (!info
->attrs
[NL80211_ATTR_MAC
])
3072 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3074 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
3075 params
.supported_rates
=
3076 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3077 params
.supported_rates_len
=
3078 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3081 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3082 params
.listen_interval
=
3083 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3085 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3087 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3089 if (!rdev
->ops
->change_station
)
3092 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3095 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3096 params
.plink_action
=
3097 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3099 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
3100 params
.plink_state
=
3101 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
3103 switch (dev
->ieee80211_ptr
->iftype
) {
3104 case NL80211_IFTYPE_AP
:
3105 case NL80211_IFTYPE_AP_VLAN
:
3106 case NL80211_IFTYPE_P2P_GO
:
3107 /* disallow mesh-specific things */
3108 if (params
.plink_action
)
3111 /* TDLS can't be set, ... */
3112 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3115 * ... but don't bother the driver with it. This works around
3116 * a hostapd/wpa_supplicant issue -- it always includes the
3117 * TLDS_PEER flag in the mask even for AP mode.
3119 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3121 /* accept only the listed bits */
3122 if (params
.sta_flags_mask
&
3123 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
3124 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
3125 BIT(NL80211_STA_FLAG_WME
) |
3126 BIT(NL80211_STA_FLAG_MFP
)))
3129 /* must be last in here for error handling */
3130 params
.vlan
= get_vlan(info
, rdev
);
3131 if (IS_ERR(params
.vlan
))
3132 return PTR_ERR(params
.vlan
);
3134 case NL80211_IFTYPE_P2P_CLIENT
:
3135 case NL80211_IFTYPE_STATION
:
3137 * Don't allow userspace to change the TDLS_PEER flag,
3138 * but silently ignore attempts to change it since we
3139 * don't have state here to verify that it doesn't try
3140 * to change the flag.
3142 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3144 case NL80211_IFTYPE_ADHOC
:
3145 /* disallow things sta doesn't support */
3146 if (params
.plink_action
)
3150 if (params
.listen_interval
>= 0)
3152 /* reject any changes other than AUTHORIZED */
3153 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
3156 case NL80211_IFTYPE_MESH_POINT
:
3157 /* disallow things mesh doesn't support */
3162 if (params
.listen_interval
>= 0)
3165 * No special handling for TDLS here -- the userspace
3166 * mesh code doesn't have this bug.
3168 if (params
.sta_flags_mask
&
3169 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
3170 BIT(NL80211_STA_FLAG_MFP
) |
3171 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
3178 /* be aware of params.vlan when changing code here */
3180 err
= rdev_change_station(rdev
, dev
, mac_addr
, ¶ms
);
3183 dev_put(params
.vlan
);
3188 static struct nla_policy
3189 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
3190 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
3191 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
3194 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
3196 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3198 struct net_device
*dev
= info
->user_ptr
[1];
3199 struct station_parameters params
;
3200 u8
*mac_addr
= NULL
;
3202 memset(¶ms
, 0, sizeof(params
));
3204 if (!info
->attrs
[NL80211_ATTR_MAC
])
3207 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
3210 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
3213 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
3216 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3217 params
.supported_rates
=
3218 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3219 params
.supported_rates_len
=
3220 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
3221 params
.listen_interval
=
3222 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
3224 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
3225 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
3228 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
3230 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
3232 if (info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
])
3234 nla_data(info
->attrs
[NL80211_ATTR_VHT_CAPABILITY
]);
3236 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
3237 params
.plink_action
=
3238 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
3240 if (!rdev
->ops
->add_station
)
3243 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
3246 switch (dev
->ieee80211_ptr
->iftype
) {
3247 case NL80211_IFTYPE_AP
:
3248 case NL80211_IFTYPE_AP_VLAN
:
3249 case NL80211_IFTYPE_P2P_GO
:
3250 /* parse WME attributes if sta is WME capable */
3251 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
3252 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
3253 info
->attrs
[NL80211_ATTR_STA_WME
]) {
3254 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
3257 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
3258 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
3259 nl80211_sta_wme_policy
);
3263 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
3264 params
.uapsd_queues
=
3265 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
3266 if (params
.uapsd_queues
&
3267 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
3270 if (tb
[NL80211_STA_WME_MAX_SP
])
3272 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
3275 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
3278 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
3280 /* TDLS peers cannot be added */
3281 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3283 /* but don't bother the driver with it */
3284 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
3286 /* must be last in here for error handling */
3287 params
.vlan
= get_vlan(info
, rdev
);
3288 if (IS_ERR(params
.vlan
))
3289 return PTR_ERR(params
.vlan
);
3291 case NL80211_IFTYPE_MESH_POINT
:
3292 /* TDLS peers cannot be added */
3293 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
3296 case NL80211_IFTYPE_STATION
:
3297 /* Only TDLS peers can be added */
3298 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
3300 /* Can only add if TDLS ... */
3301 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
3303 /* ... with external setup is supported */
3304 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
3311 /* be aware of params.vlan when changing code here */
3313 err
= rdev_add_station(rdev
, dev
, mac_addr
, ¶ms
);
3316 dev_put(params
.vlan
);
3320 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
3322 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3323 struct net_device
*dev
= info
->user_ptr
[1];
3324 u8
*mac_addr
= NULL
;
3326 if (info
->attrs
[NL80211_ATTR_MAC
])
3327 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3329 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3330 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
3331 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
3332 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3335 if (!rdev
->ops
->del_station
)
3338 return rdev_del_station(rdev
, dev
, mac_addr
);
3341 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 portid
, u32 seq
,
3342 int flags
, struct net_device
*dev
,
3343 u8
*dst
, u8
*next_hop
,
3344 struct mpath_info
*pinfo
)
3347 struct nlattr
*pinfoattr
;
3349 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
3353 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3354 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
) ||
3355 nla_put(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
) ||
3356 nla_put_u32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
))
3357 goto nla_put_failure
;
3359 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
3361 goto nla_put_failure
;
3362 if ((pinfo
->filled
& MPATH_INFO_FRAME_QLEN
) &&
3363 nla_put_u32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
3365 goto nla_put_failure
;
3366 if (((pinfo
->filled
& MPATH_INFO_SN
) &&
3367 nla_put_u32(msg
, NL80211_MPATH_INFO_SN
, pinfo
->sn
)) ||
3368 ((pinfo
->filled
& MPATH_INFO_METRIC
) &&
3369 nla_put_u32(msg
, NL80211_MPATH_INFO_METRIC
,
3371 ((pinfo
->filled
& MPATH_INFO_EXPTIME
) &&
3372 nla_put_u32(msg
, NL80211_MPATH_INFO_EXPTIME
,
3374 ((pinfo
->filled
& MPATH_INFO_FLAGS
) &&
3375 nla_put_u8(msg
, NL80211_MPATH_INFO_FLAGS
,
3377 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
) &&
3378 nla_put_u32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
3379 pinfo
->discovery_timeout
)) ||
3380 ((pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
) &&
3381 nla_put_u8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
3382 pinfo
->discovery_retries
)))
3383 goto nla_put_failure
;
3385 nla_nest_end(msg
, pinfoattr
);
3387 return genlmsg_end(msg
, hdr
);
3390 genlmsg_cancel(msg
, hdr
);
3394 static int nl80211_dump_mpath(struct sk_buff
*skb
,
3395 struct netlink_callback
*cb
)
3397 struct mpath_info pinfo
;
3398 struct cfg80211_registered_device
*dev
;
3399 struct net_device
*netdev
;
3401 u8 next_hop
[ETH_ALEN
];
3402 int path_idx
= cb
->args
[1];
3405 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3409 if (!dev
->ops
->dump_mpath
) {
3414 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
3420 err
= rdev_dump_mpath(dev
, netdev
, path_idx
, dst
, next_hop
,
3427 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).portid
,
3428 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3429 netdev
, dst
, next_hop
,
3438 cb
->args
[1] = path_idx
;
3441 nl80211_finish_netdev_dump(dev
);
3445 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3447 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3449 struct net_device
*dev
= info
->user_ptr
[1];
3450 struct mpath_info pinfo
;
3451 struct sk_buff
*msg
;
3453 u8 next_hop
[ETH_ALEN
];
3455 memset(&pinfo
, 0, sizeof(pinfo
));
3457 if (!info
->attrs
[NL80211_ATTR_MAC
])
3460 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3462 if (!rdev
->ops
->get_mpath
)
3465 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3468 err
= rdev_get_mpath(rdev
, dev
, dst
, next_hop
, &pinfo
);
3472 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3476 if (nl80211_send_mpath(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3477 dev
, dst
, next_hop
, &pinfo
) < 0) {
3482 return genlmsg_reply(msg
, info
);
3485 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3487 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3488 struct net_device
*dev
= info
->user_ptr
[1];
3490 u8
*next_hop
= NULL
;
3492 if (!info
->attrs
[NL80211_ATTR_MAC
])
3495 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3498 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3499 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3501 if (!rdev
->ops
->change_mpath
)
3504 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3507 return rdev_change_mpath(rdev
, dev
, dst
, next_hop
);
3510 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3512 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3513 struct net_device
*dev
= info
->user_ptr
[1];
3515 u8
*next_hop
= NULL
;
3517 if (!info
->attrs
[NL80211_ATTR_MAC
])
3520 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3523 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3524 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3526 if (!rdev
->ops
->add_mpath
)
3529 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3532 return rdev_add_mpath(rdev
, dev
, dst
, next_hop
);
3535 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3537 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3538 struct net_device
*dev
= info
->user_ptr
[1];
3541 if (info
->attrs
[NL80211_ATTR_MAC
])
3542 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3544 if (!rdev
->ops
->del_mpath
)
3547 return rdev_del_mpath(rdev
, dev
, dst
);
3550 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3552 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3553 struct net_device
*dev
= info
->user_ptr
[1];
3554 struct bss_parameters params
;
3556 memset(¶ms
, 0, sizeof(params
));
3557 /* default to not changing parameters */
3558 params
.use_cts_prot
= -1;
3559 params
.use_short_preamble
= -1;
3560 params
.use_short_slot_time
= -1;
3561 params
.ap_isolate
= -1;
3562 params
.ht_opmode
= -1;
3564 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3565 params
.use_cts_prot
=
3566 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3567 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3568 params
.use_short_preamble
=
3569 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3570 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3571 params
.use_short_slot_time
=
3572 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3573 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3574 params
.basic_rates
=
3575 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3576 params
.basic_rates_len
=
3577 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3579 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3580 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3581 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3583 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3585 if (!rdev
->ops
->change_bss
)
3588 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3589 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3592 return rdev_change_bss(rdev
, dev
, ¶ms
);
3595 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3596 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3597 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3598 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3599 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3600 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3601 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3604 static int parse_reg_rule(struct nlattr
*tb
[],
3605 struct ieee80211_reg_rule
*reg_rule
)
3607 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3608 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3610 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3612 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3614 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3616 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3618 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3621 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3623 freq_range
->start_freq_khz
=
3624 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3625 freq_range
->end_freq_khz
=
3626 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3627 freq_range
->max_bandwidth_khz
=
3628 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3630 power_rule
->max_eirp
=
3631 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3633 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3634 power_rule
->max_antenna_gain
=
3635 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3640 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3644 enum nl80211_user_reg_hint_type user_reg_hint_type
;
3647 * You should only get this when cfg80211 hasn't yet initialized
3648 * completely when built-in to the kernel right between the time
3649 * window between nl80211_init() and regulatory_init(), if that is
3652 mutex_lock(&cfg80211_mutex
);
3653 if (unlikely(!cfg80211_regdomain
)) {
3654 mutex_unlock(&cfg80211_mutex
);
3655 return -EINPROGRESS
;
3657 mutex_unlock(&cfg80211_mutex
);
3659 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3662 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3664 if (info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
])
3665 user_reg_hint_type
=
3666 nla_get_u32(info
->attrs
[NL80211_ATTR_USER_REG_HINT_TYPE
]);
3668 user_reg_hint_type
= NL80211_USER_REG_HINT_USER
;
3670 switch (user_reg_hint_type
) {
3671 case NL80211_USER_REG_HINT_USER
:
3672 case NL80211_USER_REG_HINT_CELL_BASE
:
3678 r
= regulatory_hint_user(data
, user_reg_hint_type
);
3683 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3684 struct genl_info
*info
)
3686 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3687 struct net_device
*dev
= info
->user_ptr
[1];
3688 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3689 struct mesh_config cur_params
;
3692 struct nlattr
*pinfoattr
;
3693 struct sk_buff
*msg
;
3695 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3698 if (!rdev
->ops
->get_mesh_config
)
3702 /* If not connected, get default parameters */
3703 if (!wdev
->mesh_id_len
)
3704 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3706 err
= rdev_get_mesh_config(rdev
, dev
, &cur_params
);
3712 /* Draw up a netlink message to send back */
3713 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3716 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
3717 NL80211_CMD_GET_MESH_CONFIG
);
3720 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3722 goto nla_put_failure
;
3723 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
3724 nla_put_u16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3725 cur_params
.dot11MeshRetryTimeout
) ||
3726 nla_put_u16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3727 cur_params
.dot11MeshConfirmTimeout
) ||
3728 nla_put_u16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3729 cur_params
.dot11MeshHoldingTimeout
) ||
3730 nla_put_u16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3731 cur_params
.dot11MeshMaxPeerLinks
) ||
3732 nla_put_u8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3733 cur_params
.dot11MeshMaxRetries
) ||
3734 nla_put_u8(msg
, NL80211_MESHCONF_TTL
,
3735 cur_params
.dot11MeshTTL
) ||
3736 nla_put_u8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3737 cur_params
.element_ttl
) ||
3738 nla_put_u8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3739 cur_params
.auto_open_plinks
) ||
3740 nla_put_u32(msg
, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3741 cur_params
.dot11MeshNbrOffsetMaxNeighbor
) ||
3742 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3743 cur_params
.dot11MeshHWMPmaxPREQretries
) ||
3744 nla_put_u32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3745 cur_params
.path_refresh_time
) ||
3746 nla_put_u16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3747 cur_params
.min_discovery_timeout
) ||
3748 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3749 cur_params
.dot11MeshHWMPactivePathTimeout
) ||
3750 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3751 cur_params
.dot11MeshHWMPpreqMinInterval
) ||
3752 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3753 cur_params
.dot11MeshHWMPperrMinInterval
) ||
3754 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3755 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
) ||
3756 nla_put_u8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3757 cur_params
.dot11MeshHWMPRootMode
) ||
3758 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3759 cur_params
.dot11MeshHWMPRannInterval
) ||
3760 nla_put_u8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3761 cur_params
.dot11MeshGateAnnouncementProtocol
) ||
3762 nla_put_u8(msg
, NL80211_MESHCONF_FORWARDING
,
3763 cur_params
.dot11MeshForwarding
) ||
3764 nla_put_u32(msg
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3765 cur_params
.rssi_threshold
) ||
3766 nla_put_u32(msg
, NL80211_MESHCONF_HT_OPMODE
,
3767 cur_params
.ht_opmode
) ||
3768 nla_put_u32(msg
, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3769 cur_params
.dot11MeshHWMPactivePathToRootTimeout
) ||
3770 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3771 cur_params
.dot11MeshHWMProotInterval
) ||
3772 nla_put_u16(msg
, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3773 cur_params
.dot11MeshHWMPconfirmationInterval
))
3774 goto nla_put_failure
;
3775 nla_nest_end(msg
, pinfoattr
);
3776 genlmsg_end(msg
, hdr
);
3777 return genlmsg_reply(msg
, info
);
3780 genlmsg_cancel(msg
, hdr
);
3786 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3787 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3788 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3789 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3790 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3791 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3792 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3793 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3794 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3795 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
] = { .type
= NLA_U32
},
3796 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3797 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3798 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3799 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3800 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3801 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3802 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3803 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3804 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3805 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3806 [NL80211_MESHCONF_FORWARDING
] = { .type
= NLA_U8
},
3807 [NL80211_MESHCONF_RSSI_THRESHOLD
] = { .type
= NLA_U32
},
3808 [NL80211_MESHCONF_HT_OPMODE
] = { .type
= NLA_U16
},
3809 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
] = { .type
= NLA_U32
},
3810 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL
] = { .type
= NLA_U16
},
3811 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
] = { .type
= NLA_U16
},
3814 static const struct nla_policy
3815 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3816 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
] = { .type
= NLA_U8
},
3817 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3818 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3819 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3820 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3821 .len
= IEEE80211_MAX_DATA_LEN
},
3822 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3825 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3826 struct mesh_config
*cfg
,
3829 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3832 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3834 if (table[attr_num]) {\
3835 cfg->param = nla_fn(table[attr_num]); \
3836 mask |= (1 << (attr_num - 1)); \
3841 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3843 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3844 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3845 nl80211_meshconf_params_policy
))
3848 /* This makes sure that there aren't more than 32 mesh config
3849 * parameters (otherwise our bitfield scheme would not work.) */
3850 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3852 /* Fill in the params struct */
3853 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3854 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3856 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3857 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3859 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3860 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3862 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3863 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3865 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3866 mask
, NL80211_MESHCONF_MAX_RETRIES
,
3868 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3869 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3870 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3871 mask
, NL80211_MESHCONF_ELEMENT_TTL
,
3873 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3874 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3876 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshNbrOffsetMaxNeighbor
, mask
,
3877 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR
,
3879 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3880 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3882 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3883 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3885 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3886 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3888 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
, mask
,
3889 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3891 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3892 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3894 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3895 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3897 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3898 dot11MeshHWMPnetDiameterTraversalTime
, mask
,
3899 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3901 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRootMode
, mask
,
3902 NL80211_MESHCONF_HWMP_ROOTMODE
, nla_get_u8
);
3903 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPRannInterval
, mask
,
3904 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3906 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3907 dot11MeshGateAnnouncementProtocol
, mask
,
3908 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3910 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshForwarding
,
3911 mask
, NL80211_MESHCONF_FORWARDING
,
3913 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, rssi_threshold
,
3914 mask
, NL80211_MESHCONF_RSSI_THRESHOLD
,
3916 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, ht_opmode
,
3917 mask
, NL80211_MESHCONF_HT_OPMODE
,
3919 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathToRootTimeout
,
3921 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT
,
3923 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMProotInterval
,
3924 mask
, NL80211_MESHCONF_HWMP_ROOT_INTERVAL
,
3926 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3927 dot11MeshHWMPconfirmationInterval
, mask
,
3928 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL
,
3935 #undef FILL_IN_MESH_PARAM_IF_SET
3938 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3939 struct mesh_setup
*setup
)
3941 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3943 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3945 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3946 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3947 nl80211_mesh_setup_params_policy
))
3950 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])
3951 setup
->sync_method
=
3952 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC
])) ?
3953 IEEE80211_SYNC_METHOD_VENDOR
:
3954 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET
;
3956 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3957 setup
->path_sel_proto
=
3958 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3959 IEEE80211_PATH_PROTOCOL_VENDOR
:
3960 IEEE80211_PATH_PROTOCOL_HWMP
;
3962 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3963 setup
->path_metric
=
3964 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3965 IEEE80211_PATH_METRIC_VENDOR
:
3966 IEEE80211_PATH_METRIC_AIRTIME
;
3969 if (tb
[NL80211_MESH_SETUP_IE
]) {
3970 struct nlattr
*ieattr
=
3971 tb
[NL80211_MESH_SETUP_IE
];
3972 if (!is_valid_ie_attr(ieattr
))
3974 setup
->ie
= nla_data(ieattr
);
3975 setup
->ie_len
= nla_len(ieattr
);
3977 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3978 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3983 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3984 struct genl_info
*info
)
3986 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3987 struct net_device
*dev
= info
->user_ptr
[1];
3988 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3989 struct mesh_config cfg
;
3993 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3996 if (!rdev
->ops
->update_mesh_config
)
3999 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
4004 if (!wdev
->mesh_id_len
)
4008 err
= rdev_update_mesh_config(rdev
, dev
, mask
, &cfg
);
4015 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4017 struct sk_buff
*msg
;
4019 struct nlattr
*nl_reg_rules
;
4023 mutex_lock(&cfg80211_mutex
);
4025 if (!cfg80211_regdomain
)
4028 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4034 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
4035 NL80211_CMD_GET_REG
);
4039 if (nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
4040 cfg80211_regdomain
->alpha2
) ||
4041 (cfg80211_regdomain
->dfs_region
&&
4042 nla_put_u8(msg
, NL80211_ATTR_DFS_REGION
,
4043 cfg80211_regdomain
->dfs_region
)))
4044 goto nla_put_failure
;
4046 if (reg_last_request_cell_base() &&
4047 nla_put_u32(msg
, NL80211_ATTR_USER_REG_HINT_TYPE
,
4048 NL80211_USER_REG_HINT_CELL_BASE
))
4049 goto nla_put_failure
;
4051 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
4053 goto nla_put_failure
;
4055 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
4056 struct nlattr
*nl_reg_rule
;
4057 const struct ieee80211_reg_rule
*reg_rule
;
4058 const struct ieee80211_freq_range
*freq_range
;
4059 const struct ieee80211_power_rule
*power_rule
;
4061 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
4062 freq_range
= ®_rule
->freq_range
;
4063 power_rule
= ®_rule
->power_rule
;
4065 nl_reg_rule
= nla_nest_start(msg
, i
);
4067 goto nla_put_failure
;
4069 if (nla_put_u32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
4071 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
4072 freq_range
->start_freq_khz
) ||
4073 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
4074 freq_range
->end_freq_khz
) ||
4075 nla_put_u32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
4076 freq_range
->max_bandwidth_khz
) ||
4077 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
4078 power_rule
->max_antenna_gain
) ||
4079 nla_put_u32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
4080 power_rule
->max_eirp
))
4081 goto nla_put_failure
;
4083 nla_nest_end(msg
, nl_reg_rule
);
4086 nla_nest_end(msg
, nl_reg_rules
);
4088 genlmsg_end(msg
, hdr
);
4089 err
= genlmsg_reply(msg
, info
);
4093 genlmsg_cancel(msg
, hdr
);
4098 mutex_unlock(&cfg80211_mutex
);
4102 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
4104 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
4105 struct nlattr
*nl_reg_rule
;
4106 char *alpha2
= NULL
;
4107 int rem_reg_rules
= 0, r
= 0;
4108 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
4110 struct ieee80211_regdomain
*rd
= NULL
;
4112 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
4115 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
4118 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
4120 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
4121 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
4123 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4126 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
4130 mutex_lock(&cfg80211_mutex
);
4132 if (!reg_is_valid_request(alpha2
)) {
4137 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
4138 (num_rules
* sizeof(struct ieee80211_reg_rule
));
4140 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
4146 rd
->n_reg_rules
= num_rules
;
4147 rd
->alpha2
[0] = alpha2
[0];
4148 rd
->alpha2
[1] = alpha2
[1];
4151 * Disable DFS master mode if the DFS region was
4152 * not supported or known on this kernel.
4154 if (reg_supported_dfs_region(dfs_region
))
4155 rd
->dfs_region
= dfs_region
;
4157 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
4159 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
4160 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
4162 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
4168 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
4174 BUG_ON(rule_idx
!= num_rules
);
4178 mutex_unlock(&cfg80211_mutex
);
4183 mutex_unlock(&cfg80211_mutex
);
4188 static int validate_scan_freqs(struct nlattr
*freqs
)
4190 struct nlattr
*attr1
, *attr2
;
4191 int n_channels
= 0, tmp1
, tmp2
;
4193 nla_for_each_nested(attr1
, freqs
, tmp1
) {
4196 * Some hardware has a limited channel list for
4197 * scanning, and it is pretty much nonsensical
4198 * to scan for a channel twice, so disallow that
4199 * and don't require drivers to check that the
4200 * channel list they get isn't longer than what
4201 * they can scan, as long as they can scan all
4202 * the channels they registered at once.
4204 nla_for_each_nested(attr2
, freqs
, tmp2
)
4205 if (attr1
!= attr2
&&
4206 nla_get_u32(attr1
) == nla_get_u32(attr2
))
4213 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
4215 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4216 struct wireless_dev
*wdev
= info
->user_ptr
[1];
4217 struct cfg80211_scan_request
*request
;
4218 struct nlattr
*attr
;
4219 struct wiphy
*wiphy
;
4220 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
4223 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4226 wiphy
= &rdev
->wiphy
;
4228 if (!rdev
->ops
->scan
)
4234 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4235 n_channels
= validate_scan_freqs(
4236 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4240 enum ieee80211_band band
;
4243 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4244 if (wiphy
->bands
[band
])
4245 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4248 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4249 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
4252 if (n_ssids
> wiphy
->max_scan_ssids
)
4255 if (info
->attrs
[NL80211_ATTR_IE
])
4256 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4260 if (ie_len
> wiphy
->max_scan_ie_len
)
4263 request
= kzalloc(sizeof(*request
)
4264 + sizeof(*request
->ssids
) * n_ssids
4265 + sizeof(*request
->channels
) * n_channels
4266 + ie_len
, GFP_KERNEL
);
4271 request
->ssids
= (void *)&request
->channels
[n_channels
];
4272 request
->n_ssids
= n_ssids
;
4275 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4277 request
->ie
= (void *)(request
->channels
+ n_channels
);
4281 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4282 /* user specified, bail out if channel not found */
4283 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
4284 struct ieee80211_channel
*chan
;
4286 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4293 /* ignore disabled channels */
4294 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4297 request
->channels
[i
] = chan
;
4301 enum ieee80211_band band
;
4304 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4306 if (!wiphy
->bands
[band
])
4308 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4309 struct ieee80211_channel
*chan
;
4311 chan
= &wiphy
->bands
[band
]->channels
[j
];
4313 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4316 request
->channels
[i
] = chan
;
4327 request
->n_channels
= i
;
4330 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4331 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
4332 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4336 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4337 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
4342 if (info
->attrs
[NL80211_ATTR_IE
]) {
4343 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4344 memcpy((void *)request
->ie
,
4345 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4349 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4350 if (wiphy
->bands
[i
])
4352 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
4354 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
4355 nla_for_each_nested(attr
,
4356 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
4358 enum ieee80211_band band
= nla_type(attr
);
4360 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4364 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
4367 &request
->rates
[band
]);
4373 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
4374 request
->flags
= nla_get_u32(
4375 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
4376 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
4377 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
4378 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
4379 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
4386 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
4388 request
->wdev
= wdev
;
4389 request
->wiphy
= &rdev
->wiphy
;
4390 request
->scan_start
= jiffies
;
4392 rdev
->scan_req
= request
;
4393 err
= rdev_scan(rdev
, request
);
4396 nl80211_send_scan_start(rdev
, wdev
);
4398 dev_hold(wdev
->netdev
);
4401 rdev
->scan_req
= NULL
;
4408 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
4409 struct genl_info
*info
)
4411 struct cfg80211_sched_scan_request
*request
;
4412 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4413 struct net_device
*dev
= info
->user_ptr
[1];
4414 struct nlattr
*attr
;
4415 struct wiphy
*wiphy
;
4416 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
4418 enum ieee80211_band band
;
4420 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
4422 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4423 !rdev
->ops
->sched_scan_start
)
4426 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4429 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
4432 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
4436 wiphy
= &rdev
->wiphy
;
4438 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4439 n_channels
= validate_scan_freqs(
4440 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
4446 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
4447 if (wiphy
->bands
[band
])
4448 n_channels
+= wiphy
->bands
[band
]->n_channels
;
4451 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
4452 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4456 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
4459 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
4460 nla_for_each_nested(attr
,
4461 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4465 if (n_match_sets
> wiphy
->max_match_sets
)
4468 if (info
->attrs
[NL80211_ATTR_IE
])
4469 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4473 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
4476 mutex_lock(&rdev
->sched_scan_mtx
);
4478 if (rdev
->sched_scan_req
) {
4483 request
= kzalloc(sizeof(*request
)
4484 + sizeof(*request
->ssids
) * n_ssids
4485 + sizeof(*request
->match_sets
) * n_match_sets
4486 + sizeof(*request
->channels
) * n_channels
4487 + ie_len
, GFP_KERNEL
);
4494 request
->ssids
= (void *)&request
->channels
[n_channels
];
4495 request
->n_ssids
= n_ssids
;
4498 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
4500 request
->ie
= (void *)(request
->channels
+ n_channels
);
4505 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
4506 else if (request
->ssids
)
4507 request
->match_sets
=
4508 (void *)(request
->ssids
+ n_ssids
);
4510 request
->match_sets
=
4511 (void *)(request
->channels
+ n_channels
);
4513 request
->n_match_sets
= n_match_sets
;
4516 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
4517 /* user specified, bail out if channel not found */
4518 nla_for_each_nested(attr
,
4519 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
4521 struct ieee80211_channel
*chan
;
4523 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
4530 /* ignore disabled channels */
4531 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4534 request
->channels
[i
] = chan
;
4539 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4541 if (!wiphy
->bands
[band
])
4543 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
4544 struct ieee80211_channel
*chan
;
4546 chan
= &wiphy
->bands
[band
]->channels
[j
];
4548 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
4551 request
->channels
[i
] = chan
;
4562 request
->n_channels
= i
;
4565 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
4566 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
4568 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4572 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4573 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4580 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4581 nla_for_each_nested(attr
,
4582 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4584 struct nlattr
*ssid
, *rssi
;
4586 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4587 nla_data(attr
), nla_len(attr
),
4588 nl80211_match_policy
);
4589 ssid
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_SSID
];
4591 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4595 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4596 nla_data(ssid
), nla_len(ssid
));
4597 request
->match_sets
[i
].ssid
.ssid_len
=
4600 rssi
= tb
[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
];
4602 request
->rssi_thold
= nla_get_u32(rssi
);
4604 request
->rssi_thold
=
4605 NL80211_SCAN_RSSI_THOLD_OFF
;
4610 if (info
->attrs
[NL80211_ATTR_IE
]) {
4611 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4612 memcpy((void *)request
->ie
,
4613 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4617 if (info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]) {
4618 request
->flags
= nla_get_u32(
4619 info
->attrs
[NL80211_ATTR_SCAN_FLAGS
]);
4620 if (((request
->flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
) &&
4621 !(wiphy
->features
& NL80211_FEATURE_LOW_PRIORITY_SCAN
)) ||
4622 ((request
->flags
& NL80211_SCAN_FLAG_FLUSH
) &&
4623 !(wiphy
->features
& NL80211_FEATURE_SCAN_FLUSH
))) {
4630 request
->wiphy
= &rdev
->wiphy
;
4631 request
->interval
= interval
;
4632 request
->scan_start
= jiffies
;
4634 err
= rdev_sched_scan_start(rdev
, dev
, request
);
4636 rdev
->sched_scan_req
= request
;
4637 nl80211_send_sched_scan(rdev
, dev
,
4638 NL80211_CMD_START_SCHED_SCAN
);
4645 mutex_unlock(&rdev
->sched_scan_mtx
);
4649 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4650 struct genl_info
*info
)
4652 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4655 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4656 !rdev
->ops
->sched_scan_stop
)
4659 mutex_lock(&rdev
->sched_scan_mtx
);
4660 err
= __cfg80211_stop_sched_scan(rdev
, false);
4661 mutex_unlock(&rdev
->sched_scan_mtx
);
4666 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4668 struct cfg80211_registered_device
*rdev
,
4669 struct wireless_dev
*wdev
,
4670 struct cfg80211_internal_bss
*intbss
)
4672 struct cfg80211_bss
*res
= &intbss
->pub
;
4676 ASSERT_WDEV_LOCK(wdev
);
4678 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).portid
, seq
, flags
,
4679 NL80211_CMD_NEW_SCAN_RESULTS
);
4683 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4685 if (nla_put_u32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
) ||
4686 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
))
4687 goto nla_put_failure
;
4689 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4691 goto nla_put_failure
;
4692 if ((!is_zero_ether_addr(res
->bssid
) &&
4693 nla_put(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
)) ||
4694 (res
->information_elements
&& res
->len_information_elements
&&
4695 nla_put(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4696 res
->len_information_elements
,
4697 res
->information_elements
)) ||
4698 (res
->beacon_ies
&& res
->len_beacon_ies
&&
4699 res
->beacon_ies
!= res
->information_elements
&&
4700 nla_put(msg
, NL80211_BSS_BEACON_IES
,
4701 res
->len_beacon_ies
, res
->beacon_ies
)))
4702 goto nla_put_failure
;
4704 nla_put_u64(msg
, NL80211_BSS_TSF
, res
->tsf
))
4705 goto nla_put_failure
;
4706 if (res
->beacon_interval
&&
4707 nla_put_u16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
))
4708 goto nla_put_failure
;
4709 if (nla_put_u16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
) ||
4710 nla_put_u32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
) ||
4711 nla_put_u32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4712 jiffies_to_msecs(jiffies
- intbss
->ts
)))
4713 goto nla_put_failure
;
4715 switch (rdev
->wiphy
.signal_type
) {
4716 case CFG80211_SIGNAL_TYPE_MBM
:
4717 if (nla_put_u32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
))
4718 goto nla_put_failure
;
4720 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4721 if (nla_put_u8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
))
4722 goto nla_put_failure
;
4728 switch (wdev
->iftype
) {
4729 case NL80211_IFTYPE_P2P_CLIENT
:
4730 case NL80211_IFTYPE_STATION
:
4731 if (intbss
== wdev
->current_bss
&&
4732 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4733 NL80211_BSS_STATUS_ASSOCIATED
))
4734 goto nla_put_failure
;
4736 case NL80211_IFTYPE_ADHOC
:
4737 if (intbss
== wdev
->current_bss
&&
4738 nla_put_u32(msg
, NL80211_BSS_STATUS
,
4739 NL80211_BSS_STATUS_IBSS_JOINED
))
4740 goto nla_put_failure
;
4746 nla_nest_end(msg
, bss
);
4748 return genlmsg_end(msg
, hdr
);
4751 genlmsg_cancel(msg
, hdr
);
4755 static int nl80211_dump_scan(struct sk_buff
*skb
,
4756 struct netlink_callback
*cb
)
4758 struct cfg80211_registered_device
*rdev
;
4759 struct net_device
*dev
;
4760 struct cfg80211_internal_bss
*scan
;
4761 struct wireless_dev
*wdev
;
4762 int start
= cb
->args
[1], idx
= 0;
4765 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4769 wdev
= dev
->ieee80211_ptr
;
4772 spin_lock_bh(&rdev
->bss_lock
);
4773 cfg80211_bss_expire(rdev
);
4775 cb
->seq
= rdev
->bss_generation
;
4777 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4780 if (nl80211_send_bss(skb
, cb
,
4781 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4782 rdev
, wdev
, scan
) < 0) {
4788 spin_unlock_bh(&rdev
->bss_lock
);
4792 nl80211_finish_netdev_dump(rdev
);
4797 static int nl80211_send_survey(struct sk_buff
*msg
, u32 portid
, u32 seq
,
4798 int flags
, struct net_device
*dev
,
4799 struct survey_info
*survey
)
4802 struct nlattr
*infoattr
;
4804 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
,
4805 NL80211_CMD_NEW_SURVEY_RESULTS
);
4809 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
))
4810 goto nla_put_failure
;
4812 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4814 goto nla_put_failure
;
4816 if (nla_put_u32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4817 survey
->channel
->center_freq
))
4818 goto nla_put_failure
;
4820 if ((survey
->filled
& SURVEY_INFO_NOISE_DBM
) &&
4821 nla_put_u8(msg
, NL80211_SURVEY_INFO_NOISE
, survey
->noise
))
4822 goto nla_put_failure
;
4823 if ((survey
->filled
& SURVEY_INFO_IN_USE
) &&
4824 nla_put_flag(msg
, NL80211_SURVEY_INFO_IN_USE
))
4825 goto nla_put_failure
;
4826 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME
) &&
4827 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4828 survey
->channel_time
))
4829 goto nla_put_failure
;
4830 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
) &&
4831 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4832 survey
->channel_time_busy
))
4833 goto nla_put_failure
;
4834 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
) &&
4835 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4836 survey
->channel_time_ext_busy
))
4837 goto nla_put_failure
;
4838 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
) &&
4839 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4840 survey
->channel_time_rx
))
4841 goto nla_put_failure
;
4842 if ((survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
) &&
4843 nla_put_u64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4844 survey
->channel_time_tx
))
4845 goto nla_put_failure
;
4847 nla_nest_end(msg
, infoattr
);
4849 return genlmsg_end(msg
, hdr
);
4852 genlmsg_cancel(msg
, hdr
);
4856 static int nl80211_dump_survey(struct sk_buff
*skb
,
4857 struct netlink_callback
*cb
)
4859 struct survey_info survey
;
4860 struct cfg80211_registered_device
*dev
;
4861 struct net_device
*netdev
;
4862 int survey_idx
= cb
->args
[1];
4865 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4869 if (!dev
->ops
->dump_survey
) {
4875 struct ieee80211_channel
*chan
;
4877 res
= rdev_dump_survey(dev
, netdev
, survey_idx
, &survey
);
4883 /* Survey without a channel doesn't make sense */
4884 if (!survey
.channel
) {
4889 chan
= ieee80211_get_channel(&dev
->wiphy
,
4890 survey
.channel
->center_freq
);
4891 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4896 if (nl80211_send_survey(skb
,
4897 NETLINK_CB(cb
->skb
).portid
,
4898 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4906 cb
->args
[1] = survey_idx
;
4909 nl80211_finish_netdev_dump(dev
);
4913 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4915 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4916 NL80211_WPA_VERSION_2
));
4919 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4921 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4922 struct net_device
*dev
= info
->user_ptr
[1];
4923 struct ieee80211_channel
*chan
;
4924 const u8
*bssid
, *ssid
, *ie
= NULL
, *sae_data
= NULL
;
4925 int err
, ssid_len
, ie_len
= 0, sae_data_len
= 0;
4926 enum nl80211_auth_type auth_type
;
4927 struct key_parse key
;
4928 bool local_state_change
;
4930 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4933 if (!info
->attrs
[NL80211_ATTR_MAC
])
4936 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4939 if (!info
->attrs
[NL80211_ATTR_SSID
])
4942 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4945 err
= nl80211_parse_key(info
, &key
);
4950 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4952 if (!key
.p
.key
|| !key
.p
.key_len
)
4954 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4955 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4956 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4957 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4969 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4970 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4979 if (!rdev
->ops
->auth
)
4982 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4983 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4986 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4987 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4988 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4989 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4992 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4993 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4995 if (info
->attrs
[NL80211_ATTR_IE
]) {
4996 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4997 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5000 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5001 if (!nl80211_valid_auth_type(rdev
, auth_type
, NL80211_CMD_AUTHENTICATE
))
5004 if (auth_type
== NL80211_AUTHTYPE_SAE
&&
5005 !info
->attrs
[NL80211_ATTR_SAE_DATA
])
5008 if (info
->attrs
[NL80211_ATTR_SAE_DATA
]) {
5009 if (auth_type
!= NL80211_AUTHTYPE_SAE
)
5011 sae_data
= nla_data(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5012 sae_data_len
= nla_len(info
->attrs
[NL80211_ATTR_SAE_DATA
]);
5013 /* need to include at least Auth Transaction and Status Code */
5014 if (sae_data_len
< 4)
5018 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5021 * Since we no longer track auth state, ignore
5022 * requests to only change local state.
5024 if (local_state_change
)
5027 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
5028 ssid
, ssid_len
, ie
, ie_len
,
5029 key
.p
.key
, key
.p
.key_len
, key
.idx
,
5030 sae_data
, sae_data_len
);
5033 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
5034 struct genl_info
*info
,
5035 struct cfg80211_crypto_settings
*settings
,
5038 memset(settings
, 0, sizeof(*settings
));
5040 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
5042 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
5044 proto
= nla_get_u16(
5045 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
5046 settings
->control_port_ethertype
= cpu_to_be16(proto
);
5047 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
5050 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
5051 settings
->control_port_no_encrypt
= true;
5053 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
5055 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
5059 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5060 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
5061 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
5063 if (len
% sizeof(u32
))
5066 if (settings
->n_ciphers_pairwise
> cipher_limit
)
5069 memcpy(settings
->ciphers_pairwise
, data
, len
);
5071 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
5072 if (!cfg80211_supported_cipher_suite(
5074 settings
->ciphers_pairwise
[i
]))
5078 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
5079 settings
->cipher_group
=
5080 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
5081 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
5082 settings
->cipher_group
))
5086 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
5087 settings
->wpa_versions
=
5088 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
5089 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
5093 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
5097 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5098 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
5099 settings
->n_akm_suites
= len
/ sizeof(u32
);
5101 if (len
% sizeof(u32
))
5104 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
5107 memcpy(settings
->akm_suites
, data
, len
);
5113 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
5115 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5116 struct net_device
*dev
= info
->user_ptr
[1];
5117 struct cfg80211_crypto_settings crypto
;
5118 struct ieee80211_channel
*chan
;
5119 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
5120 int err
, ssid_len
, ie_len
= 0;
5121 bool use_mfp
= false;
5123 struct ieee80211_ht_cap
*ht_capa
= NULL
;
5124 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
5126 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5129 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
5130 !info
->attrs
[NL80211_ATTR_SSID
] ||
5131 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5134 if (!rdev
->ops
->assoc
)
5137 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5138 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5141 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5143 chan
= ieee80211_get_channel(&rdev
->wiphy
,
5144 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5145 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
5148 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5149 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5151 if (info
->attrs
[NL80211_ATTR_IE
]) {
5152 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5153 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5156 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
5157 enum nl80211_mfp mfp
=
5158 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
5159 if (mfp
== NL80211_MFP_REQUIRED
)
5161 else if (mfp
!= NL80211_MFP_NO
)
5165 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
5166 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
5168 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5169 flags
|= ASSOC_REQ_DISABLE_HT
;
5171 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5173 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
5175 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5178 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
5181 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
5183 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
5184 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
5185 &crypto
, flags
, ht_capa
,
5191 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
5193 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5194 struct net_device
*dev
= info
->user_ptr
[1];
5195 const u8
*ie
= NULL
, *bssid
;
5198 bool local_state_change
;
5200 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5203 if (!info
->attrs
[NL80211_ATTR_MAC
])
5206 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5209 if (!rdev
->ops
->deauth
)
5212 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5213 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5216 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5218 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5219 if (reason_code
== 0) {
5220 /* Reason Code 0 is reserved */
5224 if (info
->attrs
[NL80211_ATTR_IE
]) {
5225 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5226 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5229 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5231 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5232 local_state_change
);
5235 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
5237 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5238 struct net_device
*dev
= info
->user_ptr
[1];
5239 const u8
*ie
= NULL
, *bssid
;
5242 bool local_state_change
;
5244 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5247 if (!info
->attrs
[NL80211_ATTR_MAC
])
5250 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5253 if (!rdev
->ops
->disassoc
)
5256 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5257 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5260 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5262 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5263 if (reason_code
== 0) {
5264 /* Reason Code 0 is reserved */
5268 if (info
->attrs
[NL80211_ATTR_IE
]) {
5269 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5270 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5273 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
5275 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
5276 local_state_change
);
5280 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
5281 int mcast_rate
[IEEE80211_NUM_BANDS
],
5284 struct wiphy
*wiphy
= &rdev
->wiphy
;
5288 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
5289 struct ieee80211_supported_band
*sband
;
5291 sband
= wiphy
->bands
[band
];
5295 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
5296 if (sband
->bitrates
[i
].bitrate
== rateval
) {
5297 mcast_rate
[band
] = i
+ 1;
5307 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5309 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5310 struct net_device
*dev
= info
->user_ptr
[1];
5311 struct cfg80211_ibss_params ibss
;
5312 struct wiphy
*wiphy
;
5313 struct cfg80211_cached_keys
*connkeys
= NULL
;
5316 memset(&ibss
, 0, sizeof(ibss
));
5318 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5321 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5322 !info
->attrs
[NL80211_ATTR_SSID
] ||
5323 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5326 ibss
.beacon_interval
= 100;
5328 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
5329 ibss
.beacon_interval
=
5330 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
5331 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
5335 if (!rdev
->ops
->join_ibss
)
5338 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5341 wiphy
= &rdev
->wiphy
;
5343 if (info
->attrs
[NL80211_ATTR_MAC
]) {
5344 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5346 if (!is_valid_ether_addr(ibss
.bssid
))
5349 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5350 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5352 if (info
->attrs
[NL80211_ATTR_IE
]) {
5353 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5354 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5357 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5358 enum nl80211_channel_type channel_type
;
5360 if (!nl80211_valid_channel_type(info
, &channel_type
))
5363 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5364 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
5367 ibss
.channel_type
= channel_type
;
5369 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
5372 ibss
.channel
= rdev_freq_to_chan(rdev
,
5373 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
5375 if (!ibss
.channel
||
5376 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
5377 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5380 /* Both channels should be able to initiate communication */
5381 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
5382 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
5383 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
5387 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
5388 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
5390 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
5392 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5394 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
5395 struct ieee80211_supported_band
*sband
=
5396 wiphy
->bands
[ibss
.channel
->band
];
5398 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
5404 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5405 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
5406 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5409 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5412 connkeys
= nl80211_parse_connkeys(rdev
,
5413 info
->attrs
[NL80211_ATTR_KEYS
],
5415 if (IS_ERR(connkeys
))
5416 return PTR_ERR(connkeys
);
5418 if ((ibss
.channel_type
!= NL80211_CHAN_NO_HT
) && no_ht
) {
5425 nla_get_flag(info
->attrs
[NL80211_ATTR_CONTROL_PORT
]);
5427 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
5433 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
5435 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5436 struct net_device
*dev
= info
->user_ptr
[1];
5438 if (!rdev
->ops
->leave_ibss
)
5441 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
5444 return cfg80211_leave_ibss(rdev
, dev
, false);
5447 #ifdef CONFIG_NL80211_TESTMODE
5448 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
5452 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
5454 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5457 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
5461 if (rdev
->ops
->testmode_cmd
) {
5462 rdev
->testmode_info
= info
;
5463 err
= rdev_testmode_cmd(rdev
,
5464 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
5465 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
5466 rdev
->testmode_info
= NULL
;
5472 static int nl80211_testmode_dump(struct sk_buff
*skb
,
5473 struct netlink_callback
*cb
)
5475 struct cfg80211_registered_device
*rdev
;
5483 * 0 is a valid index, but not valid for args[0],
5484 * so we need to offset by 1.
5486 phy_idx
= cb
->args
[0] - 1;
5488 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
5489 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
5494 mutex_lock(&cfg80211_mutex
);
5495 rdev
= __cfg80211_rdev_from_attrs(sock_net(skb
->sk
),
5496 nl80211_fam
.attrbuf
);
5498 mutex_unlock(&cfg80211_mutex
);
5499 return PTR_ERR(rdev
);
5501 phy_idx
= rdev
->wiphy_idx
;
5503 mutex_unlock(&cfg80211_mutex
);
5505 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
5507 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
5511 data
= nla_data((void *)cb
->args
[1]);
5512 data_len
= nla_len((void *)cb
->args
[1]);
5515 mutex_lock(&cfg80211_mutex
);
5516 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
5518 mutex_unlock(&cfg80211_mutex
);
5521 cfg80211_lock_rdev(rdev
);
5522 mutex_unlock(&cfg80211_mutex
);
5524 if (!rdev
->ops
->testmode_dump
) {
5530 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).portid
,
5531 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
5532 NL80211_CMD_TESTMODE
);
5533 struct nlattr
*tmdata
;
5535 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
)) {
5536 genlmsg_cancel(skb
, hdr
);
5540 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5542 genlmsg_cancel(skb
, hdr
);
5545 err
= rdev_testmode_dump(rdev
, skb
, cb
, data
, data_len
);
5546 nla_nest_end(skb
, tmdata
);
5548 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
5549 genlmsg_cancel(skb
, hdr
);
5552 genlmsg_cancel(skb
, hdr
);
5556 genlmsg_end(skb
, hdr
);
5561 cb
->args
[0] = phy_idx
+ 1;
5563 cfg80211_unlock_rdev(rdev
);
5567 static struct sk_buff
*
5568 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
5569 int approxlen
, u32 portid
, u32 seq
, gfp_t gfp
)
5571 struct sk_buff
*skb
;
5573 struct nlattr
*data
;
5575 skb
= nlmsg_new(approxlen
+ 100, gfp
);
5579 hdr
= nl80211hdr_put(skb
, portid
, seq
, 0, NL80211_CMD_TESTMODE
);
5585 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
))
5586 goto nla_put_failure
;
5587 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
5589 ((void **)skb
->cb
)[0] = rdev
;
5590 ((void **)skb
->cb
)[1] = hdr
;
5591 ((void **)skb
->cb
)[2] = data
;
5600 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
5603 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5605 if (WARN_ON(!rdev
->testmode_info
))
5608 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
5609 rdev
->testmode_info
->snd_portid
,
5610 rdev
->testmode_info
->snd_seq
,
5613 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5615 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5617 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5618 void *hdr
= ((void **)skb
->cb
)[1];
5619 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5621 if (WARN_ON(!rdev
->testmode_info
)) {
5626 nla_nest_end(skb
, data
);
5627 genlmsg_end(skb
, hdr
);
5628 return genlmsg_reply(skb
, rdev
->testmode_info
);
5630 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5632 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5633 int approxlen
, gfp_t gfp
)
5635 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5637 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5639 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5641 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5643 void *hdr
= ((void **)skb
->cb
)[1];
5644 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5646 nla_nest_end(skb
, data
);
5647 genlmsg_end(skb
, hdr
);
5648 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5650 EXPORT_SYMBOL(cfg80211_testmode_event
);
5653 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5655 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5656 struct net_device
*dev
= info
->user_ptr
[1];
5657 struct cfg80211_connect_params connect
;
5658 struct wiphy
*wiphy
;
5659 struct cfg80211_cached_keys
*connkeys
= NULL
;
5662 memset(&connect
, 0, sizeof(connect
));
5664 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5667 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5668 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5671 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5673 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5674 if (!nl80211_valid_auth_type(rdev
, connect
.auth_type
,
5675 NL80211_CMD_CONNECT
))
5678 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5680 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5682 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5683 NL80211_MAX_NR_CIPHER_SUITES
);
5687 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5688 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5691 wiphy
= &rdev
->wiphy
;
5693 connect
.bg_scan_period
= -1;
5694 if (info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
] &&
5695 (wiphy
->flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)) {
5696 connect
.bg_scan_period
=
5697 nla_get_u16(info
->attrs
[NL80211_ATTR_BG_SCAN_PERIOD
]);
5700 if (info
->attrs
[NL80211_ATTR_MAC
])
5701 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5702 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5703 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5705 if (info
->attrs
[NL80211_ATTR_IE
]) {
5706 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5707 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5710 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5712 ieee80211_get_channel(wiphy
,
5713 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5714 if (!connect
.channel
||
5715 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5719 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5720 connkeys
= nl80211_parse_connkeys(rdev
,
5721 info
->attrs
[NL80211_ATTR_KEYS
], NULL
);
5722 if (IS_ERR(connkeys
))
5723 return PTR_ERR(connkeys
);
5726 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5727 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5729 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5730 memcpy(&connect
.ht_capa_mask
,
5731 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5732 sizeof(connect
.ht_capa_mask
));
5734 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5735 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]) {
5739 memcpy(&connect
.ht_capa
,
5740 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5741 sizeof(connect
.ht_capa
));
5744 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5750 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5752 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5753 struct net_device
*dev
= info
->user_ptr
[1];
5756 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5757 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5759 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5764 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5765 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5768 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5771 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5773 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5778 if (!info
->attrs
[NL80211_ATTR_PID
])
5781 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5783 net
= get_net_ns_by_pid(pid
);
5785 return PTR_ERR(net
);
5789 /* check if anything to do */
5790 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5791 err
= cfg80211_switch_netns(rdev
, net
);
5797 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5799 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5800 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5801 struct cfg80211_pmksa
*pmksa
) = NULL
;
5802 struct net_device
*dev
= info
->user_ptr
[1];
5803 struct cfg80211_pmksa pmksa
;
5805 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5807 if (!info
->attrs
[NL80211_ATTR_MAC
])
5810 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5813 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5814 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5816 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5817 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5820 switch (info
->genlhdr
->cmd
) {
5821 case NL80211_CMD_SET_PMKSA
:
5822 rdev_ops
= rdev
->ops
->set_pmksa
;
5824 case NL80211_CMD_DEL_PMKSA
:
5825 rdev_ops
= rdev
->ops
->del_pmksa
;
5835 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5838 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5840 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5841 struct net_device
*dev
= info
->user_ptr
[1];
5843 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5844 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5847 if (!rdev
->ops
->flush_pmksa
)
5850 return rdev_flush_pmksa(rdev
, dev
);
5853 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5855 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5856 struct net_device
*dev
= info
->user_ptr
[1];
5857 u8 action_code
, dialog_token
;
5861 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5862 !rdev
->ops
->tdls_mgmt
)
5865 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5866 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5867 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5868 !info
->attrs
[NL80211_ATTR_IE
] ||
5869 !info
->attrs
[NL80211_ATTR_MAC
])
5872 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5873 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5874 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5875 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5877 return rdev_tdls_mgmt(rdev
, dev
, peer
, action_code
,
5878 dialog_token
, status_code
,
5879 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5880 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5883 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5885 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5886 struct net_device
*dev
= info
->user_ptr
[1];
5887 enum nl80211_tdls_operation operation
;
5890 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5891 !rdev
->ops
->tdls_oper
)
5894 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5895 !info
->attrs
[NL80211_ATTR_MAC
])
5898 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5899 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5901 return rdev_tdls_oper(rdev
, dev
, peer
, operation
);
5904 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5905 struct genl_info
*info
)
5907 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5908 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5909 struct ieee80211_channel
*chan
;
5910 struct sk_buff
*msg
;
5913 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5917 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5918 !info
->attrs
[NL80211_ATTR_DURATION
])
5921 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5923 if (!rdev
->ops
->remain_on_channel
||
5924 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5928 * We should be on that channel for at least a minimum amount of
5929 * time (10ms) but no longer than the driver supports.
5931 if (duration
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
5932 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5935 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
5936 !nl80211_valid_channel_type(info
, &channel_type
))
5939 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5940 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5944 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5948 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
5949 NL80211_CMD_REMAIN_ON_CHANNEL
);
5956 err
= rdev_remain_on_channel(rdev
, wdev
, chan
, channel_type
, duration
,
5962 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
5963 goto nla_put_failure
;
5965 genlmsg_end(msg
, hdr
);
5967 return genlmsg_reply(msg
, info
);
5976 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5977 struct genl_info
*info
)
5979 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5980 struct wireless_dev
*wdev
= info
->user_ptr
[1];
5983 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5986 if (!rdev
->ops
->cancel_remain_on_channel
)
5989 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5991 return rdev_cancel_remain_on_channel(rdev
, wdev
, cookie
);
5994 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5995 u8
*rates
, u8 rates_len
)
6000 for (i
= 0; i
< rates_len
; i
++) {
6001 int rate
= (rates
[i
] & 0x7f) * 5;
6003 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
6004 struct ieee80211_rate
*srate
=
6005 &sband
->bitrates
[ridx
];
6006 if (rate
== srate
->bitrate
) {
6011 if (ridx
== sband
->n_bitrates
)
6012 return 0; /* rate not found */
6018 static bool ht_rateset_to_mask(struct ieee80211_supported_band
*sband
,
6019 u8
*rates
, u8 rates_len
,
6020 u8 mcs
[IEEE80211_HT_MCS_MASK_LEN
])
6024 memset(mcs
, 0, IEEE80211_HT_MCS_MASK_LEN
);
6026 for (i
= 0; i
< rates_len
; i
++) {
6029 ridx
= rates
[i
] / 8;
6030 rbit
= BIT(rates
[i
] % 8);
6032 /* check validity */
6033 if ((ridx
< 0) || (ridx
>= IEEE80211_HT_MCS_MASK_LEN
))
6036 /* check availability */
6037 if (sband
->ht_cap
.mcs
.rx_mask
[ridx
] & rbit
)
6046 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
6047 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
6048 .len
= NL80211_MAX_SUPP_RATES
},
6049 [NL80211_TXRATE_MCS
] = { .type
= NLA_BINARY
,
6050 .len
= NL80211_MAX_SUPP_HT_RATES
},
6053 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
6054 struct genl_info
*info
)
6056 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
6057 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6058 struct cfg80211_bitrate_mask mask
;
6060 struct net_device
*dev
= info
->user_ptr
[1];
6061 struct nlattr
*tx_rates
;
6062 struct ieee80211_supported_band
*sband
;
6064 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
6067 if (!rdev
->ops
->set_bitrate_mask
)
6070 memset(&mask
, 0, sizeof(mask
));
6071 /* Default to all rates enabled */
6072 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
6073 sband
= rdev
->wiphy
.bands
[i
];
6074 mask
.control
[i
].legacy
=
6075 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
6077 memcpy(mask
.control
[i
].mcs
,
6078 sband
->ht_cap
.mcs
.rx_mask
,
6079 sizeof(mask
.control
[i
].mcs
));
6081 memset(mask
.control
[i
].mcs
, 0,
6082 sizeof(mask
.control
[i
].mcs
));
6086 * The nested attribute uses enum nl80211_band as the index. This maps
6087 * directly to the enum ieee80211_band values used in cfg80211.
6089 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES
> IEEE80211_HT_MCS_MASK_LEN
* 8);
6090 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
6092 enum ieee80211_band band
= nla_type(tx_rates
);
6093 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
6095 sband
= rdev
->wiphy
.bands
[band
];
6098 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
6099 nla_len(tx_rates
), nl80211_txattr_policy
);
6100 if (tb
[NL80211_TXRATE_LEGACY
]) {
6101 mask
.control
[band
].legacy
= rateset_to_mask(
6103 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
6104 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
6105 if ((mask
.control
[band
].legacy
== 0) &&
6106 nla_len(tb
[NL80211_TXRATE_LEGACY
]))
6109 if (tb
[NL80211_TXRATE_MCS
]) {
6110 if (!ht_rateset_to_mask(
6112 nla_data(tb
[NL80211_TXRATE_MCS
]),
6113 nla_len(tb
[NL80211_TXRATE_MCS
]),
6114 mask
.control
[band
].mcs
))
6118 if (mask
.control
[band
].legacy
== 0) {
6119 /* don't allow empty legacy rates if HT
6120 * is not even supported. */
6121 if (!rdev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
)
6124 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
6125 if (mask
.control
[band
].mcs
[i
])
6128 /* legacy and mcs rates may not be both empty */
6129 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
6134 return rdev_set_bitrate_mask(rdev
, dev
, NULL
, &mask
);
6137 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6139 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6140 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6141 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
6143 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
6146 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
6147 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
6149 switch (wdev
->iftype
) {
6150 case NL80211_IFTYPE_STATION
:
6151 case NL80211_IFTYPE_ADHOC
:
6152 case NL80211_IFTYPE_P2P_CLIENT
:
6153 case NL80211_IFTYPE_AP
:
6154 case NL80211_IFTYPE_AP_VLAN
:
6155 case NL80211_IFTYPE_MESH_POINT
:
6156 case NL80211_IFTYPE_P2P_GO
:
6157 case NL80211_IFTYPE_P2P_DEVICE
:
6163 /* not much point in registering if we can't reply */
6164 if (!rdev
->ops
->mgmt_tx
)
6167 return cfg80211_mlme_register_mgmt(wdev
, info
->snd_portid
, frame_type
,
6168 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
6169 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
6172 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
6174 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6175 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6176 struct ieee80211_channel
*chan
;
6177 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6178 bool channel_type_valid
= false;
6183 struct sk_buff
*msg
= NULL
;
6184 unsigned int wait
= 0;
6185 bool offchan
, no_cck
, dont_wait_for_ack
;
6187 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
6189 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
6190 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
6193 if (!rdev
->ops
->mgmt_tx
)
6196 switch (wdev
->iftype
) {
6197 case NL80211_IFTYPE_STATION
:
6198 case NL80211_IFTYPE_ADHOC
:
6199 case NL80211_IFTYPE_P2P_CLIENT
:
6200 case NL80211_IFTYPE_AP
:
6201 case NL80211_IFTYPE_AP_VLAN
:
6202 case NL80211_IFTYPE_MESH_POINT
:
6203 case NL80211_IFTYPE_P2P_GO
:
6204 case NL80211_IFTYPE_P2P_DEVICE
:
6210 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
6211 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6213 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
6216 * We should wait on the channel for at least a minimum amount
6217 * of time (10ms) but no longer than the driver supports.
6219 if (wait
< NL80211_MIN_REMAIN_ON_CHANNEL_TIME
||
6220 wait
> rdev
->wiphy
.max_remain_on_channel_duration
)
6225 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
6226 if (!nl80211_valid_channel_type(info
, &channel_type
))
6228 channel_type_valid
= true;
6231 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
6233 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
6236 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
6238 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
6239 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
6243 if (!dont_wait_for_ack
) {
6244 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6248 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6257 err
= cfg80211_mlme_mgmt_tx(rdev
, wdev
, chan
, offchan
, channel_type
,
6258 channel_type_valid
, wait
,
6259 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
6260 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
6261 no_cck
, dont_wait_for_ack
, &cookie
);
6266 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6267 goto nla_put_failure
;
6269 genlmsg_end(msg
, hdr
);
6270 return genlmsg_reply(msg
, info
);
6282 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
6284 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6285 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6288 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
6291 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
6294 switch (wdev
->iftype
) {
6295 case NL80211_IFTYPE_STATION
:
6296 case NL80211_IFTYPE_ADHOC
:
6297 case NL80211_IFTYPE_P2P_CLIENT
:
6298 case NL80211_IFTYPE_AP
:
6299 case NL80211_IFTYPE_AP_VLAN
:
6300 case NL80211_IFTYPE_P2P_GO
:
6301 case NL80211_IFTYPE_P2P_DEVICE
:
6307 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
6309 return rdev_mgmt_tx_cancel_wait(rdev
, wdev
, cookie
);
6312 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6314 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6315 struct wireless_dev
*wdev
;
6316 struct net_device
*dev
= info
->user_ptr
[1];
6321 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
6324 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
6326 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
6329 wdev
= dev
->ieee80211_ptr
;
6331 if (!rdev
->ops
->set_power_mgmt
)
6334 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
6336 if (state
== wdev
->ps
)
6339 err
= rdev_set_power_mgmt(rdev
, dev
, state
, wdev
->ps_timeout
);
6345 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
6347 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6348 enum nl80211_ps_state ps_state
;
6349 struct wireless_dev
*wdev
;
6350 struct net_device
*dev
= info
->user_ptr
[1];
6351 struct sk_buff
*msg
;
6355 wdev
= dev
->ieee80211_ptr
;
6357 if (!rdev
->ops
->set_power_mgmt
)
6360 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6364 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6365 NL80211_CMD_GET_POWER_SAVE
);
6372 ps_state
= NL80211_PS_ENABLED
;
6374 ps_state
= NL80211_PS_DISABLED
;
6376 if (nla_put_u32(msg
, NL80211_ATTR_PS_STATE
, ps_state
))
6377 goto nla_put_failure
;
6379 genlmsg_end(msg
, hdr
);
6380 return genlmsg_reply(msg
, info
);
6389 static struct nla_policy
6390 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
6391 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
6392 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
6393 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
6394 [NL80211_ATTR_CQM_TXE_RATE
] = { .type
= NLA_U32
},
6395 [NL80211_ATTR_CQM_TXE_PKTS
] = { .type
= NLA_U32
},
6396 [NL80211_ATTR_CQM_TXE_INTVL
] = { .type
= NLA_U32
},
6399 static int nl80211_set_cqm_txe(struct genl_info
*info
,
6400 u32 rate
, u32 pkts
, u32 intvl
)
6402 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6403 struct wireless_dev
*wdev
;
6404 struct net_device
*dev
= info
->user_ptr
[1];
6406 if ((rate
< 0 || rate
> 100) ||
6407 (intvl
< 0 || intvl
> NL80211_CQM_TXE_MAX_INTVL
))
6410 wdev
= dev
->ieee80211_ptr
;
6412 if (!rdev
->ops
->set_cqm_txe_config
)
6415 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6416 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6419 return rdev_set_cqm_txe_config(rdev
, dev
, rate
, pkts
, intvl
);
6422 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
6423 s32 threshold
, u32 hysteresis
)
6425 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6426 struct wireless_dev
*wdev
;
6427 struct net_device
*dev
= info
->user_ptr
[1];
6432 wdev
= dev
->ieee80211_ptr
;
6434 if (!rdev
->ops
->set_cqm_rssi_config
)
6437 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
6438 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
6441 return rdev_set_cqm_rssi_config(rdev
, dev
, threshold
, hysteresis
);
6444 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
6446 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
6450 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
6456 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
6457 nl80211_attr_cqm_policy
);
6461 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
6462 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
6465 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
6466 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
6467 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
6468 } else if (attrs
[NL80211_ATTR_CQM_TXE_RATE
] &&
6469 attrs
[NL80211_ATTR_CQM_TXE_PKTS
] &&
6470 attrs
[NL80211_ATTR_CQM_TXE_INTVL
]) {
6471 u32 rate
, pkts
, intvl
;
6472 rate
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_RATE
]);
6473 pkts
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_PKTS
]);
6474 intvl
= nla_get_u32(attrs
[NL80211_ATTR_CQM_TXE_INTVL
]);
6475 err
= nl80211_set_cqm_txe(info
, rate
, pkts
, intvl
);
6483 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6485 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6486 struct net_device
*dev
= info
->user_ptr
[1];
6487 struct mesh_config cfg
;
6488 struct mesh_setup setup
;
6491 /* start with default */
6492 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
6493 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
6495 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
6496 /* and parse parameters if given */
6497 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
6502 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
6503 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
6506 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6507 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
6509 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
6510 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
6511 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
6514 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
6515 /* parse additional setup parameters if given */
6516 err
= nl80211_parse_mesh_setup(info
, &setup
);
6521 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
6522 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
6524 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
] &&
6525 !nl80211_valid_channel_type(info
, &channel_type
))
6528 setup
.channel
= rdev_freq_to_chan(rdev
,
6529 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
6533 setup
.channel_type
= channel_type
;
6535 /* cfg80211_join_mesh() will sort it out */
6536 setup
.channel
= NULL
;
6539 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
6542 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
6544 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6545 struct net_device
*dev
= info
->user_ptr
[1];
6547 return cfg80211_leave_mesh(rdev
, dev
);
6551 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6553 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6554 struct sk_buff
*msg
;
6557 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6560 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6564 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6565 NL80211_CMD_GET_WOWLAN
);
6567 goto nla_put_failure
;
6570 struct nlattr
*nl_wowlan
;
6572 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
6574 goto nla_put_failure
;
6576 if ((rdev
->wowlan
->any
&&
6577 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_ANY
)) ||
6578 (rdev
->wowlan
->disconnect
&&
6579 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
)) ||
6580 (rdev
->wowlan
->magic_pkt
&&
6581 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
)) ||
6582 (rdev
->wowlan
->gtk_rekey_failure
&&
6583 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
)) ||
6584 (rdev
->wowlan
->eap_identity_req
&&
6585 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
)) ||
6586 (rdev
->wowlan
->four_way_handshake
&&
6587 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
)) ||
6588 (rdev
->wowlan
->rfkill_release
&&
6589 nla_put_flag(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
)))
6590 goto nla_put_failure
;
6591 if (rdev
->wowlan
->n_patterns
) {
6592 struct nlattr
*nl_pats
, *nl_pat
;
6595 nl_pats
= nla_nest_start(msg
,
6596 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
6598 goto nla_put_failure
;
6600 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
6601 nl_pat
= nla_nest_start(msg
, i
+ 1);
6603 goto nla_put_failure
;
6604 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
6605 if (nla_put(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
6606 DIV_ROUND_UP(pat_len
, 8),
6607 rdev
->wowlan
->patterns
[i
].mask
) ||
6608 nla_put(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
6610 rdev
->wowlan
->patterns
[i
].pattern
))
6611 goto nla_put_failure
;
6612 nla_nest_end(msg
, nl_pat
);
6614 nla_nest_end(msg
, nl_pats
);
6617 nla_nest_end(msg
, nl_wowlan
);
6620 genlmsg_end(msg
, hdr
);
6621 return genlmsg_reply(msg
, info
);
6628 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
6630 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6631 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
6632 struct cfg80211_wowlan new_triggers
= {};
6633 struct cfg80211_wowlan
*ntrig
;
6634 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
6636 bool prev_enabled
= rdev
->wowlan
;
6638 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
6641 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]) {
6642 cfg80211_rdev_free_wowlan(rdev
);
6643 rdev
->wowlan
= NULL
;
6647 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
6648 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6649 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
6650 nl80211_wowlan_policy
);
6654 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
6655 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
6657 new_triggers
.any
= true;
6660 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
6661 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
6663 new_triggers
.disconnect
= true;
6666 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
6667 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
6669 new_triggers
.magic_pkt
= true;
6672 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
6675 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
6676 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
6678 new_triggers
.gtk_rekey_failure
= true;
6681 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
6682 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
6684 new_triggers
.eap_identity_req
= true;
6687 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
6688 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
6690 new_triggers
.four_way_handshake
= true;
6693 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
6694 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
6696 new_triggers
.rfkill_release
= true;
6699 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
6702 int rem
, pat_len
, mask_len
;
6703 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
6705 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6708 if (n_patterns
> wowlan
->n_patterns
)
6711 new_triggers
.patterns
= kcalloc(n_patterns
,
6712 sizeof(new_triggers
.patterns
[0]),
6714 if (!new_triggers
.patterns
)
6717 new_triggers
.n_patterns
= n_patterns
;
6720 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
6722 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
6723 nla_data(pat
), nla_len(pat
), NULL
);
6725 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
6726 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
6728 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
6729 mask_len
= DIV_ROUND_UP(pat_len
, 8);
6730 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
6733 if (pat_len
> wowlan
->pattern_max_len
||
6734 pat_len
< wowlan
->pattern_min_len
)
6737 new_triggers
.patterns
[i
].mask
=
6738 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
6739 if (!new_triggers
.patterns
[i
].mask
) {
6743 new_triggers
.patterns
[i
].pattern
=
6744 new_triggers
.patterns
[i
].mask
+ mask_len
;
6745 memcpy(new_triggers
.patterns
[i
].mask
,
6746 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
6748 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
6749 memcpy(new_triggers
.patterns
[i
].pattern
,
6750 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
6756 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
), GFP_KERNEL
);
6761 cfg80211_rdev_free_wowlan(rdev
);
6762 rdev
->wowlan
= ntrig
;
6765 if (rdev
->ops
->set_wakeup
&& prev_enabled
!= !!rdev
->wowlan
)
6766 rdev_set_wakeup(rdev
, rdev
->wowlan
);
6770 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6771 kfree(new_triggers
.patterns
[i
].mask
);
6772 kfree(new_triggers
.patterns
);
6777 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6779 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6780 struct net_device
*dev
= info
->user_ptr
[1];
6781 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6782 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6783 struct cfg80211_gtk_rekey_data rekey_data
;
6786 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6789 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6790 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6791 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6792 nl80211_rekey_policy
);
6796 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6798 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6800 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6803 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6805 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6807 memcpy(rekey_data
.replay_ctr
,
6808 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6809 NL80211_REPLAY_CTR_LEN
);
6812 if (!wdev
->current_bss
) {
6817 if (!rdev
->ops
->set_rekey_data
) {
6822 err
= rdev_set_rekey_data(rdev
, dev
, &rekey_data
);
6828 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6829 struct genl_info
*info
)
6831 struct net_device
*dev
= info
->user_ptr
[1];
6832 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6834 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6835 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6838 if (wdev
->ap_unexpected_nlportid
)
6841 wdev
->ap_unexpected_nlportid
= info
->snd_portid
;
6845 static int nl80211_probe_client(struct sk_buff
*skb
,
6846 struct genl_info
*info
)
6848 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6849 struct net_device
*dev
= info
->user_ptr
[1];
6850 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6851 struct sk_buff
*msg
;
6857 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6858 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6861 if (!info
->attrs
[NL80211_ATTR_MAC
])
6864 if (!rdev
->ops
->probe_client
)
6867 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6871 hdr
= nl80211hdr_put(msg
, info
->snd_portid
, info
->snd_seq
, 0,
6872 NL80211_CMD_PROBE_CLIENT
);
6879 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6881 err
= rdev_probe_client(rdev
, dev
, addr
, &cookie
);
6885 if (nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
6886 goto nla_put_failure
;
6888 genlmsg_end(msg
, hdr
);
6890 return genlmsg_reply(msg
, info
);
6899 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6901 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6903 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6906 if (rdev
->ap_beacons_nlportid
)
6909 rdev
->ap_beacons_nlportid
= info
->snd_portid
;
6914 static int nl80211_start_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
6916 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6917 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6920 if (!rdev
->ops
->start_p2p_device
)
6923 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
6926 if (wdev
->p2p_started
)
6929 mutex_lock(&rdev
->devlist_mtx
);
6930 err
= cfg80211_can_add_interface(rdev
, wdev
->iftype
);
6931 mutex_unlock(&rdev
->devlist_mtx
);
6935 err
= rdev_start_p2p_device(rdev
, wdev
);
6939 wdev
->p2p_started
= true;
6940 mutex_lock(&rdev
->devlist_mtx
);
6942 mutex_unlock(&rdev
->devlist_mtx
);
6947 static int nl80211_stop_p2p_device(struct sk_buff
*skb
, struct genl_info
*info
)
6949 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6950 struct wireless_dev
*wdev
= info
->user_ptr
[1];
6952 if (wdev
->iftype
!= NL80211_IFTYPE_P2P_DEVICE
)
6955 if (!rdev
->ops
->stop_p2p_device
)
6958 if (!wdev
->p2p_started
)
6961 rdev_stop_p2p_device(rdev
, wdev
);
6962 wdev
->p2p_started
= false;
6964 mutex_lock(&rdev
->devlist_mtx
);
6966 mutex_unlock(&rdev
->devlist_mtx
);
6968 if (WARN_ON(rdev
->scan_req
&& rdev
->scan_req
->wdev
== wdev
)) {
6969 rdev
->scan_req
->aborted
= true;
6970 ___cfg80211_scan_done(rdev
, true);
6976 #define NL80211_FLAG_NEED_WIPHY 0x01
6977 #define NL80211_FLAG_NEED_NETDEV 0x02
6978 #define NL80211_FLAG_NEED_RTNL 0x04
6979 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6980 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6981 NL80211_FLAG_CHECK_NETDEV_UP)
6982 #define NL80211_FLAG_NEED_WDEV 0x10
6983 /* If a netdev is associated, it must be UP, P2P must be started */
6984 #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
6985 NL80211_FLAG_CHECK_NETDEV_UP)
6987 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6988 struct genl_info
*info
)
6990 struct cfg80211_registered_device
*rdev
;
6991 struct wireless_dev
*wdev
;
6992 struct net_device
*dev
;
6993 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6998 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6999 rdev
= cfg80211_get_dev_from_info(genl_info_net(info
), info
);
7003 return PTR_ERR(rdev
);
7005 info
->user_ptr
[0] = rdev
;
7006 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
||
7007 ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7008 mutex_lock(&cfg80211_mutex
);
7009 wdev
= __cfg80211_wdev_from_attrs(genl_info_net(info
),
7012 mutex_unlock(&cfg80211_mutex
);
7015 return PTR_ERR(wdev
);
7019 rdev
= wiphy_to_dev(wdev
->wiphy
);
7021 if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
7023 mutex_unlock(&cfg80211_mutex
);
7029 info
->user_ptr
[1] = dev
;
7031 info
->user_ptr
[1] = wdev
;
7035 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
7036 !netif_running(dev
)) {
7037 mutex_unlock(&cfg80211_mutex
);
7044 } else if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
) {
7045 if (!wdev
->p2p_started
) {
7046 mutex_unlock(&cfg80211_mutex
);
7053 cfg80211_lock_rdev(rdev
);
7055 mutex_unlock(&cfg80211_mutex
);
7057 info
->user_ptr
[0] = rdev
;
7063 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
7064 struct genl_info
*info
)
7066 if (info
->user_ptr
[0])
7067 cfg80211_unlock_rdev(info
->user_ptr
[0]);
7068 if (info
->user_ptr
[1]) {
7069 if (ops
->internal_flags
& NL80211_FLAG_NEED_WDEV
) {
7070 struct wireless_dev
*wdev
= info
->user_ptr
[1];
7073 dev_put(wdev
->netdev
);
7075 dev_put(info
->user_ptr
[1]);
7078 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
7082 static struct genl_ops nl80211_ops
[] = {
7084 .cmd
= NL80211_CMD_GET_WIPHY
,
7085 .doit
= nl80211_get_wiphy
,
7086 .dumpit
= nl80211_dump_wiphy
,
7087 .policy
= nl80211_policy
,
7088 /* can be retrieved by unprivileged users */
7089 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
7092 .cmd
= NL80211_CMD_SET_WIPHY
,
7093 .doit
= nl80211_set_wiphy
,
7094 .policy
= nl80211_policy
,
7095 .flags
= GENL_ADMIN_PERM
,
7096 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
7099 .cmd
= NL80211_CMD_GET_INTERFACE
,
7100 .doit
= nl80211_get_interface
,
7101 .dumpit
= nl80211_dump_interface
,
7102 .policy
= nl80211_policy
,
7103 /* can be retrieved by unprivileged users */
7104 .internal_flags
= NL80211_FLAG_NEED_WDEV
,
7107 .cmd
= NL80211_CMD_SET_INTERFACE
,
7108 .doit
= nl80211_set_interface
,
7109 .policy
= nl80211_policy
,
7110 .flags
= GENL_ADMIN_PERM
,
7111 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7112 NL80211_FLAG_NEED_RTNL
,
7115 .cmd
= NL80211_CMD_NEW_INTERFACE
,
7116 .doit
= nl80211_new_interface
,
7117 .policy
= nl80211_policy
,
7118 .flags
= GENL_ADMIN_PERM
,
7119 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7120 NL80211_FLAG_NEED_RTNL
,
7123 .cmd
= NL80211_CMD_DEL_INTERFACE
,
7124 .doit
= nl80211_del_interface
,
7125 .policy
= nl80211_policy
,
7126 .flags
= GENL_ADMIN_PERM
,
7127 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7128 NL80211_FLAG_NEED_RTNL
,
7131 .cmd
= NL80211_CMD_GET_KEY
,
7132 .doit
= nl80211_get_key
,
7133 .policy
= nl80211_policy
,
7134 .flags
= GENL_ADMIN_PERM
,
7135 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7136 NL80211_FLAG_NEED_RTNL
,
7139 .cmd
= NL80211_CMD_SET_KEY
,
7140 .doit
= nl80211_set_key
,
7141 .policy
= nl80211_policy
,
7142 .flags
= GENL_ADMIN_PERM
,
7143 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7144 NL80211_FLAG_NEED_RTNL
,
7147 .cmd
= NL80211_CMD_NEW_KEY
,
7148 .doit
= nl80211_new_key
,
7149 .policy
= nl80211_policy
,
7150 .flags
= GENL_ADMIN_PERM
,
7151 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7152 NL80211_FLAG_NEED_RTNL
,
7155 .cmd
= NL80211_CMD_DEL_KEY
,
7156 .doit
= nl80211_del_key
,
7157 .policy
= nl80211_policy
,
7158 .flags
= GENL_ADMIN_PERM
,
7159 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7160 NL80211_FLAG_NEED_RTNL
,
7163 .cmd
= NL80211_CMD_SET_BEACON
,
7164 .policy
= nl80211_policy
,
7165 .flags
= GENL_ADMIN_PERM
,
7166 .doit
= nl80211_set_beacon
,
7167 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7168 NL80211_FLAG_NEED_RTNL
,
7171 .cmd
= NL80211_CMD_START_AP
,
7172 .policy
= nl80211_policy
,
7173 .flags
= GENL_ADMIN_PERM
,
7174 .doit
= nl80211_start_ap
,
7175 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7176 NL80211_FLAG_NEED_RTNL
,
7179 .cmd
= NL80211_CMD_STOP_AP
,
7180 .policy
= nl80211_policy
,
7181 .flags
= GENL_ADMIN_PERM
,
7182 .doit
= nl80211_stop_ap
,
7183 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7184 NL80211_FLAG_NEED_RTNL
,
7187 .cmd
= NL80211_CMD_GET_STATION
,
7188 .doit
= nl80211_get_station
,
7189 .dumpit
= nl80211_dump_station
,
7190 .policy
= nl80211_policy
,
7191 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7192 NL80211_FLAG_NEED_RTNL
,
7195 .cmd
= NL80211_CMD_SET_STATION
,
7196 .doit
= nl80211_set_station
,
7197 .policy
= nl80211_policy
,
7198 .flags
= GENL_ADMIN_PERM
,
7199 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7200 NL80211_FLAG_NEED_RTNL
,
7203 .cmd
= NL80211_CMD_NEW_STATION
,
7204 .doit
= nl80211_new_station
,
7205 .policy
= nl80211_policy
,
7206 .flags
= GENL_ADMIN_PERM
,
7207 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7208 NL80211_FLAG_NEED_RTNL
,
7211 .cmd
= NL80211_CMD_DEL_STATION
,
7212 .doit
= nl80211_del_station
,
7213 .policy
= nl80211_policy
,
7214 .flags
= GENL_ADMIN_PERM
,
7215 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7216 NL80211_FLAG_NEED_RTNL
,
7219 .cmd
= NL80211_CMD_GET_MPATH
,
7220 .doit
= nl80211_get_mpath
,
7221 .dumpit
= nl80211_dump_mpath
,
7222 .policy
= nl80211_policy
,
7223 .flags
= GENL_ADMIN_PERM
,
7224 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7225 NL80211_FLAG_NEED_RTNL
,
7228 .cmd
= NL80211_CMD_SET_MPATH
,
7229 .doit
= nl80211_set_mpath
,
7230 .policy
= nl80211_policy
,
7231 .flags
= GENL_ADMIN_PERM
,
7232 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7233 NL80211_FLAG_NEED_RTNL
,
7236 .cmd
= NL80211_CMD_NEW_MPATH
,
7237 .doit
= nl80211_new_mpath
,
7238 .policy
= nl80211_policy
,
7239 .flags
= GENL_ADMIN_PERM
,
7240 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7241 NL80211_FLAG_NEED_RTNL
,
7244 .cmd
= NL80211_CMD_DEL_MPATH
,
7245 .doit
= nl80211_del_mpath
,
7246 .policy
= nl80211_policy
,
7247 .flags
= GENL_ADMIN_PERM
,
7248 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7249 NL80211_FLAG_NEED_RTNL
,
7252 .cmd
= NL80211_CMD_SET_BSS
,
7253 .doit
= nl80211_set_bss
,
7254 .policy
= nl80211_policy
,
7255 .flags
= GENL_ADMIN_PERM
,
7256 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7257 NL80211_FLAG_NEED_RTNL
,
7260 .cmd
= NL80211_CMD_GET_REG
,
7261 .doit
= nl80211_get_reg
,
7262 .policy
= nl80211_policy
,
7263 /* can be retrieved by unprivileged users */
7266 .cmd
= NL80211_CMD_SET_REG
,
7267 .doit
= nl80211_set_reg
,
7268 .policy
= nl80211_policy
,
7269 .flags
= GENL_ADMIN_PERM
,
7272 .cmd
= NL80211_CMD_REQ_SET_REG
,
7273 .doit
= nl80211_req_set_reg
,
7274 .policy
= nl80211_policy
,
7275 .flags
= GENL_ADMIN_PERM
,
7278 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
7279 .doit
= nl80211_get_mesh_config
,
7280 .policy
= nl80211_policy
,
7281 /* can be retrieved by unprivileged users */
7282 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7283 NL80211_FLAG_NEED_RTNL
,
7286 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
7287 .doit
= nl80211_update_mesh_config
,
7288 .policy
= nl80211_policy
,
7289 .flags
= GENL_ADMIN_PERM
,
7290 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7291 NL80211_FLAG_NEED_RTNL
,
7294 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
7295 .doit
= nl80211_trigger_scan
,
7296 .policy
= nl80211_policy
,
7297 .flags
= GENL_ADMIN_PERM
,
7298 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7299 NL80211_FLAG_NEED_RTNL
,
7302 .cmd
= NL80211_CMD_GET_SCAN
,
7303 .policy
= nl80211_policy
,
7304 .dumpit
= nl80211_dump_scan
,
7307 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
7308 .doit
= nl80211_start_sched_scan
,
7309 .policy
= nl80211_policy
,
7310 .flags
= GENL_ADMIN_PERM
,
7311 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7312 NL80211_FLAG_NEED_RTNL
,
7315 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
7316 .doit
= nl80211_stop_sched_scan
,
7317 .policy
= nl80211_policy
,
7318 .flags
= GENL_ADMIN_PERM
,
7319 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7320 NL80211_FLAG_NEED_RTNL
,
7323 .cmd
= NL80211_CMD_AUTHENTICATE
,
7324 .doit
= nl80211_authenticate
,
7325 .policy
= nl80211_policy
,
7326 .flags
= GENL_ADMIN_PERM
,
7327 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7328 NL80211_FLAG_NEED_RTNL
,
7331 .cmd
= NL80211_CMD_ASSOCIATE
,
7332 .doit
= nl80211_associate
,
7333 .policy
= nl80211_policy
,
7334 .flags
= GENL_ADMIN_PERM
,
7335 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7336 NL80211_FLAG_NEED_RTNL
,
7339 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
7340 .doit
= nl80211_deauthenticate
,
7341 .policy
= nl80211_policy
,
7342 .flags
= GENL_ADMIN_PERM
,
7343 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7344 NL80211_FLAG_NEED_RTNL
,
7347 .cmd
= NL80211_CMD_DISASSOCIATE
,
7348 .doit
= nl80211_disassociate
,
7349 .policy
= nl80211_policy
,
7350 .flags
= GENL_ADMIN_PERM
,
7351 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7352 NL80211_FLAG_NEED_RTNL
,
7355 .cmd
= NL80211_CMD_JOIN_IBSS
,
7356 .doit
= nl80211_join_ibss
,
7357 .policy
= nl80211_policy
,
7358 .flags
= GENL_ADMIN_PERM
,
7359 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7360 NL80211_FLAG_NEED_RTNL
,
7363 .cmd
= NL80211_CMD_LEAVE_IBSS
,
7364 .doit
= nl80211_leave_ibss
,
7365 .policy
= nl80211_policy
,
7366 .flags
= GENL_ADMIN_PERM
,
7367 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7368 NL80211_FLAG_NEED_RTNL
,
7370 #ifdef CONFIG_NL80211_TESTMODE
7372 .cmd
= NL80211_CMD_TESTMODE
,
7373 .doit
= nl80211_testmode_do
,
7374 .dumpit
= nl80211_testmode_dump
,
7375 .policy
= nl80211_policy
,
7376 .flags
= GENL_ADMIN_PERM
,
7377 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7378 NL80211_FLAG_NEED_RTNL
,
7382 .cmd
= NL80211_CMD_CONNECT
,
7383 .doit
= nl80211_connect
,
7384 .policy
= nl80211_policy
,
7385 .flags
= GENL_ADMIN_PERM
,
7386 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7387 NL80211_FLAG_NEED_RTNL
,
7390 .cmd
= NL80211_CMD_DISCONNECT
,
7391 .doit
= nl80211_disconnect
,
7392 .policy
= nl80211_policy
,
7393 .flags
= GENL_ADMIN_PERM
,
7394 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7395 NL80211_FLAG_NEED_RTNL
,
7398 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
7399 .doit
= nl80211_wiphy_netns
,
7400 .policy
= nl80211_policy
,
7401 .flags
= GENL_ADMIN_PERM
,
7402 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7403 NL80211_FLAG_NEED_RTNL
,
7406 .cmd
= NL80211_CMD_GET_SURVEY
,
7407 .policy
= nl80211_policy
,
7408 .dumpit
= nl80211_dump_survey
,
7411 .cmd
= NL80211_CMD_SET_PMKSA
,
7412 .doit
= nl80211_setdel_pmksa
,
7413 .policy
= nl80211_policy
,
7414 .flags
= GENL_ADMIN_PERM
,
7415 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7416 NL80211_FLAG_NEED_RTNL
,
7419 .cmd
= NL80211_CMD_DEL_PMKSA
,
7420 .doit
= nl80211_setdel_pmksa
,
7421 .policy
= nl80211_policy
,
7422 .flags
= GENL_ADMIN_PERM
,
7423 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7424 NL80211_FLAG_NEED_RTNL
,
7427 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
7428 .doit
= nl80211_flush_pmksa
,
7429 .policy
= nl80211_policy
,
7430 .flags
= GENL_ADMIN_PERM
,
7431 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7432 NL80211_FLAG_NEED_RTNL
,
7435 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
7436 .doit
= nl80211_remain_on_channel
,
7437 .policy
= nl80211_policy
,
7438 .flags
= GENL_ADMIN_PERM
,
7439 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7440 NL80211_FLAG_NEED_RTNL
,
7443 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7444 .doit
= nl80211_cancel_remain_on_channel
,
7445 .policy
= nl80211_policy
,
7446 .flags
= GENL_ADMIN_PERM
,
7447 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7448 NL80211_FLAG_NEED_RTNL
,
7451 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
7452 .doit
= nl80211_set_tx_bitrate_mask
,
7453 .policy
= nl80211_policy
,
7454 .flags
= GENL_ADMIN_PERM
,
7455 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7456 NL80211_FLAG_NEED_RTNL
,
7459 .cmd
= NL80211_CMD_REGISTER_FRAME
,
7460 .doit
= nl80211_register_mgmt
,
7461 .policy
= nl80211_policy
,
7462 .flags
= GENL_ADMIN_PERM
,
7463 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7464 NL80211_FLAG_NEED_RTNL
,
7467 .cmd
= NL80211_CMD_FRAME
,
7468 .doit
= nl80211_tx_mgmt
,
7469 .policy
= nl80211_policy
,
7470 .flags
= GENL_ADMIN_PERM
,
7471 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7472 NL80211_FLAG_NEED_RTNL
,
7475 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
7476 .doit
= nl80211_tx_mgmt_cancel_wait
,
7477 .policy
= nl80211_policy
,
7478 .flags
= GENL_ADMIN_PERM
,
7479 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7480 NL80211_FLAG_NEED_RTNL
,
7483 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
7484 .doit
= nl80211_set_power_save
,
7485 .policy
= nl80211_policy
,
7486 .flags
= GENL_ADMIN_PERM
,
7487 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7488 NL80211_FLAG_NEED_RTNL
,
7491 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
7492 .doit
= nl80211_get_power_save
,
7493 .policy
= nl80211_policy
,
7494 /* can be retrieved by unprivileged users */
7495 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7496 NL80211_FLAG_NEED_RTNL
,
7499 .cmd
= NL80211_CMD_SET_CQM
,
7500 .doit
= nl80211_set_cqm
,
7501 .policy
= nl80211_policy
,
7502 .flags
= GENL_ADMIN_PERM
,
7503 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7504 NL80211_FLAG_NEED_RTNL
,
7507 .cmd
= NL80211_CMD_SET_CHANNEL
,
7508 .doit
= nl80211_set_channel
,
7509 .policy
= nl80211_policy
,
7510 .flags
= GENL_ADMIN_PERM
,
7511 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7512 NL80211_FLAG_NEED_RTNL
,
7515 .cmd
= NL80211_CMD_SET_WDS_PEER
,
7516 .doit
= nl80211_set_wds_peer
,
7517 .policy
= nl80211_policy
,
7518 .flags
= GENL_ADMIN_PERM
,
7519 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7520 NL80211_FLAG_NEED_RTNL
,
7523 .cmd
= NL80211_CMD_JOIN_MESH
,
7524 .doit
= nl80211_join_mesh
,
7525 .policy
= nl80211_policy
,
7526 .flags
= GENL_ADMIN_PERM
,
7527 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7528 NL80211_FLAG_NEED_RTNL
,
7531 .cmd
= NL80211_CMD_LEAVE_MESH
,
7532 .doit
= nl80211_leave_mesh
,
7533 .policy
= nl80211_policy
,
7534 .flags
= GENL_ADMIN_PERM
,
7535 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7536 NL80211_FLAG_NEED_RTNL
,
7540 .cmd
= NL80211_CMD_GET_WOWLAN
,
7541 .doit
= nl80211_get_wowlan
,
7542 .policy
= nl80211_policy
,
7543 /* can be retrieved by unprivileged users */
7544 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7545 NL80211_FLAG_NEED_RTNL
,
7548 .cmd
= NL80211_CMD_SET_WOWLAN
,
7549 .doit
= nl80211_set_wowlan
,
7550 .policy
= nl80211_policy
,
7551 .flags
= GENL_ADMIN_PERM
,
7552 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7553 NL80211_FLAG_NEED_RTNL
,
7557 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
7558 .doit
= nl80211_set_rekey_data
,
7559 .policy
= nl80211_policy
,
7560 .flags
= GENL_ADMIN_PERM
,
7561 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7562 NL80211_FLAG_NEED_RTNL
,
7565 .cmd
= NL80211_CMD_TDLS_MGMT
,
7566 .doit
= nl80211_tdls_mgmt
,
7567 .policy
= nl80211_policy
,
7568 .flags
= GENL_ADMIN_PERM
,
7569 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7570 NL80211_FLAG_NEED_RTNL
,
7573 .cmd
= NL80211_CMD_TDLS_OPER
,
7574 .doit
= nl80211_tdls_oper
,
7575 .policy
= nl80211_policy
,
7576 .flags
= GENL_ADMIN_PERM
,
7577 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7578 NL80211_FLAG_NEED_RTNL
,
7581 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
7582 .doit
= nl80211_register_unexpected_frame
,
7583 .policy
= nl80211_policy
,
7584 .flags
= GENL_ADMIN_PERM
,
7585 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7586 NL80211_FLAG_NEED_RTNL
,
7589 .cmd
= NL80211_CMD_PROBE_CLIENT
,
7590 .doit
= nl80211_probe_client
,
7591 .policy
= nl80211_policy
,
7592 .flags
= GENL_ADMIN_PERM
,
7593 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
7594 NL80211_FLAG_NEED_RTNL
,
7597 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
7598 .doit
= nl80211_register_beacons
,
7599 .policy
= nl80211_policy
,
7600 .flags
= GENL_ADMIN_PERM
,
7601 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
7602 NL80211_FLAG_NEED_RTNL
,
7605 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
7606 .doit
= nl80211_set_noack_map
,
7607 .policy
= nl80211_policy
,
7608 .flags
= GENL_ADMIN_PERM
,
7609 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
7610 NL80211_FLAG_NEED_RTNL
,
7613 .cmd
= NL80211_CMD_START_P2P_DEVICE
,
7614 .doit
= nl80211_start_p2p_device
,
7615 .policy
= nl80211_policy
,
7616 .flags
= GENL_ADMIN_PERM
,
7617 .internal_flags
= NL80211_FLAG_NEED_WDEV
|
7618 NL80211_FLAG_NEED_RTNL
,
7621 .cmd
= NL80211_CMD_STOP_P2P_DEVICE
,
7622 .doit
= nl80211_stop_p2p_device
,
7623 .policy
= nl80211_policy
,
7624 .flags
= GENL_ADMIN_PERM
,
7625 .internal_flags
= NL80211_FLAG_NEED_WDEV_UP
|
7626 NL80211_FLAG_NEED_RTNL
,
7630 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
7634 /* multicast groups */
7635 static struct genl_multicast_group nl80211_config_mcgrp
= {
7638 static struct genl_multicast_group nl80211_scan_mcgrp
= {
7641 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
7642 .name
= "regulatory",
7645 /* notification functions */
7647 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
7649 struct sk_buff
*msg
;
7651 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7655 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
7660 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7661 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
7664 static int nl80211_add_scan_req(struct sk_buff
*msg
,
7665 struct cfg80211_registered_device
*rdev
)
7667 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
7668 struct nlattr
*nest
;
7671 ASSERT_RDEV_LOCK(rdev
);
7676 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
7678 goto nla_put_failure
;
7679 for (i
= 0; i
< req
->n_ssids
; i
++) {
7680 if (nla_put(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
))
7681 goto nla_put_failure
;
7683 nla_nest_end(msg
, nest
);
7685 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
7687 goto nla_put_failure
;
7688 for (i
= 0; i
< req
->n_channels
; i
++) {
7689 if (nla_put_u32(msg
, i
, req
->channels
[i
]->center_freq
))
7690 goto nla_put_failure
;
7692 nla_nest_end(msg
, nest
);
7695 nla_put(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
))
7696 goto nla_put_failure
;
7699 nla_put_u32(msg
, NL80211_ATTR_SCAN_FLAGS
, req
->flags
);
7706 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
7707 struct cfg80211_registered_device
*rdev
,
7708 struct wireless_dev
*wdev
,
7709 u32 portid
, u32 seq
, int flags
,
7714 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7718 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7719 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
7720 wdev
->netdev
->ifindex
)) ||
7721 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)))
7722 goto nla_put_failure
;
7724 /* ignore errors and send incomplete event anyway */
7725 nl80211_add_scan_req(msg
, rdev
);
7727 return genlmsg_end(msg
, hdr
);
7730 genlmsg_cancel(msg
, hdr
);
7735 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
7736 struct cfg80211_registered_device
*rdev
,
7737 struct net_device
*netdev
,
7738 u32 portid
, u32 seq
, int flags
, u32 cmd
)
7742 hdr
= nl80211hdr_put(msg
, portid
, seq
, flags
, cmd
);
7746 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7747 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
7748 goto nla_put_failure
;
7750 return genlmsg_end(msg
, hdr
);
7753 genlmsg_cancel(msg
, hdr
);
7757 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
7758 struct wireless_dev
*wdev
)
7760 struct sk_buff
*msg
;
7762 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7766 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7767 NL80211_CMD_TRIGGER_SCAN
) < 0) {
7772 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7773 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7776 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
7777 struct wireless_dev
*wdev
)
7779 struct sk_buff
*msg
;
7781 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7785 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7786 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
7791 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7792 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7795 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
7796 struct wireless_dev
*wdev
)
7798 struct sk_buff
*msg
;
7800 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7804 if (nl80211_send_scan_msg(msg
, rdev
, wdev
, 0, 0, 0,
7805 NL80211_CMD_SCAN_ABORTED
) < 0) {
7810 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7811 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7814 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
7815 struct net_device
*netdev
)
7817 struct sk_buff
*msg
;
7819 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7823 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
7824 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
7829 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7830 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7833 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
7834 struct net_device
*netdev
, u32 cmd
)
7836 struct sk_buff
*msg
;
7838 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7842 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
7847 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7848 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
7852 * This can happen on global regulatory changes or device specific settings
7853 * based on custom world regulatory domains.
7855 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
7857 struct sk_buff
*msg
;
7860 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
7864 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
7870 /* Userspace can always count this one always being set */
7871 if (nla_put_u8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
))
7872 goto nla_put_failure
;
7874 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0') {
7875 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7876 NL80211_REGDOM_TYPE_WORLD
))
7877 goto nla_put_failure
;
7878 } else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9') {
7879 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7880 NL80211_REGDOM_TYPE_CUSTOM_WORLD
))
7881 goto nla_put_failure
;
7882 } else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
7883 request
->intersect
) {
7884 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7885 NL80211_REGDOM_TYPE_INTERSECTION
))
7886 goto nla_put_failure
;
7888 if (nla_put_u8(msg
, NL80211_ATTR_REG_TYPE
,
7889 NL80211_REGDOM_TYPE_COUNTRY
) ||
7890 nla_put_string(msg
, NL80211_ATTR_REG_ALPHA2
,
7892 goto nla_put_failure
;
7895 if (wiphy_idx_valid(request
->wiphy_idx
) &&
7896 nla_put_u32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
))
7897 goto nla_put_failure
;
7899 genlmsg_end(msg
, hdr
);
7902 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7909 genlmsg_cancel(msg
, hdr
);
7913 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7914 struct net_device
*netdev
,
7915 const u8
*buf
, size_t len
,
7916 enum nl80211_commands cmd
, gfp_t gfp
)
7918 struct sk_buff
*msg
;
7921 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7925 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7931 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
7932 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
7933 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
7934 goto nla_put_failure
;
7936 genlmsg_end(msg
, hdr
);
7938 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7939 nl80211_mlme_mcgrp
.id
, gfp
);
7943 genlmsg_cancel(msg
, hdr
);
7947 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7948 struct net_device
*netdev
, const u8
*buf
,
7949 size_t len
, gfp_t gfp
)
7951 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7952 NL80211_CMD_AUTHENTICATE
, gfp
);
7955 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7956 struct net_device
*netdev
, const u8
*buf
,
7957 size_t len
, gfp_t gfp
)
7959 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7960 NL80211_CMD_ASSOCIATE
, gfp
);
7963 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7964 struct net_device
*netdev
, const u8
*buf
,
7965 size_t len
, gfp_t gfp
)
7967 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7968 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7971 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7972 struct net_device
*netdev
, const u8
*buf
,
7973 size_t len
, gfp_t gfp
)
7975 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7976 NL80211_CMD_DISASSOCIATE
, gfp
);
7979 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7980 struct net_device
*netdev
, const u8
*buf
,
7981 size_t len
, gfp_t gfp
)
7983 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7984 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7987 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7988 struct net_device
*netdev
, const u8
*buf
,
7989 size_t len
, gfp_t gfp
)
7991 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7992 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7995 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7996 struct net_device
*netdev
, int cmd
,
7997 const u8
*addr
, gfp_t gfp
)
7999 struct sk_buff
*msg
;
8002 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8006 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8012 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8013 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8014 nla_put_flag(msg
, NL80211_ATTR_TIMED_OUT
) ||
8015 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8016 goto nla_put_failure
;
8018 genlmsg_end(msg
, hdr
);
8020 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8021 nl80211_mlme_mcgrp
.id
, gfp
);
8025 genlmsg_cancel(msg
, hdr
);
8029 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
8030 struct net_device
*netdev
, const u8
*addr
,
8033 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
8037 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
8038 struct net_device
*netdev
, const u8
*addr
,
8041 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
8045 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
8046 struct net_device
*netdev
, const u8
*bssid
,
8047 const u8
*req_ie
, size_t req_ie_len
,
8048 const u8
*resp_ie
, size_t resp_ie_len
,
8049 u16 status
, gfp_t gfp
)
8051 struct sk_buff
*msg
;
8054 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
8064 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8065 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8066 (bssid
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
)) ||
8067 nla_put_u16(msg
, NL80211_ATTR_STATUS_CODE
, status
) ||
8069 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8071 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8072 goto nla_put_failure
;
8074 genlmsg_end(msg
, hdr
);
8076 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8077 nl80211_mlme_mcgrp
.id
, gfp
);
8081 genlmsg_cancel(msg
, hdr
);
8086 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
8087 struct net_device
*netdev
, const u8
*bssid
,
8088 const u8
*req_ie
, size_t req_ie_len
,
8089 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
8091 struct sk_buff
*msg
;
8094 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8098 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
8104 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8105 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8106 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
) ||
8108 nla_put(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
)) ||
8110 nla_put(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
)))
8111 goto nla_put_failure
;
8113 genlmsg_end(msg
, hdr
);
8115 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8116 nl80211_mlme_mcgrp
.id
, gfp
);
8120 genlmsg_cancel(msg
, hdr
);
8125 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
8126 struct net_device
*netdev
, u16 reason
,
8127 const u8
*ie
, size_t ie_len
, bool from_ap
)
8129 struct sk_buff
*msg
;
8132 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
8136 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
8142 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8143 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8144 (from_ap
&& reason
&&
8145 nla_put_u16(msg
, NL80211_ATTR_REASON_CODE
, reason
)) ||
8147 nla_put_flag(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
)) ||
8148 (ie
&& nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8149 goto nla_put_failure
;
8151 genlmsg_end(msg
, hdr
);
8153 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8154 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
8158 genlmsg_cancel(msg
, hdr
);
8163 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
8164 struct net_device
*netdev
, const u8
*bssid
,
8167 struct sk_buff
*msg
;
8170 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8174 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
8180 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8181 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8182 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8183 goto nla_put_failure
;
8185 genlmsg_end(msg
, hdr
);
8187 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8188 nl80211_mlme_mcgrp
.id
, gfp
);
8192 genlmsg_cancel(msg
, hdr
);
8196 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
8197 struct net_device
*netdev
,
8198 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
8201 struct sk_buff
*msg
;
8204 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8208 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
8214 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8215 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8216 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
) ||
8218 nla_put(msg
, NL80211_ATTR_IE
, ie_len
, ie
)))
8219 goto nla_put_failure
;
8221 genlmsg_end(msg
, hdr
);
8223 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8224 nl80211_mlme_mcgrp
.id
, gfp
);
8228 genlmsg_cancel(msg
, hdr
);
8232 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
8233 struct net_device
*netdev
, const u8
*addr
,
8234 enum nl80211_key_type key_type
, int key_id
,
8235 const u8
*tsc
, gfp_t gfp
)
8237 struct sk_buff
*msg
;
8240 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8244 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
8250 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8251 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8252 (addr
&& nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
)) ||
8253 nla_put_u32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
) ||
8255 nla_put_u8(msg
, NL80211_ATTR_KEY_IDX
, key_id
)) ||
8256 (tsc
&& nla_put(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
)))
8257 goto nla_put_failure
;
8259 genlmsg_end(msg
, hdr
);
8261 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8262 nl80211_mlme_mcgrp
.id
, gfp
);
8266 genlmsg_cancel(msg
, hdr
);
8270 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
8271 struct ieee80211_channel
*channel_before
,
8272 struct ieee80211_channel
*channel_after
)
8274 struct sk_buff
*msg
;
8276 struct nlattr
*nl_freq
;
8278 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
8282 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
8289 * Since we are applying the beacon hint to a wiphy we know its
8290 * wiphy_idx is valid
8292 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
)))
8293 goto nla_put_failure
;
8296 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
8298 goto nla_put_failure
;
8299 if (nl80211_msg_put_channel(msg
, channel_before
))
8300 goto nla_put_failure
;
8301 nla_nest_end(msg
, nl_freq
);
8304 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
8306 goto nla_put_failure
;
8307 if (nl80211_msg_put_channel(msg
, channel_after
))
8308 goto nla_put_failure
;
8309 nla_nest_end(msg
, nl_freq
);
8311 genlmsg_end(msg
, hdr
);
8314 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
8321 genlmsg_cancel(msg
, hdr
);
8325 static void nl80211_send_remain_on_chan_event(
8326 int cmd
, struct cfg80211_registered_device
*rdev
,
8327 struct wireless_dev
*wdev
, u64 cookie
,
8328 struct ieee80211_channel
*chan
,
8329 enum nl80211_channel_type channel_type
,
8330 unsigned int duration
, gfp_t gfp
)
8332 struct sk_buff
*msg
;
8335 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8339 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8345 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8346 (wdev
->netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8347 wdev
->netdev
->ifindex
)) ||
8348 nla_put_u64(msg
, NL80211_ATTR_WDEV
, wdev_id(wdev
)) ||
8349 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
) ||
8350 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
) ||
8351 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
))
8352 goto nla_put_failure
;
8354 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
&&
8355 nla_put_u32(msg
, NL80211_ATTR_DURATION
, duration
))
8356 goto nla_put_failure
;
8358 genlmsg_end(msg
, hdr
);
8360 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8361 nl80211_mlme_mcgrp
.id
, gfp
);
8365 genlmsg_cancel(msg
, hdr
);
8369 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
8370 struct wireless_dev
*wdev
, u64 cookie
,
8371 struct ieee80211_channel
*chan
,
8372 enum nl80211_channel_type channel_type
,
8373 unsigned int duration
, gfp_t gfp
)
8375 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
8376 rdev
, wdev
, cookie
, chan
,
8377 channel_type
, duration
, gfp
);
8380 void nl80211_send_remain_on_channel_cancel(
8381 struct cfg80211_registered_device
*rdev
,
8382 struct wireless_dev
*wdev
,
8383 u64 cookie
, struct ieee80211_channel
*chan
,
8384 enum nl80211_channel_type channel_type
, gfp_t gfp
)
8386 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
8387 rdev
, wdev
, cookie
, chan
,
8388 channel_type
, 0, gfp
);
8391 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
8392 struct net_device
*dev
, const u8
*mac_addr
,
8393 struct station_info
*sinfo
, gfp_t gfp
)
8395 struct sk_buff
*msg
;
8397 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8401 if (nl80211_send_station(msg
, 0, 0, 0,
8402 rdev
, dev
, mac_addr
, sinfo
) < 0) {
8407 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8408 nl80211_mlme_mcgrp
.id
, gfp
);
8411 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
8412 struct net_device
*dev
, const u8
*mac_addr
,
8415 struct sk_buff
*msg
;
8418 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8422 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
8428 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8429 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
))
8430 goto nla_put_failure
;
8432 genlmsg_end(msg
, hdr
);
8434 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8435 nl80211_mlme_mcgrp
.id
, gfp
);
8439 genlmsg_cancel(msg
, hdr
);
8443 void nl80211_send_conn_failed_event(struct cfg80211_registered_device
*rdev
,
8444 struct net_device
*dev
, const u8
*mac_addr
,
8445 enum nl80211_connect_failed_reason reason
,
8448 struct sk_buff
*msg
;
8451 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8455 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONN_FAILED
);
8461 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8462 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
) ||
8463 nla_put_u32(msg
, NL80211_ATTR_CONN_FAILED_REASON
, reason
))
8464 goto nla_put_failure
;
8466 genlmsg_end(msg
, hdr
);
8468 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8469 nl80211_mlme_mcgrp
.id
, gfp
);
8473 genlmsg_cancel(msg
, hdr
);
8477 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
8478 const u8
*addr
, gfp_t gfp
)
8480 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8481 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8482 struct sk_buff
*msg
;
8485 u32 nlportid
= ACCESS_ONCE(wdev
->ap_unexpected_nlportid
);
8490 msg
= nlmsg_new(100, gfp
);
8494 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
8500 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8501 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8502 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
))
8503 goto nla_put_failure
;
8505 err
= genlmsg_end(msg
, hdr
);
8511 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8515 genlmsg_cancel(msg
, hdr
);
8520 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
8522 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
8526 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
8527 const u8
*addr
, gfp_t gfp
)
8529 return __nl80211_unexpected_frame(dev
,
8530 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
8534 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
8535 struct wireless_dev
*wdev
, u32 nlportid
,
8536 int freq
, int sig_dbm
,
8537 const u8
*buf
, size_t len
, gfp_t gfp
)
8539 struct net_device
*netdev
= wdev
->netdev
;
8540 struct sk_buff
*msg
;
8543 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8547 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8553 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8554 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8555 netdev
->ifindex
)) ||
8556 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8558 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8559 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
))
8560 goto nla_put_failure
;
8562 genlmsg_end(msg
, hdr
);
8564 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8567 genlmsg_cancel(msg
, hdr
);
8572 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
8573 struct wireless_dev
*wdev
, u64 cookie
,
8574 const u8
*buf
, size_t len
, bool ack
,
8577 struct net_device
*netdev
= wdev
->netdev
;
8578 struct sk_buff
*msg
;
8581 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8585 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
8591 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8592 (netdev
&& nla_put_u32(msg
, NL80211_ATTR_IFINDEX
,
8593 netdev
->ifindex
)) ||
8594 nla_put(msg
, NL80211_ATTR_FRAME
, len
, buf
) ||
8595 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8596 (ack
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8597 goto nla_put_failure
;
8599 genlmsg_end(msg
, hdr
);
8601 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
8605 genlmsg_cancel(msg
, hdr
);
8610 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
8611 struct net_device
*netdev
,
8612 enum nl80211_cqm_rssi_threshold_event rssi_event
,
8615 struct sk_buff
*msg
;
8616 struct nlattr
*pinfoattr
;
8619 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8623 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8629 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8630 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8631 goto nla_put_failure
;
8633 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8635 goto nla_put_failure
;
8637 if (nla_put_u32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
8639 goto nla_put_failure
;
8641 nla_nest_end(msg
, pinfoattr
);
8643 genlmsg_end(msg
, hdr
);
8645 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8646 nl80211_mlme_mcgrp
.id
, gfp
);
8650 genlmsg_cancel(msg
, hdr
);
8654 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
8655 struct net_device
*netdev
, const u8
*bssid
,
8656 const u8
*replay_ctr
, gfp_t gfp
)
8658 struct sk_buff
*msg
;
8659 struct nlattr
*rekey_attr
;
8662 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8666 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
8672 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8673 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8674 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
))
8675 goto nla_put_failure
;
8677 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
8679 goto nla_put_failure
;
8681 if (nla_put(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
8682 NL80211_REPLAY_CTR_LEN
, replay_ctr
))
8683 goto nla_put_failure
;
8685 nla_nest_end(msg
, rekey_attr
);
8687 genlmsg_end(msg
, hdr
);
8689 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8690 nl80211_mlme_mcgrp
.id
, gfp
);
8694 genlmsg_cancel(msg
, hdr
);
8698 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
8699 struct net_device
*netdev
, int index
,
8700 const u8
*bssid
, bool preauth
, gfp_t gfp
)
8702 struct sk_buff
*msg
;
8703 struct nlattr
*attr
;
8706 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8710 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
8716 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8717 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
))
8718 goto nla_put_failure
;
8720 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
8722 goto nla_put_failure
;
8724 if (nla_put_u32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
) ||
8725 nla_put(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
) ||
8727 nla_put_flag(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
)))
8728 goto nla_put_failure
;
8730 nla_nest_end(msg
, attr
);
8732 genlmsg_end(msg
, hdr
);
8734 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8735 nl80211_mlme_mcgrp
.id
, gfp
);
8739 genlmsg_cancel(msg
, hdr
);
8743 void nl80211_ch_switch_notify(struct cfg80211_registered_device
*rdev
,
8744 struct net_device
*netdev
, int freq
,
8745 enum nl80211_channel_type type
, gfp_t gfp
)
8747 struct sk_buff
*msg
;
8750 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8754 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY
);
8760 if (nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8761 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
) ||
8762 nla_put_u32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, type
))
8763 goto nla_put_failure
;
8765 genlmsg_end(msg
, hdr
);
8767 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8768 nl80211_mlme_mcgrp
.id
, gfp
);
8772 genlmsg_cancel(msg
, hdr
);
8777 nl80211_send_cqm_txe_notify(struct cfg80211_registered_device
*rdev
,
8778 struct net_device
*netdev
, const u8
*peer
,
8779 u32 num_packets
, u32 rate
, u32 intvl
, gfp_t gfp
)
8781 struct sk_buff
*msg
;
8782 struct nlattr
*pinfoattr
;
8785 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
8789 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8795 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8796 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8797 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8798 goto nla_put_failure
;
8800 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8802 goto nla_put_failure
;
8804 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_PKTS
, num_packets
))
8805 goto nla_put_failure
;
8807 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_RATE
, rate
))
8808 goto nla_put_failure
;
8810 if (nla_put_u32(msg
, NL80211_ATTR_CQM_TXE_INTVL
, intvl
))
8811 goto nla_put_failure
;
8813 nla_nest_end(msg
, pinfoattr
);
8815 genlmsg_end(msg
, hdr
);
8817 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8818 nl80211_mlme_mcgrp
.id
, gfp
);
8822 genlmsg_cancel(msg
, hdr
);
8827 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
8828 struct net_device
*netdev
, const u8
*peer
,
8829 u32 num_packets
, gfp_t gfp
)
8831 struct sk_buff
*msg
;
8832 struct nlattr
*pinfoattr
;
8835 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8839 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
8845 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8846 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
) ||
8847 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
))
8848 goto nla_put_failure
;
8850 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
8852 goto nla_put_failure
;
8854 if (nla_put_u32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
))
8855 goto nla_put_failure
;
8857 nla_nest_end(msg
, pinfoattr
);
8859 genlmsg_end(msg
, hdr
);
8861 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8862 nl80211_mlme_mcgrp
.id
, gfp
);
8866 genlmsg_cancel(msg
, hdr
);
8870 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
8871 u64 cookie
, bool acked
, gfp_t gfp
)
8873 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
8874 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
8875 struct sk_buff
*msg
;
8879 trace_cfg80211_probe_status(dev
, addr
, cookie
, acked
);
8881 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
8886 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
8892 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8893 nla_put_u32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
) ||
8894 nla_put(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
) ||
8895 nla_put_u64(msg
, NL80211_ATTR_COOKIE
, cookie
) ||
8896 (acked
&& nla_put_flag(msg
, NL80211_ATTR_ACK
)))
8897 goto nla_put_failure
;
8899 err
= genlmsg_end(msg
, hdr
);
8905 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
8906 nl80211_mlme_mcgrp
.id
, gfp
);
8910 genlmsg_cancel(msg
, hdr
);
8913 EXPORT_SYMBOL(cfg80211_probe_status
);
8915 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
8916 const u8
*frame
, size_t len
,
8917 int freq
, int sig_dbm
, gfp_t gfp
)
8919 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
8920 struct sk_buff
*msg
;
8922 u32 nlportid
= ACCESS_ONCE(rdev
->ap_beacons_nlportid
);
8924 trace_cfg80211_report_obss_beacon(wiphy
, frame
, len
, freq
, sig_dbm
);
8929 msg
= nlmsg_new(len
+ 100, gfp
);
8933 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
8939 if (nla_put_u32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
) ||
8941 nla_put_u32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
)) ||
8943 nla_put_u32(msg
, NL80211_ATTR_RX_SIGNAL_DBM
, sig_dbm
)) ||
8944 nla_put(msg
, NL80211_ATTR_FRAME
, len
, frame
))
8945 goto nla_put_failure
;
8947 genlmsg_end(msg
, hdr
);
8949 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlportid
);
8953 genlmsg_cancel(msg
, hdr
);
8956 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
8958 static int nl80211_netlink_notify(struct notifier_block
* nb
,
8959 unsigned long state
,
8962 struct netlink_notify
*notify
= _notify
;
8963 struct cfg80211_registered_device
*rdev
;
8964 struct wireless_dev
*wdev
;
8966 if (state
!= NETLINK_URELEASE
)
8971 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
8972 list_for_each_entry_rcu(wdev
, &rdev
->wdev_list
, list
)
8973 cfg80211_mlme_unregister_socket(wdev
, notify
->portid
);
8974 if (rdev
->ap_beacons_nlportid
== notify
->portid
)
8975 rdev
->ap_beacons_nlportid
= 0;
8983 static struct notifier_block nl80211_netlink_notifier
= {
8984 .notifier_call
= nl80211_netlink_notify
,
8987 /* initialisation/exit functions */
8989 int nl80211_init(void)
8993 err
= genl_register_family_with_ops(&nl80211_fam
,
8994 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
8998 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
9002 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
9006 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
9010 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
9014 #ifdef CONFIG_NL80211_TESTMODE
9015 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
9020 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
9026 genl_unregister_family(&nl80211_fam
);
9030 void nl80211_exit(void)
9032 netlink_unregister_notifier(&nl80211_netlink_notifier
);
9033 genl_unregister_family(&nl80211_fam
);