dfs_pattern_detector.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2012 Neratec Solutions AG
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DFS_PATTERN_DETECTOR_H
  17. #define DFS_PATTERN_DETECTOR_H
  18. #include <linux/types.h>
  19. #include <linux/list.h>
  20. #include <linux/nl80211.h>
  21. /* tolerated deviation of radar time stamp in usecs on both sides
  22. * TODO: this might need to be HW-dependent
  23. */
  24. #define PRI_TOLERANCE 16
  25. /**
  26. * struct ath_dfs_pool_stats - DFS Statistics for global pools
  27. */
  28. struct ath_dfs_pool_stats {
  29. u32 pool_reference;
  30. u32 pulse_allocated;
  31. u32 pulse_alloc_error;
  32. u32 pulse_used;
  33. u32 pseq_allocated;
  34. u32 pseq_alloc_error;
  35. u32 pseq_used;
  36. };
  37. /**
  38. * struct pulse_event - describing pulses reported by PHY
  39. * @ts: pulse time stamp in us
  40. * @freq: channel frequency in MHz
  41. * @width: pulse duration in us
  42. * @rssi: rssi of radar event
  43. * @chirp: chirp detected in pulse
  44. */
  45. struct pulse_event {
  46. u64 ts;
  47. u16 freq;
  48. u8 width;
  49. u8 rssi;
  50. bool chirp;
  51. };
  52. /**
  53. * struct radar_detector_specs - detector specs for a radar pattern type
  54. * @type_id: pattern type, as defined by regulatory
  55. * @width_min: minimum radar pulse width in [us]
  56. * @width_max: maximum radar pulse width in [us]
  57. * @pri_min: minimum pulse repetition interval in [us] (including tolerance)
  58. * @pri_max: minimum pri in [us] (including tolerance)
  59. * @num_pri: maximum number of different pri for this type
  60. * @ppb: pulses per bursts for this type
  61. * @ppb_thresh: number of pulses required to trigger detection
  62. * @max_pri_tolerance: pulse time stamp tolerance on both sides [us]
  63. * @chirp: chirp required for the radar pattern
  64. */
  65. struct radar_detector_specs {
  66. u8 type_id;
  67. u8 width_min;
  68. u8 width_max;
  69. u16 pri_min;
  70. u16 pri_max;
  71. u8 num_pri;
  72. u8 ppb;
  73. u8 ppb_thresh;
  74. u8 max_pri_tolerance;
  75. bool chirp;
  76. };
  77. /**
  78. * struct dfs_pattern_detector - DFS pattern detector
  79. * @exit(): destructor
  80. * @set_dfs_domain(): set DFS domain, resets detector lines upon domain changes
  81. * @add_pulse(): add radar pulse to detector, returns true on detection
  82. * @region: active DFS region, NL80211_DFS_UNSET until set
  83. * @num_radar_types: number of different radar types
  84. * @last_pulse_ts: time stamp of last valid pulse in usecs
  85. * @radar_detector_specs: array of radar detection specs
  86. * @channel_detectors: list connecting channel_detector elements
  87. */
  88. struct dfs_pattern_detector {
  89. void (*exit)(struct dfs_pattern_detector *dpd);
  90. bool (*set_dfs_domain)(struct dfs_pattern_detector *dpd,
  91. enum nl80211_dfs_regions region);
  92. bool (*add_pulse)(struct dfs_pattern_detector *dpd,
  93. struct pulse_event *pe);
  94. struct ath_dfs_pool_stats (*get_stats)(struct dfs_pattern_detector *dpd);
  95. enum nl80211_dfs_regions region;
  96. u8 num_radar_types;
  97. u64 last_pulse_ts;
  98. /* needed for ath_dbg() */
  99. struct ath_common *common;
  100. const struct radar_detector_specs *radar_spec;
  101. struct list_head channel_detectors;
  102. };
  103. /**
  104. * dfs_pattern_detector_init() - constructor for pattern detector class
  105. * @param region: DFS domain to be used, can be NL80211_DFS_UNSET at creation
  106. * @return instance pointer on success, NULL otherwise
  107. */
  108. extern struct dfs_pattern_detector *
  109. dfs_pattern_detector_init(struct ath_common *common,
  110. enum nl80211_dfs_regions region);
  111. #endif /* DFS_PATTERN_DETECTOR_H */