core.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. /* protected by RTNL */
  45. int devlist_generation, wdev_id;
  46. int opencount;
  47. wait_queue_head_t dev_wait;
  48. struct list_head beacon_registrations;
  49. spinlock_t beacon_registrations_lock;
  50. struct list_head mlme_unreg;
  51. spinlock_t mlme_unreg_lock;
  52. struct work_struct mlme_unreg_wk;
  53. /* protected by RTNL only */
  54. int num_running_ifaces;
  55. int num_running_monitor_ifaces;
  56. /* BSSes/scanning */
  57. spinlock_t bss_lock;
  58. struct list_head bss_list;
  59. struct rb_root bss_tree;
  60. u32 bss_generation;
  61. u32 bss_entries;
  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. struct cfg80211_chan_def radar_chandef;
  80. struct work_struct propagate_radar_detect_wk;
  81. struct cfg80211_chan_def cac_done_chandef;
  82. struct work_struct propagate_cac_done_wk;
  83. /* must be last because of the way we do wiphy_priv(),
  84. * and it should at least be aligned to NETDEV_ALIGN */
  85. struct wiphy wiphy __aligned(NETDEV_ALIGN);
  86. };
  87. static inline
  88. struct cfg80211_registered_device *wiphy_to_rdev(struct wiphy *wiphy)
  89. {
  90. BUG_ON(!wiphy);
  91. return container_of(wiphy, struct cfg80211_registered_device, wiphy);
  92. }
  93. static inline void
  94. cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
  95. {
  96. #ifdef CONFIG_PM
  97. int i;
  98. if (!rdev->wiphy.wowlan_config)
  99. return;
  100. for (i = 0; i < rdev->wiphy.wowlan_config->n_patterns; i++)
  101. kfree(rdev->wiphy.wowlan_config->patterns[i].mask);
  102. kfree(rdev->wiphy.wowlan_config->patterns);
  103. if (rdev->wiphy.wowlan_config->tcp &&
  104. rdev->wiphy.wowlan_config->tcp->sock)
  105. sock_release(rdev->wiphy.wowlan_config->tcp->sock);
  106. kfree(rdev->wiphy.wowlan_config->tcp);
  107. kfree(rdev->wiphy.wowlan_config->nd_config);
  108. kfree(rdev->wiphy.wowlan_config);
  109. #endif
  110. }
  111. extern struct workqueue_struct *cfg80211_wq;
  112. extern struct list_head cfg80211_rdev_list;
  113. extern int cfg80211_rdev_list_generation;
  114. struct cfg80211_internal_bss {
  115. struct list_head list;
  116. struct list_head hidden_list;
  117. struct rb_node rbn;
  118. u64 ts_boottime;
  119. unsigned long ts;
  120. unsigned long refcount;
  121. atomic_t hold;
  122. /* time at the start of the reception of the first octet of the
  123. * timestamp field of the last beacon/probe received for this BSS.
  124. * The time is the TSF of the BSS specified by %parent_bssid.
  125. */
  126. u64 parent_tsf;
  127. /* the BSS according to which %parent_tsf is set. This is set to
  128. * the BSS that the interface that requested the scan was connected to
  129. * when the beacon/probe was received.
  130. */
  131. u8 parent_bssid[ETH_ALEN] __aligned(2);
  132. /* must be last because of priv member */
  133. struct cfg80211_bss pub;
  134. };
  135. static inline struct cfg80211_internal_bss *bss_from_pub(struct cfg80211_bss *pub)
  136. {
  137. return container_of(pub, struct cfg80211_internal_bss, pub);
  138. }
  139. static inline void cfg80211_hold_bss(struct cfg80211_internal_bss *bss)
  140. {
  141. atomic_inc(&bss->hold);
  142. }
  143. static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
  144. {
  145. int r = atomic_dec_return(&bss->hold);
  146. WARN_ON(r < 0);
  147. }
  148. struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
  149. int get_wiphy_idx(struct wiphy *wiphy);
  150. struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
  151. int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
  152. struct net *net);
  153. static inline void wdev_lock(struct wireless_dev *wdev)
  154. __acquires(wdev)
  155. {
  156. mutex_lock(&wdev->mtx);
  157. __acquire(wdev->mtx);
  158. }
  159. static inline void wdev_unlock(struct wireless_dev *wdev)
  160. __releases(wdev)
  161. {
  162. __release(wdev->mtx);
  163. mutex_unlock(&wdev->mtx);
  164. }
  165. #define ASSERT_WDEV_LOCK(wdev) lockdep_assert_held(&(wdev)->mtx)
  166. static inline bool cfg80211_has_monitors_only(struct cfg80211_registered_device *rdev)
  167. {
  168. ASSERT_RTNL();
  169. return rdev->num_running_ifaces == rdev->num_running_monitor_ifaces &&
  170. rdev->num_running_ifaces > 0;
  171. }
  172. enum cfg80211_event_type {
  173. EVENT_CONNECT_RESULT,
  174. EVENT_ROAMED,
  175. EVENT_DISCONNECTED,
  176. EVENT_IBSS_JOINED,
  177. EVENT_STOPPED,
  178. };
  179. struct cfg80211_event {
  180. struct list_head list;
  181. enum cfg80211_event_type type;
  182. union {
  183. struct {
  184. u8 bssid[ETH_ALEN];
  185. const u8 *req_ie;
  186. const u8 *resp_ie;
  187. size_t req_ie_len;
  188. size_t resp_ie_len;
  189. struct cfg80211_bss *bss;
  190. int status; /* -1 = failed; 0..65535 = status code */
  191. enum nl80211_timeout_reason timeout_reason;
  192. } cr;
  193. struct {
  194. const u8 *req_ie;
  195. const u8 *resp_ie;
  196. size_t req_ie_len;
  197. size_t resp_ie_len;
  198. struct cfg80211_bss *bss;
  199. } rm;
  200. struct {
  201. const u8 *ie;
  202. size_t ie_len;
  203. u16 reason;
  204. bool locally_generated;
  205. } dc;
  206. struct {
  207. u8 bssid[ETH_ALEN];
  208. struct ieee80211_channel *channel;
  209. } ij;
  210. };
  211. };
  212. struct cfg80211_cached_keys {
  213. struct key_params params[CFG80211_MAX_WEP_KEYS];
  214. u8 data[CFG80211_MAX_WEP_KEYS][WLAN_KEY_LEN_WEP104];
  215. int def;
  216. };
  217. enum cfg80211_chan_mode {
  218. CHAN_MODE_UNDEFINED,
  219. CHAN_MODE_SHARED,
  220. CHAN_MODE_EXCLUSIVE,
  221. };
  222. struct cfg80211_beacon_registration {
  223. struct list_head list;
  224. u32 nlportid;
  225. };
  226. struct cfg80211_iface_destroy {
  227. struct list_head list;
  228. u32 nlportid;
  229. };
  230. struct cfg80211_cqm_config {
  231. u32 rssi_hyst;
  232. s32 last_rssi_event_value;
  233. int n_rssi_thresholds;
  234. s32 rssi_thresholds[0];
  235. };
  236. void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev);
  237. /* free object */
  238. void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
  239. int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
  240. char *newname);
  241. void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
  242. void cfg80211_bss_expire(struct cfg80211_registered_device *rdev);
  243. void cfg80211_bss_age(struct cfg80211_registered_device *rdev,
  244. unsigned long age_secs);
  245. /* IBSS */
  246. int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
  247. struct net_device *dev,
  248. struct cfg80211_ibss_params *params,
  249. struct cfg80211_cached_keys *connkeys);
  250. void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
  251. int __cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  252. struct net_device *dev, bool nowext);
  253. int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
  254. struct net_device *dev, bool nowext);
  255. void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid,
  256. struct ieee80211_channel *channel);
  257. int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
  258. struct wireless_dev *wdev);
  259. /* mesh */
  260. extern const struct mesh_config default_mesh_config;
  261. extern const struct mesh_setup default_mesh_setup;
  262. int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  263. struct net_device *dev,
  264. struct mesh_setup *setup,
  265. const struct mesh_config *conf);
  266. int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
  267. struct net_device *dev,
  268. struct mesh_setup *setup,
  269. const struct mesh_config *conf);
  270. int __cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
  271. struct net_device *dev);
  272. int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
  273. struct net_device *dev);
  274. int cfg80211_set_mesh_channel(struct cfg80211_registered_device *rdev,
  275. struct wireless_dev *wdev,
  276. struct cfg80211_chan_def *chandef);
  277. /* OCB */
  278. int __cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
  279. struct net_device *dev,
  280. struct ocb_setup *setup);
  281. int cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
  282. struct net_device *dev,
  283. struct ocb_setup *setup);
  284. int __cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
  285. struct net_device *dev);
  286. int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
  287. struct net_device *dev);
  288. /* AP */
  289. int __cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
  290. struct net_device *dev, bool notify);
  291. int cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
  292. struct net_device *dev, bool notify);
  293. /* MLME */
  294. int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  295. struct net_device *dev,
  296. struct ieee80211_channel *chan,
  297. enum nl80211_auth_type auth_type,
  298. const u8 *bssid,
  299. const u8 *ssid, int ssid_len,
  300. const u8 *ie, int ie_len,
  301. const u8 *key, int key_len, int key_idx,
  302. const u8 *auth_data, int auth_data_len);
  303. int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  304. struct net_device *dev,
  305. struct ieee80211_channel *chan,
  306. const u8 *bssid,
  307. const u8 *ssid, int ssid_len,
  308. struct cfg80211_assoc_request *req);
  309. int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  310. struct net_device *dev, const u8 *bssid,
  311. const u8 *ie, int ie_len, u16 reason,
  312. bool local_state_change);
  313. int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
  314. struct net_device *dev, const u8 *bssid,
  315. const u8 *ie, int ie_len, u16 reason,
  316. bool local_state_change);
  317. void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
  318. struct net_device *dev);
  319. int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid,
  320. u16 frame_type, const u8 *match_data,
  321. int match_len);
  322. void cfg80211_mlme_unreg_wk(struct work_struct *wk);
  323. void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid);
  324. void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev);
  325. int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev,
  326. struct wireless_dev *wdev,
  327. struct cfg80211_mgmt_tx_params *params,
  328. u64 *cookie);
  329. void cfg80211_oper_and_ht_capa(struct ieee80211_ht_cap *ht_capa,
  330. const struct ieee80211_ht_cap *ht_capa_mask);
  331. void cfg80211_oper_and_vht_capa(struct ieee80211_vht_cap *vht_capa,
  332. const struct ieee80211_vht_cap *vht_capa_mask);
  333. /* SME events */
  334. int cfg80211_connect(struct cfg80211_registered_device *rdev,
  335. struct net_device *dev,
  336. struct cfg80211_connect_params *connect,
  337. struct cfg80211_cached_keys *connkeys,
  338. const u8 *prev_bssid);
  339. void __cfg80211_connect_result(struct net_device *dev, const u8 *bssid,
  340. const u8 *req_ie, size_t req_ie_len,
  341. const u8 *resp_ie, size_t resp_ie_len,
  342. int status, bool wextev,
  343. struct cfg80211_bss *bss,
  344. enum nl80211_timeout_reason timeout_reason);
  345. void __cfg80211_disconnected(struct net_device *dev, const u8 *ie,
  346. size_t ie_len, u16 reason, bool from_ap);
  347. int cfg80211_disconnect(struct cfg80211_registered_device *rdev,
  348. struct net_device *dev, u16 reason,
  349. bool wextev);
  350. void __cfg80211_roamed(struct wireless_dev *wdev,
  351. struct cfg80211_bss *bss,
  352. const u8 *req_ie, size_t req_ie_len,
  353. const u8 *resp_ie, size_t resp_ie_len);
  354. int cfg80211_mgd_wext_connect(struct cfg80211_registered_device *rdev,
  355. struct wireless_dev *wdev);
  356. void cfg80211_autodisconnect_wk(struct work_struct *work);
  357. /* SME implementation */
  358. void cfg80211_conn_work(struct work_struct *work);
  359. void cfg80211_sme_scan_done(struct net_device *dev);
  360. bool cfg80211_sme_rx_assoc_resp(struct wireless_dev *wdev, u16 status);
  361. void cfg80211_sme_rx_auth(struct wireless_dev *wdev, const u8 *buf, size_t len);
  362. void cfg80211_sme_disassoc(struct wireless_dev *wdev);
  363. void cfg80211_sme_deauth(struct wireless_dev *wdev);
  364. void cfg80211_sme_auth_timeout(struct wireless_dev *wdev);
  365. void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev);
  366. void cfg80211_sme_abandon_assoc(struct wireless_dev *wdev);
  367. /* internal helpers */
  368. bool cfg80211_supported_cipher_suite(struct wiphy *wiphy, u32 cipher);
  369. int cfg80211_validate_key_settings(struct cfg80211_registered_device *rdev,
  370. struct key_params *params, int key_idx,
  371. bool pairwise, const u8 *mac_addr);
  372. void __cfg80211_scan_done(struct work_struct *wk);
  373. void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
  374. bool send_message);
  375. void __cfg80211_sched_scan_results(struct work_struct *wk);
  376. int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
  377. bool driver_initiated);
  378. void cfg80211_upload_connect_keys(struct wireless_dev *wdev);
  379. int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
  380. struct net_device *dev, enum nl80211_iftype ntype,
  381. u32 *flags, struct vif_params *params);
  382. void cfg80211_process_rdev_events(struct cfg80211_registered_device *rdev);
  383. void cfg80211_process_wdev_events(struct wireless_dev *wdev);
  384. bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range,
  385. u32 center_freq_khz, u32 bw_khz);
  386. /**
  387. * cfg80211_chandef_dfs_usable - checks if chandef is DFS usable
  388. * @wiphy: the wiphy to validate against
  389. * @chandef: the channel definition to check
  390. *
  391. * Checks if chandef is usable and we can/need start CAC on such channel.
  392. *
  393. * Return: Return true if all channels available and at least
  394. * one channel require CAC (NL80211_DFS_USABLE)
  395. */
  396. bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy,
  397. const struct cfg80211_chan_def *chandef);
  398. void cfg80211_set_dfs_state(struct wiphy *wiphy,
  399. const struct cfg80211_chan_def *chandef,
  400. enum nl80211_dfs_state dfs_state);
  401. void cfg80211_dfs_channels_update_work(struct work_struct *work);
  402. unsigned int
  403. cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy,
  404. const struct cfg80211_chan_def *chandef);
  405. void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev);
  406. bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy,
  407. struct ieee80211_channel *chan);
  408. bool cfg80211_beaconing_iface_active(struct wireless_dev *wdev);
  409. bool cfg80211_is_sub_chan(struct cfg80211_chan_def *chandef,
  410. struct ieee80211_channel *chan);
  411. static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
  412. {
  413. unsigned long end = jiffies;
  414. if (end >= start)
  415. return jiffies_to_msecs(end - start);
  416. return jiffies_to_msecs(end + (ULONG_MAX - start) + 1);
  417. }
  418. void
  419. cfg80211_get_chan_state(struct wireless_dev *wdev,
  420. struct ieee80211_channel **chan,
  421. enum cfg80211_chan_mode *chanmode,
  422. u8 *radar_detect);
  423. int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
  424. struct cfg80211_chan_def *chandef);
  425. int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
  426. const u8 *rates, unsigned int n_rates,
  427. u32 *mask);
  428. int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
  429. enum nl80211_iftype iftype, u32 beacon_int);
  430. void cfg80211_update_iface_num(struct cfg80211_registered_device *rdev,
  431. enum nl80211_iftype iftype, int num);
  432. void __cfg80211_leave(struct cfg80211_registered_device *rdev,
  433. struct wireless_dev *wdev);
  434. void cfg80211_leave(struct cfg80211_registered_device *rdev,
  435. struct wireless_dev *wdev);
  436. void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
  437. struct wireless_dev *wdev);
  438. void cfg80211_stop_nan(struct cfg80211_registered_device *rdev,
  439. struct wireless_dev *wdev);
  440. #define CFG80211_MAX_NUM_DIFFERENT_CHANNELS 10
  441. #ifdef CONFIG_CFG80211_DEVELOPER_WARNINGS
  442. #define CFG80211_DEV_WARN_ON(cond) WARN_ON(cond)
  443. #else
  444. /*
  445. * Trick to enable using it as a condition,
  446. * and also not give a warning when it's
  447. * not used that way.
  448. */
  449. #define CFG80211_DEV_WARN_ON(cond) ({bool __r = (cond); __r; })
  450. #endif
  451. void cfg80211_cqm_config_free(struct wireless_dev *wdev);
  452. #endif /* __NET_WIRELESS_CORE_H */