Skip to content

Commit cbc161e

Browse files
authored
Op25 update Nov 2023 (#883)
* Updates from OP25 This is just the changes in the core lib * changed Tap size to improve perf * tuning performance
1 parent 23e3d9f commit cbc161e

19 files changed

+346
-234
lines changed

lib/op25_repeater/lib/dmr_slot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class dmr_slot {
104104
int d_slot_mask;
105105
int d_src_id;
106106
bool d_terminated;
107-
log_ts logts;
107+
log_ts& logts;
108108
CBPTC19696 bptc;
109109
CDMRTrellis trellis;
110110
ezpwd::RS<255,252> rs12; // Reed-Solomon(12,9) object for Link Control decode

lib/op25_repeater/lib/p25_crypt_algs.cc

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ p25_crypt_algs::p25_crypt_algs(log_ts& logger, int debug, int msgq_id) :
3333
logts(logger),
3434
d_debug(debug),
3535
d_msgq_id(msgq_id),
36-
d_fr_type(FT_UNK),
36+
d_pr_type(PT_UNK),
3737
d_algid(0x80),
3838
d_keyid(0),
3939
d_mi{0},
@@ -59,7 +59,7 @@ void p25_crypt_algs::key(uint16_t keyid, uint8_t algid, const std::vector<uint8_
5959
}
6060

6161
// generic entry point to prepare for decryption
62-
bool p25_crypt_algs::prepare(uint8_t algid, uint16_t keyid, frame_type fr_type, uint8_t *MI) {
62+
bool p25_crypt_algs::prepare(uint8_t algid, uint16_t keyid, protocol_type pr_type, uint8_t *MI) {
6363
bool rc = false;
6464
d_algid = algid;
6565
d_keyid = keyid;
@@ -79,7 +79,7 @@ bool p25_crypt_algs::prepare(uint8_t algid, uint16_t keyid, frame_type fr_type,
7979
switch (algid) {
8080
case 0xaa: // ADP RC4
8181
d_adp_position = 0;
82-
d_fr_type = fr_type;
82+
d_pr_type = pr_type;
8383
adp_keystream_gen();
8484
rc = true;
8585
break;
@@ -91,15 +91,15 @@ bool p25_crypt_algs::prepare(uint8_t algid, uint16_t keyid, frame_type fr_type,
9191
}
9292

9393
// generic entry point to perform decryption
94-
bool p25_crypt_algs::process(packed_codeword& PCW) {
94+
bool p25_crypt_algs::process(packed_codeword& PCW, frame_type fr_type, int voice_subframe) {
9595
bool rc = false;
9696

9797
if (d_key_iter == d_keys.end())
9898
return false;
9999

100100
switch (d_algid) {
101101
case 0xaa: // ADP RC4
102-
rc = adp_process(PCW);
102+
rc = adp_process(PCW, fr_type, voice_subframe);
103103
break;
104104

105105
default:
@@ -110,39 +110,48 @@ bool p25_crypt_algs::process(packed_codeword& PCW) {
110110
}
111111

112112
// ADP RC4 decryption
113-
bool p25_crypt_algs::adp_process(packed_codeword& PCW) {
113+
bool p25_crypt_algs::adp_process(packed_codeword& PCW, frame_type fr_type, int voice_subframe) {
114114
bool rc = true;
115-
size_t offset = 0;
115+
size_t offset = 256;
116116

117117
if (d_key_iter == d_keys.end())
118118
return false;
119119

120-
switch (d_fr_type) {
120+
switch (fr_type) {
121121
case FT_LDU1:
122122
offset = 0;
123123
break;
124124
case FT_LDU2:
125125
offset = 101;
126126
break;
127+
case FT_4V_0:
128+
offset += 7 * voice_subframe;
129+
break;
130+
case FT_4V_1:
131+
offset += 7 * (voice_subframe + 4);
132+
break;
133+
case FT_4V_2:
134+
offset += 7 * (voice_subframe + 8);
135+
break;
136+
case FT_4V_3:
137+
offset += 7 * (voice_subframe + 12);
138+
break;
127139
case FT_2V:
128-
case FT_4V:
129-
offset = 0;
140+
offset += 7 * (voice_subframe + 16);
130141
break;
131142
default:
132143
rc = false;
133144
break;
134145
}
135-
if ((d_fr_type == FT_LDU1) || (d_fr_type == FT_LDU2)) {
146+
if (d_pr_type == PT_P25_PHASE1) {
136147
//FDMA
137148
offset += (d_adp_position * 11) + 267 + ((d_adp_position < 8) ? 0 : 2); // voice only; skip LCW and LSD
138149
d_adp_position = (d_adp_position + 1) % 9;
139150
for (int j = 0; j < 11; ++j) {
140151
PCW[j] = adp_keystream[j + offset] ^ PCW[j];
141152
}
142-
} else if ((d_fr_type == FT_2V) || (d_fr_type == FT_4V)) {
153+
} else if (d_pr_type == PT_P25_PHASE2) {
143154
//TDMA
144-
offset += (d_adp_position * 7) + 256;
145-
d_adp_position = (d_adp_position + 1) % 18;
146155
for (int j = 0; j < 7; ++j) {
147156
PCW[j] = adp_keystream[j + offset] ^ PCW[j];
148157
}

lib/op25_repeater/lib/p25_crypt_algs.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,25 @@ struct key_info {
3636
std::vector<uint8_t> key;
3737
};
3838

39-
enum frame_type { FT_UNK = 0, FT_LDU1, FT_LDU2, FT_2V, FT_4V };
39+
enum frame_type { FT_UNK = 0, FT_LDU1, FT_LDU2, FT_2V, FT_4V_0, FT_4V_1, FT_4V_2, FT_4V_3 };
40+
enum protocol_type { PT_UNK = 0, PT_P25_PHASE1, PT_P25_PHASE2 };
4041

4142
class p25_crypt_algs
4243
{
4344
private:
4445
log_ts& logts;
4546
int d_debug;
4647
int d_msgq_id;
47-
frame_type d_fr_type;
48+
protocol_type d_pr_type;
4849
uint8_t d_algid;
4950
uint16_t d_keyid;
5051
uint8_t d_mi[9];
5152
std::unordered_map<uint16_t, key_info> d_keys;
5253
std::unordered_map<uint16_t, key_info>::const_iterator d_key_iter;
5354
uint8_t adp_keystream[469];
54-
int d_adp_position;
55+
uint32_t d_adp_position;
5556

56-
bool adp_process(packed_codeword& PCW);
57+
bool adp_process(packed_codeword& PCW, frame_type fr_type, int voice_subframe);
5758
void adp_keystream_gen();
5859
void adp_swap(uint8_t *S, uint32_t i, uint32_t j);
5960

@@ -62,8 +63,8 @@ class p25_crypt_algs
6263
~p25_crypt_algs();
6364

6465
void key(uint16_t keyid, uint8_t algid, const std::vector<uint8_t> &key);
65-
bool prepare(uint8_t algid, uint16_t keyid, frame_type fr_type, uint8_t *MI);
66-
bool process(packed_codeword& PCW);
66+
bool prepare(uint8_t algid, uint16_t keyid, protocol_type pr_type, uint8_t *MI);
67+
bool process(packed_codeword& PCW, frame_type fr_type, int voice_subframe);
6768
void reset(void);
6869
inline void set_debug(int debug) {d_debug = debug;}
6970
};

lib/op25_repeater/lib/p25p1_fdma.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ namespace gr {
404404

405405
void p25p1_fdma::process_TTDU() {
406406
process_duid(framer->duid, framer->nac, NULL, 0);
407+
reset_ess();
407408

408409
if ((d_do_imbe || d_do_audio_output) && (framer->duid == 0x3 || framer->duid == 0xf)) { // voice termination
409410
op25audio.send_audio_flag(op25_audio::DRAIN);
@@ -654,7 +655,7 @@ namespace gr {
654655
void p25p1_fdma::process_voice(const bit_vector& A, const frame_type fr_type) {
655656
if (d_do_imbe || d_do_audio_output) {
656657
if (encrypted())
657-
crypt_algs.prepare(ess_algid, ess_keyid, fr_type, ess_mi);
658+
crypt_algs.prepare(ess_algid, ess_keyid, PT_P25_PHASE1, ess_mi);
658659

659660
for(size_t i = 0; i < nof_voice_codewords; ++i) {
660661
voice_codeword cw(voice_codeword_sz);
@@ -680,7 +681,7 @@ namespace gr {
680681
if (encrypted()) {
681682
packed_codeword ciphertext;
682683
imbe_pack(ciphertext, u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7]);
683-
audio_valid = crypt_algs.process(ciphertext);
684+
audio_valid = crypt_algs.process(ciphertext, fr_type, i);
684685
imbe_unpack(ciphertext, u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7]);
685686
}
686687

@@ -777,6 +778,12 @@ namespace gr {
777778
qtimer.reset();
778779
}
779780

781+
void p25p1_fdma::call_end() {
782+
if (d_do_audio_output)
783+
op25audio.send_audio_flag(op25_audio::DRAIN);
784+
reset_ess();
785+
}
786+
780787
void p25p1_fdma::crypt_reset() {
781788
crypt_algs.reset();
782789
}

lib/op25_repeater/lib/p25p1_fdma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace gr {
6969
void process_frame();
7070
void check_timeout();
7171
inline bool encrypted() { return (ess_algid != 0x80); }
72+
inline void reset_ess() { ess_algid = 0x80; memset(ess_mi, 0, sizeof(ess_mi)); }
7273
void send_msg(const std::string msg_str, long msg_type);
7374

7475
// internal instance variables and state
@@ -116,6 +117,7 @@ namespace gr {
116117
void set_debug(int debug);
117118
void set_nac(int nac);
118119
void reset_timer();
120+
void call_end();
119121
void crypt_reset();
120122
void crypt_key(uint16_t keyid, uint8_t algid, const std::vector<uint8_t> &key);
121123
void rx_sym (const uint8_t *syms, int nsyms);

0 commit comments

Comments
 (0)