-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjamulus.lua
1127 lines (1069 loc) · 36.8 KB
/
jamulus.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
-------------------------------------------------------------------------------
--
-- author: Tony Mountifield <tony@mountifield.org>
-- Copyright (c) 2020, Tony Mountifield
-- This code is in the Public Domain, or the BSD (3 clause) license
-- if Public Domain does not apply in your country.
--
-- Version: 1.0
--
-------------------------------------------------------------------------------
--[[
This code is a plugin for Wireshark, to dissect Jamulus protocol messages
over UDP.
]]----------------------------------------
----------------------------------------
-- do not modify this table
local debug_level = {
DISABLED = 0,
LEVEL_1 = 1,
LEVEL_2 = 2
}
----------------------------------------
-- set this DEBUG to debug_level.LEVEL_1 to enable printing debug_level info
-- set it to debug_level.LEVEL_2 to enable really verbose printing
-- set it to debug_level.DISABLED to disable debug printing
-- note: this will be overridden by user's preference settings
local DEBUG = debug_level.LEVEL_1
-- a table of our default settings - these can be changed by changing
-- the preferences through the GUI or command-line; the Lua-side of that
-- preference handling is at the end of this script file
local default_settings =
{
debug_level = DEBUG,
enabled = true, -- whether this dissector is enabled or not
port1 = 22120, -- first UDP port number for Jamulus
port2 = 22139, -- last UDP port number for Jamulus
}
local dprint = function() end
local dprint2 = function() end
local function resetDebugLevel()
if default_settings.debug_level > debug_level.DISABLED then
dprint = function(...)
info(table.concat({"Lua: ", ...}," "))
end
if default_settings.debug_level > debug_level.LEVEL_1 then
dprint2 = dprint
end
else
dprint = function() end
dprint2 = dprint
end
end
-- call it now
resetDebugLevel()
----------------------------------------
-- a function to convert tables of enumerated types to value-string tables
-- i.e., from { "name" = number } to { number = "name" }
local function makeValString(enumTable)
local t = {}
for name,num in pairs(enumTable) do
t[num] = name
end
return t
end
--------------------------------------------------------------------------------
-- creates a Proto object, but doesn't register it yet
jamulus = Proto("Jamulus", "Jamulus Protocol")
opcodes = {
ILLEGAL = 0, -- illegal ID
ACKN = 1, -- acknowledge
JITT_BUF_SIZE = 10, -- jitter buffer size
REQ_JITT_BUF_SIZE = 11, -- request jitter buffer size
NET_BLSI_FACTOR = 12, -- OLD (not used anymore)
CHANNEL_GAIN = 13, -- set channel gain for mix
CONN_CLIENTS_LIST_NAME = 14, -- OLD (not used anymore)
SERVER_FULL = 15, -- OLD (not used anymore)
REQ_CONN_CLIENTS_LIST = 16, -- request connected client list
CHANNEL_NAME = 17, -- OLD (not used anymore)
CHAT_TEXT = 18, -- contains a chat text
PING_MS = 19, -- OLD (not used anymore)
NETW_TRANSPORT_PROPS = 20, -- properties for network transport
REQ_NETW_TRANSPORT_PROPS = 21, -- request properties for network transport
DISCONNECTION = 22, -- OLD (not used anymore)
REQ_CHANNEL_INFOS = 23, -- request channel infos for fader tag
CONN_CLIENTS_LIST = 24, -- channel infos for connected clients
CHANNEL_INFOS = 25, -- set channel infos
OPUS_SUPPORTED = 26, -- tells that OPUS codec is supported
LICENCE_REQUIRED = 27, -- licence required
REQ_CHANNEL_LEVEL_LIST = 28, -- request the channel level list
VERSION_AND_OS = 29, -- version number and operating system
CHANNEL_PAN = 30, -- set channel pan for mix
MUTE_STATE_CHANGED = 31, -- mute state of your signal at another client has changed
CLIENT_ID = 32, -- current user ID and server status
RECORDER_STATE = 33, -- state of the jam recorder on the server
REQ_SPLIT_MESS_SUPPORT = 34, -- request support for split messages
SPLIT_MESS_SUPPORTED = 35, -- split messages are supported
CLM_PING_MS = 1001, -- for measuring ping time
CLM_PING_MS_WITHNUMCLIENTS = 1002, -- for ping time and num. of clients info
CLM_SERVER_FULL = 1003, -- server full message
CLM_REGISTER_SERVER = 1004, -- register server
CLM_UNREGISTER_SERVER = 1005, -- unregister server
CLM_SERVER_LIST = 1006, -- server list
CLM_REQ_SERVER_LIST = 1007, -- request server list
CLM_SEND_EMPTY_MESSAGE = 1008, -- an empty message shall be send
CLM_EMPTY_MESSAGE = 1009, -- empty message
CLM_DISCONNECTION = 1010, -- disconnection
CLM_VERSION_AND_OS = 1011, -- version number and operating system
CLM_REQ_VERSION_AND_OS = 1012, -- request version number and operating system
CLM_CONN_CLIENTS_LIST = 1013, -- channel infos for connected clients
CLM_REQ_CONN_CLIENTS_LIST = 1014, -- request the connected clients list
CLM_CHANNEL_LEVEL_LIST = 1015, -- channel level list
CLM_REGISTER_SERVER_RESP = 1016, -- status of server registration request
CLM_REGISTER_SERVER_EX = 1017, -- register server with extended information
CLM_RED_SERVER_LIST = 1018, -- reduced server list
SPECIAL_SPLIT_MESSAGE = 2001, -- a container for split messages
}
local opcodes_valstr = makeValString(opcodes)
local countries = {
AnyCountry = 0,
Afghanistan = 1,
Albania = 2,
Algeria = 3,
AmericanSamoa = 4,
Andorra = 5,
Angola = 6,
Anguilla = 7,
Antarctica = 8,
AntiguaAndBarbuda = 9,
Argentina = 10,
Armenia = 11,
Aruba = 12,
Australia = 13,
Austria = 14,
Azerbaijan = 15,
Bahamas = 16,
Bahrain = 17,
Bangladesh = 18,
Barbados = 19,
Belarus = 20,
Belgium = 21,
Belize = 22,
Benin = 23,
Bermuda = 24,
Bhutan = 25,
Bolivia = 26,
BosniaAndHerzegowina = 27,
Botswana = 28,
BouvetIsland = 29,
Brazil = 30,
BritishIndianOceanTerritory = 31,
Brunei = 32,
Bulgaria = 33,
BurkinaFaso = 34,
Burundi = 35,
Cambodia = 36,
Cameroon = 37,
Canada = 38,
CapeVerde = 39,
CaymanIslands = 40,
CentralAfricanRepublic = 41,
Chad = 42,
Chile = 43,
China = 44,
ChristmasIsland = 45,
CocosIslands = 46,
Colombia = 47,
Comoros = 48,
CongoKinshasa = 49,
CongoBrazzaville = 50,
CookIslands = 51,
CostaRica = 52,
IvoryCoast = 53,
Croatia = 54,
Cuba = 55,
Cyprus = 56,
CzechRepublic = 57,
Denmark = 58,
Djibouti = 59,
Dominica = 60,
DominicanRepublic = 61,
EastTimor = 62,
Ecuador = 63,
Egypt = 64,
ElSalvador = 65,
EquatorialGuinea = 66,
Eritrea = 67,
Estonia = 68,
Ethiopia = 69,
FalklandIslands = 70,
FaroeIslands = 71,
Fiji = 72,
Finland = 73,
France = 74,
Guernsey = 75,
FrenchGuiana = 76,
FrenchPolynesia = 77,
FrenchSouthernTerritories = 78,
Gabon = 79,
Gambia = 80,
Georgia = 81,
Germany = 82,
Ghana = 83,
Gibraltar = 84,
Greece = 85,
Greenland = 86,
Grenada = 87,
Guadeloupe = 88,
Guam = 89,
Guatemala = 90,
Guinea = 91,
GuineaBissau = 92,
Guyana = 93,
Haiti = 94,
HeardAndMcDonaldIslands = 95,
Honduras = 96,
HongKong = 97,
Hungary = 98,
Iceland = 99,
India = 100,
Indonesia = 101,
Iran = 102,
Iraq = 103,
Ireland = 104,
Israel = 105,
Italy = 106,
Jamaica = 107,
Japan = 108,
Jordan = 109,
Kazakhstan = 110,
Kenya = 111,
Kiribati = 112,
NorthKorea = 113,
SouthKorea = 114,
Kuwait = 115,
Kyrgyzstan = 116,
Laos = 117,
Latvia = 118,
Lebanon = 119,
Lesotho = 120,
Liberia = 121,
Libya = 122,
Liechtenstein = 123,
Lithuania = 124,
Luxembourg = 125,
Macau = 126,
Macedonia = 127,
Madagascar = 128,
Malawi = 129,
Malaysia = 130,
Maldives = 131,
Mali = 132,
Malta = 133,
MarshallIslands = 134,
Martinique = 135,
Mauritania = 136,
Mauritius = 137,
Mayotte = 138,
Mexico = 139,
Micronesia = 140,
Moldova = 141,
Monaco = 142,
Mongolia = 143,
Montserrat = 144,
Morocco = 145,
Mozambique = 146,
Myanmar = 147,
Namibia = 148,
NauruCountry = 149,
Nepal = 150,
Netherlands = 151,
CuraSao = 152,
NewCaledonia = 153,
NewZealand = 154,
Nicaragua = 155,
Niger = 156,
Nigeria = 157,
Niue = 158,
NorfolkIsland = 159,
NorthernMarianaIslands = 160,
Norway = 161,
Oman = 162,
Pakistan = 163,
Palau = 164,
PalestinianTerritories = 165,
Panama = 166,
PapuaNewGuinea = 167,
Paraguay = 168,
Peru = 169,
Philippines = 170,
Pitcairn = 171,
Poland = 172,
Portugal = 173,
PuertoRico = 174,
Qatar = 175,
Reunion = 176,
Romania = 177,
Russia = 178,
Rwanda = 179,
SaintKittsAndNevis = 180,
SaintLucia = 181,
SaintVincentAndTheGrenadines = 182,
Samoa = 183,
SanMarino = 184,
SaoTomeAndPrincipe = 185,
SaudiArabia = 186,
Senegal = 187,
Seychelles = 188,
SierraLeone = 189,
Singapore = 190,
Slovakia = 191,
Slovenia = 192,
SolomonIslands = 193,
Somalia = 194,
SouthAfrica = 195,
SouthGeorgiaAndTheSouthSandwichIslands = 196,
Spain = 197,
SriLanka = 198,
SaintHelena = 199,
SaintPierreAndMiquelon = 200,
Sudan = 201,
Suriname = 202,
SvalbardAndJanMayenIslands = 203,
Swaziland = 204,
Sweden = 205,
Switzerland = 206,
Syria = 207,
Taiwan = 208,
Tajikistan = 209,
Tanzania = 210,
Thailand = 211,
Togo = 212,
TokelauCountry = 213,
Tonga = 214,
TrinidadAndTobago = 215,
Tunisia = 216,
Turkey = 217,
Turkmenistan = 218,
TurksAndCaicosIslands = 219,
TuvaluCountry = 220,
Uganda = 221,
Ukraine = 222,
UnitedArabEmirates = 223,
UnitedKingdom = 224,
UnitedStates = 225,
UnitedStatesMinorOutlyingIslands = 226,
Uruguay = 227,
Uzbekistan = 228,
Vanuatu = 229,
VaticanCityState = 230,
Venezuela = 231,
Vietnam = 232,
BritishVirginIslands = 233,
UnitedStatesVirginIslands = 234,
WallisAndFutunaIslands = 235,
WesternSahara = 236,
Yemen = 237,
CanaryIslands = 238,
Zambia = 239,
Zimbabwe = 240,
ClippertonIsland = 241,
Montenegro = 242,
Serbia = 243,
SaintBarthelemy = 244,
SaintMartin = 245,
LatinAmerica = 246,
AscensionIsland = 247,
AlandIslands = 248,
DiegoGarcia = 249,
CeutaAndMelilla = 250,
IsleOfMan = 251,
Jersey = 252,
TristanDaCunha = 253,
SouthSudan = 254,
Bonaire = 255,
SintMaarten = 256,
Kosovo = 257,
EuropeanUnion = 258,
OutlyingOceania = 259,
World = 260,
Europe = 261,
}
local countries_valstr = makeValString(countries)
local instruments = {
None = 0,
Drum_Set = 1,
Djembe = 2,
Electric_Guitar = 3,
Acoustic_Guitar = 4,
Bass_Guitar = 5,
Keyboard = 6,
Synthesizer = 7,
Grand_Piano = 8,
Accordion = 9,
Vocal = 10,
Microphone = 11,
Harmonica = 12,
Trumpet = 13,
Trombone = 14,
French_Horn = 15,
Tuba = 16,
Saxophone = 17,
Clarinet = 18,
Flute = 19,
Violin = 20,
Cello = 21,
Double_Bass = 22,
Recorder = 23,
Streamer = 24,
Listener = 25,
Guitar_Vocal = 26,
Keyboard_Vocal = 27,
Bodhran = 28,
Bassoon = 29,
Oboe = 30,
Harp = 31,
Viola = 32,
Congas = 33,
Bongo = 34,
Vocal_Bass = 35,
Vocal_Tenor = 36,
Vocal_Alto = 37,
Vocal_Soprano = 38,
Banjo = 39,
Mandolin = 40,
Ukulele = 41,
Bass_Ukulele = 42,
Vocal_Baritone = 43,
Vocal_Lead = 44,
Mountain_Dulcimer = 45,
Scratching = 46,
Rapping = 47,
Vibraphone = 48,
Conductor = 49,
}
local instruments_valstr = makeValString(instruments)
local skills = {
Not_Set = 0,
Beginner = 1,
Intermediate = 2,
Expert = 3,
}
local skills_valstr = makeValString(skills)
local codecs = {
NONE = 0, -- none, no audio coding applied
CELT = 1, -- CELT
OPUS = 2, -- OPUS
OPUS64 = 3, -- OPUS64
}
local codecs_valstr = makeValString(codecs)
local flags = {
NO_SEQ = 0, -- no sequence numbers
WITH_SEQ = 1, -- with sequence numbers
}
local flags_valstr = makeValString(flags)
local opsys = {
Windows = 0,
MacOS = 1,
Linux = 2,
Android = 3,
iOS = 4,
Unix = 5,
}
local opsys_valstr = makeValString(opsys)
local status = {
SUCCESS = 0, -- Successfully registered
SERVER_FULL = 1, -- Failed to register (server list full)
TOO_OLD = 2, -- Failed to register (server version too old)
NOT_FULFIL = 3, -- Failed to register (registration requirements not fulfilled)
}
local status_valstr = makeValString(status)
local muting = {
Live = 0, -- Not muted
Muted = 1, -- Muted
}
local muting_valstr = makeValString(muting)
----------------------------------------
-- #define OPUS_NUM_BYTES_MONO_LOW_QUALITY 12
-- #define OPUS_NUM_BYTES_MONO_NORMAL_QUALITY 22
-- #define OPUS_NUM_BYTES_MONO_HIGH_QUALITY 36
-- #define OPUS_NUM_BYTES_MONO_LOW_QUALITY_DBLE_FRAMESIZE 25
-- #define OPUS_NUM_BYTES_MONO_NORMAL_QUALITY_DBLE_FRAMESIZE 45
-- #define OPUS_NUM_BYTES_MONO_HIGH_QUALITY_DBLE_FRAMESIZE 71
-- #define OPUS_NUM_BYTES_MONO_HIGHER_QUALITY_DBLE_FRAMESIZE 82
-- #define OPUS_NUM_BYTES_STEREO_LOW_QUALITY 24
-- #define OPUS_NUM_BYTES_STEREO_NORMAL_QUALITY 35
-- #define OPUS_NUM_BYTES_STEREO_HIGH_QUALITY 73
-- #define OPUS_NUM_BYTES_STEREO_LOW_QUALITY_DBLE_FRAMESIZE 47
-- #define OPUS_NUM_BYTES_STEREO_NORMAL_QUALITY_DBLE_FRAMESIZE 71
-- #define OPUS_NUM_BYTES_STEREO_HIGH_QUALITY_DBLE_FRAMESIZE 142
-- #define OPUS_NUM_BYTES_STEREO_HIGHER_QUALITY_DBLE_FRAMESIZE 165
local mono_valstr = {
[12] = "Low Quality",
[22] = "Normal Quality",
[36] = "High Quality",
[25] = "Low Quality Double Framesize",
[45] = "Normal Quality Double Framesize",
[71] = "High Quality Double Framesize",
[82] = "Higher Quality Double Framesize",
}
local stereo_valstr = {
[24] = "Low Quality",
[35] = "Normal Quality",
[73] = "High Quality",
[47] = "Low Quality Double Framesize",
[71] = "Normal Quality Double Framesize",
[142] = "High Quality Double Framesize",
[165] = "Higher Quality Double Framesize",
}
----------------------------------------
-- a table of all of our Protocol's fields
local fields =
{
tag = ProtoField.uint16("jamulus.tag", "Tag", base.DEC),
id = ProtoField.uint16("jamulus.id", "ID", base.DEC, opcodes_valstr),
splitid = ProtoField.uint16("jamulus.splitid", "ID", base.DEC, opcodes_valstr),
ackid = ProtoField.uint16("jamulus.ackid", "AckID", base.DEC, opcodes_valstr),
cnt = ProtoField.uint8("jamulus.cnt", "Cnt", base.DEC),
nparts = ProtoField.uint8("jamulus.nparts", "NParts", base.DEC),
splitcnt = ProtoField.uint8("jamulus.splitcnt", "SplitCnt", base.DEC),
chanid = ProtoField.uint8("jamulus.chanid", "Channel", base.DEC),
recstate = ProtoField.uint8("jamulus.recstate", "Recording State", base.DEC),
country = ProtoField.uint16("jamulus.country", "Country", base.DEC, countries_valstr),
instrument = ProtoField.uint32("jamulus.instrument", "Instrument", base.DEC, instruments_valstr),
skill = ProtoField.uint8("jamulus.skill", "Skill", base.DEC, skills_valstr),
gain = ProtoField.uint16("jamulus.gain", "Gain", base.DEC),
pan = ProtoField.uint16("jamulus.pan", "Pan", base.DEC),
mute = ProtoField.uint8("jamulus.mute", "Mute", base.DEC, muting_valstr),
jbsize = ProtoField.uint16("jamulus.jbsize", "JBsize", base.DEC),
len = ProtoField.uint16("jamulus.len", "Len", base.DEC),
bns = ProtoField.uint32("jamulus.bns", "Base Netw Size", base.DEC),
bsf = ProtoField.uint16("jamulus.bsf", "Block Size Factor", base.DEC),
nchan = ProtoField.uint8("jamulus.nchan", "Num Chans", base.DEC),
-- level = ProtoField.uint8("jamulus.level", "Level", base.DEC),
levels = ProtoField.bytes("jamulus.levels", "Levels", base.SPACE),
samrate = ProtoField.uint32("jamulus.samrate", "Sample Rate", base.DEC),
codec = ProtoField.uint16("jamulus.codec", "Codec", base.DEC, codecs_valstr),
cver = ProtoField.uint16("jamulus.flags", "Flags", base.DEC, flags_valstr),
carg = ProtoField.uint32("jamulus.carg", "Codec Arg", base.DEC),
data = ProtoField.bytes("jamulus.data", "Data"),
name = ProtoField.string("jamulus.name", "Name", base.UNICODE),
city = ProtoField.string("jamulus.city", "City", base.UNICODE),
chat = ProtoField.string("jamulus.chat", "Chat Text", base.UNICODE),
crc = ProtoField.uint16("jamulus.crc", "CRC", base.HEX),
port = ProtoField.uint16("jamulus.port", "Port", base.DEC),
ipaddr = ProtoField.ipv4("jamulus.ipaddr", "IP Address"),
ipaddrs = ProtoField.string("jamulus.ipaddrs", "IP Address", base.UNICODE),
licreq = ProtoField.uint8("jamulus.licreq", "Licence Required", base.DEC),
chanlvlopt = ProtoField.uint8("jamulus.chanlvlopt", "Chan Level Opt", base.DEC),
txtime = ProtoField.uint32("jamulus.txtime", "Transmit Time", base.DEC),
nclients = ProtoField.uint8("jamulus.nclients", "Num Clients", base.DEC),
maxclients = ProtoField.uint8("jamulus.maxclients", "Max Clients", base.DEC),
permanent = ProtoField.uint8("jamulus.permanent", "Permanent", base.DEC),
os = ProtoField.uint8("jamulus.os", "Operating System", base.DEC, opsys_valstr),
osver = ProtoField.string("jamulus.osver", "OS Version", base.UNICODE),
status = ProtoField.uint8("jamulus.status", "Status", base.DEC, status_valstr),
}
-- register the ProtoFields
jamulus.fields = fields
dprint2("jamulus ProtoFields registered")
function jamulus.dissector(buffer, pinfo, tree)
length = buffer:len()
if length == 0 then return end
local s = "s"
if length == 1 then s = "" end
pinfo.cols.protocol = jamulus.name
if buffer(0,2):le_uint() == 0 and length >= 7 then
datalen = buffer(5,2):le_uint()
if datalen == length - 9 then
local subtree = tree:add(jamulus, buffer(), "Jamulus Protocol Data", "(" .. length .. " byte" .. s .. ")")
local header = subtree:add(jamulus, buffer(0,7), "Header")
opcode = buffer(2,2):le_uint()
pinfo.cols.info = opcodes_valstr[opcode]
cntr = buffer(4,1):le_uint()
header:append_text(" (" .. opcodes_valstr[opcode] .. ", Cnt: " .. buffer(4,1):le_uint() .. ", Datalen: " .. datalen .. ")")
header:add_le(fields.tag, buffer(0,2))
header:add_le(fields.id, buffer(2,2))
header:add_le(fields.cnt, buffer(4,1))
header:add_le(fields.len, buffer(5,2))
disect_msg(pinfo, opcode, buffer(7,datalen), subtree)
subtree:add_le(fields.crc, buffer(7+datalen, 2))
return
end
end
local monster = buffer(0,1):le_uint()
local quality
if monster == 0 then
-- Mono audio
-- First try double frame
if (length % 2) == 0 and buffer(0,1):le_uint() == buffer(length/2,1):le_uint() then
-- possibly two Opus frames
local halflen = length/2
quality = mono_valstr[halflen]
if quality then
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Mono " .. quality .. " 2 frames", "(" .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Mono " .. quality .. " 2 frames"
return
end
quality = mono_valstr[halflen-1]
if quality then
local seq1 = buffer(halflen-1,1):le_uint()
local seq2 = buffer(length-1,1):le_uint()
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Mono " .. quality .. " 2 frames Seq", "(#" .. seq1 .. "-" .. seq2 .. ", " .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Mono " .. quality .. " 2 frames Seq #" .. seq1 .. "-" .. seq2
return
end
end
-- Now try single frame
quality = mono_valstr[length]
if quality then
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Mono " .. quality , "(" .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Mono " .. quality
return
end
quality = mono_valstr[length-1]
if quality then
local seq = buffer(length-1,1):le_uint()
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Mono " .. quality .. " Seq", "(#" .. seq .. ", " .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Mono " .. quality .. " Seq #" .. seq
return
end
elseif monster == 4 then
-- Stereo audio
-- First try double frame
if (length % 2) == 0 and buffer(0,1):le_uint() == buffer(length/2,1):le_uint() then
-- possibly two Opus frames
local halflen = length/2
quality = stereo_valstr[halflen]
if quality then
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Stereo " .. quality .. " 2 frames", "(" .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Stereo " .. quality .. " 2 frames"
return
end
quality = stereo_valstr[halflen-1]
if quality then
local seq1 = buffer(halflen-1,1):le_uint()
local seq2 = buffer(length-1,1):le_uint()
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Stereo " .. quality .. " 2 frames Seq", "(#" .. seq1 .. "-" .. seq2 .. ", " .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Stereo " .. quality .. " 2 frames Seq #" .. seq1 .. "-" .. seq2
return
end
end
-- Now try single frame
quality = stereo_valstr[length]
if quality then
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Stereo " .. quality , "(" .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Stereo " .. quality
return
end
quality = stereo_valstr[length-1]
if quality then
local seq = buffer(length-1,1):le_uint()
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Stereo " .. quality .. " Seq" , "(#" .. seq .. ", " .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Stereo " .. quality .. " Seq #" .. seq
return
end
end
-- Unknown audio type
local subtree = tree:add(jamulus, buffer(), "Jamulus Audio Unknown", "(" .. length .. " byte" .. s .. ")")
pinfo.cols.info = "Audio Unknown"
end
local function panValue(pan)
if pan < 16384 then return math.floor((16384-pan)*100/16384+0.5) .. "% left" end
if pan > 16384 then return math.floor((pan-16384)*100/16384+0.5) .. "% right" end
return "Centre"
end
local function gainValue(gain)
return math.floor(gain*100/32768+0.5) .. "%"
end
function disect_msg(pinfo, opcode, buf, subtree)
local s = "s"
if buf:len() == 1 then s = "" end
local msgdata = subtree:add(jamulus, buf, "Data", "(" .. buf:len() .. " byte" .. s .. ")")
local n
if opcode == opcodes.ILLEGAL then
msgdata:add(fields.data, buf)
elseif opcode == opcodes.ACKN then
local ackopcode = buf:le_uint()
msgdata:add_le(fields.ackid, buf)
pinfo.cols.info:append(" (" .. opcodes_valstr[ackopcode] .. ")")
elseif opcode == opcodes.JITT_BUF_SIZE then
local jitnum = buf:le_uint()
local jitstr = jitnum
if jitnum == 21 then
jitstr = "AUTO"
msgdata:add_le(fields.jbsize, buf):append_text(" (" .. jitstr .. ")")
else
msgdata:add_le(fields.jbsize, buf)
end
pinfo.cols.info:append(" (" .. jitstr .. ")")
elseif opcode == opcodes.REQ_JITT_BUF_SIZE then
-- no data
elseif opcode == opcodes.NET_BLSI_FACTOR then
-- Obsolete
elseif opcode == opcodes.CHANNEL_GAIN then
local gain = gainValue(buf(1,2):le_uint())
msgdata:add_le(fields.chanid, buf(0,1))
msgdata:add_le(fields.gain, buf(1,2)):append_text(" (" .. gain .. ")")
pinfo.cols.info:append(" ([" .. buf(0,1):le_uint() .. "] => " .. gain .. ")")
elseif opcode == opcodes.CONN_CLIENTS_LIST_NAME then
-- Obsolete
elseif opcode == opcodes.SERVER_FULL then
-- Obsolete
elseif opcode == opcodes.REQ_CONN_CLIENTS_LIST then
-- no data
elseif opcode == opcodes.CHANNEL_NAME then
-- Obsolete
elseif opcode == opcodes.CHAT_TEXT then
n = buf(0,2):le_uint()
if n > 0 then
msgdata:add(fields.chat, buf(2,n))
pinfo.cols.info:append(" (\"" .. buf(2,n):string():gsub("\n", "\\n") .. "\")")
end
elseif opcode == opcodes.PING_MS then
-- Obsolete
elseif opcode == opcodes.NETW_TRANSPORT_PROPS then
msgdata:add_le(fields.bns, buf(0,4))
msgdata:add_le(fields.bsf, buf(4,2))
msgdata:add_le(fields.nchan, buf(6,1))
msgdata:add_le(fields.samrate, buf(7,4))
msgdata:add_le(fields.codec, buf(11,2))
msgdata:add_le(fields.cver, buf(13,2))
msgdata:add_le(fields.carg, buf(15,4))
pinfo.cols.info:append(
" (BNS=" .. buf(0,4):le_uint()
.. ", BSF=" .. buf(4,2):le_uint()
.. ", Chans=" .. buf(6,1):le_uint()
.. ", SRate=" .. buf(7,4):le_uint()
.. ", Codec=" .. codecs_valstr[buf(11,2):le_uint()]
.. ", Ver=" .. buf(13,2):le_uint()
.. ", Arg=" .. buf(15,4):le_uint()
.. ")"
)
elseif opcode == opcodes.REQ_NETW_TRANSPORT_PROPS then
-- no data
elseif opcode == opcodes.DISCONNECTION then
-- Obsolete
elseif opcode == opcodes.REQ_CHANNEL_INFOS then
-- no data
elseif opcode == opcodes.CONN_CLIENTS_LIST then
local c = 0
local i = 0
while i < buf:len() do
local n1 = buf(i+12,2):le_uint()
local n2 = buf(i+14+n1,2):le_uint()
local clientlen = 16+n1+n2
local client = msgdata:add(jamulus, buf(i, clientlen), "Client " .. c)
client:add_le(fields.chanid, buf(i,1)); i=i+1
client:add_le(fields.country, buf(i,2)); i=i+2
client:add_le(fields.instrument, buf(i,4)); i=i+4
client:add_le(fields.skill, buf(i,1)); i=i+1
client:add_le(fields.ipaddr, buf(i,4)); i=i+4
n = buf(i,2):le_uint(); i=i+2
if n > 0 then client:add(fields.name, buf(i, n)); i=i+n end
n = buf(i,2):le_uint(); i=i+2
if n > 0 then client:add(fields.city, buf(i, n)); i=i+n end
c = c+1
end
local s = "s"
if c == 1 then s = "" end
pinfo.cols.info:append(" (" .. c .. " client" .. s .. ")")
elseif opcode == opcodes.CHANNEL_INFOS then
msgdata:add_le(fields.country, buf(0,2))
msgdata:add_le(fields.instrument, buf(2,4))
msgdata:add_le(fields.skill, buf(6,1))
pinfo.cols.info:append(" (" .. countries_valstr[buf(0,2):le_uint()] .. ", " .. instruments_valstr[buf(2,4):le_uint()] .. ", " .. skills_valstr[buf(6,1):le_uint()])
local i = 7
n = buf(i,2):le_uint(); i=i+2
if n > 0 then
msgdata:add(fields.name, buf(i, n))
pinfo.cols.info:append(", " .. buf(i, n):string())
i=i+n
end
n = buf(i,2):le_uint(); i=i+2
if n > 0 then
msgdata:add(fields.city, buf(i, n))
pinfo.cols.info:append(", " .. buf(i, n):string())
i=i+n
end
pinfo.cols.info:append(")")
elseif opcode == opcodes.OPUS_SUPPORTED then
-- no data
elseif opcode == opcodes.LICENCE_REQUIRED then
msgdata:add_le(fields.licreq, buf)
pinfo.cols.info:append(" (" .. buf:le_uint() .. ")")
elseif opcode == opcodes.REQ_CHANNEL_LEVEL_LIST then
msgdata:add_le(fields.chanlvlopt, buf)
pinfo.cols.info:append(" (" .. buf:le_uint() .. ")")
elseif opcode == opcodes.VERSION_AND_OS then
msgdata:add_le(fields.os, buf(0,1))
pinfo.cols.info:append(" (" .. opsys_valstr[buf(0,1):le_uint()])
local i = 1
n = buf(i,2):le_uint(); i=i+2
if n > 0 then
msgdata:add(fields.osver, buf(i, n))
pinfo.cols.info:append(", " .. buf(i, n):string())
i=i+n
end
pinfo.cols.info:append(")")
elseif opcode == opcodes.CHANNEL_PAN then
local pan = panValue(buf(1,2):le_uint())
msgdata:add_le(fields.chanid, buf(0,1))
msgdata:add_le(fields.pan, buf(1,2)):append_text(" (" .. pan .. ")")
pinfo.cols.info:append(" ([" .. buf(0,1):le_uint() .. "] => " .. pan .. ")")
elseif opcode == opcodes.MUTE_STATE_CHANGED then
msgdata:add_le(fields.chanid, buf(0,1))
msgdata:add_le(fields.mute, buf(1,1))
pinfo.cols.info:append(" ([" .. buf(0,1):le_uint() .. "] => " .. muting_valstr[buf(1,1):le_uint()] .. ")")
elseif opcode == opcodes.CLIENT_ID then
msgdata:add_le(fields.chanid, buf(0,1))
pinfo.cols.info:append(" (" .. buf(0,1):le_uint() .. ")")
elseif opcode == opcodes.RECORDER_STATE then
msgdata:add_le(fields.recstate, buf(0,1))
pinfo.cols.info:append(" (" .. buf(0,1):le_uint() .. ")")
elseif opcode == opcodes.REQ_SPLIT_MESS_SUPPORT then
-- no data
elseif opcode == opcodes.SPLIT_MESS_SUPPORTED then
-- no data
elseif opcode == opcodes.CLM_PING_MS then
msgdata:add_le(fields.txtime, buf(0,4))
pinfo.cols.info:append(" (" .. buf(0,4):le_uint() .. ")")
elseif opcode == opcodes.CLM_PING_MS_WITHNUMCLIENTS then
msgdata:add_le(fields.txtime, buf(0,4))
msgdata:add_le(fields.nclients, buf(4,1))
pinfo.cols.info:append(" (" .. buf(0,4):le_uint() .. ", " .. buf(4,1):le_uint() .. ")")
elseif opcode == opcodes.CLM_SERVER_FULL then
-- no data
elseif opcode == opcodes.CLM_REGISTER_SERVER then
msgdata:add_le(fields.port, buf(0,2))
msgdata:add_le(fields.country, buf(2,2))
msgdata:add_le(fields.maxclients, buf(4,1))
msgdata:add_le(fields.permanent, buf(5,1))
pinfo.cols.info:append(" (port=" .. buf(0,2):le_uint() .. ", " .. countries_valstr[buf(2,2):le_uint()] .. ", maxclients=" .. buf(4,1):le_uint() .. ", perm=" .. buf(5,1):le_uint())
local i = 6
n = buf(i,2):le_uint(); i=i+2
if n > 0 then
msgdata:add(fields.name, buf(i, n))
pinfo.cols.info:append(", name=\"" .. buf(i,n):string() .. "\"")
i=i+n
end
n = buf(i,2):le_uint(); i=i+2
if n > 0 then
msgdata:add(fields.ipaddrs, buf(i, n))
pinfo.cols.info:append(", ipaddrs=\"" .. buf(i,n):string() .. "\"")
i=i+n
end
n = buf(i,2):le_uint(); i=i+2
if n > 0 then
msgdata:add(fields.city, buf(i, n))
pinfo.cols.info:append(", city=\"" .. buf(i,n):string() .. "\"")
i=i+n
end
pinfo.cols.info:append(")")
elseif opcode == opcodes.CLM_UNREGISTER_SERVER then
-- no data
elseif opcode == opcodes.CLM_SERVER_LIST then
local c = 0
local i = 0
while i < buf:len() do
local n1 = buf(i+10,2):le_uint()
local n2 = buf(i+12+n1,2):le_uint()
local n3 = buf(i+14+n1+n2,2):le_uint()
local serverlen = 16+n1+n2+n3
local server = msgdata:add(jamulus, buf(i,serverlen), "Server " .. c)
server:add_le(fields.ipaddr, buf(i,4)); i=i+4
server:add_le(fields.port, buf(i,2)); i=i+2
server:add_le(fields.country, buf(i,2)); i=i+2
server:add_le(fields.maxclients, buf(i,1)); i=i+1
server:add_le(fields.permanent, buf(i,1)); i=i+1
n = buf(i,2):le_uint(); i=i+2
if n > 0 then server:add(fields.name, buf(i, n)); i=i+n end
n = buf(i,2):le_uint(); i=i+2
if n > 0 then server:add(fields.ipaddrs, buf(i, n)); i=i+n end
n = buf(i,2):le_uint(); i=i+2
if n > 0 then server:add(fields.city, buf(i, n)); i=i+n end
c = c+1
end
local s = "s"
if c == 1 then s = "" end
pinfo.cols.info:append(" (" .. c .. " server" .. s .. ")")
elseif opcode == opcodes.CLM_RED_SERVER_LIST then
local c = 0
local i = 0
while i < buf:len() do
local n1 = buf(i+6,1):le_uint()
local serverlen = 7+n1
local server = msgdata:add(jamulus, buf(i,serverlen), "Server " .. c)
server:add_le(fields.ipaddr, buf(i,4)); i=i+4
server:add_le(fields.port, buf(i,2)); i=i+2
n = buf(i,1):le_uint(); i=i+1
if n > 0 then server:add(fields.name, buf(i, n)); i=i+n end
c = c+1
end
local s = "s"
if c == 1 then s = "" end
pinfo.cols.info:append(" (" .. c .. " server" .. s .. ")")
elseif opcode == opcodes.CLM_REQ_SERVER_LIST then
-- no data
elseif opcode == opcodes.CLM_SEND_EMPTY_MESSAGE then
msgdata:add_le(fields.ipaddr, buf(0,4))
msgdata:add_le(fields.port, buf(4,2))
pinfo.cols.info:append(" (" .. tostring(buf(0,4):le_ipv4()) .. ":" .. buf(4,2):le_uint() .. ")")
elseif opcode == opcodes.CLM_EMPTY_MESSAGE then
-- no data
elseif opcode == opcodes.CLM_DISCONNECTION then
-- no data
elseif opcode == opcodes.CLM_VERSION_AND_OS then
msgdata:add_le(fields.os, buf(0,1))
pinfo.cols.info:append(" (" .. opsys_valstr[buf(0,1):le_uint()])
local i = 1
n = buf(i,2):le_uint(); i=i+2
if n > 0 then
msgdata:add(fields.osver, buf(i, n))
pinfo.cols.info:append(", " .. buf(i, n):string())
i=i+n
end
pinfo.cols.info:append(")")
elseif opcode == opcodes.CLM_REQ_VERSION_AND_OS then
-- no data
elseif opcode == opcodes.CLM_CONN_CLIENTS_LIST then
local c = 0
local i = 0
while i < buf:len() do
local n1 = buf(i+12,2):le_uint()
local n2 = buf(i+14+n1,2):le_uint()
local clientlen = 16+n1+n2
local client = msgdata:add(jamulus, buf(i, clientlen), "Client " .. c); c=c+1
client:add_le(fields.chanid, buf(i,1)); i=i+1
client:add_le(fields.country, buf(i,2)); i=i+2
client:add_le(fields.instrument, buf(i,4)); i=i+4
client:add_le(fields.skill, buf(i,1)); i=i+1
client:add_le(fields.ipaddr, buf(i,4)); i=i+4
n = buf(i,2):le_uint()
client:add_le(fields.len, buf(i,2)); i=i+2
if n > 0 then client:add(fields.name, buf(i, n)); i=i+n end
n = buf(i,2):le_uint()
client:add_le(fields.len, buf(i,2)); i=i+2
if n > 0 then client:add(fields.city, buf(i, n)); i=i+n end
end
local s = "s"
if c == 1 then s = "" end
pinfo.cols.info:append(" (" .. c .. " client" .. s .. ")")
elseif opcode == opcodes.CLM_REQ_CONN_CLIENTS_LIST then
-- no data
elseif opcode == opcodes.CLM_CHANNEL_LEVEL_LIST then
local levels = msgdata:add(fields.levels, buf)
local i = 0
local desc = ""
while i < buf:len() do
local l1 = buf(i,1):le_uint()
local l2 = bit.rshift(l1, 4)
l1 = bit.band(l1, 15);
if desc == "" then
desc = " ("
else
desc = desc .. ","
end