core.h 16 KB

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