TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / epan / dissectors / packet-ax25-nol3.c
blob75931cda6c5b84713a557d5ed3b99ec8d6fdc754
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 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
14 * This dissector is for the "No Layer 3 protocol" PID of the AX.25 Amateur
15 * Packet-Radio Link-Layer Protocol, Version 2.0, October 1984
17 * At the time of writing the specification could be found here:
18 * http://www.tapr.org/pub_ax25.html
20 * Information on the "protocols" recognised by this dissector are drawn from:
21 * DX cluster:
22 * A network capture kindly donated by Luca Melette.
23 * APRS:
24 * http://www.aprs.org/
26 * Inspiration on how to build the dissector drawn from
27 * packet-sdlc.c
28 * packet-x25.c
29 * packet-lapb.c
30 * paket-gprs-llc.c
31 * xdlc.c
32 * with the base file built from README.developers.
35 #include "config.h"
37 #include <epan/packet.h>
38 #include <epan/prefs.h>
39 #include <epan/ax25_pids.h>
41 #define STRLEN 80
43 void proto_register_ax25_nol3(void);
44 void proto_reg_handoff_ax25_nol3(void);
46 /* Dissector handles - all the possibles are listed */
47 static dissector_handle_t aprs_handle;
49 /* Initialize the protocol and registered fields */
50 static int proto_ax25_nol3;
51 static int proto_dx;
53 static int hf_dx_report;
55 /* static int hf_text; */
57 /* Global preferences */
58 static bool gPREF_APRS;
59 static bool gPREF_DX;
61 /* Initialize the subtree pointers */
62 static int ett_ax25_nol3;
64 static int ett_dx;
67 /* Code to actually dissect the packets */
68 static int
69 dissect_dx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
71 proto_item *ti;
72 proto_tree *dx_tree;
74 int data_len;
75 int offset;
77 offset = 0;
78 data_len = tvb_reported_length_remaining( tvb, offset );
80 col_set_str( pinfo->cinfo, COL_PROTOCOL, "DX" );
82 col_add_str( pinfo->cinfo, COL_INFO, tvb_format_text( pinfo->pool, tvb, offset, 15 ) );
84 if ( parent_tree )
86 /* create display subtree for the protocol */
87 ti = proto_tree_add_protocol_format( parent_tree, proto_dx, tvb, 0, -1,
88 "DX (%s)", tvb_format_text( pinfo->pool, tvb, offset, 15 ) );
89 dx_tree = proto_item_add_subtree( ti, ett_dx );
90 offset = 0;
92 proto_tree_add_item( dx_tree, hf_dx_report, tvb, offset, data_len, ENC_ASCII );
95 return tvb_captured_length(tvb);
98 static bool
99 isaprs( uint8_t dti )
101 bool b = false;
103 switch ( dti )
105 case 0x1c :
106 case 0x1d :
107 case '!' :
108 case '#' :
109 case '$' :
110 case '%' :
111 case '&' :
112 case ')' :
113 case '*' :
114 case '+' :
115 case ',' :
116 case '.' :
117 case '/' :
118 case ':' :
119 case ';' :
120 case '<' :
121 case '=' :
122 case '>' :
123 case '?' :
124 case '@' :
125 case 'T' :
126 case '[' :
127 case '\'' :
128 case '_' :
129 case '`' :
130 case '{' :
131 case '}' : b = true; break;
132 default : break;
134 return b;
137 static int
138 dissect_ax25_nol3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_ )
140 proto_item *ti;
141 proto_tree *ax25_nol3_tree;
142 char *info_buffer;
143 int offset;
144 tvbuff_t *next_tvb = NULL;
145 uint8_t dti = 0;
146 bool dissected;
148 info_buffer = (char *)wmem_alloc( pinfo->pool, STRLEN );
149 info_buffer[0] = '\0';
151 col_set_str( pinfo->cinfo, COL_PROTOCOL, "AX.25-NoL3");
153 col_clear( pinfo->cinfo, COL_INFO);
155 offset = 0;
156 snprintf( info_buffer, STRLEN, "Text" );
158 if ( gPREF_APRS )
160 dti = tvb_get_uint8( tvb, offset );
161 if ( isaprs( dti ) )
162 snprintf( info_buffer, STRLEN, "APRS" );
164 if ( gPREF_DX )
166 if ( tvb_get_uint8( tvb, offset ) == 'D' && tvb_get_uint8( tvb, offset + 1 ) == 'X' )
167 snprintf( info_buffer, STRLEN, "DX cluster" );
170 col_add_str( pinfo->cinfo, COL_INFO, info_buffer );
172 /* Call sub-dissectors here */
174 /* create display subtree for the protocol */
175 ti = proto_tree_add_protocol_format( parent_tree,
176 proto_ax25_nol3,
177 tvb,
180 "AX.25 No Layer 3 - (%s)", info_buffer );
181 ax25_nol3_tree = proto_item_add_subtree( ti, ett_ax25_nol3 );
183 next_tvb = tvb_new_subset_remaining(tvb, offset);
184 dissected = false;
185 if ( gPREF_APRS )
187 if ( isaprs( dti ) )
189 dissected = true;
190 call_dissector( aprs_handle , next_tvb, pinfo, ax25_nol3_tree );
193 if ( gPREF_DX )
195 if ( tvb_get_uint8( tvb, offset ) == 'D' && tvb_get_uint8( tvb, offset + 1 ) == 'X' )
197 dissected = true;
198 dissect_dx( next_tvb, pinfo, ax25_nol3_tree, NULL );
201 if ( ! dissected )
202 call_data_dissector(next_tvb, pinfo, ax25_nol3_tree );
204 return tvb_captured_length(tvb);
207 void
208 proto_register_ax25_nol3(void)
210 module_t *ax25_nol3_module;
212 /* Setup list of header fields */
213 #if 0 /* not used ? */
214 static hf_register_info hf[] = {
215 { &hf_text,
216 { "Text", "ax25_nol3.text",
217 FT_STRING, BASE_NONE, NULL, 0x0,
218 NULL, HFILL }
221 #endif
223 static hf_register_info hf_dx[] = {
224 { &hf_dx_report,
225 { "DX", "ax25_nol3.dx",
226 FT_STRING, BASE_NONE, NULL, 0x0,
227 "DX cluster", HFILL }
231 /* Setup protocol subtree array */
232 static int *ett[] = {
233 &ett_ax25_nol3,
234 &ett_dx,
237 /* Register the protocol name and description */
238 proto_ax25_nol3 = proto_register_protocol("AX.25 no Layer 3", "AX.25 no L3", "ax25_nol3");
240 /* Required function calls to register the header fields and subtrees used */
241 /* proto_register_field_array( proto_ax25_nol3, hf, array_length(hf ) ); */
242 proto_register_subtree_array( ett, array_length( ett ) );
244 /* Register preferences module */
245 ax25_nol3_module = prefs_register_protocol( proto_ax25_nol3, NULL);
247 /* Register any preference */
248 prefs_register_bool_preference(ax25_nol3_module, "showaprs",
249 "Decode the APRS info field",
250 "Enable decoding of the payload as APRS.",
251 &gPREF_APRS );
253 prefs_register_bool_preference(ax25_nol3_module, "showcluster",
254 "Decode DX cluster info field",
255 "Enable decoding of the payload as DX cluster info.",
256 &gPREF_DX );
258 /* Register the sub-protocol name and description */
259 proto_dx = proto_register_protocol("DX cluster", "DX", "dx");
261 /* Register the dissector */
262 register_dissector( "dx", dissect_dx, proto_dx);
264 /* Register the header fields */
265 proto_register_field_array( proto_dx, hf_dx, array_length( hf_dx ) );
267 /* Register the subtrees used */
268 /* proto_register_subtree_array( ett_dx, array_length( ett_dx ) ); */
271 void
272 proto_reg_handoff_ax25_nol3(void)
274 dissector_add_uint( "ax25.pid", AX25_P_NO_L3, create_dissector_handle( dissect_ax25_nol3, proto_ax25_nol3 ) );
278 aprs_handle = find_dissector_add_dependency( "aprs", proto_ax25_nol3 );
282 * Editor modelines - https://www.wireshark.org/tools/modelines.html
284 * Local variables:
285 * c-basic-offset: 8
286 * tab-width: 8
287 * indent-tabs-mode: t
288 * End:
290 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
291 * :indentSize=8:tabSize=8:noTabs=false: