initial wireshark dissector
[gs105e.git] / wireshark / nsdp.lua
1 -- create nsdp protocol and its fields
2 p_nsdp = Proto ("nsdp","Netgear Switch Description Protocol")
3 -- local f_source = ProtoField.uint16("nsdp.src", "Source", base.HEX)
4 local f_type = ProtoField.uint16("nsdp.type", "Type", base.HEX)
5 local f_source = ProtoField.ether("nsdp.src", "Source", base.HEX)
6 local f_destination = ProtoField.ether("nsdp.dst", "Destination", base.HEX)
7 local f_seq = ProtoField.uint16("nsdp.seq", "Seq", base.HEX)
8 local f_data = ProtoField.string("nsdp.data", "Data", FT_STRING)
9 local f_cmd = ProtoField.uint16("nsdp.cmd", "Command", base.HEX)
10 local f_password = ProtoField.string("nsdp.password", "Password", FT_STRING)
11 local f_newpassword = ProtoField.string("nsdp.newpassword", "New password", FT_STRING)
12
13 --local f_debug = ProtoField.uint8("nsdp.debug", "Debug")
14 p_nsdp.fields = {f_type,f_source,f_destination,f_seq,f_cmd,f_password,f_newpassword}
15
16 -- nsdp dissector function
17 function p_nsdp.dissector (buf, pkt, root)
18   -- validate packet length is adequate, otherwise quit
19   if buf:len() == 0 then return end
20   pkt.cols.protocol = p_nsdp.name
21
22   -- create subtree for nsdp
23   subtree = root:add(p_nsdp, buf(0))
24   local offset = 0
25   local ptype = buf(offset,2):uint()
26   subtree:add(f_type, ptype)
27   offset = offset + 8
28   subtree:add(f_source, buf(offset,6))
29   offset = offset + 6
30   subtree:add(f_destination, buf(offset,6))
31   offset = offset + 8
32   subtree:add(f_seq, buf(offset,2))
33   offset = offset + 10
34   local cmd = 0
35   if offset < buf:len() then
36     cmd = buf(offset, 2):uint()
37     offset = offset + 2
38   end
39   subtree:add(f_cmd, cmd)
40
41   if cmd == 1 then
42     subtree:append_text(", init")
43   elseif cmd == 0xa or (ptype == 0x0104 and cmd == 0) then
44     if ptype == 0x0103 then
45       local pw_len = buf(offset, 2):uint()
46       offset = offset + 2
47       subtree:add(f_password, buf(offset,pw_len))
48       offset = offset + pw_len
49       local next_up = buf(offset, 2):uint()
50       offset = offset + 2
51       if next_up == 0x0009 then
52         subtree:append_text(", reset password")
53         pw_len = buf(offset, 2):uint()
54         offset = offset + 2
55         subtree:add(f_newpassword, buf(offset,pw_len))
56       else
57         subtree:append_text(", login")
58       end
59     elseif ptype == 0x0104 then
60       if buf:len() == offset then
61         subtree:append_text(", password changed")
62       else
63         subtree:append_text(", logged in")
64       end
65     end
66   end
67 end
68
69 function p_nsdp.init()
70   -- init
71 end
72
73 local tcp_dissector_table = DissectorTable.get("udp.port")
74 dissector = tcp_dissector_table:get_dissector(63321)
75 tcp_dissector_table:add(63321, p_nsdp)
76
77 local tcp_dissector_table = DissectorTable.get("udp.port")
78 dissector = tcp_dissector_table:get_dissector(63322)
79 tcp_dissector_table:add(63322, p_nsdp)