First time here? Check out the FAQ!
THIS IS A TEST INSTANCE. Feel free to ask and answer questions, but take care to avoid triggering too many notifications.
0

How to call a sub-dissector in lua

  • retag add tags

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)

qschachi's avatar
1
qschachi
asked 2023-02-10 17:31:01 +0000
Chuckc's avatar
3k
Chuckc
updated 2023-02-10 20:03:47 +0000
edit flag offensive 0 remove flag 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's avatar Chuckc (2023-02-10 21:59:34 +0000) edit
add a comment see more comments

1 Answer

0

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

cmaynard's avatar
11.1k
cmaynard
answered 2023-02-13 16:17:11 +0000, updated 2023-02-13 16:17:44 +0000
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer