ipv6: avoid unregistering inet6_dev for loopback
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / 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/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>
18 #include "reg.h"
19
20
21 #define WIPHY_IDX_INVALID -1
22
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 */
30 struct mutex mtx;
31
32 /* rfkill support */
33 struct rfkill_ops rfkill_ops;
34 struct rfkill *rfkill;
35 struct work_struct rfkill_sync;
36
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];
44
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;
48
49 /* wiphy index, internal only */
50 int wiphy_idx;
51
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;
59
60 struct list_head beacon_registrations;
61 spinlock_t beacon_registrations_lock;
62
63 /* protected by RTNL only */
64 int num_running_ifaces;
65 int num_running_monitor_ifaces;
66
67 /* BSSes/scanning */
68 spinlock_t bss_lock;
69 struct list_head bss_list;
70 struct rb_root bss_tree;
71 u32 bss_generation;
72 u32 bss_entries;
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;
78
79 struct mutex sched_scan_mtx;
80
81 #ifdef CONFIG_NL80211_TESTMODE
82 struct genl_info *testmode_info;
83 #endif
84
85 struct work_struct conn_work;
86 struct work_struct event_work;
87
88 struct cfg80211_wowlan *wowlan;
89
90 struct delayed_work dfs_update_channels_wk;
91
92 /* netlink port which started critical protocol (0 means not started) */
93 u32 crit_proto_nlportid;
94
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);
98 };
99
100 static inline
101 struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
102 {
103 BUG_ON(!wiphy);
104 return container_of(wiphy, struct cfg80211_registered_device, wiphy);
105 }
106
107 static inline void
108 cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
109 {
110 int i;
111
112 if (!rdev->wowlan)
113 return;
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);
120 kfree(rdev->wowlan);
121 }
122
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;
127
128 static inline void assert_cfg80211_lock(void)
129 {
130 lockdep_assert_held(&cfg80211_mutex);
131 }
132
133 struct cfg80211_internal_bss {
134 struct list_head list;
135 struct list_head hidden_list;
136 struct rb_node rbn;
137 unsigned long ts;
138 unsigned long refcount;
139 atomic_t hold;
140
141 /* must be last because of priv member */
142 struct cfg80211_bss pub;
143 };
144
145 static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
146 {
147 return container_of(pub, struct cfg80211_internal_bss, pub);
148 }
149
150 static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
151 {
152 atomic_inc(&bss->hold);
153 }
154
155 static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
156 {
157 int r = atomic_dec_return(&bss->hold);
158 WARN_ON(r < 0);
159 }
160
161
162 struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
163 int get_wiphy_idx(struct wiphy *wiphy);
164
165 /* requires cfg80211_rdev_mutex to be held! */
166 struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
167
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);
171
172 int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
173 struct net *net);
174
175 static inline void cfg80211_lock_rdev(struct cfg80211_registered_device *rdev)
176 {
177 mutex_lock(&rdev->mtx);
178 }
179
180 static inline void cfg80211_unlock_rdev(struct cfg80211_registered_device *rdev)
181 {
182 BUG_ON(IS_ERR(rdev) || !rdev);
183 mutex_unlock(&rdev->mtx);
184 }
185
186 static inline void wdev_lock(struct wireless_dev *wdev)
187 __acquires(wdev)
188 {
189 mutex_lock(&wdev->mtx);
190 __acquire(wdev->mtx);
191 }
192
193 static inline void wdev_unlock(struct wireless_dev *wdev)
194 __releases(wdev)
195 {
196 __release(wdev->mtx);
197 mutex_unlock(&wdev->mtx);
198 }
199
200 #define ASSERT_RDEV_LOCK(rdev) lockdep_assert_held(&(rdev)->mtx)
201 #define ASSERT_WDEV_LOCK(wdev) lockdep_assert_held(&(wdev)->mtx)
202
203 static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device *rdev)
204 {
205 ASSERT_RTNL();
206
207 return rdev->num_running_ifaces == rdev->num_running_monitor_ifaces &&
208 rdev->num_running_ifaces > 0;
209 }
210
211 enum cfg80211_event_type {
212 EVENT_CONNECT_RESULT,
213 EVENT_ROAMED,
214 EVENT_DISCONNECTED,
215 EVENT_IBSS_JOINED,
216 };
217
218 struct cfg80211_event {
219 struct list_head list;
220 enum cfg80211_event_type type;
221
222 union {
223 struct {
224 u8 bssid[ETH_ALEN];
225 const u8 *req_ie;
226 const u8 *resp_ie;
227 size_t req_ie_len;
228 size_t resp_ie_len;
229 u16 status;
230 } cr;
231 struct {
232 const u8 *req_ie;
233 const u8 *resp_ie;
234 size_t req_ie_len;
235 size_t resp_ie_len;
236 struct cfg80211_bss *bss;
237 } rm;
238 struct {
239 const u8 *ie;
240 size_t ie_len;
241 u16 reason;
242 } dc;
243 struct {
244 u8 bssid[ETH_ALEN];
245 } ij;
246 };
247 };
248
249 struct cfg80211_cached_keys {
250 struct key_params params[6];
251 u8 data[6][WLAN_MAX_KEY_LEN];
252 int def, defmgmt;
253 };
254
255 enum cfg80211_chan_mode {
256 CHAN_MODE_UNDEFINED,
257 CHAN_MODE_SHARED,
258 CHAN_MODE_EXCLUSIVE,
259 };
260
261 struct cfg80211_beacon_registration {
262 struct list_head list;
263 u32 nlportid;
264 };
265
266 /* free object */
267 extern void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
268
269 extern int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
270 char *newname);
271
272 void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
273
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);
277
278 /* IBSS */
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);
295
296 /* mesh */
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);
312
313 /* AP */
314 int cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
315 struct net_device *dev);
316
317 /* MLME */
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,
322 const u8 *bssid,
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,
337 const u8 *bssid,
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,
343 const u8 *bssid,
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,
367 int match_len);
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);
379
380 /* SME */
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,
392 bool wextev);
393 int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
394 struct net_device *dev, u16 reason,
395 bool wextev);
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);
402
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);
406
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);
429
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,
435 u8 radar_detect);
436
437 /**
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
442 */
443 int cfg80211_chandef_dfs_required(struct wiphy *wiphy,
444 const struct cfg80211_chan_def *c);
445
446 void cfg80211_set_dfs_state(struct wiphy *wiphy,
447 const struct cfg80211_chan_def *chandef,
448 enum nl80211_dfs_state dfs_state);
449
450 void cfg80211_dfs_channels_update_work(struct work_struct *work);
451
452
453 static inline int
454 cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
455 struct wireless_dev *wdev,
456 enum nl80211_iftype iftype)
457 {
458 return cfg80211_can_use_iftype_chan(rdev, wdev, iftype, NULL,
459 CHAN_MODE_UNDEFINED, 0);
460 }
461
462 static inline int
463 cfg80211_can_add_interface(struct cfg80211_registered_device *rdev,
464 enum nl80211_iftype iftype)
465 {
466 return cfg80211_can_change_interface(rdev, NULL, iftype);
467 }
468
469 static inline int
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)
474 {
475 return cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
476 chan, chanmode, 0);
477 }
478
479 static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
480 {
481 unsigned long end = jiffies;
482
483 if (end >= start)
484 return jiffies_to_msecs(end - start);
485
486 return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
487 }
488
489 void
490 cfg80211_get_chan_state(struct wireless_dev *wdev,
491 struct ieee80211_channel **chan,
492 enum cfg80211_chan_mode *chanmode);
493
494 int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
495 struct cfg80211_chan_def *chandef);
496
497 int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
498 const u8 *rates, unsigned int n_rates,
499 u32 *mask);
500
501 int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
502 u32 beacon_int);
503
504 void cfg80211_update_iface_num(struct cfg80211_registered_device *rdev,
505 enum nl80211_iftype iftype, int num);
506
507 void cfg80211_leave(struct cfg80211_registered_device *rdev,
508 struct wireless_dev *wdev);
509
510 void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
511 struct wireless_dev *wdev);
512
513 #define CFG80211_MAX_NUM_DIFFERENT_CHANNELS 10
514
515 #ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
516 #define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
517 #else
518 /*
519 * Trick to enable using it as a condition,
520 * and also not give a warning when it's
521 * not used that way.
522 */
523 #define CFG80211_DEV_WARN_ON(cond) ({bool __r = (cond); __r; })
524 #endif
525
526 #endif /* __NET_WIRELESS_CORE_H */