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