2 * Routines for IrDA dissection
3 * By Shaun Jackman <sjackman@pathwayconnect.com>
4 * Copyright 2000 Shaun Jackman
6 * Extended by Jan Kiszka <jan.kiszka@web.de>
7 * Copyright 2003 Jan Kiszka
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 #include <epan/packet.h>
40 #include <epan/proto.h>
41 #include <epan/conversation.h>
42 #include <epan/xdlc.h>
44 #include "irda-appl.h"
47 * This plugin dissects infrared data transmissions as defined by the IrDA
48 * specification (www.irda.org). See
50 * http://www.irda.org/standards/specifications.asp
52 * for various IrDA specifications.
54 * The plugin operates both offline with libpcap files and online on supported
55 * platforms. Live dissection is currently available for Linux-IrDA
56 * (irda.sourceforge.net) and for Windows if the Linux-IrDA port IrCOMM2k
57 * (www.ircomm2k.de) is installed.
64 /* Frame types and templates */
68 * XXX - the IrDA spec gives XID as 0x2c; HDLC (and other HDLC-derived
69 * protocolc) use 0xAC.
71 #define IRDA_XID_CMD 0x2c /* Exchange Station Identification */
73 #define CMD_FRAME 0x01
74 #define RSP_FRAME 0x00
80 /* Negotiation Parameters */
81 #define PI_BAUD_RATE 0x01
82 #define PI_MAX_TURN_TIME 0x82
83 #define PI_DATA_SIZE 0x83
84 #define PI_WINDOW_SIZE 0x84
85 #define PI_ADD_BOFS 0x85
86 #define PI_MIN_TURN_TIME 0x86
87 #define PI_LINK_DISC 0x08
94 /* IrLMP frame opcodes */
95 #define CONNECT_CMD 0x01
96 #define CONNECT_CNF 0x81
97 #define DISCONNECT 0x02
98 #define ACCESSMODE_CMD 0x03
99 #define ACCESSMODE_CNF 0x83
101 #define CONTROL_BIT 0x80
102 #define RESERVED_BIT 0x80
105 #define LSAP_MASK 0x7f
106 #define LSAP_IAS 0x00
107 #define LSAP_ANY 0xff
108 #define LSAP_MAX 0x6f /* 0x70-0x7f are reserved */
109 #define LSAP_CONNLESS 0x70 /* Connectionless LSAP, mostly used for Ultra */
117 #define GET_INFO_BASE 0x01
118 #define GET_OBJECTS 0x02
119 #define GET_VALUE 0x03
120 #define GET_VALUE_BY_CLASS 0x04
121 #define GET_OBJECT_INFO 0x05
122 #define GET_ATTRIB_NAMES 0x06
128 #define IAS_SUCCESS 0
129 #define IAS_CLASS_UNKNOWN 1
130 #define IAS_ATTRIB_UNKNOWN 2
131 #define IAS_ATTR_TOO_LONG 3
132 #define IAS_DISCONNECT 10
133 #define IAS_UNSUPPORTED 0xFF
140 #define TTP_PARAMETERS 0x80
141 #define TTP_MORE 0x80
143 static dissector_handle_t data_handle;
145 /* Initialize the protocol and registered fields */
146 static int proto_irlap = -1;
147 static int hf_lap_a = -1;
148 static int hf_lap_a_cr = -1;
149 static int hf_lap_a_address = -1;
150 static int hf_lap_c = -1;
151 static int hf_lap_c_nr = -1;
152 static int hf_lap_c_ns = -1;
153 static int hf_lap_c_p = -1;
154 static int hf_lap_c_f = -1;
155 static int hf_lap_c_s = -1;
156 static int hf_lap_c_u_cmd = -1;
157 static int hf_lap_c_u_rsp = -1;
158 static int hf_lap_c_i = -1;
159 static int hf_lap_c_s_u = -1;
160 static int hf_lap_i = -1;
161 static int hf_snrm_saddr = -1;
162 static int hf_snrm_daddr = -1;
163 static int hf_snrm_ca = -1;
164 static int hf_ua_saddr = -1;
165 static int hf_ua_daddr = -1;
166 static int hf_negotiation_param = -1;
167 static int hf_param_pi = -1;
168 static int hf_param_pl = -1;
169 static int hf_param_pv = -1;
170 static int hf_xid_ident = -1;
171 static int hf_xid_saddr = -1;
172 static int hf_xid_daddr = -1;
173 static int hf_xid_flags = -1;
174 static int hf_xid_s = -1;
175 static int hf_xid_conflict = -1;
176 static int hf_xid_slotnr = -1;
177 static int hf_xid_version = -1;
179 static int proto_irlmp = -1;
180 static int hf_lmp_xid_hints = -1;
181 static int hf_lmp_xid_charset = -1;
182 static int hf_lmp_xid_name = -1;
183 static int hf_lmp_xid_name_no_ascii = -1;
184 static int hf_lmp_dst = -1;
185 static int hf_lmp_dst_control = -1;
186 static int hf_lmp_dst_lsap = -1;
187 static int hf_lmp_src = -1;
188 static int hf_lmp_src_r = -1;
189 static int hf_lmp_src_lsap = -1;
190 static int hf_lmp_opcode = -1;
191 static int hf_lmp_rsvd = -1;
192 static int hf_lmp_reason = -1;
193 static int hf_lmp_mode = -1;
194 static int hf_lmp_status = -1;
196 static int proto_iap = -1;
197 static int hf_iap_ctl = -1;
198 static int hf_iap_ctl_lst = -1;
199 static int hf_iap_ctl_ack = -1;
200 static int hf_iap_ctl_opcode = -1;
201 static int hf_iap_class_name = -1;
202 static int hf_iap_attr_name = -1;
203 static int hf_iap_return = -1;
204 static int hf_iap_list_len = -1;
205 static int hf_iap_list_entry = -1;
206 static int hf_iap_obj_id = -1;
207 static int hf_iap_attr_type = -1;
208 static int hf_iap_int = -1;
209 static int hf_iap_seq_len = -1;
210 static int hf_iap_oct_seq = -1;
211 static int hf_iap_char_set = -1;
212 static int hf_iap_string = -1;
213 static int hf_iap_invaloctet = -1;
214 static int hf_iap_invallsap = -1;
216 static int proto_ttp = -1;
217 static int hf_ttp_p = -1;
218 static int hf_ttp_icredit = -1;
219 static int hf_ttp_m = -1;
220 static int hf_ttp_dcredit = -1;
222 static int proto_log = -1;
223 static int hf_log_msg = -1;
224 static int hf_log_missed = -1;
226 /* Initialize the subtree pointers */
227 static gint ett_irlap = -1;
228 static gint ett_lap_a = -1;
229 static gint ett_lap_c = -1;
230 static gint ett_lap_i = -1;
231 static gint ett_xid_flags = -1;
232 static gint ett_log = -1;
233 static gint ett_irlmp = -1;
234 static gint ett_lmp_dst = -1;
235 static gint ett_lmp_src = -1;
236 static gint ett_iap = -1;
237 static gint ett_iap_ctl = -1;
238 static gint ett_ttp = -1;
240 #define MAX_PARAMETERS 32
241 static gint ett_param[MAX_PARAMETERS];
243 static gint ett_iap_entry[MAX_IAP_ENTRIES];
245 static const xdlc_cf_items irlap_cf_items = {
257 /* IAP conversation type */
258 typedef struct iap_conversation {
259 struct iap_conversation* pnext;
260 guint32 iap_query_frame;
261 ias_attr_dissector_t* pattr_dissector;
262 } iap_conversation_t;
264 /* IrLMP conversation type */
265 typedef struct lmp_conversation {
266 struct lmp_conversation* pnext;
267 guint32 iap_result_frame;
269 dissector_t proto_dissector;
270 } lmp_conversation_t;
272 static GMemChunk* iap_conv_chunk = NULL;
273 static GMemChunk* lmp_conv_chunk = NULL;
275 static const true_false_string lap_cr_vals = {
280 static const true_false_string set_notset = {
285 static const value_string lap_c_ftype_vals[] = {
286 { XDLC_I, "Information frame" },
287 { XDLC_S, "Supervisory frame" },
288 { XDLC_U, "Unnumbered frame" },
292 static const value_string lap_c_u_cmd_abbr_vals[] = {
293 { XDLC_SNRM, "SNRM" },
294 { XDLC_DISC, "DISC" },
296 { IRDA_XID_CMD, "XID" },
297 { XDLC_TEST, "TEST" },
301 static const value_string lap_c_u_rsp_abbr_vals[] = {
302 { XDLC_SNRM, "RNRM" },
304 { XDLC_FRMR, "FRMR" },
309 { XDLC_TEST, "TEST" },
313 static const value_string lap_c_u_cmd_vals[] = {
314 { XDLC_SNRM>>2, "Set Normal Response Mode" },
315 { XDLC_DISC>>2, "Disconnect" },
316 { XDLC_UI>>2, "Unnumbered Information" },
317 { IRDA_XID_CMD>>2, "Exchange Station Identification" },
318 { XDLC_TEST>>2, "Test" },
322 static const value_string lap_c_u_rsp_vals[] = {
323 { XDLC_SNRM>>2, "Request Normal Response Mode" },
324 { XDLC_UA>>2, "Unnumbered Acknowledge" },
325 { XDLC_FRMR>>2, "Frame Reject" },
326 { XDLC_DM>>2, "Disconnect Mode" },
327 { XDLC_RD>>2, "Request Disconnect" },
328 { XDLC_UI>>2, "Unnumbered Information" },
329 { XDLC_XID>>2, "Exchange Station Identification" },
330 { XDLC_TEST>>2, "Test" },
334 static const value_string lap_c_s_vals[] = {
335 { XDLC_RR>>2, "Receiver ready" },
336 { XDLC_RNR>>2, "Receiver not ready" },
337 { XDLC_REJ>>2, "Reject" },
338 { XDLC_SREJ>>2, "Selective reject" },
342 static const value_string xid_slot_numbers[] = {
343 /* Number of XID slots */
351 static const value_string lmp_opcode_vals[] = {
352 /* IrLMP frame opcodes */
353 { CONNECT_CMD, "Connect Command" },
354 { CONNECT_CNF, "Connect Confirm" },
355 { DISCONNECT, "Disconnect" },
356 { ACCESSMODE_CMD, "Access Mode Command" },
357 { ACCESSMODE_CNF, "Access Mode Confirm" },
361 static const value_string lmp_reason_vals[] = {
362 /* IrLMP disconnect reasons */
363 { 0x01, "User Request" },
364 { 0x02, "Unexpected IrLAP Disconnect" },
365 { 0x03, "Failed to establish IrLAP connection" },
366 { 0x04, "IrLAP Reset" },
367 { 0x05, "Link Management Initiated Disconnect" },
368 { 0x06, "Data delivered on disconnected LSAP-Connection"},
369 { 0x07, "Non Responsive LM-MUX Client" },
370 { 0x08, "No available LM-MUX Client" },
371 { 0x09, "Connection Half Open" },
372 { 0x0A, "Illegal Source Address" },
373 { 0xFF, "Unspecified Disconnect Reason" },
377 static const value_string lmp_mode_vals[] = {
379 { 0x00, "Multiplexed" },
380 { 0x01, "Exclusive" },
384 static const value_string lmp_status_vals[] = {
388 { 0xFF, "Unsupported" },
392 static const value_string iap_opcode_vals[] = {
394 { GET_INFO_BASE, "GetInfoBase" },
395 { GET_OBJECTS, "GetObjects" },
396 { GET_VALUE, "GetValue" },
397 { GET_VALUE_BY_CLASS, "GetValueByClass" },
398 { GET_OBJECT_INFO, "GetObjectInfo" },
399 { GET_ATTRIB_NAMES, "GetAttributeNames" },
403 static const value_string iap_return_vals[] = {
404 /* IrIAP Return-codes */
405 { IAS_SUCCESS, "Success" },
406 { IAS_CLASS_UNKNOWN, "Class/Object Unknown" },
407 { IAS_ATTRIB_UNKNOWN, "Attribute Unknown" },
408 { IAS_ATTR_TOO_LONG, "Attribute List Too Long" },
409 { IAS_DISCONNECT, "Disconnect (Linux-IrDA only)" },
410 { IAS_UNSUPPORTED, "Unsupported Optional Operation" },
414 static const value_string iap_attr_type_vals[] = {
415 /* LM-IAS Attribute types */
416 { IAS_MISSING, "Missing" },
417 { IAS_INTEGER, "Integer" },
418 { IAS_OCT_SEQ, "Octet Sequence" },
419 { IAS_STRING, "String" },
423 static ias_attr_dissector_t device_attr_dissector[] = {
424 /* Device attribute dissectors */
425 /* { "IrLMPSupport", xxx }, not implemented yet... */
429 /* IAS class dissectors */
430 static ias_class_dissector_t class_dissector[] = { CLASS_DISSECTORS };
434 * Dissect parameter tuple
436 unsigned dissect_param_tuple(tvbuff_t* tvb, proto_tree* tree, unsigned offset)
438 guint8 len = tvb_get_guint8(tvb, offset + 1);
441 proto_tree_add_item(tree, hf_param_pi, tvb, offset, 1, FALSE);
445 proto_tree_add_item(tree, hf_param_pl, tvb, offset, 1, FALSE);
451 proto_tree_add_item(tree, hf_param_pv, tvb, offset, len, FALSE);
462 static unsigned dissect_ttp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, gboolean data)
468 if (tvb_length(tvb) == 0)
471 /* Make entries in Protocol column on summary display */
472 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TTP");
474 head = tvb_get_guint8(tvb, offset);
476 if (check_col(pinfo->cinfo, COL_INFO))
481 g_snprintf(buf, 128, ", Credit=%d", head & ~TTP_PARAMETERS);
482 col_append_str(pinfo->cinfo, COL_INFO, buf);
487 /* create display subtree for the protocol */
488 proto_item* ti = proto_tree_add_item(root, proto_ttp, tvb, 0, -1, FALSE);
489 proto_tree* tree = proto_item_add_subtree(ti, ett_ttp);
493 proto_tree_add_item(tree, hf_ttp_m, tvb, offset, 1, FALSE);
494 proto_tree_add_item(tree, hf_ttp_dcredit, tvb, offset, 1, FALSE);
499 proto_tree_add_item(tree, hf_ttp_p, tvb, offset, 1, FALSE);
500 proto_tree_add_item(tree, hf_ttp_icredit, tvb, offset, 1, FALSE);
503 proto_item_set_len(tree, offset);
513 * Dissect IAP request
515 static void dissect_iap_request(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
524 conversation_t* conv;
525 iap_conversation_t* iap_conv;
528 if (tvb_length(tvb) == 0)
531 /* Make entries in Protocol column on summary display */
532 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IAP");
534 op = tvb_get_guint8(tvb, offset) & IAP_OP;
538 case GET_VALUE_BY_CLASS:
539 clen = MIN(tvb_get_guint8(tvb, offset + 1), 60);
540 alen = MIN(tvb_get_guint8(tvb, offset + 1 + 1 + clen), 60);
542 /* create conversation entry */
543 src = pinfo->circuit_id ^ CMD_FRAME;
544 srcaddr.type = AT_NONE;
546 srcaddr.data = (guint8*)&src;
548 destaddr.type = AT_NONE;
550 destaddr.data = (guint8*)&pinfo->circuit_id;
552 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
555 iap_conv = (iap_conversation_t*)conversation_get_proto_data(conv, proto_iap);
558 if (iap_conv->iap_query_frame == pinfo->fd->num)
563 if (iap_conv->pnext == NULL)
565 iap_conv->pnext = g_mem_chunk_alloc(iap_conv_chunk);
566 iap_conv = iap_conv->pnext;
569 iap_conv = iap_conv->pnext;
574 conv = conversation_new(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
575 iap_conv = g_mem_chunk_alloc(iap_conv_chunk);
576 conversation_add_proto_data(conv, proto_iap, (void*)iap_conv);
579 /* Dissect IAP query if it is new */
583 char class_name[256];
587 iap_conv->pnext = NULL;
588 iap_conv->iap_query_frame = pinfo->fd->num;
589 iap_conv->pattr_dissector = NULL;
591 tvb_memcpy(tvb, class_name, offset + 1 + 1, clen);
592 class_name[clen] = 0;
593 tvb_memcpy(tvb, attr_name, offset + 1 + 1 + clen + 1, alen);
596 /* Find the attribute dissector */
597 for (i = 0; class_dissector[i].class_name != NULL; i++)
598 if (strcmp(class_name, class_dissector[i].class_name) == 0)
600 for (j = 0; class_dissector[i].pattr_dissector[j].attr_name != NULL; j++)
601 if (strcmp(attr_name, class_dissector[i].pattr_dissector[j].attr_name) == 0)
603 iap_conv->pattr_dissector = &class_dissector[i].pattr_dissector[j];
610 if (check_col(pinfo->cinfo, COL_INFO))
615 col_add_str(pinfo->cinfo, COL_INFO, "GetValueByClass: \"");
617 tvb_memcpy(tvb, buf, offset + 1 + 1, clen);
618 memcpy(&buf[clen], "\" \"", 3);
619 tvb_memcpy(tvb, buf + clen + 3, offset + 1 + 1 + clen + 1, alen);
620 buf[clen + 3 + alen] = '\"';
621 buf[clen + 3 + alen + 1] = 0;
622 col_append_str(pinfo->cinfo, COL_INFO, buf);
628 /* create display subtree for the protocol */
629 proto_item* ti = proto_tree_add_item(root, proto_iap, tvb, 0, -1, FALSE);
630 proto_tree* tree = proto_item_add_subtree(ti, ett_iap);
632 proto_tree* ctl_tree;
635 ti = proto_tree_add_item(tree, hf_iap_ctl, tvb, offset, 1, FALSE);
636 ctl_tree = proto_item_add_subtree(ti, ett_iap_ctl);
637 proto_tree_add_item(ctl_tree, hf_iap_ctl_lst, tvb, offset, 1, FALSE);
638 proto_tree_add_item(ctl_tree, hf_iap_ctl_ack, tvb, offset, 1, FALSE);
639 proto_tree_add_item(ctl_tree, hf_iap_ctl_opcode, tvb, offset, 1, FALSE);
644 case GET_VALUE_BY_CLASS:
645 proto_tree_add_item(tree, hf_iap_class_name, tvb, offset, 1, FALSE);
648 proto_tree_add_item(tree, hf_iap_attr_name, tvb, offset, 1, FALSE);
658 case GET_VALUE_BY_CLASS:
659 offset += 1 + clen + 1 + alen;
664 /* If any bytes remain, send it to the generic data dissector */
665 tvb = tvb_new_subset(tvb, offset, -1, -1);
666 call_dissector(data_handle, tvb, pinfo, root);
673 static void dissect_iap_result(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
676 unsigned len = tvb_length(tvb);
687 conversation_t* conv;
688 iap_conversation_t* cur_iap_conv;
689 iap_conversation_t* iap_conv = NULL;
693 if (tvb_length(tvb) == 0)
696 /* Make entries in Protocol column on summary display */
697 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IAP");
699 op = tvb_get_guint8(tvb, offset) & IAP_OP;
700 retcode = tvb_get_guint8(tvb, offset + 1);
702 src = pinfo->circuit_id ^ CMD_FRAME;
703 srcaddr.type = AT_NONE;
705 srcaddr.data = (guint8*)&src;
707 destaddr.type = AT_NONE;
709 destaddr.data = (guint8*)&pinfo->circuit_id;
711 /* Find result value dissector */
712 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
715 num = pinfo->fd->num;
717 iap_conv = (iap_conversation_t*)conversation_get_proto_data(conv, proto_iap);
718 while (iap_conv && (iap_conv->iap_query_frame >= num))
719 iap_conv = iap_conv->pnext;
723 cur_iap_conv = iap_conv->pnext;
726 if ((cur_iap_conv->iap_query_frame < num) &&
727 (cur_iap_conv->iap_query_frame > iap_conv->iap_query_frame))
729 iap_conv = cur_iap_conv;
732 cur_iap_conv = cur_iap_conv->pnext;
737 if (check_col(pinfo->cinfo, COL_INFO))
739 col_add_str(pinfo->cinfo, COL_INFO, "Result: ");
740 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(retcode, iap_return_vals, "0x%02X"));
744 case GET_VALUE_BY_CLASS:
748 switch (tvb_get_guint8(tvb, offset + 6))
751 g_snprintf(buf, 300, ", Missing");
755 g_snprintf(buf, 300, ", Integer: %d", tvb_get_ntohl(tvb, offset + 7));
759 g_snprintf(buf, 300, ", %d Octets", tvb_get_ntohs(tvb, offset + 7));
763 n = tvb_get_guint8(tvb, offset + 8);
764 string = tvb_get_ephemeral_string(tvb, offset + 9, n);
765 g_snprintf(buf, 300, ", \"%s\"", string);
768 col_append_str(pinfo->cinfo, COL_INFO, buf);
769 if (tvb_get_ntohs(tvb, offset + 2) > 1)
770 col_append_str(pinfo->cinfo, COL_INFO, ", ...");
778 /* create display subtree for the protocol */
779 proto_item* ti = proto_tree_add_item(root, proto_iap, tvb, 0, -1, FALSE);
780 proto_tree* tree = proto_item_add_subtree(ti, ett_iap);
782 proto_tree* ctl_tree;
783 proto_tree* entry_tree;
786 ti = proto_tree_add_item(tree, hf_iap_ctl, tvb, offset, 1, FALSE);
787 ctl_tree = proto_item_add_subtree(ti, ett_iap_ctl);
788 proto_tree_add_item(ctl_tree, hf_iap_ctl_lst, tvb, offset, 1, FALSE);
789 proto_tree_add_item(ctl_tree, hf_iap_ctl_ack, tvb, offset, 1, FALSE);
790 proto_tree_add_item(ctl_tree, hf_iap_ctl_opcode, tvb, offset, 1, FALSE);
793 proto_tree_add_item(tree, hf_iap_return, tvb, offset, 1, FALSE);
798 case GET_VALUE_BY_CLASS:
801 list_len = tvb_get_ntohs(tvb, offset);
803 proto_tree_add_item(tree, hf_iap_list_len, tvb, offset, 2, FALSE);
806 while ((offset < len) && (n < list_len))
808 type = tvb_get_guint8(tvb, offset + 2);
816 attr_len = tvb_get_ntohs(tvb, offset + 2 + 1) + 2;
820 attr_len = tvb_get_guint8(tvb, offset + 2 + 1 + 1) + 2;
827 ti = proto_tree_add_item(tree, hf_iap_list_entry, tvb, offset, 2 + 1 + attr_len, FALSE);
828 proto_item_append_text(ti, "%d", n + 1);
829 entry_tree = proto_item_add_subtree(ti, ett_iap_entry[n]);
831 proto_tree_add_item(entry_tree, hf_iap_obj_id, tvb, offset, 2, FALSE);
834 proto_tree_add_item(entry_tree, hf_iap_attr_type, tvb, offset, 1, FALSE);
840 if (!iap_conv || !iap_conv->pattr_dissector ||
841 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
843 proto_tree_add_item(entry_tree, hf_iap_int, tvb, offset, 4, FALSE);
847 proto_tree_add_item(entry_tree, hf_iap_seq_len, tvb, offset, 2, FALSE);
848 if (!iap_conv || !iap_conv->pattr_dissector ||
849 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
851 proto_tree_add_item(entry_tree, hf_iap_oct_seq, tvb, offset + 2,
852 attr_len - 2, FALSE);
856 proto_tree_add_item(entry_tree, hf_iap_char_set, tvb, offset, 1, FALSE);
857 if (!iap_conv || !iap_conv->pattr_dissector ||
858 !iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, entry_tree,
860 proto_tree_add_item(entry_tree, hf_iap_string, tvb, offset + 1, 1, FALSE);
876 case GET_VALUE_BY_CLASS:
884 type = tvb_get_guint8(tvb, offset);
891 if (iap_conv && iap_conv->pattr_dissector)
892 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
897 attr_len = tvb_get_ntohs(tvb, offset) + 2;
898 if (iap_conv && iap_conv->pattr_dissector)
899 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
904 attr_len = tvb_get_guint8(tvb, offset + 1) + 2;
905 if (iap_conv && iap_conv->pattr_dissector)
906 iap_conv->pattr_dissector->value_dissector(tvb, offset, pinfo, 0,
921 /* If any bytes remain, send it to the generic data dissector */
922 tvb = tvb_new_subset(tvb, offset, -1, -1);
923 call_dissector(data_handle, tvb, pinfo, root);
928 * Check if IAP result is octet sequence
930 gboolean check_iap_octet_result(tvbuff_t* tvb, proto_tree* tree, unsigned offset,
931 const char* attr_name, guint8 attr_type)
933 if (attr_type != IAS_OCT_SEQ)
937 proto_item* ti = proto_tree_add_item(tree, hf_iap_invaloctet, tvb, offset, 0, FALSE);
938 proto_item_append_text(ti, "%s", attr_name);
939 proto_item_append_text(ti, "\" attribute must be octet sequence!");
950 * Check if IAP result is correct LsapSel
952 guint8 check_iap_lsap_result(tvbuff_t* tvb, proto_tree* tree, unsigned offset,
953 const char* attr_name, guint8 attr_type)
958 if ((attr_type != IAS_INTEGER) || ((lsap = tvb_get_ntohl(tvb, offset)) < 0x01) ||
963 proto_item* ti = proto_tree_add_item(tree, hf_iap_invallsap, tvb, offset, 0, FALSE);
964 proto_item_append_text(ti, "%s", attr_name);
965 proto_item_append_text(ti, "\" attribute must be integer value between 0x01 and 0x6F!");
976 * Dissect IrDA application protocol
978 static void dissect_appl_proto(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, pdu_type_t pdu_type)
984 conversation_t* conv;
985 lmp_conversation_t* cur_lmp_conv;
986 lmp_conversation_t* lmp_conv = NULL;
990 src = pinfo->circuit_id ^ CMD_FRAME;
991 srcaddr.type = AT_NONE;
993 srcaddr.data = (guint8*)&src;
995 destaddr.type = AT_NONE;
997 destaddr.data = (guint8*)&pinfo->circuit_id;
999 /* Find result value dissector */
1000 conv = find_conversation(pinfo->fd->num, &srcaddr, &destaddr, PT_NONE, pinfo->srcport, pinfo->destport, 0);
1003 num = pinfo->fd->num;
1005 lmp_conv = (lmp_conversation_t*)conversation_get_proto_data(conv, proto_irlmp);
1006 while (lmp_conv && (lmp_conv->iap_result_frame >= num))
1007 lmp_conv = lmp_conv->pnext;
1011 cur_lmp_conv = lmp_conv->pnext;
1012 while (cur_lmp_conv)
1014 if ((cur_lmp_conv->iap_result_frame < num) &&
1015 (cur_lmp_conv->iap_result_frame > lmp_conv->iap_result_frame))
1017 lmp_conv = cur_lmp_conv;
1020 cur_lmp_conv = cur_lmp_conv->pnext;
1027 /*g_message("%x:%d->%x:%d = %p\n", src, pinfo->srcport, pinfo->circuit_id, pinfo->destport, lmp_conv); */
1028 /*g_message("->%d: %d %d %p\n", pinfo->fd->num, lmp_conv->iap_result_frame, lmp_conv->ttp, lmp_conv->proto_dissector); */
1029 if ((lmp_conv->ttp) && (pdu_type != DISCONNECT_PDU))
1031 offset += dissect_ttp(tvb, pinfo, root, (pdu_type == DATA_PDU));
1033 tvb = tvb_new_subset(tvb, offset, -1, -1);
1036 pinfo->private_data = (void *)pdu_type;
1038 lmp_conv->proto_dissector(tvb, pinfo, root);
1041 call_dissector(data_handle, tvb, pinfo, root);
1048 static void dissect_irlmp(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1050 unsigned offset = 0;
1057 /* Make entries in Protocol column on summary display */
1058 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrLMP");
1060 dlsap = tvb_get_guint8(tvb, offset);
1061 cbit = dlsap & CONTROL_BIT;
1062 dlsap &= ~CONTROL_BIT;
1064 slsap = tvb_get_guint8(tvb, offset+1) & ~CONTROL_BIT;
1066 /* save Lsaps in pinfo */
1067 pinfo->srcport = slsap;
1068 pinfo->destport = dlsap;
1072 opcode = tvb_get_guint8(tvb, offset+2);
1074 if (check_col(pinfo->cinfo, COL_INFO))
1076 col_add_fstr(pinfo->cinfo, COL_INFO, "%d > %d, ", slsap, dlsap);
1077 col_append_str(pinfo->cinfo, COL_INFO, val_to_str(opcode, lmp_opcode_vals, "0x%02X"));
1078 if ((opcode == ACCESSMODE_CMD) || (opcode == ACCESSMODE_CNF))
1080 col_append_str(pinfo->cinfo, COL_INFO, " (");
1081 col_append_str(pinfo->cinfo, COL_INFO,
1082 val_to_str(tvb_get_guint8(tvb, offset+4), lmp_mode_vals, "0x%02X"));
1083 col_append_str(pinfo->cinfo, COL_INFO, ")");
1088 if (check_col(pinfo->cinfo, COL_INFO))
1089 col_add_fstr(pinfo->cinfo, COL_INFO, "%d > %d, Len=%d", slsap, dlsap,
1090 tvb_length(tvb) - 2);
1094 /* create display subtree for the protocol */
1095 proto_item* ti = proto_tree_add_item(root, proto_irlmp, tvb, 0, -1, FALSE);
1096 proto_tree* tree = proto_item_add_subtree(ti, ett_irlmp);
1098 proto_tree* dst_tree;
1099 proto_tree* src_tree;
1102 ti = proto_tree_add_item(tree, hf_lmp_dst, tvb, offset, 1, FALSE);
1103 dst_tree = proto_item_add_subtree(ti, ett_lmp_dst);
1104 proto_tree_add_item(dst_tree, hf_lmp_dst_control, tvb, offset, 1, FALSE);
1105 proto_tree_add_item(dst_tree, hf_lmp_dst_lsap, tvb, offset, 1, FALSE);
1108 ti = proto_tree_add_item(tree, hf_lmp_src, tvb, offset, 1, FALSE);
1109 src_tree = proto_item_add_subtree(ti, ett_lmp_src);
1110 proto_tree_add_item(src_tree, hf_lmp_src_r, tvb, offset, 1, FALSE);
1111 proto_tree_add_item(src_tree, hf_lmp_src_lsap, tvb, offset, 1, FALSE);
1116 proto_tree_add_item(tree, hf_lmp_opcode, tvb, offset, 1, FALSE);
1123 if (offset < tvb_length(tvb))
1125 proto_tree_add_item(tree, hf_lmp_rsvd, tvb, offset, 1, FALSE);
1131 proto_tree_add_item(tree, hf_lmp_reason, tvb, offset, 1, FALSE);
1135 case ACCESSMODE_CMD:
1136 proto_tree_add_item(tree, hf_lmp_rsvd, tvb, offset, 1, FALSE);
1139 proto_tree_add_item(tree, hf_lmp_mode, tvb, offset, 1, FALSE);
1143 case ACCESSMODE_CNF:
1144 proto_tree_add_item( tree, hf_lmp_status, tvb, offset, 1, FALSE);
1147 proto_tree_add_item(tree, hf_lmp_mode, tvb, offset, 1, FALSE);
1153 tvb = tvb_new_subset(tvb, offset, -1, -1);
1154 proto_item_set_len(tree, offset);
1167 if (offset < tvb_length(tvb))
1175 case ACCESSMODE_CMD:
1176 case ACCESSMODE_CNF:
1182 tvb = tvb_new_subset(tvb, offset, -1, -1);
1187 if (dlsap == LSAP_IAS)
1188 dissect_iap_request(tvb, pinfo, root);
1189 else if (slsap == LSAP_IAS)
1190 dissect_iap_result(tvb, pinfo, root);
1192 dissect_appl_proto(tvb, pinfo, root, DATA_PDU);
1196 if ((dlsap == LSAP_IAS) || (slsap == LSAP_IAS))
1197 call_dissector(data_handle, tvb, pinfo, root);
1203 dissect_appl_proto(tvb, pinfo, root, CONNECT_PDU);
1207 dissect_appl_proto(tvb, pinfo, root, DISCONNECT_PDU);
1211 call_dissector(data_handle, tvb, pinfo, root);
1218 * Add LMP conversation
1220 void add_lmp_conversation(packet_info* pinfo, guint8 dlsap, gboolean ttp, dissector_t proto_dissector)
1225 conversation_t* conv;
1226 lmp_conversation_t* lmp_conv = NULL;
1229 /*g_message("%d: add_lmp_conversation(%p, %d, %d, %p) = ", pinfo->fd->num, pinfo, dlsap, ttp, proto_dissector); */
1230 srcaddr.type = AT_NONE;
1232 srcaddr.data = (guint8*)&pinfo->circuit_id;
1234 dest = pinfo->circuit_id ^ CMD_FRAME;
1235 destaddr.type = AT_NONE;
1237 destaddr.data = (guint8*)&dest;
1239 conv = find_conversation(pinfo->fd->num, &destaddr, &srcaddr, PT_NONE, dlsap, 0, NO_PORT_B);
1242 lmp_conv = (lmp_conversation_t*)conversation_get_proto_data(conv, proto_irlmp);
1245 /* Does entry already exist? */
1246 if (lmp_conv->iap_result_frame == pinfo->fd->num)
1249 if (lmp_conv->pnext == NULL)
1251 lmp_conv->pnext = g_mem_chunk_alloc(lmp_conv_chunk);
1252 lmp_conv = lmp_conv->pnext;
1255 lmp_conv = lmp_conv->pnext;
1260 conv = conversation_new(pinfo->fd->num, &destaddr, &srcaddr, PT_NONE, dlsap, 0, NO_PORT_B);
1261 lmp_conv = g_mem_chunk_alloc(lmp_conv_chunk);
1262 conversation_add_proto_data(conv, proto_irlmp, (void*)lmp_conv);
1265 lmp_conv->pnext = NULL;
1266 lmp_conv->iap_result_frame = pinfo->fd->num;
1267 lmp_conv->ttp = ttp;
1268 lmp_conv->proto_dissector = proto_dissector;
1270 /*g_message("%p\n", lmp_conv); */
1275 * Dissect Negotiation Parameters
1277 static unsigned dissect_negotiation(tvbuff_t* tvb, proto_tree* tree, unsigned offset)
1285 while (tvb_reported_length_remaining(tvb, offset) > 0)
1287 guint8 p_len = tvb_get_guint8(tvb, offset + 1);
1291 ti = proto_tree_add_item(tree, hf_negotiation_param, tvb, offset, p_len + 2, FALSE);
1292 p_tree = proto_item_add_subtree(ti, ett_param[n]);
1294 pv = tvb_get_guint8(tvb, offset+2);
1297 switch (tvb_get_guint8(tvb, offset))
1300 proto_item_append_text(ti, ": Baud Rate (");
1303 g_strlcat(buf, ", 2400", 256);
1305 g_strlcat(buf, ", 9600", 256);
1307 g_strlcat(buf, ", 19200", 256);
1309 g_strlcat(buf, ", 38400", 256);
1311 g_strlcat(buf, ", 57600", 256);
1313 g_strlcat(buf, ", 115200", 256);
1315 g_strlcat(buf, ", 576000", 256);
1317 g_strlcat(buf, ", 1152000", 256);
1318 if ((p_len > 1) && (tvb_get_guint8(tvb, offset+3) & 0x01))
1319 g_strlcat(buf, ", 4000000", 256);
1321 g_strlcat(buf, " bps)", 256);
1323 proto_item_append_text(ti, "%s", buf+2);
1327 case PI_MAX_TURN_TIME:
1328 proto_item_append_text(ti, ": Maximum Turn Time (");
1331 g_strlcat(buf, ", 500", 256);
1333 g_strlcat(buf, ", 250", 256);
1335 g_strlcat(buf, ", 100", 256);
1337 g_strlcat(buf, ", 50", 256);
1339 g_strlcat(buf, " ms)", 256);
1341 proto_item_append_text(ti, "%s", buf+2);
1346 proto_item_append_text(ti, ": Data Size (");
1349 g_strlcat(buf, ", 64", 256);
1351 g_strlcat(buf, ", 128", 256);
1353 g_strlcat(buf, ", 256", 256);
1355 g_strlcat(buf, ", 512", 256);
1357 g_strlcat(buf, ", 1024", 256);
1359 g_strlcat(buf, ", 2048", 256);
1361 g_strlcat(buf, " bytes)", 256);
1363 proto_item_append_text(ti, "%s", buf+2);
1367 case PI_WINDOW_SIZE:
1368 proto_item_append_text(ti, ": Window Size (");
1371 g_strlcat(buf, ", 1", 256);
1373 g_strlcat(buf, ", 2", 256);
1375 g_strlcat(buf, ", 3", 256);
1377 g_strlcat(buf, ", 4", 256);
1379 g_strlcat(buf, ", 5", 256);
1381 g_strlcat(buf, ", 6", 256);
1383 g_strlcat(buf, ", 7", 256);
1385 g_strlcat(buf, " frame window)", 256);
1387 proto_item_append_text(ti, "%s", buf+2);
1392 proto_item_append_text(ti, ": Additional BOFs (");
1395 g_strlcat(buf, ", 48", 256);
1397 g_strlcat(buf, ", 24", 256);
1399 g_strlcat(buf, ", 12", 256);
1401 g_strlcat(buf, ", 5", 256);
1403 g_strlcat(buf, ", 3", 256);
1405 g_strlcat(buf, ", 2", 256);
1407 g_strlcat(buf, ", 1", 256);
1409 g_strlcat(buf, ", 0", 256);
1411 g_strlcat(buf, " additional BOFs at 115200)", 256);
1413 proto_item_append_text(ti, "%s", buf+2);
1417 case PI_MIN_TURN_TIME:
1418 proto_item_append_text(ti, ": Minimum Turn Time (");
1421 g_strlcat(buf, ", 10", 256);
1423 g_strlcat(buf, ", 5", 256);
1425 g_strlcat(buf, ", 1", 256);
1427 g_strlcat(buf, ", 0.5", 256);
1429 g_strlcat(buf, ", 0.1", 256);
1431 g_strlcat(buf, ", 0.05", 256);
1433 g_strlcat(buf, ", 0.01", 256);
1435 g_strlcat(buf, ", 0", 256);
1437 g_strlcat(buf, " ms)", 256);
1439 proto_item_append_text(ti, "%s", buf+2);
1444 proto_item_append_text(ti, ": Link Disconnect/Threshold Time (");
1447 g_strlcat(buf, ", 3/0", 256);
1449 g_strlcat(buf, ", 8/3", 256);
1451 g_strlcat(buf, ", 12/3", 256);
1453 g_strlcat(buf, ", 16/3", 256);
1455 g_strlcat(buf, ", 20/3", 256);
1457 g_strlcat(buf, ", 25/3", 256);
1459 g_strlcat(buf, ", 30/3", 256);
1461 g_strlcat(buf, ", 40/3", 256);
1463 g_strlcat(buf, " s)", 256);
1465 proto_item_append_text(ti, "%s", buf+2);
1470 proto_item_append_text(ti, ": unknown");
1475 offset = dissect_param_tuple(tvb, p_tree, offset);
1484 * Dissect XID packet
1486 static void dissect_xid(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root, proto_tree* lap_tree, gboolean is_command)
1489 proto_item* ti = NULL;
1490 proto_tree* i_tree = NULL;
1491 proto_tree* flags_tree;
1492 guint32 saddr, daddr;
1494 proto_tree* lmp_tree = NULL;
1498 ti = proto_tree_add_item(lap_tree, hf_lap_i, tvb, offset, -1, FALSE);
1499 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1501 proto_tree_add_item(i_tree, hf_xid_ident, tvb, offset, 1, FALSE);
1505 saddr = tvb_get_letohl(tvb, offset);
1506 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1507 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1509 proto_tree_add_uint(i_tree, hf_xid_saddr, tvb, offset, 4, saddr);
1512 daddr = tvb_get_letohl(tvb, offset);
1513 if (check_col(pinfo->cinfo, COL_DEF_DST))
1514 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1516 proto_tree_add_uint(i_tree, hf_xid_daddr, tvb, offset, 4, daddr);
1521 ti = proto_tree_add_item(i_tree, hf_xid_flags, tvb, offset, 1, FALSE);
1522 flags_tree = proto_item_add_subtree(ti, ett_xid_flags);
1523 proto_tree_add_item(flags_tree, hf_xid_s, tvb, offset, 1, FALSE);
1524 proto_tree_add_item(flags_tree, hf_xid_conflict, tvb, offset, 1, FALSE);
1530 s = tvb_get_guint8(tvb, offset);
1531 if (check_col(pinfo->cinfo, COL_INFO))
1534 col_append_str(pinfo->cinfo, COL_INFO, ", s=final");
1536 col_append_fstr(pinfo->cinfo, COL_INFO, ", s=%u", s);
1540 ti = proto_tree_add_uint(i_tree, hf_xid_slotnr, tvb, offset, 1, s);
1542 proto_item_append_text(ti, " (final)");
1548 proto_tree_add_item(i_tree, hf_xid_version, tvb, offset, 1, FALSE);
1553 proto_item_set_end(lap_tree, tvb, offset);
1554 proto_item_set_end(i_tree, tvb, offset);
1557 if (tvb_reported_length_remaining(tvb, offset) > 0)
1565 ti = proto_tree_add_item(root, proto_irlmp, tvb, offset, -1, FALSE);
1566 lmp_tree = proto_item_add_subtree(ti, ett_irlmp);
1569 for (hints_len = 0;;)
1571 guint8 hint = tvb_get_guint8(tvb, offset + hints_len++);
1575 else if (hints_len == 2)
1578 if ((hint & 0x80) == 0)
1584 ti = proto_tree_add_item(lmp_tree, hf_lmp_xid_hints, tvb, offset, hints_len, FALSE);
1585 if ((hint1 | hint2) != 0)
1587 char service_hints[256];
1589 service_hints[0] = 0;
1592 g_strlcat(service_hints, ", PnP Compatible", 256);
1594 g_strlcat(service_hints, ", PDA/Palmtop", 256);
1596 g_strlcat(service_hints, ", Computer", 256);
1598 g_strlcat(service_hints, ", Printer", 256);
1600 g_strlcat(service_hints, ", Modem", 256);
1602 g_strlcat(service_hints, ", Fax", 256);
1604 g_strlcat(service_hints, ", LAN Access", 256);
1606 g_strlcat(service_hints, ", Telephony", 256);
1608 g_strlcat(service_hints, ", File Server", 256);
1610 g_strlcat(service_hints, ", IrCOMM", 256);
1612 g_strlcat(service_hints, ", OBEX", 256);
1614 g_strlcat(service_hints, ")", 256);
1615 service_hints[0] = ' ';
1616 service_hints[1] = '(';
1618 proto_item_append_text(ti, "%s", service_hints);
1621 offset += hints_len;
1623 if (tvb_reported_length_remaining(tvb, offset) > 0)
1628 cset = tvb_get_guint8(tvb, offset);
1630 proto_tree_add_uint(lmp_tree, hf_lmp_xid_charset, tvb, offset, 1, cset);
1632 name_len = tvb_reported_length_remaining(tvb, offset);
1637 if (check_col(pinfo->cinfo, COL_INFO))
1643 tvb_memcpy(tvb, buf, offset, name_len);
1645 col_append_str(pinfo->cinfo, COL_INFO, ", \"");
1646 col_append_str(pinfo->cinfo, COL_INFO, buf);
1647 col_append_str(pinfo->cinfo, COL_INFO, "\"");
1650 proto_tree_add_item(lmp_tree, hf_lmp_xid_name, tvb, offset,
1656 proto_tree_add_item(lmp_tree, hf_lmp_xid_name_no_ascii, tvb, offset,
1666 * Dissect Log Messages
1668 static void dissect_log(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1670 /* Make entries in Protocol column on summary display */
1671 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Log");
1673 /* missed messages? */
1674 if (pinfo->pseudo_header->irda.pkttype == IRDA_MISSED_MSG)
1676 if (check_col(pinfo->cinfo, COL_INFO))
1677 col_set_str(pinfo->cinfo, COL_INFO,
1678 "WARNING: Missed one or more messages while capturing!");
1680 else if (check_col(pinfo->cinfo, COL_INFO))
1686 length = tvb_length(tvb);
1687 if (length > sizeof(buf)-1)
1688 length = sizeof(buf)-1;
1689 tvb_memcpy(tvb, buf, 0, length);
1691 if (buf[length-1] == '\n')
1693 else if (buf[length-2] == '\n')
1696 col_add_str(pinfo->cinfo, COL_INFO, buf);
1701 proto_item* ti = proto_tree_add_item(root, proto_log, tvb, 0, -1, FALSE);
1702 proto_tree* tree = proto_item_add_subtree(ti, ett_log);
1704 if (pinfo->pseudo_header->irda.pkttype == IRDA_MISSED_MSG)
1705 proto_tree_add_item(tree, hf_log_missed, tvb, 0, 0, FALSE);
1707 proto_tree_add_item(tree, hf_log_msg, tvb, 0, -1, FALSE);
1715 static void dissect_irlap(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1719 gboolean is_response;
1721 proto_item* ti = NULL;
1722 proto_tree* tree = NULL;
1723 proto_tree* i_tree = NULL;
1724 guint32 saddr, daddr;
1727 /* Make entries in Protocol column on summary display */
1728 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IrLAP");
1730 /* Clear Info column */
1731 if (check_col(pinfo->cinfo, COL_INFO))
1732 col_clear(pinfo->cinfo, COL_INFO);
1734 /* set direction column */
1735 if (check_col(pinfo->cinfo, COL_IF_DIR))
1737 switch (pinfo->pseudo_header->irda.pkttype)
1740 col_set_str(pinfo->cinfo, COL_IF_DIR, "Out");
1744 col_set_str(pinfo->cinfo, COL_IF_DIR, "In");
1749 /* decode values used for demuxing */
1750 a = tvb_get_guint8(tvb, 0);
1752 /* save connection address field in pinfo */
1753 pinfo->circuit_id = a;
1755 /* initially set address columns to connection address */
1756 g_snprintf(addr, sizeof(addr)-1, "0x%02X", a >> 1);
1757 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1758 col_add_str(pinfo->cinfo, COL_DEF_SRC, addr);
1759 if (check_col(pinfo->cinfo, COL_DEF_DST))
1760 col_add_str(pinfo->cinfo, COL_DEF_DST, addr);
1765 proto_item* addr_item;
1767 /* create display subtree for the protocol */
1768 ti = proto_tree_add_item(root, proto_irlap, tvb, 0, -1, FALSE);
1769 tree = proto_item_add_subtree(ti, ett_irlap);
1771 /* create subtree for the address field */
1772 ti = proto_tree_add_item(tree, hf_lap_a, tvb, offset, 1, FALSE);
1773 a_tree = proto_item_add_subtree(ti, ett_lap_a);
1774 proto_tree_add_item(a_tree, hf_lap_a_cr, tvb, offset, 1, FALSE);
1775 addr_item = proto_tree_add_item(a_tree, hf_lap_a_address, tvb, offset, 1, FALSE);
1776 switch (a & ~CMD_FRAME)
1779 proto_item_append_text(addr_item, " (NULL Address)");
1782 proto_item_append_text(addr_item, " (Broadcast)");
1786 is_response = ((a & CMD_FRAME) == 0);
1789 /* process the control field */
1790 c = dissect_xdlc_control(tvb, 1, pinfo, tree, hf_lap_c,
1791 ett_lap_c, &irlap_cf_items, NULL, lap_c_u_cmd_abbr_vals,
1792 lap_c_u_rsp_abbr_vals, is_response, FALSE, FALSE);
1795 if ((c & XDLC_I_MASK) == XDLC_I) {
1797 proto_item_set_len(tree, offset);
1798 tvb = tvb_new_subset(tvb, offset, -1, -1);
1799 dissect_irlmp(tvb, pinfo, root);
1803 if ((c & 0x03) == XDLC_U) {
1805 switch (c & XDLC_U_MODIFIER_MASK)
1810 ti = proto_tree_add_item(tree, hf_lap_i, tvb, offset, -1, FALSE);
1811 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1814 saddr = tvb_get_letohl(tvb, offset);
1817 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1818 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1821 proto_tree_add_uint(i_tree, hf_snrm_saddr, tvb, offset, 4, saddr);
1824 daddr = tvb_get_letohl(tvb, offset);
1827 if (check_col(pinfo->cinfo, COL_DEF_DST))
1828 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1831 proto_tree_add_uint(i_tree, hf_snrm_daddr, tvb, offset, 4, daddr);
1834 ca = tvb_get_guint8(tvb, offset);
1837 if (check_col(pinfo->cinfo, COL_INFO))
1838 col_append_fstr(pinfo->cinfo, COL_INFO, ", ca=0x%02X",
1842 proto_tree_add_uint(i_tree, hf_snrm_ca, tvb, offset, 1, ca >> 1);
1845 offset = dissect_negotiation(tvb, i_tree, offset);
1847 proto_item_set_end(ti, tvb, offset);
1851 tvb = tvb_new_subset(tvb, offset, -1, -1);
1852 dissect_xid(tvb, pinfo, root, tree, TRUE);
1856 if (tvb_reported_length_remaining(tvb, offset) > 0)
1860 ti = proto_tree_add_item(tree, hf_lap_i, tvb, offset, -1, FALSE);
1861 i_tree = proto_item_add_subtree(ti, ett_lap_i);
1864 saddr = tvb_get_letohl(tvb, offset);
1865 if (check_col(pinfo->cinfo, COL_DEF_SRC))
1866 col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "0x%08X", saddr);
1868 proto_tree_add_uint(i_tree, hf_ua_saddr, tvb, offset, 4, saddr);
1871 daddr = tvb_get_letohl(tvb, offset);
1872 if (check_col(pinfo->cinfo, COL_DEF_DST))
1873 col_add_fstr(pinfo->cinfo, COL_DEF_DST, "0x%08X", daddr);
1875 proto_tree_add_uint(i_tree, hf_ua_daddr, tvb, offset, 4, daddr);
1878 offset = dissect_negotiation(tvb, i_tree, offset);
1880 proto_item_set_end(ti, tvb, offset);
1885 tvb = tvb_new_subset(tvb, offset, -1, -1);
1886 dissect_xid(tvb, pinfo, root, tree, FALSE);
1891 /* If any bytes remain, send it to the generic data dissector */
1892 if (tvb_reported_length_remaining(tvb, offset) > 0)
1894 tvb = tvb_new_subset(tvb, offset, -1, -1);
1895 call_dissector(data_handle, tvb, pinfo, root);
1901 * Dissect IrDA protocol
1903 static void dissect_irda(tvbuff_t* tvb, packet_info* pinfo, proto_tree* root)
1905 /* load the display labels */
1906 pinfo->current_proto = "IrDA";
1908 /* check if log message */
1909 if ((pinfo->pseudo_header->irda.pkttype & IRDA_CLASS_MASK) == IRDA_CLASS_LOG)
1911 dissect_log(tvb, pinfo, root);
1916 dissect_irlap(tvb, pinfo, root);
1921 * Re-initialize the IrDA dissector
1923 static void init_irda(void)
1926 g_mem_chunk_destroy(iap_conv_chunk);
1928 g_mem_chunk_destroy(lmp_conv_chunk);
1930 iap_conv_chunk = g_mem_chunk_new("iap_conversation", sizeof(iap_conversation_t),
1931 10 * sizeof(iap_conversation_t), G_ALLOC_AND_FREE);
1932 lmp_conv_chunk = g_mem_chunk_new("lmp_conversation", sizeof(lmp_conversation_t),
1933 10 * sizeof(lmp_conversation_t), G_ALLOC_AND_FREE);
1938 * Register the protocol with Wireshark
1939 * This format is required because a script is used to build the C function
1940 * that calls all the protocol registrations.
1942 void proto_register_irda(void)
1946 /* Setup list of header fields */
1947 static hf_register_info hf_lap[] = {
1949 { "Address Field", "irlap.a",
1950 FT_UINT8, BASE_HEX, NULL, 0,
1953 { "C/R", "irlap.a.cr",
1954 FT_BOOLEAN, 8, TFS(&lap_cr_vals), CMD_FRAME,
1956 { &hf_lap_a_address,
1957 { "Address", "irlap.a.address",
1958 FT_UINT8, BASE_HEX, NULL, ~CMD_FRAME,
1961 { "Control Field", "irlap.c",
1962 FT_UINT8, BASE_HEX, NULL, 0,
1965 { "N(R)", "irlap.c.n_r",
1966 FT_UINT8, BASE_DEC, NULL, XDLC_N_R_MASK,
1969 { "N(S)", "irlap.c.n_s",
1970 FT_UINT8, BASE_DEC, NULL, XDLC_N_S_MASK,
1973 { "Poll", "irlap.c.p",
1974 FT_BOOLEAN, 8, TFS(&set_notset), XDLC_P_F,
1977 { "Final", "irlap.c.f",
1978 FT_BOOLEAN, 8, TFS(&set_notset), XDLC_P_F,
1981 { "Supervisory frame type", "irlap.c.s_ftype",
1982 FT_UINT8, BASE_HEX, VALS(lap_c_s_vals), XDLC_S_FTYPE_MASK,
1985 { "Command", "irlap.c.u_modifier_cmd",
1986 FT_UINT8, BASE_HEX, VALS(lap_c_u_cmd_vals), XDLC_U_MODIFIER_MASK,
1989 { "Response", "irlap.c.u_modifier_resp",
1990 FT_UINT8, BASE_HEX, VALS(lap_c_u_rsp_vals), XDLC_U_MODIFIER_MASK,
1993 { "Frame Type", "irlap.c.ftype",
1994 FT_UINT8, BASE_HEX, VALS(lap_c_ftype_vals), XDLC_I_MASK,
1997 { "Frame Type", "irlap.c.ftype",
1998 FT_UINT8, BASE_HEX, VALS(lap_c_ftype_vals), XDLC_S_U_MASK,
2001 { "Information Field", "irlap.i",
2002 FT_NONE, BASE_NONE, NULL, 0,
2005 { "Source Device Address", "irlap.snrm.saddr",
2006 FT_UINT32, BASE_HEX, NULL, 0,
2009 { "Destination Device Address", "irlap.snrm.daddr",
2010 FT_UINT32, BASE_HEX, NULL, 0,
2013 { "Connection Address", "irlap.snrm.ca",
2014 FT_UINT8, BASE_HEX, NULL, 0,
2016 { &hf_negotiation_param,
2017 { "Negotiation Parameter", "irlap.negotiation",
2018 FT_NONE, BASE_NONE, NULL, 0,
2021 { "Parameter Identifier", "irlap.pi",
2022 FT_UINT8, BASE_HEX, NULL, 0,
2025 { "Parameter Length", "irlap.pl",
2026 FT_UINT8, BASE_HEX, NULL, 0,
2029 { "Parameter Value", "irlap.pv",
2030 FT_BYTES, BASE_NONE, NULL, 0,
2033 { "Source Device Address", "irlap.ua.saddr",
2034 FT_UINT32, BASE_HEX, NULL, 0,
2037 { "Destination Device Address", "irlap.ua.daddr",
2038 FT_UINT32, BASE_HEX, NULL, 0,
2041 { "Format Identifier", "irlap.xid.fi",
2042 FT_UINT8, BASE_HEX, NULL, 0,
2045 { "Source Device Address", "irlap.xid.saddr",
2046 FT_UINT32, BASE_HEX, NULL, 0,
2049 { "Destination Device Address", "irlap.xid.daddr",
2050 FT_UINT32, BASE_HEX, NULL, 0,
2053 { "Discovery Flags", "irlap.xid.flags",
2054 FT_UINT8, BASE_HEX, NULL, 0,
2057 { "Number of Slots", "irlap.xid.s",
2058 FT_UINT8, BASE_DEC, VALS(&xid_slot_numbers), S_MASK,
2061 { "Conflict", "irlap.xid.conflict",
2062 FT_BOOLEAN, 8, TFS(&set_notset), CONFLICT,
2065 { "Slot Number", "irlap.xid.slotnr",
2066 FT_UINT8, BASE_DEC, NULL, 0,
2069 { "Version Number", "irlap.xid.version",
2070 FT_UINT8, BASE_HEX, NULL, 0,
2074 static hf_register_info hf_log[] = {
2076 { "Message", "log.msg",
2077 FT_STRING, BASE_NONE, NULL, 0,
2080 { "WARNING: Missed one or more messages while capturing!", "log.missed",
2081 FT_NONE, BASE_NONE, NULL, 0,
2085 static hf_register_info hf_lmp[] = {
2086 { &hf_lmp_xid_hints,
2087 { "Service Hints", "irlmp.xid.hints",
2088 FT_BYTES, BASE_NONE, NULL, 0,
2090 { &hf_lmp_xid_charset,
2091 { "Character Set", "irlmp.xid.charset",
2092 FT_UINT8, BASE_HEX, NULL, 0,
2095 { "Device Nickname", "irlmp.xid.name",
2096 FT_STRING, BASE_NONE, NULL, 0,
2098 { &hf_lmp_xid_name_no_ascii,
2099 { "Device Nickname (unsupported character set)", "irlmp.xid.name",
2100 FT_BYTES, BASE_NONE, NULL, 0,
2103 { "Destination", "irlmp.dst",
2104 FT_UINT8, BASE_HEX, NULL, 0,
2106 { &hf_lmp_dst_control,
2107 { "Control Bit", "irlmp.dst.c",
2108 FT_BOOLEAN, 8, TFS(&set_notset), CONTROL_BIT,
2111 { "Destination LSAP", "irlmp.dst.lsap",
2112 FT_UINT8, BASE_DEC, NULL, ~CONTROL_BIT,
2115 { "Source", "irlmp.src",
2116 FT_UINT8, BASE_HEX, NULL, 0,
2119 { "reserved", "irlmp.src.r",
2120 FT_UINT8, BASE_DEC, NULL, RESERVED_BIT,
2123 { "Source LSAP", "irlmp.src.lsap",
2124 FT_UINT8, BASE_DEC, NULL, ~RESERVED_BIT,
2127 { "Opcode", "irlmp.opcode",
2128 FT_UINT8, BASE_HEX, VALS(lmp_opcode_vals), 0x0,
2131 { "Reserved", "irlmp.rsvd",
2132 FT_UINT8, BASE_HEX, NULL, 0x0,
2135 { "Reason", "irlmp.reason",
2136 FT_UINT8, BASE_HEX, VALS(lmp_reason_vals), 0x0,
2139 { "Mode", "irlmp.mode",
2140 FT_UINT8, BASE_HEX, VALS(lmp_mode_vals), 0x0,
2143 { "Status", "irlmp.status",
2144 FT_UINT8, BASE_HEX, VALS(lmp_status_vals), 0x0,
2148 static hf_register_info hf_iap[] = {
2150 { "Control Field", "iap.ctl",
2151 FT_UINT8, BASE_HEX, NULL, 0,
2154 { "Last Frame", "iap.ctl.lst",
2155 FT_BOOLEAN, 8, TFS(&set_notset), IAP_LST,
2158 { "Acknowledge", "iap.ctl.ack",
2159 FT_BOOLEAN, 8, TFS(&set_notset), IAP_ACK,
2161 { &hf_iap_ctl_opcode,
2162 { "Opcode", "iap.ctl.opcode",
2163 FT_UINT8, BASE_HEX, VALS(iap_opcode_vals), IAP_OP,
2165 { &hf_iap_class_name,
2166 { "Class Name", "iap.classname",
2167 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2169 { &hf_iap_attr_name,
2170 { "Attribute Name", "iap.attrname",
2171 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2174 { "Return", "iap.return",
2175 FT_UINT8, BASE_HEX, VALS(iap_return_vals), 0x0,
2178 { "List Length", "iap.listlen",
2179 FT_UINT16, BASE_DEC, NULL, 0x0,
2181 { &hf_iap_list_entry,
2182 { "List Entry", "iap.listentry",
2183 FT_NONE, BASE_NONE, NULL, 0x0,
2186 { "Object Identifier", "iap.objectid",
2187 FT_UINT16, BASE_HEX, NULL, 0x0,
2189 { &hf_iap_attr_type,
2190 { "Type", "iap.attrtype",
2191 FT_UINT8, BASE_DEC, VALS(iap_attr_type_vals), 0x0,
2194 { "Value", "iap.int",
2195 FT_INT32, BASE_DEC, NULL, 0x0,
2198 { "Sequence Length", "iap.seqlen",
2199 FT_UINT16, BASE_DEC, NULL, 0x0,
2202 { "Sequence", "iap.octseq",
2203 FT_BYTES, BASE_NONE, NULL, 0x0,
2206 { "Character Set", "iap.charset",
2207 FT_UINT8, BASE_HEX, NULL, 0x0,
2210 { "String", "iap.string",
2211 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
2213 { &hf_iap_invaloctet,
2214 { "Malformed IAP result: \"", "iap.invaloctet",
2215 FT_NONE, BASE_NONE, NULL, 0,
2217 { &hf_iap_invallsap,
2218 { "Malformed IAP result: \"", "iap.invallsap",
2219 FT_NONE, BASE_NONE, NULL, 0,
2223 static hf_register_info hf_ttp[] = {
2225 { "Parameter Bit", "ttp.p",
2226 FT_BOOLEAN, 8, TFS(&set_notset), TTP_PARAMETERS,
2229 { "Initial Credit", "ttp.icredit",
2230 FT_UINT8, BASE_DEC, NULL, ~TTP_PARAMETERS,
2233 { "More Bit", "ttp.m",
2234 FT_BOOLEAN, 8, TFS(&set_notset), TTP_MORE,
2237 { "Delta Credit", "ttp.dcredit",
2238 FT_UINT8, BASE_DEC, NULL, ~TTP_MORE,
2242 /* Setup protocol subtree arrays */
2243 static gint* ett[] = {
2258 static gint* ett_p[MAX_PARAMETERS];
2259 static gint* ett_iap_e[MAX_IAP_ENTRIES];
2262 /* Register re-init routine */
2263 register_init_routine(init_irda);
2265 /* Register protocol names and descriptions */
2266 proto_irlap = proto_register_protocol("IrDA Link Access Protocol", "IrLAP", "irlap");
2267 proto_log = proto_register_protocol("Log Message", "Log", "log");
2268 proto_irlmp = proto_register_protocol("IrDA Link Management Protocol", "IrLMP", "irlmp");
2269 proto_iap = proto_register_protocol("Information Access Protocol", "IAP", "iap");
2270 proto_ttp = proto_register_protocol("Tiny Transport Protocol", "TTP", "ttp");
2272 /* Register the dissector */
2273 register_dissector("irda", dissect_irda, proto_irlap);
2275 /* Required function calls to register the header fields */
2276 proto_register_field_array(proto_irlap, hf_lap, array_length(hf_lap));
2277 proto_register_field_array(proto_log, hf_log, array_length(hf_log));
2278 proto_register_field_array(proto_irlmp, hf_lmp, array_length(hf_lmp));
2279 proto_register_field_array(proto_iap, hf_iap, array_length(hf_iap));
2280 proto_register_field_array(proto_ttp, hf_ttp, array_length(hf_ttp));
2282 /* Register subtrees */
2283 proto_register_subtree_array(ett, array_length(ett));
2284 for (i = 0; i < MAX_PARAMETERS; i++)
2287 ett_p[i] = &ett_param[i];
2289 proto_register_subtree_array(ett_p, MAX_PARAMETERS);
2290 for (i = 0; i < MAX_IAP_ENTRIES; i++)
2292 ett_iap_entry[i] = -1;
2293 ett_iap_e[i] = &ett_iap_entry[i];
2295 proto_register_subtree_array(ett_iap_e, MAX_IAP_ENTRIES);
2299 /* If this dissector uses sub-dissector registration add a registration routine.
2300 This format is required because a script is used to find these routines and
2301 create the code that calls these routines.
2304 void proto_reg_handoff_irda(void)
2306 dissector_handle_t irda_handle;
2308 irda_handle = find_dissector("irda");
2309 dissector_add("wtap_encap", WTAP_ENCAP_IRDA, irda_handle);
2310 data_handle = find_dissector("data");