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