core.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. struct work_struct scan_done_wk;
  54. #ifdef CONFIG_NL80211_TESTMODE
  55. struct genl_info *testmode_info;
  56. #endif
  57. struct work_struct conn_work;
  58. struct work_struct event_work;
  59. #ifdef CONFIG_CFG80211_DEBUGFS
  60. /* Debugfs entries */
  61. struct wiphy_debugfsdentries {
  62. struct dentry *rts_threshold;
  63. struct dentry *fragmentation_threshold;
  64. struct dentry *short_retry_limit;
  65. struct dentry *long_retry_limit;
  66. struct dentry *ht40allow_map;
  67. } debugfs;
  68. #endif
  69. /* must be last because of the way we do wiphy_priv(),
  70. * and it should at least be aligned to NETDEV_ALIGN */
  71. struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
  72. };
  73. static inline
  74. struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
  75. {
  76. BUG_ON(!wiphy);
  77. return container_of(wiphy, struct cfg80211_registered_device, wiphy);
  78. }
  79. /* Note 0 is valid, hence phy0 */
  80. static inline
  81. bool wiphy_idx_valid(int wiphy_idx)
  82. {
  83. return (wiphy_idx >= 0);
  84. }
  85. extern struct mutex cfg80211_mutex;
  86. extern struct list_head cfg80211_rdev_list;
  87. #define assert_cfg80211_lock() WARN_ON(!mutex_is_locked(&cfg80211_mutex))
  88. /*
  89. * You can use this to mark a wiphy_idx as not having an associated wiphy.
  90. * It guarantees cfg80211_rdev_by_wiphy_idx(wiphy_idx) will return NULL
  91. */
  92. #define WIPHY_IDX_STALE -1
  93. struct cfg80211_internal_bss {
  94. struct list_head list;
  95. struct rb_node rbn;
  96. unsigned long ts;
  97. struct kref ref;
  98. atomic_t hold;
  99. bool ies_allocated;
  100. /* must be last because of priv member */
  101. struct cfg80211_bss pub;
  102. };
  103. static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
  104. {
  105. return container_of(pub, struct cfg80211_internal_bss, pub);
  106. }
  107. static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
  108. {
  109. atomic_inc(&bss->hold);
  110. }
  111. static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
  112. {
  113. int r = atomic_dec_return(&bss->hold);
  114. WARN_ON(r < 0);
  115. }
  116. struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
  117. int get_wiphy_idx(struct wiphy *wiphy);
  118. struct cfg80211_registered_device *
  119. __cfg80211_rdev_from_info(struct genl_info *info);
  120. /*
  121. * This function returns a pointer to the driver
  122. * that the genl_info item that is passed refers to.
  123. * If successful, it returns non-NULL and also locks
  124. * the driver's mutex!
  125. *
  126. * This means that you need to call cfg80211_unlock_rdev()
  127. * before being allowed to acquire &cfg80211_mutex!
  128. *
  129. * This is necessary because we need to lock the global
  130. * mutex to get an item off the list safely, and then
  131. * we lock the rdev mutex so it doesn't go away under us.
  132. *
  133. * We don't want to keep cfg80211_mutex locked
  134. * for all the time in order to allow requests on
  135. * other interfaces to go through at the same time.
  136. *
  137. * The result of this can be a PTR_ERR and hence must
  138. * be checked with IS_ERR() for errors.
  139. */
  140. extern struct cfg80211_registered_device *
  141. cfg80211_get_dev_from_info(struct genl_info *info);
  142. /* requires cfg80211_rdev_mutex to be held! */
  143. struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
  144. /* identical to cfg80211_get_dev_from_info but only operate on ifindex */
  145. extern struct cfg80211_registered_device *
  146. cfg80211_get_dev_from_ifindex(int ifindex);
  147. static inline void cfg80211_lock_rdev(struct cfg80211_registered_device *rdev)
  148. {
  149. mutex_lock(&rdev->mtx);
  150. }
  151. static inline void cfg80211_unlock_rdev(struct cfg80211_registered_device *rdev)
  152. {
  153. BUG_ON(IS_ERR(rdev) || !rdev);
  154. mutex_unlock(&rdev->mtx);
  155. }
  156. static inline void wdev_lock(struct wireless_dev *wdev)
  157. __acquires(wdev)
  158. {
  159. mutex_lock(&wdev->mtx);
  160. __acquire(wdev->mtx);
  161. }
  162. static inline void wdev_unlock(struct wireless_dev *wdev)
  163. __releases(wdev)
  164. {
  165. __release(wdev->mtx);
  166. mutex_unlock(&wdev->mtx);
  167. }
  168. #define ASSERT_RDEV_LOCK(rdev) WARN_ON(!mutex_is_locked(&(rdev)->mtx));
  169. #define ASSERT_WDEV_LOCK(wdev) WARN_ON(!mutex_is_locked(&(wdev)->mtx));
  170. enum cfg80211_event_type {
  171. EVENT_CONNECT_RESULT,
  172. EVENT_ROAMED,
  173. EVENT_DISCONNECTED,
  174. EVENT_IBSS_JOINED,
  175. };
  176. struct cfg80211_event {
  177. struct list_head list;
  178. enum cfg80211_event_type type;
  179. union {
  180. struct {
  181. u8 bssid[ETH_ALEN];
  182. const u8 *req_ie;
  183. const u8 *resp_ie;
  184. size_t req_ie_len;
  185. size_t resp_ie_len;
  186. u16 status;
  187. } cr;
  188. struct {
  189. u8 bssid[ETH_ALEN];
  190. const u8 *req_ie;
  191. const u8 *resp_ie;
  192. size_t req_ie_len;
  193. size_t resp_ie_len;
  194. } rm;
  195. struct {
  196. const u8 *ie;
  197. size_t ie_len;
  198. u16 reason;
  199. } dc;
  200. struct {
  201. u8 bssid[ETH_ALEN];
  202. } ij;
  203. };
  204. };
  205. /* free object */
  206. extern void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
  207. extern int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
  208. char *newname);
  209. void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
  210. void wiphy_update_regulatory(struct wiphy *wiphy,
  211. enum nl80211_reg_initiator setby);
  212. void cfg80211_bss_expire(struct cfg80211_registered_device *dev);
  213. void cfg80211_bss_age(struct cfg80211_registered_device *dev,
  214. unsigned long age_secs);
  215. /* IBSS */
  216. int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
  217. struct net_device *dev,
  218. struct cfg80211_ibss_params *params);
  219. int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
  220. struct net_device *dev,
  221. struct cfg80211_ibss_params *params);
  222. void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
  223. int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  224. struct net_device *dev, bool nowext);
  225. void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
  226. /* MLME */
  227. int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  228. struct net_device *dev,
  229. struct ieee80211_channel *chan,
  230. enum nl80211_auth_type auth_type,
  231. const u8 *bssid,
  232. const u8 *ssid, int ssid_len,
  233. const u8 *ie, int ie_len);
  234. int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  235. struct net_device *dev, struct ieee80211_channel *chan,
  236. enum nl80211_auth_type auth_type, const u8 *bssid,
  237. const u8 *ssid, int ssid_len,
  238. const u8 *ie, int ie_len);
  239. int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  240. struct net_device *dev,
  241. struct ieee80211_channel *chan,
  242. const u8 *bssid, const u8 *prev_bssid,
  243. const u8 *ssid, int ssid_len,
  244. const u8 *ie, int ie_len, bool use_mfp,
  245. struct cfg80211_crypto_settings *crypt);
  246. int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  247. struct net_device *dev, struct ieee80211_channel *chan,
  248. const u8 *bssid, const u8 *prev_bssid,
  249. const u8 *ssid, int ssid_len,
  250. const u8 *ie, int ie_len, bool use_mfp,
  251. struct cfg80211_crypto_settings *crypt);
  252. int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  253. struct net_device *dev, const u8 *bssid,
  254. const u8 *ie, int ie_len, u16 reason);
  255. int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  256. struct net_device *dev, const u8 *bssid,
  257. const u8 *ie, int ie_len, u16 reason);
  258. int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
  259. struct net_device *dev, const u8 *bssid,
  260. const u8 *ie, int ie_len, u16 reason);
  261. void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
  262. struct net_device *dev);
  263. void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
  264. const u8 *req_ie, size_t req_ie_len,
  265. const u8 *resp_ie, size_t resp_ie_len,
  266. u16 status, bool wextev);
  267. /* SME */
  268. int __cfg80211_connect(struct cfg80211_registered_device *rdev,
  269. struct net_device *dev,
  270. struct cfg80211_connect_params *connect);
  271. int cfg80211_connect(struct cfg80211_registered_device *rdev,
  272. struct net_device *dev,
  273. struct cfg80211_connect_params *connect);
  274. int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
  275. struct net_device *dev, u16 reason,
  276. bool wextev);
  277. int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
  278. struct net_device *dev, u16 reason,
  279. bool wextev);
  280. void __cfg80211_roamed(struct wireless_dev *wdev, const u8 *bssid,
  281. const u8 *req_ie, size_t req_ie_len,
  282. const u8 *resp_ie, size_t resp_ie_len);
  283. void cfg80211_conn_work(struct work_struct *work);
  284. /* internal helpers */
  285. int cfg80211_validate_key_settings(struct key_params *params, int key_idx,
  286. const u8 *mac_addr);
  287. void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
  288. size_t ie_len, u16 reason, bool from_ap);
  289. void cfg80211_sme_scan_done(struct net_device *dev);
  290. void cfg80211_sme_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
  291. void cfg80211_sme_disassoc(struct net_device *dev, int idx);
  292. void __cfg80211_scan_done(struct work_struct *wk);
  293. #endif /* __NET_WIRELESS_CORE_H */