Ask Your Question
0

LUA CAN SubDissector get CAN_ID

asked 2025-05-15 18:10:33 +0000

aapje06 gravatar image

updated 2025-05-15 18:11:42 +0000

Is it possible to get the parent dissector data into the child dissector? More specifically, I am trying to write a can dissector for a custom CAN protocol, but I need the CAN SID in order to fully dissect the data.

I've tried several things to get there, including chaining it under different dissectors, but without any luck.

The simplified setup I've got so far:

```lua

local custom_can = Proto("custom-can","Custom CAN Protocol")
function custom_can.dissector(tvbuf,pktinfo,root)
    -- Here I want to get the CAN ID...
end
DissectorTable.get("can.subdissector"):add_for_decode_as(custom_can)

```

I've also tried it with the can.id parent dissector:

``` lua

DissectorTable.get("can.id"):add('0-6', custom_can)

```

Again without any luck.

I do not want to write a complete can dissector from scratch if possible, just add it on top of the existing CAN dissector. However as far as I can see, I only get the data section from a CAN frame in the subdissector?

In C there is an option to get a void pointer and cast that to a can struct, but I do want to do it in lua if possible.: C-canopen-dissector

Is there a way to accomplish this in lua?

Thanks in advance for any help!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-05-15 19:57:51 +0000

johnthacker gravatar image

Lua dissectors do not have support for an arbitrary data parameter like in C: https://gitlab.com/wireshark/wireshar...

https://gitlab.com/wireshark/wireshar...

However, if you have added your dissector to a uint dissector table and it was called by that table matching a certain value, then the value should be in pinfo.match_uinthttps://www.wireshark.org/docs/wsdg_h...

That should work with can.id which is a 32-bit unsigned integer table.

edit flag offensive delete link more

Comments

This works perfectly! Thank you!

aapje06 gravatar imageaapje06 ( 2025-05-15 20:07:44 +0000 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2025-05-15 18:10:33 +0000

Seen: 30 times

Last updated: May 15