Skip to content

Commit 2beace2

Browse files
committed
capt.lua: link to packet containing IEEE 1284 ID
[citation needed]
1 parent 3e869af commit 2beace2

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

capt.lua

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ TYPE_IS_CONTROL = 0x02
108108
-- u is the Wireshark USB device number, without the endpoint number.
109109
-- e.g. 1.2.0 => 1.2
110110
--
111-
-- dev_journal[u] => (string)
112-
--
111+
-- dev_journal[u] => [s, n]
112+
-- s -- name of the device from IEEE 1284 identifier string
113+
-- n -- packet number where IEEE 1284 ID was found
113114
--
114115
-- TODO: Use formal OOP with classes with journals?
115116

@@ -134,17 +135,17 @@ local function get_status(sobj, src, dst) do
134135
return sobj[comm_id(src, dst)]
135136
end end
136137

137-
local function get_device_string(luobj, devid) do
138+
local function get_device_info(luobj, devid) do
138139
-- Returns: s, b
139-
-- s => device name string from lookup 'luobj'
140+
-- s => device info from lookup 'luobj'
140141
-- b => true if name found in journal (not placeholder)
141142
if luobj[devid] then return luobj[devid], true
142-
else return string.format(PLACEHOLDER_FMT, devid), false
143+
else return {string.format(PLACEHOLDER_FMT, devid), NO_PACKET}, false
143144
end
144145
end end
145146

146-
local function set_device_name(luobj, addrstr, name) do
147-
luobj[addrstr] = name
147+
local function set_device_info(luobj, dev_id, name, p_num) do
148+
luobj[dev_id] = {name, p_num}
148149
end end
149150

150151
local function set_status(sobj, src, dst, last_n, header_n, byte_count) do
@@ -239,6 +240,7 @@ local capt_cmd = ProtoField.uint16("capt.cmd","Command", base.HEX, opcodes)
239240
local dump = ProtoField.new("Dump", "capt.packet_dump", ftypes.BYTES)
240241
local pkt_size = ProtoField.uint16("capt.packet_size", "Packet Size", base.DEC)
241242
local payload = ProtoField.new("Payload", "capt.param_dump", ftypes.BYTES)
243+
local ref_packet = ProtoField.framenum("ref_packet", "Ref to Packet")
242244
-- PROTIP: ProtoField.new puts name argument first
243245
capt_proto.fields = {
244246
capt_comment,
@@ -250,6 +252,7 @@ capt_proto.fields = {
250252
dump,
251253
pkt_size,
252254
payload,
255+
ref_packet,
253256
}
254257

255258
local function capt_opcode_type(opcode) do
@@ -274,14 +277,25 @@ function capt_proto.dissector(buffer, pinfo, tree) do
274277
local size
275278

276279
-- TODO: consolidate common packet info to dissector dispatch
277-
-- TODO: cite packet number containing pretty print info
278280
tree:add(capt_comment, REMINDER_CLEAR_JOURNAL)
279-
local sdev, st = get_device_string(dev_journal, get_device_id(tostring(pinfo.src)))
280-
local ddev, dt = get_device_string(dev_journal, get_device_id(tostring(pinfo.dst)))
281-
tree:add(capt_src_dev_name, sdev)
282-
-- if st then pinfo.cols.src_res = sdev end -- NOTE: doesn't work on WS 2.66
283-
tree:add(capt_dst_dev_name, ddev)
284-
-- if dt then pinfo.cols.dst_res = ddev end -- NOTE: doesn't work
281+
local smdl, st = get_device_info(
282+
dev_journal, get_device_id(tostring(pinfo.src))
283+
)
284+
local sd_tree = tree:add(capt_src_dev_name, smdl[1])
285+
if st then
286+
sd_tree:add(ref_packet, smdl[2])
287+
pinfo.cols.src = smdl[1] -- NOTE: doesn't work on WS 2.66
288+
end
289+
local dmdl, dt = get_device_info(
290+
dev_journal, get_device_id(tostring(pinfo.dst))
291+
)
292+
local dd_tree = tree:add(capt_dst_dev_name, dmdl[1])
293+
if dt then
294+
dd_tree:add(ref_packet, dmdl[2])
295+
pinfo.cols.dst = dmdl[1] -- NOTE: doesn't work on WS 2.66
296+
end
297+
-- PROTIP: first index of numerically-indexed Lua tables is 1, not 0
298+
285299
if buflen >= 4 then
286300
br_opcode = buffer2(0, 2)
287301
opcode = br_opcode:le_uint()
@@ -338,7 +352,7 @@ function capt_proto.dissector(buffer, pinfo, tree) do
338352
if string.match(buffer2(0, minlen):string(), "MFG") then
339353
tmp = buffer2(1):string()
340354
tmp = string.match(tmp, "MDL%:(.-)%;")
341-
dev_journal[get_device_id(tostring(pinfo.src))] = tmp
355+
set_device_info(dev_journal, get_device_id(tostring(pinfo.src)), tmp, pinfo.number)
342356
end
343357
end
344358
end
@@ -686,7 +700,7 @@ local function init_journal()
686700
seg_status = {}
687701
seg_journal = {}
688702
dev_journal = {}
689-
dev_journal[HOST_DEV] = HOST_DEV
703+
dev_journal[HOST_DEV] = {HOST_DEV, NO_PACKET}
690704
if gui_enabled() then reload_packets() end
691705
end
692706

0 commit comments

Comments
 (0)