aboutsummaryrefslogtreecommitdiff
path: root/wireshark/txhdr.lua
blob: f70f983ad5a796397e4b09f0fa7b50f18175f4b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
local p = Proto("txhdr", "Hardware TX header")

-- based off <https://www.problemkaputt.de/gbatek.htm#dswifihardwareheaders>

p.fields.unknown = ProtoField.bytes("txhdr.unknown", "Unknown")

p.fields.status = ProtoField.uint16("txhdr.status", "Status", base.DEC, {
	[0x00] = "Retrying?",
	[0x01] = "OK",
	[0x03] = "Failed",
	[0x05] = "Failed",
}, 0x00ff)
p.fields.new = ProtoField.bool("txhdr.new", "New frame")
p.fields.rate = ProtoField.uint8("txhdr.rate", "Transfer rate", base.HEX)
p.fields.channel = ProtoField.uint8("txhdr.channel", "802.11 channel")
p.fields.length = ProtoField.uint16("txhdr.len", "Remaining message length")
p.fields.data = ProtoField.bytes("txhdr.data", "Remaining message")

local ieee_dissector = Dissector.get("ieee")

function p.dissector(buffer, pinfo, tree)
	local header_size = 12
	-- check buffer size
	if buffer:len() < header_size then return 0 end

	local subtree = tree:add(p, buffer(0, header_size), string.format("%s: %d bytes", p.description, header_size))

	subtree:add_le(p.fields.status, buffer(0x00, 2))
	subtree:add_le(p.fields.new, buffer(0x02, 2))
	subtree:add_le(p.fields.unknown, buffer(0x04, 1))
	subtree:add_le(p.fields.unknown, buffer(0x05, 1))
	subtree:add_le(p.fields.unknown, buffer(0x06, 2))
	local rate_field = subtree:add_le(p.fields.rate, buffer(0x08, 1))
  rate_field:append_text(string.format(" (%1.1f Mbit/s)", buffer(0x08, 1):uint() / 10))
	subtree:add_le(p.fields.channel, buffer(0x09, 1))
	subtree:add_le(p.fields.length, buffer(0x0a, 2))
	local length = buffer(0x0a, 2):le_uint()
  subtree:add(p.fields.data, buffer(0x0c, length))

	-- pretty wireshark shit
	pinfo.cols.protocol = p.name

	ieee_dissector:call(buffer(header_size, length):tvb(), pinfo, tree)

	return header_size
end