|
| 1 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | +/* |
| 3 | + * Copyright (C) 2026 by arancormonk <180709949+arancormonk@users.noreply.github.com> |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * @file |
| 8 | + * @brief Talkgroup/private policy evaluation and shared mutation helpers. |
| 9 | + */ |
| 10 | + |
| 11 | +#pragma once |
| 12 | + |
| 13 | +#include <dsd-neo/core/opts_fwd.h> |
| 14 | +#include <dsd-neo/core/state_fwd.h> |
| 15 | + |
| 16 | +#include <stdint.h> |
| 17 | + |
| 18 | +#ifdef __cplusplus |
| 19 | +extern "C" { |
| 20 | +#endif |
| 21 | + |
| 22 | +typedef enum { |
| 23 | + DSD_TG_POLICY_MATCH_NONE = 0, |
| 24 | + DSD_TG_POLICY_MATCH_RANGE = 1, |
| 25 | + DSD_TG_POLICY_MATCH_EXACT = 2, |
| 26 | +} dsd_tg_policy_match_type; |
| 27 | + |
| 28 | +typedef enum { |
| 29 | + DSD_TG_POLICY_PRIVATE_ALLOWLIST_UNKNOWN_ALLOW = 0, |
| 30 | + DSD_TG_POLICY_PRIVATE_ALLOWLIST_UNKNOWN_BLOCK = 1, |
| 31 | +} dsd_tg_policy_private_allowlist_mode; |
| 32 | + |
| 33 | +typedef enum { |
| 34 | + DSD_TG_POLICY_HOLD_COMPAT_GRANT = 0, |
| 35 | + DSD_TG_POLICY_HOLD_FORCE_MEDIA_ONLY = 1, |
| 36 | + DSD_TG_POLICY_HOLD_FORCE_TUNE_AND_MEDIA = 2, |
| 37 | +} dsd_tg_policy_hold_behavior; |
| 38 | + |
| 39 | +typedef enum { |
| 40 | + DSD_TG_POLICY_SOURCE_IMPORTED = 0, |
| 41 | + DSD_TG_POLICY_SOURCE_RUNTIME_ALIAS = 1, |
| 42 | + DSD_TG_POLICY_SOURCE_USER_LOCKOUT = 2, |
| 43 | + DSD_TG_POLICY_SOURCE_ENC_LOCKOUT = 3, |
| 44 | + DSD_TG_POLICY_SOURCE_LEGACY_UNKNOWN = 4, |
| 45 | +} dsd_tg_policy_entry_source; |
| 46 | + |
| 47 | +typedef enum { |
| 48 | + DSD_TG_POLICY_UPSERT_ADD_IF_MISSING = 0, |
| 49 | + DSD_TG_POLICY_UPSERT_REPLACE_FIRST = 1, |
| 50 | + DSD_TG_POLICY_UPSERT_REPLACE_LEARNED_ONLY = 2, |
| 51 | +} dsd_tg_policy_upsert_mode; |
| 52 | + |
| 53 | +typedef enum { |
| 54 | + DSD_TG_POLICY_BLOCK_NONE = 0u, |
| 55 | + DSD_TG_POLICY_BLOCK_GROUP_DISABLED = 1u << 0, |
| 56 | + DSD_TG_POLICY_BLOCK_PRIVATE_DISABLED = 1u << 1, |
| 57 | + DSD_TG_POLICY_BLOCK_DATA_DISABLED = 1u << 2, |
| 58 | + DSD_TG_POLICY_BLOCK_ENCRYPTED_DISABLED = 1u << 3, |
| 59 | + DSD_TG_POLICY_BLOCK_ALLOWLIST = 1u << 4, |
| 60 | + DSD_TG_POLICY_BLOCK_MODE = 1u << 5, |
| 61 | + DSD_TG_POLICY_BLOCK_HOLD = 1u << 6, |
| 62 | + DSD_TG_POLICY_BLOCK_AUDIO = 1u << 7, |
| 63 | + DSD_TG_POLICY_BLOCK_RECORD = 1u << 8, |
| 64 | + DSD_TG_POLICY_BLOCK_STREAM = 1u << 9, |
| 65 | +} dsd_tg_policy_block_reason; |
| 66 | + |
| 67 | +typedef struct { |
| 68 | + uint32_t id_start; |
| 69 | + uint32_t id_end; |
| 70 | + char mode[8]; |
| 71 | + char name[50]; |
| 72 | + int priority; |
| 73 | + uint8_t preempt; |
| 74 | + uint8_t audio; |
| 75 | + uint8_t record; |
| 76 | + uint8_t stream; |
| 77 | + uint8_t is_range; |
| 78 | + uint8_t source; |
| 79 | + unsigned int row; |
| 80 | +} dsd_tg_policy_entry; |
| 81 | + |
| 82 | +typedef struct { |
| 83 | + dsd_tg_policy_match_type match; |
| 84 | + dsd_tg_policy_entry entry; |
| 85 | +} dsd_tg_policy_lookup; |
| 86 | + |
| 87 | +typedef struct { |
| 88 | + uint32_t target_id; |
| 89 | + uint32_t source_id; |
| 90 | + int encrypted; |
| 91 | + int data_call; |
| 92 | + int tune_allowed; |
| 93 | + int audio_allowed; |
| 94 | + int record_allowed; |
| 95 | + int stream_allowed; |
| 96 | + int priority; |
| 97 | + int preempt_requested; |
| 98 | + uint32_t block_reasons; |
| 99 | + int tg_hold_active; |
| 100 | + int tg_hold_match; |
| 101 | + char mode[8]; |
| 102 | + char name[50]; |
| 103 | + dsd_tg_policy_match_type match; |
| 104 | +} dsd_tg_policy_decision; |
| 105 | + |
| 106 | +typedef struct { |
| 107 | + uint32_t target_id; |
| 108 | + uint32_t source_id; |
| 109 | + long freq_hz; |
| 110 | + int channel; |
| 111 | + int slot; |
| 112 | + int requires_tuner_retune; |
| 113 | +} dsd_tg_policy_call_route; |
| 114 | + |
| 115 | +int dsd_tg_policy_make_legacy_exact_entry(uint32_t id, const char* mode, const char* name, |
| 116 | + dsd_tg_policy_entry_source source, dsd_tg_policy_entry* out); |
| 117 | +int dsd_tg_policy_add_range_entry(dsd_state* state, const dsd_tg_policy_entry* entry); |
| 118 | +int dsd_tg_policy_lookup_id(const dsd_state* state, uint32_t id, dsd_tg_policy_lookup* out); |
| 119 | +int dsd_tg_policy_evaluate_group_call(const dsd_opts* opts, const dsd_state* state, uint32_t tg, uint32_t src, |
| 120 | + int encrypted, int data_call, dsd_tg_policy_hold_behavior hold_behavior, |
| 121 | + dsd_tg_policy_decision* out); |
| 122 | +int dsd_tg_policy_evaluate_private_call(const dsd_opts* opts, const dsd_state* state, uint32_t src, uint32_t dst, |
| 123 | + int encrypted, int data_call, |
| 124 | + dsd_tg_policy_private_allowlist_mode allowlist_mode, |
| 125 | + dsd_tg_policy_hold_behavior hold_behavior, dsd_tg_policy_decision* out); |
| 126 | +int dsd_tg_policy_append_legacy_exact(dsd_state* state, const dsd_tg_policy_entry* entry); |
| 127 | +int dsd_tg_policy_upsert_legacy_exact(dsd_state* state, const dsd_tg_policy_entry* entry, |
| 128 | + dsd_tg_policy_upsert_mode mode); |
| 129 | +int dsd_tg_policy_append_group_file_row(const dsd_opts* opts, const dsd_tg_policy_entry* entry, |
| 130 | + const char* legacy_metadata); |
| 131 | + |
| 132 | +int dsd_tg_policy_should_preempt(const dsd_opts* opts, const dsd_state* state, |
| 133 | + const dsd_tg_policy_call_route* candidate_route, |
| 134 | + const dsd_tg_policy_decision* candidate, double now_mono_s); |
| 135 | +int dsd_tg_policy_note_active_call(dsd_state* state, const dsd_tg_policy_call_route* route, |
| 136 | + const dsd_tg_policy_decision* decision, double now_mono_s); |
| 137 | +int dsd_tg_policy_clear_active_call(dsd_state* state, int slot); |
| 138 | +int dsd_tg_policy_clear_active_call_route(dsd_state* state, const dsd_tg_policy_call_route* route); |
| 139 | + |
| 140 | +int dsd_tg_policy_reload_group_file(dsd_opts* opts, dsd_state* state); |
| 141 | + |
| 142 | +#ifdef __cplusplus |
| 143 | +} |
| 144 | +#endif |
0 commit comments