3 * Routines for AX.25 KISS protocol dissection
4 * Copyright 2010,2012 R.W. Stearn <richard@rns-stearn.demon.co.uk>
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 handles the "KISS" protocol as implemented by the
31 * The original definition of the KISS protocol can be found here:
32 * http://www.ka9q.net/papers/kiss.html
34 * http://www.ax25.net/kiss.aspx
36 * The Linux implementation does not appear to attempt to implement that
37 * protocol in full. It does provide the ability to send a KISS command via
38 * ax25_kiss_cmd() and internally will send FULLDUPLEX KISS commands if
39 * DAMA is enabled/disabled.
41 * ax25_dev_dama_on sends FullDuplex ON
42 * ax25_dev_dama_off sends FullDuplex OFF
44 * Data frames are prefixed with a "Data Frame" command but the port appears to
47 * Abstract from http://www.ka9q.net/papers/kiss.html
48 * --------------------------------------------------
49 * For reference the first byte of a KISS frame is the frame type and the TNC
51 * LSB 4 bits = frame type,
52 * MSB 4 bits = port number.
54 * The frame types are:
55 * Command Function Comments
56 * 0 Data frame The rest of the frame is data to
57 * be sent on the HDLC channel.
59 * 1 TXDELAY The next byte is the transmitter
60 * keyup delay in 10 ms units.
61 * The default start-up value is 50
64 * 2 P The next byte is the persistence
65 * parameter, p, scaled to the range
66 * 0 - 255 with the following
71 * The default value is P = 63
74 * 3 SlotTime The next byte is the slot interval
76 * The default is 10 (i.e., 100ms).
78 * 4 TXtail The next byte is the time to hold
79 * up the TX after the FCS has been
80 * sent, in 10 ms units. This command
81 * is obsolete, and is included here
82 * only for compatibility with some
83 * existing implementations.
85 * 5 FullDuplex The next byte is 0 for half duplex,
86 * nonzero for full duplex.
88 * (i.e., half duplex).
90 * 6 SetHardware Specific for each TNC. In the
91 * TNC-1, this command sets the
92 * modem speed. Other implementations
93 * may use this function for other
94 * hardware-specific functions.
96 * FF Return Exit KISS and return control to a
97 * higher-level program. This is useful
98 * only when KISS is incorporated
99 * into the TNC along with other
108 #include <epan/packet.h>
109 #include <epan/emem.h>
111 #include "packet-ax25-kiss.h"
112 #include "packet-ax25.h"
116 #define KISS_HEADER_SIZE 1 /* length of the KISS type header */
118 /* KISS frame types */
119 #define KISS_DATA_FRAME 0
120 #define KISS_TXDELAY 1
121 #define KISS_PERSISTENCE 2
122 #define KISS_SLOT_TIME 3
123 #define KISS_TXTAIL 4
124 #define KISS_FULLDUPLEX 5
125 #define KISS_SETHARDWARE 6
126 #define KISS_RETURN 15
128 #define KISS_CMD_MASK 0x0f
129 #define KISS_PORT_MASK 0xf0
131 void proto_register_ax25_kiss(void);
132 void proto_reg_handoff_ax25_kiss(void);
134 /* Initialize the protocol and registered fields */
135 static int proto_ax25_kiss = -1;
137 static int hf_ax25_kiss_cmd = -1;
138 static int hf_ax25_kiss_port = -1;
139 static int hf_ax25_kiss_txdelay = -1;
140 static int hf_ax25_kiss_persistence = -1;
141 static int hf_ax25_kiss_slottime = -1;
142 static int hf_ax25_kiss_txtail = -1;
143 static int hf_ax25_kiss_fullduplex = -1;
144 static int hf_ax25_kiss_sethardware = -1;
146 /* Initialize the subtree pointers */
147 static gint ett_ax25_kiss = -1;
149 static dissector_handle_t kiss_handle;
151 /* Dissector handles - all the possibles are listed */
152 static dissector_handle_t ax25_handle;
154 static const value_string kiss_frame_types[] = {
155 { KISS_DATA_FRAME, "Data frame" },
156 { KISS_TXDELAY, "Tx Delay" },
157 { KISS_PERSISTENCE, "Persistence" },
158 { KISS_SLOT_TIME, "Slot time" },
159 { KISS_TXTAIL, "Tx tail" },
160 { KISS_FULLDUPLEX, "Full duplex" },
161 { KISS_SETHARDWARE, "Set hardware" },
162 { KISS_RETURN, "Return" },
167 capture_ax25_kiss( const guchar *pd, int offset, int len, packet_counts *ld)
172 if ( ! BYTES_ARE_IN_FRAME( offset, len, KISS_HEADER_SIZE ) )
179 kiss_cmd = pd[ l_offset ];
180 l_offset += KISS_HEADER_SIZE; /* step over kiss header */
181 switch ( kiss_cmd & KISS_CMD_MASK )
183 case KISS_DATA_FRAME : capture_ax25( pd, l_offset, len, ld ); break;
184 case KISS_TXDELAY : break;
185 case KISS_PERSISTENCE : break;
186 case KISS_SLOT_TIME : break;
187 case KISS_TXTAIL : break;
188 case KISS_FULLDUPLEX : break;
189 case KISS_SETHARDWARE : break;
190 case KISS_RETURN : break;
195 /* Code to actually dissect the packets */
197 dissect_ax25_kiss( tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree )
200 proto_tree *kiss_tree;
207 const char *frame_type_text;
209 void *saved_private_data;
210 tvbuff_t *next_tvb = NULL;
212 info_buffer = (char *)ep_alloc( STRLEN );
213 info_buffer[0] = '\0';
215 col_set_str( pinfo->cinfo, COL_PROTOCOL, "AX.25 KISS" );
216 col_clear( pinfo->cinfo, COL_INFO );
218 /* protocol offset for the KISS header */
221 kiss_cmd = tvb_get_guint8( tvb, offset ) & 0xff;
222 kiss_type = kiss_cmd & KISS_CMD_MASK;
223 kiss_port = (kiss_cmd & KISS_PORT_MASK) >> 4;
224 offset += KISS_HEADER_SIZE;
230 case KISS_TXDELAY : kiss_param_len = 1; kiss_param = tvb_get_guint8( tvb, offset ) & 0xff; break;
231 case KISS_PERSISTENCE : kiss_param_len = 1; kiss_param = tvb_get_guint8( tvb, offset ) & 0xff; break;
232 case KISS_SLOT_TIME : kiss_param_len = 1; kiss_param = tvb_get_guint8( tvb, offset ) & 0xff; break;
233 case KISS_TXTAIL : kiss_param_len = 1; kiss_param = tvb_get_guint8( tvb, offset ) & 0xff; break;
234 case KISS_FULLDUPLEX : kiss_param_len = 1; kiss_param = tvb_get_guint8( tvb, offset ) & 0xff; break;
235 case KISS_SETHARDWARE : kiss_param_len = 1; kiss_param = tvb_get_guint8( tvb, offset ) & 0xff; break;
238 frame_type_text = val_to_str(kiss_type, kiss_frame_types, "Unknown (%u)");
239 g_snprintf( info_buffer, STRLEN, "%s, Port %u", frame_type_text, kiss_port );
240 if ( kiss_param_len > 0 )
241 g_snprintf( info_buffer, STRLEN, "%s %u, Port %u", frame_type_text, kiss_param, kiss_port );
243 offset += kiss_param_len;
245 col_add_str( pinfo->cinfo, COL_INFO, info_buffer );
249 /* protocol offset for the KISS header */
252 /* create display subtree for the protocol */
253 ti = proto_tree_add_protocol_format( parent_tree, proto_ax25_kiss, tvb, offset,
254 KISS_HEADER_SIZE + kiss_param_len,
259 kiss_tree = proto_item_add_subtree( ti, ett_ax25_kiss );
261 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_cmd, tvb, offset, KISS_HEADER_SIZE,
263 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_port, tvb, offset, KISS_HEADER_SIZE,
265 offset += KISS_HEADER_SIZE;
269 case KISS_DATA_FRAME : break;
271 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_txdelay,
272 tvb, offset, kiss_param_len, kiss_param );
273 offset += kiss_param_len;
275 case KISS_PERSISTENCE :
276 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_persistence,
277 tvb, offset, kiss_param_len, kiss_param );
278 offset += kiss_param_len;
280 case KISS_SLOT_TIME :
281 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_slottime,
282 tvb, offset, kiss_param_len, kiss_param );
283 offset += kiss_param_len;
286 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_txtail,
287 tvb, offset, kiss_param_len, kiss_param );
288 offset += kiss_param_len;
290 case KISS_FULLDUPLEX :
291 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_fullduplex,
292 tvb, offset, kiss_param_len, kiss_param );
293 offset += kiss_param_len;
295 case KISS_SETHARDWARE :
296 proto_tree_add_uint( kiss_tree, hf_ax25_kiss_sethardware,
297 tvb, offset, kiss_param_len, kiss_param );
298 offset += kiss_param_len;
300 case KISS_RETURN : break;
305 /* Call sub-dissectors here */
307 if ( kiss_type == KISS_DATA_FRAME )
309 saved_private_data = pinfo->private_data;
310 next_tvb = tvb_new_subset_remaining( tvb, offset );
311 call_dissector( ax25_handle, next_tvb, pinfo, parent_tree );
312 pinfo->private_data = saved_private_data;
317 proto_register_ax25_kiss(void)
319 /* Setup list of header fields */
320 static hf_register_info hf[] = {
322 { "Cmd", "ax25_kiss.cmd",
323 FT_UINT8, BASE_DEC, VALS(kiss_frame_types), KISS_CMD_MASK,
326 { &hf_ax25_kiss_port,
327 { "Port", "ax25_kiss.port",
328 FT_UINT8, BASE_DEC, NULL, KISS_PORT_MASK,
331 { &hf_ax25_kiss_txdelay,
332 { "Tx delay", "ax25_kiss.txdelay",
333 FT_UINT8, BASE_DEC, NULL, 0x0,
336 { &hf_ax25_kiss_persistence,
337 { "Persistence", "ax25_kiss.persistence",
338 FT_UINT8, BASE_DEC, NULL, 0x0,
341 { &hf_ax25_kiss_slottime,
342 { "Slot time", "ax25_kiss.slottime",
343 FT_UINT8, BASE_DEC, NULL, 0x0,
346 { &hf_ax25_kiss_txtail,
347 { "Tx tail", "ax25_kiss.txtail",
348 FT_UINT8, BASE_DEC, NULL, 0x0,
351 { &hf_ax25_kiss_fullduplex,
352 { "Full duplex", "ax25_kiss.fullduplex",
353 FT_UINT8, BASE_DEC, NULL, 0x0,
356 { &hf_ax25_kiss_sethardware,
357 { "Set hardware", "ax25_kiss.sethardware",
358 FT_UINT8, BASE_DEC, NULL, 0x0,
363 /* Setup protocol subtree array */
364 static gint *ett[] = {
368 /* Register the protocol name and description */
369 proto_ax25_kiss = proto_register_protocol( "AX.25 KISS", "AX.25 KISS", "ax25_kiss" );
371 /* Register the dissector */
372 kiss_handle = register_dissector( "ax25_kiss", dissect_ax25_kiss, proto_ax25_kiss );
374 /* Required function calls to register the header fields and subtrees used */
375 proto_register_field_array( proto_ax25_kiss, hf, array_length( hf ) );
376 proto_register_subtree_array( ett, array_length( ett ) );
380 proto_reg_handoff_ax25_kiss(void)
382 dissector_add_uint( "wtap_encap", WTAP_ENCAP_AX25_KISS, kiss_handle );
384 /* only currently implemented for AX.25 */
385 ax25_handle = find_dissector( "ax25" );