diff --git a/.luacheckrc b/.luacheckrc index a1249d4..13f4c00 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -12,5 +12,7 @@ stds.wireshark = { "ProtoField", "base", "ftypes", + "package", + "set_plugin_info", } } diff --git a/rls-3-1.lua b/protocol/rls-3-1.lua similarity index 96% rename from rls-3-1.lua rename to protocol/rls-3-1.lua index ead69ff..e586968 100644 --- a/rls-3-1.lua +++ b/protocol/rls-3-1.lua @@ -6,8 +6,6 @@ -- CC0-1.0 2021 - Louis Royer () -- --]] -require("rls") - local rlsProtocol31 = Proto("RLS-3.1", "UERANSIM 3.1.x Radio Link Simulation (RLS) Protocol") local fields = rlsProtocol31.fields @@ -128,7 +126,9 @@ function rlsProtocol31.dissector(buffer, pinfo, tree) end end -local rls = DissectorTable.get("rls") -rls:add(0x0301, rlsProtocol31) -local udp_port = DissectorTable.get("udp.port") -udp_port:add_for_decode_as(rlsProtocol31) +function rlsProtocol31.init() + local rls = DissectorTable.get("rls") + rls:add(0x0301, rlsProtocol31) + local udp_port = DissectorTable.get("udp.port") + udp_port:add_for_decode_as(rlsProtocol31) +end diff --git a/rls-3-2.lua b/protocol/rls-3-2.lua similarity index 95% rename from rls-3-2.lua rename to protocol/rls-3-2.lua index aec8b25..a9fc42a 100644 --- a/rls-3-2.lua +++ b/protocol/rls-3-2.lua @@ -6,8 +6,6 @@ -- CC0-1.0 2021 - Louis Royer () -- --]] -require("rls") - local rlsProtocol32 = Proto("RLS-3.2", "UERANSIM 3.2.x Radio Link Simulation (RLS) Protocol") local fields = rlsProtocol32.fields @@ -124,7 +122,9 @@ function rlsProtocol32.dissector(buffer, pinfo, tree) end end -local rls = DissectorTable.get("rls") -rls:add(0x0302, rlsProtocol32) -local udp_port = DissectorTable.get("udp.port") -udp_port:add_for_decode_as(rlsProtocol32) +function rlsProtocol32.init() + local rls = DissectorTable.get("rls") + rls:add(0x0302, rlsProtocol32) + local udp_port = DissectorTable.get("udp.port") + udp_port:add_for_decode_as(rlsProtocol32) +end diff --git a/rls.lua b/rls.lua index cda89e6..06857fe 100644 --- a/rls.lua +++ b/rls.lua @@ -7,53 +7,59 @@ -- --]] --- This file must only be loaded once, but each version requires it. -if package.loaded['rls'] == nil then - -- Update the following when adding new versions - local latestVersion = 0x0302 - local oldestVersion = 0x0301 +local pluginVersion = "1.1.1" +-- Update the following when adding new versions +local latestVersion = 0x0302 +local oldestVersion = 0x0301 - local rlsProtocol = Proto("RLS", "UERANSIM Radio Link Simulation (RLS) Protocol") +local rlsProtocol = Proto("RLS", "UERANSIM Radio Link Simulation (RLS) Protocol") +set_plugin_info({ + version = pluginVersion, + author = "Louis Royer", + repository = "https://github.com/louisroyer/RLS-wireshark-dissector", + description = "Dissector for Radio Link Simulation Protocol" +}) - -- Create a DissectorTable to register dissector for each version of RLS - DissectorTable.new("rls", "RLS version", ftypes.UINT32, base.HEX, rlsProtocol) +-- Create a DissectorTable to register dissector for each version of RLS +DissectorTable.new("rls", "RLS version", ftypes.UINT32, base.HEX, rlsProtocol) - -- Preferences - rlsProtocol.prefs.udp_port = Pref.uint("RLS UDP port", 4997, "UDP port for RLS") +-- Preferences +rlsProtocol.prefs.udp_port = Pref.uint("RLS UDP port", 4997, "UDP port for RLS") - -- Add version field - local fields = rlsProtocol.fields - fields.Version = ProtoField.string("rls.version", "Version") +-- Add version field +local fields = rlsProtocol.fields +fields.Version = ProtoField.string("rls.version", "Version") - function rlsProtocol.dissector(buffer, pinfo, tree) - -- Generic check - if buffer:len() == 0 then return end - if buffer(0, 1):uint() ~= 0x03 then return end +function rlsProtocol.dissector(buffer, pinfo, tree) + -- Generic check + if buffer:len() == 0 then return end + if buffer(0, 1):uint() ~= 0x03 then return end - pinfo.cols.protocol = rlsProtocol.name + pinfo.cols.protocol = rlsProtocol.name - local version = buffer(1,2):uint() - local subprotocol = DissectorTable.get("rls"):get_dissector(version) + local version = buffer(1,2):uint() + local subprotocol = DissectorTable.get("rls"):get_dissector(version) + if subprotocol == nil then + if version > latestVersion then + -- fallback to latest version + version = latestVersion + elseif version < oldestVersion then + -- fallback to oldest version + version = oldestVersion + end + subprotocol = DissectorTable.get("rls"):get_dissector(version) if subprotocol == nil then - if version > latestVersion then - -- fallback to latest version - version = latestVersion - elseif version < oldestVersion then - -- fallback to oldest version - version = oldestVersion - end - subprotocol = DissectorTable.get("rls"):get_dissector(version) - if subprotocol == nil then - local versionNumber = buffer(1, 1):uint() .. "." .. buffer(2, 1):uint() .. "." .. buffer(3, 1):uint() - local subtree = tree:add(rlsProtocol, buffer(), "UERANSIM Radio Link Simulation (RLS) protocol") - pinfo.cols.info = "Unsupported version - Cannot decode" - subtree:add(fields.Version, buffer(1, 3), versionNumber) - return 4 - end + local versionNumber = buffer(1, 1):uint() .. "." .. buffer(2, 1):uint() .. "." .. buffer(3, 1):uint() + local subtree = tree:add(rlsProtocol, buffer(), "UERANSIM Radio Link Simulation (RLS) protocol") + pinfo.cols.info = "Unsupported version - Cannot decode" + subtree:add(fields.Version, buffer(1, 3), versionNumber) + return 4 end - subprotocol:call(buffer():tvb(), pinfo, tree) end + subprotocol:call(buffer():tvb(), pinfo, tree) +end +function rlsProtocol.init() -- Export protocol local udp_port = DissectorTable.get("udp.port") udp_port:add(rlsProtocol.prefs.udp_port, rlsProtocol)