Created
January 8, 2014 18:10
-
-
Save oro350/8321451 to your computer and use it in GitHub Desktop.
Wireshark Dissactor plug-in
IEEE1722 (AVTP) IEC61883/IIDC Subtype MPEG2-TS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ================================================= | |
-- IEEE1722 for 61883_IIDC_SUBTYPE, MPEG2-TS | |
-- ================================================= | |
function addfielditem(tree, range, value, table) | |
for i, fmt in ipairs(table) do | |
tree:add(fmt, range, value) | |
end | |
return range:len() | |
end | |
do | |
p_ieee1722 = Proto("IEEE1722_MP2T","IEEE 1722 Protocol (extended MPEG2-TS)") | |
local IEEE_1722_CIP_HEADER_SIZE = 8 | |
local f_cd = ProtoField.bool("ieee1722.cdfield", "Control/Data Indicator", 8, nil, 0x80) | |
local f_subtype = ProtoField.uint8("ieee1722.subtype", "AVBTP Subtype", base.HEX, nil, 0x7f) | |
local f_sv = ProtoField.bool("ieee1722.svfield", "AVBTP Stream ID Valid", 8, nil, 0x80) | |
local f_ver = ProtoField.uint8("ieee1722.verfield", "AVBTP Version", base.HEX, nil, 0x70) | |
local f_mr = ProtoField.uint8("ieee1722.mrfield", "AVBTP Media Reset", base.DEC, nil, 0x08) | |
local f_gv = ProtoField.bool("ieee1722.gvfield", "AVBTP Gateway Info Valid", 8, nil, 0x02) | |
local f_tv = ProtoField.bool("ieee1722.tvfield", "Source Timestamp Valid", 8, nil, 0x01) | |
local f_seqnum = ProtoField.uint8("ieee1722.seqnum", "Sequence Number", base.HEX, nil, 0x00) | |
local f_tu = ProtoField.bool("ieee1722.tufield", "AVBTP Timestamp Uncertain", 8, nil, 0x01) | |
local f_stream_id = ProtoField.uint64("ieee1722.stream_id", "Stream ID", base.HEX, nil, 0x00) | |
local f_avbtp_timestamp = ProtoField.uint32("ieee1722.avbtp_timestamp", "AVBTP Timestamp", base.HEX, nil, 0x00) | |
local f_gateway_info = ProtoField.uint32("ieee1722.gateway_info", "Gateway Info", base.HEX, nil, 0x00) | |
local f_packet_data_length = ProtoField.uint16("ieee1722.packet_data_len", "1394 Packet Data Length", base.DEC, nil, 0x00) | |
local f_tag = ProtoField.uint8("ieee1722.tag", "1394 Packet Format Tag", base.HEX, nil, 0xc0) | |
local f_channel = ProtoField.uint8("ieee1722.channel", "1394 Packet Channel", base.HEX, nil, 0x3f) | |
local f_tcode = ProtoField.uint8("ieee1722.tcode", "1394 Packet Tcode", base.HEX, nil, 0xf0) | |
local f_sy = ProtoField.uint8("ieee1722.sy", "1394 App-specific Control", base.HEX, nil, 0x0f) | |
-- | |
local f_sid = ProtoField.uint8("ieee1722.sid", "Source ID", base.HEX, nil, 0x3f) | |
local f_dbs = ProtoField.uint8("ieee1722.dbs", "Data Block Size", base.HEX, nil, 0x00) | |
local f_fn = ProtoField.uint8("ieee1722.fn", "Fraction Number", base.HEX, nil, 0xc0) | |
local f_qpc = ProtoField.uint8("ieee1722.qpc", "Quadlet Padding Count", base.HEX, nil, 0x38) | |
local f_sph = ProtoField.bool("ieee1722.sph", "Source Packet Header", 8, nil, 0x04) | |
local f_dbc = ProtoField.uint8("ieee1722.dbc", "Data Block Continuity", base.HEX, nil, 0x00) | |
local f_fmt = ProtoField.uint8("ieee1722.fmt", "Format ID", base.HEX, nil, 0x3f) | |
local f_fdf = ProtoField.uint8("ieee1722.fdf", "Format Dependent Field", base.HEX, nil, 0x00) | |
local f_syt = ProtoField.uint16("ieee1722.syt", "SYT", base.HEX, nil, 0x00) | |
-- | |
local f_data_audio = ProtoField.bytes("ieee1722.data.audio", "Audio Data", nil, nil, 0x00) | |
local f_data_audio_label = ProtoField.uint8("ieee1722.data.audio.sample.label", "Lable", base.HEX, nil, 0x00) | |
local f_data_audio_sample = ProtoField.uint24("ieee1722.data.audio.sample.sampledata", "Sample", base.HEX, nil, 0x00) | |
local f_data_audio_header = ProtoField.bytes("ieee1722.data.audio.header", "Sample ") | |
local f_incorrect_dbs = ProtoField.bytes("ieee1722.incorrect_dbs", "Incorrect DBS") | |
-- | |
local f_data_mp2t = ProtoField.bytes("ieee1722.data.mp2t", "MPEG2-TS Data", nil, nil, 0x00) | |
local f_data_mp2t_sph = ProtoField.uint32("ieee1722.data.mp2t.sph", "Source Packet Header", base.HEX, nil, 0x00) | |
local f_data_mp2t_cycle_count = ProtoField.uint32("ieee1722.data.mp2t.cycle_count", "Cycle Count", base.HEX, nil, 0x01fff000) | |
local f_data_mp2t_cycle_offset = ProtoField.uint32("ieee1722.data.mp2t.cycle_offset", "Cycle Offset", base.HEX, nil, 0x00000fff) | |
-- | |
local f_data_video_payload = ProtoField.bytes("ieee1722.data.video.payload", "1394-based Digital Camera Payload") | |
-- | |
p_ieee1722.fields = { | |
f_cd, f_subtype, | |
f_sv, f_ver, f_mr, f_gv, f_tv, | |
f_seqnum, f_tu, | |
f_stream_id, | |
f_avbtp_timestamp, | |
f_gateway_info, | |
f_packet_data_length, | |
f_tag, f_channel, | |
f_tcode, f_sy, | |
-- | |
f_sid, | |
f_dbs, | |
f_fn, f_qpc, f_sph, | |
f_dbc, | |
f_fmt, | |
f_fdf, | |
f_syt, | |
-- | |
f_data_audio, | |
f_data_audio_label, | |
f_data_audio_sample, | |
f_data_audio_header, | |
f_incorrect_dbs, | |
-- | |
f_data_mp2t, | |
f_data_mp2t_sph, | |
f_data_mp2t_cycle_count, | |
f_data_mp2t_cycle_offset, | |
-- | |
f_data_video_payload, | |
} | |
local data_dissector = Dissector.get("data") | |
local mp2t_dissector = Dissector.get("mp2t") | |
local ethertype_table = DissectorTable.get("ethertype") | |
local ieee1722_dissector = ethertype_table:get_dissector(8944) | |
function p_ieee1722.dissector(buffer,pinfo,root) | |
local subtype = (buffer(0,1):uint() % 0x80) | |
local tag = math.floor(buffer(22,1):uint() / 0x40) | |
local format_id = (buffer(28,1):uint() % 0x40) | |
if subtype ~= 0x00 then | |
-- No 61883_IIDC_SUBTYPE | |
return ieee1722_dissector:call(buffer,pinfo,root) | |
end | |
if tag == 0x01 and format_id == 0x10 then | |
-- Format ID equal 'Audio and Music' | |
return ieee1722_dissector:call(buffer,pinfo,root) | |
end | |
local tree = root:add(p_ieee1722, buffer(0), "IEEE 1722 Protocol") | |
local ofs = 0 | |
local len = 1 | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_cd, f_subtype }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_sv, f_ver, f_mr, f_gv, f_tv }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_seqnum }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_tu }) | |
len = 8 | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint64(), { f_stream_id }) | |
len = 4 | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_avbtp_timestamp }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_gateway_info }) | |
len = 2 | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_packet_data_length }) | |
len = 1 | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_tag, f_channel }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_tcode, f_sy }) | |
if tag == 0x00 then | |
-- No CIP header included | |
tree:add(f_data_video_payload, buffer(ofs)) | |
elseif tag == 0x01 then | |
-- CIP header included | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_sid }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_dbs }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_fn, f_qpc, f_sph }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_dbc }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_fmt }) | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_fdf }) | |
len = 2 | |
ofs = ofs + addfielditem(tree, buffer(ofs,len), buffer(ofs,len):uint(), { f_syt }) | |
local datalen = buffer(20,2):uint() - IEEE_1722_CIP_HEADER_SIZE | |
local dbs = buffer(25,1):uint() | |
local sph = math.floor(buffer(26,1):uint() / 0x4) | |
if format_id == 0x20 then | |
-- MPEG2-TS | |
local mp2t_tree = tree:add(f_data_mp2t, buffer(ofs,datalen)) | |
if sph == 0 then | |
ofs = ofs + mp2t_dissector:call(buffer(ofs):tvb(),pinfo,mp2t_tree) | |
else | |
local sph_len = 4 | |
for i = 0, datalen-1, 192 do | |
local sph_tree = mp2t_tree:add(f_data_mp2t_sph, buffer(ofs,sph_len), buffer(ofs,sph_len):uint()) | |
ofs = ofs + addfielditem(sph_tree, buffer(ofs,sph_len), buffer(ofs,sph_len):uint(), { f_data_mp2t_cycle_count, f_data_mp2t_cycle_offset }) | |
mp2t_dissector:call(buffer(ofs,188):tvb(),pinfo,mp2t_tree) | |
ofs = ofs + 188 | |
end | |
end | |
else | |
data_dissector:call(buffer(ofs,datalen):tvb(),pinfo,tree) | |
end | |
else | |
data_dissector:call(buffer(ofs):tvb(),pinfo,tree) | |
end | |
pinfo.cols.protocol = "IEEE1722" | |
pinfo.cols.info = "AVB Transportation Protocol" | |
return buffer:len() | |
end | |
-- ================================================= | |
-- Register ieee1722_proto | |
-- ================================================= | |
ethertype_table:add(8944, p_ieee1722) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment