-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmeraldCSBK.lua
1857 lines (1411 loc) · 59.6 KB
/
EmeraldCSBK.lua
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
----------------------------------------------------------------------------------
-- Date: 2014-10-30
-- Author: Liao Ying-RQT768
-- File: EmeraldCSBK.lua
-- Description: Handle all the Emerald CSBK PDU. Call sub dissectors by opcode.
----------------------------------------------------------------------------------
do
------------------------------------------------------------------------------
-- Some Common String Tables.
-- For All the CSBK PDU.
-- The 'gt' prefix means global table.
------------------------------------------------------------------------------
gt_LogicChannelNum = {
[0x0] = "Slot 1",
[0x1] = "Slot 2"
}
gt_SlotNum = gt_LogicChannelNum
gt_Offset = {
[0x0] = "Aligned timing",
[0x1] = "Not aligned timing"
}
gt_IG = {
[0x0] = "Target is a SU ID",
[0x1] = "Target is a talkgroup ID"
}
gt_Register = {
[0x0] = "Register",
[0x1] = "Deregister"
}
gt_MFID = {
[0x00] = "Standard",
[0x10] = "Motorola"
}
gt_ServiceKind = {
[0x00] = "Individual Voice Call", -- "(Individual, Ambient) Voice Call",
[0x01] = "Group Voice Call", -- "(Group, All, Broadcast, Emergency) Voice Call",
[0x02] = "Individual Packet Data Call",
[0x03] = "Group Packet Data Call",
[0x04] = "UDT Short Data Individual Call",
[0x05] = "UDT Short Data Group Call",
[0x06] = "Not Defined",
[0x07] = "Emergency Alarm",
[0x08] = "Not Defined",
[0x09] = "Answer Call Service",
[0x0A] = "Not Defined",
[0x0B] = "Not Defined",
[0x0C] = "Call Alert",
[0x0D] = "(Stun, Revive, Kill) / (User Id)",
[0x0E] = "Registration / (Radio Check)",
[0x0F] = "Not Defined",
[0x1C0E] = "Radio Check",
[0x1F0E] = "Registration",
[0x1C0D] = "Stun, Revive, Kill",
[0x1F0D] = "User Id",
[0xFFFF] = "If you see this string, an error has been occured."
}
gt_Address = {
[0xFFFEC5] = "SDMI - Short Data Message Identifier",
--[0xFFFEC8] = "TSI?",
[0xFFFECA] = "TSI - Address of Repeater",
[0xFFFECC] = "STUNI - Stun/Revive Identifier",
[0xFFFECD] = "AUTHI - Authentication Identifier",
[0xFFFECF] = "KILLI - Kill Identifier",
[0xFFFEC6] = "REGI - Registration Gateway Address",
[0xFFFFFD] = "SITE_ALLMSID",
[0xFFFFFE] = "ALLMSID"
}
--gt_Address = nil
gt_SKF = {
[0x0] = "Stun",
[0x1] = "Revive"
}
gt_ACKDirection = {
[0x00] = "Uplink",
[0x01] = "Downlink"
}
gt_ACKType = {
[0x00] = "NACK",
[0x01] = "ACK",
[0x02] = "QACK",
[0x03] = "WACK"
}
gt_ACKReasonCode = {
[0x60] = "Message_Accepted",
[0x62] = "Reg_Accepted",
[0x63] = "Downlink Authentication Response", --"Reg_But_No_AffiliationAccepted",
[0xA0] = "Queued-for-resource",
[0xA1] = "Queued-for-busy",
[0xE0] = "Wait",
[0x20] = "Not_Supported",
[0x21] = "Perm_User_Refused",
[0x22] = "Temp_User_Refused",
[0x23] = "Transient_Sys_Refused",
[0x24] = "NoregMSaway_Refused",
[0x25] = "MSaway_Refused",
[0x27] = "SYSbusy_Refused",
[0x28] = "SYS_NotReady",
[0x2A] = "Reg_Refused",
[0x2B] = "Reg_Denied",
[0x2D] = "MS_Not_Registered",
[0x2E] = "Called_Party_Busy",
[0x2F] = "Called_Group_Not_Allowed",
[0x3F] = "Refused_Reason_Unknown",
[0x44] = "MS_Accepted",
[0x46] = "MS_Alerting",
[0x48] = "Uplink Authentication Response",
[0xFF] = "ACKReasonCodeEnd",
[0x00] = "MSNot_Supported",
[0x13] = "EquipBusy_Refused",
[0x14] = "Recipient_Refused",
[0x15] = "Custom_Refused",
[0x1F] = "Refused_Reason_Unknown",
[0xFF] = "ReasonCodeEnd"
}
gt_AnnType = {
[0x02] = "Vote_Now",
[0x00] = "Ann-WD_TSCC",
[0x06] = "Adjacent_site",
[0xFF] = "AnnTypeEnd"
}
gt_MaintKind = {
[0x00] = "Dissconnect",
[0xFF] = "MaintKindEnd"
}
gt_NetworkModel = {
[0x0] = "Tiny(9:3)",
[0x1] = "Small(7:5)",
[0x2] = "Large(4:8)",
[0x3] = "Huge(2:10)"
}
gt_NetIDWidth = {
[0x0] = 9,
[0x1] = 7,
[0x2] = 4,
[0x3] = 2
}
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Some Common Global Var
------------------------------------------------------------------------------
g_MFID = nil
g_Opcode = nil
g_ServiceKind = nil
g_TargetAddress = nil
g_SourceAddress = nil
g_IsShowSubProtocolName = false
------------------------------------------------------------------------------
------------------------------------------------------------------------------
local p_self = Proto("em_csbk", "Em_CSBK") -- The name can't contains Upper Case Letter
local f_dataType = ProtoField.uint8("em_csbk.DataType", "Data Type", base.HEX, ota_datatypes)
local f_slotNum = ProtoField.uint8("em_csbk.SlotNum", "Slot Number", base.HEX, gt_SlotNum, 0x80) -- Mask is 1000 0000 b
local f_frameLen = ProtoField.uint16("em_csbk.FrameLength", "Frame Length", base.HEX)
local f_sigBits = ProtoField.uint16("em_csbk.SigBits", "Sig Bits", base.HEX)
local f_dataSize = ProtoField.uint16("em_csbk.DataSize", "Data Size", base.HEX)
local f_LB = ProtoField.bool("em_csbk.LB", "LB", 8, nil, 0x80) -- mask is 1000 0000
local f_PF = ProtoField.bool("em_csbk.PF", "PF", 8, nil, 0x40) -- mask is 0100 0000
local f_Opcode = ProtoField.uint8("em_csbk.Opcode", "Opcode", base.HEX, ota_csbkOpcodes, 0x3F) -- maks is 0x3F, means 00111111
local f_MFID = ProtoField.uint8("em_csbk.MFID", "MFID", base.HEX, gt_MFID)
p_self.fields = {
f_dataType,
f_slotNum,
f_frameLen,
f_sigBits,
f_dataSize,
f_LB,
f_PF,
f_Opcode,
f_MFID
}
function p_self.dissector(buf, pkt, root)
-----------------------------------------
--Reset the global var
g_MFID = 0
g_DataType = -1
g_Opcode = -1
g_ServiceKind = -1
g_TargetAddress = 0
g_SourceAddress = 0
-----------------------------------------
if (g_IsShowSubProtocolName) then
pkt.cols.protocol:set(p_self.description)
end
local t = root:add(p_self, buf(0))
local pos = 0
t:add(f_dataType, buf(pos, 1))
g_DataType = buf(pos, 1):uint()
pos = pos + 1
t:add(f_slotNum, buf(pos, 1))
pos = pos + 1
t:add(f_frameLen, buf(pos, 2))
pos = pos + 2
t:add(f_sigBits, buf(pos, 2))
pos = pos + 2
t:add(f_dataSize, buf(pos, 2))
pos = pos + 2
-- opcode
t:add(f_LB, buf(pos, 1))
t:add(f_PF, buf(pos, 1))
t:add(f_Opcode, buf(pos, 1))
g_Opcode = buf(pos, 1):uint()
g_Opcode = clearbit(g_Opcode, bit(7))
g_Opcode = clearbit(g_Opcode, bit(8))
g_info = g_info .. string.format("CSBK %s[0x%X] - ", ota_csbkOpcodes[g_Opcode] or "UnknownOpcode", g_Opcode)
pkt.cols.info:set(g_info)
pos = pos + 1
-- MFID
t:add(f_MFID, buf(pos, 1))
g_MFID = buf(pos, 1):uint()
pos = pos + 1
-- Almost all the csbk pdu contains source address, target address
ParseServiceKindTargetSource(buf, pkt, root, pos)
local sub_dissector
local subDissectorName = ""
if (g_Opcode == 0x19) then
subDissectorName = "em_c_aloha"
elseif (g_Opcode == 0x1C) then
subDissectorName = "em_c_ahoy"
elseif (g_Opcode == 0x1E) then
subDissectorName = "em_c_acvit"
elseif (g_Opcode == 0x1F) then
subDissectorName = "em_c_rand"
elseif (g_Opcode == 0x28) then
subDissectorName = "em_c_bcast"
elseif (g_Opcode == 0x2A) then
subDissectorName = "em_p_maint"
elseif (g_Opcode == 0x2E) then
subDissectorName = "em_p_clear"
elseif (g_Opcode == 0x2F) then
subDissectorName = "em_p_protect"
elseif (g_Opcode == 0x30 or g_Opcode == 0x31 or g_Opcode == 0x32) then -- (P)(BT)(T)V_Grant
subDissectorName = "em_v_grant"
elseif (g_Opcode == 0x33 or g_Opcode == 0x34) then -- (P)(T)D_Grant
subDissectorName = "em_d_grant"
elseif (g_Opcode == 0x20 or g_Opcode == 0x21) then -- C_ACKD or C_ACKU
subDissectorName = "em_c_ack"
elseif (g_Opcode == 0x38) then -- C_MOVE
subDissectorName = "em_c_move"
else
subDissectorName = "data"
end
sub_dissector = Dissector.get(subDissectorName)
if sub_dissector ~= nil then
sub_dissector:call(buf(pos):tvb(), pkt, t)
else
end
end
CheckProtocolDissector("em_csbk")
end
------------------------------------------------------------------------------------
-- There are so many same fileds between C_Rand and C_Ahoy PDUs.
-- So, we abstract serveal function and global var to parse them.
------------------------------------------------------------------------------------
function ParseServiceKindTargetSource(buf, pkt, t, pos)
g_ServiceKind = buf(pos + 1, 1):uint()
g_ServiceKind = BitHolder:_and(g_ServiceKind, 0x0F) -- 0000 1111
g_TargetAddress = buf(pos + 2, 3):uint()
g_SourceAddress = buf(pos + 5, 3):uint()
end
----------------------------------------------------------------------------------
-- Date: 2014-10-30
-- Author: Liao Ying-RQT768
-- File: EmeraldCAhoy.lua
-- Description: Handle the Emerald C_Ahoy CSBK PDU only. Called by the EmeraldCSBK.lua.
----------------------------------------------------------------------------------
do
local p_self = Proto("em_c_ahoy", "Em_C_Ahoy") -- The name can't contains Upper Case Letter
local f_Emergency = ProtoField.bool("em_c_ahoy.Emergency", "Emergency", 8, nil, 0x80) -- mask is 1000 0000
local f_EA_IG = ProtoField.bool("em_c_ahoy.IG", "IG", 8, nil, 0x80) -- mask is 1000 0000
local f_Privacy = ProtoField.bool("em_c_ahoy.Privacy", "Privacy", 8, nil, 0x40) -- mask is 0100 0000
local f_SD = ProtoField.bool("em_c_ahoy.SupplementaryData", "Supplementary Data", 8, nil, 0x20) -- mask is 0010 0000
local f_EA_SD = ProtoField.bool("em_c_ahoy.SupplementaryData", "Supplementary Data", 8, nil, 0x40) -- mask is 0100 0000
local f_Broadcast = ProtoField.bool("em_c_ahoy.Broadcast", "Broadcast", 8, nil, 0x10) -- mask is 0001 0000
local f_HR = ProtoField.bool("em_c_ahoy.HighRate", "High Rate", 8, nil, 0x10) -- mask is 0001 0000
local f_OV = ProtoField.bool("em_tv_grant.OpenVoice", "Open Voice Call Mode", 8, nil, 0x08) -- mask is 0000 1000
local f_PL = ProtoField.uint8("em_c_ahoy.PriorityLevel", "Priority Level", base.DEC, nil, 0x06) -- mask is 0000 0110
local f_SOM = ProtoField.uint8("em_c_ahoy.ServiceOptionsMirror", "Service Options Mirror", base.HEX, nil, 0xFE) -- mask is 1111 1110
local f_StatM = ProtoField.uint8("em_c_ahoy.StatM", "Stat M(Most significant bits of status)", base.HEX, nil, 0x3E) -- mask is 0011 1110
local f_SKF = ProtoField.uint8("em_c_ahoy.ServiceKindFlag", "Service Kind Flag", base.HEX, gt_SKF, 0x01) -- mask is 0000 0001
local f_Reserved1 = ProtoField.uint8("em_c_ahoy.Reserved1", "Reserved 1", base.HEX) -- nil, 0xFF) -- mask is 1111 1111
local f_Reserved2 = ProtoField.uint8("em_c_ahoy.Reserved2", "Reserved 2", base.HEX, nil, 0xF0) -- mask is 1111 0000
local f_AL = ProtoField.bool("em_c_ahoy.AmbientListeningService", "Ambient Listening Service", 8, nil, 0x80) -- mask is 1000 0000
local f_IG = ProtoField.uint8("em_c_ahoy.IG", "IG", base.HEX, gt_IG, 0x40) -- mask is 0100 0000
local f_ApBlock = ProtoField.uint8("em_c_ahoy.AppendedDataBlock", "Appended Data Blocks", base.DEC, nil, 0x30) -- mask is 0011 0000
local f_StatL = ProtoField.uint8("em_c_ahoy.StatL", "Stat L(Least significant bits of status)", base.HEX, nil, 0x30)-- mask is 0011 0000
local f_ServiceKind = ProtoField.uint8("em_c_ahoy.ServiceKind", "Service Kind", base.HEX, gt_ServiceKind, 0x0F) -- mask is 0000 1111
local f_TargetAddress = ProtoField.uint24("em_c_ahoy.TargetAddress", "Target Address", base.HEX, gt_Address)
local f_SourceAddress = ProtoField.uint24("em_c_ahoy.SourceAddress", "Source Address", base.HEX, gt_Address)
local f_CrcCCITT = ProtoField.uint16("em_c_ahoy.CRC", "CRC CCITT", base.HEX)
p_self.fields = {
f_Emergency,
f_EA_IG,
f_Privacy,
f_SD,
f_EA_SD,
f_Broadcast,
f_HR,
f_OV,
f_PL,
f_SOM,
f_StatM,
f_StatL,
f_SKF,
f_Reserved1,
f_Reserved2,
f_AL,
f_IG,
f_ApBlock,
f_ServiceKind,
f_TargetAddress,
f_SourceAddress,
f_CrcCCITT
}
function p_self.dissector(buf, pkt, root)
if (g_IsShowSubProtocolName) then
pkt.cols.protocol:set(p_self.description)
end
local t = root:add(p_self, buf(0))
local pos = 0
if (0x0 == g_ServiceKind -- Individual Voice Call, Ambient Listening
or 0x2 == g_ServiceKind -- Incividual Packet Data Call
or 0x4 == g_ServiceKind) then -- UDT Short Data Call
ParseE_SKF(buf, pkt, t, pos)
pos = pos + 1
ParseAL_SK(buf, pkt, t, pos)
pos = pos + 1
elseif (0xD == g_ServiceKind -- Stun/Revive, Kill Radio
or 0xE == g_ServiceKind) then -- Check Raido
ParseSOM_SKF(buf, pkt, t, pos)
pos = pos + 1
ParseAL_SK(buf, pkt, t, pos)
pos = pos + 1
elseif (0xC == g_ServiceKind) then -- Call Alert
ParseCallAlert(buf, pkt, t, pos)
pos = pos + 2
elseif (0x7 == g_ServiceKind) then -- Emergency Alarm
ParseEmergencyAlarm(buf, pkt, t, pos)
pos = pos + 2
else
pos = pos + 1
t:add(f_ServiceKind, buf(pos, 1))
pos = pos + 1
end
t:add(f_TargetAddress, buf(pos, 3))
pos = pos + 3
t:add(f_SourceAddress, buf(pos, 3))
pos = pos + 3
t:add(f_CrcCCITT, buf(pos, 2))
pos = pos + 2
g_info = g_info .. string.format("[%s] Src:0x%X Tgt:0x%X",
gt_ServiceKind[g_ServiceKind], g_SourceAddress, g_TargetAddress)
pkt.cols.info:set(g_info)
end
-- Check wheather the em_c_ahoy dissector has been created successfully.
CheckProtocolDissector("em_c_ahoy")
------------------------------------------------------------------------------------
-- Parse the first byte of C_Ahoy:
-- 1 2 3 4 5 6 7 8
--| E | P | SD | B/HR | OV | PL | SKF |
------------------------------------------------------------------------------------
function ParseE_SKF(buf, pkt, t, pos)
t:add(f_Emergency, buf(pos, 1))
t:add(f_Privacy, buf(pos, 1))
t:add(f_SD, buf(pos, 1))
if (0x2 == g_ServiceKind) then
t:add(f_HR, buf(pos, 1))
else
t:add(f_Broadcast, buf(pos, 1))
end
t:add(f_OV, buf(pos, 1))
t:add(f_PL, buf(pos, 1))
t:add(f_SKF, buf(pos, 1))
end
------------------------------------------------------------------------------------
-- Parse the second byte of C_Ahoy:
-- 1 2 3 4 5 6 7 8
--| AL | IG | ApBlock | Service Kind |
------------------------------------------------------------------------------------
function ParseAL_SK(buf, pkt, t, pos)
t:add(f_AL, buf(pos, 1))
t:add(f_IG, buf(pos, 1))
t:add(f_ApBlock, buf(pos, 1))
t:add(f_ServiceKind, buf(pos, 1))
end
------------------------------------------------------------------------------------
-- Parse the first byte of C_Ahoy:
--
-- | Service Options Mirror | SKF |
------------------------------------------------------------------------------------
function ParseSOM_SKF(buf, pkt, t, pos)
t:add(f_SOM, buf(pos, 1))
t:add(f_SKF, buf(pos, 1))
end
------------------------------------------------------------------------------------
-- Parse the 2 bytes of C_Ahoy:
--
-- | Reserved 1 |
-- | Reserved 2 | Service Kind |
------------------------------------------------------------------------------------
function ParseCallAlert(buf, pkt, t, pos)
t:add(f_Reserved1, buf(pos + 0, 1))
t:add(f_Reserved2, buf(pos + 1, 1))
end
------------------------------------------------------------------------------------
-- Parse the 2 + 3 + 3 bytes of C_Ahoy:
--
-- | IG | SD | Start_M(5bit) | SKF | 1
-- | AL | IG | Start_L | Service Kind | 2
-- | | 3
-- | Emergency Group Address | 4
-- | | 5
-- | | 6
-- | Source SU Address | 7
-- | | 8
------------------------------------------------------------------------------------
function ParseEmergencyAlarm(buf, pkt, t, pos)
t:add(f_EA_IG, buf(pos, 1))
t:add(f_EA_SD, buf(pos, 1))
t:add(f_StatM, buf(pos, 1))
t:add(f_SKF, buf(pos, 1))
t:add(f_AL, buf(pos + 1, 1))
t:add(f_IG, buf(pos + 1, 1))
t:add(f_StatL, buf(pos + 1, 1))
t:add(f_ServiceKind, buf(pos + 1, 1))
end
end
----------------------------------------------------------------------------------
-- Date: 2014-10-30
-- Author: Liao Ying-RQT768
-- File: EmeraldCAloha.lua
-- Description: Handle the Emerald Aloha CSBK PDU only. Called by the EmeraldCSBK.lua.
----------------------------------------------------------------------------------
do
local t_serviceFunction = {
[0x0] = "All",
[0x1] = "Registration & Payload",
[0x2] = "Registration & No Payload",
[0x3] = "Registration only"
}
local p_self = Proto("em_c_aloha", "Em_C_Aloha") -- The name can't contains Upper Case Letter
--local f_FID = ProtoField.uint8("em_c_aloha.f_fid", "Feature set ID", base.HEX)
local f_Reserved = ProtoField.uint8("em_c_aloha.Reserved", "Reserved", base.HEX, nil, 0xC0) -- mask is 1100 0000
local f_SlotSyn = ProtoField.uint8("em_c_aloha.SlotSyn", "SlotSyn", base.HEX, nil, 0x20) -- mask is 0010 0000
local f_Version = ProtoField.uint8("em_c_aloha.Version", "Version", base.HEX, nil, 0x1C) -- mask is 0001 1100
local f_Reserved2 = ProtoField.uint8("em_c_aloha.Reserved2", "Reserved2", base.HEX, nil, 0x02) -- mask is 0000 0010
local f_AC = ProtoField.bool("em_c_aloha.ActiveConnection", "Active Connection", 8, nil, 0x01) -- mask is 0000 0001
local f_Mask = ProtoField.uint8("em_c_aloha.Mask", "Mask", base.HEX, nil, 0xF8) -- mask is 11111000
local f_SF = ProtoField.uint8("em_c_aloha.ServiceFunction", "Service Function", base.HEX, t_serviceFunction, 0x06) -- mask is 00000110
local f_RandomWait = ProtoField.uint16("em_c_aloha.RandomWait", "Random Wait", base.DEC, nil, 0x01E0) -- mask is 0000 0001 1110 0000
local f_Reg = ProtoField.bool("em_c_aloha.Reg", "Require to register", 8, nil, 0x10) -- mask is 0001 0000
local f_BackOff = ProtoField.uint8("em_c_aloha.Backoff", "Back Off", base.DEC, nil, 0x0F) -- mask is 0000 1111
local f_CSysCode = ProtoField.uint16("em_c_aloha.CSyscode", "C Syscode", base.HEX)
local f_MSAddress = ProtoField.uint24("em_c_aloha.MSAddress", "MS Address", base.HEX)
local f_CRC = ProtoField.uint16("em_c_aloha.CRC", "CRC-CCITT", base.HEX)
p_self.fields = {
--f_FID,
f_Reserved,
f_SlotSyn,
f_Version,
f_Reserved2,
f_AC,
f_Mask,
f_SF,
f_RandomWait,
f_Reg,
f_BackOff,
f_CSysCode,
f_MSAddress,
f_CRC
}
function p_self.dissector(buf, pkt, root)
if (g_IsShowSubProtocolName) then
pkt.cols.protocol:set(p_self.description)
end
local t = root:add(p_self, buf(0))
local pos = 0
--t:add(f_FID, buf(pos, 1))
--pos = pos + 1
t:add(f_Reserved, buf(pos, 1))
t:add(f_SlotSyn, buf(pos, 1))
t:add(f_Version, buf(pos, 1))
t:add(f_Reserved2, buf(pos, 1))
t:add(f_AC, buf(pos, 1))
pos = pos + 1
t:add(f_Mask, buf(pos, 1))
t:add(f_SF, buf(pos, 1))
--[[ -- There is no need to do these.
local randomWait1 = buf(pos, 1):uint()
randomWait1 = BitHolder:_and(randomWait1, 0x1)
randomWait1 = BitHolder:_lshift(randomWait1, 3)
local randomWait2 = buf(pos + 1, 1):uint()
randomWait2 = BitHolder:_and(randomWait2, 0xE0)
randomWait2 = BitHolder:_rshift(randomWait2, 5)
local randomWait = BitHolder:_or(randomWait1, randomWait2)
t:add(f_RandomWait, buf(pos, 2), randomWait)
]]
t:add(f_RandomWait, buf(pos, 2))
local randomWait = buf(pos, 2):uint()
randomWait = BitHolder:_and(randomWait, 0x1E0) --0000 0001 1110 0000
randomWait = BitHolder:_rshift(randomWait, 5)
pos = pos + 1
t:add(f_Reg, buf(pos, 1))
t:add(f_BackOff, buf(pos, 1))
local backOff = buf(pos, 1):uint()
backOff = BitHolder:_and(backOff, 0x0F) --0000 1111
pos = pos + 1
t:add(f_CSysCode, buf(pos, 2))
local sysCode = buf(pos, 2):uint()
pos = pos + 2
t:add(f_MSAddress, buf(pos, 3))
pos = pos + 3
t:add(f_CRC, buf(pos, 2))
pos = pos + 2
g_info = g_info .. string.format("Wait:%d Backoff:%d ", randomWait, backOff)
pkt.cols.info:set(g_info)
end
CheckProtocolDissector("em_c_aloha")
end
----------------------------------------------------------------------------------
-- Date: 2014-11-03
-- Author: Liao Ying-RQT768
-- File: EmeraldCRand.lua
-- Description: Handle the Emerald C_Rand CSBK PDU only. Called by the EmeraldCSBK.lua.
----------------------------------------------------------------------------------
do
local p_self = Proto("em_c_rand", "Em_C_Rand") -- The name can't contains Upper Case Letter
------Fields for C_Rand Register--------------------
local f_Reg_Reserved1 = ProtoField.uint8("em_c_rand.RegReserved1", "Reserved", base.HEX, nil, 0x80) -- mask is 1000 0000
-- Privacy is same as f_Privacy
local f_IPInform = ProtoField.bool("em_c_rand.IpInform", "IP Inform", 8, nil, 0x20) -- mask is 0010 0000
local f_PowerSaveRequest = ProtoField.uint8("em_c_rand.PowerSaveRequest", "Power Save Request", base.HEX, nil, 0x1C) -- mask is 0001 1100
local f_Register = ProtoField.uint8("em_c_rand.Register", "Register", base.HEX, gt_Register, 0x02) -- mask is 0000 0010
-- Prx is same as f_PX
-- Ap Spl is same as f_SupD
local f_Reg_Reserved2 = ProtoField.uint8("em_c_rand.RegReserved2", "Reserved", base.HEX, nil, 0x30) -- mask is 0011 0000
-- Redistration is same as f_ServiceKind
----------------------------------------------------
-- Random access by SU for User Id
local f_Char1 = ProtoField.uint8("em_c_rand.Char1", "Char1", base.HEX, nil, 0x3F) -- mask is 0011 1111
local f_NumOfChar = ProtoField.uint8("em_c_rand.NumOfChar", "Number Of Char", base.HEX, nil, 0xF0) -- mask is 1111 0000
local f_Char2 = ProtoField.uint8("em_c_rand.Char2", "Char2", base.HEX, nil, 0xFC) -- mask is 1111 1100
local f_Char3 = ProtoField.uint16("em_c_rand.Char3", "Char3", base.HEX, nil, 0x3F0) -- mask is 0000 0011 1111 0000
local f_Char4 = ProtoField.uint16("em_c_rand.Char4", "Char4", base.HEX, nil, 0xFC0) -- mask is 0000 1111 1100 0000
local f_Char5 = ProtoField.uint8("em_c_rand.Char5", "Char5", base.HEX, nil, 0x3F) -- mask is 0011 1111
----------------------------------------------------
local f_Emergency = ProtoField.bool("em_c_rand.Emergency", "Emergency", 8, nil, 0x80) -- mask is 1000 0000
local f_EA_IG = ProtoField.bool("em_c_rand.IG", "IG", 8, nil, 0x80) -- mask is 1000 0000
local f_Privacy = ProtoField.bool("em_c_rand.Privacy", "Privacy", 8, nil, 0x40) -- mask is 0100 0000
local f_EA_SD = ProtoField.bool("em_c_rand.SupplementaryData", "Supplementary Data", 8, nil, 0x40) -- mask is 0100 0000
local f_SD = ProtoField.bool("em_c_rand.SupplementaryData", "Supplementary Data", 8, nil, 0x20) -- mask is 0010 0000
local f_Broadcast = ProtoField.bool("em_c_rand.Broadcast", "Broadcast", 8, nil, 0x10) -- mask is 0001 0000
local f_HR = ProtoField.bool("em_c_rand.HighRate", "High Rate", 8, nil, 0x10) -- mask is 0001 0000
local f_OV = ProtoField.bool("em_tv_grant.OpenVoice", "Open Voice Call Mode", 8, nil, 0x08) -- mask is 0000 1000
local f_PL = ProtoField.uint8("em_c_rand.PriorityLevel", "Priority Level", base.DEC, nil, 0x06) -- mask is 0000 0110
local f_StatM = ProtoField.uint8("em_c_rand.StatM", "Stat M(Most significant bits of status)", base.HEX, nil, 0x3E) -- mask is 0011 1110
local f_PX = ProtoField.bool("em_c_rand.ProxyFlag", "Proxy Flag", 8, nil, 0x01) -- mask is 0000 0001
local f_Reserved1 = ProtoField.uint8("em_c_rand.Reserved1", "Reserved 1", base.HEX) -- nil, 0xFF) -- mask is 1111 1111
local f_Reserved2 = ProtoField.uint8("em_c_rand.Reserved2", "Reserved 2", base.HEX, nil, 0xF0) -- mask is 1111 0000
local f_SupD = ProtoField.uint8("em_c_rand.SupD", "Appended Blocks for Supplementary Data", base.HEX, nil, 0xC0) -- mask is 1100 0000
local f_ShD = ProtoField.uint8("em_c_rand.ShD", "Appended Blocks for UDT Short Data", base.HEX, nil, 0x30) -- mask is 0011 0000
local f_AL = ProtoField.bool("em_c_rand.AmbientListening", "Ambient Listening", 8, nil, 0x20) -- mask is 0010 0000
local f_AR = ProtoField.bool("em_c_rand.Reject", "Reject FOACSU call", 8, nil, 0x20) -- mask is 0010 0000
local f_Reserved = ProtoField.uint8("em_c_rand.Reserved", "Reserved", base.HEX, nil, 0x10) -- mask is 0001 0000
local f_StatL = ProtoField.uint8("em_c_rand.StatL", "Stat L(Least significant bits of status)", base.HEX, nil, 0x30) --0011 0000
local f_ServiceKind = ProtoField.uint8("em_c_rand.ServiceKind", "Service Kind", base.HEX, gt_ServiceKind, 0x0F) --0000 1111
local f_TargetAddress = ProtoField.uint24("em_c_rand.TargetAddress", "Target Address", base.HEX, gt_Address)
local f_CSyscode = ProtoField.uint16("em_c_rand.CSyscode", "C Syscode", base.HEX)
local f_SourceAddress = ProtoField.uint24("em_c_rand.SourceAddress", "Source Address", base.HEX, gt_Address)
local f_CrcCCITT = ProtoField.uint16("em_c_rand.CRC", "CRC CCITT", base.HEX)
p_self.fields = {
------For Reg------
f_Reg_Reserved1,
f_IPInform,
f_PowerSaveRequest,
f_Register,
f_Reg_Reserved2,
------------------
------------------
f_Emergency,
f_EA_IG,
f_Privacy,
f_SD,
f_EA_SD,
f_Broadcast,
f_HR,
f_OV,
f_PL,
f_StatM,
f_StatL,
f_PX,
f_Reserved1,
f_Reserved2,
f_SupD,
f_ShD,
f_AL,
f_Reserved,
f_ServiceKind,
f_TargetAddress,
f_CSyscode,
f_SourceAddress,
f_CrcCCITT
}
function p_self.dissector(buf, pkt, root)
if (g_IsShowSubProtocolName) then
pkt.cols.protocol:set(p_self.description)
end
local t = root:add(p_self, buf(0))
local pos = 0
if (0x0 == g_ServiceKind -- Individual Voice Call, Ambient Listening
or 0x1 == g_ServiceKind -- (Group, Broadcast, All, Emergency) Voice Call
or 0x9 == g_ServiceKind) then -- Answer Call Service
ParseE_PX(buf, pkt, t, pos)
pos = pos + 1
ParseSupD_SK(buf, pkt, t, pos)
pos = pos + 1
elseif (0x2 == g_ServiceKind -- Individual Packet Data Call
or 0x3 == g_ServiceKind -- Talk Group Packet Data Call
or 0x4 == g_ServiceKind -- UDT Short Data Individual Call
or 0x5 == g_ServiceKind) then -- UDT Short Data Talk Group Call
ParseE_PX(buf, pkt, t, pos)
pos = pos + 1
ParseShD_SK(buf, pkt, t, pos)
pos = pos + 1
elseif (0xC == g_ServiceKind) then -- Call Alert
if (g_MFID == 0x10) then -- Motorola_MFID
ParseCallAlert(buf, pkt, t, pos)
end
pos = pos + 2
elseif (0xE == g_ServiceKind) then -- Registration
ParseRegistration(buf, pkt, t, pos)
pos = pos + 2 + 3 + 3
elseif (0xD == g_ServiceKind) then -- Random access by SU for User Id
ParseUserID(buf, pkt, t, pos) -- Not Test.
pos = pos + 2 + 3 + 3
elseif (0x7 == g_ServiceKind) then -- Emergency Alarm
ParseEmergencyAlarm(buf, pkt, t, pos)
pos = pos + 2
else
pos = pos + 1
t:add(f_ServiceKind, buf(pos, 1))
pos = pos + 1
end
if (0xE ~= g_ServiceKind and 0xD ~= g_ServiceKind) then -- Not Registration and Not User Id
t:add(f_TargetAddress, buf(pos, 3))
pos = pos + 3
t:add(f_SourceAddress, buf(pos, 3))
pos = pos + 3
g_info = g_info .. string.format("[%s] Src:0x%X Tgt:0x%X",
gt_ServiceKind[g_ServiceKind], g_SourceAddress, g_TargetAddress)
else
local newServiceKindValue = BitHolder:_lshift(g_Opcode, 8) + g_ServiceKind
if (0x0 == g_MFID) then -- Standart Registration
g_info = g_info .. string.format("[%s] Src:0x%X CSyscode:0x%X",
gt_ServiceKind[newServiceKindValue], g_SourceAddress, g_TargetAddress)
else
g_info = g_info .. string.format("[%s] Src:0x%X Tgt:0x%X",
gt_ServiceKind[newServiceKindValue], g_SourceAddress, g_TargetAddress)
end
end
t:add(f_CrcCCITT, buf(pos, 2))
pos = pos + 2
pkt.cols.info:set(g_info)
end
-- Check wheather the em_c_rand dissector has been created successfully.
CheckProtocolDissector("em_c_rand")
------------------------------------------------------------------------------------
-- Parse the first byte of C_Rand:
-- 1 2 3 4 5 6 7 8
--| E | P | SD | B/HR | OV | PL | PX |
------------------------------------------------------------------------------------
function ParseE_PX(buf, pkt, t, pos)
t:add(f_Emergency, buf(pos, 1))
t:add(f_Privacy, buf(pos, 1))
t:add(f_SD, buf(pos, 1))
if (0x2 == g_ServiceKind -- Individual Packet Data Call
or 0x3 == g_ServiceKind) then -- Talk Group Packet Data Call
t:add(f_HR, buf(pos, 1))
else
t:add(f_Broadcast, buf(pos, 1))
end
t:add(f_OV, buf(pos, 1))
t:add(f_PL, buf(pos, 1))
t:add(f_PX, buf(pos, 1))
end
------------------------------------------------------------------------------------
-- Parse the second byte of C_Rand:
-- 1 2 3 4 5 6 7 8
--| Sup_D | AL | R | Service Kind |
------------------------------------------------------------------------------------
function ParseSupD_SK(buf, pkt, t, pos)
t:add(f_SupD, buf(pos, 1))
if (0x9 == g_ServiceKind) then -- Answer Call Service
t:add(f_AR, buf(pos, 1))
else
t:add(f_AL, buf(pos, 1))
end
t:add(f_Reserved, buf(pos, 1))
t:add(f_ServiceKind, buf(pos, 1))
end
------------------------------------------------------------------------------------
-- Parse the second byte of C_Rand:
-- 1 2 3 4 5 6 7 8
--| Sup_D | Sh_D | Service Kind |
------------------------------------------------------------------------------------
function ParseShD_SK(buf, pkt, t, pos)
t:add(f_SupD, buf(pos, 1))
t:add(f_ShD, buf(pos, 1))
t:add(f_ServiceKind, buf(pos, 1))
end
------------------------------------------------------------------------------------
-- Parse the first 2 bytes of C_Rand:
--
-- | Reserved 1 |
-- | Reserved 2 | Service Kind |
------------------------------------------------------------------------------------
function ParseCallAlert(buf, pkt, t, pos)
t:add(f_Reserved1, buf(pos + 0, 1))
t:add(f_Reserved2, buf(pos + 1, 1))
end
------------------------------------------------------------------------------------
-- Parse the first 2 bytes of C_Rand:
-- 1 2 3 4 5 6 7 8
-- 1 | IG | SD | Start_M(5bit) | PX |
-- 2 | AL | IG | Start_L | Service Kind |
-- 3 | |
-- 4 | Emergency Group Address |
-- 5 | |
-- 6 | |
-- 7 | Source SU Address |
-- 8 | |
------------------------------------------------------------------------------------
function ParseEmergencyAlarm(buf, pkt, t, pos)
t:add(f_EA_IG, buf(pos, 1))
t:add(f_EA_SD, buf(pos, 1))
t:add(f_StatM, buf(pos, 1))
t:add(f_PX, buf(pos, 1))
t:add(f_SupD, buf(pos + 1, 1))
t:add(f_StatL, buf(pos + 1, 1))
t:add(f_ServiceKind, buf(pos + 1, 1))
end
------------------------------------------------------------------------------------
-- Parse the Standard Registration C_Rand:
-- 1 2 3 4 5 6 7 8
-- 1 | P | R | IPInf | Power Save Req | PX |
-- 2 | SupD | R | Service Kind |
-- 3 | 0000 0000 |
-- 4 | |
-- 5 | C_Syscode |
-- 6 | |
-- 7 | Source SU Address |
-- 8 | |
-- Parse the Motorola Registration C_Rand:
-- 1 2 3 4 5 6 7 8
-- 1 | P | R | IPInf | Power Save Req | PX |
-- 2 | SupD | R | Service Kind |
-- 3 | |
-- 4 | Target Address |
-- 5 | |
-- 6 | |
-- 7 | Source SU Address |
-- 8 | |
------------------------------------------------------------------------------------
function ParseRegistration(buf, pkt, t, pos)
t:add(f_Reg_Reserved1, buf(pos, 1))
t:add(f_Privacy, buf(pos, 1))
t:add(f_IPInform, buf(pos, 1))
t:add(f_PowerSaveRequest, buf(pos, 1))
t:add(f_Register, buf(pos, 1))
t:add(f_PX, buf(pos, 1))
t:add(f_SupD, buf(pos + 1, 1))
t:add(f_Reg_Reserved2, buf(pos + 1, 1))
local newServiceKindValue = BitHolder:_lshift(g_Opcode, 8) + g_ServiceKind
-- Logger:AppendLog("newServiceKindValue: 0x%X", newServiceKindValue)
-- t:add(f_ServiceKind, buf(pos + 1, 1), newServiceKindValue, "" .. gt_ServiceKind[newServiceKindValue])
local ti = t:add(f_ServiceKind, buf(pos + 1, 1))
ti:append_text(" --> " .. gt_ServiceKind[newServiceKindValue])
if (0x10 == g_MFID) then -- Motorola
t:add(f_TargetAddress, buf(pos + 2, 3))
t:add(f_SourceAddress, buf(pos + 5, 3))
else -- Standard
t:add(f_CSyscode, buf(pos + 3, 2))
t:add(f_SourceAddress, buf(pos + 5, 3))
end
end
------------------------------------------------------------------------------------