-
Notifications
You must be signed in to change notification settings - Fork 240
/
DMRDecoderState.java
1491 lines (1389 loc) · 66.4 KB
/
DMRDecoderState.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* *****************************************************************************
* Copyright (C) 2014-2024 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.module.decode.dmr;
import com.google.common.eventbus.Subscribe;
import io.github.dsheirer.channel.state.ChangeChannelTimeoutEvent;
import io.github.dsheirer.channel.state.DecoderStateEvent;
import io.github.dsheirer.channel.state.DecoderStateEvent.Event;
import io.github.dsheirer.channel.state.State;
import io.github.dsheirer.channel.state.TimeslotDecoderState;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.controller.channel.Channel.ChannelType;
import io.github.dsheirer.controller.channel.ChannelConfigurationChangeNotification;
import io.github.dsheirer.identifier.Form;
import io.github.dsheirer.identifier.Identifier;
import io.github.dsheirer.identifier.IdentifierClass;
import io.github.dsheirer.identifier.IdentifierCollection;
import io.github.dsheirer.identifier.MutableIdentifierCollection;
import io.github.dsheirer.identifier.Role;
import io.github.dsheirer.identifier.alias.DmrTalkerAliasIdentifier;
import io.github.dsheirer.identifier.integer.IntegerIdentifier;
import io.github.dsheirer.identifier.talkgroup.TalkgroupIdentifier;
import io.github.dsheirer.log.LoggingSuppressor;
import io.github.dsheirer.message.IMessage;
import io.github.dsheirer.module.decode.DecoderType;
import io.github.dsheirer.module.decode.dmr.channel.DMRChannel;
import io.github.dsheirer.module.decode.dmr.channel.DMRLsn;
import io.github.dsheirer.module.decode.dmr.event.DMRDecodeEvent;
import io.github.dsheirer.module.decode.dmr.identifier.DMRTalkgroup;
import io.github.dsheirer.module.decode.dmr.message.DMRMessage;
import io.github.dsheirer.module.decode.dmr.message.data.DataMessage;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.CSBKMessage;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.hytera.HyteraTrafficChannelTalkerStatus;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.CapacityMaxAdvantageModeVoiceChannelUpdate;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.CapacityMaxAloha;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.CapacityMaxOpenModeVoiceChannelUpdate;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.CapacityPlusNeighbors;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.CapacityPlusSiteStatus;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.ConnectPlusDataChannelGrant;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.ConnectPlusVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.Aloha;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.Protect;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.acknowledge.Acknowledge;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.ahoy.Ahoy;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.ahoy.ServiceRadioCheck;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.ahoy.StunReviveKill;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.announcement.Announcement;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.announcement.VoteNowAdvice;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.grant.ChannelGrant;
import io.github.dsheirer.module.decode.dmr.message.data.header.HeaderMessage;
import io.github.dsheirer.module.decode.dmr.message.data.header.hytera.HyteraDataEncryptionHeader;
import io.github.dsheirer.module.decode.dmr.message.data.lc.LCMessage;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.GPSInformation;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.GroupVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.TalkerAliasComplete;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.UnitToUnitVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.hytera.HyteraGroupVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.hytera.HyteraUnitToUnitVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.motorola.CapacityMaxTalkerAlias;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.motorola.CapacityMaxTalkerAliasContinuation;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.motorola.CapacityMaxVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.motorola.CapacityPlusEncryptedVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.motorola.CapacityPlusWideAreaVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.motorola.MotorolaGroupVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.lc.shorty.CapacityPlusRestChannel;
import io.github.dsheirer.module.decode.dmr.message.data.packet.DMRPacketMessage;
import io.github.dsheirer.module.decode.dmr.message.data.packet.UDTShortMessageService;
import io.github.dsheirer.module.decode.dmr.message.data.terminator.Terminator;
import io.github.dsheirer.module.decode.dmr.message.type.ServiceOptions;
import io.github.dsheirer.module.decode.dmr.message.voice.VoiceEMBMessage;
import io.github.dsheirer.module.decode.dmr.message.voice.VoiceMessage;
import io.github.dsheirer.module.decode.dmr.message.voice.embedded.EmbeddedParameters;
import io.github.dsheirer.module.decode.dmr.message.voice.embedded.EncryptionParameters;
import io.github.dsheirer.module.decode.event.DecodeEvent;
import io.github.dsheirer.module.decode.event.DecodeEventType;
import io.github.dsheirer.module.decode.event.IDecodeEvent;
import io.github.dsheirer.module.decode.event.PlottableDecodeEvent;
import io.github.dsheirer.module.decode.ip.hytera.rrs.HyteraRrsPacket;
import io.github.dsheirer.module.decode.ip.hytera.sds.HyteraUnknownPacket;
import io.github.dsheirer.module.decode.ip.hytera.shortdata.HyteraShortDataPacket;
import io.github.dsheirer.module.decode.ip.hytera.sms.HyteraSmsPacket;
import io.github.dsheirer.module.decode.ip.mototrbo.ars.ARSPacket;
import io.github.dsheirer.module.decode.ip.mototrbo.lrrp.LRRPPacket;
import io.github.dsheirer.module.decode.ip.mototrbo.xcmp.XCMPPacket;
import io.github.dsheirer.protocol.Protocol;
import io.github.dsheirer.source.tuner.channel.rotation.AddChannelRotationActiveStateRequest;
import io.github.dsheirer.util.PacketUtil;
import java.util.List;
import java.util.Map;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Decoder state for an DMR channel. Maintains the call/data/idle state of the channel and produces events by
* monitoring the decoded message stream.
*/
public class DMRDecoderState extends TimeslotDecoderState
{
private final static Logger mLog = LoggerFactory.getLogger(DMRDecoderState.class);
private static final LoggingSuppressor LOGGING_SUPPRESSOR = new LoggingSuppressor(mLog);
private static final long MAX_VALID_CALL_DURATION_MS = 30000;
private static final AddChannelRotationActiveStateRequest CAPACITY_PLUS_ACTIVE_STATE_REQUEST =
new AddChannelRotationActiveStateRequest(State.ACTIVE);
private Channel mChannel;
private DMRNetworkConfigurationMonitor mNetworkConfigurationMonitor;
private DMRTrafficChannelManager mTrafficChannelManager;
private DecodeEvent mCurrentCallEvent;
private long mCurrentFrequency;
private boolean mIgnoreCRCChecksums;
private DMRDecoderState mSisterDecoderState;
/**
* Constructs an DMR decoder state with an optional traffic channel manager.
* @param channel with configuration details
* @param timeslot for this decoder state (1 or 2)
* @param trafficChannelManager for handling traffic channel grants.
*/
public DMRDecoderState(Channel channel, int timeslot, DMRTrafficChannelManager trafficChannelManager)
{
super(timeslot);
mChannel = channel;
mTrafficChannelManager = trafficChannelManager;
//The decoder state passes all messages to the network configuration monitor, so we only construct
//the monitor for timeslot 1.
if(timeslot == 1)
{
mNetworkConfigurationMonitor = new DMRNetworkConfigurationMonitor(channel);
}
//For RAS protected systems, allows user to ignore CRC checksums and still decode the system
if(channel.getDecodeConfiguration() instanceof DecodeConfigDMR)
{
mIgnoreCRCChecksums = ((DecodeConfigDMR)channel.getDecodeConfiguration()).getIgnoreCRCChecksums();
}
}
/**
* Registers a reference to the decoder state that is processing the sisten timeslot. If this state is covering
* timeslot 1, then the argument will be the state covering timeslot 2, and vice-versa.
*/
public void setSisterDecoderState(DMRDecoderState state)
{
mSisterDecoderState = state;
}
/**
* Processes a map of active talkgroups received from the sister timeslot decoder state so that we can recover
* the current channel identifier to enable populating call events with accurate current channel info.
*
* This is used for Capacity Plus systems to recover the current channel.
*
* @param idMap to process
* @param lsnMap to process
*/
public DMRChannel processActiveTalkgroups(Map<Integer, IntegerIdentifier> idMap, Map<Integer, DMRLsn> lsnMap)
{
if(mCurrentCallEvent != null)
{
List<Identifier> toIds = mCurrentCallEvent.getIdentifierCollection().getIdentifiers(Role.TO);
if(toIds.size() >= 1)
{
Identifier to = toIds.get(0);
if(to instanceof TalkgroupIdentifier talkgroup)
{
Integer tgValue = talkgroup.getValue();
for(Map.Entry<Integer,IntegerIdentifier> entry: idMap.entrySet())
{
if(tgValue != null && tgValue.equals(entry.getValue().getValue()))
{
DMRLsn lsn = lsnMap.get(entry.getKey());
setCurrentChannel(lsn);
return lsn;
}
}
}
}
}
return null;
}
@Override
protected void broadcast(IDecodeEvent event)
{
super.broadcast(event);
if(mChannel.isTrafficChannel() && hasTrafficChannelManager())
{
mTrafficChannelManager.receiveTrafficChannelEvent(event);
}
}
/**
* Indicates if the message is valid or if the Ignore CRC Checksums feature is enabled.
* @param message to check
* @return true if ignore CRC checksums or if the message is valid, meaning the message has passed CRC check.
*/
private boolean isValid(IMessage message)
{
return mIgnoreCRCChecksums || message.isValid();
}
/**
* Indicates if this decoder state has an (optional) traffic channel manager.
*/
private boolean hasTrafficChannelManager()
{
return mTrafficChannelManager != null;
}
/**
* Sets the initial call event for a traffic channel.
* @param decodeEvent to use as the initial call event.
*/
public void setCurrentCallEvent(DecodeEvent decodeEvent)
{
mCurrentCallEvent = decodeEvent;
setCurrentChannel(decodeEvent.getChannelDescriptor());
}
/**
* Processes channel configuration change notifications received over the processing chain event bus. This is
* primarily used for Capacity+ systems when the standard channel is converted to a traffic channel. In response,
* we nullify the traffic channel manager to ensure the traffic channel no longer behaves as a standard channel
* regarding channel conversions and allocations.
*
* @param notification of channel configuration change
*/
@Subscribe
public void channelChanged(ChannelConfigurationChangeNotification notification)
{
if(notification.getChannel().isTrafficChannel())
{
mTrafficChannelManager = null;
}
}
/**
* Identifies the decoder type
*/
@Override
public DecoderType getDecoderType()
{
return DecoderType.DMR;
}
/**
* Performs a full reset to prepare this object for reuse on a new channel
*/
@Override
public void reset()
{
super.reset();
resetState();
mCurrentFrequency = 0;
}
/**
* Resets any temporal state details
*/
protected void resetState()
{
super.resetState();
closeCurrentCallEvent(System.currentTimeMillis());
}
/**
* Primary message processing method.
*/
@Override
public void receive(IMessage message)
{
if(message.getTimeslot() == getTimeslot())
{
if(message instanceof VoiceMessage voice)
{
processVoice(voice);
}
else if(message instanceof DataMessage data)
{
processData(data);
}
else if(isValid(message) && message instanceof LCMessage lcMessage)
{
processLinkControl(lcMessage, false);
}
else if(isValid(message) && message instanceof DMRPacketMessage packet)
{
processPacket(packet);
}
else if(message instanceof UDTShortMessageService sms)
{
processSMS(sms);
}
else if(message instanceof DMRMessage)
{
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.ACTIVE, getTimeslot()));
}
}
//SLCO messages on timeslot 0 to catch capacity plus rest channel events
else if(isValid(message) && message.getTimeslot() == 0 && message instanceof LCMessage lcMessage)
{
processLinkControl(lcMessage, false);
}
//Pass the message to the network configuration monitor, if this decoder state has a non-null instance
if(mNetworkConfigurationMonitor != null && isValid(message) && message instanceof DMRMessage dmrMessage)
{
mNetworkConfigurationMonitor.process(dmrMessage);
}
}
/**
* Processes Capacity Plus rest channel notifications to detect when the rest channel has changed. When a new
* rest channel is specified that is different from the current channel, notify the traffic channel manager so that
* it can convert the current channel to a traffic channel and start a new channel for the rest channel, using the
* current channel's configuration details and the specified rest channel frequency. This approach ensures that
* there is no disruption to the currently processing channel and that the original channel configuration can be
* recreated to follow the rest channel.
*
* @param restChannel currently indicated
*/
private void updateRestChannel(DMRChannel restChannel)
{
//Only respond if this is a standard/control channel (not a traffic channel).
if(mChannel.isStandardChannel() && mCurrentFrequency > 0 &&
restChannel.getDownlinkFrequency() > 0 &&
restChannel.getDownlinkFrequency() != mCurrentFrequency && mTrafficChannelManager != null)
{
mTrafficChannelManager.convertToTrafficChannel(mChannel, mCurrentFrequency, restChannel,
mNetworkConfigurationMonitor);
}
}
/**
* Preloads the DMR network configuration monitor that is optionally delivered as preload data. This is primarily
* used during a Capacity plus REST channel rotation to pass the monitor from the previous REST channel to the
* current REST channel to ensure data continuity.
*
* Note: the monitor is only assigned to the timeslot 1 decoder state since the decoder state passes all received
* messages (Timeslots 0, 1, and 2) to the monitor.
*
* Note: this method is invoked over the Guava event but by the ChannelProcessingManager.
*
* @param preloadData containing a DMR network configuration monitor.
*/
@Subscribe
public void preload(DMRNetworkConfigurationPreloadData preloadData)
{
if(getTimeslot() == 1 && preloadData.hasData())
{
mNetworkConfigurationMonitor = preloadData.getData();
}
}
/**
* Processes a short data message carrying SMS text
* @param sms
*/
private void processSMS(UDTShortMessageService sms)
{
broadcast(new DecoderStateEvent(this, Event.START, State.DATA, getTimeslot()));
DecodeEvent smsEvent = DMRDecodeEvent.builder(DecodeEventType.SMS, sms.getTimestamp())
.channel(getCurrentChannel())
.details("MESSAGE: " + sms.getSMS())
.identifiers(new IdentifierCollection(sms.getIdentifiers()))
.timeslot(getTimeslot())
.build();
broadcast(smsEvent);
}
/**
* Processes a packet message
*/
private void processPacket(DMRPacketMessage packet)
{
broadcast(new DecoderStateEvent(this, Event.START, State.DATA, getTimeslot()));
//Hytera SDS Long SMS message
if(packet.getPacket() instanceof HyteraSmsPacket hyteraSmsPacket)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(packet.getIdentifiers());
mic.remove(Form.RADIO);
mic.remove(Form.TALKGROUP);
mic.update(hyteraSmsPacket.getSource());
mic.update(hyteraSmsPacket.getDestination());
DecodeEvent smsEvent = DMRDecodeEvent.builder(DecodeEventType.SMS, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(mic)
.timeslot(getTimeslot())
.details("SMS:" + hyteraSmsPacket.getSMS())
.build();
broadcast(smsEvent);
}
//Hytera Radio Registration Service (RRS)
else if(packet.getPacket() instanceof HyteraRrsPacket rrs)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(packet.getIdentifiers());
StringBuilder sb = new StringBuilder();
sb.append("HYTERA RRS REGISTER RADIO:");
sb.append(rrs.getDestination());
DecodeEvent shortDataEvent = DMRDecodeEvent.builder(DecodeEventType.RADIO_REGISTRATION_SERVICE, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(mic)
.timeslot(getTimeslot())
.details(sb.toString())
.build();
broadcast(shortDataEvent);
}
//Hytera Short Data
else if(packet.getPacket() instanceof HyteraShortDataPacket hsdp)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(packet.getIdentifiers());
StringBuilder sb = new StringBuilder();
sb.append("HYTERA");
if(hsdp.getPacketSequence().isEncrypted())
{
HyteraDataEncryptionHeader hdeh = (HyteraDataEncryptionHeader)hsdp.getPacketSequence().getProprietaryDataHeader();
sb.append(" ENCRYPTED ALGORITHM:").append(hdeh.getAlgorithm());
sb.append(" KEY:").append(hdeh.getKeyId());
sb.append(" IV:").append(hdeh.getIV());
}
sb.append(" SHORT DATA:").append(hsdp.getMessage().toHexString());
DecodeEvent shortDataEvent = DMRDecodeEvent.builder(DecodeEventType.RADIO_REGISTRATION_SERVICE, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(mic)
.timeslot(getTimeslot())
.details(sb.toString())
.build();
broadcast(shortDataEvent);
}
//Unknown Hytera Long Data Service Token Message
else if(packet.getPacket() instanceof HyteraUnknownPacket hyteraUnknownPacket)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(packet.getIdentifiers());
DecodeEvent unknownTokenEvent = DMRDecodeEvent.builder(DecodeEventType.UNKNOWN_PACKET, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(mic)
.timeslot(getTimeslot())
.details("HYTERA LONG DATA UNK TOKEN MSG:" + hyteraUnknownPacket.getHeader().toString())
.build();
broadcast(unknownTokenEvent);
}
//Motorola ARS
else if(packet.getPacket() instanceof ARSPacket ars)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(packet.getIdentifiers());
DecodeEvent shortDataEvent = DMRDecodeEvent.builder(DecodeEventType.RADIO_REGISTRATION_SERVICE, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(mic)
.timeslot(getTimeslot())
.details(ars.toString())
.build();
broadcast(shortDataEvent);
}
//Motorola LRRP
else if(packet.getPacket() instanceof LRRPPacket lrrp)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(packet.getIdentifiers());
DecodeEvent shortDataEvent = DMRDecodeEvent.builder(DecodeEventType.LRRP, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(mic)
.timeslot(getTimeslot())
.details(lrrp.toString())
.build();
broadcast(shortDataEvent);
}
//Motorola XCMP
else if(packet.getPacket() instanceof XCMPPacket xcmp)
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(packet.getIdentifiers());
DecodeEvent shortDataEvent = DMRDecodeEvent.builder(DecodeEventType.XCMP, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(mic)
.timeslot(getTimeslot())
.details(xcmp.toString())
.build();
broadcast(shortDataEvent);
}
else
{
DecodeEvent packetEvent = DMRDecodeEvent.builder(DecodeEventType.DATA_PACKET, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(new IdentifierCollection(packet.getIdentifiers()))
.timeslot(getTimeslot())
.details(packet.toString())
.build();
broadcast(packetEvent);
}
GeoPosition geoPosition = PacketUtil.extractGeoPosition(packet.getPacket());
if (geoPosition != null) {
PlottableDecodeEvent plottableDecodeEvent = PlottableDecodeEvent.plottableBuilder(DecodeEventType.GPS, packet.getTimestamp())
.channel(getCurrentChannel())
.identifiers(new IdentifierCollection(packet.getIdentifiers()))
.protocol(Protocol.LRRP)
.location(geoPosition)
.build();
broadcast(plottableDecodeEvent);
}
}
/**
* Processes voice messages
*/
private void processVoice(VoiceMessage message)
{
if(message.getSyncPattern().isMobileSyncPattern())
{
if(message.getSyncPattern().isDirectMode())
{
updateCurrentCall(DecodeEventType.CALL, "DIRECT MODE", message.getTimestamp());
}
else
{
updateCurrentCall(DecodeEventType.CALL, "REPEATER", message.getTimestamp());
}
//Use the timeslot as the talkgroup identifier since DCDM & simple repeater modes don't use talkgroups
getIdentifierCollection().update(DMRTalkgroup.create(getTimeslot()));
}
else
{
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CALL, getTimeslot()));
}
if(message.getSyncPattern() == DMRSyncPattern.BS_VOICE_FRAME_F && message instanceof VoiceEMBMessage voiceEmb)
{
if(voiceEmb.hasEmbeddedParameters())
{
EmbeddedParameters embedded = voiceEmb.getEmbeddedParameters();
if(embedded.getShortBurst() instanceof EncryptionParameters arc4)
{
updateEncryptedCall(arc4, true, voiceEmb.getTimestamp());
}
}
}
}
/**
* Processes a voice header message
*/
private void processHeader(HeaderMessage header)
{
switch(header.getSlotType().getDataType())
{
case VOICE_HEADER:
broadcast(new DecoderStateEvent(this, Event.START, State.CALL, getTimeslot()));
break;
case PI_HEADER:
case MBC_HEADER:
case DATA_HEADER:
case USB_DATA:
case MBC_ENC_HEADER:
case DATA_ENC_HEADER:
case CHANNEL_CONTROL_ENC_HEADER:
broadcast(new DecoderStateEvent(this, Event.START, State.DATA, getTimeslot()));
break;
}
//Process the link control message to get the identifiers
LCMessage lc = header.getLCMessage();
if(isValid(lc))
{
processLinkControl(lc, false);
}
}
/**
* Process Data Messages
*
* Note: invalid messages are allowed to pass to this method. Messages are selectively checked for isValid()
* to overcome RAS implementation in certain systems.
*/
private void processData(DataMessage message)
{
switch(message.getSlotType().getDataType())
{
case CSBK:
if(isValid(message) && message instanceof CSBKMessage csbk)
{
processCSBK(csbk);
}
break;
case VOICE_HEADER:
if(message instanceof HeaderMessage header)
{
processVoiceHeader(header);
}
break;
case USB_DATA:
break;
case PI_HEADER:
case MBC_HEADER:
case DATA_HEADER:
case MBC_ENC_HEADER:
case DATA_ENC_HEADER:
case CHANNEL_CONTROL_ENC_HEADER:
if(message instanceof HeaderMessage header)
{
processHeader(header);
}
break;
case SLOT_IDLE:
closeCurrentCallEvent(message.getTimestamp());
getIdentifierCollection().remove(IdentifierClass.USER);
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.ACTIVE, getTimeslot()));
break;
case TLC:
if(message instanceof Terminator)
{
processTerminator((Terminator)message);
}
break;
case RATE_1_OF_2_DATA:
case RATE_3_OF_4_DATA:
case RATE_1_DATA:
broadcast(new DecoderStateEvent(this, Event.START, State.DATA, getTimeslot()));
break;
case MBC_BLOCK:
case RESERVED_15:
case UNKNOWN:
default:
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.ACTIVE, getTimeslot()));
break;
}
}
/**
* Process terminator with link control messages
*/
private void processTerminator(Terminator terminator)
{
closeCurrentCallEvent(terminator.getTimestamp());
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.ACTIVE, getTimeslot()));
LCMessage lcMessage = terminator.getLCMessage();
if(isValid(lcMessage))
{
processLinkControl(lcMessage, true);
}
}
/**
* Process a voice header message
*/
private void processVoiceHeader(HeaderMessage voiceHeader)
{
LCMessage lcMessage = voiceHeader.getLCMessage();
if(isValid(lcMessage))
{
processLinkControl(lcMessage, false);
}
}
private void processCSBK(CSBKMessage csbk)
{
switch(csbk.getOpcode())
{
case STANDARD_ACKNOWLEDGE_RESPONSE_INBOUND_PAYLOAD:
case STANDARD_ACKNOWLEDGE_RESPONSE_OUTBOUND_PAYLOAD:
if(csbk instanceof Acknowledge)
{
broadcast(getDecodeEvent(csbk, DecodeEventType.RESPONSE,
((Acknowledge) csbk).getReason().toString()));
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.ACTIVE, getTimeslot()));
break;
case STANDARD_ACKNOWLEDGE_RESPONSE_INBOUND_TSCC:
case STANDARD_ACKNOWLEDGE_RESPONSE_OUTBOUND_TSCC:
if(csbk instanceof Acknowledge)
{
broadcast(getDecodeEvent(csbk, DecodeEventType.RESPONSE,
((Acknowledge) csbk).getReason().toString()));
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case STANDARD_AHOY:
if(csbk instanceof Ahoy)
{
switch(((Ahoy)csbk).getServiceKind())
{
case AUTHENTICATE_REGISTER_RADIO_CHECK_SERVICE:
broadcast(getDecodeEvent(csbk, DecodeEventType.COMMAND, DecodeEventType.REGISTER.toString()));
break;
case CANCEL_CALL_SERVICE:
broadcast(getDecodeEvent(csbk, DecodeEventType.COMMAND, "CANCEL CALL"));
break;
case SUPPLEMENTARY_SERVICE:
if(csbk instanceof StunReviveKill)
{
broadcast(getDecodeEvent(csbk, DecodeEventType.COMMAND,
((StunReviveKill)csbk).getCommand() + " RADIO"));
}
break;
case FULL_DUPLEX_MS_TO_MS_PACKET_CALL_SERVICE:
case FULL_DUPLEX_MS_TO_MS_VOICE_CALL_SERVICE:
case INDIVIDUAL_VOICE_CALL_SERVICE:
case INDIVIDUAL_PACKET_CALL_SERVICE:
case INDIVIDUAL_UDT_SHORT_DATA_CALL_SERVICE:
case TALKGROUP_PACKET_CALL_SERVICE:
case TALKGROUP_UDT_SHORT_DATA_CALL_SERVICE:
case TALKGROUP_VOICE_CALL_SERVICE:
if(csbk instanceof ServiceRadioCheck)
{
ServiceRadioCheck src = (ServiceRadioCheck)csbk;
broadcast(getDecodeEvent(csbk, DecodeEventType.RADIO_CHECK,
src.getServiceDescription() + " SERVICE FOR " +
(src.isTalkgroupTarget() ? "TALKGROUP" : "RADIO")));
}
break;
}
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case STANDARD_ALOHA:
if(csbk instanceof Aloha)
{
Aloha aloha = (Aloha)csbk;
if(aloha.hasRadioIdentifier())
{
broadcast(getDecodeEvent(csbk, DecodeEventType.RESPONSE, "Aloha Acknowledge"));
resetState();
}
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case STANDARD_ANNOUNCEMENT:
if(csbk instanceof Announcement)
{
switch(((Announcement)csbk).getAnnouncementType())
{
case MASS_REGISTRATION:
broadcast(getDecodeEvent(csbk, DecodeEventType.REGISTER, "MASS REGISTRATION"));
break;
case VOTE_NOW_ADVICE:
if(csbk instanceof VoteNowAdvice)
{
broadcast(getDecodeEvent(csbk, DecodeEventType.COMMAND,
"VOTE NOW FOR " + ((VoteNowAdvice)csbk).getVotedSystemIdentityCode()));
}
break;
}
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case STANDARD_CLEAR:
broadcast(new DecoderStateEvent(this, Event.END, State.CALL, getTimeslot()));
resetState();
break;
case STANDARD_PREAMBLE:
getIdentifierCollection().update(csbk.getIdentifiers());
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.DATA, getTimeslot()));
break;
case STANDARD_PROTECT:
if(csbk instanceof Protect)
{
broadcast(getDecodeEvent(csbk, DecodeEventType.COMMAND,
"PROTECT: " + ((Protect)csbk).getProtectKind()));
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CALL, getTimeslot()));
break;
case HYTERA_08_ANNOUNCEMENT:
case HYTERA_68_ANNOUNCEMENT:
case HYTERA_68_XPT_SITE_STATE:
break;
case HYTERA_08_TRAFFIC_CHANNEL_TALKER_STATUS:
if(csbk instanceof HyteraTrafficChannelTalkerStatus status)
{
if(status.isChannelActive())
{
getIdentifierCollection().update(status.getIdentifiers());
updateCurrentCall(DecodeEventType.CALL_GROUP, "HYTERA TIER 3 CALL", status.getTimestamp());
}
else
{
getIdentifierCollection().remove(Role.FROM);
getIdentifierCollection().update(status.getDestinationRadio());
}
}
break;
case MOTOROLA_CAPPLUS_NEIGHBOR_REPORT:
if(csbk instanceof CapacityPlusNeighbors)
{
//Update state and rest channel
updateRestChannel(((CapacityPlusNeighbors)csbk).getRestChannel());
}
break;
case MOTOROLA_CAPPLUS_SITE_STATUS:
if(csbk instanceof CapacityPlusSiteStatus)
{
CapacityPlusSiteStatus cpss = (CapacityPlusSiteStatus)csbk;
//Channel rotation monitor normally uses only CONTROL state, so when we detect that we're a
//Capacity plus system, add ACTIVE as an active state to the monitor. This can be requested repeatedly.
getInterModuleEventBus().post(CAPACITY_PLUS_ACTIVE_STATE_REQUEST);
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.ACTIVE, getTimeslot()));
//Update state and rest channel
updateRestChannel(cpss.getRestChannel());
//If the sister timeslot hasn't identified the current channel, attempt to identify the channel
//from the current call activity map.
if(cpss.hasVoiceTalkgroups() && mSisterDecoderState != null && mSisterDecoderState.getCurrentChannel() == null)
{
DMRChannel sisterChannel = mSisterDecoderState
.processActiveTalkgroups(cpss.getActiveIdentifierMap(), cpss.getActiveLsnMap());
//If the returned channel is non-null, set our own channel
if(getCurrentChannel() == null && sisterChannel != null)
{
setCurrentChannel(sisterChannel.getSisterTimeslot());
}
}
}
break;
case MOTOROLA_CONPLUS_NEIGHBOR_REPORT:
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case STANDARD_BROADCAST_TALKGROUP_VOICE_CHANNEL_GRANT:
case STANDARD_DUPLEX_PRIVATE_DATA_CHANNEL_GRANT:
case STANDARD_DUPLEX_PRIVATE_VOICE_CHANNEL_GRANT:
case STANDARD_PRIVATE_DATA_CHANNEL_GRANT_SINGLE_ITEM:
case STANDARD_PRIVATE_VOICE_CHANNEL_GRANT:
case STANDARD_TALKGROUP_DATA_CHANNEL_GRANT_MULTI_ITEM:
case STANDARD_TALKGROUP_DATA_CHANNEL_GRANT_SINGLE_ITEM:
case STANDARD_TALKGROUP_VOICE_CHANNEL_GRANT:
if(csbk instanceof ChannelGrant channelGrant)
{
DMRChannel channel = channelGrant.getChannel();
if(hasTrafficChannelManager())
{
IdentifierCollection mergedIdentifiers = getMergedIdentifierCollection(csbk.getIdentifiers());
mTrafficChannelManager.processChannelGrant(channel, mergedIdentifiers, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}
else
{
LOGGING_SUPPRESSOR.error("NoTCM" + csbk.getOpcode().name(), 2,
"No DMR Traffic Channel Manager available for channel grant-" + csbk.getOpcode().name());
}
}
else
{
mLog.error("Unrecognized DMR channel grant CSBK ignored: " + csbk.getClass());
}
break;
case MOTOROLA_CAPMAX_ALOHA:
if(csbk instanceof CapacityMaxAloha)
{
CapacityMaxAloha cmAloha = (CapacityMaxAloha)csbk;
if(cmAloha.hasRadioIdentifier())
{
broadcast(getDecodeEvent(csbk, DecodeEventType.RESPONSE, "Aloha Acknowledge"));
resetState();
}
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case MOTOROLA_CAPMAX_CHANNEL_UPDATE_OPEN_MODE:
if(csbk instanceof CapacityMaxOpenModeVoiceChannelUpdate update)
{
if(hasTrafficChannelManager())
{
if(update.hasTimeslot1())
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(getIdentifierCollection().getIdentifiers());
mic.remove(IdentifierClass.USER);
mic.update(update.getChannelTS1());
mic.update(update.getTalkgroupTS1());
mTrafficChannelManager.processChannelGrant(update.getChannelTS1(), mic, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}
if(update.hasTimeslot2())
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(getIdentifierCollection().getIdentifiers());
mic.remove(IdentifierClass.USER);
mic.update(update.getChannelTS2());
mic.update(update.getTalkgroupTS2());
mTrafficChannelManager.processChannelGrant(update.getChannelTS2(), mic, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}
}
else
{
LOGGING_SUPPRESSOR.error("NoTCM" + csbk.getOpcode().name(), 2,
"No DMR Traffic Channel Manager available for channel grant-" + csbk.getOpcode().name());
}
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case MOTOROLA_CAPMAX_CHANNEL_UPDATE_ADVANTAGE_MODE:
if(csbk instanceof CapacityMaxAdvantageModeVoiceChannelUpdate update)
{
if(hasTrafficChannelManager())
{
if(update.hasChannel1Timeslot1())
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(getIdentifierCollection().getIdentifiers());
mic.remove(IdentifierClass.USER);
mic.update(update.getChannel1TS1());
mic.update(update.getTalkgroupCH1TS1());
mTrafficChannelManager.processChannelGrant(update.getChannel1TS1(), mic, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}
if(update.hasChannel1Timeslot2())
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(getIdentifierCollection().getIdentifiers());
mic.remove(IdentifierClass.USER);
mic.update(update.getChannel1TS2());
mic.update(update.getTalkgroupCH1TS2());
mTrafficChannelManager.processChannelGrant(update.getChannel1TS2(), mic, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}
if(update.hasChannel2Timeslot1())
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(getIdentifierCollection().getIdentifiers());
mic.remove(IdentifierClass.USER);
mic.update(update.getChannel2TS1());
mic.update(update.getTalkgroupCH2TS1());
mTrafficChannelManager.processChannelGrant(update.getChannel2TS1(), mic, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}
if(update.hasChannel2Timeslot2())
{
MutableIdentifierCollection mic = new MutableIdentifierCollection(getIdentifierCollection().getIdentifiers());
mic.remove(IdentifierClass.USER);
mic.update(update.getChannel2TS2());
mic.update(update.getTalkgroupCH2TS2());
mTrafficChannelManager.processChannelGrant(update.getChannel2TS2(), mic, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}
}
else
{
LOGGING_SUPPRESSOR.error("NoTCM" + csbk.getOpcode().name(), 2,
"No DMR Traffic Channel Manager available for channel grant-" + csbk.getOpcode().name());
}
}
broadcast(new DecoderStateEvent(this, Event.CONTINUATION, State.CONTROL, getTimeslot()));
break;
case MOTOROLA_CONPLUS_DATA_CHANNEL_GRANT:
if(csbk instanceof ConnectPlusDataChannelGrant cpdcg)
{
DMRChannel channel = cpdcg.getChannel();
if(hasTrafficChannelManager())
{
IdentifierCollection mergedIdentifiers = getMergedIdentifierCollection(csbk.getIdentifiers());
mTrafficChannelManager.processChannelGrant(channel, mergedIdentifiers, csbk.getOpcode(),
csbk.getTimestamp(), csbk.isEncrypted());
}