diff options
| author | s-ol <s+removethis@s-ol.nu> | 2024-02-18 18:41:59 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2024-02-18 18:41:59 +0000 |
| commit | 673f633d34b1919a1ce4ba57376502a1cf3f0259 (patch) | |
| tree | 1a1566cbede821141785a8dd7bec5cef3ba322f2 /pl2303.lua | |
| download | t937-serial-673f633d34b1919a1ce4ba57376502a1cf3f0259.tar.gz t937-serial-673f633d34b1919a1ce4ba57376502a1cf3f0259.zip | |
initial commit
Diffstat (limited to 'pl2303.lua')
| -rwxr-xr-x | pl2303.lua | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/pl2303.lua b/pl2303.lua new file mode 100755 index 0000000..579057e --- /dev/null +++ b/pl2303.lua @@ -0,0 +1,46 @@ +local pl2303_bulk = Proto("pl2303.bulk", "PL2303 Serial Data")
+
+local ep_dir_f = Field.new("usb.endpoint_address.direction")
+
+local data_in_F = ProtoField.bytes("pl2303.bulk.data_in", "Data In")
+local data_out_F = ProtoField.bytes("pl2303.bulk.data_out", "Data Out")
+
+pl2303_bulk.fields = {
+ data_in_F,
+ data_out_F,
+}
+
+local serial_tbl = DissectorTable.heuristic_new("pl2303.serial_data", pl2303_bulk)
+
+function pl2303_bulk.dissector(buffer, pinfo, tree)
+ if buffer:captured_len() < 1 then return end
+
+ local sub = tree:add(pl2303_bulk, buffer())
+ pinfo.cols.info:set("PL2303 Serial")
+
+ local ep_dir = ep_dir_f()() -- 0: h2d, 1: d2h
+ if ep_dir == 0 then
+ pinfo.cols.info:append(" out")
+ pinfo.p2p_dir = P2P_DIR_SENT
+ sub:add(data_out_F, buffer())
+ else
+ pinfo.cols.info:append(" in")
+ pinfo.p2p_dir = P2P_DIR_RECV
+ sub:add(data_in_F, buffer())
+ end
+
+ DissectorTable.try_heuristics("pl2303.serial_data", buffer, pinfo, tree)
+end
+
+function usb_protocol_key(class, subclass, protocol)
+ return bit.bor(
+ bit.lshift(1, 31),
+ bit.lshift(bit.band(class, 0xff), 16),
+ bit.lshift(bit.band(subclass, 0xff), 8),
+ bit.band(protocol, 0xff)
+ )
+end
+
+local bulk_table = DissectorTable.get("usb.bulk")
+bulk_table:add(usb_protocol_key(0xff, 0x00, 0x00), pl2303_bulk)
+bulk_table:add(0xffff, pl2303_bulk)
|
