blob: 1deed19275790191101087671ae2331dfc7ce5c4 [file] [log] [blame]
Holger Hans Peter Freyther629f94e2010-10-20 16:56:46 +02001-- Split trace based on SCCP Source
2do
3 local function init_listener()
4 print("CREATED LISTENER")
Holger Hans Peter Freytherf62d31f2010-10-20 18:57:17 +02005 local tap = Listener.new("ip", "sccp && (ip.src == 172.16.1.81 || ip.dst == 172.16.1.81)")
Holger Hans Peter Freyther629f94e2010-10-20 16:56:46 +02006 local sccp_type_field = Field.new("sccp.message_type")
7 local sccp_src_field = Field.new("sccp.slr")
8 local sccp_dst_field = Field.new("sccp.dlr")
9 local msg_type_field = Field.new("gsm_a.dtap_msg_mm_type")
10 local lu_rej_field = Field.new("gsm_a.dtap.rej_cause")
11 local ip_src_field = Field.new("ip.src")
12 local ip_dst_field = Field.new("ip.dst")
13
Holger Hans Peter Freyther8d4696f2010-10-20 18:58:12 +020014 --
15 local bssmap_msgtype_field = Field.new("gsm_a.bssmap_msgtype")
16 -- assignment failure 0x03
17 --
18
19 --
20 local dtap_cause_field = Field.new("gsm_a_dtap.cause")
21 local dtap_cc_field = Field.new("gsm_a.dtap_msg_cc_type")
22
Holger Hans Peter Freyther629f94e2010-10-20 16:56:46 +020023 local connections = {}
24
25 function check_failure(con)
Holger Hans Peter Freyther8d4696f2010-10-20 18:58:12 +020026 check_lu_reject(con)
27 check_disconnect(con)
Holger Hans Peter Freyther0c0fb1e2010-10-20 19:15:06 +020028 check_failures(con)
Holger Hans Peter Freytherd84fcba2010-10-20 19:08:49 +020029 end
30
31 -- cipher mode reject
Holger Hans Peter Freyther0c0fb1e2010-10-20 19:15:06 +020032 function check_failures(con)
Holger Hans Peter Freytherd84fcba2010-10-20 19:08:49 +020033 local msgtype = bssmap_msgtype_field()
34 if not msgtype then
35 return
36 end
37
Holger Hans Peter Freyther0c0fb1e2010-10-20 19:15:06 +020038 msgtype = tonumber(msgtype)
39 if msgtype == 89 then
40 print("Cipher mode reject")
Holger Hans Peter Freytherd84fcba2010-10-20 19:08:49 +020041 con[4] = true
Holger Hans Peter Freyther0c0fb1e2010-10-20 19:15:06 +020042 elseif msgtype == 0x03 then
43 print("Assignment failure")
Holger Hans Peter Freyther33e42812010-10-20 19:06:50 +020044 con[4] = true
45 end
Holger Hans Peter Freyther8d4696f2010-10-20 18:58:12 +020046 end
47
48 -- check if a DISCONNECT is normal
49 function check_disconnect(con)
50 local msg_type = dtap_cc_field()
51 if not msg_type then
52 return
53 end
54
55 if tonumber(msg_type) ~= 0x25 then
56 return
57 end
58
59 local cause = dtap_cause_field()
60 if not cause then
61 return
62 end
63
64 cause = tonumber(cause)
65 if cause ~= 0x10 then
66 print("DISCONNECT != Normal")
67 con[4] = true
68 end
69 end
70
71 -- check if we have a LU Reject
72 function check_lu_reject(con)
Holger Hans Peter Freyther629f94e2010-10-20 16:56:46 +020073 local msg_type = msg_type_field()
74 if not msg_type then
75 return
76 end
77
78 msg_type = tonumber(tostring(msg_type))
79 if msg_type == 0x04 then
80 print("LU REJECT with " .. tostring(lu_rej_field()))
81 con[4] = true
82 end
83 end
84
85 function tap.packet(pinfo,tvb,ip)
86 local ip_src = tostring(ip_src_field())
87 local ip_dst = tostring(ip_dst_field())
88 local sccp_type = tonumber(tostring(sccp_type_field()))
89 local sccp_src = sccp_src_field()
90 local sccp_dst = sccp_dst_field()
91
92 local con
93
94 if sccp_type == 0x01 then
95 elseif sccp_type == 0x2 then
96 local src = string.format("%s-%s", ip_src, tostring(sccp_src))
97 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
98 local datestring = os.date("%Y%m%d%H%M%S")
99 local pcap_name = string.format("alink_trace_%s-%s_%s.pcap", src, dst, datestring)
100 local dumper = Dumper.new_for_current(pcap_name)
101
102 local con = { ip_src, tostring(sccp_src), tostring(sccp_dst), false, dumper, pcap_name }
103
104 dumper:dump_current()
105 connections[src] = con
106 connections[dst] = con
107 elseif sccp_type == 0x4 then
108 -- close a connection... remove it from the list
109 local src = string.format("%s-%s", ip_src, tostring(sccp_src))
110 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
111
112 local con = connections[src]
113 if not con then
114 return
115 end
116
117 con[5]:dump_current()
118 con[5]:flush()
119
120 -- this causes a crash on unpacted wireshark
121 con[5]:close()
122
123 -- the connection had a failure
124 if con[4] == true then
125 local datestring = os.date("%Y%m%d%H%M%S")
126 local new_name = string.format("alink_failure_%s_%s-%s.pcap", datestring, con[2], con[3])
127 os.rename(con[6], new_name)
128 else
129 os.remove(con[6])
130 end
131
132
133 -- clear the old connection
134 connections[src] = nil
135 connections[dst] = nil
136
137 elseif sccp_type == 0x5 then
138 -- not handled yet... we should verify stuff here...
139 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
140 local con = connections[dst]
141 if not con then
142 return
143 end
144 con[5]:dump_current()
145 elseif sccp_type == 0x6 then
146 local dst = string.format("%s-%s", ip_dst, tostring(sccp_dst))
147 local con = connections[dst]
148 if not con then
149 print("DON'T KNOW THIS CONNECTION for " .. ip_dst)
150 return
151 end
152 con[5]:dump_current()
153 check_failure(con)
154 end
155
156 end
157 function tap.draw()
158 print("DRAW")
159 end
160 function tap.reset()
161 print("RESET")
162 end
163 end
164
165 init_listener()
166end