- dist fix
[oweals/gnunet.git] / bin / wireshark.lua
1 -- declare our protocol
2 gwlan_proto = Proto("gnunet","Gnunet Layer")
3 -- create a function to dissect it
4 local f = gwlan_proto.fields
5
6 f.len = ProtoField.uint16 ("gnunet.len", "Gnunet Message Len")
7 f.type = ProtoField.uint16 ("gnunet.type", "Gnunet Message Type")
8 -- rhs_proto.fields.sequence = ProtoField.uint16("rhs.sequence","Sequence number")
9 f_proto = DissectorTable.new("gnunet.proto", "Gnunet Protocoll", FT_UINT16, BASE_DEC)
10 --gwlan_proto.fields = {f_len, f_type}
11
12 function gwlan_proto.dissector(buffer,pinfo,tree)
13         pinfo.cols.protocol = "Gnunet Packet"
14         gnunet_packet_disector(buffer,pinfo,tree)
15 end
16
17 function gwlan_proto.init()
18 end
19
20 function gnunet_packet_disector(buffer,pinfo,tree)
21         if (buffer:len() > 4) then
22                 local len = buffer(0,2):uint()
23                         local type = buffer(2,2):uint()
24                 if (len <= buffer:len()) then
25                         local dissect = f_proto:get_dissector(type)
26                         if dissect ~= nil then
27                                 dissect:call(buffer(0, len):tvb(), pinfo, tree)
28                         else
29                                 local subtree = tree:add(fragmentack, buffer(),"Gnunet Packet Type: " .. buffer(2,2):uint() .. "(" .. buffer:len() .. ")")
30                                 gnunet_message_header(buffer, pinfo, subtree)
31                         end
32                 end
33                 --if (len < buffer:len()) then
34                 --      gwlan_proto.dissector(buffer(len, buffer:len() - len):tvb(), pinfo, tree)
35                 --end
36         else
37                 if (buffer:len() == 4) then
38                         local subtree = tree:add(fragmentack, buffer(),"Gnunet Packet (" .. buffer:len() .. ")")
39                         gnunet_message_header(buffer, pinfo, subtree)
40                 end
41         end
42 end
43
44 function gnunet_message_header(buffer, pinfo, tree)
45         if (buffer:len() >= 4) then
46                 local len = buffer(0,2)
47                 local type = buffer(2,2)
48                 tree:add(buffer(0,2), "Message Len: " .. buffer(0,2):uint())
49                 tree:add(buffer(2,2), "Message Type: " .. buffer(2,2):uint())
50         end
51 end
52
53 -- load the udp.port table
54 llc_table = DissectorTable.get("llc.dsap")
55 -- register our protocol to handle llc.dsap 0x1e
56 llc_table:add(31,gwlan_proto)
57
58 fragmentack = Proto("gnunet.fragmentack","Gnunet Fragment Ack")
59
60 function fragmentack.dissector(buffer,pinfo,tree)
61         pinfo.cols.protocol = "Gnunet Fragment Ack"
62         local subtree = tree:add(fragmentack, buffer(),"Gnunet Data ack (" .. buffer:len() .. ")")
63         gnunet_message_header(buffer, pinfo, subtree)
64         if buffer:len() >= 16 then
65                 subtree:add(buffer(4,4),"Fragment Id: " .. buffer(4,4):uint())
66                 subtree:add(buffer(8,8),"Bits: " .. buffer(8,8))
67         end
68 end
69
70 fragment = Proto("gnunet.fragment","Gnunet Fragment")
71
72 function fragment.dissector(buffer,pinfo,tree)
73         pinfo.cols.protocol = "Gnunet Fragment"
74         local subtree = tree:add(fragment, buffer(),"Gnunet Fragment (" .. buffer:len() .. ")")
75         gnunet_message_header(buffer, pinfo, subtree)
76         if buffer:len() >= 13 then
77                 subtree:add(buffer(4,4),"Fragment Id: " .. buffer(4,4):uint())
78                 subtree:add(buffer(8,2),"Total Size: " .. buffer(8,2):uint())
79                 subtree:add(buffer(10,2),"Offset: " .. buffer(10,2):uint())
80                 if buffer(10,2):uint() == 0 then
81                         if (buffer(8,2):uint() <= buffer:len() - 12) then
82                                 gnunet_packet_disector(buffer(12):tvb(),pinfo,tree)
83                         end 
84                 else            
85                         subtree:add(buffer(12), "Data: " .. buffer(12))
86                 end
87         end
88 end
89
90 hello = Proto("gnunet.hello","Gnunet Hello Message")
91
92 function hello.dissector(buffer,pinfo,tree)
93         pinfo.cols.protocol = "Gnunet Hello Message"
94         local subtree = tree:add(hello, buffer(),"Gnunet Hello Message (" .. buffer:len() .. ")")
95         gnunet_message_header(buffer, pinfo, subtree)           
96         if buffer:len() > (264 + 8) then
97                 subtree:add(buffer(4,4),"Reserved: " .. buffer(4,4):uint())
98                 RsaPublicKeyBinaryEncoded(buffer(8 , 264):tvb(),pinfo, subtree)
99         else
100                 subtree:add(buffer(4), "SIZE WRONG (< 272)")
101         end
102 end
103
104 wlan = Proto("gnunet.wlan","Gnunet WLAN Message")
105
106 function wlan.dissector(buffer,pinfo,tree)
107         pinfo.cols.protocol = "Gnunet WLAN Message"
108         local subtree = tree:add(wlan, buffer(),"Gnunet WLAN Message (" .. buffer:len() .. ")")
109         gnunet_message_header(buffer, pinfo, subtree)
110         if buffer:len() > (4 + 4 + 2*64) then
111                 subtree:add(buffer(4,4),"CRC: " .. buffer(4,4):uint())
112                 local peer = GNUNET_PeerIdentity(buffer(8,64), pinfo, subtree)
113                 peer:append_text(" Traget")
114                 peer = GNUNET_PeerIdentity(buffer(8 + 64,64), pinfo, subtree)
115                 peer:append_text(" Source")
116         else
117                 subtree:add(buffer(8), "SIZE WRONG (< 4 + 4 + 2*64)")
118         end
119         if (buffer:len() - (4 + 4 + 2*64) > 0) then
120                 gnunet_packet_disector(buffer(4 + 4 + 2*64):tvb(),pinfo,tree)
121         end 
122 end
123
124 function RsaPublicKeyBinaryEncoded(buffer,pinfo,tree)
125         local subtree = tree:add(gwlan_proto,buffer(),"Gnunet RsaPublicKeyBinaryEncoded(" .. buffer:len() .. ")")
126         subtree:add(buffer(0,2),"Len: " .. buffer(0,2):uint())
127         subtree:add(buffer(2,2),"Sizen: " .. buffer(2,2):uint())
128         subtree:add(buffer(4,258),"Pub Key: " .. buffer(4,258))
129         subtree:add(buffer(262,2),"Padding: " .. buffer(262,2):uint())
130 end
131
132 function GNUNET_PeerIdentity(buffer,pinfo,tree)
133         local subtree = tree:add(gwlan_proto,buffer(),"Gnunet PeerIdentity(" .. buffer:len() .. ")")
134         subtree:add(buffer(0),"hashPubKey: " .. buffer(0))
135         return subtree
136 end
137
138 transport_session_keepalive = Proto("gnunet.transport_session_keepalive","Gnunet transport session keepalive")
139
140 function transport_session_keepalive.dissector(buffer,pinfo,tree)
141         pinfo.cols.protocol = "Gnunet transport session keepalive"
142         local subtree = tree:add(transport_session_keepalive, buffer(),"Gnunet transport session keepalive (" .. buffer:len() .. ")")
143         gnunet_message_header(buffer, pinfo, subtree)
144 end
145
146 f_proto:add(43,wlan)
147 f_proto:add(39,transport_session_keepalive)
148 f_proto:add(19,fragmentack)
149 f_proto:add(18,fragment)
150 f_proto:add(16,hello)