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
|
local p = Proto("melon", "MelonDS Ni-Fi header")
p.fields.magic = ProtoField.uint32("melon.magic", "Magic", base.HEX)
p.fields.src = ProtoField.int32("melon.src", "Instance ID", base.DEC)
p.fields.type = ProtoField.new("Type", "melon.type", ftypes.UINT32)
p.fields.type_enum = ProtoField.uint16("melon.type.enum", "Numeric message type enum", base.DEC, {
[0] = "Regular",
[1] = "CMD",
[2] = "Reply",
[3] = "ACK",
})
p.fields.type_aid = ProtoField.uint16("melon.type.aid", "Message type \"aid\" value")
p.fields.length = ProtoField.uint32("melon.len", "Remaining message length", base.DEC)
p.fields.timestamp = ProtoField.uint64("melon.timestamp", "Timestamp", base.DEC)
local p_type_enum_field = Field.new("melon.type.enum")
local txhdr_dissector = Dissector.get("txhdr")
local rxhdr_dissector = Dissector.get("rxhdr")
function p.dissector(buffer, pinfo, tree)
local header_size = 0x18
-- check buffer size
if buffer:len() < header_size then return 0 end
-- check magic ("NIFI")
if buffer(0x00, 4):uint() ~= 0x4e494649 then return 0 end
local subtree = tree:add(p, buffer(0, header_size), string.format("%s: %d bytes", p.description, header_size))
subtree:add(p.fields.magic, buffer(0x00, 4))
local instance = buffer(0x04, 4):le_uint()
subtree:add_le(p.fields.src, buffer(0x04, 4))
local type_tree = subtree:add_le(p.fields.type, buffer(0x08, 4))
type_tree:add_le(p.fields.type_enum, buffer(0x08, 2))
type_tree:add_le(p.fields.type_aid, buffer(0x0a, 2))
subtree:add_le(p.fields.length, buffer(0x0c, 4))
subtree:add_le(p.fields.timestamp, buffer(0x10, 8))
-- pretty wireshark shit
pinfo.cols.protocol = p.name
pinfo.cols.src = string.format("instance %d", instance)
pinfo.cols.info = p_type_enum_field().display
-- melonds packets always contain NIFI packets
local next_dissector = txhdr_dissector
-- if instance ~= 0 then
-- next_dissector = rxhdr_dissector
-- end
next_dissector:call(buffer(header_size):tvb(), pinfo, tree)
return header_size
end
|