|
10 | 10 | * 2022-09 DSD-FME Florida Man Edition |
11 | 11 | *-----------------------------------------------------------------------------*/ |
12 | 12 |
|
| 13 | +#include <dsd-neo/core/audio.h> |
13 | 14 | #include <dsd-neo/core/constants.h> |
14 | 15 | #include <dsd-neo/core/dsd_time.h> |
15 | 16 | #include <dsd-neo/core/file_io.h> |
|
28 | 29 | #include "dsd-neo/core/opts_fwd.h" |
29 | 30 | #include "dsd-neo/core/state_fwd.h" |
30 | 31 |
|
| 32 | +static int |
| 33 | +p25p2_xcch_slot_audio_allowed(const dsd_opts* opts, const dsd_state* state, int slot) { |
| 34 | + int alg = 0; |
| 35 | + |
| 36 | + if (!state || slot < 0 || slot > 1) { |
| 37 | + return 0; |
| 38 | + } |
| 39 | + |
| 40 | + if (slot == 0) { |
| 41 | + alg = state->payload_algid; |
| 42 | + } else { |
| 43 | + alg = state->payload_algidR; |
| 44 | + } |
| 45 | + |
| 46 | + return dsd_p25p2_decode_audio_allowed(opts, state, slot, alg); |
| 47 | +} |
| 48 | + |
31 | 49 | void |
32 | 50 | process_SACCH_MAC_PDU(dsd_opts* opts, dsd_state* state, int payload[180]) { |
33 | 51 | //Figure out which PDU we are looking at, see above info on 8.4.1 |
@@ -216,14 +234,7 @@ process_SACCH_MAC_PDU(dsd_opts* opts, dsd_state* state, int payload[180]) { |
216 | 234 | } |
217 | 235 | // Conditionally enable audio only if clear or decryptable |
218 | 236 | { |
219 | | - int allow_audio = 0; |
220 | | - int alg = (slot == 0) ? state->payload_algid : state->payload_algidR; |
221 | | - unsigned long long key = (slot == 0) ? state->R : state->RR; |
222 | | - int aes_loaded = state->aes_key_loaded[slot]; |
223 | | - if (alg == 0 || alg == 0x80 || ((alg == 0xAA || alg == 0x81 || alg == 0x9F) && key != 0) |
224 | | - || ((alg == 0x84 || alg == 0x89) && aes_loaded == 1)) { |
225 | | - allow_audio = 1; // clear or decryptable with key |
226 | | - } |
| 237 | + int allow_audio = p25p2_xcch_slot_audio_allowed(opts, state, slot); |
227 | 238 | state->p25_p2_audio_allowed[slot] = allow_audio; |
228 | 239 | // Only set PTT burst indicator when audio is allowed; encrypted/locked-out |
229 | 240 | // calls should not influence audio routing decisions |
@@ -295,14 +306,7 @@ process_SACCH_MAC_PDU(dsd_opts* opts, dsd_state* state, int payload[180]) { |
295 | 306 | } |
296 | 307 | // Conditionally enable audio only if clear or decryptable |
297 | 308 | { |
298 | | - int allow_audio = 0; |
299 | | - int alg = (slot == 0) ? state->payload_algid : state->payload_algidR; |
300 | | - unsigned long long key = (slot == 0) ? state->R : state->RR; |
301 | | - int aes_loaded = state->aes_key_loaded[slot]; |
302 | | - if (alg == 0 || alg == 0x80 || ((alg == 0xAA || alg == 0x81 || alg == 0x9F) && key != 0) |
303 | | - || ((alg == 0x84 || alg == 0x89) && aes_loaded == 1)) { |
304 | | - allow_audio = 1; |
305 | | - } |
| 309 | + int allow_audio = p25p2_xcch_slot_audio_allowed(opts, state, slot); |
306 | 310 | state->p25_p2_audio_allowed[slot] = allow_audio; |
307 | 311 | // Only set PTT burst indicator when audio is allowed; encrypted/locked-out |
308 | 312 | // calls should not influence audio routing decisions |
@@ -502,18 +506,7 @@ process_SACCH_MAC_PDU(dsd_opts* opts, dsd_state* state, int payload[180]) { |
502 | 506 | fprintf(stderr, "%s", KNRM); |
503 | 507 | // Enable audio per policy (respect encryption, key presence, and ignore stale packet bit when clear) |
504 | 508 | { |
505 | | - int allow_audio = 0; |
506 | | - int alg = (slot == 0) ? state->payload_algid : state->payload_algidR; |
507 | | - unsigned long long key = (slot == 0) ? state->R : state->RR; |
508 | | - int aes_loaded = state->aes_key_loaded[slot]; |
509 | | - // If stream is clear or decryptable, enable regardless of a stale Packet/Data flag |
510 | | - if (alg == 0 || alg == 0x80 || ((alg == 0xAA || alg == 0x81 || alg == 0x9F) && key != 0) |
511 | | - || ((alg == 0x84 || alg == 0x89) && aes_loaded == 1)) { |
512 | | - allow_audio = 1; |
513 | | - } else { |
514 | | - // Otherwise, suppress audio for Packet/Data sessions |
515 | | - allow_audio = state->p25_call_is_packet[slot] ? 0 : allow_audio; |
516 | | - } |
| 509 | + int allow_audio = p25p2_xcch_slot_audio_allowed(opts, state, slot); |
517 | 510 | state->p25_p2_audio_allowed[slot] = allow_audio; |
518 | 511 |
|
519 | 512 | // Only set voice-active burst indicator when audio is allowed; |
@@ -687,14 +680,7 @@ process_FACCH_MAC_PDU(dsd_opts* opts, dsd_state* state, int payload[156]) { |
687 | 680 | } |
688 | 681 | // Conditionally enable audio only if clear or decryptable |
689 | 682 | { |
690 | | - int allow_audio = 0; |
691 | | - int alg = (slot == 0) ? state->payload_algid : state->payload_algidR; |
692 | | - unsigned long long key = (slot == 0) ? state->R : state->RR; |
693 | | - int aes_loaded = state->aes_key_loaded[slot]; |
694 | | - if (alg == 0 || alg == 0x80 || ((alg == 0xAA || alg == 0x81 || alg == 0x9F) && key != 0) |
695 | | - || ((alg == 0x84 || alg == 0x89) && aes_loaded == 1)) { |
696 | | - allow_audio = 1; // clear or decryptable with key |
697 | | - } |
| 683 | + int allow_audio = p25p2_xcch_slot_audio_allowed(opts, state, slot); |
698 | 684 | state->p25_p2_audio_allowed[slot] = allow_audio; |
699 | 685 | } |
700 | 686 | } |
@@ -761,14 +747,7 @@ process_FACCH_MAC_PDU(dsd_opts* opts, dsd_state* state, int payload[156]) { |
761 | 747 | } |
762 | 748 | // Conditionally enable audio only if clear or decryptable |
763 | 749 | { |
764 | | - int allow_audio = 0; |
765 | | - int alg = (slot == 0) ? state->payload_algid : state->payload_algidR; |
766 | | - unsigned long long key = (slot == 0) ? state->R : state->RR; |
767 | | - int aes_loaded = state->aes_key_loaded[slot]; |
768 | | - if (alg == 0 || alg == 0x80 || ((alg == 0xAA || alg == 0x81 || alg == 0x9F) && key != 0) |
769 | | - || ((alg == 0x84 || alg == 0x89) && aes_loaded == 1)) { |
770 | | - allow_audio = 1; |
771 | | - } |
| 750 | + int allow_audio = p25p2_xcch_slot_audio_allowed(opts, state, slot); |
772 | 751 | state->p25_p2_audio_allowed[slot] = allow_audio; |
773 | 752 | } |
774 | 753 | } |
@@ -961,16 +940,7 @@ process_FACCH_MAC_PDU(dsd_opts* opts, dsd_state* state, int payload[156]) { |
961 | 940 | p25_sm_emit_active(opts, state, slot); |
962 | 941 | // Enable audio per policy (respect encryption, key presence, and ignore stale packet bit when clear) |
963 | 942 | { |
964 | | - int allow_audio = 0; |
965 | | - int alg = (slot == 0) ? state->payload_algid : state->payload_algidR; |
966 | | - unsigned long long key = (slot == 0) ? state->R : state->RR; |
967 | | - int aes_loaded = state->aes_key_loaded[slot]; |
968 | | - if (alg == 0 || alg == 0x80 || ((alg == 0xAA || alg == 0x81 || alg == 0x9F) && key != 0) |
969 | | - || ((alg == 0x84 || alg == 0x89) && aes_loaded == 1)) { |
970 | | - allow_audio = 1; // clear or decryptable with key |
971 | | - } else { |
972 | | - allow_audio = state->p25_call_is_packet[slot] ? 0 : allow_audio; |
973 | | - } |
| 943 | + int allow_audio = p25p2_xcch_slot_audio_allowed(opts, state, slot); |
974 | 944 | state->p25_p2_audio_allowed[slot] = allow_audio; |
975 | 945 | } |
976 | 946 |
|
|
0 commit comments