2 * Wireless configuration interface internals.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
6 #ifndef __NET_WIRELESS_CORE_H
7 #define __NET_WIRELESS_CORE_H
8 #include <linux/mutex.h>
9 #include <linux/list.h>
10 #include <linux/netdevice.h>
11 #include <linux/rbtree.h>
12 #include <linux/debugfs.h>
13 #include <linux/rfkill.h>
14 #include <linux/workqueue.h>
15 #include <linux/rtnetlink.h>
16 #include <net/genetlink.h>
17 #include <net/cfg80211.h>
21 #define WIPHY_IDX_INVALID -1
23 struct cfg80211_registered_device
{
24 const struct cfg80211_ops
*ops
;
25 struct list_head list
;
26 /* we hold this mutex during any call so that
27 * we cannot do multiple calls at once, and also
28 * to avoid the deregister call to proceed while
29 * any call is in progress */
33 struct rfkill_ops rfkill_ops
;
34 struct rfkill
*rfkill
;
35 struct work_struct rfkill_sync
;
37 /* ISO / IEC 3166 alpha2 for which this device is receiving
38 * country IEs on, this can help disregard country IEs from APs
39 * on the same alpha2 quickly. The alpha2 may differ from
40 * cfg80211_regdomain's alpha2 when an intersection has occurred.
41 * If the AP is reconfigured this can also be used to tell us if
42 * the country on the country IE changed. */
43 char country_ie_alpha2
[2];
45 /* If a Country IE has been received this tells us the environment
46 * which its telling us its in. This defaults to ENVIRON_ANY */
47 enum environment_cap env
;
49 /* wiphy index, internal only */
52 /* associated wireless interfaces */
53 struct mutex devlist_mtx
;
54 /* protected by devlist_mtx or RCU */
55 struct list_head wdev_list
;
56 int devlist_generation
, wdev_id
;
57 int opencount
; /* also protected by devlist_mtx */
58 wait_queue_head_t dev_wait
;
60 struct list_head beacon_registrations
;
61 spinlock_t beacon_registrations_lock
;
63 /* protected by RTNL only */
64 int num_running_ifaces
;
65 int num_running_monitor_ifaces
;
69 struct list_head bss_list
;
70 struct rb_root bss_tree
;
73 struct cfg80211_scan_request
*scan_req
; /* protected by RTNL */
74 struct cfg80211_sched_scan_request
*sched_scan_req
;
75 unsigned long suspend_at
;
76 struct work_struct scan_done_wk
;
77 struct work_struct sched_scan_results_wk
;
79 struct mutex sched_scan_mtx
;
81 #ifdef CONFIG_NL80211_TESTMODE
82 struct genl_info
*testmode_info
;
85 struct work_struct conn_work
;
86 struct work_struct event_work
;
88 struct cfg80211_wowlan
*wowlan
;
90 struct delayed_work dfs_update_channels_wk
;
92 /* netlink port which started critical protocol (0 means not started) */
93 u32 crit_proto_nlportid
;
95 /* must be last because of the way we do wiphy_priv(),
96 * and it should at least be aligned to NETDEV_ALIGN */
97 struct wiphy wiphy
__aligned(NETDEV_ALIGN
);
101 struct cfg80211_registered_device
*wiphy_to_dev(struct wiphy
*wiphy
)
104 return container_of(wiphy
, struct cfg80211_registered_device
, wiphy
);
108 cfg80211_rdev_free_wowlan(struct cfg80211_registered_device
*rdev
)
114 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++)
115 kfree(rdev
->wowlan
->patterns
[i
].mask
);
116 kfree(rdev
->wowlan
->patterns
);
117 if (rdev
->wowlan
->tcp
&& rdev
->wowlan
->tcp
->sock
)
118 sock_release(rdev
->wowlan
->tcp
->sock
);
119 kfree(rdev
->wowlan
->tcp
);
123 extern struct workqueue_struct
*cfg80211_wq
;
124 extern struct mutex cfg80211_mutex
;
125 extern struct list_head cfg80211_rdev_list
;
126 extern int cfg80211_rdev_list_generation
;
128 static inline void assert_cfg80211_lock(void)
130 lockdep_assert_held(&cfg80211_mutex
);
133 struct cfg80211_internal_bss
{
134 struct list_head list
;
135 struct list_head hidden_list
;
138 unsigned long refcount
;
141 /* must be last because of priv member */
142 struct cfg80211_bss pub
;
145 static inline struct cfg80211_internal_bss
*bss_from_pub(struct cfg80211_bss
*pub
)
147 return container_of(pub
, struct cfg80211_internal_bss
, pub
);
150 static inline void cfg80211_hold_bss(struct cfg80211_internal_bss
*bss
)
152 atomic_inc(&bss
->hold
);
155 static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss
*bss
)
157 int r
= atomic_dec_return(&bss
->hold
);
162 struct cfg80211_registered_device
*cfg80211_rdev_by_wiphy_idx(int wiphy_idx
);
163 int get_wiphy_idx(struct wiphy
*wiphy
);
165 /* requires cfg80211_rdev_mutex to be held! */
166 struct wiphy
*wiphy_idx_to_wiphy(int wiphy_idx
);
168 /* identical to cfg80211_get_dev_from_info but only operate on ifindex */
169 extern struct cfg80211_registered_device
*
170 cfg80211_get_dev_from_ifindex(struct net
*net
, int ifindex
);
172 int cfg80211_switch_netns(struct cfg80211_registered_device
*rdev
,
175 static inline void cfg80211_lock_rdev(struct cfg80211_registered_device
*rdev
)
177 mutex_lock(&rdev
->mtx
);
180 static inline void cfg80211_unlock_rdev(struct cfg80211_registered_device
*rdev
)
182 BUG_ON(IS_ERR(rdev
) || !rdev
);
183 mutex_unlock(&rdev
->mtx
);
186 static inline void wdev_lock(struct wireless_dev
*wdev
)
189 mutex_lock(&wdev
->mtx
);
190 __acquire(wdev
->mtx
);
193 static inline void wdev_unlock(struct wireless_dev
*wdev
)
196 __release(wdev
->mtx
);
197 mutex_unlock(&wdev
->mtx
);
200 #define ASSERT_RDEV_LOCK(rdev) lockdep_assert_held(&(rdev)->mtx)
201 #define ASSERT_WDEV_LOCK(wdev) lockdep_assert_held(&(wdev)->mtx)
203 static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device
*rdev
)
207 return rdev
->num_running_ifaces
== rdev
->num_running_monitor_ifaces
&&
208 rdev
->num_running_ifaces
> 0;
211 enum cfg80211_event_type
{
212 EVENT_CONNECT_RESULT
,
218 struct cfg80211_event
{
219 struct list_head list
;
220 enum cfg80211_event_type type
;
236 struct cfg80211_bss
*bss
;
249 struct cfg80211_cached_keys
{
250 struct key_params params
[6];
251 u8 data
[6][WLAN_MAX_KEY_LEN
];
255 enum cfg80211_chan_mode
{
261 struct cfg80211_beacon_registration
{
262 struct list_head list
;
267 extern void cfg80211_dev_free(struct cfg80211_registered_device
*rdev
);
269 extern int cfg80211_dev_rename(struct cfg80211_registered_device
*rdev
,
272 void ieee80211_set_bitrate_flags(struct wiphy
*wiphy
);
274 void cfg80211_bss_expire(struct cfg80211_registered_device
*dev
);
275 void cfg80211_bss_age(struct cfg80211_registered_device
*dev
,
276 unsigned long age_secs
);
279 int __cfg80211_join_ibss(struct cfg80211_registered_device
*rdev
,
280 struct net_device
*dev
,
281 struct cfg80211_ibss_params
*params
,
282 struct cfg80211_cached_keys
*connkeys
);
283 int cfg80211_join_ibss(struct cfg80211_registered_device
*rdev
,
284 struct net_device
*dev
,
285 struct cfg80211_ibss_params
*params
,
286 struct cfg80211_cached_keys
*connkeys
);
287 void cfg80211_clear_ibss(struct net_device
*dev
, bool nowext
);
288 int __cfg80211_leave_ibss(struct cfg80211_registered_device
*rdev
,
289 struct net_device
*dev
, bool nowext
);
290 int cfg80211_leave_ibss(struct cfg80211_registered_device
*rdev
,
291 struct net_device
*dev
, bool nowext
);
292 void __cfg80211_ibss_joined(struct net_device
*dev
, const u8
*bssid
);
293 int cfg80211_ibss_wext_join(struct cfg80211_registered_device
*rdev
,
294 struct wireless_dev
*wdev
);
297 extern const struct mesh_config default_mesh_config
;
298 extern const struct mesh_setup default_mesh_setup
;
299 int __cfg80211_join_mesh(struct cfg80211_registered_device
*rdev
,
300 struct net_device
*dev
,
301 struct mesh_setup
*setup
,
302 const struct mesh_config
*conf
);
303 int cfg80211_join_mesh(struct cfg80211_registered_device
*rdev
,
304 struct net_device
*dev
,
305 struct mesh_setup
*setup
,
306 const struct mesh_config
*conf
);
307 int cfg80211_leave_mesh(struct cfg80211_registered_device
*rdev
,
308 struct net_device
*dev
);
309 int cfg80211_set_mesh_channel(struct cfg80211_registered_device
*rdev
,
310 struct wireless_dev
*wdev
,
311 struct cfg80211_chan_def
*chandef
);
314 int cfg80211_stop_ap(struct cfg80211_registered_device
*rdev
,
315 struct net_device
*dev
);
318 int __cfg80211_mlme_auth(struct cfg80211_registered_device
*rdev
,
319 struct net_device
*dev
,
320 struct ieee80211_channel
*chan
,
321 enum nl80211_auth_type auth_type
,
323 const u8
*ssid
, int ssid_len
,
324 const u8
*ie
, int ie_len
,
325 const u8
*key
, int key_len
, int key_idx
,
326 const u8
*sae_data
, int sae_data_len
);
327 int cfg80211_mlme_auth(struct cfg80211_registered_device
*rdev
,
328 struct net_device
*dev
, struct ieee80211_channel
*chan
,
329 enum nl80211_auth_type auth_type
, const u8
*bssid
,
330 const u8
*ssid
, int ssid_len
,
331 const u8
*ie
, int ie_len
,
332 const u8
*key
, int key_len
, int key_idx
,
333 const u8
*sae_data
, int sae_data_len
);
334 int __cfg80211_mlme_assoc(struct cfg80211_registered_device
*rdev
,
335 struct net_device
*dev
,
336 struct ieee80211_channel
*chan
,
338 const u8
*ssid
, int ssid_len
,
339 struct cfg80211_assoc_request
*req
);
340 int cfg80211_mlme_assoc(struct cfg80211_registered_device
*rdev
,
341 struct net_device
*dev
,
342 struct ieee80211_channel
*chan
,
344 const u8
*ssid
, int ssid_len
,
345 struct cfg80211_assoc_request
*req
);
346 int __cfg80211_mlme_deauth(struct cfg80211_registered_device
*rdev
,
347 struct net_device
*dev
, const u8
*bssid
,
348 const u8
*ie
, int ie_len
, u16 reason
,
349 bool local_state_change
);
350 int cfg80211_mlme_deauth(struct cfg80211_registered_device
*rdev
,
351 struct net_device
*dev
, const u8
*bssid
,
352 const u8
*ie
, int ie_len
, u16 reason
,
353 bool local_state_change
);
354 int cfg80211_mlme_disassoc(struct cfg80211_registered_device
*rdev
,
355 struct net_device
*dev
, const u8
*bssid
,
356 const u8
*ie
, int ie_len
, u16 reason
,
357 bool local_state_change
);
358 void cfg80211_mlme_down(struct cfg80211_registered_device
*rdev
,
359 struct net_device
*dev
);
360 void __cfg80211_connect_result(struct net_device
*dev
, const u8
*bssid
,
361 const u8
*req_ie
, size_t req_ie_len
,
362 const u8
*resp_ie
, size_t resp_ie_len
,
363 u16 status
, bool wextev
,
364 struct cfg80211_bss
*bss
);
365 int cfg80211_mlme_register_mgmt(struct wireless_dev
*wdev
, u32 snd_pid
,
366 u16 frame_type
, const u8
*match_data
,
368 void cfg80211_mlme_unregister_socket(struct wireless_dev
*wdev
, u32 nlpid
);
369 void cfg80211_mlme_purge_registrations(struct wireless_dev
*wdev
);
370 int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device
*rdev
,
371 struct wireless_dev
*wdev
,
372 struct ieee80211_channel
*chan
, bool offchan
,
373 unsigned int wait
, const u8
*buf
, size_t len
,
374 bool no_cck
, bool dont_wait_for_ack
, u64
*cookie
);
375 void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap
*ht_capa
,
376 const struct ieee80211_ht_cap
*ht_capa_mask
);
377 void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap
*vht_capa
,
378 const struct ieee80211_vht_cap
*vht_capa_mask
);
381 int __cfg80211_connect(struct cfg80211_registered_device
*rdev
,
382 struct net_device
*dev
,
383 struct cfg80211_connect_params
*connect
,
384 struct cfg80211_cached_keys
*connkeys
,
385 const u8
*prev_bssid
);
386 int cfg80211_connect(struct cfg80211_registered_device
*rdev
,
387 struct net_device
*dev
,
388 struct cfg80211_connect_params
*connect
,
389 struct cfg80211_cached_keys
*connkeys
);
390 int __cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
391 struct net_device
*dev
, u16 reason
,
393 int cfg80211_disconnect(struct cfg80211_registered_device
*rdev
,
394 struct net_device
*dev
, u16 reason
,
396 void __cfg80211_roamed(struct wireless_dev
*wdev
,
397 struct cfg80211_bss
*bss
,
398 const u8
*req_ie
, size_t req_ie_len
,
399 const u8
*resp_ie
, size_t resp_ie_len
);
400 int cfg80211_mgd_wext_connect(struct cfg80211_registered_device
*rdev
,
401 struct wireless_dev
*wdev
);
403 void cfg80211_conn_work(struct work_struct
*work
);
404 void cfg80211_sme_failed_assoc(struct wireless_dev
*wdev
);
405 bool cfg80211_sme_failed_reassoc(struct wireless_dev
*wdev
);
407 /* internal helpers */
408 bool cfg80211_supported_cipher_suite(struct wiphy
*wiphy
, u32 cipher
);
409 int cfg80211_validate_key_settings(struct cfg80211_registered_device
*rdev
,
410 struct key_params
*params
, int key_idx
,
411 bool pairwise
, const u8
*mac_addr
);
412 void __cfg80211_disconnected(struct net_device
*dev
, const u8
*ie
,
413 size_t ie_len
, u16 reason
, bool from_ap
);
414 void cfg80211_sme_scan_done(struct net_device
*dev
);
415 void cfg80211_sme_rx_auth(struct net_device
*dev
, const u8
*buf
, size_t len
);
416 void cfg80211_sme_disassoc(struct net_device
*dev
,
417 struct cfg80211_internal_bss
*bss
);
418 void __cfg80211_scan_done(struct work_struct
*wk
);
419 void ___cfg80211_scan_done(struct cfg80211_registered_device
*rdev
, bool leak
);
420 void __cfg80211_sched_scan_results(struct work_struct
*wk
);
421 int __cfg80211_stop_sched_scan(struct cfg80211_registered_device
*rdev
,
422 bool driver_initiated
);
423 void cfg80211_upload_connect_keys(struct wireless_dev
*wdev
);
424 int cfg80211_change_iface(struct cfg80211_registered_device
*rdev
,
425 struct net_device
*dev
, enum nl80211_iftype ntype
,
426 u32
*flags
, struct vif_params
*params
);
427 void cfg80211_process_rdev_events(struct cfg80211_registered_device
*rdev
);
428 void cfg80211_process_wdev_events(struct wireless_dev
*wdev
);
430 int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device
*rdev
,
431 struct wireless_dev
*wdev
,
432 enum nl80211_iftype iftype
,
433 struct ieee80211_channel
*chan
,
434 enum cfg80211_chan_mode chanmode
,
438 * cfg80211_chandef_dfs_required - checks if radar detection is required
439 * @wiphy: the wiphy to validate against
440 * @chandef: the channel definition to check
441 * Return: 1 if radar detection is required, 0 if it is not, < 0 on error
443 int cfg80211_chandef_dfs_required(struct wiphy
*wiphy
,
444 const struct cfg80211_chan_def
*c
);
446 void cfg80211_set_dfs_state(struct wiphy
*wiphy
,
447 const struct cfg80211_chan_def
*chandef
,
448 enum nl80211_dfs_state dfs_state
);
450 void cfg80211_dfs_channels_update_work(struct work_struct
*work
);
454 cfg80211_can_change_interface(struct cfg80211_registered_device
*rdev
,
455 struct wireless_dev
*wdev
,
456 enum nl80211_iftype iftype
)
458 return cfg80211_can_use_iftype_chan(rdev
, wdev
, iftype
, NULL
,
459 CHAN_MODE_UNDEFINED
, 0);
463 cfg80211_can_add_interface(struct cfg80211_registered_device
*rdev
,
464 enum nl80211_iftype iftype
)
466 return cfg80211_can_change_interface(rdev
, NULL
, iftype
);
470 cfg80211_can_use_chan(struct cfg80211_registered_device
*rdev
,
471 struct wireless_dev
*wdev
,
472 struct ieee80211_channel
*chan
,
473 enum cfg80211_chan_mode chanmode
)
475 return cfg80211_can_use_iftype_chan(rdev
, wdev
, wdev
->iftype
,
479 static inline unsigned int elapsed_jiffies_msecs(unsigned long start
)
481 unsigned long end
= jiffies
;
484 return jiffies_to_msecs(end
- start
);
486 return jiffies_to_msecs(end
+ (MAX_JIFFY_OFFSET
- start
) + 1);
490 cfg80211_get_chan_state(struct wireless_dev
*wdev
,
491 struct ieee80211_channel
**chan
,
492 enum cfg80211_chan_mode
*chanmode
);
494 int cfg80211_set_monitor_channel(struct cfg80211_registered_device
*rdev
,
495 struct cfg80211_chan_def
*chandef
);
497 int ieee80211_get_ratemask(struct ieee80211_supported_band
*sband
,
498 const u8
*rates
, unsigned int n_rates
,
501 int cfg80211_validate_beacon_int(struct cfg80211_registered_device
*rdev
,
504 void cfg80211_update_iface_num(struct cfg80211_registered_device
*rdev
,
505 enum nl80211_iftype iftype
, int num
);
507 void cfg80211_leave(struct cfg80211_registered_device
*rdev
,
508 struct wireless_dev
*wdev
);
510 void cfg80211_stop_p2p_device(struct cfg80211_registered_device
*rdev
,
511 struct wireless_dev
*wdev
);
513 #define CFG80211_MAX_NUM_DIFFERENT_CHANNELS 10
515 #ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
516 #define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
519 * Trick to enable using it as a condition,
520 * and also not give a warning when it's
523 #define CFG80211_DEV_WARN_ON(cond) ({bool __r = (cond); __r; })
526 #endif /* __NET_WIRELESS_CORE_H */