Move 3 ASN1 dissectors to 'clean' group; move 1 PIDL dissector to 'dirty' group.
[metze/wireshark/wip.git] / epan / dissectors / packet-bpq.c
1 /* packet-bpq.c
2  *
3  * Routines for Amateur Packet Radio protocol dissection
4  * Copyright 2005,2006,2007,2008,2009,2010,2012 R.W. Stearn <richard@rns-stearn.demon.co.uk>
5  *
6  * $Id$
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 /*
28  * This dissector is for:
29  *   Ethernet encapsulated Amateur AX.25 (AX.25 over Ethernet)
30  *
31  * Information was drawn from:
32  *   ?
33  *
34  * It uses Ether ID 0x08ff which is not not officially registered.
35  *
36  */
37
38 #include "config.h"
39
40 #include <glib.h>
41
42 #include <epan/packet.h>
43 #include <epan/etypes.h>
44
45 #include "packet-bpq.h"
46 #include "packet-ax25.h"
47
48 #define STRLEN  80
49
50 #define BPQ_HEADER_SIZE 2 /* length of bpq_len */
51
52 static dissector_handle_t ax25_handle;
53
54 static int proto_bpq            = -1;
55 static int hf_bpq_len           = -1;
56
57 static gint ett_bpq = -1;
58
59 static void
60 dissect_bpq( tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree )
61 {
62         proto_item *ti;
63         proto_tree *bpq_tree;
64         int         offset;
65         guint16     bpq_len;
66         void       *saved_private_data;
67         tvbuff_t   *next_tvb;
68
69
70         col_set_str( pinfo->cinfo, COL_PROTOCOL, "BPQ" );
71
72         col_clear( pinfo->cinfo, COL_INFO );
73
74         /* protocol offset for the BPQ header */
75         offset = 0;
76
77         bpq_len = tvb_get_letohs( tvb, offset );
78
79         col_add_fstr( pinfo->cinfo, COL_INFO, "%u", bpq_len );
80
81         if ( parent_tree )
82                 {
83                 /* protocol offset for the BPQ header */
84                 offset = 0;
85
86                 /* create display subtree for the protocol */
87                 ti = proto_tree_add_protocol_format( parent_tree, proto_bpq, tvb, offset, BPQ_HEADER_SIZE,
88                         "BPQ, Len: %u",
89                         bpq_len & 0xfff /* XXX - lower 12 bits? */
90                         );
91
92                 bpq_tree = proto_item_add_subtree( ti, ett_bpq );
93
94                 proto_tree_add_item( bpq_tree, hf_bpq_len, tvb, offset, BPQ_HEADER_SIZE, ENC_LITTLE_ENDIAN );
95
96         }
97
98         offset += BPQ_HEADER_SIZE;
99
100         saved_private_data = pinfo->private_data;
101         /* XXX - use the length */
102         next_tvb = tvb_new_subset( tvb, offset, -1, -1 );
103         call_dissector( ax25_handle, next_tvb, pinfo, parent_tree );
104         pinfo->private_data = saved_private_data;
105 }
106
107 void
108 capture_bpq( const guchar *pd, int offset, int len, packet_counts *ld)
109 {
110         int l_offset;
111
112         if ( ! BYTES_ARE_IN_FRAME( offset, len, BPQ_HEADER_SIZE ) )
113                 {
114                 ld->other++;
115                 return;
116                 }
117
118         l_offset = offset;
119         l_offset += BPQ_HEADER_SIZE; /* step over bpq header to point at the AX.25 packet*/
120         capture_ax25( pd, l_offset, len, ld );
121 }
122
123 void
124 proto_register_bpq(void)
125 {
126         /* Setup list of header fields */
127         static hf_register_info hf[] = {
128                 { &hf_bpq_len,
129                         { "BPQ len",                    "bpq.len",
130                         FT_UINT16, BASE_DEC, NULL, 0x0,
131                         NULL, HFILL }
132                 },
133         };
134
135         /* Setup protocol subtree array */
136         static gint *ett[] = {
137                 &ett_bpq,
138         };
139
140         /* Register the protocol name and description */
141         proto_bpq = proto_register_protocol( "Amateur Radio BPQ", "BPQ", "bpq" );
142
143         /* Register the dissector */
144         register_dissector( "bpq", dissect_bpq, proto_bpq );
145
146         /* Required function calls to register the header fields and subtrees used */
147         proto_register_field_array( proto_bpq, hf, array_length( hf ) );
148         proto_register_subtree_array( ett, array_length( ett ) );
149 }
150
151 void
152 proto_reg_handoff_bpq(void)
153 {
154         dissector_handle_t bpq_handle;
155
156         bpq_handle = create_dissector_handle( dissect_bpq, proto_bpq );
157         dissector_add_uint("ethertype", ETHERTYPE_BPQ, bpq_handle);
158
159         /* BPQ is only implemented for AX.25 */
160         ax25_handle     = find_dissector( "ax25" );
161
162 }