Skip to content

Commit

Permalink
Merge pull request #8 from jamores/develop
Browse files Browse the repository at this point in the history
TCP PDUs assembling
  • Loading branch information
geynis authored May 29, 2019
2 parents ddb24b1 + c56ddac commit d8a1e52
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
12 changes: 6 additions & 6 deletions sd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ local band,bor = bit.band,bit.bor
local lshift, rshift = bit.lshift,bit.rshift
local tohex = bit.tohex

-- SD protocol
p_sd = Proto("sd","SD")
-- SOME/IP-SD protocol
p_sd = Proto("sd","Scalable service-Oriented MiddlewarE over IP - Service Discovery")

local f_flags = ProtoField.uint8("sd.flags","Flags",base.HEX)
local f_flags_reboot = ProtoField.bool("sd.flags.reboot", "Reboot Flag")
Expand All @@ -24,7 +24,7 @@ local f_opts = ProtoField.bytes("sd.opt","OptionsArray")
p_sd.fields = {f_flags,f_flags_reboot,f_flags_unicast,f_flags_init_data,f_res,f_ents_len,f_ents,f_opts_len,f_opts}

function p_sd.dissector(buf,pinfo,root)
pinfo.cols.protocol = "SOME-IP/SD"
pinfo.cols.protocol = "SOME/IP-SD"

-- create subtree
local subtree = root:add(p_sd,buf(0))
Expand All @@ -39,7 +39,7 @@ function p_sd.dissector(buf,pinfo,root)
flags_tree:add(f_flags_unicast,buf(0,1):bitfield(1,1))
flags_tree:add(f_flags_init_data,buf(0,1):bitfield(2,1))

offset = offset+1
offset = offset + 1

-- Reserved
subtree:add(f_res,buf(offset,3))
Expand All @@ -48,7 +48,7 @@ function p_sd.dissector(buf,pinfo,root)
-- Entries length
local e_len = buf(offset,4):uint()
subtree:add(f_ents_len,buf(offset,4))
offset = offset+4
offset = offset + 4
-- Entries
--e_tree = subtree:add(f_ents,buf(offset,e_len))
e_tree = subtree:add("EntriesArray")
Expand All @@ -58,7 +58,7 @@ function p_sd.dissector(buf,pinfo,root)
-- Options length
local o_len = buf(offset,4):uint()
subtree:add(f_opts_len,buf(offset,4))
offset = offset+4
offset = offset + 4
-- Options
--o_tree = subtree:add(f_ents,buf(offset,o_len))
o_tree = subtree:add("OptionsArray")
Expand Down
42 changes: 29 additions & 13 deletions someip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ local lshift, rshift = bit.lshift,bit.rshift
local tohex = bit.tohex

-- SOME/IP protocol
local SOMEIP_LENGTH = 16
local SOMEIP_HDR_LENGTH = 16

p_someip = Proto("someip","SOME/IP")
p_someip = Proto("someip","Scalable service-Oriented MiddlewarE over IP")

local f_msg_id = ProtoField.uint32("someip.messageid","MessageID",base.HEX)
local f_len = ProtoField.uint32("someip.length","Length",base.HEX)
Expand Down Expand Up @@ -70,7 +70,7 @@ p_someip.fields = {f_msg_id,f_len,f_req_id,f_pv,f_iv,f_mt,f_rc, f_offset, f_rese
p_someip.prefs["udp_port"] = Pref.uint("UDP Port",30490,"UDP Port for SOME/IP")

-- fields functions
function field_msgid(subtree,buf)
local function field_msgid(subtree,buf)
msg_id = subtree:add(f_msg_id,buf(0,4))
local msg_id_uint = buf(0,4):uint()

Expand All @@ -85,7 +85,8 @@ function field_msgid(subtree,buf)
msg_id:add("event_id : "..tohex(band(msg_id_uint,0x7fff),4))
end
end
function field_reqid(subtree,buf)

local function field_reqid(subtree,buf)
req_id = subtree:add(f_req_id,buf(8,4))
local req_id_uint = buf(8,4):uint()

Expand All @@ -95,9 +96,10 @@ function field_reqid(subtree,buf)
req_id:add("session_id : "..tohex(req_id_uint,4))
end

-- dissection function
function p_someip.dissector(buf,pinfo,root)
pinfo.cols.protocol = p_someip.name
-- PDU dissection function
local function someip_pdu_dissect(buf,pinfo,root)

pinfo.cols.protocol = "SOME/IP"

-- create subtree
--
Expand All @@ -119,9 +121,9 @@ function p_someip.dissector(buf,pinfo,root)
subtree:add(f_iv,buf(13,1))

-- Message type
local type = subtree:add(f_mt,buf(14,1))
local m_type = subtree:add(f_mt,buf(14,1))
if msg_types[buf(14,1):uint()] ~= nil then
type:append_text(" (" .. msg_types[buf(14,1):uint()] ..")")
m_type:append_text(" (" .. msg_types[buf(14,1):uint()] ..")")
end

pinfo.cols.info = msg_types[buf(14,1):uint()]
Expand Down Expand Up @@ -149,14 +151,28 @@ function p_someip.dissector(buf,pinfo,root)

-- SD payload --
--
if (buf(0,4):uint() == 0xffff8100) and (buf:len() > SOMEIP_LENGTH) then
Dissector.get("sd"):call(buf(SOMEIP_LENGTH):tvb(),pinfo,root)
elseif (buf:len() > SOMEIP_LENGTH) then
Dissector.get("data"):call(buf(SOMEIP_LENGTH):tvb(),pinfo,root)
if (buf(0,4):uint() == 0xffff8100) and (buf:len() > SOMEIP_HDR_LENGTH) then
Dissector.get("sd"):call(buf(SOMEIP_HDR_LENGTH):tvb(),pinfo,root)
elseif (buf:len() > SOMEIP_HDR_LENGTH) then
Dissector.get("data"):call(buf(SOMEIP_HDR_LENGTH):tvb(),pinfo,root)
end

end

local function get_someip_length(buf, pktinfo, offset)
return buf(offset + 4,4):uint()
end

-- main dissection function
function p_someip.dissector(buf,pinfo,root)
-- if above TCP we need to assemble the PDU
if pinfo.port_type == 2 then
dissect_tcp_pdus(buf,root, SOMEIP_HDR_LENGTH, get_someip_length, someip_pdu_dissect)
else
someip_pdu_dissect(buf,pinfo,root)
end
end

-- initialization routine
function p_someip.init()
-- register protocol (some ports arount 30490, that is referenced on Specs)
Expand Down

0 comments on commit d8a1e52

Please sign in to comment.