-
Notifications
You must be signed in to change notification settings - Fork 5
/
seismocloud.lua
185 lines (151 loc) · 5.13 KB
/
seismocloud.lua
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
-- Script Wireshark for SeismoCloud local command interface decoding (app<->device)
-- Add into init.lua this line (without "--"):
-- dofile("seismocloud.lua")
-- You should place this file into the same directory of "init.lua"
seismoproto = Proto("seismoproto", "SeismoCloud Protocol")
function mac2string(buffer, i)
return string.format('%02X', buffer(i, 1):uint())
.. string.format('%02X', buffer(i+1, 1):uint())
.. string.format('%02X', buffer(i+2, 1):uint())
.. string.format('%02X', buffer(i+3, 1):uint())
.. string.format('%02X', buffer(i+4, 1):uint())
.. string.format('%02X', buffer(i+5, 1):uint());
end
function hex2float (c)
if c == 0 then return 0.0 end
local c = string.gsub(string.format("%08X", c),"(..)",function (x) return string.char(tonumber(x, 16)) end)
local b1,b2,b3,b4 = string.byte(c, 1, 4)
local sign = b1 > 0x7F
local expo = (b1 % 0x80) * 0x2 + math.floor(b2 / 0x80)
local mant = ((b2 % 0x80) * 0x100 + b3) * 0x100 + b4
if sign then
sign = -1
else
sign = 1
end
local n
if mant == 0 and expo == 0 then
n = sign * 0.0
elseif expo == 0xFF then
if mant == 0 then
n = sign * math.huge
else
n = 0.0/0.0
end
else
n = sign * math.ldexp(1.0 + mant / 0x800000, expo - 0x7F)
end
return n
end
function seismoproto.dissector(buffer, pinfo, tree)
pinfo.cols.protocol = "SEISMOPROTO"
if buffer(0, 4):uint() == 0x494e4756 then -- INGV in hex
local i = 0
local subtree = tree:add(seismoproto, buffer(), "SeismoCloud Protocol Data")
subtree:add(buffer(i, 5), i .. ": Magic bytes")
i = i + 5
local command = "UNKNOWN"
local cmdbyte = buffer(i, 1):uint()
if cmdbyte == 1 then
command = "DISCOVERY"
elseif cmdbyte == 2 then
command = "DISCOVERY_REPLY"
elseif cmdbyte == 3 then
command = "PING"
elseif cmdbyte == 4 then
command = "PONG"
elseif cmdbyte == 5 then
command = "STREAM_START"
elseif cmdbyte == 6 then
command = "STREAM_STOP"
elseif cmdbyte == 7 then
command = "SENDGPS"
elseif cmdbyte == 8 then
command = "OK"
elseif cmdbyte == 9 then
command = "SETSYSLOG"
elseif cmdbyte == 10 then
command = "REBOOT"
elseif cmdbyte == 11 then
command = "GETINFO"
elseif cmdbyte == 12 then
command = "GETINFO_REPLY"
end
subtree:add(buffer(i, 1), i .. ": " .. command .. " command")
i = i + 1
if cmdbyte == 2 then -- DISCOVERY_REPLY
subtree:add(buffer(i, 6), i .. ": MAC Address: " .. mac2string(buffer, i));
i = i + 6
subtree:add(buffer(i, 4), i .. ": Version")
i = i + 4
subtree:add(buffer(i, 8), i .. ": Model")
i = i + 8
elseif cmdbyte == 7 then
subtree:add(buffer(i, 6), i .. ": Dest. MAC Address: " .. mac2string(buffer, i));
i = i + 6
local lat = buffer(i, 1):uint() * 16777216
+ buffer(i+1, 1):uint() * 65536
+ buffer(i+2, 1):uint() * 256
+ buffer(i+3, 1):uint();
subtree:add(buffer(i, 4), i .. ": GPS Latitude: " .. hex2float(lat))
i = i + 4
local lon = buffer(i, 1):uint() * 16777216
+ buffer(i+1, 1):uint() * 65536
+ buffer(i+2, 1):uint() * 256
+ buffer(i+3, 1):uint();
subtree:add(buffer(i, 4), i .. ": GPS Longitude: " .. hex2float(lon))
i = i + 4
elseif cmdbyte == 12 then
subtree:add(buffer(i, 6), i .. ": Dest. MAC Address: " .. mac2string(buffer, i));
i = i + 6
subtree:add(buffer(i, 4), i .. ": SYSLOG server");
i = i + 4
subtree:add(buffer(i, 4), i .. ": X threshold");
i = i + 4
subtree:add(buffer(i, 4), i .. ": Y threshold");
i = i + 4
subtree:add(buffer(i, 4), i .. ": Z threshold");
i = i + 4
subtree:add(buffer(i, 4), i .. ": Uptime: " .. buffer(i, 4):uint());
i = i + 4
subtree:add(buffer(i, 4), i .. ": UNIX time: " .. buffer(i, 4):uint());
i = i + 4
subtree:add(buffer(i, 4), i .. ": Software version");
i = i + 4
subtree:add(buffer(i, 4), i .. ": Free RAM");
i = i + 4
subtree:add(buffer(i, 4), i .. ": Latency");
i = i + 4
subtree:add(buffer(i, 4), i .. ": NTP server");
i = i + 4
local b = i
local strsize = 0
while buffer(b, 1):uint() > 0 do
strsize = strsize + 1
b = b + 1
end
subtree:add(buffer(i, strsize), i .. ": HTTP Base address")
i = i + strsize
b = i
strsize = 0
while buffer(b, 1):uint() > 0 do
strsize = strsize + 1
b = b + 1
end
subtree:add(buffer(i, strsize), i .. ": Platform name")
i = i + strsize
b = i
strsize = 0
while buffer(b, 1):uint() > 0 do
strsize = strsize + 1
b = b + 1
end
subtree:add(buffer(i, strsize), i .. ": Accelerometer name")
i = i + strsize
subtree:add(buffer(i, 4), i .. ": Probe Speed (values/sec)");
i = i + 4
end
end
end
udp_table = DissectorTable.get("udp.port")
udp_table:add(62001, seismoproto)