core.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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 <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. /* protected by devlist_mtx or RCU */
  46. struct list_head netdev_list;
  47. int devlist_generation;
  48. int opencount; /* also protected by devlist_mtx */
  49. wait_queue_head_t dev_wait;
  50. u32 ap_beacons_nlpid;
  51. /* BSSes/scanning */
  52. spinlock_t bss_lock;
  53. struct list_head bss_list;
  54. struct rb_root bss_tree;
  55. u32 bss_generation;
  56. struct cfg80211_scan_request *scan_req; /* protected by RTNL */
  57. struct cfg80211_sched_scan_request *sched_scan_req;
  58. unsigned long suspend_at;
  59. struct work_struct scan_done_wk;
  60. struct work_struct sched_scan_results_wk;
  61. struct mutex sched_scan_mtx;
  62. #ifdef CONFIG_NL80211_TESTMODE
  63. struct genl_info *testmode_info;
  64. #endif
  65. struct work_struct conn_work;
  66. struct work_struct event_work;
  67. struct cfg80211_wowlan *wowlan;
  68. /* must be last because of the way we do wiphy_priv(),
  69. * and it should at least be aligned to NETDEV_ALIGN */
  70. struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
  71. };
  72. static inline
  73. struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
  74. {
  75. BUG_ON(!wiphy);
  76. return container_of(wiphy, struct cfg80211_registered_device, wiphy);
  77. }
  78. /* Note 0 is valid, hence phy0 */
  79. static inline
  80. bool wiphy_idx_valid(int wiphy_idx)
  81. {
  82. return wiphy_idx >= 0;
  83. }
  84. static inline void
  85. cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
  86. {
  87. int i;
  88. if (!rdev->wowlan)
  89. return;
  90. for (i = 0; i < rdev->wowlan->n_patterns; i++)
  91. kfree(rdev->wowlan->patterns[i].mask);
  92. kfree(rdev->wowlan->patterns);
  93. kfree(rdev->wowlan);
  94. }
  95. extern struct workqueue_struct *cfg80211_wq;
  96. extern struct mutex cfg80211_mutex;
  97. extern struct list_head cfg80211_rdev_list;
  98. extern int cfg80211_rdev_list_generation;
  99. static inline void assert_cfg80211_lock(void)
  100. {
  101. lockdep_assert_held(&cfg80211_mutex);
  102. }
  103. /*
  104. * You can use this to mark a wiphy_idx as not having an associated wiphy.
  105. * It guarantees cfg80211_rdev_by_wiphy_idx(wiphy_idx) will return NULL
  106. */
  107. #define WIPHY_IDX_STALE -1
  108. struct cfg80211_internal_bss {
  109. struct list_head list;
  110. struct rb_node rbn;
  111. unsigned long ts;
  112. struct kref ref;
  113. atomic_t hold;
  114. bool beacon_ies_allocated;
  115. bool proberesp_ies_allocated;
  116. /* must be last because of priv member */
  117. struct cfg80211_bss pub;
  118. };
  119. static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
  120. {
  121. return container_of(pub, struct cfg80211_internal_bss, pub);
  122. }
  123. static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
  124. {
  125. atomic_inc(&bss->hold);
  126. }
  127. static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
  128. {
  129. int r = atomic_dec_return(&bss->hold);
  130. WARN_ON(r < 0);
  131. }
  132. struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
  133. int get_wiphy_idx(struct wiphy *wiphy);
  134. /* requires cfg80211_rdev_mutex to be held! */
  135. struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
  136. /* identical to cfg80211_get_dev_from_info but only operate on ifindex */
  137. extern struct cfg80211_registered_device *
  138. cfg80211_get_dev_from_ifindex(struct net *net, int ifindex);
  139. int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
  140. struct net *net);
  141. static inline void cfg80211_lock_rdev(struct cfg80211_registered_device *rdev)
  142. {
  143. mutex_lock(&rdev->mtx);
  144. }
  145. static inline void cfg80211_unlock_rdev(struct cfg80211_registered_device *rdev)
  146. {
  147. BUG_ON(IS_ERR(rdev) || !rdev);
  148. mutex_unlock(&rdev->mtx);
  149. }
  150. static inline void wdev_lock(struct wireless_dev *wdev)
  151. __acquires(wdev)
  152. {
  153. mutex_lock(&wdev->mtx);
  154. __acquire(wdev->mtx);
  155. }
  156. static inline void wdev_unlock(struct wireless_dev *wdev)
  157. __releases(wdev)
  158. {
  159. __release(wdev->mtx);
  160. mutex_unlock(&wdev->mtx);
  161. }
  162. #define ASSERT_RDEV_LOCK(rdev) lockdep_assert_held(&(rdev)->mtx)
  163. #define ASSERT_WDEV_LOCK(wdev) lockdep_assert_held(&(wdev)->mtx)
  164. enum cfg80211_event_type {
  165. EVENT_CONNECT_RESULT,
  166. EVENT_ROAMED,
  167. EVENT_DISCONNECTED,
  168. EVENT_IBSS_JOINED,
  169. };
  170. struct cfg80211_event {
  171. struct list_head list;
  172. enum cfg80211_event_type type;
  173. union {
  174. struct {
  175. u8 bssid[ETH_ALEN];
  176. const u8 *req_ie;
  177. const u8 *resp_ie;
  178. size_t req_ie_len;
  179. size_t resp_ie_len;
  180. u16 status;
  181. } cr;
  182. struct {
  183. const u8 *req_ie;
  184. const u8 *resp_ie;
  185. size_t req_ie_len;
  186. size_t resp_ie_len;
  187. struct cfg80211_bss *bss;
  188. } rm;
  189. struct {
  190. const u8 *ie;
  191. size_t ie_len;
  192. u16 reason;
  193. } dc;
  194. struct {
  195. u8 bssid[ETH_ALEN];
  196. } ij;
  197. };
  198. };
  199. struct cfg80211_cached_keys {
  200. struct key_params params[6];
  201. u8 data[6][WLAN_MAX_KEY_LEN];
  202. int def, defmgmt;
  203. };
  204. /* free object */
  205. extern void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
  206. extern int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
  207. char *newname);
  208. void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
  209. void cfg80211_bss_expire(struct cfg80211_registered_device *dev);
  210. void cfg80211_bss_age(struct cfg80211_registered_device *dev,
  211. unsigned long age_secs);
  212. /* IBSS */
  213. int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
  214. struct net_device *dev,
  215. struct cfg80211_ibss_params *params,
  216. struct cfg80211_cached_keys *connkeys);
  217. int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
  218. struct net_device *dev,
  219. struct cfg80211_ibss_params *params,
  220. struct cfg80211_cached_keys *connkeys);
  221. void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
  222. int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  223. struct net_device *dev, bool nowext);
  224. int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  225. struct net_device *dev, bool nowext);
  226. void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
  227. int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
  228. struct wireless_dev *wdev);
  229. /* mesh */
  230. extern const struct mesh_config default_mesh_config;
  231. extern const struct mesh_setup default_mesh_setup;
  232. int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  233. struct net_device *dev,
  234. struct mesh_setup *setup,
  235. const struct mesh_config *conf);
  236. int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  237. struct net_device *dev,
  238. struct mesh_setup *setup,
  239. const struct mesh_config *conf);
  240. int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
  241. struct net_device *dev);
  242. int cfg80211_set_mesh_freq(struct cfg80211_registered_device *rdev,
  243. struct wireless_dev *wdev, int freq,
  244. enum nl80211_channel_type channel_type);
  245. /* AP */
  246. int cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
  247. struct net_device *dev);
  248. /* MLME */
  249. int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  250. struct net_device *dev,
  251. struct ieee80211_channel *chan,
  252. enum nl80211_auth_type auth_type,
  253. const u8 *bssid,
  254. const u8 *ssid, int ssid_len,
  255. const u8 *ie, int ie_len,
  256. const u8 *key, int key_len, int key_idx);
  257. int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  258. struct net_device *dev, struct ieee80211_channel *chan,
  259. enum nl80211_auth_type auth_type, const u8 *bssid,
  260. const u8 *ssid, int ssid_len,
  261. const u8 *ie, int ie_len,
  262. const u8 *key, int key_len, int key_idx);
  263. int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  264. struct net_device *dev,
  265. struct ieee80211_channel *chan,
  266. const u8 *bssid, const u8 *prev_bssid,
  267. const u8 *ssid, int ssid_len,
  268. const u8 *ie, int ie_len, bool use_mfp,
  269. struct cfg80211_crypto_settings *crypt,
  270. u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
  271. struct ieee80211_ht_cap *ht_capa_mask);
  272. int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  273. struct net_device *dev, struct ieee80211_channel *chan,
  274. const u8 *bssid, const u8 *prev_bssid,
  275. const u8 *ssid, int ssid_len,
  276. const u8 *ie, int ie_len, bool use_mfp,
  277. struct cfg80211_crypto_settings *crypt,
  278. u32 assoc_flags, struct ieee80211_ht_cap *ht_capa,
  279. struct ieee80211_ht_cap *ht_capa_mask);
  280. int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  281. struct net_device *dev, const u8 *bssid,
  282. const u8 *ie, int ie_len, u16 reason,
  283. bool local_state_change);
  284. int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  285. struct net_device *dev, const u8 *bssid,
  286. const u8 *ie, int ie_len, u16 reason,
  287. bool local_state_change);
  288. int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
  289. struct net_device *dev, const u8 *bssid,
  290. const u8 *ie, int ie_len, u16 reason,
  291. bool local_state_change);
  292. void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
  293. struct net_device *dev);
  294. void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
  295. const u8 *req_ie, size_t req_ie_len,
  296. const u8 *resp_ie, size_t resp_ie_len,
  297. u16 status, bool wextev,
  298. struct cfg80211_bss *bss);
  299. int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
  300. u16 frame_type, const u8 *match_data,
  301. int match_len);
  302. void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid);
  303. void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev);
  304. int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
  305. struct net_device *dev,
  306. struct ieee80211_channel *chan, bool offchan,
  307. enum nl80211_channel_type channel_type,
  308. bool channel_type_valid, unsigned int wait,
  309. const u8 *buf, size_t len, bool no_cck,
  310. bool dont_wait_for_ack, u64 *cookie);
  311. void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
  312. const struct ieee80211_ht_cap *ht_capa_mask);
  313. /* SME */
  314. int __cfg80211_connect(struct cfg80211_registered_device *rdev,
  315. struct net_device *dev,
  316. struct cfg80211_connect_params *connect,
  317. struct cfg80211_cached_keys *connkeys,
  318. const u8 *prev_bssid);
  319. int cfg80211_connect(struct cfg80211_registered_device *rdev,
  320. struct net_device *dev,
  321. struct cfg80211_connect_params *connect,
  322. struct cfg80211_cached_keys *connkeys);
  323. int __cfg80211_disconnect(struct cfg80211_registered_device *rdev,
  324. struct net_device *dev, u16 reason,
  325. bool wextev);
  326. int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
  327. struct net_device *dev, u16 reason,
  328. bool wextev);
  329. void __cfg80211_roamed(struct wireless_dev *wdev,
  330. struct cfg80211_bss *bss,
  331. const u8 *req_ie, size_t req_ie_len,
  332. const u8 *resp_ie, size_t resp_ie_len);
  333. int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
  334. struct wireless_dev *wdev);
  335. void cfg80211_conn_work(struct work_struct *work);
  336. void cfg80211_sme_failed_assoc(struct wireless_dev *wdev);
  337. bool cfg80211_sme_failed_reassoc(struct wireless_dev *wdev);
  338. /* internal helpers */
  339. bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher);
  340. int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
  341. struct key_params *params, int key_idx,
  342. bool pairwise, const u8 *mac_addr);
  343. void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
  344. size_t ie_len, u16 reason, bool from_ap);
  345. void cfg80211_sme_scan_done(struct net_device *dev);
  346. void cfg80211_sme_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
  347. void cfg80211_sme_disassoc(struct net_device *dev,
  348. struct cfg80211_internal_bss *bss);
  349. void __cfg80211_scan_done(struct work_struct *wk);
  350. void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak);
  351. void __cfg80211_sched_scan_results(struct work_struct *wk);
  352. int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
  353. bool driver_initiated);
  354. void cfg80211_upload_connect_keys(struct wireless_dev *wdev);
  355. int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
  356. struct net_device *dev, enum nl80211_iftype ntype,
  357. u32 *flags, struct vif_params *params);
  358. void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
  359. int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
  360. struct wireless_dev *wdev,
  361. enum nl80211_iftype iftype);
  362. static inline int
  363. cfg80211_can_add_interface(struct cfg80211_registered_device *rdev,
  364. enum nl80211_iftype iftype)
  365. {
  366. return cfg80211_can_change_interface(rdev, NULL, iftype);
  367. }
  368. struct ieee80211_channel *
  369. rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
  370. int freq, enum nl80211_channel_type channel_type);
  371. int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
  372. int freq, enum nl80211_channel_type chantype);
  373. int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
  374. const u8 *rates, unsigned int n_rates,
  375. u32 *mask);
  376. int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
  377. u32 beacon_int);
  378. #ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
  379. #define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
  380. #else
  381. /*
  382. * Trick to enable using it as a condition,
  383. * and also not give a warning when it's
  384. * not used that way.
  385. */
  386. #define CFG80211_DEV_WARN_ON(cond) ({bool __r = (cond); __r; })
  387. #endif
  388. #endif /* __NET_WIRELESS_CORE_H */