-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridstream.lua
694 lines (533 loc) · 22.6 KB
/
gridstream.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
-- ============================================================================
--
-- DRAFT WireShark Dissector for Landis+Gyr Gridstream protocol
--
-- Reverse engineered from publicly shared dumps of RF traffic.
-- https://wiki.recessim.com/view/Landis%2BGyr_GridStream_Protocol#Data_captures
--
-- Incomplete, and likely wrong in many places.
--
-- ============================================================================
local gs_proto = Proto("gridstream", "GRIDSTREAM Protocol")
local gs_proto_info = Proto("gridstream.mesg", "Message")
-- Removed, there aren't enough of these packets to test this.
-- local gs_proto_rpu = Proto("gridstream.rpu", "Report Power Usage")
-- ----------------------------------------------------------------------------
-- HEADER ProtocolFields
-- ----------------------------------------------------------------------------
local gs_header_flags = { -- These look more like flags
-- [0x00] = "Report",
-- [0x01] = "Report",
-- [0x02] = "Report",
-- [0x03] = "Report",
-- [0x2a] = "Report up-time and unknown"
}
-- @BUG: These might only apply to packages of type 2a!
local gs_type_classes = {
[0x55] = "broadcast",
[0xD5] = "forward"
}
local pf_framestart = ProtoField.new("start", "gridstream.start", ftypes.UINT16, nil, base.HEX)
local pf_flags = ProtoField.new("flags", "gridstream.flags", ftypes.UINT8, gs_header_flags, base.HEX)
local pf_type = ProtoField.new("type", "gridstream.type", ftypes.UINT8, gs_type_classes, base.HEX)
gs_proto.fields = {
pf_framestart,
pf_flags,
pf_type
}
-- ----------------------------------------------------------------------------
-- MESSAGE ProtocolFields
-- ----------------------------------------------------------------------------
local gs_subtype_classes = {
[0x30] = "Report uptime and unknown",
[0x51] = "Epoch and Uptime"
}
local pf_info_length = ProtoField.new("len", "gridstream.mesg.len", ftypes.UINT16, nil, base.DEC)
local pf_subtype = ProtoField.new("subtype", "gridstream.mesg.type", ftypes.UINT8, gs_subtype_classes, base.HEX)
local pf_dest_device_id1 = ProtoField.new("dest device ID", "gridstream.mesg.dest_device_id", ftypes.BYTES, nil, base.COLON)
local pf_src_device_id1 = ProtoField.new("src device ID", "gridstream.mesg.src_device_id", ftypes.BYTES, nil, base.COLON)
local pf_pkt_count = ProtoField.new("packet count", "gridstream.mesg.count", ftypes.UINT8, nil, base.HEX)
local pf_epoc_sec = ProtoField.new("date & time (epoch sec)", "gridstream.mesg.etime", ftypes.UINT32, nil, base.DEC)
local pf_epoc_ts = ProtoField.new("date & time (parsed)", "gridstream.mesg.timestamp", ftypes.ABSOLUTE_TIME, nil, base.UTC)
local pf_uptime = ProtoField.new("uptime (0.1s)", "gridstream.mesg.uptime", ftypes.UINT32, nil, base.DEC)
local pf_uptime_str = ProtoField.new("uptime (hh:mm:ss)", "gridstream.mesg.uptime_str", ftypes.STRING)
local pf_payload_raw = ProtoField.new("payload raw", "gridstream.mesg.payload", ftypes.BYTES, nil, base.SPACE)
local pf_payload_len = ProtoField.new("payload len", "gridstream.mesg.payload_len", ftypes.UINT16, nil, base.DEC)
local pf_timer = ProtoField.new("timer (msec)", "gridstream.mesg.timer", ftypes.UINT16, nil, base.DEC)
local pf_footerval = ProtoField.new("unknown", "gridstream.mesg.footer", ftypes.UINT16, nil, base.DEC)
local pf_checksum = ProtoField.new("checksum", "gridstream.mesg.checksum", ftypes.UINT16, nil, base.HEX)
local pf_unk1 = ProtoField.new("flags?", "gridstream.mesg.unk1", ftypes.BYTES, nil, base.SPACE)
local pf_unk2 = ProtoField.new("unknown", "gridstream.mesg.unk2", ftypes.BYTES, nil, base.SPACE)
local pf_unk3 = ProtoField.new("unknown", "gridstream.mesg.unk3", ftypes.BYTES, nil, base.SPACE)
local pf_unk4 = ProtoField.new("unknown", "gridstream.mesg.unk4", ftypes.BYTES, nil, base.SPACE)
local pf_unk5 = ProtoField.new("unknown", "gridstream.mesg.unk5", ftypes.BYTES, nil, base.SPACE)
local pf_unk6 = ProtoField.new("unknown", "gridstream.mesg.unk6", ftypes.BYTES, nil, base.SPACE)
local pf_unk7 = ProtoField.new("unknown", "gridstream.mesg.unk7", ftypes.BYTES, nil, base.SPACE)
-- local pf_dest_wan_mac = ProtoField.new("dest device wan mac", "gridstream.mesg.dest_device_wan_mac", ftypes.BYTES, nil, base.COLON)
local pf_dest_wan_mac = ProtoField.new("dest device wan mac", "gridstream.mesg.dest_device_wan_mac", ftypes.ETHER)
local pf_dest_device_id2 = ProtoField.new("dest device ID2", "gridstream.mesg.dest_device_id2", ftypes.BYTES, nil, base.COLON)
-- local pf_src_wan_mac = ProtoField.new("src device wan mac", "gridstream.mesg.src_device_wan_mac", ftypes.BYTES, nil, base.COLON)
local pf_src_wan_mac = ProtoField.new("src device wan mac", "gridstream.mesg.src_device_wan_mac", ftypes.ETHER)
local pf_src_device_id2 = ProtoField.new("src device ID2", "gridstream.mesg.src_device_id2", ftypes.BYTES, nil, base.COLON)
local pf_subflag = ProtoField.new("subtype flags?", "gridstream.mesg.subtype_flags", ftypes.BYTES, nil, base.SPACE)
gs_proto_info.fields ={
pf_info_length,
pf_subtype,
pf_dest_device_id1,
pf_src_device_id1,
pf_pkt_count,
pf_epoc_sec,
pf_epoc_ts,
pf_uptime,
pf_uptime_str,
pf_payload_len,
pf_payload_raw,
pf_timer,
pf_footerval,
pf_checksum,
pf_unk1,
pf_unk2,
pf_unk3,
pf_unk4,
pf_unk5,
pf_unk6,
pf_unk7,
pf_subflag,
pf_src_wan_mac,
pf_src_device_id2,
pf_dest_wan_mac,
pf_dest_device_id2
}
-- ==================================================================================
--
-- UTILITIES
--
-- ==================================================================================
-- ----------------------------------------------------------------------------
-- Utility function - puts the rest of the buffer into raw payload
--
-- ----------------------------------------------------------------------------
local function util_remainder_as_payload(buffer,subtree,start)
local cursor = start
local payloadLen = buffer:len() - cursor
if (payloadLen) < 0 then return end
subtree:add(pf_payload_len, payloadLen):set_generated()
subtree:add(pf_payload_raw, buffer(cursor,payloadLen))
end
-- ----------------------------------------------------------------------------
-- helper to show unknowns in multiple formats
-- ----------------------------------------------------------------------------
local _padmap =
{
[1] = " ",
[2] = " ",
[3] = "",
[4] = ""
}
local function util_add_unknown(field,buffer,subtree,start,len,suffix)
local u16str = ""
local i16str = ""
if len <= 2 then
u16str = string.format("%6d as u16",buffer(start,len):uint())
i16str = string.format("%6d as i16",buffer(start,len):int())
-- too small for float
end
local f3264str = ""
if len == 4 then
-- too big for decimal
local fval=buffer(start,len):float()
f3264str = string.format("%f as f32",fval)
elseif len==8 then
local fval=buffer(start,len):float()
f3264str = string.format("%f as f64",fval)
end
local padstr = _padmap[len]
if padstr == nil then
padstr=""
end
local str = padstr .. " // " .. u16str .. ", " .. i16str .. ", " .. f3264str
if suffix ~= nil then
str = str .. suffix
end
subtree:add(field, buffer(start,len)):append_text(str)
return subtree
end
-- ----------------------------------------------------------------------------
-- Convert an elapsed time, counting whole teths of seconds, to a readible string
--
-- ----------------------------------------------------------------------------
local function util_elapsedtime_tostring(uptimeInDeciSeconds)
-- Parse the uptime
local part_tenths = uptimeInDeciSeconds % 10 -- tenths
local rest = uptimeInDeciSeconds / 10 -- whole seconds
local part_sec = rest % 60 -- residual seconds
rest = rest / 60 -- whole minutes
local part_mins = rest % 60 -- residual minutes
local part_hrs = rest / 60 -- whole hours
local timestr = string.format("%d:%.2d:%.2d.%d",part_hrs,part_mins,part_sec,part_tenths)
return timestr
end
-- ==================================================================================
--
-- DISSECTORS
--
-- ==================================================================================
-- ----------------------------------------------------------------------------
-- Dissect a payload that includes CRC suffix
--
-- ----------------------------------------------------------------------------
local function gs_payload_with_crc_dissector(buffer,subtree,start)
-- Last 6 octets are the footer
local payloadFooter = 6
local payloadLen = buffer:len() - start - payloadFooter
if (payloadLen) < 0 then return end
-- payload body
local payloadtree = subtree:add(pf_payload_len, payloadLen):set_generated()
payloadtree:add(pf_payload_raw, buffer(start,payloadLen))
-- FOOTER FIELDS
-- Timer?
-- max 16.798sec for Oncor dataset...
local timerval = buffer(start+payloadLen,2):uint()
payloadtree:add(pf_timer, buffer(start+payloadLen,2)):append_text(string.format(" => %2.3f sec",timerval/1000))
-- Fixed value
util_add_unknown(pf_footerval, buffer, payloadtree, start+payloadLen+2,2)
-- CRC
payloadtree:add(pf_checksum, buffer(start+payloadLen+4,2))
return start,payloadtree
end
-- ----------------------------------------------------------------------------
-- Dissects rest of packets of subtype 0x29, 0x22, 0x21
-- Assumes these end with the CRC footer.
--
-- STUB
-- ----------------------------------------------------------------------------
local function gs_subtype_29_22_21_dissector(buffer, pinfo, subtree, start)
local cursor = start
subtree:add(pf_dest_device_id1, buffer(cursor,4))
cursor=cursor+4
subtree:add(pf_src_device_id1, buffer(cursor,4))
cursor=cursor+4
subtree:add(pf_pkt_count, buffer(cursor,1))
cursor = cursor + 1
util_add_unknown(pf_unk3, buffer, subtree, cursor,1)
cursor = cursor + 1
gs_payload_with_crc_dissector(buffer,subtree,cursor)
end
-- ----------------------------------------------------------------------------
-- Dissects packets of the C0 subtype
--
-- These appear to all be broadcasts, sent in repeating blocks.
-- The final bytes vary if any part of the payload varies, so maybe it's a CRC?
--
-- Observations
-- payload [len-4] == 0x7e in every packet in the Oncor dataset.
--
-- ----------------------------------------------------------------------------
local function gs_subtype_c0_dissector(buffer, pinfo, subtree, start)
local cursor = start
-- start the payload dump here
local payloadstart = cursor
subtree:add(pf_dest_device_id1, buffer(cursor,4))
cursor=cursor+4
subtree:add(pf_src_device_id1, buffer(cursor,4))
cursor = cursor+4
subtree:add(pf_pkt_count, buffer(cursor,1))
cursor = cursor+1
-- unknown, looks like a source device ID?
subtree:add(pf_src_device_id2, buffer(cursor,4))
cursor = cursor+4
-- always 32bit FF:FF:FF:FF
subtree:add(pf_dest_device_id2, buffer(cursor,4))
cursor = cursor+4
-- maybe a flag bit? always 0 / 1
subtree:add(pf_subflag, buffer(cursor,1))
cursor = cursor+1
-- unk byte
subtree:add(pf_unk3, buffer(cursor,1))
cursor = cursor+1
-- This is a guess. Most times, it's 48-bit FF:FF:FF.... like a broadcast
-- but sometimes, it starts with 00:08:FF... which may be a different packet type
subtree:add(pf_dest_wan_mac, buffer(cursor,6))
pinfo.dst = Address.ether(buffer(cursor,6):raw())
cursor = cursor+6
util_add_unknown(pf_unk4, buffer, subtree, cursor, 4)
cursor = cursor + 4
-- Is this a counter/time difference?
util_add_unknown(pf_unk5, buffer, subtree, cursor, 2, " ## time difference?")
cursor = cursor + 2
-- Flag/indicator? Toggles between 2 values.
util_add_unknown(pf_unk6, buffer, subtree, cursor, 1, " ## flag?")
cursor = cursor + 1
-- Unknown,
-- for a single device, it is always increasing
-- appears to count up ONLY when the whole set changes
-- local unk_count_str = string.format(" ## %d increasing)",buffer(cursor,4):uint())
-- subtree:add(pf_unk7, buffer(cursor,4)):append_text(unk_count_str)
util_add_unknown(pf_unk7, buffer, subtree, cursor, 4, " ## increasing?")
cursor = cursor + 4
payloadstart = cursor
-- rest as raw payload body
-- most then start with 0xc1 0x80 0x00 0x00
-- util_remainder_as_payload(buffer,subtree,cursor)
gs_payload_with_crc_dissector(buffer,subtree,payloadstart)
end
-- ----------------------------------------------------------------------------
-- DISSECT body of Epoch Uptime packages
-- ----------------------------------------------------------------------------
local function gs_subtype_epoch_uptime_dissector(buffer, pinfo, subtree, start)
local length = buffer:len()
if (length-start) <= 0 then return end
subtree:add(pf_dest_device_id1, buffer(start, 4))
subtree:add(pf_src_device_id1, buffer(start+4, 4))
subtree:add(pf_pkt_count, buffer(start+8, 1))
-- As second
subtree:add(pf_epoc_sec, buffer(start+9, 4))
-- As timestamp
subtree:add(pf_epoc_ts, buffer(start+9,4))
subtree:add(pf_unk2, buffer(start+13,4))
-- As uptime
local raw_uptime = buffer(start+17,4):uint()
subtree:add(pf_uptime, raw_uptime)
local uptime_str = util_elapsedtime_tostring(raw_uptime)
subtree:add(pf_uptime_str, uptime_str):set_generated()
subtree:add(pf_unk3, buffer(start+21,2))
subtree:add(pf_unk5, buffer(start+23,2))
subtree:add(pf_src_wan_mac, buffer(start+25,6))
pinfo.src = Address.ether(buffer(start+25,6):raw())
subtree:add(pf_src_device_id2, buffer(start+31,4))
gs_payload_with_crc_dissector(buffer,subtree,start+35) -- BUG, was raw 35
end
-- ----------------------------------------------------------------------------
-- DISSECTOR - Info broadcasts
-- ----------------------------------------------------------------------------
local function gs_subtype_30_dissector(buffer, pinfo, subtree, start)
local length = buffer:len()
if (length-start) <= 0 then return end
local cursor = start
-- Looks like a MAC address, so set in packet for WireShark Conversation analysis
pinfo.dst = Address.ether(buffer(cursor,6):raw())
subtree:add(pf_dest_wan_mac, buffer(cursor,6))
cursor = cursor + 6
-- Looks like a MAC address, so set in packet for WireShark Conversation analysis
pinfo.src = Address.ether(buffer(cursor,6):raw())
subtree:add(pf_src_wan_mac, buffer(cursor,6))
cursor = cursor + 6
-- Appears to be sequence number
subtree:add(pf_pkt_count, buffer(cursor,1))
cursor = cursor + 1
-- For the 0x30 type, For a specific source device,
-- this counts up continuously across the ONCOR sample set.
local raw_uptime = buffer(cursor,4):uint()
subtree:add(pf_uptime, buffer(cursor,4))
cursor = cursor + 4
-- reformat the time as a string
local uptime_str = util_elapsedtime_tostring(raw_uptime)
subtree:add(pf_uptime_str, uptime_str):set_generated()
-- unknown
util_add_unknown(pf_unk3, buffer, subtree, cursor, 2)
cursor = cursor + 2
-- maybe a device ID?
subtree:add(pf_src_device_id2, buffer(cursor,4))
cursor = cursor + 4
-- rest is unknown, dump into payload
-- 24 May - Appears to have same time/unk/crc footer
gs_payload_with_crc_dissector(buffer,subtree,cursor)
-- util_remainder_as_payload(buffer,subtree,cursor)
end
-- ----------------------------------------------------------------------------
-- MAP OF SUB-DISSECTORS
-- ----------------------------------------------------------------------------
local gs_subtype_dissector_map = {
[0x21] = gs_subtype_29_22_21_dissector,
[0x22] = gs_subtype_29_22_21_dissector,
[0x29] = gs_subtype_29_22_21_dissector,
[0x30] = gs_subtype_30_dissector,
[0x51] = gs_subtype_epoch_uptime_dissector,
[0x55] = gs_subtype_epoch_uptime_dissector,
[0xC0] = gs_subtype_c0_dissector
}
-- ----------------------------------------------------------------------------
-- DISSECTOR - General Info packets
--
-- 24May - "Broadcast" and "Forward" types are really the same top structure,
-- merging dissectors.
-- ----------------------------------------------------------------------------
local function gs_type_general_dissector(buffer, pinfo, tree, start)
local length = buffer:len()
if (length-start) <= 0 then return end
pinfo.cols.protocol = "gridstream.mesg"
local subtree = tree:add(gs_proto_info,buffer)
local cursor = start
-- Unknown, maybe flags
subtree:add(pf_unk1, buffer(cursor,1))
cursor = cursor+1
-- length
subtree:add(pf_info_length, buffer(cursor,1))
cursor = cursor + 1
-- maybe a subsubtype?
local subtype_val = buffer(cursor,1):uint()
local subsubtree = subtree:add(pf_subtype, buffer(cursor,1))
cursor = cursor + 1
local subtype_dissector = gs_subtype_dissector_map[subtype_val]
-- exit if no match
if subtype_dissector ~= nil then
subtype_dissector(buffer, pinfo, subsubtree, start+3)
end
end
-- ----------------------------------------------------------------------------
-- Dissector for device header d2
-- ----------------------------------------------------------------------------
local function gs_type_d2_dissector(buffer, pinfo, tree, start)
local length = buffer:len()
local cursor = start
if (length-cursor) <= 0 then return end
pinfo.cols.protocol = "gridstream.mesg"
local subtree = tree:add(gs_proto_info,buffer)
subtree:add(pf_info_length, buffer(cursor,1))
cursor = cursor+1
local payloadStart = cursor
-- Guesses to help decode this
util_add_unknown(pf_unk1, buffer, subtree, cursor, 1)
cursor = cursor+1
util_add_unknown(pf_unk2, buffer, subtree, cursor, 1, " ttl?")
cursor = cursor+1
util_add_unknown(pf_unk3, buffer, subtree, cursor, 1)
cursor = cursor+1
util_add_unknown(pf_unk4, buffer, subtree, cursor, 2)
cursor = cursor+2
if (length-cursor) < 2 then
return
end
util_add_unknown(pf_unk5, buffer, subtree, cursor, 2)
cursor = cursor+2
-- Rest as raw payload
util_remainder_as_payload(buffer,subtree,payloadStart)
end
-- ----------------------------------------------------------------------------
-- Dissector for type 0x81 or 0x85
--
-- These only appear in the CRC:BAD packets, and some of the fields are way off
-- e.g. uptime counts that are 10x - 100x previous values, and out of sequence
--
-- ----------------------------------------------------------------------------
local function gs_type_8185_dissector(buffer, pinfo, tree, start)
local length = buffer:len()
local cursor = start
if (length-cursor) <= 0 then return end
pinfo.cols.protocol = "gridstream.mesg"
local subtree = tree:add(gs_proto_info,buffer)
subtree:add(pf_unk1, buffer(cursor,1))
cursor = cursor+1
subtree:add(pf_dest_wan_mac, buffer(cursor,6))
cursor = cursor+6
subtree:add(pf_dest_device_id1, buffer(cursor,4))
cursor = cursor+4
subtree:add(pf_src_wan_mac, buffer(cursor,6))
cursor = cursor+6
subtree:add(pf_src_device_id1, buffer(cursor,4))
cursor = cursor+4
end
--
-- Setting it to
-- https://seclists.org/wireshark/2021/Aug/53
--
-- ----------------------------------------------------------------------------
--
-- GRIDSTREAM DISSECTOR - STARTS from the FRAME TYPE
--
-- ----------------------------------------------------------------------------
local gs_type_to_dissector_map = {
[0xD2] = gs_type_d2_dissector,
-- [0xD5] = gs_type_forward_dissector,
[0xD5] = gs_type_general_dissector, -- common?
[0x55] = gs_type_general_dissector,
[0x81] = gs_type_8185_dissector,
[0x85] = gs_type_8185_dissector,
-- other types in the Austin file - do these work too?
[0x15] = gs_type_general_dissector,
[0x45] = gs_type_general_dissector,
[0x51] = gs_type_general_dissector,
[0x54] = gs_type_general_dissector,
[0x5D] = gs_type_general_dissector,
[0x75] = gs_type_general_dissector,
[0x95] = gs_type_general_dissector,
[0xC5] = gs_type_general_dissector,
[0xd7] = gs_type_general_dissector,
[0xdf] = gs_type_general_dissector,
[0xf5] = gs_type_general_dissector
}
-- ----------------------------------------------------------------------------
-- Dissector
--
-- Retrieves the header fields. Based upon the type field, looks up the next
-- dissector call for that message variant.
--
-- ----------------------------------------------------------------------------
function gs_proto.dissector(buffer,pinfo,tree)
local length = buffer:len()
if length == 0 then return end
pinfo.cols.protocol = gs_proto.name
local subtree = tree:add(gs_proto,buffer)
subtree:add(pf_framestart, buffer(0,2)) -- 0x80FF or 0x00FF
subtree:add(pf_flags, buffer(2,1))
subtree:add(pf_type, buffer(3,1))
-- Lookup the dissector for the subtype
local type_field_val = buffer(3,1):uint()
local type_specific_dissector = gs_type_to_dissector_map[type_field_val]
-- exit if no match
if type_specific_dissector == nil then return end
type_specific_dissector(buffer, pinfo, subtree, 4)
end
-- ----------------------------------------------------------------------------
-- de facto "main"
--
-- Since the protocol is unknown to wireshark, register as type USER0 (147)
-- Type USER0 must also be set in pcap files to match
-- ----------------------------------------------------------------------------
local udlt = DissectorTable.get("wtap_encap")
udlt:add(wtap.USER0,gs_proto)
-- -- ================================================================================================
-- -- This program will register a menu that will open a window with a count of occurrences
-- -- of every address in the capture
-- --
-- -- https://www.wireshark.org/docs/wsdg_html_chunked/wslua_tap_example.html
-- --
-- local function menuable_tap()
-- -- Declare the window we will use
-- local tw = TextWindow.new("Address Counter")
-- -- This will contain a hash of counters of appearances of a certain address
-- local ips = {}
-- -- this is our tap
-- local tap = Listener.new();
-- local function remove()
-- -- this way we remove the listener that otherwise will remain running indefinitely
-- tap:remove();
-- end
-- -- we tell the window to call the remove() function when closed
-- tw:set_atclose(remove)
-- -- this function will be called once for each packet
-- function tap.packet(pinfo,tvb)
-- local src = ips[tostring(pinfo.src)] or 0
-- local dst = ips[tostring(pinfo.dst)] or 0
-- ips[tostring(pinfo.src)] = src + 1
-- ips[tostring(pinfo.dst)] = dst + 1
-- end
-- -- this function will be called once every few seconds to update our window
-- function tap.draw(t)
-- tw:clear()
-- for ip,num in pairs(ips) do
-- tw:append(ip .. "\t" .. num .. "\n");
-- end
-- end
-- -- this function will be called whenever a reset is needed
-- -- e.g. when reloading the capture file
-- function tap.reset()
-- tw:clear()
-- ips = {}
-- end
-- -- Ensure that all existing packets are processed.
-- retap_packets()
-- end
-- -- using this function we register our function
-- -- to be called when the user selects the Tools->Test->Packets menu
-- register_menu("Test/Packets", menuable_tap, MENU_TOOLS_UNSORTED)