Merge remote-tracking branch 'wireless-next/master' into mac80211-next
[deliverable/linux.git] / net / wireless / core.h
CommitLineData
704232c2
JB
1/*
2 * Wireless configuration interface internals.
3 *
5f2aa25e 4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
704232c2
JB
5 */
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>
2a519311
JB
11#include <linux/kref.h>
12#include <linux/rbtree.h>
1ac61302 13#include <linux/debugfs.h>
1f87f7d3
JB
14#include <linux/rfkill.h>
15#include <linux/workqueue.h>
704232c2 16#include <net/genetlink.h>
704232c2 17#include <net/cfg80211.h>
3f2355cb 18#include "reg.h"
704232c2
JB
19
20struct cfg80211_registered_device {
3dcf670b 21 const struct cfg80211_ops *ops;
704232c2
JB
22 struct list_head list;
23 /* we hold this mutex during any call so that
24 * we cannot do multiple calls at once, and also
25 * to avoid the deregister call to proceed while
26 * any call is in progress */
27 struct mutex mtx;
28
1f87f7d3
JB
29 /* rfkill support */
30 struct rfkill_ops rfkill_ops;
31 struct rfkill *rfkill;
32 struct work_struct rfkill_sync;
33
3f2355cb
LR
34 /* ISO / IEC 3166 alpha2 for which this device is receiving
35 * country IEs on, this can help disregard country IEs from APs
36 * on the same alpha2 quickly. The alpha2 may differ from
37 * cfg80211_regdomain's alpha2 when an intersection has occurred.
38 * If the AP is reconfigured this can also be used to tell us if
39 * the country on the country IE changed. */
40 char country_ie_alpha2[2];
41
42 /* If a Country IE has been received this tells us the environment
43 * which its telling us its in. This defaults to ENVIRON_ANY */
44 enum environment_cap env;
45
704232c2 46 /* wiphy index, internal only */
b5850a7a 47 int wiphy_idx;
704232c2
JB
48
49 /* associate netdev list */
50 struct mutex devlist_mtx;
5f2aa25e 51 /* protected by devlist_mtx or RCU */
704232c2 52 struct list_head netdev_list;
f5ea9120 53 int devlist_generation;
ad002395
JB
54 int opencount; /* also protected by devlist_mtx */
55 wait_queue_head_t dev_wait;
704232c2 56
5e760230
JB
57 u32 ap_beacons_nlpid;
58
2a519311
JB
59 /* BSSes/scanning */
60 spinlock_t bss_lock;
61 struct list_head bss_list;
62 struct rb_root bss_tree;
63 u32 bss_generation;
64 struct cfg80211_scan_request *scan_req; /* protected by RTNL */
807f8a8c 65 struct cfg80211_sched_scan_request *sched_scan_req;
cb3a8eec 66 unsigned long suspend_at;
667503dd 67 struct work_struct scan_done_wk;
807f8a8c 68 struct work_struct sched_scan_results_wk;
2a519311 69
c10841ca
LC
70 struct mutex sched_scan_mtx;
71
aff89a9b
JB
72#ifdef CONFIG_NL80211_TESTMODE
73 struct genl_info *testmode_info;
74#endif
75
6829c878 76 struct work_struct conn_work;
667503dd 77 struct work_struct event_work;
6829c878 78
ff1b6e69
JB
79 struct cfg80211_wowlan *wowlan;
80
704232c2
JB
81 /* must be last because of the way we do wiphy_priv(),
82 * and it should at least be aligned to NETDEV_ALIGN */
83 struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
84};
85
86static inline
87struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
88{
89 BUG_ON(!wiphy);
90 return container_of(wiphy, struct cfg80211_registered_device, wiphy);
91}
92
85fd129a
LR
93/* Note 0 is valid, hence phy0 */
94static inline
95bool wiphy_idx_valid(int wiphy_idx)
96{
a02cec21 97 return wiphy_idx >= 0;
85fd129a
LR
98}
99
ff1b6e69
JB
100static inline void
101cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
102{
103 int i;
104
105 if (!rdev->wowlan)
106 return;
107 for (i = 0; i < rdev->wowlan->n_patterns; i++)
108 kfree(rdev->wowlan->patterns[i].mask);
109 kfree(rdev->wowlan->patterns);
110 kfree(rdev->wowlan);
111}
e60d7443
AB
112
113extern struct workqueue_struct *cfg80211_wq;
a1794390 114extern struct mutex cfg80211_mutex;
79c97e97 115extern struct list_head cfg80211_rdev_list;
f5ea9120 116extern int cfg80211_rdev_list_generation;
704232c2 117
46a5ebaf
JB
118static inline void assert_cfg80211_lock(void)
119{
120 lockdep_assert_held(&cfg80211_mutex);
121}
761cf7ec 122
806a9e39
LR
123/*
124 * You can use this to mark a wiphy_idx as not having an associated wiphy.
79c97e97 125 * It guarantees cfg80211_rdev_by_wiphy_idx(wiphy_idx) will return NULL
806a9e39
LR
126 */
127#define WIPHY_IDX_STALE -1
128
2a519311
JB
129struct cfg80211_internal_bss {
130 struct list_head list;
131 struct rb_node rbn;
132 unsigned long ts;
133 struct kref ref;
19957bb3 134 atomic_t hold;
34a6eddb
JM
135 bool beacon_ies_allocated;
136 bool proberesp_ies_allocated;
a08c1c1a 137
2a519311
JB
138 /* must be last because of priv member */
139 struct cfg80211_bss pub;
140};
141
19957bb3
JB
142static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
143{
144 return container_of(pub, struct cfg80211_internal_bss, pub);
145}
146
147static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
148{
149 atomic_inc(&bss->hold);
150}
151
152static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
153{
154 int r = atomic_dec_return(&bss->hold);
155 WARN_ON(r < 0);
156}
157
158
79c97e97 159struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
806a9e39
LR
160int get_wiphy_idx(struct wiphy *wiphy);
161
79c97e97 162/* requires cfg80211_rdev_mutex to be held! */
806a9e39
LR
163struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
164
55682965
JB
165/* identical to cfg80211_get_dev_from_info but only operate on ifindex */
166extern struct cfg80211_registered_device *
463d0183
JB
167cfg80211_get_dev_from_ifindex(struct net *net, int ifindex);
168
169int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
170 struct net *net);
55682965 171
79c97e97 172static inline void cfg80211_lock_rdev(struct cfg80211_registered_device *rdev)
667503dd 173{
79c97e97 174 mutex_lock(&rdev->mtx);
667503dd
JB
175}
176
79c97e97 177static inline void cfg80211_unlock_rdev(struct cfg80211_registered_device *rdev)
4d0c8aea 178{
79c97e97
JB
179 BUG_ON(IS_ERR(rdev) || !rdev);
180 mutex_unlock(&rdev->mtx);
4d0c8aea 181}
55682965 182
667503dd
JB
183static inline void wdev_lock(struct wireless_dev *wdev)
184 __acquires(wdev)
185{
186 mutex_lock(&wdev->mtx);
187 __acquire(wdev->mtx);
188}
189
190static inline void wdev_unlock(struct wireless_dev *wdev)
191 __releases(wdev)
192{
193 __release(wdev->mtx);
194 mutex_unlock(&wdev->mtx);
195}
196
46a5ebaf
JB
197#define ASSERT_RDEV_LOCK(rdev) lockdep_assert_held(&(rdev)->mtx)
198#define ASSERT_WDEV_LOCK(wdev) lockdep_assert_held(&(wdev)->mtx)
667503dd
JB
199
200enum cfg80211_event_type {
201 EVENT_CONNECT_RESULT,
202 EVENT_ROAMED,
203 EVENT_DISCONNECTED,
204 EVENT_IBSS_JOINED,
205};
206
207struct cfg80211_event {
208 struct list_head list;
209 enum cfg80211_event_type type;
210
211 union {
212 struct {
213 u8 bssid[ETH_ALEN];
214 const u8 *req_ie;
215 const u8 *resp_ie;
216 size_t req_ie_len;
217 size_t resp_ie_len;
218 u16 status;
219 } cr;
220 struct {
667503dd
JB
221 const u8 *req_ie;
222 const u8 *resp_ie;
223 size_t req_ie_len;
224 size_t resp_ie_len;
adbde344 225 struct cfg80211_bss *bss;
667503dd
JB
226 } rm;
227 struct {
228 const u8 *ie;
229 size_t ie_len;
230 u16 reason;
231 } dc;
232 struct {
233 u8 bssid[ETH_ALEN];
234 } ij;
235 };
236};
237
fffd0934
JB
238struct cfg80211_cached_keys {
239 struct key_params params[6];
240 u8 data[6][WLAN_MAX_KEY_LEN];
241 int def, defmgmt;
242};
243
667503dd 244
704232c2 245/* free object */
79c97e97 246extern void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
704232c2 247
79c97e97 248extern int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
55682965
JB
249 char *newname);
250
8318d78a 251void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
8318d78a 252
2a519311 253void cfg80211_bss_expire(struct cfg80211_registered_device *dev);
cb3a8eec
DW
254void cfg80211_bss_age(struct cfg80211_registered_device *dev,
255 unsigned long age_secs);
2a519311 256
04a773ad 257/* IBSS */
667503dd
JB
258int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
259 struct net_device *dev,
fffd0934
JB
260 struct cfg80211_ibss_params *params,
261 struct cfg80211_cached_keys *connkeys);
04a773ad
JB
262int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
263 struct net_device *dev,
fffd0934
JB
264 struct cfg80211_ibss_params *params,
265 struct cfg80211_cached_keys *connkeys);
9d308429 266void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
98d3a7ca
JB
267int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
268 struct net_device *dev, bool nowext);
04a773ad 269int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
9d308429 270 struct net_device *dev, bool nowext);
667503dd 271void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
fffd0934
JB
272int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
273 struct wireless_dev *wdev);
04a773ad 274
29cbe68c
JB
275/* mesh */
276extern const struct mesh_config default_mesh_config;
c80d545d 277extern const struct mesh_setup default_mesh_setup;
29cbe68c
JB
278int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
279 struct net_device *dev,
cc1d2806 280 struct mesh_setup *setup,
29cbe68c
JB
281 const struct mesh_config *conf);
282int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
283 struct net_device *dev,
cc1d2806 284 struct mesh_setup *setup,
29cbe68c
JB
285 const struct mesh_config *conf);
286int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
287 struct net_device *dev);
cc1d2806
JB
288int cfg80211_set_mesh_freq(struct cfg80211_registered_device *rdev,
289 struct wireless_dev *wdev, int freq,
290 enum nl80211_channel_type channel_type);
29cbe68c 291
19957bb3 292/* MLME */
667503dd
JB
293int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
294 struct net_device *dev,
295 struct ieee80211_channel *chan,
296 enum nl80211_auth_type auth_type,
297 const u8 *bssid,
298 const u8 *ssid, int ssid_len,
fffd0934 299 const u8 *ie, int ie_len,
95de817b 300 const u8 *key, int key_len, int key_idx);
19957bb3
JB
301int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
302 struct net_device *dev, struct ieee80211_channel *chan,
303 enum nl80211_auth_type auth_type, const u8 *bssid,
304 const u8 *ssid, int ssid_len,
fffd0934 305 const u8 *ie, int ie_len,
95de817b 306 const u8 *key, int key_len, int key_idx);
667503dd
JB
307int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
308 struct net_device *dev,
309 struct ieee80211_channel *chan,
310 const u8 *bssid, const u8 *prev_bssid,
311 const u8 *ssid, int ssid_len,
312 const u8 *ie, int ie_len, bool use_mfp,
7e7c8926
BG
313 struct cfg80211_crypto_settings *crypt,
314 u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
315 struct ieee80211_ht_cap *ht_capa_mask);
19957bb3
JB
316int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
317 struct net_device *dev, struct ieee80211_channel *chan,
3e5d7649
JB
318 const u8 *bssid, const u8 *prev_bssid,
319 const u8 *ssid, int ssid_len,
19957bb3 320 const u8 *ie, int ie_len, bool use_mfp,
7e7c8926
BG
321 struct cfg80211_crypto_settings *crypt,
322 u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
323 struct ieee80211_ht_cap *ht_capa_mask);
667503dd
JB
324int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
325 struct net_device *dev, const u8 *bssid,
d5cdfacb
JM
326 const u8 *ie, int ie_len, u16 reason,
327 bool local_state_change);
19957bb3
JB
328int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
329 struct net_device *dev, const u8 *bssid,
d5cdfacb
JM
330 const u8 *ie, int ie_len, u16 reason,
331 bool local_state_change);
19957bb3
JB
332int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
333 struct net_device *dev, const u8 *bssid,
d5cdfacb
JM
334 const u8 *ie, int ie_len, u16 reason,
335 bool local_state_change);
19957bb3
JB
336void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
337 struct net_device *dev);
667503dd
JB
338void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
339 const u8 *req_ie, size_t req_ie_len,
340 const u8 *resp_ie, size_t resp_ie_len,
df7fc0f9
JB
341 u16 status, bool wextev,
342 struct cfg80211_bss *bss);
2e161f78
JB
343int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
344 u16 frame_type, const u8 *match_data,
345 int match_len);
346void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid);
347void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev);
348int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
349 struct net_device *dev,
f7ca38df 350 struct ieee80211_channel *chan, bool offchan,
2e161f78 351 enum nl80211_channel_type channel_type,
f7ca38df 352 bool channel_type_valid, unsigned int wait,
e9f935e3 353 const u8 *buf, size_t len, bool no_cck,
e247bd90 354 bool dont_wait_for_ack, u64 *cookie);
7e7c8926
BG
355void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
356 const struct ieee80211_ht_cap *ht_capa_mask);
19957bb3 357
b23aa676 358/* SME */
667503dd
JB
359int __cfg80211_connect(struct cfg80211_registered_device *rdev,
360 struct net_device *dev,
fffd0934 361 struct cfg80211_connect_params *connect,
f401a6f7
JB
362 struct cfg80211_cached_keys *connkeys,
363 const u8 *prev_bssid);
b23aa676
SO
364int cfg80211_connect(struct cfg80211_registered_device *rdev,
365 struct net_device *dev,
fffd0934
JB
366 struct cfg80211_connect_params *connect,
367 struct cfg80211_cached_keys *connkeys);
667503dd
JB
368int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
369 struct net_device *dev, u16 reason,
370 bool wextev);
b23aa676 371int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
f2129354
JB
372 struct net_device *dev, u16 reason,
373 bool wextev);
ed9d0102 374void __cfg80211_roamed(struct wireless_dev *wdev,
adbde344 375 struct cfg80211_bss *bss,
667503dd
JB
376 const u8 *req_ie, size_t req_ie_len,
377 const u8 *resp_ie, size_t resp_ie_len);
fffd0934
JB
378int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
379 struct wireless_dev *wdev);
b23aa676 380
6829c878 381void cfg80211_conn_work(struct work_struct *work);
7d930bc3 382void cfg80211_sme_failed_assoc(struct wireless_dev *wdev);
f401a6f7 383bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev);
6829c878 384
08645126 385/* internal helpers */
38ba3c57 386bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher);
fffd0934
JB
387int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
388 struct key_params *params, int key_idx,
e31b8213 389 bool pairwise, const u8 *mac_addr);
667503dd 390void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
6829c878
JB
391 size_t ie_len, u16 reason, bool from_ap);
392void cfg80211_sme_scan_done(struct net_device *dev);
393void cfg80211_sme_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
95de817b
JB
394void cfg80211_sme_disassoc(struct net_device *dev,
395 struct cfg80211_internal_bss *bss);
667503dd 396void __cfg80211_scan_done(struct work_struct *wk);
01a0ac41 397void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak);
807f8a8c
LC
398void __cfg80211_sched_scan_results(struct work_struct *wk);
399int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
400 bool driver_initiated);
fffd0934 401void cfg80211_upload_connect_keys(struct wireless_dev *wdev);
3d54d255
JB
402int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
403 struct net_device *dev, enum nl80211_iftype ntype,
404 u32 *flags, struct vif_params *params);
405void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
08645126 406
7527a782
JB
407int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
408 struct wireless_dev *wdev,
409 enum nl80211_iftype iftype);
410
411static inline int
412cfg80211_can_add_interface(struct cfg80211_registered_device *rdev,
413 enum nl80211_iftype iftype)
414{
415 return cfg80211_can_change_interface(rdev, NULL, iftype);
416}
417
9588bbd5
JM
418struct ieee80211_channel *
419rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
420 int freq, enum nl80211_channel_type channel_type);
e8c9bd5b
JB
421int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
422 int freq, enum nl80211_channel_type chantype);
59bbb6f7 423
34850ab2
JB
424int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
425 const u8 *rates, unsigned int n_rates,
426 u32 *mask);
427
56d1893d
JB
428int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
429 u32 beacon_int);
430
f7969969
JB
431#ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
432#define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
433#else
434/*
435 * Trick to enable using it as a condition,
436 * and also not give a warning when it's
437 * not used that way.
438 */
439#define CFG80211_DEV_WARN_ON(cond) ({bool __r = (cond); __r; })
440#endif
441
704232c2 442#endif /* __NET_WIRELESS_CORE_H */
This page took 0.706873 seconds and 5 git commands to generate.