core.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Wireless configuration interface internals.
  3. *
  4. * Copyright 2006-2009 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 <net/genetlink.h>
  17. #include <net/cfg80211.h>
  18. #include "reg.h"
  19. struct cfg80211_registered_device {
  20. const struct cfg80211_ops *ops;
  21. struct list_head list;
  22. /* we hold this mutex during any call so that
  23. * we cannot do multiple calls at once, and also
  24. * to avoid the deregister call to proceed while
  25. * any call is in progress */
  26. struct mutex mtx;
  27. /* rfkill support */
  28. struct rfkill_ops rfkill_ops;
  29. struct rfkill *rfkill;
  30. struct work_struct rfkill_sync;
  31. /* ISO / IEC 3166 alpha2 for which this device is receiving
  32. * country IEs on, this can help disregard country IEs from APs
  33. * on the same alpha2 quickly. The alpha2 may differ from
  34. * cfg80211_regdomain's alpha2 when an intersection has occurred.
  35. * If the AP is reconfigured this can also be used to tell us if
  36. * the country on the country IE changed. */
  37. char country_ie_alpha2[2];
  38. /* If a Country IE has been received this tells us the environment
  39. * which its telling us its in. This defaults to ENVIRON_ANY */
  40. enum environment_cap env;
  41. /* wiphy index, internal only */
  42. int wiphy_idx;
  43. /* associate netdev list */
  44. struct mutex devlist_mtx;
  45. struct list_head netdev_list;
  46. /* BSSes/scanning */
  47. spinlock_t bss_lock;
  48. struct list_head bss_list;
  49. struct rb_root bss_tree;
  50. u32 bss_generation;
  51. struct cfg80211_scan_request *scan_req; /* protected by RTNL */
  52. unsigned long suspend_at;
  53. #ifdef CONFIG_NL80211_TESTMODE
  54. struct genl_info *testmode_info;
  55. #endif
  56. struct work_struct conn_work;
  57. #ifdef CONFIG_CFG80211_DEBUGFS
  58. /* Debugfs entries */
  59. struct wiphy_debugfsdentries {
  60. struct dentry *rts_threshold;
  61. struct dentry *fragmentation_threshold;
  62. struct dentry *short_retry_limit;
  63. struct dentry *long_retry_limit;
  64. struct dentry *ht40allow_map;
  65. } debugfs;
  66. #endif
  67. /* must be last because of the way we do wiphy_priv(),
  68. * and it should at least be aligned to NETDEV_ALIGN */
  69. struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
  70. };
  71. static inline
  72. struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
  73. {
  74. BUG_ON(!wiphy);
  75. return container_of(wiphy, struct cfg80211_registered_device, wiphy);
  76. }
  77. /* Note 0 is valid, hence phy0 */
  78. static inline
  79. bool wiphy_idx_valid(int wiphy_idx)
  80. {
  81. return (wiphy_idx >= 0);
  82. }
  83. extern struct mutex cfg80211_mutex;
  84. extern struct list_head cfg80211_drv_list;
  85. #define assert_cfg80211_lock() WARN_ON(!mutex_is_locked(&cfg80211_mutex))
  86. /*
  87. * You can use this to mark a wiphy_idx as not having an associated wiphy.
  88. * It guarantees cfg80211_drv_by_wiphy_idx(wiphy_idx) will return NULL
  89. */
  90. #define WIPHY_IDX_STALE -1
  91. struct cfg80211_internal_bss {
  92. struct list_head list;
  93. struct rb_node rbn;
  94. unsigned long ts;
  95. struct kref ref;
  96. atomic_t hold;
  97. bool ies_allocated;
  98. /* must be last because of priv member */
  99. struct cfg80211_bss pub;
  100. };
  101. static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
  102. {
  103. return container_of(pub, struct cfg80211_internal_bss, pub);
  104. }
  105. static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
  106. {
  107. atomic_inc(&bss->hold);
  108. }
  109. static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
  110. {
  111. int r = atomic_dec_return(&bss->hold);
  112. WARN_ON(r < 0);
  113. }
  114. struct cfg80211_registered_device *cfg80211_drv_by_wiphy_idx(int wiphy_idx);
  115. int get_wiphy_idx(struct wiphy *wiphy);
  116. struct cfg80211_registered_device *
  117. __cfg80211_drv_from_info(struct genl_info *info);
  118. /*
  119. * This function returns a pointer to the driver
  120. * that the genl_info item that is passed refers to.
  121. * If successful, it returns non-NULL and also locks
  122. * the driver's mutex!
  123. *
  124. * This means that you need to call cfg80211_put_dev()
  125. * before being allowed to acquire &cfg80211_mutex!
  126. *
  127. * This is necessary because we need to lock the global
  128. * mutex to get an item off the list safely, and then
  129. * we lock the drv mutex so it doesn't go away under us.
  130. *
  131. * We don't want to keep cfg80211_mutex locked
  132. * for all the time in order to allow requests on
  133. * other interfaces to go through at the same time.
  134. *
  135. * The result of this can be a PTR_ERR and hence must
  136. * be checked with IS_ERR() for errors.
  137. */
  138. extern struct cfg80211_registered_device *
  139. cfg80211_get_dev_from_info(struct genl_info *info);
  140. /* requires cfg80211_drv_mutex to be held! */
  141. struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
  142. /* identical to cfg80211_get_dev_from_info but only operate on ifindex */
  143. extern struct cfg80211_registered_device *
  144. cfg80211_get_dev_from_ifindex(int ifindex);
  145. extern void cfg80211_put_dev(struct cfg80211_registered_device *drv);
  146. /* free object */
  147. extern void cfg80211_dev_free(struct cfg80211_registered_device *drv);
  148. extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv,
  149. char *newname);
  150. void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
  151. void wiphy_update_regulatory(struct wiphy *wiphy,
  152. enum nl80211_reg_initiator setby);
  153. void cfg80211_bss_expire(struct cfg80211_registered_device *dev);
  154. void cfg80211_bss_age(struct cfg80211_registered_device *dev,
  155. unsigned long age_secs);
  156. /* IBSS */
  157. int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
  158. struct net_device *dev,
  159. struct cfg80211_ibss_params *params);
  160. void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
  161. int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  162. struct net_device *dev, bool nowext);
  163. /* MLME */
  164. int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  165. struct net_device *dev, struct ieee80211_channel *chan,
  166. enum nl80211_auth_type auth_type, const u8 *bssid,
  167. const u8 *ssid, int ssid_len,
  168. const u8 *ie, int ie_len);
  169. int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  170. struct net_device *dev, struct ieee80211_channel *chan,
  171. const u8 *bssid, const u8 *prev_bssid,
  172. const u8 *ssid, int ssid_len,
  173. const u8 *ie, int ie_len, bool use_mfp,
  174. struct cfg80211_crypto_settings *crypt);
  175. int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  176. struct net_device *dev, const u8 *bssid,
  177. const u8 *ie, int ie_len, u16 reason);
  178. int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
  179. struct net_device *dev, const u8 *bssid,
  180. const u8 *ie, int ie_len, u16 reason);
  181. void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
  182. struct net_device *dev);
  183. /* SME */
  184. int cfg80211_connect(struct cfg80211_registered_device *rdev,
  185. struct net_device *dev,
  186. struct cfg80211_connect_params *connect);
  187. int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
  188. struct net_device *dev, u16 reason,
  189. bool wextev);
  190. void cfg80211_conn_work(struct work_struct *work);
  191. /* internal helpers */
  192. int cfg80211_validate_key_settings(struct key_params *params, int key_idx,
  193. const u8 *mac_addr);
  194. void __cfg80211_disconnected(struct net_device *dev, gfp_t gfp, u8 *ie,
  195. size_t ie_len, u16 reason, bool from_ap);
  196. void cfg80211_sme_scan_done(struct net_device *dev);
  197. void cfg80211_sme_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
  198. void cfg80211_sme_disassoc(struct net_device *dev, int idx);
  199. #endif /* __NET_WIRELESS_CORE_H */