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/wmem/wmem.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 tvbuff_t
*next_tvb
= NULL
;
211 info_buffer
= (char *)wmem_alloc( wmem_packet_scope(), STRLEN
);
212 info_buffer
[0] = '\0';
214 col_set_str( pinfo
->cinfo
, COL_PROTOCOL
, "AX.25 KISS" );
215 col_clear( pinfo
->cinfo
, COL_INFO
);
217 /* protocol offset for the KISS header */
220 kiss_cmd
= tvb_get_guint8( tvb
, offset
) & 0xff;
221 kiss_type
= kiss_cmd
& KISS_CMD_MASK
;
222 kiss_port
= (kiss_cmd
& KISS_PORT_MASK
) >> 4;
223 offset
+= KISS_HEADER_SIZE
;
229 case KISS_TXDELAY
: kiss_param_len
= 1; kiss_param
= tvb_get_guint8( tvb
, offset
) & 0xff; break;
230 case KISS_PERSISTENCE
: kiss_param_len
= 1; kiss_param
= tvb_get_guint8( tvb
, offset
) & 0xff; break;
231 case KISS_SLOT_TIME
: kiss_param_len
= 1; kiss_param
= tvb_get_guint8( tvb
, offset
) & 0xff; break;
232 case KISS_TXTAIL
: kiss_param_len
= 1; kiss_param
= tvb_get_guint8( tvb
, offset
) & 0xff; break;
233 case KISS_FULLDUPLEX
: kiss_param_len
= 1; kiss_param
= tvb_get_guint8( tvb
, offset
) & 0xff; break;
234 case KISS_SETHARDWARE
: kiss_param_len
= 1; kiss_param
= tvb_get_guint8( tvb
, offset
) & 0xff; break;
237 frame_type_text
= val_to_str(kiss_type
, kiss_frame_types
, "Unknown (%u)");
238 g_snprintf( info_buffer
, STRLEN
, "%s, Port %u", frame_type_text
, kiss_port
);
239 if ( kiss_param_len
> 0 )
240 g_snprintf( info_buffer
, STRLEN
, "%s %u, Port %u", frame_type_text
, kiss_param
, kiss_port
);
242 offset
+= kiss_param_len
;
244 col_add_str( pinfo
->cinfo
, COL_INFO
, info_buffer
);
248 /* protocol offset for the KISS header */
251 /* create display subtree for the protocol */
252 ti
= proto_tree_add_protocol_format( parent_tree
, proto_ax25_kiss
, tvb
, offset
,
253 KISS_HEADER_SIZE
+ kiss_param_len
,
258 kiss_tree
= proto_item_add_subtree( ti
, ett_ax25_kiss
);
260 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_cmd
, tvb
, offset
, KISS_HEADER_SIZE
,
262 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_port
, tvb
, offset
, KISS_HEADER_SIZE
,
264 offset
+= KISS_HEADER_SIZE
;
268 case KISS_DATA_FRAME
: break;
270 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_txdelay
,
271 tvb
, offset
, kiss_param_len
, kiss_param
);
272 offset
+= kiss_param_len
;
274 case KISS_PERSISTENCE
:
275 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_persistence
,
276 tvb
, offset
, kiss_param_len
, kiss_param
);
277 offset
+= kiss_param_len
;
279 case KISS_SLOT_TIME
:
280 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_slottime
,
281 tvb
, offset
, kiss_param_len
, kiss_param
);
282 offset
+= kiss_param_len
;
285 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_txtail
,
286 tvb
, offset
, kiss_param_len
, kiss_param
);
287 offset
+= kiss_param_len
;
289 case KISS_FULLDUPLEX
:
290 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_fullduplex
,
291 tvb
, offset
, kiss_param_len
, kiss_param
);
292 offset
+= kiss_param_len
;
294 case KISS_SETHARDWARE
:
295 proto_tree_add_uint( kiss_tree
, hf_ax25_kiss_sethardware
,
296 tvb
, offset
, kiss_param_len
, kiss_param
);
297 offset
+= kiss_param_len
;
299 case KISS_RETURN
: break;
304 /* Call sub-dissectors here */
306 if ( kiss_type
== KISS_DATA_FRAME
)
308 next_tvb
= tvb_new_subset_remaining( tvb
, offset
);
309 call_dissector( ax25_handle
, next_tvb
, pinfo
, parent_tree
);
314 proto_register_ax25_kiss(void)
316 /* Setup list of header fields */
317 static hf_register_info hf
[] = {
319 { "Cmd", "ax25_kiss.cmd",
320 FT_UINT8
, BASE_DEC
, VALS(kiss_frame_types
), KISS_CMD_MASK
,
323 { &hf_ax25_kiss_port
,
324 { "Port", "ax25_kiss.port",
325 FT_UINT8
, BASE_DEC
, NULL
, KISS_PORT_MASK
,
328 { &hf_ax25_kiss_txdelay
,
329 { "Tx delay", "ax25_kiss.txdelay",
330 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
333 { &hf_ax25_kiss_persistence
,
334 { "Persistence", "ax25_kiss.persistence",
335 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
338 { &hf_ax25_kiss_slottime
,
339 { "Slot time", "ax25_kiss.slottime",
340 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
343 { &hf_ax25_kiss_txtail
,
344 { "Tx tail", "ax25_kiss.txtail",
345 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
348 { &hf_ax25_kiss_fullduplex
,
349 { "Full duplex", "ax25_kiss.fullduplex",
350 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
353 { &hf_ax25_kiss_sethardware
,
354 { "Set hardware", "ax25_kiss.sethardware",
355 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
360 /* Setup protocol subtree array */
361 static gint
*ett
[] = {
365 /* Register the protocol name and description */
366 proto_ax25_kiss
= proto_register_protocol( "AX.25 KISS", "AX.25 KISS", "ax25_kiss" );
368 /* Register the dissector */
369 kiss_handle
= register_dissector( "ax25_kiss", dissect_ax25_kiss
, proto_ax25_kiss
);
371 /* Required function calls to register the header fields and subtrees used */
372 proto_register_field_array( proto_ax25_kiss
, hf
, array_length( hf
) );
373 proto_register_subtree_array( ett
, array_length( ett
) );
377 proto_reg_handoff_ax25_kiss(void)
379 dissector_add_uint( "wtap_encap", WTAP_ENCAP_AX25_KISS
, kiss_handle
);
381 /* only currently implemented for AX.25 */
382 ax25_handle
= find_dissector( "ax25" );