core.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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/list.h>
  9. #include <linux/netdevice.h>
  10. #include <linux/rbtree.h>
  11. #include <linux/debugfs.h>
  12. #include <linux/rfkill.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/rtnetlink.h>
  15. #include <net/genetlink.h>
  16. #include <net/cfg80211.h>
  17. #include "reg.h"
  18. #define WIPHY_IDX_INVALID -1
  19. struct cfg80211_registered_device {
  20. const struct cfg80211_ops *ops;
  21. struct list_head list;
  22. /* rfkill support */
  23. struct rfkill_ops rfkill_ops;
  24. struct rfkill *rfkill;
  25. struct work_struct rfkill_sync;
  26. /* ISO / IEC 3166 alpha2 for which this device is receiving
  27. * country IEs on, this can help disregard country IEs from APs
  28. * on the same alpha2 quickly. The alpha2 may differ from
  29. * cfg80211_regdomain's alpha2 when an intersection has occurred.
  30. * If the AP is reconfigured this can also be used to tell us if
  31. * the country on the country IE changed. */
  32. char country_ie_alpha2[2];
  33. /*
  34. * the driver requests the regulatory core to set this regulatory
  35. * domain as the wiphy's. Only used for %REGULATORY_WIPHY_SELF_MANAGED
  36. * devices using the regulatory_set_wiphy_regd() API
  37. */
  38. const struct ieee80211_regdomain *requested_regd;
  39. /* If a Country IE has been received this tells us the environment
  40. * which its telling us its in. This defaults to ENVIRON_ANY */
  41. enum environment_cap env;
  42. /* wiphy index, internal only */
  43. int wiphy_idx;
  44. /* associated wireless interfaces, protected by rtnl or RCU */
  45. struct list_head wdev_list;
  46. int devlist_generation, wdev_id;
  47. int opencount; /* also protected by devlist_mtx */
  48. wait_queue_head_t dev_wait;
  49. struct list_head beacon_registrations;
  50. spinlock_t beacon_registrations_lock;
  51. struct list_head mlme_unreg;
  52. spinlock_t mlme_unreg_lock;
  53. struct work_struct mlme_unreg_wk;
  54. /* protected by RTNL only */
  55. int num_running_ifaces;
  56. int num_running_monitor_ifaces;
  57. /* BSSes/scanning */
  58. spinlock_t bss_lock;
  59. struct list_head bss_list;
  60. struct rb_root bss_tree;
  61. u32 bss_generation;
  62. struct cfg80211_scan_request *scan_req; /* protected by RTNL */
  63. struct sk_buff *scan_msg;
  64. struct cfg80211_sched_scan_request __rcu *sched_scan_req;
  65. unsigned long suspend_at;
  66. struct work_struct scan_done_wk;
  67. struct work_struct sched_scan_results_wk;
  68. struct genl_info *cur_cmd_info;
  69. struct work_struct conn_work;
  70. struct work_struct event_work;
  71. struct delayed_work dfs_update_channels_wk;
  72. /* netlink port which started critical protocol (0 means not started) */
  73. u32 crit_proto_nlportid;
  74. struct cfg80211_coalesce *coalesce;
  75. spinlock_t destroy_list_lock;
  76. struct list_head destroy_list;
  77. struct work_struct destroy_work;
  78. struct work_struct sched_scan_stop_wk;
  79. /* must be last because of the way we do wiphy_priv(),
  80. * and it should at least be aligned to NETDEV_ALIGN */
  81. struct wiphy wiphy __aligned(NETDEV_ALIGN);
  82. };
  83. static inline
  84. struct cfg80211_registered_device *wiphy_to_rdev(struct wiphy *wiphy)
  85. {
  86. BUG_ON(!wiphy);
  87. return container_of(wiphy, struct cfg80211_registered_device, wiphy);
  88. }
  89. static inline void
  90. cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
  91. {
  92. #ifdef CONFIG_PM
  93. int i;
  94. if (!rdev->wiphy.wowlan_config)
  95. return;
  96. for (i = 0; i < rdev->wiphy.wowlan_config->n_patterns; i++)
  97. kfree(rdev->wiphy.wowlan_config->patterns[i].mask);
  98. kfree(rdev->wiphy.wowlan_config->patterns);
  99. if (rdev->wiphy.wowlan_config->tcp &&
  100. rdev->wiphy.wowlan_config->tcp->sock)
  101. sock_release(rdev->wiphy.wowlan_config->tcp->sock);
  102. kfree(rdev->wiphy.wowlan_config->tcp);
  103. kfree(rdev->wiphy.wowlan_config->nd_config);
  104. kfree(rdev->wiphy.wowlan_config);
  105. #endif
  106. }
  107. extern struct workqueue_struct *cfg80211_wq;
  108. extern struct list_head cfg80211_rdev_list;
  109. extern int cfg80211_rdev_list_generation;
  110. struct cfg80211_internal_bss {
  111. struct list_head list;
  112. struct list_head hidden_list;
  113. struct rb_node rbn;
  114. unsigned long ts;
  115. unsigned long refcount;
  116. atomic_t hold;
  117. /* must be last because of priv member */
  118. struct cfg80211_bss pub;
  119. };
  120. static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
  121. {
  122. return container_of(pub, struct cfg80211_internal_bss, pub);
  123. }
  124. static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
  125. {
  126. atomic_inc(&bss->hold);
  127. }
  128. static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
  129. {
  130. int r = atomic_dec_return(&bss->hold);
  131. WARN_ON(r < 0);
  132. }
  133. struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
  134. int get_wiphy_idx(struct wiphy *wiphy);
  135. struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
  136. int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
  137. struct net *net);
  138. static inline void wdev_lock(struct wireless_dev *wdev)
  139. __acquires(wdev)
  140. {
  141. mutex_lock(&wdev->mtx);
  142. __acquire(wdev->mtx);
  143. }
  144. static inline void wdev_unlock(struct wireless_dev *wdev)
  145. __releases(wdev)
  146. {
  147. __release(wdev->mtx);
  148. mutex_unlock(&wdev->mtx);
  149. }
  150. #define ASSERT_WDEV_LOCK(wdev) lockdep_assert_held(&(wdev)->mtx)
  151. static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device *rdev)
  152. {
  153. ASSERT_RTNL();
  154. return rdev->num_running_ifaces == rdev->num_running_monitor_ifaces &&
  155. rdev->num_running_ifaces > 0;
  156. }
  157. enum cfg80211_event_type {
  158. EVENT_CONNECT_RESULT,
  159. EVENT_ROAMED,
  160. EVENT_DISCONNECTED,
  161. EVENT_IBSS_JOINED,
  162. EVENT_STOPPED,
  163. };
  164. struct cfg80211_event {
  165. struct list_head list;
  166. enum cfg80211_event_type type;
  167. union {
  168. struct {
  169. u8 bssid[ETH_ALEN];
  170. const u8 *req_ie;
  171. const u8 *resp_ie;
  172. size_t req_ie_len;
  173. size_t resp_ie_len;
  174. u16 status;
  175. } cr;
  176. struct {
  177. const u8 *req_ie;
  178. const u8 *resp_ie;
  179. size_t req_ie_len;
  180. size_t resp_ie_len;
  181. struct cfg80211_bss *bss;
  182. } rm;
  183. struct {
  184. const u8 *ie;
  185. size_t ie_len;
  186. u16 reason;
  187. bool locally_generated;
  188. } dc;
  189. struct {
  190. u8 bssid[ETH_ALEN];
  191. struct ieee80211_channel *channel;
  192. } ij;
  193. };
  194. };
  195. struct cfg80211_cached_keys {
  196. struct key_params params[6];
  197. u8 data[6][WLAN_MAX_KEY_LEN];
  198. int def, defmgmt;
  199. };
  200. enum cfg80211_chan_mode {
  201. CHAN_MODE_UNDEFINED,
  202. CHAN_MODE_SHARED,
  203. CHAN_MODE_EXCLUSIVE,
  204. };
  205. struct cfg80211_beacon_registration {
  206. struct list_head list;
  207. u32 nlportid;
  208. };
  209. struct cfg80211_iface_destroy {
  210. struct list_head list;
  211. u32 nlportid;
  212. };
  213. void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev);
  214. /* free object */
  215. void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
  216. int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
  217. char *newname);
  218. void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
  219. void cfg80211_bss_expire(struct cfg80211_registered_device *rdev);
  220. void cfg80211_bss_age(struct cfg80211_registered_device *rdev,
  221. unsigned long age_secs);
  222. /* IBSS */
  223. int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
  224. struct net_device *dev,
  225. struct cfg80211_ibss_params *params,
  226. struct cfg80211_cached_keys *connkeys);
  227. void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
  228. int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  229. struct net_device *dev, bool nowext);
  230. int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  231. struct net_device *dev, bool nowext);
  232. void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
  233. struct ieee80211_channel *channel);
  234. int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
  235. struct wireless_dev *wdev);
  236. /* mesh */
  237. extern const struct mesh_config default_mesh_config;
  238. extern const struct mesh_setup default_mesh_setup;
  239. int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  240. struct net_device *dev,
  241. struct mesh_setup *setup,
  242. const struct mesh_config *conf);
  243. int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  244. struct net_device *dev,
  245. struct mesh_setup *setup,
  246. const struct mesh_config *conf);
  247. int __cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
  248. struct net_device *dev);
  249. int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
  250. struct net_device *dev);
  251. int cfg80211_set_mesh_channel(struct cfg80211_registered_device *rdev,
  252. struct wireless_dev *wdev,
  253. struct cfg80211_chan_def *chandef);
  254. /* OCB */
  255. int __cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
  256. struct net_device *dev,
  257. struct ocb_setup *setup);
  258. int cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
  259. struct net_device *dev,
  260. struct ocb_setup *setup);
  261. int __cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
  262. struct net_device *dev);
  263. int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
  264. struct net_device *dev);
  265. /* AP */
  266. int __cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
  267. struct net_device *dev, bool notify);
  268. int cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
  269. struct net_device *dev, bool notify);
  270. /* MLME */
  271. int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  272. struct net_device *dev,
  273. struct ieee80211_channel *chan,
  274. enum nl80211_auth_type auth_type,
  275. const u8 *bssid,
  276. const u8 *ssid, int ssid_len,
  277. const u8 *ie, int ie_len,
  278. const u8 *key, int key_len, int key_idx,
  279. const u8 *sae_data, int sae_data_len);
  280. int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  281. struct net_device *dev,
  282. struct ieee80211_channel *chan,
  283. const u8 *bssid,
  284. const u8 *ssid, int ssid_len,
  285. struct cfg80211_assoc_request *req);
  286. int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  287. struct net_device *dev, const u8 *bssid,
  288. const u8 *ie, int ie_len, u16 reason,
  289. bool local_state_change);
  290. int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
  291. struct net_device *dev, const u8 *bssid,
  292. const u8 *ie, int ie_len, u16 reason,
  293. bool local_state_change);
  294. void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
  295. struct net_device *dev);
  296. int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
  297. u16 frame_type, const u8 *match_data,
  298. int match_len);
  299. void cfg80211_mlme_unreg_wk(struct work_struct *wk);
  300. void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid);
  301. void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev);
  302. int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
  303. struct wireless_dev *wdev,
  304. struct cfg80211_mgmt_tx_params *params,
  305. u64 *cookie);
  306. void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
  307. const struct ieee80211_ht_cap *ht_capa_mask);
  308. void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
  309. const struct ieee80211_vht_cap *vht_capa_mask);
  310. /* SME events */
  311. int cfg80211_connect(struct cfg80211_registered_device *rdev,
  312. struct net_device *dev,
  313. struct cfg80211_connect_params *connect,
  314. struct cfg80211_cached_keys *connkeys,
  315. const u8 *prev_bssid);
  316. void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
  317. const u8 *req_ie, size_t req_ie_len,
  318. const u8 *resp_ie, size_t resp_ie_len,
  319. u16 status, bool wextev,
  320. struct cfg80211_bss *bss);
  321. void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
  322. size_t ie_len, u16 reason, bool from_ap);
  323. int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
  324. struct net_device *dev, u16 reason,
  325. bool wextev);
  326. void __cfg80211_roamed(struct wireless_dev *wdev,
  327. struct cfg80211_bss *bss,
  328. const u8 *req_ie, size_t req_ie_len,
  329. const u8 *resp_ie, size_t resp_ie_len);
  330. int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
  331. struct wireless_dev *wdev);
  332. /* SME implementation */
  333. void cfg80211_conn_work(struct work_struct *work);
  334. void cfg80211_sme_scan_done(struct net_device *dev);
  335. bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status);
  336. void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len);
  337. void cfg80211_sme_disassoc(struct wireless_dev *wdev);
  338. void cfg80211_sme_deauth(struct wireless_dev *wdev);
  339. void cfg80211_sme_auth_timeout(struct wireless_dev *wdev);
  340. void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev);
  341. /* internal helpers */
  342. bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher);
  343. int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
  344. struct key_params *params, int key_idx,
  345. bool pairwise, const u8 *mac_addr);
  346. void __cfg80211_scan_done(struct work_struct *wk);
  347. void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
  348. bool send_message);
  349. void __cfg80211_sched_scan_results(struct work_struct *wk);
  350. int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
  351. bool driver_initiated);
  352. void cfg80211_upload_connect_keys(struct wireless_dev *wdev);
  353. int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
  354. struct net_device *dev, enum nl80211_iftype ntype,
  355. u32 *flags, struct vif_params *params);
  356. void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
  357. void cfg80211_process_wdev_events(struct wireless_dev *wdev);
  358. int cfg80211_can_use_iftype_chan(struct cfg80211_registered_device *rdev,
  359. struct wireless_dev *wdev,
  360. enum nl80211_iftype iftype,
  361. struct ieee80211_channel *chan,
  362. enum cfg80211_chan_mode chanmode,
  363. u8 radar_detect);
  364. /**
  365. * cfg80211_chandef_dfs_usable - checks if chandef is DFS usable
  366. * @wiphy: the wiphy to validate against
  367. * @chandef: the channel definition to check
  368. *
  369. * Checks if chandef is usable and we can/need start CAC on such channel.
  370. *
  371. * Return: Return true if all channels available and at least
  372. * one channel require CAC (NL80211_DFS_USABLE)
  373. */
  374. bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy,
  375. const struct cfg80211_chan_def *chandef);
  376. void cfg80211_set_dfs_state(struct wiphy *wiphy,
  377. const struct cfg80211_chan_def *chandef,
  378. enum nl80211_dfs_state dfs_state);
  379. void cfg80211_dfs_channels_update_work(struct work_struct *work);
  380. unsigned int
  381. cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy,
  382. const struct cfg80211_chan_def *chandef);
  383. static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
  384. {
  385. unsigned long end = jiffies;
  386. if (end >= start)
  387. return jiffies_to_msecs(end - start);
  388. return jiffies_to_msecs(end + (ULONG_MAX - start) + 1);
  389. }
  390. void
  391. cfg80211_get_chan_state(struct wireless_dev *wdev,
  392. struct ieee80211_channel **chan,
  393. enum cfg80211_chan_mode *chanmode,
  394. u8 *radar_detect);
  395. int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
  396. struct cfg80211_chan_def *chandef);
  397. int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
  398. const u8 *rates, unsigned int n_rates,
  399. u32 *mask);
  400. int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
  401. u32 beacon_int);
  402. void cfg80211_update_iface_num(struct cfg80211_registered_device *rdev,
  403. enum nl80211_iftype iftype, int num);
  404. void __cfg80211_leave(struct cfg80211_registered_device *rdev,
  405. struct wireless_dev *wdev);
  406. void cfg80211_leave(struct cfg80211_registered_device *rdev,
  407. struct wireless_dev *wdev);
  408. void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
  409. struct wireless_dev *wdev);
  410. #define CFG80211_MAX_NUM_DIFFERENT_CHANNELS 10
  411. #ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
  412. #define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
  413. #else
  414. /*
  415. * Trick to enable using it as a condition,
  416. * and also not give a warning when it's
  417. * not used that way.
  418. */
  419. #define CFG80211_DEV_WARN_ON(cond) ({bool __r = (cond); __r; })
  420. #endif
  421. #endif /* __NET_WIRELESS_CORE_H */