1 /* packet-ipsi-ctl.c
2  * Routines for Avaya IPSI Control packet disassembly
3  * Traffic is encapsulated Avaya proprietary CCMS
4  * (Control Channel Message Set) between PCD and SIM
5  *
6  * Copyright 2008, Randy McEoin <rmceoin@ahbelo.com>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * SPDX-License-Identifier: GPL-2.0-or-later
13  */
14 
15 #include "config.h"
16 
17 #include <epan/packet.h>
18 
19 void proto_register_ipsictl(void);
20 void proto_reg_handoff_ipsictl(void);
21 
22 #define IPSICTL_PORT            5010 /* Not IANA registered */
23 #define IPSICTL_PDU_MAGIC       0x0300
24 
25 static int proto_ipsictl = -1;
26 
27 static int hf_ipsictl_pdu = -1;
28 static int hf_ipsictl_magic = -1;
29 static int hf_ipsictl_length = -1;
30 static int hf_ipsictl_type = -1;
31 static int hf_ipsictl_sequence = -1;
32 static int hf_ipsictl_field1 = -1;
33 static int hf_ipsictl_data = -1;
34 
35 static gint ett_ipsictl = -1;
36 static gint ett_ipsictl_pdu = -1;
37 
38 static int dissect_ipsictl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
39 {
40 
41   proto_tree   *ipsictl_tree;
42   proto_tree   *pdu_tree;
43   proto_item   *ti;
44   int           offset = 0;
45   int           loffset = 0;
46   int           llength = 0;
47   int           remaining_length;
48   guint16       magic;
49   guint16       length;
50   guint16       type=0;
51   guint16       sequence=0;
52   int           first_sequence=-1;
53   int           last_sequence=-1;
54   guint16       field1=0;
55   guint16       pdu=0;
56   int           haspdus=0;
57 
58   remaining_length=tvb_reported_length_remaining(tvb, offset);
59 
60   ti = proto_tree_add_item(tree, proto_ipsictl, tvb, offset, remaining_length, ENC_NA);
61   ipsictl_tree = proto_item_add_subtree(ti, ett_ipsictl);
62 
63   magic = tvb_get_ntohs(tvb, offset);
64   if (magic == IPSICTL_PDU_MAGIC)
65   {
66     haspdus=1;
67   }
68 
69   while (haspdus &&
70     ((remaining_length=tvb_reported_length_remaining(tvb, offset)) > 6))
71   {
72     loffset = offset;
73 
74     magic = tvb_get_ntohs(tvb, loffset); loffset+=2;
75     length = tvb_get_ntohs(tvb, loffset); loffset+=2;
76     llength=length;
77     remaining_length-=4;
78     if (remaining_length>=2)
79     {
80       type = tvb_get_ntohs(tvb, loffset); loffset+=2;
81       remaining_length-=2;
82       llength-=2;
83     }
84     if (remaining_length>=2)
85     {
86       sequence = tvb_get_ntohs(tvb, loffset); loffset+=2;
87       remaining_length-=2;
88       llength-=2;
89       if (first_sequence==-1)
90       {
91         first_sequence=sequence;
92       }else{
93         last_sequence=sequence;
94       }
95     }
96     if (remaining_length>=2)
97     {
98       field1 = tvb_get_ntohs(tvb, loffset);
99       llength-=2;
100     }
101 
102     ti = proto_tree_add_uint(ipsictl_tree, hf_ipsictl_pdu, tvb,
103            offset, (length+4), pdu);
104     pdu_tree = proto_item_add_subtree(ti, ett_ipsictl_pdu);
105 
106     loffset=offset;
107     remaining_length=tvb_reported_length_remaining(tvb, offset);
108 
109     if (tree) {
110       proto_tree_add_uint(pdu_tree, hf_ipsictl_magic, tvb, loffset, 2, magic);
111     }
112     loffset+=2; remaining_length-=2;
113     if (tree) {
114       proto_tree_add_uint(pdu_tree, hf_ipsictl_length, tvb, loffset, 2, length);
115     }
116     loffset+=2; remaining_length-=2;
117 
118     if (remaining_length>=2)
119     {
120       if (tree) {
121         proto_tree_add_uint(pdu_tree, hf_ipsictl_type, tvb, loffset, 2, type);
122       }
123       loffset+=2; remaining_length-=2;
124     }
125     if (remaining_length>=2)
126     {
127       if (tree) {
128         proto_tree_add_uint(pdu_tree, hf_ipsictl_sequence, tvb, loffset, 2, sequence);
129       }
130       loffset+=2; remaining_length-=2;
131     }
132     if (remaining_length>=2)
133     {
134       if (tree) {
135         proto_tree_add_uint(pdu_tree, hf_ipsictl_field1, tvb, loffset, 2, field1);
136       }
137       loffset+=2; remaining_length-=2;
138     }
139     if (remaining_length>=2)
140     {
141       if (tree) {
142         proto_tree_add_item(pdu_tree, hf_ipsictl_data, tvb, loffset, llength, ENC_NA);
143       }
144       loffset+=llength;
145     }
146 
147     offset=loffset;
148     pdu++;
149   }
150 
151   if (!haspdus)
152   {
153     proto_tree_add_item(ipsictl_tree, hf_ipsictl_data, tvb, offset, -1, ENC_NA);
154   }
155 
156   col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPSICTL");
157 
158   if (haspdus)
159   {
160     if (last_sequence==-1)
161     {
162       col_add_fstr(pinfo->cinfo, COL_INFO, "PDUS=%d, Seq=0x%04x",
163         pdu,first_sequence);
164     }else{
165       col_add_fstr(pinfo->cinfo, COL_INFO, "PDUS=%d, Seq=0x%04x-0x%04x",
166         pdu,first_sequence,last_sequence);
167     }
168   }else{
169     col_set_str(pinfo->cinfo, COL_INFO, "Initialization");
170   }
171 
172   return tvb_captured_length(tvb);
173 
174 } /* dissect_ipsictl */
175 
176 void proto_register_ipsictl(void)
177 {
178 
179   static hf_register_info hf[] = {
180     { &hf_ipsictl_pdu,
181       { "PDU",  "ipsictl.pdu",
182         FT_UINT16,      BASE_DEC,       NULL,   0x0,
183         "IPSICTL PDU", HFILL }},
184     { &hf_ipsictl_magic,
185       { "Magic",        "ipsictl.magic",
186         FT_UINT16,      BASE_HEX,       NULL,   0x0,
187         "IPSICTL Magic", HFILL }},
188     { &hf_ipsictl_length,
189       { "Length",       "ipsictl.length",
190         FT_UINT16,      BASE_HEX,       NULL,   0x0,
191         "IPSICTL Length", HFILL }},
192     { &hf_ipsictl_type,
193       { "Type", "ipsictl.type",
194         FT_UINT16,      BASE_HEX,       NULL,   0x0,
195         "IPSICTL Type", HFILL }},
196     { &hf_ipsictl_sequence,
197       { "Sequence",     "ipsictl.sequence",
198         FT_UINT16,      BASE_HEX,       NULL,   0x0,
199         "IPSICTL Sequence", HFILL }},
200     { &hf_ipsictl_field1,
201       { "Field1",       "ipsictl.field1",
202         FT_UINT16,      BASE_HEX,       NULL,   0x0,
203         "IPSICTL Field1", HFILL }},
204     { &hf_ipsictl_data,
205       { "Data", "ipsictl.data",
206         FT_BYTES,       BASE_NONE,      NULL,   0x0,
207         "IPSICTL data", HFILL }},
208   };
209 
210   static gint *ett[] = {
211     &ett_ipsictl,
212     &ett_ipsictl_pdu
213   };
214 
215   proto_ipsictl = proto_register_protocol("IPSICTL", "IPSICTL", "ipsictl");
216   proto_register_field_array(proto_ipsictl, hf, array_length(hf));
217   proto_register_subtree_array(ett, array_length(ett));
218 
219 }
220 
221 void proto_reg_handoff_ipsictl(void)
222 {
223 
224   dissector_handle_t ipsictl_handle = NULL;
225 
226   ipsictl_handle = create_dissector_handle(dissect_ipsictl, proto_ipsictl);
227 
228   dissector_add_uint_with_preference("tcp.port", IPSICTL_PORT, ipsictl_handle);
229 
230 }
231 
232 /*
233  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
234  *
235  * Local Variables:
236  * c-basic-offset: 2
237  * tab-width: 8
238  * indent-tabs-mode: nil
239  * End:
240  *
241  * ex: set shiftwidth=2 tabstop=8 expandtab:
242  * :indentSize=2:tabSize=8:noTabs=true:
243  */
244