-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CRC32 at the end of a transfer and demark the payload as a field #6
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
-- Protocol constants | ||
local CYPHAL_UDP_PORT = 9382 -- The port number used by Cyphal/UDP | ||
|
||
local CYPHAL_UDP_HEADER_SIZE = 24 -- The sizeof the Cyphal/UDP Header | ||
-- Custom protocol dissector | ||
local cyphal_udp = Proto("cyphaludp", "Cyphal/UDP Protocol 1.0 beta") | ||
|
||
|
@@ -23,7 +23,10 @@ frame_index_eot = ProtoField.uint32("cyphal_udp.frame_index_eot", "frame_index_e | |
frame_index = ProtoField.uint32("cyphal_udp.frame_index", "frame_index", base.DEC) | ||
end_of_transfer = ProtoField.bool("cyphal_udp.end_of_transfer", "end_of_transfer", base.NONE) | ||
user_data = ProtoField.uint16("cyphal_udp.user_data", "user_data", base.HEX) | ||
crc16_ccitt_false = ProtoField.uint16("cyphal_udp.crc16_ccitt_false", "crc16_ccitt_false (BE)", base.HEX) | ||
crc16_ccitt_false = ProtoField.uint16("cyphal_udp.crc16_ccitt_false", "CRC16-CCITT-FALSE (BE)", base.HEX) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's all upper-case now. Okay. Am I supposed to be impressed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the reference online are in SHOUTY CASE. So I thought I'd SHOUT too. |
||
serialized_payload = ProtoField.bytes("cyphal_udp.serialized_payload", "serialized_payload", base.SPACE) | ||
serialized_payload_size = ProtoField.uint32("cyphal_udp.serialized_payload_size", "serialized_payload_size", base.DEC) | ||
crc32 = ProtoField.uint32("cyphal_udp.crc32", "CRC32-C (LE)", base.HEX) | ||
|
||
-- Protocol fields | ||
cyphal_udp.fields = { | ||
|
@@ -41,7 +44,10 @@ cyphal_udp.fields = { | |
frame_index, | ||
end_of_transfer, | ||
user_data, | ||
crc16_ccitt_false | ||
crc16_ccitt_false, | ||
serialized_payload, | ||
serialized_payload_size, | ||
crc32 | ||
-- Add more fields as needed | ||
} | ||
|
||
|
@@ -51,22 +57,25 @@ ipv4_destination_address_field = Field.new("ip.dst") | |
-- Function to dissect the custom protocol | ||
local function dissect_cyphal_udp(buffer, pinfo, tree) | ||
-- Create a subtree for the custom protocol | ||
local cyphal_udp_tree = tree:add(cyphal_udp, buffer(), "Cyphal/UDP Header") | ||
local metadata_tree = tree:add(cyphal_udp, buffer(), "Cyphal/UDP Metadata") | ||
local header_tree = tree:add(cyphal_udp, buffer(), "Cyphal/UDP Header") | ||
local payload_tree = tree:add(cyphal_udp, buffer(), "Cyphal/UDP Payload") | ||
local footer_tree = tree:add(cyphal_udp, buffer(), "Cyphal/UDP Footer") | ||
|
||
if (ipv4_source_address_field()) then | ||
local ip_src = ipv4_source_address_field().value | ||
cyphal_udp_tree:add(ipv4_src, ip_src) | ||
metadata_tree:add(ipv4_src, ip_src) | ||
end | ||
if (ipv4_destination_address_field()) then | ||
local ip_dst = ipv4_destination_address_field().value | ||
cyphal_udp_tree:add(ipv4_dst, ip_dst) | ||
metadata_tree:add(ipv4_dst, ip_dst) | ||
end | ||
|
||
-- Add fields to the subtree | ||
cyphal_udp_tree:add_le(version, buffer(0, 1)) | ||
cyphal_udp_tree:add_le(priority, buffer(1, 1)) | ||
cyphal_udp_tree:add_le(source_node_id, buffer(2, 2)) | ||
cyphal_udp_tree:add_le(destination_node_id, buffer(4, 2)) | ||
header_tree:add_le(version, buffer(0, 1)) | ||
header_tree:add_le(priority, buffer(1, 1)) | ||
header_tree:add_le(source_node_id, buffer(2, 2)) | ||
header_tree:add_le(destination_node_id, buffer(4, 2)) | ||
local ds = buffer(6, 2):le_uint() | ||
local port_id = bit.band(ds, 0x7FFF) | ||
local snm = bit.rshift(bit.band(ds, 0x8000), 15) | ||
|
@@ -76,23 +85,30 @@ local function dissect_cyphal_udp(buffer, pinfo, tree) | |
port_id = port_id - 16384 | ||
rnr = true | ||
end | ||
cyphal_udp_tree:add_le(request_not_response, rnr) | ||
cyphal_udp_tree:add_le(service_id, port_id) | ||
header_tree:add_le(request_not_response, rnr) | ||
header_tree:add_le(service_id, port_id) | ||
else | ||
cyphal_udp_tree:add_le(subject_id, port_id) | ||
header_tree:add_le(subject_id, port_id) | ||
end | ||
cyphal_udp_tree:add_le(service_not_message, snm) | ||
cyphal_udp_tree:add_le(data_specifier, buffer(6, 2)) | ||
cyphal_udp_tree:add_le(transfer_id, buffer(8, 8)) | ||
header_tree:add_le(service_not_message, snm) | ||
header_tree:add_le(data_specifier, buffer(6, 2)) | ||
header_tree:add_le(transfer_id, buffer(8, 8)) | ||
-- process the number as BE | ||
cyphal_udp_tree:add_le(frame_index_eot, buffer(16, 4)) | ||
header_tree:add_le(frame_index_eot, buffer(16, 4)) | ||
local fi = buffer(16, 4):le_uint() | ||
local fidx = bit.band(fi, 0x7FFFFFFF) | ||
local eot = bit.rshift(bit.band(fi, 0x80000000), 31) | ||
cyphal_udp_tree:add_le(frame_index, fidx) | ||
cyphal_udp_tree:add_le(end_of_transfer, eot) | ||
cyphal_udp_tree:add_le(user_data, buffer(20, 2)) | ||
cyphal_udp_tree:add(crc16_ccitt_false, buffer(22, 2)) | ||
header_tree:add_le(frame_index, fidx) | ||
header_tree:add_le(end_of_transfer, eot) | ||
header_tree:add_le(user_data, buffer(20, 2)) | ||
header_tree:add(crc16_ccitt_false, buffer(22, 2)) | ||
local len = buffer:len() | ||
local rem = len - CYPHAL_UDP_HEADER_SIZE - 4 -- the remaining bytes minus CRC32C | ||
if rem > 0 then | ||
payload_tree:add_le(serialized_payload_size, rem) | ||
payload_tree:add_le(serialized_payload, buffer(24, rem)) | ||
end | ||
footer_tree:add_le(crc32, buffer(len-4, 4)) | ||
-- Add more field dissectors as needed | ||
end | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version is only 4 bits. The following 4 bits are reserved.