Wideband autonomous SDR analysis engine forked from sdr-visual-suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.9KB

  1. package pipeline
  2. import "strings"
  3. // SurveillanceDetectionPolicy describes how surveillance levels are governed for detection.
  4. type SurveillanceDetectionPolicy struct {
  5. DerivedDetection string `json:"derived_detection"`
  6. DerivedDetectionEnabled bool `json:"derived_detection_enabled"`
  7. DerivedDetectionReason string `json:"derived_detection_reason,omitempty"`
  8. DerivedDetectionMode string `json:"derived_detection_mode,omitempty"`
  9. PrimaryRole string `json:"primary_role"`
  10. DerivedRole string `json:"derived_role"`
  11. SupportRole string `json:"support_role"`
  12. PresentationRole string `json:"presentation_role"`
  13. }
  14. func normalizeDerivedDetection(mode string) string {
  15. switch strings.ToLower(strings.TrimSpace(mode)) {
  16. case "on", "true", "enabled", "enable":
  17. return "on"
  18. case "off", "false", "disabled", "disable":
  19. return "off"
  20. case "auto", "":
  21. return "auto"
  22. default:
  23. return "auto"
  24. }
  25. }
  26. func strategyIsMulti(strategy string) bool {
  27. switch strings.ToLower(strings.TrimSpace(strategy)) {
  28. case "multi-resolution", "multi", "multi-res", "multi_res":
  29. return true
  30. default:
  31. return strings.Contains(strings.ToLower(strategy), "multi")
  32. }
  33. }
  34. // SurveillanceDetectionPolicyFromPolicy derives detection governance from policy intent/profile.
  35. func SurveillanceDetectionPolicyFromPolicy(policy Policy) SurveillanceDetectionPolicy {
  36. mode := normalizeDerivedDetection(policy.SurveillanceDerivedDetection)
  37. strategyMulti := strategyIsMulti(policy.SurveillanceStrategy)
  38. enabled := false
  39. reason := ""
  40. switch mode {
  41. case "on":
  42. if strategyMulti {
  43. enabled = true
  44. reason = "config"
  45. } else {
  46. enabled = false
  47. reason = "strategy"
  48. }
  49. case "off":
  50. enabled = false
  51. reason = "config"
  52. default:
  53. if !strategyMulti {
  54. enabled = false
  55. reason = "strategy"
  56. } else {
  57. intent := strings.ToLower(strings.TrimSpace(policy.Intent))
  58. profile := strings.ToLower(strings.TrimSpace(policy.Profile))
  59. modeName := strings.ToLower(strings.TrimSpace(policy.Mode))
  60. switch {
  61. case strings.Contains(profile, "archive") || strings.Contains(intent, "archive") || strings.Contains(intent, "triage") || strings.Contains(modeName, "archive"):
  62. enabled = false
  63. reason = "archive"
  64. case strings.Contains(profile, "legacy") || strings.Contains(modeName, "legacy"):
  65. enabled = false
  66. reason = "legacy"
  67. default:
  68. enabled = true
  69. reason = "auto"
  70. }
  71. }
  72. }
  73. modeState := "disabled"
  74. if strategyMulti {
  75. if enabled {
  76. modeState = "detection"
  77. } else {
  78. modeState = "support"
  79. }
  80. }
  81. return SurveillanceDetectionPolicy{
  82. DerivedDetection: mode,
  83. DerivedDetectionEnabled: enabled,
  84. DerivedDetectionReason: reason,
  85. DerivedDetectionMode: modeState,
  86. PrimaryRole: RoleSurveillancePrimary,
  87. DerivedRole: RoleSurveillanceDerived,
  88. SupportRole: RoleSurveillanceSupport,
  89. PresentationRole: RolePresentation,
  90. }
  91. }