3608106a29d26a28d2e75d48af7ef45e6bf6067d
[metze/wireshark/wip.git] / epan / dissectors / packet-ipsi-ctl.c
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  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <epan/packet.h>
30
31 void proto_register_ipsictl(void);
32 void proto_reg_handoff_ipsictl(void);
33
34 #define IPSICTL_PORT            5010
35 #define IPSICTL_PDU_MAGIC       0x0300
36
37 static int proto_ipsictl = -1;
38
39 static int hf_ipsictl_pdu = -1;
40 static int hf_ipsictl_magic = -1;
41 static int hf_ipsictl_length = -1;
42 static int hf_ipsictl_type = -1;
43 static int hf_ipsictl_sequence = -1;
44 static int hf_ipsictl_field1 = -1;
45 static int hf_ipsictl_data = -1;
46
47 static gint ett_ipsictl = -1;
48 static gint ett_ipsictl_pdu = -1;
49
50 static void dissect_ipsictl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
51 {
52
53   proto_tree   *ipsictl_tree;
54   proto_tree   *pdu_tree;
55   proto_item   *ti;
56   int           offset = 0;
57   int           loffset = 0;
58   int           llength = 0;
59   int           remaining_length;
60   guint16       magic;
61   guint16       length;
62   guint16       type=0;
63   guint16       sequence=0;
64   int           first_sequence=-1;
65   int           last_sequence=-1;
66   guint16       field1=0;
67   guint16       pdu=0;
68   int           haspdus=0;
69
70   remaining_length=tvb_reported_length_remaining(tvb, offset);
71
72   ti = proto_tree_add_item(tree, proto_ipsictl, tvb, offset, remaining_length, ENC_NA);
73   ipsictl_tree = proto_item_add_subtree(ti, ett_ipsictl);
74
75   magic = tvb_get_ntohs(tvb, offset);
76   if (magic == IPSICTL_PDU_MAGIC)
77   {
78     haspdus=1;
79   }
80
81   while (haspdus &&
82     ((remaining_length=tvb_reported_length_remaining(tvb, offset)) > 6))
83   {
84     loffset = offset;
85
86     magic = tvb_get_ntohs(tvb, loffset); loffset+=2;
87     length = tvb_get_ntohs(tvb, loffset); loffset+=2;
88     llength=length;
89     remaining_length-=4;
90     if (remaining_length>=2)
91     {
92       type = tvb_get_ntohs(tvb, loffset); loffset+=2;
93       remaining_length-=2;
94       llength-=2;
95     }
96     if (remaining_length>=2)
97     {
98       sequence = tvb_get_ntohs(tvb, loffset); loffset+=2;
99       remaining_length-=2;
100       llength-=2;
101       if (first_sequence==-1)
102       {
103         first_sequence=sequence;
104       }else{
105         last_sequence=sequence;
106       }
107     }
108     if (remaining_length>=2)
109     {
110       field1 = tvb_get_ntohs(tvb, loffset);
111       llength-=2;
112     }
113
114     ti = proto_tree_add_uint(ipsictl_tree, hf_ipsictl_pdu, tvb,
115            offset, (length+4), pdu);
116     pdu_tree = proto_item_add_subtree(ti, ett_ipsictl_pdu);
117
118     loffset=offset;
119     remaining_length=tvb_reported_length_remaining(tvb, offset);
120
121     if (tree) {
122       proto_tree_add_uint(pdu_tree, hf_ipsictl_magic, tvb, loffset, 2, magic);
123     }
124     loffset+=2; remaining_length-=2;
125     if (tree) {
126       proto_tree_add_uint(pdu_tree, hf_ipsictl_length, tvb, loffset, 2, length);
127     }
128     loffset+=2; remaining_length-=2;
129
130     if (remaining_length>=2)
131     {
132       if (tree) {
133         proto_tree_add_uint(pdu_tree, hf_ipsictl_type, tvb, loffset, 2, type);
134       }
135       loffset+=2; remaining_length-=2;
136     }
137     if (remaining_length>=2)
138     {
139       if (tree) {
140         proto_tree_add_uint(pdu_tree, hf_ipsictl_sequence, tvb, loffset, 2, sequence);
141       }
142       loffset+=2; remaining_length-=2;
143     }
144     if (remaining_length>=2)
145     {
146       if (tree) {
147         proto_tree_add_uint(pdu_tree, hf_ipsictl_field1, tvb, loffset, 2, field1);
148       }
149       loffset+=2; remaining_length-=2;
150     }
151     if (remaining_length>=2)
152     {
153       if (tree) {
154         proto_tree_add_item(pdu_tree, hf_ipsictl_data, tvb, loffset, llength, ENC_NA);
155       }
156       loffset+=llength;
157     }
158
159     offset=loffset;
160     pdu++;
161   }
162
163   if (!haspdus)
164   {
165     if (tree) {
166       proto_tree_add_item(ipsictl_tree, hf_ipsictl_data, tvb, offset, -1, ENC_NA);
167     }
168   }
169
170   col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPSICTL");
171
172   if (haspdus)
173   {
174     if (last_sequence==-1)
175     {
176       col_add_fstr(pinfo->cinfo, COL_INFO, "PDUS=%d, Seq=0x%04x",
177         pdu,first_sequence);
178     }else{
179       col_add_fstr(pinfo->cinfo, COL_INFO, "PDUS=%d, Seq=0x%04x-0x%04x",
180         pdu,first_sequence,last_sequence);
181     }
182   }else{
183     col_set_str(pinfo->cinfo, COL_INFO, "Initialization");
184   }
185
186
187 } /* dissect_ipsictl */
188
189 void proto_register_ipsictl(void)
190 {
191
192   static hf_register_info hf[] = {
193     { &hf_ipsictl_pdu,
194       { "PDU",  "ipsictl.pdu",
195         FT_UINT16,      BASE_DEC,       NULL,   0x0,
196         "IPSICTL PDU", HFILL }},
197     { &hf_ipsictl_magic,
198       { "Magic",        "ipsictl.magic",
199         FT_UINT16,      BASE_HEX,       NULL,   0x0,
200         "IPSICTL Magic", HFILL }},
201     { &hf_ipsictl_length,
202       { "Length",       "ipsictl.length",
203         FT_UINT16,      BASE_HEX,       NULL,   0x0,
204         "IPSICTL Length", HFILL }},
205     { &hf_ipsictl_type,
206       { "Type", "ipsictl.type",
207         FT_UINT16,      BASE_HEX,       NULL,   0x0,
208         "IPSICTL Type", HFILL }},
209     { &hf_ipsictl_sequence,
210       { "Sequence",     "ipsictl.sequence",
211         FT_UINT16,      BASE_HEX,       NULL,   0x0,
212         "IPSICTL Sequence", HFILL }},
213     { &hf_ipsictl_field1,
214       { "Field1",       "ipsictl.field1",
215         FT_UINT16,      BASE_HEX,       NULL,   0x0,
216         "IPSICTL Field1", HFILL }},
217     { &hf_ipsictl_data,
218       { "Data", "ipsictl.data",
219         FT_BYTES,       BASE_NONE,      NULL,   0x0,
220         "IPSICTL data", HFILL }},
221   };
222
223   static gint *ett[] = {
224     &ett_ipsictl,
225     &ett_ipsictl_pdu
226   };
227
228   proto_ipsictl = proto_register_protocol("IPSICTL", "IPSICTL", "ipsictl");
229   proto_register_field_array(proto_ipsictl, hf, array_length(hf));
230   proto_register_subtree_array(ett, array_length(ett));
231
232 }
233
234 void proto_reg_handoff_ipsictl(void)
235 {
236
237   dissector_handle_t ipsictl_handle = NULL;
238
239   ipsictl_handle = create_dissector_handle(dissect_ipsictl, proto_ipsictl);
240
241   dissector_add_uint("tcp.port", IPSICTL_PORT, ipsictl_handle);
242
243 }
244
245 /*
246  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
247  *
248  * Local Variables:
249  * c-basic-offset: 2
250  * tab-width: 8
251  * indent-tabs-mode: nil
252  * End:
253  *
254  * ex: set shiftwidth=2 tabstop=8 expandtab:
255  * :indentSize=2:tabSize=8:noTabs=true:
256  */