MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / dissectors / packet-ax25-nol3.c
blobc67c4169f3f99f98c2e418f29a8e21d6d6aa738b
1 /* packet-ax25-nol3.c
3 * Routines for Amateur Packet Radio protocol dissection
4 * Copyright 2007,2008,2009,2010,2012 R.W. Stearn <richard@rns-stearn.demon.co.uk>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
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.
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.
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.
28 * This dissector is for the "No Layer 3 protocol" PID of the AX.25 Amateur
29 * Packet-Radio Link-Layer Protocol, Version 2.0, October 1984
31 * At the time of writing the specification could be found here:
32 * http://www.tapr.org/pub_ax25.html
34 * Information on the "protocols" recognised by this dissector are drawn from:
35 * DX cluster:
36 * A network capture kindly donated by Luca Melette.
37 * APRS:
38 * http://www.aprs.org/
40 * Inspiration on how to build the dissector drawn from
41 * packet-sdlc.c
42 * packet-x25.c
43 * packet-lapb.c
44 * paket-gprs-llc.c
45 * xdlc.c
46 * with the base file built from README.developers.
49 #include "config.h"
51 #include <glib.h>
53 #include <epan/packet.h>
54 #include <epan/prefs.h>
55 #include <epan/wmem/wmem.h>
56 #include <epan/ax25_pids.h>
58 #define STRLEN 80
60 void proto_register_ax25_nol3(void);
61 void proto_reg_handoff_ax25_nol3(void);
63 /* Dissector handles - all the possibles are listed */
64 static dissector_handle_t aprs_handle;
65 static dissector_handle_t default_handle;
67 /* Initialize the protocol and registered fields */
68 static int proto_ax25_nol3 = -1;
69 static int proto_dx = -1;
71 static int hf_dx_report = -1;
73 /* static int hf_text = -1; */
75 /* Global preferences */
76 static gboolean gPREF_APRS = FALSE;
77 static gboolean gPREF_DX = FALSE;
79 /* Initialize the subtree pointers */
80 static gint ett_ax25_nol3 = -1;
82 static gint ett_dx = -1;
85 /* Code to actually dissect the packets */
86 static void
87 dissect_dx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
89 proto_item *ti;
90 proto_tree *dx_tree;
92 int data_len;
93 int offset;
95 offset = 0;
96 data_len = tvb_length_remaining( tvb, offset );
98 col_set_str( pinfo->cinfo, COL_PROTOCOL, "DX" );
100 col_add_fstr( pinfo->cinfo, COL_INFO, "%s", tvb_format_text( tvb, offset, 15 ) );
102 if ( parent_tree )
104 /* create display subtree for the protocol */
105 ti = proto_tree_add_protocol_format( parent_tree, proto_dx, tvb, 0, -1,
106 "DX (%s)", tvb_format_text( tvb, offset, 15 ) );
107 dx_tree = proto_item_add_subtree( ti, ett_dx );
108 offset = 0;
110 proto_tree_add_item( dx_tree, hf_dx_report, tvb, offset, data_len, ENC_ASCII|ENC_NA );
114 static gboolean
115 isaprs( guint8 dti )
117 gboolean b = FALSE;
119 switch ( dti )
121 case 0x1c :
122 case 0x1d :
123 case '!' :
124 case '#' :
125 case '$' :
126 case '%' :
127 case '&' :
128 case ')' :
129 case '*' :
130 case '+' :
131 case ',' :
132 case '.' :
133 case '/' :
134 case ':' :
135 case ';' :
136 case '<' :
137 case '=' :
138 case '>' :
139 case '?' :
140 case '@' :
141 case 'T' :
142 case '[' :
143 case '\'' :
144 case '_' :
145 case '`' :
146 case '{' :
147 case '}' : b = TRUE; break;
148 default : break;
150 return b;
153 static void
154 dissect_ax25_nol3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree )
156 proto_item *ti;
157 proto_tree *ax25_nol3_tree;
158 char *info_buffer;
159 int offset;
160 tvbuff_t *next_tvb = NULL;
161 guint8 dti = 0;
162 gboolean dissected;
164 info_buffer = (char *)wmem_alloc( wmem_packet_scope(), STRLEN );
165 info_buffer[0] = '\0';
167 col_set_str( pinfo->cinfo, COL_PROTOCOL, "AX.25-NoL3");
169 col_clear( pinfo->cinfo, COL_INFO);
171 offset = 0;
172 g_snprintf( info_buffer, STRLEN, "Text" );
174 if ( gPREF_APRS )
176 dti = tvb_get_guint8( tvb, offset );
177 if ( isaprs( dti ) )
178 g_snprintf( info_buffer, STRLEN, "APRS" );
180 if ( gPREF_DX )
182 if ( tvb_get_guint8( tvb, offset ) == 'D' && tvb_get_guint8( tvb, offset + 1 ) == 'X' )
183 g_snprintf( info_buffer, STRLEN, "DX cluster" );
186 col_add_str( pinfo->cinfo, COL_INFO, info_buffer );
188 /* Call sub-dissectors here */
190 if ( parent_tree )
192 /* create display subtree for the protocol */
193 ti = proto_tree_add_protocol_format( parent_tree,
194 proto_ax25_nol3,
195 tvb,
198 "AX.25 No Layer 3 - (%s)", info_buffer );
199 ax25_nol3_tree = proto_item_add_subtree( ti, ett_ax25_nol3 );
201 next_tvb = tvb_new_subset_remaining(tvb, offset);
202 dissected = FALSE;
203 if ( gPREF_APRS )
205 if ( isaprs( dti ) )
207 dissected = TRUE;
208 call_dissector( aprs_handle , next_tvb, pinfo, ax25_nol3_tree );
211 if ( gPREF_DX )
213 if ( tvb_get_guint8( tvb, offset ) == 'D' && tvb_get_guint8( tvb, offset + 1 ) == 'X' )
215 dissected = TRUE;
216 dissect_dx( next_tvb, pinfo, ax25_nol3_tree );
219 if ( ! dissected )
220 call_dissector( default_handle , next_tvb, pinfo, ax25_nol3_tree );
225 void
226 proto_register_ax25_nol3(void)
228 module_t *ax25_nol3_module;
230 /* Setup list of header fields */
231 #if 0 /* not used ? */
232 static hf_register_info hf[] = {
233 { &hf_text,
234 { "Text", "ax25_nol3.text",
235 FT_STRING, BASE_NONE, NULL, 0x0,
236 NULL, HFILL }
239 #endif
241 static hf_register_info hf_dx[] = {
242 { &hf_dx_report,
243 { "DX", "ax25_nol3.dx",
244 FT_STRING, BASE_NONE, NULL, 0x0,
245 "DX cluster", HFILL }
249 /* Setup protocol subtree array */
250 static gint *ett[] = {
251 &ett_ax25_nol3,
252 &ett_dx,
255 /* Register the protocol name and description */
256 proto_ax25_nol3 = proto_register_protocol("AX.25 no Layer 3", "AX.25 no L3", "ax25_nol3");
258 /* Required function calls to register the header fields and subtrees used */
259 /* proto_register_field_array( proto_ax25_nol3, hf, array_length(hf ) ); */
260 proto_register_subtree_array( ett, array_length( ett ) );
262 /* Register preferences module */
263 ax25_nol3_module = prefs_register_protocol( proto_ax25_nol3, NULL);
265 /* Register any preference */
266 prefs_register_bool_preference(ax25_nol3_module, "showaprs",
267 "Decode the APRS info field",
268 "Enable decoding of the payload as APRS.",
269 &gPREF_APRS );
271 prefs_register_bool_preference(ax25_nol3_module, "showcluster",
272 "Decode DX cluster info field",
273 "Enable decoding of the payload as DX cluster info.",
274 &gPREF_DX );
276 /* Register the sub-protocol name and description */
277 proto_dx = proto_register_protocol("DX cluster", "DX", "dx");
279 /* Register the dissector */
280 register_dissector( "dx", dissect_dx, proto_dx);
282 /* Register the header fields */
283 proto_register_field_array( proto_dx, hf_dx, array_length( hf_dx ) );
285 /* Register the subtrees used */
286 /* proto_register_subtree_array( ett_dx, array_length( ett_dx ) ); */
289 void
290 proto_reg_handoff_ax25_nol3(void)
292 dissector_add_uint( "ax25.pid", AX25_P_NO_L3, create_dissector_handle( dissect_ax25_nol3, proto_ax25_nol3 ) );
296 aprs_handle = find_dissector( "aprs" );
297 default_handle = find_dissector( "data" );