core.h 15 KB

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