2 * Routines for IrCOMM dissection
3 * By Jan Kiszka <jan.kiszka@web.de>
4 * Copyright 2003 Jan Kiszka
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@unicom.net>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "moduleinfo.h"
39 #include <epan/packet.h>
40 #include <epan/proto.h>
46 * http://www.irda.org/standards/specifications.asp
48 * for various IrDA specifications.
51 #include "irda-appl.h"
54 /* Parameters common to all service types */
55 #define IRCOMM_SERVICE_TYPE 0x00
56 #define IRCOMM_PORT_TYPE 0x01 /* Only used in LM-IAS */
57 #define IRCOMM_PORT_NAME 0x02 /* Only used in LM-IAS */
59 /* Parameters for both 3 wire and 9 wire */
60 #define IRCOMM_DATA_RATE 0x10
61 #define IRCOMM_DATA_FORMAT 0x11
62 #define IRCOMM_FLOW_CONTROL 0x12
63 #define IRCOMM_XON_XOFF 0x13
64 #define IRCOMM_ENQ_ACK 0x14
65 #define IRCOMM_LINE_STATUS 0x15
66 #define IRCOMM_BREAK 0x16
68 /* Parameters for 9 wire */
69 #define IRCOMM_DTE 0x20
70 #define IRCOMM_DCE 0x21
71 #define IRCOMM_POLL 0x22
73 /* Service type (details) */
74 #define IRCOMM_3_WIRE_RAW 0x01
75 #define IRCOMM_3_WIRE 0x02
76 #define IRCOMM_9_WIRE 0x04
77 #define IRCOMM_CENTRONICS 0x08
79 /* Port type (details) */
80 #define IRCOMM_SERIAL 0x01
81 #define IRCOMM_PARALLEL 0x02
83 /* Data format (details) */
84 #define IRCOMM_WSIZE_5 0x00
85 #define IRCOMM_WSIZE_6 0x01
86 #define IRCOMM_WSIZE_7 0x02
87 #define IRCOMM_WSIZE_8 0x03
89 #define IRCOMM_1_STOP_BIT 0x00
90 #define IRCOMM_2_STOP_BIT 0x04 /* 1.5 if char len 5 */
92 #define IRCOMM_PARITY_DISABLE 0x00
93 #define IRCOMM_PARITY_ENABLE 0x08
95 #define IRCOMM_PARITY_ODD 0x00
96 #define IRCOMM_PARITY_EVEN 0x10
97 #define IRCOMM_PARITY_MARK 0x20
98 #define IRCOMM_PARITY_SPACE 0x30
101 #define IRCOMM_XON_XOFF_IN 0x01
102 #define IRCOMM_XON_XOFF_OUT 0x02
103 #define IRCOMM_RTS_CTS_IN 0x04
104 #define IRCOMM_RTS_CTS_OUT 0x08
105 #define IRCOMM_DSR_DTR_IN 0x10
106 #define IRCOMM_DSR_DTR_OUT 0x20
107 #define IRCOMM_ENQ_ACK_IN 0x40
108 #define IRCOMM_ENQ_ACK_OUT 0x80
111 #define IRCOMM_OVERRUN_ERROR 0x02
112 #define IRCOMM_PARITY_ERROR 0x04
113 #define IRCOMM_FRAMING_ERROR 0x08
115 /* DTE (Data terminal equipment) line settings */
116 #define IRCOMM_DELTA_DTR 0x01
117 #define IRCOMM_DELTA_RTS 0x02
118 #define IRCOMM_DTR 0x04
119 #define IRCOMM_RTS 0x08
121 /* DCE (Data communications equipment) line settings */
122 #define IRCOMM_DELTA_CTS 0x01 /* Clear to send has changed */
123 #define IRCOMM_DELTA_DSR 0x02 /* Data set ready has changed */
124 #define IRCOMM_DELTA_RI 0x04 /* Ring indicator has changed */
125 #define IRCOMM_DELTA_CD 0x08 /* Carrier detect has changed */
126 #define IRCOMM_CTS 0x10 /* Clear to send is high */
127 #define IRCOMM_DSR 0x20 /* Data set ready is high */
128 #define IRCOMM_RI 0x40 /* Ring indicator is high */
129 #define IRCOMM_CD 0x80 /* Carrier detect is high */
130 #define IRCOMM_DCE_DELTA_ANY 0x0f
132 /* Initialize the subtree pointers */
133 static gint ett_ircomm = -1;
134 static gint ett_ircomm_ctrl = -1;
136 #define MAX_PARAMETERS 32
137 static gint ett_param[MAX_IAP_ENTRIES * MAX_PARAMETERS];
140 static int proto_ircomm = -1;
141 static int hf_ircomm_param = -1;
142 static int hf_param_pi = -1;
143 static int hf_param_pl = -1;
144 static int hf_param_pv = -1;
145 static int hf_control = -1;
146 static int hf_control_len = -1;
148 static gboolean dissect_ircomm_parameters(tvbuff_t* tvb, unsigned offset, packet_info* pinfo,
149 proto_tree* tree, unsigned list_index, guint8 attr_type);
150 static gboolean dissect_ircomm_ttp_lsap(tvbuff_t* tvb, unsigned offset, packet_info* pinfo,
151 proto_tree* tree, unsigned list_index, guint8 attr_type);
152 static gboolean dissect_ircomm_lmp_lsap(tvbuff_t* tvb, unsigned offset, packet_info* pinfo,
153 proto_tree* tree, unsigned list_index, guint8 attr_type);
155 ias_attr_dissector_t ircomm_attr_dissector[] = {
156 /* IrDA:IrCOMM attribute dissectors */
157 { "Parameters", dissect_ircomm_parameters },
158 { "IrDA:TinyTP:LsapSel", dissect_ircomm_ttp_lsap },
162 ias_attr_dissector_t irlpt_attr_dissector[] = {
163 /* IrLPT attribute dissectors */
164 { "IrDA:IrLMP:LsapSel", dissect_ircomm_lmp_lsap },
165 { "IrDA:IrLMP:LSAPSel", dissect_ircomm_lmp_lsap }, /* according to IrCOMM V1.0, p25 */
171 * Dissect the cooked IrCOMM protocol
173 static void dissect_cooked_ircomm(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
179 if (tvb_length(tvb) == 0)
182 /* Make entries in Protocol column on summary display */
183 if (check_col(pinfo->cinfo, COL_PROTOCOL))
184 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrCOMM");
186 clen = tvb_get_guint8(tvb, offset);
188 if (check_col(pinfo->cinfo, COL_INFO))
191 unsigned len = tvb_length(tvb) - 1 - clen;
195 sprintf(buf, "Clen=%d, UserData: %d byte%s", clen, len, (len > 1)? "s": "");
197 sprintf(buf, "Clen=%d", clen);
198 col_add_str(pinfo->cinfo, COL_INFO, buf);
203 /* create display subtree for the protocol */
204 proto_item* ti = proto_tree_add_item(root, proto_ircomm, tvb, 0, -1, FALSE);
205 proto_tree* tree = proto_item_add_subtree(ti, ett_ircomm);
207 proto_tree* ctrl_tree;
210 ti = proto_tree_add_item(tree, hf_control, tvb, 0, clen + 1, FALSE);
211 ctrl_tree = proto_item_add_subtree(ti, ett_ircomm_ctrl);
212 proto_tree_add_item(ctrl_tree, hf_control_len, tvb, offset, 1, FALSE);
215 tvbuff_t *cvalue = tvb_new_subset(tvb, offset, clen, clen);
216 call_dissector(data_handle, cvalue, pinfo, ctrl_tree);
220 tvb = tvb_new_subset(tvb, offset, -1, -1);
221 call_dissector(data_handle, tvb, pinfo, tree);
227 * Dissect the raw IrCOMM/IrLPT protocol
229 static void dissect_raw_ircomm(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
231 unsigned len = tvb_length(tvb);
237 /* Make entries in Protocol column on summary display */
238 if (check_col(pinfo->cinfo, COL_PROTOCOL))
239 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrCOMM");
241 if (check_col(pinfo->cinfo, COL_INFO))
246 sprintf(buf, "User Data: %d byte%s", len, (len > 1)? "s": "");
247 col_add_str(pinfo->cinfo, COL_INFO, buf);
252 /* create display subtree for the protocol */
253 proto_item* ti = proto_tree_add_item(root, proto_ircomm, tvb, 0, -1, FALSE);
254 proto_tree* tree = proto_item_add_subtree(ti, ett_ircomm);
256 call_dissector(data_handle, tvb, pinfo, tree);
262 * Dissect IrCOMM IAS "Parameters" attribute
264 static gboolean dissect_ircomm_parameters(tvbuff_t* tvb, unsigned offset, packet_info* pinfo _U_,
265 proto_tree* tree, unsigned list_index, guint8 attr_type)
275 if (!check_iap_octet_result(tvb, tree, offset, "Parameters", attr_type))
280 len = tvb_get_ntohs(tvb, offset) + offset + 2;
285 guint8 p_len = tvb_get_guint8(tvb, offset + 1);
288 ti = proto_tree_add_item(tree, hf_ircomm_param, tvb, offset, p_len + 2, FALSE);
289 p_tree = proto_item_add_subtree(ti, ett_param[list_index * MAX_PARAMETERS + n]);
293 switch (tvb_get_guint8(tvb, offset))
295 case IRCOMM_SERVICE_TYPE:
296 proto_item_append_text(ti, ": Service Type (");
298 pv = tvb_get_guint8(tvb, offset+2);
299 if (pv & IRCOMM_3_WIRE_RAW)
300 strcat(buf, ", 3-Wire raw");
301 if (pv & IRCOMM_3_WIRE)
302 strcat(buf, ", 3-Wire");
303 if (pv & IRCOMM_9_WIRE)
304 strcat(buf, ", 9-Wire");
305 if (pv & IRCOMM_CENTRONICS)
306 strcat(buf, ", Centronics");
310 proto_item_append_text(ti, buf+2);
314 case IRCOMM_PORT_TYPE:
315 proto_item_append_text(ti, ": Port Type (");
317 pv = tvb_get_guint8(tvb, offset+2);
318 if (pv & IRCOMM_SERIAL)
319 strcat(buf, ", serial");
320 if (pv & IRCOMM_PARALLEL)
321 strcat(buf, ", parallel");
325 proto_item_append_text(ti, buf+2);
329 case IRCOMM_PORT_NAME:
330 /* XXX - the IrCOMM V1.0 spec says this "Normally
331 human readable text, but not required". */
332 proto_item_append_text(ti, ": Port Name (\"%s\")",
333 tvb_format_text(tvb, offset+2, p_len));
338 proto_item_append_text(ti, ": unknown");
341 offset = dissect_param_tuple(tvb, p_tree, offset);
352 * Dissect IrCOMM IAS "IrDA:TinyTP:LsapSel" attribute
354 static gboolean dissect_ircomm_ttp_lsap(tvbuff_t* tvb, unsigned offset, packet_info* pinfo,
355 proto_tree* tree, unsigned list_index _U_, guint8 attr_type)
360 if ((dlsap = check_iap_lsap_result(tvb, tree, offset, "IrDA:TinyTP:LsapSel", attr_type)) == 0)
363 add_lmp_conversation(pinfo, dlsap, TRUE, dissect_cooked_ircomm);
370 * Dissect IrCOMM/IrLPT IAS "IrDA:IrLMP:LsapSel" attribute
372 static gboolean dissect_ircomm_lmp_lsap(tvbuff_t* tvb, unsigned offset, packet_info* pinfo,
373 proto_tree* tree, unsigned list_index _U_, guint8 attr_type)
378 if ((dlsap = check_iap_lsap_result(tvb, tree, offset, "IrDA:IrLMP:LsapSel", attr_type)) == 0)
381 add_lmp_conversation(pinfo, dlsap, FALSE, dissect_raw_ircomm);
388 * Register the IrCOMM protocol
390 void proto_register_ircomm(void)
394 /* Setup list of header fields */
395 static hf_register_info hf_ircomm[] = {
397 { "IrCOMM Parameter", "ircomm.parameter",
398 FT_NONE, BASE_NONE, NULL, 0,
401 { "Parameter Identifier", "ircomm.pi",
402 FT_UINT8, BASE_HEX, NULL, 0,
405 { "Parameter Length", "ircomm.pl",
406 FT_UINT8, BASE_HEX, NULL, 0,
409 { "Parameter Value", "ircomm.pv",
410 FT_BYTES, BASE_HEX, NULL, 0,
413 { "Control Channel", "ircomm.control",
414 FT_NONE, BASE_NONE, NULL, 0,
417 { "Clen", "ircomm.control.len",
418 FT_UINT8, BASE_DEC, NULL, 0,
422 /* Setup protocol subtree arrays */
423 static gint* ett[] = {
428 static gint* ett_p[MAX_IAP_ENTRIES * MAX_PARAMETERS];
431 /* Register protocol names and descriptions */
432 proto_ircomm = proto_register_protocol("IrCOMM Protocol", "IrCOMM", "ircomm");
434 /* Required function calls to register the header fields */
435 proto_register_field_array(proto_ircomm, hf_ircomm, array_length(hf_ircomm));
437 /* Register subtrees */
438 proto_register_subtree_array(ett, array_length(ett));
439 for (i = 0; i < MAX_IAP_ENTRIES * MAX_PARAMETERS; i++)
442 ett_p[i] = &ett_param[i];
444 proto_register_subtree_array(ett_p, MAX_IAP_ENTRIES * MAX_PARAMETERS);