Remove check_col() and the occasional tree.
[metze/wireshark/wip.git] / epan / dissectors / packet-pcli.c
1 /* packet-pcli.c
2  * Routines for Packet Cable Lawful Intercept packet disassembly
3  * Packet Cable Lawful Intercept is detailed at
4  * http://www.cablelabs.com/specifications/archives/PKT-SP-ESP-I01-991229.pdf
5  * Chapter 4 ( Call Content Connection Interface )
6  *
7  * $Id$
8  *
9  * Copyright (c) 2000 by Ed Warnicke <hagbard@physics.rutgers.edu>
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1999 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28  */
29
30 /* Include files */
31
32 #include "config.h"
33
34 #include <glib.h>
35
36 #include <epan/packet.h>
37 #include <epan/addr_resolv.h>
38 #include <epan/prefs.h>
39 #include <epan/strutil.h>
40
41 /* Define udp_port for lawful intercept */
42
43 #define UDP_PORT_PCLI 9000
44
45 void proto_reg_handoff_pcli(void);
46
47 /* Define the pcli proto */
48
49 static int proto_pcli = -1;
50
51 /* Define headers for pcli */
52
53 static int hf_pcli_cccid = -1;
54
55 /* Define the tree for pcli */
56
57 static int ett_pcli = -1;
58
59 /*
60  * Here are the global variables associated with the preferences
61  * for pcli
62  */
63
64 static guint global_udp_port_pcli = UDP_PORT_PCLI;
65
66 /* A static handle for the ip dissector */
67 static dissector_handle_t ip_handle;
68
69 static void
70 dissect_pcli(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
71
72   guint32 cccid;
73   proto_tree *ti,*pcli_tree;
74   tvbuff_t * next_tvb;
75
76   /* Set the protocol column */
77   col_set_str(pinfo->cinfo, COL_PROTOCOL, "PCLI");
78
79   /* Get the CCCID */
80   cccid = tvb_get_ntohl(tvb,0);
81
82   /* Set the info column */
83   col_add_fstr(pinfo->cinfo, COL_INFO, "CCCID: %u",cccid);
84
85   /*
86    *If we have a non-null tree (ie we are building the proto_tree
87    * instead of just filling out the columns ), then add a PLCI
88    * tree node and put a CCCID header element under it.
89    */
90   if(tree) {
91     ti = proto_tree_add_item(tree,proto_pcli,tvb,0,0,ENC_NA);
92     pcli_tree = proto_item_add_subtree(ti,ett_pcli);
93     proto_tree_add_uint(pcli_tree,hf_pcli_cccid,tvb,
94                         0,4,cccid);
95   }
96
97   /*
98    * Hand off to the IP dissector.
99    */
100   next_tvb = tvb_new_subset_remaining(tvb,4);
101   call_dissector(ip_handle,next_tvb,pinfo,tree);
102 }
103
104 void
105 proto_register_pcli(void) {
106   static hf_register_info hf[] = {
107     { &hf_pcli_cccid,
108       { "CCCID", "pcli.cccid", FT_UINT32, BASE_DEC, NULL, 0x0,
109         "Call Content Connection Identifier", HFILL }},
110   };
111
112   static gint *ett[] = {
113     &ett_pcli,
114   };
115
116   module_t *pcli_module;
117
118   proto_pcli = proto_register_protocol("Packet Cable Lawful Intercept",
119                                        "PCLI","pcli");
120   proto_register_field_array(proto_pcli,hf,array_length(hf));
121   proto_register_subtree_array(ett,array_length(ett));
122
123   pcli_module = prefs_register_protocol(proto_pcli,
124                                         proto_reg_handoff_pcli);
125   prefs_register_uint_preference(pcli_module, "udp_port",
126                                  "PCLI UDP Port",
127                                  "The UDP port on which "
128                                  "Packet Cable Lawful Intercept "
129                                  "packets will be sent",
130                                  10,&global_udp_port_pcli);
131
132 }
133
134 /* The registration hand-off routing */
135
136 void
137 proto_reg_handoff_pcli(void) {
138   static gboolean pcli_initialized = FALSE;
139   static dissector_handle_t pcli_handle;
140   static guint udp_port_pcli;
141
142   if(!pcli_initialized) {
143     pcli_handle = create_dissector_handle(dissect_pcli,proto_pcli);
144     ip_handle = find_dissector("ip");
145     pcli_initialized = TRUE;
146   } else {
147     dissector_delete_uint("udp.port",udp_port_pcli,pcli_handle);
148   }
149
150   udp_port_pcli = global_udp_port_pcli;
151
152   dissector_add_uint("udp.port",global_udp_port_pcli,pcli_handle);
153 }