Skip to content
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

Cherrypick ueransimv3.2.0 #4

Merged
merged 5 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ stds.wireshark = {
read_globals = {
"Dissector",
"DissectorTable",
"Pref",
"Proto",
"ProtoField",
"base",
"ftypes",
}
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
[![Build Status](https://travis-ci.org/louisroyer/RLS-wireshark-dissector.svg?branch=master)](https://travis-ci.org/louisroyer/RLS-wireshark-dissector)

## Quick Start
Copy `rls.lua` into `~/.local/lib/wireshark/plugins`.
```
$ mkdir -p ${XDG_LIB_HOME:-~/.local/lib}/wireshark/plugins
$ git -C ${XDG_LIB_HOME:-~/.local/lib}/wireshark/plugins https://github.com/louisroyer/RLS-wireshark-dissector

NB: you need to use a recent Wireshark version with implementation for `nr-rrc` dissectors.
```

NB: you need to use a recent Wireshark version with implementation for `nr-rrc` dissectors (Wireshark version 3.0.0 at least).
Binary file added pcap/rls_3-2-0.pcapng
Binary file not shown.
134 changes: 134 additions & 0 deletions rls-3-1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
--[[
--
-- Dissector for Radio Link Simulation Protocol version 3.1.x
-- (UERANSIM project <https://github.com/aligungr/UERANSIM>).
--
-- CC0-1.0 2021 - Louis Royer (<https://github.com/louisroyer/RLS-wireshark-dissector>)
--
--]]
require("rls")

local rlsProtocol31 = Proto("RLS-3.1", "UERANSIM 3.1.x Radio Link Simulation (RLS) Protocol")
local fields = rlsProtocol31.fields

local msgTypeNames = {
[0] = "[Reserved]",
[1] = "Cell Info Request",
[2] = "Cell Info Response",
[3] = "PDU Delivery",
}

local pduTypeNames = {
[0] = "[Reserved]",
[1] = "RRC",
[2] = "Data"
}

local rrcMsgTypeNames = {
[0] = "BCCH-BCH",
[1] = "BCCH-DL-SCH",
[2] = "DL-CCCH",
[3] = "DL-DCCH",
[4] = "PCCH",
[5] = "UL-CCCH",
[6] = "UL-CCCH1",
[7] = "UL-DCCH",
}

local nrRrcDissectors = {
[0] = "nr-rrc.bcch.bch",
[1] = "nr-rrc.bcch.dl.sch",
[2] = "nr-rrc.dl.ccch",
[3] = "nr-rrc.dl.dcch",
[4] = "nr-rrc.pcch",
[5] = "nr-rrc.ul.ccch",
[6] = "nr-rrc.ul.ccch1",
[7] = "nr-rrc.ul.dcch",
}

fields.Version = ProtoField.string("rls.version", "Version")
fields.MsgType = ProtoField.uint8("rls.message_type", "Message Type", base.DEC, msgTypeNames)
fields.Sti = ProtoField.uint64("rls.sti", "Sender Node Temporary ID", base.DEC)
fields.PduType = ProtoField.uint8("rls.pdu_type", "PDU Type", base.DEC, pduTypeNames)
fields.RrcMsgType = ProtoField.uint32("rls.rrc_message_type", "RRC Message Type", base.DEC, rrcMsgTypeNames)
fields.PduLength = ProtoField.uint32("rls.pdu_length", "PDU Length", base.DEC)
fields.PduSessionId = ProtoField.uint32("rls.pdu_session_id", "PDU Session ID", base.DEC)
fields.Dbm = ProtoField.int32("rls.dbm", "RLS Signal Strength (dBm)", base.DEC)
fields.PosX = ProtoField.uint32("rls.pos_x", "RLS Position X", base.DEC)
fields.PosY = ProtoField.uint32("rls.pos_y", "RLS Position Y", base.DEC)
fields.PosZ = ProtoField.uint32("rls.pos_z", "RLS Position Z", base.DEC)
fields.Mcc = ProtoField.uint16("rls.mcc", "MCC", base.DEC)
fields.Mnc = ProtoField.uint16("rls.mnc", "MNC", base.DEC)
fields.LongMnc = ProtoField.bool("rls.long_mnc", "MNC is 3-digit", base.BOOL)
fields.Nci = ProtoField.uint64("rls.nci", "NR Cell Identity", base.HEX)
fields.Tac = ProtoField.uint32("rls.tac", "Tracking Area Code", base.DEC)
fields.GnbName = ProtoField.string("rls.gnb_name", "gNB Name")
fields.LinkIp = ProtoField.string("rls.link_ip", "gNB Link IP")

function rlsProtocol31.dissector(buffer, pinfo, tree)
if buffer:len() == 0 then return false end
if buffer(0, 1):uint() ~= 0x03 then return false end
if buffer(1, 2):uint() > 0x0301 then return false end

pinfo.cols.protocol = rlsProtocol31.name

local versionNumber = buffer(1, 1):uint() .. "." .. buffer(2, 1):uint() .. "." .. buffer(3, 1):uint()
local subtree = tree:add(rlsProtocol31, buffer(), "UERANSIM Radio Link Simulation (RLS) protocol")

subtree:add(fields.Version, buffer(1, 3), versionNumber)
subtree:add(fields.MsgType, buffer(4, 1))
local msgType = buffer(4, 1):uint()

pinfo.cols.info = msgTypeNames[msgType]
subtree:add(fields.Sti, buffer(5, 8))

if msgType == 1 then -- Cell Info Request
subtree:add(fields.PosX, buffer(13,4))
subtree:add(fields.PosY, buffer(17,4))
subtree:add(fields.PosZ, buffer(21,4))
elseif msgType == 2 then -- Cell Info Response
subtree:add(fields.Mcc, buffer(13,2))
local mnc_tree = subtree:add(rlsProtocol31, buffer(15,3), "MNC: "..tostring(buffer(15,2):uint()))
mnc_tree:add(fields.Mnc, buffer(15,2))
mnc_tree:add(fields.LongMnc, buffer(17,1))
subtree:add(fields.Nci, buffer(18,8))
subtree:add(fields.Tac, buffer(26,4))
subtree:add(fields.Dbm, buffer(30,4))
local gnbNameLength = buffer(34,4):uint()
subtree:add(fields.GnbName, buffer(38,gnbNameLength))
local linkIpLength = buffer(38+gnbNameLength,4):uint()
subtree:add(fields.LinkIp, buffer(42+gnbNameLength,linkIpLength))
elseif msgType == 3 then -- PDU Delivery
subtree:add(fields.PduType, buffer(13,1))
local pduType = buffer(13,1):uint()
local pduLength = buffer(14,4):uint()
local payloadLength = buffer(18+pduLength,4):uint()
if pduType == 1 then -- RRC
local rrcMsgType = buffer(22+pduLength,payloadLength):uint()
subtree:add(fields.RrcMsgType, buffer(22+pduLength,payloadLength))
subtree:add(fields.PduLength, buffer(14,4))
-- Old versions of Wireshark (< 3.0.0) cannot handle NR-RRC correctly
local dissector
local function get_dissector()
dissector = Dissector.get(nrRrcDissectors[rrcMsgType])
end
if pcall(get_dissector) then
dissector:call(buffer(18, pduLength):tvb(), pinfo, tree)
else
pinfo.cols.info = msgTypeNames[msgType]
.. " - " .. rrcMsgTypeNames[rrcMsgType]
.. " - Cannot decode"
return false
end
elseif pduType == 2 then -- DATA
subtree:add(fields.PduSessionId, buffer(22+pduLength,payloadLength))
subtree:add(fields.PduLength, buffer(14,4))
Dissector.get("ip"):call(buffer(18,pduLength):tvb(), pinfo, tree)
end
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)
130 changes: 130 additions & 0 deletions rls-3-2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
--[[
--
-- Dissector for Radio Link Simulation Protocol version 3.2.x
-- (UERANSIM project <https://github.com/aligungr/UERANSIM>).
--
-- CC0-1.0 2021 - Louis Royer (<https://github.com/louisroyer/RLS-wireshark-dissector>)
--
--]]
require("rls")

local rlsProtocol32 = Proto("RLS-3.2", "UERANSIM 3.2.x Radio Link Simulation (RLS) Protocol")
local fields = rlsProtocol32.fields

local msgTypeNames = {
[0] = "[Reserved]",
[1] = "[Reserved]",
[2] = "[Reserved]",
[3] = "[Reserved]",
[4] = "Heartbeat",
[5] = "Heartbeat ACK",
[6] = "PDU Transmission",
[7] = "PDU Transmission ACK",
}

local pduTypeNames = {
[0] = "[Reserved]",
[1] = "RRC",
[2] = "Data"
}

local rrcMsgTypeNames = {
[0] = "BCCH-BCH",
[1] = "BCCH-DL-SCH",
[2] = "DL-CCCH",
[3] = "DL-DCCH",
[4] = "PCCH",
[5] = "UL-CCCH",
[6] = "UL-CCCH1",
[7] = "UL-DCCH",
}

local nrRrcDissectors = {
[0] = "nr-rrc.bcch.bch",
[1] = "nr-rrc.bcch.dl.sch",
[2] = "nr-rrc.dl.ccch",
[3] = "nr-rrc.dl.dcch",
[4] = "nr-rrc.pcch",
[5] = "nr-rrc.ul.ccch",
[6] = "nr-rrc.ul.ccch1",
[7] = "nr-rrc.ul.dcch",
}

fields.Version = ProtoField.string("rls.version", "Version")
fields.MsgType = ProtoField.uint8("rls.message_type", "Message Type", base.DEC, msgTypeNames)
fields.Sti = ProtoField.uint64("rls.sti", "Sender Node Temporary ID", base.DEC)
fields.PduType = ProtoField.uint8("rls.pdu_type", "PDU Type", base.DEC, pduTypeNames)
fields.PduId = ProtoField.uint32("rls.pdu_id", "PDU ID", base.DEC)
fields.RrcMsgType = ProtoField.uint32("rls.rrc_message_type", "RRC Message Type", base.DEC, rrcMsgTypeNames)
fields.PduLength = ProtoField.uint32("rls.pdu_length", "PDU Length", base.DEC)
fields.PduSessionId = ProtoField.uint32("rls.pdu_session_id", "PDU Session ID", base.DEC)
fields.AcknowledgeItem = ProtoField.uint32("rls.ack_item", "PDU ID")
fields.Dbm = ProtoField.int32("rls.dbm", "RLS Signal Strength (dBm)", base.DEC)
fields.PosX = ProtoField.uint32("rls.pos_x", "RLS Position X", base.DEC)
fields.PosY = ProtoField.uint32("rls.pos_y", "RLS Position Y", base.DEC)
fields.PosZ = ProtoField.uint32("rls.pos_z", "RLS Position Z", base.DEC)

function rlsProtocol32.dissector(buffer, pinfo, tree)
if buffer:len() == 0 then return false end
if buffer(0, 1):uint() ~= 0x03 then return false end
if buffer(1, 2):uint() < 0x0302 then return false end

pinfo.cols.protocol = rlsProtocol32.name

local versionNumber = buffer(1, 1):uint() .. "." .. buffer(2, 1):uint() .. "." .. buffer(3, 1):uint()
local subtree = tree:add(rlsProtocol32, buffer(), "UERANSIM Radio Link Simulation (RLS) protocol")

subtree:add(fields.Version, buffer(1, 3), versionNumber)
subtree:add(fields.MsgType, buffer(4, 1))
local msgType = buffer(4, 1):uint()

pinfo.cols.info = msgTypeNames[msgType]
subtree:add(fields.Sti, buffer(5, 8))

if msgType == 4 then -- Heartbeat
subtree:add(fields.PosX, buffer(13,4))
subtree:add(fields.PosY, buffer(17,4))
subtree:add(fields.PosZ, buffer(21,4))
elseif msgType == 5 then -- Heartbeat ACK
subtree:add(fields.Dbm, buffer(13,4))
elseif msgType == 6 then -- PDU Transmission
local pduType = buffer(13, 1):uint()
subtree:add(fields.PduType, buffer(13, 1))
subtree:add(fields.PduId, buffer(14, 4))
if pduType == 1 then -- RRC PDU
local rrcMsgType = buffer(18, 4):uint()
local pduLength = buffer(22, 4):uint()
subtree:add(fields.RrcMsgType, buffer(18, 4))
subtree:add(fields.PduLength, buffer(22, 4))
-- Old versions of Wireshark (< 3.0.0) cannot handle NR-RRC correctly
local dissector
local function get_dissector()
dissector = Dissector.get(nrRrcDissectors[rrcMsgType])
end
if pcall(get_dissector) then
dissector:call(buffer(26, pduLength):tvb(), pinfo, tree)
else
pinfo.cols.info = msgTypeNames[msgType]
.. " - " .. rrcMsgTypeNames[rrcMsgType]
.. " - Cannot decode"
return false
end
elseif (pduType == 2) then -- Data PDU
subtree:add(fields.PduSessionId, buffer(18, 4))
local pduLength = buffer(22, 4):uint()
subtree:add(fields.PduLength, buffer(22, 4))
Dissector.get("ip"):call(buffer(26, pduLength):tvb(), pinfo, tree)
end
elseif msgType == 7 then -- PDU Transmission ACK
local ackCount = buffer(13, 4):uint()
local ackArray = subtree:add(rlsProtocol32, buffer(13, 4), "Acknowledge List (" .. ackCount .. ")")
for i = 1,ackCount,1 do
ackArray:add(fields.AcknowledgeItem, buffer(17 + (i - 1) * 4, 4))
end
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)
Loading