Ask Your Question
0

How to call a sub-dissector in lua

asked 2023-02-10 17:31:01 +0000

qschachi gravatar image

updated 2023-02-10 20:03:47 +0000

Chuckc gravatar image

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)

edit retag flag offensive close merge delete

Comments

Dissector.get("LoxonePayload") won't succeed until LoxonePayload is registered - somewhere.
If you replace Dissector.get("LoxonePayload") with Dissector.list() and check the output, is LoxonePayload listed?

Chuckc gravatar imageChuckc ( 2023-02-10 21:59:34 +0000 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-02-13 16:17:11 +0000

cmaynard gravatar image

updated 2023-02-13 16:17:44 +0000

You can try adding a pL1_LoxoneLink.init() function that calls Dissector.get("LoxonePayload"). For example:

local LoxonePayloadDissector

function pL1_LoxoneLink.init()
    LoxonePayloadDissector = Dissector.get("LoxonePayload")
end

function pL1_LoxoneLink.dissector(buffer, pinfo, tree)
    local subtree = tree:add(pL1_LoxoneLink, buffer())

    ************** some more code ****************  
    -- call Layer2 dissector for payload
    LoxonePayloadDissector:call(buffer(offset, buffer:len() - offset):tvb(), packet_info, tree)
end

Ref: 11.3.5.7. proto.init

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2023-02-10 17:31:01 +0000

Seen: 765 times

Last updated: Feb 13 '23