Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to call a sub-dissector in lua

Hello,

I'm streaming CAN data from a CAN2USB interface into Wireshark over a pipe - this works fine so far. Now I'm writing a dissector for a custom protocol where the "1st layer" is to decode the CanId and the "2nd layer" shall decode the payload.

Since *im new to lua I worked through some examples and I'm already able to dissect the CanId but now I want to call a second own written dissector to dissect the payload but I always getting a error that the 2nd dissector is not found

the lua script looks like this: The problem is when I want to call the 2nd dissector with Dissector.get("LoxonePayload") --:call(buffer(offset, buffer:len() - offset):tvb(), packet_info, tree) I always get the error "bad argument #1 to 'get' (Dissector_get: No such dissector)

What make I wrong? I found an example where it is done like this way

Every hints/help appriciated

BR Martin

-- ############################################################################### -- ## Layer 2: Dissect Payload -- ###############################################################################

-- Register a protocol named LoxonePayload and followed with its description. pL2_LoxonePayload = Proto.new("LoxonePayload", "Loxone Payload Dissector")

local fL2 = pL2_LoxonePayload.fields

-- ############################################################################### -- The argument buffer is the source of packet contents ,and -- pinfo and tree are the object to display our info function pL2_LoxonePayload.dissector(buffer, pinfo, tree) local subtree = tree:add(pL2_LoxonePayload, buffer())

local offset=0

 ******** some code **********

end

-- ############################################################################### -- ## Layer 1: Dissect Loxone Link Protocol (CAN Identifier) -- ###############################################################################

-- Register a protocol named LoxoneLink and followed with its description. pL1_LoxoneLink = Proto("LoxoneLink", "Loxone Protocol Dissector")

-- Create some local variable and array ,and -- these variables will be used in the tree in packet decode local fL1 = pL1_LoxoneLink.fields

-- ############################################################################### -- This function is regarded as the main function that -- the argument buffer is the source of packet contents ,and -- pinfo and tree are the object to display our info function pL1_LoxoneLink.dissector(buffer, pinfo, tree) local subtree = tree:add(pL1_LoxoneLink, buffer())

************** some more code ****************  
-- call Layer2 dissector for payload

=================> here I get the error from Dissector.get: "No such dissector" Dissector.get("LoxonePayload") --:call(buffer(offset, buffer:len() - offset):tvb(), packet_info, tree) end

-- ############################################################################### -- ## Attach dissector -- ###############################################################################

-- this sub dissector lox_CanId_Table is from CAN protocol (ID 125) local lox_CanId_Table = DissectorTable.get("wtap_encap") lox_CanId_Table:add(125, pL1_LoxoneLink)

click to hide/show revision 2
None

How to call a sub-dissector in lua

Hello,

I'm streaming CAN data from a CAN2USB interface into Wireshark over a pipe - this works fine so far. Now I'm writing a dissector for a custom protocol where the "1st layer" is to decode the CanId and the "2nd layer" shall decode the payload.

Since *im new to lua I worked through some examples and I'm already able to dissect the CanId but now I want to call a second own written dissector to dissect the payload but I always getting a error that the 2nd dissector is not found

the lua script looks like this: The problem is when I want to call the 2nd dissector with Dissector.get("LoxonePayload") --:call(buffer(offset, buffer:len() - offset):tvb(), packet_info, tree) I always get the error "bad argument #1 to 'get' (Dissector_get: No such dissector)

What make I wrong? I found an example where it is done like this way

Every hints/help appriciated

BR Martin

-- ###############################################################################
-- ## Layer 2: Dissect Payload
-- ###############################################################################

############################################################################### -- Register a protocol named LoxonePayload and followed with its description. pL2_LoxonePayload = Proto.new("LoxonePayload", "Loxone Payload Dissector")

Dissector") local fL2 = pL2_LoxonePayload.fields

pL2_LoxonePayload.fields -- ############################################################################### -- The argument buffer is the source of packet contents ,and -- pinfo and tree are the object to display our info function pL2_LoxonePayload.dissector(buffer, pinfo, tree) local subtree = tree:add(pL2_LoxonePayload, buffer())

buffer())

    local offset=0

  ******** some code **********

end

end -- ############################################################################### -- ## Layer 1: Dissect Loxone Link Protocol (CAN Identifier) -- ###############################################################################

############################################################################### -- Register a protocol named LoxoneLink and followed with its description. pL1_LoxoneLink = Proto("LoxoneLink", "Loxone Protocol Dissector")

Dissector") -- Create some local variable and array ,and -- these variables will be used in the tree in packet decode local fL1 = pL1_LoxoneLink.fields

pL1_LoxoneLink.fields -- ############################################################################### -- This function is regarded as the main function that -- the argument buffer is the source of packet contents ,and -- pinfo and tree are the object to display our info function pL1_LoxoneLink.dissector(buffer, pinfo, tree) local subtree = tree:add(pL1_LoxoneLink, buffer())

buffer())

    ************** some more code ****************  
 -- call Layer2 dissector for payload

=================> here I get the error from Dissector.get: "No such dissector" Dissector.get("LoxonePayload") --:call(buffer(offset, buffer:len() - offset):tvb(), packet_info, tree) end

end -- ############################################################################### -- ## Attach dissector -- ###############################################################################

############################################################################### -- this sub dissector lox_CanId_Table is from CAN protocol (ID 125) local lox_CanId_Table = DissectorTable.get("wtap_encap") lox_CanId_Table:add(125, pL1_LoxoneLink)

pL1_LoxoneLink)