-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathQuantar.pm
1450 lines (1350 loc) · 40.8 KB
/
Quantar.pm
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
package Quantar;
# Quantar.pm
use strict;
use warnings;
use Switch;
use Config::IniFiles;
use Term::ANSIColor;
# Custom files:
use FindBin 1.51 qw( $RealBin );
use lib $RealBin;
#use Packets;
#my $CiscoDebug = 1;
# ICW (Infrastructure Control Word).
# Byte 1 address.
# Bte 2 frame type.
use constant C_RR => 0x41;
use constant C_UI => 0x03;
use constant C_SABM => 0x3F;
use constant C_XID => 0xBF;
# Byte 3.
#0x60 thru 0x73, etc
use constant C_RN_Page => 0xA1;
# Byte 4.
# Byte 5 RT mode flag.
use constant C_RTRT_Enabled => 0x02;
use constant C_RTRT_Disabled => 0x04;
use constant C_RTRT_DCRMode => 0x05;
# Byte 6 Op Code Start/Stop flag.
use constant C_ChangeChannel => 0x06;
use constant C_StartTx => 0x0C;
use constant C_EndTx => 0x25;
# Byte 7 OpArg, type flag.
use constant C_AVoice => 0x00;
use constant C_TMS_Data_Payload => 0x06;
use constant C_DVoice => 0x0B;
use constant C_TMS_Data => 0x0C;
use constant C_From_Comparator_Start => 0x0D;
use constant C_From_Comparator_Stop => 0x0E;
use constant C_Page => 0x0F;
# Byte 8 ICW flag.
use constant C_DIU3000 => 0x00;
use constant C_Quantar => 0xC2;
use constant C_QuantarAlt => 0x1B;
# Byte 9 LDU1 RSSI.
# Byte 10 1A flag.
use constant C_RSSI_Is_Valid => 0x1A;
# Byte 11 LDU1 RSSI.
#
# Byte 12.
use constant C_Normal_Page => 0x9F;
use constant C_Emergency_Page => 0xA7;
# Byte 13 Page.
use constant C_Individual_Page => 0x00;
use constant C_Group_Page => 0x90;
#
use constant C_SystemCallTG => 0xFFFF;
our $HDLC_RTRT_Enabled;
our $HDLC_ATAC_Enabled;
my $Verbose;
my %Quant;
use constant C_Implicit_MFID => 0;
use constant C_Explicit_MFID => 1;
my $SuperframeCounter = 0;
my %HDLC;
my $HDLC_Handshake = 0;
my $SABM_Counter = 0;
my $StationType = 0;
my $SuperFrameCounter = 0;
my $HDLC_TxTraffic = 0;
my $LocalRx_Time;
my $NewTG = 0;
my $RptEnabled = 1;
##################################################################
# Qunatar ########################################################
##################################################################
sub Init {
my ($ConfigFile) = @_;
print color('green'), "Init HDLC.\n", color('reset');
my $cfg = Config::IniFiles->new( -file => $ConfigFile);
$HDLC_RTRT_Enabled = $cfg->val('HDLC', 'RTRT_Enabled');
$HDLC_ATAC_Enabled = $cfg->val('HDLC', 'ATAC_Enabled');
$Verbose =$cfg->val('HDLC', 'Verbose');
print " RT/RT Enabled = $HDLC_RTRT_Enabled\n";
print " ATAC Enabled = $HDLC_ATAC_Enabled\n";
print " Verbose = $Verbose\n";
$Quant{'FrameType'} = 0;
$Quant{'LocalRx'} = 0;
$Quant{'LocalRx_Time'} = 0;
$Quant{'IsDigitalVoice'} = 1;
$Quant{'IsPage'} = 0;
$Quant{'dBm'} = 0;
$Quant{'RSSI'} = 0;
$Quant{'RSSI_Is_Valid'} = 0;
$Quant{'InvertedSignal'} = 0;
$Quant{'CandidateAdjustedMM'} = 0;
$Quant{'BER'} = 0;
$Quant{'SourceDev'} = 0;
$Quant{'Encrypted'} = 0;
$Quant{'Explicit'} = 0;
$Quant{'IndividualCall'} = 0;
$Quant{'ManufacturerID'} = 0;
$Quant{'ManufacturerName'} = "";
$Quant{'Emergency'} = 0;
$Quant{'Protected'} = 0;
$Quant{'FullDuplex'} = 0;
$Quant{'PacketMode'} = 0;
$Quant{'Priority'} = 0;
$Quant{'IsTGData'} = 0;
$Quant{'AstroTalkGroup'} = 0;
$Quant{'DestinationRadioID'} = 0;
$Quant{'SourceRadioID'} = 0;
$Quant{'LSD'} = [0, 0, 0, 0];
$Quant{'LSD0'} = 0;
$Quant{'LSD1'} = 0;
$Quant{'LSD2'} = 0;
$Quant{'LSD3'} = 0;
$Quant{'EncryptionI'} = 0;
$Quant{'EncryptionII'} = 0;
$Quant{'EncryptionIII'} = 0;
$Quant{'EncryptionIV'} = 0;
$Quant{'Algorythm'} = 0;
$Quant{'AlgoName'} = "";
$Quant{'KeyID'} = 0;
$Quant{'Speech'} = "";
$Quant{'Raw0x60'} = "";
$Quant{'Raw0x61'} = "";
$Quant{'Raw0x62'} = "";
$Quant{'Raw0x63'} = "";
$Quant{'Raw0x64'} = "";
$Quant{'Raw0x65'} = "";
$Quant{'Raw0x66'} = "";
$Quant{'Raw0x67'} = "";
$Quant{'Raw0x68'} = "";
$Quant{'Raw0x69'} = "";
$Quant{'Raw0x6A'} = "";
$Quant{'Raw0x6B'} = "";
$Quant{'Raw0x6C'} = "";
$Quant{'Raw0x6D'} = "";
$Quant{'Raw0x6E'} = "";
$Quant{'Raw0x6F'} = "";
$Quant{'Raw0x70'} = "";
$Quant{'Raw0x71'} = "";
$Quant{'Raw0x72'} = "";
$Quant{'Raw0x73'} = "";
$Quant{'IMBEFrame'} = "";
$Quant{'Tail'} = 0;
$Quant{'PrevFrame'} = "";
$HDLC{'RR_Timer'}{'Enabled'} = 0;
$HDLC{'RR_Timer'}{'Interval'} = 4; # Seconds.
$HDLC{'RR_Timer'}{'NextTime'} = 0;
$HDLC{'Connection_WD_Timer'}{'Enabled'} = 1;
$HDLC{'Connection_WD_Timer'}{'Interval'} = 10; # Seconds.
$HDLC{'Connection_WD_Timer'}{'NextTime'} = P25Link::GetTickCount();
$HDLC{'SABM_Timer'}{'Enabled'} = 1;
$HDLC{'SABM_Timer'}{'Interval'} = 0.5; # Seconds.
$HDLC{'SABM_Timer'}{'NextTime'} = 0;
print "----------------------------------------------------------------------\n";
}
##################################################################
# HDLC ###########################################################
##################################################################
sub HDLC_Rx {
my ($Message, $RemoteHostIP) = @_;
my $RTRTOn;
my $OpCode;
my $OpArg;
my $SiteID;
my $IsChannelChange;
my $Channel;
my $IsStart;
my $IsEnd;
if ($Verbose) {
print color('green'), "HDLC_Rx Message.\n", color('reset');
}
if ($Verbose >= 2) {
P25Link::Bytes_2_HexString($Message);
}
Recorder::RecorderBytes_2_HexString($Message);
# 01 Address
my $Address = ord(substr($Message, 0, 1));
#print "Address = ", sprintf("0x%x", $Address), "\n";
#P25Link::Bytes_2_HexString($Message);
$Quant{'FrameType'} = ord(substr($Message, 1, 1));
#print "Frame Types = ", sprintf("0x%x", $Quant{'FrameType'}), "\n";
switch ($Quant{'FrameType'}) {
case 0x01 { # RR Receive Ready.
if ($Address == 0xFD) { # 253
Start_Connection_WD_Timer(); # Reset HDLC connection timer.
} else {
print color('red'), "*** Warning *** HDLC_Rx RR Address 0xFD (253) != $Address\n",
color('reset');
}
return;
}
case 0x03 { #0x03 { # User Information.
#print "Case 0x03 UI.", substr($Message, 2, 1), "\n";
#P25Link::Bytes_2_HexString($Message);
$Quant{'LocalRx'} = 1;
$Quant{'LocalRx_Time'} = P25Link::GetTickCount();
switch (ord(substr($Message, 2, 1))) {
case 0x00 { #Network ID, NID Start/Stop.
if ($Verbose) {
print "UI 0x00 NID Start/Stop";
}
if (ord(substr($Message, 3, 1)) != 0x02) {warn "Debug this with the XML.\n"; }
if (ord(substr($Message, 4, 1)) == C_RTRT_Enabled) {
$RTRTOn = 1;
if ($Verbose) {
print ", RT/RT Enabled";
}
}
if (ord(substr($Message, 4, 1)) == C_RTRT_Disabled) {
$RTRTOn = 0;
if ($Verbose) {
print ", RT/RT Disabled";
}
}
$OpCode = ord(substr($Message, 5, 1));
$OpArg = ord(substr($Message, 6, 1));
switch ($OpCode) {
case 0x06 { # ChannelChange
$IsChannelChange = 1;
$Channel = $OpArg;
#if ($Verbose) {
print " HDLC Channel change to $Channel\n";
#}
}
case 0x0C { # StartTx
$IsStart = 1;
if ($Verbose) {
print " HDLC ICW Start";
}
}
case 0x0D {
if ($Verbose) {
print " HDLC DIU Monitor";
}
}
case 0x25 { # StopTx
$IsEnd = 1;
if ($Verbose) {
print " HDLC ICW Terminate";
}
$Quant{'LocalRx'} = 0;
$Quant{'LocalTx'} = 0;
if ($Quant{'Tail'} == 1) {
$Packets::Pending_CourtesyTone = 1;
$Quant{'Tail'} = 0;
print " HDLC Stop 0x25 Tail Rx\n";
if ($Verbose) { P25Link::Bytes_2_HexString($Message) };
} else {
print " HDLC Stop 0x25 Tail Rx (dupe).\n";
if ($Verbose) { P25Link::Bytes_2_HexString($Message) };
}
}
}
if ($Verbose) {
print ", Linked Talk Group " . Packets::GetLinkedTalkGroup() . "\n";
}
switch ($OpArg) {
case 0x00 { # AVoice
if ($Verbose) { print ", Analog Voice\n"; }
$Quant{'IsDigitalVoice'} = 0;
$Quant{'IsPage'} = 0;
}
case 0x06 { # TMS Data Payload
if ($Verbose) {
print ", TMS Data Payload\n";
P25Link::Bytes_2_HexString($Message);
}
print "----------------------------------------------------------------------\n";
Packets::Tx_to_Network($Message);
}
case 0x0B { # DVoice
if ($Verbose) { print ", Digital Voice\n"; }
$Quant{'IsDigitalVoice'} = 1;
$Quant{'IsPage'} = 0;
Packets::Tx_to_Network($Message);
}
case 0x0C { # TMS
if ($Verbose) {
print ", TMS\n";
P25Link::Bytes_2_HexString($Message);
}
print "----------------------------------------------------------------------\n";
Packets::Tx_to_Network($Message);
}
case 0x0D { # From Comparator Start
if ($Verbose) {
print ", From Comparator Start\n";
P25Link::Bytes_2_HexString($Message);
}
print "----------------------------------------------------------------------\n";
#AddToSuperFrame(0x0D, $Message);
#Packets::Tx_to_Network($Message);
}
case 0x0E { # From Comprator Stop
if ($Verbose) {
print ", From Comparator Stop\n";
P25Link::Bytes_2_HexString($Message);
}
print "----------------------------------------------------------------------\n";
#AddToSuperFrame(0x0E, $Message);
#Packets::Tx_to_Network($Message);
}
case 0x0F { # Page
if ($Verbose) { print ", Page\n"; }
$Quant{'IsPage'} = 1;
Packets::Tx_to_Network($Message);
}
}
if ($Verbose) {
print "\n";
}
RDAC::Tx(Packets::GetLinkedTalkGroup(), $Quant{'LocalRx'}, $Quant{'LocalTx'},
$Quant{'IsDigitalVoice'}, $Quant{'IsPage'}, $StationType);
}
case 0x01 {
warn color('yellow'), "UI 0x01 Undefined.\n", color('reset');
}
case 0x59 {
warn color('yellow'), "UI 0x59 Undefined.\n", color('reset');
return;
}
case 0x60 {
if ($Verbose) { print "UI 0x60 Voice Header part 1.\n"; }
if ($Verbose >= 2) {P25Link::Bytes_2_HexString($Message); }
switch (ord(substr($Message, 4, 1))) {
case 0x02 { # RTRT_Enabled
$RTRTOn = 1;
if ($Verbose) { print "RT/RT Enabled"; }
}
case 0x04 { # RTRT_Disabled
$RTRTOn = 0;
if ($Verbose) { print "RT/RT Disabled"; }
}
}
switch (ord(substr($Message, 6, 1))) {
case 0x00 { # AVoice
if ($Verbose) { print ", Analog Voice"; }
$Quant{'IsDigitalVoice'} = 0;
$Quant{'IsPage'} = 0;
}
case 0x0B { # DVoice
if ($Verbose) { print ", Digital Voice"; }
$Quant{'IsDigitalVoice'} = 1;
$Quant{'IsPage'} = 0;
}
case 0x0F { # Page
if ($Verbose) { print ", Page"; }
$Quant{'IsDigitalVoice'} = 0;
$Quant{'IsPage'} = 1;
}
}
$SiteID = ord(substr($Message,7 ,1));
$StationType = $SiteID; # Informative for RDAC.
switch ($SiteID) {
case C_DIU3000 { # DIU3000
if ($Verbose) { print ", Source: DIU 3000 or ATAC"; }
}
case C_Quantar { # Quantar
if ($Verbose) { print ", Source: Quantar"; }
}
}
if (ord(substr($Message, 9, 1)) == 1) {
$Quant{'RSSI_Is_Valid'} = 1;
$Quant{'RSSI'} = ord(substr($Message, 8, 1));
$Quant{'InvertedSignal'} = ord(substr($Message, 10, 1));
if ($Verbose) {
print ", RSSI = $Quant{'RSSI'}\n";
print ", Inverted signal = $Quant{'InvertedSignal'}\n";
}
} else {
$Quant{'RSSI_Is_Valid'} = 0;
if ($Verbose) { print ".\n"; }
}
if ( ($Quant{'IsDigitalVoice'} == 1) or ($Quant{'IsPage'} == 1) ) {
$Quant{'Raw0x60'} = $Message;
Packets::Tx_to_Network($Message);
}
}
case 0x61 {
if ($Verbose) {
print "UI 0x61 Voice Header part 2.\n";
}
if ($Verbose >= 2) {P25Link::Bytes_2_HexString($Message); }
#my $TGID = 256 * ord(substr($Message, 4, 1)) + ord(substr($Message, 3, 1));;
#warn "Not true TalkGroup ID = $TGID\n";
if ( ($Quant{'IsDigitalVoice'} == 1) or ($Quant{'IsPage'} == 1) ) {
$Quant{'Raw0x61'} = $Message;
Packets::Tx_to_Network($Message);
}
}
case 0x62 { # dBm, RSSI, BER.
if ($Verbose) {
print "UI 0x62 IMBE Voice part 1.\n";
}
switch (ord(substr($Message, 4, 1))) {
case 0x02 { # RT/RT Enable
$RTRTOn = 1;
if ($Verbose) { print "RT/RT Enabled"; }
}
case 0x04 { # RT/RT Disable
$RTRTOn = 0;
if ($Verbose) { print "RT/RT Disabled"; }
}
}
switch (ord(substr($Message, 6, 1))) {
case 0x0B { # DVoice
$Quant{'IsDigitalVoice'} = 1;
$Quant{'IsPage'} = 0;
if ($Verbose) { print ", Digital Voice"; }
}
case 0x0F { # Page
$Quant{'IsDigitalVoice'} = 0;
$Quant{'IsPage'} = 1;
if ($Verbose) { print ", Page"; }
}
}
$SiteID = ord(substr($Message, 7, 1));
$StationType = $SiteID; # Informative for RDAC.
switch ($SiteID) {
case C_DIU3000 { # DIU3000
if ($Verbose) { print ", SiteID: DIU 3000 or ATAC"; }
}
case C_Quantar { # Quantar
if ($Verbose) { print ", SiteID: Quantar"; }
}
}
if (ord(substr($Message, 9, 1))) {
$Quant{'RSSI_Is_Valid'} = 1;
$Quant{'RSSI'} = ord(substr($Message, 8, 1));
$Quant{'InvertedSignal'} = ord(substr($Message, 10, 1));
$Quant{'CandidateAdjustedMM'} = ord(substr($Message, 11, 1));
if ($Verbose) {
print ", RSSI = $Quant{'RSSI'}";
print ", Inverted signal = $Quant{'InvertedSignal'}";
}
} else {
$Quant{'RSSI_Is_Valid'} = 0;
}
if ($Verbose) { print "\n"; }
$Quant{'Speech'} = ord(substr($Message, 12, 11));
$Quant{'Raw0x62'} = $Message;
$Quant{'IMBEFrame'} = $Quant{'Speech'};
$Quant{'SourceDev'} = ord(substr($Message, 23, 1));
Packets::Tx_to_Network($Message);
}
case 0x63 {
if ($Verbose) {
print "UI 0x63 IMBE Voice part 2.\n";
}
$Quant{'Speech'} = ord(substr($Message, 3, 11));
$Quant{'Raw0x63'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
$Quant{'SourceDev'} = ord(substr($Message, 14, 1));
Packets::Tx_to_Network($Message);
}
case 0x64 { # Group/Direct Call, Clear/Private.
if ($Verbose) {
print "UI 0x64 IMBE Voice part 3 + link control.\n";
}
if (ord(substr($Message, 3, 1)) & 0x80) {
$Quant{'Encrypted'} = 1;
}
if (ord(substr($Message, 3, 1))& 0x40) {
$Quant{'Explicit'} = 1;
}
$Quant{'IsTGData'} = 0;
CallType(ord(substr($Message, 3, 1)));
$Quant{'ManufacturerID'} = ord(substr($Message, 4, 1));
ManufacturerName ($Quant{'ManufacturerID'});
if (ord(substr($Message, 5, 1)) and 0x80) {
$Quant{'Emergency'} = 1;
} else {
$Quant{'Emergency'} = 0;
}
if (ord(substr($Message, 5, 1)) and 0x40) {
$Quant{'Protected'} = 1;
} else {
$Quant{'Protected'} = 0;
}
if (ord(substr($Message, 5, 1)) and 0x20) {
$Quant{'FullDuplex'} = 1;
} else {
$Quant{'FullDuplex'} = 0;
}
if (ord(substr($Message, 5, 1)) and 0x10) {
$Quant{'PacketMode'} = 1;
} else {
$Quant{'PacketMode'} = 0;
}
$Quant{'Priority'} = ord(substr($Message, 5, 1));
#switch (ord(substr($Message, 6, 1))) {
# case Implicit_MFID {
#
# }
# case Explicit_MFID {
#
# }
#}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
$Quant{'Raw0x64'} = $Message;
Packets::Tx_to_Network($Message);
}
case 0x65 { # Talk Group.
if ($Verbose) {
print "UI 0x65 IMBE Voice part 4 + link control.\n";
}
#P25Link::Bytes_2_HexString($Message);
if ($Quant{'IsTGData'} == 1) {
my $MMSB = ord(substr($Message, 3, 1));
my $MSB = ord(substr($Message, 4, 1));
my $LSB = ord(substr($Message, 5, 1));
$Quant{'AstroTalkGroup'} = ($MSB << 8) | $LSB;
$Quant{'DestinationRadioID'} = ($MMSB << 16) | ($MSB << 8) | $LSB;
# Leave previous line empty.
if ($Quant{'IndividualCall'}) {
if ($Verbose) {
print "Destination ID = $Quant{'DestinationID'}\n";
}
} else {
if ($Verbose) {
print "AstroTalkGroup = $Quant{'AstroTalkGroup'}\n";
}
Packets::AddLinkTG($Quant{'AstroTalkGroup'}, 1);
}
}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x65'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x66 { # Source ID.
if ($Verbose) {
print "UI 0x66 IMBE Voice part 5. + link control.\n";
}
# Get Called ID.
if ($Quant{'IsTGData'}) {
my $MMSB = ord(substr($Message, 3, 1));
my $MSB = ord(substr($Message, 4, 1));
my $LSB = ord(substr($Message, 5, 1));
$Quant{'SourceRadioID'} = ($MMSB << 16) | ($MSB << 8) | $LSB;
# Leave previous line empty.
if ($Verbose) {
print "HDLC SourceRadioID = $Quant{'SourceRadioID'}\n";
}
#QSO_Log($RemoteHostIP);
} else {
if ($Verbose) {warn "Misterious packet 0x66\n"; }
}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x66'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x67 { # TBD
if ($Verbose) {
print "UI 0x67 IMBE Voice part 6 + link control.\n";
}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x67'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x68 {
if ($Verbose) {
print "UI 0x68 IMBE Voice part 7 + link control.\n";
}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x68'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x69 {
if ($Verbose) {
print "UI 0x69 IMBE Voice part 8 + link control.\n";
}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x69'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x6A { # Low speed data Byte 1.
if ($Verbose) {
print "UI 0x6A IMBE Voice part 9 + low speed data 1.\n";
}
$Quant{'LSD0'} = ord(substr($Message, 4, 1));
$Quant{'LSD1'} = ord(substr($Message, 5, 1));
$Quant{'Speech'} = ord(substr($Message, 6, 11));
$Quant{'Raw0x6A'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
$Quant{'Tail'} = 1;
Packets::Tx_to_Network($Message);
}
case 0x6B { # dBm, RSSI, BER.
if ($Verbose) {
print "UI 0x6B IMBE Voice part 10.\n";
}
switch (ord(substr($Message, 4, 1))) {
case 0x02 { # RT/RT Enable
$RTRTOn = 1;
if ($Verbose) { print "RT/RT Enabled"; }
}
case 0x04 { # RT/RT Disable
$RTRTOn = 0;
if ($Verbose) { print "RT/RT Disabled"; }
}
}
switch (ord(substr($Message, 6, 1))) {
case 0x0B { # DVoice
$Quant{'IsDigitalVoice'} = 1;
$Quant{'IsPage'} = 0;
if ($Verbose) { print ", Digital Voice"; }
}
case 0x0F { # Page
$Quant{'IsDigitalVoice'} = 0;
$Quant{'IsPage'} = 1;
if ($Verbose) { print ", Page"; }
}
}
$SiteID = ord(substr($Message, 7, 1));
$StationType = $SiteID; # Informative for RDAC.
switch ($SiteID) {
case C_DIU3000 { # DIU3000
if ($Verbose) { print ", SiteID: DIU 3000 or ATAC"; }
}
case C_Quantar { # Quantar
if ($Verbose) { print ", SiteID: Quantar"; }
}
}
$Quant{'RSSI'} = ord(substr($Message, 8, 1));
if (ord(substr($Message, 9, 1))) {
$Quant{'RSSI_Is_Valid'} = 1;
if ($Verbose) {
print ", RSSI = $Quant{'RSSI'}";
print ", Inverted signal = $Quant{'InvertedSignal'}";
}
} else {
$Quant{'RSSI_Is_Valid'} = 0;
}
if ($Verbose) { print "\n"; }
$Quant{'InvertedSignal'} = ord(substr($Message, 10, 1));
$Quant{'CandidateAdjustedMM'} = ord(substr($Message, 11, 1));
$Quant{'Speech'} = ord(substr($Message, 12, 11));
$Quant{'Raw0x6B'} = $Message;
$Quant{'SourceDev'} = ord(substr($Message, 23, 1));
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x6C {
if ($Verbose) {
print "UI 0x6C IMBE Voice part 11.\n";
}
$Quant{'Speech'} = ord(substr($Message, 3, 11));
$Quant{'Raw0x6C'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x6D {
if ($Verbose) {
print "UI 0x6D IMBE Voice part 12 + encryption sync.\n";
}
$Quant{'EncryptionI'} = ord(substr($Message, 3, 4));
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x6D'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x6E {
if ($Verbose) {
print "UI 0x6E IMBE Voice part 13 + encryption sync.\n";
}
$Quant{'EncryptionII'} = ord(substr($Message, 3,4));
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x6E'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x6F {
if ($Verbose) {
print "UI 0x6F IMBE Voice part 14 + encryption sync.\n";
}
$Quant{'EncryptionIII'} = ord(substr($Message, 3,4));
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x6F'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x70 { # Algorithm.
if ($Verbose) {
print "UI 0x70 IMBE Voice part 15 + encryption sync.\n";
}
$Quant{'Algorythm'} = ord(substr($Message, 3,1));
AlgoName ($Quant{'Algorythm'});
$Quant{'KeyID'} = ord(substr($Message, 4,2));
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x70'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x71 {
if ($Verbose) {
print "UI 0x71 IMBE Voice part 16 + encryption sync.\n";
}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x71'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x72 {
if ($Verbose) {
print "UI 0x72 IMBE Voice part 17 + encryption sync.\n";
}
$Quant{'Speech'} = ord(substr($Message, 7, 11));
$Quant{'Raw0x72'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
Packets::Tx_to_Network($Message);
}
case 0x73 { # Low speed data Byte 2.
if ($Verbose) {
print "UI 0x73 IMBE Voice part 18 + low speed data 2.\n";
}
$Quant{'LSD2'} = ord(substr($Message, 4, 1));
$Quant{'LSD3'} = ord(substr($Message, 5, 1));
$Quant{'Speech'} = ord(substr($Message, 6, 11));
$Quant{'Raw0x73'} = $Message;
$Quant{'IMBEFrame'} .= $Quant{'Speech'};
$Quant{'Tail'} = 1;
Packets::Tx_to_Network($Message);
}
case 0x80 {
print color('yellow'), "UI 0x80.\n", color('reset');
P25Link::Bytes_2_HexString($Message);
print "----------------------------------------------------------------------\n";
#print "Raw " . substr($Message, 1, length($Message)) . '\n';
#my $MMSB = ord(substr($Message, 51, 1));
#my $MSB = ord(substr($Message, 52, 1));
#my $LSB = ord(substr($Message, 53, 1));
#my $SourceID = ($MMSB << 16) | ($MSB << 8) | $LSB;
#print "SourceID $SourceID\n";
}
case 0x85 {
print color('yellow'), "UI 0x85.\n", color('reset');
P25Link::Bytes_2_HexString($Message);
print "----------------------------------------------------------------------\n";
#print "Raw " . substr($Message, 1, length($Message)) . '\n';
#print "Alias " . substr($Message, 11, 4) . substr($Message, 16, 4) . '\n';
}
case 0x87 {
print color('yellow'), "UI 0x87.\n", color('reset');
P25Link::Bytes_2_HexString($Message);
print "----------------------------------------------------------------------\n";
}
case 0x88 {
print color('yellow'), "UI 0x88.\n", color('reset');
P25Link::Bytes_2_HexString($Message);
print "----------------------------------------------------------------------\n";
}
case 0x8D {
print color('yellow'), "UI 0x8D.\n", color('reset');
P25Link::Bytes_2_HexString($Message);
print "----------------------------------------------------------------------\n";
}
case 0x8F {
print color('yellow'), "UI 0x8F.\n", color('reset');
P25Link::Bytes_2_HexString($Message);
print "----------------------------------------------------------------------\n";
}
case 0xA1 { # Page affliate request.
print color('yellow'), "UI 0xA1 Page call.\n", color('reset');
my $MMSB = ord(substr($Message, 15, 1));
my $MSB = ord(substr($Message, 16, 1));
my $LSB = ord(substr($Message, 17, 1));
$Quant{'DestinationRadioID'} = ($MMSB << 16) | ($MSB << 8) | $LSB;
# Leave previous line empty.
$MMSB = ord(substr($Message, 18, 1));
$MSB = ord(substr($Message, 19, 1));
$LSB = ord(substr($Message, 20, 1));
$Quant{'SourceRadioID'} = ($MMSB << 16) | ($MSB << 8) | $LSB;
# Leave previous line empty.
print color('yellow'), " Source $Quant{'SourceRadioID'}" .
", Dest $Quant{'DestinationRadioID'}", color('reset');
my $Flag = ord(substr($Message, 11, 1));
switch ($Flag) {
case 0x98 { # STS
print " Flag = STS\n";
#$StatusIndex = ord(substr(Message, 13, 1));
}
case 0x9F { # Page
print " Flag = Page\n";
}
case 0xA0 { # Page Ack.
print " Flag = Page Ack\n";
#if ($Quant{'DestinationRadioID'} == $MasterRadioID) {Then
#PageAck_Tx $Quant{'SourceRadioID'},
#$Quant{'DestinationRadioID'}, 1;
#}
}
case 0xA7 {
print color('red'), " Flag = EMERGENCY\n", color('reset');
}
}
switch (ord(substr($Message, 12, 1))) {
case 0x00 { # Individual Page
print color('yellow'), " Individual Page 12\n", color('reset');
P25Link::Bytes_2_HexString($Message);
}
case 0x90 { #Group Page
print color('yellow'), " Group Page 12\n", color('reset');
P25Link::Bytes_2_HexString($Message);
}
}
switch (ord(substr($Message, 13, 1))) {
case 0x00 { # Individual Page
print color('yellow'), " Individual Page 13.\n", color('reset');
}
case 0x80 { # Group Page
print color('yellow'), " Group Page 13.\n", color('reset');
}
case 0x9F { # Individual Page Ack
print color('yellow'), " Individual Page Ack 13.\n", color('reset');
}
}
# AddToSuperFrame(0xA1, $Message);
Packets::Tx_to_Network($Message);
} else {
print color('yellow'), "UI else 0x" . ord(substr($Message, 2, 1)) . "\n", color('reset');
P25Link::Bytes_2_HexString($Message);
print "----------------------------------------------------------------------\n";
}
}
}
case 0x3F { # SABM Rx
if ($Verbose) { print " Rx SABM\n"; }
if ($Verbose >= 3) {P25Link::Bytes_2_HexString($Message); }
$HDLC_Handshake = 0;
$HDLC{'RR_Timer'}{'Enabled'} = 0;
#if ($Verbose > 1) { print " Calling HDLC_Tx_UA\n"; }
HDLC_Tx_UA(0xFD); # 253
$SABM_Counter = $SABM_Counter + 1;
if ($SABM_Counter > 3) {
if ($Packets::Mode == 0) {
Serial::Reset();
}
$HDLC_TxTraffic = 0;
$SABM_Counter = 0;
}
}
case 0x73 { #
if ($Verbose) { print color('green'), " Rx UA (case 0x73 Unumbered Ack).\n", color('reset'); }
if ($Verbose >= 3) {P25Link::Bytes_2_HexString($Message); }
}
case 0xBF { # XID Quantar to DIU identification packet.
if ($Verbose) { print color('green'), " Rx XID.\n", color('reset'); }
if ($Verbose >= 3) {P25Link::Bytes_2_HexString($Message); }
$SABM_Counter = 0;
my $MessageType = ord(substr($Message, 2, 1));
my $StationSiteNumber = (int(ord(substr($Message, 3, 1))) - 1) / 2;
$StationType = ord(substr($Message, 4, 1));
if ($StationType == C_Quantar) {
if ($Verbose > 1) { print " Station type = Quantar.\n"; }
}
if ($StationType == C_DIU3000) {
if ($Verbose > 1) { print " Station type = DIU3000 or ATAC.\n"; }
}
if ($Verbose) { print color('yellow'), " 0x0B calling HDLC_Tx_XID\n", color('reset'); }
HDLC_Tx_XID(0x0B);
$HDLC_Handshake = 1;
$HDLC{'RR_Timer'}{'Enabled'} = 1;
#if ($Verbose) { print color('yellow'), " 0x0B calling HDLC_Tx_RR\n", color('reset'); }
#HDLC_Tx_RR();
}
}
if ($Verbose) {
print "----------------------------------------------------------------------\n";
}
return($Packets::Pending_CourtesyTone, Packets::GetLinkedTalkGroup());
}
sub HDLC_RR_Timer { # HDLC Receive Ready keep alive.
#my $Verbose = 1;
#if ($Verbose) { print color('yellow'), "HDLC_RR_Timer event $HDLC{'RR_Timer'}{'Enabled'}\n", color('reset'); }
if ($HDLC{'RR_Timer'}{'Enabled'}) {
#my $Verbose = 1;
#if ($Verbose) { print color('green'), "HDLC_RR_Timer event $HDLC{'RR_Timer'}{'Enabled'}\n", color('reset'); }
if (P25Link::GetTickCount() >= $HDLC{'RR_Timer'}{'NextTime'}) {
if ($Verbose) { print color('green'), "HDLC_RR_Timer event\n", color('reset'); }
if ($HDLC_Handshake) {
#print " RR Timed out @{[int time - $^T]}\n";
if (($Packets::Mode == 0) or (($Packets::Mode == 1) and CiscoSTUN::GetSTUN_Connected())) {
if ($Verbose) {
#print "$hour:$min:$sec Send RR by timer.\n";
#print " Mode = $Mode, STUN_Connected = " . CiscoSTUN::GetSTUN_Connected() .
# ", and HDLC_TxTraffic = $HDLC_TxTraffic\n";
}
HDLC_Tx_RR();
if ($Verbose) {
print "----------------------------------------------------------------------\n";
}
}
}
$HDLC{'RR_Timer'}{'NextTime'} = P25Link::GetTickCount() + $HDLC{'RR_Timer'}{'Interval'};
}
}
}
sub Start_RR_Timer {
$HDLC{'RR_Timer'}{'NextTime'} = P25Link::GetTickCount() + $HDLC{'RR_Timer'}{'Interval'};
}
sub HDLC_Connection_WD_Timer { # HDLC connection watchdog.
if ($HDLC{'Connection_WD_Timer'}{'Enabled'}) {
if (P25Link::GetTickCount() >= $HDLC{'Connection_WD_Timer'}{'NextTime'}) {
if ($Verbose) { print color('Yellow'), "HDLC_Connection_WD_Timer event\n", color('reset'); }
$HDLC_Handshake = 0;
$HDLC{'RR_Timer'}{'Enabled'} = 0;
if ($Verbose) {
print "----------------------------------------------------------------------\n";
}
}
$HDLC{'Connection_WD_Timer'}{'NextTime'} = P25Link::GetTickCount() + $HDLC{'Connection_WD_Timer'}{'Interval'};
}
}
sub Start_Connection_WD_Timer {
$HDLC{'Connection_WD_Timer'}{'NextTime'} = P25Link::GetTickCount() + $HDLC{'Connection_WD_Timer'}{'Interval'};
}
sub HDLC_SABM_Timer { # HDLC SABM Tx to init connection.
if ($HDLC{'SABM_Timer'}{'Enabled'}) {
if ($Packets::Mode == 0) {
$HDLC_Handshake = 1;
} else {
if (P25Link::GetTickCount() >= $HDLC{'SABM_Timer'}{'NextTime'}) {
if ($Verbose) { print color('green'), "HDLC_SABM_Timer event\n", color('reset'); }
if (!$HDLC_Handshake) {
#print " SABM Timed out @{[int time - $^T]}\n";
if (($Packets::Mode == 0) or (($Packets::Mode == 1) and !CiscoSTUN::GetSTUN_Connected())) {